IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18632


Ignore:
Timestamp:
Jul 20, 2008, 1:06:21 PM (18 years ago)
Author:
eugene
Message:

mask the cosmic rays

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080719/psphot/src/psphotSourceSize.c

    r17396 r18632  
    1010// deviation from the psf model at the r = FWHM/2 position
    1111
    12 bool psphotSourceSize (pmReadout *readout, psArray *sources, psMetadata *recipe, long first) {
     12bool psphotSourceSize (pmConfig *config, pmReadout *readout, psArray *sources, psMetadata *recipe, long first) {
    1313
    1414    bool status;
    1515
    1616    psTimerStart ("psphot");
     17
     18    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     19    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     20    assert (maskVal);
     21
     22    // bit to mask the cosmic-ray pixels
     23    psMaskType crMask  = pmConfigMaskGet("CR", config); // Mask value for cosmic rays
    1724
    1825    float CR_NSIGMA_LIMIT = psMetadataLookupF32 (&status, recipe, "PSPHOT.CR.NSIGMA.LIMIT");
     
    129136        }
    130137
     138        // this source is thought to be a cosmic ray.  flag the detection and mask the pixels
    131139        if (source->crNsigma > CR_NSIGMA_LIMIT) {
    132           source->mode |= PM_SOURCE_MODE_CR_LIMIT;
     140            source->mode |= PM_SOURCE_MODE_CR_LIMIT;
     141            pmPeak *peak = source->peak;
     142            psAssert (peak, "NULL peak");
     143
     144            // replace the source flux
     145            pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     146            source->mode &= ~PM_SOURCE_MODE_SUBTRACTED;
     147
     148            psImage *mask   = source->maskView;
     149            psImage *pixels = source->pixels;
     150            psImage *weight = source->weight;
     151
     152            # define SN_LIMIT 5.0
     153
     154            int xo = peak->x - pixels->col0;
     155            int yo = peak->y - pixels->row0;
     156
     157            // mark the pixels in this row to the left, then the right
     158            for (int ix = xo; ix >= 0; ix--) {
     159                float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);
     160                if (SN > SN_LIMIT) {
     161                    mask->data.U8[yo][ix] |= crMask;
     162                }
     163            }
     164            for (int ix = xo + 1; ix < pixels->numCols; ix++) {
     165                float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);
     166                if (SN > SN_LIMIT) {
     167                    mask->data.U8[yo][ix] |= crMask;
     168                }
     169            }
     170
     171            // for each of the neighboring rows, mark the high pixels if they have a marked neighbor
     172            // first go up:
     173            for (int iy = yo; iy >= 0; iy--) {
     174                // mark the pixels in this row to the left, then the right
     175                for (int ix = 0; ix < pixels->numCols; ix++) {
     176                    float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]);
     177                    if (SN < SN_LIMIT) continue;
     178                   
     179                    bool valid = false;
     180                    valid |= (mask->data.U8[iy+1][ix] & crMask);
     181                    valid |= (ix > 0) ? (mask->data.U8[iy+1][ix-1] & crMask) : 0;
     182                    valid |= (ix <= mask->numCols) ? (mask->data.U8[iy+1][ix+1] & crMask) : 0;
     183
     184                    if (!valid) continue;
     185                    mask->data.U8[iy][ix] |= crMask;
     186                }
     187            }
     188            // next go down:
     189            for (int iy = yo+1; iy < pixels->numRows; iy++) {
     190                // mark the pixels in this row to the left, then the right
     191                for (int ix = 0; ix < pixels->numCols; ix++) {
     192                    float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]);
     193                    if (SN < SN_LIMIT) continue;
     194                   
     195                    bool valid = false;
     196                    valid |= (mask->data.U8[iy-1][ix] & crMask);
     197                    valid |= (ix > 0) ? (mask->data.U8[iy-1][ix-1] & crMask) : 0;
     198                    valid |= (ix <= mask->numCols) ? (mask->data.U8[iy-1][ix+1] & crMask) : 0;
     199
     200                    if (!valid) continue;
     201                    mask->data.U8[iy][ix] |= crMask;
     202                }
     203            }
    133204        }
    134205    }
Note: See TracChangeset for help on using the changeset viewer.