IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6556


Ignore:
Timestamp:
Mar 8, 2006, 5:14:23 PM (20 years ago)
Author:
magnier
Message:

major rework of objects code

Location:
branches/rel10_ifa/psModules/src/objects
Files:
2 added
31 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/objects/Makefile.am

    r6448 r6556  
    44libpsmoduleobjects_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    55libpsmoduleobjects_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 \
    721    pmPSF.c \
    822    pmPSFtry.c \
    9     pmModelGroup.c \
    1023    pmGrowthCurve.c \
    11     psEllipse.c
     24    pmFPAviewReadObjects.c \
     25    pmFPAviewWriteObjects.c
    1226
    1327EXTRA_DIST = \
     
    1933psmoduleincludedir = $(includedir)
    2034psmoduleinclude_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 \
    2246    pmPSF.h \
    2347    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"
    228
    329// Given a FITS file pointer, read the table of object data
     
    4268
    4369// read in all chip-level Objects files for this FPA
    44 pmFPAReadObjects (pmFPA *fpa, pmFPAview *view, pmFPAfile *file)
     70bool pmFPAReadObjects (pmFPA *fpa, pmFPAview *view, pmFPAfile *file)
    4571{
    4672
    4773    for (int i = 0; i < fpa->chips->n; i++) {
    4874
    49         pmChip *chip = fpa->data[i];
     75        pmChip *chip = fpa->chips->data[i];
    5076        pmChipReadObjects (chip, view, file);
    5177    }
     
    5480
    5581// read in all cell-level Objects files for this chip
    56 pmChipReadObjects (pmChip *chip, pmFPAview *view, pmFPAfile *file)
     82bool pmChipReadObjects (pmChip *chip, pmFPAview *view, pmFPAfile *file)
    5783{
    5884
    5985    for (int i = 0; i < chip->cells->n; i++) {
    6086
    61         pmCell *cell = chip->data[i];
     87        pmCell *cell = chip->cells->data[i];
    6288        pmCellReadObjects (cell, view, file);
    6389    }
     
    6692
    6793// read in all readout-level Objects files for this cell
    68 pmCellReadObjects (pmCell *cell, pmFPAview *view, pmFPAfile *file)
     94bool pmCellReadObjects (pmCell *cell, pmFPAview *view, pmFPAfile *file)
    6995{
    7096
    7197    for (int i = 0; i < cell->readouts->n; i++) {
    7298
    73         pmReadout *readout = cell->data[i];
     99        pmReadout *readout = cell->readouts->data[i];
    74100        pmReadoutReadObjects (readout, view, file);
    75101    }
     
    78104
    79105// read in all readout-level Objects files for this cell
    80 pmReadoutReadObjects (pmReadout *readout, pmFPAview *view, pmFPAfile *file)
     106bool pmReadoutReadObjects (pmReadout *readout, pmFPAview *view, pmFPAfile *file)
    81107{
    82108
     109    bool status;
    83110    psArray *sources;
     111    pmHDU *hdu;
    84112
    85113    switch (file->type) {
     
    96124
    97125        // read in header, if not yet loaded
    98         pmHDU *hdu = pmFPAviewThisHDU (view);
     126        hdu = pmFPAviewThisHDU (view);
    99127
    100         filename = pmConfigNameFromRule (file->filerule, view);
     128        char *filename = pmFPAviewNameFromRule (file->filerule, view);
    101129        file->fits = psFitsOpen (filename, "r");
    102         hdu->header = psFitsReadHeader (file->fits);
     130        hdu->header = psFitsReadHeader (NULL, file->fits);
    103131        psFitsClose (file->fits);
    104132        sources  = pmSourcesReadCMP (filename, hdu->header);
     
    107135    case PM_FPA_FILE_CMF:
    108136        // read in header, if not yet loaded
    109         pmHDU *hdu = pmFPAviewThisHDU (view);
     137        hdu = pmFPAviewThisHDU (view);
    110138        if (hdu->header == NULL) {
    111             headname = pmConfigNameFromRule (file->extxtra, view);
    112             psFitsMoveExtName (fits, 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);
    114142        }
    115143
    116         dataname = pmConfigNameFromRule (file->extrule, view);
    117         psFitsMoveExtName (fits, dataname);
     144        char *dataname = pmFPAviewNameFromRule (file->extrule, view);
     145        psFitsMoveExtName (file->fits, dataname);
    118146        sources  = pmSourcesReadCMF (file->fits, hdu->header);
     147        break;
     148
     149    default:
     150        fprintf (stderr, "warning: type mismatch\n");
    119151        break;
    120152    }
  • 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"
    228
    329// Given a FITS file pointer, read the table of object data
     
    4268
    4369// read in all chip-level Objects files for this FPA
    44 pmFPAWriteObjects (pmFPA *fpa, pmFPAview *view, pmFPAfile *file)
     70bool pmFPAWriteObjects (pmFPA *fpa, pmFPAview *view, pmFPAfile *file)
    4571{
    4672
    4773    for (int i = 0; i < fpa->chips->n; i++) {
    4874
    49         pmChip *chip = fpa->data[i];
     75        pmChip *chip = fpa->chips->data[i];
    5076        pmChipWriteObjects (chip, view, file);
    5177    }
     
    5480
    5581// read in all cell-level Objects files for this chip
    56 pmChipWriteObjects (pmChip *chip, pmFPAview *view, pmFPAfile *file)
     82bool pmChipWriteObjects (pmChip *chip, pmFPAview *view, pmFPAfile *file)
    5783{
    5884
    5985    for (int i = 0; i < chip->cells->n; i++) {
    6086
    61         pmCell *cell = chip->data[i];
     87        pmCell *cell = chip->cells->data[i];
    6288        pmCellWriteObjects (cell, view, file);
    6389    }
     
    6692
    6793// read in all readout-level Objects files for this cell
    68 pmCellWriteObjects (pmCell *cell, pmFPAview *view, pmFPAfile *file)
     94bool pmCellWriteObjects (pmCell *cell, pmFPAview *view, pmFPAfile *file)
    6995{
    7096
    7197    for (int i = 0; i < cell->readouts->n; i++) {
    7298
    73         pmReadout *readout = cell->data[i];
     99        pmReadout *readout = cell->readouts->data[i];
    74100        pmReadoutWriteObjects (readout, view, file);
    75101    }
     
    78104
    79105// read in all readout-level Objects files for this cell
    80 pmReadoutWriteObjects (pmReadout *readout, pmFPAview *view, pmFPAfile *file)
     106bool pmReadoutWriteObjects (pmReadout *readout, pmFPAview *view, pmFPAfile *file)
    81107{
     108
     109    bool status;
     110    char *filename;
     111    char *dataname;
     112    char *headname;
     113    pmHDU *hdu;
    82114
    83115    psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
     
    85117    switch (file->type) {
    86118    case PM_FPA_FILE_OBJ:
    87         filename = pmConfigNameFromRule (file->filerule, view);
    88         pmSourcesWriteOBJ (filename, sources);
     119        filename = pmFPAviewNameFromRule (file->filerule, view);
     120        pmSourcesWriteOBJ (sources, filename);
    89121        break;
    90122
    91123    case PM_FPA_FILE_SX:
    92         filename = pmConfigNameFromRule (file->filerule, view);
    93         pmSourcesWriteSX (filename, sources);
     124        filename = pmFPAviewNameFromRule (file->filerule, view);
     125        pmSourcesWriteSX (sources, filename);
    94126        break;
    95127
    96128    case PM_FPA_FILE_CMP:
    97129        // a SPLIT format : only one header and object table per file
    98         pmHDU *hdu = pmFPAviewThisHDU (view);
    99         filename = pmConfigNameFromRule (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);
    101133        break;
    102134
    103135    case PM_FPA_FILE_CMF:
    104136        // write header, if not yet written?
    105         pmHDU *hdu = pmFPAviewThisHDU (view);
     137        hdu = pmFPAviewThisHDU (view);
    106138
    107139        // XXX is this needed? is it automatically added?
     
    111143        if (hdu->header) {
    112144            psMetadataItem *mdi = NULL;
    113             headname = pmConfigNameFromRule (file->extxtra, view);
     145            headname = pmFPAviewNameFromRule (file->extxtra, view);
    114146
    115147            // set NAXIS to 0 (we don't write out the data array)
     
    119151            mdi->type = PS_DATA_S32;
    120152
    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);
    122157        }
    123         dataname = pmConfigNameFromRule (file->extrule, view);
     158        dataname = pmFPAviewNameFromRule (file->extrule, view);
    124159        pmSourcesWriteCMF (file->fits, sources, hdu->header, dataname);
     160        break;
     161
     162    default:
     163        fprintf (stderr, "warning: type mismatch\n");
    125164        break;
    126165    }
  • 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
    114#include <pslib.h>
    2 # include "pmGrowthCurve.h"
     15#include "pmGrowthCurve.h"
    316
    417static void pmGrowthCurveFree (pmGrowthCurve *growth)
  • branches/rel10_ifa/psModules/src/objects/pmGrowthCurve.h

    r6448 r6556  
     1
    12# ifndef PM_GROWTH_CURVE_H
    23# define PM_GROWTH_CURVE_H
     
    1920psF32 pmGrowthCurveCorrect (pmGrowthCurve *growth, psF32 radius);
    2021
     22// XXX psVectorBracket,Interpolate should be put in pslib
     23
    2124# endif /* PM_GROWTH_CURVE_H */
  • branches/rel10_ifa/psModules/src/objects/pmModel.c

    r6537 r6556  
    1 /** @file  pmObjects.c
    2  *
    3  *  This file will ...
     1/** @file  pmModel.c
     2 *
     3 *  Functions to define and manipulate object models
    44 *
    55 *  @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-07 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 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717#include <string.h>
    1818#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
     25typedef psMinimizeLMChi2Func pmModelFunc;
     26typedef bool (*pmModelFitStatusFunc)(pmModel *model);
     27pmModelFunc pmModelFunc_GetFunction (pmModelType type);
     28pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type);
     29int pmModelParameterCount(pmModelType type);
    2130
    2231static void modelFree(pmModel *tmp)
  • branches/rel10_ifa/psModules/src/objects/pmModel.h

    r6537 r6556  
    11/** @file  pmObjects.h
    22 *
    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
    94 *
    105 *  @author GLG, MHPCC
     6 *  @author EAM, IfA
    117 *
    12  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-03-07 06:33:35 $
     8 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-03-09 03:14:23 $
    1410 *
    1511 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6157pmModel *pmModelCopy (pmModel *model);
    6258
    63 psF32 pmModelEval(pmModel *model, psImage *image, psS32 col, psS32 row)
     59psF32 pmModelEval(pmModel *model, psImage *image, psS32 col, psS32 row);
    6460
    6561/** 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 ???
    331double hypot(double x, double y);
    432double sqrt (double x);
    533
    6 #include "psEllipse.h"
    734#include "models/pmModel_GAUSS.c"
    835#include "models/pmModel_PGAUSS.c"
     
    159186    return (models[type].name);
    160187}
     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*****************************************************************************/
     199pmModel *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  
    99 *  @author EAM, IfA
    1010 *
    11  *  @version $Revision: 1.2.4.1 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2006-02-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 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1515 *
    1616 */
    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.
     22typedef psMinimizeLMChi2Func pmModelFunc;
     23
     24// This function returns the integrated flux for the given model parameters.
     25typedef 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.
     30typedef psF64 (*pmModelRadius)(const psVector *params, double flux);
     31
     32/*  This function sets the model parameter limits vectors for the given model
     33 */
     34typedef 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 */
     39typedef 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 */
     45typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf);
     46
     47/*  This function returns the success / failure status of the given model fit
     48 */
     49typedef 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 */
     64typedef 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}
     76pmModelGroup;
     77
     78// allocate a pmModelGroup to hold nModels entries
     79pmModelGroup *pmModelGroupAlloc (int nModels);
     80
     81// initialize the internal (static) model group with the default models
     82void pmModelGroupInit (void);
     83
     84// free the internal (static) model group
     85void pmModelGroupCleanup (void);
     86
     87// add a new model to the internal (static) model group
     88void pmModelGroupAdd (pmModelGroup *model);
     89
     90/* This function returns the number of parameters used by the listed function.
    2391 */
    2492int pmModelParameterCount(
     
    2795
    2896
    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.
    3398 */
    3499char *pmModelGetType(
     
    46111);
    47112
    48 
    49 #ifndef PM_MODEL_GROUP_H
    50 #define PM_MODEL_GROUP_H
    51 
    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 parameters
    70  *  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 model
    78  *
    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 of
    85  *   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 the
    94  *  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 fit
    102  *
    103  */
    104 typedef bool (*pmModelFitStatusFunc)(pmModel *model);
    105 
    106113/**
    107114 *
     
    110117 *
    111118 */
    112 
    113119
    114120/**
     
    177183
    178184
     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 */
     194pmModel *pmSourceModelGuess(
     195    pmSource *source,   ///< The input pmSource
     196    pmModelType model   ///< The type of model to be created.
     197);
    179198
    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  pmObjects.c
     1/** @file  pmMoments.c
    22 *
    3  *  This file will ...
     3 *  Functions defining the pmMoments structure
    44 *
    55 *  @author GLG, MHPCC
    6  *  @author EAM, IfA: significant modifications.
     6 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-03-07 06:33:35 $
     8 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-03-09 03:14:23 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1313 */
    1414
    15 #include <stdio.h>
    16 #include <math.h>
    17 #include <string.h>
    1815#include "pslib.h"
    19 #include "pmObjects.h"
    20 #include "pmModelGroup.h"
     16#include "pmMoments.h"
    2117
    2218/******************************************************************************
     
    4238}
    4339
    44 /******************************************************************************
    45 pmSourceMoments(source, radius): this function takes a subImage defined in the
    46 pmSource data structure, along with the peak location, and determines the
    47 various moments associated with that peak.
    48  
    49 Requires the following to have been created:
    50     pmSource
    51     pmSource->peak
    52     pmSource->pixels
    53     pmSource->weight
    54     pmSource->mask
    55  
    56 XXX: The peak calculations are done in image coords, not subImage coords.
    57  
    58 XXX EAM : this version clips input pixels on S/N
    59 XXX EAM : this version returns false for several reasons
    60 *****************************************************************************/
    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 sky
    109     // 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 each
    111     // pixel that is not masked, AND within the radius of the peak pixel, we
    112     // proceed with the moments calculation.  need to do two loops for a
    113     // numerically stable result.  first loop: get the sums.
    114     // XXX EAM : mask == 0 is valid
    115 
    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 pixel
    142             // 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 retry
    170     // 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 + xc
    183     // second moment X = sqrt (X2/Sum - (X1/Sum)^2)
    184     // Sxy             = XY / Sum
    185     //
    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 subtracted
    200     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 range
    207     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  pmObjects.h
     1/** @file  pmMoments.h
    22 *
    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
    94 *
    105 *  @author GLG, MHPCC
    116 *
    12  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-03-07 06:33:35 $
     7 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-03-09 03:14:23 $
    149 *
    1510 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1611 *
    1712 */
     13
     14# ifndef PM_MOMENTS_H
     15# define PM_MOMENTS_H
    1816
    1917/** pmMoments data structure
     
    4543pmMoments *pmMomentsAlloc();
    4644
    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  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.4.4.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-02-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 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818
    1919#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"
    2127#include "pmPSF.h"
    2228#include "pmModelGroup.h"
  • branches/rel10_ifa/psModules/src/objects/pmPSF.h

    r6448 r6556  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.1.22.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-02-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 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1515# ifndef PM_PSF_H
    1616# define PM_PSF_H
    17 
    18 #include "pmGrowthCurve.h"
    1917
    2018/** pmPSF data structure
  • branches/rel10_ifa/psModules/src/objects/pmPSFtry.c

    r6448 r6556  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.4.4.1 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-02-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 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1313
    1414# 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"
    1927
    2028// ********  pmPSFtry functions  **************************************************
     
    104112        // fit model as EXT, not PSF
    105113
    106         psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PSPHOT_MASK_MARKED);
     114        psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PM_SOURCE_MASK_MARKED);
    107115        status = pmSourceFitModel (source, model, false);
    108         psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PSPHOT_MASK_MARKED);
     116        psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PM_SOURCE_MASK_MARKED);
    109117
    110118        // exclude the poor fits
     
    138146        y = source->peak->y;
    139147
    140         psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PSPHOT_MASK_MARKED);
     148        psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PM_SOURCE_MASK_MARKED);
    141149        status = pmSourceFitModel (source, modelPSF, true);
    142150
     
    154162        // XXX : use a different estimator for the local sky?
    155163        // 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)) {
    157169            psfTry->mask->data.U8[i] = PSFTRY_MASK_BAD_PHOT;
    158170            goto next_source;
     
    164176
    165177next_source:
    166         psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PSPHOT_MASK_MARKED);
     178        psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PM_SOURCE_MASK_MARKED);
    167179
    168180    }
  • branches/rel10_ifa/psModules/src/objects/pmPeaks.c

    r6537 r6556  
    1 /** @file  pmObjects.c
     1/** @file  pmPeaks.c
    22 *
    3  *  This file will ...
     3 *  This file defines functions to detect and manipulate peaks in images
    44 *
    55 *  @author GLG, MHPCC
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-03-07 06:33:35 $
     8 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-03-09 03:14:23 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717#include <string.h>
    1818#include "pslib.h"
    19 #include "pmObjects.h"
    20 #include "pmModelGroup.h"
     19#include "pmPeaks.h"
    2120
    2221/******************************************************************************
     
    110109}
    111110
    112 // XXX are these private or public?
    113111// psSort comparison function for peaks
    114 int pmComparePeakAscend (const void **a, const void **b)
     112int pmPeaksCompareAscend (const void **a, const void **b)
    115113{
    116114    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
     
    133131
    134132// psSort comparison function for peaks
    135 int pmComparePeakDescend (const void **a, const void **b)
     133int pmPeaksCompareDescend (const void **a, const void **b)
    136134{
    137135    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
  • branches/rel10_ifa/psModules/src/objects/pmPeaks.h

    r6537 r6556  
    1010 *  @author GLG, MHPCC
    1111 *
    12  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-03-07 06:33:35 $
     12 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-03-09 03:14:23 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    138138);
    139139
     140int pmPeaksCompareAscend (const void **a, const void **b);
     141int pmPeaksCompareDescend (const void **a, const void **b);
     142
    140143# endif /* PM_PEAKS_H */
  • branches/rel10_ifa/psModules/src/objects/pmSource.c

    r6537 r6556  
    1 /** @file  pmObjects.c
     1/** @file  pmSource.c
    22 *
    3  *  This file will ...
     3 *  Functions to define and manipulate sources on images
    44 *
    55 *  @author GLG, MHPCC
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-03-07 06:33:35 $
     8 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-03-09 03:14:23 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717#include <string.h>
    1818#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"
    2125
    2226static void sourceFree(pmSource *tmp)
     
    5054    tmp->modelPSF = NULL;
    5155    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;
    5458    psMemSetDeallocator(tmp, (psFreeFunc) sourceFree);
    5559
     
    219223
    220224        // XXX EAM : this lets us takes the single highest peak
    221         psArraySort (peaks, pmComparePeakDescend);
     225        psArraySort (peaks, pmPeaksCompareDescend);
    222226        clump = peaks->data[0];
    223227        psTrace (".pmObjects.pmSourceRoughClass", 2, "clump is at %d, %d (%f)\n", clump->x, clump->y, clump->counts);
     
    331335        // inner = psRegionForSquare (tmpSrc->peak->x - tmpSrc->mask->col0, tmpSrc->peak->y - tmpSrc->mask->row0, 2);
    332336        inner = psRegionForSquare (tmpSrc->peak->x, tmpSrc->peak->y, 2);
    333         int Nsatpix = psImageCountPixelMask (tmpSrc->mask, inner, PSPHOT_MASK_SATURATED);
     337        int Nsatpix = psImageCountPixelMask (tmpSrc->mask, inner, PM_SOURCE_MASK_SATURATED);
    334338
    335339        // saturated star (size consistent with PSF or larger)
     
    338342        big = true;
    339343        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;
    342346            Nsatstar ++;
    343347            continue;
     
    346350        // saturated object (not a star, eg bleed trails, hot pixels)
    347351        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;
    350354            Nsat ++;
    351355            continue;
     
    356360        // only set candidate defects if
    357361        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;
    360364            Ncr ++;
    361365            continue;
     
    364368        // likely unsaturated extended source (too large to be stellar)
    365369        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;
    368372            Next ++;
    369373            continue;
     
    378382        psF32 radius = hypot ((sigX-clump.X)/clump.dX, (sigY-clump.Y)/clump.dY);
    379383        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;
    382386            Npsf ++;
    383387            continue;
     
    385389
    386390        // 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;
    389393    }
    390394
     
    409413}
    410414
     415/******************************************************************************
     416pmSourceMoments(source, radius): this function takes a subImage defined in the
     417pmSource data structure, along with the peak location, and determines the
     418various moments associated with that peak.
     419 
     420Requires the following to have been created:
     421    pmSource
     422    pmSource->peak
     423    pmSource->pixels
     424    pmSource->weight
     425    pmSource->mask
     426 
     427XXX: The peak calculations are done in image coords, not subImage coords.
     428 
     429XXX EAM : this version clips input pixels on S/N
     430XXX 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
     434bool 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
     590pmModel *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  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-07 06:33:35 $
     5 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-03-09 03:14:23 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8181    pmSourceMode mode;   ///< Best identification of object.
    8282    psArray *blends;
    83     float fitMag;
     83    float psfMag;
     84    float extMag;
     85    float errMag;
    8486    float apMag;
    8587    psRegion region;   // area on image covered by selected pixels
     
    125127 *
    126128 */
    127 // XXX: Uncommenting the pmReadout causes compile errors.
    128129bool 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
     137bool 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);
    138144
    139145/** pmSourcePSFClump()
     
    188194
    189195
     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 */
     206bool 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
     213pmModel *pmSourceSelectModel (pmSource *source);
     214
    190215# 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"
    226
    327/******************************************************************************
  • branches/rel10_ifa/psModules/src/objects/pmSourceContour.h

    r6537 r6556  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-07 06:33:35 $
     5 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-03-09 03:14:23 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1313# define PM_SOURCE_CONTOUR_H
    1414
    15 psArray *pmSourceContour (psImage *image, int xc, int yc, float threshold)
    16 {
     15psArray *pmSourceContour (psImage *image, int xc, int yc, float threshold);
    1716
    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     );
    3617
    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 */
     31psArray *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  pmObjects.c
     1/** @file  pmSourceFitModel.c
    22 *
    3  *  This file will ...
     3 *  fit single source models to image pixels
    44 *
     5 *  @author EAM, IfA
    56 *  @author GLG, MHPCC
    6  *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-03-07 06:33:35 $
     8 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-03-09 03:14:23 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717#include <string.h>
    1818#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"
    2027#include "pmModelGroup.h"
     28#include "pmSourceFitModel.h"
    2129
    2230// save a static values so they may be set externally
     
    169177    }
    170178
    171     source->mode |= PM_SOURCE_FITTED;
     179    source->mode |= PM_SOURCE_MODE_FITTED;
    172180
    173181    psFree(x);
     
    186194    return(rc);
    187195}
    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 new
    206     pmModel structure based on the given modelType specified in the argument list. 
    207     The corresponding pmModelGuess function is returned, and used to
    208     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 in
    211     image, not subImage coords.  Therefore, the calls to the model evaluation
    212     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  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-07 06:33:35 $
     5 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-03-09 03:14:23 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3333);
    3434
    35 
    36 pmModel *pmSourceSelectModel (pmSource *source);
    37 
    38 /** pmSourceModelGuess()
    39  *
    40  * Convert available data to an initial guess for the given model. This
    41  * function allocates a pmModel entry for the pmSource structure based on the
    42  * provided model selection. The method of defining the model parameter guesses
    43  * are specified for each model below. The guess values are placed in the model
    44  * parameters. The function returns TRUE on success or FALSE on failure.
    45  *
    46  */
    47 pmModel *pmSourceModelGuess(
    48     pmSource *source,   ///< The input pmSource
    49     pmModelType model   ///< The type of model to be created.
    50 );
    51 
    5235# endif /* PM_SOURCE_FIT_MODEL_H */
  • branches/rel10_ifa/psModules/src/objects/pmSourceFitSet.c

    r6537 r6556  
    1 /** @file  pmSourceFitSet.h
     1/** @file  pmSourceFitSet.c
    22 *
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-07 06:33:35 $
     5 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-03-09 03:14:23 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1010 */
    1111
     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
    1227// sky, p1.1, p1.2, p1.3,... p1.n, p2.1, p2.2,
    1328// nPar = nSrc*(nOnePar - 1) + 1
    14 
    15 # include <stdio.h>
    16 # include <math.h>
    17 # include <pslib.h>
    18 # include "pmSource.h"
    1929
    2030static pmModelFunc mFunc;
     
    110120
    111121    // set the static variables
    112     pmSourceFitSetInit (model->type);
     122    pmModelFitSetInit (model->type);
    113123
    114124    int nSrc = modelSet->n;
     
    272282    }
    273283
    274     source->mode |= PM_SOURCE_FITTED;
     284    source->mode |= PM_SOURCE_MODE_FITTED;
    275285
    276286    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"
    126
    227// translations between psphot object types and dophot object types
     
    631    switch (source->type) {
    732
    8     case PM_SOURCE_DEFECT:
    9     case PM_SOURCE_SATURATED:
     33    case PM_SOURCE_TYPE_DEFECT:
     34    case PM_SOURCE_TYPE_SATURATED:
    1035        return (8);
    1136
    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)
    1439            return (10);
    15         if (source->mode & PM_SOURCE_POOR)
     40        if (source->mode & PM_SOURCE_MODE_POOR)
    1641            return (7);
    17         if (source->mode & PM_SOURCE_FAIL)
     42        if (source->mode & PM_SOURCE_MODE_FAIL)
    1843            return (4);
    1944        return (1);
    2045
    21     case PM_SOURCE_EXTENDED:
     46    case PM_SOURCE_TYPE_EXTENDED:
    2247        return (2);
    2348
     
    2954
    3055/***** Text Output Methods *****/
    31 
    32 bool pmSourcesWriteText (psArray *sources, char *filename)
     56# if (0)
     57    bool pmSourcesWriteText (psArray *sources, char *filename)
    3358{
    3459
     
    5075    return true;
    5176}
    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"
    227
    328// elixir-style FITS table output (header + table in 1st extension)
     
    1237    int i, type;
    1338    psF32 *PAR, *dPAR;
    14     float dmag, lsky;
     39    float lsky;
    1540    bool status;
     41    EllipseShape shape;
     42    EllipseAxes axes;
    1643
    1744    // find config information for output header
     
    2350    for (i = 0; i < sources->n; i++) {
    2451        pmSource *source = (pmSource *) sources->data[i];
    25         pmModel *model = pmModelSelect (source);
     52        pmModel *model = pmSourceSelectModel (source);
    2653        if (model == NULL)
    2754            continue;
     
    3057        dPAR = model->dparams->data.F32;
    3158
    32         dmag = dPAR[1] / PAR[1];
    3359        type = pmSourceDophotType (source);
    3460        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);
    3566
    3667        row = psMetadataAlloc ();
    3768        psMetadataAdd (row, PS_LIST_TAIL, "X_PIX",   PS_DATA_F32, "", PAR[2]);
    3869        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));
    4374        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);
    4879        psMetadataAdd (row, PS_LIST_TAIL, "DUMMY",   PS_DATA_STRING, "", "123");
    4980
     
    6293
    6394// read in a readout from the fits file
    64 psArray *pmReadoutReadCMF (psFits *fits, psMetadata *header)
     95psArray *pmSourcesReadCMF (psFits *fits, psMetadata *header)
    6596{
    6697
    6798    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    }
    68111
    69112    // find config information for output header
    70113    float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT");
     114    if (!status)
     115        ZERO_POINT = 25.0;
    71116
    72117    psArray *table = psFitsReadTable (fits);
     
    76121
    77122    // convert the table to the pmSource entries
     123    // XXX need to chooose PSF vs EXT, based on type?
    78124    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;
    80131
    81132        psMetadata *row = table->data[i];
    82133
    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");
    87151        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");
    93152
    94153        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"
    228
    329// elixir-style pseudo FITS table (header + ascii list)
     
    1036    float dmag, lsky;
    1137    bool status;
     38    EllipseShape shape;
     39    EllipseAxes axes;
    1240
    1341    // find config information for output header
     
    1947    for (i = nSrc = 0; i < sources->n; i++) {
    2048        pmSource *source = (pmSource *) sources->data[i];
    21         pmModel *model = pmModelSelect (source);
     49        pmModel *model = pmSourceSelectModel (source);
    2250        if (model == NULL)
    2351            continue;
     
    4977    for (i = 0; i < sources->n; i++) {
    5078        pmSource *source = (pmSource *) sources->data[i];
    51         pmModel *model = pmModelSelect (source);
     79        pmModel *model = pmSourceSelectModel (source);
    5280        if (model == NULL)
    5381            continue;
     
    5684        dPAR = model->dparams->data.F32;
    5785
    58         dmag = dPAR[1] / PAR[1];
    5986        type = pmSourceDophotType (source);
    6087        lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]);
    6188
     89        shape.sx  = PAR[4];
     90        shape.sy  = PAR[5];
     91        shape.sxy = PAR[6];
     92        axes = EllipseShapeToAxes (shape);
     93
    6294        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 'Mgal
    70         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 theta
     95        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);
    74106        fwrite (line->line, 1, line->Nline, f);
    75107    }
     
    82114
    83115// elixir-style pseudo FITS table (header + ascii list)
    84 psArray *sources pmSourcesReadCMP (char *filename, psMetadata *header)
     116psArray *pmSourcesReadCMP (char *filename, psMetadata *header)
    85117{
    86118
    87     int i, type, nSrc;
    88     psMetadataItem *mdi;
     119    int Ninstar;
    89120    psF32 *PAR, *dPAR;
    90     float dmag, lsky;
    91121    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    }
    92132
    93133    // find config information for output header
     
    113153
    114154    // prepare array to store data
    115     int nStars = psMetadataLookupS32 (&status, myHeader, "NSTARS");
     155    int nStars = psMetadataLookupS32 (&status, header, "NSTARS");
    116156    psArray *sources = psArrayAlloc (nStars);
    117157    sources->n = 0;
    118158
    119159    // we have fixed bytes / line : use that info
    120     char *buffer = psAlloc (NBYTES_STAR*nStars);
     160    char *buffer = psAlloc (BYTES_STAR*nStars);
    121161
    122162    int Nextra = 0;
     
    161201
    162202        /* extract data for stars */
    163         int Ninstar = nbytes / BYTES_STAR;
     203        Ninstar = nbytes / BYTES_STAR;
    164204        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);
    167207            psList *list = psStringSplit (line, " ");
    168208            psArray *array = psListToArray (list);
    169209
    170210            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;
    179223            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]);
    183235
    184236            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"
    228
    329// dophot-style output list with fixed line width
     
    834    psF32 *PAR, *dPAR;
    935    float dmag, apResid;
     36    EllipseShape shape;
     37    EllipseAxes axes;
    1038
    1139    psTimerStart ("string");
     
    2250    for (int i = 0; i < sources->n; i++) {
    2351        pmSource *source = (pmSource *) sources->data[i];
    24         pmModel *model = pmModelSelect (source);
     52        pmModel *model = pmSourceSelectModel (source);
    2553        if (model == NULL)
    2654            continue;
     
    3159        dmag = dPAR[1] / PAR[1];
    3260        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);
    3471
    3572        psLineInit (line);
     
    3774        psLineAdd (line, "%8.2f", PAR[2]);
    3875        psLineAdd (line, "%8.2f", PAR[3]);
    39         psLineAdd (line, "%8.3f", source->fitMag);
     76        psLineAdd (line, "%8.3f", source->psfMag);
    4077        psLineAdd (line, "%6.3f", dmag);
    4178        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);
    4683        psLineAdd (line, "%8.3f", source->apMag);
    4784        psLineAdd (line, "%8.2f\n", apResid);
     
    5087    fclose (f);
    5188    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);
    9690    return true;
    9791}
    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"
    228
    329// elixir-mode / sextractor-style output list with fixed line width
     
    632
    733    psF32 *PAR, *dPAR;
    8     float dmag;
     34    EllipseShape shape;
     35    EllipseAxes axes;
    936
    1037    psLine *line = psLineAlloc (110);  // 110 is sextractor line length
     
    1946    for (int i = 0; i < sources->n; i++) {
    2047        pmSource *source = (pmSource *) sources->data[i];
    21         pmModel *model = pmModelSelect (source);
     48        pmModel *model = pmSourceSelectModel (source);
    2249        if (model == NULL)
    2350            continue;
     
    2855        // pmSourceSextractType (source, &type, &flags);
    2956
    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);
    3161
    3262        psLineInit (line);
    33         psLineAdd (line, "%5.2f", 0.0); // should be type
     63        psLineAdd (line, "%5.2f",  0.0); // should be type
    3464        psLineAdd (line, "%11.3f", PAR[2]);
    3565        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);
    3868        psLineAdd (line, "%13.4f", PAR[0]);
    39         psLineAdd (line, "%9.2f", 0.0); // should be FWHMx
    40         psLineAdd (line, "%9.2f", 0.0); // should be FWHMy
    41         psLineAdd (line, "%6.1f", 0.0); // should be Theta
    42         psLineAdd (line, "%9.4f", 99.999); // should be MAG_ISO
    43         psLineAdd (line, "%9.4f", source->apMag);
    44         psLineAdd (line, "%4d\n", 0); // should be flags
     69        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
    4575        fwrite (line->line, 1, line->Nline, f);
    4676    }
  • branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c

    r6537 r6556  
    1 /** @file  pmSourcePhotometry.C
     1/** @file  pmSourcePhotometry.c
    22 *
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-07 06:33:35 $
     5 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-03-09 03:14:23 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1010 */
    1111
    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
     27static float AP_MIN_SN = 0.0;
     28
     29bool 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
    1455// XXX EAM : masked region should be (optionally) elliptical
     56// XXX curve of growth is corrected to
    1557pmModel *pmSourceMagnitudes (pmSource *source, pmPSF *psf, float apRadius)
    1658{
     
    2163    float rflux;
    2264    float radius;
     65    float SN;
    2366    pmModel *model;
    2467
    2568    switch (source->type) {
    26     case PM_SOURCE_STAR:
     69    case PM_SOURCE_TYPE_STAR:
    2770        model = source->modelPSF;
    2871        if (model == NULL)
     
    3275        break;
    3376
    34     case PM_SOURCE_EXTENDED:
     77    case PM_SOURCE_TYPE_EXTENDED:
    3578        model = source->modelEXT;
    3679        if (model == NULL)
     
    4487    }
    4588
     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    }
    4696    x = model->params->data.F32[2];
    4797    y = model->params->data.F32[3];
    4898
    4999    // replace source flux
     100    // XXX test to see if source has been subtracted?
    50101    pmModelAdd (source->pixels, source->mask, model, false, false);
    51102
    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
    59118    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);
    67127    }
    68128
    69129    // 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);
    71131
    72132    // subtract object, leave local sky
     
    85145*/
    86146
    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
     148bool 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
     171bool 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)
    89201{
    90202
     
    96208    *obsMag = 99.0;
    97209
     210    // measure fitMag
    98211    pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
    99212    fitSum = modelFluxFunc (model->params);
     
    104217    *fitMag = -2.5*log10(fitSum);
    105218
     219    // measure apMag
    106220    for (int ix = 0; ix < image->numCols; ix++) {
    107221        for (int iy = 0; iy < image->numRows; iy++) {
     
    117231    return (true);
    118232}
     233# endif
    119234
    120235float pmSourceCrossProduct (pmSource *Mi, pmSource *Mj)
  • branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.h

    r6537 r6556  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-07 06:33:35 $
     5 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-03-09 03:14:23 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2525 *
    2626 */
    27 bool pmSourcePhotometry(
     27bool pmSourcePhotometryModel(
    2828    float *fitMag,                      ///< integrated fit magnitude
    29     float *obsMag,   ///< aperture flux magnitude
     29    pmModel *model                      ///< model used for photometry
     30);
     31
     32bool pmSourcePhotometryAper(
     33    float *apMag,                       ///< aperture flux magnitude
    3034    pmModel *model,                     ///< model used for photometry
    3135    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"
    126
    227/******************************************************************************
    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
     28pmSource *pmSourceLocalSky(source, statsOptions, Radius): this
     29routine creates a new pmSource.moments element if needed and sets pmSource.pmMoments.sky
    730 
    831The sky value is set from the pixels in the square annulus surrounding the
    932peak pixel.
    1033 
    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.
     34The source.pixels and source.mask must already exist
    3935*****************************************************************************/
    4036
     
    6056    srcRegion = psRegionForImage(mask, srcRegion);
    6157
    62     psImageMaskRegion(mask, srcRegion, "OR", PSPHOT_MASK_MARKED);
     58    psImageMaskRegion(mask, srcRegion, "OR", PM_SOURCE_MASK_MARKED);
    6359    psStats *myStats = psStatsAlloc(statsOptions);
    6460    myStats = psImageStats(myStats, image, mask, 0xff);
    65     psImageMaskRegion(mask, srcRegion, "AND", ~PSPHOT_MASK_MARKED);
     61    psImageMaskRegion(mask, srcRegion, "AND", ~PM_SOURCE_MASK_MARKED);
    6662
    6763    psF64 tmpF64;
     
    10399    srcRegion = psRegionForImage(mask, srcRegion);
    104100
    105     psImageMaskRegion(mask, srcRegion, "OR", PSPHOT_MASK_MARKED);
     101    psImageMaskRegion(mask, srcRegion, "OR", PM_SOURCE_MASK_MARKED);
    106102    psStats *myStats = psStatsAlloc(statsOptions);
    107103    myStats = psImageStats(myStats, image, mask, 0xff);
    108     psImageMaskRegion(mask, srcRegion, "AND", ~PSPHOT_MASK_MARKED);
     104    psImageMaskRegion(mask, srcRegion, "AND", ~PM_SOURCE_MASK_MARKED);
    109105
    110106    psF64 tmpF64;
Note: See TracChangeset for help on using the changeset viewer.