Changeset 21108
- Timestamp:
- Jan 12, 2009, 4:14:01 PM (17 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 3 edited
-
psphot.h (modified) (2 diffs)
-
psphotDiagnosticPlots.c (modified) (1 diff)
-
psphotModelBackground.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphot.h
r20938 r21108 213 213 bool psphotKapaClose (); 214 214 bool psphotImageBackgroundCellHistogram (psVector *values, float mean, float sigma, int ix, int iy); 215 bool psphotDiagnosticPlots ( pmConfig *config,char *name, ...);215 bool psphotDiagnosticPlots (const pmConfig *config, const char *name, ...); 216 216 217 217 bool psphotMakeFluxScale (psImage *image, psMetadata *recipe, pmPSF *psf); … … 222 222 int psphotSupplementStars (psArray *stars, psArray *sources, psImageBinning *binning, int ix, int iy); 223 223 224 225 // Create a background model for a readout 226 // Essentially identical to psphotModelBackground, but with a more convenient API for outsiders. 227 psImage *psphotBackgroundModel(pmReadout *ro, // Readout for which to generate background model 228 const pmConfig *config // Configuration 229 ); 230 231 224 232 #endif -
trunk/psphot/src/psphotDiagnosticPlots.c
r18846 r21108 135 135 } 136 136 137 bool psphotDiagnosticPlots ( pmConfig *config,char *name, ...) {137 bool psphotDiagnosticPlots (const pmConfig *config, const char *name, ...) { 138 138 139 139 va_list argPtr; -
trunk/psphot/src/psphotModelBackground.c
r20770 r21108 1 1 # include "psphotInternal.h" 2 2 static int npass = 0; 3 4 // generate the median in NxN boxes, clipping heavily 5 // linear interpolation to generate full-scale model 6 bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filename) 3 static char *defaultStatsName = "FITTED_MEAN"; 4 5 // Determine the binning characteristics for the background model 6 // Sets the ruff image size and skip based on recipe values for the binning 7 static psImageBinning *backgroundBinning(const psImage *image, // Image for which to generate a bg model 8 const pmConfig *config // Configuration 9 ) 7 10 { 8 11 bool status = true; 9 static char *defaultStatsName = "FITTED_MEAN"; 10 12 13 // select the appropriate recipe information 14 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 15 assert (recipe); 16 17 // I have the fine image size, I know the binning factor, determine the ruff image size 18 psImageBinning *binning = psImageBinningAlloc(); 19 binning->nXfine = image->numCols; 20 binning->nYfine = image->numRows; 21 binning->nXbin = psMetadataLookupS32(&status, recipe, "BACKGROUND.XBIN"); 22 binning->nYbin = psMetadataLookupS32(&status, recipe, "BACKGROUND.YBIN"); 23 24 psImageBinningSetRuffSize(binning, PS_IMAGE_BINNING_CENTER); 25 psImageBinningSetSkip(binning, image); 26 27 return binning; 28 } 29 30 // Generate the background model 31 static bool backgroundModel(psImage *model, // Model image 32 psImage *modelStdev, // Model stdev image 33 psImage *image, // Image for which to generate a background model 34 psImage *mask, // Mask for image 35 psImageBinning *binning, // Binning parameters 36 const pmConfig *config // Configuration 37 ) 38 { 11 39 psTimerStart ("psphot.background"); 12 40 13 // find the currently selected readout 14 pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename); 15 pmFPA *inFPA = file->fpa; 16 pmReadout *readout = pmFPAviewThisReadout (view, inFPA); 17 psImage *image = readout->image; 18 psImage *mask = readout->mask; 41 bool status = true; 19 42 20 43 // select the appropriate recipe information … … 116 139 *statsDefaults = *stats; 117 140 118 // I have the fine image size, I know the binning factor, determine the ruff image size 119 psImageBinning *binning = psImageBinningAlloc(); 120 binning->nXfine = image->numCols; 121 binning->nYfine = image->numRows; 122 binning->nXbin = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN"); 123 binning->nYbin = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN"); 124 125 psImageBinningSetRuffSize(binning, PS_IMAGE_BINNING_CENTER); 126 psImageBinningSetSkip(binning, image); 141 // we save the binning structure for use in psphotMagnitudes 127 142 status = psMetadataAddPtr(recipe, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning); 128 143 PS_ASSERT (status, false); 129 144 130 // we save the binning structure for use in psphotMagnitudes 131 pmReadout *model = pmFPAGenerateReadout (config, view, "PSPHOT.BACKMDL", inFPA, binning); 132 pmReadout *modelStdev = pmFPAGenerateReadout (config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning); 133 134 psF32 **modelData = model->image->data.F32; 135 psF32 **modelStdevData = modelStdev->image->data.F32; 145 146 psF32 **modelData = model->data.F32; 147 psF32 **modelStdevData = modelStdev->data.F32; 136 148 137 149 // XXXX we can thread this here by running blocks in parallel … … 140 152 psRegion ruffRegion = {0,0,0,0}; 141 153 psRegion fineRegion = {0,0,0,0}; 142 for (int iy = 0; iy < model-> image->numRows; iy++) {143 for (int ix = 0; ix < model-> image->numCols; ix++) {154 for (int iy = 0; iy < model->numRows; iy++) { 155 for (int ix = 0; ix < model->numCols; ix++) { 144 156 145 157 // convert the ruff grid cell to the equivalent fine grid cell … … 229 241 char name[256]; 230 242 sprintf (name, "backraw.%02d.fits", npass); 231 psphotSaveImage (NULL, model ->image, name);243 psphotSaveImage (NULL, model, name); 232 244 } 233 245 … … 237 249 double Value = 0; // sum of good pixel's value 238 250 double ValueStdev = 0; // sum of good pixel's standard deviations 239 for (int iy = 0; iy < model-> image->numRows; iy++) {240 for (int ix = 0; ix < model-> image->numCols; ix++) {251 for (int iy = 0; iy < model->numRows; iy++) { 252 for (int ix = 0; ix < model->numCols; ix++) { 241 253 if (!isnan(modelData[iy][ix])) { 242 254 Value += modelData[iy][ix]; … … 250 262 for (int jy = iy - 1; jy <= iy + 1; jy++) { 251 263 if (jy < 0) continue; 252 if (jy >= model-> image->numRows) continue;264 if (jy >= model->numRows) continue; 253 265 for (int jx = ix - 1; jx <= ix + 1; jx++) { 254 266 if (!jx && !jy) continue; 255 267 if (jx < 0) continue; 256 if (jx >= model-> image->numCols) continue;268 if (jx >= model->numCols) continue; 257 269 value += modelData[jy][jx]; 258 270 count += 1.0; … … 275 287 276 288 // patch over remaining bad regions (use global average) 277 for (int iy = 0; iy < model-> image->numRows; iy++) {278 for (int ix = 0; ix < model-> image->numCols; ix++) {289 for (int iy = 0; iy < model->numRows; iy++) { 290 for (int ix = 0; ix < model->numCols; ix++) { 279 291 if (!isnan(modelData[iy][ix])) continue; 280 292 modelData[iy][ix] = Value; … … 294 306 PS_STAT_MIN | 295 307 PS_STAT_MAX); 296 psImageStats (statsBck, model ->image, NULL, 0);308 psImageStats (statsBck, model, NULL, 0); 297 309 psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MN", 298 310 PS_META_REPLACE, "sky model mean", statsBck->sampleMean); … … 304 316 PS_META_REPLACE, "sky model minimum value", statsBck->min); 305 317 psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NX", 306 PS_META_REPLACE, "sky model size (x)", model-> image->numCols);318 PS_META_REPLACE, "sky model size (x)", model->numCols); 307 319 psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NY", 308 PS_META_REPLACE, "sky model size (y)", model-> image->numRows);320 PS_META_REPLACE, "sky model size (y)", model->numRows); 309 321 psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f", 310 322 statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev); … … 316 328 psFree(rng); 317 329 330 return model; 331 } 332 333 334 335 psImage *psphotBackgroundModel(pmReadout *ro, const pmConfig *config) 336 { 337 PM_ASSERT_READOUT_NON_NULL(ro, NULL); 338 PM_ASSERT_READOUT_IMAGE(ro, NULL); 339 PS_ASSERT_PTR_NON_NULL(config, NULL); 340 341 psImageBinning *binning = backgroundBinning(ro->image, config); // Image binning parameters 342 psImage *model = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Background model 343 psImage *modelStdev = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Standard deviation 344 345 if (!backgroundModel(model, modelStdev, ro->image, ro->mask, binning, config)) { 346 psFree(model); 347 psFree(modelStdev); 348 psError(PS_ERR_UNKNOWN, false, "Unable to generate background model"); 349 return NULL; 350 } 351 352 psFree(modelStdev); 353 354 return model; 355 } 356 357 358 // generate the median in NxN boxes, clipping heavily 359 // linear interpolation to generate full-scale model 360 bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filename) 361 { 362 bool status = true; 363 364 // find the currently selected readout 365 pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename); 366 pmFPA *inFPA = file->fpa; 367 pmReadout *readout = pmFPAviewThisReadout (view, inFPA); 368 psImage *image = readout->image; 369 psImage *mask = readout->mask; 370 371 psImageBinning *binning = backgroundBinning(image, config); // Image binning parameters 372 pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning); 373 pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning); 374 375 if (!backgroundModel(model->image, modelStdev->image, image, mask, binning, config)) { 376 psError(PS_ERR_UNKNOWN, false, "Unable to generate background model"); 377 return false; 378 } 379 318 380 npass ++; 319 381 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
