IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 8, 2008, 8:09:07 AM (18 years ago)
Author:
Paul Price
Message:

Fixing to match slight differences in psThread

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmShutterCorrection.c

    r18893 r18960  
    122122
    123123    // 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++);
    125125
    126126    if (index == N - 1) {
     
    344344    psVector *resid = psVectorAlloc (exptime->n, PS_TYPE_F32);
    345345    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
    350350    psStats *rawStats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    351351    psStats *resStats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
     
    353353    psVectorStats (resStats, resid, NULL, NULL, 0);
    354354
    355     // XXX temporary hard-wired minimum stdev improvement factor 
     355    // XXX temporary hard-wired minimum stdev improvement factor
    356356    psTrace("psModules.detrend", 3, "raw scatter %f vs res scatter %f\n", rawStats->sampleStdev, resStats->sampleStdev);
    357357    if (rawStats->sampleStdev / resStats->sampleStdev < 1.5) corr->valid = false;
     
    433433            numRows = image->numRows;
    434434            numCols = image->numCols;
    435             // define the reference region : a box of size 'size' at the center
     435            // define the reference region : a box of size 'size' at the center
    436436            refRegion = psRegionForSquare(0.5 * numCols, 0.5 * numRows, size);
    437437            // Set up the sample regions : boxes of size 'size' at the 4 image corners
     
    656656
    657657
    658 bool pmShutterCorrectionApplyScan_Threaded (psThreadJob *job) {
     658bool pmShutterCorrectionApplyScan_Threaded(const psThreadJob *job)
     659{
     660    PS_ASSERT_THREAD_JOB_NON_NULL(job, false);
     661
    659662    psImage *image        = job->args->data[0];
    660663    psImage *shutterImage = job->args->data[1];
     
    672675{
    673676    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        }
    682685    }
    683686    return true;
     
    732735    bool threaded = true;
    733736    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;
    737740    }
    738741
     
    756759        psFree (line);
    757760    } 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        }
    799799    }
    800800    psFree(shutterImage);
     
    952952        stdev->data.F32[stdev->n] = psStatsGetValue(stats, stdevStat) * refValue;
    953953
    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]);
    957957
    958958        data->mean->data[j] = psVectorExtend(mean, IMAGES_BUFFER, 1);
     
    978978    // reshuffle exptimes to new sequence (this is only a local value)
    979979    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]];
    981981    }
    982982
     
    984984    int numGood = 0;                    // Number of good measurements
    985985    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 measurements
     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 measurements
    997997        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);
    999999
    10001000        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);
    10021002
    10031003        if (corr && isfinite(corr->offref) && corr->valid) {
     
    10091009        psFree(corr);
    10101010        psFree(guess);
    1011         psFree (newcounts);
    1012         psFree (newerrors);
     1011        psFree (newcounts);
     1012        psFree (newerrors);
    10131013    }
    10141014    psFree (newtimes);
     
    10401040    pmReadoutStackDefineOutput(shutter, col0, row0, numCols, numRows, false, false, maskVal);
    10411041    if (pattern) {
    1042         pmReadoutStackDefineOutput(pattern, col0, row0, numCols, numRows, false, false, maskVal);
     1042        pmReadoutStackDefineOutput(pattern, col0, row0, numCols, numRows, false, false, maskVal);
    10431043    }
    10441044
     
    10721072
    10731073    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        }
    10791079    }
    10801080
     
    11371137                    errors->data.F32[r] = sqrtf(readout->weight->data.F32[yIn][xIn]) * ref;
    11381138                } else {
    1139                     // XXX guess that the input data is Poisson distributed; if we go negative, force high
     1139                    // XXX guess that the input data is Poisson distributed; if we go negative, force high
    11401140                    errors->data.F32[r] = sqrtf(fabs(image->data.F32[yIn][xIn])) * ref;
    11411141                }
Note: See TracChangeset for help on using the changeset viewer.