Changeset 29936 for trunk/psphot/src/psphotReadout.c
- Timestamp:
- Dec 5, 2010, 9:42:25 PM (16 years ago)
- Location:
- trunk/psphot
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/psphotReadout.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20101103/psphot (added) merged: 29660,29824-29825,29904,29914,29918,29920
- Property svn:mergeinfo changed
-
trunk/psphot/src/psphotReadout.c
r29004 r29936 9 9 } 10 10 11 bool psphotReadout(pmConfig *config, const pmFPAview *view ) {11 bool psphotReadout(pmConfig *config, const pmFPAview *view, const char *filerule) { 12 12 13 13 // measure the total elapsed time in psphotReadout. dtime is the elapsed time used jointly … … 27 27 psAssert (breakPt, "configuration error: set BREAK_POINT"); 28 28 29 // remove cruft from the input analysis structure 30 if (!psphotCleanInputs (config, view, filerule)) { 31 psError (PSPHOT_ERR_PROG, false, "trouble setting up the inputs"); 32 return false; 33 } 34 29 35 // set the photcode for this image 30 if (!psphotAddPhotcode (config, view, "PSPHOT.INPUT")) {36 if (!psphotAddPhotcode (config, view, filerule)) { 31 37 psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode"); 32 38 return false; … … 34 40 35 41 // Generate the mask and weight images, including the user-defined analysis region of interest 36 if (!psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT")) {37 return psphotReadoutCleanup(config, view, "PSPHOT.INPUT");42 if (!psphotSetMaskAndVariance (config, view, filerule)) { 43 return psphotReadoutCleanup(config, view, filerule); 38 44 } 39 45 if (!strcasecmp (breakPt, "NOTHING")) { 40 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");46 return psphotReadoutCleanup (config, view, filerule); 41 47 } 42 48 43 49 // generate a background model (median, smoothed image) 44 if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {45 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");46 } 47 48 if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {49 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");50 if (!psphotModelBackground (config, view, filerule)) { 51 return psphotReadoutCleanup (config, view, filerule); 52 } 53 54 if (!psphotSubtractBackground (config, view, filerule)) { 55 return psphotReadoutCleanup (config, view, filerule); 50 56 } 51 57 if (!strcasecmp (breakPt, "BACKMDL")) { 52 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");58 return psphotReadoutCleanup (config, view, filerule); 53 59 } 54 60 55 61 // load the psf model, if suppled. FWHM_MAJ,FWHM_MIN,etc are determined and saved on 56 // readout->analysis. XXX Note: this function currently only works with a single 57 // PSPHOT.INPUT 58 if (!psphotLoadPSF (config, view)) { // ??? need to supply 2 ? 62 // readout->analysis. NOTE: this function currently only loads from PSPHOT.PSF.LOAD 63 if (!psphotLoadPSF (config, view, filerule)) { // ??? need to supply 2 ? 59 64 psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model"); 60 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");65 return psphotReadoutCleanup (config, view, filerule); 61 66 } 62 67 63 68 // find the detections (by peak and/or footprint) in the image. 64 if (!psphotFindDetections (config, view, "PSPHOT.INPUT", true)) { // pass 169 if (!psphotFindDetections (config, view, filerule, true)) { // pass 1 65 70 // this only happens if we had an error in psphotFindDetections 66 71 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 67 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");72 return psphotReadoutCleanup (config, view, filerule); 68 73 } 69 74 70 75 // construct sources and measure basic stats (saved on detections->newSources) 71 if (!psphotSourceStats (config, view, "PSPHOT.INPUT", true)) { // pass 176 if (!psphotSourceStats (config, view, filerule, true)) { // pass 1 72 77 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 73 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");78 return psphotReadoutCleanup (config, view, filerule); 74 79 } 75 80 if (!strcasecmp (breakPt, "PEAKS")) { 76 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");81 return psphotReadoutCleanup (config, view, filerule); 77 82 } 78 83 79 84 // find blended neighbors of very saturated stars (detections->newSources) 80 if (!psphotDeblendSatstars (config, view, "PSPHOT.INPUT")) {85 if (!psphotDeblendSatstars (config, view, filerule)) { 81 86 psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 82 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");87 return psphotReadoutCleanup (config, view, filerule); 83 88 } 84 89 85 90 // mark blended peaks PS_SOURCE_BLEND (detections->newSources) 86 if (!psphotBasicDeblend (config, view, "PSPHOT.INPUT")) {91 if (!psphotBasicDeblend (config, view, filerule)) { 87 92 psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis"); 88 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");93 return psphotReadoutCleanup (config, view, filerule); 89 94 } 90 95 91 96 // classify sources based on moments, brightness. if a PSF model has been loaded, the PSF 92 97 // clump defined for it is used not measured (detections->newSources) 93 if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) { // pass 198 if (!psphotRoughClass (config, view, filerule)) { // pass 1 94 99 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 95 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");100 return psphotReadoutCleanup (config, view, filerule); 96 101 } 97 102 98 103 // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources) 99 if (!psphotImageQuality (config, view, "PSPHOT.INPUT")) { // pass 1104 if (!psphotImageQuality (config, view, filerule)) { // pass 1 100 105 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); 101 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");106 return psphotReadoutCleanup (config, view, filerule); 102 107 } 103 108 if (!strcasecmp (breakPt, "MOMENTS")) { 104 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");109 return psphotReadoutCleanup (config, view, filerule); 105 110 } 106 111 107 112 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 108 113 // this step is skipped 109 if (!psphotChoosePSF (config, view, "PSPHOT.INPUT")) { // pass 1114 if (!psphotChoosePSF (config, view, filerule)) { // pass 1 110 115 psLogMsg ("psphot", 3, "failure to construct a psf model"); 111 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");116 return psphotReadoutCleanup (config, view, filerule); 112 117 } 113 118 if (!strcasecmp (breakPt, "PSFMODEL")) { 114 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");119 return psphotReadoutCleanup (config, view, filerule); 115 120 } 116 121 117 122 // include externally-supplied sources 118 123 // XXX fix this in the new multi-input context 119 // psphotLoadExtSources (config, view, "PSPHOT.INPUT"); // pass 1124 // psphotLoadExtSources (config, view, filerule); // pass 1 120 125 121 126 // construct an initial model for each object, set the radius to fitRadius, set circular 122 127 // fit mask (detections->newSources) 123 psphotGuessModels (config, view, "PSPHOT.INPUT"); // pass 1128 psphotGuessModels (config, view, filerule); // pass 1 124 129 125 130 // merge the newly selected sources into the existing list 126 131 // NOTE: merge OLD and NEW 127 psphotMergeSources (config, view, "PSPHOT.INPUT");132 psphotMergeSources (config, view, filerule); 128 133 129 134 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 130 psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false); // pass 1 (detections->allSources)135 psphotFitSourcesLinear (config, view, filerule, false); // pass 1 (detections->allSources) 131 136 132 137 // identify CRs and extended sources (only unmeasured sources are measured) 133 psphotSourceSize (config, view, "PSPHOT.INPUT", true); // pass 1 (detections->allSources)138 psphotSourceSize (config, view, filerule, true); // pass 1 (detections->allSources) 134 139 if (!strcasecmp (breakPt, "ENSEMBLE")) { 135 140 goto finish; … … 138 143 // non-linear PSF and EXT fit to brighter sources 139 144 // replace model flux, adjust mask as needed, fit, subtract the models (full stamp) 140 psphotBlendFit (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)145 psphotBlendFit (config, view, filerule); // pass 1 (detections->allSources) 141 146 142 147 // replace all sources 143 psphotReplaceAllSources (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)148 psphotReplaceAllSources (config, view, filerule); // pass 1 (detections->allSources) 144 149 145 150 // linear fit to include all sources (subtract again) 146 151 // NOTE : apply to ALL sources (extended + psf) 147 psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", true); // pass 2 (detections->allSources)152 psphotFitSourcesLinear (config, view, filerule, true); // pass 2 (detections->allSources) 148 153 149 154 // if we only do one pass, skip to extended source analysis … … 153 158 154 159 // add noise for subtracted objects 155 psphotAddNoise (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)160 psphotAddNoise (config, view, filerule); // pass 1 (detections->allSources) 156 161 157 162 // find fainter sources 158 163 // NOTE: finds new peaks and new footprints, OLD and FULL set are saved on detections 159 psphotFindDetections (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->peaks, detections->footprints)164 psphotFindDetections (config, view, filerule, false); // pass 2 (detections->peaks, detections->footprints) 160 165 161 166 // remove noise for subtracted objects (ie, return to normal noise level) 162 167 // NOTE: this needs to operate only on the OLD sources 163 psphotSubNoise (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)168 psphotSubNoise (config, view, filerule); // pass 1 (detections->allSources) 164 169 165 170 // define new sources based on only the new peaks 166 171 // NOTE: new sources are saved on detections->newSources 167 psphotSourceStats (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->newSources)172 psphotSourceStats (config, view, filerule, false); // pass 2 (detections->newSources) 168 173 169 174 // set source type 170 175 // NOTE: apply only to detections->newSources 171 if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) { // pass 2 (detections->newSources)176 if (!psphotRoughClass (config, view, filerule)) { // pass 2 (detections->newSources) 172 177 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 173 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");178 return psphotReadoutCleanup (config, view, filerule); 174 179 } 175 180 176 181 // create full input models, set the radius to fitRadius, set circular fit mask 177 182 // NOTE: apply only to detections->newSources 178 psphotGuessModels (config, view, "PSPHOT.INPUT"); // pass 2 (detections->newSources)183 psphotGuessModels (config, view, filerule); // pass 2 (detections->newSources) 179 184 180 185 // replace all sources so fit below applies to all at once 181 186 // NOTE: apply only to OLD sources (which have been subtracted) 182 psphotReplaceAllSources (config, view, "PSPHOT.INPUT"); // pass 2187 psphotReplaceAllSources (config, view, filerule); // pass 2 183 188 184 189 // merge the newly selected sources into the existing list 185 190 // NOTE: merge OLD and NEW 186 191 // XXX check on free of sources... 187 psphotMergeSources (config, view, "PSPHOT.INPUT"); // (detections->newSources + detections->allSources -> detections->allSources)192 psphotMergeSources (config, view, filerule); // (detections->newSources + detections->allSources -> detections->allSources) 188 193 189 194 // NOTE: apply to ALL sources 190 psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", true); // pass 3 (detections->allSources)195 psphotFitSourcesLinear (config, view, filerule, true); // pass 3 (detections->allSources) 191 196 192 197 pass1finish: … … 194 199 // measure source size for the remaining sources 195 200 // NOTE: applies only to NEW (unmeasured) sources 196 psphotSourceSize (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->allSources)197 198 psphotExtendedSourceAnalysis (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)199 psphotExtendedSourceFits (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)201 psphotSourceSize (config, view, filerule, false); // pass 2 (detections->allSources) 202 203 psphotExtendedSourceAnalysis (config, view, filerule); // pass 1 (detections->allSources) 204 psphotExtendedSourceFits (config, view, filerule); // pass 1 (detections->allSources) 200 205 201 206 finish: … … 205 210 206 211 // measure aperture photometry corrections 207 if (!psphotApResid (config, view, "PSPHOT.INPUT")) { // pass 1 (detections->allSources)212 if (!psphotApResid (config, view, filerule)) { // pass 1 (detections->allSources) 208 213 psLogMsg ("psphot", 3, "failed on psphotApResid"); 209 return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");214 return psphotReadoutCleanup (config, view, filerule); 210 215 } 211 216 212 217 // calculate source magnitudes 213 if (!psphotMagnitudes(config, view, "PSPHOT.INPUT")) { // pass 1 (detections->allSources)218 if (!psphotMagnitudes(config, view, filerule)) { // pass 1 (detections->allSources) 214 219 psErrorStackPrint(stderr, "Unable to do magnitudes."); 215 220 psErrorClear(); 216 221 } 217 if (!psphotEfficiency(config, view, "PSPHOT.INPUT")) { // pass 1222 if (!psphotEfficiency(config, view, filerule)) { // pass 1 218 223 psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources"); 219 224 psErrorClear(); … … 224 229 225 230 // replace background in residual image 226 if (!psphotSkyReplace (config, view, "PSPHOT.INPUT")) { // pass 1231 if (!psphotSkyReplace (config, view, filerule)) { // pass 1 227 232 psErrorStackPrint(stderr, "Unable to replace sky"); 228 233 psErrorClear(); 229 234 230 235 /* psLogMsg("psphot", 3, "failed on psphotSkyReplace"); */ 231 /* return(psphotReadoutCleanup(config, view, "PSPHOT.INPUT")); */236 /* return(psphotReadoutCleanup(config, view, filerule)); */ 232 237 } 233 238 // drop the references to the image pixels held by each source 234 if (!psphotSourceFreePixels (config, view, "PSPHOT.INPUT")) { // pass 1239 if (!psphotSourceFreePixels (config, view, filerule)) { // pass 1 235 240 psErrorStackPrint(stderr, "Unable to free source pixels"); 236 241 psErrorClear(); 237 242 238 243 /* psLogMsg ("psphot", 3, "failed on psphotSourceFreePixels"); */ 239 /* return(psphotReadoutCleanup(config, view, "PSPHOT.INPUT")); */244 /* return(psphotReadoutCleanup(config, view, filerule)); */ 240 245 } 241 246 // create the exported-metadata and free local data 242 return psphotReadoutCleanup(config, view, "PSPHOT.INPUT");247 return psphotReadoutCleanup(config, view, filerule); 243 248 }
Note:
See TracChangeset
for help on using the changeset viewer.
