IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6622


Ignore:
Timestamp:
Mar 16, 2006, 4:25:16 PM (20 years ago)
Author:
Paul Price
Message:

Getting rid of old code.

File:
1 edited

Legend:

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

    r6621 r6622  
    1212// File-static functions
    1313//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    14 
    15 #if 0
    16 // Read a FITS extension into a chip
    17 static bool readExtension(p_pmHDU *hdu, // Pixel data into which to read
    18                           psFits *fits  // The FITS file from which to read
    19                          )
    20 {
    21     const char *extName = hdu->extname; // Extension name
    22 
    23     psTrace(__func__, 7, "Moving to extension %s...\n", extName);
    24     if (strncmp(extName, "PHU", 3) == 0) {
    25         if (!psFitsMoveExtNum(fits, 0, false)) {
    26             psError(PS_ERR_IO, false, "Unable to find PHU in FITS file!\n");
    27             return false;
    28         }
    29     } else if (! psFitsMoveExtName(fits, extName)) {
    30         psError(PS_ERR_IO, false, "Unable to find extension %s in FITS file!\n", extName);
    31         return false;
    32     }
    33     psTrace(__func__, 7, "Reading header....\n");
    34     psMetadata *header = psFitsReadHeader(NULL, fits); // Header
    35     if (! header) {
    36         psError(PS_ERR_IO, false, "Unable to read FITS header!\n");
    37         return false;
    38     }
    39 
    40     psTrace(__func__, 7, "Checking NAXIS....\n");
    41     bool mdStatus = false;
    42     int nAxis = psMetadataLookupS32(&mdStatus, header, "NAXIS");
    43     if (!mdStatus) {
    44         psLogMsg(__func__, PS_LOG_WARN, "There is no NAXIS keyword in the FITS header of extension %s!\n",
    45                  extName);
    46     }
    47     if (nAxis != 2 && nAxis != 3) {
    48         psLogMsg(__func__, PS_LOG_WARN, "Image is not 2- or 3-dimensional --- reading into a single image "
    49                  "anyway.\n");
    50     }
    51     psTrace(__func__, 9, "NAXIS = %d\n", nAxis);
    52 
    53     int numPlanes = 1;                  // Number of planes
    54     if (nAxis == 3) {
    55         numPlanes = psMetadataLookupS32(&mdStatus, header, "NAXIS3");
    56         if (!mdStatus) {
    57             psError(PS_ERR_IO, false, "Unable to read NAXIS3 for 3-dimensional image!\n");
    58             return false;
    59         }
    60     }
    61     psRegion region = {0, 0, 0, 0};     // Region to read is everything
    62 
    63     // Read each plane into the array
    64     psTrace(__func__, 7, "Reading %d planes into array....\n", numPlanes);
    65     psArray *pixels = psArrayAlloc(numPlanes); // Array of images
    66     for (int i = 0; i < numPlanes; i++) {
    67         psTrace(__func__, 9, "Reading plane %d\n", i);
    68         psMemCheckCorruption(true);
    69         psImage *image = psFitsReadImage(NULL, fits, region, i);
    70 
    71         // XXX: Type conversion here to support the modules, which don't have multiple type support yet
    72         if (image->type.type != PS_TYPE_F32) {
    73             pixels->data[i] = psImageCopy(NULL, image, PS_TYPE_F32);
    74 
    75             // XXX: Temporary fix for writing images, until psFits gets cleaned up
    76             psMetadataItem *bitpixItem = psMetadataLookup(header, "BITPIX");
    77             bitpixItem->data.S32 = -32;
    78             psMetadataRemove(header, 0, "BZERO");
    79             psMetadataRemove(header, 0, "BSCALE");
    80 
    81             psFree(image);
    82         } else {
    83             pixels->data[i] = image;
    84         }
    85         psTrace(__func__, 10, "Done\n");
    86         if (! pixels->data[i]) {
    87             psError(PS_ERR_IO, false, "Unable to read image for extension %s, plane %d\n", extName, i);
    88             return false;
    89         }
    90     }
    91 
    92     // Update the HDU with the new data
    93     hdu->images = pixels;
    94     hdu->header = header;
    95 
    96     // Mask and weight not set yet
    97     hdu->weights = NULL;
    98     hdu->masks = NULL;
    99 
    100     return true;
    101 }
    102 
    103 // Portion out an image into the cell
    104 static bool generateReadouts(pmCell *cell, // The cell that gets its bits
    105                              pmHDU *hdu // Pixel data, containing image, mask, weights
    106                             )
    107 {
    108     psArray *images = hdu->images;      // Array of images (each of which is a readout)
    109 
    110     psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC");
    111     psList *biassecs = psMetadataLookupPtr(NULL, cell->concepts, "CELL.BIASSEC");
    112 
    113     // Iterate over each of the image planes
    114     for (int i = 0; i < images->n; i++) {
    115         psImage *image = images->data[i]; // The i-th plane
    116         pmReadout *readout = pmReadoutAlloc(cell);
    117 
    118         readout->image = psMemIncrRefCounter(psImageSubset(image, *trimsec)); // The image corresponding to the trim region
    119 
    120         // Get the list of overscans
    121         psListIterator *iter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false); // Iterator
    122         psRegion *biassec = NULL;       // A BIASSEC region from the list
    123         while ((biassec = psListGetAndIncrement(iter))) {
    124             psImage *overscan = psMemIncrRefCounter(psImageSubset(image, *biassec));
    125             psListAdd(readout->bias, PS_LIST_TAIL, overscan);
    126             psFree(overscan);
    127         }
    128         psFree(iter);
    129 
    130         readout->mask = NULL;
    131         readout->weight = NULL;
    132 
    133         psFree(readout);                // Drop reference
    134     }
    135 
    136     return true;
    137 }
    138 #endif
    13914
    14015// Carve a readout from the image pixels
     
    309184{
    310185    return readPHU(fpa->hdu, fits);
    311 }
    312 #endif
    313 
    314 
    315 
    316 #if 0
    317 
    318 bool pmFPARead(pmFPA *fpa,              // FPA to read into
    319                psFits *fits,            // FITS file from which to read
    320                psMetadata *phu,         // Primary header
    321                psDB *db                 // Database handle, for concept ingest
    322               )
    323 {
    324     p_pmHDU *hdu = NULL;        // Pixel data from FITS file
    325 
    326     // Read the PHU, if required
    327     if (! phu) {
    328         if (! psFitsMoveExtNum(fits, 0, false)) {
    329             psError(PS_ERR_IO, false, "Unable to find PHU in FITS file!\n");
    330             return false;
    331         }
    332         psTrace(__func__, 7, "Reading PHU....\n");
    333         fpa->phu = psFitsReadHeader(NULL, fits); // Primary header
    334     } else if (! fpa->phu) {
    335         fpa->phu = psMemIncrRefCounter(phu);
    336     }
    337 
    338     // Read in....
    339     psTrace(__func__, 1, "Reading FPA...\n");
    340     if (fpa->hdu) {
    341         hdu = fpa->hdu;
    342         psTrace(__func__, 3, "Reading pixels from extension %s into FPA.\n", hdu->extname);
    343         if (! readExtension(hdu, fits)) {
    344             psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);
    345             return false;
    346         }
    347     }
    348     pmConceptsReadFPA(fpa, db);
    349 
    350     psArray *chips = fpa->chips;        // Array of chips
    351     // Iterate over the FPA
    352     for (int i = 0; i < chips->n; i++) {
    353         pmChip *chip = chips->data[i]; // The chip
    354 
    355         // Only read chips marked to "read"
    356         if (! chip || ! chip->process || chip->exists) {
    357             psTrace(__func__, 2, "Ignoring chip %d...\n", i);
    358             continue;
    359         }
    360         psTrace(__func__, 2, "Reading in chip %d...\n", i);
    361 
    362         if (chip->hdu) {
    363             hdu = chip->hdu;
    364             psTrace(__func__, 3, "Reading pixels from extension %s into chip %d.\n", hdu->extname, i);
    365             if (! readExtension(hdu, fits)) {
    366                 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);
    367                 return false;
    368             }
    369         }
    370 
    371         pmConceptsReadChip(chip, db);
    372 
    373         // Iterate over the chip
    374         psArray *cells = chip->cells;   // Array of cells
    375         for (int j = 0; j < cells->n; j++) {
    376             pmCell *cell = cells->data[j]; // The cell
    377 
    378             // Only read cells marked to "read"
    379             if (!cell || ! cell->process || cell->exists) {
    380                 psTrace(__func__, 3, "Ignoring chip %d...\n", i);
    381                 continue;
    382             }
    383             psTrace(__func__, 3, "Reading in cell %d...\n", j);
    384 
    385             if (cell->hdu) {
    386                 hdu = cell->hdu;
    387                 psTrace(__func__, 5, "Reading pixels from extension %s into cell %d.\n", hdu->extname,
    388                         j);
    389                 if (! readExtension(hdu, fits)) {
    390                     psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n",
    391                             hdu->extname);
    392                     return false;
    393                 }
    394             }
    395             psTrace(__func__, 5, "Reading concepts for cell %d...\n", j);
    396             pmConceptsReadCell(cell, db);
    397 
    398             psTrace(__func__, 5, "Allocating readouts for chip %d cell %d...\n", i, j);
    399             generateReadouts(cell, hdu);
    400 
    401             cell->exists = true;
    402         }
    403         chip->exists = true;
    404     }
    405 
    406     psTrace(__func__, 1, "Done reading FPA...\n");
    407 
    408     return true;
    409186}
    410187
Note: See TracChangeset for help on using the changeset viewer.