IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6896


Ignore:
Timestamp:
Apr 18, 2006, 5:24:09 PM (20 years ago)
Author:
Paul Price
Message:

Adding pmReadoutWriteNext, which is to be used in concert with pmReadoutReadNext. Updated pmFPAWrite, pmChipWrite, pmCellWrite to optionally not write the pixels (i.e., PHU only), so that an output file should always have a PHU. This necessitated some small changes to the way the 'concepts' are written, in the case that they don't exist.

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

Legend:

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

    r6888 r6896  
    129129                             )
    130130{
     131    if (!hdu->header) {
     132        return false;
     133    }
    131134    switch (item->type) {
    132135    case PS_DATA_STRING:
     
    166169    if (item->type == PS_DATA_LIST) {
    167170        psList *values = item->data.V;  // List of outputs
     171        if (values->n == 0) {
     172            // Nothing to write
     173            return false;
     174        }
    168175        psList *keys = psStringSplit(keywords, " ,;"); // List of keywords
    169176        if (keys->n != values->n) {
  • trunk/psModules/src/astrom/pmFPA.c

    r6872 r6896  
    1212* XXX: Should we implement non-linear cell->chip transforms?
    1313*
    14 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2006-04-17 18:01:04 $
     14*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2006-04-19 03:24:09 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    231231    pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout));
    232232    tmpReadout->row0 = 0;
     233    tmpReadout->col0 = 0;
    233234
    234235    tmpReadout->image = NULL;
  • trunk/psModules/src/astrom/pmFPA.h

    r6872 r6896  
    77*  @author GLG, MHPCC
    88*
    9 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-04-17 18:01:04 $
     9*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-04-19 03:24:09 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    129129typedef struct
    130130{
    131     int row0;                           ///< Row offset; non-zero if reading in bit by bit
     131    int col0;                           ///< Column offset; non-zero if reading in columns bit by bit
     132    int row0;                           ///< Row offset; non-zero if reading in rows bit by bit
    132133    psImage *image;                     ///< Imaging area of readout
    133134    psImage *mask;                      ///< Mask of input image
  • trunk/psModules/src/astrom/pmFPARead.c

    r6894 r6896  
    3434        return NULL;
    3535    }
    36     psRegion region = psRegionSet(trimsec->x0, trimsec->x1, MAX(trimsec->y0 - readout->row0, 0),
    37                                   MIN(trimsec->y1 - readout->row0, image->numRows));
     36    psRegion region = psRegionSet(MAX(trimsec->x0 - readout->col0, 0), // x0
     37                                  MIN(trimsec->x1 - readout->col0, image->numCols), // x1
     38                                  MAX(trimsec->y0 - readout->row0, 0), // y0
     39                                  MIN(trimsec->y1 - readout->row0, image->numRows) // y1
     40                                 );
    3841    if (readout->image) {
    3942        psFree(readout->image);         // Make way!
     
    5760            return NULL;
    5861        }
    59         psRegion region = psRegionSet(biassec->x0, biassec->x1, MAX(biassec->y0 - readout->row0, 0),
    60                                       MIN(biassec->y1 - readout->row0, image->numRows));
     62        psRegion region = psRegionSet(MAX(biassec->x0 - readout->col0, 0), // x0
     63                                      MIN(biassec->x1 - readout->col0, image->numCols), // x1
     64                                      MAX(biassec->y0 - readout->row0, 0), // y0
     65                                      MIN(biassec->y1 - readout->row0, image->numRows) // y1
     66                                     );
    6167        psImage *overscan = psMemIncrRefCounter(psImageSubset(image, region));
    6268        psListAdd(readout->bias, PS_LIST_TAIL, overscan);
     
    7682                       psFits *fits,    // FITS file from which to read
    7783                       int z,           // Readout number/plane; zero-offset indexing
    78                        int numRows      // The number of rows to read
     84                       int numScans     // The number of scans to read
    7985                      )
    8086{
     
    96102    // Get the trim and bias sections
    97103    bool mdok = true;                   // Status of MD lookup
    98     psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC");
     104    psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim sections
    99105    if (!mdok || !trimsec || psRegionIsBad(*trimsec)) {
    100106        psError(PS_ERR_IO, true, "CELL.TRIMSEC is not set.\n");
    101107        return false;
    102108    }
    103     psList *biassecs = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.BIASSEC");
     109    psList *biassecs = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.BIASSEC"); // Bias sections
    104110    if (!mdok || !biassecs) {
    105111        psError(PS_ERR_IO, true, "CELL.BIASSEC is not set.\n");
     112        return false;
     113    }
     114    int readdir = psMetadataLookupS32(&mdok, cell->concepts, "CELL.READDIR"); // Read direction
     115    if (!mdok || readdir == 0 || (readdir != -1 && readdir != 1)) {
     116        psError(PS_ERR_IO, true, "CELL.READDIR is not set to -1 or +1.\n");
    106117        return false;
    107118    }
     
    150161    int offset = readout->row0;         // The row number to read
    151162    if (readout->image) {
    152         offset += readout->image->numRows;
    153     }
    154     if (offset >= naxis2) {
     163        if (readdir > 0) {
     164            // Reading rows
     165            offset += readout->image->numRows;
     166        } else {
     167            // Reading columns
     168            offset += readout->image->numCols;
     169        }
     170    }
     171    if ((readdir > 0 && offset >= naxis2) || (readdir < 0 && offset > naxis1)) {
    155172        // We've read everything there is
    156173        return false;
    157174    }
    158     int upper = offset + numRows;       // The upper limit for the pixel read
    159     if (upper > naxis2) {
     175    int upper = offset + numScans;      // The upper limit for the pixel read
     176    if (readdir > 0 && upper > naxis2) {
    160177        upper = naxis2;
    161     }
    162     psRegion region = psRegionSet(0, naxis1, offset, upper); // Region to be read
     178    } else if (readdir < 0 && upper > naxis1) {
     179        upper = naxis1;
     180    }
     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    }
    163187    psImage *image = psFitsReadImage(fits, region, z); // The image
    164188
     
    177201    hdu->images->data[z] = image;
    178202    readout->row0 = region.y0;
     203    readout->col0 = region.x0;
    179204    readoutCarve(readout, image, trimsec, biassecs);
    180205
  • trunk/psModules/src/astrom/pmFPAWrite.c

    r6872 r6896  
    55#include "pmFPA.h"
    66#include "pmHDU.h"
     7#include "pmHDUUtils.h"
    78#include "pmConcepts.h"
     9
     10
     11bool pmReadoutWriteNext(pmReadout *readout, // Readout to write
     12                        psFits *fits,   // FITS file to which to write
     13                        int z           // Image plane to write
     14                       )
     15{
     16    pmHDU *hdu = pmHDUFromReadout(readout); // The HDU to which to write
     17    psMetadata *header = hdu->header;   // The FITS header
     18    if (!header) {
     19        psError(PS_ERR_IO, true, "No FITS header available in the HDU.\n");
     20        return false;
     21    }
     22
     23    // We have to rely to a great extent on the FITS header, because otherwise we simply don't know how many
     24    // image planes there are (NAXIS3) or the size of the original image (NAXIS1, NAXIS2).
     25    bool mdok = true;                   // Status of MD lookup
     26    int naxis1 = psMetadataLookupS32(&mdok, header, "NAXIS1"); // Number of columns
     27    if (!mdok || naxis1 <= 0) {
     28        psError(PS_ERR_IO, true, "Can't find NAXIS1 in header.\n");
     29        return false;
     30    }
     31    int naxis2 = psMetadataLookupS32(&mdok, header, "NAXIS2"); // Number of rows
     32    if (!mdok || naxis2 <= 0) {
     33        psError(PS_ERR_IO, true, "Can't find NAXIS2 in header.\n");
     34        return false;
     35    }
     36    int naxis3 = psMetadataLookupS32(&mdok, header, "NAXIS3"); // Number of image planes
     37    if (!mdok || naxis3 <= 0) {
     38        naxis3 = 1;
     39    }
     40    if (z >= naxis3) {
     41        psError(PS_ERR_IO, true, "Specified a plane number (%d) greater than NAXIS3 allows.\n", z);
     42        return false;
     43    }
     44
     45    psImage *image = hdu->images->data[z]; // The image from the HDU to write
     46    if (readout->row0 == 0 && readout->col0 == 0 && z == 0) {
     47        // Then we can assume that nothing has been written to the FITS file for now
     48        if (naxis1 == image->numCols && naxis2 == image->numRows) {
     49            // We can write the whole lot at once
     50            return psFitsWriteImage(fits, header, image, z, hdu->extname);
     51        }
     52        // Create a dummy image so we can write something larger than we actually have
     53        psImage *dummy = psImageAlloc(naxis1, naxis2, image->type.type); // Dummy image
     54        psImageInit(dummy, 0);
     55        psImageOverlaySection(dummy, image, 0, 0, "=");
     56        bool result = psFitsWriteImage(fits, header, dummy, z, hdu->extname);
     57        psFree(dummy);
     58        return result;
     59    }
     60
     61    // We can simply update an existing HDU
     62    if (!psFitsMoveExtName(fits, hdu->extname)) {
     63        psError(PS_ERR_IO, false, "Unable to move to extension %s\n", hdu->extname);
     64        return false;
     65    }
     66    return psFitsUpdateImage(fits, image, readout->col0, readout->row0, z);
     67}
     68
     69
    870
    971
    1072bool pmCellWrite(pmCell *cell,          // Cell to write
    1173                 psFits *fits,          // FITS file to which to write
    12                  psDB *db               // Database handle for "concepts" update
     74                 psDB *db,              // Database handle for "concepts" update
     75                 bool pixels            // Write the pixels?
    1376                )
    1477{
     
    1780
    1881    pmHDU *hdu = cell->hdu;             // The HDU
    19     if (hdu && !pmHDUWrite(hdu, fits)) {
     82    if (hdu && ((!pixels && hdu->phu) || pixels) && !pmHDUWrite(hdu, fits)) {
    2083        psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n");
    2184        return false;
     
    2891bool pmChipWrite(pmChip *chip,          // Chip to write
    2992                 psFits *fits,          // FITS file to which to write
    30                  psDB *db               // Database handle for "concepts" update
     93                 psDB *db,              // Database handle for "concepts" update
     94                 bool pixels            // Write the pixels?
    3195                )
    3296{
     
    3599
    36100    pmHDU *hdu = chip->hdu;             // The HDU
    37     if (hdu && !pmHDUWrite(hdu, fits)) {
     101    if (hdu && ((!pixels && hdu->phu) || pixels) && !pmHDUWrite(hdu, fits)) {
    38102        psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n");
    39103        return false;
     
    41105
    42106    bool success = true;                // Success of writing
    43     psArray *cells = chip->cells;       // Array of cells
    44     for (int i = 0; i < cells->n; i++) {
    45         pmCell *cell = cells->data[i];  // The cell of interest
    46         success |= pmCellWrite(cell, fits, db);
     107    if (pixels) {
     108        psArray *cells = chip->cells;       // Array of cells
     109        for (int i = 0; i < cells->n; i++) {
     110            pmCell *cell = cells->data[i];  // The cell of interest
     111            success |= pmCellWrite(cell, fits, db, true);
     112        }
    47113    }
    48114
     
    55121bool pmFPAWrite(pmFPA *fpa,             // FPA to write
    56122                psFits *fits,           // FITS file to which to write
    57                 psDB *db                // Database handle for "concepts" update
     123                psDB *db,               // Database handle for "concepts" update
     124                bool pixels             // Write the pixels?
    58125               )
    59126{
     
    62129
    63130    pmHDU *hdu = fpa->hdu;              // The HDU
    64     if (hdu && !pmHDUWrite(hdu, fits)) {
     131    if (hdu && ((!pixels && hdu->phu) || pixels) && !pmHDUWrite(hdu, fits)) {
    65132        psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n");
    66133        return false;
     
    68135
    69136    bool success = true;                // Success of writing
    70     psArray *chips = fpa->chips;        // Array of chips
    71     for (int i = 0; i < chips->n; i++) {
    72         pmChip *chip = chips->data[i];  // The chip of interest
    73         success |= pmChipWrite(chip, fits, db);
     137    if (pixels) {
     138        psArray *chips = fpa->chips;        // Array of chips
     139        for (int i = 0; i < chips->n; i++) {
     140            pmChip *chip = chips->data[i];  // The chip of interest
     141            success |= pmChipWrite(chip, fits, db, true);
     142        }
    74143    }
    75144
  • trunk/psModules/src/astrom/pmFPAWrite.h

    r6872 r6896  
    55#include "pmFPA.h"
    66
     7bool pmReadoutWriteNext(pmReadout *readout, // Readout to write
     8                        psFits *fits,   // FITS file to which to write
     9                        int z           // Image plane to write
     10                       );
    711
    812bool pmCellWrite(pmCell *cell,          // Cell to write
    913                 psFits *fits,          // FITS file to which to write
    10                  psDB *db               // Database handle for "concepts" update
     14                 psDB *db,              // Database handle for "concepts" update
     15                 bool pixels            // Write the pixels?
    1116                );
    1217bool pmChipWrite(pmChip *chip,          // Chip to write
    1318                 psFits *fits,          // FITS file to which to write
    14                  psDB *db               // Database handle for "concepts" update
     19                 psDB *db,              // Database handle for "concepts" update
     20                 bool pixels            // Write the pixels?
    1521                );
    1622bool pmFPAWrite(pmFPA *fpa,             // FPA to write
    1723                psFits *fits,           // FITS file to which to write
    18                 psDB *db                // Database handle for "concepts" update
     24                psDB *db,               // Database handle for "concepts" update
     25                bool pixels             // Write the pixels?
    1926               );
    2027
  • trunk/psModules/src/astrom/pmFPAfile.c

    r6872 r6896  
    634634    // pmFPAWrite takes care of all PHUs as needed
    635635    if (view->chip == -1) {
    636         pmFPAWrite (fpa, fits, NULL);
     636        pmFPAWrite (fpa, fits, NULL, true);
    637637        return true;
    638638    }
     
    660660
    661661    if (view->cell == -1) {
    662         pmChipWrite (chip, fits, NULL);
     662        pmChipWrite (chip, fits, NULL, true);
    663663        return true;
    664664    }
     
    670670
    671671    if (view->readout == -1) {
    672         pmCellWrite (cell, fits, NULL);
     672        pmCellWrite (cell, fits, NULL, true);
    673673        return true;
    674674    }
Note: See TracChangeset for help on using the changeset viewer.