Changeset 31153 for trunk/psModules/src/objects/pmSourceIO_CMF_PS1_DV2.c
- Timestamp:
- Apr 4, 2011, 1:04:41 PM (15 years ago)
- Location:
- trunk/psModules
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/objects/pmSourceIO_CMF_PS1_DV2.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules
- Property svn:ignore
-
old new 28 28 ChangeLog 29 29 psmodules-*.tar.* 30 a.out.dSYM
-
- Property svn:ignore
-
trunk/psModules/src/objects/pmSourceIO_CMF_PS1_DV2.c
r30621 r31153 49 49 50 50 #include "pmSourceIO.h" 51 #include "pmSourceOutputs.h" 51 52 52 53 // panstarrs-style FITS table output (header + table in 1st extension) … … 62 63 PS_ASSERT_PTR_NON_NULL(extname, false); 63 64 64 int i;65 65 psArray *table; 66 66 psMetadata *row; 67 psF32 *PAR, *dPAR;68 psEllipseAxes axes;69 psF32 xPos, yPos;70 psF32 xErr, yErr;71 psF32 chisq, apRadius;72 psS32 nPix, nDOF;73 67 74 68 pmChip *chip = readout->parent->parent; 75 pmFPA *fpa = chip->parent;76 77 bool status1 = false;78 bool status2 = false;79 float magOffset = NAN;80 float exptime = psMetadataLookupF32 (&status1, fpa->concepts, "FPA.EXPOSURE");81 float zeropt = psMetadataLookupF32(&status2, fpa->concepts, "FPA.ZP");82 if (!isfinite(zeropt)) {83 zeropt = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS");84 }85 if (status1 && status2 && (exptime > 0.0)) {86 magOffset = zeropt + 2.5*log10(exptime);87 }88 float zeroptErr = psMetadataLookupF32 (&status2, imageHeader, "ZPT_ERR");89 90 // we need a measure of the image quality (FWHM) for this image, in order to get the positional errors91 float fwhmMajor = psMetadataLookupF32(&status1, readout->analysis, "FWHM_MAJ");92 if (!status1) {93 fwhmMajor = psMetadataLookupF32(&status1, readout->analysis, "IQ_FW1");94 if (!status1) {95 fwhmMajor = 5.0; // XXX just a guess!96 }97 }98 float fwhmMinor = psMetadataLookupF32(&status1, readout->analysis, "FWHM_MIN");99 if (!status1) {100 fwhmMinor = psMetadataLookupF32(&status1, readout->analysis, "IQ_FW2");101 if (!status1) {102 fwhmMinor = 5.0; // XXX just a guess!103 }104 }105 69 106 70 // if the sequence is defined, write these in seq order; otherwise … … 110 74 if (source->seq == -1) { 111 75 // let's write these out in S/N order 112 sources = psArraySort (sources, pmSourceSortBy SN);76 sources = psArraySort (sources, pmSourceSortByFlux); 113 77 } else { 114 78 sources = psArraySort (sources, pmSourceSortBySeq); … … 118 82 table = psArrayAllocEmpty (sources->n); 119 83 84 short nImageOverlap; 85 float magOffset; 86 float zeroptErr; 87 float fwhmMajor; 88 float fwhmMinor; 89 pmSourceOutputsCommonValues (&nImageOverlap, &magOffset, &zeroptErr, &fwhmMajor, &fwhmMinor, readout, imageHeader); 90 120 91 // we write out PSF-fits for all sources, regardless of quality. the source flags tell us the state 121 92 // by the time we call this function, all values should be assigned. let's use asserts to be sure in some cases. 122 for (i = 0; i < sources->n; i++) {93 for (int i = 0; i < sources->n; i++) { 123 94 pmSource *source = (pmSource *) sources->data[i]; 124 95 … … 131 102 } 132 103 133 // no difference between PSF and non-PSF model 134 pmModel *model = source->modelPSF; 135 136 if (model != NULL) { 137 PAR = model->params->data.F32; 138 dPAR = model->dparams->data.F32; 139 xPos = PAR[PM_PAR_XPOS]; 140 yPos = PAR[PM_PAR_YPOS]; 141 if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) { 142 xErr = dPAR[PM_PAR_XPOS]; 143 yErr = dPAR[PM_PAR_YPOS]; 144 } else { 145 // in linear-fit mode, there is no error on the centroid 146 xErr = fwhmMajor * source->errMag / 2.35; 147 yErr = fwhmMinor * source->errMag / 2.35; 148 } 149 if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) { 150 axes = pmPSF_ModelToAxes (PAR, 20.0); 151 } else { 152 axes.major = NAN; 153 axes.minor = NAN; 154 axes.theta = NAN; 155 } 156 chisq = model->chisq; 157 nDOF = model->nDOF; 158 nPix = model->nPix; 159 apRadius = source->apRadius; 160 } else { 161 bool useMoments = true; 162 useMoments = (useMoments && source->moments); // can't if there are no moments 163 useMoments = (useMoments && source->moments->nPixels); // can't if the moments were not measured 164 useMoments = (useMoments && !(source->mode && PM_SOURCE_MODE_MOMENTS_FAILURE)); // can't if the moments failed... 165 166 if (useMoments) { 167 xPos = source->moments->Mx; 168 yPos = source->moments->My; 169 xErr = fwhmMajor * source->errMag / 2.35; 170 yErr = fwhmMinor * source->errMag / 2.35; 171 } else { 172 xPos = source->peak->xf; 173 yPos = source->peak->yf; 174 xErr = source->peak->dx; 175 yErr = source->peak->dy; 176 } 177 axes.major = NAN; 178 axes.minor = NAN; 179 axes.theta = NAN; 180 chisq = NAN; 181 nDOF = 0; 182 nPix = 0; 183 apRadius = NAN; 184 } 185 186 float calMag = isfinite(magOffset) ? source->psfMag + magOffset : NAN; 187 float peakMag = (source->peak->flux > 0) ? -2.5*log10(source->peak->flux) : NAN; 188 psS16 nImageOverlap = 1; 189 190 psSphere ptSky = {0.0, 0.0, 0.0, 0.0}; 191 float posAngle = 0.0; 192 float pltScale = 0.0; 193 pmSourceLocalAstrometry (&ptSky, &posAngle, &pltScale, chip, xPos, yPos); 104 // set the 'best' values for various output fields: 105 pmSourceOutputs outputs; 106 pmSourceOutputsSetValues (&outputs, source, chip, fwhmMajor, fwhmMinor, magOffset); 107 108 pmSourceOutputsMoments moments; 109 pmSourceOutputsSetMoments (&moments, source); 194 110 195 111 pmSourceDiffStats diffStats; … … 201 117 row = psMetadataAlloc (); 202 118 psMetadataAdd (row, PS_LIST_TAIL, "IPP_IDET", PS_DATA_U32, "IPP detection identifier index", source->seq); 203 psMetadataAdd (row, PS_LIST_TAIL, "X_PSF", PS_DATA_F32, "PSF x coordinate", xPos);204 psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF", PS_DATA_F32, "PSF y coordinate", yPos);205 psMetadataAdd (row, PS_LIST_TAIL, "X_PSF_SIG", PS_DATA_F32, "Sigma in PSF x coordinate", xErr); // XXX this is only measured for non-linear fits206 psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF_SIG", PS_DATA_F32, "Sigma in PSF y coordinate", yErr); // XXX this is only measured for non-linear fits207 psMetadataAdd (row, PS_LIST_TAIL, "POSANGLE", PS_DATA_F32, "position angle at source (degrees)", posAngle*PS_DEG_RAD);208 psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE", PS_DATA_F32, "plate scale at source (arcsec/pixel)", pltScale*PS_DEG_RAD*3600.0);119 psMetadataAdd (row, PS_LIST_TAIL, "X_PSF", PS_DATA_F32, "PSF x coordinate", outputs.xPos); 120 psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF", PS_DATA_F32, "PSF y coordinate", outputs.yPos); 121 psMetadataAdd (row, PS_LIST_TAIL, "X_PSF_SIG", PS_DATA_F32, "Sigma in PSF x coordinate", outputs.xErr); // XXX this is only measured for non-linear fits 122 psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF_SIG", PS_DATA_F32, "Sigma in PSF y coordinate", outputs.yErr); // XXX this is only measured for non-linear fits 123 psMetadataAdd (row, PS_LIST_TAIL, "POSANGLE", PS_DATA_F32, "position angle at source (degrees)", outputs.posAngle); 124 psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE", PS_DATA_F32, "plate scale at source (arcsec/pixel)", outputs.pltScale); 209 125 psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG", PS_DATA_F32, "PSF fit instrumental magnitude", source->psfMag); 210 126 psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude", source->errMag); … … 214 130 psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG", PS_DATA_F32, "magnitude in standard aperture", source->apMag); 215 131 psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RAW", PS_DATA_F32, "magnitude in real aperture", source->apMagRaw); 216 psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS", PS_DATA_F32, "radius used for aperture mags", apRadius);132 psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS", PS_DATA_F32, "radius used for aperture mags", outputs.apRadius); 217 133 psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX", PS_DATA_F32, "instrumental flux in standard aperture", source->apFlux); 218 134 psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX_SIG", PS_DATA_F32, "aperture flux error", source->apFluxErr); 219 135 220 psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude", peakMag);221 psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG", PS_DATA_F32, "PSF Magnitude using supplied calibration", calMag);136 psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude", outputs.peakMag); 137 psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG", PS_DATA_F32, "PSF Magnitude using supplied calibration", outputs.calMag); 222 138 psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG_SIG", PS_DATA_F32, "measured scatter of zero point calibration", zeroptErr); 223 psMetadataAdd (row, PS_LIST_TAIL, "RA_PSF", PS_DATA_F64, "PSF RA coordinate (degrees)", ptSky.r*PS_DEG_RAD);224 psMetadataAdd (row, PS_LIST_TAIL, "DEC_PSF", PS_DATA_F64, "PSF DEC coordinate (degrees)", ptSky.d*PS_DEG_RAD);139 psMetadataAdd (row, PS_LIST_TAIL, "RA_PSF", PS_DATA_F64, "PSF RA coordinate (degrees)", outputs.ra); 140 psMetadataAdd (row, PS_LIST_TAIL, "DEC_PSF", PS_DATA_F64, "PSF DEC coordinate (degrees)", outputs.dec); 225 141 psMetadataAdd (row, PS_LIST_TAIL, "SKY", PS_DATA_F32, "Sky level", source->sky); 226 142 psMetadataAdd (row, PS_LIST_TAIL, "SKY_SIGMA", PS_DATA_F32, "Sigma of sky level", source->skyErr); 227 143 228 psMetadataAdd (row, PS_LIST_TAIL, "PSF_CHISQ", PS_DATA_F32, "Chisq of PSF-fit", chisq);144 psMetadataAdd (row, PS_LIST_TAIL, "PSF_CHISQ", PS_DATA_F32, "Chisq of PSF-fit", outputs.chisq); 229 145 psMetadataAdd (row, PS_LIST_TAIL, "CR_NSIGMA", PS_DATA_F32, "Nsigma deviations from PSF to CF", source->crNsigma); 230 146 psMetadataAdd (row, PS_LIST_TAIL, "EXT_NSIGMA", PS_DATA_F32, "Nsigma deviations from PSF to EXT", source->extNsigma); 231 147 232 psMetadataAdd (row, PS_LIST_TAIL, "PSF_MAJOR", PS_DATA_F32, "PSF width (major axis)", axes.major);233 psMetadataAdd (row, PS_LIST_TAIL, "PSF_MINOR", PS_DATA_F32, "PSF width (minor axis)", axes.minor);234 psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA", PS_DATA_F32, "PSF orientation angle", axes.theta);148 psMetadataAdd (row, PS_LIST_TAIL, "PSF_MAJOR", PS_DATA_F32, "PSF width (major axis)", outputs.psfMajor); 149 psMetadataAdd (row, PS_LIST_TAIL, "PSF_MINOR", PS_DATA_F32, "PSF width (minor axis)", outputs.psfMinor); 150 psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA", PS_DATA_F32, "PSF orientation angle", outputs.psfTheta); 235 151 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor (bad)", source->pixWeightNotBad); 236 152 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF_PERFECT", PS_DATA_F32, "PSF coverage/quality factor (poor)", source->pixWeightNotPoor); 237 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NDOF", PS_DATA_S32, "degrees of freedom", nDOF); 238 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX", PS_DATA_S32, "number of pixels in fit", nPix); 239 240 // distinguish moments measure from window vs S/N > XX ?? 241 float mxx = source->moments ? source->moments->Mxx : NAN; 242 float mxy = source->moments ? source->moments->Mxy : NAN; 243 float myy = source->moments ? source->moments->Myy : NAN; 244 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX", PS_DATA_F32, "second moments (X^2)", mxx); 245 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY", PS_DATA_F32, "second moments (X*Y)", mxy); 246 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY", PS_DATA_F32, "second moments (Y*Y)", myy); 247 248 float Mrf = source->moments ? source->moments->Mrf : NAN; 249 float Mrh = source->moments ? source->moments->Mrh : NAN; 250 float Krf = source->moments ? source->moments->KronFlux : NAN; 251 float dKrf = source->moments ? source->moments->KronFluxErr : NAN; 252 253 float Kinner = source->moments ? source->moments->KronFinner : NAN; 254 float Kouter = source->moments ? source->moments->KronFouter : NAN; 255 256 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1", PS_DATA_F32, "first radial moment", Mrf); 257 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_RH", PS_DATA_F32, "half radial moment", Mrh); 258 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX", PS_DATA_F32, "Kron Flux (in 2.5 R1)", Krf); 259 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_ERR", PS_DATA_F32, "Kron Flux Error", dKrf); 260 261 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER", PS_DATA_F32, "Kron Flux (in 1.0 R1)", Kinner); 262 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER", PS_DATA_F32, "Kron Flux (in 4.0 R1)", Kouter); 263 264 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NPOS", PS_DATA_S32, "nPos (n pix > 3 sigma)", diffStats.nGood); 265 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_FRATIO", PS_DATA_F32, "fPos / (fPos + fNeg)", diffStats.fRatio); 266 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_BAD", PS_DATA_F32, "nPos / (nPos + nNeg)", diffStats.nRatioBad); 267 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_MASK", PS_DATA_F32, "nPos / (nPos + nMask)", diffStats.nRatioMask); 268 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_ALL", PS_DATA_F32, "nPos / (nGood + nMask + nBad)", diffStats.nRatioAll); 153 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NDOF", PS_DATA_S32, "degrees of freedom", outputs.nDOF); 154 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX", PS_DATA_S32, "number of pixels in fit", outputs.nPix); 155 156 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX", PS_DATA_F32, "second moments (X^2)", moments.Mxx); 157 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY", PS_DATA_F32, "second moments (X*Y)", moments.Mxy); 158 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY", PS_DATA_F32, "second moments (Y*Y)", moments.Myy); 159 160 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1", PS_DATA_F32, "first radial moment", moments.Mrf); 161 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_RH", PS_DATA_F32, "half radial moment", moments.Mrh); 162 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX", PS_DATA_F32, "Kron Flux (in 2.5 R1)", moments.Krf); 163 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_ERR", PS_DATA_F32, "Kron Flux Error", moments.dKrf); 164 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER", PS_DATA_F32, "Kron Flux (in 1.0 R1)", moments.Kinner); 165 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER", PS_DATA_F32, "Kron Flux (in 4.0 R1)", moments.Kouter); 166 167 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NPOS", PS_DATA_S32, "nPos (n pix > 3 sigma)", diffStats.nGood); 168 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_FRATIO", PS_DATA_F32, "fPos / (fPos + fNeg)", diffStats.fRatio); 169 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_BAD", PS_DATA_F32, "nPos / (nPos + nNeg)", diffStats.nRatioBad); 170 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_MASK", PS_DATA_F32, "nPos / (nPos + nMask)", diffStats.nRatioMask); 171 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_ALL", PS_DATA_F32, "nPos / (nGood + nMask + nBad)", diffStats.nRatioAll); 269 172 270 173 psMetadataAdd (row, PS_LIST_TAIL, "DIFF_R_P", PS_DATA_F32, "distance to positive match source", diffStats.Rp); … … 385 288 // recreate the peak to match (xPos, yPos) +/- (xErr, yErr) 386 289 source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE); 387 source->peak->flux = peakFlux; 290 source->peak->rawFlux = peakFlux; 291 source->peak->smoothFlux = peakFlux; 388 292 source->peak->xf = PAR[PM_PAR_XPOS]; // more accurate position 389 293 source->peak->yf = PAR[PM_PAR_YPOS]; // more accurate position 390 294 source->peak->dx = dPAR[PM_PAR_XPOS]; 391 295 source->peak->dy = dPAR[PM_PAR_YPOS]; 392 if (isfinite (source->errMag) && (source->errMag > 0.0)) {393 source->peak->SN = 1.0 / source->errMag;394 } else {395 source->peak->SN = sqrt(source->peak->flux); // an alternate proxy: various functions sort by peak S/N396 }397 296 398 297 source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF"); … … 408 307 409 308 source->moments = pmMomentsAlloc (); 309 source->moments->Mx = source->peak->xf; // we don't have both Mx,My and xf,yf in the cmf 310 source->moments->My = source->peak->yf; // we don't have both Mx,My and xf,yf in the cmf 311 410 312 source->moments->Mxx = psMetadataLookupF32 (&status, row, "MOMENTS_XX"); 411 313 source->moments->Mxy = psMetadataLookupF32 (&status, row, "MOMENTS_XY"); … … 456 358 457 359 // let's write these out in S/N order 458 sources = psArraySort (sources, pmSourceSortBy SN);360 sources = psArraySort (sources, pmSourceSortByFlux); 459 361 460 362 table = psArrayAllocEmpty (sources->n); … … 629 531 630 532 // let's write these out in S/N order 631 sources = psArraySort (sources, pmSourceSortBy SN);533 sources = psArraySort (sources, pmSourceSortByFlux); 632 534 633 535 // we are writing one row per model; we need to write out same number of columns for each row: find the max Nparams
Note:
See TracChangeset
for help on using the changeset viewer.
