IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 25, 2009, 2:00:56 PM (17 years ago)
Author:
eugene
Message:

merging changes from head

Location:
branches/eam_branches/20090522
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090522

  • branches/eam_branches/20090522/psModules

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090522/psModules/src/camera/pmFPABin.c

    r24003 r24557  
    6565            }
    6666
    67             float imageValue, maskValue;// Values to set
     67            // Values to set
     68            float imageValue;
     69            psImageMaskType maskValue;
    6870            if (numPix > 0) {
    6971                imageValue = sum / numPix;
  • branches/eam_branches/20090522/psModules/src/camera/pmFPACopy.c

    r23761 r24557  
    7070    psImageBinningSetRuffSize(binning, PS_IMAGE_BINNING_CENTER);
    7171    *target = psImageAlloc(binning->nXruff, binning->nYruff, source->type.type);
     72    psImageInit (*target, 0.0);
    7273    return;
    7374}
     
    221222    psTrace("psModules.camera", 3, "xFlip: %d; yFlip: %d\n", xFlip, yFlip);
    222223
     224    // Blow away extant readouts
     225    for (int i = 0; i < target->readouts->n; i++) {
     226        psFree(target->readouts->data[i]);
     227        target->readouts->data[i] = NULL;
     228    }
     229    target->readouts->n = 0;
     230
    223231    // Perform deep copy of the images.  I would prefer *not* to do a deep copy, in the interests of speed (we
    224232    // still need to do another deep copy into the HDU for when we write out), but this is the only way I can
     
    242250        readoutCopyComponent(&targetReadout->variance, sourceReadout->variance, binning, xFlip, yFlip,
    243251                             pixels);
     252        // Copy covariance matrix: doesn't care about flips, etc.
     253        if (sourceReadout->covariance) {
     254            if (targetReadout->covariance) {
     255                psFree(targetReadout->covariance);
     256            }
     257            targetReadout->covariance = psKernelCopy(sourceReadout->covariance);
     258#if 0
     259            if (binning) {
     260                // XXX This isn't strictly correct, but we don't have a function that bins covariance matrices
     261                // with unequal binning factors.
     262                psKernel *covar = psImageCovarianceBin(PS_MAX(binning->nXbin, binning->nYbin),
     263                                                       targetReadout->covariance);
     264                psFree(targetReadout->covariance);
     265                targetReadout->covariance = covar;
     266            }
     267#endif
     268        }
    244269
    245270        // Copy bias
  • branches/eam_branches/20090522/psModules/src/camera/pmFPAMaskWeight.c

    r23989 r24557  
    199199}
    200200
    201 bool pmReadoutSetVariance(pmReadout *readout, bool poisson)
     201bool pmReadoutSetVariance(pmReadout *readout, const psImage *noiseMap, bool poisson)
    202202{
    203203    PS_ASSERT_PTR_NON_NULL(readout, false);
     204    // check that the noiseMap (if it exists) matches the readout variance size)
    204205
    205206    pmCell *cell = readout->parent;     // The parent cell
     
    228229
    229230        // a negative variance is non-sensical. if the image value drops below 1, the variance must be 1.
     231        // XXX this calculation is wrong: limit is 1 e-, but this is in DN
    230232        readout->variance = (psImage*)psUnaryOp(readout->variance, readout->variance, "abs");
    231233        readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "max",
     
    239241    }
    240242
    241     readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+",
    242                                            psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
     243    // apply a supplied readnoise map (NOTE: in DN, not electrons):
     244    if (noiseMap) {
     245        psImage *rdVar = (psImage*)psBinaryOp(NULL, (const psPtr) noiseMap, "*", (const psPtr) noiseMap);
     246        readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+", rdVar);
     247        psFree (rdVar);
     248    } else {
     249        readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+", psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
     250    }
    243251
    244252    return true;
     
    247255// this function creates the variance pixels, or uses the existing variance pixels.  it will set
    248256// the noise pixel values only if the variance image is not supplied
    249 bool pmReadoutGenerateVariance(pmReadout *readout, bool poisson)
     257bool pmReadoutGenerateVariance(pmReadout *readout, const psImage *noiseMap, bool poisson)
    250258{
    251259    PS_ASSERT_PTR_NON_NULL(readout, false);
     
    291299    readout->variance = variance;
    292300
    293     return pmReadoutSetVariance(readout, poisson);
    294 }
    295 
    296 bool pmReadoutGenerateMaskVariance(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask, bool poisson)
     301    return pmReadoutSetVariance(readout, noiseMap, poisson);
     302}
     303
     304bool pmReadoutGenerateMaskVariance(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask, const psImage *noiseMap, bool poisson)
    297305{
    298306    PS_ASSERT_PTR_NON_NULL(readout, false);
     
    301309
    302310    success &= pmReadoutGenerateMask(readout, satMask, badMask);
    303     success &= pmReadoutGenerateVariance(readout, poisson);
     311    success &= pmReadoutGenerateVariance(readout, noiseMap, poisson);
    304312
    305313    return success;
    306314}
    307315
    308 bool pmCellGenerateMaskVariance(pmCell *cell, psImageMaskType satMask, psImageMaskType badMask, bool poisson)
     316bool pmCellGenerateMaskVariance(pmCell *cell, psImageMaskType satMask, psImageMaskType badMask, const psImage *noiseMap, bool poisson)
    309317{
    310318    PS_ASSERT_PTR_NON_NULL(cell, false);
     
    314322    for (int i = 0; i < readouts->n; i++) {
    315323        pmReadout *readout = readouts->data[i]; // The readout
    316         success &= pmReadoutGenerateMaskVariance(readout, poisson, satMask, badMask);
     324        success &= pmReadoutGenerateMaskVariance(readout, satMask, badMask, noiseMap, poisson);
    317325    }
    318326
  • branches/eam_branches/20090522/psModules/src/camera/pmFPAMaskWeight.h

    r21363 r24557  
    5454/// can't be generated.
    5555bool pmReadoutSetVariance(pmReadout *readout, ///< Readout for which to set variance
     56                          const psImage *noiseMap, ///< 2D image of the read noise in DN
    5657                          bool poisson    ///< Include poisson variance (in addition to read noise)?
    5758    );
     
    7273/// with HDU entry).  This is intended for most operations.
    7374bool pmReadoutGenerateVariance(pmReadout *readout, ///< Readout for which to generate variance
     75                          const psImage *noiseMap, ///< 2D image of the read noise in DN
    7476                               bool poisson    ///< Include poisson variance (in addition to read noise)?
    7577    );
     
    8183                                   psImageMaskType sat, ///< Mask value to give saturated pixels
    8284                                   psImageMaskType bad, ///< Mask value to give bad (low) pixels
     85                                   const psImage *noiseMap, ///< 2D image of the read noise in DN
    8386                                   bool poisson ///< Include poisson variance (in addition to read noise)?
    8487    );
     
    9093                                psImageMaskType sat, ///< Mask value to give saturated pixels
    9194                                psImageMaskType bad, ///< Mask value to give bad (low) pixels
     95                                const psImage *noiseMap, ///< 2D image of the read noise in DN
    9296                                bool poisson ///< Include poisson variance (in addition to read noise)?
    9397    );
  • branches/eam_branches/20090522/psModules/src/camera/pmHDU.c

    r21363 r24557  
    9393    }
    9494
     95    psTrace("psModules.camera", 5, "Reading the header...\n");
     96
     97    // The header may already exist (e.g., from doing concept writing at the PHU level) so we need to be
     98    // careful.  We read into a separate container and copy that over the top of anything that's already read.
     99    psMetadata *header = psFitsReadHeader(NULL, fits);
     100    if (!header) {
     101        psError(PS_ERR_IO, false, "Unable to read header for extension %s\n", hdu->extname);
     102        return false;
     103    }
     104
    95105    if (!hdu->header) {
    96         psTrace("psModules.camera", 5, "Reading the header...\n");
    97         hdu->header = psFitsReadHeader(hdu->header, fits);
    98         if (! hdu->header) {
    99             psError(PS_ERR_IO, false, "Unable to read header for extension %s\n", hdu->extname);
    100             return false;
    101         }
    102     }
     106        hdu->header = header;
     107        return true;
     108    }
     109
     110    psMetadataIterator *iter = psMetadataIteratorAlloc(header, PS_LIST_HEAD, NULL); // Iterator
     111    psMetadataItem *item;           // Item from iteration
     112    while ((item = psMetadataGetAndIncrement(iter))) {
     113        const char *name = item->name; // Name of item
     114        if (psMetadataLookup(hdu->header, name)) {
     115            // It exists; clobber
     116            psMetadataRemoveKey(hdu->header, name);
     117        }
     118        psMetadataAddItem(hdu->header, item, PS_LIST_TAIL, 0);
     119    }
     120    psFree(iter);
     121    psFree(header);
    103122
    104123    return true;
Note: See TracChangeset for help on using the changeset viewer.