IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12956


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

Location:
branches/eam_02_branch/psModules
Files:
8 edited

Legend:

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

    r12951 r12956  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.9.6.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-04-21 21:30:21 $
     8 *  @version $Revision: 1.9.6.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
     
    160160    float skySave = params->data.F32[PM_PAR_SKY];
    161161
    162     if (mode & PM_MODEL_ADD_NORM) {
     162    if (mode & PM_MODEL_OP_NORM) {
    163163        params->data.F32[PM_PAR_I0] = 1.0;
    164164    }
    165     if (!(mode & PM_MODEL_ADD_SKY)) {
     165    if (!(mode & PM_MODEL_OP_SKY)) {
    166166        params->data.F32[PM_PAR_SKY] = 0.0;
    167167    }
    168     if (mode & PM_MODEL_ADD_CENTER) {
     168    if (mode & PM_MODEL_OP_CENTER) {
    169169        params->data.F32[PM_PAR_XPOS] = image->col0 + 0.5*image->numCols;
    170170        params->data.F32[PM_PAR_YPOS] = image->row0 + 0.5*image->numRows;
     
    184184    psImageInterpolateOptions *Rx = NULL;
    185185    psImageInterpolateOptions *Ry = NULL;
    186     if (model->residuals && (mode & (PM_MODEL_ADD_RES0 | PM_MODEL_ADD_RES1))) {
     186    if (model->residuals && (mode & (PM_MODEL_OP_RES0 | PM_MODEL_OP_RES1))) {
    187187        Ro = psImageInterpolateOptionsAlloc(
    188188            PS_INTERPOLATE_BILINEAR,
     
    217217
    218218            // add in the desired components for this coordinate
    219             if (mode & PM_MODEL_ADD_FUNC) {
     219            if (mode & PM_MODEL_OP_FUNC) {
    220220                pixelValue += modelFunc (NULL, params, x);
    221221            }
     
    227227                float oy = yBin*(imageRow + 0.5 - yCenter) + yResidCenter;
    228228
    229                 if (mode & PM_MODEL_ADD_RES0) {
     229                if (mode & PM_MODEL_OP_RES0) {
    230230                    psU8 mflux = 0;
    231231                    double Fo = 0.0;
     
    235235                    }
    236236                }
    237                 if (mode & PM_MODEL_ADD_RES1) {
     237                if (mode & PM_MODEL_OP_RES1) {
    238238                    psU8 mflux = 0;
    239239                    double Fx = 0.0;
  • branches/eam_02_branch/psModules/src/objects/pmModel.h

    r12951 r12956  
    55 * @author EAM, IfA
    66 *
    7  * @version $Revision: 1.6.6.2 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-04-21 21:30:21 $
     7 * @version $Revision: 1.6.6.3 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2007-04-23 03:26:23 $
    99 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1010 */
     
    2828
    2929typedef enum {
    30     PM_MODEL_ADD_NONE   = 0x00,
    31     PM_MODEL_ADD_FUNC   = 0x01,
    32     PM_MODEL_ADD_RES0   = 0x02,
    33     PM_MODEL_ADD_RES1   = 0x04,
    34     PM_MODEL_ADD_FULL   = 0x07,
    35     PM_MODEL_ADD_SKY    = 0x08,
    36     PM_MODEL_ADD_CENTER = 0x10,
    37     PM_MODEL_ADD_NORM   = 0x20,
    38 } pmModelAddMode;
     30    PM_MODEL_OP_NONE    = 0x00,
     31    PM_MODEL_OP_FUNC    = 0x01,
     32    PM_MODEL_OP_RES0    = 0x02,
     33    PM_MODEL_OP_RES1    = 0x04,
     34    PM_MODEL_OP_FULL   = 0x07,
     35    PM_MODEL_OP_SKY     = 0x08,
     36    PM_MODEL_OP_CENTER = 0x10,
     37    PM_MODEL_OP_NORM    = 0x20,
     38} pmModelOpMode;
    3939
    4040/** pmModel data structure
  • branches/eam_02_branch/psModules/src/objects/pmPSF.c

    r12951 r12956  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.19.2.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-04-21 21:30:21 $
     8 *  @version $Revision: 1.19.2.4 $ $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
     
    425425    // no need to mask the source here
    426426    // XXX should we measure this for the analytical model only or the full model?
    427     pmModelAdd (image, NULL, model, PM_MODEL_ADD_FULL);
     427    pmModelAdd (image, NULL, model, PM_MODEL_OP_FULL);
    428428
    429429    // loop over a range of source fluxes
  • 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}
  • branches/eam_02_branch/psModules/src/objects/pmSource.h

    r12951 r12956  
    33 * @author EAM, IfA; GLG, MHPCC
    44 *
    5  * @version $Revision: 1.10.6.1 $ $Name: not supported by cvs2svn $
    6  * @date $Date: 2007-04-21 21:30:21 $
     5 * @version $Revision: 1.10.6.2 $ $Name: not supported by cvs2svn $
     6 * @date $Date: 2007-04-23 03:26:23 $
    77 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    88 */
     
    5858typedef struct
    5959{
    60     const int id;   ///< Unique ID for object
    61     pmPeak *peak;   ///< Description of peak pixel.
    62     psImage *pixels;   ///< Rectangular region including object pixels.
    63     psImage *weight;   ///< Image variance.
    64     psImage *mask;   ///< Mask which marks pixels associated with objects.
    65     pmMoments *moments;   ///< Basic moments measure for the object.
    66     pmModel *modelPSF;   ///< PSF Model fit (parameters and type)
    67     pmModel *modelEXT;   ///< EXT (floating) Model fit (parameters and type).
    68     pmSourceType type;   ///< Best identification of object.
    69     pmSourceMode mode;   ///< Best identification of object.
     60    const int id;                       ///< Unique ID for object
     61    pmPeak *peak;                       ///< Description of peak pixel.
     62    psImage *pixels;                    ///< Rectangular region including object pixels.
     63    psImage *weight;                    ///< Image variance.
     64    psImage *modelFlux;                 ///< cached copy of the model for this source
     65    psImage *maskObj;                   ///< unique mask for this object which marks included pixels associated with objects.
     66    psImage *maskView;                  ///< view into global image mask for this object region
     67    pmMoments *moments;                 ///< Basic moments measure for the object.
     68    pmModel *modelPSF;                  ///< PSF Model fit (parameters and type)
     69    pmModel *modelEXT;                  ///< EXT (floating) Model fit (parameters and type).
     70    pmSourceType type;                  ///< Best identification of object.
     71    pmSourceMode mode;                  ///< Best identification of object.
    7072    psArray *blends;
    71     float psfMag;   ///< calculated from flux in modelPsf
    72     float extMag;   ///< calculated from flux in modelEXT
    73     float errMag;   ///< error in psfMag OR extMag (depending on type)
    74     float apMag;   ///< apMag corresponding to psfMag or extMag (depending on type)
    75     float pixWeight;   // model-weighted coverage of valid pixels
    76     psRegion region;   // area on image covered by selected pixels
    77     float sky, skyErr;   //?< The sky and its error at the center of the object
     73    float psfMag;                       ///< calculated from flux in modelPsf
     74    float extMag;                       ///< calculated from flux in modelEXT
     75    float errMag;                       ///< error in psfMag OR extMag (depending on type)
     76    float apMag;               ///< apMag corresponding to psfMag or extMag (depending on type)
     77    float pixWeight;                    // model-weighted coverage of valid pixels
     78    psRegion region;                    // area on image covered by selected pixels
     79    float sky, skyErr;                  //?< The sky and its error at the center of the object
    7880}
    7981pmSource;
  • branches/eam_02_branch/psModules/src/objects/pmSourcePhotometry.c

    r12951 r12956  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.22.4.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-04-21 21:30:21 $
     5 *  @version $Revision: 1.22.4.4 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-04-23 03:26:23 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    109109    // XXX use pmSourceAdd instead?
    110110    if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
    111         pmModelAdd (source->pixels, source->mask, model, PM_MODEL_ADD_FULL);
     111        pmModelAdd (source->pixels, source->mask, model, PM_MODEL_OP_FULL);
    112112    }
    113113
     
    212212    // if source was originally subtracted, re-subtract object, leave local sky
    213213    if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
    214         pmModelSub (source->pixels, source->mask, model, PM_MODEL_ADD_FULL);
     214        pmModelSub (source->pixels, source->mask, model, PM_MODEL_OP_FULL);
    215215    }
    216216
  • branches/eam_02_branch/psModules/test/objects/tap_pmSourceFitModel.c

    r12951 r12956  
    136136
    137137    // create an image with the model, and add noise: gain is 1, subtracted sky is 100, readnoise is 5
    138     pmModelAdd (source->pixels, source->mask, source->modelEXT, PM_MODEL_ADD_FULL);
     138    pmModelAdd (source->pixels, source->mask, source->modelEXT, PM_MODEL_OP_FULL);
    139139    int npix = 0;
    140140    for (int j = 0; j < source->pixels->numRows; j++) {
  • branches/eam_02_branch/psModules/test/objects/tap_pmSourceFitModel_Delta.c

    r12951 r12956  
    5454
    5555    // create an image with the model, and add noise: gain is 1, subtracted sky is 100, readnoise is 5
    56     pmModelAdd (source->pixels, source->mask, source->modelEXT, PM_MODEL_ADD_FULL);
     56    pmModelAdd (source->pixels, source->mask, source->modelEXT, PM_MODEL_OP_FULL);
    5757    int npix = 0;
    5858    for (int j = 0; j < source->pixels->numRows; j++) {
Note: See TracChangeset for help on using the changeset viewer.