Changeset 42679 for branches/2dbias/ppImage/src/ppImageDetrendReadout.c
- Timestamp:
- May 21, 2024, 8:50:38 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2dbias/ppImage/src/ppImageDetrendReadout.c
r42382 r42679 5 5 #include "ppImage.h" 6 6 7 #define ESCAPE(STATUS, ...) \ 8 { \ 9 psError(PS_ERR_UNKNOWN, STATUS, __VA_ARGS__); \ 10 psFree(view); \ 11 return false; \ 12 } 13 7 14 bool ppImageDetrendReadout(pmConfig *config, ppImageOptions *options, pmFPAview *view) 8 15 { 9 // psTimerStart("detrend.readout");16 // psTimerStart("detrend.readout"); 10 17 11 18 // construct a view for the detrend images (which have only one readout) … … 18 25 19 26 // Check that the gain is set (this is used by both pmReadoutGenerateMask and pmReadoutGenerateVariance) 20 { 21 float gain = psMetadataLookupF32(NULL, input->parent->concepts, "CELL.GAIN"); // Gain for cell 22 if (!isfinite(gain)) { 23 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, RECIPE_NAME); // Recipe 24 psAssert(recipe, "Should be there!"); 25 bool override = psMetadataLookupBool(NULL, recipe, "GAIN.OVERRIDE"); // Override the bad gain? 26 if (override) { 27 psWarning("CELL.GAIN is not set for readout (%d,%d,%d) --- setting to unity.", view->chip, view->cell, view->readout); 28 psMetadataItem *item = psMetadataLookup(input->parent->concepts, "CELL.GAIN"); // Gain item 29 psAssert(item, "Should be there!"); 30 item->data.F32 = 1.0; 31 32 // for unity gain, there is no modification for the readnoise, note that it has (effectively) been updated 33 psMetadataRemoveKey(input->parent->concepts, "CELL.READNOISE.UPDATE"); 34 } else { 35 psWarning("CELL.GAIN is NAN for readout (%d,%d,%d), image will be masked.", view->chip, view->cell, view->readout); 36 } 37 } 27 { 28 float gain = psMetadataLookupF32(NULL, input->parent->concepts, "CELL.GAIN"); // Gain for cell 29 if (!isfinite(gain)) 30 { 31 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, RECIPE_NAME); // Recipe 32 psAssert(recipe, "Should be there!"); 33 bool override = psMetadataLookupBool(NULL, recipe, "GAIN.OVERRIDE"); // Override the bad gain? 34 if (override) 35 { 36 psWarning("CELL.GAIN is not set for readout (%d,%d,%d) --- setting to unity.", view->chip, view->cell, view->readout); 37 psMetadataItem *item = psMetadataLookup(input->parent->concepts, "CELL.GAIN"); // Gain item 38 psAssert(item, "Should be there!"); 39 item->data.F32 = 1.0; 40 41 // for unity gain, there is no modification for the readnoise, note that it has (effectively) been updated 42 psMetadataRemoveKey(input->parent->concepts, "CELL.READNOISE.UPDATE"); 43 } 44 else 45 { 46 psWarning("CELL.GAIN is NAN for readout (%d,%d,%d), image will be masked.", view->chip, view->cell, view->readout); 47 } 48 } 38 49 } 39 50 // psLogMsg ("ppImage", 6, "check gain: %f sec\n", psTimerMark ("detrend.readout")); … … 43 54 bool hasVideo = false; 44 55 { 45 // XXX test for GPC1? or CAN_HAVE_VIDEO in camera config? 46 bool status = false; 47 if (!input) goto done_video_check; 48 if (!input->parent) goto done_video_check; 49 if (!input->parent->parent) goto done_video_check; 50 if (!input->parent->parent->hdu) goto done_video_check; 51 if (!input->parent->parent->hdu->header) goto done_video_check; 52 char *ptr = psMetadataLookupStr(&status,input->parent->parent->hdu->header,"CELLMODE"); 53 if (status) { 54 psLogMsg ("ppImage.detrend", PS_LOG_DETAIL, "VIDEO: %d %d %d\n",(int) options->hasVideo,(int) options->useVideoDark, (int) options->useVideoMask); 55 char *Vptr = strchr(ptr,'V'); 56 if (Vptr) { 57 hasVideo = options->hasVideo = true; 58 psLogMsg ("ppImage.detrend", PS_LOG_INFO, "VIDEO: %d %d %d\n",(int) options->hasVideo,(int) options->useVideoDark, (int) options->useVideoMask); 59 } 60 } 61 } 62 done_video_check: 56 // XXX test for GPC1? or CAN_HAVE_VIDEO in camera config? 57 bool status = false; 58 if (!input) 59 goto done_video_check; 60 if (!input->parent) 61 goto done_video_check; 62 if (!input->parent->parent) 63 goto done_video_check; 64 if (!input->parent->parent->hdu) 65 goto done_video_check; 66 if (!input->parent->parent->hdu->header) 67 goto done_video_check; 68 char *ptr = psMetadataLookupStr(&status, input->parent->parent->hdu->header, "CELLMODE"); 69 if (status) 70 { 71 psLogMsg("ppImage.detrend", PS_LOG_DETAIL, "VIDEO: %d %d %d\n", (int)options->hasVideo, (int)options->useVideoDark, (int)options->useVideoMask); 72 char *Vptr = strchr(ptr, 'V'); 73 if (Vptr) 74 { 75 hasVideo = options->hasVideo = true; 76 psLogMsg("ppImage.detrend", PS_LOG_INFO, "VIDEO: %d %d %d\n", (int)options->hasVideo, (int)options->useVideoDark, (int)options->useVideoMask); 77 } 78 } 79 } 80 done_video_check: 63 81 // psLogMsg ("ppImage", 6, "check video: %f sec\n", psTimerMark ("detrend.readout")); 64 82 … … 74 92 75 93 // Masking on the basis of pixel value needs to be done before anything else, so the values are pristine. 76 if (options->doMaskBuild) { 94 if (options->doMaskBuild) 95 { 77 96 psImageMaskType satMask = options->doMaskSat ? options->satMask : 0; 78 97 psImageMaskType lowMask = options->doMaskLow ? options->lowMask : 0; 79 if (!pmReadoutGenerateMask(input, satMask, lowMask)) { 80 psError(PS_ERR_UNKNOWN, false, "Unable to generate a mask."); 81 psFree(detview); 82 return false; 83 } 84 // psLogMsg ("ppImage", 6, "generate mask: %f sec\n", psTimerMark ("detrend.readout")); 98 if (!pmReadoutGenerateMask(input, satMask, lowMask)) 99 { 100 psError(PS_ERR_UNKNOWN, false, "Unable to generate a mask."); 101 psFree(detview); 102 return false; 103 } 104 // psLogMsg ("ppImage", 6, "generate mask: %f sec\n", psTimerMark ("detrend.readout")); 85 105 } 86 106 // apply the externally supplied mask to the input->mask pixels 87 if (options->doMask) { 88 pmReadout *mask; 89 if ((options->useVideoMask)&&(hasVideo)) { 90 mask = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.VIDEOMASK"); 91 } 92 else { 93 mask = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.MASK"); 94 } 95 pmMaskBadPixels(input, mask, options->maskValue); 96 // psLogMsg ("ppImage", 6, "apply mask: %f sec\n", psTimerMark ("detrend.readout")); 107 if (options->doMask) 108 { 109 pmReadout *mask; 110 if ((options->useVideoMask) && (hasVideo)) 111 { 112 mask = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.VIDEOMASK"); 113 } 114 else 115 { 116 mask = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.MASK"); 117 } 118 pmMaskBadPixels(input, mask, options->maskValue); 119 // psLogMsg ("ppImage", 6, "apply mask: %f sec\n", psTimerMark ("detrend.readout")); 97 120 } 98 121 … … 101 124 // extern bool ppImageBurntoolApply(pmConfig *, ppImageOptions *, pmFPAview *, pmReadout *); 102 125 ppImageBurntoolApply(config, options, view, input); 103 // psLogMsg ("ppImage", 6, "apply burntool: %f sec\n", psTimerMark ("detrend.readout")); 104 } 105 106 if (options->doMaskBurntool) { 107 if (options->doApplyBurntool) { 126 // psLogMsg ("ppImage", 6, "apply burntool: %f sec\n", psTimerMark ("detrend.readout")); 127 } 128 129 if (options->doMaskBurntool) 130 { 131 if (options->doApplyBurntool) 132 { 108 133 // build burntool mask from data input burntool table 109 ppImageBurntoolMaskFromTable(config,options,view,input); 110 } else { 134 ppImageBurntoolMaskFromTable(config, options, view, input); 135 } 136 else 137 { 111 138 // build burntool mask from data in the input image's fits extension 112 ppImageBurntoolMask(config, options,view,input);113 } 114 // psLogMsg ("ppImage", 6, "apply burntool mask: %f sec\n", psTimerMark ("detrend.readout"));139 ppImageBurntoolMask(config, options, view, input); 140 } 141 // psLogMsg ("ppImage", 6, "apply burntool mask: %f sec\n", psTimerMark ("detrend.readout")); 115 142 } 116 143 117 144 // Subtract the overscan 118 if (options->doOverscan) { 119 if (!pmOverscanSubtract (input, options->overscan)) { 120 psError(PS_ERR_UNKNOWN, false, "Unable to subtract overscan."); 121 psFree(detview); 122 return false; 123 } 124 // psLogMsg ("ppImage", 6, "subtract overscan: %f sec\n", psTimerMark ("detrend.readout")); 145 if (options->doOverscan) 146 { 147 bool doTwoDOverscan = false; 148 if (options->overscan->TwoD) 149 { 150 pmChip *chip = pmFPAfileThisChip(config->files, view, "PPIMAGE.INPUT"); 151 if (!ppImageDoPatternForView(&doTwoDOverscan, config, chip, view, RECIPE_NAME, "OVERSCAN.2D.SUBSET")) 152 { 153 ESCAPE(false, "Unable to determine whether 2D Overscan subtraction should be applied."); 154 } 155 } 156 if (!pmOverscanSubtract(input, options->overscan, doTwoDOverscan)) 157 { 158 psError(PS_ERR_UNKNOWN, false, "Unable to subtract overscan."); 159 psFree(detview); 160 return false; 161 } 162 // psLogMsg ("ppImage", 6, "subtract overscan: %f sec\n", psTimerMark ("detrend.readout")); 125 163 } 126 164 127 165 // measure the overscan-subtracted readoutBackground here (or subtract the overscan value?) 128 166 // XXX this is the measurements and should be independent of the pattern masking 129 if (options->doPatternDeadCells) { 130 psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 131 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); 132 psImageBackground (stats, NULL, input->image, NULL, 0xffff, rng); 133 134 // save this value somewhere 135 pmHDU *hdu = pmHDUFromReadout(input); // HDU of interest 136 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "BACK_VAL", PS_META_REPLACE, "Median cell background", stats->robustMedian); 137 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "BACK_ERR", PS_META_REPLACE, "Stdev of cell background", stats->robustStdev); 138 psFree (stats); 139 psFree (rng); 167 if (options->doPatternDeadCells) 168 { 169 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 170 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); 171 psImageBackground(stats, NULL, input->image, NULL, 0xffff, rng); 172 173 // save this value somewhere 174 pmHDU *hdu = pmHDUFromReadout(input); // HDU of interest 175 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "BACK_VAL", PS_META_REPLACE, "Median cell background", stats->robustMedian); 176 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "BACK_ERR", PS_META_REPLACE, "Stdev of cell background", stats->robustStdev); 177 psFree(stats); 178 psFree(rng); 140 179 } 141 180 142 181 // Non-linearity correction 143 if (options->doNonLin) { 144 if (!ppImageDetrendNonLinear(input,detview,config)) { 145 psError(PS_ERR_UNKNOWN, false, "Unable to correct NonLinearity"); 146 psFree(detview); 147 return(false); 148 } 149 // psLogMsg ("ppImage", 6, "nonlinear correction: %f sec\n", psTimerMark ("detrend.readout")); 182 if (options->doNonLin) 183 { 184 if (!ppImageDetrendNonLinear(input, detview, config)) 185 { 186 psError(PS_ERR_UNKNOWN, false, "Unable to correct NonLinearity"); 187 psFree(detview); 188 return (false); 189 } 190 // psLogMsg ("ppImage", 6, "nonlinear correction: %f sec\n", psTimerMark ("detrend.readout")); 150 191 } 151 192 // New Non-linearity correction (exclusive of the above) 152 if (options->doNewNonLin) { 153 if (!ppImageDetrendNewNonLinear(input, detview, config)) { 154 psError(PS_ERR_UNKNOWN, false, "Unable to correct Non-Linearity with new version (2023)"); 155 psFree(detview); 156 return(false); 157 } 158 // psLogMsg ("ppImage", 6, "nonlinear correction: %f sec\n", psTimerMark ("detrend.readout")); 193 if (options->doNewNonLin) 194 { 195 if (!ppImageDetrendNewNonLinear(input, detview, config)) 196 { 197 psError(PS_ERR_UNKNOWN, false, "Unable to correct Non-Linearity with new version (2023)"); 198 psFree(detview); 199 return (false); 200 } 201 // psLogMsg ("ppImage", 6, "nonlinear correction: %f sec\n", psTimerMark ("detrend.readout")); 159 202 } 160 203 161 204 // set up the dark and bias 162 pmCell *dark = NULL; // Multi-dark 163 pmReadout *oldDark = NULL; // Old-fashioned dark 164 pmReadout *bias = NULL; 165 if (options->doBias) { 205 pmCell *dark = NULL; // Multi-dark 206 pmReadout *oldDark = NULL; // Old-fashioned dark 207 pmReadout *bias = NULL; 208 if (options->doBias) 209 { 166 210 bias = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.BIAS"); 167 211 } 168 if (options->doDark) { 169 bool mdok; // Status of MD lookup 170 psMetadata *recipe = psMetadataLookupPtr (&mdok, config->recipes, RECIPE_NAME); 212 if (options->doDark) 213 { 214 bool mdok; // Status of MD lookup 215 psMetadata *recipe = psMetadataLookupPtr(&mdok, config->recipes, RECIPE_NAME); 171 216 assert(mdok && recipe); 172 217 173 if ((options->useVideoDark)&&(hasVideo)) { 174 if (psMetadataLookupBool(&mdok, recipe, "OLDDARK")) { 175 oldDark = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.VIDEODARK"); 176 } else { 177 dark = pmFPAfileThisCell(config->files, detview, "PPIMAGE.VIDEODARK"); 178 } 179 } 180 else { 181 if (psMetadataLookupBool(&mdok, recipe, "OLDDARK")) { 182 oldDark = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.DARK"); 183 } else { 184 dark = pmFPAfileThisCell(config->files, detview, "PPIMAGE.DARK"); 185 } 186 } 218 if ((options->useVideoDark) && (hasVideo)) 219 { 220 if (psMetadataLookupBool(&mdok, recipe, "OLDDARK")) 221 { 222 oldDark = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.VIDEODARK"); 223 } 224 else 225 { 226 dark = pmFPAfileThisCell(config->files, detview, "PPIMAGE.VIDEODARK"); 227 } 228 } 229 else 230 { 231 if (psMetadataLookupBool(&mdok, recipe, "OLDDARK")) 232 { 233 oldDark = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.DARK"); 234 } 235 else 236 { 237 dark = pmFPAfileThisCell(config->files, detview, "PPIMAGE.DARK"); 238 } 239 } 187 240 } 188 241 189 242 // Bias and temperature-independent-dark subtraction are merged. 190 if (options->doBias) { 191 if (!pmBiasSubtract(input, bias, oldDark, view)) { 243 if (options->doBias) 244 { 245 if (!pmBiasSubtract(input, bias, oldDark, view)) 246 { 192 247 psError(PS_ERR_UNKNOWN, false, "Unable to subtract bias."); 193 248 psFree(detview); 194 249 return false; 195 250 } 196 // psLogMsg ("ppImage", 6, "apply bias: %f sec\n", psTimerMark ("detrend.readout"));197 } 198 251 // psLogMsg ("ppImage", 6, "apply bias: %f sec\n", psTimerMark ("detrend.readout")); 252 } 253 199 254 // Weight on the basis of pixel value needs to be done after the overscan has been subtracted 200 if (options->doVarianceBuild) { 255 if (options->doVarianceBuild) 256 { 201 257 // create the target mask and variance images 202 258 psImage *noiseImage = NULL; 203 if (options->doNoiseMap) { 259 if (options->doNoiseMap) 260 { 204 261 // XXX convert the noiseMap image to a binned image 205 262 pmReadout *noiseMap = NULL; 206 263 noiseMap = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.NOISEMAP"); 207 noiseImage = psImageCopy (NULL, input->image, PS_TYPE_F32);208 psImageInit (noiseImage, 0.0);264 noiseImage = psImageCopy(NULL, input->image, PS_TYPE_F32); 265 psImageInit(noiseImage, 0.0); 209 266 210 267 // XXX this works, but is not really quite right: the model shoud include the 211 268 // offset information, we are not really getting exactly the right mapping from the 212 269 // original file. 213 // CZW 2012-03-21: I do not believe this is true anymore. In any case, this seems to be what214 // ppImageReplaceBackground does to do sky subtraction.270 // CZW 2012-03-21: I do not believe this is true anymore. In any case, this seems to be what 271 // ppImageReplaceBackground does to do sky subtraction. 215 272 psImageBinning *binning = psImageBinningAlloc(); 216 273 binning->nXruff = noiseMap->image->numCols; … … 220 277 psImageBinningSetScale(binning, PS_IMAGE_BINNING_LEFT); 221 278 222 psImageUnbin (noiseImage, noiseMap->image, binning); 223 psFree (binning); 224 } 225 226 if (!pmReadoutGenerateVariance(input, noiseImage, true)) { 227 psError(PS_ERR_UNKNOWN, false, "Unable to generate a variance image."); 228 psFree(detview); 229 return false; 230 } 231 psFree (noiseImage); 232 // psLogMsg ("ppImage", 6, "generate variance: %f sec\n", psTimerMark ("detrend.readout")); 233 } 234 235 if (options->doDark && dark) { 236 if (!pmDarkApply(input, dark, options->darkMask)) { 279 psImageUnbin(noiseImage, noiseMap->image, binning); 280 psFree(binning); 281 } 282 283 if (!pmReadoutGenerateVariance(input, noiseImage, true)) 284 { 285 psError(PS_ERR_UNKNOWN, false, "Unable to generate a variance image."); 286 psFree(detview); 287 return false; 288 } 289 psFree(noiseImage); 290 // psLogMsg ("ppImage", 6, "generate variance: %f sec\n", psTimerMark ("detrend.readout")); 291 } 292 293 if (options->doDark && dark) 294 { 295 if (!pmDarkApply(input, dark, options->darkMask)) 296 { 237 297 psError(PS_ERR_UNKNOWN, false, "Unable to subtract dark."); 238 298 psFree(detview); 239 299 return false; 240 300 } 241 // psLogMsg ("ppImage", 6, "apply dark: %f sec\n", psTimerMark ("detrend.readout")); 242 } 243 244 if (options->doRemnance) { 301 // psLogMsg ("ppImage", 6, "apply dark: %f sec\n", psTimerMark ("detrend.readout")); 302 } 303 304 if (options->doRemnance) 305 { 245 306 if (!pmRemnance(input, options->maskValue, options->lowMask, 246 options->remnanceSize, options->remnanceThresh)) { 307 options->remnanceSize, options->remnanceThresh)) 308 { 247 309 psError(PS_ERR_UNKNOWN, false, "Unable to mask remnance."); 248 310 psFree(detview); 249 311 return false; 250 312 } 251 // psLogMsg ("ppImage", 6, "mask remnance: %f sec\n", psTimerMark ("detrend.readout"));313 // psLogMsg ("ppImage", 6, "mask remnance: %f sec\n", psTimerMark ("detrend.readout")); 252 314 } 253 315 254 316 // Shutter correction 255 if (options->doShutter) { 317 if (options->doShutter) 318 { 256 319 pmReadout *shutter = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.SHUTTER"); 257 if (!pmShutterCorrectionApply(input, shutter, pmConfigMaskGet("FLAT", config))) { 258 psFree(detview); 259 return false; 260 } 261 // psLogMsg ("ppImage", 6, "shutter correction: %f sec\n", psTimerMark ("detrend.readout")); 320 if (!pmShutterCorrectionApply(input, shutter, pmConfigMaskGet("FLAT", config))) 321 { 322 psFree(detview); 323 return false; 324 } 325 // psLogMsg ("ppImage", 6, "shutter correction: %f sec\n", psTimerMark ("detrend.readout")); 262 326 } 263 327 264 328 // Flat-field correction (no options used?) 265 if (options->doFlat) { 329 if (options->doFlat) 330 { 266 331 pmReadout *flat = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.FLAT"); 267 if (!pmFlatField(input, flat, options->flatMask)) { 268 psFree(detview); 269 return false; 270 } 271 // psLogMsg ("ppImage", 6, "apply flat: %f sec\n", psTimerMark ("detrend.readout")); 272 } 273 274 /* // Pattern noise correction */ 275 /* if (options->doPattern) { */ 276 /* if (!pmPatternRow(input, options->patternOrder, options->patternIter, options->patternRej, */ 277 /* options->patternThresh, options->patternMean, options->patternStdev, */ 278 /* options->maskValue, options->darkMask)) { */ 279 /* psFree(detview); */ 280 /* return false; */ 281 /* } */ 282 /* } */ 332 if (!pmFlatField(input, flat, options->flatMask)) 333 { 334 psFree(detview); 335 return false; 336 } 337 // psLogMsg ("ppImage", 6, "apply flat: %f sec\n", psTimerMark ("detrend.readout")); 338 } 339 340 /* // Pattern noise correction */ 341 /* if (options->doPattern) { */ 342 /* if (!pmPatternRow(input, options->patternOrder, options->patternIter, options->patternRej, */ 343 /* options->patternThresh, options->patternMean, options->patternStdev, */ 344 /* options->maskValue, options->darkMask)) { */ 345 /* psFree(detview); */ 346 /* return false; */ 347 /* } */ 348 /* } */ 283 349 284 350 // Normalization by a single (known) constant 285 bool mdok; // Status of MD lookup351 bool mdok; // Status of MD lookup 286 352 float norm = psMetadataLookupF32(&mdok, config->arguments, "NORMALIZATION"); 287 if (mdok && isfinite(norm) && norm != 1.0) { 353 if (mdok && isfinite(norm) && norm != 1.0) 354 { 288 355 pmHDU *hdu = pmHDUFromReadout(input); // HDU of interest 289 psString comment = NULL; // Comment to add356 psString comment = NULL; // Comment to add 290 357 psStringAppend(&comment, "Normalization: %f", norm); 291 358 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); … … 293 360 294 361 psBinaryOp(input->image, input->image, "*", psScalarAlloc(norm, PS_TYPE_F32)); 295 // psLogMsg ("ppImage", 6, "renormalize: %f sec\n", psTimerMark ("detrend.readout"));296 } 297 298 # if (1)362 // psLogMsg ("ppImage", 6, "renormalize: %f sec\n", psTimerMark ("detrend.readout")); 363 } 364 365 #if (1) 299 366 // Normalization by per-class values 300 367 psMetadata *normlist = psMetadataLookupMetadata(&mdok, config->arguments, "NORMALIZATION.TABLE"); 301 if (normlist) { 368 if (normlist) 369 { 302 370 pmFPAfile *inputFile = psMetadataLookupPtr(&mdok, config->files, "PPIMAGE.INPUT"); 303 371 304 372 // get the menu of class IDs 305 373 psMetadata *menu = psMetadataLookupMetadata(&mdok, inputFile->camera, "CLASSID"); 306 if (!menu) { 374 if (!menu) 375 { 307 376 psError(PS_ERR_IO, false, "Unable to find CLASSID metadata in camera configuration"); 308 377 psFree(detview); … … 311 380 // get the rule for class_id for the desired class 312 381 const char *rule = psMetadataLookupStr(&mdok, menu, options->normClass); 313 if (!rule) { 382 if (!rule) 383 { 314 384 psError(PS_ERR_IO, false, "Unable to find NORM.CLASS value %s in CLASSID in camera configuration", options->normClass); 315 385 psFree(detview); … … 318 388 // get the class_id from the rule 319 389 char *classID = pmFPAfileNameFromRule(rule, inputFile, view); 320 if (!classID) { 390 if (!classID) 391 { 321 392 psError(PS_ERR_IO, false, "error converting CLASSID rule %s to name\n", rule); 322 393 psFree(detview); … … 325 396 326 397 // get normalization from the class_id 327 float norm = psMetadataLookupF32 (&mdok, normlist, classID); 328 if (!mdok) { 398 float norm = psMetadataLookupF32(&mdok, normlist, classID); 399 if (!mdok) 400 { 329 401 psError(PS_ERR_IO, false, "failed to find class ID %s in normalization table\n", classID); 330 402 psFree(detview); … … 333 405 334 406 pmHDU *hdu = pmHDUFromReadout(input); // HDU of interest 335 psString comment = NULL; // Comment to add407 psString comment = NULL; // Comment to add 336 408 psStringAppend(&comment, "Normalization: %f", norm); 337 409 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); … … 341 413 psBinaryOp(input->image, input->image, "*", psScalarAlloc(norm, PS_TYPE_F32)); 342 414 343 psFree (classID); 344 345 // psLogMsg ("ppImage", 6, "renormalize by class: %f sec\n", psTimerMark ("detrend.readout")); 346 } 347 # endif 348 349 if (options->doFringe) { 415 psFree(classID); 416 417 // psLogMsg ("ppImage", 6, "renormalize by class: %f sec\n", psTimerMark ("detrend.readout")); 418 } 419 #endif 420 421 if (options->doFringe) 422 { 350 423 pmCell *fringe = pmFPAfileThisCell(config->files, detview, "PPIMAGE.FRINGE"); 351 if (!ppImageDetrendFringeMeasure(input, fringe, false, options)) { 352 psFree(detview); 353 return false; 354 } 355 // psLogMsg ("ppImage", 6, "measure fringe: %f sec\n", psTimerMark ("detrend.readout")); 424 if (!ppImageDetrendFringeMeasure(input, fringe, false, options)) 425 { 426 psFree(detview); 427 return false; 428 } 429 // psLogMsg ("ppImage", 6, "measure fringe: %f sec\n", psTimerMark ("detrend.readout")); 356 430 } 357 431
Note:
See TracChangeset
for help on using the changeset viewer.
