IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21271


Ignore:
Timestamp:
Feb 2, 2009, 3:00:34 PM (17 years ago)
Author:
Paul Price
Message:

Making behaviour of psMetadataLookupImageMaskFromGeneric consistent
with the regular psMetadataLookupType functions w.r.t. errors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_20090128/psModules/src/config/pmConfigMask.c

    r21183 r21271  
    1010
    1111static pmConfigMaskInfo masks[] = {
    12     { "DETECTOR",  NULL,       0x00, true  },   // Something is wrong with the detector
    13     { "DARK",      "DETECTOR", 0x00, true  },   // Pixel doesn't dark-subtract properly
    14     { "FLAT",      "DETECTOR", 0x01, true  },   // Pixel doesn't flat-field properly
    15     { "BLANK",     "DETECTOR", 0x01, true  },   // Pixel doesn't contain valid data
    16     { "RANGE",     NULL,       0x00, true  },   // Pixel is out-of-range of linearity
    17     { "SAT",       "RANGE",    0x01, true  },   // Pixel is saturated
    18     { "BAD",       "RANGE",    0x01, true  },   // Pixel is low
    19     { "BAD.WARP",  NULL,       0x01, true  },   // Pixel is bad after convolution with a bad pixel
    20     { "CR",        NULL,       0x00, true  },   // Pixel contains a cosmic ray
    21     { "GHOST",     NULL,       0x00, true  },   // Pixel contains an optical ghost
    22     { "POOR.WARP", NULL,       0x00, false },   // Pixel is poor after convolution with a bad pixel
     12    { "DETECTOR",  NULL,       0x00, true  },   // Something is wrong with the detector
     13    { "DARK",      "DETECTOR", 0x00, true  },   // Pixel doesn't dark-subtract properly
     14    { "FLAT",      "DETECTOR", 0x01, true  },   // Pixel doesn't flat-field properly
     15    { "BLANK",     "DETECTOR", 0x01, true  },   // Pixel doesn't contain valid data
     16    { "RANGE",     NULL,       0x00, true  },   // Pixel is out-of-range of linearity
     17    { "SAT",       "RANGE",    0x01, true  },   // Pixel is saturated
     18    { "BAD",       "RANGE",    0x01, true  },   // Pixel is low
     19    { "BAD.WARP",  NULL,       0x01, true  },   // Pixel is bad after convolution with a bad pixel
     20    { "CR",        NULL,       0x00, true  },   // Pixel contains a cosmic ray
     21    { "GHOST",     NULL,       0x00, true  },   // Pixel contains an optical ghost
     22    { "POOR.WARP", NULL,       0x00, false },   // Pixel is poor after convolution with a bad pixel
    2323    // "LOW"  Pixel is low
    2424    // "CONV" Pixel is bad after convolution with a bad pixel
     
    3131// bits in 8-bits of space).
    3232
    33 // XXX this file does not have psError vs psWarning worked out correctly.  some of the 
     33// XXX this file does not have psError vs psWarning worked out correctly.  some of the
    3434// failure modes should result in errors, not just warnings.
    3535
     
    4040
    4141bool pmConfigMaskSetInMetadata(psImageMaskType *outMaskValue, // Value of MASK.VALUE, returned
    42                                psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned
    43                                psMetadata *source  // Source of mask bits
     42                               psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned
     43                               psMetadata *source  // Source of mask bits
    4444    )
    4545{
    4646    PS_ASSERT_METADATA_NON_NULL(source, false);
    47    
     47
    4848    // Ensure all the bad mask names exist, and set the value to catch all bad pixels
    4949    psImageMaskType maskValue = 0;           // Value to mask to catch all the bad pixels
    50     psImageMaskType allMasks = 0;            // Value to mask to catch all masked bits (to set MARK)
     50    psImageMaskType allMasks = 0;            // Value to mask to catch all masked bits (to set MARK)
    5151
    5252    int nMasks = sizeof (masks) / sizeof (pmConfigMaskInfo);
     
    5555        bool mdok;                      // Status of MD lookup
    5656        psImageMaskType value = psMetadataLookupImageMaskFromGeneric(&mdok, source, masks[i].badMaskName); // Value of mask
    57         if (!mdok) {
    58             psWarning ("problem with mask value %s\n", masks[i].badMaskName);
    59         }
     57        if (!mdok) {
     58            psWarning ("problem with mask value %s\n", masks[i].badMaskName);
     59        }
    6060
    6161        if (!value) {
    62             if (masks[i].fallbackName) {
    63                 value = psMetadataLookupImageMaskFromGeneric(&mdok, source, masks[i].fallbackName);
    64             }
    65             if (!value) {
    66                 value = masks[i].defaultMaskValue;
    67             }
    68             psMetadataAddImageMask(source, PS_LIST_TAIL, masks[i].badMaskName, PS_META_REPLACE, NULL, value);
    69         }
    70         if (masks[i].isBad) {
    71             maskValue |= value;
    72         }
    73         allMasks |= value;
     62            if (masks[i].fallbackName) {
     63                value = psMetadataLookupImageMaskFromGeneric(&mdok, source, masks[i].fallbackName);
     64            }
     65            if (!value) {
     66                value = masks[i].defaultMaskValue;
     67            }
     68            psMetadataAddImageMask(source, PS_LIST_TAIL, masks[i].badMaskName, PS_META_REPLACE, NULL, value);
     69        }
     70        if (masks[i].isBad) {
     71            maskValue |= value;
     72        }
     73        allMasks |= value;
    7474    }
    7575
     
    107107// Get a mask value by name(s)
    108108psImageMaskType pmConfigMaskGetFromMetadata(psMetadata *source, // Source of masks
    109                                             const char *masks // Mask values to get
     109                                            const char *masks // Mask values to get
    110110    )
    111111{
     
    139139}
    140140
    141 // lookup an image mask value by name from a psMetadata, without requiring the entry to 
     141// lookup an image mask value by name from a psMetadata, without requiring the entry to
    142142// be of type psImageMaskType, but verifying that it will fit in psImageMaskType
    143 psImageMaskType psMetadataLookupImageMaskFromGeneric (bool *status, const psMetadata *md, const char *name) {
    144 
     143psImageMaskType psMetadataLookupImageMaskFromGeneric(bool *status, const psMetadata *md, const char *name)
     144{
     145    if (!md) {
     146        psError(PS_ERR_UNEXPECTED_NULL, true, "Metadata is NULL.");
     147        if (status) {
     148            *status = false;
     149        }
     150        return 0;
     151    }
     152    if (!name) {
     153        psError(PS_ERR_UNEXPECTED_NULL, true, "Keyword is NULL.");
     154        if (status) {
     155            *status = false;
     156        }
     157        return 0;
     158    }
    145159    *status = true;
    146160
    147         // select the mask bit name from the header
    148         psMetadataItem *item = psMetadataLookup (md, name);
    149         if (!item) {
    150             psWarning("Unable to find header keyword %s when parsing mask", name);
    151             *status = false;
    152             return 0;
    153         }
    154 
    155         // the value may be any of the U8, U16, U32, U64 types : accept the value regardless of type size
    156         psU64 fullValue = 0;
    157         switch (item->type) {
    158           case PS_DATA_U8:
    159             fullValue = item->data.U8;
    160             break;
    161           case PS_DATA_U16:
    162             fullValue = item->data.U16;
    163             break;
    164           case PS_DATA_U32:
    165             fullValue = item->data.U32;
    166             break;
    167           case PS_DATA_U64:
    168             fullValue = item->data.U64;
    169             break;
    170           case PS_DATA_S8:
    171             fullValue = item->data.S8;
    172             break;
    173           case PS_DATA_S16:
    174             fullValue = item->data.S16;
    175             break;
    176           case PS_DATA_S32:
    177             fullValue = item->data.S32;
    178             break;
    179           case PS_DATA_S64:
    180             fullValue = item->data.S64;
    181             break;
    182           default:
    183             psWarning("Mask entry %s in metadata is not of a mask type", name);
    184             *status = false;
    185             return 0;
    186         }
    187 
    188         // will the incoming value fit within the current image mask type?
    189         if (fullValue > PS_MAX_IMAGE_MASK_TYPE) {
    190             psWarning("Mask entry %s in metadata is larger than allowed by the psImageMaskType", name);
    191             *status = false;
    192             return 0;
    193         }
    194         psImageMaskType value = fullValue;
    195         // XXX validate that value is a 2^n value?
    196 
    197         return value;
     161    // select the mask bit name from the header
     162    psMetadataItem *item = psMetadataLookup(md, name);
     163    if (!item) {
     164        if (status) {
     165            *status = false;
     166        } else {
     167            psError(PS_ERR_BAD_PARAMETER_VALUE, "Unable to find keyword %s when parsing mask", name);
     168        }
     169        return 0;
     170    }
     171
     172    // the value may be any of the U8, U16, U32, U64 types : accept the value regardless of type size
     173    psU64 fullValue = 0;
     174    switch (item->type) {
     175      case PS_DATA_U8:
     176        fullValue = item->data.U8;
     177        break;
     178      case PS_DATA_U16:
     179        fullValue = item->data.U16;
     180        break;
     181      case PS_DATA_U32:
     182        fullValue = item->data.U32;
     183        break;
     184      case PS_DATA_U64:
     185        fullValue = item->data.U64;
     186        break;
     187      case PS_DATA_S8:
     188        fullValue = item->data.S8;
     189        break;
     190      case PS_DATA_S16:
     191        fullValue = item->data.S16;
     192        break;
     193      case PS_DATA_S32:
     194        fullValue = item->data.S32;
     195        break;
     196      case PS_DATA_S64:
     197        fullValue = item->data.S64;
     198        break;
     199      default:
     200        if (status) {
     201            *status = false;
     202        } else {
     203            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     204                    "Mask entry %s in metadata is not of a mask type", name);
     205        }
     206        return 0;
     207    }
     208
     209    // will the incoming value fit within the current image mask type?
     210    if (fullValue > PS_MAX_IMAGE_MASK_TYPE) {
     211        if (status) {
     212            *status = false;
     213        } else {
     214            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     215                    "Mask entry %s in metadata is larger than allowed by the psImageMaskType", name);
     216        }
     217        return 0;
     218    }
     219    psImageMaskType value = fullValue;
     220    // XXX validate that value is a 2^n value?
     221
     222    return value;
    198223}
    199224
    200225// Remove from the header keywords starting with the provided string
    201226int pmConfigMaskRemoveHeaderKeywords(psMetadata *header, // Header from which to remove keywords
    202                                      const char *start // Remove keywords that start with this string
     227                                     const char *start // Remove keywords that start with this string
    203228    )
    204229{
     
    229254        return 0;
    230255    }
    231    
     256
    232257    psImageMaskType mask = pmConfigMaskGetFromMetadata (recipe, masks);
    233258    return mask;
     
    274299    }
    275300
    276     // How many mask values do we need to read?  We raise an error if this is not found, 
     301    // How many mask values do we need to read?  We raise an error if this is not found,
    277302    // unless the MASK.FORCE is set to true in the camera config
    278303    int nMask = psMetadataLookupS32(&status, header, "MSKNUM");
     
    300325        }
    301326
    302         psImageMaskType headerValue = psMetadataLookupImageMaskFromGeneric (&status, header, valuekey);
    303         if (!status) {
     327        psImageMaskType headerValue = psMetadataLookupImageMaskFromGeneric (&status, header, valuekey);
     328        if (!status) {
    304329            psWarning("Failed to get mask value %s from header, skipping", valuekey);
    305             continue;
    306         }           
    307 
    308         // since we may read multiple mask files, we need to warn (or error?) if any of the
    309         // header mask values conflict with other header mask values; However, the original
    310         // mask values from the recipe do not need to match the header values.
    311 
    312         // when we add a header mask value, we will also add the NAME.ALREADY entry; check for
    313         // the NAME.ALREADY entry to see if we have previously added this mask value from a
    314         // header.
     330            continue;
     331        }
     332
     333        // since we may read multiple mask files, we need to warn (or error?) if any of the
     334        // header mask values conflict with other header mask values; However, the original
     335        // mask values from the recipe do not need to match the header values.
     336
     337        // when we add a header mask value, we will also add the NAME.ALREADY entry; check for
     338        // the NAME.ALREADY entry to see if we have previously added this mask value from a
     339        // header.
    315340
    316341        psString nameAlready = NULL;    // Name of key with ".ALREADY" added
     
    318343        bool already = psMetadataLookupBool(&status, recipe, nameAlready); // Already read this one?
    319344
    320         bool inRecipe = false;
    321         psImageMaskType recipeValue = psMetadataLookupImageMaskFromGeneric (&inRecipe, recipe, name);
    322         if (!inRecipe) {
     345        bool inRecipe = false;
     346        psImageMaskType recipeValue = psMetadataLookupImageMaskFromGeneric (&inRecipe, recipe, name);
     347        if (!inRecipe) {
    323348            psWarning("Mask value %s is not defined in the recipe", name);
    324         }           
     349        }
    325350
    326351        if (already) {
    327             assert (inRecipe); // XXX makes no sense for NAME.ALREADY to be in without NAME
     352            assert (inRecipe); // XXX makes no sense for NAME.ALREADY to be in without NAME
    328353            if (recipeValue != headerValue) {
    329354                psWarning("New mask header value does not match previously loaded entry: %x vs %x", headerValue, recipeValue);
    330                 psMetadataAddImageMask(recipe, PS_LIST_TAIL, name, PS_META_REPLACE, "Bitmask bit value", headerValue);
    331                 // XXX alternatively, error here
     355                psMetadataAddImageMask(recipe, PS_LIST_TAIL, name, PS_META_REPLACE, "Bitmask bit value", headerValue);
     356                // XXX alternatively, error here
    332357            }
    333358        } else {
     
    369394    while ((item = psMetadataGetAndIncrement(iter))) {
    370395
    371         // XXX this would give a false positive for mask which include '.ALREADY' in their names
    372         char *ptr = strstr (item->name, ".ALREADY");
    373         if (ptr) continue;
    374 
    375         psU64 fullValue = 0;
     396        // XXX this would give a false positive for mask which include '.ALREADY' in their names
     397        char *ptr = strstr (item->name, ".ALREADY");
     398        if (ptr) continue;
     399
     400        psU64 fullValue = 0;
    376401        switch (item->type) {
    377           case PS_DATA_U8:
    378             fullValue = item->data.U8;
    379             break;
    380           case PS_DATA_U16:
    381             fullValue = item->data.U16;
    382             break;
    383           case PS_DATA_U32:
    384             fullValue = item->data.U32;
    385             break;
    386           case PS_DATA_U64:
    387             fullValue = item->data.U64;
    388             break;
    389           default:
     402          case PS_DATA_U8:
     403            fullValue = item->data.U8;
     404            break;
     405          case PS_DATA_U16:
     406            fullValue = item->data.U16;
     407            break;
     408          case PS_DATA_U32:
     409            fullValue = item->data.U32;
     410            break;
     411          case PS_DATA_U64:
     412            fullValue = item->data.U64;
     413            break;
     414          default:
    390415            psWarning("mask recipe entry %s is not a bit value\n", item->name);
    391416            continue;
    392417        }
    393         assert (fullValue <= PS_MAX_IMAGE_MASK_TYPE); // this should have been asserted on read...
     418        assert (fullValue <= PS_MAX_IMAGE_MASK_TYPE); // this should have been asserted on read...
    394419
    395420        snprintf(namekey,  64, "MSKNAM%02d", nMask);
Note: See TracChangeset for help on using the changeset viewer.