IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16842


Ignore:
Timestamp:
Mar 6, 2008, 10:49:03 AM (18 years ago)
Author:
Paul Price
Message:

Changing to produce multi-darks instead of boring old darks. This allows us to fit the dark current as a function of temperature, time since PON, etc. In fact, what's fit is very configurable.

Location:
trunk/ppMerge/src
Files:
4 edited

Legend:

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

    r16229 r16842  
    1616#include "ppMergeVersion.h"
    1717
     18#define TESTING
     19
     20
    1821#if 0
    19 static psMemId memId = 0;
    20 
    2122static FILE *dumpFile = NULL;
    2223
     
    3637    exit(EXIT_FAILURE);
    3738}
    38 
    39 
     39#endif
     40
     41#if 0
     42static psMemId memId = 0;
    4043static void memDump(void)
    4144{
     
    5255    psFree(leaks);
    5356}
    54 
     57#endif
     58
     59#if 0
    5560static void memCheck(void)
    5661{
     
    7378        psTrace("ppMerge", 0, "Memory in use: %zd\n", totalSize);
    7479        psTrace("ppMerge", 0, "Largest block: %ld\n", largest);
    75         psTrace("ppMerge", 0, "sbrk(): %zd\n", sbrk(0));
     80        psTrace("ppMerge", 0, "sbrk(): %p\n", sbrk(0));
    7681    }
    7782    return;
     
    119124    }
    120125    while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
    121         if (chip->hdu) {
    122             // Data will exist soon
    123             pmFPAUpdateNames(data->out, chip, NULL);
    124             chip->data_exists = true;
    125         }
     126        if (!chip->hdu) {
     127            continue;
     128        }
     129        // Data will exist soon
     130        pmFPAUpdateNames(data->out, chip, NULL);
     131        chip->data_exists = true;
    126132        pmChipWrite(chip, data->outFile, config->database, true, false); // Write header only
    127133        pmCell *cell;                   // Cell of interest
    128134        while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
    129135            cellNum++;
    130             if (cell->hdu) {
    131                 // Data will exist soon
    132                 pmFPAUpdateNames(data->out, chip, cell);
    133                 chip->data_exists = cell->data_exists = true;
    134             }
     136            if (!cell->hdu) {
     137                continue;
     138            }
     139            // Data will exist soon
     140            pmFPAUpdateNames(data->out, chip, cell);
     141            chip->data_exists = cell->data_exists = true;
    135142            pmCellWrite(cell, data->outFile, config->database, true); // Write header only
    136143            pmReadout *readout = pmReadoutAlloc(cell); // Output readout of interest
     
    197204
    198205                        // If we're combining with weights, we want to generate weights.
    199                         if (options->combine->weights) {
     206                        if (options->combine->weights && !options->dark) {
    200207
    201208                            // If it's a bias or dark, set the gain to zero: noise only contributed by read
    202                             if ((!options->zero && !options->scale) || options->darktime) {
     209                            if (!options->zero && !options->scale) {
    203210                                pmReadoutSetWeight(stack->data[i], false);
    204211                            } else {
     
    209216                        numRead++;
    210217                    } else {
    211                         psTrace("ppMerge", 3, "Finished reading file %d, chip %d, cell %d, scan %d\n", i, view->chip, view->cell, numScan);
     218                        psTrace("ppMerge", 3, "Finished reading file %d, chip %d, cell %d, scan %d\n",
     219                                i, view->chip, view->cell, numScan);
    212220                    }
    213221
     
    220228                                                    options->shutterIter, options->shutterRej,
    221229                                                    options->combine->maskVal);
     230                    } else if (options->dark) {
     231                        pmDarkCombine(cell, stack, options->darkOrdinates, options->combine->iter,
     232                                      options->combine->rej, options->combine->maskVal);
    222233                    } else {
    223234                        pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine);
     
    246257            psFree(stack);
    247258
     259#if 0
    248260            // Set the dark time for the output image, since we normalised
    249261            if (options->darktime) {
     
    253265                expItem->data.F32 = 1.0;
    254266            }
     267#endif
    255268
    256269            // Measure the fringes for this cell
     
    334347            if (cell->hdu && !cell->hdu->blankPHU) {
    335348                psTrace("ppMerge", 5, "Writing out cell HDU.\n");
    336                 pmCellWrite(cell, data->outFile, config->database, false);
    337                 if (options->fringe) {
    338                     pmCellWriteTable(data->outFile, cell, "FRINGE");
    339                 }
    340 
     349                if (options->dark) {
     350                    pmCellWriteDark(cell, data->outFile, config->database, false);
     351                } else {
     352                    pmCellWrite(cell, data->outFile, config->database, false);
     353                    if (options->fringe) {
     354                        pmCellWriteTable(data->outFile, cell, "FRINGE");
     355                    }
     356                }
    341357                pmCellFreeData(cell);
    342358            }
     
    354370        if (chip->hdu && !chip->hdu->blankPHU) {
    355371            psTrace("ppMerge", 5, "Writing out chip HDU.\n");
    356             pmChipWrite(chip, data->outFile, config->database, false, false);
    357             if (options->fringe) {
    358                 pmChipWriteTable(data->outFile, chip, "FRINGE");
     372            if (options->dark) {
     373                pmChipWriteDark(chip, data->outFile, config->database, false, false);
     374            } else {
     375                pmChipWrite(chip, data->outFile, config->database, false, false);
     376                if (options->fringe) {
     377                    pmChipWriteTable(data->outFile, chip, "FRINGE");
     378                }
    359379            }
    360380
     
    373393        // Write the pixels
    374394        psTrace("ppMerge", 5, "Writing out FPA HDU.\n");
    375         pmFPAWrite(data->out, data->outFile, config->database, false, false);
    376         if (options->fringe) {
    377             pmFPAWriteTable(data->outFile, fpa, "FRINGE");
     395        if (options->dark) {
     396            pmFPAWriteDark(data->out, data->outFile, config->database, false, false);
     397        } else {
     398            pmFPAWrite(data->out, data->outFile, config->database, false, false);
     399            if (options->fringe) {
     400                pmFPAWriteTable(data->outFile, fpa, "FRINGE");
     401            }
    378402        }
    379403    }
  • trunk/ppMerge/src/ppMergeOptions.c

    r15953 r16842  
    1010#include "ppMerge.h"
    1111#include "ppMergeOptions.h"
     12
     13#define ARRAY_BUFFER 4                  // Number of values to add at once
    1214
    1315//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    3436    options->zero = false;
    3537    options->scale = false;
    36     options->darktime = false;
     38    options->dark = false;
    3739    options->fringe = false;
    3840    options->shutter = false;
     
    6567    options->badMask = 0x00;
    6668    options->growPixels = 0;
     69    options->darkOrdinates = NULL;
    6770    return options;
    6871}
     
    174177            options->zero = false;
    175178            options->scale = false;
    176             options->darktime = false;
     179            options->dark = false;
    177180            options->fringe = false;
    178181            options->shutter = false;
     
    181184            options->zero = false;
    182185            options->scale = false;
    183             options->darktime = true;
     186            options->dark = true;
    184187            options->fringe = false;
    185188            options->shutter = false;
     
    188191            options->zero = false;
    189192            options->scale = true;
    190             options->darktime = false;
     193            options->dark = false;
    191194            options->fringe = false;
    192195            options->shutter = false;
     
    195198            options->zero = false;
    196199            options->scale = true;
    197             options->darktime = false;
     200            options->dark = false;
    198201            options->fringe = false;
    199202            options->shutter = false;
     
    202205            options->zero = false;
    203206            options->scale = true;
    204             options->darktime = false;
     207            options->dark = false;
    205208            options->fringe = false;
    206209            options->shutter = false;
     
    209212            options->zero = true;
    210213            options->scale = true;
    211             options->darktime = false;
     214            options->dark = false;
    212215            options->fringe = true;
    213216            options->shutter = false;
     
    216219            options->zero = false;
    217220            options->scale = false;
    218             options->darktime = false;
     221            options->dark = false;
    219222            options->fringe = false;
    220223            options->shutter = true;
     
    225228            options->zero = false;
    226229            options->scale = false;
    227             options->darktime = false;
     230            options->dark = false;
    228231            options->fringe = false;
    229232            options->shutter = false;
     
    255258
    256259#if 0
    257     // Or you can set them individually
    258     OPTION_PARSE(options->zero,     config->arguments, "-zero",    Bool);
    259     OPTION_PARSE(options->scale,    config->arguments, "-scale",   Bool);
    260     OPTION_PARSE(options->darktime, config->arguments, "-exptime", Bool);
    261 #endif
    262 
    263260    // Number of on/off images
    264261    OPTION_PARSE(options->onOff, config->arguments, "-onoff", S32);
     262#endif
    265263
    266264    // Masking options
     
    268266    options->badMask = pmConfigMask("BAD", config);
    269267
     268    if (options->dark) {
     269        psMetadata *ordinates = psMetadataLookupMetadata(NULL, recipe, "DARK.ORDINATES"); // Ordinates info
     270        options->darkOrdinates = psArrayAllocEmpty(psListLength(ordinates->list));
     271
     272        psMetadataIterator *iter = psMetadataIteratorAlloc(ordinates, PS_LIST_HEAD, NULL); // Iterator
     273        psMetadataItem *item;           // Item from iteration
     274        while ((item = psMetadataGetAndIncrement(iter))) {
     275            int order = 0;              // Polynomial order
     276            bool scale = false;         // Scale values?
     277            float min = NAN, max = NAN; // Minimum and maximum values for scaling
     278            switch (item->type) {
     279              case PS_TYPE_S32:
     280                order = item->data.S32;
     281                break;
     282              case PS_DATA_METADATA:
     283                order = psMetadataLookupS32(NULL, item->data.md, "ORDER");
     284                bool mdok;                  // Status of MD lookup
     285                scale = psMetadataLookupBool(&mdok, item->data.md, "SCALE");
     286                min = psMetadataLookupF32(&mdok, item->data.md, "MIN");
     287                max = psMetadataLookupF32(&mdok, item->data.md, "MAX");
     288                break;
     289              default:
     290                psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     291                        "Type of DARK.ORDINATES entry %s (%x) is not METADATA or S32",
     292                        item->name, item->type);
     293                psFree(options);
     294                return false;
     295            }
     296            if (order <= 0) {
     297                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "ORDER not positive (%d) for DARK.ORDINATES %s",
     298                        order, item->name);
     299                psFree(options);
     300                return false;
     301            }
     302
     303            pmDarkOrdinate *ord = pmDarkOrdinateAlloc(item->name, order);
     304            ord->scale = scale;
     305            ord->min = min;
     306            ord->max = max;
     307            psArrayAdd(options->darkOrdinates, options->darkOrdinates->n, ord);
     308            psFree(ord);
     309        }
     310        psFree(iter);
     311    }
     312
    270313    return options;
    271314}
  • trunk/ppMerge/src/ppMergeOptions.h

    r15953 r16842  
    2121    bool zero;                          // Subtract background before combining?
    2222    bool scale;                         // Scale by the background before combining?
    23     bool darktime;                      // Normalise by the dark time (time since flush)?
     23    bool dark;                          // Generate dark?
    2424    bool fringe;                        // Make fringe measurements?
    2525    bool shutter;                       // Generate shutter correction?
     
    3737    float maskSuspect;                  // Threshold for identifying suspect pixels
    3838    float maskBad;                      // Threshold for identifying bad pixels
    39     bool statsByChip;                   // measure statistics for masking by chip or readout?
    40     pmMaskIdentifyMode maskMode;        // how to set the limit based on the threshold value above?
     39    bool statsByChip;                   // measure statistics for masking by chip or readout?
     40    pmMaskIdentifyMode maskMode;        // how to set the limit based on the threshold value above?
    4141    ppOnOff onOff;                      // On/off pairs?
    4242    pmCombineParams *combine;           // Combination parameters
     
    4444    psMaskType badMask;                 // Mask value for bad (low) pixels
    4545    int growPixels;
     46    psArray *darkOrdinates;             // Ordinates for dark combination
    4647} ppMergeOptions;
    4748
  • trunk/ppMerge/src/ppMergeScaleZero.c

    r13957 r16842  
    2525    assert(config);
    2626
    27     if (!options->scale && !options->zero && !options->darktime && !options->shutter) {
     27    if (!options->scale && !options->zero && !options->shutter) {
    2828        return true;                    // We did everything we were asked for
    2929    }
     
    151151    psStats *bgStats = psStatsAlloc(options->mean); // Statistic to measure the background
    152152    psVector *gains = NULL;             // The gains for each cell
    153     psImage *darktime = NULL;           // The dark time for each integration of each cell
    154153    if (options->scale) {
    155154        gains = psVectorAlloc(data->numCells, PS_TYPE_F32);
    156     }
    157     if (options->darktime) {
    158         darktime = psImageAlloc(data->numCells, filenames->n, PS_TYPE_F32);
    159155    }
    160156
     
    187183                if (!pmCellReadHeader(cell, inFile)) {
    188184                    continue;
    189                 }
    190 
    191                 // Normalising by the exposure time
    192                 if (options->darktime) {
    193                     darktime->data.F32[i][cellNum] = psMetadataLookupF32(NULL, cell->concepts,
    194                                                                          "CELL.DARKTIME");
    195                     if (isnan(darktime->data.F32[i][cellNum])) {
    196                         psWarning("CELL.DARKTIME for file %s chip %d cell %d is not set.\n", name, j, k);
    197                         status = false;
    198                     } else {
    199                         view->chip = j;
    200                         view->cell = k;
    201 
    202                         // This step applies the dark exptime / background relationship: F =
    203                         // polymomial(exptime).  Below, the input images are scaled by the
    204                         // output of this relationship.
    205 
    206                         // For devices with linear dark and no residual bias, this relationship
    207                         // is not defined in the configuration system, and the transformation
    208                         // is defined (when loaded by the concepts) to be F = exptime.  Thus,
    209                         // in this case, the resulting dark image consists of counts/sec.
    210 
    211                         // For devices with a different relationship, the transformation yields
    212                         // the expected number of counts in the given exposure, based on the
    213                         // recorded exptime.  Thus, in this case, the resulting dark image
    214                         // should have a median value of 1.0.
    215 
    216                         // note that these corrections must be applied differently when used to
    217                         // correct a science image. 
    218 
    219                         darktime->data.F32[i][cellNum] = pmFPADarkNorm(fpa, view,
    220                                                                        darktime->data.F32[i][cellNum]);
    221                         if (isnan(darktime->data.F32[i][cellNum])) {
    222                             psWarning("Cannot get dark normalisation for file %s chip %d cell %d.\n",
    223                                       name, j, k);
    224                             status = false;
    225                         }
    226                     }
    227185                }
    228186
     
    355313    }
    356314
    357     if (options->darktime) {
    358         if (!options->scale) {
    359             // Copy over the exposure times
    360             *scales = psImageCopy(*scales, darktime, PS_TYPE_F32);
    361         } else {
    362             *scales = (psImage*)psBinaryOp(*scales, *scales, "*", darktime);
    363         }
    364     }
    365 
    366315    if (options->zero) {
    367316        if (!*zeros) {
Note: See TracChangeset for help on using the changeset viewer.