Changeset 25027 for branches/pap/psModules/src/camera/pmFPAMaskWeight.c
- Timestamp:
- Aug 7, 2009, 4:08:25 PM (17 years ago)
- Location:
- branches/pap
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/psModules
- Property svn:mergeinfo deleted
-
branches/pap/psModules/src/camera/pmFPAMaskWeight.c
r23259 r25027 109 109 float saturation = psMetadataLookupF32(&mdok, cell->concepts, "CELL.SATURATION"); // Saturation level 110 110 if (!mdok || isnan(saturation)) { 111 psError(PS_ERR_IO, true, "CELL.SATURATION is not set --- unable to set mask.\n"); 112 return false; 111 // psError(PS_ERR_IO, true, "CELL.SATURATION is not set --- unable to set mask.\n"); 112 // return false; 113 psWarning("CELL.SATURATION is not set --- completely masking cell.\n"); 114 saturation = NAN; 113 115 } 114 116 float bad = psMetadataLookupF32(&mdok, cell->concepts, "CELL.BAD"); // Bad level 115 117 if (!mdok || isnan(bad)) { 116 psError(PS_ERR_IO, true, "CELL.BAD is not set --- unable to set mask.\n"); 117 return false; 118 // psError(PS_ERR_IO, true, "CELL.BAD is not set --- unable to set mask.\n"); 119 // return false; 120 psWarning("CELL.BAD is not set --- completely masking cell.\n"); 121 bad = NAN; 118 122 } 119 123 psTrace("psModules.camera", 5, "Saturation: %f, bad: %f\n", saturation, bad); 120 124 125 // if CELL.GAIN or CELL.READNOISE are not set, then the variance will be set to NAN; 126 // in this case, we have to set the mask as well 127 float gain = psMetadataLookupF32(&mdok, cell->concepts, "CELL.GAIN"); // Cell gain 128 if (!mdok) { gain = NAN; } 129 float readnoise = psMetadataLookupF32(&mdok, cell->concepts, "CELL.READNOISE"); // Cell read noise 130 if (!mdok) { readnoise = NAN; } 121 131 122 132 // Set up the mask … … 127 137 } 128 138 psImage *mask = readout->mask; // The mask pixels 139 140 // completely mask if SATURATION or BAD are invalid 141 if (isnan(saturation) || isnan(bad) || isnan(gain) || isnan(readnoise)) { 142 psImageInit(mask, badMask); 143 return true; 144 } 145 129 146 psImageInit(mask, 0); 130 147 … … 199 216 } 200 217 201 bool pmReadoutSetVariance(pmReadout *readout, bool poisson)218 bool pmReadoutSetVariance(pmReadout *readout, const psImage *noiseMap, bool poisson) 202 219 { 203 220 PS_ASSERT_PTR_NON_NULL(readout, false); 221 // check that the noiseMap (if it exists) matches the readout variance size) 204 222 205 223 pmCell *cell = readout->parent; // The parent cell … … 209 227 float gain = psMetadataLookupF32(&mdok, cell->concepts, "CELL.GAIN"); // Cell gain 210 228 if (!mdok || isnan(gain)) { 211 psError(PS_ERR_IO, true, "CELL.GAIN is not set --- unable to set variance.\n"); 212 return false; 229 // psError(PS_ERR_IO, true, "CELL.GAIN is not set --- unable to set variance.\n"); 230 // return false; 231 psWarning("CELL.GAIN is not set --- setting variance to NAN\n"); 232 gain = NAN; 213 233 } 214 234 float readnoise = psMetadataLookupF32(&mdok, cell->concepts, "CELL.READNOISE"); // Cell read noise 215 235 if (!mdok || isnan(readnoise)) { 216 psError(PS_ERR_IO, true, "CELL.READNOISE is not set --- unable to set variance.\n"); 217 return false; 218 } 219 if (psMetadataLookup(cell->concepts, "CELL.READNOISE.UPDATE")) { 236 // psError(PS_ERR_IO, true, "CELL.READNOISE is not set --- unable to set variance.\n"); 237 // return false; 238 psWarning("CELL.READNOISE is not set --- setting variance to NAN\n"); 239 readnoise = NAN; 240 } 241 // if we have a non-NAN readnoise, then we need to ensure it has been updated (not necessary if NAN) 242 if (!isnan(gain) && psMetadataLookup(cell->concepts, "CELL.READNOISE.UPDATE")) { 220 243 psError(PS_ERR_IO, true, "CELL.READNOISE has not yet been updated for the gain"); 221 244 return false; 245 } 246 247 // for invalid input data, set the readout variance to NAN 248 if (isnan(gain) || isnan(readnoise)) { 249 if (!readout->variance) { 250 // generate the image if needed 251 readout->variance = psImageAlloc(readout->image->numCols, readout->image->numRows, PS_TYPE_F32); 252 } 253 // XXX need to set the mask, if defined 254 psImageInit(readout->variance, NAN); 255 return true; 222 256 } 223 257 … … 228 262 229 263 // a negative variance is non-sensical. if the image value drops below 1, the variance must be 1. 264 // XXX this calculation is wrong: limit is 1 e-, but this is in DN 230 265 readout->variance = (psImage*)psUnaryOp(readout->variance, readout->variance, "abs"); 231 266 readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "max", … … 239 274 } 240 275 241 readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+", 242 psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32)); 276 // apply a supplied readnoise map (NOTE: in DN, not electrons): 277 if (noiseMap) { 278 psImage *rdVar = (psImage*)psBinaryOp(NULL, (const psPtr) noiseMap, "*", (const psPtr) noiseMap); 279 readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+", rdVar); 280 psFree (rdVar); 281 } else { 282 readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+", psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32)); 283 } 243 284 244 285 return true; … … 247 288 // this function creates the variance pixels, or uses the existing variance pixels. it will set 248 289 // the noise pixel values only if the variance image is not supplied 249 bool pmReadoutGenerateVariance(pmReadout *readout, bool poisson)290 bool pmReadoutGenerateVariance(pmReadout *readout, const psImage *noiseMap, bool poisson) 250 291 { 251 292 PS_ASSERT_PTR_NON_NULL(readout, false); … … 291 332 readout->variance = variance; 292 333 293 return pmReadoutSetVariance(readout, poisson);294 } 295 296 bool pmReadoutGenerateMaskVariance(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask, bool poisson)334 return pmReadoutSetVariance(readout, noiseMap, poisson); 335 } 336 337 bool pmReadoutGenerateMaskVariance(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask, const psImage *noiseMap, bool poisson) 297 338 { 298 339 PS_ASSERT_PTR_NON_NULL(readout, false); … … 301 342 302 343 success &= pmReadoutGenerateMask(readout, satMask, badMask); 303 success &= pmReadoutGenerateVariance(readout, poisson);344 success &= pmReadoutGenerateVariance(readout, noiseMap, poisson); 304 345 305 346 return success; 306 347 } 307 348 308 bool pmCellGenerateMaskVariance(pmCell *cell, psImageMaskType satMask, psImageMaskType badMask, bool poisson)349 bool pmCellGenerateMaskVariance(pmCell *cell, psImageMaskType satMask, psImageMaskType badMask, const psImage *noiseMap, bool poisson) 309 350 { 310 351 PS_ASSERT_PTR_NON_NULL(cell, false); … … 314 355 for (int i = 0; i < readouts->n; i++) { 315 356 pmReadout *readout = readouts->data[i]; // The readout 316 success &= pmReadoutGenerateMaskVariance(readout, poisson, satMask, badMask);357 success &= pmReadoutGenerateMaskVariance(readout, satMask, badMask, noiseMap, poisson); 317 358 } 318 359 … … 482 523 return false; 483 524 } 484 float stdev = psStatsGetValue(stdevStats, stdevStat); // Sta dard deviation of fluxes525 float stdev = psStatsGetValue(stdevStats, stdevStat); // Standard deviation of fluxes 485 526 psFree(stdevStats); 486 527 psFree(noise);
Note:
See TracChangeset
for help on using the changeset viewer.
