IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9996


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

Reorganising shutter stuff to make it fit within the general framework in ppMergeCombine. Adding ppMergeMask to create a bad pixel mask.

Location:
trunk/ppMerge/src
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppMerge/src/Makefile.am

    r8405 r9996  
    1010        ppMergeConfig.c         \
    1111        ppMergeData.c           \
     12        ppMergeMask.c           \
    1213        ppMergeOptions.c        \
    1314        ppMergeScaleZero.c
     
    2021        ppMergeConfig.h         \
    2122        ppMergeData.h           \
     23        ppMergeMask.h           \
    2224        ppMergeOptions.h        \
    2325        ppMergeScaleZero.h
  • trunk/ppMerge/src/ppMerge.c

    r9463 r9996  
    1414#include "ppMergeCombine.h"
    1515#include "ppMergeScaleZero.h"
     16#include "ppMergeMask.h"
    1617
    1718//#include "ppMem.h"
     
    4546    }
    4647
    47     // Measure the background in each image
    4848    psImage *scale = NULL;              // The scalings
    4949    psImage *zero = NULL;               // The zeros
    50     ppMergeScaleZero(&scale, &zero, data, options, config);
    5150
    52     // Do the combination and write
    53     ppMergeCombine(scale, zero, data, options, config);
     51    if (options->mask) {
     52        // Generate a mask
     53        ppMergeMask(data, options, config);
     54    } else {
     55        // Measure the background in each image
     56        ppMergeScaleZero(&scale, &zero, data, options, config);
     57
     58        // Do the combination and write
     59        ppMergeCombine(scale, zero, data, options, config);
     60    }
    5461
    5562    // Output the statistics
  • trunk/ppMerge/src/ppMergeCombine.c

    r9954 r9996  
    7878#endif
    7979
    80 #if 0
    81 // Write fringe extensions
    82 static void writeFringes(psMetadata *fringes, // Table of extensions with fringe statistics to write
    83                          psFits *fits   // FITS file to which to write
    84                          )
    85 {
    86     assert(fringes);
    87 
    88     // Write the fringe extensions
    89     psMetadataIterator *fringesIter = psMetadataIteratorAlloc(fringes, PS_LIST_HEAD, false); // Iterator
    90     psMetadataItem *fringeItem;         // Item from iteration
    91     while ((fringeItem = psMetadataGetAndIncrement(fringesIter))) {
    92         const char *extname = fringeItem->name; // Extension name
    93         psArray *fringe = fringeItem->data.V; // Fringe data (array of fringe components)
    94         if (!pmFringesWriteFits(fits, NULL, fringe, extname)) {
    95             psWarning("Unable to write fringe data to extension %s\n", extname);
    96         }
    97     }
    98 
    99     // Clear the list
    100     while (psListLength(fringes->list) > 0) {
    101         psMetadataRemoveIndex(fringes, PS_LIST_TAIL);
    102     }
    103 
    104     return;
    105 }
    106 #endif
    10780
    10881// Combine the inputs
     
    133106    pmFPAWrite(data->out, data->outFile, config->database, true, false); // Write header only
    134107    pmChip *chip;                       // Chip of interest
     108    psRandom *rng = NULL;               // Random number generator; required for building a mask
     109    if (options->mask) {
     110        rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     111    }
    135112    while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
    136113        pmChipWrite(chip, data->outFile, config->database, true, false); // Write header only
     
    150127            }
    151128
    152             // Building a shutter correction
    153             if (options->shutter) {
    154                 // Read in the pixels
    155                 int numRead = 0;  // Number of inputs read
    156                 psVector *exptimes = psVectorAlloc(filenames->n, PS_TYPE_F32);  // Reference measurements
    157                 psVectorInit(exptimes, 0);
    158                 psArray *images = psArrayAlloc(filenames->n); // Array of images
    159                 psArray *weights = psArrayAlloc(filenames->n); // Array of weights
    160                 psArray *masks = psArrayAlloc(filenames->n); // Array of masks
     129            // Read bit by bit
     130            int numRead;  // Number of inputs read
     131            int numScan = 0;
     132
     133            do {
     134                numRead = 0;
    161135                for (int i = 0; i < filenames->n; i++) {
    162136                    if (! filenames->data[i] || strlen(filenames->data[i]) == 0) {
     
    167141                        continue;
    168142                    }
    169                     pmFPA *fpaIn = data->in->data[i]; // Input FPA
    170                     pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
    171                     pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
    172                     if (!cellIn->file_exists) {
    173                         // || !cellIn->data_exists) {
    174                         continue;
    175                     }
    176                     if (!pmCellRead(cellIn, fits, config->database) || cellIn->readouts->n == 0) {
    177                         continue;
    178                     }
    179                     if (cellIn->readouts->n > 1) {
    180                         psWarning("Multiple readouts in file %d, chip %d, cell %d --- "
    181                                   "only the first will be used.\n", i, view->chip, view->cell);
    182                     }
    183                     float exptime = psMetadataLookupF32(NULL, cellIn->concepts, "CELL.EXPOSURE");
    184                     if (!isfinite(exptime)) {
    185                         psWarning("File %d, chip %d, cell %d has bad exposure time.\n",
    186                                   i, view->chip, view->cell);
    187                     }
    188                     exptimes->data.F32[i] = exptime;
    189                     pmReadout *readoutIn = cellIn->readouts->data[0];
    190                     pmReadoutSetWeight(readoutIn);
    191                     images->data[i] = psMemIncrRefCounter(readoutIn->image);
    192                     weights->data[i] = psMemIncrRefCounter(readoutIn->weight);
    193                     masks->data[i] = psMemIncrRefCounter(readoutIn->mask);
    194                     numRead++;
     143
     144                    if (!stack->data[i]) {
     145                        pmFPA *fpaIn = data->in->data[i]; // Input FPA
     146                        pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
     147                        pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
     148                        stack->data[i] = pmReadoutAlloc(cellIn); // Input readout
     149                    }
     150
     151                    // Only reading and writing the first readout in each cell (plane 0)
     152                    if (pmReadoutReadNext(stack->data[i], fits, 0, options->rows)) {
     153                        // For anything except BIAS and DARK, we want a mask
     154                        if (options->scale || options->zero || options->shutter) {
     155                            pmReadoutSetMask(stack->data[i]);
     156                        }
     157                        if (options->shutter) {
     158                            pmReadoutSetWeight(stack->data[i]);
     159                        }
     160
     161                        numRead++;
     162                    } else {
     163                        psTrace("ppMerge", 3, "Unable to read from file %d for chip %d, "
     164                                "cell %d, scan %d\n", i, view->chip, view->cell, numScan);
     165                    }
     166
    195167                }
    196                 if (numRead > 1) {
    197                     readout->image = pmShutterCorrectionMeasure(exptimes, images, weights, masks,
    198                                                                 options->shutterSize, options->mean,
    199                                                                 options->stdev, options->shutterIter,
    200                                                                 options->shutterRej,
    201                                                                 options->combine->maskVal);
    202                     psTrace("ppMerge", 5, "Chip %d, cell %d\n", view->chip, view->cell);
    203                 } else {
    204                     psError(PS_ERR_UNKNOWN, true, "Not enough images to combine: %d\n", numRead);
    205                     psFree(images);
    206                     psFree(exptimes);
    207                     return false;
     168
     169                psTrace("ppMerge", 5, "Chip %d, cell %d, scan %d\n", view->chip, view->cell, numScan);
     170                if (numRead > 0) {
     171
     172                    if (options->shutter) {
     173                        readout->image = pmShutterCorrectionMeasure(stack, options->shutterSize,
     174                                                                    options->mean, options->stdev,
     175                                                                    options->shutterIter,
     176                                                                    options->shutterRej,
     177                                                                    options->combine->maskVal);
     178                    } else {
     179                        pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
     180                    }
    208181                }
    209                 psFree(images);
    210                 psFree(masks);
    211                 psFree(weights);
    212                 psFree(exptimes);
    213             } else {
    214 #if 1
    215                 // Read bit by bit
    216 
    217                 int numRead;  // Number of inputs read
    218                 int numScan = 0;
    219                 do {
    220                     numRead = 0;
    221                     for (int i = 0; i < filenames->n; i++) {
    222                         if (! filenames->data[i] || strlen(filenames->data[i]) == 0) {
    223                             continue;
    224                         }
    225                         psFits *fits = data->files->data[i]; // FITS file handle
    226                         if (!fits) {
    227                             continue;
    228                         }
    229 
    230                         if (!stack->data[i]) {
    231                             pmFPA *fpaIn = data->in->data[i]; // Input FPA
    232                             pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
    233                             pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
    234                             stack->data[i] = pmReadoutAlloc(cellIn); // Input readout
    235                         }
    236 
    237                         // Only reading and writing the first readout in each cell (plane 0)
    238                         if (pmReadoutReadNext(stack->data[i], fits, 0, options->rows)) {
    239                             // For anything except BIAS and DARK, we want a mask
    240                             if (options->scale || options->zero) {
    241                                 pmReadoutSetMask(stack->data[i]);
    242                             }
    243                             numRead++;
    244                         } else {
    245                             psTrace("ppMerge", 3, "Unable to read from file %d for chip %d, "
    246                                     "cell %d, scan %d\n", i, view->chip, view->cell, numScan);
    247                         }
    248                     }
    249 
    250                     psTrace("ppMerge", 5, "Chip %d, cell %d, scan %d\n", view->chip, view->cell, numScan);
    251                     if (numRead > 0) {
    252                         pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
    253                     }
    254                     numScan++;
    255 
    256                 } while (numRead > 0);
    257 
    258 #else
    259             // Read whole cells at a time
    260 
    261                 printf("Chip %d, cell %d\n", view->chip, view->cell);
    262                 int numRead = 0;  // Number of inputs read
    263                 for (int i = 0; i < filenames->n; i++) {
    264                     if (! filenames->data[i] || strlen(filenames->data[i]) == 0) {
    265                         continue;
    266                     }
    267                     psFits *fits = data->files->data[i]; // FITS file handle
    268                     if (!fits) {
    269                         continue;
    270                     }
    271                     pmFPA *fpaIn = data->in->data[i]; // Input FPA
    272                     pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip
    273                     pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell
    274                     if (!cellIn->file_exists || !cellIn->data_exists) {
    275                         continue;
    276                     }
    277                     if (!pmCellRead(cellIn, fits, config->database) || cellIn->readouts->n == 0) {
    278                         continue;
    279                     }
    280                     stack->data[i] = cellIn->readouts->data[0];
    281                     numRead++;
    282                 }
    283                 if (numRead > 0) {
    284                     pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
    285                     psTrace("ppMerge", 5, "Chip %d, cell %d\n", view->chip, view->cell);
    286                 }
    287 
    288                 memCheck();
    289 #endif
    290             }
     182                numScan++;
     183
     184            } while (numRead > 0);
    291185
    292186            psFree(stack);
     
    392286
    393287    psFree(view);
     288    psFree(rng);
    394289
    395290    return true;
  • trunk/ppMerge/src/ppMergeOptions.c

    r9832 r9996  
    3737    options->fringe = false;
    3838    options->shutter = false;
     39    options->mask = false;
    3940    options->sample = 1;
    4041    options->mean = PS_STAT_SAMPLE_MEDIAN;
     
    4748    options->shutterIter = 2;
    4849    options->shutterRej = 3.0;
     50    options->maskSuspect = 5.0;
     51    options->maskBad = 10.0;
    4952    options->onOff = 0;
    5053    options->combine = pmCombineParamsAlloc(PS_STAT_SAMPLE_MEAN);
     
    143146    OPTION_PARSE(options->shutterIter,       recipe, "SHUTTER.ITER",   S32);
    144147    OPTION_PARSE(options->shutterRej,        recipe, "SHUTTER.REJECT", F32);
     148    OPTION_PARSE(options->maskSuspect,       recipe, "MASK.SUSPECT",   F32);
     149    OPTION_PARSE(options->maskBad,           recipe, "MASK.BAD",       F32);
    145150
    146151    options->combine->combine = parseStat(recipe, "COMBINE");
     
    159164            options->fringe = false;
    160165            options->shutter = false;
     166            options->mask = false;
    161167        } else if (strcasecmp(type, "DARK") == 0) {
    162168            options->zero = false;
     
    165171            options->fringe = false;
    166172            options->shutter = false;
     173            options->mask = false;
    167174        } else if (strcasecmp(type, "FLAT") == 0) {
    168175            options->zero = false;
     
    171178            options->fringe = false;
    172179            options->shutter = false;
     180            options->mask = false;
    173181        } else if (strcasecmp(type, "FRINGE") == 0) {
    174182            options->zero = true;
     
    177185            options->fringe = true;
    178186            options->shutter = false;
     187            options->mask = false;
    179188        } else if (strcasecmp(type, "SHUTTER") == 0) {
    180189            options->zero = false;
     
    183192            options->fringe = false;
    184193            options->shutter = true;
     194            options->mask = false;
     195            options->rows = 0;          // Read the whole image at once
     196        } else if (strcasecmp(type, "MASK") == 0) {
     197            options->zero = false;
     198            options->scale = false;
     199            options->darktime = false;
     200            options->fringe = false;
     201            options->shutter = false;
     202            options->mask = true;
    185203        } else {
    186204            psLogMsg(__func__, PS_LOG_WARN, "Unrecognised image type: %s --- assuming BIAS.\n", type);
     
    190208            options->fringe = false;
    191209            options->shutter = false;
     210            options->mask = false;
    192211        }
    193212    } else {
     
    198217        options->fringe = false;
    199218        options->shutter = false;
     219        options->mask = false;
    200220    }
    201221
  • trunk/ppMerge/src/ppMergeOptions.h

    r9832 r9996  
    2424    bool fringe;                        // Make fringe measurements?
    2525    bool shutter;                       // Generate shutter correction?
     26    bool mask;                          // Generate bad pixel mask?
    2627    unsigned int sample;                // Sampling factor for measuring the background
    2728    psStatsOptions mean;                // Statistic to use to measure the mean
     
    3435    int shutterIter;                    // Number of iterations for shutter measurement
    3536    float shutterRej;                   // Rejection limit for shutter measurement
     37    float maskSuspect;                  // Threshold for identifying suspect pixels
     38    float maskBad;                      // Threshold for identifying bad pixels
    3639    ppOnOff onOff;                      // On/off pairs?
    3740    pmCombineParams *combine;           // Combination parameters
Note: See TracChangeset for help on using the changeset viewer.