Changeset 16820 for trunk/psphot/src/psphotReadout.c
- Timestamp:
- Mar 4, 2008, 3:10:25 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotReadout.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotReadout.c
r16250 r16820 9 9 psTimerStart ("psphotReadout"); 10 10 11 bool dump = (psTraceGetLevel("psphot") >= 6);12 13 11 // select the current recipe 14 12 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE); … … 18 16 } 19 17 20 // Interpret the mask values21 const char *maskValStr = psMetadataLookupStr(NULL, recipe, "MASKVAL"); // String with mask names22 if (!maskValStr) {23 psError(PSPHOT_ERR_CONFIG, false, "Missing recipe item: MASKVAL(STR)");24 return false;25 }26 psMaskType maskVal = pmConfigMask(maskValStr, config); // Mask values to mask against27 psMaskType maskMark = pmConfigMask("MARK", config); // Mask value for marking28 psMaskType maskSat = pmConfigMask("SAT", config); // Mask value for saturated pixels29 psMaskType maskBad = pmConfigMask("BAD", config); // Mask value for bad pixels30 31 // find the currently selected readout32 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT");33 PS_ASSERT_PTR_NON_NULL (readout, false);34 35 // optional break-point for processing36 char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");37 PS_ASSERT_PTR_NON_NULL (breakPt, false);38 39 // Use the new pmFootprints approach?40 const bool useFootprints = psMetadataLookupBool(NULL, recipe, "USE_FOOTPRINTS");41 42 // generate mask & weight images if they don't already exit43 if (!readout->mask) {44 if (!pmReadoutGenerateMask(readout, maskSat, maskBad)) {45 psError (PSPHOT_ERR_CONFIG, false, "trouble creating mask");46 return false;47 }48 }49 if (!readout->weight) {50 if (!pmReadoutGenerateWeight(readout, true)) {51 psError (PSPHOT_ERR_CONFIG, false, "trouble creating weight");52 return false;53 }54 }55 56 18 // set the photcode for this image 57 19 if (!psphotAddPhotcode (recipe, config, view)) { … … 60 22 } 61 23 62 // I have a valid mask, now mask in the analysis region of interest 63 psphotMaskReadout (readout, recipe, maskBad); 64 65 if (psTraceGetLevel("psphot") >= 5) { 66 psphotSaveImage (NULL, readout->image, "image.fits"); 67 psphotSaveImage (NULL, readout->mask, "mask.fits"); 68 psphotSaveImage (NULL, readout->weight, "weight.fits"); 69 } 70 24 // find the currently selected readout 25 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT"); 26 PS_ASSERT_PTR_NON_NULL (readout, false); 27 28 // optional break-point for processing 29 char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT"); 30 PS_ASSERT_PTR_NON_NULL (breakPt, false); 31 32 // Generate the mask and weight images, including the user-defined analysis region of interest 33 psphotSetMaskAndWeight (config, readout, recipe); 71 34 if (!strcasecmp (breakPt, "NOTHING")) { 72 return psphotReadoutCleanup(config, readout, recipe, NULL, NULL );35 return psphotReadoutCleanup(config, readout, recipe, NULL, NULL, NULL); 73 36 } 74 37 75 38 // generate a background model (median, smoothed image) 76 if (!psphotModelBackground (config, view, "PSPHOT.INPUT", maskVal)) { 77 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL); 78 } 79 if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT", maskVal)) { 80 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL); 81 } 82 39 if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) { 40 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL); 41 } 42 if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) { 43 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL); 44 } 83 45 if (!strcasecmp (breakPt, "BACKMDL")) { 84 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL );85 } 86 87 // run a single-model test if desired 88 psphotModelTest (config, view, recipe , maskVal, maskMark);46 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL); 47 } 48 49 // run a single-model test if desired (exits from here if test is run) 50 psphotModelTest (config, view, recipe); 89 51 90 52 // load the psf model, if suppled. FWHM_X,FWHM_Y,etc are saved in the recipe … … 94 56 bool havePSF = (psf != NULL); 95 57 96 // find the peaks in the image. 97 98 // XXX clean this up into a single function. if psf is defined, we should treat this as 99 // pass "2", not "1". re-define this boolean to be "have PSF" 100 psArray *peaks; 101 psArray *footprints = NULL; 102 if (useFootprints) { 103 footprints = psphotFindPeaks (readout, recipe, useFootprints, 1, maskVal); 104 int growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS"); 105 if (growRadius > 0) { 106 psArray *tmp = pmGrowFootprintArray(footprints, growRadius); 107 psFree(footprints); 108 footprints = tmp; 109 } 110 psphotCullPeaks(readout->image, readout->weight, recipe, footprints); 111 112 peaks = pmFootprintArrayToPeaks(footprints); 113 } else { 114 peaks = psphotFindPeaks (readout, recipe, useFootprints, 1, maskVal); 115 } 116 117 if (!peaks) { 118 psLogMsg ("psphot", 3, "unable to find peaks in this image"); 119 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL); 58 // find the detections (by peak and/or footprint) in the image. 59 pmDetections *detections = psphotFindDetections (NULL, readout, recipe); 60 if (!detections) { 61 psLogMsg ("psphot", 3, "unable to find detections in this image"); 62 return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL); 120 63 } 121 64 122 65 // construct sources and measure basic stats 123 psArray *sources = psphotSourceStats (readout, recipe, peaks, maskVal, maskMark);66 psArray *sources = psphotSourceStats (readout, recipe, detections); 124 67 if (!sources) return false; 125 psFree (peaks);126 127 68 if (!strcasecmp (breakPt, "PEAKS")) { 128 return psphotReadoutCleanup(config, readout, recipe, NULL, sources); 129 } 130 69 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources); 70 } 71 72 // find blended neighbors of very saturated stars 73 // XXX merge this with Basic Deblend? 131 74 psphotDeblendSatstars (sources, recipe); 132 75 … … 134 77 if (!psphotBasicDeblend (sources, recipe)) { 135 78 psLogMsg ("psphot", 3, "failed on deblend analysis"); 136 return psphotReadoutCleanup (config, readout, recipe, NULL, sources);79 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 137 80 } 138 81 139 82 // classify sources based on moments, brightness 140 if (!psphotRoughClass (sources, recipe, havePSF , maskSat)) {83 if (!psphotRoughClass (sources, recipe, havePSF)) { 141 84 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 142 return psphotReadoutCleanup (config, readout, recipe, NULL, sources);85 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 143 86 } 144 87 if (!strcasecmp (breakPt, "MOMENTS")) { 145 return psphotReadoutCleanup(config, readout, recipe, NULL, sources);88 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources); 146 89 } 147 90 … … 151 94 // XXX if we do not have enough stars to generate the PSF, build one 152 95 // from the SEEING guess and model class 153 psf = psphotChoosePSF (readout, sources, recipe , maskVal, maskMark);96 psf = psphotChoosePSF (readout, sources, recipe); 154 97 if (psf == NULL) { 155 98 psLogMsg ("psphot", 3, "failure to construct a psf model"); 156 return psphotReadoutCleanup (config, readout, recipe, psf, sources);99 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 157 100 } 158 101 havePSF = true; 159 102 } 160 161 // XXX Test dump of PSF parameters across image field.162 163 103 if (!strcasecmp (breakPt, "PSFMODEL")) { 164 return psphotReadoutCleanup (config, readout, recipe, psf, sources);104 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 165 105 } 166 106 … … 169 109 170 110 // construct an initial model for each object 171 psphotGuessModels (readout, sources, recipe, psf , maskVal);111 psphotGuessModels (readout, sources, recipe, psf); 172 112 173 113 // XXX test output of models 174 114 // psphotTestSourceOutput (readout, sources, recipe, psf); 175 115 176 if (dump) psphotSaveImage (NULL, readout->image, "image.v0.fits"); 177 178 // linear PSF fit to peaks 179 psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE, maskVal); 180 if (dump) psphotSaveImage (NULL, readout->image, "image.v1.fits"); 116 // linear PSF fit to source peaks 117 psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); 181 118 182 119 // XXX test the CR/EXT measurement 183 120 // XXX we need to call this here and after the second pass: option for starting number? 184 psphotSourceSize (readout, sources, recipe); 185 121 psphotSourceSize (readout, sources, recipe, 0); 186 122 if (!strcasecmp (breakPt, "ENSEMBLE")) { 187 123 goto finish; … … 189 125 190 126 // non-linear PSF and EXT fit to brighter sources 191 psphotBlendFit (readout, sources, recipe, psf, maskVal); 192 if (dump) psphotSaveImage (NULL, readout->image, "image.v2.fits"); 193 194 // replace all sources 195 psphotReplaceAll (sources, maskVal); 196 if (dump) psphotSaveImage (NULL, readout->image, "image.v3.fits"); 197 198 // linear PSF fit to remaining peaks 199 psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE, maskVal); 200 if (dump) psphotSaveImage (NULL, readout->image, "image.v4.fits"); 127 psphotBlendFit (readout, sources, recipe, psf); 128 129 // replace all sources (make this part of psphotFitSourcesLinear?) 130 psphotReplaceAll (sources, recipe); 131 132 // linear fit to include all sources 133 psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE); 201 134 if (!strcasecmp (breakPt, "PASS1")) { 202 135 goto finish; … … 210 143 211 144 // add noise for subtracted objects 212 psphotAddNoise (readout, sources, recipe, true, maskVal); 213 214 // find the peaks in the image 215 psArray *newPeaks; 216 if (useFootprints) { 217 psArray *newFootprints = psphotFindPeaks (readout, recipe, useFootprints, 2, maskVal); 218 219 int growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS_2"); 220 if (growRadius > 0) { 221 psArray *tmp = pmGrowFootprintArray(newFootprints, growRadius); 222 psFree(newFootprints); 223 newFootprints = tmp; 224 } 225 226 // merge in old peaks 227 const int includePeaks = 0x0 | 0x2; // i.e. just from newFootprints 228 psArray *mergedFootprints = pmMergeFootprintArrays(footprints, newFootprints, includePeaks); 229 psFree(footprints); 230 psFree(newFootprints); 231 232 psphotCullPeaks(readout->image, readout->weight, recipe, mergedFootprints); 233 234 newPeaks = pmFootprintArrayToPeaks(mergedFootprints); 235 236 psFree(mergedFootprints); 237 } else { 238 newPeaks = psphotFindPeaks(readout, recipe, useFootprints, 2, maskVal); 239 } 145 psphotAddNoise (readout, sources, recipe); 146 147 detections = psphotFindDetections (detections, readout, recipe); 240 148 241 149 // remove noise for subtracted objects 242 psphotAddNoise (readout, sources, recipe, false, maskVal); 243 244 // define new sources based on the new peaks 245 psArray *newSources = psphotSourceStats (readout, recipe, newPeaks, maskVal, maskMark); 246 psFree (newPeaks); 150 psphotSubNoise (readout, sources, recipe); 151 152 // define new sources based on only the new peaks 153 psArray *newSources = psphotSourceStats (readout, recipe, detections); 247 154 248 155 // set source type 249 if (!psphotRoughClass (newSources, recipe, havePSF , maskSat)) {156 if (!psphotRoughClass (newSources, recipe, havePSF)) { 250 157 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 251 return psphotReadoutCleanup (config, readout, recipe, psf, sources);158 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 252 159 } 253 160 254 161 // create full input models 255 psphotGuessModels (readout, newSources, recipe, psf, maskVal); 256 257 // replace all sources 258 psphotReplaceAll (sources, maskVal); 259 if (dump) psphotSaveImage (NULL, readout->image, "image.v5.fits"); 260 261 // merge the newly selected peaks into the existing list 162 psphotGuessModels (readout, newSources, recipe, psf); 163 164 // replace all sources so fit below applies to all at once 165 psphotReplaceAll (sources, recipe); 166 167 // merge the newly selected sources into the existing list 262 168 psphotMergeSources (sources, newSources); 263 169 psFree (newSources); 264 170 265 // linear PSF fit to remaining peaks 266 psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE, maskVal); 267 if (dump) psphotSaveImage (NULL, readout->image, "image.v6.fits"); 268 269 psphotExtendedSources (readout, sources, recipe, maskVal); 171 // linear fit to all sources 172 psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE); 173 174 // measure source size for the remaining sources 175 psphotSourceSize (readout, sources, recipe, 0); 176 177 psphotExtendedSources (readout, sources, recipe); 270 178 271 179 finish: … … 273 181 // plot positive sources 274 182 if (!havePSF) { 275 // psphotSourcePlots (readout, sources, recipe , maskVal);183 // psphotSourcePlots (readout, sources, recipe); 276 184 } 277 185 278 186 // measure aperture photometry corrections 279 if (!havePSF && !psphotApResid (readout, sources, recipe, psf, maskVal, maskMark)) { 280 psTrace ("psphot", 4, "failure on psphotApResid"); 281 psError(PSPHOT_ERR_PHOTOM, false, "Measure aperture photometry corrections"); 282 return false; 187 if (!havePSF && !psphotApResid (readout, sources, recipe, psf)) { 188 psLogMsg ("psphot", 3, "failed on psphotApResid"); 189 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 283 190 } 284 191 285 192 // calculate source magnitudes 286 193 pmReadout *background = psphotSelectBackground (config, view, false); 287 psphotMagnitudes(sources, recipe, psf, background , maskVal, maskMark);194 psphotMagnitudes(sources, recipe, psf, background); 288 195 289 196 // replace failed sources? … … 297 204 298 205 // create the exported-metadata and free local data 299 return psphotReadoutCleanup(config, readout, recipe, psf, sources);206 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources); 300 207 }
Note:
See TracChangeset
for help on using the changeset viewer.
