Changeset 4630 for trunk/psphot/src/fit_galaxies.c
- Timestamp:
- Jul 27, 2005, 3:26:57 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/fit_galaxies.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/fit_galaxies.c
r4582 r4630 1 1 # include "psphot.h" 2 3 // fit selected galaxy model (GAUSS) to all bright objects of type GALAXY4 2 5 3 bool fit_galaxies (psImageData *imdata, psMetadata *config, psArray *sources, psStats *skyStats) 6 4 { 7 bool status ;5 bool status, goodfit; 8 6 float x; 9 7 float y; … … 13 11 int Niter = 0; 14 12 15 float MOMENT_R= psMetadataLookupF32 (&status, config, "GAL_MOMENTS_RADIUS");16 // float RADIUS = psMetadataLookupF32 (&status, config, "FIT_RADIUS");17 float snFaint = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM");18 float OUTER = psMetadataLookupF32 (&status, config, "OUTER_RADIUS");19 float FIT_NSIGMA = psMetadataLookupF32 (&status, config, "FIT_NSIGMA");20 float FIT_PADDING = psMetadataLookupF32 (&status, config, "FIT_PADDING");13 float MOMENT_R = psMetadataLookupF32 (&status, config, "GAL_MOMENTS_RADIUS"); 14 float snFaint = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM"); 15 float OUTER = psMetadataLookupF32 (&status, config, "OUTER_RADIUS"); 16 float FIT_NSIGMA = psMetadataLookupF32 (&status, config, "FIT_NSIGMA"); 17 float FIT_PADDING = psMetadataLookupF32 (&status, config, "FIT_PADDING"); 18 char *modelName = psMetadataLookupPtr (&status, config, "GAL_MODEL"); 21 19 22 20 float FLUX_LIMIT = FIT_NSIGMA * skyStats->sampleStdev; 23 21 24 psModelType modelType = psModelSetType ( "PS_MODEL_SGAUSS");22 psModelType modelType = psModelSetType (modelName); 25 23 psModelRadius modelRadius = psModelRadius_GetFunction (modelType); 26 27 psTraceSetLevel (".psModules.pmSourceMoments", 5);28 24 29 25 psTimerStart ("psphot"); 30 26 for (int i = 0; i < sources->n; i++) { 31 27 psSource *source = sources->data[i]; 32 if (source->type != PS_SOURCE_GALAXY) continue; 33 if (source->moments->SN < snFaint) continue; 28 29 // sources which should not be fitted 30 // skip all valid stars 31 if (source->type == PS_SOURCE_PSFSTAR) continue; 32 if (source->type == PS_SOURCE_SATSTAR) continue; 33 if (source->type == PS_SOURCE_GOODSTAR) continue; 34 // skip all likely defects 35 if (source->type == PS_SOURCE_DEFECT) continue; 36 if (source->type == PS_SOURCE_SATURATED) continue; 37 // 38 if (source->type == PS_SOURCE_FAINTSTAR) continue; 39 if (source->type == PS_SOURCE_POOR_FIT_PSF) continue; 40 41 // XXX when do we pick these up again? 42 if (source->moments->SN < snFaint) { 43 source->type = PS_SOURCE_FAINT_GALAXY; // better choice? 44 continue; 45 } 34 46 35 47 // recalculate the source moments using the galaxy radius (larger) 36 48 status = pmSourceMoments_EAM (source, MOMENT_R); 37 49 if (!status) { 38 fprintf (stderr, "invalid moments, skipping\n");50 source->type = PS_SOURCE_DROP_GALAXY; // better choice? 39 51 continue; 40 52 } … … 46 58 y = model->params->data.F32[3]; 47 59 48 // need a better model guess and a better radius choice49 // when radius is not fixed, we will need to check if new radius fits on image50 51 60 // set the fit radius based on the object flux limit and the model 52 61 // FLUX_LIMIT should be set based on local sky model (not global median) 53 // model->radius = 25.0;54 62 model->radius = modelRadius (model->params, FLUX_LIMIT) + FIT_PADDING; 55 if (isnan(model->radius)) { 56 fprintf (stderr, "error in radius\n"); 57 continue; 58 } 63 if (isnan(model->radius)) psAbort ("fit_galaxies", "error in radius"); 64 59 65 if (model->radius > OUTER) { 60 66 // allocate image, noise, mask arrays for each peak (square of radius OUTER) … … 64 70 // fit as FLT, not PSF (skip poor fits) 65 71 psImageKeepCircle (source->mask, x, y, model->radius, OR, 0x80); 66 status = pmSourceFitModel (source, model, false);72 status = pmSourceFitModel_EAM (source, model, false); 67 73 psImageKeepCircle (source->mask, x, y, model->radius, AND, 0x7f); 68 if (!status || (model->params->data.F32[1] < 0)) {74 if (!status) { 69 75 // if the fit fails, we need to change the classification 70 76 psLogMsg ("psphot", 3, "GAL fit failed for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius); 71 source->type = PS_SOURCE_OTHER; // better choice? 77 source->type = PS_SOURCE_FAIL_FIT_GAL; // better choice? 78 source->modelFLT = model; 72 79 Nfail ++; 73 80 continue; 74 81 } 75 82 83 goodfit = pmModelFitStatus (model); 84 if (!goodfit) { 85 // if the fit fails, we need to change the classification 86 psLogMsg ("psphot", 3, "GAL fit poor for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius); 87 source->type = PS_SOURCE_POOR_FIT_GAL; // better choice? 88 source->modelFLT = model; 89 Nfail ++; 90 continue; 91 } 92 93 source->type = PS_SOURCE_GALAXY; 76 94 source->modelFLT = model; 77 95 Niter += model[0].nIter;
Note:
See TracChangeset
for help on using the changeset viewer.
