Changeset 18960 for trunk/psModules/src/detrend/pmShutterCorrection.c
- Timestamp:
- Aug 8, 2008, 8:09:07 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmShutterCorrection.c
r18893 r18960 122 122 123 123 // Iterate only 124 for (index = 0; !isfinite(exptime->data.F32[index]) && index < N - 1; index++); 124 for (index = 0; !isfinite(exptime->data.F32[index]) && index < N - 1; index++); 125 125 126 126 if (index == N - 1) { … … 344 344 psVector *resid = psVectorAlloc (exptime->n, PS_TYPE_F32); 345 345 for (int i = 0; i < exptime->n; i++) { 346 float fitCounts = corr->scale * (exptime->data.F32[i] + corr->offset) / (exptime->data.F32[i] + corr->offref);347 resid->data.F32[i] = counts->data.F32[i] - fitCounts;348 } 349 346 float fitCounts = corr->scale * (exptime->data.F32[i] + corr->offset) / (exptime->data.F32[i] + corr->offref); 347 resid->data.F32[i] = counts->data.F32[i] - fitCounts; 348 } 349 350 350 psStats *rawStats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 351 351 psStats *resStats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); … … 353 353 psVectorStats (resStats, resid, NULL, NULL, 0); 354 354 355 // XXX temporary hard-wired minimum stdev improvement factor 355 // XXX temporary hard-wired minimum stdev improvement factor 356 356 psTrace("psModules.detrend", 3, "raw scatter %f vs res scatter %f\n", rawStats->sampleStdev, resStats->sampleStdev); 357 357 if (rawStats->sampleStdev / resStats->sampleStdev < 1.5) corr->valid = false; … … 433 433 numRows = image->numRows; 434 434 numCols = image->numCols; 435 // define the reference region : a box of size 'size' at the center435 // define the reference region : a box of size 'size' at the center 436 436 refRegion = psRegionForSquare(0.5 * numCols, 0.5 * numRows, size); 437 437 // Set up the sample regions : boxes of size 'size' at the 4 image corners … … 656 656 657 657 658 bool pmShutterCorrectionApplyScan_Threaded (psThreadJob *job) { 658 bool pmShutterCorrectionApplyScan_Threaded(const psThreadJob *job) 659 { 660 PS_ASSERT_THREAD_JOB_NON_NULL(job, false); 661 659 662 psImage *image = job->args->data[0]; 660 663 psImage *shutterImage = job->args->data[1]; … … 672 675 { 673 676 for (int y = rowStart; y < rowStop; y++) { 674 for (int x = 0; x < image->numCols; x++) {675 if (mask && !isfinite(shutterImage->data.F32[y][x])) {676 mask->data.PS_TYPE_MASK_DATA[y][x] |= blank;677 image->data.F32[y][x] = NAN;678 continue;679 }680 image->data.F32[y][x] *= exptime / (exptime + shutterImage->data.F32[y][x]);681 }677 for (int x = 0; x < image->numCols; x++) { 678 if (mask && !isfinite(shutterImage->data.F32[y][x])) { 679 mask->data.PS_TYPE_MASK_DATA[y][x] |= blank; 680 image->data.F32[y][x] = NAN; 681 continue; 682 } 683 image->data.F32[y][x] *= exptime / (exptime + shutterImage->data.F32[y][x]); 684 } 682 685 } 683 686 return true; … … 732 735 bool threaded = true; 733 736 int scanRows = pmDetrendGetScanRows(); 734 if (scanRows == 0) { 735 threaded = false;736 scanRows = image->numRows;737 if (scanRows == 0) { 738 threaded = false; 739 scanRows = image->numRows; 737 740 } 738 741 … … 756 759 psFree (line); 757 760 } else { 758 for (int rowStart = 0; rowStart < image->numRows; rowStart += scanRows) { 759 int rowStop = PS_MIN (rowStart + scanRows, image->numRows); 760 761 # define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \ 762 psScalar *scalar = psScalarAlloc(VALUE, TYPE); \ 763 psArrayAdd(ARRAY, 1, scalar); \ 764 psFree (scalar); } 765 766 if (threaded) { 767 // allocate a job, construct the arguments for this job 768 psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_SHUTTER"); 769 psArrayAdd (job->args, 1, image); 770 psArrayAdd (job->args, 1, shutterImage); 771 psArrayAdd (job->args, 1, mask); 772 PS_ARRAY_ADD_SCALAR (job->args, exptime, PS_TYPE_F32); 773 PS_ARRAY_ADD_SCALAR (job->args, blank, PS_TYPE_MASK); 774 PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32); 775 PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32); 776 777 // ppImageDetrendReadout(config, options, view) 778 if (!psThreadJobAddPending (job)) { 779 return false; 780 } 781 } else { 782 pmShutterCorrectionApplyScan (image, shutterImage, mask, exptime, blank, rowStart, rowStop); 783 } 784 } 785 if (threaded) { 786 // wait here for the threaded jobs to finish 787 if (!psThreadPoolWait ()) { 788 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 789 return false; 790 } 791 fprintf (stderr, "success for threaded jobs\n"); 792 793 // free the done jobs 794 psThreadJob *job = NULL; 795 while ((job = psThreadJobGetDone()) != NULL) { 796 psFree (job); 797 } 798 } 761 for (int rowStart = 0; rowStart < image->numRows; rowStart += scanRows) { 762 int rowStop = PS_MIN (rowStart + scanRows, image->numRows); 763 764 if (threaded) { 765 // allocate a job, construct the arguments for this job 766 psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_SHUTTER"); 767 psArrayAdd (job->args, 1, image); 768 psArrayAdd (job->args, 1, shutterImage); 769 psArrayAdd (job->args, 1, mask); 770 PS_ARRAY_ADD_SCALAR (job->args, exptime, PS_TYPE_F32); 771 PS_ARRAY_ADD_SCALAR (job->args, blank, PS_TYPE_MASK); 772 PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32); 773 PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32); 774 775 // ppImageDetrendReadout(config, options, view) 776 if (!psThreadJobAddPending (job)) { 777 psFree(job); 778 return false; 779 } 780 psFree(job); 781 } else { 782 pmShutterCorrectionApplyScan (image, shutterImage, mask, exptime, blank, rowStart, rowStop); 783 } 784 } 785 if (threaded) { 786 // wait here for the threaded jobs to finish 787 if (!psThreadPoolWait(false)) { 788 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 789 return false; 790 } 791 fprintf (stderr, "success for threaded jobs\n"); 792 793 // free the done jobs 794 psThreadJob *job = NULL; 795 while ((job = psThreadJobGetDone()) != NULL) { 796 psFree (job); 797 } 798 } 799 799 } 800 800 psFree(shutterImage); … … 952 952 stdev->data.F32[stdev->n] = psStatsGetValue(stats, stdevStat) * refValue; 953 953 954 psTrace("psModules.detrend", 5, "input shutter image sample value %d: %f +/- %f -> %f +/- %f\n", j,955 psStatsGetValue(stats, meanStat), psStatsGetValue(stats, stdevStat),956 mean->data.F32[mean->n], stdev->data.F32[stdev->n]);954 psTrace("psModules.detrend", 5, "input shutter image sample value %d: %f +/- %f -> %f +/- %f\n", j, 955 psStatsGetValue(stats, meanStat), psStatsGetValue(stats, stdevStat), 956 mean->data.F32[mean->n], stdev->data.F32[stdev->n]); 957 957 958 958 data->mean->data[j] = psVectorExtend(mean, IMAGES_BUFFER, 1); … … 978 978 // reshuffle exptimes to new sequence (this is only a local value) 979 979 for (int j = 0; j < newtimes->n; j++) { 980 newtimes->data.F32[j] = data->exptimes->data.F32[index->data.S32[j]];980 newtimes->data.F32[j] = data->exptimes->data.F32[index->data.S32[j]]; 981 981 } 982 982 … … 984 984 int numGood = 0; // Number of good measurements 985 985 for (int i = 0; i < MEASURE_SAMPLES; i++) { 986 psVector *newcounts = psVectorAlloc (data->exptimes->n, PS_TYPE_F32);987 psVector *newerrors = psVectorAlloc (data->exptimes->n, PS_TYPE_F32);988 psVector *counts = data->mean->data[i];989 psVector *errors = data->stdev->data[i];990 991 for (int j = 0; j < newcounts->n; j++) {992 newcounts->data.F32[j] = counts->data.F32[index->data.S32[j]];993 newerrors->data.F32[j] = errors->data.F32[index->data.S32[j]];994 }995 996 // use the sorted exptime, counts, and errors for the measurements986 psVector *newcounts = psVectorAlloc (data->exptimes->n, PS_TYPE_F32); 987 psVector *newerrors = psVectorAlloc (data->exptimes->n, PS_TYPE_F32); 988 psVector *counts = data->mean->data[i]; 989 psVector *errors = data->stdev->data[i]; 990 991 for (int j = 0; j < newcounts->n; j++) { 992 newcounts->data.F32[j] = counts->data.F32[index->data.S32[j]]; 993 newerrors->data.F32[j] = errors->data.F32[index->data.S32[j]]; 994 } 995 996 // use the sorted exptime, counts, and errors for the measurements 997 997 pmShutterCorrection *guess = pmShutterCorrectionGuess(newtimes, newcounts); // Guess at correction 998 psTrace("psModules.detrend", 5, "Shutter correction guess: scale: %f, offset: %f, offref: %f\n", guess->scale, guess->offset, guess->offref);998 psTrace("psModules.detrend", 5, "Shutter correction guess: scale: %f, offset: %f, offref: %f\n", guess->scale, guess->offset, guess->offref); 999 999 1000 1000 pmShutterCorrection *corr = pmShutterCorrectionFullFit(newtimes, newcounts, newerrors, guess); // The actual correction 1001 psTrace("psModules.detrend", 5, "Shutter correction fit: scale: %f, offset: %f, offref: %f\n", corr->scale, corr->offset, corr->offref);1001 psTrace("psModules.detrend", 5, "Shutter correction fit: scale: %f, offset: %f, offref: %f\n", corr->scale, corr->offset, corr->offref); 1002 1002 1003 1003 if (corr && isfinite(corr->offref) && corr->valid) { … … 1009 1009 psFree(corr); 1010 1010 psFree(guess); 1011 psFree (newcounts);1012 psFree (newerrors);1011 psFree (newcounts); 1012 psFree (newerrors); 1013 1013 } 1014 1014 psFree (newtimes); … … 1040 1040 pmReadoutStackDefineOutput(shutter, col0, row0, numCols, numRows, false, false, maskVal); 1041 1041 if (pattern) { 1042 pmReadoutStackDefineOutput(pattern, col0, row0, numCols, numRows, false, false, maskVal);1042 pmReadoutStackDefineOutput(pattern, col0, row0, numCols, numRows, false, false, maskVal); 1043 1043 } 1044 1044 … … 1072 1072 1073 1073 pattern->data_exists = true; 1074 if (pattern->parent) { 1075 pattern->parent->data_exists = true;1076 if (pattern->parent->parent) {1077 pattern->parent->parent->data_exists = true;1078 }1074 if (pattern->parent) { 1075 pattern->parent->data_exists = true; 1076 if (pattern->parent->parent) { 1077 pattern->parent->parent->data_exists = true; 1078 } 1079 1079 } 1080 1080 … … 1137 1137 errors->data.F32[r] = sqrtf(readout->weight->data.F32[yIn][xIn]) * ref; 1138 1138 } else { 1139 // XXX guess that the input data is Poisson distributed; if we go negative, force high1139 // XXX guess that the input data is Poisson distributed; if we go negative, force high 1140 1140 errors->data.F32[r] = sqrtf(fabs(image->data.F32[yIn][xIn])) * ref; 1141 1141 }
Note:
See TracChangeset
for help on using the changeset viewer.
