IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11793


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

adding HEADER Read options for loading headers with images

Location:
trunk/psModules/src/camera
Files:
7 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//////////////////////////////////////////////////////////////////////////////////////////////////////////////
  • trunk/psModules/src/camera/pmFPARead.h

    r11253 r11793  
    44 * @author Paul Price, IfA
    55 *
    6  * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-01-24 02:54:14 $
     6 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-02-15 00:34:00 $
    88 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    99 */
     
    107107                    );
    108108
     109/// Read cell headers
     110///
     111/// Same as pmCellRead, but reads only the headers of the readouts.
     112bool pmCellReadHeaderSet(pmCell *cell,           // Cell to read into
     113                         psFits *fits,           // FITS file from which to read
     114                         psDB *db                // Database handle, for "concepts" ingest
     115    );
     116
     117/// Read chip headers
     118///
     119/// Same as pmChipRead, but reads only the headers of the readouts.
     120bool pmChipReadHeaderSet(pmChip *chip,           // Chip to read into
     121                      psFits *fits,           // FITS file from which to read
     122                      psDB *db                // Database handle, for "concepts" ingest
     123                     );
     124
     125/// Read FPA headers
     126///
     127/// Same as pmFPARead, but reads only the headers of the readouts.
     128bool pmFPAReadHeaderSet(pmFPA *fpa,              // FPA to read into
     129                        psFits *fits,            // FITS file from which to read
     130                        psDB *db                 // Database handle, for "concepts" ingest
     131    );
     132
    109133/// Read a FITS table into the cell
    110134///
  • trunk/psModules/src/camera/pmFPAfile.c

    r11376 r11793  
    408408        return PM_FPA_FILE_FRINGE;
    409409    }
     410    if (!strcasecmp (type, "HEADER"))     {
     411        return PM_FPA_FILE_HEADER;
     412    }
    410413
    411414    return PM_FPA_FILE_NONE;
  • trunk/psModules/src/camera/pmFPAfile.h

    r11253 r11793  
    44 * @author EAM, IfA
    55 *
    6  * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-01-24 02:54:14 $
     6 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-02-15 00:34:00 $
    88 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
    99 */
     
    4040    PM_FPA_FILE_WEIGHT,
    4141    PM_FPA_FILE_FRINGE,
     42    PM_FPA_FILE_HEADER,
    4243} pmFPAfileType;
    4344
  • trunk/psModules/src/camera/pmFPAfileFitsIO.c

    r11687 r11793  
    218218}
    219219
     220bool pmFPAviewReadFitsHeaderSet(const pmFPAview *view, pmFPAfile *file)
     221{
     222    PS_ASSERT_PTR_NON_NULL(view, false);
     223    PS_ASSERT_PTR_NON_NULL(file, false);
     224    return fpaViewReadFitsImage(view, file, pmFPAReadHeaderSet, pmChipReadHeaderSet, pmCellReadHeaderSet);
     225}
     226
    220227// given an already-opened fits file, write the components corresponding
    221228// to the specified view. when the file was opened, pmFPA/Chip/CellWrite was
  • trunk/psModules/src/camera/pmFPAfileFitsIO.h

    r11339 r11793  
    55 * @author PAP, IfA
    66 *
    7  * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-01-27 03:33:37 $
     7 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2007-02-15 00:34:00 $
    99 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
    1010 */
     
    2929                             pmFPAfile *file ///< FPA file into which to read
    3030                            );
     31
     32/// Read an image header into the current view
     33bool pmFPAviewReadFitsHeaderSet(const pmFPAview *view,  ///< View specifying level of interest
     34                                pmFPAfile *file ///< FPA file into which to read
     35    );
    3136
    3237/// Write the image for the specified view
  • trunk/psModules/src/camera/pmFPAfileIO.c

    r11687 r11793  
    251251
    252252    switch (file->type) {
    253         // open the FITS types:
    254     case PM_FPA_FILE_IMAGE:
    255     case PM_FPA_FILE_MASK:
    256     case PM_FPA_FILE_WEIGHT:
    257     case PM_FPA_FILE_FRINGE:
     253      // open the FITS types:
     254      case PM_FPA_FILE_IMAGE:
     255      case PM_FPA_FILE_MASK:
     256      case PM_FPA_FILE_WEIGHT:
     257      case PM_FPA_FILE_HEADER:
     258      case PM_FPA_FILE_FRINGE:
    258259        psTrace ("pmFPAfile", 5, "opening %s (type: %d)\n", file->filename, file->type);
    259260        if (!openImage(file, view, mode, config)) {
     
    263264        break;
    264265        // open the FITS object files
    265     case PM_FPA_FILE_CMF:
     266      case PM_FPA_FILE_CMF:
    266267        psTrace ("pmFPAfile", 5, "opening %s (type: %d)\n", file->filename, file->type);
    267268        file->fits = psFitsOpen (file->filename, mode);
     
    273274        break;
    274275
    275         // defer opening TEXT types:
    276     case PM_FPA_FILE_SX:
    277     case PM_FPA_FILE_OBJ:
    278     case PM_FPA_FILE_CMP:
    279     case PM_FPA_FILE_RAW:
    280     case PM_FPA_FILE_PSF:
    281     case PM_FPA_FILE_JPEG:
    282     case PM_FPA_FILE_KAPA:
    283     case PM_FPA_FILE_MANAPLOT:
     276      // defer opening TEXT types:
     277      case PM_FPA_FILE_SX:
     278      case PM_FPA_FILE_OBJ:
     279      case PM_FPA_FILE_CMP:
     280      case PM_FPA_FILE_RAW:
     281      case PM_FPA_FILE_PSF:
     282      case PM_FPA_FILE_JPEG:
     283      case PM_FPA_FILE_KAPA:
     284      case PM_FPA_FILE_MANAPLOT:
    284285        psTrace ("pmFPAfile", 5, "defer opening %s\n", file->filename);
    285286        break;
    286287
    287     default:
     288      default:
    288289        psError(PS_ERR_IO, true, "type mismatch for %s : %d\n", file->filename, file->type);
    289290        return false;
     
    357358    case PM_FPA_FILE_WEIGHT:
    358359        if (!pmFPAviewReadFitsWeight(view, file)) {
     360            psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
     361            return false;
     362        }
     363        psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
     364        break;
     365    case PM_FPA_FILE_HEADER:
     366        if (!pmFPAviewReadFitsHeaderSet(view, file)) {
    359367            psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
    360368            return false;
     
    432440    case PM_FPA_FILE_MASK:
    433441    case PM_FPA_FILE_WEIGHT:
     442    case PM_FPA_FILE_HEADER:
    434443    case PM_FPA_FILE_FRINGE:
    435444        if (pmFPAviewFreeData(view, file)) {
     
    525534        pmFPAviewWriteFitsWeight(view, file, config);
    526535        psTrace ("pmFPAfile", 5, "wrote weight %s (fpa: %p)\n", file->filename, file->fpa);
     536        break;
     537    case PM_FPA_FILE_HEADER:
     538      // pmFPAviewWriteFitsWeight(view, file, config);
     539      // psTrace ("pmFPAfile", 5, "wrote weight %s (fpa: %p)\n", file->filename, file->fpa);
     540      psAbort ("no HEADER write functions defined");
    527541        break;
    528542    case PM_FPA_FILE_FRINGE:
     
    616630    case PM_FPA_FILE_WEIGHT:
    617631    case PM_FPA_FILE_FRINGE: {
    618             // create FPA structure component based on view
    619             #if 0
    620             psMetadata *format = file->format; // Camera format configuration
    621             if (!format) {
    622                 // It's likely a mosaic, for which we don't yet know the appropriate format
    623                 const psMetadata *camera = file->fpa->camera; // Camera configuration
    624                 psMetadata *formats = psMetadataLookupMetadata(NULL, camera, "FORMATS"); // The FORMATS
    625                 if (!formats) {
    626                     psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FORMATS in camera configuration.\n");
    627                     return false;
    628                 }
    629                 format = psMetadataLookupMetadata(NULL, formats, config->formatName);
    630                 if (!format) {
    631                     psError(PS_ERR_UNEXPECTED_NULL, false,
    632                             "Unable to find format %s in camera configuration.\n", config->formatName);
    633                     return false;
    634                 }
    635                 file->format = psMemIncrRefCounter(format);
    636             }
    637             #endif
    638             pmFPAAddSourceFromView (file->fpa, view, file->format);
    639             psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->name, file->fpa);
    640             break;
    641         }
     632        // create FPA structure component based on view
     633        // XXX drop this ifdef'ed out code??
     634#if 0
     635        psMetadata *format = file->format; // Camera format configuration
     636        if (!format) {
     637            // It's likely a mosaic, for which we don't yet know the appropriate format
     638            const psMetadata *camera = file->fpa->camera; // Camera configuration
     639            psMetadata *formats = psMetadataLookupMetadata(NULL, camera, "FORMATS"); // The FORMATS
     640            if (!formats) {
     641                psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FORMATS in camera configuration.\n");
     642                return false;
     643            }
     644            format = psMetadataLookupMetadata(NULL, formats, config->formatName);
     645            if (!format) {
     646                psError(PS_ERR_UNEXPECTED_NULL, false,
     647                        "Unable to find format %s in camera configuration.\n", config->formatName);
     648                return false;
     649            }
     650            file->format = psMemIncrRefCounter(format);
     651        }
     652#endif
     653        pmFPAAddSourceFromView (file->fpa, view, file->format);
     654        psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->name, file->fpa);
     655        break;
     656    }
     657    case PM_FPA_FILE_HEADER:
     658      psAbort ("Create not defined for HEADER");
     659      break;
    642660    case PM_FPA_FILE_SX:
    643661    case PM_FPA_FILE_RAW:
     
    691709    case PM_FPA_FILE_MASK:
    692710    case PM_FPA_FILE_WEIGHT:
     711    case PM_FPA_FILE_HEADER:
    693712    case PM_FPA_FILE_FRINGE:
    694713    case PM_FPA_FILE_CMF:
Note: See TracChangeset for help on using the changeset viewer.