Changeset 13411
- Timestamp:
- May 17, 2007, 11:53:28 AM (19 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 7 edited
-
psphot.h (modified) (5 diffs)
-
psphotImageMedian.c (modified) (13 diffs)
-
psphotLoadPSF.c (modified) (2 diffs)
-
psphotMergeSources.c (modified) (1 diff)
-
psphotOutput.c (modified) (5 diffs)
-
psphotReadout.c (modified) (3 diffs)
-
psphotSkyReplace.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphot.h
r13374 r13411 17 17 18 18 bool psphotModelTest (pmReadout *readout, psMetadata *recipe); 19 bool psphotReadout (pmConfig *config, pmFPAview *view);19 bool psphotReadout (pmConfig *config, const pmFPAview *view); 20 20 bool psphotReadoutCleanup (pmConfig *config, pmReadout *readout, psMetadata *recipe, pmPSF *psf, psArray *sources); 21 21 bool psphotDefineFiles (pmConfig *config, pmFPAfile *input); … … 26 26 27 27 // psphotReadout functions 28 bool psphotImageMedian (pmConfig *config, pmFPAview *view);28 bool psphotImageMedian (pmConfig *config, const pmFPAview *view); 29 29 psArray *psphotFindPeaks (pmReadout *readout, psMetadata *recipe, 30 30 const bool returnFootprints, const int pass); 31 31 #include "pmFootprint.h" 32 psErrorCode psphotCullPeaks(const psImage *img, const psImage *weight,32 psErrorCode psphotCullPeaks(const psImage *img, const psImage *weight, 33 33 const psMetadata *recipe, psArray *footprints); 34 34 psArray *psphotSourceStats (pmReadout *readout, psMetadata *recipe, psArray *allpeaks); … … 48 48 bool psphotApResid (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf); 49 49 bool psphotMagnitudes (psArray *sources, psMetadata *recipe, pmPSF *psf, pmReadout *background); 50 bool psphotSkyReplace (pmConfig *config, pmFPAview *view);50 bool psphotSkyReplace (pmConfig *config, const pmFPAview *view); 51 51 52 52 // basic support functions … … 68 68 69 69 // output functions 70 bool psphotAddPhotcode (psMetadata *recipe, pmConfig *config, pmFPAview *view);70 bool psphotAddPhotcode (psMetadata *recipe, pmConfig *config, const pmFPAview *view); 71 71 bool psphotDumpMoments (psMetadata *recipe, psArray *sources); 72 72 psMetadata *psphotDefineHeader (psMetadata *recipe); 73 73 int psphotSaveImage (psMetadata *header, psImage *image, char *filename); 74 74 bool psphotDumpConfig (pmConfig *config); 75 pmReadout *psphotSelectBackground (pmConfig *config, pmFPAview *view, const bool stdev);75 pmReadout *psphotSelectBackground (pmConfig *config, const pmFPAview *view, const bool stdev); 76 76 77 77 // PSF / DBL / EXT evaluation functions … … 93 93 94 94 // plotting functions (available if libkapa is installed) 95 bool psphotPlotMoments (pmConfig *config, pmFPAview *view, psArray *sources);96 bool psphotPlotPSFModel (pmConfig *config, pmFPAview *view, psArray *sources);97 bool psphotFitInit ();98 bool psphotFitSummary ();99 bool psphotMergeSources (psArray *oldSources, psArray *newSources);100 bool psphotLoadExtSources (pmConfig *config,pmFPAview *view, psArray *sources);101 pmPSF *psphotLoadPSF (pmConfig *config,pmFPAview *view, psMetadata *recipe);102 bool psphotSetHeaderNstars (psMetadata *recipe, psArray *sources);103 bool psphotAddNoise (pmReadout *readout, psArray *sources, psMetadata *recipe, bool add);104 bool psphotRadialPlot (int *kapa, const char *filename, pmSource *source);105 bool psphotSourcePlots (pmReadout *readout, psArray *sources, psMetadata *recipe);106 bool psphotMosaicSubimage (psImage *outImage, pmSource *source, int Xo, int Yo, int DX, int DY);95 bool psphotPlotMoments (pmConfig *config, pmFPAview *view, psArray *sources); 96 bool psphotPlotPSFModel (pmConfig *config, pmFPAview *view, psArray *sources); 97 bool psphotFitInit (); 98 bool psphotFitSummary (); 99 bool psphotMergeSources (psArray *oldSources, psArray *newSources); 100 bool psphotLoadExtSources (pmConfig *config, const pmFPAview *view, psArray *sources); 101 pmPSF *psphotLoadPSF (pmConfig *config, const pmFPAview *view, psMetadata *recipe); 102 bool psphotSetHeaderNstars (psMetadata *recipe, psArray *sources); 103 bool psphotAddNoise (pmReadout *readout, psArray *sources, psMetadata *recipe, bool add); 104 bool psphotRadialPlot (int *kapa, const char *filename, pmSource *source); 105 bool psphotSourcePlots (pmReadout *readout, psArray *sources, psMetadata *recipe); 106 bool psphotMosaicSubimage (psImage *outImage, pmSource *source, int Xo, int Yo, int DX, int DY); 107 107 108 bool psphotAddWithTest (pmSource *source, bool useState);109 bool psphotSubWithTest (pmSource *source, bool useState);110 bool psphotSetState (pmSource *source, bool curState);111 bool psphotDeblendSatstars (psArray *sources, psMetadata *recipe);108 bool psphotAddWithTest (pmSource *source, bool useState); 109 bool psphotSubWithTest (pmSource *source, bool useState); 110 bool psphotSetState (pmSource *source, bool curState); 111 bool psphotDeblendSatstars (psArray *sources, psMetadata *recipe); 112 112 bool psphotSourceSize (pmReadout *readout, psArray *sources, psMetadata *recipe); 113 113 -
trunk/psphot/src/psphotImageMedian.c
r13013 r13411 2 2 static int npass = 0; 3 3 4 // we have 4 possibilities: (INTERNAL or I/O file) and (exists or not) 4 // we have 4 possibilities: (INTERNAL or I/O file) and (exists or not) 5 5 // select model pixels (from output background model file, or create internal file) 6 6 static pmReadout *get_model_readout(const char *name, // name of internal/external file 7 const pmConfig *config, // configuration information8 pmFPAview *view,9 pmFPA *inFPA,10 const psImageBinning *binning) {7 const pmConfig *config, // configuration information 8 const pmFPAview *view, 9 pmFPA *inFPA, 10 const psImageBinning *binning) { 11 11 pmReadout *model = NULL; 12 12 … … 14 14 pmFPAfile *file = psMetadataLookupPtr(&status, config->files, name); 15 15 if (file == NULL) { 16 // we are not using PSPHOT.BACKMDL as an I/O file: define an internal version16 // we are not using PSPHOT.BACKMDL as an I/O file: define an internal version 17 17 model = pmFPAfileDefineInternal (config->files, name, binning->nXruff, binning->nYruff, PS_TYPE_F32); 18 18 } else { 19 if (file->mode == PM_FPA_MODE_INTERNAL) {20 // we are not using PSPHOT.BACKMDL as an I/O file: already defined above21 model = file->readout;22 } else {23 // we are using PSPHOT.BACKMDL as an I/O file: select readout or create24 model = pmFPAviewThisReadout (view, file->fpa);25 if (model == NULL) {26 // readout does not yet exist: create from input27 // XXX we have an inconsistency in this calculation here and in pmFPACopy28 // XXX use the psImageBinning functions to set the output image size29 pmFPAfileCopyStructureView (file->fpa, inFPA, binning->nXbin, binning->nYbin, view);30 model = pmFPAviewThisReadout (view, file->fpa);31 PS_ASSERT (binning->nXruff == model->image->numCols, false);32 PS_ASSERT (binning->nYruff == model->image->numRows, false);33 }34 }19 if (file->mode == PM_FPA_MODE_INTERNAL) { 20 // we are not using PSPHOT.BACKMDL as an I/O file: already defined above 21 model = file->readout; 22 } else { 23 // we are using PSPHOT.BACKMDL as an I/O file: select readout or create 24 model = pmFPAviewThisReadout (view, file->fpa); 25 if (model == NULL) { 26 // readout does not yet exist: create from input 27 // XXX we have an inconsistency in this calculation here and in pmFPACopy 28 // XXX use the psImageBinning functions to set the output image size 29 pmFPAfileCopyStructureView (file->fpa, inFPA, binning->nXbin, binning->nYbin, view); 30 model = pmFPAviewThisReadout (view, file->fpa); 31 PS_ASSERT (binning->nXruff == model->image->numCols, false); 32 PS_ASSERT (binning->nYruff == model->image->numRows, false); 33 } 34 } 35 35 } 36 36 … … 40 40 // generate the median in NxN boxes, clipping heavily 41 41 // linear interpolation to generate full-scale model 42 bool psphotImageMedian (pmConfig *config, pmFPAview *view)42 bool psphotImageMedian (pmConfig *config, const pmFPAview *view) 43 43 { 44 44 bool status = true; … … 70 70 char *statsName = psMetadataLookupStr (&status, recipe, "SKY_STAT"); 71 71 if (statsName == NULL) { 72 statsName = defaultStatsName;72 statsName = defaultStatsName; 73 73 } 74 74 psStatsOptions statsOptionLocation = psStatsOptionFromString(statsName); 75 75 if (!(statsOptionLocation & (PS_STAT_SAMPLE_MEAN | 76 PS_STAT_SAMPLE_MEDIAN |77 PS_STAT_ROBUST_MEDIAN |78 PS_STAT_ROBUST_QUARTILE |79 PS_STAT_CLIPPED_MEAN |80 PS_STAT_FITTED_MEAN |81 PS_STAT_FITTED_MEAN_V2 |82 PS_STAT_FITTED_MEAN_V3))) {83 statsOptionLocation = PS_STAT_FITTED_MEAN;76 PS_STAT_SAMPLE_MEDIAN | 77 PS_STAT_ROBUST_MEDIAN | 78 PS_STAT_ROBUST_QUARTILE | 79 PS_STAT_CLIPPED_MEAN | 80 PS_STAT_FITTED_MEAN | 81 PS_STAT_FITTED_MEAN_V2 | 82 PS_STAT_FITTED_MEAN_V3))) { 83 statsOptionLocation = PS_STAT_FITTED_MEAN; 84 84 } 85 85 86 86 psStatsOptions statsOptionWidth = PS_STAT_NONE; 87 87 if (statsOptionLocation & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN)) { 88 statsOptionWidth = PS_STAT_SAMPLE_STDEV;88 statsOptionWidth = PS_STAT_SAMPLE_STDEV; 89 89 } else if (statsOptionLocation & (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_QUARTILE)) { 90 90 #if 1 91 statsOptionWidth = PS_STAT_ROBUST_STDEV; // not set; => NaN91 statsOptionWidth = PS_STAT_ROBUST_STDEV; // not set; => NaN 92 92 #else 93 statsOptionWidth = PS_STAT_FITTED_STDEV;93 statsOptionWidth = PS_STAT_FITTED_STDEV; 94 94 #endif 95 95 } else if (statsOptionLocation & PS_STAT_FITTED_MEAN) { 96 statsOptionWidth = PS_STAT_FITTED_STDEV;96 statsOptionWidth = PS_STAT_FITTED_STDEV; 97 97 } else if (statsOptionLocation & PS_STAT_CLIPPED_MEAN) { 98 statsOptionWidth = PS_STAT_CLIPPED_STDEV;98 statsOptionWidth = PS_STAT_CLIPPED_STDEV; 99 99 } else if (statsOptionLocation & PS_STAT_FITTED_MEAN_V2) { 100 statsOptionWidth = PS_STAT_FITTED_STDEV_V2;100 statsOptionWidth = PS_STAT_FITTED_STDEV_V2; 101 101 } else if (statsOptionLocation & PS_STAT_FITTED_MEAN_V3) { 102 statsOptionWidth = PS_STAT_FITTED_STDEV_V3;102 statsOptionWidth = PS_STAT_FITTED_STDEV_V3; 103 103 } else { 104 psAbort("Unable to estimate variance of selected statsOptionLocations 0x%x", statsOptionLocation);104 psAbort("Unable to estimate variance of selected statsOptionLocations 0x%x", statsOptionLocation); 105 105 } 106 106 … … 110 110 // set range for old-version of sky statistic 111 111 if (statsOptionLocation & PS_STAT_ROBUST_QUARTILE) { 112 stats->min = 0.25;113 stats->max = 0.75;112 stats->min = 0.25; 113 stats->max = 0.75; 114 114 } 115 115 … … 130 130 if (!status) { 131 131 if ((stats->options & PS_STAT_FITTED_MEAN) || (stats->options & PS_STAT_FITTED_MEAN_V2)) { 132 stats->clipSigma = 1.0;133 } else {134 stats->clipSigma = 3.0;135 }132 stats->clipSigma = 1.0; 133 } else { 134 stats->clipSigma = 3.0; 135 } 136 136 } 137 137 … … 172 172 for (int iy = 0; iy < model->image->numRows; iy++) { 173 173 for (int ix = 0; ix < model->image->numCols; ix++) { 174 175 // convert the ruff grid cell to the equivalent fine grid cell176 // XXX we need to watch out for row0,col0177 ruffRegion = psRegionSet (ix, ix + 2, iy, iy + 2);178 fineRegion = psImageBinningSetFineRegion (binning, ruffRegion);174 175 // convert the ruff grid cell to the equivalent fine grid cell 176 // XXX we need to watch out for row0,col0 177 ruffRegion = psRegionSet (ix, ix + 2, iy, iy + 2); 178 fineRegion = psImageBinningSetFineRegion (binning, ruffRegion); 179 179 fineRegion = psRegionForImage (image, fineRegion); 180 180 181 181 psImage *subset = psImageSubset (image, fineRegion); 182 if (!subset->numCols || !subset->numRows) {183 psFree (subset);184 continue;185 }182 if (!subset->numCols || !subset->numRows) { 183 psFree (subset); 184 continue; 185 } 186 186 psImage *submask = psImageSubset (mask, fineRegion); 187 187 188 // reset the default values189 *stats = *statsDefaults;188 // reset the default values 189 *stats = *statsDefaults; 190 190 191 191 // Use the selected background statistic for the first pass 192 // If it fails, fall back on the "ROBUST_MEDIAN" version193 // If both fail, set the pixel to NAN and (below) interpolate194 // XXX psImageBackground will probably be renamed psImageStats195 // XXX don't bother trying if there are no valid pixels...196 197 if (psImageBackground(stats, subset, submask, 0xff, rng)) {198 if (stats->options & PS_STAT_ROBUST_QUARTILE) {199 modelData[iy][ix] = stats->robustMedian;200 } else { 201 modelData[iy][ix] = psStatsGetValue(stats, statsOptionLocation);202 }203 modelStdevData[iy][ix] = psStatsGetValue(stats, statsOptionWidth);204 } else {205 psStatsOptions currentOptions = stats->options;206 stats->options = PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV;207 if (!psImageBackground(stats, subset, submask, 0xff, rng)) {208 psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for "209 "(%dx%d, (row0,col0) = (%d,%d)",210 subset->numRows, subset->numCols, subset->row0, subset->col0);211 modelData[iy][ix] = modelStdevData[iy][ix] = NAN;212 } else {213 modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN);214 modelStdevData[iy][ix] = psStatsGetValue(stats, PS_STAT_ROBUST_STDEV);215 }216 // drop errors caused by psImageBackground failures217 // XXX we probably should trap and exit on serious failures218 psErrorClear(); 219 stats->options = currentOptions;220 }221 modelData[iy][ix] += SKY_BIAS;192 // If it fails, fall back on the "ROBUST_MEDIAN" version 193 // If both fail, set the pixel to NAN and (below) interpolate 194 // XXX psImageBackground will probably be renamed psImageStats 195 // XXX don't bother trying if there are no valid pixels... 196 197 if (psImageBackground(stats, subset, submask, 0xff, rng)) { 198 if (stats->options & PS_STAT_ROBUST_QUARTILE) { 199 modelData[iy][ix] = stats->robustMedian; 200 } else { 201 modelData[iy][ix] = psStatsGetValue(stats, statsOptionLocation); 202 } 203 modelStdevData[iy][ix] = psStatsGetValue(stats, statsOptionWidth); 204 } else { 205 psStatsOptions currentOptions = stats->options; 206 stats->options = PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV; 207 if (!psImageBackground(stats, subset, submask, 0xff, rng)) { 208 psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for " 209 "(%dx%d, (row0,col0) = (%d,%d)", 210 subset->numRows, subset->numCols, subset->row0, subset->col0); 211 modelData[iy][ix] = modelStdevData[iy][ix] = NAN; 212 } else { 213 modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN); 214 modelStdevData[iy][ix] = psStatsGetValue(stats, PS_STAT_ROBUST_STDEV); 215 } 216 // drop errors caused by psImageBackground failures 217 // XXX we probably should trap and exit on serious failures 218 psErrorClear(); 219 stats->options = currentOptions; 220 } 221 modelData[iy][ix] += SKY_BIAS; 222 222 psFree (subset); 223 223 psFree (submask); … … 227 227 // patch over bad regions (use average of 8 possible neighbor pixels) 228 228 // XXX consider testing all pixels against the 8 neighbors and replacing outliers... 229 double Count = 0; // number of good pixels230 double Value = 0; // sum of good pixel's value231 double ValueStdev = 0; // sum of good pixel's standard deviations229 double Count = 0; // number of good pixels 230 double Value = 0; // sum of good pixel's value 231 double ValueStdev = 0; // sum of good pixel's standard deviations 232 232 for (int iy = 0; iy < model->image->numRows; iy++) { 233 233 for (int ix = 0; ix < model->image->numCols; ix++) { 234 if (!isnan(modelData[iy][ix])) {235 Value += modelData[iy][ix];236 ValueStdev += modelStdevData[iy][ix];237 Count++;238 continue;239 }240 241 double value = 0;242 double count = 0;243 for (int jy = iy - 1; jy <= iy + 1; jy++) {244 if (jy < 0) continue;245 if (jy >= model->image->numRows) continue;246 for (int jx = ix - 1; jx <= ix + 1; jx++) {247 if (!jx && !jy) continue;248 if (jx < 0) continue;249 if (jx >= model->image->numCols) continue;250 value += modelData[jy][jx];251 count += 1.0;252 }253 }254 if (count > 0) modelData[iy][ix] = value / count;255 }234 if (!isnan(modelData[iy][ix])) { 235 Value += modelData[iy][ix]; 236 ValueStdev += modelStdevData[iy][ix]; 237 Count++; 238 continue; 239 } 240 241 double value = 0; 242 double count = 0; 243 for (int jy = iy - 1; jy <= iy + 1; jy++) { 244 if (jy < 0) continue; 245 if (jy >= model->image->numRows) continue; 246 for (int jx = ix - 1; jx <= ix + 1; jx++) { 247 if (!jx && !jy) continue; 248 if (jx < 0) continue; 249 if (jx >= model->image->numCols) continue; 250 value += modelData[jy][jx]; 251 count += 1.0; 252 } 253 } 254 if (count > 0) modelData[iy][ix] = value / count; 255 } 256 256 } 257 257 assert (Count > 0); 258 258 Value /= Count; 259 259 ValueStdev /= Count; 260 260 261 261 // patch over remaining bad regions (use global average) 262 262 for (int iy = 0; iy < model->image->numRows; iy++) { 263 263 for (int ix = 0; ix < model->image->numCols; ix++) { 264 if (!isnan(modelData[iy][ix])) continue;265 modelData[iy][ix] = Value;266 modelStdevData[iy][ix] = ValueStdev;267 }264 if (!isnan(modelData[iy][ix])) continue; 265 modelData[iy][ix] = Value; 266 modelStdevData[iy][ix] = ValueStdev; 267 } 268 268 } 269 269 … … 273 273 psMetadataAddF32(recipe, PS_LIST_TAIL, "SKY_STDEV", PS_META_REPLACE, "sky stdev", ValueStdev); 274 274 psLogMsg ("psphot", PS_LOG_INFO, "image sky : mean %f stdev %f", Value, ValueStdev); 275 275 276 276 // measure image and background stats and save for later output 277 277 psStats *statsBck = psStatsAlloc (PS_STAT_SAMPLE_MEAN | 278 PS_STAT_SAMPLE_STDEV |279 PS_STAT_MIN |280 PS_STAT_MAX);278 PS_STAT_SAMPLE_STDEV | 279 PS_STAT_MIN | 280 PS_STAT_MAX); 281 281 psImageStats (statsBck, model->image, NULL, 0); 282 282 psMetadataAddF32 (recipe, PS_LIST_TAIL, "SKY_MODEL_MEAN", 283 PS_META_REPLACE, "sky model mean", statsBck->sampleMean);283 PS_META_REPLACE, "sky model mean", statsBck->sampleMean); 284 284 psMetadataAddF32 (recipe, PS_LIST_TAIL, "SKY_MODEL_STDEV", 285 PS_META_REPLACE, "sky model stdev", statsBck->sampleStdev);285 PS_META_REPLACE, "sky model stdev", statsBck->sampleStdev); 286 286 psMetadataAddF32 (recipe, PS_LIST_TAIL, "SKY_MODEL_MAX", 287 PS_META_REPLACE, "sky model maximum value", statsBck->max);287 PS_META_REPLACE, "sky model maximum value", statsBck->max); 288 288 psMetadataAddF32 (recipe, PS_LIST_TAIL, "SKY_MODEL_MIN", 289 PS_META_REPLACE, "sky model minimum value", statsBck->min);289 PS_META_REPLACE, "sky model minimum value", statsBck->min); 290 290 psMetadataAddS32 (recipe, PS_LIST_TAIL, "SKY_MODEL_NX", 291 PS_META_REPLACE, "sky model size (x)", model->image->numCols);291 PS_META_REPLACE, "sky model size (x)", model->image->numCols); 292 292 psMetadataAddS32 (recipe, PS_LIST_TAIL, "SKY_MODEL_NY", 293 PS_META_REPLACE, "sky model size (y)", model->image->numRows);294 psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f", 295 statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev);293 PS_META_REPLACE, "sky model size (y)", model->image->numRows); 294 psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f", 295 statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev); 296 296 psFree (statsBck); 297 297 … … 299 299 file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKGND"); 300 300 if (file) { 301 // we are using PSPHOT.BACKGND as an I/O file: select readout or create302 if (file->mode == PM_FPA_MODE_INTERNAL) {303 background = file->readout;304 } else {305 background = pmFPAviewThisReadout (view, file->fpa);306 }307 if (background == NULL) {308 // readout does not yet exist: create from input309 pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view);310 background = pmFPAviewThisReadout (view, file->fpa);311 if ((image->numCols != background->image->numCols) || (image->numRows != background->image->numRows)) {312 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for background dimensions");313 return false;314 }315 }301 // we are using PSPHOT.BACKGND as an I/O file: select readout or create 302 if (file->mode == PM_FPA_MODE_INTERNAL) { 303 background = file->readout; 304 } else { 305 background = pmFPAviewThisReadout (view, file->fpa); 306 } 307 if (background == NULL) { 308 // readout does not yet exist: create from input 309 pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view); 310 background = pmFPAviewThisReadout (view, file->fpa); 311 if ((image->numCols != background->image->numCols) || (image->numRows != background->image->numRows)) { 312 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for background dimensions"); 313 return false; 314 } 315 } 316 316 } else { 317 317 background = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", image->numCols, image->numRows, PS_TYPE_F32); … … 321 321 // linear interpolation to full-scale 322 322 if (!psImageUnbin (background->image, model->image, binning)) { 323 psError (PSPHOT_ERR_PROG, true, "failed to build background image");324 return false;325 } 326 323 psError (PSPHOT_ERR_PROG, true, "failed to build background image"); 324 return false; 325 } 326 327 327 psLogMsg ("psphot", PS_LOG_MINUTIA, "build resampled image: %f sec\n", psTimerMark ("psphot")); 328 328 … … 330 330 file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKSUB"); 331 331 if (file) { 332 // we are using PSPHOT.BACKSUB as an I/O file: select readout or create333 backSub = pmFPAviewThisReadout (view, file->fpa);334 if (backSub == NULL) {335 // readout does not yet exist: create from input336 pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view);337 backSub = pmFPAviewThisReadout (view, file->fpa);338 }332 // we are using PSPHOT.BACKSUB as an I/O file: select readout or create 333 backSub = pmFPAviewThisReadout (view, file->fpa); 334 if (backSub == NULL) { 335 // readout does not yet exist: create from input 336 pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view); 337 backSub = pmFPAviewThisReadout (view, file->fpa); 338 } 339 339 } 340 340 341 341 if (psTraceGetLevel("psphot") > 5) { 342 char name[256];343 sprintf (name, "image.%02d.fits", npass);344 psphotSaveImage (NULL, image, name);345 sprintf (name, "back.%02d.fits", npass);346 psphotSaveImage (NULL, background->image, name);347 sprintf (name, "mask.%02d.fits", npass);348 psphotSaveImage (NULL, mask, name);349 sprintf (name, "backmdl.%02d.fits", npass);350 psphotSaveImage (NULL, model->image, name);342 char name[256]; 343 sprintf (name, "image.%02d.fits", npass); 344 psphotSaveImage (NULL, image, name); 345 sprintf (name, "back.%02d.fits", npass); 346 psphotSaveImage (NULL, background->image, name); 347 sprintf (name, "mask.%02d.fits", npass); 348 psphotSaveImage (NULL, mask, name); 349 sprintf (name, "backmdl.%02d.fits", npass); 350 psphotSaveImage (NULL, model->image, name); 351 351 } 352 352 … … 354 354 for (int j = 0; j < image->numRows; j++) { 355 355 for (int i = 0; i < image->numCols; i++) { 356 image->data.F32[j][i] -= backData[j][i];357 if (backSub) {358 backSub->image->data.F32[j][i] = image->data.F32[j][i];359 }356 image->data.F32[j][i] -= backData[j][i]; 357 if (backSub) { 358 backSub->image->data.F32[j][i] = image->data.F32[j][i]; 359 } 360 360 } 361 361 } 362 362 363 363 if (psTraceGetLevel("psphot") > 5) { 364 char name[256];365 sprintf (name, "backsub.%02d.fits", npass);366 psphotSaveImage (NULL, image, name);364 char name[256]; 365 sprintf (name, "backsub.%02d.fits", npass); 366 psphotSaveImage (NULL, image, name); 367 367 } 368 368 npass ++; -
trunk/psphot/src/psphotLoadPSF.c
r13225 r13411 2 2 3 3 // load an externally supplied psf model 4 pmPSF *psphotLoadPSF (pmConfig *config, pmFPAview *view, psMetadata *recipe) {4 pmPSF *psphotLoadPSF (pmConfig *config, const pmFPAview *view, psMetadata *recipe) { 5 5 6 6 // find the currently selected readout … … 11 11 pmPSF *psf = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.PSF"); 12 12 if (psf == NULL) { 13 psLogMsg ("psphot", 3, "no psf supplied for this readout");14 return NULL;13 psLogMsg ("psphot", 3, "no psf supplied for this readout"); 14 return NULL; 15 15 } 16 16 -
trunk/psphot/src/psphotMergeSources.c
r13225 r13411 5 5 6 6 for (int i = 0; i < newSources->n; i++) { 7 pmSource *source = newSources->data[i];8 psArrayAdd (oldSources, 100, source);7 pmSource *source = newSources->data[i]; 8 psArrayAdd (oldSources, 100, source); 9 9 } 10 10 return true; 11 11 } 12 12 13 // merge the externally supplied sources with the existing sources. mark them as having 13 // merge the externally supplied sources with the existing sources. mark them as having 14 14 // mode PM_SOURCE_MODE_EXTERNAL 15 bool psphotLoadExtSources (pmConfig *config, pmFPAview *view, psArray *sources) {15 bool psphotLoadExtSources (pmConfig *config, const pmFPAview *view, psArray *sources) { 16 16 17 17 // find the currently selected readout 18 18 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT.CMF"); 19 19 if (!readout) { 20 psLogMsg ("psphot", 3, "no external sources supplied");21 return true;20 psLogMsg ("psphot", 3, "no external sources supplied"); 21 return true; 22 22 } 23 23 24 24 psArray *extSources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES"); 25 25 if (!extSources) { 26 psLogMsg ("psphot", 3, "no external sources for this readout");27 return true;26 psLogMsg ("psphot", 3, "no external sources for this readout"); 27 return true; 28 28 } 29 29 30 30 for (int i = 0; i < extSources->n; i++) { 31 pmSource *source = extSources->data[i];32 source->mode |= PM_SOURCE_MODE_EXTERNAL;33 pmModel *model = source->modelPSF;31 pmSource *source = extSources->data[i]; 32 source->mode |= PM_SOURCE_MODE_EXTERNAL; 33 pmModel *model = source->modelPSF; 34 34 35 float xpos = model->params->data.F32[PM_PAR_XPOS];36 float ypos = model->params->data.F32[PM_PAR_YPOS];35 float xpos = model->params->data.F32[PM_PAR_XPOS]; 36 float ypos = model->params->data.F32[PM_PAR_YPOS]; 37 37 38 source->peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE);39 source->peak->xf = xpos;40 source->peak->yf = ypos;41 source->peak->flux = 1.0;42 43 // drop the loaded source modelPSF44 psFree (source->modelPSF);45 source->modelPSF = NULL;38 source->peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE); 39 source->peak->xf = xpos; 40 source->peak->yf = ypos; 41 source->peak->flux = 1.0; 42 43 // drop the loaded source modelPSF 44 psFree (source->modelPSF); 45 source->modelPSF = NULL; 46 46 } 47 47 -
trunk/psphot/src/psphotOutput.c
r13035 r13411 2 2 3 3 pmReadout *psphotSelectBackground (pmConfig *config, 4 pmFPAview *view,5 const bool stdev // return background's standard deviation?6 ) {4 const pmFPAview *view, 5 const bool stdev // return background's standard deviation? 6 ) { 7 7 8 8 bool status; 9 pmReadout *background; 9 pmReadout *background; 10 10 11 11 pmFPAfile *file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKMDL"); 12 12 if (!file) return NULL; 13 13 if (file->mode == PM_FPA_MODE_INTERNAL) { 14 background = file->readout;14 background = file->readout; 15 15 } else { 16 background = pmFPAviewThisReadout (view, file->fpa);16 background = pmFPAviewThisReadout (view, file->fpa); 17 17 } 18 18 return background; … … 67 67 } 68 68 69 fprintf (f, "%d %d %f %f %d\n", 70 (j + source->pixels->col0),71 (i + source->pixels->row0),72 source->pixels->data.F32[i][j],73 1.0 / source->weight->data.F32[i][j],74 source->maskObj->data.U8[i][j]);69 fprintf (f, "%d %d %f %f %d\n", 70 (j + source->pixels->col0), 71 (i + source->pixels->row0), 72 source->pixels->data.F32[i][j], 73 1.0 / source->weight->data.F32[i][j], 74 source->maskObj->data.U8[i][j]); 75 75 } 76 76 } … … 79 79 } 80 80 81 bool psphotAddPhotcode (psMetadata *recipe, pmConfig *config, pmFPAview *view) {81 bool psphotAddPhotcode (psMetadata *recipe, pmConfig *config, const pmFPAview *view) { 82 82 83 83 bool status; … … 128 128 psMetadataItemSupplement (header, recipe, "SKYBIAS"); 129 129 psMetadataItemSupplement (header, recipe, "SKYSAT"); 130 130 131 131 // PSF model parameters (shape values for image center) 132 132 psMetadataItemSupplement (header, recipe, "NPSFSTAR"); … … 148 148 psMetadataItemSupplement (header, recipe, "SKY_NX"); 149 149 psMetadataItemSupplement (header, recipe, "SKY_NY"); 150 150 151 151 // XXX : don't require any of these about values to exist 152 152 psErrorClear (); -
trunk/psphot/src/psphotReadout.c
r13375 r13411 1 1 # include "psphotInternal.h" 2 2 3 bool psphotReadout (pmConfig *config,pmFPAview *view) {3 bool psphotReadout(pmConfig *config, const pmFPAview *view) { 4 4 5 5 bool dump = (psTraceGetLevel("psphot") >= 6); … … 68 68 int growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS"); 69 69 if (growRadius > 0) { 70 psArray *tmp = pmGrowFootprintArray(footprints, growRadius);71 psFree(footprints);72 footprints = tmp;70 psArray *tmp = pmGrowFootprintArray(footprints, growRadius); 71 psFree(footprints); 72 footprints = tmp; 73 73 } 74 74 psphotCullPeaks(readout->image, readout->weight, recipe, footprints); … … 180 180 int growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS_2"); 181 181 if (growRadius > 0) { 182 psArray *tmp = pmGrowFootprintArray(newFootprints, growRadius);183 psFree(newFootprints);184 newFootprints = tmp;182 psArray *tmp = pmGrowFootprintArray(newFootprints, growRadius); 183 psFree(newFootprints); 184 newFootprints = tmp; 185 185 } 186 186 -
trunk/psphot/src/psphotSkyReplace.c
r12792 r13411 3 3 // XXX make this an option? 4 4 // in order to successfully replace the sky, we must define a corresponding file... 5 bool psphotSkyReplace (pmConfig *config, pmFPAview *view) {5 bool psphotSkyReplace (pmConfig *config, const pmFPAview *view) { 6 6 7 7 psTimerStart ("psphot"); … … 22 22 // replace the background model 23 23 for (int j = 0; j < readout->image->numRows; j++) { 24 for (int i = 0; i < readout->image->numCols; i++) {25 if (!mask[j][i]) {26 image[j][i] += back[j][i];27 }28 }24 for (int i = 0; i < readout->image->numCols; i++) { 25 if (!mask[j][i]) { 26 image[j][i] += back[j][i]; 27 } 28 } 29 29 } 30 30 psLogMsg ("psphot.sky", PS_LOG_DETAIL, "replace background flux : %f sec\n", psTimerMark ("psphot"));
Note:
See TracChangeset
for help on using the changeset viewer.
