IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 17, 2008, 12:38:15 PM (18 years ago)
Author:
Paul Price
Message:

The FPA format in psastroDataSave was bad: the GPC1 inputs (which is used for the output) had HDUs in the chips, but the output format is supposed to have an HDU in the FPA. It comes down to a pmFPAfileSuitableFPA not being called at the right place. To fix this, I've sprinkled calls to pmFPAfileSuitableFPA in all the FITS writing functions. This provides the HDU in the right place to these functions. pmFPAfileSuitableFPA should now automatically take care of header conformity, updating concepts, etc. Now, if adding a function to write FITS data, you should make sure that you call pmFPAfileSuitableFPA to get the right format, HDU, header keywords, etc.

File:
1 edited

Legend:

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

    r18554 r18601  
    405405    }
    406406
    407     // check if the file is a FITS file (or uses the fits header)
    408     bool fitsType = false;
    409     fitsType |= (file->type == PM_FPA_FILE_IMAGE);
    410     fitsType |= (file->type == PM_FPA_FILE_MASK);
    411     fitsType |= (file->type == PM_FPA_FILE_WEIGHT);
    412     fitsType |= (file->type == PM_FPA_FILE_HEADER);
    413     fitsType |= (file->type == PM_FPA_FILE_FRINGE);
    414     fitsType |= (file->type == PM_FPA_FILE_DARK);
    415     fitsType |= (file->type == PM_FPA_FILE_CMP);
    416     fitsType |= (file->type == PM_FPA_FILE_CMF);
    417     fitsType |= (file->type == PM_FPA_FILE_PSF);
    418     fitsType |= (file->type == PM_FPA_FILE_ASTROM_MODEL);
    419     fitsType |= (file->type == PM_FPA_FILE_ASTROM_REFSTARS);
    420 
    421     // Ensure headers and all are updated
    422     // This is here so that the individual write functions (e.g., images, PSFs, sources, etc) don't have to
    423     // take care of all this themselves (because they generally don't).
    424     if (fitsType) {
    425         pmHDU *hdu = pmFPAviewThisHDU(view, file->fpa);
    426         if (hdu) {
    427             if (!hdu->header) {
    428                 hdu->header = psMetadataAlloc();
    429             }
    430             pmConfigConformHeader(hdu->header, file->format);
    431 
    432             // whenever we write out a mask image, we should define the bits which represent mask concepts
    433             if (file->type == PM_FPA_FILE_MASK) {
    434                 assert (hdu->header);
    435                 if (!pmConfigMaskWriteHeader (config, hdu->header)) {
    436                     psError(PS_ERR_UNKNOWN, false, "failed to set the bitmask names in the PHU header for Image %s (%s)\n", file->filename, file->name);
    437                     return false;
    438                 }
    439             }
    440         }
    441 
    442         pmFPA *fpa = file->fpa;         // FPA of interest
    443         pmChip *chip = pmFPAviewThisChip(view, file->fpa); // Chip of interest, or NULL
    444         pmCell *cell = pmFPAviewThisCell(view, file->fpa); // Cell of interest, or NULL
    445         if (!pmFPAUpdateNames(fpa, chip, cell)) {
    446             psError(PS_ERR_UNKNOWN, false, "Unable to update names in header.");
    447             return false;
    448         }
    449 
    450         pmConceptSource sources = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS |
    451             PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE; // Concept sources to write
    452         if (cell) {
    453             if (!pmConceptsWriteCell(cell, sources, true, config)) {
    454                 psError(PS_ERR_IO, false, "Unable to write concepts for cell.\n");
    455                 return false;
    456             }
    457         } else if (chip) {
    458             if (!pmConceptsWriteChip(chip, sources, true, true, config)) {
    459                 psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n");
    460                 return false;
    461             }
    462         } else if (!pmConceptsWriteFPA(fpa, sources, true, config)) {
    463             psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n");
    464             return false;
    465         }
    466     }
     407    // IMPORTANT: If adding a FITS-based file, make sure your write function uses an FPA produced by
     408    // pmFPAfileSuitableFPA.  This ensures the HDUs are at the correct level for your output format, and sets
     409    // the headers correctly.
    467410
    468411    // select a writing method
     
    487430        status = pmFPAviewWriteFitsImage (view, file, config);
    488431        if (status) {
    489             if (!pmFPAviewWriteFitsTable(view, file, "FRINGE")) {
     432            if (!pmFPAviewWriteFitsTable(view, file, "FRINGE", config)) {
    490433                psError(PS_ERR_UNKNOWN, false, "Unable to write fringe data from %s.\n", file->filename);
    491434                return false;
     
    802745          }
    803746
    804           // XXX if we have a mask file, then we need to read the mask bit names
    805           // defined for this file
    806           if (file->type == PM_FPA_FILE_MASK) {
    807             if (!pmConfigMaskReadHeader (config, phu)) {
    808                 psError(PS_ERR_IO, false, "error in mask bits");
    809                 return false;
    810             }
    811           }
     747          // XXX if we have a mask file, then we need to read the mask bit names
     748          // defined for this file
     749          if (file->type == PM_FPA_FILE_MASK) {
     750            if (!pmConfigMaskReadHeader (config, phu)) {
     751                psError(PS_ERR_IO, false, "error in mask bits");
     752                return false;
     753            }
     754          }
    812755
    813756          // determine the current format from the header
Note: See TracChangeset for help on using the changeset viewer.