IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6894


Ignore:
Timestamp:
Apr 18, 2006, 2:54:19 PM (20 years ago)
Author:
Paul Price
Message:

Doing bias for pmReadoutReadNext

Location:
trunk/psModules/src/astrom
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/astrom/pmFPAConstruct.c

    r6888 r6894  
    755755            for (int k = 0; k < readouts->n; k++) {
    756756                pmReadout *readout = readouts->data[k]; // The readout
     757                psTrace(__func__, 8, "row0: %d\n", readout->row0);
    757758                psImage *image = readout->image; // The image
    758759                psList *bias = readout->bias; // The list of bias images
  • trunk/psModules/src/astrom/pmFPARead.c

    r6889 r6894  
    1212#include "pmHDUUtils.h"
    1313
     14#define MAX(x,y) ((x) > (y) ? (x) : (y))
     15#define MIN(x,y) ((x) < (y) ? (x) : (y))
     16
    1417//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1518// File-static functions
     
    1720
    1821// Carve a readout from the image pixels
    19 static pmReadout *readoutCarve(pmCell *cell, // Cell into which the new readout will be placed
    20                                psImage *image, // Image that will be carved
    21                                const psRegion *trimsec, // Trim section
    22                                const psList *biassecs // Bias sections
    23                               )
    24 {
    25     pmReadout *readout = pmReadoutAlloc(cell);
    26 
     22static bool readoutCarve(pmReadout *readout, // Readout to be carved up
     23                         psImage *image, // Image that will be carved
     24                         const psRegion *trimsec, // Trim section
     25                         const psList *biassecs // Bias sections
     26                        )
     27{
    2728    // The image corresponding to the trim region
    2829    if (psRegionIsBad(*trimsec)) {
     
    3334        return NULL;
    3435    }
    35     readout->image = psMemIncrRefCounter(psImageSubset(image, *trimsec));
     36    psRegion region = psRegionSet(trimsec->x0, trimsec->x1, MAX(trimsec->y0 - readout->row0, 0),
     37                                  MIN(trimsec->y1 - readout->row0, image->numRows));
     38    if (readout->image) {
     39        psFree(readout->image);         // Make way!
     40    }
     41    readout->image = psMemIncrRefCounter(psImageSubset(image, region));
    3642
    3743    // Get the list of overscans
     44    if (readout->bias->n != 0) {
     45        // Make way!
     46        psFree(readout->bias);
     47        readout->bias = psListAlloc(NULL);
     48    }
    3849    psListIterator *iter = psListIteratorAlloc((psList*)biassecs, PS_LIST_HEAD, false); // Iterator
    3950    psRegion *biassec = NULL;       // A BIASSEC region from the list
     
    4657            return NULL;
    4758        }
    48         psImage *overscan = psMemIncrRefCounter(psImageSubset(image, *biassec));
     59        psRegion region = psRegionSet(biassec->x0, biassec->x1, MAX(biassec->y0 - readout->row0, 0),
     60                                      MIN(biassec->y1 - readout->row0, image->numRows));
     61        psImage *overscan = psMemIncrRefCounter(psImageSubset(image, region));
    4962        psListAdd(readout->bias, PS_LIST_TAIL, overscan);
    5063        psFree(overscan);
     
    7386    }
    7487
    75     if (!pmHDUReadHeader(hdu, fits)) {
    76         psError(PS_ERR_IO, false, "Unable to read HDU header!\n");
     88    if (!hdu->header) {
     89        if (!pmHDUReadHeader(hdu, fits)) {
     90            psError(PS_ERR_IO, false, "Unable to read HDU header!\n");
     91            return false;
     92        }
     93        pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, false, NULL);
     94    }
     95
     96    // Get the trim and bias sections
     97    bool mdok = true;                   // Status of MD lookup
     98    psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC");
     99    if (!mdok || !trimsec || psRegionIsBad(*trimsec)) {
     100        psError(PS_ERR_IO, true, "CELL.TRIMSEC is not set.\n");
     101        return false;
     102    }
     103    psList *biassecs = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.BIASSEC");
     104    if (!mdok || !biassecs) {
     105        psError(PS_ERR_IO, true, "CELL.BIASSEC is not set.\n");
    77106        return false;
    78107    }
    79108
    80109    // Check the third dimension
    81     bool mdok = true;                   // Status of MD lookup
    82110    int naxis = psMetadataLookupS32(&mdok, hdu->header, "NAXIS"); // The number of axes
    83111    if (!mdok) {
     
    134162    psRegion region = psRegionSet(0, naxis1, offset, upper); // Region to be read
    135163    psImage *image = psFitsReadImage(fits, region, z); // The image
    136     if (readout->image) {
    137         psFree(readout->image);
    138     }
    139164
    140165    // Stick the image into the HDU and the readout
     
    151176    }
    152177    hdu->images->data[z] = image;
    153     readout->image = psImageSubset(hdu->images->data[z], psRegionSet(0,0,0,0));
    154178    readout->row0 = region.y0;
     179    readoutCarve(readout, image, trimsec, biassecs);
    155180
    156181    return true;
     
    191216        }
    192217
    193         pmReadout *readout = readoutCarve(cell, image, trimsec, biassecs);
     218        pmReadout *readout = pmReadoutAlloc(cell);
     219        readoutCarve(readout, image, trimsec, biassecs);
    194220        readout->mask = NULL;
    195221        readout->weight = NULL;
Note: See TracChangeset for help on using the changeset viewer.