IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.