IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12941


Ignore:
Timestamp:
Apr 20, 2007, 2:02:35 PM (19 years ago)
Author:
magnier
Message:

added residual subtraction code to pmModelAdd

File:
1 edited

Legend:

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

    r9810 r12941  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-10-31 19:38:44 $
     8 *  @version $Revision: 1.9.6.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-04-21 00:02:35 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2121#include <string.h>
    2222#include <pslib.h>
     23#include "pmResiduals.h"
    2324#include "pmModel.h"
    2425
     
    4950{
    5051    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     52
    5153    pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));
     54    psMemSetDeallocator(tmp, (psFreeFunc) modelFree);
    5255
    5356    tmp->type = type;
     
    5760    tmp->radiusFit = 0;
    5861    tmp->status = PM_MODEL_UNTRIED;
     62    tmp->residuals = NULL;              // XXX should the model own this memory?
    5963
    6064    psS32 Nparams = pmModelParameterCount(type);
     
    7276    }
    7377
    74     psMemSetDeallocator(tmp, (psFreeFunc) modelFree);
    7578    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
    7679    return(tmp);
     
    8891    new->status = model->status;
    8992    new->radiusFit = model->radiusFit;
     93
     94    // XXX note that model->residuals is just a reference
     95    new->residuals = model->residuals;
    9096
    9197    for (int i = 0; i < new->params->n; i++) {
     
    147153    psF32 skyValue = params->data.F32[0];
    148154    psF32 pixelValue;
    149 
    150     for (psS32 i = 0; i < image->numRows; i++) {
    151         for (psS32 j = 0; j < image->numCols; j++) {
    152             if ((mask != NULL) && mask->data.U8[i][j])
     155   
     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];
     159
     160    int xBin = 1;
     161    int yBin = 1;
     162    float xResidCenter = 0.0;
     163    float yResidCenter = 0.0;
     164
     165    psImageInterpolateOptions *Ro = NULL;
     166    psImageInterpolateOptions *Rx = NULL;
     167    psImageInterpolateOptions *Ry = NULL;
     168    if (model->residuals) {
     169        Ro = psImageInterpolateOptionsAlloc(
     170            PS_INTERPOLATE_BILINEAR,
     171            model->residuals->Ro, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
     172        Rx = psImageInterpolateOptionsAlloc(
     173            PS_INTERPOLATE_BILINEAR,
     174            model->residuals->Rx, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
     175        Ry = psImageInterpolateOptionsAlloc(
     176            PS_INTERPOLATE_BILINEAR,
     177            model->residuals->Ry, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
     178
     179        xBin = model->residuals->xBin;
     180        yBin = model->residuals->yBin;
     181        xResidCenter = model->residuals->xCenter;
     182        yResidCenter = model->residuals->yCenter;
     183    }
     184
     185    for (psS32 iy = 0; iy < image->numRows; iy++) {
     186        for (psS32 ix = 0; ix < image->numCols; ix++) {
     187            if ((mask != NULL) && mask->data.U8[iy][ix])
    153188                continue;
    154189
     
    156191            // 'center' option changes meaning of i,j:
    157192            if (center) {
    158                 imageCol = j - 0.5*image->numCols + model->params->data.F32[2];
    159                 imageRow = i - 0.5*image->numRows + model->params->data.F32[3];
     193                imageCol = ix - 0.5*image->numCols + xCenter;
     194                imageRow = iy - 0.5*image->numRows + yCenter;
    160195            } else {
    161                 imageCol = j + image->col0;
    162                 imageRow = i + image->row0;
     196                imageCol = ix + image->col0;
     197                imageRow = iy + image->row0;
    163198            }
    164199
     
    173208            }
    174209
     210            // get the contribution from the residual model
     211            // XXX for a test, do this for all sources and all pixels
     212            if (Ro) {
     213                // 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;
     229                }
     230            }
    175231
    176232            // add or subtract the value
    177             if (add
    178                ) {
    179                 image->data.F32[i][j] += pixelValue;
    180             }
    181             else {
    182                 image->data.F32[i][j] -= pixelValue;
     233            if (add) {
     234                image->data.F32[iy][ix] += pixelValue;
     235            } else {
     236                image->data.F32[iy][ix] -= pixelValue;
    183237            }
    184238        }
    185239    }
    186240    psFree(x);
     241    psFree(Ro);
     242    psFree(Rx);
     243    psFree(Ry);
    187244    psTrace("psModules.objects", 3, "---- %s(true) end ----\n", __func__);
    188245    return(true);
Note: See TracChangeset for help on using the changeset viewer.