Changeset 33993 for trunk/psphot/src/psphotFitSourcesLinear.c
- Timestamp:
- Jun 8, 2012, 6:32:36 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotFitSourcesLinear.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotFitSourcesLinear.c
r33963 r33993 12 12 static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psImageMaskType markVal); 13 13 14 # if (HAVE_MODEL_VAR) 14 15 bool psphotGenerateModelVariance (pmConfig *config, const pmFPAview *view, pmFPAfile *file, int index, psMetadata *recipe, pmReadout *readout, psArray *sources); 15 16 pmSourceFitVarMode psphotGetFitVarMode (psMetadata *recipe); 16 17 bool psphotFreeModelVariance (pmReadout *readout, psArray *sources); 18 # endif 17 19 18 20 // for now, let's store the detections on the readout->analysis for each readout … … 28 30 assert (recipe); 29 31 32 # if (HAVE_MODEL_VAR) 30 33 pmSourceFitVarMode fitVarMode = psphotGetFitVarMode (recipe); 31 34 if (!fitVarMode) { … … 37 40 // do a single pass. 38 41 pmSourceFitVarMode fitVarModePass1 = (fitVarMode == PM_SOURCE_PHOTFIT_MODEL_VAR) ? PM_SOURCE_PHOTFIT_CONST : fitVarMode; 42 # endif 39 43 40 44 int num = psphotFileruleCount(config, filerule); … … 64 68 psAssert (psf, "missing psf?"); 65 69 70 # if (HAVE_MODEL_VAR) 66 71 if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarModePass1)) { 72 # else 73 if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final)) { 74 # endif 67 75 psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i); 68 76 return false; 69 77 } 70 78 79 # if (HAVE_MODEL_VAR) 71 80 // the MODEL_VAR weighting scheme requires knowledge of the model fluxes to generate the variance 72 81 // after we have determined the initial set of fits, then we can generate the variance image and … … 94 103 } 95 104 } 105 # endif 96 106 97 107 psphotVisualShowResidualImage (readout, (num > 0)); … … 102 112 } 103 113 114 # if (HAVE_MODEL_VAR) 104 115 // look up the fit variance mode from the recipe; older recipes do not have the value 105 116 // 'LINEAR_FIT_VARIANCE_MODE'; in those cases, look for 'CONSTANT_PHOTOMETRIC_WEIGHTS' as a boolean and … … 130 141 return PM_SOURCE_PHOTFIT_NONE; 131 142 } 132 143 # endif 144 145 # if (HAVE_MODEL_VAR) 133 146 bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode) { 147 # else 148 bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final) { 149 # endif 134 150 135 151 bool status; … … 168 184 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 169 185 186 # if (!HAVE_MODEL_VAR) 187 bool CONSTANT_PHOTOMETRIC_WEIGHTS = 188 psMetadataLookupBool(&status, recipe, "CONSTANT_PHOTOMETRIC_WEIGHTS"); 189 if (!status) { 190 psAbort("You must provide a value for the BOOL recipe CONSTANT_PHOTOMETRIC_WEIGHTS"); 191 } 192 # endif 170 193 int SKY_FIT_ORDER = psMetadataLookupS32(&status, recipe, "SKY_FIT_ORDER"); 171 194 if (!status) { … … 295 318 psSparseBorder *border = psSparseBorderAlloc (sparse, nBorder); 296 319 320 # if (HAVE_MODEL_VAR) 297 321 // if fitVarMode is MODEL_VAR, then we need to generate the model image variance 298 322 // XXX we have two possibilities here: … … 302 326 303 327 // 2) do a single pass, and use the model guess to define the model variance (but do I trust the Model Guess?) 328 # endif 304 329 305 330 // fill out the sparse matrix elements and border elements (B) … … 310 335 311 336 // diagonal elements of the sparse matrix (auto-cross-product) 337 # if (HAVE_MODEL_VAR) 312 338 f = pmSourceModelDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal); 339 # else 340 f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 341 # endif 313 342 psSparseMatrixElement (sparse, i, i, f); 314 343 344 # if (HAVE_MODEL_VAR) 315 345 // if we have used CONSTANT errors, then we need to calculate the value of the parameter error 316 346 if (fitVarMode != PM_SOURCE_PHOTFIT_IMAGE_VAR) { … … 320 350 errors->data.F32[i] = 1.0 / sqrt(f); 321 351 } 322 352 # else 353 // the formal error depends on the weighting scheme 354 if (CONSTANT_PHOTOMETRIC_WEIGHTS) { 355 float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor, maskVal); 356 errors->data.F32[i] = 1.0 / sqrt(var); 357 } else { 358 errors->data.F32[i] = 1.0 / sqrt(f); 359 } 360 # endif 323 361 324 362 // find the image x model value 363 # if (HAVE_MODEL_VAR) 325 364 f = pmSourceDataDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal); 365 # else 366 f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 367 # endif 326 368 psSparseVectorElement (sparse, i, f); 327 369 … … 329 371 switch (SKY_FIT_ORDER) { 330 372 case 1: 373 # if (HAVE_MODEL_VAR) 331 374 f = pmSourceModelWeight (SRCi, 1, fitVarMode, covarFactor, maskVal); 332 375 psSparseBorderElementB (border, i, 1, f); 333 376 f = pmSourceModelWeight (SRCi, 2, fitVarMode, covarFactor, maskVal); 334 377 psSparseBorderElementB (border, i, 2, f); 378 # else 379 f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 380 psSparseBorderElementB (border, i, 1, f); 381 f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 382 psSparseBorderElementB (border, i, 2, f); 383 # endif 335 384 336 385 case 0: 386 # if (HAVE_MODEL_VAR) 337 387 f = pmSourceModelWeight (SRCi, 0, fitVarMode, covarFactor, maskVal); 388 # else 389 f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 390 # endif 338 391 psSparseBorderElementB (border, i, 0, f); 339 392 break; … … 355 408 356 409 // got an overlap; calculate cross-product and add to output array 410 # if (HAVE_MODEL_VAR) 357 411 f = pmSourceModelDotModel (SRCi, SRCj, fitVarMode, covarFactor, maskVal); 412 # else 413 f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 414 # endif 358 415 psSparseMatrixElement (sparse, j, i, f); 359 416 } … … 393 450 394 451 // set the sky, sky_x, sky_y components of border matrix 452 # if (HAVE_MODEL_VAR) 395 453 SetBorderMatrixElements (border, readout, fitSources, (fitVarMode == PM_SOURCE_PHOTFIT_CONST), SKY_FIT_ORDER, markVal); 454 # else 455 SetBorderMatrixElements (border, readout, fitSources, CONSTANT_PHOTOMETRIC_WEIGHTS, SKY_FIT_ORDER, markVal); 456 # endif 396 457 397 458 psSparseConstraint constraint; … … 552 613 } 553 614 615 # if (HAVE_MODEL_VAR) 554 616 bool psphotModelBackgroundReadout(psImage *model, // Model image 555 617 psImage *modelStdev, // Model stdev image … … 661 723 return true; 662 724 } 725 # endif
Note:
See TracChangeset
for help on using the changeset viewer.
