IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42293


Ignore:
Timestamp:
Sep 27, 2022, 5:08:10 PM (4 years ago)
Author:
tdeboer
Message:

adding CTE detection functionality and new CTE source flag

Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippconfig/recipes/ppImage.config

    r41898 r42293  
    2121APPLY.BURNTOOL     BOOL    FALSE           # apply burntool coorection
    2222APPLY.PIXELZERO    BOOL    FALSE           # apply zero'ing of pixels underneath masks
     23DETECT.CTE         BOOL    FALSE           # perform object detections in the CTE regions
    2324VARIANCE.BUILD     BOOL    FALSE           # Build internal variance image
    2425ADDNOISE           BOOL    FALSE           # Add noise to degrade an MD image to a 3pi image?
  • trunk/ippconfig/recipes/pswarp.config

    r42100 r42293  
    1313SOURCES                 BOOL    TRUE            # Write source list for warped image?
    1414APPLY.PIXELNAN          BOOL    FALSE           # Apply NAN'ing of pixels underneath masks
     15DETECT.CTE              BOOL    FALSE           # perform object detections in the CTE regions
    1516
    1617# as of r41891, dvoImageOverlaps compares the header keyword CERSTD to MAX.CERROR
  • trunk/ppImage/src/ppImage.h

    r41894 r42293  
    156156ppImageOptions *ppImageParseCamera(pmConfig *config);
    157157bool ppImageSetMaskBits (pmConfig *config, ppImageOptions *options);
     158bool ppImageMaskSetInMetadata(psImageMaskType *outMaskValue, // Value of MASK.VALUE, returned
     159                               psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned
     160                               psMetadata *source  // Source of mask bits
     161  );
    158162
    159163// apply the cell flips to the input data before analysis
  • trunk/ppImage/src/ppImageSetMaskBits.c

    r37406 r42293  
    55#include "ppImage.h"
    66
     7// Structure to hold the properties of a mask value
     8typedef struct {
     9    char *badMaskName;                  // name for "bad" (i.e., mask me please) pixels
     10    char *fallbackName;                 // Fallback name in case a bad mask name is not defined
     11    psImageMaskType defaultMaskValue;   // Default value in case a bad mask name and its fallback are not defined
     12    bool isBad; // include this value as part of the MASK.VALUE entry (generically bad)
     13} pmConfigMaskInfo;
     14
     15static pmConfigMaskInfo ppimagemasks[] = {
     16    // Features of the detector
     17    { "DETECTOR",  NULL,       0x01, true }, // Something is wrong with the detector
     18    { "FLAT",      "DETECTOR", 0x01, true }, // Pixel doesn't flat-field properly
     19    { "DARK",      "DETECTOR", 0x01, true }, // Pixel doesn't dark-subtract properly
     20    { "BLANK",     "DETECTOR", 0x01, true }, // Pixel doesn't contain valid data
     21    { "CTE",       "DETECTOR", 0x01, false }, // Pixel has poor CTE
     22    { "BURNTOOL",  NULL,       0x04, false }, // Pixel has been touched by burntool
     23    // Invalid signal ranges
     24    { "SAT",       NULL,       0x02, true  }, // Pixel is saturated or non-linear
     25    { "LOW",       "SAT",      0x02, true  }, // Pixel is low
     26    { "SUSPECT",   NULL,       0x04, false }, // Pixel is suspected of being bad
     27    // Non-astronomical structures
     28    { "CR",        NULL,       0x08, true  }, // Pixel contains a cosmic ray
     29    { "SPIKE",     NULL,       0x08, false  }, // Pixel contains a diffraction spike
     30    { "GHOST",     NULL,       0x08, false  }, // Pixel contains an optical ghost
     31    { "STREAK",    NULL,       0x08, false  }, // Pixel contains a streak
     32    { "CROSSTALK", NULL,       0x08, false  }, // Pixel contains crosstalk data
     33    { "STARCORE",  NULL,       0x08, false  }, // Pixel contains a bright star core
     34    // Effects of convolution and interpolation
     35    { "CONV.BAD",  NULL,       0x02, true  }, // Pixel is bad after convolution with a bad pixel
     36    { "CONV.POOR", NULL,       0x04, false }, // Pixel is poor after convolution with a bad pixel
     37};
     38
    739bool ppImageSetMaskBits (pmConfig *config, ppImageOptions *options) {
    840
    9     if (!pmConfigMaskSetBits(&options->maskValue, &options->markValue, config)) {
    10         psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
    11         return false;
     41
     42    // Look up recipe values
     43    psMetadata *pprecipe = psMetadataLookupMetadata(NULL, config->recipes, RECIPE_NAME);
     44
     45    psAssert(pprecipe, "We checked this earlier, so it should be here.");
     46    bool doDetectCTE = psMetadataLookupBool(NULL, pprecipe, "DETECT.CTE"); // Do detections on pixels underneath CTE masks
     47
     48    // this function sets the required single-image mask bits
     49    if(!doDetectCTE) {
     50      if (!pmConfigMaskSetBits (&options->maskValue, &options->markValue, config)) {
     51          psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
     52          return false;
     53      }
     54    } else {
     55      psMetadata *maskrecipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
     56      if (!maskrecipe) {
     57          psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
     58          return false;
     59      }
     60      if (!ppImageMaskSetInMetadata(&options->maskValue, &options->markValue, maskrecipe)) {
     61          psError (PS_ERR_UNKNOWN, true, "Unable to determine the mask value");
     62          return false;
     63      }
    1264    }
    1365
     
    63115    return true;
    64116}
     117
     118
     119bool ppImageMaskSetInMetadata(psImageMaskType *outMaskValue, // Value of MASK.VALUE, returned
     120                               psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned
     121                               psMetadata *source  // Source of mask bits
     122    )
     123{
     124    PS_ASSERT_METADATA_NON_NULL(source, false);
     125
     126    // Ensure all the bad mask names exist, and set the value to catch all bad pixels
     127    psImageMaskType maskValue = 0;           // Value to mask to catch all the bad pixels
     128    psImageMaskType allMasks = 0;            // Value to mask to catch all masked bits (to set MARK)
     129
     130    int nMasks = sizeof (ppimagemasks) / sizeof (pmConfigMaskInfo);
     131
     132    for (int i = 0; i < nMasks; i++) {
     133        bool mdok;                      // Status of MD lookup
     134        psImageMaskType value = psMetadataLookupImageMaskFromGeneric(&mdok, source, ppimagemasks[i].badMaskName); // Value of mask
     135        if (!mdok) {
     136            psWarning ("problem with mask value %s\n", ppimagemasks[i].badMaskName);
     137        }
     138
     139        if (!value) {
     140            if (ppimagemasks[i].fallbackName) {
     141                value = psMetadataLookupImageMaskFromGeneric(&mdok, source, ppimagemasks[i].fallbackName);
     142            }
     143            if (!value) {
     144                value = ppimagemasks[i].defaultMaskValue;
     145            }
     146            psMetadataAddImageMask(source, PS_LIST_TAIL, ppimagemasks[i].badMaskName, PS_META_REPLACE, NULL, value);
     147        }
     148        if (ppimagemasks[i].isBad) {
     149            maskValue |= value;
     150        }
     151        allMasks |= value;
     152    }
     153
     154    // search for an unset bit to use for MARK:
     155    psImageMaskType markValue = 0x00;
     156    psImageMaskType markTrial = 0x01;
     157
     158    int nBits = sizeof(psImageMaskType) * 8;
     159    for (int i = 0; !markValue && (i < nBits); i++) {
     160        if (allMasks & markTrial) {
     161            markTrial <<= 1;
     162        } else {
     163            markValue = markTrial;
     164        }
     165    }
     166    if (!markValue) {
     167        psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
     168        return false;
     169    }
     170
     171    // update the list with the results
     172    psMetadataAddImageMask(source, PS_LIST_TAIL, "MASK.VALUE", PS_META_REPLACE, NULL, maskValue);
     173    psMetadataAddImageMask(source, PS_LIST_TAIL, "MARK.VALUE", PS_META_REPLACE, NULL, markValue);
     174
     175    if (outMaskValue) {
     176        *outMaskValue = maskValue;
     177    }
     178    if (outMarkValue) {
     179        *outMarkValue = markValue;
     180    }
     181
     182    return true;
     183}
     184
  • trunk/ppSub/src/ppSubSetMasks.c

    r41707 r42293  
    3232static pmConfigMaskInfo skycellmasks[] = {
    3333    // Features of the detector
    34     { "DETECTOR",  NULL,       0x01, false }, // Something is wrong with the detector
    35     { "FLAT",      "DETECTOR", 0x01, false }, // Pixel doesn't flat-field properly
    36     { "DARK",      "DETECTOR", 0x01, false }, // Pixel doesn't dark-subtract properly
     34    { "DETECTOR",  NULL,       0x01, true }, // Something is wrong with the detector
     35    { "FLAT",      "DETECTOR", 0x01, true }, // Pixel doesn't flat-field properly
     36    { "DARK",      "DETECTOR", 0x01, true }, // Pixel doesn't dark-subtract properly
    3737    { "BLANK",     "DETECTOR", 0x01, true }, // Pixel doesn't contain valid data
    3838    { "CTE",       "DETECTOR", 0x01, false }, // Pixel has poor CTE
  • trunk/psModules/src/objects/pmSourceMasks.h

    r41705 r42293  
    7272    PM_SOURCE_MODE2_ON_GHOST              = 0x00800000, ///< > 25% of (PSF-weighted) pixels land on ghost
    7373    PM_SOURCE_MODE2_ON_CROSSTALK          = 0x01000000, ///< peaks land on electronic crostalk
     74    PM_SOURCE_MODE2_ON_CTE                = 0x02000000, ///< peaks land on CTE region
    7475
    7576   
  • trunk/psModules/src/objects/pmSourcePhotometry.c

    r41705 r42293  
    5353
    5454// make this a bit more clever and dynamic
    55 static psImageMaskType maskSuspect  = 0;
    56 static psImageMaskType maskSpike    = 0;
    57 static psImageMaskType maskStarCore = 0;
    58 static psImageMaskType maskBurntool = 0;
    59 static psImageMaskType maskConvPoor = 0;
    60 static psImageMaskType maskGhost    = 0;
    61 static psImageMaskType maskGlint    = 0;
    62 static psImageMaskType maskCrosstalk    = 0;
     55static psImageMaskType maskSuspect   = 0;
     56static psImageMaskType maskSpike     = 0;
     57static psImageMaskType maskStarCore  = 0;
     58static psImageMaskType maskBurntool  = 0;
     59static psImageMaskType maskConvPoor  = 0;
     60static psImageMaskType maskGhost     = 0;
     61static psImageMaskType maskGlint     = 0;
     62static psImageMaskType maskCrosstalk = 0;
     63static psImageMaskType maskCTE       = 0;
    6364
    6465bool pmSourceMagnitudesInit (pmConfig *config, psMetadata *recipe)
     
    6970    // we are going to test specially against these poor values
    7071    if (config) {
    71         maskSpike    = pmConfigMaskGet("SPIKE", config);
    72         maskStarCore = pmConfigMaskGet("STARCORE", config);
    73         maskBurntool = pmConfigMaskGet("BURNTOOL", config);
    74         maskConvPoor = pmConfigMaskGet("CONV.POOR", config);
    75         maskGhost    = pmConfigMaskGet("GHOST", config);
    76         maskGlint    = pmConfigMaskGet("GHOST", config);
    77         maskCrosstalk    = pmConfigMaskGet("CROSSTALK", config);
    78         maskSuspect  = maskSpike | maskStarCore | maskBurntool | maskConvPoor;
     72        maskSpike     = pmConfigMaskGet("SPIKE", config);
     73        maskStarCore  = pmConfigMaskGet("STARCORE", config);
     74        maskBurntool  = pmConfigMaskGet("BURNTOOL", config);
     75        maskConvPoor  = pmConfigMaskGet("CONV.POOR", config);
     76        maskGhost     = pmConfigMaskGet("GHOST", config);
     77        maskGlint     = pmConfigMaskGet("GHOST", config);
     78        maskCrosstalk = pmConfigMaskGet("CROSSTALK", config);
     79        maskCTE       = pmConfigMaskGet("CTE", config);
     80        maskSuspect   = maskSpike | maskStarCore | maskBurntool | maskConvPoor;
    7981    }
    8082
     
    440442    float convpoorSum = 0;
    441443    float ghostSum = 0;
     444    float cteSum = 0;
    442445
    443446    int Xo, Yo, dP;
     
    534537                convpoorSum += value;
    535538            }
     539            // count pixels which are masked with an mask bit (bad or poor)
     540            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskCTE) {
     541                cteSum += value;
     542            }
     543
    536544        }
    537545    }
     
    555563    if ((convpoorSum/modelSum) > 0.25) {
    556564        source->mode2 |= PM_SOURCE_MODE2_ON_CONVPOOR;
     565    }
     566    if ((cteSum/modelSum) > 0.25) {
     567        source->mode2 |= PM_SOURCE_MODE2_ON_CTE;
    557568    }
    558569
     
    614625    float convpoorSum = 0;
    615626    float ghostSum = 0;
     627    float cteSum = 0;
    616628
    617629    int Xo, Yo, dP;
     
    683695                convpoorSum += 1.;
    684696            }
     697            // count pixels which are masked with an mask bit (bad or poor)
     698            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskCTE) {
     699                cteSum += 1.;
     700            }
    685701        }
    686702    }
     
    701717    if ((convpoorSum/modelSum) > 0.25) {
    702718        source->mode2 |= PM_SOURCE_MODE2_ON_CONVPOOR;
     719    }
     720    if ((cteSum/modelSum) > 0.25) {
     721        source->mode2 |= PM_SOURCE_MODE2_ON_CTE;
    703722    }
    704723
  • trunk/psastro/src/psastroConvert.c

    r41895 r42293  
    1818# define PHOT_SOURCE_MASK (PM_SOURCE_MODE_FAIL | PM_SOURCE_MODE_BLEND | PM_SOURCE_MODE_BADPSF | \
    1919                           PM_SOURCE_MODE_DEFECT | PM_SOURCE_MODE_CR_LIMIT | PM_SOURCE_MODE_EXT_LIMIT | \
    20                            PM_SOURCE_MODE_POOR) // Mask to apply to sources for rejection
     20                           PM_SOURCE_MODE_POOR ) // Mask to apply to sources for rejection
    2121
    2222static psArray *chooseStars(psArray *inStars, char *listName, psArray *sources, psVector *index, int nMax, float iMagMin, float iMagMax, pmSourceMode skip);
     
    193193    int nBrightSkip = 0;
    194194    int nInfSkip = 0;
     195    int nCTESkip = 0;
    195196
    196197    for (int i = 0; (i < inStars->n) && (j < rawStars->n); i++) {
     
    217218          continue;
    218219        }
     220        //Also kick out stars that touch the CTE region
     221        if (source->mode2 & PM_SOURCE_MODE2_ON_CTE) {
     222            nCTESkip ++;
     223            continue;
     224        }
     225       
    219226        mMin = PS_MIN (mMin, source->psfMag);
    220227        mMax = PS_MAX (mMax, source->psfMag);
     
    225232
    226233    psLogMsg ("psastro", 4, "loaded %ld %ssources, using %ld of %ld good sources (inst mag: %f to %f)\n", sources->n, listName, rawStars->n, inStars->n, mMin, mMax);
    227     psLogMsg ("psastro", 4, "skip reasons: mode: %d, faint: %d, bright: %d, inf: %d\n", nModeSkip, nFaintSkip, nBrightSkip, nInfSkip);
     234    psLogMsg ("psastro", 4, "skip reasons: mode: %d, faint: %d, bright: %d, inf: %d, CTE: %d\n", nModeSkip, nFaintSkip, nBrightSkip, nInfSkip,nCTESkip);
    228235
    229236    return rawStars;
     
    509516  float myPltScale = fabs(pltScale[chipID]);
    510517
     518  psLogMsg ("psastro.correctKH", PS_LOG_INFO, "applying KH correction to %s (%d)\n", chipName, chipID);
     519
    511520  // apply the correction to the detections
    512521  for (int i = 0; i < inStars->n; i++) {
  • trunk/pswarp/src/pswarpSetMaskBits.c

    r27096 r42293  
    2020 * updated in the config metadata.
    2121 */
     22 
    2223bool pswarpSetMaskBits (pmConfig *config)
    2324{
     
    2627    psImageMaskType maskOut = 0x00;                     // mask for the output image
    2728
     29    // Look up recipe values
     30    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PSWARP_RECIPE); // Recipe for ppSim
     31    psAssert(recipe, "We checked this earlier, so it should be here.");
     32    bool doDetectCTE = psMetadataLookupBool(NULL, recipe, "DETECT.CTE"); // Do detections on pixels underneath CTE masks
     33
    2834    // this function sets the required single-image mask bits
    29     if (!pmConfigMaskSetBits (&maskIn, &markIn, config)) {
    30         psError (psErrorCodeLast(), false, "Unable to define the mask bit values");
    31         return false;
     35    if(!doDetectCTE) {
     36      if (!pmConfigMaskSetBits (&maskIn, &markIn, config)) {
     37          psError (psErrorCodeLast(), false, "Unable to define the mask bit values");
     38          return false;
     39      }
     40    } else {
     41      psMetadata *maskrecipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
     42      if (!maskrecipe) {
     43          psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
     44          return false;
     45      }
     46      if (!pswarpMaskSetInMetadata(&maskIn, &markIn, maskrecipe)) {
     47          psError (psErrorCodeLast(), false, "Unable to determine the mask value");
     48          return false;
     49      }
    3250    }
    33 
     51   
    3452    // mask for non-linear flat regions (default to DETECTOR if not defined)
    3553    psImageMaskType badMask = pmConfigMaskGet("CONV.BAD", config);
Note: See TracChangeset for help on using the changeset viewer.