IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

changed API for pmModelAdd

File:
1 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);
Note: See TracChangeset for help on using the changeset viewer.