IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2007, 2:34:00 PM (19 years ago)
Author:
magnier
Message:

adding HEADER Read options for loading headers with images

File:
1 edited

Legend:

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

    r11687 r11793  
    2626    FPA_READ_TYPE_IMAGE,                // Read image
    2727    FPA_READ_TYPE_MASK,                 // Read mask
    28     FPA_READ_TYPE_WEIGHT                // Read weight map
     28    FPA_READ_TYPE_WEIGHT,               // Read weight map
     29    FPA_READ_TYPE_HEADER                // Read header
    2930} fpaReadType;
    3031
     
    3536// Carve a readout from the image pixels
    3637static bool readoutCarve(pmReadout *readout, // Readout to be carved up
    37                          psImage **target, // Target pointer for the carved image
    3838                         psImage *image, // Image that will be carved
    3939                         const psRegion *trimsec, // Trim section
    40                          const psList *biassecs // Bias sections
     40                         const psList *biassecs, // Bias sections
     41                         fpaReadType type
    4142                        )
    4243{
     
    5960                                  PS_MIN(trimsec->y1 - readout->row0, image->numRows) // y1
    6061                                 );
    61     if (readout->image) {
    62         psFree(readout->image);         // Make way!
    63     }
    64     *target = psMemIncrRefCounter(psImageSubset(image, region));
    65 
     62
     63    // place the image subset in the appropriate target location, freeing if needed
     64    // XXX why psMemIncrRefCounter on psImageSubset??
     65    switch (type) {
     66      case FPA_READ_TYPE_IMAGE:
     67        if (readout->image) {
     68            psFree (readout->image);
     69        }
     70        readout->image = psMemIncrRefCounter(psImageSubset(image, region));     
     71        break;
     72      case FPA_READ_TYPE_MASK:
     73        if (readout->mask) {
     74            psFree (readout->mask);
     75        }
     76        readout->mask = psMemIncrRefCounter(psImageSubset(image, region));     
     77        break;
     78      case FPA_READ_TYPE_WEIGHT:
     79        if (readout->weight) {
     80            psFree (readout->weight);
     81        }
     82        readout->weight = psMemIncrRefCounter(psImageSubset(image, region));   
     83        break;
     84      default:
     85        psAbort("Unknown read type: %x\n", type);
     86    }
     87   
    6688    // Get the list of overscans
     89    // XXX should this step only be performed for IMAGE, not MASK and WEIGHT types?
     90    // XXX that would allow us to overlay a MASK and WEIGHT which have been trimmed...
    6791    if (readout->bias->n != 0) {
    6892        // Make way!
     
    184208    }
    185209
     210    // check if we have read the desired data, read it if needed
    186211    bool (*hduReadFunc)(pmHDU*, psFits*) = NULL; // Function to use to read the HDU
    187     psArray **imageArray = NULL; // Array of images in the HDU
    188     psElemType imageType = PS_TYPE_F32; // Expected type for image
     212    void *dataPointer = NULL;           // pointer to location of desired data
    189213    switch (type) {
    190     case FPA_READ_TYPE_IMAGE:
     214      case FPA_READ_TYPE_IMAGE:
    191215        hduReadFunc = pmHDURead;
    192         imageArray = &hdu->images;
    193         imageType = PS_TYPE_F32;
     216        dataPointer = hdu->images;
    194217        break;
    195     case FPA_READ_TYPE_MASK:
     218      case FPA_READ_TYPE_HEADER:
     219        hduReadFunc = pmHDUReadHeader;
     220        dataPointer = hdu->header;
     221        break;
     222      case FPA_READ_TYPE_MASK:
    196223        hduReadFunc = pmHDUReadMask;
    197         imageArray = &hdu->masks;
    198         imageType = PS_TYPE_MASK;
     224        dataPointer = hdu->masks;
    199225        break;
    200     case FPA_READ_TYPE_WEIGHT:
     226      case FPA_READ_TYPE_WEIGHT:
    201227        hduReadFunc = pmHDUReadWeight;
    202         imageArray = &hdu->weights;
    203         imageType = PS_TYPE_F32;
     228        dataPointer = hdu->weights;
    204229        break;
    205     default:
     230      default:
    206231        psAbort("Unknown read type: %x\n", type);
    207232    }
    208233
    209     if (!(*imageArray) && !hduReadFunc(hdu, fits)) {
    210         psError(PS_ERR_UNKNOWN, false, "Unable to read HDU for cell.\n");
    211         return false;
    212     }
    213 
     234    // do we have the data we want (image, header, or etc).
     235    if (!dataPointer) {
     236        // attempt to read in the desired data
     237        if (!hduReadFunc(hdu, fits)) {
     238            psError(PS_ERR_UNKNOWN, false, "Unable to read HDU for cell.\n");
     239            return false;
     240        }
     241    }
     242
     243    // load in the concept information for this cell
    214244    if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
    215245        //psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for cell");
    216246        //return false;
    217247        psWarning("Difficulty reading concepts for cell; attempting to proceed.");
     248    }
     249
     250    // skip the image arrays completely for the header-only files
     251    if (type == FPA_READ_TYPE_HEADER) {
     252        pmCellSetDataStatus(cell, true);
     253        return true;
     254    }
     255
     256    // set up pointers for the different possible image arrays
     257    psArray *imageArray = NULL; // Array of images in the HDU
     258    psElemType imageType = PS_TYPE_F32; // Expected type for image
     259    switch (type) {
     260      case FPA_READ_TYPE_IMAGE:
     261        imageArray = hdu->images;
     262        imageType = PS_TYPE_F32;
     263        break;
     264      case FPA_READ_TYPE_MASK:
     265        imageArray = hdu->masks;
     266        imageType = PS_TYPE_MASK;
     267        break;
     268      case FPA_READ_TYPE_WEIGHT:
     269        imageArray = hdu->weights;
     270        imageType = PS_TYPE_F32;
     271        break;
     272      default:
     273        psAbort("Unknown read type: %x\n", type);
    218274    }
    219275
     
    228284    // Iterate over each of the image planes, converting type if necessary, and extracting the bits that
    229285    // matter (CELL.TRIMSEC, CELL.BIASSEC) into readouts with readoutCarve.
    230     for (int i = 0; i < (*imageArray)->n; i++) {
    231         psImage *source = (*imageArray)->data[i]; // Source image, from the i-th plane
     286    for (int i = 0; i < imageArray->n; i++) {
     287        psImage *source = imageArray->data[i]; // Source image, from the i-th plane
    232288
    233289        // Type conversion here to support the modules, which don't have multiple type support yet
    234290        if (source->type.type != imageType) {
    235291            psImage *temp = psImageCopy(NULL, source, imageType); // Temporary image
    236             psFree((*imageArray)->data[i]);
    237             (*imageArray)->data[i] = temp;
     292            psFree(imageArray->data[i]);
     293            imageArray->data[i] = temp;
    238294            source = temp;
    239295        }
     
    246302        }
    247303
    248         psImage **target = NULL;               // Place in readout to put carved image
    249         switch (type) {
    250         case FPA_READ_TYPE_IMAGE:
    251             target = &readout->image;
    252             break;
    253         case FPA_READ_TYPE_MASK:
    254             target = &readout->mask;
    255             break;
    256         case FPA_READ_TYPE_WEIGHT:
    257             target = &readout->weight;
    258             break;
    259         default:
    260             psAbort("Unknown read type: %x\n", type);
    261         }
    262 
    263         if (!readoutCarve(readout, target, source, trimsec, biassecs)) {
     304        if (!readoutCarve(readout, source, trimsec, biassecs, type)) {
    264305            psError(PS_ERR_UNEXPECTED_NULL, false,
    265306                    "Unable to carve readout into image and bias sections for %d the plane.", i);
     
    594635
    595636//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     637// Reading the image header
     638//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     639
     640bool pmCellReadHeaderSet(pmCell *cell, psFits *fits, psDB *db)
     641{
     642    PS_ASSERT_PTR_NON_NULL(cell, false);
     643    PS_ASSERT_PTR_NON_NULL(fits, false);
     644
     645    return cellRead(cell, fits, db, FPA_READ_TYPE_HEADER);
     646}
     647
     648bool pmChipReadHeaderSet(pmChip *chip, psFits *fits, psDB *db)
     649{
     650    PS_ASSERT_PTR_NON_NULL(chip, false);
     651    PS_ASSERT_PTR_NON_NULL(fits, false);
     652
     653    return chipRead(chip, fits, db, FPA_READ_TYPE_HEADER);
     654}
     655
     656bool pmFPAReadHeaderSet(pmFPA *fpa, psFits *fits, psDB *db)
     657{
     658    PS_ASSERT_PTR_NON_NULL(fpa, false);
     659    PS_ASSERT_PTR_NON_NULL(fits, false);
     660
     661    return fpaRead(fpa, fits, db, FPA_READ_TYPE_HEADER);
     662}
     663
     664//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    596665// Reading FITS tables
    597666//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.