Changeset 4574
- Timestamp:
- Jul 16, 2005, 6:02:29 AM (21 years ago)
- Location:
- trunk/psphot
- Files:
-
- 10 edited
-
Makefile (modified) (1 diff)
-
src/apply_psf_model.c (modified) (2 diffs)
-
src/basic_classes.c (modified) (1 diff)
-
src/fit_galaxies.c (modified) (2 diffs)
-
src/mark_psf_source.c (modified) (3 diffs)
-
src/psphot-utils.c (modified) (4 diffs)
-
src/psphot.c (modified) (1 diff)
-
src/psphot.h (modified) (1 diff)
-
src/source_moments.c (modified) (1 diff)
-
src/subtract_psf_source.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/Makefile
r4375 r4574 39 39 $(SRC)/subtract_galaxies.$(ARCH).o \ 40 40 $(SRC)/LocalSky.$(ARCH).o \ 41 $(SRC)/basic_classes.$(ARCH).o \ 41 42 $(SRC)/find_defects.$(ARCH).o 42 43 -
trunk/psphot/src/apply_psf_model.c
r4421 r4574 65 65 status = pmSourceFitModel (source, model, true); 66 66 psImageKeepCircle (source->mask, x, y, model->radius, AND, 0x7f); 67 if (!status) continue; 67 if (!status || (model->params->data.F32[1] < 0)) { 68 // if the fit fails, we need to change the classification 69 psLogMsg ("psphot", 3, "PSF fit failed for %f, %f (%d iterations)\n", x, y, model->nIter); 70 source->type = PS_SOURCE_OTHER; // better choice? 71 continue; 72 } 68 73 69 74 source->modelPSF = model; … … 71 76 Nfit ++; 72 77 73 mark_psf_source (source, shapeNsigma );78 mark_psf_source (source, shapeNsigma, SATURATE); 74 79 if (subtract_psf_source (source)) { 75 80 Nsub ++; -
trunk/psphot/src/basic_classes.c
r4398 r4574 2 2 3 3 bool basic_classes (psArray *sources, psMetadata *config) { 4 5 pmPSFClump psfClump; 4 6 5 7 // group into STAR, COSMIC, GALAXY, SATURATED -
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 } -
trunk/psphot/src/mark_psf_source.c
r4375 r4574 15 15 // PS_SOURCE_BRIGHTSTAR 16 16 # define MIN_DS 0.01 17 bool mark_psf_source (psSource *source, float shapeNsigma )17 bool mark_psf_source (psSource *source, float shapeNsigma, float SATURATE) 18 18 { 19 19 float dSX, dSY, SX, SY, SN; … … 22 22 if (source->modelPSF == NULL) return (false); 23 23 24 // SATSTAR objects are fitted with PSF regardless 25 if (source->type == PS_SOURCE_SATSTAR) return (true); 24 // if object has fitted peak above saturation, label as SATSTAR 25 // remember: fit does not use saturated pixels (masked) 26 if (source->modelPSF->params->data.F32[1] >= SATURATE) { 27 if (source->type == PS_SOURCE_PSFSTAR) { 28 psLogMsg ("psphot", 3, "PSFSTAR marked saturated\n"); 29 } 30 source->type = PS_SOURCE_SATSTAR; 31 return (true); 32 } 33 if (source->type == PS_SOURCE_SATSTAR) { 34 psLogMsg ("psphot", 4, "SATSTAR marked bright (fitted peak below saturation)\n"); 35 source->type = PS_SOURCE_BRIGHTSTAR; 36 } 26 37 27 38 SN = source->modelPSF->params->data.F32[1]/source->modelPSF->dparams->data.F32[1]; … … 35 46 // sigma = 1 / SX 36 47 // dsx = 1 / (SX * SN) 37 // dsx_o = hypot (1/ SX*SN +MIN_DSX)48 // dsx_o = hypot (1/(SX*SN), MIN_DSX) 38 49 39 50 // assign PS_SOURCE_BRIGHTSTAR to bright objects within PSF region of dparams[] 40 51 if ((fabs(nSx) < shapeNsigma) && (fabs(nSy) < shapeNsigma)) { 41 if (source->type == PS_SOURCE_PSFSTAR) return (true);42 source->type = PS_SOURCE_BRIGHTSTAR;43 return (true);52 if (source->type == PS_SOURCE_PSFSTAR) return (true); 53 source->type = PS_SOURCE_BRIGHTSTAR; 54 return (true); 44 55 } 45 56 46 57 if (source->type == PS_SOURCE_PSFSTAR) { 47 psLogMsg ("psphot", 3, "PSFSTAR demoted based on dSx, dSy\n");58 psLogMsg ("psphot", 3, "PSFSTAR demoted based on dSx, dSy\n"); 48 59 } 49 60 50 61 if ((nSx >= shapeNsigma) || (nSy >= shapeNsigma)) { 51 source->type = PS_SOURCE_GALAXY;52 return (false);62 source->type = PS_SOURCE_GALAXY; 63 return (false); 53 64 } 54 65 // replace DEFECT with COSMIC? 55 66 if ((nSx <= -shapeNsigma) || (nSy <= -shapeNsigma)) { 56 source->type = PS_SOURCE_DEFECT;57 return (false);67 source->type = PS_SOURCE_DEFECT; 68 return (false); 58 69 } 59 70 psTrace (".psphot.mark_psf_source", 2, "unexpected result: unmarked object\n"); -
trunk/psphot/src/psphot-utils.c
r4421 r4574 96 96 model = (psModel *) source->modelPSF; 97 97 if (model == NULL) continue; 98 if (source->type == PS_SOURCE_GALAXY) continue; 99 if (source->type == PS_SOURCE_DEFECT) continue; 100 if (source->type == PS_SOURCE_SATURATED) continue; 98 101 params = model->params; 99 102 dparams = model->dparams; … … 107 110 fprintf (f, "%9.6f ", dparams[0].data.F32[j+4]); 108 111 } 109 fprintf (f, ": %2d %7.4f %7.4f %7.2f (%d %d)\n", source[0].type, log10(model[0].chisq), source[0].moments->SN, model[0].radius, model[0].nDOF, model[0].nIter); 112 fprintf (f, ": %2d %7.4f %7.4f %7.2f (%d %d)\n", 113 source[0].type, log10(model[0].chisq), source[0].moments->SN, 114 model[0].radius, model[0].nDOF, model[0].nIter); 110 115 } 111 116 fclose (f); … … 134 139 model = (psModel *) source->modelFLT; 135 140 if (model == NULL) continue; 141 if (source->type == PS_SOURCE_PSFSTAR) continue; 142 if (source->type == PS_SOURCE_SATSTAR) continue; 143 if (source->type == PS_SOURCE_BRIGHTSTAR) continue; 144 if (source->type == PS_SOURCE_FAINTSTAR) continue; 145 if (source->type == PS_SOURCE_OTHER) continue; 146 if (source->type == PS_SOURCE_DEFECT) continue; 147 if (source->type == PS_SOURCE_SATURATED) continue; 148 136 149 params = model->params; 137 150 dparams = model->dparams; … … 287 300 } 288 301 302 /* this code is in pmObjects.h / psModules:psEllipse */ 303 # if (0) 304 typedef struct { 305 double major; 306 double minor; 307 double theta; 308 } EllipseAxes; 309 310 typedef struct { 311 double x2; 312 double y2; 313 double xy; 314 } EllipseMoments; 315 316 typedef struct { 317 double sx; 318 double sy; 319 double sxy; 320 } EllipseShape; 321 322 EllipseAxes EllipseMomentsToAxes (EllipseMoments moments) { 323 324 EllipseAxes axes; 325 326 double f = sqrt (0.25*PS_SQR(moments.x2 - moments.y2) + PS_SQR(moments.sy)); 327 328 axes.major = sqrt (0.5*(moments.x2 + moments.y2) + f); 329 axes.minor = sqrt (0.5*(moments.x2 + moments.y2) - f) 330 axes.theta = atan2 (2*moments.xy, moments.x2 - moments.y2) / 2; 331 // theta in radians 332 333 return (axes); 334 } 335 336 EllipseShape EllipseMomentsToShape (EllipseMoments moments) { 337 338 EllipseShape shape; 339 340 double f = sqrt(0.25*PS_SQR(axes.x2 - axes.y2) + PS_SQR(axes.sxy)); 341 342 shape.sx = moments.y2 / f; 343 shape.sy = moments.x2 / f; 344 shape.sxy = -2.0*moments.xy / f; 345 // XXX - these are probably wrong 346 347 return (shape); 348 } 349 350 EllipseMoments EllipseShapeToMoments (EllipseShape shape) { 351 352 EllipseMoments moments; 353 354 return (moments); 355 } 356 357 EllipseAxes EllipseShapeToAxes (EllipseShape shape) { 358 359 EllipseAxes axes; 360 361 362 return (axes); 363 } 364 365 EllipseShape EllipseAxesToShape (EllipseAxes axes) { 366 367 EllipseShape shape; 368 369 shape.sx = PS_SQR(cos(axes.theta) / axes.major) + PS_SQR(sin(axes.theta) / axes.minor); 370 shape.sy = PS_SQR(sin(axes.theta) / axes.major) + PS_SQR(cos(axes.theta) / axes.minor); 371 shape.sxy = cos(axes.theta)*sin(axes.theta)*(1.0/PS_SQR(axes.major) - 1.0/PS_SQR(axes.minor)); 372 373 return (shape); 374 } 375 376 EllipseMoments EllipseAxesToMoments (EllipseAxes axes) { 377 378 EllipseMoments moments; 379 380 return (moments); 381 } 382 383 # endif -
trunk/psphot/src/psphot.c
r4421 r4574 41 41 42 42 // fit extended objects with galaxy models 43 // fit_galaxies (imdata, config, sources);43 fit_galaxies (imdata, config, sources, sky); 44 44 45 45 // subtract_galaxies (sources, config); -
trunk/psphot/src/psphot.h
r4375 r4574 46 46 bool mark_psf_sources (psArray *sources, psMetadata *config); 47 47 bool subtract_psf_sources (psArray *sources); 48 bool fit_galaxies (psImage *image, psMetadata *config, psArray *sources);48 bool fit_galaxies (psImageData *imdata, psMetadata *config, psArray *sources, psStats *skyStats); 49 49 bool subtract_galaxies (psArray *sources, psMetadata *config); 50 50 bool subtract_psf_source (psSource *source); 51 bool mark_psf_source (psSource *source, float shapeNsigma );51 bool mark_psf_source (psSource *source, float shapeNsigma, float SATURATE); 52 52 bool find_defects (psImage *zapmask, psArray *sources, psMetadata *config, pmPSF *psf); 53 bool basic_classes (psArray *sources, psMetadata *config); 53 54 54 55 // psf utilities -
trunk/psphot/src/source_moments.c
r4398 r4574 5 5 bool status = false; 6 6 psArray *sources = NULL; 7 pmPSFClump psfClump;8 7 9 8 psTimerStart ("psphot"); -
trunk/psphot/src/subtract_psf_source.c
r4251 r4574 9 9 10 10 // non-stellar sources are ignored 11 if (source->type == PS_SOURCE_OTHER) return (false); 11 12 if (source->type == PS_SOURCE_GALAXY) return (false); 12 13 if (source->type == PS_SOURCE_DEFECT) return (false); 14 if (source->type == PS_SOURCE_SATURATED) return (false); 13 15 14 16 psModel *model = source->modelPSF; … … 18 20 } 19 21 20 psImage *pixels = source->pixels;22 psImage *pixels = source->pixels; 21 23 22 24 // subtract object, leave local sky
Note:
See TracChangeset
for help on using the changeset viewer.
