- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src (modified) (1 prop)
-
psphot/src/psphotSourceFits.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/psphot
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psphot merged eligible /branches/eam_branches/stackphot.20100406/psphot 27622-27655 /branches/pap_delete/psphot 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/simtest_nebulous_branches/psphot/src
- Property svn:ignore
-
old new 18 18 psphotVersionDefinitions.h 19 19 psphotMomentsStudy 20 psphotPetrosianStudy 21 psphotForced 22 psphotMakePSF 23 psphotStack
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/psphot/src/psphotSourceFits.c
r24592 r27840 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 … … 216 219 double chiTrend; 217 220 pmModel *ONE = NULL; 221 pmSource *tmpSrc = NULL; 222 pmModel *EXT = NULL; 223 psArray *DBL = NULL; 218 224 219 225 // skip the source if we don't think it is extended … … 221 227 if (source->type == PM_SOURCE_TYPE_DEFECT) return false; 222 228 if (source->type == PM_SOURCE_TYPE_SATURATED) return false; 223 if (source->peak->SN < EXT_MIN_SN) return false; 224 229 230 // set the radius based on the footprint (also sets the mask pixels) 231 float radius = psphotSetRadiusEXT (readout, source, markVal); 232 233 // XXX note that this changes the source moments that are published... 225 234 // recalculate the source moments using the larger extended-source moments radius 226 235 // 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; 236 // this uses the footprint to judge both radius and aperture? 237 if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) return false; 228 238 229 239 psTrace ("psphot", 5, "trying blob...\n"); … … 233 243 234 244 // this temporary source is used as a place-holder by the psphotEval functions below 235 pmSource *tmpSrc = pmSourceAlloc ();245 tmpSrc = pmSourceAlloc (); 236 246 237 247 // XXX need to handle failures better here 238 pmModel *EXT = psphotFitEXT (readout, source, modelTypeEXT, maskVal, markVal); 248 EXT = psphotFitEXT (readout, source, modelTypeEXT, maskVal, markVal); 249 if (!EXT) goto escape; 250 if (!isfinite(EXT->params->data.F32[PM_PAR_I0])) goto escape; 251 239 252 okEXT = psphotEvalEXT (tmpSrc, EXT); 240 253 chiEXT = EXT ? EXT->chisq / EXT->nDOF : NAN; 241 254 242 255 // DBL will always be defined, but DBL->data[n] might not 243 psArray *DBL = psphotFitDBL (readout, source, maskVal, markVal); 256 DBL = psphotFitDBL (readout, source, maskVal, markVal); 257 if (!DBL) goto escape; 258 if (!DBL->n) goto escape; 259 244 260 okDBL = psphotEvalDBL (tmpSrc, DBL->data[0]); 245 261 okDBL &= psphotEvalDBL (tmpSrc, DBL->data[1]); 246 262 // XXX should I keep / save the flags set in the eval functions? 263 264 // clear the circular mask 265 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 247 266 248 267 // correct first model chisqs for flux trend … … 250 269 ONE = DBL->data[0]; 251 270 if (ONE) { 271 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 252 272 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]); 253 273 ONE->chisqNorm = ONE->chisq / chiTrend; … … 258 278 ONE = DBL->data[1]; 259 279 if (ONE) { 280 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 260 281 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]); 261 282 ONE->chisqNorm = ONE->chisq / chiTrend; … … 277 298 278 299 // both models failed; reject them both 300 // XXX -- change type flags to psf in this case and keep original moments? 279 301 psFree (EXT); 280 302 psFree (DBL); … … 287 309 // save new model 288 310 source->modelEXT = EXT; 311 source->modelEXT->fitRadius = radius; 289 312 source->type = PM_SOURCE_TYPE_EXTENDED; 290 313 source->mode |= PM_SOURCE_MODE_EXTMODEL; … … 293 316 pmSourceCacheModel (source, maskVal); 294 317 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 295 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 318 319 # if (PS_TRACE_ON) 296 320 psTrace ("psphot", 5, "blob as EXT: %f %f\n", EXT->params->data.F32[PM_PAR_XPOS], EXT->params->data.F32[PM_PAR_YPOS]); 321 if (psTraceGetLevel("psphot") >= 6) { 322 psLogMsg ("psphot", 1, "source 2:\n"); 323 for (int i = 0; i < source->modelEXT->params->n; i++) { 324 psLogMsg ("psphot", 1, "PAR %d : %f +/- %f\n", i, source->modelEXT->params->data.F32[i], source->modelEXT->dparams->data.F32[i]); 325 } 326 } 327 # endif 328 297 329 return true; 298 330 … … 304 336 psFree (source->modelPSF); 305 337 source->modelPSF = psMemIncrRefCounter (DBL->data[0]); 306 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;307 338 source->mode |= PM_SOURCE_MODE_PAIR; 339 source->modelPSF->fitRadius = radius; 308 340 309 341 // copy most data from the primary source (modelEXT, blends stay NULL) 310 // XXX use pmSourceCopy?311 342 pmSource *newSrc = pmSourceCopy (source); 312 343 newSrc->modelPSF = psMemIncrRefCounter (DBL->data[1]); 344 newSrc->modelPSF->fitRadius = radius; 313 345 314 346 // build cached models and subtract … … 317 349 pmSourceCacheModel (newSrc, maskVal); 318 350 pmSourceSub (newSrc, PM_MODEL_OP_FULL, maskVal); 351 352 # if (PS_TRACE_ON) 319 353 psTrace ("psphot", 5, "blob as DBL: %f %f\n", ONE->params->data.F32[PM_PAR_XPOS], ONE->params->data.F32[PM_PAR_YPOS]); 354 if (psTraceGetLevel("psphot") >= 6) { 355 psLogMsg ("psphot", 1, "source 1:\n"); 356 for (int i = 0; i < newSrc->modelPSF->params->n; i++) { 357 psLogMsg ("psphot", 1, "PAR %d : %f +/- %f\n", i, newSrc->modelPSF->params->data.F32[i], newSrc->modelPSF->dparams->data.F32[i]); 358 } 359 psLogMsg ("psphot", 1, "source 2:\n"); 360 for (int i = 0; i < source->modelPSF->params->n; i++) { 361 psLogMsg ("psphot", 1, "PAR %d : %f +/- %f\n", i, source->modelPSF->params->data.F32[i], source->modelPSF->dparams->data.F32[i]); 362 } 363 psphotVisualShowResidualImage (readout); 364 } 365 # endif 320 366 321 367 psArrayAdd (newSources, 100, newSrc); … … 323 369 psFree (DBL); 324 370 return true; 371 372 escape: 373 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 374 psFree (tmpSrc); 375 psFree (EXT); 376 psFree (DBL); 377 return false; 325 378 } 326 379 … … 356 409 // save the PSF model from the Ensemble fit 357 410 PSF = source->modelPSF; 358 psphotCheckRadiusPSFBlend (readout, source, PSF, markVal, 8.0);359 411 if (isnan(PSF->params->data.F32[1])) psAbort("nan in dbl fit"); 360 412 … … 387 439 // use the source moments, etc to guess basic model parameters 388 440 pmModel *EXT = pmSourceModelGuess (source, modelType); 389 PS_ASSERT (EXT, NULL); 390 391 // if (isnan(EXT->params->data.F32[1])) psAbort("nan in ext fit"); 392 393 psphotCheckRadiusEXT (readout, source, EXT, markVal); 441 if (!EXT) { 442 psTrace ("psphot", 5, "failed to generate a model for source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); 443 return NULL; 444 } 394 445 395 446 if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) { … … 401 452 return (EXT); 402 453 } 403
Note:
See TracChangeset
for help on using the changeset viewer.
