Changeset 4574 for trunk/psphot/src/fit_galaxies.c
- Timestamp:
- Jul 16, 2005, 6:02:29 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/fit_galaxies.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/fit_galaxies.c
r4251 r4574 3 3 // fit selected galaxy model (GAUSS) to all bright objects of type GALAXY 4 4 5 bool fit_galaxies (psImage *image, psMetadata *config, psArray *sources)5 bool fit_galaxies (psImageData *imdata, psMetadata *config, psArray *sources, psStats *skyStats) 6 6 { 7 7 bool status; 8 float x; 9 float y; 10 float sky; 8 11 int Nfit = 0; 12 int Nfail = 0; 9 13 int Niter = 0; 10 14 15 float MOMENT_R = psMetadataLookupF32 (&status, config, "GAL_MOMENTS_RADIUS"); 11 16 float RADIUS = psMetadataLookupF32 (&status, config, "FIT_RADIUS"); 12 17 float snFaint = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM"); 13 psModelType modelType = psModelSetType ("PS_MODEL_PGAUSS"); 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"); 21 22 float FLUX_LIMIT = FIT_NSIGMA * skyStats->sampleStdev; 23 24 psModelType modelType = psModelSetType ("PS_MODEL_RGAUSS"); 25 psModelRadius modelRadius = psModelRadius_GetFunction (modelType); 26 27 psTraceSetLevel (".psModules.pmSourceMoments", 5); 14 28 15 29 psTimerStart ("psphot"); … … 19 33 if (source->moments->SN < snFaint) continue; 20 34 35 // recalculate the source moments using the galaxy radius (larger) 36 status = pmSourceMoments (source, MOMENT_R); 37 38 // use the source moments, etc to guess basic model parameters 39 psModel *model = pmSourceModelGuess (source, modelType); 40 41 x = model->params->data.F32[2]; 42 y = model->params->data.F32[3]; 43 21 44 // need a better model guess and a better radius choice 22 45 // when radius is not fixed, we will need to check if new radius fits on image 23 # if (0) 46 47 // set the fit radius based on the object flux limit and the model 48 // FLUX_LIMIT should be set based on local sky model (not global median) 49 // model->radius = 25.0; 50 model->radius = modelRadius (model->params, FLUX_LIMIT) + FIT_PADDING; 51 if (isnan(model->radius)) { 52 fprintf (stderr, "error in radius\n"); 53 continue; 54 } 24 55 if (model->radius > OUTER) { 25 56 // allocate image, noise, mask arrays for each peak (square of radius OUTER) 26 pmSourceDefinePixels (source, imdata, x, y, OUTER);57 pmSourceDefinePixels (source, imdata, x, y, model->radius); 27 58 } 28 # endif29 psModel *model = pmSourceModelGuess (source, modelType);30 59 31 60 // fit as FLT, not PSF (skip poor fits) 32 if (!pmSourceFitModel (source, model, false)) continue; 61 psImageKeepCircle (source->mask, x, y, model->radius, OR, 0x80); 62 status = pmSourceFitModel (source, model, false); 63 psImageKeepCircle (source->mask, x, y, model->radius, AND, 0x7f); 64 if (!status || (model->params->data.F32[1] < 0)) { 65 // if the fit fails, we need to change the classification 66 psLogMsg ("psphot", 3, "GAL fit failed for %f, %f (%d iterations, %f radius)\n", x, y, model->nIter, model->radius); 67 source->type = PS_SOURCE_OTHER; // better choice? 68 Nfail ++; 69 continue; 70 } 71 33 72 source->modelFLT = model; 34 35 73 Niter += model[0].nIter; 36 74 Nfit++; 75 76 // subtract object, leave local sky 77 sky = model->params->data.F32[0]; 78 model->params->data.F32[0] = 0; 79 pmSourceSubModel (source->pixels, source->mask, model, false); 80 model->params->data.F32[0] = sky; 81 37 82 } 38 psLogMsg ("psphot", 3, "fit galaxies: %f sec for %d galaxies (%d total iterations)\n", psTimerMark ("psphot"), Nfit, Niter);83 psLogMsg ("psphot", 3, "fit galaxies: %f sec for %d galaxies (%d failures, %d total iterations)\n", psTimerMark ("psphot"), Nfit, Nfail, Niter); 39 84 return (true); 40 85 }
Note:
See TracChangeset
for help on using the changeset viewer.
