Changeset 25755 for trunk/psphot/src/psphotSourceFits.c
- Timestamp:
- Oct 2, 2009, 3:12:47 PM (17 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psphotSourceFits.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src
- Property svn:ignore
-
old new 18 18 psphotVersionDefinitions.h 19 19 psphotMomentsStudy 20 psphotPetrosianStudy
-
- Property svn:ignore
-
trunk/psphot/src/psphotSourceFits.c
r24592 r25755 90 90 psphotCheckRadiusPSFBlend (readout, source, PSF, markVal, dR); 91 91 92 // fit PSF model (set/unset the pixel mask)92 // fit PSF model 93 93 pmSourceFitSet (source, modelSet, PM_SOURCE_FIT_PSF, maskVal); 94 95 // clear the circular mask 96 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 97 98 if (!isfinite(PSF->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 94 99 95 100 // correct model chisq for flux trend … … 101 106 pmSource *blend = sourceSet->data[i]; 102 107 pmModel *model = modelSet->data[i]; 108 109 if (!isfinite(model->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 103 110 104 111 // correct model chisq for flux trend … … 120 127 pmSourceCacheModel (blend, maskVal); 121 128 pmSourceSub (blend, PM_MODEL_OP_FULL, maskVal); 122 blend->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;123 129 blend->mode |= PM_SOURCE_MODE_BLEND_FIT; 124 130 } … … 144 150 pmSourceCacheModel (source, maskVal); 145 151 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 146 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;147 152 source->mode |= PM_SOURCE_MODE_BLEND_FIT; 148 153 return true; … … 167 172 // fit PSF model (set/unset the pixel mask) 168 173 pmSourceFitModel (source, PSF, PM_SOURCE_FIT_PSF, maskVal); 174 175 if (!isfinite(PSF->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 176 177 // clear the circular mask 178 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 169 179 170 180 // correct model chisq for flux trend … … 186 196 pmSourceCacheModel (source, maskVal); 187 197 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 188 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 189 return true; 190 } 191 192 static float EXT_MIN_SN; 193 static float EXT_MOMENTS_RAD; 198 return true; 199 } 200 194 201 static pmModelType modelTypeEXT; 195 202 … … 197 204 198 205 bool status; 199 200 // extended source model parameters201 EXT_MIN_SN = psMetadataLookupF32 (&status, recipe, "EXT_MIN_SN");202 EXT_MOMENTS_RAD = psMetadataLookupF32 (&status, recipe, "EXT_MOMENTS_RADIUS");203 206 204 207 // extended source model descriptions … … 221 224 if (source->type == PM_SOURCE_TYPE_DEFECT) return false; 222 225 if (source->type == PM_SOURCE_TYPE_SATURATED) return false; 223 if (source->peak->SN < EXT_MIN_SN) return false; 224 226 227 // set the radius based on the footprint (also sets the mask pixels) 228 float radius = psphotSetRadiusEXT (readout, source, markVal); 229 230 // XXX note that this changes the source moments that are published... 225 231 // recalculate the source moments using the larger extended-source moments radius 226 232 // at this stage, skip Gaussian windowing, and do not clip pixels by S/N 227 if (!pmSourceMoments (source, EXT_MOMENTS_RAD, 0.0, 0.0)) return false; 233 // this uses the footprint to judge both radius and aperture? 234 if (!pmSourceMoments (source, radius, 0.0, 0.0)) return false; 228 235 229 236 psTrace ("psphot", 5, "trying blob...\n"); … … 237 244 // XXX need to handle failures better here 238 245 pmModel *EXT = psphotFitEXT (readout, source, modelTypeEXT, maskVal, markVal); 246 if (!isfinite(EXT->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 247 239 248 okEXT = psphotEvalEXT (tmpSrc, EXT); 240 249 chiEXT = EXT ? EXT->chisq / EXT->nDOF : NAN; … … 246 255 // XXX should I keep / save the flags set in the eval functions? 247 256 257 // clear the circular mask 258 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 259 248 260 // correct first model chisqs for flux trend 249 261 chiDBL = NAN; 250 262 ONE = DBL->data[0]; 251 263 if (ONE) { 264 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 252 265 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]); 253 266 ONE->chisqNorm = ONE->chisq / chiTrend; … … 258 271 ONE = DBL->data[1]; 259 272 if (ONE) { 273 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 260 274 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]); 261 275 ONE->chisqNorm = ONE->chisq / chiTrend; … … 277 291 278 292 // both models failed; reject them both 293 // XXX -- change type flags to psf in this case and keep original moments? 279 294 psFree (EXT); 280 295 psFree (DBL); … … 287 302 // save new model 288 303 source->modelEXT = EXT; 304 source->modelEXT->fitRadius = radius; 289 305 source->type = PM_SOURCE_TYPE_EXTENDED; 290 306 source->mode |= PM_SOURCE_MODE_EXTMODEL; … … 293 309 pmSourceCacheModel (source, maskVal); 294 310 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 295 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 311 312 # if (PS_TRACE_ON) 296 313 psTrace ("psphot", 5, "blob as EXT: %f %f\n", EXT->params->data.F32[PM_PAR_XPOS], EXT->params->data.F32[PM_PAR_YPOS]); 314 if (psTraceGetLevel("psphot") >= 6) { 315 psLogMsg ("psphot", 1, "source 2:\n"); 316 for (int i = 0; i < source->modelEXT->params->n; i++) { 317 psLogMsg ("psphot", 1, "PAR %d : %f +/- %f\n", i, source->modelEXT->params->data.F32[i], source->modelEXT->dparams->data.F32[i]); 318 } 319 } 320 # endif 321 297 322 return true; 298 323 … … 304 329 psFree (source->modelPSF); 305 330 source->modelPSF = psMemIncrRefCounter (DBL->data[0]); 306 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;307 331 source->mode |= PM_SOURCE_MODE_PAIR; 332 source->modelPSF->fitRadius = radius; 308 333 309 334 // copy most data from the primary source (modelEXT, blends stay NULL) 310 // XXX use pmSourceCopy?311 335 pmSource *newSrc = pmSourceCopy (source); 312 336 newSrc->modelPSF = psMemIncrRefCounter (DBL->data[1]); 337 newSrc->modelPSF->fitRadius = radius; 313 338 314 339 // build cached models and subtract … … 317 342 pmSourceCacheModel (newSrc, maskVal); 318 343 pmSourceSub (newSrc, PM_MODEL_OP_FULL, maskVal); 344 345 # if (PS_TRACE_ON) 319 346 psTrace ("psphot", 5, "blob as DBL: %f %f\n", ONE->params->data.F32[PM_PAR_XPOS], ONE->params->data.F32[PM_PAR_YPOS]); 347 if (psTraceGetLevel("psphot") >= 6) { 348 psLogMsg ("psphot", 1, "source 1:\n"); 349 for (int i = 0; i < newSrc->modelPSF->params->n; i++) { 350 psLogMsg ("psphot", 1, "PAR %d : %f +/- %f\n", i, newSrc->modelPSF->params->data.F32[i], newSrc->modelPSF->dparams->data.F32[i]); 351 } 352 psLogMsg ("psphot", 1, "source 2:\n"); 353 for (int i = 0; i < source->modelPSF->params->n; i++) { 354 psLogMsg ("psphot", 1, "PAR %d : %f +/- %f\n", i, source->modelPSF->params->data.F32[i], source->modelPSF->dparams->data.F32[i]); 355 } 356 psphotVisualShowResidualImage (readout); 357 } 358 # endif 320 359 321 360 psArrayAdd (newSources, 100, newSrc); … … 356 395 // save the PSF model from the Ensemble fit 357 396 PSF = source->modelPSF; 358 psphotCheckRadiusPSFBlend (readout, source, PSF, markVal, 8.0);359 397 if (isnan(PSF->params->data.F32[1])) psAbort("nan in dbl fit"); 360 398 … … 389 427 PS_ASSERT (EXT, NULL); 390 428 391 // if (isnan(EXT->params->data.F32[1])) psAbort("nan in ext fit");392 393 psphotCheckRadiusEXT (readout, source, EXT, markVal);394 395 429 if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) { 396 430 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); … … 401 435 return (EXT); 402 436 } 403
Note:
See TracChangeset
for help on using the changeset viewer.
