Changeset 17995 for trunk/psModules/src/detrend/pmShutterCorrection.c
- Timestamp:
- Jun 8, 2008, 2:42:04 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmShutterCorrection.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmShutterCorrection.c
r17228 r17995 80 80 corr->num = 0; 81 81 corr->stdev = NAN; 82 corr->valid = true; 82 83 83 84 return corr; … … 118 119 119 120 long index; 120 for (index = 0; !isfinite(exptime->data.F32[index]) && index < N - 1; index++) 121 ; // Iterate only 121 122 // Iterate only 123 for (index = 0; !isfinite(exptime->data.F32[index]) && index < N - 1; index++); 124 122 125 if (index == N - 1) { 123 126 psError(PS_ERR_BAD_PARAMETER_VALUE, true, … … 336 339 corr->offset = params->data.F32[1]; 337 340 corr->offref = params->data.F32[2]; 341 342 // apply the correction and measure the residual scatter 343 psVector *resid = psVectorAlloc (exptime->n, PS_TYPE_F32); 344 for (int i = 0; i < exptime->n; i++) { 345 float fitCounts = corr->scale * (exptime->data.F32[i] + corr->offset) / (exptime->data.F32[i] + corr->offref); 346 resid->data.F32[i] = counts->data.F32[i] - fitCounts; 347 } 348 349 psStats *rawStats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 350 psStats *resStats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 351 psVectorStats (rawStats, counts, NULL, NULL, 0); 352 psVectorStats (resStats, resid, NULL, NULL, 0); 353 354 // XXX temporary hard-wired minimum stdev improvement factor 355 psTrace("psModules.detrend", 3, "raw scatter %f vs res scatter %f\n", rawStats->sampleStdev, resStats->sampleStdev); 356 if (rawStats->sampleStdev / resStats->sampleStdev < 1.5) corr->valid = false; 357 358 psFree (rawStats); 359 psFree (resStats); 360 psFree (resid); 338 361 339 362 psFree(minInfo); … … 409 432 numRows = image->numRows; 410 433 numCols = image->numCols; 411 // Set up the sample regions 434 // define the reference region : a box of size 'size' at the center 412 435 refRegion = psRegionForSquare(0.5 * numCols, 0.5 * numRows, size); 436 // Set up the sample regions : boxes of size 'size' at the 4 image corners 413 437 for (int j = 0; j < MEASURE_SAMPLES; j++) { 414 438 int x = (j % 2) ? size : image->numCols - size; … … 823 847 psFree(rng); 824 848 float refValue = psStatsGetValue(stats, meanStat); // Reference value 825 psTrace("psModules.detrend", 3, "Reference value for shutter image = %f\n", refValue);849 psTrace("psModules.detrend", 3, "Reference value & exptime for shutter image : %f cnts %f sec\n", refValue, exptime); 826 850 if (refValue <= 0.0) { 827 851 psError(PS_ERR_UNKNOWN, true, "Measured non-positive reference value.\n"); … … 860 884 mean->data.F32[mean->n] = psStatsGetValue(stats, meanStat) * refValue; 861 885 stdev->data.F32[stdev->n] = psStatsGetValue(stats, stdevStat) * refValue; 886 887 psTrace("psModules.detrend", 5, "input shutter image sample value %d: %f +/- %f -> %f +/- %f\n", j, 888 psStatsGetValue(stats, meanStat), psStatsGetValue(stats, stdevStat), 889 mean->data.F32[mean->n], stdev->data.F32[stdev->n]); 890 862 891 data->mean->data[j] = psVectorExtend(mean, IMAGES_BUFFER, 1); 863 892 data->stdev->data[j] = psVectorExtend(stdev, IMAGES_BUFFER, 1); … … 869 898 } 870 899 871 float pmShutterCorrectionReference( constpmShutterCorrectionData *data)900 float pmShutterCorrectionReference(pmShutterCorrectionData *data) 872 901 { 873 902 PS_ASSERT_PTR_NON_NULL(data, NAN); 874 903 PS_ASSERT_INT_POSITIVE(data->num, NAN); 904 905 // supply counts sorted by exptime 906 907 // generate the index for the exptimes vector 908 psVector *index = psVectorSortIndex (NULL, data->exptimes); 909 psVector *newtimes = psVectorAlloc (data->exptimes->n, PS_TYPE_F32); 910 911 // reshuffle exptimes to new sequence (this is only a local value) 912 for (int j = 0; j < newtimes->n; j++) { 913 newtimes->data.F32[j] = data->exptimes->data.F32[index->data.S32[j]]; 914 } 875 915 876 916 float meanRef = 0.0; // Mean reference offset 877 917 int numGood = 0; // Number of good measurements 878 918 for (int i = 0; i < MEASURE_SAMPLES; i++) { 879 psVector *counts = data->mean->data[i]; // Mean for each image 880 psVector *errors = data->stdev->data[i]; // Stdev for each image 881 pmShutterCorrection *guess = pmShutterCorrectionGuess(data->exptimes, counts); // Guess at correction 882 pmShutterCorrection *corr = pmShutterCorrectionFullFit(data->exptimes, counts, 883 errors, guess); // The actual correction 884 psFree(guess); 885 if (corr && isfinite(corr->offref)) { 919 psVector *newcounts = psVectorAlloc (data->exptimes->n, PS_TYPE_F32); 920 psVector *newerrors = psVectorAlloc (data->exptimes->n, PS_TYPE_F32); 921 psVector *counts = data->mean->data[i]; 922 psVector *errors = data->stdev->data[i]; 923 924 for (int j = 0; j < newcounts->n; j++) { 925 newcounts->data.F32[j] = counts->data.F32[index->data.S32[j]]; 926 newerrors->data.F32[j] = errors->data.F32[index->data.S32[j]]; 927 } 928 929 // use the sorted exptime, counts, and errors for the measurements 930 pmShutterCorrection *guess = pmShutterCorrectionGuess(newtimes, newcounts); // Guess at correction 931 psTrace("psModules.detrend", 5, "Shutter correction guess: scale: %f, offset: %f, offref: %f\n", guess->scale, guess->offset, guess->offref); 932 933 pmShutterCorrection *corr = pmShutterCorrectionFullFit(newtimes, newcounts, newerrors, guess); // The actual correction 934 psTrace("psModules.detrend", 5, "Shutter correction fit: scale: %f, offset: %f, offref: %f\n", corr->scale, corr->offset, corr->offref); 935 936 if (corr && isfinite(corr->offref) && corr->valid) { 886 937 psTrace("psModules.detrend", 5, "Sample reference value: %f\n", corr->offref); 887 938 meanRef += corr->offref; 888 939 numGood++; 889 940 } 941 890 942 psFree(corr); 891 } 943 psFree(guess); 944 psFree (newcounts); 945 psFree (newerrors); 946 } 947 psFree (newtimes); 948 psFree (index); 892 949 893 950 if (numGood == 0) {
Note:
See TracChangeset
for help on using the changeset viewer.
