IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 18, 2005, 4:19:41 PM (21 years ago)
Author:
Paul Price
Message:

Current state before I go on holiday. Not sure if it works or not. Not current for pslib8.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/phase2/pmFPARead.c

    r5105 r5371  
    1717
    1818// Read a FITS extension into a chip
    19 static bool readExtension(p_pmHDU *hdu, // HDU to read
     19static bool readExtension(pmPixelData *pixelData, // Pixel data into which to read
    2020                          psFits *fits  // The FITS file from which to read
    2121    )
    2222{
    23     const char *extName = hdu->extname; // Extension name
     23    const char *extName = pixelData->extname; // Extension name
    2424
    2525    psTrace(__func__, 7, "Moving to extension %s...\n", extName);
     
    7474        if (image->type.type != PS_TYPE_F32) {
    7575            pixels->data[i] = psImageCopy(NULL, image, PS_TYPE_F32);
     76
     77#ifndef PRODUCTION
     78            // XXX: Temporary fix for writing images, until psFits gets cleaned up
     79            psMetadataItem *bitpixItem = psMetadataLookup(header, "BITPIX");
     80            bitpixItem->data.S32 = -32;
     81            psMetadataRemove(header, 0, "BZERO");
     82            psMetadataRemove(header, 0, "BSCALE");
     83#endif
     84
    7685            psFree(image);
    7786        } else {
     
    8695
    8796    // Update the HDU with the new data
    88     hdu->pixels = pixels;
    89     hdu->header = header;
     97    pixelData->images = pixels;
     98    pixelData->header = header;
     99
     100    // XXX: Insert mask and weight reading here
    90101
    91102    return true;
    92103}
    93104
    94 
    95105// Portion out an image into the cell
    96 static bool portionCell(pmCell *cell,   // The cell that gets its bits
    97                         psArray *images // Array of images from which the readouts are assigned
     106static bool generateReadouts(pmCell *cell, // The cell that gets its bits
     107                             pmPixelData *data // Pixel data, containing image, mask, weights
    98108    )
    99109{
    100     bool mdStatus = false;              // Status of MD lookup
    101 
    102     // Get the trim and bias sections
    103     psMetadataItem *mdItem = psMetadataLookup(cell->concepts, "CELL.TRIMSEC");
    104     psRegion *trimRegion = mdItem->data.V;
    105     mdItem = psMetadataLookup(cell->concepts, "CELL.BIASSEC");
    106     psList *biasRegionList = mdItem->data.V;
    107 
     110    psArray *images = data->images;     // Array of images (each of which is a readout)
     111    psArray *masks = data->masks;       // Array of masks (one for each readout)
    108112    // Iterate over each of the image planes
    109113    for (int i = 0; i < images->n; i++) {
    110114        psImage *image = images->data[i]; // The i-th plane
    111 
    112         // Convert from FITS standard to PS standard
    113         // We don't touch the x1 and y1 values because they aren't included by psImageSubset.
    114         //trimRegion->x0 -= 1;
    115         //trimRegion->y0 -= 1;
    116 
    117         psImage *trimImage = psImageSubset(image, *trimRegion); // Image from trim section
    118 
    119         psList *biasImages = psListAlloc(NULL); // List of images from bias sections
    120         psListIterator *biasRegionIter = psListIteratorAlloc(biasRegionList, PS_LIST_HEAD, true); // Iterator
    121         psRegion *biasRegion = NULL;    // Bias region from list
    122         while (biasRegion = psListGetAndIncrement(biasRegionIter)) {
    123             // Convert from FITS standard to PS standard
    124             // We don't touch the x1 and y1 values because they aren't included by psImageSubset.
    125             //biasRegion->x0 -= 1;
    126             //biasRegion->y0 -= 1;
    127            
    128             psImage *biasImage = psImageSubset(image, *biasRegion); // Image from bias section
    129             psListAdd(biasImages, PS_LIST_TAIL, biasImage);
    130             psFree(biasImage);
    131         }
    132         psFree(biasRegionIter);
    133 
    134         pmReadout *readout = pmReadoutAlloc(cell, trimImage, biasImages, 0,0,0,0,1,1);
     115        psImage *mask = NULL;           // The mask
     116        if (masks) {
     117            mask = masks->data[i];
     118        }
     119
     120        pmReadout *readout = pmReadoutAlloc(cell, image, mask, 0,0,0,0,1,1);
    135121        psFree(readout);                // This seems silly, but the alloc registers it with the cell, so we
    136122                                        // don't have to do anything with it.  Perhaps we should change
    137123                                        // pmReadoutAlloc to pmReadoutAdd?
    138         psFree(trimImage);
    139         psFree(biasImages);
    140     }
    141     psFree(biasRegionList);
     124    }
    142125
    143126    return true;
     
    154137    )
    155138{
    156     p_pmHDU *hdu = NULL;                // Current HDU from FITS file
     139    pmPixelData *pixelData = NULL;      // Pixel data from FITS file
    157140
    158141    // Read the PHU, if required
     
    169152    // Read in....
    170153    psTrace(__func__, 1, "Working on FPA...\n");
    171     if (fpa->private) {
    172         hdu = fpa->private;
    173         psTrace(__func__, 3, "Reading pixels from extension %s into FPA.\n", hdu->extname);
    174         if (! readExtension(hdu, fits)) {
    175             psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);
     154    if (fpa->data) {
     155        pixelData= fpa->data;
     156        psTrace(__func__, 3, "Reading pixels from extension %s into FPA.\n", pixelData->extname);
     157        if (! readExtension(pixelData, fits)) {
     158            psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", pixelData->extname);
    176159            return false;
    177160        }
     
    191174        psTrace(__func__, 2, "Reading in chip %d...\n", i);
    192175
    193         if (chip->private) {
    194             hdu = chip->private;
    195             psTrace(__func__, 3, "Reading pixels from extension %s into chip %d.\n", hdu->extname, i);
    196             if (! readExtension(hdu, fits)) {
    197                 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);
     176        if (chip->data) {
     177            pixelData = chip->data;
     178            psTrace(__func__, 3, "Reading pixels from extension %s into chip %d.\n", pixelData->extname, i);
     179            if (! readExtension(pixelData, fits)) {
     180                psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", pixelData->extname);
    198181                return false;
    199182            }
     
    213196            psTrace(__func__, 3, "Reading in cell %d...\n", j);
    214197
    215             if (cell->private) {
    216                 hdu = cell->private;
    217                 psTrace(__func__, 5, "Reading pixels from extension %s into cell %d.\n", hdu->extname, j);
    218                 if (! readExtension(hdu, fits)) {
    219                     psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);
     198            if (cell->data) {
     199                pixelData = cell->data;
     200                psTrace(__func__, 5, "Reading pixels from extension %s into cell %d.\n", pixelData->extname,
     201                        j);
     202                if (! readExtension(pixelData, fits)) {
     203                    psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n",
     204                            pixelData->extname);
    220205                    return false;
    221206                }
     
    225210            psTrace(__func__, 5, "Allocating readouts for chip %d cell %d...\n",
    226211                    i, j);
    227             portionCell(cell, hdu->pixels);
     212            generateReadouts(cell, pixelData);
    228213        }
    229214    }
Note: See TracChangeset for help on using the changeset viewer.