IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 22, 2006, 2:23:08 PM (20 years ago)
Author:
Paul Price
Message:

Adding pmHDUGenerate to make an HDU (image) from the cells contained below. Altered pmFPACopy to use pmHDUGenerate functions. The motivation for pmHDUGenerate is that when we go through an FPA bit by bit, creating an output FPA, we don't know the size of the resultant output images until we're done with the whole lot. So we simply create the cells, and call pmHDUGenerateFromFPA (etc) to generate the HDU image which is then written out. It takes care of the TRIMSEC, BIASSEC, etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPARead.c

    r7017 r7168  
    55
    66#include "pmFPA.h"
    7 #include "pmFPARead.h"
    87#include "pmHDU.h"
    98#include "pmHDUUtils.h"
     
    1110#include "psRegionIsBad.h"
    1211#include "pmFPAHeader.h"
     12
     13#include "pmFPARead.h"
    1314
    1415#define MAX(x,y) ((x) > (y) ? (x) : (y))
     
    7475}
    7576
     77// Read a component of a readout
     78psImage *readoutReadComponent(psFits *fits, // FITS file from which to read
     79                              const psRegion *region, // Region to read
     80                              int readdir, // Read direction (1=rows, 2=cols)
     81                              int min,  // Minimum row/col number to read
     82                              int max,   // Maximum row/col number to read
     83                              int z,     // Image plane to read
     84                              float bad // Bad value
     85                             )
     86{
     87    bool resize = false;                // Do we need to resize the image once read?
     88    psRegion toRead = psRegionSet(region->x0, region->x1, region->y0, region->y1); // Region to read
     89    psRegion fullSize = toRead;         // Full sized region
     90    if (readdir == 1) {
     91        if (toRead.y0 <= min) {
     92            toRead.y0 = min;
     93        } else {
     94            fullSize.y0 = min;
     95            resize = true;
     96        }
     97        if (toRead.y1 >= max) {
     98            toRead.y1 = max;
     99        } else {
     100            fullSize.y1 = max;
     101            resize = false;
     102        }
     103    } else if (readdir == 2) {
     104        if (toRead.x0 <= min) {
     105            toRead.x0 = min;
     106        } else {
     107            fullSize.x0 = min;
     108            resize = true;
     109        }
     110        if (toRead.x1 >= max) {
     111            toRead.x1 = max;
     112        } else {
     113            fullSize.x1 = max;
     114            resize = false;
     115        }
     116    } else {
     117        psAbort(__func__, "Read direction can only be 1 (rows) or 2 (cols).\n");
     118    }
     119
     120    psImage *image = psFitsReadImage(fits, toRead, z); // Desired pixels
     121
     122    if (resize) {
     123        // For some reason, the region of interest is smaller than the number of pixels we want.
     124        psImage *temp = psImageAlloc(fullSize.x1 - fullSize.x0, fullSize.y1 - fullSize.y0, image->type.type);
     125        psImageInit(temp, bad);
     126        psImageOverlaySection(temp, image, toRead.x0, toRead.y0, "=");
     127        psFree(image);
     128        image = temp;
     129    }
     130
     131    return image;
     132}
     133
    76134//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    77135// Public functions
     
    79137
    80138// Read the next readout; return true if we read pixels in.
     139//
     140// Note that this doesn't put pixels in the HDU.  It is therefore NOT COMPATIBLE with pmCellWrite,
     141// pmChipWrite, and pmFPAWrite.  Use pmReadoutWriteNext to write the data that's read by this function.
    81142bool pmReadoutReadNext(pmReadout *readout, // Readout into which to read
    82143                       psFits *fits,    // FITS file from which to read
     
    98159
    99160    // Make sure we have the information we need
    100     pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, false, NULL);
     161    pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | PM_CONCEPT_SOURCE_DEFAULTS,
     162                       false, NULL);
    101163
    102164    // Get the trim and bias sections
     
    113175    }
    114176    int readdir = psMetadataLookupS32(&mdok, cell->concepts, "CELL.READDIR"); // Read direction
    115     if (!mdok || readdir == 0 || (readdir != -1 && readdir != 1)) {
     177    if (!mdok || readdir == 0 || (readdir != 1 && readdir != 2)) {
    116178        psError(PS_ERR_IO, true, "CELL.READDIR is not set to -1 or +1.\n");
    117179        return false;
     180    }
     181    float bad = psMetadataLookupF32(&mdok, cell->concepts, "CELL.BAD"); // Bad level
     182    if (!mdok) {
     183        psLogMsg(__func__, PS_LOG_WARN, "CELL.BAD is not set --- assuming zero.\n");
     184        bad = 0.0;
    118185    }
    119186
     
    159226
    160227    // Read the FITS image
    161     int offset = readout->row0;         // The row number to read
     228    int offset = 0;                     // The offset from the start of the image to where we are now
    162229    if (readout->image) {
    163         if (readdir > 0) {
     230        if (readdir == 1) {
    164231            // Reading rows
    165             offset += readout->image->numRows;
     232            readout->row0 += readout->image->numRows;
     233            offset = readout->row0;
    166234        } else {
    167235            // Reading columns
    168             offset += readout->image->numCols;
    169         }
    170     }
    171     if ((readdir > 0 && offset >= naxis2) || (readdir < 0 && offset > naxis1)) {
     236            readout->col0 += readout->image->numCols;
     237            offset = readout->col0;
     238        }
     239    }
     240    if ((readdir == 1 && offset >= naxis2) || (readdir == 2 && offset > naxis1)) {
    172241        // We've read everything there is
    173242        return false;
    174243    }
    175244    int upper = offset + numScans;      // The upper limit for the pixel read
    176     if (readdir > 0 && upper > naxis2) {
     245    if (readdir == 1 && upper > naxis2) {
    177246        upper = naxis2;
    178     } else if (readdir < 0 && upper > naxis1) {
     247    } else if (readdir == 2 && upper > naxis1) {
    179248        upper = naxis1;
    180249    }
    181     psRegion region = {0, 0, 0, 0};     // Region to be read
    182     if (readdir > 0) {
    183         region = psRegionSet(0, naxis1, offset, upper); // Read rows
    184     } else {
    185         region = psRegionSet(offset, upper, 0, naxis2); // Read columns
    186     }
    187     psImage *image = psFitsReadImage(fits, region, z); // The image
    188 
    189     // Stick the image into the HDU and the readout
    190     if (!hdu->images) {
    191         hdu->images = psArrayAlloc(naxis3);
    192         hdu->images->n = naxis3;
    193     }
    194     if (hdu->images->nalloc != naxis3) {
    195         hdu->images = psArrayRealloc(hdu->images, naxis3);
    196         hdu->images->n = naxis3;
    197     }
    198     if (hdu->images->data[z]) {
    199         psFree(hdu->images->data[z]);
    200     }
    201     hdu->images->data[z] = image;
    202     readout->row0 = region.y0;
    203     readout->col0 = region.x0;
    204     readoutCarve(readout, image, trimsec, biassecs);
     250
     251    // Blow away existing data
     252    psFree(readout->image);
     253    while (readout->bias->n > 0) {
     254        psListRemove(readout->bias, PS_LIST_HEAD);
     255    }
     256
     257    // Get the new the trim section
     258    readout->image = readoutReadComponent(fits, trimsec, readdir, offset, upper, z, bad); // The image
     259
     260    // Get the new bias sections
     261    psListIterator *biassecsIter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false); // Iterator for BIASSEC
     262    psRegion *biassec = NULL;           // Bias section from iteration
     263    while ((biassec = psListGetAndIncrement(biassecsIter))) {
     264        psImage *bias = readoutReadComponent(fits, biassec, readdir, offset, upper, z, bad); // The bias
     265        psListAdd(readout->bias, PS_LIST_TAIL, bias);
     266    }
     267    psFree(biassecsIter);
    205268
    206269    return true;
Note: See TracChangeset for help on using the changeset viewer.