Changeset 9595 for trunk/psphot/src/psphotSourceFits.c
- Timestamp:
- Oct 16, 2006, 4:24:03 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotSourceFits.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotSourceFits.c
r9576 r9595 3 3 // given a source with an existing modelPSF, attempt a full PSF fit, subtract if successful 4 4 5 bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf) { 5 bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf) { 6 6 7 7 float x, y, dR; … … 9 9 // if this source is not a possible blend, just fit as PSF 10 10 if ((source->blends == NULL) || (source->mode & PM_SOURCE_MODE_SATSTAR)) { 11 bool status = psphotFitPSF (readout, source, psf);12 return status;11 bool status = psphotFitPSF (readout, source, psf); 12 return status; 13 13 } 14 14 psTrace ("psphot", 5, "trying blend...\n"); … … 23 23 psArray *modelSet = psArrayAlloc (source->blends->n + 1); 24 24 psArrayAdd (modelSet, 16, PSF); 25 25 26 26 psArray *sourceSet = psArrayAlloc (source->blends->n + 1); 27 27 psArrayAdd (sourceSet, 16, source); … … 30 30 dR = 0; 31 31 for (int i = 0; i < source->blends->n; i++) { 32 pmSource *blend = source->blends->data[i];33 34 // find the blend which is furthest from source35 dR = PS_MAX (dR, hypot (blend->peak->x - x, blend->peak->y - y));36 37 // create the model and guess parameters for this blend38 pmModel *model = pmModelAlloc (PSF->type);39 for (int j = 0; j < model->params->n; j++) {40 model->params->data.F32[j] = PSF->params->data.F32[j];41 model->dparams->data.F32[j] = PSF->dparams->data.F32[j];42 }43 44 // XXX assume local sky is 0.0?45 model->params->data.F32[1] = blend->moments->Peak - blend->moments->Sky;46 if (isnan(model->params->data.F32[1])) psAbort ("psphot", "nan in blend fit");47 model->params->data.F32[2] = blend->peak->x;48 model->params->data.F32[3] = blend->peak->y;49 50 // add this blend to the list51 psArrayAdd (modelSet, 16, model);52 psArrayAdd (sourceSet, 16, blend);53 54 // free to avoid double counting model 55 psFree (model);32 pmSource *blend = source->blends->data[i]; 33 34 // find the blend which is furthest from source 35 dR = PS_MAX (dR, hypot (blend->peak->x - x, blend->peak->y - y)); 36 37 // create the model and guess parameters for this blend 38 pmModel *model = pmModelAlloc (PSF->type); 39 for (int j = 0; j < model->params->n; j++) { 40 model->params->data.F32[j] = PSF->params->data.F32[j]; 41 model->dparams->data.F32[j] = PSF->dparams->data.F32[j]; 42 } 43 44 // XXX assume local sky is 0.0? 45 model->params->data.F32[1] = blend->moments->Peak - blend->moments->Sky; 46 if (isnan(model->params->data.F32[1])) psAbort ("psphot", "nan in blend fit"); 47 model->params->data.F32[2] = blend->peak->x; 48 model->params->data.F32[3] = blend->peak->y; 49 50 // add this blend to the list 51 psArrayAdd (modelSet, 16, model); 52 psArrayAdd (sourceSet, 16, blend); 53 54 // free to avoid double counting model 55 psFree (model); 56 56 } 57 57 … … 62 62 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "OR", PM_MASK_MARK); 63 63 pmSourceFitSet (source, modelSet, PM_SOURCE_FIT_PSF); 64 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "AND", NOT_U8(PM_MASK_MARK));64 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "AND", PS_NOT_U8(PM_MASK_MARK)); 65 65 66 66 // correct model chisq for flux trend … … 70 70 // evaluate the blend objects, subtract if good, free otherwise 71 71 for (int i = 1; i < modelSet->n; i++) { 72 pmSource *blend = sourceSet->data[i];73 pmModel *model = modelSet->data[i];74 75 // correct model chisq for flux trend76 chiTrend = psPolynomial1DEval (psf->ChiTrend, model->params->data.F32[1]);77 model->chisqNorm = model->chisq / chiTrend;78 79 // if this one failed, skip it80 if (!psphotEvalPSF (blend, model)) {81 psTrace ("psphot", 5, "failed on blend %d of %ld\n", i, modelSet->n);82 continue;83 }84 85 // otherwise, supply the resulting model to the corresponding blend86 psFree(blend->modelPSF);87 blend->modelPSF = psMemIncrRefCounter (model);88 psTrace ("psphot", 5, "fitted blend as PSF\n");89 pmModelSub (source->pixels, source->mask, model, false, false);90 blend->mode |= PM_SOURCE_MODE_SUBTRACTED;91 blend->mode &= ~PM_SOURCE_MODE_TEMPSUB;72 pmSource *blend = sourceSet->data[i]; 73 pmModel *model = modelSet->data[i]; 74 75 // correct model chisq for flux trend 76 chiTrend = psPolynomial1DEval (psf->ChiTrend, model->params->data.F32[1]); 77 model->chisqNorm = model->chisq / chiTrend; 78 79 // if this one failed, skip it 80 if (!psphotEvalPSF (blend, model)) { 81 psTrace ("psphot", 5, "failed on blend %d of %ld\n", i, modelSet->n); 82 continue; 83 } 84 85 // otherwise, supply the resulting model to the corresponding blend 86 psFree(blend->modelPSF); 87 blend->modelPSF = psMemIncrRefCounter (model); 88 psTrace ("psphot", 5, "fitted blend as PSF\n"); 89 pmModelSub (source->pixels, source->mask, model, false, false); 90 blend->mode |= PM_SOURCE_MODE_SUBTRACTED; 91 blend->mode &= ~PM_SOURCE_MODE_TEMPSUB; 92 92 } 93 93 psFree (modelSet); … … 96 96 // evaluate the primary object 97 97 if (!psphotEvalPSF (source, PSF)) { 98 psTrace ("psphot", 5, "failed on blend 0 of %ld\n", modelSet->n);99 psFree (PSF);100 return false;98 psTrace ("psphot", 5, "failed on blend 0 of %ld\n", modelSet->n); 99 psFree (PSF); 100 return false; 101 101 } 102 102 … … 110 110 } 111 111 112 bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf) { 112 bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf) { 113 113 114 114 float x, y; … … 128 128 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "OR", PM_MASK_MARK); 129 129 pmSourceFitModel (source, PSF, PM_SOURCE_FIT_PSF); 130 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "AND", NOT_U8(PM_MASK_MARK));131 130 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "AND", PS_NOT_U8(PM_MASK_MARK)); 131 132 132 // correct model chisq for flux trend 133 133 chiTrend = psPolynomial1DEval (psf->ChiTrend, PSF->params->data.F32[1]); … … 136 136 // does the PSF model succeed? 137 137 if (!psphotEvalPSF (source, PSF)) { 138 psFree (PSF);139 return false;138 psFree (PSF); 139 return false; 140 140 } 141 141 … … 143 143 pmModelSub (source->pixels, source->mask, PSF, false, false); 144 144 145 // free old model, save new model 145 // free old model, save new model 146 146 psFree (source->modelPSF); 147 147 source->modelPSF = PSF; … … 173 173 } 174 174 175 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources, pmPSF *psf) { 175 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources, pmPSF *psf) { 176 176 177 177 bool okEXT, okDBL; … … 216 216 ONE->chisqNorm = ONE->chisq / chiTrend; 217 217 218 psFree (tmpSrc); 218 psFree (tmpSrc); 219 219 220 220 if (okEXT && okDBL) { 221 psTrace ("psphot", 5, "blob chisq: %f vs %f\n", chiEXT, chiDBL);222 // XXX EAM : a bogus bias: need to examine this better 223 if (3*chiEXT > chiDBL) goto keepDBL;224 goto keepEXT;221 psTrace ("psphot", 5, "blob chisq: %f vs %f\n", chiEXT, chiDBL); 222 // XXX EAM : a bogus bias: need to examine this better 223 if (3*chiEXT > chiDBL) goto keepDBL; 224 goto keepEXT; 225 225 } 226 226 … … 276 276 277 277 // fit a double PSF source to an extended blob 278 psArray *psphotFitDBL (pmReadout *readout, pmSource *source) { 278 psArray *psphotFitDBL (pmReadout *readout, pmSource *source) { 279 279 280 280 float x, y, dx, dy; … … 284 284 psEllipseMoments moments; 285 285 psArray *modelSet; 286 286 287 287 // make a guess at the position of the two sources 288 288 moments.x2 = source->moments->Sx; … … 320 320 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "OR", PM_MASK_MARK); 321 321 pmSourceFitSet (source, modelSet, PM_SOURCE_FIT_PSF); 322 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "AND", NOT_U8(PM_MASK_MARK));322 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "AND", PS_NOT_U8(PM_MASK_MARK)); 323 323 324 324 return (modelSet); 325 325 } 326 326 327 pmModel *psphotFitEXT (pmReadout *readout, pmSource *source) { 327 pmModel *psphotFitEXT (pmReadout *readout, pmSource *source) { 328 328 329 329 float x, y; 330 330 331 331 // use the source moments, etc to guess basic model parameters 332 pmModel *EXT = pmSourceModelGuess (source, modelTypeEXT); 332 pmModel *EXT = pmSourceModelGuess (source, modelTypeEXT); 333 333 // if (isnan(EXT->params->data.F32[1])) psAbort ("psphot", "nan in ext fit"); 334 334 … … 339 339 340 340 if ((source->moments->Sx < 1e-3) || (source->moments->Sx < 1e-3)) { 341 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Sx, source->moments->Sy);341 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Sx, source->moments->Sy); 342 342 } 343 343 … … 345 345 psImageKeepCircle (source->mask, x, y, EXT->radiusTMP, "OR", PM_MASK_MARK); 346 346 pmSourceFitModel (source, EXT, PM_SOURCE_FIT_EXT); 347 psImageKeepCircle (source->mask, x, y, EXT->radiusTMP, "AND", NOT_U8(PM_MASK_MARK));347 psImageKeepCircle (source->mask, x, y, EXT->radiusTMP, "AND", PS_NOT_U8(PM_MASK_MARK)); 348 348 349 349 return (EXT);
Note:
See TracChangeset
for help on using the changeset viewer.
