Changeset 5772 for trunk/psphot/src/psphotFitGalaxies.c
- Timestamp:
- Dec 13, 2005, 6:43:44 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotFitGalaxies.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotFitGalaxies.c
r5672 r5772 3 3 bool psphotFitGalaxies (eamReadout *imdata, psMetadata *config, psArray *sources, psStats *skyStats) 4 4 { 5 bool status , goodfit;5 bool status; 6 6 float x; 7 7 float y; 8 int Nfit = 0;9 int N fail= 0;8 int Nfit = 0; 9 int Nsub = 0; 10 10 int Niter = 0; 11 11 12 float OUTER_RADIUS = psMetadataLookupF32 (&status, config, "SKY_OUTER_RADIUS");12 psTimerStart ("psphot"); 13 13 14 14 float GAL_MIN_SN = psMetadataLookupF32 (&status, config, "GAL_MIN_SN"); 15 float GAL_FIT_NSIGMA = psMetadataLookupF32 (&status, config, "GAL_FIT_NSIGMA");16 float GAL_FIT_PADDING = psMetadataLookupF32 (&status, config, "GAL_FIT_PADDING");17 15 float GAL_MOMENTS_RAD = psMetadataLookupF32 (&status, config, "GAL_MOMENTS_RADIUS"); 16 char *modelName = psMetadataLookupPtr (&status, config, "GAL_MODEL"); 17 pmModelType modelType = pmModelSetType (modelName); 18 18 19 float FLUX_LIMIT = GAL_FIT_NSIGMA * skyStats->sampleStdev; 20 21 char *modelName = psMetadataLookupPtr (&status, config, "GAL_MODEL"); 22 pmModelType modelType = pmModelSetType (modelName); 23 pmModelRadius modelRadius = pmModelRadius_GetFunction (modelType); 24 25 psTimerStart ("psphot"); 19 psphotInitRadiusFLT (config, skyStats, modelType); 26 20 27 21 for (int i = 0; i < sources->n; i++) { 28 22 pmSource *source = sources->data[i]; 29 23 30 // sources which should not be fitted 31 // skip all valid stars 32 if (source->type == PM_SOURCE_PSFSTAR) continue; 33 if (source->type == PM_SOURCE_SATSTAR) continue; 34 if (source->type == PM_SOURCE_GOODSTAR) continue; 24 // only fit suspected extended sources 25 if (source->type != PM_SOURCE_GALAXY) continue; 26 if (source->mode & PM_SOURCE_BLEND) continue; 35 27 36 // skip all likely defects 37 if (source->type == PM_SOURCE_DEFECT) continue; 38 if (source->type == PM_SOURCE_SATURATED) continue; 39 40 // skip poorly fitted stars 41 if (source->type == PM_SOURCE_FAINTSTAR) continue; 42 if (source->type == PM_SOURCE_POOR_FIT_PSF) continue; 43 44 // XXX EAM when do we pick these up again? 45 if (source->moments->SN < GAL_MIN_SN) { 46 source->type = PM_SOURCE_FAINT_GALAXY; // better choice? 47 continue; 48 } 28 // skip possible extended sources below fit threshold 29 if (source->moments->SN < GAL_MIN_SN) continue; 49 30 50 31 // recalculate the source moments using the larger galaxy moments radius 51 32 status = pmSourceMoments (source, GAL_MOMENTS_RAD); 52 33 if (!status) { 53 source-> type = PM_SOURCE_DROP_GALAXY; // better choice?34 source->mode |= PM_SOURCE_FAIL; // better choice? 54 35 continue; 55 36 } … … 57 38 // use the source moments, etc to guess basic model parameters 58 39 pmModel *model = pmSourceModelGuess (source, modelType); 40 source->modelFLT = model; 59 41 x = model->params->data.F32[2]; 60 42 y = model->params->data.F32[3]; 61 43 62 // set the fit radius based on the object flux limit and the model 63 // XXX EAM : FLUX_LIMIT should be set based on local sky model (not global median) 64 model->radius = modelRadius (model->params, FLUX_LIMIT) + GAL_FIT_PADDING; 65 if (isnan(model->radius)) psAbort ("fit_galaxies", "error in radius"); 66 67 // check if we need to redefine the pixels 68 // XXX EAM : a better test would examine the source pixels 69 if (model->radius > OUTER_RADIUS) { 70 // (re)-allocate image, weight, mask arrays for each peak (square of radius OUTER) 71 psphotDefinePixels (source, imdata, x, y, model->radius); 72 } 44 // sets the model radius (via source->model) and adjusts pixels as needed 45 psphotCheckRadiusFLT (imdata, source); 73 46 74 47 // fit FLT (not PSF) model (set/unset the pixel mask) 75 48 psImageKeepCircle (source->mask, x, y, model->radius, "OR", PSPHOT_MASK_MARKED); 76 status =pmSourceFitModel (source, model, false);49 pmSourceFitModel (source, model, false); 77 50 psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PSPHOT_MASK_MARKED); 78 if (!status) {79 // if the fit fails, we need to change the classification80 psLogMsg ("psphot", 5, "GAL fit failed for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius);81 source->type = PM_SOURCE_FAIL_FIT_GAL; // better choice?82 source->modelFLT = model;83 Nfail ++;84 continue;85 }86 51 87 // check if model fit is acceptable88 goodfit = pmModelFitStatus (model);89 if (!goodfit) {90 // if the fit fails, we need to change the classification91 psLogMsg ("psphot", 5, "GAL fit poor for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius);92 source->type = PM_SOURCE_POOR_FIT_GAL; // better choice?93 source->modelFLT = model;94 Nfail ++;95 continue;96 }97 98 // accept the model99 source->type = PM_SOURCE_GALAXY;100 source->modelFLT = model;101 52 Niter += model[0].nIter; 102 53 Nfit++; 103 54 104 // subtract object, leave local sky 105 pmSourceSubModel (source->pixels, source->mask, model, false, false); 55 // check if model fit is acceptable 56 if (pmModelFitStatus (model)) { 57 pmSourceSubModel (source->pixels, source->mask, model, false, false); 58 source->mode |= PM_SOURCE_SUBTRACTED; 59 Nsub ++; 60 } 106 61 } 107 psLogMsg ("psphot", 3, "fit galaxies: %f sec for %d galaxies (%d failures, %d total iterations)\n", psTimerMark ("psphot"), Nfit, Nfail, Niter); 62 psLogMsg ("psphot", 3, "fit GAL models: %f sec for %d galaxies (%d total iterations)\n", psTimerMark ("psphot"), Nfit, Niter); 63 psLogMsg ("psphot", 4, "subtracted %d GAL models\n", Nsub); 108 64 return (true); 109 65 }
Note:
See TracChangeset
for help on using the changeset viewer.
