IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 27, 2006, 4:16:26 PM (20 years ago)
Author:
magnier
Message:

added HDU weights, masks; substantial work on the pmFPAfile,view concepts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/pmReadout.c

    r6448 r6713  
    11#include <stdio.h>
    22#include "pslib.h"
    3 
    43#include "pmFPA.h"
     4#include "pmHDUUtils.h"
     5#include "pmFPAMaskWeight.h"
    56
    67// Get the bias images for a readout, using the CELL.BIASSEC
     
    2526    return images;
    2627}
     28
     29bool pmReadoutSetWeights(pmReadout *readout)
     30{
     31
     32    pmCell *cell = readout->parent;
     33
     34    float gain = psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN"); // Cell gain
     35    float readnoise = psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE"); // Cell read noise
     36    psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); // Trim section
     37    float saturation = psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION"); // Saturation level
     38    float bad = psMetadataLookupF32(NULL, cell->concepts, "CELL.BAD"); // Bad level
     39
     40    pmHDU *hdu = pmHDUFromCell (cell);
     41
     42    psArray *pixels = hdu->images;      // Array of images
     43    psArray *weights = hdu->weights;    // Array of weight images
     44    psArray *masks = hdu->masks;        // Array of mask images
     45    // Generate the weights and masks if required
     46    if (! weights) {
     47        weights = psArrayAlloc(pixels->n);
     48        for (int i = 0; i < pixels->n; i++) {
     49            psImage *image = pixels->data[i];
     50            weights->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32);
     51            psImageInit(weights->data[i], 0.0);
     52        }
     53        hdu->weights = weights;
     54    }
     55    if (! masks) {
     56        masks = psArrayAlloc(pixels->n);
     57        for (int i = 0; i < pixels->n; i++) {
     58            psImage *image = pixels->data[i];
     59            masks->data[i] = psImageAlloc(image->numCols, image->numRows, PS_TYPE_U8);
     60            psImageInit(masks->data[i], 0);
     61        }
     62        hdu->masks = masks;
     63    }
     64
     65    // Set the pixels
     66    psArray *readouts = cell->readouts; // Array of readouts
     67    for (int i = 0; i < readouts->n; i++) {
     68        pmReadout *readout = readouts->data[i]; // The readout of interest
     69
     70        if (! readout->weight) {
     71            readout->weight = psMemIncrRefCounter(psImageSubset(weights->data[i], *trimsec));
     72        }
     73        if (! readout->mask) {
     74            readout->mask = psMemIncrRefCounter(psImageSubset(masks->data[i], *trimsec));
     75        }
     76
     77        // Set up the mask
     78        psImage *image = readout->image;// Pixels
     79        psImage *mask = readout->mask;  // Mask image
     80        for (int i = 0; i < image->numRows; i++) {
     81            for (int j = 0; j < image->numCols; j++) {
     82                if (image->data.F32[i][j] >= saturation) {
     83                    mask->data.U8[i][j] = PM_MASK_SAT;
     84                }
     85                if (image->data.F32[i][j] <= bad) {
     86                    mask->data.U8[i][j] = PM_MASK_BAD;
     87                }
     88            }
     89        }
     90
     91        psImage *weight = readout->weight;  // Mask image
     92        float rnoise = PS_SQR(readnoise/gain);
     93        for (int i = 0; i < image->numRows; i++) {
     94            for (int j = 0; j < image->numCols; j++) {
     95                if (!mask->data.U8[i][j]) {
     96                    weight->data.F32[i][j] = image->data.F32[i][j]/ gain + rnoise;
     97                }
     98            }
     99        }
     100
     101        // Set weight image to the variance = g*f + rn^2
     102        // psBinaryOp(readout->weight, image, "/", psScalarAlloc(gain, PS_TYPE_F32));
     103        // psBinaryOp(readout->weight, readout->weight, "+",
     104        // psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
     105    }
     106
     107    return true;
     108}
     109
Note: See TracChangeset for help on using the changeset viewer.