IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8004


Ignore:
Timestamp:
Jul 27, 2006, 5:21:19 PM (20 years ago)
Author:
Paul Price
Message:

Changing p_psGetStatsValue over to psStatsSingleOption and psStatsGetValue

Location:
trunk/psModules/src
Files:
5 edited

Legend:

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

    r7604 r8004  
    1111 *  @author GLG, MHPCC
    1212 *
    13  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-06-21 03:21:16 $
     13 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-07-28 03:21:19 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    165165}
    166166
    167 
    168 /******************************************************************************
    169 GenNewStatOptions(): this routine will take as input the options member of the
    170 stat data structure, determine if multiple options have been specified, issue
    171 a warning message if so, and return the highest priority option (according to
    172 the order of the if-statements in this code).  The higher priority options are
    173 listed lower in the code.
    174  *****************************************************************************/
    175 static psStatsOptions GenNewStatOptions(const psStats *stat)
    176 {
    177     assert(stat);
    178 
    179     psS32 numOptions = 0;
    180     psStatsOptions opt = 0;
    181 
    182     if (stat->options & PS_STAT_ROBUST_MEDIAN) {
    183         if (numOptions == 0) {
    184             opt = PS_STAT_ROBUST_MEDIAN;
    185         }
    186         numOptions++;
    187     }
    188 
    189     if (stat->options & PS_STAT_CLIPPED_MEAN) {
    190         if (numOptions == 0) {
    191             opt = PS_STAT_CLIPPED_MEAN;
    192         }
    193         numOptions++;
    194     }
    195 
    196     if (stat->options & PS_STAT_SAMPLE_MEDIAN) {
    197         if (numOptions == 0) {
    198             opt = PS_STAT_SAMPLE_MEDIAN;
    199         }
    200         numOptions++;
    201     }
    202 
    203     if (stat->options & PS_STAT_SAMPLE_MEAN) {
    204         numOptions++;
    205         opt = PS_STAT_SAMPLE_MEAN;
    206     }
    207 
    208 
    209     if (numOptions == 0) {
    210         psError(PS_ERR_UNKNOWN,true, "No statistics options have been specified.\n");
    211     }
    212     if (numOptions != 1) {
    213         psLogMsg(__func__, PS_LOG_WARN,
    214                  "WARNING: pmSubtractBias.c: GenNewStatOptions(): Too many statistics options "
    215                  "have been specified\n");
    216     }
    217     return opt;
    218 }
    219 
    220 
    221167// Produce an overscan vector from an array of pixels
    222168static psVector *overscanVector(pmOverscanOptions *overscanOpts, // Overscan options
     
    228174    assert(pixels);
    229175    assert(myStats);
     176
     177    psStatsOptions statistic = psStatsSingleOption(myStats->options); // Statistic to use
     178    assert(statistic != 0);
    230179
    231180    // Reduce the overscans
     
    241190            ordinate->data.F32[i] = 2.0*(float)i/(float)pixels->n - 1.0; // Scale to [-1,1]
    242191            psVectorStats(myStats, values, NULL, NULL, 0);
    243             double reducedVal = NAN; // Result of statistics
    244             if (! p_psGetStatValue(myStats, &reducedVal)) {
    245                 psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine result "
    246                         "of statistics on row %d.\n", i);
    247                 return NULL;
    248             }
    249             reduced->data.F32[i] = reducedVal;
     192            reduced->data.F32[i] = psStatsGetValue(myStats, statistic);
    250193        } else if (overscanOpts->fitType == PM_FIT_NONE) {
    251194            psError(PS_ERR_UNKNOWN, true, "The overscan is not supplied for all points on the "
     
    344287        psList *overscans = in->bias; // List of the overscan images
    345288
    346         psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); // A new psStats, to avoid clobbering original
    347         myStats->options = GenNewStatOptions(overscanOpts->stat);
     289        psStatsOptions statistic = psStatsSingleOption(overscanOpts->stat->options); // Statistic to use
     290        if (statistic == 0) {
     291            psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Multiple or no statistics options set: %x\n",
     292                    overscanOpts->stat);
     293            return false;
     294        }
     295        psStats *stats = psStatsAlloc(statistic); // A new psStats, to avoid clobbering original
    348296
    349297        // Reduce all overscan pixels to a single value
     
    365313            psFree(iter);
    366314
    367             (void)psVectorStats(myStats, pixels, NULL, NULL, 0);
    368             double reduced = NAN;     // Result of statistics
    369             if (! p_psGetStatValue(myStats, &reduced)) {
    370                 psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine result from requested statistical operation.  Returning input image.\n");
    371                 return false;
    372             }
     315            (void)psVectorStats(stats, pixels, NULL, NULL, 0);
     316            double reduced = psStatsGetValue(stats, statistic); // Result of statistics
    373317            (void)psBinaryOp(image, image, "-", psScalarAlloc((float)reduced, PS_TYPE_F32));
    374318        } else {
     
    408352
    409353                // Reduce the overscans
    410                 psVector *reduced = overscanVector(overscanOpts, pixels, myStats);
     354                psVector *reduced = overscanVector(overscanOpts, pixels, stats);
    411355                psFree(pixels);
    412356                if (! reduced) {
     
    452396
    453397                // Reduce the overscans
    454                 psVector *reduced = overscanVector(overscanOpts, pixels, myStats);
     398                psVector *reduced = overscanVector(overscanOpts, pixels, stats);
    455399                psFree(pixels);
    456400                if (! reduced) {
     
    467411            }
    468412        }
    469         psFree(myStats);
     413        psFree(stats);
    470414    } // End of overscan subtraction
    471415
  • trunk/psModules/src/detrend/pmSubtractSky.c

    r7769 r8004  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-06-30 23:59:49 $
     8 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-07-28 03:21:19 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    9090requirements change and we might need a custom reBin function.
    9191 *****************************************************************************/
    92 /*
     92#if 0
    9393static psImage *binImage(psImage *origImage,
    9494                         int binFactor,
     
    9696{
    9797    psTrace("SubtractSky.binImage", 4, "Calling binImage(%d)\n", binFactor);
    98  
     98
    9999    if (binFactor <= 0) {
    100100        psLogMsg(__func__, PS_LOG_WARN,
     
    105105        return(origImage);
    106106    }
    107  
     107
    108108    psVector *binVector = psVectorAlloc(binFactor * binFactor, PS_TYPE_F32);
    109109    psVector *binMask = psVectorAlloc(binFactor * binFactor, PS_TYPE_U8);
    110110    psStats *myStats = psStatsAlloc(statOptions);
    111  
     111
    112112    for (psS32 row = 0; row < origImage->numRows ; row+=binFactor) {
    113113        for (psS32 col = 0; col < origImage->numCols ; col+=binFactor) {
     
    134134            psF64 statValue;
    135135            psBool rc = p_psGetStatValue(rc1, &statValue);
    136  
     136
    137137            if (rc == true) {
    138138                origImage->data.F32[row][col] = (psF32) statValue;
     
    147147    psFree(binMask);
    148148    psFree(myStats);
    149  
     149
    150150    psTrace("SubtractSky.binImage", 4, "Exiting binImage(%d)\n", binFactor);
    151151    return(origImage);
    152152}
    153 */
     153#endif
    154154
    155155/******************************************************************************
     
    601601    } else {
    602602        // Determine the mean and standard deviation of the binned image.
    603         psF64 binnedMean;
    604         psF64 binnedStdev;
    605         psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    606         psStats *rc =  psImageStats(myStats, binnedImage, NULL, 0);
    607         if (rc == NULL) {
    608             psError(PS_ERR_UNKNOWN, false, "psImageStats(): could not perform requested statistical operation.  Returning in image.\n");
    609             return(in);
    610         }
    611         if (false == p_psGetStatValue(rc, &binnedMean)) {
    612             psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine requested statistical operation.  Returning in image.\n");
    613             return(in);
    614         }
    615         psTrace(".psModule.pmSubtractSky", 6,
    616                 "binned Mean is %f\n", binnedMean);
    617 
    618         myStats->options = PS_STAT_SAMPLE_STDEV;
    619         rc =  psImageStats(myStats, binnedImage, NULL, 0);
    620         if (rc == NULL) {
    621             psError(PS_ERR_UNKNOWN, false, "psImageStats(): could not perform requested statistical operation.  Returning in image.\n");
    622             return(in);
    623         }
    624         if (false == p_psGetStatValue(myStats, &binnedStdev)) {
    625             psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine requested statistical operation.  Returning in image.\n");
    626             return(in);
    627         }
     603        psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
     604        if (!psImageStats(myStats, binnedImage, NULL, 0)) {
     605            psError(PS_ERR_UNEXPECTED_NULL, false, "Couldn't get statistics for image.\n");
     606            return NULL;
     607        }
     608        psF64 binnedMean = myStats->sampleMean;
     609        psF64 binnedStdev = myStats->sampleStdev;
    628610        psFree(myStats);
    629611        psTrace(".psModule.pmSubtractSky", 6,
  • trunk/psModules/src/imcombine/pmImageCombine.c

    r7769 r8004  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-06-30 23:59:49 $
     10 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-07-28 03:21:19 $
    1212 *
    1313 *  XXX: pmRejectPixels() has a known bug with the pmImageTransform() call.
     
    4545    psS32 numIter,                      ///< Number of rejection iterations
    4646    psF32 sigmaClip,                    ///< Number of standard deviations at which to reject
    47     const psStats *stats)               ///< Statistics to use in the combination
     47    psStats *stats)               ///< Statistics to use in the combination
    4848{
    4949
     
    9898    }
    9999    PS_ASSERT_PTR_NON_NULL(stats, combine);
     100    psStatsOptions statistic = psStatsSingleOption(stats->options);
     101    if (statistic == 0) {
     102        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Multiple or no statistics options set: %x\n", statistic);
     103        return combine;
     104    }
    100105
    101106    // Allocate and initialize the combined image, if necessary.
     
    185190                // Combine all the pixels, using the specified stat.
    186191
    187                 stats = psVectorStats((psStats *) stats, pixelData, pixelErrors, pixelMask, maskVal);
    188                 psF64 combinedPixel;
    189                 psBool rc = p_psGetStatValue(stats, &combinedPixel);
    190                 if (rc != true) {
    191                     psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not combine pixels (%d, %d) with the specified stat.\n", row, col);
    192                 }
     192                stats = psVectorStats(stats, pixelData, pixelErrors, pixelMask, maskVal);
     193                psF64 combinedPixel = psStatsGetValue(stats, statistic);
     194
    193195                if (iter == 0) {
    194196                    combine->data.F32[row][col] = (psF32) combinedPixel;
     
    202204                for (psS32 im = 0 ; im < numImages ; im++) {
    203205                    stdevStats = psVectorStats(stdevStats, pixelData, pixelErrors, pixelMask, maskVal);
    204                     psF64 stdev;
    205                     psBool rc = p_psGetStatValue(stdevStats, &stdev);
    206                     if (rc != true) {
    207                         psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not compute the standard deviation of pixel (%d, %d).\n", row, col);
    208                         psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not combine pixels (%d, %d) with the specified stat.\n", row, col);
    209                     }
     206                    psF64 stdev = stdevStats->sampleStdev;
    210207
    211208                    if (!(pixelMask->data.U8[im] & maskVal)) {
     
    289286                }
    290287                // Combine all the pixels, using the specified stat.
    291                 stats = psVectorStats((psStats *) stats, pixelData, pixelErrors, pixelMask, maskVal);
    292                 psF64 tmpF64;
    293                 psBool rc = p_psGetStatValue(stats, &tmpF64);
    294                 combine->data.F32[row][col] = (psF32) tmpF64;
    295                 if (rc != true) {
    296                     psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not combine pixels (%d, %d) with the specified stat.\n", row, col);
    297                 }
     288                stats = psVectorStats(stats, pixelData, pixelErrors, pixelMask, maskVal);
     289                combine->data.F32[row][col] = psStatsGetValue(stats, statistic);
    298290            }
    299291        }
  • trunk/psModules/src/imcombine/pmImageCombine.h

    r5170 r8004  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2005-09-28 20:43:52 $
     10 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-07-28 03:21:19 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3636    psS32 numIter,                      ///< Number of rejection iterations
    3737    psF32 sigmaClip,                    ///< Number of standard deviations at which to reject
    38     const psStats *stats                ///< Statistics to use in the combination
     38    psStats *stats                      ///< Statistics to use in the combination
    3939);
    4040
  • trunk/psModules/src/objects/pmSourceSky.c

    r7604 r8004  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-06-21 03:21:16 $
     8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-07-28 03:21:19 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4949    PS_ASSERT_INT_NONNEGATIVE(Radius, false);
    5050
     51    psStatsOptions statistic = psStatsSingleOption(statsOptions);
     52    if (statistic == 0) {
     53        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Multiple or no statistics specified: %x\n", statsOptions);
     54        return NULL;
     55    }
     56
    5157    psImage *image = source->pixels;
    5258    psImage *mask  = source->mask;
     
    6167    myStats = psImageStats(myStats, image, mask, 0xff);
    6268    psImageMaskRegion(mask, srcRegion, "AND", NOT_U8(PM_MASK_MARK));
    63 
    64     psF64 tmpF64;
    65     p_psGetStatValue(myStats, &tmpF64);
     69    double value = psStatsGetValue(myStats, statistic);
    6670    psFree(myStats);
    6771
    68     if (isnan(tmpF64)) {
     72    if (isnan(value)) {
    6973        psTrace(__func__, 3, "---- %s(false) end ----\n", __func__);
    7074        return(false);
     
    7377        source->moments = pmMomentsAlloc();
    7478    }
    75     source->moments->Sky = (psF32) tmpF64;
     79    source->moments->Sky = value;
    7680    psTrace(__func__, 3, "---- %s(true) end ----\n", __func__);
    7781    return (true);
     
    9296    PS_ASSERT_INT_NONNEGATIVE(Radius, false);
    9397
     98    psStatsOptions statistic = psStatsSingleOption(statsOptions);
     99    if (statistic == 0) {
     100        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Multiple or no statistics specified: %x\n", statsOptions);
     101        return NULL;
     102    }
     103
    94104    psImage *image = source->weight;
    95105    psImage *mask  = source->mask;
     
    104114    myStats = psImageStats(myStats, image, mask, 0xff);
    105115    psImageMaskRegion(mask, srcRegion, "AND", NOT_U8(PM_MASK_MARK));
    106 
    107     psF64 tmpF64;
    108     p_psGetStatValue(myStats, &tmpF64);
     116    double value = psStatsGetValue(myStats, statistic);
    109117    psFree(myStats);
    110118
    111     if (isnan(tmpF64)) {
     119    if (isnan(value)) {
    112120        psTrace(__func__, 3, "---- %s(false) end ----\n", __func__);
    113121        return(false);
     
    116124        source->moments = pmMomentsAlloc();
    117125    }
    118     source->moments->dSky = (psF32) tmpF64;
     126    source->moments->dSky = value;
    119127    psTrace(__func__, 3, "---- %s(true) end ----\n", __func__);
    120128    return (true);
Note: See TracChangeset for help on using the changeset viewer.