IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/psModules

    • Property svn:mergeinfo deleted
  • branches/pap/psModules/src/camera/pmFPAMaskWeight.c

    r23259 r25027  
    109109    float saturation = psMetadataLookupF32(&mdok, cell->concepts, "CELL.SATURATION"); // Saturation level
    110110    if (!mdok || isnan(saturation)) {
    111         psError(PS_ERR_IO, true, "CELL.SATURATION is not set --- unable to set mask.\n");
    112         return false;
     111        // psError(PS_ERR_IO, true, "CELL.SATURATION is not set --- unable to set mask.\n");
     112        // return false;
     113        psWarning("CELL.SATURATION is not set --- completely masking cell.\n");
     114        saturation = NAN;
    113115    }
    114116    float bad = psMetadataLookupF32(&mdok, cell->concepts, "CELL.BAD"); // Bad level
    115117    if (!mdok || isnan(bad)) {
    116         psError(PS_ERR_IO, true, "CELL.BAD is not set --- unable to set mask.\n");
    117         return false;
     118        // psError(PS_ERR_IO, true, "CELL.BAD is not set --- unable to set mask.\n");
     119        // return false;
     120        psWarning("CELL.BAD is not set --- completely masking cell.\n");
     121        bad = NAN;
    118122    }
    119123    psTrace("psModules.camera", 5, "Saturation: %f, bad: %f\n", saturation, bad);
    120124
     125    // if CELL.GAIN or CELL.READNOISE are not set, then the variance will be set to NAN;
     126    // in this case, we have to set the mask as well
     127    float gain = psMetadataLookupF32(&mdok, cell->concepts, "CELL.GAIN"); // Cell gain
     128    if (!mdok) { gain = NAN; }
     129    float readnoise = psMetadataLookupF32(&mdok, cell->concepts, "CELL.READNOISE"); // Cell read noise
     130    if (!mdok) { readnoise = NAN; }
    121131
    122132    // Set up the mask
     
    127137    }
    128138    psImage *mask = readout->mask;      // The mask pixels
     139
     140    // completely mask if SATURATION or BAD are invalid
     141    if (isnan(saturation) || isnan(bad) || isnan(gain) || isnan(readnoise)) {
     142        psImageInit(mask, badMask);
     143        return true;
     144    }
     145
    129146    psImageInit(mask, 0);
    130147
     
    199216}
    200217
    201 bool pmReadoutSetVariance(pmReadout *readout, bool poisson)
     218bool pmReadoutSetVariance(pmReadout *readout, const psImage *noiseMap, bool poisson)
    202219{
    203220    PS_ASSERT_PTR_NON_NULL(readout, false);
     221    // check that the noiseMap (if it exists) matches the readout variance size)
    204222
    205223    pmCell *cell = readout->parent;     // The parent cell
     
    209227    float gain = psMetadataLookupF32(&mdok, cell->concepts, "CELL.GAIN"); // Cell gain
    210228    if (!mdok || isnan(gain)) {
    211         psError(PS_ERR_IO, true, "CELL.GAIN is not set --- unable to set variance.\n");
    212         return false;
     229        // psError(PS_ERR_IO, true, "CELL.GAIN is not set --- unable to set variance.\n");
     230        // return false;
     231        psWarning("CELL.GAIN is not set --- setting variance to NAN\n");
     232        gain = NAN;
    213233    }
    214234    float readnoise = psMetadataLookupF32(&mdok, cell->concepts, "CELL.READNOISE"); // Cell read noise
    215235    if (!mdok || isnan(readnoise)) {
    216         psError(PS_ERR_IO, true, "CELL.READNOISE is not set --- unable to set variance.\n");
    217         return false;
    218     }
    219     if (psMetadataLookup(cell->concepts, "CELL.READNOISE.UPDATE")) {
     236        // psError(PS_ERR_IO, true, "CELL.READNOISE is not set --- unable to set variance.\n");
     237        // return false;
     238        psWarning("CELL.READNOISE is not set --- setting variance to NAN\n");
     239        readnoise = NAN;
     240    }
     241    // if we have a non-NAN readnoise, then we need to ensure it has been updated (not necessary if NAN)
     242    if (!isnan(gain) && psMetadataLookup(cell->concepts, "CELL.READNOISE.UPDATE")) {
    220243        psError(PS_ERR_IO, true, "CELL.READNOISE has not yet been updated for the gain");
    221244        return false;
     245    }
     246
     247    // for invalid input data, set the readout variance to NAN
     248    if (isnan(gain) || isnan(readnoise)) {
     249        if (!readout->variance) {
     250            // generate the image if needed
     251            readout->variance = psImageAlloc(readout->image->numCols, readout->image->numRows, PS_TYPE_F32);
     252        }
     253        // XXX need to set the mask, if defined
     254        psImageInit(readout->variance, NAN);
     255        return true;
    222256    }
    223257
     
    228262
    229263        // a negative variance is non-sensical. if the image value drops below 1, the variance must be 1.
     264        // XXX this calculation is wrong: limit is 1 e-, but this is in DN
    230265        readout->variance = (psImage*)psUnaryOp(readout->variance, readout->variance, "abs");
    231266        readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "max",
     
    239274    }
    240275
    241     readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+",
    242                                            psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
     276    // apply a supplied readnoise map (NOTE: in DN, not electrons):
     277    if (noiseMap) {
     278        psImage *rdVar = (psImage*)psBinaryOp(NULL, (const psPtr) noiseMap, "*", (const psPtr) noiseMap);
     279        readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+", rdVar);
     280        psFree (rdVar);
     281    } else {
     282        readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+", psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
     283    }
    243284
    244285    return true;
     
    247288// this function creates the variance pixels, or uses the existing variance pixels.  it will set
    248289// the noise pixel values only if the variance image is not supplied
    249 bool pmReadoutGenerateVariance(pmReadout *readout, bool poisson)
     290bool pmReadoutGenerateVariance(pmReadout *readout, const psImage *noiseMap, bool poisson)
    250291{
    251292    PS_ASSERT_PTR_NON_NULL(readout, false);
     
    291332    readout->variance = variance;
    292333
    293     return pmReadoutSetVariance(readout, poisson);
    294 }
    295 
    296 bool pmReadoutGenerateMaskVariance(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask, bool poisson)
     334    return pmReadoutSetVariance(readout, noiseMap, poisson);
     335}
     336
     337bool pmReadoutGenerateMaskVariance(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask, const psImage *noiseMap, bool poisson)
    297338{
    298339    PS_ASSERT_PTR_NON_NULL(readout, false);
     
    301342
    302343    success &= pmReadoutGenerateMask(readout, satMask, badMask);
    303     success &= pmReadoutGenerateVariance(readout, poisson);
     344    success &= pmReadoutGenerateVariance(readout, noiseMap, poisson);
    304345
    305346    return success;
    306347}
    307348
    308 bool pmCellGenerateMaskVariance(pmCell *cell, psImageMaskType satMask, psImageMaskType badMask, bool poisson)
     349bool pmCellGenerateMaskVariance(pmCell *cell, psImageMaskType satMask, psImageMaskType badMask, const psImage *noiseMap, bool poisson)
    309350{
    310351    PS_ASSERT_PTR_NON_NULL(cell, false);
     
    314355    for (int i = 0; i < readouts->n; i++) {
    315356        pmReadout *readout = readouts->data[i]; // The readout
    316         success &= pmReadoutGenerateMaskVariance(readout, poisson, satMask, badMask);
     357        success &= pmReadoutGenerateMaskVariance(readout, satMask, badMask, noiseMap, poisson);
    317358    }
    318359
     
    482523        return false;
    483524    }
    484     float stdev = psStatsGetValue(stdevStats, stdevStat); // Stadard deviation of fluxes
     525    float stdev = psStatsGetValue(stdevStats, stdevStat); // Standard deviation of fluxes
    485526    psFree(stdevStats);
    486527    psFree(noise);
Note: See TracChangeset for help on using the changeset viewer.