- Timestamp:
- Jan 25, 2010, 7:52:41 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/psphot.stack.20100120/src/psphotReadout.c
r26643 r26681 3 3 // this should be called by every program that links against libpsphot 4 4 bool psphotInit (void) { 5 6 5 psphotErrorRegister(); // register our error codes/messages 7 6 psphotModelClassInit (); // load implementation-specific models … … 12 11 bool psphotReadout(pmConfig *config, const pmFPAview *view) { 13 12 14 // measure the total elapsed time in psphotReadout. XXX the current threading plan 15 // for psphot envisions threading within psphotReadout, not multiple threads calling 16 // the same psphotReadout. In the current plan, this dtime is the elapsed time used 17 // jointly by the multiple threads, not the total time used by all threads. 13 // measure the total elapsed time in psphotReadout. dtime is the elapsed time used jointly 14 // by the multiple threads, not the total time used by all threads. 18 15 psTimerStart ("psphotReadout"); 19 16 … … 26 23 return false; 27 24 } 25 // optional break-point for processing 26 char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT"); 27 psAssert (breakPt, "configuration error: set BREAK_POINT"); 28 28 29 29 // set the photcode for this image … … 33 33 } 34 34 35 // find the currently selected readout36 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT");37 PS_ASSERT_PTR_NON_NULL (readout, false);38 39 // optional break-point for processing40 char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");41 PS_ASSERT_PTR_NON_NULL (breakPt, false);42 43 35 // Generate the mask and weight images, including the user-defined analysis region of interest 44 psphotSetMaskAndVariance (config, view , recipe);36 psphotSetMaskAndVariance (config, view); 45 37 if (!strcasecmp (breakPt, "NOTHING")) { 46 return psphotReadoutCleanup(config, readout, recipe, NULL, NULL, NULL); 47 } 48 49 // display the image, weight, mask (ch 1,2,3) 50 // XXX move this into the loop above 51 psphotVisualShowImage (readout); 38 return psphotReadoutCleanup(config, view); 39 } 52 40 53 41 // generate a background model (median, smoothed image) 54 42 if (!psphotModelBackground (config, view)) { 55 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);43 return psphotReadoutCleanup (config, view); 56 44 } 57 45 if (!psphotSubtractBackground (config, view)) { 58 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);46 return psphotReadoutCleanup (config, view); 59 47 } 60 48 if (!strcasecmp (breakPt, "BACKMDL")) { 61 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL); 62 } 63 64 // display the backsub and backgnd images 65 // move this inthe the subtract background loop 66 psphotVisualShowBackground (config, view, readout); 49 return psphotReadoutCleanup (config, view); 50 } 67 51 68 52 // run a single-model test if desired (exits from here if test is run) 69 psphotModelTest (config, view, recipe); 53 // XXX drop this and only keep the stand-alone program? 54 // psphotModelTest (config, view, recipe); 70 55 71 56 // load the psf model, if suppled. FWHM_X,FWHM_Y,etc are saved in the recipe 72 pmPSF *psf = psphotLoadPSF (config, view, recipe); 73 74 // several functions below behave differently if we have a PSF model already 75 bool havePSF = (psf != NULL); 76 57 // XXX this needs to save the PSF on the chip->analysis or readout->analysis 58 if (!psphotLoadPSF (config, view, recipe)) { 59 // this only happens if we had a programming error in psphotLoadPSF 60 psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model"); 61 return psphotReadoutCleanup (config, view); 62 } 63 77 64 // find the detections (by peak and/or footprint) in the image. 78 65 if (!psphotFindDetections (config, view)) { 79 66 // this only happens if we had an error in psphotFindDetections 80 67 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 81 return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL); 82 } 68 return psphotReadoutCleanup (config, view); 69 } 70 71 XXX: // need to handle or ignore this !! 83 72 if (!detections->peaks->n) { 84 73 psLogMsg ("psphot", 3, "unable to find detections in this image"); 85 return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);74 return psphotReadoutCleanup (config, view); 86 75 } 87 76 88 77 // construct sources and measure basic stats 89 78 if (!psphotSourceStats (config, view, true)) { 90 // XXX do I need to raise an error here? 91 return false; 79 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 80 return psphotReadoutCleanup (config, view); 92 81 } 93 82 if (!strcasecmp (breakPt, "PEAKS")) { 94 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);83 return psphotReadoutCleanup(config, view); 95 84 } 96 85 97 86 // find blended neighbors of very saturated stars 98 // XXX merge this with Basic Deblend?99 87 if (!psphotDeblendSatstars (config, view)) { 100 ps LogMsg ("psphot", 3, "failed on satstar deblend analysis");101 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);88 psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 89 return psphotReadoutCleanup (config, view); 102 90 } 103 91 104 92 // mark blended peaks PS_SOURCE_BLEND 105 93 if (!psphotBasicDeblend (config, view)) { 106 psLogMsg ("psphot", 3, "failed on deblend analysis"); 107 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 108 } 109 110 // classify sources based on moments, brightness 111 if (!psphotRoughClass (config, view, havePSF)) { 112 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 113 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 94 psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis"); 95 return psphotReadoutCleanup (config, view); 96 } 97 98 // classify sources based on moments, brightness. if a PSF model has been loaded, the PSF 99 // clump defined for it is used not measured 100 if (!psphotRoughClass (config, view)) { 101 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 102 return psphotReadoutCleanup (config, view); 114 103 } 115 104 if (!strcasecmp (breakPt, "MOMENTS")) { 116 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources); 117 } 118 119 if (!havePSF && !psphotImageQuality (recipe, sources)) { 105 return psphotReadoutCleanup(config, view); 106 } 107 108 // if we were not supplied a PSF model, determine the IQ stats here 109 if (!psphotImageQuality (config, view)) { 120 110 psLogMsg("psphot", 3, "failed to measure image quality"); 121 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources); 122 } 123 124 // if we were not supplied a PSF, choose one here 125 if (psf == NULL) { 126 // use bright stellar objects to measure PSF 127 // XXX if we do not have enough stars to generate the PSF, build one 128 // from the SEEING guess and model class 129 if (!psphotChoosePSF (config, view)) { 130 psLogMsg ("psphot", 3, "failure to construct a psf model"); 131 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 132 } 133 havePSF = true; 111 return psphotReadoutCleanup(config, view); 112 } 113 114 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 115 // this step is skipped 116 if (!psphotChoosePSF (config, view)) { 117 psLogMsg ("psphot", 3, "failure to construct a psf model"); 118 return psphotReadoutCleanup (config, view); 134 119 } 135 120 if (!strcasecmp (breakPt, "PSFMODEL")) { 136 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 137 } 138 // move into psphotChoosePSF 139 psphotVisualShowPSFModel (readout, psf); 121 return psphotReadoutCleanup (config, view); 122 } 140 123 141 124 // include externally-supplied sources 125 // XXX hmm... 142 126 psphotLoadExtSources (config, view, sources); 143 127 144 128 // construct an initial model for each object, set the radius to fitRadius, set circular fit mask 145 psphotGuessModels (config, readout, sources, psf);129 psphotGuessModels (config, view); 146 130 147 131 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 148 psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); 149 150 // We have to place these visualizations here because the models are not realized until 151 // psphotGuessModels or fitted until psphotFitSourcesLinear. 152 psphotVisualShowPSFStars (recipe, psf, sources); 132 psphotFitSourcesLinear (config, view, FALSE); 153 133 154 134 // identify CRs and extended sources … … 157 137 goto finish; 158 138 } 159 psphotVisualShowSatStars (recipe, psf, sources);160 139 161 140 // non-linear PSF and EXT fit to brighter sources 162 141 // replace model flux, adjust mask as needed, fit, subtract the models (full stamp) 163 psphotBlendFit (config, readout, sources, psf);142 psphotBlendFit (config, view); 164 143 165 144 // replace all sources 166 psphotReplaceAllSources ( sources, recipe);145 psphotReplaceAllSources (config, view); 167 146 168 147 // linear fit to include all sources (subtract again) 169 psphotFitSourcesLinear ( readout, sources, recipe, psf, TRUE);148 psphotFitSourcesLinear (config, view, TRUE); 170 149 171 150 // if we only do one pass, skip to extended source analysis … … 176 155 177 156 // add noise for subtracted objects 178 psphotAddNoise ( readout, sources, recipe);157 psphotAddNoise (config, view); 179 158 180 159 // find fainter sources (pass 2) 181 detections = psphotFindDetections (detections, readout, recipe); 160 // XXX need to distinguish old from new sources 161 psphotFindDetections (config, view); 182 162 183 163 // remove noise for subtracted objects (ie, return to normal noise level) 184 psphotSubNoise (readout, sources, recipe); 164 // XXX this needs to operate only on the OLD sources 165 psphotSubNoise (config, view); 185 166 186 167 // define new sources based on only the new peaks 187 psArray *newSources = psphotSourceStats (config, readout, detections, false); 168 // XXX need to distinguish old from new sources 169 psphotSourceStats (config, view, false); 188 170 189 171 // set source type 190 if (!psphotRoughClass (config, view , havePSF)) {172 if (!psphotRoughClass (config, view)) { 191 173 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 192 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);174 return psphotReadoutCleanup (config, view); 193 175 } 194 176 195 177 // create full input models, set the radius to fitRadius, set circular fit mask 196 psphotGuessModels (config, readout, newSources, psf); 178 // XXX need to distinguish old from new sources 179 psphotGuessModels (config, view); 197 180 198 181 // replace all sources so fit below applies to all at once 199 psphotReplaceAllSources ( sources, recipe);182 psphotReplaceAllSources (config, view); 200 183 201 184 // merge the newly selected sources into the existing list 202 psphotMergeSources (sources, newSources); 185 // XXX old vs new???? 186 FIX: psphotMergeSources (sources, newSources); 203 187 psFree (newSources); 204 188 205 189 // linear fit to all sources 206 psphotFitSourcesLinear ( readout, sources, recipe, psf, TRUE);190 psphotFitSourcesLinear (config, view, TRUE); 207 191 208 192 pass1finish: … … 211 195 psphotSourceSize (config, view); 212 196 213 psphotExtendedSourceAnalysis (readout, sources, recipe); 214 215 psphotExtendedSourceFits (readout, sources, recipe); 197 FIX: psphotExtendedSourceAnalysis (readout, sources, recipe); 198 FIX: psphotExtendedSourceFits (readout, sources, recipe); 216 199 217 200 finish: … … 221 204 222 205 // measure aperture photometry corrections 223 if (!psphotApResid (config, readout, sources, psf)) {206 FIX: if (!psphotApResid (config, readout, sources, psf)) { 224 207 psLogMsg ("psphot", 3, "failed on psphotApResid"); 225 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);208 return psphotReadoutCleanup (config, view); 226 209 } 227 210 228 211 // calculate source magnitudes 229 psphotMagnitudes(config, readout, view, sources, psf);230 231 if (!psphotEfficiency(config, readout, view, psf, recipe, sources)) {212 FIX: psphotMagnitudes(config, readout, view, sources, psf); 213 214 FIX: if (!psphotEfficiency(config, readout, view, psf, recipe, sources)) { 232 215 psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources"); 233 216 psErrorClear(); … … 238 221 239 222 // replace background in residual image 240 psphotSkyReplace (config, view);223 FIX: psphotSkyReplace (config, view); 241 224 242 225 // drop the references to the image pixels held by each source 243 psphotSourceFreePixels (sources);226 FIX: psphotSourceFreePixels (sources); 244 227 245 228 // create the exported-metadata and free local data 246 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);229 return psphotReadoutCleanup(config, view); 247 230 } 248
Note:
See TracChangeset
for help on using the changeset viewer.
