IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12951


Ignore:
Timestamp:
Apr 21, 2007, 11:30:21 AM (19 years ago)
Author:
magnier
Message:

changed API for pmModelAdd

Location:
branches/eam_02_branch/psModules
Files:
7 edited

Legend:

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

    r12941 r12951  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.9.6.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-04-21 00:02:35 $
     8 *  @version $Revision: 1.9.6.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-04-21 21:30:21 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    135135                   psImage *mask,
    136136                   pmModel *model,
    137                    bool center,
    138                    bool sky,
     137                   pmModelAddMode mode,
    139138                   bool add
    140139                      )
     
    151150    psS32 imageCol;
    152151    psS32 imageRow;
    153     psF32 skyValue = params->data.F32[0];
    154152    psF32 pixelValue;
    155153   
    156     float xCenter = model->params->data.F32[PM_PAR_XPOS];
    157     float yCenter = model->params->data.F32[PM_PAR_YPOS];
    158     float Io = model->params->data.F32[PM_PAR_I0];
     154    // save original values; restore before returning
     155    // use the true source position for the residual model
     156    // the PSF model has presumably already been set for this coordinate
     157    float xPos    = params->data.F32[PM_PAR_XPOS];
     158    float yPos    = params->data.F32[PM_PAR_YPOS];
     159    float IoSave  = params->data.F32[PM_PAR_I0];
     160    float skySave = params->data.F32[PM_PAR_SKY];
     161
     162    if (mode & PM_MODEL_ADD_NORM) {
     163        params->data.F32[PM_PAR_I0] = 1.0;
     164    }
     165    if (!(mode & PM_MODEL_ADD_SKY)) {
     166        params->data.F32[PM_PAR_SKY] = 0.0;
     167    }
     168    if (mode & PM_MODEL_ADD_CENTER) {
     169        params->data.F32[PM_PAR_XPOS] = image->col0 + 0.5*image->numCols;
     170        params->data.F32[PM_PAR_YPOS] = image->row0 + 0.5*image->numRows;
     171    }
     172
     173    // use these values for this realization
     174    float xCenter  = params->data.F32[PM_PAR_XPOS];
     175    float yCenter  = params->data.F32[PM_PAR_YPOS];
     176    float Io       = params->data.F32[PM_PAR_I0];
    159177
    160178    int xBin = 1;
     
    166184    psImageInterpolateOptions *Rx = NULL;
    167185    psImageInterpolateOptions *Ry = NULL;
    168     if (model->residuals) {
     186    if (model->residuals && (mode & (PM_MODEL_ADD_RES0 | PM_MODEL_ADD_RES1))) {
    169187        Ro = psImageInterpolateOptionsAlloc(
    170188            PS_INTERPOLATE_BILINEAR,
     
    189207
    190208            // Convert i/j to image coord space:
    191             // 'center' option changes meaning of i,j:
    192             if (center) {
    193                 imageCol = ix - 0.5*image->numCols + xCenter;
    194                 imageRow = iy - 0.5*image->numRows + yCenter;
    195             } else {
    196                 imageCol = ix + image->col0;
    197                 imageRow = iy + image->row0;
    198             }
     209            // XXX should we use using 0.5 pixel offset?
     210            imageCol = ix + image->col0;
     211            imageRow = iy + image->row0;
    199212
    200213            x->data.F32[0] = (float) imageCol;
    201214            x->data.F32[1] = (float) imageRow;
    202215
    203             // set the appropriate pixel value for this coordinate
    204             if (sky) {
    205                 pixelValue = modelFunc (NULL, params, x);
    206             } else {
    207                 pixelValue = modelFunc (NULL, params, x) - skyValue;
    208             }
     216            pixelValue = 0.0;
     217
     218            // add in the desired components for this coordinate
     219            if (mode & PM_MODEL_ADD_FUNC) {
     220                pixelValue += modelFunc (NULL, params, x);
     221            } 
    209222
    210223            // get the contribution from the residual model
    211             // XXX for a test, do this for all sources and all pixels
    212224            if (Ro) {
    213225                // fractional image position
    214                 // this is wrong for the 'center' case
    215                 float ox = xBin*(ix + 0.5 + image->col0 - xCenter) + xResidCenter;
    216                 float oy = yBin*(iy + 0.5 + image->row0 - yCenter) + yResidCenter;
    217 
    218                 psU8 mflux = 0;
    219                 double Fo = 0.0;
    220                 double Fx = 0.0;
    221                 double Fy = 0.0;
    222                 psImageInterpolate (&Fo, NULL, &mflux, ox, oy, Ro);
    223                 psImageInterpolate (&Fx, NULL, &mflux, ox, oy, Rx);
    224                 psImageInterpolate (&Fy, NULL, &mflux, ox, oy, Ry);
    225 
    226                 if (!mflux && isfinite(Fo) && isfinite(Fx) && isfinite(Fy)) {
    227                     double flux = Fo + xCenter*Fx + yCenter*Fy;
    228                     pixelValue += Io*flux;
     226                float ox = xBin*(imageCol + 0.5 - xCenter) + xResidCenter;
     227                float oy = yBin*(imageRow + 0.5 - yCenter) + yResidCenter;
     228
     229                if (mode & PM_MODEL_ADD_RES0) {
     230                    psU8 mflux = 0;
     231                    double Fo = 0.0;
     232                    psImageInterpolate (&Fo, NULL, &mflux, ox, oy, Ro);
     233                    if (!mflux && isfinite(Fo)) {
     234                        pixelValue += Io*Fo;
     235                    }
     236                }
     237                if (mode & PM_MODEL_ADD_RES1) {
     238                    psU8 mflux = 0;
     239                    double Fx = 0.0;
     240                    double Fy = 0.0;
     241                    psImageInterpolate (&Fx, NULL, &mflux, ox, oy, Rx);
     242                    psImageInterpolate (&Fy, NULL, &mflux, ox, oy, Ry);
     243                    if (!mflux && isfinite(Fx) && isfinite(Fy)) {
     244                        pixelValue += Io*(xPos*Fx + yPos*Fy);
     245                    }
    229246                }
    230247            }
     
    238255        }
    239256    }
     257
     258    // restore original values
     259    params->data.F32[PM_PAR_I0]   = IoSave;
     260    params->data.F32[PM_PAR_SKY]  = skySave;
     261    params->data.F32[PM_PAR_XPOS] = xPos;
     262    params->data.F32[PM_PAR_YPOS] = yPos;
     263
    240264    psFree(x);
    241265    psFree(Ro);
     
    251275                psImage *mask,
    252276                pmModel *model,
    253                 bool center,
    254                 bool sky)
    255 {
    256     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    257     psBool rc = AddOrSubModel(image, mask, model, center, sky, true);
     277                pmModelAddMode mode)
     278{
     279    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     280    psBool rc = AddOrSubModel(image, mask, model, mode, true);
    258281    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    259282    return(rc);
     
    265288                psImage *mask,
    266289                pmModel *model,
    267                 bool center,
    268                 bool sky)
    269 {
    270     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    271     psBool rc = AddOrSubModel(image, mask, model, center, sky, false);
     290                pmModelAddMode mode)
     291{
     292    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     293    psBool rc = AddOrSubModel(image, mask, model, mode, false);
    272294    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    273295    return(rc);
  • branches/eam_02_branch/psModules/src/objects/pmModel.h

    r12942 r12951  
    55 * @author EAM, IfA
    66 *
    7  * @version $Revision: 1.6.6.1 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-04-21 00:03:11 $
     7 * @version $Revision: 1.6.6.2 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2007-04-21 21:30:21 $
    99 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1010 */
     
    2626    PM_MODEL_BADARGS   ///< model fit called with invalid args
    2727} pmModelStatus;
     28
     29typedef 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;
    2839
    2940/** pmModel data structure
     
    91102 */
    92103bool pmModelAdd(
    93     psImage *image,   ///< The output image (float)
    94     psImage *mask,   ///< The image pixel mask (valid == 0)
    95     pmModel *model,   ///< The input pmModel
    96     bool center,   ///< A boolean flag that determines whether pixels are centered
    97     bool sky    ///< A boolean flag that determines if the sky is subtracted
     104    psImage *image,                     ///< The output image (float)
     105    psImage *mask,                      ///< The image pixel mask (valid == 0)
     106    pmModel *model,                     ///< The input pmModel
     107    pmModelAddMode mode              ///< mode to control how the model is added into the image
    98108);
    99 
    100109
    101110/** pmModelSub()
     
    110119 */
    111120bool pmModelSub(
    112     psImage *image,   ///< The output image (float)
    113     psImage *mask,   ///< The image pixel mask (valid == 0)
    114     pmModel *model,   ///< The input pmModel
    115     bool center,   ///< A boolean flag that determines whether pixels are centered
    116     bool sky    ///< A boolean flag that determines if the sky is subtracted
     121    psImage *image,                     ///< The output image (float)
     122    psImage *mask,                      ///< The image pixel mask (valid == 0)
     123    pmModel *model,                     ///< The input pmModel
     124    pmModelAddMode mode              ///< mode to control how the model is added into the image
    117125);
    118126
  • branches/eam_02_branch/psModules/src/objects/pmPSF.c

    r12943 r12951  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.19.2.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-04-21 00:03:31 $
     8 *  @version $Revision: 1.19.2.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-04-21 21:30:21 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    424424    // place the reference object in the image center
    425425    // no need to mask the source here
    426     pmModelAdd (image, NULL, model, false, false);
     426    // XXX should we measure this for the analytical model only or the full model?
     427    pmModelAdd (image, NULL, model, PM_MODEL_ADD_FULL);
    427428
    428429    // loop over a range of source fluxes
  • branches/eam_02_branch/psModules/src/objects/pmSource.h

    r11253 r12951  
    33 * @author EAM, IfA; GLG, MHPCC
    44 *
    5  * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    6  * @date $Date: 2007-01-24 02:54:15 $
     5 * @version $Revision: 1.10.6.1 $ $Name: not supported by cvs2svn $
     6 * @date $Date: 2007-04-21 21:30:21 $
    77 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    88 */
     
    1313/// @addtogroup Objects Object Detection / Analysis Functions
    1414/// @{
    15 
    16 /**
    17  * In the object analysis process, we will use specific mask values to mark the
    18  * image pixels. The following structure defines the relevant mask values.
    19  *
    20  * XXX: This is probably a bad solution: we will want to set mask values
    21  * outside of the PSPHOT code.  Perhaps we can set up a registered set of mask
    22  * values with specific meanings that other functions can add to or define?
    23  
    24  * XXX We will only use the PM_MASK_xxx mask values
    25 typedef enum {
    26     PM_SOURCE_MASK_CLEAR     = 0x00,
    27     PM_SOURCE_MASK_INVALID   = 0x01,
    28     PM_SOURCE_MASK_SATURATED = 0x02,
    29     PM_SOURCE_MASK_MARKED    = 0x08,
    30 } psphotMaskValues;
    31 */
    3215
    3316/** pmSourceType enumeration
  • branches/eam_02_branch/psModules/src/objects/pmSourcePhotometry.c

    r12943 r12951  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.22.4.2 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-04-21 00:03:31 $
     5 *  @version $Revision: 1.22.4.3 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-04-21 21:30:21 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    106106    // replace source flux
    107107    // XXX need to be certain which model and size of mask for prior subtraction
     108    // XXX full model or just analytical?
     109    // XXX use pmSourceAdd instead?
    108110    if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
    109         pmModelAdd (source->pixels, source->mask, model, false, false);
     111        pmModelAdd (source->pixels, source->mask, model, PM_MODEL_ADD_FULL);
    110112    }
    111113
     
    210212    // if source was originally subtracted, re-subtract object, leave local sky
    211213    if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
    212         pmModelSub (source->pixels, source->mask, model, false, false);
     214        pmModelSub (source->pixels, source->mask, model, PM_MODEL_ADD_FULL);
    213215    }
    214216
  • branches/eam_02_branch/psModules/test/objects/tap_pmSourceFitModel.c

    r10263 r12951  
    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, false, false);
     138    pmModelAdd (source->pixels, source->mask, source->modelEXT, PM_MODEL_ADD_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

    r10194 r12951  
    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, false, false);
     56    pmModelAdd (source->pixels, source->mask, source->modelEXT, PM_MODEL_ADD_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.