IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 23, 2007, 2:11:02 PM (19 years ago)
Author:
magnier
Message:
  • added function pointers to pmModel to provide class-dependent functions
  • dropped pmModel*_GetFunction functions (use pmModel->func functions instead)
  • added modelParamsFromPSF functions to model classes
  • changed pmModelGroup to pmModelClass
  • added pmSourceFitSet.[ch]
  • updated pmSourceFitSet to allow variable model classes
  • added functions to add/sub and eval models & sources with an offset between image and chip
  • added function to set a pmModel flux
  • added function to instatiate a pmModel from a pmPSF at a coordinate
  • moved pmPSF I/O to chip->analysis from readout->analysis
  • changed pmPSF I/O function names from *ForPSFmodel to pmPSFmodel*
  • changed pmModel.params_NEW back to pmModel.params
  • changed pmFind*Peaks to pmPeaksIn* (* = Image,Vector)
  • dropped pmCullPeaks (deprecated)
  • changed pmModelSetType to pmModelClassGetType
  • changed pmModelGetType to pmModelClassGetName
  • fixed PGAUSS implementation of modelRadius function
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmModel.c

    r13898 r14652  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-06-20 02:22:26 $
     8 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2121#include <string.h>
    2222#include <pslib.h>
     23#include "pmHDU.h"
     24#include "pmFPA.h"
    2325#include "pmResiduals.h"
     26#include "pmGrowthCurve.h"
     27#include "pmPSF.h"
    2428#include "pmModel.h"
    25 
    26 /* The following types and functions need to be known by pmModel.c and are defined in
    27    pmModelGroup.h.  The use of pmSource and other types in pmModelGroup.h prevent us from
    28    directly including it here  ***/
    29 
    30 typedef psMinimizeLMChi2Func pmModelFunc;
    31 typedef bool (*pmModelFitStatusFunc)(pmModel *model);
    32 pmModelFunc pmModelFunc_GetFunction (pmModelType type);
    33 pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type);
    34 int pmModelParameterCount(pmModelType type);
     29#include "pmModelClass.h"
    3530
    3631static void modelFree(pmModel *tmp)
     
    4540pmModelAlloc(): Allocate the pmModel structure, along with its parameters,
    4641and initialize the type member.  Initialize the params to 0.0.
    47 XXX EAM: simplifying code with pmModelParameterCount
    4842*****************************************************************************/
    4943pmModel *pmModelAlloc(pmModelType type)
     
    5347    pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));
    5448    psMemSetDeallocator(tmp, (psFreeFunc) modelFree);
     49
     50    pmModelClass *class = pmModelClassSelect (type);
     51    if (class == NULL) {
     52        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     53        return(NULL);
     54    }
    5555
    5656    tmp->type = type;
     
    6262    tmp->residuals = NULL;              // XXX should the model own this memory?
    6363
    64     psS32 Nparams = pmModelParameterCount(type);
    65     if (Nparams == 0) {
    66         psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
    67         return(NULL);
    68     }
     64    psS32 Nparams = pmModelClassParameterCount(type);
     65    assert (Nparams);
    6966
    7067    tmp->params  = psVectorAlloc(Nparams, PS_TYPE_F32);
    7168    tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32);
     69    assert (tmp->params);
     70    assert (tmp->dparams);
    7271
    7372    for (psS32 i = 0; i < tmp->params->n; i++) {
     
    7574        tmp->dparams->data.F32[i] = 0.0;
    7675    }
     76
     77    tmp->modelFunc          = class->modelFunc;
     78    tmp->modelFlux          = class->modelFlux;
     79    tmp->modelRadius        = class->modelRadius;
     80    tmp->modelLimits        = class->modelLimits;
     81    tmp->modelGuess         = class->modelGuess;
     82    tmp->modelFromPSF       = class->modelFromPSF;
     83    tmp->modelParamsFromPSF = class->modelParamsFromPSF;
     84    tmp->modelFitStatus     = class->modelFitStatus;
    7785
    7886    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     
    92100    new->radiusFit = model->radiusFit;
    93101
    94     // XXX note that model->residuals is just a reference
    95     new->residuals = model->residuals;
    96 
    97102    for (int i = 0; i < new->params->n; i++) {
    98103        new->params->data.F32[i]  = model->params->data.F32[i];
    99104        new->dparams->data.F32[i] = model->dparams->data.F32[i];
    100105    }
     106
     107    // note that model->residuals is just a reference
     108    new->residuals = model->residuals;
    101109
    102110    return (new);
     
    123131    x->data.F32[1] = (psF32) (row + image->row0);
    124132    psF32 tmpF;
    125     pmModelFunc modelFunc;
    126 
    127     modelFunc = pmModelFunc_GetFunction (model->type);
    128     tmpF = modelFunc (NULL, model->params, x);
     133
     134    tmpF = model->modelFunc (NULL, model->params, x);
     135    psFree(x);
     136    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     137    return(tmpF);
     138}
     139
     140psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, psS32 col, psS32 row, int dx, int dy)
     141{
     142    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     143    PS_ASSERT_PTR_NON_NULL(image, false);
     144    PS_ASSERT_PTR_NON_NULL(model, false);
     145    PS_ASSERT_PTR_NON_NULL(model->params, false);
     146
     147    // Allocate the x coordinate structure and convert row/col to image space.
     148    //
     149    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
     150    x->data.F32[0] = (psF32) (col + image->col0 + dx);
     151    x->data.F32[1] = (psF32) (row + image->row0 + dy);
     152    psF32 tmpF;
     153
     154    tmpF = model->modelFunc (NULL, model->params, x);
    129155    psFree(x);
    130156    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     
    137163                          pmModelOpMode mode,
    138164                          bool add,
    139                           psMaskType maskVal
     165                          psMaskType maskVal,
     166                          int dx,
     167                          int dy
    140168    )
    141169{
     
    148176    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
    149177    psVector *params = model->params;
    150     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
     178
    151179    psS32 imageCol;
    152180    psS32 imageRow;
     
    209237            // Convert i/j to image coord space:
    210238            // XXX should we use using 0.5 pixel offset?
    211             imageCol = ix + image->col0;
    212             imageRow = iy + image->row0;
     239            imageCol = ix + image->col0 + dx;
     240            imageRow = iy + image->row0 + dy;
    213241
    214242            x->data.F32[0] = (float) imageCol;
     
    219247            // add in the desired components for this coordinate
    220248            if (mode & PM_MODEL_OP_FUNC) {
    221                 pixelValue += modelFunc (NULL, params, x);
     249                pixelValue += model->modelFunc (NULL, params, x);
    222250            }
    223251
     
    280308{
    281309    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    282     psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal);
     310    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, 0.0, 0.0);
    283311    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    284312    return(rc);
     
    294322{
    295323    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    296     psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal);
     324    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, 0.0, 0.0);
    297325    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    298326    return(rc);
    299327}
    300328
    301 // check for success of model fit
    302 bool pmModelFitStatus (pmModel *model)
    303 {
    304 
    305     bool status;
    306 
    307     pmModelFitStatusFunc statusFunc = pmModelFitStatusFunc_GetFunction (model->type);
    308     status = statusFunc (model);
    309 
    310     return (status);
    311 }
    312 
     329/******************************************************************************
     330 *****************************************************************************/
     331bool pmModelAddWithOffset(psImage *image,
     332                          psImage *mask,
     333                          pmModel *model,
     334                          pmModelOpMode mode,
     335                          psMaskType maskVal,
     336                          int dx,
     337                          int dy)
     338{
     339    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     340    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, dx, dy);
     341    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     342    return(rc);
     343}
     344
     345/******************************************************************************
     346 *****************************************************************************/
     347bool pmModelSubWithOffset(psImage *image,
     348                          psImage *mask,
     349                          pmModel *model,
     350                          pmModelOpMode mode,
     351                          psMaskType maskVal,
     352                          int dx,
     353                          int dy)
     354{
     355    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     356    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, dx, dy);
     357    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     358    return(rc);
     359}
Note: See TracChangeset for help on using the changeset viewer.