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