IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.