IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27440


Ignore:
Timestamp:
Mar 24, 2010, 4:56:11 PM (16 years ago)
Author:
eugene
Message:

updates for source sizes and CR masking

Location:
branches/eam_branches/20100225/psphot
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20100225/psphot/doc/notes.20100131.txt

    r26894 r27440  
     1
     22010.03.24
     3
     4 I have finished another iteration on source size analysis.  I feel
     5 fairly confident of the extended source and CR identifications.  They
     6 are not perfect, but they are in pretty good shape.  The CR IDs use
     7 the moments to find things smaller in one dimension than a PSF, while
     8 the EXT is set for things larger than a PSF in one dimention.
     9
     10 There still seems to be some trouble with SATSTARS : these are being
     11 set for sources which are fainter than the SAT limit -- I'm not sure
     12 if this is due to the quality of the PSF fit or if they really are
     13 SAT, but have integrated fluxes lower than expected (underfitted in
     14 PSF).
    115
    21620100131
  • branches/eam_branches/20100225/psphot/src/psphotSourceSize.c

    r27270 r27440  
    2323bool psphotMaskCosmicRay (pmReadout *readout, pmSource *source, psImageMaskType maskVal);
    2424bool psphotMaskCosmicRayFootprintCheck (psArray *sources);
     25int  psphotMaskCosmicRayConnected (int xPeak, int yPeak, psImage *mymask, psImage *myvar, psImage *edges, int binning, float sigma_thresh);
    2526
    2627// we need to call this function after sources have been fitted to the PSF model and
     
    252253
    253254# define SIZE_SN_LIM 10
    254 
    255255bool psphotSourceClassRegion (psRegion *region, pmPSFClump *psfClump, psArray *sources, psMetadata *recipe, pmPSF *psf, psphotSourceSizeOptions *options) {
    256256
     
    484484
    485485    // XXX test : save the mask image
    486     if (1) {
     486    if (0) {
    487487        psphotSaveImage (NULL, readout->mask,   "mask.fits");
    488488    }
     
    491491}
    492492
     493# define DUMPPICS 0
    493494# define LIMIT_XRANGE(X, IMAGE) { X = PS_MIN(PS_MAX(0, X), IMAGE->numCols); }
    494495# define LIMIT_YRANGE(Y, IMAGE) { Y = PS_MIN(PS_MAX(0, Y), IMAGE->numRows); }
     
    524525    int binning = 2;
    525526    float sigma_thresh = 3.0;
    526     int max_iter = 5;
    527     float noise_factor = 5.0 / 4.0;  // Intrinsic to the Laplacian making noise spikes spikier.
     527    int max_iter = 1; // XXX with isophot masking, we only want to do a single pass
    528528
    529529    // Temporary images.
     
    591591        }
    592592
    593         // Modify my mask if we're above the significance threshold
    594         for (int y = 0; y < dy; y++) {
    595             for (int x = 0; x < dx; x++) {
    596                 if (!(mymask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & 0x01)) continue;
    597 
    598                 float noise = binning * sqrt(noise_factor * myvar->data.F32[y][x]);
    599                 float value = edges->data.F32[y][x] / noise;
    600 
    601                 if (value > sigma_thresh ) {
    602                     mymask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= 0x40;
    603                     nCRpix ++;
    604                 }
    605             }
    606         }
    607 
    608 # if 1
     593        // coordinate of peak in subimage pixels:
     594        int xPeak = peak->x - xs;
     595        int yPeak = peak->y - ys;
     596
     597        // Modify my mask if we're above the significance threshold, but only for connected pixels
     598        nCRpix = psphotMaskCosmicRayConnected (xPeak, yPeak, mymask, myvar, edges, binning, sigma_thresh);
     599       
     600# if DUMPPICS
    609601        psphotSaveImage (NULL, mypix,   "crmask.pix.fits");
    610602# endif
    611 
     603       
     604// XXX do not repair the pixels in isophot version
     605# if 0
    612606        // "Repair" Masked pixels for the next round.
    613607        for (int y = 1; y < dy - 1; y++) {
     
    629623            }
    630624        }
    631 
    632 # if 1
     625# endif
     626
     627# if DUMPPICS
    633628        fprintf (stderr, "CRMASK %d %d %d %d %d\n", xs, ys, dx, dy, iteration);
    634629        psphotSaveImage (NULL, mypix,   "crmask.fix.fits");
     
    642637    }
    643638
     639# if 0
    644640    // A solitary masked pixel is likely a lie. Remove those
    645641    // XXX can't we use nCRpix == 1 to test for these?
     
    662658        }
    663659    }
     660# endif
    664661
    665662    // transfer temporary mask to real mask & count masked pixels
     
    677674    if (nCRpix > 1) {
    678675        source->mode |= PM_SOURCE_MODE_CR_LIMIT;
    679     }
     676        source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;
     677    }
     678    // fprintf (stderr, "CRMASK %d %d %d %d %d\n", peak->x, peak->y, dx, dy, nCRpix);
    680679
    681680    psFree(mypix);
     
    753752}
    754753
     754# define VERBOSE 0
     755int psphotMaskCosmicRayConnected (int xPeak, int yPeak, psImage *mymask, psImage *myvar, psImage *edges, int binning, float sigma_thresh) {
     756   
     757    int xLo, xRo;
     758    int nCRpix = 0;
     759
     760    float noise_factor = 5.0 / 4.0;  // Intrinsic to the Laplacian making noise spikes spikier.
     761   
     762    // mark the pixels in this row to the left, then the right. stay within footprint
     763    int xL = xPeak; // find the range of valid pixels in this row
     764    int xR = xPeak;
     765    for (int ix = xPeak; (ix >= 0) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[yPeak][ix] & 0x01); ix--) {
     766        float noise = binning * sqrt(noise_factor * myvar->data.F32[yPeak][ix]);
     767        float value = edges->data.F32[yPeak][ix] / noise;
     768        if (value < sigma_thresh ) break;
     769        mymask->data.PS_TYPE_IMAGE_MASK_DATA[yPeak][ix] |= 0x40;
     770        xL = ix;
     771        nCRpix ++;
     772        if (VERBOSE) fprintf (stderr, "mark %d,%d (%d) : %d - %d\n", ix, yPeak, nCRpix, xL, xR);
     773    }
     774    for (int ix = xPeak; (ix < mymask->numCols) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[yPeak][ix] & 0x01); ix++) {
     775        float noise = binning * sqrt(noise_factor * myvar->data.F32[yPeak][ix]);
     776        float value = edges->data.F32[yPeak][ix] / noise;
     777        if (value < sigma_thresh ) break;
     778        mymask->data.PS_TYPE_IMAGE_MASK_DATA[yPeak][ix] |= 0x40;
     779        xR = ix;
     780        nCRpix ++;
     781        if (VERBOSE) fprintf (stderr, "mark %d,%d (%d) : %d - %d\n", ix, yPeak, nCRpix, xL, xR);
     782    }
     783    // xL and xR mark the first and last valid pixel in the row
     784
     785    // for each of the neighboring rows, mark the high pixels if they touch the range xL to xR
     786    xLo = PS_MAX(xL - 1, 0);
     787    xRo = PS_MIN(xR + 1, mymask->numCols);
     788
     789    // first go down:
     790    for (int iy = yPeak - 1; iy >= 0; iy--) {
     791
     792        int xLn = -1;
     793        int xRn = -1;
     794        int newPix = 0;
     795
     796        // mark the pixels in the good range
     797        for (int ix = xLo; ix < xRo; ix++) {
     798            if (!(mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01)) continue; // only use pixels in the footprint
     799            float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]);
     800            float value = edges->data.F32[iy][ix] / noise;
     801            if (value < sigma_thresh ) continue;
     802            mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40;
     803            if (xLn == -1) xLn = ix; // first valid pixel in this row
     804            xRn = ix;                // last valid pixel in this row
     805            nCRpix ++;
     806            newPix ++;
     807            if (VERBOSE) fprintf (stderr, "mark C %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn);
     808        }
     809
     810        // mark the pixels to the left of the good range
     811        for (int ix = xLo; (ix >= 0) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01); ix--) {
     812            float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]);
     813            float value = edges->data.F32[iy][ix] / noise;
     814            if (value < sigma_thresh ) break;
     815            mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40;
     816            if (xRn == -1) xRn = ix; // last valid pixel in this row
     817            xLn = ix;
     818            nCRpix ++;
     819            newPix ++;
     820            if (VERBOSE) fprintf (stderr, "mark L %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn);
     821        }
     822
     823        // mark the pixels to the right of the good range
     824        for (int ix = xRo; (ix < mymask->numCols) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01); ix++) {
     825            float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]);
     826            float value = edges->data.F32[iy][ix] / noise;
     827            if (value < sigma_thresh ) break;
     828            mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40;
     829            if (xLn == -1) xLn = ix; // first valid pixel in this row
     830            xRn = ix;
     831            nCRpix ++;
     832            newPix ++;
     833            if (VERBOSE) fprintf (stderr, "mark R %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn);
     834        }
     835        if (newPix == 0) break;
     836        xLo = PS_MAX(xLn - 1, 0);
     837        xRo = PS_MIN(xRn + 1, mymask->numCols);
     838    }
     839
     840    xLo = PS_MAX(xL - 1, 0);
     841    xRo = PS_MIN(xR + 1, mymask->numCols);
     842
     843    // next go up:
     844    for (int iy = yPeak + 1; iy < mymask->numRows; iy++) {
     845
     846        int xLn = -1;
     847        int xRn = -1;
     848        int newPix = 0;
     849
     850        // mark the pixels in the good range
     851        for (int ix = xLo; ix < xRo; ix++) {
     852            if (!(mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01)) continue; // only use pixels in the footprint
     853            float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]);
     854            float value = edges->data.F32[iy][ix] / noise;
     855            if (value < sigma_thresh ) continue;
     856            mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40;
     857            if (xLn == -1) xLn = ix; // first valid pixel in this row
     858            xRn = ix;                // last valid pixel in this row
     859            nCRpix ++;
     860            newPix ++;
     861            if (VERBOSE) fprintf (stderr, "mark C %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn);
     862        }
     863
     864        // mark the pixels to the left of the good range
     865        for (int ix = xLo; (ix >= 0) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01); ix--) {
     866            float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]);
     867            float value = edges->data.F32[iy][ix] / noise;
     868            if (value < sigma_thresh ) break;
     869            mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40;
     870            if (xRn == -1) xRn = ix; // last valid pixel in this row
     871            xLn = ix;
     872            nCRpix ++;
     873            newPix ++;
     874            if (VERBOSE) fprintf (stderr, "mark L %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn);
     875        }
     876
     877        // mark the pixels to the right of the good range
     878        for (int ix = xRo; (ix < mymask->numCols) && (mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & 0x01); ix++) {
     879            float noise = binning * sqrt(noise_factor * myvar->data.F32[iy][ix]);
     880            float value = edges->data.F32[iy][ix] / noise;
     881            if (value < sigma_thresh ) break;
     882            mymask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= 0x40;
     883            if (xLn == -1) xLn = ix; // first valid pixel in this row
     884            xRn = ix;
     885            nCRpix ++;
     886            newPix ++;
     887            if (VERBOSE) fprintf (stderr, "mark R %d,%d (%d) : %d - %d | %d - %d | %d - %d \n", ix, iy, nCRpix, xL, xR, xLo, xRo, xLn, xRn);
     888        }
     889        if (newPix == 0) break;
     890        xLo = PS_MAX(xLn - 1, 0);
     891        xRo = PS_MIN(xRn + 1, mymask->numCols);
     892    }
     893
     894    return nCRpix;
     895}
     896
    755897bool psphotMaskCosmicRayIsophot (pmSource *source, psImageMaskType maskVal, psImageMaskType crMask) {
    756898
  • branches/eam_branches/20100225/psphot/src/psphotVisual.c

    r27268 r27440  
    180180bool psphotVisualShowImage (pmReadout *readout) {
    181181
    182     // if (!pmVisualIsVisual()) return true;
     182    if (!pmVisualIsVisual()) return true;
    183183
    184184    int kapa = psphotKapaChannel (1);
     
    15141514        if (source == NULL) continue;
    15151515
    1516         // if (source->type != type) continue;
    15171516        if (mode) {
    15181517            if (keep) {
     
    15511550bool psphotVisualShowSourceSize (pmReadout *readout, psArray *sources) {
    15521551
    1553     // if (!pmVisualIsVisual()) return true;
     1552    if (!pmVisualIsVisual()) return true;
    15541553
    15551554    int myKapa = psphotKapaChannel (1);
     
    15781577    KapaSection section;
    15791578
    1580     // if (!pmVisualIsVisual()) return true;
     1579    if (!pmVisualIsVisual()) return true;
    15811580
    15821581    int myKapa = psphotKapaChannel (2);
Note: See TracChangeset for help on using the changeset viewer.