Changeset 21528
- Timestamp:
- Feb 17, 2009, 4:44:19 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c
r21516 r21528 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $6 * @date $Date: 2009-02-1 6 22:30:50$5 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2009-02-18 02:44:19 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 45 45 // followed by a zero-size matrix, followed by the table data 46 46 47 bool pmSourcesWrite_CMF_PS1_V1 (psFits *fits, pmReadout *readout, psArray *sources, 48 psMetadata *imageHeader, psMetadata *tableHeader, char *extname)47 bool pmSourcesWrite_CMF_PS1_V1 (psFits *fits, pmReadout *readout, psArray *sources, 48 psMetadata *imageHeader, psMetadata *tableHeader, char *extname) 49 49 { 50 50 PS_ASSERT_PTR_NON_NULL(fits, false); … … 72 72 float zeroptErr = psMetadataLookupF32 (&status2, imageHeader, "ZPT_ERR"); 73 73 if (status1 && status2 && (exptime > 0.0)) { 74 magOffset = zeropt + 2.5*log10(exptime);74 magOffset = zeropt + 2.5*log10(exptime); 75 75 } 76 76 … … 79 79 if (sources->n > 0) { 80 80 pmSource *source = (pmSource *) sources->data[0]; 81 if (source->seq == -1) {82 // let's write these out in S/N order83 sources = psArraySort (sources, pmSourceSortBySN);84 } else {85 sources = psArraySort (sources, pmSourceSortBySeq);86 }81 if (source->seq == -1) { 82 // let's write these out in S/N order 83 sources = psArraySort (sources, pmSourceSortBySN); 84 } else { 85 sources = psArraySort (sources, pmSourceSortBySeq); 86 } 87 87 } 88 88 … … 94 94 pmSource *source = (pmSource *) sources->data[i]; 95 95 96 // If source->seq is -1, source was generated in this analysis. If source->seq is97 // not -1, source was read from elsewhere: in the latter case, preserve the source98 // ID. source.seq is used instead of source.id since the latter is a const99 // generated on Alloc, and would thus be wrong for read in sources.100 if (source->seq == -1) {101 source->seq = i;102 }96 // If source->seq is -1, source was generated in this analysis. If source->seq is 97 // not -1, source was read from elsewhere: in the latter case, preserve the source 98 // ID. source.seq is used instead of source.id since the latter is a const 99 // generated on Alloc, and would thus be wrong for read in sources. 100 if (source->seq == -1) { 101 source->seq = i; 102 } 103 103 104 104 // no difference between PSF and non-PSF model … … 110 110 xPos = PAR[PM_PAR_XPOS]; 111 111 yPos = PAR[PM_PAR_YPOS]; 112 if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) {113 xErr = dPAR[PM_PAR_XPOS];114 yErr = dPAR[PM_PAR_YPOS];115 } else {116 // in linear-fit mode, there is no error on the centroid117 xErr = source->peak->dx;118 yErr = source->peak->dy;119 } 120 if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {121 axes = pmPSF_ModelToAxes (PAR, 20.0);122 } else {123 axes.major = NAN;124 axes.minor = NAN;125 axes.theta = NAN;126 }127 chisq = model->chisq;128 nDOF = model->nDOF;129 nPix = model->nPix;130 apRadius = model->radiusFit; // XXX should we really use the fitRadius for aperture Radius?131 errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];112 if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) { 113 xErr = dPAR[PM_PAR_XPOS]; 114 yErr = dPAR[PM_PAR_YPOS]; 115 } else { 116 // in linear-fit mode, there is no error on the centroid 117 xErr = source->peak->dx; 118 yErr = source->peak->dy; 119 } 120 if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) { 121 axes = pmPSF_ModelToAxes (PAR, 20.0); 122 } else { 123 axes.major = NAN; 124 axes.minor = NAN; 125 axes.theta = NAN; 126 } 127 chisq = model->chisq; 128 nDOF = model->nDOF; 129 nPix = model->nPix; 130 apRadius = model->radiusFit; // XXX should we really use the fitRadius for aperture Radius? 131 errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0]; 132 132 } else { 133 133 xPos = source->peak->xf; … … 138 138 axes.minor = NAN; 139 139 axes.theta = NAN; 140 chisq = NAN;141 nDOF = 0;142 nPix = 0;143 apRadius = NAN;144 errMag = NAN;145 } 146 147 float calMag = isfinite(magOffset) ? source->psfMag + magOffset : NAN;140 chisq = NAN; 141 nDOF = 0; 142 nPix = 0; 143 apRadius = NAN; 144 errMag = NAN; 145 } 146 147 float calMag = isfinite(magOffset) ? source->psfMag + magOffset : NAN; 148 148 float peakMag = (source->peak->flux > 0) ? -2.5*log10(source->peak->flux) : NAN; 149 149 psS16 nImageOverlap = 1; 150 150 151 psSphere ptSky = {0.0, 0.0, 0.0, 0.0};152 float posAngle = 0.0;153 float pltScale = 0.0;154 pmSourceLocalAstrometry (&ptSky, &posAngle, &pltScale, chip, xPos, yPos);151 psSphere ptSky = {0.0, 0.0, 0.0, 0.0}; 152 float posAngle = 0.0; 153 float pltScale = 0.0; 154 pmSourceLocalAstrometry (&ptSky, &posAngle, &pltScale, chip, xPos, yPos); 155 155 156 156 row = psMetadataAlloc (); … … 185 185 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX", PS_DATA_S32, "number of pixels in fit", nPix); 186 186 187 // distinguish moments measure from window vs S/N > XX ?? 188 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX", PS_DATA_F32, "second moments (X^2)", source->moments->Mxx); 189 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY", PS_DATA_F32, "second moments (X*Y)", source->moments->Mxy); 190 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY", PS_DATA_F32, "second moments (Y*Y)", source->moments->Myy); 187 // distinguish moments measure from window vs S/N > XX ?? 188 float mxx = source->moments ? source->moments->Mxx : NAN; 189 float mxy = source->moments ? source->moments->Mxy : NAN; 190 float myy = source->moments ? source->moments->Myy : NAN; 191 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX", PS_DATA_F32, "second moments (X^2)", mxx); 192 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY", PS_DATA_F32, "second moments (X*Y)", mxy); 193 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY", PS_DATA_F32, "second moments (Y*Y)", myy); 191 194 192 195 psMetadataAdd (row, PS_LIST_TAIL, "FLAGS", PS_DATA_U32, "psphot analysis flags", source->mode); … … 199 202 psFree (row); 200 203 201 // EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not202 // subtracted203 204 // CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image205 // edge; 3) any pixels in the 3x3 peak region are masked; 204 // EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not 205 // subtracted 206 207 // CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image 208 // edge; 3) any pixels in the 3x3 peak region are masked; 206 209 } 207 210 … … 281 284 source->apMag = psMetadataLookupF32 (&status, row, "AP_MAG"); 282 285 283 // XXX this scaling is incorrect: does not include the 2 \pi AREA factor 284 PAR[PM_PAR_I0] = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;285 dPAR[PM_PAR_I0] = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;286 // XXX this scaling is incorrect: does not include the 2 \pi AREA factor 287 PAR[PM_PAR_I0] = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN; 288 dPAR[PM_PAR_I0] = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN; 286 289 287 290 pmPSF_AxesToModel (PAR, axes); … … 290 293 float peakFlux = (isfinite(peakMag)) ? pow(10.0, -0.4*peakMag) : NAN; 291 294 292 // recreate the peak to match (xPos, yPos) +/- (xErr, yErr)295 // recreate the peak to match (xPos, yPos) +/- (xErr, yErr) 293 296 source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE); 294 297 source->peak->flux = peakFlux; … … 300 303 source->extNsigma = psMetadataLookupF32 (&status, row, "EXT_NSIGMA"); 301 304 302 // note that some older versions used PSF_PROBABILITY: this was not well defined.303 model->chisq = psMetadataLookupF32 (&status, row, "PSF_CHISQ");304 model->nDOF = psMetadataLookupS32 (&status, row, "PSF_NDOF");305 model->nPix = psMetadataLookupS32 (&status, row, "PSF_NPIX");305 // note that some older versions used PSF_PROBABILITY: this was not well defined. 306 model->chisq = psMetadataLookupF32 (&status, row, "PSF_CHISQ"); 307 model->nDOF = psMetadataLookupS32 (&status, row, "PSF_NDOF"); 308 model->nPix = psMetadataLookupS32 (&status, row, "PSF_NPIX"); 306 309 model->radiusFit = psMetadataLookupS32 (&status, row, "AP_MAG_RADIUS"); 307 310 308 source->moments = pmMomentsAlloc ();311 source->moments = pmMomentsAlloc (); 309 312 source->moments->Mxx = psMetadataLookupF32 (&status, row, "MOMENTS_XX"); 310 313 source->moments->Mxy = psMetadataLookupF32 (&status, row, "MOMENTS_XY"); … … 321 324 } 322 325 323 // XXX this layout is still the same as PS1_DEV_1 326 // XXX this layout is still the same as PS1_DEV_1 324 327 bool pmSourcesWrite_CMF_PS1_V1_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe) 325 328 { … … 355 358 // we write out all sources, regardless of quality. the source flags tell us the state 356 359 for (int i = 0; i < sources->n; i++) { 357 // skip source if it is not a ext sourc358 // XXX we have two places that extended source parameters are measured:359 // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,360 // psphotFitEXT, which does the simple extended source model fit (not psf-convolved)361 // should we require both?362 363 pmSource *source = sources->data[i];364 365 // skip sources without measurements366 if (source->extpars == NULL) continue;367 368 // we require a PSF model fit (ignore the real crud)369 pmModel *model = source->modelPSF;370 if (model == NULL) continue;371 372 // XXX I need to split the extended models from the extended aperture measurements373 PAR = model->params->data.F32;374 dPAR = model->dparams->data.F32;375 xPos = PAR[PM_PAR_XPOS];376 yPos = PAR[PM_PAR_YPOS];377 xErr = dPAR[PM_PAR_XPOS];378 yErr = dPAR[PM_PAR_YPOS];360 // skip source if it is not a ext sourc 361 // XXX we have two places that extended source parameters are measured: 362 // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models, 363 // psphotFitEXT, which does the simple extended source model fit (not psf-convolved) 364 // should we require both? 365 366 pmSource *source = sources->data[i]; 367 368 // skip sources without measurements 369 if (source->extpars == NULL) continue; 370 371 // we require a PSF model fit (ignore the real crud) 372 pmModel *model = source->modelPSF; 373 if (model == NULL) continue; 374 375 // XXX I need to split the extended models from the extended aperture measurements 376 PAR = model->params->data.F32; 377 dPAR = model->dparams->data.F32; 378 xPos = PAR[PM_PAR_XPOS]; 379 yPos = PAR[PM_PAR_YPOS]; 380 xErr = dPAR[PM_PAR_XPOS]; 381 yErr = dPAR[PM_PAR_YPOS]; 379 382 380 383 row = psMetadataAlloc (); … … 387 390 psMetadataAdd (row, PS_LIST_TAIL, "Y_EXT_SIG", PS_DATA_F32, "Sigma in EXT y coordinate", yErr); 388 391 389 // Petrosian measurements390 // XXX insert header data: petrosian ref radius, flux ratio391 if (doPetrosian) {392 pmSourcePetrosianValues *petrosian = source->extpars->petrosian;393 if (petrosian) {394 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG", PS_DATA_F32, "Petrosian Magnitude", petrosian->mag);395 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR", PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);396 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS", PS_DATA_F32, "Petrosian Radius", petrosian->rad);397 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error", petrosian->radErr);398 } else {399 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG", PS_DATA_F32, "Petrosian Magnitude", NAN);400 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR", PS_DATA_F32, "Petrosian Magnitude Error", NAN);401 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS", PS_DATA_F32, "Petrosian Radius", NAN);402 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error", NAN);403 }404 } 405 406 // Kron measurements407 if (doKron) {408 pmSourceKronValues *kron = source->extpars->kron;409 if (kron) {410 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG", PS_DATA_F32, "Kron Magnitude", kron->mag);411 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR", PS_DATA_F32, "Kron Magnitude Error", kron->magErr);412 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS", PS_DATA_F32, "Kron Radius", kron->rad);413 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error", kron->radErr);414 } else {415 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG", PS_DATA_F32, "Kron Magnitude", NAN);416 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR", PS_DATA_F32, "Kron Magnitude Error", NAN);417 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS", PS_DATA_F32, "Kron Radius", NAN);418 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error", NAN);419 }420 }421 422 // Isophot measurements423 // XXX insert header data: isophotal level424 if (doIsophotal) {425 pmSourceIsophotalValues *isophot = source->extpars->isophot;426 if (isophot) {427 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG", PS_DATA_F32, "Isophot Magnitude", isophot->mag);428 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR", PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);429 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS", PS_DATA_F32, "Isophot Radius", isophot->rad);430 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error", isophot->radErr);431 } else {432 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG", PS_DATA_F32, "Isophot Magnitude", NAN);433 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR", PS_DATA_F32, "Isophot Magnitude Error", NAN);434 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS", PS_DATA_F32, "Isophot Radius", NAN);435 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error", NAN);436 }437 }438 439 // Flux Annuli440 if (doAnnuli) {441 pmSourceAnnuli *annuli = source->extpars->annuli;442 if (annuli) {443 psVector *fluxVal = annuli->flux;444 psVector *fluxErr = annuli->fluxErr;445 psVector *fluxVar = annuli->fluxVar;446 447 for (int j = 0; j < fluxVal->n; j++) {448 char name[32];449 sprintf (name, "FLUX_VAL_R_%02d", j);450 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);451 sprintf (name, "FLUX_ERR_R_%02d", j);452 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);453 sprintf (name, "FLUX_VAR_R_%02d", j);454 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);455 } 456 } else {457 for (int j = 0; j < radialBinsLower->n; j++) {458 char name[32];459 sprintf (name, "FLUX_VAL_R_%02d", j);460 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);461 sprintf (name, "FLUX_ERR_R_%02d", j);462 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);463 sprintf (name, "FLUX_VAR_R_%02d", j);464 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);465 } 466 }467 }468 469 psArrayAdd (table, 100, row);470 psFree (row);392 // Petrosian measurements 393 // XXX insert header data: petrosian ref radius, flux ratio 394 if (doPetrosian) { 395 pmSourcePetrosianValues *petrosian = source->extpars->petrosian; 396 if (petrosian) { 397 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG", PS_DATA_F32, "Petrosian Magnitude", petrosian->mag); 398 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR", PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr); 399 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS", PS_DATA_F32, "Petrosian Radius", petrosian->rad); 400 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error", petrosian->radErr); 401 } else { 402 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG", PS_DATA_F32, "Petrosian Magnitude", NAN); 403 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR", PS_DATA_F32, "Petrosian Magnitude Error", NAN); 404 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS", PS_DATA_F32, "Petrosian Radius", NAN); 405 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error", NAN); 406 } 407 } 408 409 // Kron measurements 410 if (doKron) { 411 pmSourceKronValues *kron = source->extpars->kron; 412 if (kron) { 413 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG", PS_DATA_F32, "Kron Magnitude", kron->mag); 414 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR", PS_DATA_F32, "Kron Magnitude Error", kron->magErr); 415 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS", PS_DATA_F32, "Kron Radius", kron->rad); 416 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error", kron->radErr); 417 } else { 418 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG", PS_DATA_F32, "Kron Magnitude", NAN); 419 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR", PS_DATA_F32, "Kron Magnitude Error", NAN); 420 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS", PS_DATA_F32, "Kron Radius", NAN); 421 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error", NAN); 422 } 423 } 424 425 // Isophot measurements 426 // XXX insert header data: isophotal level 427 if (doIsophotal) { 428 pmSourceIsophotalValues *isophot = source->extpars->isophot; 429 if (isophot) { 430 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG", PS_DATA_F32, "Isophot Magnitude", isophot->mag); 431 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR", PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr); 432 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS", PS_DATA_F32, "Isophot Radius", isophot->rad); 433 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error", isophot->radErr); 434 } else { 435 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG", PS_DATA_F32, "Isophot Magnitude", NAN); 436 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR", PS_DATA_F32, "Isophot Magnitude Error", NAN); 437 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS", PS_DATA_F32, "Isophot Radius", NAN); 438 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error", NAN); 439 } 440 } 441 442 // Flux Annuli 443 if (doAnnuli) { 444 pmSourceAnnuli *annuli = source->extpars->annuli; 445 if (annuli) { 446 psVector *fluxVal = annuli->flux; 447 psVector *fluxErr = annuli->fluxErr; 448 psVector *fluxVar = annuli->fluxVar; 449 450 for (int j = 0; j < fluxVal->n; j++) { 451 char name[32]; 452 sprintf (name, "FLUX_VAL_R_%02d", j); 453 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]); 454 sprintf (name, "FLUX_ERR_R_%02d", j); 455 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]); 456 sprintf (name, "FLUX_VAR_R_%02d", j); 457 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]); 458 } 459 } else { 460 for (int j = 0; j < radialBinsLower->n; j++) { 461 char name[32]; 462 sprintf (name, "FLUX_VAL_R_%02d", j); 463 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN); 464 sprintf (name, "FLUX_ERR_R_%02d", j); 465 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN); 466 sprintf (name, "FLUX_VAR_R_%02d", j); 467 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN); 468 } 469 } 470 } 471 472 psArrayAdd (table, 100, row); 473 psFree (row); 471 474 } 472 475 473 476 if (table->n == 0) { 474 psFitsWriteBlank (fits, outhead, extname);475 psFree (outhead);476 psFree (table);477 return true;477 psFitsWriteBlank (fits, outhead, extname); 478 psFree (outhead); 479 psFree (table); 480 return true; 478 481 } 479 482 480 483 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 481 484 if (!psFitsWriteTable (fits, outhead, table, extname)) { 482 psError(PS_ERR_IO, false, "writing ext data %s\n", extname);483 psFree (outhead);484 psFree(table);485 return false;485 psError(PS_ERR_IO, false, "writing ext data %s\n", extname); 486 psFree (outhead); 487 psFree(table); 488 return false; 486 489 } 487 490 psFree (outhead); … … 491 494 } 492 495 493 // XXX this layout is still the same as PS1_DEV_1 496 // XXX this layout is still the same as PS1_DEV_1 494 497 bool pmSourcesWrite_CMF_PS1_V1_XFIT (psFits *fits, psArray *sources, char *extname) 495 498 { … … 515 518 int nParamMax = 0; 516 519 for (int i = 0; i < sources->n; i++) { 517 pmSource *source = sources->data[i];518 if (source->modelFits == NULL) continue;519 for (int j = 0; j < source->modelFits->n; j++) {520 pmModel *model = source->modelFits->data[j];521 assert (model);522 nParamMax = PS_MAX (nParamMax, model->params->n);523 }520 pmSource *source = sources->data[i]; 521 if (source->modelFits == NULL) continue; 522 for (int j = 0; j < source->modelFits->n; j++) { 523 pmModel *model = source->modelFits->data[j]; 524 assert (model); 525 nParamMax = PS_MAX (nParamMax, model->params->n); 526 } 524 527 } 525 528 … … 529 532 for (int i = 0; i < sources->n; i++) { 530 533 531 pmSource *source = sources->data[i];532 533 // XXX if no model fits are saved, write out modelEXT?534 if (source->modelFits == NULL) continue;535 536 // We have multiple sources : need to flag the one used to subtract the light (the 'best' model)537 for (int j = 0; j < source->modelFits->n; j++) {538 539 // choose the convolved EXT model, if available, otherwise the simple one540 pmModel *model = source->modelFits->data[j];541 assert (model);542 543 PAR = model->params->data.F32;544 dPAR = model->dparams->data.F32;545 xPos = PAR[PM_PAR_XPOS];546 yPos = PAR[PM_PAR_YPOS];547 xErr = dPAR[PM_PAR_XPOS];548 yErr = dPAR[PM_PAR_YPOS];549 550 axes = pmPSF_ModelToAxes (PAR, 20.0);551 552 row = psMetadataAlloc ();553 554 // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)555 psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET", 0, "IPP detection identifier index", source->seq);556 psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT", 0, "EXT model x coordinate", xPos);557 psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT", 0, "EXT model y coordinate", yPos);558 psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG", 0, "Sigma in EXT x coordinate", xErr);559 psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG", 0, "Sigma in EXT y coordinate", yErr);560 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG", 0, "EXT fit instrumental magnitude", model->mag);561 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude", model->magErr);562 563 psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS", 0, "number of model parameters", model->params->n);564 psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE", 0, "name of model", pmModelClassGetName (model->type));565 566 // XXX these should be major and minor, not 'x' and 'y'567 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ", 0, "EXT width in x coordinate", axes.major);568 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN", 0, "EXT width in y coordinate", axes.minor);569 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA", 0, "EXT orientation angle", axes.theta);570 571 // write out the other generic parameters572 for (int k = 0; k < nParamMax; k++) {573 if (k == PM_PAR_I0) continue;574 if (k == PM_PAR_SKY) continue;575 if (k == PM_PAR_XPOS) continue;576 if (k == PM_PAR_YPOS) continue;577 if (k == PM_PAR_SXX) continue;578 if (k == PM_PAR_SXY) continue;579 if (k == PM_PAR_SYY) continue;580 581 snprintf (name, 64, "EXT_PAR_%02d", k);582 583 if (k < model->params->n) {584 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);585 } else {586 psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);587 }588 }589 590 // XXX other parameters which may be set.591 // XXX flag / value to define the model592 // XXX write out the model type, fit status flags593 594 psArrayAdd (table, 100, row);595 psFree (row);596 }534 pmSource *source = sources->data[i]; 535 536 // XXX if no model fits are saved, write out modelEXT? 537 if (source->modelFits == NULL) continue; 538 539 // We have multiple sources : need to flag the one used to subtract the light (the 'best' model) 540 for (int j = 0; j < source->modelFits->n; j++) { 541 542 // choose the convolved EXT model, if available, otherwise the simple one 543 pmModel *model = source->modelFits->data[j]; 544 assert (model); 545 546 PAR = model->params->data.F32; 547 dPAR = model->dparams->data.F32; 548 xPos = PAR[PM_PAR_XPOS]; 549 yPos = PAR[PM_PAR_YPOS]; 550 xErr = dPAR[PM_PAR_XPOS]; 551 yErr = dPAR[PM_PAR_YPOS]; 552 553 axes = pmPSF_ModelToAxes (PAR, 20.0); 554 555 row = psMetadataAlloc (); 556 557 // XXX we are not writing out the mode (flags) or the type (psf, ext, etc) 558 psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET", 0, "IPP detection identifier index", source->seq); 559 psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT", 0, "EXT model x coordinate", xPos); 560 psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT", 0, "EXT model y coordinate", yPos); 561 psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG", 0, "Sigma in EXT x coordinate", xErr); 562 psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG", 0, "Sigma in EXT y coordinate", yErr); 563 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG", 0, "EXT fit instrumental magnitude", model->mag); 564 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude", model->magErr); 565 566 psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS", 0, "number of model parameters", model->params->n); 567 psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE", 0, "name of model", pmModelClassGetName (model->type)); 568 569 // XXX these should be major and minor, not 'x' and 'y' 570 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ", 0, "EXT width in x coordinate", axes.major); 571 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN", 0, "EXT width in y coordinate", axes.minor); 572 psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA", 0, "EXT orientation angle", axes.theta); 573 574 // write out the other generic parameters 575 for (int k = 0; k < nParamMax; k++) { 576 if (k == PM_PAR_I0) continue; 577 if (k == PM_PAR_SKY) continue; 578 if (k == PM_PAR_XPOS) continue; 579 if (k == PM_PAR_YPOS) continue; 580 if (k == PM_PAR_SXX) continue; 581 if (k == PM_PAR_SXY) continue; 582 if (k == PM_PAR_SYY) continue; 583 584 snprintf (name, 64, "EXT_PAR_%02d", k); 585 586 if (k < model->params->n) { 587 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]); 588 } else { 589 psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN); 590 } 591 } 592 593 // XXX other parameters which may be set. 594 // XXX flag / value to define the model 595 // XXX write out the model type, fit status flags 596 597 psArrayAdd (table, 100, row); 598 psFree (row); 599 } 597 600 } 598 601 599 602 if (table->n == 0) { 600 psFitsWriteBlank (fits, outhead, extname);601 psFree (outhead);602 psFree (table);603 return true;603 psFitsWriteBlank (fits, outhead, extname); 604 psFree (outhead); 605 psFree (table); 606 return true; 604 607 } 605 608 606 609 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 607 610 if (!psFitsWriteTable (fits, outhead, table, extname)) { 608 psError(PS_ERR_IO, false, "writing ext data %s\n", extname);609 psFree (outhead);610 psFree(table);611 return false;611 psError(PS_ERR_IO, false, "writing ext data %s\n", extname); 612 psFree (outhead); 613 psFree(table); 614 return false; 612 615 } 613 616 psFree (outhead); … … 645 648 psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH); 646 649 psPlaneTransformApply (&ptTP_y, fpa->toTPA, &ptFP); 647 650 648 651 // the resulting Tangent Plane coordinates are in TP pixels; convert to local Tangent Plane 649 652 // degrees … … 671 674 *posAngle = NAN; 672 675 *pltScale = NAN; 673 676 674 677 return false; 675 678 }
Note:
See TracChangeset
for help on using the changeset viewer.
