- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src (modified) (1 prop)
-
psphot/src/psphotModelBackground.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/psphot
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psphot merged eligible /branches/eam_branches/stackphot.20100406/psphot 27622-27655 /branches/pap_delete/psphot 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/psphot/src
- Property svn:ignore
-
old new 19 19 psphotMomentsStudy 20 20 psphotPetrosianStudy 21 psphotForced 22 psphotMakePSF 23 psphotStack
-
- Property svn:ignore
-
branches/tap_branches/psphot/src/psphotModelBackground.c
r24188 r27838 5 5 // Determine the binning characteristics for the background model 6 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 model7 psImageBinning *psphotBackgroundBinning(const psImage *image, // Image for which to generate a bg model 8 8 const pmConfig *config // Configuration 9 9 ) … … 28 28 } 29 29 30 30 31 // Generate the background model 31 static bool backgroundModel(psImage *model, // Model image 32 psImage *modelStdev, // Model stdev image 33 psMetadata *analysis, // Analysis metadata for outputs 34 pmReadout *readout, // Readout for which to generate a background model 35 psImageBinning *binning, // Binning parameters 36 const pmConfig *config // Configuration 37 ) 32 // generate the median in NxN boxes, clipping heavily 33 // linear interpolation to generate full-scale model 34 // 35 // NOTE that the 'analysis' metedata pass in here is used to store the binning information. 36 // This may be the analysis for this readout, but it may be the analysis for the pmFPAfile 37 // corresponding to the model. Other information about the background model is saved on the 38 // readout->analysis 39 static bool psphotModelBackgroundReadout(psImage *model, // Model image 40 psImage *modelStdev, // Model stdev image 41 psMetadata *analysis, // Analysis metadata for outputs 42 pmReadout *readout, // Readout for which to generate a background model 43 psImageBinning *binning, // Binning parameters 44 const pmConfig *config // Configuration 45 ) 38 46 { 39 47 psTimerStart ("psphot.background"); … … 137 145 138 146 // we save the binning structure for use in psphotMagnitudes 139 psMetadataAddPtr(analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", 140 PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning); 147 psMetadataAddPtr(analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning); 141 148 142 149 psF32 **modelData = model->data.F32; … … 144 151 145 152 // XXXX we can thread this here by running blocks in parallel 153 154 int nFailures = 0; 155 psImageBackgroundInit(); 146 156 147 157 // measure clipped median for subimages … … 211 221 stats->options = PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV; 212 222 if (!psImageBackground(stats, &sample, subset, submask, maskVal, rng)) { 213 psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for " 214 "(%dx%d, (row0,col0) = (%d,%d)", 215 subset->numRows, subset->numCols, subset->row0, subset->col0); 223 if ((nFailures < 3) || (nFailures % 100 == 0)) { 224 psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for " 225 "(%dx%d, (row0,col0) = (%d,%d)", 226 subset->numRows, subset->numCols, subset->row0, subset->col0); 227 } 228 nFailures ++; 216 229 modelData[iy][ix] = modelStdevData[iy][ix] = NAN; 217 230 } else { … … 232 245 psFree (submask); 233 246 } 247 } 248 249 if (nFailures) { 250 psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background for %d of %d subimages", nFailures, (model->numRows*model->numCols)); 234 251 } 235 252 … … 293 310 psLogMsg ("psphot", PS_LOG_INFO, "built background image: %f sec\n", psTimerMark ("psphot.background")); 294 311 295 psMetadataAddF32(re cipe, PS_LIST_TAIL, "SKY_MEAN", PS_META_REPLACE, "sky mean", Value);296 psMetadataAddF32(re cipe, PS_LIST_TAIL, "SKY_STDEV", PS_META_REPLACE, "sky stdev", ValueStdev);312 psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "SKY_MEAN", PS_META_REPLACE, "sky mean", Value); 313 psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "SKY_STDEV", PS_META_REPLACE, "sky stdev", ValueStdev); 297 314 psLogMsg ("psphot", PS_LOG_INFO, "image sky : mean %f stdev %f", Value, ValueStdev); 298 315 … … 303 320 PS_STAT_MAX); 304 321 psImageStats (statsBck, model, NULL, 0); 305 psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MN", 306 PS_META_REPLACE, "sky model mean", statsBck->sampleMean); 307 psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_SIG", 308 PS_META_REPLACE, "sky model stdev", statsBck->sampleStdev); 309 psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MAX", 310 PS_META_REPLACE, "sky model maximum value", statsBck->max); 311 psMetadataAddF32 (recipe, PS_LIST_TAIL, "MSKY_MIN", 312 PS_META_REPLACE, "sky model minimum value", statsBck->min); 313 psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NX", 314 PS_META_REPLACE, "sky model size (x)", model->numCols); 315 psMetadataAddS32 (recipe, PS_LIST_TAIL, "MSKY_NY", 316 PS_META_REPLACE, "sky model size (y)", model->numRows); 322 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "MSKY_MN", PS_META_REPLACE, "sky model mean", statsBck->sampleMean); 323 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "MSKY_SIG", PS_META_REPLACE, "sky model stdev", statsBck->sampleStdev); 324 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "MSKY_MAX", PS_META_REPLACE, "sky model maximum value", statsBck->max); 325 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "MSKY_MIN", PS_META_REPLACE, "sky model minimum value", statsBck->min); 326 psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "MSKY_NX", PS_META_REPLACE, "sky model size (x)", model->numCols); 327 psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "MSKY_NY", PS_META_REPLACE, "sky model size (y)", model->numRows); 317 328 psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f", 318 329 statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev); … … 327 338 } 328 339 329 330 331 psImage *psphotBackgroundModel(pmReadout *ro, const pmConfig *config) 340 // generate a background model for a single readout. do not save an associated pmFPAfile for possible output 341 psImage *psphotModelBackgroundReadoutNoFile(pmReadout *readout, const pmConfig *config) 332 342 { 333 PM_ASSERT_READOUT_NON_NULL(r o, NULL);334 PM_ASSERT_READOUT_IMAGE(r o, NULL);343 PM_ASSERT_READOUT_NON_NULL(readout, NULL); 344 PM_ASSERT_READOUT_IMAGE(readout, NULL); 335 345 PS_ASSERT_PTR_NON_NULL(config, NULL); 336 346 337 psImageBinning *binning = backgroundBinning(ro->image, config); // Image binning parameters347 psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters 338 348 psImage *model = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Background model 339 349 psImage *modelStdev = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Standard deviation 340 350 341 if (! backgroundModel(model, modelStdev, ro->analysis, ro, binning, config)) {351 if (!psphotModelBackgroundReadout(model, modelStdev, readout->analysis, readout, binning, config)) { 342 352 psFree(model); 343 353 psFree(modelStdev); … … 345 355 return NULL; 346 356 } 347 348 357 psFree(modelStdev); 349 350 358 return model; 351 359 } 352 360 353 354 // generate the median in NxN boxes, clipping heavily 355 // linear interpolation to generate full-scale model 356 bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filename) 361 // generate a background model for readout number index; save an associated pmFPAfile for possible output 362 bool psphotModelBackgroundReadoutFileIndex (pmConfig *config, const pmFPAview *view, const char *filename, int index) 357 363 { 358 bool status = true;359 360 364 // find the currently selected readout 361 pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename); 365 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest 366 psAssert (file, "missing file?"); 367 362 368 pmFPA *inFPA = file->fpa; 363 369 pmReadout *readout = pmFPAviewThisReadout(view, inFPA); 364 365 psImageBinning *binning = backgroundBinning(readout->image, config); // Image binning parameters 366 pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning); 367 pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning); 368 369 if (!backgroundModel(model->image, modelStdev->image, model->analysis, readout, binning, config)) { 370 psAssert (readout, "missing readout?"); 371 372 psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters 373 pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning, index); 374 pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning, index); 375 376 if (!psphotModelBackgroundReadout(model->image, modelStdev->image, model->analysis, readout, binning, config)) { 370 377 psError(PS_ERR_UNKNOWN, false, "Unable to generate background model"); 371 378 return false; … … 375 382 return true; 376 383 } 384 385 // XXX supply filename or keep PSPHOT.INPUT fixed? 386 bool psphotModelBackground (pmConfig *config, const pmFPAview *view) 387 { 388 bool status = false; 389 390 int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); 391 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 392 393 // loop over the available readouts 394 for (int i = 0; i < num; i++) { 395 if (!psphotModelBackgroundReadoutFileIndex(config, view, "PSPHOT.INPUT", i)) { 396 psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i); 397 return false; 398 } 399 } 400 return true; 401 }
Note:
See TracChangeset
for help on using the changeset viewer.
