IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14544


Ignore:
Timestamp:
Aug 17, 2007, 11:01:59 AM (19 years ago)
Author:
magnier
Message:

substantial cleanups of APIs:

changed pmModelGroup to pmModelClass

dropped the _GetFunctions, and moved the modelClass-specific functions
to functions pointers in the pmModel structure. These are assigned
when the model is allocated, based on the model type. Now, instead of
calling, for example,

modelFunc = pmModelFunc_GetFunctions(model->type)
modelFunc();

you just do:

model->modelFunc()

moved some of the support functions into pmModelUtils and
pmSourceUtils.

changed pmIsFooBar to pmFooBarTest for better api listing.

added functions to evaluate and add/subtract models applying an offset
between the image coordinate frame and the chip frame (required frame
for model parameters)

added function(s) to instatiate a pmModel from a pmPSF based on a
given coordinate and peak flux.

added a function to set the model normalization based on a source flux
value.

Location:
branches/eam_branch_20070817/psModules
Files:
5 added
29 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070817/psModules/src/astrom/pmAstrometryObjects.c

    r13943 r14544  
    88*  @author EAM, IfA
    99*
    10 *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2007-06-22 00:40:01 $
     10*  @version $Revision: 1.31.4.1 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2007-08-17 21:01:59 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    135135    PS_ASSERT_PTR_NON_NULL(st2, NULL); \
    136136    \
    137     assert(st1->n == 0 || pmIsAstromObj(st1->data[0])); \
    138     assert(st2->n == 0 || pmIsAstromObj(st2->data[0])); \
     137    assert(st1->n == 0 || pmAstromObjTest(st1->data[0])); \
     138    assert(st2->n == 0 || pmAstromObjTest(st2->data[0])); \
    139139    \
    140140    /* sort both lists by X coord; st1 first */ \
     
    400400}
    401401
    402 bool pmIsAstromObj(const psPtr ptr)
     402bool pmAstromObjTest(const psPtr ptr)
    403403{
    404404    return (psMemGetDeallocator(ptr) == (psFreeFunc)astromObjFree);
  • branches/eam_branch_20070817/psModules/src/astrom/pmAstrometryObjects.h

    r11253 r14544  
    44 * @author EAM, IfA
    55 *
    6  * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-01-24 02:54:14 $
     6 * @version $Revision: 1.15.14.1 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-08-17 21:01:59 $
    88 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    99 */
     
    293293 * Is a given pointer a pmAstromObj?
    294294 */
    295 bool pmIsAstromObj(const psPtr ptr);
     295bool pmAstromObjTest(const psPtr ptr);
    296296
    297297
  • branches/eam_branch_20070817/psModules/src/objects/Makefile.am

    r14472 r14544  
    77     pmMoments.c \
    88     pmModel.c \
    9      pmModelGroup.c \
     9     pmModelClass.c \
     10     pmModelUtils.c \
    1011     pmSource.c \
     12     pmSourceUtils.c \
    1113     pmSourceSky.c \
    1214     pmSourceContour.c \
     
    3133
    3234EXTRA_DIST = \
    33         models/pmModel_GAUSS.c \
    34         models/pmModel_PGAUSS.c \
    35         models/pmModel_QGAUSS.c \
    36         models/pmModel_SGAUSS.c \
    37         models/pmModel_RGAUSS.c \
    38         models/pmModel_SERSIC.c
     35     models/pmModel_GAUSS.c \
     36     models/pmModel_PGAUSS.c \
     37     models/pmModel_QGAUSS.c \
     38     models/pmModel_SGAUSS.c \
     39     models/pmModel_RGAUSS.c \
     40     models/pmModel_SERSIC.c
    3941
    4042pkginclude_HEADERS = \
     
    4244     pmMoments.h \
    4345     pmModel.h \
    44      pmModelGroup.h \
     46     pmModelClass.h \
     47     pmModelUtils.h \
    4548     pmSource.h \
     49     pmSourceUtils.h \
    4650     pmSourceSky.h \
    4751     pmSourceContour.h \
  • branches/eam_branch_20070817/psModules/src/objects/models/pmModel_GAUSS.c

    r14220 r14544  
    1919 *****************************************************************************/
    2020
    21 # define PM_MODEL_FUNC       pmModelFunc_GAUSS
    22 # define PM_MODEL_FLUX       pmModelFlux_GAUSS
    23 # define PM_MODEL_GUESS      pmModelGuess_GAUSS
    24 # define PM_MODEL_LIMITS     pmModelLimits_GAUSS
    25 # define PM_MODEL_RADIUS     pmModelRadius_GAUSS
    26 # define PM_MODEL_FROM_PSF   pmModelFromPSF_GAUSS
    27 # define PM_MODEL_FIT_STATUS pmModelFitStatus_GAUSS
     21# define PM_MODEL_FUNC            pmModelFunc_GAUSS
     22# define PM_MODEL_FLUX            pmModelFlux_GAUSS
     23# define PM_MODEL_GUESS           pmModelGuess_GAUSS
     24# define PM_MODEL_LIMITS          pmModelLimits_GAUSS
     25# define PM_MODEL_RADIUS          pmModelRadius_GAUSS
     26# define PM_MODEL_FROM_PSF        pmModelFromPSF_GAUSS
     27# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_GAUSS
     28# define PM_MODEL_FIT_STATUS      pmModelFitStatus_GAUSS
    2829
    2930psF32 PM_MODEL_FUNC(psVector *deriv,
     
    185186
    186187// make an initial guess for parameters
    187 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
    188 {
     188bool PM_MODEL_GUESS (void *inModel, void *inSource)
     189{
     190    pmModel *model = inModel;
     191    pmSource *source = inSource;
     192
    189193    pmMoments *moments = source->moments;
    190194    psF32     *PAR  = model->params->data.F32;
     
    255259
    256260// construct the PSF model from the FLT model and the psf
    257 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf)
    258 {
     261bool PM_MODEL_FROM_PSF (void *inModelPSF, void *inModelFLT, void *inPSF)
     262{
     263    pmModel *modelPSF = inModelPSF;
     264    pmModel *modelFLT = inModelFLT;
     265    pmPSF *psf = inPSF;
    259266
    260267    psF32 *out = modelPSF->params->data.F32;
     
    306313}
    307314
     315// construct the PSF model from the FLT model and the psf
     316// XXX is this sufficiently general do be a global function, not a pmModelClass function?
     317bool PM_MODEL_PARAMS_FROM_PSF (void *inModel, void *inPSF, float Xo, float Yo, float Io)
     318{
     319    pmModel *model = inModel;
     320    pmPSF *psf = inPSF;
     321
     322    psF32 *PAR = model->params->data.F32;
     323
     324    // we require these two parameters to exist
     325    assert (psf->params_NEW->n > PM_PAR_YPOS);
     326    assert (psf->params_NEW->n > PM_PAR_XPOS);
     327
     328    PAR[PM_PAR_SKY]  = 0.0;
     329    PAR[PM_PAR_I0]   = Io;
     330    PAR[PM_PAR_XPOS] = Xo;
     331    PAR[PM_PAR_YPOS] = Yo;
     332   
     333    // supply the model-fitted parameters, or copy from the input
     334    for (int i = 0; i < psf->params_NEW->n; i++) {
     335        if (i == PM_PAR_SKY) continue;
     336        psPolynomial2D *poly = psf->params_NEW->data[i];
     337        assert (poly);
     338        PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     339    }
     340
     341    // the 2D PSF model fits polarization terms (E0,E1,E2)
     342    // convert to shape terms (SXX,SYY,SXY)
     343    // XXX user-defined value for limit?
     344    if (!pmPSF_FitToModel (PAR, 0.1)) {
     345        psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
     346        return false;
     347    }
     348
     349    // apply the model limits here: this truncates excessive extrapolation
     350    // XXX do we need to do this still?  should we put in asserts to test?
     351    for (int i = 0; i < psf->params_NEW->n; i++) {
     352        // apply the limits to all components or just the psf-model parameters?
     353        if (psf->params_NEW->data[i] == NULL)
     354            continue;
     355
     356        bool status = true;
     357        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
     358        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
     359        if (!status) {
     360            psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
     361            model->flags |= PM_MODEL_STATUS_LIMITS;
     362        }
     363    }
     364    return(true);
     365}
     366
    308367// check the status of the fitted model
    309368// this test is invalid if the parameters are derived
    310369// from the PSF model
    311 bool PM_MODEL_FIT_STATUS (pmModel *model)
    312 {
     370bool PM_MODEL_FIT_STATUS (void *inModel)
     371{
     372    pmModel *model = inModel;
    313373
    314374    psF32 dP;
     
    339399# undef PM_MODEL_RADIUS
    340400# undef PM_MODEL_FROM_PSF
     401# undef PM_MODEL_PARAMS_FROM_PSF
    341402# undef PM_MODEL_FIT_STATUS
  • branches/eam_branch_20070817/psModules/src/objects/pmModel.c

    r13898 r14544  
    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.13.6.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-17 21:01:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "pmResiduals.h"
    2424#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);
     25#include "pmModelClass.h"
    3526
    3627static void modelFree(pmModel *tmp)
     
    4536pmModelAlloc(): Allocate the pmModel structure, along with its parameters,
    4637and initialize the type member.  Initialize the params to 0.0.
    47 XXX EAM: simplifying code with pmModelParameterCount
    4838*****************************************************************************/
    4939pmModel *pmModelAlloc(pmModelType type)
     
    5343    pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));
    5444    psMemSetDeallocator(tmp, (psFreeFunc) modelFree);
     45
     46    pmModelClass *class = pmModelClassSelect (type);
     47    if (class == NULL) {
     48        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     49        return(NULL);
     50    }
    5551
    5652    tmp->type = type;
     
    6258    tmp->residuals = NULL;              // XXX should the model own this memory?
    6359
    64     psS32 Nparams = pmModelParameterCount(type);
    65     if (Nparams == 0) {
    66         psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
    67         return(NULL);
    68     }
     60    psS32 Nparams = pmModelClassParameterCount(type);
     61    assert (Nparams);
    6962
    7063    tmp->params  = psVectorAlloc(Nparams, PS_TYPE_F32);
    7164    tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32);
     65    assert (tmp->params);
     66    assert (tmp->dparams);
    7267
    7368    for (psS32 i = 0; i < tmp->params->n; i++) {
     
    7570        tmp->dparams->data.F32[i] = 0.0;
    7671    }
     72
     73    tmp->modelFunc          = class->modelFunc;
     74    tmp->modelFlux          = class->modelFlux;
     75    tmp->modelRadius        = class->modelRadius;
     76    tmp->modelLimits        = class->modelLimits;
     77    tmp->modelGuess         = class->modelGuess;
     78    tmp->modelFromPSF       = class->modelFromPSF;
     79    tmp->modelParamsFromPSF = class->modelParamsFromPSF;
     80    tmp->modelFitStatus     = class->modelFitStatus;
    7781
    7882    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     
    9296    new->radiusFit = model->radiusFit;
    9397
    94     // XXX note that model->residuals is just a reference
    95     new->residuals = model->residuals;
    96 
    9798    for (int i = 0; i < new->params->n; i++) {
    9899        new->params->data.F32[i]  = model->params->data.F32[i];
    99100        new->dparams->data.F32[i] = model->dparams->data.F32[i];
    100101    }
     102
     103    // note that model->residuals is just a reference
     104    new->residuals = model->residuals;
    101105
    102106    return (new);
     
    123127    x->data.F32[1] = (psF32) (row + image->row0);
    124128    psF32 tmpF;
    125     pmModelFunc modelFunc;
    126 
    127     modelFunc = pmModelFunc_GetFunction (model->type);
    128     tmpF = modelFunc (NULL, model->params, x);
     129
     130    tmpF = model->modelFunc (NULL, model->params, x);
     131    psFree(x);
     132    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     133    return(tmpF);
     134}
     135
     136psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, psS32 col, psS32 row, int dx, int dy)
     137{
     138    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     139    PS_ASSERT_PTR_NON_NULL(image, false);
     140    PS_ASSERT_PTR_NON_NULL(model, false);
     141    PS_ASSERT_PTR_NON_NULL(model->params, false);
     142
     143    // Allocate the x coordinate structure and convert row/col to image space.
     144    //
     145    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
     146    x->data.F32[0] = (psF32) (col + image->col0 + dx);
     147    x->data.F32[1] = (psF32) (row + image->row0 + dy);
     148    psF32 tmpF;
     149
     150    tmpF = model->modelFunc (NULL, model->params, x);
    129151    psFree(x);
    130152    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     
    137159                          pmModelOpMode mode,
    138160                          bool add,
    139                           psMaskType maskVal
     161                          psMaskType maskVal,
     162                          int dx,
     163                          int dy
    140164    )
    141165{
     
    148172    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
    149173    psVector *params = model->params;
    150     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
     174
    151175    psS32 imageCol;
    152176    psS32 imageRow;
     
    209233            // Convert i/j to image coord space:
    210234            // XXX should we use using 0.5 pixel offset?
    211             imageCol = ix + image->col0;
    212             imageRow = iy + image->row0;
     235            imageCol = ix + image->col0 + dx;
     236            imageRow = iy + image->row0 + dy;
    213237
    214238            x->data.F32[0] = (float) imageCol;
     
    219243            // add in the desired components for this coordinate
    220244            if (mode & PM_MODEL_OP_FUNC) {
    221                 pixelValue += modelFunc (NULL, params, x);
     245                pixelValue += model->modelFunc (NULL, params, x);
    222246            }
    223247
     
    280304{
    281305    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    282     psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal);
     306    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, 0.0, 0.0);
    283307    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    284308    return(rc);
     
    294318{
    295319    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    296     psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal);
     320    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, 0.0, 0.0);
    297321    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    298322    return(rc);
    299323}
    300324
    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 
     325/******************************************************************************
     326 *****************************************************************************/
     327bool pmModelAddWithOffset(psImage *image,
     328                          psImage *mask,
     329                          pmModel *model,
     330                          pmModelOpMode mode,
     331                          psMaskType maskVal,
     332                          int dx,
     333                          int dy)
     334{
     335    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     336    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, dx, dy);
     337    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     338    return(rc);
     339}
     340
     341/******************************************************************************
     342 *****************************************************************************/
     343bool pmModelSubWithOffset(psImage *image,
     344                          psImage *mask,
     345                          pmModel *model,
     346                          pmModelOpMode mode,
     347                          psMaskType maskVal,
     348                          int dx,
     349                          int dy)
     350{
     351    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     352    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, dx, dy);
     353    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     354    return(rc);
     355}
  • branches/eam_branch_20070817/psModules/src/objects/pmModel.h

    r13898 r14544  
    1 /* @file  pmObjects.h
     1/* @file  pmModel.h
    22 * @brief Functions to define and manipulate object models
    33 *
     
    55 * @author EAM, IfA
    66 *
    7  * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-06-20 02:22:26 $
     7 * @version $Revision: 1.11.6.1 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2007-08-17 21:01:59 $
    99 *
    1010 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1414# define PM_MODEL_H
    1515
     16# define TMP_PSF_TYPE void
     17# define TMP_MODEL_TYPE void
     18# define TMP_SOURCE_TYPE void
     19
    1620/// @addtogroup Objects Object Detection / Analysis Functions
    1721/// @{
     22
     23/* pointers for the functions types below are supplied to each pmModel, and can be used by
     24   the programmer without needing to know the model class */
    1825
    1926// type of model carried by the pmModel structure
     
    4148} pmModelOpMode;
    4249
     50//  This function is the model chi-square minimization function for this model.
     51typedef psMinimizeLMChi2Func pmModelFunc;
     52
     53//  This function sets the parameter limits for this model.
     54typedef psMinimizeLMLimitFunc pmModelLimits;
     55
     56// This function returns the integrated flux for the given model parameters.
     57typedef psF64 (*pmModelFlux)(const psVector *params);
     58
     59// This function returns the radius at which the given model and parameters
     60// achieves the given flux.
     61typedef psF64 (*pmModelRadius)(const psVector *params, double flux);
     62
     63//  This function provides the model guess parameters based on the details of
     64//  the given source.
     65typedef bool (*pmModelGuessFunc)(TMP_MODEL_TYPE *model, TMP_SOURCE_TYPE *source);
     66
     67//  This function constructs the PSF model for the given source based on the
     68//  supplied psf and the EXT model for the object.
     69typedef bool (*pmModelFromPSFFunc)(TMP_MODEL_TYPE *modelPSF, TMP_MODEL_TYPE *modelEXT, TMP_PSF_TYPE *psf);
     70
     71//  This function sets the model parameters based on the PSF for a given coordinate and central
     72//  intensity
     73typedef bool (*pmModelParamsFromPSF)(TMP_MODEL_TYPE *model, TMP_PSF_TYPE *psf, float Xo, float Yo, float Io);
     74
     75//  This function returns the success / failure status of the given model fit
     76typedef bool (*pmModelFitStatusFunc)(TMP_MODEL_TYPE *model);
     77
    4378/** pmModel data structure
    4479 *
     
    6297    float radiusFit;                    ///< fit radius actually used
    6398    pmResiduals *residuals;             ///< normalized PSF residuals
    64 }
    65 pmModel;
    6699
    67 /* XXX we are currently saving the residuals with the pmModel.  It might be better to save this
    68  * in the pmSource.  we may want an API to Add/Sub a pmModel (analytical model only) or a
    69  * pmSource (analytical + residuals).
    70  */
     100    // functions for this model which depend on the model class
     101    pmModelFunc          modelFunc;
     102    pmModelFlux          modelFlux;
     103    pmModelRadius        modelRadius;
     104    pmModelLimits        modelLimits;
     105    pmModelGuessFunc     modelGuess;
     106    pmModelFromPSFFunc   modelFromPSF;
     107    pmModelParamsFromPSF modelParamsFromPSF;
     108    pmModelFitStatusFunc modelFitStatus;
     109} pmModel;
    71110
    72111/** Symbolic names for the elements of [d]params
  • branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.c

    r14325 r14544  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-07-20 00:31:43 $
     8 *  @version $Revision: 1.17.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-17 21:01:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828#include "pmResiduals.h"
    2929#include "pmModel.h"
    30 #include "pmResiduals.h"
    31 #include "pmPSF.h"
    32 #include "pmSource.h"
     30// #include "pmResiduals.h"
     31// #include "pmPSF.h"
     32// #include "pmSource.h"
    3333#include "pmModelGroup.h"
    3434#include "pmErrorCodes.h"
     
    198198    return (models[type].name);
    199199}
    200 
    201 /******************************************************************************
    202     pmSourceModelGuess(source, model): This function allocates a new
    203     pmModel structure based on the given modelType specified in the argument list.
    204     The corresponding pmModelGuess function is returned, and used to
    205     supply the values of the params array in the pmModel structure.
    206  
    207     XXX: Many parameters are based on the src->moments structure, which is in
    208     image, not subImage coords.  Therefore, the calls to the model evaluation
    209     functions will be in image, not subImage coords.  Remember this.
    210 *****************************************************************************/
    211 pmModel *pmSourceModelGuess(pmSource *source,
    212                             pmModelType modelType)
    213 {
    214     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    215     PS_ASSERT_PTR_NON_NULL(source, NULL);
    216     PS_ASSERT_PTR_NON_NULL(source->moments, NULL);
    217     PS_ASSERT_PTR_NON_NULL(source->peak, NULL);
    218 
    219     pmModel *model = pmModelAlloc(modelType);
    220 
    221     pmModelGuessFunc modelGuessFunc = pmModelGuessFunc_GetFunction(modelType);
    222     if (!modelGuessFunc(model, source)) {
    223         psFree (model);
    224         return NULL;
    225     }
    226 
    227     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
    228     return(model);
    229 }
    230 
  • branches/eam_branch_20070817/psModules/src/objects/pmModelGroup.h

    r11253 r14544  
    11/* @file  pmModelGroup.h
    22 *
    3  * The object model function types are defined to allow for the flexible addition
    4  * of new object models. Every object model, with parameters represented by
    5  * pmModel, has an associated set of functions which provide necessary support
    6  * operations. A set of abstract functions allow the programmer to select the
    7  * approriate function or property for a specific named object model.
     3 * The object model function types are desined to allow for the flexible addition of new object
     4 * models. Every object model, with parameters represented by pmModel, has an associated set of
     5 * functions which provide necessary support operations. A set of abstract functions allow the
     6 * programmer to select the approriate function or property for a specific named object model.
     7 *
     8 * Every model instance belongs to a class of models, defined by the value of
     9 * the pmModelType type entry. Various functions need access to information about
     10 * each of the models. Some of this information varies from model to model, and
     11 * may depend on the current parameter values or other data quantities. In order
     12 * to keep the code from requiring the information about each model to be coded
     13 * into the low-level fitting routines, we define a collection of functions which
     14 * allow us to abstract this type of model-dependent information. These generic
     15 * functions take the model type and return the corresponding function pointer
     16 * for the specified model. Each model is defined by creating this collection of
     17 * specific functions, and placing them in a single file for each model. We
     18 * define the following structure to carry the collection of information about
     19 * the models.
    820 *
    921 * @author EAM, IfA
    1022 *
    11  * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    12  * @date $Date: 2007-01-24 02:54:15 $
     23 * @version $Revision: 1.7.14.1 $ $Name: not supported by cvs2svn $
     24 * @date $Date: 2007-08-17 21:01:59 $
    1325 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1426 */
     
    2335typedef psMinimizeLMChi2Func pmModelFunc;
    2436
    25 //  This function is the model chi-square minimization function for this model.
     37//  This function sets the parameter limits for this model.
    2638typedef psMinimizeLMLimitFunc pmModelLimits;
    2739
     
    2941typedef psF64 (*pmModelFlux)(const psVector *params);
    3042
    31 
    3243// This function returns the radius at which the given model and parameters
    3344// achieves the given flux.
    3445typedef psF64 (*pmModelRadius)(const psVector *params, double flux);
    3546
    36 /*  This function sets the model parameter limits vectors for the given model
    37  */
    38 // typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max);
    39 
    40 /*  This function provides the model guess parameters based on the details of
    41  *   the given source.
    42  */
     47//  This function provides the model guess parameters based on the details of
     48//  the given source.
    4349typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source);
    4450
    45 
    46 /*  This function constructs the PSF model for the given source based on the
    47  *  supplied psf and the EXT model for the object.
    48  */
     51//  This function constructs the PSF model for the given source based on the
     52//  supplied psf and the EXT model for the object.
    4953typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf);
    5054
    51 /*  This function returns the success / failure status of the given model fit
    52  */
     55//  This function sets the model parameters based on the PSF for a given coordinate and central
     56//  intensity
     57typedef bool (*pmModelParamsFromPSF)(pmModel *model, pmPSF *psf, float Xo, float Yo, float Io);
     58
     59//  This function returns the success / failure status of the given model fit
    5360typedef bool (*pmModelFitStatusFunc)(pmModel *model);
    5461
    55 /* Every model instance belongs to a class of models, defined by the value of
    56  * the pmModelType type entry. Various functions need access to information about
    57  * each of the models. Some of this information varies from model to model, and
    58  * may depend on the current parameter values or other data quantities. In order
    59  * to keep the code from requiring the information about each model to be coded
    60  * into the low-level fitting routines, we define a collection of functions which
    61  * allow us to abstract this type of model-dependent information. These generic
    62  * functions take the model type and return the corresponding function pointer
    63  * for the specified model. Each model is defined by creating this collection of
    64  * specific functions, and placing them in a single file for each model. We
    65  * define the following structure to carry the collection of information about
    66  * the models.
    67  */
    6862typedef struct
    6963{
     
    7670    pmModelGuessFunc     modelGuessFunc;
    7771    pmModelFromPSFFunc   modelFromPSFFunc;
     72    pmModelParamsFromPSF modelParamsFromPSF;
    7873    pmModelFitStatusFunc modelFitStatusFunc;
    7974}
  • branches/eam_branch_20070817/psModules/src/objects/pmModelUtils.c

    r14530 r14544  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-08-16 18:33:37 $
     7 *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-08-17 21:01:59 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2020#include <string.h>
    2121#include <pslib.h>
     22#include "pmHDU.h"
     23#include "pmFPA.h"
     24#include "pmGrowthCurve.h"
    2225#include "pmResiduals.h"
    2326#include "pmModel.h"
     27#include "pmPSF.h"
     28#include "pmErrorCodes.h"
     29#include "pmModelUtils.h"
    2430
    25 // instantiate a model for the PSF at this location (normalized or not?)
    26 // NOTE: psf and (x,y) are defined wrt chip coordinates
    27 pmModel *pmModelFromPSFforXY (pmPSF *psf, float x, float y, float flux) {
     31// instantiate a model for the PSF at this location with peak flux
     32// NOTE: psf and (Xo,Yo) are defined wrt chip coordinates
     33pmModel *pmModelFromPSFforXY (pmPSF *psf, float Xo, float Yo, float Io) {
    2834
    2935    assert (psf);
    3036
    3137    // allocate a new pmModel to hold the PSF version
    32     pmModel *modelEXT = pmModelAlloc (psf->type);
    33 
    34     modelEXT->params->data.F32[PM_PAR_SKY]  = 0.0;
    35     modelEXT->params->data.F32[PM_PAR_I0]   = 1.0;
    36     modelEXT->params->data.F32[PM_PAR_XPOS] = x;
    37     modelEXT->params->data.F32[PM_PAR_YPOS] = y;
    38 
    39     // find function used to set the model parameters
    40     pmModelFromPSFFunc modelFromPSFFunc = pmModelFromPSFFunc_GetFunction (psf->type);
    41 
    42     // allocate a new pmModel to hold the PSF version
    4338    pmModel *modelPSF = pmModelAlloc (psf->type);
    4439
    45     // adjust the normalization:
    46     pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
    47     normFlux = modelFluxFunc (model->params);
    48     assert (isfinite(normFlux));
    49     assert (normFlux > 0);
    50 
    51     // set the correct normalization
    52     modelEXT->params->data.F32[PM_PAR_I0] = flux / normFlux;
    53 
    5440    // set model parameters for this source based on PSF information
    55     if (!modelFromPSFFunc (modelPSF, modelEXT, psf)) {
     41    if (!modelPSF->modelParamsFromPSF (modelPSF, psf, Xo, Yo, Io)) {
    5642        psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
    5743        psFree(modelPSF);
    5844        return NULL;
    5945    }
     46
    6047    // XXX note that model->residuals is just a reference
    6148    modelPSF->residuals = psf->residuals;
    62     psFree (modelEXT);
    6349
    6450    return (modelPSF);
    6551}
    6652
    67 pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, pmSourceType type) {
     53// set this model to have the requested flux
     54bool pmModelSetFlux (pmModel *model, float flux) {
    6855
    69     pmSource *source = pmSourceAlloc ();
     56    // set Io to be 1.0
     57    model->params->data.F32[PM_PAR_I0] = 1.0;
    7058
    71     // use the model centroid for the peak
    72     switch (type) {
    73       case PM_SOURCE_TYPE_STAR:
    74         source->modelPSF = model;
    75         break;
    76       case PM_SOURCE_TYPE_EXTENDED:
    77         source->modelEXT = model;
    78         break;
    79       default:
    80         psAbort ("psphot", "error");
    81     }
     59    // determine the normalized flux
     60    float normFlux = model->modelFlux (model->params);
     61    assert (isfinite(normFlux));
     62    assert (normFlux > 0);
    8263
    83     source->peak = pmPeakAlloc ();
     64    // set the desired normalization
     65    model->params->data.F32[PM_PAR_I0] = flux / normFlux;
    8466
    85     float x = model->params->data.F32[PM_PAR_XPOS];
    86     float y = model->params->data.F32[PM_PAR_YPOS];
    87 
    88     // XXX need to define the radius in some rational way
    89     // XXX x,y are defined wrt readout->image parent, but the model
    90     // parameters are defined wrt chip coordinates
    91     pmSourceDefinePixels (source, readout, x, y, radius);
    92 
    93     return (source);
     67    return true;
    9468}
  • branches/eam_branch_20070817/psModules/src/objects/pmPSF.c

    r13898 r14544  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-06-20 02:22:26 $
     8 *  @version $Revision: 1.25.6.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-17 21:01:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232#include "pmGrowthCurve.h"
    3333#include "pmPSF.h"
    34 #include "pmModelGroup.h"
     34#include "pmModelClass.h"
    3535#include "pmSourcePhotometry.h"
    3636#include "pmFPAMaskWeight.h"
     
    124124    psf->residuals = NULL;
    125125
    126     Nparams = pmModelParameterCount (type);
     126    Nparams = pmModelClassParameterCount (type);
    127127    if (!Nparams) {
    128128        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    169169pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)
    170170{
    171 
    172     // need to define the relationship between the modelEXT and modelPSF ?
    173 
    174     // find function used to set the model parameters
    175     pmModelFromPSFFunc modelFromPSFFunc = pmModelFromPSFFunc_GetFunction (psf->type);
    176 
    177171    // allocate a new pmModel to hold the PSF version
    178172    pmModel *modelPSF = pmModelAlloc (psf->type);
    179173
    180174    // set model parameters for this source based on PSF information
    181     if (!modelFromPSFFunc (modelPSF, modelEXT, psf)) {
     175    if (!modelEXT->modelFromPSF (modelPSF, modelEXT, psf)) {
    182176        psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
    183177        psFree(modelPSF);
     
    335329    va_start(ap, sxy);
    336330
    337     pmModelType type = pmModelSetType (typeName);
     331    pmModelType type = pmModelClassGetType (typeName);
    338332    psPolynomial2D *psfTrend = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 0, 0);
    339333    pmPSF *psf = pmPSFAlloc (type, true, psfTrend);
  • branches/eam_branch_20070817/psModules/src/objects/pmPSF_IO.c

    r14207 r14544  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-07-14 03:20:22 $
     8 *  @version $Revision: 1.20.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-17 21:01:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4444#include "pmPSF_IO.h"
    4545#include "pmSource.h"
    46 #include "pmModelGroup.h"
     46#include "pmModelClass.h"
    4747#include "pmSourceIO.h"
    4848
     
    313313        psMetadata *header = psMetadataAlloc();
    314314
    315         char *modelName = pmModelGetType (psf->type);
     315        char *modelName = pmModelClassGetName (psf->type);
    316316        psMetadataAddStr (header, PS_LIST_TAIL, "PSF_NAME", 0, "PSF model name", modelName);
    317317
    318318        psMetadataAddBool (header, PS_LIST_TAIL, "POISSON",  0, "Use Poisson errors in fits?", psf->poissonErrors);
    319319
    320         int nPar = pmModelParameterCount (psf->type)    ;
     320        int nPar = pmModelClassParameterCount (psf->type)    ;
    321321        psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
    322322
     
    599599    // load the PSF model parameters from the FITS table
    600600    char *modelName = psMetadataLookupStr (&status, header, "PSF_NAME");
    601     pmModelType type = pmModelSetType (modelName);
     601    pmModelType type = pmModelClassGetType (modelName);
    602602    if (type == -1) {
    603603        psError(PS_ERR_UNKNOWN, true, "invalid model name %s in psf file %s", modelName, file->filename);
     
    612612    // check the number of expected parameters
    613613    int nPar = psMetadataLookupS32 (&status, header, "PSF_NPAR");
    614     if (nPar != pmModelParameterCount (psf->type))
     614    if (nPar != pmModelClassParameterCount (psf->type))
    615615        psAbort("mismatch model par count");
    616616
     
    717717    }
    718718
    719     char *modelName = pmModelGetType (psf->type);
     719    char *modelName = pmModelClassGetName (psf->type);
    720720    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NAME", PS_DATA_STRING, "PSF model name", modelName);
    721721
    722     int nPar = pmModelParameterCount (psf->type)    ;
     722    int nPar = pmModelClassParameterCount (psf->type)    ;
    723723    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
    724724
     
    749749
    750750    char *modelName = psMetadataLookupPtr (&status, metadata, "PSF_MODEL_NAME");
    751     pmModelType type = pmModelSetType (modelName);
     751    pmModelType type = pmModelClassGetType (modelName);
    752752
    753753    bool poissonErrors = psMetadataLookupPtr (&status, metadata, "PSF_POISSON_ERRORS");
     
    759759
    760760    int nPar = psMetadataLookupS32 (&status, metadata, "PSF_MODEL_NPAR");
    761     if (nPar != pmModelParameterCount (psf->type))
     761    if (nPar != pmModelClassParameterCount (psf->type))
    762762        psAbort("mismatch model par count");
    763763
  • branches/eam_branch_20070817/psModules/src/objects/pmPSFtry.c

    r13898 r14544  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-06-20 02:22:26 $
     7 *  @version $Revision: 1.43.6.1 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-08-17 21:01:59 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2525#include "pmModel.h"
    2626#include "pmSource.h"
     27#include "pmSourceUtils.h"
    2728#include "pmGrowthCurve.h"
    2829#include "pmPSF.h"
    2930#include "pmPSFtry.h"
    30 #include "pmModelGroup.h"
     31#include "pmModelClass.h"
    3132#include "pmSourceFitModel.h"
    3233#include "pmSourcePhotometry.h"
     
    5960
    6061    // validate the requested model name
    61     pmModelType type = pmModelSetType (modelName);
     62    pmModelType type = pmModelClassGetType (modelName);
    6263    if (type == -1) {
    6364        psError (PS_ERR_UNKNOWN, true, "invalid model name %s", modelName);
  • branches/eam_branch_20070817/psModules/src/objects/pmPeaks.c

    r13034 r14544  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-04-26 01:20:29 $
     8 *  @version $Revision: 1.15.8.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-17 21:01:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535                        pmPeakType type)
    3636{
    37     psTrace(__func__, 5, "---- begin ----\n");
     37    psTrace("psModules.objects", 5, "---- begin ----\n");
    3838
    3939    if (peaks == NULL) {
     
    6767    psFree (peak);
    6868
    69     psTrace(__func__, 5, "---- end ----\n");
     69    psTrace("psModules.objects", 5, "---- end ----\n");
    7070    return(peaks);
    7171}
     
    118118*****************************************************************************/
    119119static void peakFree(pmPeak *tmp)
    120 {} // used by pmIsPeak()
     120{} // used by pmPeakTest()
    121121
    122122pmPeak *pmPeakAlloc(psS32 x,
     
    145145}
    146146
    147 bool pmIsPeak(const psPtr ptr)
     147bool pmPeakTest(const psPtr ptr)
    148148{
    149149    return (psMemGetDeallocator(ptr) == (psFreeFunc)peakFree);
     
    193193
    194194/******************************************************************************
    195 pmFindVectorPeaks(vector, threshold): Find all local peaks in the given vector
     195pmPeaksInVector(vector, threshold): Find all local peaks in the given vector
    196196above the given threshold.  Returns a vector of type PS_TYPE_U32 containing
    197197the location (x value) of all peaks.
     
    203203Depending upon actual use, this may need to be optimized.
    204204*****************************************************************************/
    205 psVector *pmFindVectorPeaks(const psVector *vector,
    206                             psF32 threshold)
     205psVector *pmPeaksInVector(const psVector *vector,
     206                        psF32 threshold)
    207207{
    208208    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     
    295295
    296296/******************************************************************************
    297 pmFindImagePeaks(image, threshold): Find all local peaks in the given psImage
     297pmPeaksInImage(image, threshold): Find all local peaks in the given psImage
    298298above the given threshold.  Returns a psArray containing location (x/y value)
    299299of all peaks.
     
    309309
    310310*****************************************************************************/
    311 psArray *pmFindImagePeaks(const psImage *image, psF32 threshold)
     311psArray *pmPeaksInImage(const psImage *image, psF32 threshold)
    312312{
    313313    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     
    327327    row = 0;
    328328    tmpRow = getRowVectorFromImage((psImage *) image, row);
    329     psVector *row1 = pmFindVectorPeaks(tmpRow, threshold);
    330     // pmFindVectorPeaks returns coords in the vector, not corrected for col0
     329    psVector *row1 = pmPeaksInVector(tmpRow, threshold);
     330    // pmPeaksInVector returns coords in the vector, not corrected for col0
    331331
    332332    for (psU32 i = 0 ; i < row1->n ; i++ ) {
     
    382382    for (row = 1 ; row < (image->numRows - 1) ; row++) {
    383383        tmpRow = getRowVectorFromImage((psImage *) image, row);
    384         row1 = pmFindVectorPeaks(tmpRow, threshold);
     384        row1 = pmPeaksInVector(tmpRow, threshold);
    385385
    386386        // Step through all local peaks in this row.
     
    461461    row = image->numRows - 1;
    462462    tmpRow = getRowVectorFromImage((psImage *) image, row);
    463     row1 = pmFindVectorPeaks(tmpRow, threshold);
     463    row1 = pmPeaksInVector(tmpRow, threshold);
    464464    for (psU32 i = 0 ; i < row1->n ; i++ ) {
    465465        col = row1->data.U32[i];
     
    501501}
    502502
    503 
    504 /******************************************************************************
    505 psCullPeaks(peaks, maxValue, valid): eliminate peaks from the psArray that have
    506 a peak value above the given maximum, or fall outside the valid region.
    507  
    508 XXX: Should the sky value be used when comparing the maximum?
    509  
    510 XXX: warning message if valid is NULL?
    511  
    512 XXX: changed API to create a NEW output psArray (should change name as well)
    513  
    514 XXX: Do we free the psList elements of those culled peaks?
    515  
    516 XXX EAM : do we still need pmCullPeaks, or only pmPeaksSubset?
    517 *****************************************************************************/
    518 psList *pmCullPeaks(psList *peaks,
    519                     psF32 maxValue,
    520                     const psRegion valid)
    521 {
    522     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    523     PS_ASSERT_PTR_NON_NULL(peaks, NULL);
    524 
    525     psListElem *tmpListElem = (psListElem *) peaks->head;
    526     psS32 indexNum = 0;
    527 
    528     //    printf("pmCullPeaks(): list size is %d\n", peaks->size);
    529     while (tmpListElem != NULL) {
    530         pmPeak *tmpPeak = (pmPeak *) tmpListElem->data;
    531         if ((tmpPeak->value > maxValue) ||
    532                 (true == isItInThisRegion(valid, tmpPeak->x, tmpPeak->y))) {
    533             psListRemoveData(peaks, (psPtr) tmpPeak);
    534         }
    535 
    536         indexNum++;
    537         tmpListElem = tmpListElem->next;
    538     }
    539 
    540     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
    541     return(peaks);
    542 }
    543 
    544 // XXX EAM: I changed this to return a new, subset array
    545 //          rather than alter the existing one
    546 // XXX: Fix the *valid pointer.
     503// return a new array of peaks which are in the valid region and below threshold
     504// XXX this function is unused and probably could be dropped
    547505psArray *pmPeaksSubset(
    548506    psArray *peaks,
     
    555513    psArray *output = psArrayAllocEmpty (200);
    556514
    557     psTrace (".pmObjects.pmCullPeaks", 3, "list size is %ld\n", peaks->n);
     515    psTrace ("psModules.objects", 3, "list size is %ld\n", peaks->n);
    558516
    559517    for (int i = 0; i < peaks->n; i++) {
  • branches/eam_branch_20070817/psModules/src/objects/pmPeaks.h

    r11253 r14544  
    1010 * @author GLG, MHPCC
    1111 *
    12  * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    13  * @date $Date: 2007-01-24 02:54:15 $
     12 * @version $Revision: 1.6.14.1 $ $Name: not supported by cvs2svn $
     13 * @date $Date: 2007-08-17 21:01:59 $
    1414 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1515 */
     
    7272);
    7373
    74 bool pmIsPeak(const psPtr ptr);
     74bool pmPeakTest(const psPtr ptr);
    7575
    76 /** pmFindVectorPeaks()
     76/** pmPeaksInVector()
    7777 *
    7878 * Find all local peaks in the given vector above the given threshold. A peak
     
    9191 *
    9292 */
    93 psVector *pmFindVectorPeaks(
     93psVector *pmPeaksInVector(
    9494    const psVector *vector,  ///< The input vector (float)
    9595    float threshold   ///< Threshold above which to find a peak
     
    9797
    9898
    99 /** pmFindImagePeaks()
     99/** pmPeaksInImage()
    100100 *
    101101 * Find all local peaks in the given image above the given threshold. This
     
    111111 *
    112112 */
    113 psArray *pmFindImagePeaks(
     113psArray *pmPeaksInImage(
    114114    const psImage *image,  ///< The input image where peaks will be found (float)
    115115    float threshold   ///< Threshold above which to find a peak
  • branches/eam_branch_20070817/psModules/src/objects/pmSource.c

    r14529 r14544  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-08-16 18:33:00 $
     8 *  @version $Revision: 1.34.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-17 21:01:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    113113}
    114114
    115 bool pmIsSource(const psPtr ptr)
     115bool pmSourceTest(const psPtr ptr)
    116116{
    117117    return (psMemGetDeallocator(ptr) == (psFreeFunc)sourceFree);
     
    337337            return emptyClump;
    338338        }
    339         peaks = pmFindImagePeaks (splane, stats[0].max / 2);
     339        peaks = pmPeaksInImage (splane, stats[0].max / 2);
    340340        psTrace ("psModules.objects", 2, "clump threshold is %f\n", stats[0].max/2);
    341341
  • branches/eam_branch_20070817/psModules/src/objects/pmSource.h

    r14505 r14544  
    33 * @author EAM, IfA; GLG, MHPCC
    44 *
    5  * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    6  * @date $Date: 2007-08-15 20:21:18 $
     5 * @version $Revision: 1.16.2.1 $ $Name: not supported by cvs2svn $
     6 * @date $Date: 2007-08-17 21:01:59 $
    77 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    88 */
     
    114114void pmSourceFreePixels(pmSource *source);
    115115
    116 bool pmIsSource(const psPtr ptr);
     116bool pmSourceTest(const psPtr ptr);
    117117
    118118/** pmSourceDefinePixels()
  • branches/eam_branch_20070817/psModules/src/objects/pmSourceFitModel.c

    r13932 r14544  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-06-21 22:58:11 $
     8 *  @version $Revision: 1.24.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-17 21:01:59 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3030#include "pmPSF.h"
    3131#include "pmSource.h"
    32 #include "pmModelGroup.h"
     32#include "pmModelClass.h"
    3333#include "pmSourceFitModel.h"
    3434
     
    116116    psVector *dparams = model->dparams;
    117117
    118     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
    119     if (!modelFunc)
    120         psAbort("invalid model function");
    121     pmModelLimits checkLimits = pmModelLimits_GetFunction (model->type);
    122     if (!checkLimits)
    123         psAbort("invalid model limits function");
    124 
    125118    // create the minimization constraints
    126119    psMinConstraint *constraint = psMinConstraintAlloc();
    127120    constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_U8);
    128     constraint->checkLimits = checkLimits;
     121    constraint->checkLimits = model->modelLimits;
    129122
    130123    // set parameter mask based on fitting mode
     
    156149    // force the floating parameters to fall within the contraint ranges
    157150    for (int i = 0; i < params->n; i++) {
    158         checkLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
    159         checkLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
     151        model->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
     152        model->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
    160153    }
    161154
     
    174167    psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
    175168
    176     fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, modelFunc);
     169    fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, model->modelFunc);
    177170    for (int i = 0; i < dparams->n; i++) {
    178171        if (psTraceGetLevel("psModules.objects") >= 4) {
     
    201194            altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1;
    202195        }
    203         psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, modelFunc);
     196        psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, model->modelFunc);
    204197        for (int i = 0; i < dparams->n; i++) {
    205198            if (!constraint->paramMask->data.U8[i])
     
    236229    return(rc);
    237230}
     231
     232# define SKIP_FIT_SET 1
     233# if (SKIP_FIT_SET)
     234
     235bool pmSourceFitSet (pmSource *source,
     236                     psArray *modelSet,
     237                     pmSourceFitMode mode,
     238                     psMaskType maskVal)
     239{
     240    psTrace("psModules.objects", 3, "---- %s begin ----\n", __func__);
     241    PS_ASSERT_PTR_NON_NULL(source, false);
     242    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
     243    PS_ASSERT_PTR_NON_NULL(source->maskObj, false);
     244    PS_ASSERT_PTR_NON_NULL(source->weight, false);
     245
     246    return true;
     247}
     248
     249# else
    238250
    239251/********************* Source Model Set Functions ***************************/
     
    255267    oneModelFunc = pmModelFunc_GetFunction (type);
    256268    oneCheckLimits = pmModelLimits_GetFunction (type);
    257     nOnePar = pmModelParameterCount (type);
     269    nOnePar = pmModelClassParameterCount (type);
    258270
    259271    onePar = psVectorAlloc (nOnePar, PS_DATA_F32);
     
    567579}
    568580
     581# endif
  • branches/eam_branch_20070817/psModules/src/objects/pmSourceIO.c

    r14208 r14544  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-07-14 03:20:44 $
     5 *  @version $Revision: 1.45.4.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-17 21:01:59 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3737#include "pmPSF.h"
    3838#include "pmSource.h"
    39 #include "pmModelGroup.h"
     39#include "pmModelClass.h"
    4040#include "pmSourceIO.h"
    4141
  • branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_CMP.c

    r13137 r14544  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-05-03 00:13:03 $
     5 *  @version $Revision: 1.29.8.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-17 21:01:59 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
     
    154154
    155155    // define PSF model type
    156     int modelType = pmModelSetType ("PS_MODEL_GAUSS");
     156    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
    157157
    158158    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
    159159    if (PSF_NAME != NULL) {
    160         modelType = pmModelSetType (PSF_NAME);
     160        modelType = pmModelClassGetType (PSF_NAME);
    161161    }
    162162
  • branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_OBJ.c

    r13137 r14544  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-05-03 00:13:03 $
     5 *  @version $Revision: 1.13.8.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-17 21:01:59 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
  • branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_PS1_DEV_0.c

    r13139 r14544  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-05-03 00:13:42 $
     5 *  @version $Revision: 1.10.8.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-17 21:01:59 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
     
    152152
    153153    // define PSF model type
    154     int modelType = pmModelSetType ("PS_MODEL_GAUSS");
     154    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
    155155
    156156    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
    157157    if (PSF_NAME != NULL) {
    158         modelType = pmModelSetType (PSF_NAME);
     158        modelType = pmModelClassGetType (PSF_NAME);
    159159    }
    160160
  • branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_RAW.c

    r12949 r14544  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-04-21 19:47:14 $
     5 *  @version $Revision: 1.15.8.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-17 21:01:59 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourcePhotometry.h"
    3939#include "pmSourceIO.h"
  • branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SMPDATA.c

    r13139 r14544  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-05-03 00:13:42 $
     5 *  @version $Revision: 1.9.8.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-17 21:01:59 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
     
    132132
    133133    // define PSF model type
    134     int modelType = pmModelSetType ("PS_MODEL_GAUSS");
     134    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
    135135
    136136    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
    137137    if (PSF_NAME != NULL) {
    138         modelType = pmModelSetType (PSF_NAME);
     138        modelType = pmModelClassGetType (PSF_NAME);
    139139    }
    140140
  • branches/eam_branch_20070817/psModules/src/objects/pmSourceIO_SX.c

    r13064 r14544  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-04-27 22:14:08 $
     5 *  @version $Revision: 1.11.8.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-17 21:01:59 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
  • branches/eam_branch_20070817/psModules/src/objects/pmSourcePhotometry.c

    r13898 r14544  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-06-20 02:22:26 $
     5 *  @version $Revision: 1.28.6.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-17 21:01:59 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2929#include "pmPSF.h"
    3030#include "pmSource.h"
    31 #include "pmModelGroup.h"
     31#include "pmModelClass.h"
    3232#include "pmSourcePhotometry.h"
    3333
     
    250250
    251251    // measure fitMag
    252     pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
    253     fitSum = modelFluxFunc (model->params);
     252    fitSum = model->modelFlux (model->params);
    254253    if (fitSum <= 0)
    255254        return false;
     
    324323
    325324    // the model function returns the source flux at a position
    326     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
    327325    psVector *coord = psVectorAlloc(2, PS_TYPE_F32);
    328326
     
    354352
    355353            // for the full model, add all points
    356             value = modelFunc (NULL, params, coord) - sky;
     354            value = model->modelFunc (NULL, params, coord) - sky;
    357355            modelSum += value;
    358356
  • branches/eam_branch_20070817/psModules/src/psmodules.h

    r14505 r14544  
    8484#include <pmModel.h>
    8585#include <pmSource.h>
     86#include <pmSourceUtils.h>
    8687#include <pmSourceIO.h>
    8788#include <pmSourceSky.h>
     
    9394#include <pmPSF_IO.h>
    9495#include <pmPSFtry.h>
    95 #include <pmModelGroup.h>
     96#include <pmModelClass.h>
     97#include <pmModelUtils.h>
    9698#include <pmSourcePhotometry.h>
    9799
  • branches/eam_branch_20070817/psModules/test/objects/tap_pmSourceFitModel.c

    r13034 r14544  
    117117    source->moments = pmMomentsAlloc ();
    118118
    119     pmModelType type = pmModelSetType ("PS_MODEL_GAUSS");
     119    pmModelType type = pmModelClassGetType ("PS_MODEL_GAUSS");
    120120    source->modelEXT = pmModelAlloc (type);
    121121
  • branches/eam_branch_20070817/psModules/test/objects/tap_pmSourceFitModel_Delta.c

    r13034 r14544  
    3535    source->moments = pmMomentsAlloc ();
    3636
    37     pmModelType type = pmModelSetType ("PS_MODEL_GAUSS");
     37    pmModelType type = pmModelClassGetType ("PS_MODEL_GAUSS");
    3838    source->modelEXT = pmModelAlloc (type);
    3939
     
    7171    pmModel *guess;
    7272
    73     type = pmModelSetType ("PS_MODEL_PGAUSS");
     73    type = pmModelClassGetType ("PS_MODEL_PGAUSS");
    7474    guess = pmModelAlloc (type);
    7575
  • branches/eam_branch_20070817/psModules/test/objects/tst_pmObjects01.c

    r6511 r14544  
    3131    most of psObjects.c is not tested
    3232 *
    33  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    34  *  @date $Date: 2006-03-04 01:01:34 $
     33 *  @version $Revision: 1.8.16.1 $ $Name: not supported by cvs2svn $
     34 *  @date $Date: 2007-08-17 21:01:59 $
    3535 *
    3636 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    186186    //
    187187    psS32 i = 0;
    188     while (0 != pmModelParameterCount(i)) {
    189         printf("Testing pmModelAlloc(%s)...\n", pmModelGetType(0));
     188    while (0 != pmModelClassParameterCount(i)) {
     189        printf("Testing pmModelAlloc(%s)...\n", pmModelClassGetName(0));
    190190        pmModel *tmpModel = pmModelAlloc(i);
    191191        if (tmpModel == NULL) {
    192             printf("TEST ERROR: pmModelAlloc(%s) returned a NULL pmModel\n", pmModelGetType(0));
     192            printf("TEST ERROR: pmModelAlloc(%s) returned a NULL pmModel\n", pmModelClassGetName(0));
    193193            testStatus = false;
    194194        } else {
Note: See TracChangeset for help on using the changeset viewer.