- Timestamp:
- Mar 5, 2012, 5:19:48 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src (modified) (2 props)
-
psphot/src/psphotStackReadout.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/psphot
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/psphot/src
- Property svn:ignore
-
old new 22 22 psphotMakePSF 23 23 psphotStack 24 psphotModelTest
-
- Property svn:mergeinfo set to
- Property svn:ignore
-
branches/meh_branches/ppstack_test/psphot/src/psphotStackReadout.c
r31154 r33415 44 44 bool psphotStackReadout (pmConfig *config, const pmFPAview *view) { 45 45 46 psArray *objects = NULL; // used below after 'pass1finish' label 47 48 // measure the total elapsed time in psphotReadout. dtime is the elapsed time used jointly 49 // by the multiple threads, not the total time used by all threads. 46 50 psTimerStart ("psphotReadout"); 47 51 … … 56 60 // optional break-point for processing 57 61 char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT"); 58 PS_ASSERT_PTR_NON_NULL (breakPt, false); 59 60 // XXX or do I set OUT to be a pmFPAfile pointing at the input of interest? 62 psAssert (breakPt, "configuration error: set BREAK_POINT"); 63 64 // we have 3 relevant files: RAW (unconvolved), CNV (convolved stack), OUT (psf-matched stack) 65 // select which image (RAW or CNV) is used for analysis (RAW always used for detection) 61 66 bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW"); 62 67 char *STACK_SRC = useRaw ? STACK_RAW : STACK_CNV; 63 char *STACK_DET = STACK_RAW; // XXX optionally allow this to be CNV? 64 65 // we have 3 relevant files: RAW, CNV, OUT 68 char *STACK_DET = STACK_RAW; 66 69 67 70 // set the photcode for each image … … 71 74 } 72 75 73 // Generate the mask and weight images 74 // XXX this should be done before we perform the convolutions 76 // Generate the mask and weight images (if not supplied) and set mask bits 75 77 if (!psphotSetMaskAndVariance (config, view, STACK_DET)) { 76 78 return psphotReadoutCleanup (config, view, STACK_SRC); … … 81 83 82 84 // generate a background model (median, smoothed image) 83 // XXX I think this is not defined correctly for an array of images.84 // XXX probably need to subtract the model (same model?) for both RAW and OUT85 85 if (!psphotModelBackground (config, view, STACK_DET)) { 86 86 return psphotReadoutCleanup (config, view, STACK_SRC); … … 89 89 return psphotReadoutCleanup (config, view, STACK_SRC); 90 90 } 91 if (!psphotSubtractBackground (config, view, STACK_SRC)) { 92 return psphotReadoutCleanup (config, view, STACK_SRC); 93 } 91 94 if (!strcasecmp (breakPt, "BACKMDL")) { 92 95 return psphotReadoutCleanup (config, view, STACK_SRC); 93 96 } 94 97 98 // also make the chisq detection image 95 99 if (!psphotStackChisqImage(config, view, STACK_DET, STACK_SRC)) { 96 100 psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image"); … … 109 113 } 110 114 111 // copy the detections from DET to SRC 115 // If DET and SRC are different images, copy the detections from DET to SRC. This 'copy' 116 // is just a copy of the container pointer; the sources on both DET and SRC are the same 117 // memory objects 112 118 if (strcmp(STACK_SRC, STACK_DET)) { 113 119 if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) { … … 122 128 return psphotReadoutCleanup (config, view, STACK_SRC); 123 129 } 124 125 if (!strcasecmp (breakPt, "TEST1")) { 126 return psphotReadoutCleanup (config, view, STACK_SRC); 127 } 128 130 if (!strcasecmp (breakPt, "PEAKS")) { 131 return psphotReadoutCleanup (config, view, STACK_SRC); 132 } 133 // psphotDumpTest (config, view, STACK_SRC); 129 134 psMemDump("sourcestats"); 130 131 // generate the objects (object unify the sources from the different images)132 // XXX this could just match the detections for the chisq image, and not bother measuring the133 // source stats in that case...134 psArray *objects = psphotMatchSources (config, view, STACK_SRC);135 136 psMemDump("matchsources");137 138 if (!strcasecmp (breakPt, "TEST2")) {139 psFree(objects);140 return psphotReadoutCleanup (config, view, STACK_SRC);141 }142 143 // construct sources for the newly-generated sources (from other images)144 if (!psphotSourceStats (config, view, STACK_SRC, false)) { // pass 1145 psFree(objects);146 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");147 return psphotReadoutCleanup (config, view, STACK_SRC);148 }149 150 psMemDump("sourcestats");151 152 // find blended neighbors of very saturated stars (detections->newSources)153 // if (!psphotDeblendSatstars (config, view)) {154 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");155 // return psphotReadoutCleanup (config, view, STACK_SRC);156 // }157 158 // mark blended peaks PS_SOURCE_BLEND (detections->newSources)159 // if (!psphotBasicDeblend (config, view)) {160 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");161 // return psphotReadoutCleanup (config, view, STACK_SRC);162 // }163 135 164 136 // classify sources based on moments, brightness 165 137 // only run this on detections from the input images, not chisq image 166 138 if (!psphotRoughClass (config, view, STACK_SRC)) { 167 psFree(objects);168 139 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 169 140 return psphotReadoutCleanup (config, view, STACK_SRC); 170 141 } 142 171 143 // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources) 172 144 // only run this on detections from the input images, not chisq image 173 145 if (!psphotImageQuality (config, view, STACK_SRC)) { // pass 1 174 psFree(objects);175 146 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); 176 147 return psphotReadoutCleanup (config, view, STACK_SRC); 177 148 } 178 149 if (!strcasecmp (breakPt, "MOMENTS")) { 179 psFree(objects); 180 return psphotReadoutCleanup (config, view, STACK_SRC); 181 } 182 183 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 184 // this step is skipped 150 return psphotReadoutCleanup (config, view, STACK_SRC); 151 } 152 153 // use bright stellar objects to measure PSF 185 154 if (!psphotChoosePSF (config, view, STACK_SRC, true)) { // pass 1 186 psFree(objects);187 155 psLogMsg ("psphot", 3, "failure to construct a psf model"); 188 156 return psphotReadoutCleanup (config, view, STACK_SRC); 189 157 } 190 158 if (!strcasecmp (breakPt, "PSFMODEL")) { 191 psFree(objects); 192 return psphotReadoutCleanup (config, view, STACK_SRC); 193 } 194 195 // construct an initial model for each object, set the radius to fitRadius, set circular fit mask 196 psphotGuessModels (config, view, STACK_SRC); 159 return psphotReadoutCleanup (config, view, STACK_SRC); 160 } 197 161 198 162 // merge the newly selected sources into the existing list … … 200 164 psphotMergeSources (config, view, STACK_SRC); 201 165 166 // Construct an initial model for each object, set the radius to fitRadius, set circular 167 // fit mask. NOTE: only applied to sources without guess models 168 psphotGuessModels (config, view, STACK_SRC); 169 202 170 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 203 psphotFitSourcesLinear Stack (config, objects, FALSE);171 psphotFitSourcesLinear (config, view, STACK_SRC, false); 204 172 psphotStackVisualFilerule(config, view, STACK_SRC); 205 173 174 // measure the radial profiles to the sky 175 psphotRadialProfileWings (config, view, STACK_SRC); 176 177 // re-measure the kron mags with models subtracted. this pass starts with a circular 178 // window of size PSF_MOMENTS_RADIUS (same window used to measure the psf-scale moments) 179 // but iterates to an appropriately larger size 180 psphotKronIterate(config, view, STACK_SRC); 181 206 182 // identify CRs and extended sources 207 psphotSourceSize (config, view, STACK_SRC, TRUE); 208 209 // XXX do we want to do a preliminary (unconvolved) model fit here, and then 210 // do a second detection pass? (like standard psphot) 211 212 // measure aperture photometry corrections 213 if (!psphotApResid (config, view, STACK_SRC)) { 214 psFree (objects); 215 psLogMsg ("psphot", 3, "failed on psphotApResid"); 216 return psphotReadoutCleanup (config, view, STACK_SRC); 217 } 183 psphotSourceSize (config, view, STACK_SRC, true); 184 185 // non-linear PSF and EXT fit to brighter sources 186 // replace model flux, adjust mask as needed, fit, subtract the models (full stamp) 187 psphotBlendFit (config, view, STACK_SRC); // pass 1 (detections->allSources) 188 189 // replace all sources (do NOT ignore subtraction state) 190 psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 1 (detections->allSources) 191 192 // if we only do one pass, skip to extended source analysis 193 if (!strcasecmp (breakPt, "PASS1")) goto pass1finish; 194 195 // linear fit to include all sources (subtract again) 196 // NOTE : apply to ALL sources (extended + psf) 197 // NOTE 2 : this function subtracts the models from the given filerule (SRC), not DET 198 psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 2 (detections->allSources) 199 200 // NOTE: possibly re-measure background model here with objects subtracted / or masked 201 202 // NOTE: this block performs the 2nd pass low-significance PSF detection stage 203 { 204 // if DET and SRC are different images, generate children sources for all sources in 205 // the SRC image. This operation replaces the existing DETECTION container on DET 206 // which is currently a view to the one on SRC). children sources go to 207 // det->allSources 208 if (strcmp(STACK_SRC, STACK_DET)) { 209 psphotSourceChildren (config, view, STACK_DET, STACK_SRC); 210 211 // subtract all sources from DET (this will subtract using the psf model for SRC, which 212 // will somewhat oversubtract the sources -- this is OK 213 psphotRemoveAllSources (config, view, STACK_DET, false); // ignore subtraction state for sources 214 } 215 216 // add noise for subtracted objects 217 psphotAddNoise (config, view, STACK_DET); // pass 1 (detections->allSources) 218 219 // find fainter sources 220 // NOTE: finds new peaks and new footprints, OLD and FULL set are saved on detections 221 psphotFindDetections (config, view, STACK_DET, false); // pass 2 (detections->peaks, detections->footprints) 222 223 // remove noise for subtracted objects (ie, return to normal noise level) 224 // NOTE: this needs to operate only on the OLD sources 225 psphotSubNoise (config, view, STACK_DET); // pass 1 (detections->allSources) 226 227 // if DET and SRC are different images, copy the detections from DET to SRC 228 // (this operation just ensures the metadata container has a view on SRC as well 229 if (strcmp(STACK_SRC, STACK_DET)) { 230 // replace all sources in DET 231 psphotReplaceAllSources (config, view, STACK_DET, false); // ignore subtraction state for sources 232 233 // copy the newly detected peaks from DET to SRC so SourceStats below can operate on them 234 if (!psphotCopyPeaks (config, view, STACK_SRC, STACK_DET)) { 235 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 236 return psphotReadoutCleanup (config, view, STACK_SRC); 237 } 238 } 239 240 // define new sources based on only the new peaks & measure moments 241 // NOTE: new sources are saved on detections->newSources 242 psphotSourceStats (config, view, STACK_SRC, false); // pass 2 (detections->newSources) 243 244 // set source type 245 // NOTE: apply only to detections->newSources 246 if (!psphotRoughClass (config, view, STACK_SRC)) { // pass 2 (detections->newSources) 247 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 248 return psphotReadoutCleanup (config, view, STACK_SRC); 249 } 250 251 // replace all sources so fit below applies to all at once 252 // NOTE: apply only to OLD sources (which have been subtracted) 253 psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 2 254 255 // merge the newly selected sources into the existing list 256 // NOTE: merge OLD and NEW 257 // XXX check on free of sources... 258 psphotMergeSources (config, view, STACK_SRC); // (detections->newSources + detections->allSources -> detections->allSources) 259 260 // Construct an initial model for each object, set the radius to fitRadius, set circular 261 // fit mask. NOTE: only applied to sources without guess models 262 psphotGuessModels (config, view, STACK_SRC); 263 } 264 265 pass1finish: 266 267 // generate the objects (objects unify the sources from the different images) NOTE: could 268 // this just match the detections for the chisq image, and not bother measuring the source 269 // stats in that case...? 270 objects = psphotMatchSources (config, view, STACK_SRC); 271 psMemDump("matchsources"); 272 273 // Construct an initial model for each object, set the radius to fitRadius, set circular 274 // fit mask. NOTE: only applied to sources without guess models 275 psphotGuessModels (config, view, STACK_SRC); 276 277 psphotStackObjectsUnifyPosition (objects); 278 279 psphotStackObjectsSelectForAnalysis (config, view, STACK_SRC, objects); 280 281 // NOTE: apply to ALL sources 282 psphotFitSourcesLinear (config, view, STACK_SRC, true); // pass 3 (detections->allSources) 283 284 // measure the radial profiles to the sky (only measures new objects) 285 psphotRadialProfileWings (config, view, STACK_SRC); 286 287 // re-measure the kron mags with models subtracted 288 // psphotKronMasked(config, view, STACK_SRC); 289 psphotKronIterate(config, view, STACK_SRC); 290 291 // measure source size for the remaining sources 292 // NOTE: applies only to NEW (unmeasured) sources 293 psphotSourceSize (config, view, STACK_SRC, false); // pass 2 (detections->allSources) 218 294 219 295 psMemDump("psfstats"); 220 296 221 psphotStackObjectsUnifyPosition (objects);222 223 297 // measure elliptical apertures, petrosians (objects sorted by S/N) 224 psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_SRC); // pass 1 (detections->allSources) 298 // psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_SRC); // pass 1 (detections->allSources) 299 psphotExtendedSourceAnalysis (config, view, STACK_SRC); // pass 1 (detections->allSources) 225 300 226 301 // measure non-linear extended source models (exponential, deVaucouleur, Sersic) (sources sorted by S/N) 227 302 psphotExtendedSourceFits (config, view, STACK_SRC); // pass 1 (detections->allSources) 228 229 // calculate source magnitudes230 psphotMagnitudes(config, view, STACK_SRC);231 303 232 304 // create source children for the OUT filerule (for radial aperture photometry) … … 238 310 } 239 311 312 // measure circular, radial apertures (objects sorted by S/N) 313 // this forces photometry on the undetected sources from other images 314 psphotRadialApertures (config, view, STACK_SRC, 0); // XXX entry 0 == unmatched? 240 315 psMemDump("extmeas"); 241 316 242 bool smoothAgain = true; 243 for (int nMatchedPSF = 0; smoothAgain; nMatchedPSF++) { 317 int nRadialEntries = psphotStackMatchPSFsEntries(config, view, STACK_OUT); 318 319 for (int entry = 1; entry < nRadialEntries; entry++) { 320 // NOTE: entry 0 is the unmatched image set 244 321 245 322 // re-measure the PSF for the smoothed image (using entries in 'allSources') … … 253 330 254 331 // measure circular, radial apertures (objects sorted by S/N) 255 psphotRadialAperturesByObject (config, objectsRadial, view, STACK_OUT, nMatchedPSF); 332 // entry 0 == unmatched? pass entry + 1? 333 psphotRadialApertures (config, view, STACK_OUT, entry); 256 334 257 335 // replace the flux in the image so it is returned to its original state 258 psphotReplaceAllSources (config, view, STACK_OUT );336 psphotReplaceAllSources (config, view, STACK_OUT, false); 259 337 260 338 // smooth to the next FWHM, or set 'smoothAgain' to false if no more 261 psphotStackMatchPSFsNext( &smoothAgain, config, view, STACK_OUT, nMatchedPSF);339 psphotStackMatchPSFsNext(config, view, STACK_OUT, entry); 262 340 psMemDump("matched"); 263 341 } 264 342 265 if (0 && !psphotEfficiency(config, view, STACK_OUT)) { 343 // measure aperture photometry corrections 344 if (!psphotApResid (config, view, STACK_SRC)) { 345 psFree (objects); 346 psLogMsg ("psphot", 3, "failed on psphotApResid"); 347 return psphotReadoutCleanup (config, view, STACK_SRC); 348 } 349 350 // calculate source magnitudes 351 psphotMagnitudes(config, view, STACK_SRC); 352 353 // XXX NOTE: this function wants to have the PSF of the image, but we (so far) only measure the 354 // PSF of the SRC image. can we fake it by generating the PSF for DET as well (up above)? 355 if (false && !psphotEfficiency(config, view, STACK_DET)) { 266 356 psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources"); 267 357 psErrorClear();
Note:
See TracChangeset
for help on using the changeset viewer.
