Changeset 34086 for trunk/psphot/src/psphotMaskReadout.c
- Timestamp:
- Jun 26, 2012, 11:33:10 AM (14 years ago)
- Location:
- trunk/psphot
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20120601/psphot (added) merged: 34002,34032,34049,34051,34053,34055-34056,34060-34061,34071-34073,34076,34078
- Property svn:mergeinfo changed
-
trunk/psphot/src
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20120601/psphot/src (added) merged: 34049,34051,34053,34060-34061,34071-34073,34078
- Property svn:mergeinfo changed
-
trunk/psphot/src/psphotMaskReadout.c
r29936 r34086 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 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 138 psAssert (file, "missing file?"); 139 140 // find the currently selected readout 141 pmReadout *readout = pmFPAviewThisReadout (view, file->fpa); 142 psAssert (readout, "missing readout?"); 143 144 pmSourceFitVarMode varMode = psphotGetFitVarMode (recipe); 145 if (varMode == PM_SOURCE_PHOTFIT_NONE) { 146 psError (PSPHOT_ERR_CONFIG, false, "need valid LINEAR_FIT_VARIANCE_MODE"); 147 return false; 148 } 149 150 // make this an option via the recipe 151 if (varMode != PM_SOURCE_PHOTFIT_MODEL_SKY) return true; 152 153 // create a model variance image (full-scale image to take result of psImageUnbin below) 154 psImage *modelVar = psImageCopy (NULL, readout->variance, PS_TYPE_F32); 155 156 // find the binning information 157 psImageBinning *backBinning = psphotBackgroundBinning (modelVar, config); 158 assert (backBinning); 159 160 psImage *varModel = psImageAlloc(backBinning->nXruff, backBinning->nYruff, PS_TYPE_F32); // Background model 161 psImage *varModelStdev = psImageAlloc(backBinning->nXruff, backBinning->nYruff, PS_TYPE_F32); // Background model 162 163 if (!psphotModelBackgroundReadout(varModel, varModelStdev, NULL, readout, backBinning, config, true)) { 164 psError(PS_ERR_UNKNOWN, false, "Unable to generate background model"); 165 psFree (varModel); 166 psFree (varModelStdev); 167 return false; 168 } 169 170 // linear interpolation to full-scale 171 if (!psImageUnbin (modelVar, varModel, backBinning)) { 172 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for unbinning"); 173 psFree (varModel); 174 psFree (varModelStdev); 175 return false; 176 } 177 178 // XXX save these? 179 psFree (varModel); 180 psFree (varModelStdev); 181 182 psImage *im = readout->image; 183 psImage *wt = readout->variance; 184 for (int j = 0; j < im->numRows; j++) { 185 for (int i = 0; i < im->numCols; i++) { 186 if (!isfinite(im->data.F32[j][i])) continue; 187 if (!isfinite(wt->data.F32[j][i])) continue; 188 // XXX for a test, make variance constant wt->data.F32[j][i] = PS_MAX(wt->data.F32[j][i], modelVar->data.F32[j][i]); 189 wt->data.F32[j][i] = modelVar->data.F32[j][i]; 190 } 191 } 192 193 // test output of files at this stage 194 if (psTraceGetLevel("psphot.imsave") >= 5) { 195 psphotSaveImage (NULL, readout->image, "image.varsky.fits"); 196 psphotSaveImage (NULL, readout->mask, "mask.varsky.fits"); 197 psphotSaveImage (NULL, readout->variance, "variance.varsky.fits"); 198 } 199 200 psFree (modelVar); 201 202 return true; 203 }
Note:
See TracChangeset
for help on using the changeset viewer.
