Changeset 5772 for trunk/psphot/src/psphotApplyPSF.c
- Timestamp:
- Dec 13, 2005, 6:43:44 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotApplyPSF.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotApplyPSF.c
r5131 r5772 2 2 3 3 // fit psf model to all objects 4 // PSFSTAR objects will be refitted5 // run this function to a specific flux limit?6 7 4 bool psphotApplyPSF (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) 8 5 { 9 bool status;10 6 float x; 11 7 float y; 12 int Nfit = 0;13 int Nsub = 0;8 int Nfit = 0; 9 int Nsub = 0; 14 10 int Niter = 0; 15 11 16 12 psTimerStart ("psphot"); 17 13 18 // we may set this differently here from the value used to mark likely saturated stars 19 float SATURATION = psMetadataLookupF32 (&status, config, "SATURATION"); 20 float OUTER_RADIUS = psMetadataLookupF32 (&status, config, "SKY_OUTER_RADIUS"); 21 22 float PSF_MIN_SN = psMetadataLookupF32 (&status, config, "PSF_MIN_SN"); 23 float PSF_MAX_CHI = psMetadataLookupF32 (&status, config, "PSF_MAX_CHI"); 24 float PSF_FIT_NSIGMA = psMetadataLookupF32 (&status, config, "PSF_FIT_NSIGMA"); 25 float PSF_FIT_PADDING = psMetadataLookupF32 (&status, config, "PSF_FIT_PADDING"); 26 float PSF_SHAPE_NSIGMA = psMetadataLookupF32 (&status, config, "PSF_SHAPE_NSIGMA"); 27 28 // set the object surface-brightness limit for fitted pixels 29 float FLUX_LIMIT = PSF_FIT_NSIGMA * sky->sampleStdev; 30 psLogMsg ("psphot.apply_psf_model", 4, "fitting pixels with at least %f object counts\n", FLUX_LIMIT); 31 32 // this function specifies the radius at this the model hits the given flux 33 pmModelRadius modelRadius = pmModelRadius_GetFunction (psf->type); 14 psphotInitLimitsPSF (config); 15 psphotInitRadiusPSF (config, sky, psf->type); 34 16 35 17 for (int i = 0; i < sources->n; i++) { … … 38 20 39 21 // skip non-astronomical objects (very likely defects) 40 // XXX EAM : should we try these anyway?22 if (source->mode & PM_SOURCE_BLEND) continue; 41 23 if (source->type == PM_SOURCE_DEFECT) continue; 42 24 if (source->type == PM_SOURCE_SATURATED) continue; … … 47 29 // set PSF parameters for this model 48 30 pmModel *model = pmModelFromPSF (modelFLT, psf); 31 psFree (modelFLT); 32 33 source->modelPSF = model; 34 35 // sets the model radius (via source->model) and adjusts pixels as needed 36 psphotCheckRadiusPSF (imdata, source); 37 49 38 x = model->params->data.F32[2]; 50 39 y = model->params->data.F32[3]; 51 psFree (modelFLT);52 40 53 // set the fit radius based on the object flux limit and the model54 // XXX EAM : FLUX_LIMIT should be set based on local sky model (not global median)55 model->radius = modelRadius (model->params, FLUX_LIMIT) + PSF_FIT_PADDING;56 if (isnan(model->radius)) {57 psAbort ("apply_psf_model", "error in radius");58 }59 60 // check if we need to redefine the pixels61 // XXX EAM : a better test would examine the source pixels62 if (model->radius > OUTER_RADIUS) {63 // (re)-allocate image, weight, mask arrays for each peak (square of radius OUTER)64 psphotDefinePixels (source, imdata, x, y, model->radius);65 }66 67 // if (i > 66) psTraceSetLevel (".psLib.dataManip.psMinimizeLMChi2", 5);68 69 41 // fit PSF model (set/unset the pixel mask) 70 42 psImageKeepCircle (source->mask, x, y, model->radius, "OR", PSPHOT_MASK_MARKED); 71 status =pmSourceFitModel (source, model, true);43 pmSourceFitModel (source, model, true); 72 44 psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PSPHOT_MASK_MARKED); 73 45 74 if (!status || (model->params->data.F32[1] < 0)) {75 psLogMsg ("psphot", 5, "PSF fit failed for %f, %f (%d iterations)\n", x, y, model->nIter);76 source->type = PM_SOURCE_FAIL_FIT_PSF; // better choice?77 psFree (model);78 continue;79 }80 // XXX EAM : this was an attempt to correct for fit-sky biases81 // pmModelSkyOffset (model, x, y, model->radius);82 83 // model succeeded : tentatively keep it84 source->modelPSF = model;85 46 Niter += model[0].nIter; 86 47 Nfit ++; 87 48 88 // is it a good model? 89 psphotMarkPSF (source, PSF_SHAPE_NSIGMA, PSF_MIN_SN, PSF_MAX_CHI, SATURATION); 90 if (psphotSubtractPSF (source)) { 91 Nsub ++; 49 // check if model fit is acceptable 50 if (psphotEvalPSF (source)) { 51 pmSourceSubModel (source->pixels, source->mask, source->modelPSF, false, false); 52 source->mode |= PM_SOURCE_SUBTRACTED; 53 Nsub ++; 92 54 } 93 55 } 94 56 95 57 psLogMsg ("psphot", 3, "fit PSF models: %f sec for %d objects (%d total iterations)\n", psTimerMark ("psphot"), Nfit, Niter); 96 psLogMsg ("psphot", 4, "subtracted %d PSF objects\n", Nsub);58 psLogMsg ("psphot", 4, "subtracted %d PSF models\n", Nsub); 97 59 return (true); 98 60 }
Note:
See TracChangeset
for help on using the changeset viewer.
