- Timestamp:
- Jun 22, 2012, 3:33:32 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20120601/psphot/src/psphotFitSourcesLinear.c
r34049 r34053 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)15 14 bool psphotGenerateModelVariance (pmConfig *config, const pmFPAview *view, pmFPAfile *file, int index, psMetadata *recipe, pmReadout *readout, psArray *sources); 16 15 pmSourceFitVarMode psphotGetFitVarMode (psMetadata *recipe); 17 16 bool psphotFreeModelVariance (pmReadout *readout, psArray *sources); 18 # endif19 17 20 18 // for now, let's store the detections on the readout->analysis for each readout … … 30 28 assert (recipe); 31 29 32 # if (HAVE_MODEL_VAR)33 30 pmSourceFitVarMode fitVarMode = psphotGetFitVarMode (recipe); 34 31 if (!fitVarMode) { … … 40 37 // do a single pass. 41 38 pmSourceFitVarMode fitVarModePass1 = (fitVarMode == PM_SOURCE_PHOTFIT_MODEL_VAR) ? PM_SOURCE_PHOTFIT_CONST : fitVarMode; 42 # endif43 39 44 40 int num = psphotFileruleCount(config, filerule); … … 68 64 psAssert (psf, "missing psf?"); 69 65 70 # if (HAVE_MODEL_VAR) 71 if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarModePass1)) 72 # else 73 if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final)) 74 # endif 75 { 66 if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarModePass1)) { 76 67 psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i); 77 68 return false; 78 69 } 79 70 80 # if (HAVE_MODEL_VAR)81 71 // the MODEL_VAR weighting scheme requires knowledge of the model fluxes to generate the variance 82 72 // after we have determined the initial set of fits, then we can generate the variance image and … … 104 94 } 105 95 } 106 # endif107 96 108 97 psphotVisualShowResidualImage (readout, (num > 0)); … … 113 102 } 114 103 115 # if (HAVE_MODEL_VAR)116 104 // look up the fit variance mode from the recipe; older recipes do not have the value 117 105 // 'LINEAR_FIT_VARIANCE_MODE'; in those cases, look for 'CONSTANT_PHOTOMETRIC_WEIGHTS' as a boolean and … … 136 124 return PM_SOURCE_PHOTFIT_IMAGE_VAR; 137 125 } 126 if (!strcasecmp(fitVarModeString, "SKY") || !strcasecmp(fitVarModeString, "MODEL_SKY")) { 127 return PM_SOURCE_PHOTFIT_MODEL_SKY; 128 } 138 129 if (!strcasecmp(fitVarModeString, "MODEL") || !strcasecmp(fitVarModeString, "MODEL_VAR")) { 139 130 return PM_SOURCE_PHOTFIT_MODEL_VAR; … … 142 133 return PM_SOURCE_PHOTFIT_NONE; 143 134 } 144 # endif 145 146 # if (HAVE_MODEL_VAR) 147 bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode) 148 # else 149 bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final) 150 # endif 151 { 135 136 bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode) { 152 137 bool status; 153 138 float x; … … 185 170 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 186 171 187 # if (!HAVE_MODEL_VAR)188 bool CONSTANT_PHOTOMETRIC_WEIGHTS =189 psMetadataLookupBool(&status, recipe, "CONSTANT_PHOTOMETRIC_WEIGHTS");190 if (!status) {191 psAbort("You must provide a value for the BOOL recipe CONSTANT_PHOTOMETRIC_WEIGHTS");192 }193 # endif194 172 int SKY_FIT_ORDER = psMetadataLookupS32(&status, recipe, "SKY_FIT_ORDER"); 195 173 if (!status) { … … 319 297 psSparseBorder *border = psSparseBorderAlloc (sparse, nBorder); 320 298 321 # if (HAVE_MODEL_VAR)322 299 // if fitVarMode is MODEL_VAR, then we need to generate the model image variance 323 300 // XXX we have two possibilities here: … … 327 304 328 305 // 2) do a single pass, and use the model guess to define the model variance (but do I trust the Model Guess?) 329 # endif330 306 331 307 // fill out the sparse matrix elements and border elements (B) … … 336 312 337 313 // diagonal elements of the sparse matrix (auto-cross-product) 338 # if (HAVE_MODEL_VAR)339 314 f = pmSourceModelDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal); 340 # else341 f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);342 # endif343 315 psSparseMatrixElement (sparse, i, i, f); 344 316 345 # if (HAVE_MODEL_VAR) 346 // if we have used CONSTANT errors, then we need to calculate the value of the parameter error 347 if (fitVarMode != PM_SOURCE_PHOTFIT_IMAGE_VAR) { 317 // if we have used CONSTANT errors, then we need to re-calculate the value of the parameter error 318 if (fitVarMode == PM_SOURCE_PHOTFIT_CONST) { 348 319 float var = pmSourceModelDotModel (SRCi, SRCi, PM_SOURCE_PHOTFIT_IMAGE_VAR, covarFactor, maskVal); 349 320 errors->data.F32[i] = 1.0 / sqrt(var); … … 351 322 errors->data.F32[i] = 1.0 / sqrt(f); 352 323 } 353 # else354 // the formal error depends on the weighting scheme355 if (CONSTANT_PHOTOMETRIC_WEIGHTS) {356 float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor, maskVal);357 errors->data.F32[i] = 1.0 / sqrt(var);358 } else {359 errors->data.F32[i] = 1.0 / sqrt(f);360 }361 # endif362 324 363 325 // find the image x model value 364 # if (HAVE_MODEL_VAR)365 326 f = pmSourceDataDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal); 366 # else367 f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);368 # endif369 327 psSparseVectorElement (sparse, i, f); 370 328 … … 372 330 switch (SKY_FIT_ORDER) { 373 331 case 1: 374 # if (HAVE_MODEL_VAR)375 332 f = pmSourceModelWeight (SRCi, 1, fitVarMode, covarFactor, maskVal); 376 333 psSparseBorderElementB (border, i, 1, f); 377 334 f = pmSourceModelWeight (SRCi, 2, fitVarMode, covarFactor, maskVal); 378 335 psSparseBorderElementB (border, i, 2, f); 379 # else380 f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);381 psSparseBorderElementB (border, i, 1, f);382 f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);383 psSparseBorderElementB (border, i, 2, f);384 # endif385 336 386 337 case 0: 387 # if (HAVE_MODEL_VAR)388 338 f = pmSourceModelWeight (SRCi, 0, fitVarMode, covarFactor, maskVal); 389 # else390 f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);391 # endif392 339 psSparseBorderElementB (border, i, 0, f); 393 340 break; … … 409 356 410 357 // got an overlap; calculate cross-product and add to output array 411 # if (HAVE_MODEL_VAR)412 358 f = pmSourceModelDotModel (SRCi, SRCj, fitVarMode, covarFactor, maskVal); 413 # else414 f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);415 # endif416 359 psSparseMatrixElement (sparse, j, i, f); 417 360 } … … 451 394 452 395 // set the sky, sky_x, sky_y components of border matrix 453 # if (HAVE_MODEL_VAR)454 396 SetBorderMatrixElements (border, readout, fitSources, (fitVarMode == PM_SOURCE_PHOTFIT_CONST), SKY_FIT_ORDER, markVal); 455 # else456 SetBorderMatrixElements (border, readout, fitSources, CONSTANT_PHOTOMETRIC_WEIGHTS, SKY_FIT_ORDER, markVal);457 # endif458 397 459 398 psSparseConstraint constraint; … … 614 553 } 615 554 616 # if (HAVE_MODEL_VAR)617 555 bool psphotModelBackgroundReadout(psImage *model, // Model image 618 556 psImage *modelStdev, // Model stdev image … … 650 588 psImage *varModelStdev = psImageAlloc(backBinning->nXruff, backBinning->nYruff, PS_TYPE_F32); // Background model 651 589 590 // generate an image of the mean variance image in DN 652 591 if (!psphotModelBackgroundReadout(varModel, varModelStdev, NULL, readout, backBinning, config, true)) { 653 592 psError(PS_ERR_UNKNOWN, false, "Unable to generate background model"); … … 668 607 psFree (varModelStdev); 669 608 670 // XXX for a test: 671 psphotSaveImage (NULL, modelVar, "model.bck.fits"); 609 float gain = 1.0; // accept 1.0 as a default since it is not critical to the analysis 610 pmCell *cell = readout->parent; // The parent cell 611 if (cell) { 612 gain = psMetadataLookupF32(&status, cell->concepts, "CELL.GAIN"); // Cell gain 613 if (!status) { 614 gain = 1.0; // set note above 615 } 616 } 617 if (gain > 2.0) { /* warn? */ } 672 618 673 619 // insert all of the source models … … 690 636 691 637 // add the source model to the model variance image 638 // XXX note that this should be added with gain applied 639 // var_DN = flux_DN / gain [e/DN] 640 // to do this requires an API upgrade... 692 641 pmSourceAdd (source, PM_MODEL_OP_MODELVAR, maskVal); 693 642 } 694 695 // XXX for a test:696 psphotSaveImage (NULL, modelVar, "model.var.fits");697 psphotSaveImage (NULL, readout->variance, "image.var.fits");698 643 699 644 // we save the model variance for future reference … … 724 669 return true; 725 670 } 726 # endif
Note:
See TracChangeset
for help on using the changeset viewer.
