- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src (modified) (1 prop)
-
psphot/src/psphotChoosePSF.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_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/simtest_nebulous_branches/psphot/src
- Property svn:ignore
-
old new 18 18 psphotVersionDefinitions.h 19 19 psphotMomentsStudy 20 psphotPetrosianStudy 21 psphotForced 22 psphotMakePSF 23 psphotStack
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/psphot/src/psphotChoosePSF.c
r23989 r27840 1 1 # include "psphotInternal.h" 2 2 3 void psphotCountPSFStars (psArray *sources) { 4 5 int nPSF = 0; 6 7 // select the candidate PSF stars (pointers to original sources) 8 for (int i = 0; i < sources->n; i++) { 9 pmSource *source = sources->data[i]; 10 if (source->mode & PM_SOURCE_MODE_PSFSTAR) { 11 nPSF ++; 12 } 13 } 14 15 fprintf (stderr, "N PSF: %d\n", nPSF); 3 // generate a PSF model for inputs without PSF models already loaded 4 bool psphotChoosePSF (pmConfig *config, const pmFPAview *view) 5 { 6 bool status = true; 7 8 // select the appropriate recipe information 9 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 10 psAssert (recipe, "missing recipe?"); 11 12 int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); 13 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 14 15 // skip the chisq image (optionally?) 16 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 17 if (!status) chisqNum = -1; 18 19 // loop over the available readouts 20 for (int i = 0; i < num; i++) { 21 if (i == chisqNum) continue; // skip chisq image 22 if (!psphotChoosePSFReadout (config, view, "PSPHOT.INPUT", i, recipe)) { 23 psError (PSPHOT_ERR_CONFIG, false, "failed to choose a psf model for PSPHOT.INPUT entry %d", i); 24 return false; 25 } 26 } 27 return true; 16 28 } 17 29 18 30 // try PSF models and select best option 19 pmPSF *psphotChoosePSF (pmReadout *readout, psArray *sources, psMetadata *recipe) {31 bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) { 20 32 21 33 bool status; 22 34 23 35 psTimerStart ("psphot.choose.psf"); 36 37 // find the currently selected readout 38 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest 39 psAssert (file, "missing file?"); 40 41 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 42 psAssert (readout, "missing readout?"); 43 44 // do not generate a PSF if we already were supplied one 45 if (psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF")) { 46 psLogMsg ("psphot", PS_LOG_DETAIL, "psf model supplied for input file %d", index); 47 return true; 48 } 49 50 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 51 psAssert (detections, "missing detections?"); 52 53 psArray *sources = detections->newSources; 54 psAssert (sources, "missing sources?"); 55 56 if (!sources->n) { 57 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping PSF model"); 58 return false; 59 } 24 60 25 61 // bit-masks to test for good/bad pixels 26 62 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); 27 assert (maskVal);63 psAssert (maskVal, "missing mask value?"); 28 64 29 65 // bit-mask to mark pixels not used in analysis 30 66 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 31 assert (markVal);67 psAssert (markVal, "missing mark value?"); 32 68 33 69 // maskVal is used to test for rejected pixels, and must include markVal … … 73 109 // get the fixed PSF fit radius 74 110 // XXX check that PSF_FIT_RADIUS < SKY_OUTER_RADIUS 75 options->radius = psMetadataLookupF32 (&status, recipe, "PSF_FIT_RADIUS"); 76 assert (status); 77 78 // XXX ROBUST seems to be too agressive given the small numbers. 79 // options->stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 80 options->stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 111 // options->radius = psMetadataLookupF32 (&status, recipe, "PSF_FIT_RADIUS"); 112 // assert (status); 113 114 // values on readout->analysis if we have calculated a Gaussian window function, use that 115 // for both the PSF fit radius and the aperture radius (scaling SIGMA), otherwise base the value on the recipe value for MOMENTS_GAUSS_SIGMA 116 float gaussSigma = psMetadataLookupF32 (&status, readout->analysis, "MOMENTS_GAUSS_SIGMA"); 117 if (!status) { 118 gaussSigma = psMetadataLookupF32 (&status, recipe, "MOMENTS_GAUSS_SIGMA"); 119 } 120 float fitScale = psMetadataLookupF32(&status, recipe, "PSF_FIT_RADIUS_SCALE"); 121 float apScale = psMetadataLookupF32(&status, recipe, "PSF_APERTURE_SCALE"); 122 options->fitRadius = (int)(fitScale*gaussSigma); 123 options->apRadius = (int)(apScale*gaussSigma); 124 125 // XXX use the same radii for standard analysis as for the PSF creation 126 psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "PSF_FIT_RADIUS", PS_META_REPLACE, "fit radius", options->fitRadius); 127 psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "PSF_APERTURE", PS_META_REPLACE, "psf aperture", options->apRadius); 81 128 82 129 // dimensions of the field for which the PSF is defined … … 99 146 100 147 psArray *stars = psArrayAllocEmpty (sources->n); 101 102 // psphotCountPSFStars (sources);103 148 104 149 // select the candidate PSF stars (pointers to original sources) … … 115 160 } 116 161 117 // psphotCountPSFStars (sources);118 119 162 // check that the identified psf stars sufficiently cover the region; if not, extend the 120 163 // limits somewhat 121 164 psphotCheckStarDistribution (stars, sources, options); 122 165 123 // psphotCountPSFStars (sources);124 125 166 psLogMsg ("psphot.pspsf", PS_LOG_DETAIL, "selected candidate %ld PSF objects\n", stars->n); 167 168 if (stars->n < 50) { 169 // ROBUST is too agressive if we only have a small number of PSF stars 170 options->stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 171 } else { 172 options->stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 173 } 126 174 127 175 // get the list pointers for the PSF_MODEL entries … … 164 212 bool status = true; 165 213 status &= psphotMakeFluxScale (readout->image, recipe, psf); 166 status &= psphotPSFstats (readout, recipe,psf);214 status &= psphotPSFstats (readout, psf); 167 215 if (!status) { 168 216 psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF"); … … 239 287 bool status = true; 240 288 status &= psphotMakeFluxScale (readout->image, recipe, psf); 241 status &= psphotPSFstats (readout, recipe,psf);289 status &= psphotPSFstats (readout, psf); 242 290 if (!status) { 243 291 psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF"); … … 289 337 // XXX test dump of psf star data and psf-subtracted image 290 338 if (psTraceGetLevel("psphot.psfstars") > 5) { 291 psphotDumpPSFStars (readout, try, options-> radius, maskVal, markVal);339 psphotDumpPSFStars (readout, try, options->fitRadius, maskVal, markVal); 292 340 } 293 341 294 342 // save only the best model; 295 // XXX we are not saving the fitted sources296 // XXX do we want to keep them so we may optionally write them out?297 343 pmPSF *psf = psMemIncrRefCounter(try->psf); 298 344 psFree (models); 299 345 300 if (!psphotPSFstats (readout, recipe,psf)) {346 if (!psphotPSFstats (readout, psf)) { 301 347 psError(PSPHOT_ERR_PSF, false, "cannot measure PSF shape terms"); 302 348 psFree(options); … … 305 351 } 306 352 307 // psphotCountPSFStars (sources);308 309 353 char *modelName = pmModelClassGetName (psf->type); 310 354 psLogMsg ("psphot.pspsf", PS_LOG_INFO, "select psf model: %f sec\n", psTimerMark ("psphot.choose.psf")); … … 312 356 313 357 psFree (options); 314 return (psf); 358 359 // save PSF on readout->analysis 360 if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot psf model", psf)) { 361 psError (PSPHOT_ERR_UNKNOWN, false, "problem saving sources on readout"); 362 return false; 363 } 364 psFree (psf); // XXX double-check 365 366 // move into psphotChoosePSF 367 psphotVisualShowPSFModel (readout, psf); 368 369 return true; 315 370 } 316 371 317 372 // measure average parameters of the PSF model 318 bool psphotPSFstats (pmReadout *readout, p sMetadata *recipe, pmPSF *psf) {373 bool psphotPSFstats (pmReadout *readout, pmPSF *psf) { 319 374 320 375 psEllipseShape shape; … … 322 377 323 378 PS_ASSERT_PTR_NON_NULL(readout, false); 324 PS_ASSERT_PTR_NON_NULL(recipe, false);325 379 PS_ASSERT_PTR_NON_NULL(psf, false); 326 380 … … 341 395 // create modelPSF from this model 342 396 pmModel *modelPSF = pmModelFromPSFforXY (psf, xc, yc, 1.0); 343 if (!modelPSF) continue; 397 if (!modelPSF) { 398 fprintf (stderr, "?"); 399 continue; 400 } 344 401 345 402 // get the model full-width at half-max … … 354 411 355 412 float FWHM_MINOR = FWHM_MAJOR * (axes.minor / axes.major); 356 if (!isfinite(FWHM_MAJOR) || !isfinite(FWHM_MINOR)) continue; 413 if (!isfinite(FWHM_MAJOR) || !isfinite(FWHM_MINOR)) { 414 fprintf (stderr, "!"); 415 continue; 416 } 357 417 psVectorAppend (fwhmMajor, FWHM_MAJOR); 358 418 psVectorAppend (fwhmMinor, FWHM_MINOR); … … 366 426 } 367 427 368 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FWHM_MAJ", PS_META_REPLACE, "PSF FWHM Major axis (mean)", stats->sampleMean); 369 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MJ_SG", PS_META_REPLACE, "PSF FWHM Major axis (sigma)", stats->sampleStdev); 370 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MJ_LQ", PS_META_REPLACE, "PSF FWHM Major axis (lower quartile)", stats->sampleLQ); 371 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MJ_UQ", PS_META_REPLACE, "PSF FWHM Major axis (upper quartile)", stats->sampleUQ); 428 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FWHM_MAJ", PS_META_REPLACE, "PSF FWHM Major axis (mean)", stats->sampleMean); 429 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MJ_SG", PS_META_REPLACE, "PSF FWHM Major axis (sigma)", stats->sampleStdev); 430 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MJ_LQ", PS_META_REPLACE, "PSF FWHM Major axis (lower quartile)", stats->sampleLQ); 431 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MJ_UQ", PS_META_REPLACE, "PSF FWHM Major axis (upper quartile)", stats->sampleUQ); 432 433 float fwhmMaj = stats->sampleMean; // FWHM on major axis 372 434 373 435 if (!psVectorStats (stats, fwhmMinor, NULL, NULL, 0)) { … … 375 437 return false; 376 438 } 377 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FWHM_MIN", PS_META_REPLACE, "PSF FWHM Minor axis (mean)", stats->sampleMean); 378 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MN_SG", PS_META_REPLACE, "PSF FWHM Minor axis (sigma)", stats->sampleStdev); 379 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MN_LQ", PS_META_REPLACE, "PSF FWHM Minor axis (lower quartile)", stats->sampleLQ); 380 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MN_UQ", PS_META_REPLACE, "PSF FWHM Minor axis (upper quartile)", stats->sampleUQ); 381 382 psMetadataAddF32 (recipe, PS_LIST_TAIL, "ANGLE", PS_META_REPLACE, "PSF angle", axes.theta); 383 psMetadataAddS32 (recipe, PS_LIST_TAIL, "NPSFSTAR", PS_META_REPLACE, "Number of stars used to make PSF", psf->nPSFstars); 384 psMetadataAddBool(recipe, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "Valid PSF Model?", true); 439 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FWHM_MIN", PS_META_REPLACE, "PSF FWHM Minor axis (mean)", stats->sampleMean); 440 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MN_SG", PS_META_REPLACE, "PSF FWHM Minor axis (sigma)", stats->sampleStdev); 441 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MN_LQ", PS_META_REPLACE, "PSF FWHM Minor axis (lower quartile)", stats->sampleLQ); 442 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MN_UQ", PS_META_REPLACE, "PSF FWHM Minor axis (upper quartile)", stats->sampleUQ); 443 444 float fwhmMin = stats->sampleMean; // FWHM on minor axis 445 if (readout->parent) { 446 pmChip *chip = readout->parent->parent; // Parent chip 447 psAssert(chip, "Cell should be attached to a chip."); 448 psMetadataItem *item = psMetadataLookup(chip->concepts, "CHIP.SEEING"); // Item with chip 449 item->data.F32 = 0.5 * (fwhmMaj + fwhmMin); 450 } 451 452 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "ANGLE", PS_META_REPLACE, "PSF angle", axes.theta); 453 psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NPSFSTAR", PS_META_REPLACE, "Number of stars used to make PSF", psf->nPSFstars); 454 psMetadataAddBool(readout->analysis, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "Valid PSF Model?", true); 385 455 386 456 psFree (fwhmMajor); … … 391 461 392 462 // determine approximate PSF shape parameters based on the moments 393 bool psphotMomentsStats (pmReadout *readout, ps Metadata *recipe, psArray *sources) {463 bool psphotMomentsStats (pmReadout *readout, psArray *sources) { 394 464 395 465 // without the PSF model, we can only rely on the source->moments … … 405 475 406 476 PS_ASSERT_PTR_NON_NULL(readout, false); 407 PS_ASSERT_PTR_NON_NULL(recipe, false);408 477 PS_ASSERT_PTR_NON_NULL(sources, false); 409 478 … … 433 502 FWHM_T /= FWHM_N; 434 503 435 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FWHM_MAJ", PS_META_REPLACE, "PSF FWHM Major axis (mean)", FWHM_X); 436 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MJ_SG", PS_META_REPLACE, "PSF FWHM Major axis (sigma)", 0); 437 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MJ_LQ", PS_META_REPLACE, "PSF FWHM Major axis (lower quartile)", 0); 438 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MJ_UQ", PS_META_REPLACE, "PSF FWHM Major axis (upper quartile)", 0); 439 440 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FWHM_MIN", PS_META_REPLACE, "PSF FWHM Minor axis (mean)", FWHM_Y); 441 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MN_SG", PS_META_REPLACE, "PSF FWHM Minor axis (sigma)", 0); 442 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MN_LQ", PS_META_REPLACE, "PSF FWHM Minor axis (lower quartile)", 0); 443 psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MN_UQ", PS_META_REPLACE, "PSF FWHM Minor axis (upper quartile)", 0); 444 445 psMetadataAddF32 (recipe, PS_LIST_TAIL, "ANGLE", PS_META_REPLACE, "PSF angle", FWHM_T); 446 psMetadataAddS32 (recipe, PS_LIST_TAIL, "NPSFSTAR", PS_META_REPLACE, "Number of stars used to make PSF", 0); 447 psMetadataAddBool(recipe, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "Valid PSF Model?", false); 504 if (readout->parent) { 505 pmChip *chip = readout->parent->parent; // Parent chip 506 psAssert(chip, "Cell should be attached to a chip."); 507 psMetadataItem *item = psMetadataLookup(chip->concepts, "CHIP.SEEING"); // Item with chip 508 item->data.F32 = 0.5 * (FWHM_X + FWHM_Y); 509 } 510 511 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FWHM_MAJ", PS_META_REPLACE, "PSF FWHM Major axis (mean)", FWHM_X); 512 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MJ_SG", PS_META_REPLACE, "PSF FWHM Major axis (sigma)", 0); 513 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MJ_LQ", PS_META_REPLACE, "PSF FWHM Major axis (lower quartile)", 0); 514 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MJ_UQ", PS_META_REPLACE, "PSF FWHM Major axis (upper quartile)", 0); 515 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FWHM_MIN", PS_META_REPLACE, "PSF FWHM Minor axis (mean)", FWHM_Y); 516 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MN_SG", PS_META_REPLACE, "PSF FWHM Minor axis (sigma)", 0); 517 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MN_LQ", PS_META_REPLACE, "PSF FWHM Minor axis (lower quartile)", 0); 518 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MN_UQ", PS_META_REPLACE, "PSF FWHM Minor axis (upper quartile)", 0); 519 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "ANGLE", PS_META_REPLACE, "PSF angle", FWHM_T); 520 psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NPSFSTAR", PS_META_REPLACE, "Number of stars used to make PSF", 0); 521 psMetadataAddBool(readout->analysis, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "Valid PSF Model?", false); 448 522 449 523 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
