Changeset 30624 for trunk/psphot/src/psphotStackReadout.c
- Timestamp:
- Feb 13, 2011, 12:33:05 PM (15 years ago)
- Location:
- trunk/psphot
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/psphotStackReadout.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot
- Property svn:mergeinfo changed
-
trunk/psphot/src/psphotStackReadout.c
r29936 r30624 1 1 # include "psphotInternal.h" 2 2 3 // we have 3 possible real filesets: 3 4 # define STACK_RAW "PSPHOT.STACK.INPUT.RAW" 4 # define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE" 5 # define STACK_CNV "PSPHOT.STACK.INPUT.CNV" 6 # define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE" /* the psf-matched image */ 7 8 // we have 3 files on which we operate: 9 // DET (detection image) : nominally RAW (optionally CNV?) 10 // SRC (source analysis image) : nominally CNV (optionally RAW) 11 // OUT (psf-matched images) : always OUT 12 13 bool psphotStackVisualFilerule(pmConfig *config, const pmFPAview *view, const char *filerule) { 14 15 bool status = false; 16 17 int num = psphotFileruleCount(config, filerule); 18 19 // select the appropriate recipe information 20 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 21 22 // loop over the available readouts 23 for (int i = 0; i < num; i++) { 24 25 // find the currently selected readout 26 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest 27 psAssert (file, "missing file?"); 28 29 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 30 psAssert (readout, "missing readout?"); 31 32 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 33 psAssert (detections, "missing detections?"); 34 35 psArray *sources = detections->allSources; 36 psAssert (sources, "missing sources?"); 37 38 psphotVisualShowResidualImage (readout, true); 39 psphotVisualShowObjectRegions (readout, recipe, sources); 40 } 41 return true; 42 } 5 43 6 44 bool psphotStackReadout (pmConfig *config, const pmFPAview *view) { … … 20 58 PS_ASSERT_PTR_NON_NULL (breakPt, false); 21 59 60 // XXX or do I set OUT to be a pmFPAfile pointing at the input of interest? 61 bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW"); 62 char *STACK_SRC = useRaw ? STACK_RAW : STACK_CNV; 63 char *STACK_DET = STACK_RAW; // XXX optionally allow this to be CNV? 64 22 65 // we have 3 relevant files: RAW, CNV, OUT 23 66 24 67 // set the photcode for each image 25 if (!psphotAddPhotcode (config, view, STACK_ OUT)) {68 if (!psphotAddPhotcode (config, view, STACK_SRC)) { 26 69 psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode"); 27 70 return false; … … 30 73 // Generate the mask and weight images 31 74 // XXX this should be done before we perform the convolutions 32 if (!psphotSetMaskAndVariance (config, view, STACK_ RAW)) {33 return psphotReadoutCleanup (config, view, STACK_ OUT);75 if (!psphotSetMaskAndVariance (config, view, STACK_DET)) { 76 return psphotReadoutCleanup (config, view, STACK_SRC); 34 77 } 35 78 if (!strcasecmp (breakPt, "NOTHING")) { 36 return psphotReadoutCleanup (config, view, STACK_ OUT);79 return psphotReadoutCleanup (config, view, STACK_SRC); 37 80 } 38 81 … … 40 83 // XXX I think this is not defined correctly for an array of images. 41 84 // XXX probably need to subtract the model (same model?) for both RAW and OUT 42 if (!psphotModelBackground (config, view, STACK_ RAW)) {43 return psphotReadoutCleanup (config, view, STACK_ OUT);44 } 45 if (!psphotSubtractBackground (config, view, STACK_ RAW)) {46 return psphotReadoutCleanup (config, view, STACK_ OUT);85 if (!psphotModelBackground (config, view, STACK_DET)) { 86 return psphotReadoutCleanup (config, view, STACK_SRC); 87 } 88 if (!psphotSubtractBackground (config, view, STACK_DET)) { 89 return psphotReadoutCleanup (config, view, STACK_SRC); 47 90 } 48 91 if (!strcasecmp (breakPt, "BACKMDL")) { 49 return psphotReadoutCleanup (config, view, STACK_OUT); 50 } 51 52 // load the psf model, if suppled. FWHM_X,FWHM_Y,etc are determined and saved on 53 // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT 54 if (!psphotLoadPSF (config, view, STACK_RAW)) { 55 psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model"); 56 return psphotReadoutCleanup (config, view, STACK_OUT); 57 } 58 59 if (!psphotStackChisqImage(config, view, STACK_RAW, STACK_OUT)) { 92 return psphotReadoutCleanup (config, view, STACK_SRC); 93 } 94 95 if (!psphotStackChisqImage(config, view, STACK_DET, STACK_SRC)) { 60 96 psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image"); 61 return psphotReadoutCleanup (config, view, STACK_ OUT);97 return psphotReadoutCleanup (config, view, STACK_SRC); 62 98 } 63 99 if (!strcasecmp (breakPt, "CHISQ")) { 64 return psphotReadoutCleanup (config, view, STACK_ OUT);100 return psphotReadoutCleanup (config, view, STACK_SRC); 65 101 } 66 102 67 103 // find the detections (by peak and/or footprint) in the image. 68 104 // This finds the detections on Chisq image as well as the individuals 69 if (!psphotFindDetections (config, view, STACK_ RAW, true)) { // pass 1105 if (!psphotFindDetections (config, view, STACK_DET, true)) { // pass 1 70 106 // this only happens if we had an error in psphotFindDetections 71 107 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 72 return psphotReadoutCleanup (config, view, STACK_OUT); 73 } 74 75 // copy the detections from RAW to OUT 76 if (!psphotCopySources (config, view, STACK_OUT, STACK_RAW)) { 77 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 78 return psphotReadoutCleanup (config, view, STACK_OUT); 108 return psphotReadoutCleanup (config, view, STACK_SRC); 109 } 110 111 // copy the detections from DET to SRC 112 if (strcmp(STACK_SRC, STACK_DET)) { 113 if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) { 114 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 115 return psphotReadoutCleanup (config, view, STACK_SRC); 116 } 79 117 } 80 118 81 119 // construct sources and measure basic stats (saved on detections->newSources) 82 // only run this on detections from the input images, not chisq image 83 if (!psphotSourceStats (config, view, STACK_OUT, true)) { // pass 1 120 if (!psphotSourceStats (config, view, STACK_SRC, true)) { // pass 1 84 121 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 85 return psphotReadoutCleanup (config, view, STACK_OUT); 122 return psphotReadoutCleanup (config, view, STACK_SRC); 123 } 124 125 if (!strcasecmp (breakPt, "TEST1")) { 126 return psphotReadoutCleanup (config, view, STACK_SRC); 86 127 } 87 128 88 129 // generate the objects (object unify the sources from the different images) 89 psArray *objects = psphotMatchSources (config, view, STACK_OUT); 130 // XXX this could just match the detections for the chisq image, and not bother measuring the 131 // source stats in that case... 132 psArray *objects = psphotMatchSources (config, view, STACK_SRC); 133 134 if (!strcasecmp (breakPt, "TEST2")) { 135 psFree(objects); 136 return psphotReadoutCleanup (config, view, STACK_SRC); 137 } 90 138 91 139 // construct sources for the newly-generated sources (from other images) 92 if (!psphotSourceStats (config, view, STACK_OUT, false)) { // pass 1 140 if (!psphotSourceStats (config, view, STACK_SRC, false)) { // pass 1 141 psFree(objects); 93 142 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 94 return psphotReadoutCleanup (config, view, STACK_ OUT);143 return psphotReadoutCleanup (config, view, STACK_SRC); 95 144 } 96 145 … … 98 147 // if (!psphotDeblendSatstars (config, view)) { 99 148 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 100 // return psphotReadoutCleanup (config, view, STACK_ OUT);149 // return psphotReadoutCleanup (config, view, STACK_SRC); 101 150 // } 102 151 … … 104 153 // if (!psphotBasicDeblend (config, view)) { 105 154 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis"); 106 // return psphotReadoutCleanup (config, view, STACK_ OUT);155 // return psphotReadoutCleanup (config, view, STACK_SRC); 107 156 // } 108 157 109 158 // classify sources based on moments, brightness 110 159 // only run this on detections from the input images, not chisq image 111 if (!psphotRoughClass (config, view, STACK_OUT)) { 160 if (!psphotRoughClass (config, view, STACK_SRC)) { 161 psFree(objects); 112 162 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 113 return psphotReadoutCleanup (config, view, STACK_ OUT);163 return psphotReadoutCleanup (config, view, STACK_SRC); 114 164 } 115 165 // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources) 116 166 // only run this on detections from the input images, not chisq image 117 if (!psphotImageQuality (config, view, STACK_OUT)) { // pass 1 167 if (!psphotImageQuality (config, view, STACK_SRC)) { // pass 1 168 psFree(objects); 118 169 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); 119 return psphotReadoutCleanup (config, view, STACK_ OUT);170 return psphotReadoutCleanup (config, view, STACK_SRC); 120 171 } 121 172 if (!strcasecmp (breakPt, "MOMENTS")) { 122 return psphotReadoutCleanup (config, view, STACK_OUT); 173 psFree(objects); 174 return psphotReadoutCleanup (config, view, STACK_SRC); 123 175 } 124 176 125 177 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 126 178 // this step is skipped 127 if (!psphotChoosePSF (config, view, STACK_OUT)) { // pass 1 179 if (!psphotChoosePSF (config, view, STACK_SRC, true)) { // pass 1 180 psFree(objects); 128 181 psLogMsg ("psphot", 3, "failure to construct a psf model"); 129 return psphotReadoutCleanup (config, view, STACK_ OUT);182 return psphotReadoutCleanup (config, view, STACK_SRC); 130 183 } 131 184 if (!strcasecmp (breakPt, "PSFMODEL")) { 132 return psphotReadoutCleanup (config, view, STACK_OUT); 185 psFree(objects); 186 return psphotReadoutCleanup (config, view, STACK_SRC); 133 187 } 134 188 135 189 // construct an initial model for each object, set the radius to fitRadius, set circular fit mask 136 psphotGuessModels (config, view, STACK_ OUT);190 psphotGuessModels (config, view, STACK_SRC); 137 191 138 192 // merge the newly selected sources into the existing list 139 193 // NOTE: merge OLD and NEW 140 psphotMergeSources (config, view, STACK_ OUT);194 psphotMergeSources (config, view, STACK_SRC); 141 195 142 196 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 143 197 psphotFitSourcesLinearStack (config, objects, FALSE); 198 psphotStackVisualFilerule(config, view, STACK_SRC); 144 199 145 200 // identify CRs and extended sources 146 psphotSourceSize (config, view, STACK_OUT, TRUE); 201 psphotSourceSize (config, view, STACK_SRC, TRUE); 202 203 // XXX do we want to do a preliminary (unconvolved) model fit here, and then 204 // do a second detection pass? (like standard psphot) 147 205 148 206 // measure aperture photometry corrections 149 if (!psphotApResid (config, view, STACK_ OUT)) {207 if (!psphotApResid (config, view, STACK_SRC)) { 150 208 psFree (objects); 151 209 psLogMsg ("psphot", 3, "failed on psphotApResid"); 152 return psphotReadoutCleanup (config, view, STACK_ OUT);210 return psphotReadoutCleanup (config, view, STACK_SRC); 153 211 } 154 212 155 213 psphotStackObjectsUnifyPosition (objects); 156 214 157 // measure circular, radial apertures (objects sorted by S/N)158 psphotRadialAperturesByObject (config, objects, view, STACK_OUT);159 160 215 // measure elliptical apertures, petrosians (objects sorted by S/N) 161 psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_ OUT); // pass 1 (detections->allSources)216 psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_SRC); // pass 1 (detections->allSources) 162 217 163 218 // measure non-linear extended source models (exponential, deVaucouleur, Sersic) (sources sorted by S/N) 164 psphotExtendedSourceFits (config, view, STACK_ OUT); // pass 1 (detections->allSources)219 psphotExtendedSourceFits (config, view, STACK_SRC); // pass 1 (detections->allSources) 165 220 166 221 // calculate source magnitudes 167 psphotMagnitudes(config, view, STACK_OUT); 222 psphotMagnitudes(config, view, STACK_SRC); 223 224 // create source children for the OUT filerule (for radial aperture photometry) 225 psArray *objectsRadial = psphotSourceChildrenByObject (config, view, STACK_OUT, objects); 226 if (!objectsRadial) { 227 psFree(objects); 228 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 229 return psphotReadoutCleanup (config, view, STACK_SRC); 230 } 231 232 bool smoothAgain = true; 233 for (int nMatchedPSF = 0; smoothAgain; nMatchedPSF++) { 234 235 // re-measure the PSF for the smoothed image (using entries in 'allSources') 236 psphotChoosePSF (config, view, STACK_OUT, false); 237 238 // this is necessary to update the models based on the new PSF 239 psphotResetModels (config, view, STACK_OUT); 240 241 // this is necessary to get the right normalization for the new models 242 psphotFitSourcesLinear (config, view, STACK_OUT, false); 243 244 // measure circular, radial apertures (objects sorted by S/N) 245 psphotRadialAperturesByObject (config, objectsRadial, view, STACK_OUT, nMatchedPSF); 246 247 // replace the flux in the image so it is returned to its original state 248 psphotReplaceAllSources (config, view, STACK_OUT); 249 250 // smooth to the next FWHM, or set 'smoothAgain' to false if no more 251 psphotStackMatchPSFsNext(&smoothAgain, config, view, STACK_OUT, nMatchedPSF); 252 } 168 253 169 254 if (0 && !psphotEfficiency(config, view, STACK_OUT)) { … … 176 261 177 262 // replace background in residual image 178 psphotSkyReplace (config, view, STACK_ RAW);263 psphotSkyReplace (config, view, STACK_DET); 179 264 180 265 // drop the references to the image pixels held by each source 181 psphotSourceFreePixels (config, view, STACK_OUT); 182 183 // remove chisq image from config->file:PSPHOT.INPUT (why?) 184 psphotStackRemoveChisqFromInputs(config, STACK_RAW); 266 // psphotSourceFreePixels (config, view, STACK_OUT); 267 psphotSourceFreePixels (config, view, STACK_SRC); 268 269 // remove chisq image from config->file:PSPHOT.INPUT 270 psphotStackRemoveChisqFromInputs(config, STACK_DET); 271 if (strcmp(STACK_SRC, STACK_DET)) { 272 psphotStackRemoveChisqFromInputs(config, STACK_SRC); 273 } 185 274 186 275 psFree (objects); 276 psFree (objectsRadial); 187 277 188 278 // create the exported-metadata and free local data 189 return psphotReadoutCleanup (config, view, STACK_ OUT);279 return psphotReadoutCleanup (config, view, STACK_SRC); 190 280 } 191 281 282 /* here is the process: 283 284 * we have three(*) images: 285 * RAW : unconvolved image stack 286 * CNV : input convolved image 287 288 * OUT : psf-matched output image (there may be more than one of 289 * these. we will generate the first matched image by selecting the 290 * target PSF and doing a full psf-maching process (as used by ppStack 291 * and ppSub). But, additional target output files should use a 292 * simple gaussian convolution kernel determind from therms of the 293 * current and the target). 294 295 * the output should be / could be one of the matched images, but not 296 * all. should we ensure the first gets written out, and ot save the 297 * others (or only optionally). 298 299 * by default, we probably only sve the cmf ffile outputs. 300 301 * load the RAW image (unconvolved stacks) 302 * add photcode to the output headers / readout->analysis 303 * generate mask and variance image (this is probably never needed in 304 practice: we always load an input mask & var. 305 * generate & subtract a model background for ?? (RAW? CNV? OUT? all?) 306 * load a PSF (probably not yet working) 307 308 * generate the CHISQ image from the RAW input images (why save on OUT?) 309 310 * find detections on RAW 311 312 * copy detections to OUT 313 314 * generate source stats (moments) for OUT 315 316 * match sources across inputs (on OUT?) 317 318 * generate source stats for the new constructions 319 320 * rough class (star, galaxy, cosmic, etc) 321 322 * Image quality 323 324 * generate PSF 325 326 * guess models 327 328 * merge sources (new -> old) 329 330 * linear fit to the psf 331 332 * find ApResid 333 334 * assign common positions 335 336 * radial apertures (** this should be on the PSF-matched images 337 338 * extended analysis (elliptical profile & petrosian) 339 340 * extended fits (sersic, etc) 341 342 * psphot magnitudes 343 344 345 ****** 346 347 the above is all wrong: first, we should be doing the full 348 morphology analysis (ExtendedAnalysis & ExtendedFits) on the CNV or 349 RAW image (as desired optionally), etc. 350 351 In the discussion below, 'BST' (best) means optionally RAW or CNV 352 353 * detection : RAW & CHISQ (of RAW) 354 * moments : used by psf analysis & classification (BST) 355 * rough class : uses moments, not pixels 356 * image quality : uses moments as well 357 * generate PSF : (BST) 358 * guess models (BST) 359 * linear fit (BST) 360 * find ApResid (BST) -- uses sources not pixels 361 * extended analysis (BST) 362 * extended fits (BST) 363 * detection efficiency (BST) 364 365 * somehow need to copy the sources so they point at the pixels on the 366 * OUT image 367 368 * foreach target PSF 369 * radial aperture 370 * convolve to next target PSF 371 372 * somehow need to organize the output file to have the values from 373 * the different PSFs in separate tables (with header info to 374 * specify the size of that PSF) 375 376 */
Note:
See TracChangeset
for help on using the changeset viewer.
