IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 22, 2007, 5:26:23 PM (19 years ago)
Author:
magnier
Message:

changed PM_MODEL_ADD_.. to PM_MODEL_OP_..; added pmSourceAdd/Sub; adding modelFlux and maskView/maskObj to pmSource

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_02_branch/psModules/src/objects/pmSource.c

    r12954 r12956  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.25.4.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-04-22 22:23:20 $
     8 *  @version $Revision: 1.25.4.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-04-23 03:26:23 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3939    psFree(tmp->pixels);
    4040    psFree(tmp->weight);
    41     psFree(tmp->mask);
     41    psFree(tmp->maskObj);
     42    psFree(tmp->maskView);
     43    psFree(tmp->modelFlux);
    4244    psFree(tmp->moments);
    4345    psFree(tmp->modelPSF);
     
    4749}
    4850
     51// free only the pixel data associated with this source
    4952void pmSourceFreePixels(pmSource *source)
    5053{
     
    5558    psFree (source->pixels);
    5659    psFree (source->weight);
    57     psFree (source->mask);
     60    psFree (source->maskObj);
     61    psFree (source->maskView);
     62    psFree (source->modelFlux);
    5863
    5964    source->pixels = NULL;
    6065    source->weight = NULL;
    61     source->mask = NULL;
     66    source->maskObj = NULL;
     67    source->maskView = NULL;
     68    source->modelFlux = NULL;
    6269    return;
    6370}
     
    7683    source->pixels = NULL;
    7784    source->weight = NULL;
    78     source->mask = NULL;
     85    source->maskObj = NULL;
     86    source->maskView = NULL;
     87    source->modelFlux = NULL;
    7988    source->moments = NULL;
    8089    source->blends = NULL;
     
    117126    source->pixels = psMemIncrRefCounter (in->pixels);
    118127    source->weight = psMemIncrRefCounter (in->weight);
    119     source->mask = psMemIncrRefCounter (in->mask);
     128    source->maskObj = psMemIncrRefCounter (in->maskObj);
     129    source->maskView = psMemIncrRefCounter (in->maskView);
    120130    source->moments = psMemIncrRefCounter (in->moments);
    121131    source->blends = NULL;
    122132    source->modelPSF = NULL;
    123133    source->modelEXT = NULL;
     134    source->modelFlux = NULL;
    124135    source->type = in->type;
    125136    source->mode = in->mode;
     
    151162    srcRegion = psRegionForImage (readout->image, srcRegion);
    152163
    153     mySource->pixels = psMemIncrRefCounter(psImageSubset(readout->image, srcRegion));
    154     mySource->weight = psMemIncrRefCounter(psImageSubset(readout->weight, srcRegion));
    155     mySource->mask   = psMemIncrRefCounter(psImageSubset(readout->mask,  srcRegion));
    156     mySource->region = srcRegion;
     164    // these images are subset images of the equivalent parents
     165    mySource->pixels   = psMemIncrRefCounter(psImageSubset(readout->image, srcRegion));
     166    mySource->weight   = psMemIncrRefCounter(psImageSubset(readout->weight, srcRegion));
     167    mySource->maskView = psMemIncrRefCounter(psImageSubset(readout->mask,  srcRegion));
     168    mySource->region   = srcRegion;
     169
     170    // the object mask is a copy, and used to define the source pixels
     171    mySource->maskObj = psImageCopy (NULL, mySource->maskView, PS_TYPE_MASK);
    157172
    158173    return true;
     
    183198    extend |= (mySource->pixels == NULL);
    184199    extend |= (mySource->weight == NULL);
    185     extend |= (mySource->mask == NULL);
     200    extend |= (mySource->maskObj == NULL);
     201    extend |= (mySource->maskView == NULL);
    186202
    187203    // extend = true;
     
    190206        psFree (mySource->pixels);
    191207        psFree (mySource->weight);
    192         psFree (mySource->mask);
    193 
    194         mySource->pixels = psMemIncrRefCounter(psImageSubset(readout->image,  newRegion));
    195         mySource->weight = psMemIncrRefCounter(psImageSubset(readout->weight, newRegion));
    196         mySource->mask   = psMemIncrRefCounter(psImageSubset(readout->mask,   newRegion));
    197         mySource->region = newRegion;
    198     }
    199 
     208        psFree (mySource->maskView);
     209
     210        mySource->pixels   = psMemIncrRefCounter(psImageSubset(readout->image,  newRegion));
     211        mySource->weight   = psMemIncrRefCounter(psImageSubset(readout->weight, newRegion));
     212        mySource->maskView = psMemIncrRefCounter(psImageSubset(readout->mask,   newRegion));
     213        mySource->region   = newRegion;
     214
     215        // XXX how do we extend the mask?  do we need to keep the old masked pixels?
     216        // the object mask is a copy, and used to define the source pixels
     217        psFree (mySource->maskObj);
     218        mySource->maskObj = psImageCopy (NULL, mySource->maskView, PS_TYPE_MASK);
     219       
     220        // XXX what about the modelFlux image?
     221    }
    200222    return extend;
    201223}
     
    207229
    208230// XXX EAM include a S/N cutoff in selecting the sources?
     231// XXX this function should probably accept the values, not a recipe. wrap with a
     232// psphot-specific function which applies the recipe values
    209233pmPSFClump pmSourcePSFClump(psArray *sources, psMetadata *recipe)
    210234{
     
    458482        // XXX EAM : can we use the value of SATURATE if mask is NULL?
    459483        inner = psRegionForSquare (source->peak->x, source->peak->y, 2);
    460         inner = psRegionForImage (source->mask, inner);
    461         int Nsatpix = psImageCountPixelMask (source->mask, inner, PM_MASK_SAT);
     484        inner = psRegionForImage (source->maskView, inner);
     485        int Nsatpix = psImageCountPixelMask (source->maskView, inner, PM_MASK_SAT);
    462486
    463487        // saturated star (size consistent with PSF or larger)
     
    572596    PS_ASSERT_PTR_NON_NULL(source->peak, false);
    573597    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
    574     PS_ASSERT_PTR_NON_NULL(source->mask, false);
     598    PS_ASSERT_PTR_NON_NULL(source->maskObj, false);
    575599    PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false);
    576600
     
    622646        psF32 *vPix = source->pixels->data.F32[row];
    623647        psF32 *vWgt = source->weight->data.F32[row];
    624         psU8  *vMsk = (source->mask == NULL) ? NULL : source->mask->data.U8[row];
     648        psU8  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.U8[row];
    625649
    626650        for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
     
    751775    // in some places (psphotEnsemble), we need a normalized version
    752776    // in others, we just want the model.  which is more commonly used?
    753     pmModelAdd (source->modelFlux, source->mask, model, PM_MODEL_ADD_FULL | PM_MODEL_ADD_NORM);
     777    pmModelAdd (source->modelFlux, source->maskObj, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM);
    754778    return true;
    755779}
    756780
    757 // XXX should this API take an operator (+/-)?
    758 // XXX should we specify norm, etc?
    759 bool pmSourceAdd (pmSource *source) {
     781// should we call pmSourceCacheModel if it does not exist?
     782bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add) {
     783
     784    pmModel *model = pmSourceGetModel (NULL, source);
     785    if (model == NULL) continue;  // model must be defined
    760786
    761787    if (source->modelFlux) {
    762788        // add in the pixels from the modelFlux image
    763         psImageSubsetAdd (source->pixels, source->modelFlux);
     789        int dX = source->modelFlux->col0 - source->pixels->col0;
     790        int dY = source->modelFlux->row0 - source->pixels->row0;
     791        assert (dX >= 0);
     792        assert (dY >= 0);
     793        assert (dX + source->modelFlux->numCols < source->pixels->numCols);
     794        assert (dY + source->modelFlux->numRows < source->pixels->numRows);
     795       
     796        float Io = 1.0;
     797        if (mode & PM_MODEL_OP_NORM) {
     798            Io = 1.0 / model->params->data.F32[PM_PAR_I0];
     799        }
     800
     801        // XXX need to respect the source and model masks?
     802        for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
     803            oy = iy + dY;
     804            for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
     805                ox = ix + dX;
     806                float value = Io*source->modelFlux->data.F32[iy][ix];
     807                if (add) {
     808                    source->pixels->data.F32[oy][ox] -= value;
     809                } else {
     810                    source->pixels->data.F32[oy][ox] += value;
     811                }
     812            }
     813        }
    764814    } else {
    765         pmModel *model = pmSourceGetModel (NULL, source);
    766         if (model == NULL) continue;  // model must be defined
    767         pmModelAdd (source->pixels, source->mask, model, PM_MODEL_ADD_FULL);
     815        if (add) {
     816            pmModelAdd (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL);
     817        } else {
     818            pmModelSub (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL);
     819        }
    768820    }   
    769821
    770     // we would need to save X,Y somehow (or use the peak?)
    771     // psTrace ("psphot", 3, "replacing object at %f,%f\n",
    772     // model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]);
     822    if (add) {
     823        psTrace ("psphot", 3, "replacing object at %f,%f\n", source->peak->xf, source->peak->yf);
     824    } else {
     825        psTrace ("psphot", 3, "removing object at %f,%f\n", source->peak->xf, source->peak->yf);
     826    }
    773827    return true;
    774828}
    775829
    776 bool pmSourceSub (pmSource *source) {
    777 
    778     if (source->modelFlux) {
    779         // add in the pixels from the modelFlux image
    780         psImageSubsetSub (source->pixels, source->modelFlux);
    781     } else {
    782         pmModel *model = pmSourceGetModel (NULL, source);
    783         if (model == NULL) continue;  // model must be defined
    784         pmModelSub (source->pixels, source->mask, model, PM_MODEL_ADD_FULL);
    785     }   
    786     return true;
    787 }
    788 
    789 // XXX merge this function with psImageOverlay, which is probably mid-defined
    790 bool psImageSubsetAdd (psImage *input, psImage *subset) {
    791 
    792     // col0,row0 in both images refer to parent coordinates
    793 
    794     int dX = subset->col0 - input->col0;
    795     int dY = subset->row0 - input->row0;
    796     assert (dX >= 0);
    797     assert (dY >= 0);
    798     assert (dX + subset->numCols < input->numCols);
    799     assert (dY + subset->numRows < input->numRows);
    800     assert (input->type.type == PS_TYPE_F32);
    801     assert (subset->type.type == PS_TYPE_F32);
    802 
    803     for (int iy = 0; iy < subset->numRows; iy++) {
    804         oy = iy + dY;
    805         for (int ix = 0; ix < subset->numCols; ix++) {
    806             ox = ix + dX;
    807             input->data.F32[oy][ox] += subset->data.F32[iy][ix];
    808         }
    809     }
    810     return true;
    811 }
    812 
    813 // XXX merge this function with psImageOverlay, which is probably mid-defined
    814 bool psImageSubsetSub (psImage *input, psImage *subset) {
    815 
    816     // col0,row0 in both images refer to parent coordinates
    817 
    818     int dX = subset->col0 - input->col0;
    819     int dY = subset->row0 - input->row0;
    820     assert (dX >= 0);
    821     assert (dY >= 0);
    822     assert (dX + subset->numCols < input->numCols);
    823     assert (dY + subset->numRows < input->numRows);
    824     assert (input->type.type == PS_TYPE_F32);
    825     assert (subset->type.type == PS_TYPE_F32);
    826 
    827     for (int iy = 0; iy < subset->numRows; iy++) {
    828         oy = iy + dY;
    829         for (int ix = 0; ix < subset->numCols; ix++) {
    830             ox = ix + dX;
    831             input->data.F32[oy][ox] -= subset->data.F32[iy][ix];
    832         }
    833     }
    834     return true;
    835 }
     830bool pmSourceAdd (pmSource *source, pmSourceOpMode mode) {
     831    pmSourceOp (source, mode, true);
     832}
     833
     834bool pmSourceSub (pmSource *source, pmSourceOpMode mode) {
     835    pmSourceOp (source, mode, false);
     836}
Note: See TracChangeset for help on using the changeset viewer.