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/pmModelUtils.c

    r14530 r14652  
    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.2 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-08-24 00:11:02 $
    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"
    2224#include "pmResiduals.h"
     25#include "pmGrowthCurve.h"
     26#include "pmPSF.h"
    2327#include "pmModel.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) {
    28 
    29     assert (psf);
    30 
    31     // 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 
     31/*****************************************************************************
     32pmModelFromPSF (*modelEXT, *psf):  use the model position parameters to
     33construct a realization of the PSF model at the object coordinates
     34 *****************************************************************************/
     35pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)
     36{
    4237    // 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 (!modelEXT->modelFromPSF (modelPSF, modelEXT, psf)) {
    5642        psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
    5743        psFree(modelPSF);
     
    6046    // XXX note that model->residuals is just a reference
    6147    modelPSF->residuals = psf->residuals;
    62     psFree (modelEXT);
    6348
    6449    return (modelPSF);
    6550}
    6651
    67 pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, pmSourceType type) {
     52// instantiate a model for the PSF at this location with peak flux
     53// NOTE: psf and (Xo,Yo) are defined wrt chip coordinates
     54pmModel *pmModelFromPSFforXY (pmPSF *psf, float Xo, float Yo, float Io) {
    6855
    69     pmSource *source = pmSourceAlloc ();
     56    assert (psf);
    7057
    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");
     58    // allocate a new pmModel to hold the PSF version
     59    pmModel *modelPSF = pmModelAlloc (psf->type);
     60
     61    // set model parameters for this source based on PSF information
     62    if (!modelPSF->modelParamsFromPSF (modelPSF, psf, Xo, Yo, Io)) {
     63        psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
     64        psFree(modelPSF);
     65        return NULL;
    8166    }
    8267
    83     source->peak = pmPeakAlloc ();
     68    // XXX note that model->residuals is just a reference
     69    modelPSF->residuals = psf->residuals;
    8470
    85     float x = model->params->data.F32[PM_PAR_XPOS];
    86     float y = model->params->data.F32[PM_PAR_YPOS];
     71    return (modelPSF);
     72}
    8773
    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);
     74// set this model to have the requested flux
     75bool pmModelSetFlux (pmModel *model, float flux) {
    9276
    93     return (source);
     77    // set Io to be 1.0
     78    model->params->data.F32[PM_PAR_I0] = 1.0;
     79
     80    // determine the normalized flux
     81    float normFlux = model->modelFlux (model->params);
     82    assert (isfinite(normFlux));
     83    assert (normFlux > 0);
     84
     85    // set the desired normalization
     86    model->params->data.F32[PM_PAR_I0] = flux / normFlux;
     87
     88    return true;
    9489}
Note: See TracChangeset for help on using the changeset viewer.