IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 19, 2007, 4:22:26 PM (19 years ago)
Author:
Paul Price
Message:

Extensive changes to APIs to allow use of a nominated value to mask
against (the maskVal). Previously, the mask values were either
hard-coded (e.g., PM_MASK_SAT) or taken as anything non-zero. The
code is tested under psphot (which has similar changes) and does not
crash, but neither is it successful in marking all bad pixels (EAM
will investigate). For this reason, I have left the "gutter" pixels
(cell gaps) set to 0 instead of NAN in pmFPAMosaic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSource.c

    r13338 r13898  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-05-10 20:25:05 $
     8 *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-06-20 02:22:26 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    135135    *source->moments = *in->moments;
    136136
    137     // These images are all views to the parent. 
     137    // These images are all views to the parent.
    138138    // We want a new view, but pointing at the same pixels.
    139139    source->pixels   = psImageCopyView (NULL, in->pixels);
     
    143143    // the maskObj is a unique mask array; create a new mask image
    144144    if (in->maskObj) {
    145         source->maskObj = psImageCopy (NULL, in->maskObj, PS_TYPE_MASK);
     145        source->maskObj = psImageCopy (NULL, in->maskObj, PS_TYPE_MASK);
    146146    }
    147147
     
    216216        mySource->region   = newRegion;
    217217
    218         // re-copy the main mask pixels.  NOTE: the user will need to reset the object mask
    219         // pixels (eg, with psImageKeepCircle)
    220         mySource->maskObj = psImageCopy (mySource->maskObj, mySource->maskView, PS_TYPE_MASK);
    221        
    222         // drop the old modelFlux pixels and force the user to re-create
    223         psFree (mySource->modelFlux);
    224         mySource->modelFlux = NULL;
     218        // re-copy the main mask pixels.  NOTE: the user will need to reset the object mask
     219        // pixels (eg, with psImageKeepCircle)
     220        mySource->maskObj = psImageCopy (mySource->maskObj, mySource->maskView, PS_TYPE_MASK);
     221
     222        // drop the old modelFlux pixels and force the user to re-create
     223        psFree (mySource->modelFlux);
     224        mySource->modelFlux = NULL;
    225225    }
    226226    return extend;
     
    233233
    234234// XXX EAM include a S/N cutoff in selecting the sources?
    235 // XXX this function should probably accept the values, not a recipe. wrap with a 
     235// XXX this function should probably accept the values, not a recipe. wrap with a
    236236// psphot-specific function which applies the recipe values
    237237pmPSFClump pmSourcePSFClump(psArray *sources, psMetadata *recipe)
     
    436436*****************************************************************************/
    437437
    438 bool pmSourceRoughClass(psArray *sources, psMetadata *recipe, pmPSFClump clump)
     438bool pmSourceRoughClass(psArray *sources, psMetadata *recipe, pmPSFClump clump, psMaskType maskSat)
    439439{
    440440    psTrace("psModules.objects", 5, "---- begin ----");
     
    487487        inner = psRegionForSquare (source->peak->x, source->peak->y, 2);
    488488        inner = psRegionForImage (source->maskView, inner);
    489         int Nsatpix = psImageCountPixelMask (source->maskView, inner, PM_MASK_SAT);
     489        int Nsatpix = psImageCountPixelMask (source->maskView, inner, maskSat);
    490490
    491491        // saturated star (size consistent with PSF or larger)
     
    747747}
    748748
    749 // construct a realization of the source model 
    750 bool pmSourceCacheModel (pmSource *source) {
     749// construct a realization of the source model
     750bool pmSourceCacheModel (pmSource *source, psMaskType maskVal) {
    751751
    752752    // select appropriate model
    753753    pmModel *model = pmSourceGetModel (NULL, source);
    754754    if (model == NULL) return false;  // model must be defined
    755        
     755
    756756    // if we already have a cached image, re-use that memory
    757757    source->modelFlux = psImageCopy (source->modelFlux, source->pixels, PS_TYPE_F32);
     
    761761    // in others, we just want the model.  which is more commonly used?
    762762    // modelFlux always has unity normalization (I0 = 1.0)
    763     pmModelAdd (source->modelFlux, source->maskObj, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM);
     763    pmModelAdd (source->modelFlux, source->maskObj, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);
    764764    return true;
    765765}
    766766
    767767// should we call pmSourceCacheModel if it does not exist?
    768 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add) {
     768bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal) {
    769769
    770770    bool status;
    771771
    772772    if (add) {
    773         psTrace ("psphot", 3, "replacing object at %f,%f\n", source->peak->xf, source->peak->yf);
     773        psTrace ("psphot", 3, "replacing object at %f,%f\n", source->peak->xf, source->peak->yf);
    774774    } else {
    775         psTrace ("psphot", 3, "removing object at %f,%f\n", source->peak->xf, source->peak->yf);
     775        psTrace ("psphot", 3, "removing object at %f,%f\n", source->peak->xf, source->peak->yf);
    776776    }
    777777
     
    780780
    781781    if (source->modelFlux) {
    782         // add in the pixels from the modelFlux image
    783         int dX = source->modelFlux->col0 - source->pixels->col0;
    784         int dY = source->modelFlux->row0 - source->pixels->row0;
    785         assert (dX >= 0);
    786         assert (dY >= 0);
    787         assert (dX + source->modelFlux->numCols <= source->pixels->numCols);
    788         assert (dY + source->modelFlux->numRows <= source->pixels->numRows);
    789        
    790         // modelFlux has unity normalization
    791         float Io = model->params->data.F32[PM_PAR_I0];
    792         if (mode & PM_MODEL_OP_NORM) {
    793             Io = 1.0;
    794         }
    795 
    796         psU8 **mask = NULL;
    797         if (source->maskObj) {
    798             mask = source->maskObj->data.U8;
    799         }
    800 
    801         psF32 **target = source->pixels->data.F32;
    802         if (mode & PM_MODEL_OP_NOISE) {
    803             target = source->weight->data.F32;
    804         }
    805 
    806         // XXX need to respect the source and model masks?
    807         for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
    808             int oy = iy + dY;
    809             for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
    810                 int ox = ix + dX;
    811                 if (mask && mask[iy][ix]) continue;
    812                 float value = Io*source->modelFlux->data.F32[iy][ix];
    813                 if (add) {
    814                     target[oy][ox] += value;
    815                 } else {
    816                     target[oy][ox] -= value;
    817                 }
    818             }
    819         }
    820         return true;
    821     } 
     782        // add in the pixels from the modelFlux image
     783        int dX = source->modelFlux->col0 - source->pixels->col0;
     784        int dY = source->modelFlux->row0 - source->pixels->row0;
     785        assert (dX >= 0);
     786        assert (dY >= 0);
     787        assert (dX + source->modelFlux->numCols <= source->pixels->numCols);
     788        assert (dY + source->modelFlux->numRows <= source->pixels->numRows);
     789
     790        // modelFlux has unity normalization
     791        float Io = model->params->data.F32[PM_PAR_I0];
     792        if (mode & PM_MODEL_OP_NORM) {
     793            Io = 1.0;
     794        }
     795
     796        psU8 **mask = NULL;
     797        if (source->maskObj) {
     798            mask = source->maskObj->data.U8;
     799        }
     800
     801        psF32 **target = source->pixels->data.F32;
     802        if (mode & PM_MODEL_OP_NOISE) {
     803            target = source->weight->data.F32;
     804        }
     805
     806        // XXX need to respect the source and model masks?
     807        for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
     808            int oy = iy + dY;
     809            for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
     810                int ox = ix + dX;
     811                if (mask && (mask[iy][ix] & maskVal)) continue;
     812                float value = Io*source->modelFlux->data.F32[iy][ix];
     813                if (add) {
     814                    target[oy][ox] += value;
     815                } else {
     816                    target[oy][ox] -= value;
     817                }
     818            }
     819        }
     820        return true;
     821    }
    822822
    823823    psImage *target = source->pixels;
    824824    if (mode & PM_MODEL_OP_NOISE) {
    825         target = source->weight;
     825        target = source->weight;
    826826    }
    827827    if (add) {
    828         status = pmModelAdd (target, source->maskObj, model, PM_MODEL_OP_FULL);
     828        status = pmModelAdd (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
    829829    } else {
    830         status = pmModelSub (target, source->maskObj, model, PM_MODEL_OP_FULL);
     830        status = pmModelSub (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
    831831    }
    832832
     
    834834}
    835835
    836 bool pmSourceAdd (pmSource *source, pmModelOpMode mode) {
    837     bool status = pmSourceOp (source, mode, true);
    838     return status;
    839 }
    840 
    841 bool pmSourceSub (pmSource *source, pmModelOpMode mode) {
    842     bool status = pmSourceOp (source, mode, false);
    843     return status;
     836bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psMaskType maskVal) {
     837    return pmSourceOp (source, mode, true, maskVal);
     838}
     839
     840bool pmSourceSub (pmSource *source, pmModelOpMode mode, psMaskType maskVal) {
     841    return pmSourceOp (source, mode, false, maskVal);
    844842}
    845843
     
    863861        if (isPSF) {
    864862            *isPSF = true;
    865         }
     863        }
    866864        return model;
    867865
     
    871869            if (isPSF) {
    872870                *isPSF = true;
    873             }
    874             return source->modelPSF;
     871            }
     872            return source->modelPSF;
    875873        }
    876874        return (model);
Note: See TracChangeset for help on using the changeset viewer.