IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 8, 2008, 2:42:04 PM (18 years ago)
Author:
eugene
Message:

add some trace entries; sort input exptime and counts to pmShutterCorrectionGuess (needed for valid result); add test of improved scatter for pmShutterCorectionFit

File:
1 edited

Legend:

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

    r17228 r17995  
    8080    corr->num = 0;
    8181    corr->stdev = NAN;
     82    corr->valid = true;
    8283
    8384    return corr;
     
    118119
    119120    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
    122125    if (index == N - 1) {
    123126        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     
    336339    corr->offset = params->data.F32[1];
    337340    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);
    338361
    339362    psFree(minInfo);
     
    409432            numRows = image->numRows;
    410433            numCols = image->numCols;
    411             // Set up the sample regions
     434            // define the reference region : a box of size 'size' at the center
    412435            refRegion = psRegionForSquare(0.5 * numCols, 0.5 * numRows, size);
     436            // Set up the sample regions : boxes of size 'size' at the 4 image corners
    413437            for (int j = 0; j < MEASURE_SAMPLES; j++) {
    414438                int x = (j % 2) ? size : image->numCols - size;
     
    823847    psFree(rng);
    824848    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);
    826850    if (refValue <= 0.0) {
    827851        psError(PS_ERR_UNKNOWN, true, "Measured non-positive reference value.\n");
     
    860884        mean->data.F32[mean->n] = psStatsGetValue(stats, meanStat) * refValue;
    861885        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
    862891        data->mean->data[j] = psVectorExtend(mean, IMAGES_BUFFER, 1);
    863892        data->stdev->data[j] = psVectorExtend(stdev, IMAGES_BUFFER, 1);
     
    869898}
    870899
    871 float pmShutterCorrectionReference(const pmShutterCorrectionData *data)
     900float pmShutterCorrectionReference(pmShutterCorrectionData *data)
    872901{
    873902    PS_ASSERT_PTR_NON_NULL(data, NAN);
    874903    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    }
    875915
    876916    float meanRef = 0.0;                // Mean reference offset
    877917    int numGood = 0;                    // Number of good measurements
    878918    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) {
    886937            psTrace("psModules.detrend", 5, "Sample reference value: %f\n", corr->offref);
    887938            meanRef += corr->offref;
    888939            numGood++;
    889940        }
     941
    890942        psFree(corr);
    891     }
     943        psFree(guess);
     944        psFree (newcounts);
     945        psFree (newerrors);
     946    }
     947    psFree (newtimes);
     948    psFree (index);
    892949
    893950    if (numGood == 0) {
Note: See TracChangeset for help on using the changeset viewer.