IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23989


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
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImageMeasureCrosstalk.c

    r23903 r23989  
    149149
    150150                psStatsInit (stats);
    151                 psVectorStats (stats, vector, NULL, NULL, 0);
     151                if (!psVectorStats (stats, vector, NULL, NULL, 0)) {
     152                    psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     153                    return false;
     154                }
    152155                   
    153156                float background = psMetadataLookupF32 (&status, cell->analysis, "XTALK.REF");
  • trunk/ppStats/src/ppStatsFromMetadataStats.c

    r20888 r23989  
    3838
    3939        psStats *stats = psStatsAlloc(option);
    40         psVectorStats(stats, entry->vector, NULL, NULL, 0);
     40        if (!psVectorStats(stats, entry->vector, NULL, NULL, 0)) {
     41            psError(PS_ERR_UNKNOWN, false, "failure to measure stats for %s", entry->statistic);
     42            continue;
     43        }
    4144
    4245        double value;
  • trunk/ppStats/src/ppStatsReadout.c

    r21183 r23989  
    9292        }
    9393        if (!psVectorStats(data->stats, sampleValues, NULL, sampleMask, 1)) {
    94             psWarning("Unable to perform statistics on readout %s.\n", readoutName);
    95             psErrorClear();
    96         }
     94            psError(PS_ERR_UNKNOWN, false, "failure to measure stats for readout %s", readoutName);
     95        }
     96        // XXX raise if we get a NAN? psWarning("Unable to perform statistics on readout %s.\n", readoutName);
    9797        psFree(sampleValues);
    9898        psFree(sampleMask);
  • trunk/psLib/src/imageops/psImageGeomManip.c

    r21183 r23989  
    110110    out = psImageRecycle(out, outCols, outRows, in->type.type);
    111111
    112     #define PS_IMAGE_REBIN_CASE(TYPE) \
    113 case PS_TYPE_##TYPE: { \
    114         ps##TYPE *outRowData; \
    115         ps##TYPE *vecData = vec->data.TYPE; \
    116         psImageMaskType *inRowMask = NULL; \
    117         for (psS32 row = 0; row < outRows; row++) { \
    118             outRowData = out->data.TYPE[row]; \
    119             psS32 inCurrentRow = row * scale; \
    120             psS32 inNextRow = (row + 1) * scale; \
    121             for (psS32 col = 0; col < outCols; col++) { \
    122                 psS32 inCurrentCol = col * scale; \
    123                 psS32 inNextCol = (col + 1) * scale; \
    124                 psS32 n = 0; \
     112#define PS_IMAGE_REBIN_CASE(TYPE)                                       \
     113    case PS_TYPE_##TYPE: {                                              \
     114        ps##TYPE *outRowData;                                           \
     115        ps##TYPE *vecData = vec->data.TYPE;                             \
     116        psImageMaskType *inRowMask = NULL;                              \
     117        for (psS32 row = 0; row < outRows; row++) {                     \
     118            outRowData = out->data.TYPE[row];                           \
     119            psS32 inCurrentRow = row * scale;                           \
     120            psS32 inNextRow = (row + 1) * scale;                        \
     121            for (psS32 col = 0; col < outCols; col++) {                 \
     122                psS32 inCurrentCol = col * scale;                       \
     123                psS32 inNextCol = (col + 1) * scale;                    \
     124                psS32 n = 0;                                            \
    125125                for (psS32 inRow = inCurrentRow; inRow < inNextRow && inRow < inRows; inRow++) { \
    126                     ps##TYPE* inRowData = in->data.TYPE[inRow]; \
    127                     if (mask != NULL) { \
     126                    ps##TYPE* inRowData = in->data.TYPE[inRow];         \
     127                    if (mask != NULL) {                                 \
    128128                        inRowMask = mask->data.PS_TYPE_IMAGE_MASK_DATA[inRow]; \
    129                     } \
     129                    }                                                   \
    130130                    for (psS32 inCol = inCurrentCol; inCol < inNextCol && inCol < inCols; inCol++) { \
    131                         if (maskData != NULL) { \
     131                        if (maskData != NULL) {                         \
    132132                            maskData[n] = (inRowMask[inCol] & maskVal); \
    133                         } \
    134                         vecData[n++] = inRowData[inCol]; \
    135                     } \
    136                 } \
    137                 vec->n = n; \
    138                 if (maskVec) { \
    139                     maskVec->n = n; \
    140                 } \
    141                  psVectorStats(myStats, vec, NULL, maskVec, 0xff); /* the mask vector has only 0 or 1 */ \
    142                 outRowData[col] = (ps##TYPE)psStatsGetValue(myStats, statistic); \
    143             } \
    144         } \
    145     } \
     133                        }                                               \
     134                        vecData[n++] = inRowData[inCol];                \
     135                    }                                                   \
     136                }                                                       \
     137                vec->n = n;                                             \
     138                if (maskVec) {                                          \
     139                    maskVec->n = n;                                     \
     140                }                                                       \
     141                if (!psVectorStats(myStats, vec, NULL, maskVec, 0xff)) { /* the mask vector has only 0 or 1 */ \
     142                    psError(PS_ERR_UNKNOWN, false, "failure to measure stats"); \
     143                    psFree(out);                                        \
     144                    out = NULL;                                         \
     145                    goto escape;                                        \
     146                }                                                       \
     147                outRowData[col] = (ps##TYPE)psStatsGetValue(myStats, statistic); \
     148            }                                                           \
     149        }                                                               \
     150    }                                                                   \
    146151    break;
    147152
     
    161166            char* typeStr;
    162167            PS_TYPE_NAME(typeStr,in->type.type);
    163             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    164                     _("Specified psImage type, %s, is not supported."),
    165                     typeStr);
     168            psError(PS_ERR_BAD_PARAMETER_TYPE, true, _("Specified psImage type, %s, is not supported."), typeStr);
    166169            psFree(out);
    167170            out = NULL;
     
    169172    }
    170173
     174escape:
    171175    psFree(vec);
    172176    psFree(maskVec);
  • trunk/psLib/src/imageops/psImageMap.c

    r21183 r23989  
    211211            // XXX need to supply a mask and skip the masked pixels when calculating the centroid
    212212            // this will not in general be properly weighted...
    213             if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
     213            if (!psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
     214                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     215                return false;
     216            }
     217
     218            // XXX ensure only one option is selected, or save both position and width
     219            map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
     220
     221            if (isnan(map->map->data.F32[iy][ix])) {
     222                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 1;
     223            } else {
    214224                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 0;
    215                 // XXX ensure only one option is selected, or save both position and width
    216                 map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
    217225
    218226                // calculate the mean position and save:
    219227                psStatsInit (meanStat);
    220                 psVectorStats (meanStat, xCell, NULL, NULL, 0);
     228                if (!psVectorStats (meanStat, xCell, NULL, NULL, 0)) {
     229                    psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     230                    return false;
     231                }
    221232                xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
    222233                psStatsInit (meanStat);
    223                 psVectorStats (meanStat, yCell, NULL, NULL, 0);
     234                if (!psVectorStats (meanStat, yCell, NULL, NULL, 0)) {
     235                    psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     236                    return false;
     237                }
    224238                yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
    225             } else {
    226                 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 1;
    227239            }
    228240
  • trunk/psLib/src/imageops/psImageMapFit.c

    r21183 r23989  
    7373
    7474        // XXX does ROBUST_MEDIAN work with weight?
    75         psVectorStats(map->stats, f, NULL, mask, maskValue);
     75        if (!psVectorStats(map->stats, f, NULL, mask, maskValue)) {
     76            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     77            return false;
     78        }
    7679
    7780        map->map->data.F32[0][0]   = psStatsGetValue(map->stats, mean);
  • trunk/psLib/src/imageops/psImagePixelExtract.c

    r21183 r23989  
    419419        }
    420420
    421 #define PSIMAGE_CUT_VERTICAL(TYPE) \
    422     case PS_TYPE_##TYPE: { \
    423             psVectorMaskType* maskVecData = NULL; \
    424             for (psS32 c = col0; c < col1; c++) { \
    425                 ps##TYPE *imgData = input->data.TYPE[row0] + c; \
    426                 ps##TYPE *imgVecData = imgVec->data.TYPE; \
    427                 if (maskVec != NULL) { \
     421#define PSIMAGE_CUT_VERTICAL(TYPE)                                      \
     422        case PS_TYPE_##TYPE: {                                          \
     423            psVectorMaskType* maskVecData = NULL;                       \
     424            for (psS32 c = col0; c < col1; c++) {                       \
     425                ps##TYPE *imgData = input->data.TYPE[row0] + c;         \
     426                ps##TYPE *imgVecData = imgVec->data.TYPE;               \
     427                if (maskVec != NULL) {                                  \
    428428                    maskVecData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA; \
    429429                    maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[row0][c]; /* XXX double check this... */ \
    430430                    /** old entry: maskData = (psMaskType* )(mask->data.PS_TYPE_IMAGE_MASK_DATA[row0]) + c; */ \
    431                 } \
    432                 for (psS32 r = row0; r < row1; r++) { \
    433                    *imgVecData = *imgData; \
    434                     imgVecData ++; \
    435                     imgData += inCols; \
    436                     if (maskVecData != NULL) { \
    437                         *maskVecData = (*maskData & maskVal); \
    438                         maskVecData ++; \
    439                         maskData += inCols; \
    440                     } \
    441                 } \
    442                 psVectorStats(myStats, imgVec, NULL, maskVec, 0xff); \
    443                 *outData = psStatsGetValue(myStats, statistic); \
    444                 if (outPosition != NULL) { \
    445                     outPosition->x = c; \
    446                     outPosition->y = row0; \
    447                     outPosition += delta; \
    448                 } \
    449                 outData += delta; \
    450             } \
    451             break; \
     431                }                                                       \
     432                for (psS32 r = row0; r < row1; r++) {                   \
     433                    *imgVecData = *imgData;                             \
     434                    imgVecData ++;                                      \
     435                    imgData += inCols;                                  \
     436                    if (maskVecData != NULL) {                          \
     437                        *maskVecData = (*maskData & maskVal);           \
     438                        maskVecData ++;                                 \
     439                        maskData += inCols;                             \
     440                    }                                                   \
     441                }                                                       \
     442                if (!psVectorStats(myStats, imgVec, NULL, maskVec, 0xff)) { \
     443                    psError(PS_ERR_UNKNOWN, false, "failure to measure stats"); \
     444                    psFree(out);                                        \
     445                    out = NULL;                                         \
     446                    break;                                              \
     447                }                                                       \
     448                *outData = psStatsGetValue(myStats, statistic);         \
     449                if (outPosition != NULL) {                              \
     450                    outPosition->x = c;                                 \
     451                    outPosition->y = row0;                              \
     452                    outPosition += delta;                               \
     453                }                                                       \
     454                outData += delta;                                       \
     455            }                                                           \
     456            break;                                                      \
    452457        }
    453458
     
    466471                char* typeStr;
    467472                PS_TYPE_NAME(typeStr,type);
    468                 psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    469                         _("Specified psImage type, %s, is not supported."),
    470                         typeStr);
     473                psError(PS_ERR_BAD_PARAMETER_TYPE, true, _("Specified psImage type, %s, is not supported."), typeStr);
    471474                psFree(out);
    472475                out = NULL;
     
    534537            }
    535538
    536             psVectorStats(myStats, imgVec, NULL, maskVec, 0xff);
     539            if (!psVectorStats(myStats, imgVec, NULL, maskVec, 0xff)) {
     540                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     541                psFree (out);
     542                out = NULL;
     543                break;
     544            }
    537545            *outData = psStatsGetValue(myStats, statistic);
    538546            if (outPosition != NULL) {
     
    933941
    934942    for (psS32 r = 0; r < numOut; r++) {
    935         psVectorStats(myStats, buffer[r], NULL, bufferMask[r], 0xff);
     943        if (!psVectorStats(myStats, buffer[r], NULL, bufferMask[r], 0xff)){
     944            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     945            psFree(out);
     946            out = NULL;
     947            break;
     948        }
    936949        outData[r] = psStatsGetValue(myStats, statistic);
    937950    }
  • trunk/psLib/src/imageops/psImageStats.c

    r21183 r23989  
    104104    }
    105105
    106     psVectorStats(stats, junkData, NULL, junkMask, 0xff);
     106    if (!psVectorStats(stats, junkData, NULL, junkMask, 0xff)) {
     107        psFree(junkMask);
     108        psFree(junkData);
     109        return false;
     110    }
    107111
    108112    psFree(junkMask);
  • 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
  • trunk/psastro/src/psastroAstromGuess.c

    r21422 r23989  
    382382    psStats *statsQ = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
    383383
    384     psVectorStats (statsP, cornerPd, NULL, cornerMK, 1);
    385     psVectorStats (statsQ, cornerQd, NULL, cornerMK, 1);
     384    if (!psVectorStats (statsP, cornerPd, NULL, cornerMK, 1)) {
     385        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     386        return false;
     387    }
     388    if (!psVectorStats (statsQ, cornerQd, NULL, cornerMK, 1)) {
     389        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     390        return false;
     391    }
    386392
    387393    float angle = atan2 (map->y->coeff[1][0], map->x->coeff[1][0]);
  • trunk/psastro/src/psastroFixChipsTest.c

    r21409 r23989  
    140140    psStats *stats;
    141141    stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    142     psVectorStats (stats, dX, NULL, NULL, 0);
     142    if (!psVectorStats (stats, dX, NULL, NULL, 0)) {
     143        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     144        return false;
     145    }
    143146    Xo = stats->robustMedian;
    144147    fprintf (stderr, "offset x: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
     
    146149
    147150    stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    148     psVectorStats (stats, dY, NULL, NULL, 0);
     151    if (!psVectorStats (stats, dY, NULL, NULL, 0)) {
     152        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     153        return false;
     154    }
    149155    Yo = stats->robustMedian;
    150156    fprintf (stderr, "offset y: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
     
    168174    }
    169175    stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    170     psVectorStats (stats, dT, NULL, NULL, 0);
     176    if (!psVectorStats (stats, dT, NULL, NULL, 0)) {
     177        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     178        return false;
     179    }
    171180    float To = stats->robustMedian;
    172181    fprintf (stderr, "offset t: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
  • trunk/psastro/src/psastroModelAnalysis.c

    r21409 r23989  
    153153
    154154    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    155     psVectorStats (stats, posZero, NULL, NULL, 0);
     155    if (!psVectorStats (stats, posZero, NULL, NULL, 0)) {
     156        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     157        return false;
     158    }
    156159
    157160    fprintf (outfile, "# pos zero %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
  • trunk/psastro/src/psastroModelFitBoresite.c

    r21409 r23989  
    6262
    6363    // center (Xo) = mean(Xo), RX = range / 2
    64     psVectorStats (stats, Xo, NULL, NULL, 0);
     64    if (!psVectorStats (stats, Xo, NULL, NULL, 0)) {
     65        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     66        return NULL;
     67    }
    6568    params->data.F32[PAR_X0] = stats->sampleMean;
    6669    params->data.F32[PAR_RX] = (stats->max - stats->min) / 2.0;
    6770
    6871    // center (Yo) = mean(Yo), RY = range / 2
    69     psVectorStats (stats, Yo, NULL, NULL, 0);
     72    if (!psVectorStats (stats, Yo, NULL, NULL, 0)) {
     73        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     74        return NULL;
     75    }
    7076    params->data.F32[PAR_Y0] = stats->sampleMean;
    7177    params->data.F32[PAR_RY] = (stats->max - stats->min) / 2.0;
  • trunk/psastro/src/psastroZeroPoint.c

    r21409 r23989  
    126126    // this analysis has too few data points to use the robust median method
    127127    psStats *stats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
    128     psVectorStats (stats, dMag, NULL, NULL, 0);
     128    if (!psVectorStats (stats, dMag, NULL, NULL, 0)) {
     129        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     130        return false;
     131    }
    129132    fprintf (stderr, "zero point %f +/- %f using %d stars; transparency %f\n", stats->clippedMean, stats->clippedStdev, Npts, zeropt - stats->clippedMean);
    130133
  • trunk/psphot/src/psphotApResid.c

    r21519 r23989  
    355355
    356356        if (j > 2) {
    357             bool status = true;
    358             status &= psVectorStats (statsS, dASubset, NULL, mkSubset, 0xff);
    359             status &= psVectorStats (statsM, dMSubset, NULL, mkSubset, 0xff);
    360             if (!status) { psErrorClear (); }
     357            if (!psVectorStats (statsS, dASubset, NULL, mkSubset, 0xff)) {
     358                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     359                return false;
     360            }
     361            if (!psVectorStats (statsM, dMSubset, NULL, mkSubset, 0xff)) {
     362                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     363                return false;
     364            }
    361365            dSo->data.F32[i] = statsS->robustStdev;
    362366            dMo->data.F32[i] = statsM->sampleMean;
    363367            dRo->data.F32[i] = statsS->robustStdev / statsM->sampleMean;
    364             //      fprintf (stderr, "%d (%d) : sys: %f, phot: %f, rat: %f\n", i, j, dSo->data.F32[i], dMo->data.F32[i], dRo->data.F32[i]);
    365368        } else {
    366369            dSo->data.F32[i] = NAN;
     
    375378    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
    376379    if (!psVectorStats (stats, dRo, NULL, NULL, 0)) {
    377         // XXX better testing of raised error
    378         psErrorClear();
     380        psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     381        return false;
    379382    }
    380383
  • trunk/psphot/src/psphotChoosePSF.c

    r21183 r23989  
    361361
    362362    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV | PS_STAT_SAMPLE_QUARTILE);
    363     psVectorStats (stats, fwhmMajor, NULL, NULL, 0);
     363    if (!psVectorStats (stats, fwhmMajor, NULL, NULL, 0)) {
     364        psError(PS_ERR_UNKNOWN, false, "failure to measure stats for FWHM MAJOR");
     365        return false;
     366    }
     367
    364368    psMetadataAddF32 (recipe, PS_LIST_TAIL, "FWHM_MAJ",   PS_META_REPLACE, "PSF FWHM Major axis (mean)", stats->sampleMean);
    365369    psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MJ_SG",   PS_META_REPLACE, "PSF FWHM Major axis (sigma)", stats->sampleStdev);
     
    367371    psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MJ_UQ",   PS_META_REPLACE, "PSF FWHM Major axis (upper quartile)", stats->sampleUQ);
    368372
    369     psVectorStats (stats, fwhmMinor, NULL, NULL, 0);
     373    if (!psVectorStats (stats, fwhmMinor, NULL, NULL, 0)) {
     374        psError(PS_ERR_UNKNOWN, false, "failure to measure stats for FWHM MINOR");
     375        return false;
     376    }
    370377    psMetadataAddF32 (recipe, PS_LIST_TAIL, "FWHM_MIN",   PS_META_REPLACE, "PSF FWHM Minor axis (mean)", stats->sampleMean);
    371378    psMetadataAddF32 (recipe, PS_LIST_TAIL, "FW_MN_SG",   PS_META_REPLACE, "PSF FWHM Minor axis (sigma)", stats->sampleStdev);
  • trunk/psphot/src/psphotDiagnosticPlots.c

    r21108 r23989  
    4040
    4141    psStats *stats = psStatsAlloc (PS_STAT_MAX | PS_STAT_MIN);
    42     psVectorStats (stats, values, NULL, NULL, 0);
     42    if (!psVectorStats (stats, values, NULL, NULL, 0)) {
     43        psError(PS_ERR_UNKNOWN, false, "failure to measure stats for histogram");
     44        return false;
     45    }
    4346
    4447    psHistogram *histogram = psHistogramAlloc (stats->min, stats->max, 1000);
     
    6366    psStatsInit (stats);
    6467    stats->options = PS_STAT_MAX | PS_STAT_MIN;
    65     psVectorStats (stats, histogram->nums, NULL, NULL, 0);
     68    if (!psVectorStats (stats, histogram->nums, NULL, NULL, 0)) {
     69        psError(PS_ERR_UNKNOWN, false, "failure to measure stats for histogram");
     70        return false;
     71    }
    6672
    6773    // scale the plot to hold the histogram
     
    100106    psStatsInit (stats);
    101107    stats->options = PS_STAT_MAX | PS_STAT_MIN;
    102     psVectorStats (stats, histogram->nums, NULL, NULL, 0);
     108    if (!psVectorStats (stats, histogram->nums, NULL, NULL, 0)) {
     109        psError(PS_ERR_UNKNOWN, false, "failure to measure stats for histogram");
     110        return false;
     111    }
    103112
    104113    // scale the plot to hold the histogram
  • trunk/psphot/src/psphotImageQuality.c

    r20471 r23989  
    8888                     "Number of stars used for IQ measurements", M2->n);
    8989
     90// XXX make this a recipe option
    9091#if (USE_SAMPLE)
    9192    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV | PS_STAT_SAMPLE_QUARTILE);
  • trunk/psphot/src/psphotMakeResiduals.c

    r21366 r23989  
    200200            // measure the robust median to determine a baseline reference value
    201201            *fluxClip = *fluxClipDef;
    202             psVectorStats (fluxClip, fluxes, NULL, fmasks, fmaskVal);
    203             psErrorClear();             // clear (ignore) any outstanding errors
     202            if (!psVectorStats (fluxClip, fluxes, NULL, fmasks, fmaskVal)) {
     203                psError(PSPHOT_ERR_CONFIG, false, "Error calculating residual stats");
     204                return false;
     205            }
     206            if (isnan(fluxClip->robustMedian)) {
     207                resid->Ro->data.F32[oy][ox] = 0.0;
     208                resid->Rx->data.F32[oy][ox] = 0.0;
     209                resid->Ry->data.F32[oy][ox] = 0.0;
     210                resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = badMask;
     211                continue;
     212            }
    204213
    205214            // mark input pixels which are more than N sigma from the median
     
    220229                // measure the desired statistic on the unclipped pixels
    221230                *fluxStats = *fluxStatsDef;
    222                 psVectorStats (fluxStats, fluxes, NULL, fmasks, fmaskVal);
    223                 psErrorClear();         // clear (ignore) any outstanding errors
     231                if (!psVectorStats (fluxStats, fluxes, NULL, fmasks, fmaskVal)) {
     232                    psError(PSPHOT_ERR_CONFIG, false, "Error calculating residual stats");
     233                    return false;
     234                }
    224235
    225236                resid->Ro->data.F32[oy][ox] = psStatsGetValue(fluxStats, statOption);
    226237                resid->Rx->data.F32[oy][ox] = resid->Ry->data.F32[oy][ox] = 0.0;
    227                 //resid->variance->data.F32[oy][ox] = fluxStats->sampleStdev;
     238
     239                if (isnan(resid->Ro->data.F32[oy][ox])) {
     240                    resid->Ro->data.F32[oy][ox] = 0.0;
     241                    resid->Rx->data.F32[oy][ox] = 0.0;
     242                    resid->Ry->data.F32[oy][ox] = 0.0;
     243                    resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = badMask;
     244                    continue;
     245                }
    228246
    229247                if (fabs(resid->Ro->data.F32[oy][ox]) < pixelSN*fluxStats->sampleStdev/sqrt(nKeep)) {
  • trunk/psphot/src/psphotRoughClass.c

    r21183 r23989  
    9191        return false;
    9292    }
    93     if (!psfClump.X || !psfClump.Y) {
     93    if (!psfClump.X || !psfClump.Y || isnan(psfClump.X) || isnan(psfClump.Y)) {
    9494        psLogMsg ("psphot", 4, "Failed to find a valid PSF clump for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);
    9595        return false;
Note: See TracChangeset for help on using the changeset viewer.