- Timestamp:
- Dec 17, 2010, 9:57:34 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/psphot/src/psphotStackReadout.c
r30027 r30101 1 1 # include "psphotInternal.h" 2 2 3 // we have 3 possible real filesets: 3 4 # define STACK_RAW "PSPHOT.STACK.INPUT.RAW" 4 5 # define STACK_CNV "PSPHOT.STACK.INPUT.CNV" 5 # define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE" 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 6 12 7 13 bool psphotStackReadout (pmConfig *config, const pmFPAview *view) { … … 21 27 PS_ASSERT_PTR_NON_NULL (breakPt, false); 22 28 23 BST = RAW : CNV; 29 // XXX or do I set OUT to be a pmFPAfile pointing at the input of interest? 30 bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW"); 31 char *STACK_SRC = useRaw ? STACK_RAW : STACK_CNV; 32 char *STACK_DET = STACK_RAW; // XXX optionally allow this to be CNV? 24 33 25 34 // we have 3 relevant files: RAW, CNV, OUT 26 35 27 36 // set the photcode for each image 28 if (!psphotAddPhotcode (config, view, STACK_ BST)) {37 if (!psphotAddPhotcode (config, view, STACK_SRC)) { 29 38 psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode"); 30 39 return false; … … 33 42 // Generate the mask and weight images 34 43 // XXX this should be done before we perform the convolutions 35 if (!psphotSetMaskAndVariance (config, view, STACK_ RAW)) {36 return psphotReadoutCleanup (config, view, STACK_ OUT);44 if (!psphotSetMaskAndVariance (config, view, STACK_DET)) { 45 return psphotReadoutCleanup (config, view, STACK_SRC); 37 46 } 38 47 if (!strcasecmp (breakPt, "NOTHING")) { 39 return psphotReadoutCleanup (config, view, STACK_ OUT);48 return psphotReadoutCleanup (config, view, STACK_SRC); 40 49 } 41 50 … … 43 52 // XXX I think this is not defined correctly for an array of images. 44 53 // XXX probably need to subtract the model (same model?) for both RAW and OUT 45 if (!psphotModelBackground (config, view, STACK_ RAW)) {46 return psphotReadoutCleanup (config, view, STACK_ OUT);47 } 48 if (!psphotSubtractBackground (config, view, STACK_ RAW)) {49 return psphotReadoutCleanup (config, view, STACK_ OUT);54 if (!psphotModelBackground (config, view, STACK_DET)) { 55 return psphotReadoutCleanup (config, view, STACK_SRC); 56 } 57 if (!psphotSubtractBackground (config, view, STACK_DET)) { 58 return psphotReadoutCleanup (config, view, STACK_SRC); 50 59 } 51 60 if (!strcasecmp (breakPt, "BACKMDL")) { 52 return psphotReadoutCleanup (config, view, STACK_OUT); 53 } 54 55 // load the psf model, if suppled. FWHM_X,FWHM_Y,etc are determined and saved on 56 // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT 57 if (!psphotLoadPSF (config, view, STACK_RAW)) { 58 psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model"); 59 return psphotReadoutCleanup (config, view, STACK_OUT); 60 } 61 62 if (!psphotStackChisqImage(config, view, STACK_RAW, STACK_OUT)) { 61 return psphotReadoutCleanup (config, view, STACK_SRC); 62 } 63 64 if (!psphotStackChisqImage(config, view, STACK_DET, STACK_SRC)) { 63 65 psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image"); 64 return psphotReadoutCleanup (config, view, STACK_ OUT);66 return psphotReadoutCleanup (config, view, STACK_SRC); 65 67 } 66 68 if (!strcasecmp (breakPt, "CHISQ")) { 67 return psphotReadoutCleanup (config, view, STACK_ OUT);69 return psphotReadoutCleanup (config, view, STACK_SRC); 68 70 } 69 71 70 72 // find the detections (by peak and/or footprint) in the image. 71 73 // This finds the detections on Chisq image as well as the individuals 72 if (!psphotFindDetections (config, view, STACK_ RAW, true)) { // pass 174 if (!psphotFindDetections (config, view, STACK_DET, true)) { // pass 1 73 75 // this only happens if we had an error in psphotFindDetections 74 76 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 75 return psphotReadoutCleanup (config, view, STACK_OUT); 76 } 77 78 // copy the detections from RAW to OUT 79 if (!psphotCopySources (config, view, STACK_OUT, STACK_RAW)) { 80 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 81 return psphotReadoutCleanup (config, view, STACK_OUT); 77 return psphotReadoutCleanup (config, view, STACK_SRC); 78 } 79 80 // copy the detections from DET to SRC 81 if (strcmp(STACK_SRC, STACK_DET)) { 82 if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) { 83 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 84 return psphotReadoutCleanup (config, view, STACK_SRC); 85 } 82 86 } 83 87 84 88 // construct sources and measure basic stats (saved on detections->newSources) 85 // only run this on detections from the input images, not chisq image 86 if (!psphotSourceStats (config, view, STACK_OUT, true)) { // pass 1 89 if (!psphotSourceStats (config, view, STACK_SRC, true)) { // pass 1 87 90 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 88 return psphotReadoutCleanup (config, view, STACK_ OUT);91 return psphotReadoutCleanup (config, view, STACK_SRC); 89 92 } 90 93 91 94 // generate the objects (object unify the sources from the different images) 92 psArray *objects = psphotMatchSources (config, view, STACK_OUT); 95 // XXX this could just match the detections for the chisq image, and not bother measuring the 96 // source stats in that case... 97 psArray *objects = psphotMatchSources (config, view, STACK_SRC); 93 98 94 99 // construct sources for the newly-generated sources (from other images) 95 if (!psphotSourceStats (config, view, STACK_ OUT, false)) { // pass 1100 if (!psphotSourceStats (config, view, STACK_SRC, false)) { // pass 1 96 101 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 97 return psphotReadoutCleanup (config, view, STACK_ OUT);102 return psphotReadoutCleanup (config, view, STACK_SRC); 98 103 } 99 104 … … 101 106 // if (!psphotDeblendSatstars (config, view)) { 102 107 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 103 // return psphotReadoutCleanup (config, view, STACK_ OUT);108 // return psphotReadoutCleanup (config, view, STACK_SRC); 104 109 // } 105 110 … … 107 112 // if (!psphotBasicDeblend (config, view)) { 108 113 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis"); 109 // return psphotReadoutCleanup (config, view, STACK_ OUT);114 // return psphotReadoutCleanup (config, view, STACK_SRC); 110 115 // } 111 116 112 117 // classify sources based on moments, brightness 113 118 // only run this on detections from the input images, not chisq image 114 if (!psphotRoughClass (config, view, STACK_ OUT)) {119 if (!psphotRoughClass (config, view, STACK_SRC)) { 115 120 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 116 return psphotReadoutCleanup (config, view, STACK_ OUT);121 return psphotReadoutCleanup (config, view, STACK_SRC); 117 122 } 118 123 // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources) 119 124 // only run this on detections from the input images, not chisq image 120 if (!psphotImageQuality (config, view, STACK_ OUT)) { // pass 1125 if (!psphotImageQuality (config, view, STACK_SRC)) { // pass 1 121 126 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); 122 return psphotReadoutCleanup (config, view, STACK_ OUT);127 return psphotReadoutCleanup (config, view, STACK_SRC); 123 128 } 124 129 if (!strcasecmp (breakPt, "MOMENTS")) { 125 return psphotReadoutCleanup (config, view, STACK_ OUT);130 return psphotReadoutCleanup (config, view, STACK_SRC); 126 131 } 127 132 128 133 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 129 134 // this step is skipped 130 if (!psphotChoosePSF (config, view, STACK_ OUT)) { // pass 1135 if (!psphotChoosePSF (config, view, STACK_SRC)) { // pass 1 131 136 psLogMsg ("psphot", 3, "failure to construct a psf model"); 132 return psphotReadoutCleanup (config, view, STACK_ OUT);137 return psphotReadoutCleanup (config, view, STACK_SRC); 133 138 } 134 139 if (!strcasecmp (breakPt, "PSFMODEL")) { 135 return psphotReadoutCleanup (config, view, STACK_ OUT);140 return psphotReadoutCleanup (config, view, STACK_SRC); 136 141 } 137 142 138 143 // construct an initial model for each object, set the radius to fitRadius, set circular fit mask 139 psphotGuessModels (config, view, STACK_ OUT);144 psphotGuessModels (config, view, STACK_SRC); 140 145 141 146 // merge the newly selected sources into the existing list 142 147 // NOTE: merge OLD and NEW 143 psphotMergeSources (config, view, STACK_ OUT);148 psphotMergeSources (config, view, STACK_SRC); 144 149 145 150 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) … … 147 152 148 153 // identify CRs and extended sources 149 psphotSourceSize (config, view, STACK_ OUT, TRUE);154 psphotSourceSize (config, view, STACK_SRC, TRUE); 150 155 151 156 // measure aperture photometry corrections 152 if (!psphotApResid (config, view, STACK_ OUT)) {157 if (!psphotApResid (config, view, STACK_SRC)) { 153 158 psFree (objects); 154 159 psLogMsg ("psphot", 3, "failed on psphotApResid"); 155 return psphotReadoutCleanup (config, view, STACK_ OUT);160 return psphotReadoutCleanup (config, view, STACK_SRC); 156 161 } 157 162 158 163 psphotStackObjectsUnifyPosition (objects); 159 164 160 // measure circular, radial apertures (objects sorted by S/N)161 psphotRadialAperturesByObject (config, objects, view, STACK_OUT);162 163 165 // measure elliptical apertures, petrosians (objects sorted by S/N) 164 psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_ OUT); // pass 1 (detections->allSources)166 psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_SRC); // pass 1 (detections->allSources) 165 167 166 168 // measure non-linear extended source models (exponential, deVaucouleur, Sersic) (sources sorted by S/N) 167 psphotExtendedSourceFits (config, view, STACK_ OUT); // pass 1 (detections->allSources)169 psphotExtendedSourceFits (config, view, STACK_SRC); // pass 1 (detections->allSources) 168 170 169 171 // calculate source magnitudes 170 psphotMagnitudes(config, view, STACK_OUT); 172 psphotMagnitudes(config, view, STACK_SRC); 173 174 // copy the detections from SRC to OUT (for radial aperture photometry) 175 if (!psphotCopySources (config, view, STACK_OUT, STACK_SRC)) { 176 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 177 return psphotReadoutCleanup (config, view, STACK_SRC); 178 } 179 // XXX need to do something to reassign the source pixels here 180 181 bool smoothAgain = true; 182 for (int nMatchedPSF = 0; smoothAgain; nMatchedPSF++) { 183 // measure circular, radial apertures (objects sorted by S/N) 184 psphotRadialAperturesByObject (config, objects, view, STACK_OUT, nMatchedPSF); 185 psphotStackMatchPSFsNext(&smoothAgain, config, view, STACK_OUT, nMatchedPSF); 186 } 171 187 172 188 if (0 && !psphotEfficiency(config, view, STACK_OUT)) { … … 179 195 180 196 // replace background in residual image 181 psphotSkyReplace (config, view, STACK_ RAW);197 psphotSkyReplace (config, view, STACK_DET); 182 198 183 199 // drop the references to the image pixels held by each source 184 psphotSourceFreePixels (config, view, STACK_OUT); 185 186 // remove chisq image from config->file:PSPHOT.INPUT (why?) 187 psphotStackRemoveChisqFromInputs(config, STACK_RAW); 200 // psphotSourceFreePixels (config, view, STACK_OUT); 201 psphotSourceFreePixels (config, view, STACK_SRC); 202 203 // remove chisq image from config->file:PSPHOT.INPUT 204 psphotStackRemoveChisqFromInputs(config, STACK_DET); 205 if (strcmp(STACK_SRC, STACK_DET)) { 206 psphotStackRemoveChisqFromInputs(config, STACK_SRC); 207 } 188 208 189 209 psFree (objects); 190 210 191 211 // create the exported-metadata and free local data 192 return psphotReadoutCleanup (config, view, STACK_ OUT);212 return psphotReadoutCleanup (config, view, STACK_SRC); 193 213 } 194 214 … … 258 278 ****** 259 279 260 the above is all wrong: first, we s ohould be doing the full280 the above is all wrong: first, we should be doing the full 261 281 morphology analysis (ExtendedAnalysis & ExtendedFits) on the CNV or 262 282 RAW image (as desired optionally), etc.
Note:
See TracChangeset
for help on using the changeset viewer.
