Changeset 6556
- Timestamp:
- Mar 8, 2006, 5:14:23 PM (20 years ago)
- Location:
- branches/rel10_ifa/psModules/src/objects
- Files:
-
- 2 added
- 31 edited
-
Makefile.am (modified) (2 diffs)
-
pmFPAviewObjectsIO.h (added)
-
pmFPAviewReadObjects.c (modified) (7 diffs)
-
pmFPAviewWriteObjects.c (modified) (8 diffs)
-
pmGrowthCurve.c (modified) (1 diff)
-
pmGrowthCurve.h (modified) (2 diffs)
-
pmModel.c (modified) (2 diffs)
-
pmModel.h (modified) (2 diffs)
-
pmModelGroup.c (modified) (2 diffs)
-
pmModelGroup.h (modified) (5 diffs)
-
pmMoments.c (modified) (3 diffs)
-
pmMoments.h (modified) (2 diffs)
-
pmPSF.c (modified) (2 diffs)
-
pmPSF.h (modified) (2 diffs)
-
pmPSFtry.c (modified) (6 diffs)
-
pmPeaks.c (modified) (4 diffs)
-
pmPeaks.h (modified) (2 diffs)
-
pmSource.c (modified) (12 diffs)
-
pmSource.h (modified) (4 diffs)
-
pmSourceContour.c (modified) (1 diff)
-
pmSourceContour.h (modified) (2 diffs)
-
pmSourceFitModel.c (modified) (4 diffs)
-
pmSourceFitModel.h (modified) (2 diffs)
-
pmSourceFitSet.c (modified) (4 diffs)
-
pmSourceIO.c (modified) (4 diffs)
-
pmSourceIO.h (added)
-
pmSourceIO_CMF.c (modified) (6 diffs)
-
pmSourceIO_CMP.c (modified) (8 diffs)
-
pmSourceIO_OBJ.c (modified) (6 diffs)
-
pmSourceIO_SX.c (modified) (4 diffs)
-
pmSourcePhotometry.c (modified) (9 diffs)
-
pmSourcePhotometry.h (modified) (2 diffs)
-
pmSourceSky.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/objects/Makefile.am
r6448 r6556 4 4 libpsmoduleobjects_la_LDFLAGS = -release $(PACKAGE_VERSION) 5 5 libpsmoduleobjects_la_SOURCES = \ 6 pmObjects.c \ 6 pmPeaks.c \ 7 pmMoments.c \ 8 pmModel.c \ 9 pmModelGroup.c \ 10 pmSource.c \ 11 pmSourceSky.c \ 12 pmSourceContour.c \ 13 pmSourceFitModel.c \ 14 pmSourceFitSet.c \ 15 pmSourcePhotometry.c \ 16 pmSourceIO.c \ 17 pmSourceIO_CMF.c \ 18 pmSourceIO_CMP.c \ 19 pmSourceIO_OBJ.c \ 20 pmSourceIO_SX.c \ 7 21 pmPSF.c \ 8 22 pmPSFtry.c \ 9 pmModelGroup.c \10 23 pmGrowthCurve.c \ 11 psEllipse.c 24 pmFPAviewReadObjects.c \ 25 pmFPAviewWriteObjects.c 12 26 13 27 EXTRA_DIST = \ … … 19 33 psmoduleincludedir = $(includedir) 20 34 psmoduleinclude_HEADERS = \ 21 pmObjects.h \ 35 pmPeaks.h \ 36 pmMoments.h \ 37 pmModel.h \ 38 pmModelGroup.h \ 39 pmSource.h \ 40 pmSourceSky.h \ 41 pmSourceContour.h \ 42 pmSourceFitModel.h \ 43 pmSourceFitSet.h \ 44 pmSourcePhotometry.h \ 45 pmSourceIO.h \ 22 46 pmPSF.h \ 23 47 pmPSFtry.h \ 24 pmModelGroup.h \ 25 pmGrowthCurve.h \ 26 psEllipse.h 48 pmGrowthCurve.h -
branches/rel10_ifa/psModules/src/objects/pmFPAviewReadObjects.c
r6545 r6556 1 # include "pmFPAviewReadObjects.h" 1 /** @file pmSourcePhotometry.c 2 * 3 * @author EAM, IfA; GLG, MHPCC 4 * 5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 * 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 9 * 10 */ 11 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "pmHDU.h" 17 #include "pmFPA.h" 18 #include "pmFPAview.h" 19 #include "pmFPAfile.h" 20 21 #include "pmPeaks.h" 22 #include "pmMoments.h" 23 #include "pmModel.h" 24 #include "pmSource.h" 25 26 #include "pmSourceIO.h" 27 #include "pmFPAviewObjectsIO.h" 2 28 3 29 // Given a FITS file pointer, read the table of object data … … 42 68 43 69 // read in all chip-level Objects files for this FPA 44 pmFPAReadObjects (pmFPA *fpa, pmFPAview *view, pmFPAfile *file)70 bool pmFPAReadObjects (pmFPA *fpa, pmFPAview *view, pmFPAfile *file) 45 71 { 46 72 47 73 for (int i = 0; i < fpa->chips->n; i++) { 48 74 49 pmChip *chip = fpa-> data[i];75 pmChip *chip = fpa->chips->data[i]; 50 76 pmChipReadObjects (chip, view, file); 51 77 } … … 54 80 55 81 // read in all cell-level Objects files for this chip 56 pmChipReadObjects (pmChip *chip, pmFPAview *view, pmFPAfile *file)82 bool pmChipReadObjects (pmChip *chip, pmFPAview *view, pmFPAfile *file) 57 83 { 58 84 59 85 for (int i = 0; i < chip->cells->n; i++) { 60 86 61 pmCell *cell = chip-> data[i];87 pmCell *cell = chip->cells->data[i]; 62 88 pmCellReadObjects (cell, view, file); 63 89 } … … 66 92 67 93 // read in all readout-level Objects files for this cell 68 pmCellReadObjects (pmCell *cell, pmFPAview *view, pmFPAfile *file)94 bool pmCellReadObjects (pmCell *cell, pmFPAview *view, pmFPAfile *file) 69 95 { 70 96 71 97 for (int i = 0; i < cell->readouts->n; i++) { 72 98 73 pmReadout *readout = cell-> data[i];99 pmReadout *readout = cell->readouts->data[i]; 74 100 pmReadoutReadObjects (readout, view, file); 75 101 } … … 78 104 79 105 // read in all readout-level Objects files for this cell 80 pmReadoutReadObjects (pmReadout *readout, pmFPAview *view, pmFPAfile *file)106 bool pmReadoutReadObjects (pmReadout *readout, pmFPAview *view, pmFPAfile *file) 81 107 { 82 108 109 bool status; 83 110 psArray *sources; 111 pmHDU *hdu; 84 112 85 113 switch (file->type) { … … 96 124 97 125 // read in header, if not yet loaded 98 pmHDU *hdu = pmFPAviewThisHDU (view);126 hdu = pmFPAviewThisHDU (view); 99 127 100 filename = pmConfigNameFromRule (file->filerule, view);128 char *filename = pmFPAviewNameFromRule (file->filerule, view); 101 129 file->fits = psFitsOpen (filename, "r"); 102 hdu->header = psFitsReadHeader ( file->fits);130 hdu->header = psFitsReadHeader (NULL, file->fits); 103 131 psFitsClose (file->fits); 104 132 sources = pmSourcesReadCMP (filename, hdu->header); … … 107 135 case PM_FPA_FILE_CMF: 108 136 // read in header, if not yet loaded 109 pmHDU *hdu = pmFPAviewThisHDU (view);137 hdu = pmFPAviewThisHDU (view); 110 138 if (hdu->header == NULL) { 111 headname = pmConfigNameFromRule (file->extxtra, view);112 psFitsMoveExtName (fi ts, headname);113 hdu->header = psFitsReadHeader ( file->fits);139 char *headname = pmFPAviewNameFromRule (file->extxtra, view); 140 psFitsMoveExtName (file->fits, headname); 141 hdu->header = psFitsReadHeader (NULL, file->fits); 114 142 } 115 143 116 dataname = pmConfigNameFromRule (file->extrule, view);117 psFitsMoveExtName (fi ts, dataname);144 char *dataname = pmFPAviewNameFromRule (file->extrule, view); 145 psFitsMoveExtName (file->fits, dataname); 118 146 sources = pmSourcesReadCMF (file->fits, hdu->header); 147 break; 148 149 default: 150 fprintf (stderr, "warning: type mismatch\n"); 119 151 break; 120 152 } -
branches/rel10_ifa/psModules/src/objects/pmFPAviewWriteObjects.c
r6545 r6556 1 # include "pmFPAviewWriteObjects.h" 1 /** @file pmSourcePhotometry.c 2 * 3 * @author EAM, IfA; GLG, MHPCC 4 * 5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 * 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 9 * 10 */ 11 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "pmHDU.h" 17 #include "pmFPA.h" 18 #include "pmFPAview.h" 19 #include "pmFPAfile.h" 20 21 #include "pmPeaks.h" 22 #include "pmMoments.h" 23 #include "pmModel.h" 24 #include "pmSource.h" 25 26 #include "pmSourceIO.h" 27 #include "pmFPAviewObjectsIO.h" 2 28 3 29 // Given a FITS file pointer, read the table of object data … … 42 68 43 69 // read in all chip-level Objects files for this FPA 44 pmFPAWriteObjects (pmFPA *fpa, pmFPAview *view, pmFPAfile *file)70 bool pmFPAWriteObjects (pmFPA *fpa, pmFPAview *view, pmFPAfile *file) 45 71 { 46 72 47 73 for (int i = 0; i < fpa->chips->n; i++) { 48 74 49 pmChip *chip = fpa-> data[i];75 pmChip *chip = fpa->chips->data[i]; 50 76 pmChipWriteObjects (chip, view, file); 51 77 } … … 54 80 55 81 // read in all cell-level Objects files for this chip 56 pmChipWriteObjects (pmChip *chip, pmFPAview *view, pmFPAfile *file)82 bool pmChipWriteObjects (pmChip *chip, pmFPAview *view, pmFPAfile *file) 57 83 { 58 84 59 85 for (int i = 0; i < chip->cells->n; i++) { 60 86 61 pmCell *cell = chip-> data[i];87 pmCell *cell = chip->cells->data[i]; 62 88 pmCellWriteObjects (cell, view, file); 63 89 } … … 66 92 67 93 // read in all readout-level Objects files for this cell 68 pmCellWriteObjects (pmCell *cell, pmFPAview *view, pmFPAfile *file)94 bool pmCellWriteObjects (pmCell *cell, pmFPAview *view, pmFPAfile *file) 69 95 { 70 96 71 97 for (int i = 0; i < cell->readouts->n; i++) { 72 98 73 pmReadout *readout = cell-> data[i];99 pmReadout *readout = cell->readouts->data[i]; 74 100 pmReadoutWriteObjects (readout, view, file); 75 101 } … … 78 104 79 105 // read in all readout-level Objects files for this cell 80 pmReadoutWriteObjects (pmReadout *readout, pmFPAview *view, pmFPAfile *file)106 bool pmReadoutWriteObjects (pmReadout *readout, pmFPAview *view, pmFPAfile *file) 81 107 { 108 109 bool status; 110 char *filename; 111 char *dataname; 112 char *headname; 113 pmHDU *hdu; 82 114 83 115 psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES"); … … 85 117 switch (file->type) { 86 118 case PM_FPA_FILE_OBJ: 87 filename = pm ConfigNameFromRule (file->filerule, view);88 pmSourcesWriteOBJ ( filename, sources);119 filename = pmFPAviewNameFromRule (file->filerule, view); 120 pmSourcesWriteOBJ (sources, filename); 89 121 break; 90 122 91 123 case PM_FPA_FILE_SX: 92 filename = pm ConfigNameFromRule (file->filerule, view);93 pmSourcesWriteSX ( filename, sources);124 filename = pmFPAviewNameFromRule (file->filerule, view); 125 pmSourcesWriteSX (sources, filename); 94 126 break; 95 127 96 128 case PM_FPA_FILE_CMP: 97 129 // a SPLIT format : only one header and object table per file 98 pmHDU *hdu = pmFPAviewThisHDU (view);99 filename = pm ConfigNameFromRule (file->filerule, view);100 pmSourcesWriteCMP ( filename, sources, hdu->header);130 hdu = pmFPAviewThisHDU (view); 131 filename = pmFPAviewNameFromRule (file->filerule, view); 132 pmSourcesWriteCMP (sources, filename, hdu->header); 101 133 break; 102 134 103 135 case PM_FPA_FILE_CMF: 104 136 // write header, if not yet written? 105 pmHDU *hdu = pmFPAviewThisHDU (view);137 hdu = pmFPAviewThisHDU (view); 106 138 107 139 // XXX is this needed? is it automatically added? … … 111 143 if (hdu->header) { 112 144 psMetadataItem *mdi = NULL; 113 headname = pm ConfigNameFromRule (file->extxtra, view);145 headname = pmFPAviewNameFromRule (file->extxtra, view); 114 146 115 147 // set NAXIS to 0 (we don't write out the data array) … … 119 151 mdi->type = PS_DATA_S32; 120 152 121 psFitsWriteHeader (file->fits, hdu->header, headname); 153 if (strcasecmp (headname, "PHU")) { 154 psMetadataAdd (hdu->header, PS_LIST_HEAD, "EXTNAME", PS_DATA_STRING, "extension name", headname); 155 } 156 psFitsWriteHeader (hdu->header, file->fits); 122 157 } 123 dataname = pm ConfigNameFromRule (file->extrule, view);158 dataname = pmFPAviewNameFromRule (file->extrule, view); 124 159 pmSourcesWriteCMF (file->fits, sources, hdu->header, dataname); 160 break; 161 162 default: 163 fprintf (stderr, "warning: type mismatch\n"); 125 164 break; 126 165 } -
branches/rel10_ifa/psModules/src/objects/pmGrowthCurve.c
r6448 r6556 1 /** @file pmGrowthCurve.c 2 * 3 * Measure the curve-of-growth for sources 4 * 5 * @author EAM, IfA 6 * 7 * @version $Revision: 1.1.4.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-03-09 03:14:23 $ 9 * 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 11 * 12 */ 13 1 14 #include <pslib.h> 2 # include "pmGrowthCurve.h"15 #include "pmGrowthCurve.h" 3 16 4 17 static void pmGrowthCurveFree (pmGrowthCurve *growth) -
branches/rel10_ifa/psModules/src/objects/pmGrowthCurve.h
r6448 r6556 1 1 2 # ifndef PM_GROWTH_CURVE_H 2 3 # define PM_GROWTH_CURVE_H … … 19 20 psF32 pmGrowthCurveCorrect (pmGrowthCurve *growth, psF32 radius); 20 21 22 // XXX psVectorBracket,Interpolate should be put in pslib 23 21 24 # endif /* PM_GROWTH_CURVE_H */ -
branches/rel10_ifa/psModules/src/objects/pmModel.c
r6537 r6556 1 /** @file pm Objects.c2 * 3 * This file will ...1 /** @file pmModel.c 2 * 3 * Functions to define and manipulate object models 4 4 * 5 5 * @author GLG, MHPCC 6 * @author EAM, IfA : significant modifications.7 * 8 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-03-0 7 06:33:35$6 * @author EAM, IfA 7 * 8 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 17 17 #include <string.h> 18 18 #include "pslib.h" 19 #include "pmObjects.h" 20 #include "pmModelGroup.h" 19 #include "pmModel.h" 20 21 /* The following types and functions need to be known by pmModel.c and are defined in 22 pmModelGroup.h. The use of pmSource and other types in pmModelGroup.h prevent us from 23 directly including it here ***/ 24 25 typedef psMinimizeLMChi2Func pmModelFunc; 26 typedef bool (*pmModelFitStatusFunc)(pmModel *model); 27 pmModelFunc pmModelFunc_GetFunction (pmModelType type); 28 pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type); 29 int pmModelParameterCount(pmModelType type); 21 30 22 31 static void modelFree(pmModel *tmp) -
branches/rel10_ifa/psModules/src/objects/pmModel.h
r6537 r6556 1 1 /** @file pmObjects.h 2 2 * 3 * The process of finding, measuring, and classifying astronomical sources on 4 * images is one of the critical tasks of the IPP or any astronomical software 5 * system. This file will define structures and functions related to the task 6 * of source detection and measurement. The elements defined in this section 7 * are generally low-level components which can be connected together to 8 * construct a complete object measurement suite. 3 * Functions to define and manipulate object models 9 4 * 10 5 * @author GLG, MHPCC 6 * @author EAM, IfA 11 7 * 12 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-03-0 7 06:33:35$8 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 14 10 * 15 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 61 57 pmModel *pmModelCopy (pmModel *model); 62 58 63 psF32 pmModelEval(pmModel *model, psImage *image, psS32 col, psS32 row) 59 psF32 pmModelEval(pmModel *model, psImage *image, psS32 col, psS32 row); 64 60 65 61 /** pmModelAdd() -
branches/rel10_ifa/psModules/src/objects/pmModelGroup.c
r6448 r6556 1 # include "pmModelGroup.h" 2 1 /** @file pmModelGroup.c 2 * 3 * Functions to define and manipulate object model attributes 4 * 5 * @author GLG, MHPCC 6 * @author EAM, IfA 7 * 8 * @version $Revision: 1.2.4.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 * 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 12 * 13 */ 14 15 #include <stdio.h> 16 #include <math.h> 17 #include <string.h> 18 #include "pslib.h" 19 #include "psEllipse.h" 20 #include "pmHDU.h" 21 #include "pmFPA.h" 22 #include "pmPeaks.h" 23 #include "pmMoments.h" 24 #include "pmGrowthCurve.h" 25 #include "pmModel.h" 26 #include "pmPSF.h" 27 #include "pmSource.h" 28 #include "pmModelGroup.h" 29 30 // XXX shouldn't these be defined for us in pslib.h ??? 3 31 double hypot(double x, double y); 4 32 double sqrt (double x); 5 33 6 #include "psEllipse.h"7 34 #include "models/pmModel_GAUSS.c" 8 35 #include "models/pmModel_PGAUSS.c" … … 159 186 return (models[type].name); 160 187 } 188 189 /****************************************************************************** 190 pmSourceModelGuess(source, model): This function allocates a new 191 pmModel structure based on the given modelType specified in the argument list. 192 The corresponding pmModelGuess function is returned, and used to 193 supply the values of the params array in the pmModel structure. 194 195 XXX: Many parameters are based on the src->moments structure, which is in 196 image, not subImage coords. Therefore, the calls to the model evaluation 197 functions will be in image, not subImage coords. Remember this. 198 *****************************************************************************/ 199 pmModel *pmSourceModelGuess(pmSource *source, 200 pmModelType modelType) 201 { 202 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 203 PS_ASSERT_PTR_NON_NULL(source->moments, false); 204 PS_ASSERT_PTR_NON_NULL(source->peak, false); 205 206 pmModel *model = pmModelAlloc(modelType); 207 208 pmModelGuessFunc modelGuessFunc = pmModelGuessFunc_GetFunction(modelType); 209 modelGuessFunc(model, source); 210 psTrace(__func__, 3, "---- %s() end ----\n", __func__); 211 return(model); 212 } 213 -
branches/rel10_ifa/psModules/src/objects/pmModelGroup.h
r6448 r6556 9 9 * @author EAM, IfA 10 10 * 11 * @version $Revision: 1.2.4. 1$ $Name: not supported by cvs2svn $12 * @date $Date: 2006-0 2-17 17:13:42$11 * @version $Revision: 1.2.4.2 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-03-09 03:14:23 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 15 * 16 16 */ 17 #include "pmObjects.h" 18 #include "pmPSF.h" 19 /** 20 * 21 * This function returns the number of parameters used by the listed function. 22 * 17 18 # ifndef PM_MODEL_GROUP_H 19 # define PM_MODEL_GROUP_H 20 21 // This function is the model chi-square minimization function for this model. 22 typedef psMinimizeLMChi2Func pmModelFunc; 23 24 // This function returns the integrated flux for the given model parameters. 25 typedef psF64 (*pmModelFlux)(const psVector *params); 26 27 28 // This function returns the radius at which the given model and parameters 29 // achieves the given flux. 30 typedef psF64 (*pmModelRadius)(const psVector *params, double flux); 31 32 /* This function sets the model parameter limits vectors for the given model 33 */ 34 typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max); 35 36 /* This function provides the model guess parameters based on the details of 37 * the given source. 38 */ 39 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source); 40 41 42 /* This function constructs the PSF model for the given source based on the 43 * supplied psf and the EXT model for the object. 44 */ 45 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf); 46 47 /* This function returns the success / failure status of the given model fit 48 */ 49 typedef bool (*pmModelFitStatusFunc)(pmModel *model); 50 51 /* Every model instance belongs to a class of models, defined by the value of 52 * the pmModelType type entry. Various functions need access to information about 53 * each of the models. Some of this information varies from model to model, and 54 * may depend on the current parameter values or other data quantities. In order 55 * to keep the code from requiring the information about each model to be coded 56 * into the low-level fitting routines, we define a collection of functions which 57 * allow us to abstract this type of model-dependent information. These generic 58 * functions take the model type and return the corresponding function pointer 59 * for the specified model. Each model is defined by creating this collection of 60 * specific functions, and placing them in a single file for each model. We 61 * define the following structure to carry the collection of information about 62 * the models. 63 */ 64 typedef struct 65 { 66 char *name; 67 int nParams; 68 pmModelFunc modelFunc; 69 pmModelFlux modelFlux; 70 pmModelRadius modelRadius; 71 pmModelLimits modelLimits; 72 pmModelGuessFunc modelGuessFunc; 73 pmModelFromPSFFunc modelFromPSFFunc; 74 pmModelFitStatusFunc modelFitStatusFunc; 75 } 76 pmModelGroup; 77 78 // allocate a pmModelGroup to hold nModels entries 79 pmModelGroup *pmModelGroupAlloc (int nModels); 80 81 // initialize the internal (static) model group with the default models 82 void pmModelGroupInit (void); 83 84 // free the internal (static) model group 85 void pmModelGroupCleanup (void); 86 87 // add a new model to the internal (static) model group 88 void pmModelGroupAdd (pmModelGroup *model); 89 90 /* This function returns the number of parameters used by the listed function. 23 91 */ 24 92 int pmModelParameterCount( … … 27 95 28 96 29 /** 30 * 31 * This function returns the user-space model names for the specified model type. 32 * 97 /* This function returns the user-space model names for the specified model type. 33 98 */ 34 99 char *pmModelGetType( … … 46 111 ); 47 112 48 49 #ifndef PM_MODEL_GROUP_H50 #define PM_MODEL_GROUP_H51 52 /**53 *54 * This function is the model chi-square minimization function for this model.55 *56 */57 typedef psMinimizeLMChi2Func pmModelFunc;58 59 60 /**61 *62 * This function returns the integrated flux for the given model parameters.63 */64 typedef psF64 (*pmModelFlux)(const psVector *params);65 66 67 /**68 *69 * This function returns the radius at which the given model and parameters70 * achieves the given flux.71 *72 */73 typedef psF64 (*pmModelRadius)(const psVector *params, double flux);74 75 /**76 *77 * This function sets the model parameter limits vectors for the given model78 *79 */80 typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max);81 82 /**83 *84 * This function provides the model guess parameters based on the details of85 * the given source.86 *87 */88 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source);89 90 91 /**92 *93 * This function constructs the PSF model for the given source based on the94 * supplied psf and the EXT model for the object.95 *96 */97 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf);98 99 /**100 *101 * This function returns the success / failure status of the given model fit102 *103 */104 typedef bool (*pmModelFitStatusFunc)(pmModel *model);105 106 113 /** 107 114 * … … 110 117 * 111 118 */ 112 113 119 114 120 /** … … 177 183 178 184 185 /** pmSourceModelGuess() 186 * 187 * Convert available data to an initial guess for the given model. This 188 * function allocates a pmModel entry for the pmSource structure based on the 189 * provided model selection. The method of defining the model parameter guesses 190 * are specified for each model below. The guess values are placed in the model 191 * parameters. The function returns TRUE on success or FALSE on failure. 192 * 193 */ 194 pmModel *pmSourceModelGuess( 195 pmSource *source, ///< The input pmSource 196 pmModelType model ///< The type of model to be created. 197 ); 179 198 180 181 /** 182 * 183 * Every model instance belongs to a class of models, defined by the value of 184 * the pmModelType type entry. Various functions need access to information about 185 * each of the models. Some of this information varies from model to model, and 186 * may depend on the current parameter values or other data quantities. In order 187 * to keep the code from requiring the information about each model to be coded 188 * into the low-level fitting routines, we define a collection of functions which 189 * allow us to abstract this type of model-dependent information. These generic 190 * functions take the model type and return the corresponding function pointer 191 * for the specified model. Each model is defined by creating this collection of 192 * specific functions, and placing them in a single file for each model. We 193 * define the following structure to carry the collection of information about 194 * the models. 195 * 196 */ 197 typedef struct 198 { 199 char *name; 200 int nParams; 201 pmModelFunc modelFunc; 202 pmModelFlux modelFlux; 203 pmModelRadius modelRadius; 204 pmModelLimits modelLimits; 205 pmModelGuessFunc modelGuessFunc; 206 pmModelFromPSFFunc modelFromPSFFunc; 207 pmModelFitStatusFunc modelFitStatusFunc; 208 } 209 pmModelGroup; 210 211 // allocate a pmModelGroup to hold nModels entries 212 pmModelGroup *pmModelGroupAlloc (int nModels); 213 214 // initialize the internal (static) model group with the default models 215 void pmModelGroupInit (void); 216 217 // free the internal (static) model group 218 void pmModelGroupCleanup (void); 219 220 // add a new model to the internal (static) model group 221 void pmModelGroupAdd (pmModelGroup *model); 222 223 # endif 199 # endif /* PM_MODEL_GROUP_H */ -
branches/rel10_ifa/psModules/src/objects/pmMoments.c
r6537 r6556 1 /** @file pm Objects.c1 /** @file pmMoments.c 2 2 * 3 * This file will ...3 * Functions defining the pmMoments structure 4 4 * 5 5 * @author GLG, MHPCC 6 * @author EAM, IfA : significant modifications.6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-03-0 7 06:33:35$8 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 13 13 */ 14 14 15 #include <stdio.h>16 #include <math.h>17 #include <string.h>18 15 #include "pslib.h" 19 #include "pmObjects.h" 20 #include "pmModelGroup.h" 16 #include "pmMoments.h" 21 17 22 18 /****************************************************************************** … … 42 38 } 43 39 44 /******************************************************************************45 pmSourceMoments(source, radius): this function takes a subImage defined in the46 pmSource data structure, along with the peak location, and determines the47 various moments associated with that peak.48 49 Requires the following to have been created:50 pmSource51 pmSource->peak52 pmSource->pixels53 pmSource->weight54 pmSource->mask55 56 XXX: The peak calculations are done in image coords, not subImage coords.57 58 XXX EAM : this version clips input pixels on S/N59 XXX EAM : this version returns false for several reasons60 *****************************************************************************/61 # define VALID_RADIUS(X,Y,RAD2) (((RAD2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0)62 63 bool pmSourceMoments(pmSource *source,64 psF32 radius)65 {66 psTrace(__func__, 3, "---- %s() begin ----\n", __func__);67 PS_ASSERT_PTR_NON_NULL(source, false);68 PS_ASSERT_PTR_NON_NULL(source->peak, false);69 PS_ASSERT_PTR_NON_NULL(source->pixels, false);70 PS_ASSERT_PTR_NON_NULL(source->mask, false);71 PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false);72 73 //74 // XXX: Verify the setting for sky if source->moments == NULL.75 //76 psF32 sky = 0.0;77 if (source->moments == NULL) {78 source->moments = pmMomentsAlloc();79 } else {80 sky = source->moments->Sky;81 }82 83 //84 // Sum = SUM (z - sky)85 // X1 = SUM (x - xc)*(z - sky)86 // X2 = SUM (x - xc)^2 * (z - sky)87 // XY = SUM (x - xc)*(y - yc)*(z - sky)88 //89 psF32 peakPixel = -PS_MAX_F32;90 psS32 numPixels = 0;91 psF32 Sum = 0.0;92 psF32 Var = 0.0;93 psF32 X1 = 0.0;94 psF32 Y1 = 0.0;95 psF32 X2 = 0.0;96 psF32 Y2 = 0.0;97 psF32 XY = 0.0;98 psF32 x = 0;99 psF32 y = 0;100 psF32 R2 = PS_SQR(radius);101 102 psF32 xPeak = source->peak->x;103 psF32 yPeak = source->peak->y;104 psF32 xOff = source->pixels->col0 - source->peak->x;105 psF32 yOff = source->pixels->row0 - source->peak->y;106 107 // XXX why do I get different results for these two methods of finding Sx?108 // XXX Sx, Sy would be better measured if we clip pixels close to sky109 // XXX Sx, Sy can still be imaginary, so we probably need to keep Sx^2?110 // We loop through all pixels in this subimage (source->pixels), and for each111 // pixel that is not masked, AND within the radius of the peak pixel, we112 // proceed with the moments calculation. need to do two loops for a113 // numerically stable result. first loop: get the sums.114 // XXX EAM : mask == 0 is valid115 116 for (psS32 row = 0; row < source->pixels->numRows ; row++) {117 118 psF32 *vPix = source->pixels->data.F32[row];119 psF32 *vWgt = source->weight->data.F32[row];120 psU8 *vMsk = (source->mask == NULL) ? NULL : source->mask->data.U8[row];121 122 for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {123 if ((vMsk != NULL) && *vMsk) {124 vMsk++;125 continue;126 }127 128 psF32 xDiff = col + xOff;129 psF32 yDiff = row + yOff;130 131 // radius is just a function of (xDiff, yDiff)132 if (!VALID_RADIUS(xDiff, yDiff, R2)) {133 if (vMsk != NULL)134 vMsk++;135 continue;136 }137 138 psF32 pDiff = *vPix - sky;139 psF32 wDiff = *vWgt;140 141 // XXX EAM : check for valid S/N in pixel142 // XXX EAM : should this limit be user-defined?143 if (PS_SQR(pDiff) < wDiff) {144 if (vMsk != NULL)145 vMsk++;146 continue;147 }148 149 Var += wDiff;150 Sum += pDiff;151 152 psF32 xWght = xDiff * pDiff;153 psF32 yWght = yDiff * pDiff;154 155 X1 += xWght;156 Y1 += yWght;157 158 XY += xDiff * yWght;159 X2 += xDiff * xWght;160 Y2 += yDiff * yWght;161 162 peakPixel = PS_MAX (*vPix, peakPixel);163 numPixels++;164 if (vMsk != NULL)165 vMsk++;166 }167 }168 169 // if we have less than (1/4) of the possible pixels, force a retry170 // XXX EAM - the limit is a bit arbitrary. make it user defined?171 if ((numPixels < 0.75*R2) || (Sum <= 0)) {172 psTrace (".psModules.pmSourceMoments", 3, "no valid pixels for source\n");173 psTrace(__func__, 3, "---- %s(false) end ----\n", __func__);174 return (false);175 }176 177 psTrace (".psModules.pmSourceMoments", 5,178 "sky: %f Sum: %f X1: %f Y1: %f X2: %f Y2: %f XY: %f Npix: %d\n",179 sky, Sum, X1, Y1, X2, Y2, XY, numPixels);180 181 //182 // first moment X = X1/Sum + xc183 // second moment X = sqrt (X2/Sum - (X1/Sum)^2)184 // Sxy = XY / Sum185 //186 x = X1/Sum;187 y = Y1/Sum;188 if ((fabs(x) > radius) || (fabs(y) > radius)) {189 psTrace (".psModules.pmSourceMoments", 3,190 "large centroid swing; invalid peak %d, %d\n",191 source->peak->x, source->peak->y);192 psTrace(__func__, 3, "---- %s(false) end ----\n", __func__);193 return (false);194 }195 196 source->moments->x = x + xPeak;197 source->moments->y = y + yPeak;198 199 // XXX EAM : Sxy needs to have x*y subtracted200 source->moments->Sxy = XY/Sum - x*y;201 source->moments->Sum = Sum;202 source->moments->SN = Sum / sqrt(Var);203 source->moments->Peak = peakPixel;204 source->moments->nPixels = numPixels;205 206 // XXX EAM : these values can be negative, so we need to limit the range207 source->moments->Sx = sqrt(PS_MAX(X2/Sum - PS_SQR(x), 0));208 source->moments->Sy = sqrt(PS_MAX(Y2/Sum - PS_SQR(y), 0));209 210 psTrace (".psModules.pmSourceMoments", 4,211 "sky: %f Sum: %f x: %f y: %f Sx: %f Sy: %f Sxy: %f\n",212 sky, Sum, source->moments->x, source->moments->y,213 source->moments->Sx, source->moments->Sy, source->moments->Sxy);214 215 psTrace(__func__, 3, "---- %s(true) end ----\n", __func__);216 return(true);217 }218 -
branches/rel10_ifa/psModules/src/objects/pmMoments.h
r6537 r6556 1 /** @file pm Objects.h1 /** @file pmMoments.h 2 2 * 3 * The process of finding, measuring, and classifying astronomical sources on 4 * images is one of the critical tasks of the IPP or any astronomical software 5 * system. This file will define structures and functions related to the task 6 * of source detection and measurement. The elements defined in this section 7 * are generally low-level components which can be connected together to 8 * construct a complete object measurement suite. 3 * Definitions of the moments structure 9 4 * 10 5 * @author GLG, MHPCC 11 6 * 12 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-03-0 7 06:33:35$7 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-03-09 03:14:23 $ 14 9 * 15 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 16 11 * 17 12 */ 13 14 # ifndef PM_MOMENTS_H 15 # define PM_MOMENTS_H 18 16 19 17 /** pmMoments data structure … … 45 43 pmMoments *pmMomentsAlloc(); 46 44 47 /** pmSourceMoments() 48 * 49 * Measure source moments for the given source, using the value of 50 * source.moments.sky provided as the local background value and the peak 51 * coordinates as the initial source location. The resulting moment values are 52 * applied to the source.moments entry, and the source is returned. The moments 53 * are measured within the given circular radius of the source.peak coordinates. 54 * The return value indicates the success (TRUE) of the operation. 55 * 56 */ 57 bool pmSourceMoments( 58 pmSource *source, ///< The input pmSource for which moments will be computed 59 float radius ///< Use a circle of pixels around the peak 60 ); 45 # endif -
branches/rel10_ifa/psModules/src/objects/pmPSF.c
r6448 r6556 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.4.4. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-0 2-17 17:13:42$8 * @version $Revision: 1.4.4.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 19 19 #include <pslib.h> 20 #include "pmObjects.h" 20 #include "pmHDU.h" 21 #include "pmFPA.h" 22 #include "pmPeaks.h" 23 #include "pmMoments.h" 24 #include "pmModel.h" 25 #include "pmSource.h" 26 #include "pmGrowthCurve.h" 21 27 #include "pmPSF.h" 22 28 #include "pmModelGroup.h" -
branches/rel10_ifa/psModules/src/objects/pmPSF.h
r6448 r6556 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.1.22. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-0 2-17 17:13:42$8 * @version $Revision: 1.1.22.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 15 # ifndef PM_PSF_H 16 16 # define PM_PSF_H 17 18 #include "pmGrowthCurve.h"19 17 20 18 /** pmPSF data structure -
branches/rel10_ifa/psModules/src/objects/pmPSFtry.c
r6448 r6556 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1.4.4. 1$ $Name: not supported by cvs2svn $8 * @date $Date: 2006-0 2-17 17:13:42$7 * @version $Revision: 1.4.4.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-03-09 03:14:23 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 13 13 14 14 # include <pslib.h> 15 # include "pmObjects.h" 16 # include "pmPSF.h" 17 # include "pmPSFtry.h" 18 # include "pmModelGroup.h" 15 #include "pmHDU.h" 16 #include "pmFPA.h" 17 #include "pmPeaks.h" 18 #include "pmMoments.h" 19 #include "pmModel.h" 20 #include "pmSource.h" 21 #include "pmGrowthCurve.h" 22 #include "pmPSF.h" 23 #include "pmPSFtry.h" 24 #include "pmModelGroup.h" 25 #include "pmSourceFitModel.h" 26 #include "pmSourcePhotometry.h" 19 27 20 28 // ******** pmPSFtry functions ************************************************** … … 104 112 // fit model as EXT, not PSF 105 113 106 psImageKeepCircle (source->mask, x, y, RADIUS, "OR", P SPHOT_MASK_MARKED);114 psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PM_SOURCE_MASK_MARKED); 107 115 status = pmSourceFitModel (source, model, false); 108 psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~P SPHOT_MASK_MARKED);116 psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PM_SOURCE_MASK_MARKED); 109 117 110 118 // exclude the poor fits … … 138 146 y = source->peak->y; 139 147 140 psImageKeepCircle (source->mask, x, y, RADIUS, "OR", P SPHOT_MASK_MARKED);148 psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PM_SOURCE_MASK_MARKED); 141 149 status = pmSourceFitModel (source, modelPSF, true); 142 150 … … 154 162 // XXX : use a different estimator for the local sky? 155 163 // XXX : pass 'source' as input? 156 if (!pmSourcePhotometry (&fitMag, &obsMag, modelPSF, source->pixels, source->mask)) { 164 if (!pmSourcePhotometryModel (&fitMag, modelPSF)) { 165 psfTry->mask->data.U8[i] = PSFTRY_MASK_BAD_PHOT; 166 goto next_source; 167 } 168 if (!pmSourcePhotometryAper (&obsMag, modelPSF, source->pixels, source->mask)) { 157 169 psfTry->mask->data.U8[i] = PSFTRY_MASK_BAD_PHOT; 158 170 goto next_source; … … 164 176 165 177 next_source: 166 psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~P SPHOT_MASK_MARKED);178 psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PM_SOURCE_MASK_MARKED); 167 179 168 180 } -
branches/rel10_ifa/psModules/src/objects/pmPeaks.c
r6537 r6556 1 /** @file pm Objects.c1 /** @file pmPeaks.c 2 2 * 3 * This file will ...3 * This file defines functions to detect and manipulate peaks in images 4 4 * 5 5 * @author GLG, MHPCC 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-03-0 7 06:33:35$8 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 17 17 #include <string.h> 18 18 #include "pslib.h" 19 #include "pmObjects.h" 20 #include "pmModelGroup.h" 19 #include "pmPeaks.h" 21 20 22 21 /****************************************************************************** … … 110 109 } 111 110 112 // XXX are these private or public?113 111 // psSort comparison function for peaks 114 int pm ComparePeakAscend (const void **a, const void **b)112 int pmPeaksCompareAscend (const void **a, const void **b) 115 113 { 116 114 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); … … 133 131 134 132 // psSort comparison function for peaks 135 int pm ComparePeakDescend (const void **a, const void **b)133 int pmPeaksCompareDescend (const void **a, const void **b) 136 134 { 137 135 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); -
branches/rel10_ifa/psModules/src/objects/pmPeaks.h
r6537 r6556 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-03-0 7 06:33:35$12 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-03-09 03:14:23 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 138 138 ); 139 139 140 int pmPeaksCompareAscend (const void **a, const void **b); 141 int pmPeaksCompareDescend (const void **a, const void **b); 142 140 143 # endif /* PM_PEAKS_H */ -
branches/rel10_ifa/psModules/src/objects/pmSource.c
r6537 r6556 1 /** @file pm Objects.c1 /** @file pmSource.c 2 2 * 3 * This file will ...3 * Functions to define and manipulate sources on images 4 4 * 5 5 * @author GLG, MHPCC 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-03-0 7 06:33:35$8 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 17 17 #include <string.h> 18 18 #include "pslib.h" 19 #include "pmObjects.h" 20 #include "pmModelGroup.h" 19 #include "pmHDU.h" 20 #include "pmFPA.h" 21 #include "pmPeaks.h" 22 #include "pmMoments.h" 23 #include "pmModel.h" 24 #include "pmSource.h" 21 25 22 26 static void sourceFree(pmSource *tmp) … … 50 54 tmp->modelPSF = NULL; 51 55 tmp->modelEXT = NULL; 52 tmp->type = PM_SOURCE_ UNKNOWN;53 tmp->mode = PM_SOURCE_ DEFAULT;56 tmp->type = PM_SOURCE_TYPE_UNKNOWN; 57 tmp->mode = PM_SOURCE_MODE_DEFAULT; 54 58 psMemSetDeallocator(tmp, (psFreeFunc) sourceFree); 55 59 … … 219 223 220 224 // XXX EAM : this lets us takes the single highest peak 221 psArraySort (peaks, pm ComparePeakDescend);225 psArraySort (peaks, pmPeaksCompareDescend); 222 226 clump = peaks->data[0]; 223 227 psTrace (".pmObjects.pmSourceRoughClass", 2, "clump is at %d, %d (%f)\n", clump->x, clump->y, clump->counts); … … 331 335 // inner = psRegionForSquare (tmpSrc->peak->x - tmpSrc->mask->col0, tmpSrc->peak->y - tmpSrc->mask->row0, 2); 332 336 inner = psRegionForSquare (tmpSrc->peak->x, tmpSrc->peak->y, 2); 333 int Nsatpix = psImageCountPixelMask (tmpSrc->mask, inner, P SPHOT_MASK_SATURATED);337 int Nsatpix = psImageCountPixelMask (tmpSrc->mask, inner, PM_SOURCE_MASK_SATURATED); 334 338 335 339 // saturated star (size consistent with PSF or larger) … … 338 342 big = true; 339 343 if ((Nsatpix > 1) && big) { 340 tmpSrc->type = PM_SOURCE_ STAR;341 tmpSrc->mode = PM_SOURCE_ SATSTAR;344 tmpSrc->type = PM_SOURCE_TYPE_STAR; 345 tmpSrc->mode = PM_SOURCE_MODE_SATSTAR; 342 346 Nsatstar ++; 343 347 continue; … … 346 350 // saturated object (not a star, eg bleed trails, hot pixels) 347 351 if (Nsatpix > 1) { 348 tmpSrc->type = PM_SOURCE_ SATURATED;349 tmpSrc->mode = PM_SOURCE_ DEFAULT;352 tmpSrc->type = PM_SOURCE_TYPE_SATURATED; 353 tmpSrc->mode = PM_SOURCE_MODE_DEFAULT; 350 354 Nsat ++; 351 355 continue; … … 356 360 // only set candidate defects if 357 361 if ((sigX < 0.05) || (sigY < 0.05)) { 358 tmpSrc->type = PM_SOURCE_ DEFECT;359 tmpSrc->mode = PM_SOURCE_ DEFAULT;362 tmpSrc->type = PM_SOURCE_TYPE_DEFECT; 363 tmpSrc->mode = PM_SOURCE_MODE_DEFAULT; 360 364 Ncr ++; 361 365 continue; … … 364 368 // likely unsaturated extended source (too large to be stellar) 365 369 if ((sigX > (clump.X + 3*clump.dX)) || (sigY > (clump.Y + 3*clump.dY))) { 366 tmpSrc->type = PM_SOURCE_ EXTENDED;367 tmpSrc->mode = PM_SOURCE_ DEFAULT;370 tmpSrc->type = PM_SOURCE_TYPE_EXTENDED; 371 tmpSrc->mode = PM_SOURCE_MODE_DEFAULT; 368 372 Next ++; 369 373 continue; … … 378 382 psF32 radius = hypot ((sigX-clump.X)/clump.dX, (sigY-clump.Y)/clump.dY); 379 383 if ((tmpSrc->moments->SN > PSF_SN_LIM) && (radius < 1.5)) { 380 tmpSrc->type = PM_SOURCE_ STAR;381 tmpSrc->mode = PM_SOURCE_ PSFSTAR;384 tmpSrc->type = PM_SOURCE_TYPE_STAR; 385 tmpSrc->mode = PM_SOURCE_MODE_PSFSTAR; 382 386 Npsf ++; 383 387 continue; … … 385 389 386 390 // random type of star 387 tmpSrc->type = PM_SOURCE_ STAR;388 tmpSrc->mode = PM_SOURCE_ DEFAULT;391 tmpSrc->type = PM_SOURCE_TYPE_STAR; 392 tmpSrc->mode = PM_SOURCE_MODE_DEFAULT; 389 393 } 390 394 … … 409 413 } 410 414 415 /****************************************************************************** 416 pmSourceMoments(source, radius): this function takes a subImage defined in the 417 pmSource data structure, along with the peak location, and determines the 418 various moments associated with that peak. 419 420 Requires the following to have been created: 421 pmSource 422 pmSource->peak 423 pmSource->pixels 424 pmSource->weight 425 pmSource->mask 426 427 XXX: The peak calculations are done in image coords, not subImage coords. 428 429 XXX EAM : this version clips input pixels on S/N 430 XXX EAM : this version returns false for several reasons 431 *****************************************************************************/ 432 # define VALID_RADIUS(X,Y,RAD2) (((RAD2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0) 433 434 bool pmSourceMoments(pmSource *source, 435 psF32 radius) 436 { 437 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 438 PS_ASSERT_PTR_NON_NULL(source, false); 439 PS_ASSERT_PTR_NON_NULL(source->peak, false); 440 PS_ASSERT_PTR_NON_NULL(source->pixels, false); 441 PS_ASSERT_PTR_NON_NULL(source->mask, false); 442 PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false); 443 444 // 445 // XXX: Verify the setting for sky if source->moments == NULL. 446 // 447 psF32 sky = 0.0; 448 if (source->moments == NULL) { 449 source->moments = pmMomentsAlloc(); 450 } else { 451 sky = source->moments->Sky; 452 } 453 454 // 455 // Sum = SUM (z - sky) 456 // X1 = SUM (x - xc)*(z - sky) 457 // X2 = SUM (x - xc)^2 * (z - sky) 458 // XY = SUM (x - xc)*(y - yc)*(z - sky) 459 // 460 psF32 peakPixel = -PS_MAX_F32; 461 psS32 numPixels = 0; 462 psF32 Sum = 0.0; 463 psF32 Var = 0.0; 464 psF32 X1 = 0.0; 465 psF32 Y1 = 0.0; 466 psF32 X2 = 0.0; 467 psF32 Y2 = 0.0; 468 psF32 XY = 0.0; 469 psF32 x = 0; 470 psF32 y = 0; 471 psF32 R2 = PS_SQR(radius); 472 473 psF32 xPeak = source->peak->x; 474 psF32 yPeak = source->peak->y; 475 psF32 xOff = source->pixels->col0 - source->peak->x; 476 psF32 yOff = source->pixels->row0 - source->peak->y; 477 478 // XXX why do I get different results for these two methods of finding Sx? 479 // XXX Sx, Sy would be better measured if we clip pixels close to sky 480 // XXX Sx, Sy can still be imaginary, so we probably need to keep Sx^2? 481 // We loop through all pixels in this subimage (source->pixels), and for each 482 // pixel that is not masked, AND within the radius of the peak pixel, we 483 // proceed with the moments calculation. need to do two loops for a 484 // numerically stable result. first loop: get the sums. 485 // XXX EAM : mask == 0 is valid 486 487 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 488 489 psF32 *vPix = source->pixels->data.F32[row]; 490 psF32 *vWgt = source->weight->data.F32[row]; 491 psU8 *vMsk = (source->mask == NULL) ? NULL : source->mask->data.U8[row]; 492 493 for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) { 494 if ((vMsk != NULL) && *vMsk) { 495 vMsk++; 496 continue; 497 } 498 499 psF32 xDiff = col + xOff; 500 psF32 yDiff = row + yOff; 501 502 // radius is just a function of (xDiff, yDiff) 503 if (!VALID_RADIUS(xDiff, yDiff, R2)) { 504 if (vMsk != NULL) 505 vMsk++; 506 continue; 507 } 508 509 psF32 pDiff = *vPix - sky; 510 psF32 wDiff = *vWgt; 511 512 // XXX EAM : check for valid S/N in pixel 513 // XXX EAM : should this limit be user-defined? 514 if (PS_SQR(pDiff) < wDiff) { 515 if (vMsk != NULL) 516 vMsk++; 517 continue; 518 } 519 520 Var += wDiff; 521 Sum += pDiff; 522 523 psF32 xWght = xDiff * pDiff; 524 psF32 yWght = yDiff * pDiff; 525 526 X1 += xWght; 527 Y1 += yWght; 528 529 XY += xDiff * yWght; 530 X2 += xDiff * xWght; 531 Y2 += yDiff * yWght; 532 533 peakPixel = PS_MAX (*vPix, peakPixel); 534 numPixels++; 535 if (vMsk != NULL) 536 vMsk++; 537 } 538 } 539 540 // if we have less than (1/4) of the possible pixels, force a retry 541 // XXX EAM - the limit is a bit arbitrary. make it user defined? 542 if ((numPixels < 0.75*R2) || (Sum <= 0)) { 543 psTrace (".psModules.pmSourceMoments", 3, "no valid pixels for source\n"); 544 psTrace(__func__, 3, "---- %s(false) end ----\n", __func__); 545 return (false); 546 } 547 548 psTrace (".psModules.pmSourceMoments", 5, 549 "sky: %f Sum: %f X1: %f Y1: %f X2: %f Y2: %f XY: %f Npix: %d\n", 550 sky, Sum, X1, Y1, X2, Y2, XY, numPixels); 551 552 // 553 // first moment X = X1/Sum + xc 554 // second moment X = sqrt (X2/Sum - (X1/Sum)^2) 555 // Sxy = XY / Sum 556 // 557 x = X1/Sum; 558 y = Y1/Sum; 559 if ((fabs(x) > radius) || (fabs(y) > radius)) { 560 psTrace (".psModules.pmSourceMoments", 3, 561 "large centroid swing; invalid peak %d, %d\n", 562 source->peak->x, source->peak->y); 563 psTrace(__func__, 3, "---- %s(false) end ----\n", __func__); 564 return (false); 565 } 566 567 source->moments->x = x + xPeak; 568 source->moments->y = y + yPeak; 569 570 // XXX EAM : Sxy needs to have x*y subtracted 571 source->moments->Sxy = XY/Sum - x*y; 572 source->moments->Sum = Sum; 573 source->moments->SN = Sum / sqrt(Var); 574 source->moments->Peak = peakPixel; 575 source->moments->nPixels = numPixels; 576 577 // XXX EAM : these values can be negative, so we need to limit the range 578 source->moments->Sx = sqrt(PS_MAX(X2/Sum - PS_SQR(x), 0)); 579 source->moments->Sy = sqrt(PS_MAX(Y2/Sum - PS_SQR(y), 0)); 580 581 psTrace (".psModules.pmSourceMoments", 4, 582 "sky: %f Sum: %f x: %f y: %f Sx: %f Sy: %f Sxy: %f\n", 583 sky, Sum, source->moments->x, source->moments->y, 584 source->moments->Sx, source->moments->Sy, source->moments->Sxy); 585 586 psTrace(__func__, 3, "---- %s(true) end ----\n", __func__); 587 return(true); 588 } 589 590 pmModel *pmSourceSelectModel (pmSource *source) 591 { 592 switch (source->type) { 593 case PM_SOURCE_TYPE_STAR: 594 return source->modelPSF; 595 596 case PM_SOURCE_TYPE_EXTENDED: 597 return source->modelEXT; 598 599 default: 600 return NULL; 601 } 602 return NULL; 603 } -
branches/rel10_ifa/psModules/src/objects/pmSource.h
r6537 r6556 3 3 * @author EAM, IfA; GLG, MHPCC 4 4 * 5 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-03-0 7 06:33:35$5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 81 81 pmSourceMode mode; ///< Best identification of object. 82 82 psArray *blends; 83 float fitMag; 83 float psfMag; 84 float extMag; 85 float errMag; 84 86 float apMag; 85 87 psRegion region; // area on image covered by selected pixels … … 125 127 * 126 128 */ 127 // XXX: Uncommenting the pmReadout causes compile errors.128 129 bool pmSourceDefinePixels( 129 pmSource *mySource, ///< Add comment. 130 pmReadout *readout, ///< Add comment. 131 psF32 x, ///< Add comment. 132 psF32 y, ///< Add comment. 133 psF32 Radius ///< Add comment. 134 ); 135 136 bool pmSourceDefinePixels (pmSource *mySource, const pmReadout *readout, psF32 x, psF32 y, psF32 Radius); 137 bool pmSourceRedefinePixels (pmSource *mySource, const pmReadout *readout, psF32 x, psF32 y, psF32 Radius); 130 pmSource *mySource, ///< source to be re-defined 131 const pmReadout *readout, ///< base the source on this readout 132 psF32 x, ///< center coords of source 133 psF32 y, ///< center coords of source 134 psF32 Radius ///< size of box on source 135 ); 136 137 bool pmSourceRedefinePixels ( 138 pmSource *mySource, ///< source to be re-defined 139 const pmReadout *readout, ///< base the source on this readout 140 psF32 x, ///< center coords of source 141 psF32 y, ///< center coords of source 142 psF32 Radius ///< size of box on source 143 ); 138 144 139 145 /** pmSourcePSFClump() … … 188 194 189 195 196 /** pmSourceMoments() 197 * 198 * Measure source moments for the given source, using the value of 199 * source.moments.sky provided as the local background value and the peak 200 * coordinates as the initial source location. The resulting moment values are 201 * applied to the source.moments entry, and the source is returned. The moments 202 * are measured within the given circular radius of the source.peak coordinates. 203 * The return value indicates the success (TRUE) of the operation. 204 * 205 */ 206 bool pmSourceMoments( 207 pmSource *source, ///< The input pmSource for which moments will be computed 208 float radius ///< Use a circle of pixels around the peak 209 ); 210 211 212 // select the model used for this source 213 pmModel *pmSourceSelectModel (pmSource *source); 214 190 215 # endif /* PM_SOURCE_H */ -
branches/rel10_ifa/psModules/src/objects/pmSourceContour.c
r6537 r6556 1 # include "psphot.h" 1 /** @file pmSourceContour.c 2 * 3 * Functions to measure the local sky and sky variance for sources on images 4 * 5 * @author GLG, MHPCC 6 * @author EAM, IfA: significant modifications. 7 * 8 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 * 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 12 * 13 */ 14 15 #include <stdio.h> 16 #include <math.h> 17 #include <string.h> 18 #include "pslib.h" 19 #include "pmHDU.h" 20 #include "pmFPA.h" 21 #include "pmPeaks.h" 22 #include "pmMoments.h" 23 #include "pmModel.h" 24 #include "pmSource.h" 25 #include "pmSourceContour.h" 2 26 3 27 /****************************************************************************** -
branches/rel10_ifa/psModules/src/objects/pmSourceContour.h
r6537 r6556 3 3 * @author EAM, IfA; GLG, MHPCC 4 4 * 5 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-03-0 7 06:33:35$5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 13 13 # define PM_SOURCE_CONTOUR_H 14 14 15 psArray *pmSourceContour (psImage *image, int xc, int yc, float threshold) 16 { 15 psArray *pmSourceContour (psImage *image, int xc, int yc, float threshold); 17 16 18 /** pmSourceContour()19 *20 * Find points in a contour for the given source at the given level. If type21 * is PM_CONTOUR_CRUDE, the contour is found by starting at the source peak,22 * running along each pixel row until the level is crossed, then interpolating to23 * the level coordinate for that row. This is done for each row, with the24 * starting point determined by the midpoint of the previous row, until the25 * starting point has a value below the contour level. The returned contour26 * consists of two vectors giving the x and y coordinates of the contour levels.27 * This function may be used as part of the model guess inputs. Other contour28 * types may be specified in the future for more refined contours (TBD)29 *30 */31 psArray *pmSourceContour_Crude(32 pmSource *source, ///< The input pmSource33 const psImage *image, ///< The input image (float) (this arg should be removed)34 float level ///< The level of the contour35 );36 17 37 # endif /* PM_SOURCE_PHOTOMETRY_H */ 18 /** pmSourceContour() 19 * 20 * Find points in a contour for the given source at the given level. If type 21 * is PM_CONTOUR_CRUDE, the contour is found by starting at the source peak, 22 * running along each pixel row until the level is crossed, then interpolating to 23 * the level coordinate for that row. This is done for each row, with the 24 * starting point determined by the midpoint of the previous row, until the 25 * starting point has a value below the contour level. The returned contour 26 * consists of two vectors giving the x and y coordinates of the contour levels. 27 * This function may be used as part of the model guess inputs. Other contour 28 * types may be specified in the future for more refined contours (TBD) 29 * 30 */ 31 psArray *pmSourceContour_Crude( 32 pmSource *source, ///< The input pmSource 33 const psImage *image, ///< The input image (float) (this arg should be removed) 34 float level ///< The level of the contour 35 ); 36 37 # endif /* PM_SOURCE_PHOTOMETRY_H */ -
branches/rel10_ifa/psModules/src/objects/pmSourceFitModel.c
r6537 r6556 1 /** @file pm Objects.c1 /** @file pmSourceFitModel.c 2 2 * 3 * This file will ...3 * fit single source models to image pixels 4 4 * 5 * @author EAM, IfA 5 6 * @author GLG, MHPCC 6 * @author EAM, IfA: significant modifications.7 7 * 8 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-03-0 7 06:33:35$8 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 17 17 #include <string.h> 18 18 #include "pslib.h" 19 #include "pmObjects.h" 19 #include "pmHDU.h" 20 #include "pmFPA.h" 21 #include "pmPeaks.h" 22 #include "pmMoments.h" 23 #include "pmGrowthCurve.h" 24 #include "pmModel.h" 25 #include "pmPSF.h" 26 #include "pmSource.h" 20 27 #include "pmModelGroup.h" 28 #include "pmSourceFitModel.h" 21 29 22 30 // save a static values so they may be set externally … … 169 177 } 170 178 171 source->mode |= PM_SOURCE_ FITTED;179 source->mode |= PM_SOURCE_MODE_FITTED; 172 180 173 181 psFree(x); … … 186 194 return(rc); 187 195 } 188 189 pmModel *pmSourceSelectModel (pmSource *source)190 {191 switch (source->type) {192 case PM_SOURCE_STAR:193 return source->modelPSF;194 195 case PM_SOURCE_EXTENDED:196 return source->modelEXT;197 198 default:199 return NULL;200 }201 return NULL;202 }203 204 /******************************************************************************205 pmSourceModelGuess(source, model): This function allocates a new206 pmModel structure based on the given modelType specified in the argument list.207 The corresponding pmModelGuess function is returned, and used to208 supply the values of the params array in the pmModel structure.209 210 XXX: Many parameters are based on the src->moments structure, which is in211 image, not subImage coords. Therefore, the calls to the model evaluation212 functions will be in image, not subImage coords. Remember this.213 *****************************************************************************/214 pmModel *pmSourceModelGuess(pmSource *source,215 pmModelType modelType)216 {217 psTrace(__func__, 3, "---- %s() begin ----\n", __func__);218 PS_ASSERT_PTR_NON_NULL(source->moments, false);219 PS_ASSERT_PTR_NON_NULL(source->peak, false);220 221 pmModel *model = pmModelAlloc(modelType);222 223 pmModelGuessFunc modelGuessFunc = pmModelGuessFunc_GetFunction(modelType);224 modelGuessFunc(model, source);225 psTrace(__func__, 3, "---- %s() end ----\n", __func__);226 return(model);227 }228 -
branches/rel10_ifa/psModules/src/objects/pmSourceFitModel.h
r6537 r6556 3 3 * @author EAM, IfA; GLG, MHPCC 4 4 * 5 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-03-0 7 06:33:35$5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 33 33 ); 34 34 35 36 pmModel *pmSourceSelectModel (pmSource *source);37 38 /** pmSourceModelGuess()39 *40 * Convert available data to an initial guess for the given model. This41 * function allocates a pmModel entry for the pmSource structure based on the42 * provided model selection. The method of defining the model parameter guesses43 * are specified for each model below. The guess values are placed in the model44 * parameters. The function returns TRUE on success or FALSE on failure.45 *46 */47 pmModel *pmSourceModelGuess(48 pmSource *source, ///< The input pmSource49 pmModelType model ///< The type of model to be created.50 );51 52 35 # endif /* PM_SOURCE_FIT_MODEL_H */ -
branches/rel10_ifa/psModules/src/objects/pmSourceFitSet.c
r6537 r6556 1 /** @file pmSourceFitSet. h1 /** @file pmSourceFitSet.c 2 2 * 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-03-0 7 06:33:35$5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 10 10 */ 11 11 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "pmHDU.h" 17 #include "pmFPA.h" 18 #include "pmPeaks.h" 19 #include "pmMoments.h" 20 #include "pmGrowthCurve.h" 21 #include "pmModel.h" 22 #include "pmPSF.h" 23 #include "pmSource.h" 24 #include "pmModelGroup.h" 25 #include "pmSourceFitSet.h" 26 12 27 // sky, p1.1, p1.2, p1.3,... p1.n, p2.1, p2.2, 13 28 // nPar = nSrc*(nOnePar - 1) + 1 14 15 # include <stdio.h>16 # include <math.h>17 # include <pslib.h>18 # include "pmSource.h"19 29 20 30 static pmModelFunc mFunc; … … 110 120 111 121 // set the static variables 112 pm SourceFitSetInit (model->type);122 pmModelFitSetInit (model->type); 113 123 114 124 int nSrc = modelSet->n; … … 272 282 } 273 283 274 source->mode |= PM_SOURCE_ FITTED;284 source->mode |= PM_SOURCE_MODE_FITTED; 275 285 276 286 psFree(x); -
branches/rel10_ifa/psModules/src/objects/pmSourceIO.c
r6545 r6556 1 /** @file pmSourceIO.c 2 * 3 * @author EAM, IfA 4 * 5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 * 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 9 * 10 */ 11 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "pmHDU.h" 17 #include "pmFPA.h" 18 #include "pmPeaks.h" 19 #include "pmMoments.h" 20 #include "pmGrowthCurve.h" 21 #include "pmModel.h" 22 #include "pmPSF.h" 23 #include "pmSource.h" 24 #include "pmModelGroup.h" 25 #include "pmSourceIO.h" 1 26 2 27 // translations between psphot object types and dophot object types … … 6 31 switch (source->type) { 7 32 8 case PM_SOURCE_ DEFECT:9 case PM_SOURCE_ SATURATED:33 case PM_SOURCE_TYPE_DEFECT: 34 case PM_SOURCE_TYPE_SATURATED: 10 35 return (8); 11 36 12 case PM_SOURCE_ STAR:13 if (source->mode & PM_SOURCE_ SATSTAR)37 case PM_SOURCE_TYPE_STAR: 38 if (source->mode & PM_SOURCE_MODE_SATSTAR) 14 39 return (10); 15 if (source->mode & PM_SOURCE_ POOR)40 if (source->mode & PM_SOURCE_MODE_POOR) 16 41 return (7); 17 if (source->mode & PM_SOURCE_ FAIL)42 if (source->mode & PM_SOURCE_MODE_FAIL) 18 43 return (4); 19 44 return (1); 20 45 21 case PM_SOURCE_ EXTENDED:46 case PM_SOURCE_TYPE_EXTENDED: 22 47 return (2); 23 48 … … 29 54 30 55 /***** Text Output Methods *****/ 31 32 bool pmSourcesWriteText (psArray *sources, char *filename)56 # if (0) 57 bool pmSourcesWriteText (psArray *sources, char *filename) 33 58 { 34 59 … … 50 75 return true; 51 76 } 52 77 # endif -
branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMF.c
r6545 r6556 1 # include "pmSource.h" 1 /** @file pmSourceIO.c 2 * 3 * @author EAM, IfA 4 * 5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 * 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 9 * 10 */ 11 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "psEllipse.h" 17 #include "pmHDU.h" 18 #include "pmFPA.h" 19 #include "pmPeaks.h" 20 #include "pmMoments.h" 21 #include "pmGrowthCurve.h" 22 #include "pmModel.h" 23 #include "pmPSF.h" 24 #include "pmSource.h" 25 #include "pmModelGroup.h" 26 #include "pmSourceIO.h" 2 27 3 28 // elixir-style FITS table output (header + table in 1st extension) … … 12 37 int i, type; 13 38 psF32 *PAR, *dPAR; 14 float dmag,lsky;39 float lsky; 15 40 bool status; 41 EllipseShape shape; 42 EllipseAxes axes; 16 43 17 44 // find config information for output header … … 23 50 for (i = 0; i < sources->n; i++) { 24 51 pmSource *source = (pmSource *) sources->data[i]; 25 pmModel *model = pm ModelSelect(source);52 pmModel *model = pmSourceSelectModel (source); 26 53 if (model == NULL) 27 54 continue; … … 30 57 dPAR = model->dparams->data.F32; 31 58 32 dmag = dPAR[1] / PAR[1];33 59 type = pmSourceDophotType (source); 34 60 lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]); 61 62 shape.sx = PAR[4]; 63 shape.sy = PAR[5]; 64 shape.sxy = PAR[6]; 65 axes = EllipseShapeToAxes (shape); 35 66 36 67 row = psMetadataAlloc (); 37 68 psMetadataAdd (row, PS_LIST_TAIL, "X_PIX", PS_DATA_F32, "", PAR[2]); 38 69 psMetadataAdd (row, PS_LIST_TAIL, "Y_PIX", PS_DATA_F32, "", PAR[3]); 39 psMetadataAdd (row, PS_LIST_TAIL, "MAG_RAW", PS_DATA_F32, "", source->fitMag + ZERO_POINT);40 psMetadataAdd (row, PS_LIST_TAIL, "MAG_ ERR", PS_DATA_F32, "", (int)(1000*dmag));41 psMetadataAdd (row, PS_LIST_TAIL, "MAG_ GAL", PS_DATA_F32, "", 32.0);42 psMetadataAdd (row, PS_LIST_TAIL, "MAG_ AP", PS_DATA_F32, "", source->apMag + ZERO_POINT);70 psMetadataAdd (row, PS_LIST_TAIL, "MAG_RAW", PS_DATA_F32, "", PS_MIN (99.0, source->psfMag + ZERO_POINT)); 71 psMetadataAdd (row, PS_LIST_TAIL, "MAG_GAL", PS_DATA_F32, "", PS_MIN (99.0, source->extMag + ZERO_POINT)); 72 psMetadataAdd (row, PS_LIST_TAIL, "MAG_AP", PS_DATA_F32, "", PS_MIN (99.0, source->apMag + ZERO_POINT)); 73 psMetadataAdd (row, PS_LIST_TAIL, "MAG_ERR", PS_DATA_F32, "", PS_MIN (999, 1000*source->errMag)); 43 74 psMetadataAdd (row, PS_LIST_TAIL, "LOG_SKY", PS_DATA_F32, "", lsky); 44 psMetadataAdd (row, PS_LIST_TAIL, "FWHM_X", PS_DATA_F32, "", type);45 psMetadataAdd (row, PS_LIST_TAIL, "FWHM_Y", PS_DATA_F32, "", PAR[4]);46 psMetadataAdd (row, PS_LIST_TAIL, "THETA", PS_DATA_F32, "", PAR[5]);47 psMetadataAdd (row, PS_LIST_TAIL, "DOPHOT", PS_DATA_ STRING, "", "0");75 psMetadataAdd (row, PS_LIST_TAIL, "FWHM_X", PS_DATA_F32, "", axes.major); 76 psMetadataAdd (row, PS_LIST_TAIL, "FWHM_Y", PS_DATA_F32, "", axes.minor); 77 psMetadataAdd (row, PS_LIST_TAIL, "THETA", PS_DATA_F32, "", axes.theta); 78 psMetadataAdd (row, PS_LIST_TAIL, "DOPHOT", PS_DATA_U8, "", type); 48 79 psMetadataAdd (row, PS_LIST_TAIL, "DUMMY", PS_DATA_STRING, "", "123"); 49 80 … … 62 93 63 94 // read in a readout from the fits file 64 psArray *pm ReadoutReadCMF (psFits *fits, psMetadata *header)95 psArray *pmSourcesReadCMF (psFits *fits, psMetadata *header) 65 96 { 66 97 67 98 bool status; 99 psF32 *PAR, *dPAR; 100 EllipseShape shape; 101 EllipseAxes axes; 102 float lsky; 103 104 // define PSF model type 105 int modelType = pmModelSetType ("PS_MODEL_GAUSS"); 106 107 char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME"); 108 if (PSF_NAME != NULL) { 109 modelType = pmModelSetType (PSF_NAME); 110 } 68 111 69 112 // find config information for output header 70 113 float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT"); 114 if (!status) 115 ZERO_POINT = 25.0; 71 116 72 117 psArray *table = psFitsReadTable (fits); … … 76 121 77 122 // convert the table to the pmSource entries 123 // XXX need to chooose PSF vs EXT, based on type? 78 124 for (int i = 0; i < table->n; i++) { 79 pmStar *source = pmSourceAlloc (); 125 pmSource *source = pmSourceAlloc (); 126 pmModel *model = pmModelAlloc (modelType); 127 source->modelPSF = model; 128 129 PAR = model->params->data.F32; 130 dPAR = model->dparams->data.F32; 80 131 81 132 psMetadata *row = table->data[i]; 82 133 83 source->x = psMetadataLookupF32 (&status, row, "X_PIX"); 84 source->y = psMetadataLookupF32 (&status, row, "Y_PIX"); 85 source->fitMag = psMetadataLookupF32 (&status, row, "MAG_RAW") - ZERO_POINT; 86 source->galMag = psMetadataLookupF32 (&status, row, "MAG_GAL") - ZERO_POINT; 134 lsky = psMetadataLookupF32 (&status, row, "LOG_SKY"); 135 PAR[0] = pow(lsky, 10.0); 136 PAR[2] = psMetadataLookupF32 (&status, row, "X_PIX"); 137 PAR[3] = psMetadataLookupF32 (&status, row, "Y_PIX"); 138 axes.major = psMetadataLookupF32 (&status, row, "FWHM_X"); 139 axes.minor = psMetadataLookupF32 (&status, row, "FWHM_Y"); 140 axes.theta = psMetadataLookupF32 (&status, row, "THETA"); 141 142 shape = EllipseAxesToShape (axes); 143 144 PAR[4] = shape.sx; 145 PAR[5] = shape.sy; 146 PAR[6] = shape.sxy; 147 148 source->psfMag = psMetadataLookupF32 (&status, row, "MAG_RAW") - ZERO_POINT; 149 source->extMag = psMetadataLookupF32 (&status, row, "MAG_GAL") - ZERO_POINT; 150 source->errMag = psMetadataLookupF32 (&status, row, "MAG_ERR"); 87 151 source->apMag = psMetadataLookupF32 (&status, row, "MAG_AP") - ZERO_POINT; 88 source->dMag = psMetadataLookupF32 (&status, row, "MAG_ERR");89 source->sky = psMetadataLookupF32 (&status, row, "LOG_SKY");90 source->sx = psMetadataLookupF32 (&status, row, "FWHM_X");91 source->sy = psMetadataLookupF32 (&status, row, "FWHM_Y");92 source->theta = psMetadataLookupF32 (&status, row, "THETA");93 152 94 153 sources->data[i] = source; -
branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c
r6545 r6556 1 # include "pmSource.h" 1 /** @file pmSourceIO.c 2 * 3 * @author EAM, IfA 4 * 5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 * 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 9 * 10 */ 11 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "psLine.h" 17 #include "psEllipse.h" 18 #include "pmHDU.h" 19 #include "pmFPA.h" 20 #include "pmPeaks.h" 21 #include "pmMoments.h" 22 #include "pmGrowthCurve.h" 23 #include "pmModel.h" 24 #include "pmPSF.h" 25 #include "pmSource.h" 26 #include "pmModelGroup.h" 27 #include "pmSourceIO.h" 2 28 3 29 // elixir-style pseudo FITS table (header + ascii list) … … 10 36 float dmag, lsky; 11 37 bool status; 38 EllipseShape shape; 39 EllipseAxes axes; 12 40 13 41 // find config information for output header … … 19 47 for (i = nSrc = 0; i < sources->n; i++) { 20 48 pmSource *source = (pmSource *) sources->data[i]; 21 pmModel *model = pm ModelSelect(source);49 pmModel *model = pmSourceSelectModel (source); 22 50 if (model == NULL) 23 51 continue; … … 49 77 for (i = 0; i < sources->n; i++) { 50 78 pmSource *source = (pmSource *) sources->data[i]; 51 pmModel *model = pm ModelSelect(source);79 pmModel *model = pmSourceSelectModel (source); 52 80 if (model == NULL) 53 81 continue; … … 56 84 dPAR = model->dparams->data.F32; 57 85 58 dmag = dPAR[1] / PAR[1];59 86 type = pmSourceDophotType (source); 60 87 lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]); 61 88 89 shape.sx = PAR[4]; 90 shape.sy = PAR[5]; 91 shape.sxy = PAR[6]; 92 axes = EllipseShapeToAxes (shape); 93 62 94 psLineInit (line); 63 psLineAdd (line, "%6.1f ", PAR[2]);64 psLineAdd (line, "%6.1f ", PAR[3]);65 psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->fitMag + ZERO_POINT));66 psLineAdd (line, "%03d ", PS_MIN (999, (int)(1000*dmag)));67 psLineAdd (line, "%2d ", type);68 psLineAdd (line, "%3.1f ", lsky);69 psLineAdd (line, "%6.3f ", 99.999); // should be 'Mgal70 psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->apMag+ ZERO_POINT));71 psLineAdd (line, "%6.2f ", PAR[4]); // should be 'FHWM x'72 psLineAdd (line, "%6.2f ", PAR[5]); // should be 'FHWM y'73 psLineAdd (line, "%5.1f\n", 0); // should be theta95 psLineAdd (line, "%6.1f ", PAR[2]); 96 psLineAdd (line, "%6.1f ", PAR[3]); 97 psLineAdd (line, "%6.3f ", PS_MIN (99.0, source->psfMag + ZERO_POINT)); 98 psLineAdd (line, "%03d ", PS_MIN (999, (int)(1000*dmag))); 99 psLineAdd (line, "%2d ", type); 100 psLineAdd (line, "%3.1f ", lsky); 101 psLineAdd (line, "%6.3f ", PS_MIN (99.0, source->extMag + ZERO_POINT)); 102 psLineAdd (line, "%6.3f ", PS_MIN (99.0, source->apMag + ZERO_POINT)); 103 psLineAdd (line, "%6.2f ", axes.major); 104 psLineAdd (line, "%6.2f ", axes.minor); 105 psLineAdd (line, "%5.1f\n", axes.theta); 74 106 fwrite (line->line, 1, line->Nline, f); 75 107 } … … 82 114 83 115 // elixir-style pseudo FITS table (header + ascii list) 84 psArray * sourcespmSourcesReadCMP (char *filename, psMetadata *header)116 psArray *pmSourcesReadCMP (char *filename, psMetadata *header) 85 117 { 86 118 87 int i, type, nSrc; 88 psMetadataItem *mdi; 119 int Ninstar; 89 120 psF32 *PAR, *dPAR; 90 float dmag, lsky;91 121 bool status; 122 EllipseShape shape; 123 EllipseAxes axes; 124 125 // define PSF model type 126 int modelType = pmModelSetType ("PS_MODEL_GAUSS"); 127 128 char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME"); 129 if (PSF_NAME != NULL) { 130 modelType = pmModelSetType (PSF_NAME); 131 } 92 132 93 133 // find config information for output header … … 113 153 114 154 // prepare array to store data 115 int nStars = psMetadataLookupS32 (&status, myHeader, "NSTARS");155 int nStars = psMetadataLookupS32 (&status, header, "NSTARS"); 116 156 psArray *sources = psArrayAlloc (nStars); 117 157 sources->n = 0; 118 158 119 159 // we have fixed bytes / line : use that info 120 char *buffer = psAlloc ( NBYTES_STAR*nStars);160 char *buffer = psAlloc (BYTES_STAR*nStars); 121 161 122 162 int Nextra = 0; … … 161 201 162 202 /* extract data for stars */ 163 intNinstar = nbytes / BYTES_STAR;203 Ninstar = nbytes / BYTES_STAR; 164 204 Nextra = nbytes % BYTES_STAR; 165 for ( j = 0; j < Ninstar; j++, N++) {166 psString line = psStringNCopy (&buffer[j*BYTES_STAR] );205 for (int j = 0; j < Ninstar; j++) { 206 psString line = psStringNCopy (&buffer[j*BYTES_STAR], BYTES_STAR); 167 207 psList *list = psStringSplit (line, " "); 168 208 psArray *array = psListToArray (list); 169 209 170 210 pmSource *source = pmSourceAlloc (); 171 172 source->x = atof (array->data[0]); 173 source->y = atof (array->data[1]); 174 source->fitMag = atof (array->data[2]); 175 source->dMag = 0.001*atof (array->data[3]); 176 source->type = atof (array->data[4]); 177 source->sky = pow (atof (array->data[5]), 10.0); 178 source->galMag = atof (array->data[6]); 211 pmModel *model = pmModelAlloc (modelType); 212 source->modelPSF = model; 213 214 PAR = model->params->data.F32; 215 dPAR = model->dparams->data.F32; 216 217 PAR[0] = pow (atof (array->data[5]), 10.0); 218 PAR[2] = atof (array->data[0]); 219 PAR[3] = atof (array->data[1]); 220 source->psfMag = atof (array->data[2]); 221 source->extMag = atof (array->data[6]); 222 source->errMag = atof (array->data[3]) / 1000.0; 179 223 source->apMag = atof (array->data[7]); 180 source->sx = atof (array->data[8]); 181 source->sy = atof (array->data[9]); 182 source->theta = atof (array->data[10]); 224 axes.major = atof (array->data[8]); 225 axes.minor = atof (array->data[9]); 226 axes.theta = atof (array->data[10]); 227 228 shape = EllipseAxesToShape (axes); 229 230 PAR[4] = shape.sx; 231 PAR[5] = shape.sy; 232 PAR[6] = shape.sxy; 233 234 // source->type = atof (array->data[4]); 183 235 184 236 psArrayAdd (sources, 100, source); -
branches/rel10_ifa/psModules/src/objects/pmSourceIO_OBJ.c
r6545 r6556 1 # include "pmSource.h" 1 /** @file pmSourceIO.c 2 * 3 * @author EAM, IfA 4 * 5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 * 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 9 * 10 */ 11 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "psLine.h" 17 #include "psEllipse.h" 18 #include "pmHDU.h" 19 #include "pmFPA.h" 20 #include "pmPeaks.h" 21 #include "pmMoments.h" 22 #include "pmGrowthCurve.h" 23 #include "pmModel.h" 24 #include "pmPSF.h" 25 #include "pmSource.h" 26 #include "pmModelGroup.h" 27 #include "pmSourceIO.h" 2 28 3 29 // dophot-style output list with fixed line width … … 8 34 psF32 *PAR, *dPAR; 9 35 float dmag, apResid; 36 EllipseShape shape; 37 EllipseAxes axes; 10 38 11 39 psTimerStart ("string"); … … 22 50 for (int i = 0; i < sources->n; i++) { 23 51 pmSource *source = (pmSource *) sources->data[i]; 24 pmModel *model = pm ModelSelect(source);52 pmModel *model = pmSourceSelectModel (source); 25 53 if (model == NULL) 26 54 continue; … … 31 59 dmag = dPAR[1] / PAR[1]; 32 60 type = pmSourceDophotType (source); 33 apResid = source->apMag - source->fitMag; 61 if ((source->apMag < 99.0) && (source->psfMag < 99.0)) { 62 apResid = source->apMag - source->psfMag; 63 } else { 64 apResid = 0.0; 65 } 66 67 shape.sx = PAR[4]; 68 shape.sy = PAR[5]; 69 shape.sxy = PAR[6]; 70 axes = EllipseShapeToAxes (shape); 34 71 35 72 psLineInit (line); … … 37 74 psLineAdd (line, "%8.2f", PAR[2]); 38 75 psLineAdd (line, "%8.2f", PAR[3]); 39 psLineAdd (line, "%8.3f", source-> fitMag);76 psLineAdd (line, "%8.3f", source->psfMag); 40 77 psLineAdd (line, "%6.3f", dmag); 41 78 psLineAdd (line, "%9.2f", PAR[0]); 42 psLineAdd (line, "%9.3f", PAR[4]);43 psLineAdd (line, "%9.3f", PAR[5]);44 psLineAdd (line, "%7.2f", PAR[6]);45 psLineAdd (line, "%8.3f", 99.999);79 psLineAdd (line, "%9.3f", axes.major); 80 psLineAdd (line, "%9.3f", axes.minor); 81 psLineAdd (line, "%7.2f", axes.theta); 82 psLineAdd (line, "%8.3f", source->extMag); 46 83 psLineAdd (line, "%8.3f", source->apMag); 47 84 psLineAdd (line, "%8.2f\n", apResid); … … 50 87 fclose (f); 51 88 psFree (line); 52 fprintf (stderr, "%f seconds for %d objects with psLine\n", psTimerMark ("string"), (int)sources->n); 53 54 psTimerStart ("string"); 55 56 f = fopen ("test.obj", "w"); 57 if (f == NULL) { 58 psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", "test.obj"); 59 return false; 60 } 61 62 char *string; 63 // write sources with models 64 for (int i = 0; i < sources->n; i++) { 65 pmSource *source = (pmSource *) sources->data[i]; 66 pmModel *model = pmModelSelect (source); 67 if (model == NULL) 68 continue; 69 70 PAR = model->params->data.F32; 71 dPAR = model->dparams->data.F32; 72 73 dmag = dPAR[1] / PAR[1]; 74 type = pmSourceDophotType (source); 75 apResid = source->apMag - source->fitMag; 76 77 string = NULL; 78 psStringAppend (&string, "%3d", type); 79 psStringAppend (&string, "%8.2f", PAR[2]); 80 psStringAppend (&string, "%8.2f", PAR[3]); 81 psStringAppend (&string, "%8.3f", source->fitMag); 82 psStringAppend (&string, "%6.3f", dmag); 83 psStringAppend (&string, "%9.2f", PAR[0]); 84 psStringAppend (&string, "%9.3f", PAR[4]); 85 psStringAppend (&string, "%9.3f", PAR[5]); 86 psStringAppend (&string, "%7.2f", PAR[6]); 87 psStringAppend (&string, "%8.3f", 99.999); 88 psStringAppend (&string, "%8.3f", source->apMag); 89 psStringAppend (&string, "%8.2f\n", apResid); 90 fwrite (string, 1, strlen(string), f); 91 psFree (string); 92 } 93 fclose (f); 94 fprintf (stderr, "%f seconds for %d objects with psString\n", psTimerMark ("string"), (int)sources->n); 95 89 fprintf (stderr, "%f seconds for %d objects\n", psTimerMark ("string"), (int)sources->n); 96 90 return true; 97 91 } 98 99 // XXX should we use psStringAppend or psLineAdd? -
branches/rel10_ifa/psModules/src/objects/pmSourceIO_SX.c
r6545 r6556 1 # include "pmSource.h" 1 /** @file pmSourceIO.c 2 * 3 * @author EAM, IfA 4 * 5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 * 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 9 * 10 */ 11 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "psLine.h" 17 #include "psEllipse.h" 18 #include "pmHDU.h" 19 #include "pmFPA.h" 20 #include "pmPeaks.h" 21 #include "pmMoments.h" 22 #include "pmGrowthCurve.h" 23 #include "pmModel.h" 24 #include "pmPSF.h" 25 #include "pmSource.h" 26 #include "pmModelGroup.h" 27 #include "pmSourceIO.h" 2 28 3 29 // elixir-mode / sextractor-style output list with fixed line width … … 6 32 7 33 psF32 *PAR, *dPAR; 8 float dmag; 34 EllipseShape shape; 35 EllipseAxes axes; 9 36 10 37 psLine *line = psLineAlloc (110); // 110 is sextractor line length … … 19 46 for (int i = 0; i < sources->n; i++) { 20 47 pmSource *source = (pmSource *) sources->data[i]; 21 pmModel *model = pm ModelSelect(source);48 pmModel *model = pmSourceSelectModel (source); 22 49 if (model == NULL) 23 50 continue; … … 28 55 // pmSourceSextractType (source, &type, &flags); 29 56 30 dmag = dPAR[1] / PAR[1]; 57 shape.sx = PAR[4]; 58 shape.sy = PAR[5]; 59 shape.sxy = PAR[6]; 60 axes = EllipseShapeToAxes (shape); 31 61 32 62 psLineInit (line); 33 psLineAdd (line, "%5.2f", 0.0); // should be type63 psLineAdd (line, "%5.2f", 0.0); // should be type 34 64 psLineAdd (line, "%11.3f", PAR[2]); 35 65 psLineAdd (line, "%11.3f", PAR[3]); 36 psLineAdd (line, "%9.4f", source->fitMag);37 psLineAdd (line, "%9.4f", dmag);66 psLineAdd (line, "%9.4f", source->psfMag); 67 psLineAdd (line, "%9.4f", source->errMag); 38 68 psLineAdd (line, "%13.4f", PAR[0]); 39 psLineAdd (line, "%9.2f", 0.0); // should be FWHMx40 psLineAdd (line, "%9.2f", 0.0); // should be FWHMy41 psLineAdd (line, "%6.1f", 0.0); // should be Theta42 psLineAdd (line, "%9.4f", 99.999); // should be MAG_ISO43 psLineAdd (line, "%9.4f", source->apMag);44 psLineAdd (line, "%4d\n", 0); // should be flags69 psLineAdd (line, "%9.2f", axes.major); 70 psLineAdd (line, "%9.2f", axes.minor); 71 psLineAdd (line, "%6.1f", axes.theta); 72 psLineAdd (line, "%9.4f", source->extMag); 73 psLineAdd (line, "%9.4f", source->apMag); 74 psLineAdd (line, "%4d\n", 0); // should be flags 45 75 fwrite (line->line, 1, line->Nline, f); 46 76 } -
branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c
r6537 r6556 1 /** @file pmSourcePhotometry. C1 /** @file pmSourcePhotometry.c 2 2 * 3 3 * @author EAM, IfA; GLG, MHPCC 4 4 * 5 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-03-0 7 06:33:35$5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 10 10 */ 11 11 12 // XXX EAM : the apMag should only be calculated for the brighter sources? 13 // XXX EAM : SN limit set by user? 12 #include <stdio.h> 13 #include <math.h> 14 #include <string.h> 15 #include "pslib.h" 16 #include "pmHDU.h" 17 #include "pmFPA.h" 18 #include "pmPeaks.h" 19 #include "pmMoments.h" 20 #include "pmGrowthCurve.h" 21 #include "pmModel.h" 22 #include "pmPSF.h" 23 #include "pmSource.h" 24 #include "pmModelGroup.h" 25 #include "pmSourcePhotometry.h" 26 27 static float AP_MIN_SN = 0.0; 28 29 bool pmSourceMagnitudesInit (psMetadata *config) 30 { 31 32 bool status; 33 34 float limit = psMetadataLookupF32 (&status, config, "AP_MIN_SN"); 35 if (status) { 36 AP_MIN_SN = limit; 37 } 38 return true; 39 } 40 41 /** 42 this function is used to calculate the three defined source magnitudes: 43 - apMag : only if S/N > AP_MIN_SN 44 : is optionally corrected for curve-of-growth if: 45 - the source is a STAR (PSF) 46 - the option is selected (how??) 47 - psfMag : all sources with non-NULL modelPSF 48 : is optionally corrected for aperture residual if: 49 - the source is a STAR (PSF) 50 - the option is selected (how??) 51 52 - extMag : all sources with non-NULL modelEXT 53 **/ 54 14 55 // XXX EAM : masked region should be (optionally) elliptical 56 // XXX curve of growth is corrected to 15 57 pmModel *pmSourceMagnitudes (pmSource *source, pmPSF *psf, float apRadius) 16 58 { … … 21 63 float rflux; 22 64 float radius; 65 float SN; 23 66 pmModel *model; 24 67 25 68 switch (source->type) { 26 case PM_SOURCE_ STAR:69 case PM_SOURCE_TYPE_STAR: 27 70 model = source->modelPSF; 28 71 if (model == NULL) … … 32 75 break; 33 76 34 case PM_SOURCE_ EXTENDED:77 case PM_SOURCE_TYPE_EXTENDED: 35 78 model = source->modelEXT; 36 79 if (model == NULL) … … 44 87 } 45 88 89 if (model->dparams->data.F32[1] > 0) { 90 SN = model->params->data.F32[1] / model->dparams->data.F32[1]; 91 source->errMag = 1.0 / SN; 92 } else { 93 SN = 0.0; 94 source->errMag = 0.0; 95 } 46 96 x = model->params->data.F32[2]; 47 97 y = model->params->data.F32[3]; 48 98 49 99 // replace source flux 100 // XXX test to see if source has been subtracted? 50 101 pmModelAdd (source->pixels, source->mask, model, false, false); 51 102 52 // set aperture mask circle of PSF_FIT_RADIUS 53 psImageKeepCircle (source->mask, x, y, radius, "OR", PSPHOT_MASK_MARKED); 54 55 // measure object photometry 56 status = pmSourcePhotometry (&source->fitMag, &source->apMag, model, source->pixels, source->mask); 57 58 // for PSFs, correct both apMag and fitMag to same system, consistent with infinite flux star in aperture RADIUS 103 // set aperture mask circle to scaled radius 104 psImageKeepCircle (source->mask, x, y, model->radius, "OR", PM_SOURCE_MASK_MARKED); 105 106 // measure object model photometry 107 status = pmSourcePhotometryModel (&source->psfMag, source->modelPSF); 108 status = pmSourcePhotometryModel (&source->extMag, source->modelEXT); 109 110 // measure object aperture photometry 111 if (SN > AP_MIN_SN) { 112 status = pmSourcePhotometryAper (&source->apMag, model, source->pixels, source->mask); 113 } else { 114 source->apMag = 99.0; 115 } 116 117 // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS 59 118 if (isPSF && (psf != NULL)) { 60 if (psf->growth != NULL) { 61 source->apMag += pmGrowthCurveCorrect (psf->growth, model->radius); 62 } 63 64 rflux = pow (10.0, 0.4*source->fitMag); 65 source->apMag -= PS_SQR(model->radius)*rflux * psf->skyBias + psf->skySat / rflux; 66 source->fitMag += psPolynomial4DEval (psf->ApTrend, x, y, 0.0, 0.0); 119 if (SN > AP_MIN_SN) { 120 if (psf->growth != NULL) { 121 source->apMag += pmGrowthCurveCorrect (psf->growth, radius); 122 } 123 rflux = pow (10.0, 0.4*source->psfMag); 124 source->apMag -= PS_SQR(model->radius)*rflux * psf->skyBias + psf->skySat / rflux; 125 } 126 source->psfMag += psPolynomial4DEval (psf->ApTrend, x, y, 0.0, 0.0); 67 127 } 68 128 69 129 // unmask aperture 70 psImageKeepCircle (source->mask, x, y, radius, "AND", ~PSPHOT_MASK_MARKED);130 psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PM_SOURCE_MASK_MARKED); 71 131 72 132 // subtract object, leave local sky … … 85 145 */ 86 146 87 // XXX split into ap, psf, ext mags? 88 bool pmSourcePhotometry (float *fitMag, float *obsMag, pmModel *model, psImage *image, psImage *mask) 147 // return source model magnitude 148 bool pmSourcePhotometryModel (float *fitMag, pmModel *model) 149 { 150 151 float fitSum = 0; 152 *fitMag = 99.0; 153 154 if (model == NULL) { 155 return false; 156 } 157 158 // measure fitMag 159 pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type); 160 fitSum = modelFluxFunc (model->params); 161 if (fitSum <= 0) 162 return false; 163 if (!isfinite(fitSum)) 164 return false; 165 *fitMag = -2.5*log10(fitSum); 166 167 return (true); 168 } 169 170 // return source aperture magnitude 171 bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask) 172 { 173 174 float apSum = 0; 175 *apMag = 99.0; 176 177 if (model == NULL) { 178 return false; 179 } 180 181 float sky = model->params->data.F32[0]; 182 183 // measure apMag 184 for (int ix = 0; ix < image->numCols; ix++) { 185 for (int iy = 0; iy < image->numRows; iy++) { 186 if (mask->data.U8[iy][ix]) 187 continue; 188 apSum += image->data.F32[iy][ix] - sky; 189 } 190 } 191 if (apSum <= 0) 192 return false; 193 *apMag = -2.5*log10(apSum); 194 195 return (true); 196 } 197 198 # if (0) 199 // XXX split into ap, psf, ext mags? 200 bool pmSourcePhotometry (float *fitMag, float *apMag, pmModel *model, psImage *image, psImage *mask) 89 201 { 90 202 … … 96 208 *obsMag = 99.0; 97 209 210 // measure fitMag 98 211 pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type); 99 212 fitSum = modelFluxFunc (model->params); … … 104 217 *fitMag = -2.5*log10(fitSum); 105 218 219 // measure apMag 106 220 for (int ix = 0; ix < image->numCols; ix++) { 107 221 for (int iy = 0; iy < image->numRows; iy++) { … … 117 231 return (true); 118 232 } 233 # endif 119 234 120 235 float pmSourceCrossProduct (pmSource *Mi, pmSource *Mj) -
branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.h
r6537 r6556 3 3 * @author EAM, IfA; GLG, MHPCC 4 4 * 5 * @version $Revision: 1.1.2. 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-03-0 7 06:33:35$5 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-03-09 03:14:23 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 25 25 * 26 26 */ 27 bool pmSourcePhotometry (27 bool pmSourcePhotometryModel( 28 28 float *fitMag, ///< integrated fit magnitude 29 float *obsMag, ///< aperture flux magnitude 29 pmModel *model ///< model used for photometry 30 ); 31 32 bool pmSourcePhotometryAper( 33 float *apMag, ///< aperture flux magnitude 30 34 pmModel *model, ///< model used for photometry 31 35 psImage *image, ///< image pixels to be used -
branches/rel10_ifa/psModules/src/objects/pmSourceSky.c
r6537 r6556 1 /** @file pmSourceSky.c 2 * 3 * Functions to measure the local sky and sky variance for sources on images 4 * 5 * @author GLG, MHPCC 6 * @author EAM, IfA: significant modifications. 7 * 8 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-03-09 03:14:23 $ 10 * 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 12 * 13 */ 14 15 #include <stdio.h> 16 #include <math.h> 17 #include <string.h> 18 #include "pslib.h" 19 #include "pmHDU.h" 20 #include "pmFPA.h" 21 #include "pmPeaks.h" 22 #include "pmMoments.h" 23 #include "pmModel.h" 24 #include "pmSource.h" 25 #include "pmSourceSky.h" 1 26 2 27 /****************************************************************************** 3 pmSource *pmSourceLocalSky(image, peak, innerRadius, outerRadius): this 4 routine creates a new pmSource data structure and sets the following members: 5 ->pmPeak 6 ->pmMoments->sky 28 pmSource *pmSourceLocalSky(source, statsOptions, Radius): this 29 routine creates a new pmSource.moments element if needed and sets pmSource.pmMoments.sky 7 30 8 31 The sky value is set from the pixels in the square annulus surrounding the 9 32 peak pixel. 10 33 11 We simply create a subSet image and mask the inner pixels, then call 12 psImageStats on that subImage+mask. 13 14 XXX: The subImage has width of 1+2*outerRadius. Verify with IfA. 15 16 XXX: Use static data structures for: 17 subImage 18 subImageMask 19 myStats 20 21 XXX: ensure that the inner and out radius fit in the actual image. Should 22 we generate an error, or warning? Currently an error. 23 24 XXX: Sync with IfA on whether the peak x/y coords are data structure coords, 25 or they use the image row/column offsets. 26 XXX EAM : peak->x,y uses parent coordinates 27 28 XXX: Should we simply set pmSource->peak = peak? If so, should we increase 29 the reference counter? Or, should we copy the data structure? 30 31 XXX: Currently the subimage always has an even number of rows/columns. Is 32 this correct? Since there is a center pixel, maybe it should have an 33 odd number of rows/columns. 34 35 XXX: Use psTrace() for the print statements. 36 37 XXX: Don't use separate structs for the subimage and mask. Use the source-> 38 members. 34 The source.pixels and source.mask must already exist 39 35 *****************************************************************************/ 40 36 … … 60 56 srcRegion = psRegionForImage(mask, srcRegion); 61 57 62 psImageMaskRegion(mask, srcRegion, "OR", P SPHOT_MASK_MARKED);58 psImageMaskRegion(mask, srcRegion, "OR", PM_SOURCE_MASK_MARKED); 63 59 psStats *myStats = psStatsAlloc(statsOptions); 64 60 myStats = psImageStats(myStats, image, mask, 0xff); 65 psImageMaskRegion(mask, srcRegion, "AND", ~P SPHOT_MASK_MARKED);61 psImageMaskRegion(mask, srcRegion, "AND", ~PM_SOURCE_MASK_MARKED); 66 62 67 63 psF64 tmpF64; … … 103 99 srcRegion = psRegionForImage(mask, srcRegion); 104 100 105 psImageMaskRegion(mask, srcRegion, "OR", P SPHOT_MASK_MARKED);101 psImageMaskRegion(mask, srcRegion, "OR", PM_SOURCE_MASK_MARKED); 106 102 psStats *myStats = psStatsAlloc(statsOptions); 107 103 myStats = psImageStats(myStats, image, mask, 0xff); 108 psImageMaskRegion(mask, srcRegion, "AND", ~P SPHOT_MASK_MARKED);104 psImageMaskRegion(mask, srcRegion, "AND", ~PM_SOURCE_MASK_MARKED); 109 105 110 106 psF64 tmpF64;
Note:
See TracChangeset
for help on using the changeset viewer.
