Changeset 14652 for trunk/psModules/src/objects/pmModelUtils.c
- Timestamp:
- Aug 23, 2007, 2:11:02 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmModelUtils.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmModelUtils.c
r14530 r14652 5 5 * @author EAM, IfA 6 6 * 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 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 20 20 #include <string.h> 21 21 #include <pslib.h> 22 #include "pmHDU.h" 23 #include "pmFPA.h" 22 24 #include "pmResiduals.h" 25 #include "pmGrowthCurve.h" 26 #include "pmPSF.h" 23 27 #include "pmModel.h" 28 #include "pmErrorCodes.h" 29 #include "pmModelUtils.h" 24 30 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 /***************************************************************************** 32 pmModelFromPSF (*modelEXT, *psf): use the model position parameters to 33 construct a realization of the PSF model at the object coordinates 34 *****************************************************************************/ 35 pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf) 36 { 42 37 // allocate a new pmModel to hold the PSF version 43 38 pmModel *modelPSF = pmModelAlloc (psf->type); 44 39 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 normalization52 modelEXT->params->data.F32[PM_PAR_I0] = flux / normFlux;53 54 40 // set model parameters for this source based on PSF information 55 if (!model FromPSFFunc(modelPSF, modelEXT, psf)) {41 if (!modelEXT->modelFromPSF (modelPSF, modelEXT, psf)) { 56 42 psError(PM_ERR_PSF, false, "Failed to set model params from PSF"); 57 43 psFree(modelPSF); … … 60 46 // XXX note that model->residuals is just a reference 61 47 modelPSF->residuals = psf->residuals; 62 psFree (modelEXT);63 48 64 49 return (modelPSF); 65 50 } 66 51 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 54 pmModel *pmModelFromPSFforXY (pmPSF *psf, float Xo, float Yo, float Io) { 68 55 69 pmSource *source = pmSourceAlloc ();56 assert (psf); 70 57 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; 81 66 } 82 67 83 source->peak = pmPeakAlloc (); 68 // XXX note that model->residuals is just a reference 69 modelPSF->residuals = psf->residuals; 84 70 85 float x = model->params->data.F32[PM_PAR_XPOS];86 float y = model->params->data.F32[PM_PAR_YPOS]; 71 return (modelPSF); 72 } 87 73 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 75 bool pmModelSetFlux (pmModel *model, float flux) { 92 76 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; 94 89 }
Note:
See TracChangeset
for help on using the changeset viewer.
