Changeset 17228 for trunk/psModules/src/detrend/pmShutterCorrection.c
- Timestamp:
- Mar 28, 2008, 5:10:17 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmShutterCorrection.c
r16600 r17228 78 78 corr->offset = 0.0; 79 79 corr->offref = 0.0; 80 corr->num = 0; 81 corr->stdev = NAN; 80 82 81 83 return corr; … … 190 192 191 193 // linear fit to the counts and exptime, given a value for offref 192 pmShutterCorrection *pmShutterCorrectionLinFit(const psVector *exptime, 193 const psVector *counts, 194 const psVector *cntError, 195 const psVector *mask, 196 float offref, 197 int nIter, 198 float rej, 199 psMaskType maskVal 200 ) 194 pmShutterCorrection *pmShutterCorrectionLinFit(const psVector *exptime, const psVector *counts, 195 const psVector *cntError, const psVector *mask, float offref, 196 int nIter, float rej, psMaskType maskVal) 201 197 { 202 198 PS_ASSERT_VECTOR_NON_NULL(exptime, NULL); … … 249 245 return NULL; 250 246 } 251 psFree(stats);252 247 253 248 pmShutterCorrection *corr = pmShutterCorrectionAlloc(); … … 255 250 corr->scale = line->coeff[1][0]; 256 251 corr->offset = line->coeff[0][1] / line->coeff[1][0]; 257 252 corr->num = stats->clippedNvalues; 253 corr->stdev = stats->clippedStdev; 254 255 psFree(stats); 258 256 psFree(x); 259 257 psFree(y); … … 263 261 } 264 262 265 static psF32 pmShutterCorrectionModel(psVector *deriv, 266 const psVector *params, 267 const psVector *x) 263 static psF32 pmShutterCorrectionModel(psVector *deriv, const psVector *params, const psVector *x) 268 264 { 269 265 // This is in a tight loop, so we won't assert here. … … 283 279 284 280 // non-linear fit to the counts and exptime, given a guess for the three parameters 285 pmShutterCorrection *pmShutterCorrectionFullFit(const psVector *exptime, 286 const psVector *counts, 287 const psVector *cntError, 288 const pmShutterCorrection *guess 289 ) 281 pmShutterCorrection *pmShutterCorrectionFullFit(const psVector *exptime, const psVector *counts, 282 const psVector *cntError, const pmShutterCorrection *guess) 290 283 { 291 284 PS_ASSERT_VECTOR_NON_NULL(exptime, NULL); … … 638 631 639 632 640 bool pmShutterCorrectionApply(pmReadout *readout, const pmReadout *shutter )633 bool pmShutterCorrectionApply(pmReadout *readout, const pmReadout *shutter, psMaskType blank) 641 634 { 642 635 PS_ASSERT_PTR_NON_NULL(readout, false); … … 682 675 } 683 676 psImage *image = readout->image; // Image to correct 677 psImage *mask = readout->mask; // Corresponding mask 684 678 685 679 if (exptime <= 0.0) { … … 688 682 for (int y = 0; y < image->numRows; y++) { 689 683 for (int x = 0; x < image->numCols; x++) { 684 if (mask && !isfinite(shutterImage->data.F32[y][x])) { 685 mask->data.PS_TYPE_MASK_DATA[y][x] |= blank; 686 image->data.F32[y][x] = NAN; 687 continue; 688 } 690 689 image->data.F32[y][x] *= 1.0 / (exptime + shutterImage->data.F32[y][x]); 691 690 } … … 699 698 for (int y = 0; y < image->numRows; y++) { 700 699 for (int x = 0; x < image->numCols; x++) { 700 if (mask && !isfinite(shutterImage->data.F32[y][x])) { 701 mask->data.PS_TYPE_MASK_DATA[y][x] |= blank; 702 image->data.F32[y][x] = NAN; 703 continue; 704 } 701 705 image->data.F32[y][x] *= exptime / (exptime + shutterImage->data.F32[y][x]); 702 706 } … … 903 907 PS_ASSERT_ARRAY_NON_NULL(inputs, false); 904 908 PS_ASSERT_INT_EQUAL(data->num, inputs->n, false); 909 PS_ASSERT_INT_NONNEGATIVE(nIter, false); 910 PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false); 905 911 906 912 int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine … … 915 921 if (pattern) { 916 922 pmReadoutUpdateSize(pattern, minInputCols, minInputRows, xSize, ySize, false, false, maskVal); 923 } 924 925 psImage *nums = pmReadoutAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_COUNT, xSize, ySize, 926 PS_TYPE_U16, 0); // Image with number fitted per pixel 927 if (!nums) { 928 return false; 929 } 930 psImage *sigma = pmReadoutAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_SIGMA, xSize, ySize, 931 PS_TYPE_F32, NAN); // Image with stdev per pixel 932 if (!sigma) { 933 psFree(nums); 934 return false; 917 935 } 918 936 … … 955 973 pmShutterCorrection *corr = pmShutterCorrectionLinFit(data->exptimes, counts, errors, mask, 956 974 reference, nIter, rej, maskVal); 975 if (!corr) { 976 // Nothing we can do about it 977 psErrorClear(); 978 shutterImage->data.F32[yOut][xOut] = NAN; 979 patternImage->data.F32[yOut][xOut] = NAN; 980 nums->data.U16[yOut][xOut] = 0; 981 sigma->data.F32[yOut][xOut] = NAN; 982 continue; 983 } 957 984 shutterImage->data.F32[yOut][xOut] = corr->offset; 958 985 patternImage->data.F32[yOut][xOut] = corr->scale; 986 nums->data.U16[yOut][xOut] = corr->num; 987 sigma->data.F32[yOut][xOut] = corr->stdev; 959 988 psFree(corr); 960 989 } … … 963 992 psFree(errors); 964 993 psFree(counts); 994 psFree(nums); 995 psFree(sigma); 965 996 966 997 // Update the "concepts"
Note:
See TracChangeset
for help on using the changeset viewer.
