IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 14, 2006, 2:40:49 PM (19 years ago)
Author:
Paul Price
Message:

Input is an array of readouts, instead of multiple arrays of images, masks, weights and exposure times. The function can generate these arrays, saving the user some work.

File:
1 edited

Legend:

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

    r9730 r9984  
    345345#define MEASURE_SAMPLES 4
    346346
    347 psImage *pmShutterCorrectionMeasure(const psVector *exptimes, const psArray *images, const psArray *weights,
    348                                     const psArray *masks, unsigned int size, psStatsOptions meanStat,
     347psImage *pmShutterCorrectionMeasure(const psArray *readouts, int size, psStatsOptions meanStat,
    349348                                    psStatsOptions stdevStat, int nIter, float rej, psMaskType maskVal)
    350349{
    351     PS_ASSERT_VECTOR_NON_NULL(exptimes, NULL);
    352     PS_ASSERT_VECTOR_TYPE(exptimes, PS_TYPE_F32, NULL);
    353     PS_ASSERT_ARRAY_NON_NULL(images, NULL);
    354     if (masks) {
    355         PS_ASSERT_ARRAYS_SIZE_EQUAL(images, masks, NULL);
    356     }
    357     if (weights) {
    358         PS_ASSERT_ARRAYS_SIZE_EQUAL(images, weights, NULL);
    359     }
    360     long num = images->n;               // Number of images
    361     PS_ASSERT_VECTOR_SIZE(exptimes, num, NULL);
     350    PS_ASSERT_ARRAY_NON_NULL(readouts, NULL);
     351    PS_ASSERT_ARRAY_NON_EMPTY(readouts, NULL);
     352    PS_ASSERT_INT_POSITIVE(size, NULL);
     353
     354    long num = readouts->n;             // Number of readouts
    362355    PS_ASSERT_INT_POSITIVE(nIter, NULL);
    363356    PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, NULL);
     357
     358    psArray *images = psArrayAlloc(num);// Array of images
     359    psArray *masks = NULL; // Array of masks
     360    psArray *weights = NULL; // Array of weights
     361    psVector *exptimes = psVectorAlloc(num, PS_TYPE_F32); // Vector of exposure times
     362
     363    {
     364        pmReadout *readout = readouts->data[0]; // Representative readout
     365        if (readout->mask)
     366        {
     367            masks = psArrayAlloc(num);
     368        }
     369        if (readout->weight)
     370        {
     371            weights = psArrayAlloc(num);
     372        }
     373    }
    364374
    365375    // Check input sizes, generate first-pass statistics
     
    373383    int numRows = 0, numCols = 0; // Size of images
    374384    for (long i = 0; i < images->n; i++) {
    375         psImage *image = images->data[i]; // Image of interest
     385        pmReadout *readout = readouts->data[i]; // Readout of interest
     386        if (!readout) {
     387            continue;
     388        }
     389
     390        bool mdok;                      // Status of MD lookup
     391        float exptime = psMetadataLookupF32(&mdok, readout->parent->concepts, "CELL.EXPOSURE"); // Exp. time
     392        if (!mdok || !isfinite(exptime)) {
     393            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Exposure time for readout %ld is not set.\n", i);
     394            goto MEASURE_ERROR;
     395        }
     396        exptimes->data.F32[i] = exptime;
     397
     398        psImage *image = readout->image; // Image of interest
    376399        if (!image) {
    377400            continue;
    378401        }
     402        images->data[i] = image;
    379403        if (image->type.type != PS_TYPE_F32) {
    380404            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Bad type for image: %x\n", image->type.type);
     
    399423            goto MEASURE_ERROR;
    400424        }
    401         if (masks) {
    402             psImage *mask = masks->data[i];
    403             if (mask) {
    404                 if (mask->type.type != PS_TYPE_U8) {
    405                     psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Bad type for mask: %x\n", mask->type.type);
    406                     goto MEASURE_ERROR;
    407                 }
    408                 if (mask->numRows != numRows || mask->numCols != numCols) {
    409                     psError(PS_ERR_BAD_PARAMETER_SIZE, true,
    410                             "Mask sizes don't match: %dx%d vs %dx%d\n", mask->numCols, mask->numRows,
    411                             numCols, numRows);
    412                     goto MEASURE_ERROR;
    413                 }
    414             }
    415         }
     425        psImage *mask = readout->mask; // Mask of interest
     426        if (mask) {
     427            if (!masks) {
     428                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Not all readouts have masks.\n");
     429                goto MEASURE_ERROR;
     430            }
     431            masks->data[i] = mask;
     432
     433            if (mask->type.type != PS_TYPE_U8) {
     434                psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Bad type for mask: %x\n", mask->type.type);
     435                goto MEASURE_ERROR;
     436            }
     437            if (mask->numRows != numRows || mask->numCols != numCols) {
     438                psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     439                        "Mask sizes don't match: %dx%d vs %dx%d\n", mask->numCols, mask->numRows,
     440                        numCols, numRows);
     441                goto MEASURE_ERROR;
     442            }
     443        } else if (masks) {
     444            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Not all readouts have masks.\n");
     445            goto MEASURE_ERROR;
     446        }
     447
     448        psImage *weight = readout->weight; // Weight map of interest
     449        if (weight) {
     450            if (!weights) {
     451                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Not all readouts have weights.\n");
     452                goto MEASURE_ERROR;
     453            }
     454            masks->data[i] = mask;
     455
     456            if (mask->type.type != PS_TYPE_F32) {
     457                psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Bad type for weights: %x\n", weight->type.type);
     458                goto MEASURE_ERROR;
     459            }
     460            if (weight->numRows != numRows || weight->numCols != numCols) {
     461                psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     462                        "Weight sizes don't match: %dx%d vs %dx%d\n", weight->numCols, weight->numRows,
     463                        numCols, numRows);
     464                goto MEASURE_ERROR;
     465            }
     466        } else if (weights) {
     467            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Not all readouts have weights.\n");
     468            goto MEASURE_ERROR;
     469        }
     470
    416471
    417472        // Measure statistics
    418         if (!psImageStats(stats, image, masks->data[i], maskVal)) {
     473        if (!psImageStats(stats, image, mask, maskVal)) {
    419474            psWarning("Unable to measure reference statistics.\n");
    420475        }
     
    539594MEASURE_ERROR:
    540595    // Clean up after error
     596    psFree(exptimes);
     597    psFree(images);
     598    psFree(masks);
     599    psFree(weights);
    541600    psFree(refs);
    542601    psFree(regions);
Note: See TracChangeset for help on using the changeset viewer.