IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23989 for trunk/psModules


Ignore:
Timestamp:
Apr 28, 2009, 11:21:56 AM (17 years ago)
Author:
eugene
Message:

always handle psVectorStats false return status (is an error); check for NAN results and handle as possible

Location:
trunk/psModules/src
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/astrom/pmAstrometryDistortion.c

    r23487 r23989  
    151151
    152152            // also measure the L and M median positions as a representative coordinate
    153             psVectorStats (stats, L, NULL, NULL, 0);
     153            if (!psVectorStats (stats, L, NULL, NULL, 0)) {
     154                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     155                goto skip;
     156            }
    154157            grad->FP.x = stats->sampleMedian;
    155158
    156             psVectorStats (stats, M, NULL, NULL, 0);
     159            if (!psVectorStats (stats, M, NULL, NULL, 0)) {
     160                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     161                goto skip;
     162            }
    157163            grad->FP.y = stats->sampleMedian;
    158164
  • trunk/psModules/src/camera/pmFPAMaskWeight.c

    r23259 r23989  
    482482        return false;
    483483    }
    484     float stdev = psStatsGetValue(stdevStats, stdevStat); // Stadard deviation of fluxes
     484    float stdev = psStatsGetValue(stdevStats, stdevStat); // Standard deviation of fluxes
    485485    psFree(stdevStats);
    486486    psFree(noise);
  • trunk/psModules/src/detrend/pmFringeStats.c

    r23259 r23989  
    882882
    883883    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_QUARTILE); // Statistics
    884     psVectorStats(stats, diffs, NULL, mask, 1);
     884    if (!psVectorStats(stats, diffs, NULL, mask, 1)) {
     885        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     886        return 0;
     887    }
    885888    float middle = stats->sampleMedian; // The middle of the distribution
    886889    float thresh = rej * 0.74 * (stats->sampleUQ - stats->sampleLQ); // The rejection threshold
     
    969972
    970973    // Get rid of the extreme outliers by assuming most of the points are somewhat clustered
    971     psVectorStats(median, science->f, NULL, NULL, 0);
     974    if (!psVectorStats(median, science->f, NULL, NULL, 0)) {
     975        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     976        return NULL;
     977    }
    972978    scale->coeff->data.F32[0] = median->sampleMedian;
    973979    for (int i = 0; i < fringes->n; i++) {
    974980        pmFringeStats *fringe = fringes->data[i]; // The fringe of interest
    975         psVectorStats(median, fringe->f, NULL, NULL, 0);
     981        if (!psVectorStats(median, fringe->f, NULL, NULL, 0)) {
     982            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     983            return NULL;
     984        }
    976985        scale->coeff->data.F32[0] -= median->sampleMedian;
    977986        scale->coeff->data.F32[i] = 0.0;
  • trunk/psModules/src/detrend/pmOverscan.c

    r23826 r23989  
    7474            mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0;
    7575            ordinate->data.F32[i] = 2.0*(float)i/(float)pixels->n - 1.0; // Scale to [-1,1]
    76             psVectorStats(myStats, values, NULL, NULL, 0);
     76            if (!psVectorStats(myStats, values, NULL, NULL, 0)) {
     77                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     78                return false;
     79            }
    7780            reduced->data.F32[i] = psStatsGetValue(myStats, statistic);
    7881        } else if (overscanOpts->fitType == PM_FIT_NONE) {
     
    275278        psFree(iter);
    276279
    277         (void)psVectorStats(stats, pixels, NULL, NULL, 0);
     280        if (!psVectorStats(stats, pixels, NULL, NULL, 0)) {
     281            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     282            return false;
     283        }
    278284        psFree(pixels);
    279285        double reduced = psStatsGetValue(stats, statistic); // Result of statistics
     
    349355          psString comment = NULL;    // Comment to add
    350356          psStats *vectorStats = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
    351           psVectorStats (vectorStats, reduced, NULL, NULL, 0);
     357          if (!psVectorStats (vectorStats, reduced, NULL, NULL, 0)) {
     358              psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     359              return false;
     360          }
    352361          psStringAppend(&comment, "Mean Overscan value: %f", vectorStats->sampleMean);
    353362          psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     
    412421          psString comment = NULL;    // Comment to add
    413422          psStats *vectorStats = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
    414           psVectorStats (vectorStats, reduced, NULL, NULL, 0);
     423          if (!psVectorStats (vectorStats, reduced, NULL, NULL, 0)) {
     424              psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     425              return false;
     426          }
    415427          psStringAppend(&comment, "Mean Overscan value: %f", vectorStats->sampleMean);
    416428          psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
  • trunk/psModules/src/detrend/pmRemnance.c

    r23259 r23989  
    6666            values->n = numValues;
    6767            if (!psVectorStats(stats, values, NULL, NULL, 0)) {
    68                 // Can't do anything about it
    69                 psErrorClear();
     68                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     69                return false;
     70            }
     71            if (isnan(stats->sampleMedian)) {
    7072                maxMask = max;
    7173                continue;
  • trunk/psModules/src/detrend/pmShutterCorrection.c

    r23487 r23989  
    350350    psStats *rawStats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    351351    psStats *resStats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    352     psVectorStats (rawStats, counts, NULL, NULL, 0);
    353     psVectorStats (resStats, resid, NULL, NULL, 0);
     352    if (!psVectorStats (rawStats, counts, NULL, NULL, 0)) {
     353        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     354        return NULL;
     355    }
     356    if (!psVectorStats (resStats, resid, NULL, NULL, 0)) {
     357        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     358        return NULL;
     359    }
    354360
    355361    // XXX temporary hard-wired minimum stdev improvement factor
    356362    psTrace("psModules.detrend", 3, "raw scatter %f vs res scatter %f\n", rawStats->sampleStdev, resStats->sampleStdev);
    357363    if (rawStats->sampleStdev / resStats->sampleStdev < 1.5) corr->valid = false;
     364    if (isnan(rawStats->sampleStdev) || isnan(resStats->sampleStdev)) corr->valid = false;
    358365
    359366    psFree (rawStats);
  • trunk/psModules/src/extras/pmVisual.c

    r23242 r23989  
    281281    psStats *statsX = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    282282    psStats *statsY = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    283     psVectorStats (statsX, xVec, NULL, NULL, 0);
    284     psVectorStats (statsY, yVec, NULL, NULL, 0);
     283    if (!psVectorStats (statsX, xVec, NULL, NULL, 0)) {
     284        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     285        return false;
     286    }
     287    if (!psVectorStats (statsY, yVec, NULL, NULL, 0)) {
     288        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     289        return false;
     290    }
    285291
    286292    float xhi  = statsX->sampleMedian + 3 *statsX->sampleStdev;
  • trunk/psModules/src/imcombine/pmImageCombine.c

    r21183 r23989  
    132132        // Combine all the pixels, using the specified stat.
    133133        if (!psVectorStats(stats, pixelData, pixelErrors, pixelMasks, 0xff)) {
     134            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     135            return false;
     136        }
     137        if (isnan(stats->sampleMean)) {
    134138            combine->data.F32[y][x] = NAN;
    135139            psFree(buffer);
     
    137141        }
    138142        float combinedPixel = stats->sampleMean; // Value of the combination
    139 
     143       
    140144        if (iter == 0) {
    141145            // Save the value produced with no rejection, since it may be useful later
     
    364368    // Get the median
    365369    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
    366     psVectorStats(stats, pixels, NULL, mask, 1);
     370    if (!psVectorStats(stats, pixels, NULL, mask, 1)) {
     371        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     372    }
    367373    float median = stats->sampleMedian;
    368374    psFree(stats);
  • trunk/psModules/src/imcombine/pmReadoutCombine.c

    r21363 r23989  
    384384            // Combination
    385385            if (!psVectorStats(stats, pixels, errors, mask, 1)) {
    386                 // Can't do much about it, but it's not worth worrying about
    387                 psErrorClear();
     386                psError(PS_ERR_UNKNOWN, false, "error in pixel stats");
     387                return false;
     388            }
     389           
     390            outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
     391
     392            if (isnan(outputImage[yOut][xOut])) {
    388393                outputImage[yOut][xOut] = NAN;
    389394                outputMask[yOut][xOut] = params->blank;
     395                sigma->data.F32[yOut][xOut] = NAN;
    390396                if (params->variances) {
    391397                    outputVariance[yOut][xOut] = NAN;
    392398                }
    393                 sigma->data.F32[yOut][xOut] = NAN;
    394             } else {
    395                 outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
    396                 outputMask[yOut][xOut] = isfinite(outputImage[yOut][xOut]) ? 0 : params->blank;
    397                 if (params->variances) {
    398                     float stdev = psStatsGetValue(stats, combineStdev);
    399                     outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
    400                     // XXXX this is not the correct formal error.
    401                     // also, the weighted mean is not obviously the correct thing here
    402                 }
    403                 sigma->data.F32[yOut][xOut] = psStatsGetValue(stats, combineStdev);
    404             }
     399                continue;
     400            }
     401            outputMask[yOut][xOut] = 0;
     402            sigma->data.F32[yOut][xOut] = psStatsGetValue(stats, combineStdev);
     403            if (params->variances) {
     404                float stdev = psStatsGetValue(stats, combineStdev);
     405                outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
     406                // XXXX this is not the correct formal error.
     407                // also, the weighted mean is not obviously the correct thing here
     408            }
    405409        }
    406410    }
  • trunk/psModules/src/imcombine/pmSubtraction.c

    r23839 r23989  
    822822    psFree(mask);
    823823
     824    // XXX raise an error?
     825    if (isnan(stats->sampleMean)) {
     826        psFree(stats);
     827        return -1;
     828    }
     829
    824830    double mean, rms;                 // Mean and RMS of deviations
    825831    if (numStamps < MIN_SAMPLE_STATS) {
  • trunk/psModules/src/imcombine/pmSubtractionMatch.c

    r23944 r23989  
    830830    psFree(mask);
    831831
     832    // XXX raise an error here or not?
     833    if (isnan(stats->robustMedian)) {
     834        psFree(stats);
     835        return PM_SUBTRACTION_MODE_ERR;
     836    }
     837
    832838    psLogMsg("psModules.imcombine", PS_LOG_INFO, "Median width ratio: %lf", stats->robustMedian);
    833839    pmSubtractionMode mode = (stats->robustMedian <= 1.0 ? PM_SUBTRACTION_MODE_1 : PM_SUBTRACTION_MODE_2);
    834840    psFree(stats);
    835841
    836     // XXX EAM : I think Paul left some test code in here.  I've commented these lines out
    837     // return PM_SUBTRACTION_MODE_2;
    838     // exit(1);
    839 
    840842    return mode;
    841843}
  • trunk/psModules/src/objects/models/pmModel_SGAUSS.c

    r15834 r23989  
    325325
    326326    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
    327     psVectorStats (stats, contour, NULL, NULL, 0);
     327    if (!psVectorStats (stats, contour, NULL, NULL, 0)) {
     328        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     329        return false;
     330    }
    328331    value = stats->sampleMedian;
    329332
  • trunk/psModules/src/objects/pmGrowthCurveGenerate.c

    r21183 r23989  
    8989        psVectorAppend (values, growth->fitMag);
    9090    }
    91     psVectorStats (stats, values, NULL, NULL, 0);
     91    if (!psVectorStats (stats, values, NULL, NULL, 0)) {
     92        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     93        return false;
     94    }
    9295    psf->growth->fitMag = stats->sampleMedian;
    9396
     
    104107            psVectorAppend (values, growth->apMag->data.F32[i]);
    105108        }
    106         psVectorStats (stats, values, NULL, NULL, 0);
     109        if (!psVectorStats (stats, values, NULL, NULL, 0)) {
     110            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     111            return false;
     112        }
    107113        psf->growth->apMag->data.F32[i] = stats->sampleMedian;
    108114    }
  • trunk/psModules/src/objects/pmPSFtry.c

    r21183 r23989  
    211211
    212212    if (Next == 0) {
    213         psError(PS_ERR_UNKNOWN, true, "No sources with good extended fits from which to determine PSF.");
     213        psError(PS_ERR_UNKNOWN, false, "No sources with good extended fits from which to determine PSF.");
    214214        psFree(psfTry);
    215215        return NULL;
     
    282282
    283283    if (Npsf == 0) {
    284         psError(PS_ERR_UNKNOWN, true, "No sources with good PSF fits after model is built.");
     284        psError(PS_ERR_UNKNOWN, false, "No sources with good PSF fits after model is built.");
    285285        psFree(psfTry);
    286286        return NULL;
     
    643643        }
    644644        if (entryMin == -1) {
    645             psError (PS_ERR_UNKNOWN, true, "failed to find image map for shape params");
     645            psError (PS_ERR_UNKNOWN, false, "failed to find image map for shape params");
    646646            return false;
    647647        }
     
    958958    float dEsquare = 0.0;
    959959    psStatsInit (stats);
    960     psVectorStats (stats, e0res, NULL, mask, maskValue);
     960    if (!psVectorStats (stats, e0res, NULL, mask, maskValue)) {
     961        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     962        return false;
     963    }
    961964    dEsquare += PS_SQR(psStatsGetValue(stats, stdevOpt));
    962965
    963966    psStatsInit (stats);
    964     psVectorStats (stats, e1res, NULL, mask, maskValue);
     967    if (!psVectorStats (stats, e1res, NULL, mask, maskValue)) {
     968        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     969        return false;
     970    }
    965971    dEsquare += PS_SQR(psStatsGetValue(stats, stdevOpt));
    966972
    967973    psStatsInit (stats);
    968     psVectorStats (stats, e2res, NULL, mask, maskValue);
     974    if (!psVectorStats (stats, e2res, NULL, mask, maskValue)) {
     975        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     976        return false;
     977    }
    969978    dEsquare += PS_SQR(psStatsGetValue(stats, stdevOpt));
    970979
     
    10181027        float dEsquare = 0.0;
    10191028        psStatsInit (statsS);
    1020         psVectorStats (statsS, dE0subset, NULL, mkSubset, 0xff);
     1029        if (!psVectorStats (statsS, dE0subset, NULL, mkSubset, 0xff)) {
     1030        }
    10211031        dEsquare += PS_SQR(psStatsGetValue(statsS, stdevOpt));
    10221032
    10231033        psStatsInit (statsS);
    1024         psVectorStats (statsS, dE1subset, NULL, mkSubset, 0xff);
    1025         dEsquare += PS_SQR(psStatsGetValue(statsS, stdevOpt));
     1034        if (!psVectorStats (statsS, dE1subset, NULL, mkSubset, 0xff)) {
     1035            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     1036            return false;
     1037        }       
     1038        dEsquare += PS_SQR(psStatsGetValue(statsS, stdevOpt));
    10261039
    10271040        psStatsInit (statsS);
    1028         psVectorStats (statsS, dE2subset, NULL, mkSubset, 0xff);
     1041        if (!psVectorStats (statsS, dE2subset, NULL, mkSubset, 0xff)) {
     1042            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     1043            return false;
     1044        }
    10291045        dEsquare += PS_SQR(psStatsGetValue(statsS, stdevOpt));
    10301046
  • trunk/psModules/src/objects/pmSource.c

    r23187 r23989  
    479479        stats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
    480480
    481         psVectorStats (stats, tmpSx, NULL, NULL, 0);
     481        if (!psVectorStats (stats, tmpSx, NULL, NULL, 0)) {
     482            psError(PS_ERR_UNKNOWN, false, "failed to measure Sx stats");
     483            return (emptyClump);
     484        }
    482485        psfClump.X  = stats->clippedMean;
    483486        psfClump.dX = stats->clippedStdev;
    484487
    485         psVectorStats (stats, tmpSy, NULL, NULL, 0);
     488        if (!psVectorStats (stats, tmpSy, NULL, NULL, 0)) {
     489            psError(PS_ERR_UNKNOWN, false, "failed to measure Sy stats");
     490            return (emptyClump);
     491        }
    486492        psfClump.Y  = stats->clippedMean;
    487493        psfClump.dY = stats->clippedStdev;
     
    636642
    637643        if (!psVectorStats (stats, starsn_moments, NULL, NULL, 0)) {
    638             // Don't care about this error
    639             psErrorClear();
     644            psError(PS_ERR_UNKNOWN, false, "failed to measure SN / moments stats");
     645            psFree (stats);
     646            psFree (starsn_peaks);
     647            return false;
    640648        }
    641649        psLogMsg ("pmObjects", 3, "SN range (moments): %f - %f\n", stats->min, stats->max);
     
    648656        stats = psStatsAlloc (PS_STAT_MIN | PS_STAT_MAX);
    649657        if (!psVectorStats (stats, starsn_peaks, NULL, NULL, 0)) {
    650             // Don't care about this error
    651             psErrorClear();
     658            psError(PS_ERR_UNKNOWN, false, "failed to measure SN / moments stats");
     659            psFree (stats);
     660            psFree (starsn_peaks);
     661            return false;
    652662        }
    653663        psLogMsg ("psModules.objects", 3, "SN range (peaks)  : %f - %f (%ld)\n",
  • trunk/psModules/src/objects/pmSourceFitModel.c

    r23187 r23989  
    172172    fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, model->modelFunc);
    173173    for (int i = 0; i < dparams->n; i++) {
    174         if (psTraceGetLevel("psModules.objects") >= 4) {
    175             fprintf (stderr, "%f ", params->data.F32[i]);
    176         }
    177174        if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])
    178175            continue;
    179176        dparams->data.F32[i] = sqrt(covar->data.F32[i][i]);
     177        if (psTraceGetLevel("psModules.objects") >= 4) {
     178            fprintf (stderr, "%f +/- %f\n", params->data.F32[i], dparams->data.F32[i]);
     179        }
    180180    }
    181181    psTrace ("psModules.objects", 4, "niter: %d, chisq: %f", myMin->iter, myMin->value);
  • trunk/psModules/src/objects/pmSourceMatch.c

    r23241 r23989  
    473473        return -1;
    474474    }
     475    // XXX handle this case better:
     476    if (isnan(stats->clippedMean))  {
     477        psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics on transparencies.");
     478        psFree(stats);
     479        return -1;
     480    }
    475481
    476482    float thresh = stats->clippedMean + photoLevel * stats->clippedStdev; // Threshold for clouds
Note: See TracChangeset for help on using the changeset viewer.