IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 8, 2021, 9:47:22 AM (5 years ago)
Author:
eugene
Message:

reintegrate changes from tag ipp-ps1-20210510

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/pswarp/src/pswarpTransformReadout.c

    r41526 r41705  
    1313#include "pswarp.h"
    1414
     15// Structure to hold the properties of a mask value
     16typedef struct {
     17    char *badMaskName;                  // name for "bad" (i.e., mask me please) pixels
     18    char *fallbackName;                 // Fallback name in case a bad mask name is not defined
     19    psImageMaskType defaultMaskValue;   // Default value in case a bad mask name and its fallback are not defined
     20    bool isBad; // include this value as part of the MASK.VALUE entry (generically bad)
     21} pmConfigMaskInfo;
     22
     23static pmConfigMaskInfo warp_convolve_masks[] = {
     24    // Features of the detector
     25    { "DETECTOR",  NULL,       0x01, true }, // Something is wrong with the detector
     26    { "FLAT",      "DETECTOR", 0x01, true }, // Pixel doesn't flat-field properly
     27    { "DARK",      "DETECTOR", 0x01, true }, // Pixel doesn't dark-subtract properly
     28    { "BLANK",     "DETECTOR", 0x01, true }, // Pixel doesn't contain valid data
     29    { "CTE",       "DETECTOR", 0x01, false }, // Pixel has poor CTE
     30    { "BURNTOOL",  NULL,       0x04, false }, // Pixel has been touched by burntool
     31    // Invalid signal ranges
     32    { "SAT",       NULL,       0x02, true  }, // Pixel is saturated or non-linear
     33    { "LOW",       "SAT",      0x02, true  }, // Pixel is low
     34    { "SUSPECT",   NULL,       0x04, false }, // Pixel is suspected of being bad
     35    // Non-astronomical structures
     36    { "CR",        NULL,       0x08, true  }, // Pixel contains a cosmic ray
     37    { "SPIKE",     NULL,       0x08, false  }, // Pixel contains a diffraction spike
     38    { "GHOST",     NULL,       0x08, false  }, // Pixel contains an optical ghost
     39    { "CROSSTALK", NULL,       0x08, false  }, // Pixel contains crosstalk data
     40    { "STARCORE",  NULL,       0x08, false  }, // Pixel contains a bright star core
     41    // Effects of convolution and interpolation
     42    { "CONV.BAD",  NULL,       0x02, true  }, // Pixel is bad after convolution with a bad pixel
     43    { "CONV.POOR", NULL,       0x04, false }, // Pixel is poor after convolution with a bad pixel
     44};
     45
    1546/**
    1647 * NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT
     
    4475      psAssert(mdok, "MASK.INPUT was not defined");
    4576    }
     77    else {
     78      psMetadata *maskrecipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
     79      if (!maskrecipe) {
     80          psError(psErrorCodeLast(), false, "Unable to find MASKS recipe.");
     81          return false;
     82      }
     83      if (!pswarpMaskSetInMetadata(&maskIn, NULL, maskrecipe)) {
     84          psError(psErrorCodeLast(), false, "Unable to determine mask value.");
     85          return false;
     86      }
     87    }
    4688    psImageMaskType maskPoor = pmConfigMaskGet("CONV.POOR", config);
    4789    if (!maskPoor) {
     
    229271    return true;
    230272}
     273
     274bool pswarpMaskSetInMetadata(psImageMaskType *outMaskValue, // Value of MASK.VALUE, returned
     275                               psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned
     276                               psMetadata *source  // Source of mask bits
     277    )
     278{
     279    PS_ASSERT_METADATA_NON_NULL(source, false);
     280
     281    // Ensure all the bad mask names exist, and set the value to catch all bad pixels
     282    psImageMaskType maskValue = 0;           // Value to mask to catch all the bad pixels
     283    psImageMaskType allMasks = 0;            // Value to mask to catch all masked bits (to set MARK)
     284
     285    int nMasks = sizeof (warp_convolve_masks) / sizeof (pmConfigMaskInfo);
     286
     287    for (int i = 0; i < nMasks; i++) {
     288        bool mdok;                      // Status of MD lookup
     289        psImageMaskType value = psMetadataLookupImageMaskFromGeneric(&mdok, source, warp_convolve_masks[i].badMaskName); // Value of mask
     290        if (!mdok) {
     291            psWarning ("problem with mask value %s\n", warp_convolve_masks[i].badMaskName);
     292        }
     293
     294        if (!value) {
     295            if (warp_convolve_masks[i].fallbackName) {
     296                value = psMetadataLookupImageMaskFromGeneric(&mdok, source, warp_convolve_masks[i].fallbackName);
     297            }
     298            if (!value) {
     299                value = warp_convolve_masks[i].defaultMaskValue;
     300            }
     301            psMetadataAddImageMask(source, PS_LIST_TAIL, warp_convolve_masks[i].badMaskName, PS_META_REPLACE, NULL, value);
     302        }
     303        if (warp_convolve_masks[i].isBad) {
     304            maskValue |= value;
     305        }
     306        allMasks |= value;
     307    }
     308
     309    // search for an unset bit to use for MARK:
     310    psImageMaskType markValue = 0x00;
     311    psImageMaskType markTrial = 0x01;
     312
     313    int nBits = sizeof(psImageMaskType) * 8;
     314    for (int i = 0; !markValue && (i < nBits); i++) {
     315        if (allMasks & markTrial) {
     316            markTrial <<= 1;
     317        } else {
     318            markValue = markTrial;
     319        }
     320    }
     321    if (!markValue) {
     322        psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
     323        return false;
     324    }
     325
     326    // update the list with the results
     327    psMetadataAddImageMask(source, PS_LIST_TAIL, "MASK.VALUE", PS_META_REPLACE, NULL, maskValue);
     328    psMetadataAddImageMask(source, PS_LIST_TAIL, "MARK.VALUE", PS_META_REPLACE, NULL, markValue);
     329
     330    if (outMaskValue) {
     331        *outMaskValue = maskValue;
     332    }
     333    if (outMarkValue) {
     334        *outMarkValue = markValue;
     335    }
     336
     337    return true;
     338}
     339
Note: See TracChangeset for help on using the changeset viewer.