IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.