Changeset 34053 for branches/eam_branches/ipp-20120601/psphot/src
- Timestamp:
- Jun 22, 2012, 3:33:32 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20120601/psphot/src
- Files:
-
- 4 edited
-
psphot.h (modified) (2 diffs)
-
psphotEfficiency.c (modified) (1 diff)
-
psphotFitSourcesLinear.c (modified) (21 diffs)
-
psphotMaskReadout.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20120601/psphot/src/psphot.h
r34049 r34053 61 61 bool psphotSetMaskAndVarianceReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 62 62 63 bool psphotUpdateVariance (pmConfig *config, const pmFPAview *view, const char *filerule); 64 bool psphotUpdateVarianceReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 65 63 66 bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filerule); 64 67 bool psphotModelBackgroundReadoutFileIndex (pmConfig *config, const pmFPAview *view, const char *filerule, int index); … … 99 102 100 103 bool psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, const char *filerule, bool final); 101 102 # if (HAVE_MODEL_VAR)103 104 bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode); 104 # else105 bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final);106 # endif107 105 108 106 bool psphotSourceSize (pmConfig *config, const pmFPAview *view, const char *filerule, bool getPSFsize); -
branches/eam_branches/ipp-20120601/psphot/src/psphotEfficiency.c
r34049 r34053 420 420 421 421 // psphotFitSourcesLinearReadout subtracts the model fits 422 # if (HAVE_MODEL_VAR)423 422 if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true, PM_SOURCE_PHOTFIT_CONST)) { 424 # else425 if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true)) {426 # endif427 423 psError(PS_ERR_UNKNOWN, false, "Unable to perform linear fit on fake sources."); 428 424 psFree(fakeSources); -
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 -
branches/eam_branches/ipp-20120601/psphot/src/psphotMaskReadout.c
r29936 r34053 94 94 95 95 // test output of files at this stage 96 if (psTraceGetLevel("psphot ") >= 5) {96 if (psTraceGetLevel("psphot.imsave") >= 5) { 97 97 psphotSaveImage (NULL, readout->image, "image.fits"); 98 98 psphotSaveImage (NULL, readout->mask, "mask.fits"); … … 105 105 return true; 106 106 } 107 108 // XXX this function and support below was created to test the theory that the faint-end 109 // bias results from the Poisson variation of the background pixels. This is NOT the 110 // case. Using the code below maintains the faint-end bias. 111 bool psphotUpdateVariance (pmConfig *config, const pmFPAview *view, const char *filerule) { 112 113 bool status = false; 114 115 // select the appropriate recipe information 116 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 117 psAssert (recipe, "missing recipe?"); 118 119 int num = psphotFileruleCount(config, filerule); 120 121 // loop over the available readouts 122 for (int i = 0; i < num; i++) { 123 124 // Generate the mask and weight images, including the user-defined analysis region of interest 125 if (!psphotUpdateVarianceReadout (config, view, filerule, i, recipe)) { 126 psError (PSPHOT_ERR_CONFIG, false, "failed to generate mask for %s entry %d", filerule, i); 127 return false; 128 } 129 } 130 return true; 131 } 132 133 // determine the mean variance image (equivalent to the background model, but for the variance image) 134 // set the variance image to the MAX(input, mean) 135 bool psphotUpdateVarianceReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 136 137 bool status; 138 139 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 140 psAssert (file, "missing file?"); 141 142 // find the currently selected readout 143 pmReadout *readout = pmFPAviewThisReadout (view, file->fpa); 144 psAssert (readout, "missing readout?"); 145 146 pmSourceFitVarMode varMode = psphotGetFitVarMode (recipe); 147 if (varMode == PM_SOURCE_PHOTFIT_NONE) { 148 psError (PSPHOT_ERR_CONFIG, false, "need valid LINEAR_FIT_VARIANCE_MODE"); 149 return false; 150 } 151 152 // make this an option via the recipe 153 if (varMode != PM_SOURCE_PHOTFIT_MODEL_SKY) return true; 154 155 // create a model variance image (full-scale image to take result of psImageUnbin below) 156 psImage *modelVar = psImageCopy (NULL, readout->variance, PS_TYPE_F32); 157 158 // find the binning information 159 psImageBinning *backBinning = psphotBackgroundBinning (modelVar, config); 160 assert (backBinning); 161 162 psImage *varModel = psImageAlloc(backBinning->nXruff, backBinning->nYruff, PS_TYPE_F32); // Background model 163 psImage *varModelStdev = psImageAlloc(backBinning->nXruff, backBinning->nYruff, PS_TYPE_F32); // Background model 164 165 if (!psphotModelBackgroundReadout(varModel, varModelStdev, NULL, readout, backBinning, config, true)) { 166 psError(PS_ERR_UNKNOWN, false, "Unable to generate background model"); 167 psFree (varModel); 168 psFree (varModelStdev); 169 return false; 170 } 171 172 // linear interpolation to full-scale 173 if (!psImageUnbin (modelVar, varModel, backBinning)) { 174 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for unbinning"); 175 psFree (varModel); 176 psFree (varModelStdev); 177 return false; 178 } 179 180 // XXX save these? 181 psFree (varModel); 182 psFree (varModelStdev); 183 184 psImage *im = readout->image; 185 psImage *wt = readout->variance; 186 for (int j = 0; j < im->numRows; j++) { 187 for (int i = 0; i < im->numCols; i++) { 188 if (!isfinite(im->data.F32[j][i])) continue; 189 if (!isfinite(wt->data.F32[j][i])) continue; 190 // XXX for a test, make variance constant wt->data.F32[j][i] = PS_MAX(wt->data.F32[j][i], modelVar->data.F32[j][i]); 191 wt->data.F32[j][i] = modelVar->data.F32[j][i]; 192 } 193 } 194 195 // test output of files at this stage 196 if (psTraceGetLevel("psphot.imsave") >= 5) { 197 psphotSaveImage (NULL, readout->image, "image.varsky.fits"); 198 psphotSaveImage (NULL, readout->mask, "mask.varsky.fits"); 199 psphotSaveImage (NULL, readout->variance, "variance.varsky.fits"); 200 } 201 202 psFree (modelVar); 203 204 return true; 205 }
Note:
See TracChangeset
for help on using the changeset viewer.
