Changeset 36198
- Timestamp:
- Oct 9, 2013, 4:14:19 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130904/psphot
- Files:
-
- 13 edited
-
. (modified) (1 prop)
-
src (modified) (1 prop)
-
src/psphot.h (modified) (1 diff)
-
src/psphotExtendedSourceAnalysis.c (modified) (11 diffs)
-
src/psphotExtendedSourceFits.c (modified) (3 diffs)
-
src/psphotMergeSources.c (modified) (2 diffs)
-
src/psphotPetrosianRadialBins.c (modified) (2 diffs)
-
src/psphotPetrosianStats.c (modified) (4 diffs)
-
src/psphotRadialProfile.c (modified) (7 diffs)
-
src/psphotSourceFits.c (modified) (1 diff)
-
src/psphotStackImageLoop.c (modified) (9 diffs, 1 prop)
-
src/psphotStackMatchPSFsNext.c (modified) (2 diffs)
-
src/psphotStackReadout.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130904/psphot
- Property svn:mergeinfo changed
/trunk/psphot (added) merged: 36096,36100,36107-36108,36115,36117-36119,36124,36128
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20130904/psphot/src
- Property svn:mergeinfo changed
/trunk/psphot/src merged: 36096,36100,36107-36108,36115,36117-36119,36124,36128
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20130904/psphot/src/psphot.h
r36148 r36198 479 479 bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc); 480 480 bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index); 481 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc );481 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc, bool sourcesSubtracted); 482 482 483 483 bool psphotSourceParents (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc); -
branches/eam_branches/ipp-20130904/psphot/src/psphotExtendedSourceAnalysis.c
r34404 r36198 1 1 # include "psphotInternal.h" 2 void psphotRadialProfileShowSkips (); 2 3 3 4 // measure the elliptical radial profile and use this to measure the petrosian parameters for the sources … … 33 34 } 34 35 36 /*** for the moment, this test code : it is not thread safe ***/ 37 int Nall = 0; 38 int Nskip1 = 0; 39 int Nskip2 = 0; 40 int Nskip3 = 0; 41 int Nskip4 = 0; 42 int Nskip5 = 0; 43 int Nskip6 = 0; 44 int Nskip7 = 0; 45 int Nskip8 = 0; 46 int Nskip9 = 0; 47 int Nskip10 = 0; 48 int Nskip11 = 0; 49 int Nskip12 = 0; 50 int Nskip13 = 0; 51 int Nskip14 = 0; 52 53 # define SKIP(VALUE) { VALUE++; continue; } 54 35 55 // aperture-like measurements for extended sources 36 56 bool psphotExtendedSourceAnalysisReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 37 57 38 58 bool status; 59 int NfaintEXT = 0; 60 int NfaintPSF = 0; 61 39 62 int Next = 0; 40 63 int Npetro = 0; … … 108 131 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npetro 109 132 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nannuli 133 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for NfaintEXT 134 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for NfaintPSF 110 135 111 136 // set this to 0 to run without threading 112 # if ( 1)137 # if (0) 113 138 if (!psThreadJobAddPending(job)) { 114 139 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); … … 129 154 scalar = job->args->data[7]; 130 155 Nannuli += scalar->data.S32; 156 scalar = job->args->data[8]; 157 NfaintEXT += scalar->data.S32; 158 scalar = job->args->data[9]; 159 NfaintPSF += scalar->data.S32; 131 160 psFree(job); 132 161 # endif … … 153 182 scalar = job->args->data[7]; 154 183 Nannuli += scalar->data.S32; 184 scalar = job->args->data[8]; 185 NfaintEXT += scalar->data.S32; 186 scalar = job->args->data[9]; 187 NfaintPSF += scalar->data.S32; 155 188 } 156 189 psFree(job); … … 163 196 psLogMsg ("psphot", PS_LOG_INFO, " %d petrosian\n", Npetro); 164 197 psLogMsg ("psphot", PS_LOG_INFO, " %d annuli\n", Nannuli); 198 psLogMsg ("psphot", PS_LOG_INFO, " skipped: %d EXT, %d PSF\n", NfaintEXT, NfaintPSF); 199 200 fprintf (stderr, "ext analysis skipped @ 1 : %d\n", Nskip1); 201 fprintf (stderr, "ext analysis skipped @ 2 : %d\n", Nskip2); 202 fprintf (stderr, "ext analysis skipped @ 3 : %d\n", Nskip3); 203 fprintf (stderr, "ext analysis skipped @ 4 : %d\n", Nskip4); 204 fprintf (stderr, "ext analysis skipped @ 5 : %d\n", Nskip5); 205 fprintf (stderr, "ext analysis skipped @ 6 : %d\n", Nskip6); 206 fprintf (stderr, "ext analysis skipped @ 7 : %d\n", Nskip7); 207 fprintf (stderr, "ext analysis skipped @ 8 : %d\n", Nskip8); 208 fprintf (stderr, "ext analysis skipped @ 9 : %d\n", Nskip9); 209 fprintf (stderr, "ext analysis skipped @ 10 : %d\n", Nskip10); 210 fprintf (stderr, "ext analysis skipped @ 11 : %d\n", Nskip11); 211 fprintf (stderr, "ext analysis skipped @ 12 : %d\n", Nskip12); 212 fprintf (stderr, "ext analysis skipped @ 13 : %d\n", Nskip13); 213 fprintf (stderr, "ext analysis skipped @ 14 : %d\n", Nskip14); 214 215 psphotRadialProfileShowSkips (); 165 216 166 217 psphotVisualShowResidualImage (readout, false); … … 177 228 178 229 bool status; 230 231 int NfaintEXT = 0; 232 int NfaintPSF = 0; 179 233 180 234 int Next = 0; … … 207 261 pmSource *source = sources->data[i]; 208 262 263 Nall ++; 264 209 265 // if we have checked the source validity on the basis of the object set, then 210 266 // we either skip these tests below or we skip the source completely 211 if (source->tmpFlags & PM_SOURCE_TMPF_PETRO_SKIP) continue;267 if (source->tmpFlags & PM_SOURCE_TMPF_PETRO_SKIP) SKIP (Nskip1); 212 268 if (source->tmpFlags & PM_SOURCE_TMPF_PETRO_KEEP) goto keepSource; 213 269 214 270 // skip PSF-like and non-astronomical objects 215 if (source->type == PM_SOURCE_TYPE_DEFECT) continue;216 if (source->type == PM_SOURCE_TYPE_SATURATED) continue;217 if (source->mode & PM_SOURCE_MODE_DEFECT) continue;218 if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;271 if (source->type == PM_SOURCE_TYPE_DEFECT) SKIP (Nskip2); 272 if (source->type == PM_SOURCE_TYPE_SATURATED) SKIP (Nskip3); 273 if (source->mode & PM_SOURCE_MODE_DEFECT) SKIP (Nskip4); 274 if (source->mode & PM_SOURCE_MODE_SATSTAR) SKIP (Nskip5); 219 275 220 276 // skip saturated stars modeled with a radial profile 221 if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;277 if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) SKIP (Nskip6); 222 278 223 279 // optionally allow non-extended objects to get petrosians as well 224 280 if (!doPetroStars) { 225 if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) continue;226 if (source->type == PM_SOURCE_TYPE_STAR) continue;281 if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) SKIP (Nskip7); 282 // if (source->type == PM_SOURCE_TYPE_STAR) SKIP (Nskip8); -- XXX this might be set for input lists (instead of EXT_LIMIT) 227 283 } 228 284 … … 233 289 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 234 290 skipSource = (source->moments->KronFlux < SN_LIM * source->moments->KronFluxErr); 291 NfaintEXT ++; 235 292 } else { 236 293 skipSource = (sqrt(source->peak->detValue) < SN_LIM); 237 } 238 if (skipSource) continue; 294 NfaintPSF ++; 295 } 296 if (skipSource) SKIP (Nskip9); 239 297 240 298 // limit selection by analysis region (this automatically apply 241 if (source->peak->x < region->x0) continue;242 if (source->peak->y < region->y0) continue;243 if (source->peak->x > region->x1) continue;244 if (source->peak->y > region->y1) continue;299 if (source->peak->x < region->x0) SKIP (Nskip10); 300 if (source->peak->y < region->y0) SKIP (Nskip11); 301 if (source->peak->x > region->x1) SKIP (Nskip12); 302 if (source->peak->y > region->y1) SKIP (Nskip13); 245 303 246 304 keepSource: … … 266 324 psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 267 325 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 268 continue;326 SKIP (Nskip14); 269 327 } 270 328 Nannuli ++; … … 304 362 scalar->data.S32 = Nannuli; 305 363 364 scalar = job->args->data[8]; 365 scalar->data.S32 = NfaintEXT; 366 367 scalar = job->args->data[9]; 368 scalar->data.S32 = NfaintPSF; 369 306 370 return true; 307 371 } -
branches/eam_branches/ipp-20130904/psphot/src/psphotExtendedSourceFits.c
r36086 r36198 475 475 } 476 476 477 bool testObject = false; 478 // testObject |= ((fabs(source->peak->xf - 179) < 5) && (fabs(source->peak->yf - 1138) < 5)); 479 // testObject |= ((fabs(source->peak->xf - 5047) < 5) && (fabs(source->peak->yf - 151) < 5)); 480 // testObject |= ((fabs(source->peak->xf - 3929) < 5) && (fabs(source->peak->yf - 4109) < 5)); 481 // testObject |= ((fabs(source->peak->xf - 915) < 5) && (fabs(source->peak->yf - 5998) < 5)); 482 // testObject |= ((fabs(source->peak->xf - 5406) < 5) && (fabs(source->peak->yf - 326) < 5)); 483 if (testObject) { 484 fprintf (stderr, "test object @ %f, %f\n", source->peak->xf, source->peak->yf); 485 psTraceSetLevel ("psModules.objects.pmPCM_MinimizeChisq", 5); 486 psTraceSetLevel ("psphot.psphotExtendedSourceFits_Threaded", 5); 487 } 488 477 489 // loop here over the models chosen for each source (exclude by S/N) 478 490 // Reset the iterator … … 531 543 psFree (source->modelFlux); 532 544 source->modelFlux = NULL; 533 // if ((fabs(source->peak->xf - 2572) < 20) && (fabs(source->peak->yf - 5874) < 20)) {534 // fprintf (stderr, "test object\n");535 // }536 537 545 modelFit = psphotFitEXT (modelFit, readout, source, fitOptions, modelType, maskVal, markVal); 538 546 if (!modelFit) { … … 646 654 psTrace ("psphot", 4, "best ext model for %f, %f : %s chisq = %f\n", source->moments->Mx, source->moments->My, pmModelClassGetName (source->modelEXT->type), source->modelEXT->chisq); 647 655 psTrace ("psphot", 5, "extended source model for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 656 657 if (testObject) { 658 psTraceSetLevel ("psModules.objects.pmPCM_MinimizeChisq", 0); 659 psTraceSetLevel ("psphot.psphotExtendedSourceFits_Threaded", 0); 660 } 648 661 } 649 662 -
branches/eam_branches/ipp-20130904/psphot/src/psphotMergeSources.c
r36161 r36198 844 844 // array containing the child sources. XXX currently, this is only used by psphotStackReadout 845 845 // (sources go on allSources so that psphotChoosePSF can be called repeatedly) 846 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc ) {846 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc, bool sourcesSubtracted) { 847 847 848 848 bool status; … … 951 951 // child sources have not been subtracted in this image, but this flag may be raised if 952 952 // they were subtracted in the parent's image 953 sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 953 // XXX NOTE : in the pre-20130914 version of psphotStack, we carried a copy of the pixels 954 // generated before the subtraction took place (and then we smoothed to match the desired PSF). 955 // in the new version, we copy the image after subtraction; we need to distinguish these cases 956 if (!sourcesSubtracted) { 957 sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 958 } 954 959 955 960 // set the output detections: -
branches/eam_branches/ipp-20130904/psphot/src/psphotPetrosianRadialBins.c
r31154 r36198 36 36 pmSourceRadialProfile *profile = source->extpars->petProfile; 37 37 38 float skyModelErrorSQ = PS_SQR(skynoise);38 // float skyModelErrorSQ = PS_SQR(skynoise); 39 39 40 40 int nMax = radiusMax; … … 133 133 if (radius->data.F32[i] > Rmax) { 134 134 // calculate the value for the nOut bin 135 float value , dvalue;135 float value; // , dvalue; 136 136 if (values->n > 0) { 137 137 psVectorStats (stats, values, NULL, NULL, 0); 138 138 value = stats->robustMedian; 139 dvalue = stats->robustStdev;139 // dvalue = stats->robustStdev; 140 140 } else { 141 141 value = NAN; 142 dvalue = NAN;142 // dvalue = NAN; 143 143 } 144 144 145 145 binSB->data.F32[nOut] = value; 146 binSBstdev->data.F32[nOut] = sqrt(PS_SQR(dvalue) / values->n + skyModelErrorSQ); 146 // binSBstdev->data.F32[nOut] = sqrt(PS_SQR(dvalue) / values->n + skyModelErrorSQ); 147 binSBstdev->data.F32[nOut] = skynoise / sqrt(values->n); 147 148 binFill->data.F32[nOut] = values->n / binArea->data.F32[nOut]; 148 149 -
branches/eam_branches/ipp-20130904/psphot/src/psphotPetrosianStats.c
r34086 r36198 6 6 // generate the Petrosian radius and flux from the mean surface brightness (r_i) 7 7 8 float InterpolateValuesQuadratic (float *Xin, float *Yin, float X); 8 9 float InterpolateValues (float X0, float Y0, float X1, float Y1, float X); 9 10 float InterpolateValuesErrX (float X0, float Y0, float X1, float Y1, float X, float dX0, float dX1); … … 53 54 float dFsum2 = 0.0; 54 55 55 float nSigma = 3.0;56 float nSigma = 2.0; 56 57 int lowestSignificantRadius = 0; 57 58 float lowestSignificantRatio = 1.0; … … 118 119 petRadiusErr = InterpolateValuesErrX (1.0, 0.0, petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO, 0.0, petRatioErr->data.F32[nOut]); 119 120 } else { 120 petRadius = InterpolateValues (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO); 121 petRadiusErr = InterpolateValuesErrX (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO, petRatioErr->data.F32[nOut-1], petRatioErr->data.F32[nOut]); 121 // petRadius = InterpolateValues (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO); 122 if (nOut > 1) { 123 petRadius = InterpolateValuesQuadratic (&petRatio->data.F32[nOut-2], &refRadius->data.F32[nOut-2], PETROSIAN_RATIO); 124 } else { 125 petRadius = InterpolateValuesQuadratic (&petRatio->data.F32[nOut-3], &refRadius->data.F32[nOut-3], PETROSIAN_RATIO); 126 } 127 float petRadiusLinear = InterpolateValues (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO); 128 if (fabs(petRadius - petRadiusLinear) > fabs(refRadius->data.F32[nOut] - refRadius->data.F32[nOut-1])) { 129 fprintf (stderr, "big difference : %f vs %f\n", petRadius, petRadiusLinear); 130 } 131 petRadiusErr = InterpolateValuesErrX (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO, petRatioErr->data.F32[nOut-1], petRatioErr->data.F32[nOut]); 122 132 } 123 133 above = false; … … 235 245 } 236 246 247 // Lagrange's form of the interpolating polynomial... 248 float InterpolateValuesQuadratic (float *Xin, float *Yin, float X) { 249 250 float dx01 = Xin[0] - Xin[1]; 251 float dx02 = Xin[0] - Xin[2]; 252 float dx12 = Xin[1] - Xin[2]; 253 254 float dx0 = X - Xin[0]; 255 float dx1 = X - Xin[1]; 256 float dx2 = X - Xin[2]; 257 258 float y0 = Yin[0]*dx1*dx2/(dx01*dx02); 259 float y1 = Yin[1]*dx0*dx2/(dx01*dx12); // need - sign 260 float y2 = Yin[2]*dx0*dx1/(dx02*dx12); 261 262 float Y = y0 - y1 + y2; 263 return Y; 264 } 265 237 266 float InterpolateValues (float X0, float Y0, float X1, float Y1, float X) { 238 267 float dydx = (Y1 - Y0) / (X1 - X0); -
branches/eam_branches/ipp-20130904/psphot/src/psphotRadialProfile.c
r32348 r36198 1 1 # include "psphotInternal.h" 2 3 static int Nskip1 = 0; 4 static int Nskip2 = 0; 5 static int Nskip3 = 0; 6 static int Nskip4 = 0; 7 static int Nskip5 = 0; 8 9 # define SKIP(VALUE) { VALUE++; return false; } 2 10 3 11 bool psphotRadialProfile (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal) { … … 23 31 if (!psphotRadialProfilesByAngles (source, Nsec, Rmax)) { 24 32 psError (PS_ERR_UNKNOWN, false, "failed to measure radial profile for petrosian"); 25 return false;33 SKIP (Nskip1); 26 34 } 27 35 // allocate: extpars->radFlux->radii,fluxes,theta … … 32 40 if (!psphotRadiiFromProfiles (source, fluxMin, fluxMax)) { 33 41 psError (PS_ERR_UNKNOWN, false, "failed to measure isophotal radii from profiles"); 34 return false;42 SKIP (Nskip2); 35 43 } 36 44 // allocate : extpars->radFlux->isophotalRadii (use profile->radii,fluxes) … … 40 48 if (!psphotEllipticalContour (source)) { 41 49 // psLogMsg ("psphot", 3, "failed to measure elliptical contour"); 42 return false;50 SKIP (Nskip3); 43 51 } 44 52 // use extpars->radFlux->isophotalRadii,theta (result in extpars->axes) … … 48 56 if (!psphotEllipticalProfile (source, RAW_RADIUS)) { 49 57 psError (PS_ERR_UNKNOWN, false, "failed to generate elliptical profile"); 50 return false;58 SKIP (Nskip4); 51 59 } 52 60 // allocate extpars->ellipticalFlux->radiusElliptical,fluxElliptical (use axes to scale raw pixels) … … 55 63 if (!psphotRadialBins (recipe, source, Rmax, skynoise)) { 56 64 psError (PS_ERR_UNKNOWN, false, "failed to generate radial bins"); 57 return false;65 SKIP (Nskip5); 58 66 } 59 67 // allocate extpars->radProfile->binSB, binSBstdv, binSum, binFill, radialBins, area (small lengths) … … 62 70 return true; 63 71 } 72 73 void psphotRadialProfileShowSkips () { 74 75 fprintf (stderr, "radial profile skipped @ 1 : %d\n", Nskip1); 76 fprintf (stderr, "radial profile skipped @ 2 : %d\n", Nskip2); 77 fprintf (stderr, "radial profile skipped @ 3 : %d\n", Nskip3); 78 fprintf (stderr, "radial profile skipped @ 4 : %d\n", Nskip4); 79 fprintf (stderr, "radial profile skipped @ 5 : %d\n", Nskip5); 80 } -
branches/eam_branches/ipp-20130904/psphot/src/psphotSourceFits.c
r36086 r36198 589 589 if (TIMING) { psTimerStart ("psphotFitPCM"); } 590 590 591 // if we are ever (in a given psphot implementation) going to fit a parameter, we must set the options here to include 592 // that parameter (otherwise pmPCMupdate will fail to allocate the dmodelFlux image) 593 // thus, if the sersic analysis below uses an index fit, need to use this EXT_AND_SKY mode for init 594 595 options.mode = PM_SOURCE_FIT_EXT; 591 596 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { 592 options.mode = PM_SOURCE_FIT_NO_INDEX; // XXX note that there may be a conflict with psphotExtendedSourceFits.c:133593 597 options.mode = PM_SOURCE_FIT_EXT_AND_SKY; 594 // if we are ever (in a given psphot implementation) going to fit a parameter, we must set the options here to include 595 // that parameter (otherwise pmPCMupdate will fail to allocate the dmodelFlux image) 596 // thus, if the sersic analysis below uses an index fit, need to use this EXT_AND_SKY mode for init 597 } else { 598 } 599 if (modelType == pmModelClassGetType("PS_MODEL_DEV")) { 600 options.mode = PM_SOURCE_FIT_SHAPE; 601 options.mode = PM_SOURCE_FIT_EXT_AND_SKY; 602 } 603 if (modelType == pmModelClassGetType("PS_MODEL_EXP")) { 598 604 options.mode = PM_SOURCE_FIT_EXT_AND_SKY; 599 605 } -
branches/eam_branches/ipp-20130904/psphot/src/psphotStackImageLoop.c
- Property svn:mergeinfo changed
/trunk/psphot/src/psphotStackImageLoop.c merged: 36119
r36086 r36198 22 22 23 23 pmFPAview *view = pmFPAviewAlloc (0); 24 pmFPAfile *inputRaw = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.RAW"); 25 pmFPAfile *inputCnv = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.CNV"); 26 pmFPAfile *input = inputRaw ? inputRaw : inputCnv; 24 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.RAW"); 27 25 28 26 if (!input) { … … 32 30 33 31 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE); 34 bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW");35 if (useRaw && inputRaw == NULL) {36 psLogMsg ("psphot", 1, "PSPHOT.STACK.USE.RAW set but no raw input.");37 useRaw = false;38 }39 40 bool radial_apertures = psMetadataLookupBool(NULL, recipe, "RADIAL_APERTURES");41 bool match_psfs = radial_apertures;42 bool needConvolved = radial_apertures || !useRaw;43 if (!needConvolved) {44 pmFPAfileActivate (config->files, false, "PSPHOT.STACK.INPUT.CNV");45 pmFPAfileActivate (config->files, false, "PSPHOT.STACK.MASK.CNV");46 pmFPAfileActivate (config->files, false, "PSPHOT.STACK.VARIANCE.CNV");47 pmFPAfileActivate (config->files, false, "PSPHOT.STACK.PSF.CNV");48 }49 32 50 33 // just load the full set of images up front except for EXPNUM which we defer 51 34 pmFPAfileActivate (config->files, false, "PSPHOT.STACK.EXPNUM.RAW"); 52 pmFPAfileActivate (config->files, false, "PSPHOT.STACK.EXPNUM.CNV");53 35 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot."); 54 36 … … 71 53 psMemDump("load"); 72 54 73 if (match_psfs) { 74 // Generate the 1st PSF-matched image set (larger target PSFs are generated by smoothing this image) 75 if (!psphotStackMatchPSFs (config, view)) { 76 psError(psErrorCodeLast(), false, "failure in psphotStackMatchPSFs for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout); 77 psFree (view); 78 return false; 79 } 80 } else { 81 if (!psphotStackAllocateOutput (config, view, recipe)) { 82 psError(psErrorCodeLast(), false, "failure in psphotStackAllocateOutput for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout); 83 psFree (view); 84 return false; 85 } 55 if (!psphotStackAllocateOutput (config, view, recipe)) { 56 psError(psErrorCodeLast(), false, "failure in psphotStackAllocateOutput for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout); 57 psFree (view); 58 return false; 86 59 } 87 60 psMemDump("stackmatch"); … … 126 99 127 100 // Load the appropriate EXPNUM image 128 pmFPAfileActivate (config->files, true, useRaw ? "PSPHOT.STACK.EXPNUM.RAW" : "PSPHOT.STACK.EXPNUM.CNV");101 pmFPAfileActivate (config->files, true, "PSPHOT.STACK.EXPNUM.RAW"); 129 102 130 103 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa EXPNUM in psphot."); … … 146 119 if (! readout->data_exists) { continue; } 147 120 148 if (!psphotSetNFrames (config, view, useRaw ? inputRaw->name : inputCnv->name)) ESCAPE ("failed to setNFrames.");121 if (!psphotSetNFrames (config, view, input->name)) ESCAPE ("failed to setNFrames."); 149 122 } 150 123 } … … 167 140 bool UpdateHeadersForReadout (pmConfig *config, pmFPAview *view) { 168 141 169 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);170 bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW");171 172 142 int num = psphotFileruleCount(config, "PSPHOT.INPUT"); 173 143 … … 179 149 psAssert (output, "missing file?"); 180 150 181 pmFPAfile *inputRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest 182 pmFPAfile *inputCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", i); // File of interest 183 pmFPAfile *input = useRaw ? inputRaw : inputCnv; 151 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest 184 152 psAssert (input, "missing input file"); 185 153 … … 205 173 psAssert (output, "missing file?"); 206 174 207 pmFPAfile *inputRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest 208 pmFPAfile *inputCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", i); // File of interest 209 pmFPAfile *input = inputRaw ? inputRaw : inputCnv; 175 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest 210 176 psAssert (input, "missing input file"); 211 177 … … 242 208 psAssert (output, "missing file?"); 243 209 244 pmFPAfile *inputRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest 245 pmFPAfile *inputCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", i); // File of interest 246 pmFPAfile *input = inputRaw ? inputRaw : inputCnv; 210 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest 247 211 psAssert (input, "missing input file"); 248 212 - Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20130904/psphot/src/psphotStackMatchPSFsNext.c
r34317 r36198 43 43 for (int i = 0; i < num; i++) { 44 44 if (!psphotStackMatchPSFsNextReadout (config, view, filerule, i, lastSize)) { 45 psError (PSPHOT_ERR_CONFIG, false, "failed to smooth image %s (%d) to target PSF", filerule, i);45 psLogMsg ("psphot", PS_LOG_INFO, "failed to smooth image %s (%d) to target PSF", filerule, i); 46 46 psImageConvolveSetThreads(oldThreads); 47 47 return false; … … 102 102 103 103 if (targetFWHM <= currentFWHM) { 104 psError (PSPHOT_ERR_CONFIG, true, "target FWHM cannot be smaller than current FWHM"); 104 // psError (PSPHOT_ERR_CONFIG, true, "target FWHM cannot be smaller than current FWHM"); 105 psLogMsg ("psphot", PS_LOG_INFO, "target FWHM (%f) is smaller than current FWHM (%f), not smoothing\n", targetFWHM, currentFWHM); 106 fwhmValues->data.F32[lastSize + 1] = currentFWHM; 105 107 return false; 106 108 } -
branches/eam_branches/ipp-20130904/psphot/src/psphotStackReadout.c
r34721 r36198 1 1 # include "psphotInternal.h" 2 2 3 static bool psphotStackMatchPSFsetup (pmConfig *config, const pmFPAview *view, const char *filerule, const char *fPSF); 4 static bool psphotStackMatchPSFsetupReadout (pmConfig *config, const pmFPAview *view, const char *filerule, const char *fPSF, int index); 3 5 static bool psphotStackLoadWCS(pmConfig *config, const pmFPAview *view, const char *filerule); 4 6 static void logMemStats(const char *heading); 5 7 6 // we have 3 possible realfilesets:8 // relevant filesets: 7 9 # define STACK_RAW "PSPHOT.STACK.INPUT.RAW" 8 # define STACK_CNV "PSPHOT.STACK.INPUT.CNV" 9 # define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE" /* the psf-matched image */ 10 11 // we have 3 files on which we operate: 12 // DET (detection image) : nominally RAW (optionally CNV?) 13 // SRC (source analysis image) : nominally CNV (optionally RAW) 14 // OUT (psf-matched images) : always OUT 10 # define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE" 11 12 // XXX STACK_OUT currently is a copy of STACK_RAW, but should be a pointer to is as in psphot (single) 13 14 // TEST CODE, can be removed 15 bool psphotDumpImages (pmConfig *config, const pmFPAview *view, const char *filerule, char *base) { 16 17 // XXX do nothing 18 return true; 19 20 int num = psphotFileruleCount(config, "PSPHOT.INPUT"); 21 22 for (int i = 0; i < num; i++) { 23 // find the currently selected readout 24 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest 25 psAssert (file, "missing file?"); 26 27 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 28 psAssert (readout, "missing readout?"); 29 30 char line[256]; 31 snprintf (line, 256, "%s.%d.im.fits", base, i); 32 psphotSaveImage (NULL, readout->image, line); 33 34 snprintf (line, 256, "%s.%d.wt.fits", base, i); 35 psphotSaveImage (NULL, readout->variance, line); 36 37 snprintf (line, 256, "%s.%d.mk.fits", base, i); 38 psphotSaveImage (NULL, readout->mask, line); 39 } 40 return true; 41 } 15 42 16 43 bool psphotStackVisualFilerule(pmConfig *config, const pmFPAview *view, const char *filerule) { … … 67 94 psAssert (breakPt, "configuration error: set BREAK_POINT"); 68 95 69 // we have 3 relevant files: RAW (unconvolved), CNV (convolved stack), OUT (psf-matched stack)70 // select which image (RAW or CNV) is used for analysis (RAW always used for detection)71 bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW");72 char *STACK_SRC = useRaw ? STACK_RAW : STACK_CNV;73 char *STACK_DET = STACK_RAW;74 75 96 // load WCS 76 if (!psphotStackLoadWCS(config, view, STACK_ SRC)) {77 psError (PSPHOT_ERR_CONFIG, false, "trouble loading WCS for %s", STACK_ SRC);97 if (!psphotStackLoadWCS(config, view, STACK_RAW)) { 98 psError (PSPHOT_ERR_CONFIG, false, "trouble loading WCS for %s", STACK_RAW); 78 99 return false; 79 100 } 80 101 81 102 // set the photcode for each image 82 if (!psphotAddPhotcode (config, view, STACK_ SRC)) {103 if (!psphotAddPhotcode (config, view, STACK_RAW)) { 83 104 psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode"); 84 105 return false; … … 86 107 87 108 // Generate the mask and weight images (if not supplied) and set mask bits. 88 // This also insures that all invalid pixels are masked (this is done for STACK_CNV in psphotStackMatchPSFs) 89 if (!psphotSetMaskAndVariance (config, view, STACK_DET)) { 90 return psphotReadoutCleanup (config, view, STACK_SRC); 91 } 92 if (!psphotSetMaskAndVariance (config, view, STACK_OUT)) { 93 return psphotReadoutCleanup (config, view, STACK_SRC); 109 if (!psphotSetMaskAndVariance (config, view, STACK_RAW)) { 110 return psphotReadoutCleanup (config, view, STACK_RAW); 94 111 } 95 112 if (!strcasecmp (breakPt, "NOTHING")) { 96 return psphotReadoutCleanup (config, view, STACK_ SRC);113 return psphotReadoutCleanup (config, view, STACK_RAW); 97 114 } 98 115 99 116 // generate a background model (median, smoothed image) 100 if (!psphotModelBackground (config, view, STACK_DET)) { 101 return psphotReadoutCleanup (config, view, STACK_SRC); 102 } 103 if (!psphotSubtractBackground (config, view, STACK_DET)) { 104 return psphotReadoutCleanup (config, view, STACK_SRC); 105 } 106 if (strcmp(STACK_SRC, STACK_DET)) { 107 #define MODEL_BACKGROUND_SRC 1 108 #ifdef MODEL_BACKGROUND_SRC 109 // work around the fact that the background levels on the convolved 110 // and unconvolved stacks can be different 111 if (!psphotModelBackground (config, view, STACK_SRC)) { 112 return psphotReadoutCleanup (config, view, STACK_SRC); 113 } 114 #endif 115 if (!psphotSubtractBackground (config, view, STACK_SRC)) { 116 return psphotReadoutCleanup (config, view, STACK_SRC); 117 } 117 if (!psphotModelBackground (config, view, STACK_RAW)) { 118 return psphotReadoutCleanup (config, view, STACK_RAW); 119 } 120 if (!psphotSubtractBackground (config, view, STACK_RAW)) { 121 return psphotReadoutCleanup (config, view, STACK_RAW); 118 122 } 119 123 if (!strcasecmp (breakPt, "BACKMDL")) { 120 return psphotReadoutCleanup (config, view, STACK_SRC); 121 } 124 return psphotReadoutCleanup (config, view, STACK_RAW); 125 } 126 127 // XXX TEST for background: 128 if (!psphotModelBackground (config, view, STACK_RAW)) { 129 return psphotReadoutCleanup (config, view, STACK_RAW); 130 } 131 if (!psphotSubtractBackground (config, view, STACK_RAW)) { 132 return psphotReadoutCleanup (config, view, STACK_RAW); 133 } 134 if (!psphotModelBackground (config, view, STACK_RAW)) { 135 return psphotReadoutCleanup (config, view, STACK_RAW); 136 } 137 if (!psphotSubtractBackground (config, view, STACK_RAW)) { 138 return psphotReadoutCleanup (config, view, STACK_RAW); 139 } 140 // XXX TEST END 122 141 123 142 #ifdef MAKE_CHISQ_IMAGE 124 143 // also make the chisq detection image 125 if (!psphotStackChisqImage(config, view, STACK_ DET, STACK_SRC)) {144 if (!psphotStackChisqImage(config, view, STACK_RAW, STACK_RAW)) { 126 145 psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image"); 127 return psphotReadoutCleanup (config, view, STACK_SRC); 146 return psphotReadoutCleanup (config, view, STACK_RAW); 147 } 148 if (!strcasecmp (breakPt, "CHISQ")) { 149 return psphotReadoutCleanup (config, view, STACK_RAW); 128 150 } 129 151 #endif 130 if (!strcasecmp (breakPt, "CHISQ")) {131 return psphotReadoutCleanup (config, view, STACK_SRC);132 }133 152 134 153 // find the detections (by peak and/or footprint) in the image. 135 154 // This finds the detections on Chisq image as well as the individuals 136 if (!psphotFindDetections (config, view, STACK_DET, true)) { // pass 1 137 // this only happens if we had an error in psphotFindDetections 155 if (!psphotFindDetections (config, view, STACK_RAW, true)) { // pass 1 138 156 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 139 return psphotReadoutCleanup (config, view, STACK_SRC); 140 } 141 142 // If DET and SRC are different images, copy the detections from DET to SRC. This 'copy' 143 // is just a copy of the container pointer; the sources on both DET and SRC are the same 144 // memory objects 145 if (strcmp(STACK_SRC, STACK_DET)) { 146 if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) { 147 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 148 return psphotReadoutCleanup (config, view, STACK_SRC); 149 } 157 return psphotReadoutCleanup (config, view, STACK_RAW); 150 158 } 151 159 152 160 // construct sources and measure basic stats (saved on detections->newSources) 153 if (!psphotSourceStats (config, view, STACK_ SRC, true)) { // pass 1161 if (!psphotSourceStats (config, view, STACK_RAW, true)) { // pass 1 154 162 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 155 return psphotReadoutCleanup (config, view, STACK_ SRC);163 return psphotReadoutCleanup (config, view, STACK_RAW); 156 164 } 157 165 if (!strcasecmp (breakPt, "PEAKS")) { 158 return psphotReadoutCleanup (config, view, STACK_ SRC);159 } 160 // psphotDumpTest (config, view, STACK_ SRC);166 return psphotReadoutCleanup (config, view, STACK_RAW); 167 } 168 // psphotDumpTest (config, view, STACK_RAW); 161 169 psMemDump("sourcestats"); 162 170 logMemStats("sourcestats"); … … 164 172 // classify sources based on moments, brightness 165 173 // only run this on detections from the input images, not chisq image 166 if (!psphotRoughClass (config, view, STACK_ SRC)) {174 if (!psphotRoughClass (config, view, STACK_RAW)) { 167 175 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 168 return psphotReadoutCleanup (config, view, STACK_SRC); 169 } 170 171 // If DET and SRC are different images, subtract radial profiles for the convolved 172 // image first. The profiles found on the convolved image will be replaced by those 173 // found for the unconvolved image. Downstream, in psphotFindDetections, we will 174 // replace the the profiles (and re-subtract them) for the detection image, so we want 175 // to keep those versions of the profiles on the sources. 176 if (strcmp(STACK_SRC, STACK_DET)) { 177 // find and subtract radial profile models for saturated stars (XXX change name eventually) 178 if (!psphotDeblendSatstars (config, view, STACK_SRC)) { 176 return psphotReadoutCleanup (config, view, STACK_RAW); 177 } 178 179 // find and subtract radial profile models for saturated stars (XXX change name eventually) 180 if (!psphotDeblendSatstars (config, view, STACK_RAW)) { 179 181 psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 180 return psphotReadoutCleanup (config, view, STACK_SRC); 181 } 182 } 183 // find and subtract radial profile models for saturated stars (XXX change name eventually) 184 if (!psphotDeblendSatstars (config, view, STACK_DET)) { 185 psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 186 return psphotReadoutCleanup (config, view, STACK_SRC); 182 return psphotReadoutCleanup (config, view, STACK_RAW); 187 183 } 188 184 189 185 // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources) 190 186 // only run this on detections from the input images, not chisq image 191 if (!psphotImageQuality (config, view, STACK_ SRC)) { // pass 1187 if (!psphotImageQuality (config, view, STACK_RAW)) { // pass 1 192 188 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); 193 return psphotReadoutCleanup (config, view, STACK_ SRC);189 return psphotReadoutCleanup (config, view, STACK_RAW); 194 190 } 195 191 if (!strcasecmp (breakPt, "MOMENTS")) { 196 return psphotReadoutCleanup (config, view, STACK_ SRC);192 return psphotReadoutCleanup (config, view, STACK_RAW); 197 193 } 198 194 199 195 // use bright stellar objects to measure PSF 200 if (!psphotChoosePSF (config, view, STACK_ SRC, true)) { // pass 1196 if (!psphotChoosePSF (config, view, STACK_RAW, true)) { // pass 1 201 197 psLogMsg ("psphot", 3, "failure to construct a psf model"); 202 return psphotReadoutCleanup (config, view, STACK_ SRC);198 return psphotReadoutCleanup (config, view, STACK_RAW); 203 199 } 204 200 if (!strcasecmp (breakPt, "PSFMODEL")) { 205 return psphotReadoutCleanup (config, view, STACK_ SRC);201 return psphotReadoutCleanup (config, view, STACK_RAW); 206 202 } 207 203 208 204 // merge the newly selected sources into the existing list 209 205 // NOTE: merge OLD and NEW 210 psphotMergeSources (config, view, STACK_ SRC);206 psphotMergeSources (config, view, STACK_RAW); 211 207 212 208 // Construct an initial model for each object, set the radius to fitRadius, set circular 213 209 // fit mask. NOTE: only applied to sources without guess models 214 psphotGuessModels (config, view, STACK_ SRC);210 psphotGuessModels (config, view, STACK_RAW); 215 211 216 212 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 217 psphotFitSourcesLinear (config, view, STACK_ SRC, false, false);218 psphotStackVisualFilerule(config, view, STACK_ SRC);213 psphotFitSourcesLinear (config, view, STACK_RAW, false, false); 214 psphotStackVisualFilerule(config, view, STACK_RAW); 219 215 220 216 // measure the radial profiles to the sky 221 psphotRadialProfileWings (config, view, STACK_ SRC);217 psphotRadialProfileWings (config, view, STACK_RAW); 222 218 223 219 // re-measure the kron mags with models subtracted. this pass starts with a circular … … 225 221 // but iterates to an appropriately larger size 226 222 logMemStats("before.kron.1"); 227 psphotKronIterate(config, view, STACK_ SRC, 1);223 psphotKronIterate(config, view, STACK_RAW, 1); 228 224 logMemStats("after.kron.1"); 229 225 230 226 // identify CRs and extended sources 231 psphotSourceSize (config, view, STACK_ SRC, true);227 psphotSourceSize (config, view, STACK_RAW, true); 232 228 233 229 // non-linear PSF and EXT fit to brighter sources 234 230 // replace model flux, adjust mask as needed, fit, subtract the models (full stamp) 235 psphotBlendFit (config, view, STACK_ SRC); // pass 1 (detections->allSources)231 psphotBlendFit (config, view, STACK_RAW); // pass 1 (detections->allSources) 236 232 237 233 // replace all sources (do NOT ignore subtraction state) 238 psphotReplaceAllSources (config, view, STACK_ SRC, false); // pass 1 (detections->allSources)234 psphotReplaceAllSources (config, view, STACK_RAW, false); // pass 1 (detections->allSources) 239 235 240 236 logMemStats("pass1"); … … 245 241 // linear fit to include all sources (subtract again) 246 242 // NOTE : apply to ALL sources (extended + psf) 247 // NOTE 2 : this function subtracts the models from the given filerule (SRC), not DET248 psphotFitSourcesLinear (config, view, STACK_ SRC, true, false); // pass 2 (detections->allSources)243 // NOTE 2 : this function subtracts the models from the given filerule 244 psphotFitSourcesLinear (config, view, STACK_RAW, true, false); // pass 2 (detections->allSources) 249 245 250 246 // NOTE: possibly re-measure background model here with objects subtracted / or masked … … 252 248 // NOTE: this block performs the 2nd pass low-significance PSF detection stage 253 249 { 254 // if DET and SRC are different images, generate children sources for all sources in255 // the SRC image. This operation replaces the existing DETECTION container on DET256 // which is currently a view to the one on SRC). children sources go to257 // det->allSources258 if (strcmp(STACK_SRC, STACK_DET)) {259 psphotSourceChildren (config, view, STACK_DET, STACK_SRC);260 261 // subtract all sources from DET (this will subtract using the psf model for SRC, which262 // will somewhat oversubtract the sources -- this is OK263 psphotRemoveAllSources (config, view, STACK_DET, false); // do not ignore subtraction state for sources264 }265 266 250 // add noise for subtracted objects 267 psphotAddNoise (config, view, STACK_ DET); // pass 1 (detections->allSources)251 psphotAddNoise (config, view, STACK_RAW); // pass 1 (detections->allSources) 268 252 269 253 // find fainter sources 270 254 // NOTE: finds new peaks and new footprints, OLD and FULL set are saved on detections 271 psphotFindDetections (config, view, STACK_ DET, false); // pass 2 (detections->peaks, detections->footprints)255 psphotFindDetections (config, view, STACK_RAW, false); // pass 2 (detections->peaks, detections->footprints) 272 256 273 257 // remove noise for subtracted objects (ie, return to normal noise level) … … 276 260 bool footprintsUseUnsubtracted = psMetadataLookupBool(NULL, recipe, "FOOTPRINT_USE_UNSUBTRACTED"); 277 261 if (!footprintsUseUnsubtracted) { 278 psphotSubNoise (config, view, STACK_ DET); // pass 1 (detections->allSources)262 psphotSubNoise (config, view, STACK_RAW); // pass 1 (detections->allSources) 279 263 } 280 281 // if DET and SRC are different images, copy the detections from DET to SRC282 // (this operation just ensures the metadata container has a view on SRC as well283 if (strcmp(STACK_SRC, STACK_DET)) {284 // replace all sources in DET285 psphotReplaceAllSources (config, view, STACK_DET, false); // ignore subtraction state for sources286 287 // copy the newly detected peaks from DET to SRC so SourceStats below can operate on them288 if (!psphotCopyPeaks (config, view, STACK_SRC, STACK_DET)) {289 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");290 return psphotReadoutCleanup (config, view, STACK_SRC);291 }292 }293 264 294 265 // define new sources based on only the new peaks & measure moments 295 266 // NOTE: new sources are saved on detections->newSources 296 psphotSourceStats (config, view, STACK_ SRC, false); // pass 2 (detections->newSources)267 psphotSourceStats (config, view, STACK_RAW, false); // pass 2 (detections->newSources) 297 268 298 269 // set source type 299 270 // NOTE: apply only to detections->newSources 300 if (!psphotRoughClass (config, view, STACK_ SRC)) { // pass 2 (detections->newSources)271 if (!psphotRoughClass (config, view, STACK_RAW)) { // pass 2 (detections->newSources) 301 272 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 302 return psphotReadoutCleanup (config, view, STACK_ SRC);273 return psphotReadoutCleanup (config, view, STACK_RAW); 303 274 } 304 275 305 276 // replace all sources so fit below applies to all at once 306 277 // NOTE: apply only to OLD sources (which have been subtracted) 307 psphotReplaceAllSources (config, view, STACK_ SRC, false); // pass 2278 psphotReplaceAllSources (config, view, STACK_RAW, false); // pass 2 308 279 309 280 // merge the newly selected sources into the existing list 310 281 // NOTE: merge OLD and NEW 311 282 // XXX check on free of sources... 312 psphotMergeSources (config, view, STACK_ SRC); // (detections->newSources + detections->allSources -> detections->allSources)283 psphotMergeSources (config, view, STACK_RAW); // (detections->newSources + detections->allSources -> detections->allSources) 313 284 314 285 // Construct an initial model for each object, set the radius to fitRadius, set circular 315 286 // fit mask. NOTE: only applied to sources without guess models 316 psphotGuessModels (config, view, STACK_ SRC);287 psphotGuessModels (config, view, STACK_RAW); 317 288 } 318 289 … … 325 296 if (splitLinearFit) { 326 297 psLogMsg ("psphot", 3, "splitting fit of detected and matched soures\n"); 327 // Fit the detected sources separately from matched that weaare about to create.298 // Fit the detected sources separately from matched ones that we are about to create. 328 299 // NOTE: apply to ALL sources but only include sources with postitive flux in the fit 329 psphotFitSourcesLinear (config, view, STACK_ SRC, true, true); // pass 3 (detections->allSources)300 psphotFitSourcesLinear (config, view, STACK_RAW, true, true); // pass 3 (detections->allSources) 330 301 } 331 302 … … 335 306 // this just match the detections for the chisq image, and not bother measuring the source 336 307 // stats in that case...? 337 objects = psphotMatchSources (config, view, STACK_ SRC);308 objects = psphotMatchSources (config, view, STACK_RAW); 338 309 psMemDump("matchsources"); 339 310 … … 344 315 // Construct an initial model for each object, set the radius to fitRadius, set circular 345 316 // fit mask. NOTE: only applied to sources without guess models 346 psphotGuessModels (config, view, STACK_ SRC);317 psphotGuessModels (config, view, STACK_RAW); 347 318 348 319 psphotStackObjectsUnifyPosition (objects); 349 320 350 psphotStackObjectsSelectForAnalysis (config, view, STACK_ SRC, objects);321 psphotStackObjectsSelectForAnalysis (config, view, STACK_RAW, objects); 351 322 352 323 // final linear fit. NOTE: if splitLinearFit is true above, this pass will only fit 353 324 // the unsubtracted (matched) sources (the sources that we fit above are subtracted) 354 psphotFitSourcesLinear (config, view, STACK_ SRC, true, false); // pass 4 (detections->allSources)325 psphotFitSourcesLinear (config, view, STACK_RAW, true, false); // pass 4 (detections->allSources) 355 326 356 327 // measure the radial profiles to the sky (only measures new objects) 357 psphotRadialProfileWings (config, view, STACK_ SRC);328 psphotRadialProfileWings (config, view, STACK_RAW); 358 329 359 330 // re-measure the kron mags with models subtracted 360 331 // psphotKronMasked(config, view, STACK_SRC); 361 332 logMemStats("before.kron.2"); 362 psphotKronIterate(config, view, STACK_ SRC, 2);333 psphotKronIterate(config, view, STACK_RAW, 2); 363 334 logMemStats("after.kron.2"); 364 335 365 336 // measure source size for the remaining sources 366 337 // NOTE: applies only to NEW (unmeasured) sources 367 psphotSourceSize (config, view, STACK_ SRC, false); // pass 2 (detections->allSources)338 psphotSourceSize (config, view, STACK_RAW, false); // pass 2 (detections->allSources) 368 339 369 340 psMemDump("psfstats"); … … 371 342 // drop matched sources without any useful measurements and set kron radii for the ones 372 343 // we decide to keep 373 psphotFilterMatchedSources (config, view, STACK_ SRC, objects);344 psphotFilterMatchedSources (config, view, STACK_RAW, objects); 374 345 375 346 // measure kron fluxes for the matched sources only 376 psphotKronIterate(config, view, STACK_ SRC, 3);347 psphotKronIterate(config, view, STACK_RAW, 3); 377 348 378 349 // measure elliptical apertures, petrosians (objects sorted by S/N) 379 350 // psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_SRC); // pass 1 (detections->allSources) 380 psphotExtendedSourceAnalysis (config, view, STACK_ SRC); // pass 1 (detections->allSources)351 psphotExtendedSourceAnalysis (config, view, STACK_RAW); // pass 1 (detections->allSources) 381 352 382 353 // measure non-linear extended source models (exponential, deVaucouleur, Sersic) (sources sorted by S/N) 383 psphotExtendedSourceFits (config, view, STACK_ SRC); // pass 1 (detections->allSources)354 psphotExtendedSourceFits (config, view, STACK_RAW); // pass 1 (detections->allSources) 384 355 385 356 // create source children for the OUT filerule (for radial aperture photometry and output) 386 psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, objects); 357 // NOTE: The new source children have image arrays pointing to the readout associated with 358 // STACK_OUT. in psphotStackMatchPSFsetup, we copy the current pixel values from RAW to OUT, 359 // but keep the pointers the same so we do not break these source image references 360 // XXX NOTE : if we use the pre-20130914 psphotStackReadout code, we need to use 'false' for the 361 // sourcesSubtracted argument 362 psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, objects, true); 387 363 if (!objectsOut) { 388 364 psFree(objects); 389 365 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 390 return psphotReadoutCleanup (config, view, STACK_ SRC);366 return psphotReadoutCleanup (config, view, STACK_RAW); 391 367 } 392 368 … … 396 372 // this forces photometry on the undetected sources from other images 397 373 398 // NOTE: we always do the radial apertures analysis on the convolved image since 399 // those are the ones that are psf matched and are the source of STACK_OUT's pixels 400 // XXX: Actually if PSPHOT.STACK.MATCH.PSF.SOURCE were set to RAW this wouldn't be true. 401 // but in that case we don't get past the psf matching step because there is no 402 // target psf for the RAW inputs 403 404 // If useRaw copy the sources to the convolved readout 405 if (strcmp(STACK_SRC, STACK_CNV)) { 406 if (!psphotCopySources (config, view, STACK_CNV, STACK_SRC)) { 407 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 408 return psphotReadoutCleanup (config, view, STACK_SRC); 409 } 410 } 411 // mark any inputs that we want to skip the matched apertures for 412 psphotStackSetInputsToSkip(config, view, STACK_CNV, true); 413 psphotStackSetInputsToSkip(config, view, STACK_OUT, true); 414 psphotRadialApertures (config, view, STACK_CNV, 0); // entry 0 == unmatched 415 psMemDump("extmeas"); 416 374 // set up the FWHM vector 375 psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW); 376 psphotDumpImages (config, view, STACK_RAW, "raw.t0"); 377 psphotDumpImages (config, view, STACK_OUT, "out.t0"); 417 378 418 379 int nRadialEntries = psphotStackMatchPSFsEntries(config, view, STACK_OUT); 419 for (int entry = 1; entry < nRadialEntries; entry++) { 380 381 for (int entry = 0; entry < nRadialEntries; entry++) { 420 382 // NOTE: entry 0 is the unmatched image set 421 383 422 // re-measure the PSF for the smoothed image (using entries in 'allSources') 423 psphotChoosePSF (config, view, STACK_OUT, false); 424 425 // this is necessary to update the models based on the new PSF 426 psphotResetModels (config, view, STACK_OUT); 427 428 // this is necessary to get the right normalization for the new models 429 psphotFitSourcesLinear (config, view, STACK_OUT, false, false); 384 char line[256]; 430 385 431 386 // measure circular, radial apertures (objects sorted by S/N) 432 387 psphotRadialApertures (config, view, STACK_OUT, entry); 388 snprintf (line, 256, "%s.%d", "out.t1", entry); 389 psphotDumpImages (config, view, STACK_OUT, line); 433 390 434 391 // replace the flux in the image so it is returned to its original state 435 392 psphotReplaceAllSources (config, view, STACK_OUT, false); 436 437 // smooth to the next FWHM, or set 'smoothAgain' to false if no more 438 psphotStackMatchPSFsNext(config, view, STACK_OUT, entry); 439 psMemDump("matched"); 393 snprintf (line, 256, "%s.%d", "out.t2", entry); 394 psphotDumpImages (config, view, STACK_OUT, line); 395 396 if (entry < nRadialEntries - 1) { 397 // smooth to the next FWHM 398 // this function does nothing if the targetFWHM is smaller than the currentFWHM 399 psphotStackMatchPSFsNext(config, view, STACK_OUT, entry); 400 snprintf (line, 256, "%s.%d", "out.t3", entry); 401 psphotDumpImages (config, view, STACK_OUT, line); 402 psMemDump("matched"); 403 404 // re-measure the PSF for the smoothed image (using entries in 'allSources') 405 psphotChoosePSF (config, view, STACK_OUT, false); 406 407 // this is necessary to update the models based on the new PSF 408 psphotResetModels (config, view, STACK_OUT); 409 410 // this is necessary to get the right normalization for the new models 411 // and to subtract the sources 412 psphotFitSourcesLinear (config, view, STACK_OUT, false, false); 413 snprintf (line, 256, "%s.%d", "out.t4", entry); 414 psphotDumpImages (config, view, STACK_OUT, line); 415 } 440 416 } 441 417 } 442 psphotStackSetInputsToSkip(config, view, STACK_CNV, false);443 psphotStackSetInputsToSkip(config, view, STACK_OUT, false);444 418 445 419 // measure aperture photometry corrections 446 if (!psphotApResid (config, view, STACK_ SRC)) {420 if (!psphotApResid (config, view, STACK_RAW)) { 447 421 psFree (objects); 448 422 psFree (objectsOut); 449 423 psLogMsg ("psphot", 3, "failed on psphotApResid"); 450 return psphotReadoutCleanup (config, view, STACK_ SRC);424 return psphotReadoutCleanup (config, view, STACK_RAW); 451 425 } 452 426 453 427 // calculate source magnitudes 454 psphotMagnitudes(config, view, STACK_SRC); 455 456 if (!useRaw) { 457 // psphotEfficiency wants to have the PSF of the image, but since we are measuring on 458 // the convolved images we need to generate PSFs for the DET images 459 if (!psphotChoosePSF (config, view, STACK_DET, false)) { 460 psLogMsg ("psphot", 3, "failure to construct a psf model for raw input"); 461 return psphotReadoutCleanup (config, view, STACK_DET); 462 } 463 } 464 if (!psphotEfficiency(config, view, STACK_DET)) { 428 psphotMagnitudes(config, view, STACK_RAW); 429 430 if (!psphotEfficiency(config, view, STACK_RAW)) { 465 431 psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources"); 466 432 psErrorClear(); 467 433 } 468 psphotCopyEfficiency (config, view, STACK_OUT, STACK_ DET);434 psphotCopyEfficiency (config, view, STACK_OUT, STACK_RAW); 469 435 470 436 logMemStats("final"); 471 437 #if (1) 472 psphotSourceMemory(config, view, STACK_ SRC);438 psphotSourceMemory(config, view, STACK_RAW); 473 439 psphotSourceMemory(config, view, STACK_OUT); 474 440 #endif 475 441 476 // replace failed sources?477 // psphotReplaceUnfitSources (sources);478 479 442 // replace background in residual image 480 psphotSkyReplace (config, view, STACK_ DET);443 psphotSkyReplace (config, view, STACK_RAW); 481 444 482 445 // drop the references to the image pixels held by each source 446 psphotSourceFreePixels (config, view, STACK_RAW); 483 447 psphotSourceFreePixels (config, view, STACK_OUT); 484 psphotSourceFreePixels (config, view, STACK_SRC);485 448 486 449 #ifdef MAKE_CHISQ_IMAGE 487 450 // remove chisq image from config->file:PSPHOT.INPUT 488 psphotStackRemoveChisqFromInputs(config, STACK_DET); 489 if (strcmp(STACK_SRC, STACK_DET)) { 490 psphotStackRemoveChisqFromInputs(config, STACK_SRC); 491 } 451 psphotStackRemoveChisqFromInputs(config, STACK_RAW); 492 452 #endif 493 453 … … 496 456 497 457 // create the exported-metadata and free local data 498 return psphotReadoutCleanup (config, view, STACK_ SRC);458 return psphotReadoutCleanup (config, view, STACK_RAW); 499 459 } 500 460 … … 552 512 } 553 513 554 555 556 514 /* here is the process: 557 515 558 * we have three(*) images: 559 * RAW : unconvolved image stack 560 * CNV : input convolved image 516 * we have two image sets: 517 * RAW : unconvolved image stacks 561 518 562 519 * OUT : psf-matched output image (there may be more than one of … … 649 606 650 607 */ 608 609 610 // generate a vector fwhmValues where the first has the fwhm of the raw image and the 611 // successive entries have the target values 612 613 bool psphotStackMatchPSFsetup (pmConfig *config, const pmFPAview *view, const char *filerule, const char *filerulePSF) { 614 615 bool status; 616 617 int num = psphotFileruleCount(config, filerule); 618 619 // skip the chisq image (optionally?) 620 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 621 if (!status) chisqNum = -1; 622 623 // loop over the available readouts 624 for (int i = 0; i < num; i++) { 625 if (i == chisqNum) continue; // skip chisq image 626 627 if (!psphotStackMatchPSFsetupReadout (config, view, filerule, filerulePSF, i)) { 628 psError (PSPHOT_ERR_CONFIG, false, "failed to define target PSF sizes"); 629 return false; 630 } 631 } 632 633 return true; 634 } 635 636 float psphotPSFseeing (pmPSF *psf, pmReadout *readout, int index); 637 638 // copy the pixels from RAW to OUT ( 639 640 bool psphotStackMatchPSFsetupReadout (pmConfig *config, const pmFPAview *view, const char *fileruleOut, const char *fileruleRaw, int index) { 641 642 bool status; 643 644 // select the appropriate recipe information 645 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 646 647 // find the currently selected readout 648 pmFPAfile *fileOut = pmFPAfileSelectSingle(config->files, fileruleOut, index); // File of interest 649 psAssert (fileOut, "missing file?"); 650 651 pmReadout *readoutOut = pmFPAviewThisReadout(view, fileOut->fpa); 652 psAssert (readoutOut, "missing readout?"); 653 654 // find the currently selected readout 655 pmFPAfile *fileRaw = pmFPAfileSelectSingle(config->files, fileruleRaw, index); // File of interest 656 psAssert (fileRaw, "missing file?"); 657 658 pmReadout *readoutRaw = pmFPAviewThisReadout(view, fileRaw->fpa); 659 psAssert (readoutRaw, "missing readout?"); 660 661 readoutOut->image = psImageCopy(readoutOut->image, readoutRaw->image, PS_TYPE_F32); 662 if (readoutRaw->variance) { 663 readoutOut->variance = psImageCopy(readoutOut->variance, readoutRaw->variance, PS_TYPE_F32); 664 } 665 if (readoutRaw->mask) { 666 readoutOut->mask = psImageCopy(readoutOut->mask, readoutRaw->mask, PS_TYPE_IMAGE_MASK); 667 } 668 669 // pmChip *chipRaw = pmFPAviewThisChip(view, fileRaw->fpa); // The chip holds the PSF 670 // psAssert (chipRaw, "missing chip"); 671 672 pmPSF *psf = psMetadataLookupPtr(&status, readoutRaw->analysis, "PSPHOT.PSF"); // PSF 673 if (!psf) { 674 // we should have a PSF by this point in psphot 675 psError(PSPHOT_ERR_PROG, true, "Unable to find PSF."); 676 return false; 677 } 678 679 float fwhmRaw = psphotPSFseeing (psf, readoutRaw, index); 680 681 psVector *fwhmValues = psVectorAllocEmpty(10, PS_TYPE_F32); 682 psVectorAppend(fwhmValues, fwhmRaw); 683 684 // is a single target FWHM specified, or a set of values? set up the vector options->targetSeeing and the local 1st value 685 float targetSeeing = psMetadataLookupF32 (&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); 686 if (!status) { 687 psVector *targetSeeing = psMetadataLookupVector(&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); // Magnitude offsets 688 psAssert (status, "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM"); 689 for (int i = 0; i < targetSeeing->n; i++) { 690 psVectorAppend(fwhmValues, targetSeeing->data.F32[i]); 691 } 692 } else { 693 psVectorAppend(fwhmValues, targetSeeing); 694 } 695 696 psMetadataAddVector(readoutOut->analysis, PS_LIST_TAIL, "STACK.PSF.FWHM.VALUES", PS_META_REPLACE, "PSF sizes", fwhmValues); 697 psFree (fwhmValues); 698 699 return true; 700 } 701 702 float psphotPSFseeing (pmPSF *psf, pmReadout *readout, int index) { 703 704 psImage *image = readout->image; 705 706 int Nx = image->numCols; 707 int Ny = image->numRows; 708 709 float sumFWHM = 0.0; // FWHM for image 710 int numFWHM = 0; // Number of FWHM measurements 711 for (float x = 0; x < Nx; x += 0.25*Nx) { 712 for (float y = 0; y < Ny; y += 0.25*Ny) { 713 float fwhm = pmPSFtoFWHM(psf, x, y); 714 if (isfinite(fwhm)) { 715 sumFWHM += fwhm; 716 numFWHM++; 717 } 718 } 719 } 720 if (numFWHM == 0) { 721 psLogMsg("ppStack", PS_LOG_INFO, "Unable to measure PSF FWHM for image %d --- rejected.", index); 722 return NAN; 723 } 724 725 float fwhm = sumFWHM / (float) numFWHM; 726 psLogMsg ("psphotStack", PS_LOG_INFO, "Input Seeing for %d: %f\n", index, fwhm); 727 728 return fwhm; 729 }
Note:
See TracChangeset
for help on using the changeset viewer.
