IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13873


Ignore:
Timestamp:
Jun 18, 2007, 5:59:32 PM (19 years ago)
Author:
Paul Price
Message:

Changes to allow shutter correction to be processed piece by piece.

Location:
trunk/ppMerge/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppMerge/src/ppMerge.c

    r9996 r13873  
    4646    }
    4747
    48     psImage *scale = NULL;              // The scalings
    49     psImage *zero = NULL;               // The zeros
    50 
    5148    if (options->mask) {
    5249        // Generate a mask
    5350        ppMergeMask(data, options, config);
    5451    } else {
     52
     53        psImage *scale = NULL;              // The scalings
     54        psImage *zero = NULL;               // The zeros
     55        psArray *shutters = NULL;           // The shutter correction data
     56
    5557        // Measure the background in each image
    56         ppMergeScaleZero(&scale, &zero, data, options, config);
     58        ppMergeScaleZero(&scale, &zero, &shutters, data, options, config);
    5759
    5860        // Do the combination and write
    59         ppMergeCombine(scale, zero, data, options, config);
     61        ppMergeCombine(scale, zero, shutters, data, options, config);
     62
     63        psFree(scale);
     64        psFree(zero);
     65        psFree(shutters);
    6066    }
    6167
     
    7379    // Cleaning up
    7480    psFree(data);
    75     psFree(scale);
    76     psFree(zero);
    7781    psFree(options);
    7882    psFree(config);
  • trunk/ppMerge/src/ppMergeCombine.c

    r13769 r13873  
    8383bool ppMergeCombine(psImage *scales,    // Scales for each cell of each integration, or NULL
    8484                    psImage *zeros,     // Zeros for each cell of each integration, or NULL
     85                    psArray *shutters, // Shutter correction data for each cell, or NULL
    8586                    ppMergeData *data,  // Data
    8687                    ppMergeOptions *options, // Options
     
    100101                      zeros->numCols == data->numCells &&
    101102                      zeros->numRows == filenames->n));
     103    assert(!options->shutter || shutters);
     104    assert(!shutters || (shutters->n == data->numCells));
    102105
    103106    // Iterate over the FPA
     
    143146            }
    144147
     148            float shutterRef;           // Reference shutter correction
     149            if (options->shutter) {
     150                shutterRef = pmShutterCorrectionReference(shutters->data[cellNum]);
     151            }
     152
    145153            do {
    146154                numRead = 0;
     
    162170
    163171                    // Only reading and writing the first readout in each cell (plane 0)
    164                     bool readOK;
     172                    bool readOK;
    165173                    if (pmReadoutReadNext(&readOK, stack->data[i], fits, 0, options->rows)) {
    166                         if (!readOK) {
    167                             psError(PS_ERR_IO, false, "Failed to read concepts for cell.\n");
    168                             psErrorStackPrint(stderr, "trouble reading data!\n");
    169                             exit (1);
    170                         }
     174                        if (!readOK) {
     175                            psError(PS_ERR_IO, false, "Failed to read concepts for cell.\n");
     176                            psErrorStackPrint(stderr, "trouble reading data!\n");
     177                            exit (1);
     178                        }
    171179                        // If we're creating a bias or a dark, we don't want to generate a mask
    172180                        if ((options->zero || options->scale || options->shutter || options->mask) &&
     
    198206
    199207                    if (options->shutter) {
    200                         pmShutterCorrectionMeasure(readout, stack, options->shutterSize,
    201                                                    options->mean, options->stdev,
    202                                                    options->shutterIter,
    203                                                    options->shutterRej,
    204                                                    options->combine->maskVal);
     208                        pmShutterCorrectionGenerate(readout, NULL, stack, shutterRef, shutters->data[cellNum],
     209                                                    options->shutterIter, options->shutterRej,
     210                                                    options->combine->maskVal);
    205211                    } else {
    206212                        pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
     
    271277            // Statistics on the merged cell
    272278            if (data->statsFile) {
    273                 if (!data->stats) {
    274                     data->stats = psMetadataAlloc();
    275                 }
    276                 if (!ppStats(data->stats,
    277                              data->out,
    278                              view,
    279                              options->combine->maskVal,
    280                              config)) {
     279                if (!data->stats) {
     280                    data->stats = psMetadataAlloc();
     281                }
     282                if (!ppStats(data->stats, data->out, view, options->combine->maskVal, config)) {
    281283                    psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to generate stats for image.\n");
    282                     return false;
    283                 }
    284             }
     284                    return false;
     285                }
     286            }
    285287
    286288            // We threw away the bias sections --- record this
  • trunk/ppMerge/src/ppMergeCombine.h

    r7064 r13873  
    1111bool ppMergeCombine(psImage *scales,    // Scales for each cell of each integration, or NULL
    1212                    psImage *zeros,     // Zeros for each cell of each integration, or NULL
     13                    psArray *shutters, // Shutter correction data for each cell, or NULL
    1314                    ppMergeData *data,  // Data
    1415                    ppMergeOptions *options, // Options
  • trunk/ppMerge/src/ppMergeOptions.c

    r13593 r13873  
    6161    options->satMask = 0x00;
    6262    options->badMask = 0x00;
    63 
    6463    return options;
    6564}
     
    135134
    136135    // First, deal with the recipe.  These are parameters that will typically be constant for a camera.
    137     OPTION_PARSE(options->rows,              recipe, "ROWS",           U16);
     136    OPTION_PARSE(options->rows,              recipe, "ROWS",           S32);
    138137    OPTION_PARSE(options->minElectrons,      recipe, "ELECTRONS",      F32);
    139138    OPTION_PARSE(options->sample,            recipe, "SAMPLE",         S32);
     
    215214            options->shutter = true;
    216215            options->mask = false;
    217             options->rows = 0;          // Read the whole image at once
    218216        } else if (strcasecmp(type, "MASK") == 0) {
    219217            options->zero = false;
  • trunk/ppMerge/src/ppMergeScaleZero.c

    r13814 r13873  
    1515bool ppMergeScaleZero(psImage **scales, // The scales for each integration/cell
    1616                      psImage **zeros, // The zeroes for each integration/cell
     17                      psArray **shutters, // The shutter correction data for each cell
    1718                      ppMergeData *data,// The data
    1819                      const ppMergeOptions *options, // The options
     
    2425    assert(config);
    2526
    26     if (!options->scale && !options->zero && !options->darktime) {
     27    if (!options->scale && !options->zero && !options->darktime && !options->shutter) {
    2728        return true;                    // We did everything we were asked for
    2829    }
     
    4344                                 (*zeros)->numCols == data->numCells &&
    4445                                 (*zeros)->numRows == filenames->n));
     46    assert(!options->shutter || shutters);
     47    assert(!shutters || !*shutters || (*shutters)->n == data->numCells);
    4548
    4649    // Allocate the outputs
     
    5760        *zeros = psImageAlloc(data->numCells, filenames->n, PS_TYPE_F32);
    5861    }
    59 
    60     bool fromConcepts = false;          // Do we get the scale and zero points from the concepts
     62    psRandom *rng = NULL;               // Random number generator
     63    if (options->shutter) {
     64        if (*shutters) {
     65            psFree(*shutters);
     66        }
     67        *shutters = psArrayAlloc(data->numCells);
     68        rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     69    }
     70
     71    bool fromConcepts = false;          // Do we get the scale and zero points from the concepts?
    6172    bool first = true;                  // Are we on the first cell (that sets the standard for the rest)?
    6273    bool done = false;                  // Are we done going through the list?
     
    8697                    if (mdok && !isnan(scale)) {
    8798                        if (!first && !fromConcepts) {
    88                             psLogMsg(__func__, PS_LOG_WARN, "PPMERGE.SCALE and PPMERGE.ZERO have been set "
     99                            psWarning("PPMERGE.SCALE and PPMERGE.ZERO have been set "
    89100                                     "for some, but not all cells --- we will re-measure it for all cells.");
    90101                            done = true;
     
    93104                        fromConcepts = true;
    94105                        (*scales)->data.F32[i][cellNum] = scale;
    95                         psTrace("ppMerge", 9, "Scale for input %ld, chip %ld, cell %ld: %f\n", i, j, k, scale);
     106                        psTrace("ppMerge", 9, "Scale for input %ld, chip %ld, cell %ld: %f\n",
     107                                i, j, k, scale);
    96108                    } else if (!first && fromConcepts) {
    97                         psLogMsg(__func__, PS_LOG_WARN, "PPMERGE.SCALE and PPMERGE.ZERO have been set "
     109                        psWarning("PPMERGE.SCALE and PPMERGE.ZERO have been set "
    98110                                 "for some, but not all cells --- we will re-measure it for all cells.");
    99111                        fromConcepts = false;
     
    107119                    if (mdok && !isnan(zero)) {
    108120                        if (!first && !fromConcepts) {
    109                             psLogMsg(__func__, PS_LOG_WARN, "PPMERGE.SCALE and PPMERGE.ZERO have been set "
     121                            psWarning("PPMERGE.SCALE and PPMERGE.ZERO have been set "
    110122                                     "for some, but not all cells --- we will re-measure it for all cells.");
    111123                            done = true;
     
    116128                        psTrace("ppMerge", 9, "Zero for input %ld, chip %ld, cell %ld: %f\n", i, j, k, zero);
    117129                    } else if (!first && fromConcepts) {
    118                         psLogMsg(__func__, PS_LOG_WARN, "PPMERGE.SCALE and PPMERGE.ZERO have been set "
     130                        psWarning("PPMERGE.SCALE and PPMERGE.ZERO have been set "
    119131                                 "for some, but not all cells --- we will re-measure it for all cells.");
    120132                        fromConcepts = false;
     
    131143    if (fromConcepts) {
    132144        // We've already done everything we need to
     145        psFree(rng);
    133146        return true;
    134147    }
     
    205218
    206219                    if (cell->readouts->n > 1) {
    207                         psLogMsg(__func__, PS_LOG_WARN, "File %s chip %d cell %d contains more than one "
     220                        psWarning("File %s chip %d cell %d contains more than one "
    208221                                 "readout --- ignoring all but the first.\n", name, j, k);
    209222                        status = false;
     
    222235                        gains->data.F32[cellNum] = psMetadataLookupF32(&mdok, cell->concepts, "CELL.GAIN");
    223236                        if (!mdok || isnan(gains->data.F32[cellNum])) {
    224                             psLogMsg(__func__, PS_LOG_WARN, "CELL.GAIN for file %s chip %d cell %d is not "
     237                            psWarning("CELL.GAIN for file %s chip %d cell %d is not "
    225238                                     "set.\n", name, j, k);
    226239                            gains->data.F32[cellNum] = NAN;
     
    259272                }
    260273
     274                // Shutter correction
     275                if (options->shutter) {
     276                    if (!pmCellRead(cell, inFile, config->database)) {
     277                        // Nothing here
     278                        pmCellFreeData(cell);
     279                        continue;
     280                    }
     281
     282                    if (cell->readouts->n > 1) {
     283                        psWarning("File %s chip %d cell %d contains more than one "
     284                                  "readout --- ignoring all but the first.\n", name, j, k);
     285                        status = false;
     286                    }
     287                    pmReadout *readout = cell->readouts->data[0]; // The readout of interest
     288
     289                    pmShutterCorrectionData *shutter = (*shutters)->data[cellNum]; // Shutter correction data
     290                    if (!shutter) {
     291                        shutter = pmShutterCorrectionDataAlloc(readout->image->numCols,
     292                                                               readout->image->numRows,
     293                                                               options->shutterSize);
     294                        (*shutters)->data[cellNum] = shutter;
     295                    }
     296                    if (!pmShutterCorrectionAddReadout(shutter, readout, options->mean, options->stdev,
     297                                                       options->combine->maskVal, rng)) {
     298                        psWarning("Can't add file %s chip %d cell %d to shutter correction --- ignored.",
     299                                  name, j, k);
     300                        status = false;
     301                    }
     302                }
     303
     304
    261305                pmCellFreeData(cell);
    262306            }
     
    265309        pmFPAFreeData(fpa);
    266310    }
     311    psFree(rng);
    267312    psFree(bgStats);
    268313    psFree(view);
     
    277322        psVector *fluxes = NULL;        // Solution to fluxes
    278323        if (!pmFlatNormalize(&fluxes, &gains, background)) {
    279             psLogMsg(__func__, PS_LOG_WARN, "Normalisation failed to converge --- continuing anyway.\n");
     324            psWarning("Normalisation failed to converge --- continuing anyway.\n");
    280325            status = false;
    281326        }
  • trunk/ppMerge/src/ppMergeScaleZero.h

    r7263 r13873  
    1111bool ppMergeScaleZero(psImage **scales, // The scales for each integration/cell
    1212                      psImage **zeros, // The zeroes for each integration/cell
     13                      psArray **shutter,// The shutter correction data for each cell
    1314                      ppMergeData *data,// The data
    1415                      const ppMergeOptions *options, // The options
Note: See TracChangeset for help on using the changeset viewer.