IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19385


Ignore:
Timestamp:
Sep 4, 2008, 10:21:35 PM (18 years ago)
Author:
Paul Price
Message:

Provide mask and mask value when writing an HDU. This is required for the case when a large masked region of the image has been set to a constant (or close to a constant). If the mask is not provided in this case, then the standard deviation is under-estimated, leading to a choice of BSCALE,BZERO that adversely affects the dynamic range of the image. Mask value comes from MASK.VALUE using pmConfigMaskGet.

Location:
trunk/psModules/src/camera
Files:
3 edited

Legend:

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

    r18177 r19385  
    3636//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    3737
    38 
    39 // Update the FPA.OBS, CHIP.NAME and CELL.NAME in the FITS header, if required
    40 bool pmFPAUpdateNames(pmFPA *fpa, pmChip *chip, pmCell *cell)
    41 {
    42     pmHDU *hdu = pmHDUGetHighest(fpa, chip, cell); // Highest HDU, i.e., the PHU
    43     if (!hdu) {
    44         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU.\n");
    45         return false;
    46     }
    47     if (!hdu->header) {
    48         hdu->header = psMetadataAlloc();
    49     }
    50     bool mdok;                          // Status of MD lookup
    51     psMetadata *fileData = psMetadataLookupMetadata(&mdok, hdu->format, "FILE"); // File information
    52     if (!mdok || !fileData) {
    53         psError(PS_ERR_UNKNOWN, true, "Unable to find FILE information in camera format.\n");
    54         return false;
    55     }
    56     if (fpa) {
    57         const char *fpaObsHdr = psMetadataLookupStr(&mdok, fileData, "FPA.OBS");
    58         if (mdok && fpaObsHdr && strlen(fpaObsHdr) > 0) {
    59             const char *fpaObs = psMetadataLookupStr(NULL, fpa->concepts, "FPA.OBS");
    60             psMetadataAddStr(hdu->header, PS_LIST_TAIL, fpaObsHdr, PS_META_REPLACE,
    61                              "Observation identifier", fpaObs);
    62         }
    63     }
    64 
    65     if (fpa && !fpa->hdu && (chip || cell)) {
    66         const char *rule = psMetadataLookupStr(NULL, fileData, "CONTENT.RULE"); // How to define the CONTENT
    67         if (!rule) {
    68             psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT.RULE in FILE in camera format.");
    69             return false;
    70         }
    71 
    72         pmFPAview *view = pmFPAviewGenerate(fpa, chip, cell, NULL); // View for fpa, chip, cell
    73         psString content = pmFPANameFromRule(rule, fpa, view); // Content of this file, specified by the rule
    74         psFree(view);
    75 
    76         const char *contentKey = psMetadataLookupStr(NULL, fileData, "CONTENT"); // The CONTENT header keyword
    77         if (!contentKey) {
    78             psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT in FILE in the camera format.");
    79             psFree(content);
    80             return false;
    81         }
    82 
    83         psMetadataAddStr(hdu->header, PS_LIST_TAIL, contentKey, PS_META_REPLACE, "Content of file", content);
    84         psFree(content);                // Drop reference
    85     }
    86 
    87     return true;
    88 }
    89 
    9038// Return the appropriate image array for the given type
    9139static psArray **appropriateImageArray(pmHDU *hdu, // HDU containing the image arrays
     
    10957static bool appropriateWriteFunc(pmHDU *hdu, // HDU to write
    11058                                 psFits *fits, // FITS file to which to write
     59                                 const pmConfig *config, // Configuration
    11160                                 fpaWriteType type // Type to write
    11261                                )
     
    11463    switch (type) {
    11564    case FPA_WRITE_TYPE_IMAGE:
    116         return pmHDUWrite(hdu, fits);
     65        return pmHDUWrite(hdu, fits, config);
    11766    case FPA_WRITE_TYPE_MASK:
    118         return pmHDUWriteMask(hdu, fits);
     67        return pmHDUWriteMask(hdu, fits, config);
    11968    case FPA_WRITE_TYPE_WEIGHT:
    120         return pmHDUWriteWeight(hdu, fits);
     69        return pmHDUWriteWeight(hdu, fits, config);
    12170    default:
    12271        psAbort("Unknown write type: %x\n", type);
     
    165114            return false;
    166115        }
    167         if (!appropriateWriteFunc(hdu, fits, type)) {
     116        if (!appropriateWriteFunc(hdu, fits, config, type)) {
    168117            psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n");
    169118            return false;
     
    215164                return false;
    216165            }
    217             if (!appropriateWriteFunc(hdu, fits, type)) {
     166            if (!appropriateWriteFunc(hdu, fits, config, type)) {
    218167                psError(PS_ERR_IO, false, "Unable to write HDU for chip.\n");
    219168                return false;
     
    279228                return false;
    280229            }
    281             if (!appropriateWriteFunc(hdu, fits, type))  {
     230            if (!appropriateWriteFunc(hdu, fits, config, type))  {
    282231                psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n");
    283232                return false;
     
    305254//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    306255
     256// Update the FPA.OBS, CHIP.NAME and CELL.NAME in the FITS header, if required
     257bool pmFPAUpdateNames(pmFPA *fpa, pmChip *chip, pmCell *cell)
     258{
     259    pmHDU *hdu = pmHDUGetHighest(fpa, chip, cell); // Highest HDU, i.e., the PHU
     260    if (!hdu) {
     261        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU.\n");
     262        return false;
     263    }
     264    if (!hdu->header) {
     265        hdu->header = psMetadataAlloc();
     266    }
     267    bool mdok;                          // Status of MD lookup
     268    psMetadata *fileData = psMetadataLookupMetadata(&mdok, hdu->format, "FILE"); // File information
     269    if (!mdok || !fileData) {
     270        psError(PS_ERR_UNKNOWN, true, "Unable to find FILE information in camera format.\n");
     271        return false;
     272    }
     273    if (fpa) {
     274        const char *fpaObsHdr = psMetadataLookupStr(&mdok, fileData, "FPA.OBS");
     275        if (mdok && fpaObsHdr && strlen(fpaObsHdr) > 0) {
     276            const char *fpaObs = psMetadataLookupStr(NULL, fpa->concepts, "FPA.OBS");
     277            psMetadataAddStr(hdu->header, PS_LIST_TAIL, fpaObsHdr, PS_META_REPLACE,
     278                             "Observation identifier", fpaObs);
     279        }
     280    }
     281
     282    if (fpa && !fpa->hdu && (chip || cell)) {
     283        const char *rule = psMetadataLookupStr(NULL, fileData, "CONTENT.RULE"); // How to define the CONTENT
     284        if (!rule) {
     285            psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT.RULE in FILE in camera format.");
     286            return false;
     287        }
     288
     289        pmFPAview *view = pmFPAviewGenerate(fpa, chip, cell, NULL); // View for fpa, chip, cell
     290        psString content = pmFPANameFromRule(rule, fpa, view); // Content of this file, specified by the rule
     291        psFree(view);
     292
     293        const char *contentKey = psMetadataLookupStr(NULL, fileData, "CONTENT"); // The CONTENT header keyword
     294        if (!contentKey) {
     295            psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT in FILE in the camera format.");
     296            psFree(content);
     297            return false;
     298        }
     299
     300        psMetadataAddStr(hdu->header, PS_LIST_TAIL, contentKey, PS_META_REPLACE, "Content of file", content);
     301        psFree(content);                // Drop reference
     302    }
     303
     304    return true;
     305}
     306
    307307bool pmReadoutWriteNext(pmReadout *readout, psFits *fits, int z)
    308308{
     
    347347        return false;
    348348    }
    349     psImage *image = readout->image; // The image from the HDU to write
     349    psImage *image = readout->image;    // The image from the HDU to write
     350    //    psImage *mask = readout->mask;        // Corresponding mask image
    350351    if (readout->row0 == 0 && readout->col0 == 0 && z == 0) {
    351352        // Then we can assume that nothing has been written to the FITS file for now
  • trunk/psModules/src/camera/pmHDU.c

    r15973 r19385  
    99
    1010#include "pmConfig.h"
     11#include "pmConfigMask.h"
    1112#include "pmHDU.h"
    1213#include "pmFPA.h"
     
    164165// Write an HDU to a FITS file
    165166static bool hduWrite(pmHDU *hdu,        // HDU to write
    166                      psArray *images,   // Images to write
     167                     const psArray *images, // Images to write
     168                     const psArray *masks, // Masks to use when writing
     169                     psMaskType maskVal,// Value to mask
    167170                     psFits *fits       // FITS file to which to write
    168171                    )
     
    205208    if (images) {
    206209        psTrace("psModules.camera", 9, "Writing pixels for %s\n", hdu->extname);
    207         if (!psFitsWriteImageCube(fits, hdu->header, images, extname)) {
     210        if (!psFitsWriteImageCubeWithMask(fits, hdu->header, images, masks, maskVal, extname)) {
    208211            psError(PS_ERR_IO, false, "Unable to write image to extension %s\n", hdu->extname);
    209212            return false;
     
    214217
    215218// XXX: Add a region specifier?
    216 bool pmHDUWrite(pmHDU *hdu, psFits *fits)
    217 {
    218     PS_ASSERT_PTR_NON_NULL(hdu, false);
    219     PS_ASSERT_PTR_NON_NULL(fits, false);
    220 
    221     return hduWrite(hdu, hdu->images, fits);
    222 }
    223 
    224 bool pmHDUWriteMask(pmHDU *hdu, psFits *fits)
    225 {
    226     PS_ASSERT_PTR_NON_NULL(hdu, false);
    227     PS_ASSERT_PTR_NON_NULL(fits, false);
    228 
    229     return hduWrite(hdu, hdu->masks, fits);
    230 }
    231 
    232 bool pmHDUWriteWeight(pmHDU *hdu, psFits *fits)
    233 {
    234     PS_ASSERT_PTR_NON_NULL(hdu, false);
    235     PS_ASSERT_PTR_NON_NULL(fits, false);
    236 
    237     return hduWrite(hdu, hdu->weights, fits);
    238 }
     219bool pmHDUWrite(pmHDU *hdu, psFits *fits, const pmConfig *config)
     220{
     221    PS_ASSERT_PTR_NON_NULL(hdu, false);
     222    PS_ASSERT_PTR_NON_NULL(fits, false);
     223
     224    psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
     225    return hduWrite(hdu, hdu->images, hdu->masks, maskVal, fits);
     226}
     227
     228bool pmHDUWriteMask(pmHDU *hdu, psFits *fits, const pmConfig *config)
     229{
     230    PS_ASSERT_PTR_NON_NULL(hdu, false);
     231    PS_ASSERT_PTR_NON_NULL(fits, false);
     232
     233    // We don't supply a mask because we're writing the mask!
     234    return hduWrite(hdu, hdu->masks, NULL, 0, fits);
     235}
     236
     237bool pmHDUWriteWeight(pmHDU *hdu, psFits *fits, const pmConfig *config)
     238{
     239    PS_ASSERT_PTR_NON_NULL(hdu, false);
     240    PS_ASSERT_PTR_NON_NULL(fits, false);
     241
     242    psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
     243    return hduWrite(hdu, hdu->weights, hdu->masks, maskVal, fits);
     244}
  • trunk/psModules/src/camera/pmHDU.h

    r15973 r19385  
    44 * @author Paul Price, IfA
    55 *
    6  * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2008-01-02 20:33:41 $
     6 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2008-09-05 08:21:35 $
    88 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    99 */
     
    1111#ifndef PM_HDU_H
    1212#define PM_HDU_H
     13
     14#include <pslib.h>
     15#include "pmConfig.h"
    1316
    1417/// @addtogroup Camera Camera Layout
     
    6265bool pmHDUReadWeight(pmHDU *hdu,        ///< HDU to read
    6366                     psFits *fits       ///< FITS file to read from
    64                     );
     67    );
    6568
    6669/// Write the HDU header and pixels
    6770bool pmHDUWrite(pmHDU *hdu,             ///< HDU to write
    68                 psFits *fits            ///< FITS file to write to
    69                );
     71                psFits *fits,           ///< FITS file to write to
     72                const pmConfig *config  ///< Configuration
     73    );
    7074
    7175/// Write the HDU header and mask
    7276bool pmHDUWriteMask(pmHDU *hdu,         ///< HDU to write
    73                     psFits *fits        ///< FITS file to write to
    74                    );
     77                    psFits *fits,       ///< FITS file to write to
     78                    const pmConfig *config  ///< Configuration
     79    );
    7580
    7681/// Write the HDU header and weight map
    7782bool pmHDUWriteWeight(pmHDU *hdu,       ///< HDU to write
    78                       psFits *fits      ///< FITS file to write to
    79                      );
     83                      psFits *fits,     ///< FITS file to write to
     84                      const pmConfig *config  ///< Configuration
     85    );
    8086
    8187/// @}
Note: See TracChangeset for help on using the changeset viewer.