Changeset 30141
- Timestamp:
- Dec 21, 2010, 3:01:12 PM (15 years ago)
- Location:
- branches/eam_branches/ipp-20101205/psphot/src
- Files:
-
- 8 edited
-
psphot.h (modified) (3 diffs)
-
psphotChoosePSF.c (modified) (4 diffs)
-
psphotCleanup.c (modified) (1 diff)
-
psphotReadoutKnownSources.c (modified) (1 diff)
-
psphotReplaceUnfit.c (modified) (2 diffs)
-
psphotSourceMatch.c (modified) (3 diffs)
-
psphotStackMatchPSFsNext.c (modified) (5 diffs)
-
psphotStackReadout.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/psphot/src/psphot.h
r30101 r30141 75 75 bool psphotImageQualityReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 76 76 77 bool psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule );78 bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe );77 bool psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule, bool newSources); 78 bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool newSources); 79 79 80 80 bool psphotGuessModels (pmConfig *config, const pmFPAview *view, const char *filerule); … … 404 404 bool psphotStackMatchPSFsReadout (pmConfig *config, const pmFPAview *view, psphotStackOptions *options, int index); 405 405 bool psphotStackMatchPSFsPrepare (pmConfig *config, const pmFPAview *view, psphotStackOptions *options, int index); 406 bool psphotStackMatchPSFsNext (bool *smoothAgain, pmConfig *config, const pmFPAview *view, const char *filerule, int nextSize);407 bool psphotStackMatchPSFsNextReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, float currentFWHM, float targetFWHM);406 bool psphotStackMatchPSFsNext (bool *smoothAgain, pmConfig *config, const pmFPAview *view, const char *filerule, int lastSize); 407 bool psphotStackMatchPSFsNextReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, psVector *fwhmValues, int lastSize); 408 408 409 409 // psphotStackMatchPSFsUtils … … 443 443 bool psphotCleanInputs (pmConfig *config, const pmFPAview *view, const char *filerule); 444 444 445 bool psphotResetModels (pmConfig *config, const pmFPAview *view, const char *filerule); 446 bool psphotResetModelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 447 448 bool psphotRedefinePixels (pmConfig *config, const pmFPAview *view, const char *filerule); 449 bool psphotRedefinePixelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 450 445 451 #endif 452 -
branches/eam_branches/ipp-20101205/psphot/src/psphotChoosePSF.c
r30108 r30141 2 2 3 3 // generate a PSF model for inputs without PSF models already loaded 4 bool psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule )4 bool psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule, bool newSources) 5 5 { 6 6 bool status = true; … … 19 19 for (int i = 0; i < num; i++) { 20 20 if (i == chisqNum) continue; // skip chisq image 21 if (!psphotChoosePSFReadout (config, view, filerule, i, recipe )) {21 if (!psphotChoosePSFReadout (config, view, filerule, i, recipe, newSources)) { 22 22 psError (PSPHOT_ERR_CONFIG, false, "failed to choose a psf model for %s entry %d", filerule, i); 23 23 return false; … … 28 28 29 29 // try PSF models and select best option 30 bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe ) {30 bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool newSources) { 31 31 32 32 bool status; … … 50 50 psAssert (detections, "missing detections?"); 51 51 52 psArray *sources = detections->newSources;52 psArray *sources = newSources ? detections->newSources : detections->allSources; 53 53 psAssert (sources, "missing sources?"); 54 54 -
branches/eam_branches/ipp-20101205/psphot/src/psphotCleanup.c
r29548 r30141 22 22 pmVisualCleanup (); 23 23 psLibFinalize(); 24 //fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "psphot");25 fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "psphot");24 fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "psphot"); 25 // fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "psphot"); 26 26 return; 27 27 } -
branches/eam_branches/ipp-20101205/psphot/src/psphotReadoutKnownSources.c
r29936 r30141 43 43 } 44 44 45 if (!psphotChoosePSF (config, view, filerule )) {45 if (!psphotChoosePSF (config, view, filerule, true)) { 46 46 psError(PSPHOT_ERR_PSF, false, "Failed to construct a psf model"); 47 47 return psphotReadoutCleanup (config, view, filerule); -
branches/eam_branches/ipp-20101205/psphot/src/psphotReplaceUnfit.c
r29936 r30141 75 75 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 76 76 } 77 78 psphotVisualShowImage(readout); 77 79 psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); 78 80 return true; … … 101 103 return true; 102 104 } 105 106 // modify the sources to point at the corresponding pixels for the given filerule 107 bool psphotRedefinePixels (pmConfig *config, const pmFPAview *view, const char *filerule) 108 { 109 bool status = true; 110 111 // select the appropriate recipe information 112 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 113 psAssert (recipe, "missing recipe?"); 114 115 int num = psphotFileruleCount(config, filerule); 116 117 // loop over the available readouts 118 for (int i = 0; i < num; i++) { 119 if (!psphotRedefinePixelsReadout (config, view, filerule, i, recipe)) { 120 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 121 return false; 122 } 123 } 124 return true; 125 } 126 127 bool psphotRedefinePixelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 128 129 bool status; 130 pmSource *source; 131 132 psTimerStart ("psphot.replace"); 133 134 // find the currently selected readout 135 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 136 psAssert (file, "missing file?"); 137 138 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 139 psAssert (readout, "missing readout?"); 140 141 // XXX the sources have already been copied (merge into here?) 142 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 143 psAssert (detections, "missing detections?"); 144 145 psArray *sources = detections->allSources; 146 psAssert (sources, "missing sources?"); 147 148 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 149 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 150 psAssert (maskVal, "missing mask value?"); 151 152 for (int i = 0; i < sources->n; i++) { 153 source = sources->data[i]; 154 155 // sources have not yet been subtracted in this image (but this flag may be raised) 156 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 157 158 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 159 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 160 float radius = source->modelPSF->fitRadius; 161 if (radius < 1) { 162 fprintf (stderr, "!"); 163 } 164 165 pmSourceRedefinePixels (source, readout, Xo, Yo, radius, true); 166 } 167 return true; 168 } 169 170 // for now, let's store the detections on the readout->analysis for each readout 171 bool psphotResetModels (pmConfig *config, const pmFPAview *view, const char *filerule) 172 { 173 bool status = true; 174 175 // select the appropriate recipe information 176 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 177 psAssert (recipe, "missing recipe?"); 178 179 int num = psphotFileruleCount(config, filerule); 180 181 // loop over the available readouts 182 for (int i = 0; i < num; i++) { 183 if (!psphotResetModelsReadout (config, view, filerule, i, recipe)) { 184 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 185 return false; 186 } 187 } 188 return true; 189 } 190 191 bool psphotResetModelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 192 193 bool status; 194 pmSource *source; 195 196 psTimerStart ("psphot.replace"); 197 198 // find the currently selected readout 199 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 200 psAssert (file, "missing file?"); 201 202 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 203 psAssert (readout, "missing readout?"); 204 205 // XXX the sources have already been copied (merge into here?) 206 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 207 psAssert (detections, "missing detections?"); 208 209 psArray *sources = detections->allSources; 210 psAssert (sources, "missing sources?"); 211 212 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 213 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 214 psAssert (maskVal, "missing mask value?"); 215 216 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 217 psAssert (psf, "missing psf?"); 218 219 for (int i = 0; i < sources->n; i++) { 220 source = sources->data[i]; 221 222 // sources have not yet been subtracted in this image (but this flag may be raised) 223 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 224 225 // the guess central intensity comes from the peak: 226 float Io = source->peak->flux; 227 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 228 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 229 float radius = source->modelPSF->fitRadius; 230 231 // generate a model for this object with Io = 1.0 232 pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io); 233 if (modelPSF == NULL) { 234 psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo); 235 continue; 236 } 237 238 // set the source PSF model 239 psFree (source->modelPSF); 240 source->modelPSF = modelPSF; 241 source->modelPSF->fitRadius = radius; 242 243 pmSourceCacheModel (source, maskVal); // ALLOC x14 (!) 244 } 245 246 // psphotSaveImage(NULL, readoutIn->image, "image.in.fits"); 247 // psphotSaveImage(NULL, readoutOut->image, "image.out.sub.fits"); 248 // psphotVisualShowImage (readout); 249 250 psLogMsg ("psphot.replace", PS_LOG_INFO, "subtracted models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); 251 return true; 252 } 253 -
branches/eam_branches/ipp-20101205/psphot/src/psphotSourceMatch.c
r30096 r30141 243 243 peak->footprint = pmFootprintCopyData(footprint, readout->image); 244 244 245 // the peak does not claim ownership of the footprint (it does not free it). save a copy of this 246 // footprint on detections->footprints so we can free it later 247 psArrayAdd(detections->footprints, 100, peak->footprint); 248 psFree (peak->footprint); 249 245 250 // create a new source 246 251 pmSource *source = pmSourceAlloc(); … … 249 254 250 255 // add the peak 251 source->peak = p sMemIncrRefCounter(peak);256 source->peak = peak; 252 257 253 258 // allocate space for moments … … 261 266 psArrayAdd (detections->newSources, 100, source); 262 267 psFree (source); 263 psFree (peak);264 268 } 265 269 psFree (footprint); -
branches/eam_branches/ipp-20101205/psphot/src/psphotStackMatchPSFsNext.c
r30101 r30141 26 26 } 27 27 28 float targetFWHM = fwhmValues->data.F32[lastSize + 1];29 float currentFWHM = fwhmValues->data.F32[lastSize];30 31 28 int num = psphotFileruleCount(config, filerule); 32 29 … … 36 33 // loop over the available readouts 37 34 for (int i = 0; i < num; i++) { 38 if (!psphotStackMatchPSFsNextReadout (config, view, filerule, i, recipe, currentFWHM, targetFWHM)) {39 psError (PSPHOT_ERR_CONFIG, false, "failed to smooth image %s (%d) to target PSF %f", filerule, i, targetFWHM);35 if (!psphotStackMatchPSFsNextReadout (config, view, filerule, i, recipe, fwhmValues, lastSize)) { 36 psError (PSPHOT_ERR_CONFIG, false, "failed to smooth image %s (%d) to target PSF %f", filerule, i, fwhmValues->data.F32[lastSize+1]); 40 37 psImageConvolveSetThreads(oldThreads); 41 38 return false; … … 47 44 } 48 45 49 bool psphotStackMatchPSFsNextReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, float currentFWHM, float targetFWHM) {46 bool psphotStackMatchPSFsNextReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, psVector *fwhmValues, int lastSize) { 50 47 51 48 bool status = false; … … 70 67 minGauss = 0.5; 71 68 } 69 70 float targetFWHM = fwhmValues->data.F32[lastSize + 1]; 71 float currentFWHM = fwhmValues->data.F32[lastSize]; 72 72 73 73 if (targetFWHM <= currentFWHM) { … … 131 131 // so we save this in a vector. if the vector is not yet defined, create it 132 132 133 psVector *fwhmValues = psMetadataLookupVector(&status, readout->analysis, "STACK.PSF.FWHM.VALUES"); 134 psAssert(fwhmValues, "should already exist.."); 135 psVectorAppend(fwhmValues, targetFWHM); 133 psVector *fwhmValuesOut = psMetadataLookupVector(&status, readout->analysis, "STACK.PSF.FWHM.VALUES"); 134 psAssert(fwhmValuesOut, "should already exist.."); 135 psVectorAppend(fwhmValuesOut, targetFWHM); 136 137 // do not generate a PSF if we already were supplied one 138 pmPSF *psfOld = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 139 if (psfOld) { 140 // save PSF on readout->analysis 141 char psfEntry[64]; 142 snprintf (psfEntry, 64, "PSPHOT.PSF.V%d", lastSize); 143 if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, psfEntry, PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot psf model", psfOld)) { 144 psError (PSPHOT_ERR_UNKNOWN, false, "problem saving sources on readout"); 145 return false; 146 } 147 psMetadataRemoveKey(readout->analysis, "PSPHOT.PSF"); 148 } 136 149 137 150 return true; -
branches/eam_branches/ipp-20101205/psphot/src/psphotStackReadout.c
r30101 r30141 10 10 // SRC (source analysis image) : nominally CNV (optionally RAW) 11 11 // OUT (psf-matched images) : always OUT 12 13 bool psphotStackVisualFilerule(pmConfig *config, const pmFPAview *view, const char *filerule) { 14 15 int num = psphotFileruleCount(config, filerule); 16 17 // loop over the available readouts 18 for (int i = 0; i < num; i++) { 19 20 // find the currently selected readout 21 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest 22 psAssert (file, "missing file?"); 23 24 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 25 psAssert (readout, "missing readout?"); 26 27 psphotVisualShowImage (readout); 28 psphotVisualShowResidualImage (readout); 29 } 30 return true; 31 } 12 32 13 33 bool psphotStackReadout (pmConfig *config, const pmFPAview *view) { … … 92 112 } 93 113 114 if (!strcasecmp (breakPt, "TEST1")) { 115 return psphotReadoutCleanup (config, view, STACK_SRC); 116 } 117 94 118 // generate the objects (object unify the sources from the different images) 95 119 // XXX this could just match the detections for the chisq image, and not bother measuring the … … 97 121 psArray *objects = psphotMatchSources (config, view, STACK_SRC); 98 122 123 if (!strcasecmp (breakPt, "TEST2")) { 124 psFree(objects); 125 return psphotReadoutCleanup (config, view, STACK_SRC); 126 } 127 99 128 // construct sources for the newly-generated sources (from other images) 100 129 if (!psphotSourceStats (config, view, STACK_SRC, false)) { // pass 1 130 psFree(objects); 101 131 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 102 132 return psphotReadoutCleanup (config, view, STACK_SRC); … … 118 148 // only run this on detections from the input images, not chisq image 119 149 if (!psphotRoughClass (config, view, STACK_SRC)) { 150 psFree(objects); 120 151 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 121 152 return psphotReadoutCleanup (config, view, STACK_SRC); … … 124 155 // only run this on detections from the input images, not chisq image 125 156 if (!psphotImageQuality (config, view, STACK_SRC)) { // pass 1 157 psFree(objects); 126 158 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); 127 159 return psphotReadoutCleanup (config, view, STACK_SRC); 128 160 } 129 161 if (!strcasecmp (breakPt, "MOMENTS")) { 162 psFree(objects); 130 163 return psphotReadoutCleanup (config, view, STACK_SRC); 131 164 } … … 133 166 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 134 167 // this step is skipped 135 if (!psphotChoosePSF (config, view, STACK_SRC)) { // pass 1 168 if (!psphotChoosePSF (config, view, STACK_SRC, true)) { // pass 1 169 psFree(objects); 136 170 psLogMsg ("psphot", 3, "failure to construct a psf model"); 137 171 return psphotReadoutCleanup (config, view, STACK_SRC); 138 172 } 139 173 if (!strcasecmp (breakPt, "PSFMODEL")) { 174 psFree(objects); 140 175 return psphotReadoutCleanup (config, view, STACK_SRC); 141 176 } … … 150 185 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 151 186 psphotFitSourcesLinearStack (config, objects, FALSE); 187 psphotStackVisualFilerule(config, view, STACK_SRC); 152 188 153 189 // identify CRs and extended sources … … 174 210 // copy the detections from SRC to OUT (for radial aperture photometry) 175 211 if (!psphotCopySources (config, view, STACK_OUT, STACK_SRC)) { 212 psFree(objects); 176 213 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 177 214 return psphotReadoutCleanup (config, view, STACK_SRC); 178 215 } 179 // XXX need to do something to reassign the source pixels here180 216 181 217 bool smoothAgain = true; 182 218 for (int nMatchedPSF = 0; smoothAgain; nMatchedPSF++) { 219 psphotRedefinePixels (config, view, STACK_OUT); 220 221 psphotChoosePSF (config, view, STACK_OUT, false); 222 223 psphotResetModels (config, view, STACK_OUT); 224 225 psphotFitSourcesLinear (config, view, STACK_OUT, false); 226 183 227 // measure circular, radial apertures (objects sorted by S/N) 184 228 psphotRadialAperturesByObject (config, objects, view, STACK_OUT, nMatchedPSF); 229 230 psphotReplaceAllSources (config, view, STACK_OUT); 231 185 232 psphotStackMatchPSFsNext(&smoothAgain, config, view, STACK_OUT, nMatchedPSF); 186 233 }
Note:
See TracChangeset
for help on using the changeset viewer.
