IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5844


Ignore:
Timestamp:
Dec 23, 2005, 3:24:38 PM (20 years ago)
Author:
desonia
Message:

changes from eam_rel9_b1

Location:
trunk/psModules
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/Makefile.am

    r5765 r5844  
    1515        models/pmModel_QGAUSS.c \
    1616        models/pmModel_SGAUSS.c
    17    
     17
    1818psmoduleincludedir = $(includedir)
    1919psmoduleinclude_HEADERS = \
  • trunk/psModules/src/objects/pmModelGroup.c

    r5255 r5844  
    1010#include "models/pmModel_SGAUSS.c"
    1111
    12 static pmModelGroup models[] = {
    13                                    {"PS_MODEL_GAUSS",        7, pmModelFunc_GAUSS,   pmModelFlux_GAUSS,   pmModelRadius_GAUSS,   pmModelLimits_GAUSS,   pmModelGuess_GAUSS,  pmModelFromPSF_GAUSS,  pmModelFitStatus_GAUSS},
    14                                    {"PS_MODEL_PGAUSS",       7, pmModelFunc_PGAUSS,  pmModelFlux_PGAUSS,  pmModelRadius_PGAUSS,  pmModelLimits_PGAUSS,  pmModelGuess_PGAUSS, pmModelFromPSF_PGAUSS, pmModelFitStatus_PGAUSS},
    15                                    {"PS_MODEL_QGAUSS",       8, pmModelFunc_QGAUSS,  pmModelFlux_QGAUSS,  pmModelRadius_QGAUSS,  pmModelLimits_QGAUSS,  pmModelGuess_QGAUSS, pmModelFromPSF_QGAUSS, pmModelFitStatus_QGAUSS},
    16                                    {"PS_MODEL_SGAUSS",       9, pmModelFunc_SGAUSS,  pmModelFlux_SGAUSS,  pmModelRadius_SGAUSS,  pmModelLimits_SGAUSS,  pmModelGuess_SGAUSS, pmModelFromPSF_SGAUSS, pmModelFitStatus_SGAUSS},
    17                                };
     12static pmModelGroup defaultModels[] = {
     13                                          {"PS_MODEL_GAUSS",        7, pmModelFunc_GAUSS,   pmModelFlux_GAUSS,   pmModelRadius_GAUSS,   pmModelLimits_GAUSS,   pmModelGuess_GAUSS,  pmModelFromPSF_GAUSS,  pmModelFitStatus_GAUSS},
     14                                          {"PS_MODEL_PGAUSS",       7, pmModelFunc_PGAUSS,  pmModelFlux_PGAUSS,  pmModelRadius_PGAUSS,  pmModelLimits_PGAUSS,  pmModelGuess_PGAUSS, pmModelFromPSF_PGAUSS, pmModelFitStatus_PGAUSS},
     15                                          {"PS_MODEL_QGAUSS",       8, pmModelFunc_QGAUSS,  pmModelFlux_QGAUSS,  pmModelRadius_QGAUSS,  pmModelLimits_QGAUSS,  pmModelGuess_QGAUSS, pmModelFromPSF_QGAUSS, pmModelFitStatus_QGAUSS},
     16                                          {"PS_MODEL_SGAUSS",       9, pmModelFunc_SGAUSS,  pmModelFlux_SGAUSS,  pmModelRadius_SGAUSS,  pmModelLimits_SGAUSS,  pmModelGuess_SGAUSS, pmModelFromPSF_SGAUSS, pmModelFitStatus_SGAUSS},
     17                                      };
     18
     19static pmModelGroup *models = NULL;
     20static int Nmodels = 0;
     21
     22static void ModelGroupFree (pmModelGroup *modelGroup)
     23{
     24
     25    if (modelGroup == NULL)
     26        return;
     27    psFree (modelGroup);
     28    return;
     29}
     30
     31pmModelGroup *pmModelGroupAlloc (int nModels)
     32{
     33
     34    pmModelGroup *modelGroup = (pmModelGroup *) psAlloc (nModels * sizeof(pmModelGroup));
     35    psMemSetDeallocator(modelGroup, (psFreeFunc) ModelGroupFree);
     36    return (modelGroup);
     37}
     38
     39void pmModelGroupAdd (pmModelGroup *model)
     40{
     41
     42    if (models == NULL) {
     43        pmModelGroupInit ();
     44    }
     45
     46    Nmodels ++;
     47    models = (pmModelGroup *) psRealloc (models, Nmodels*sizeof(pmModelGroup));
     48    models[Nmodels-1] = model[0];
     49    return;
     50}
     51
     52void pmModelGroupInit (void)
     53{
     54
     55    int Nnew = sizeof (defaultModels) / sizeof (pmModelGroup);
     56
     57    models = pmModelGroupAlloc (Nnew);
     58    for (int i = 0; i < Nnew; i++) {
     59        models[i] = defaultModels[i];
     60    }
     61    Nmodels = Nnew;
     62    return;
     63}
    1864
    1965pmModelFunc pmModelFunc_GetFunction (pmModelType type)
    2066{
    21     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    2267    if ((type < 0) || (type >= Nmodels)) {
    2368        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    2974pmModelFlux pmModelFlux_GetFunction (pmModelType type)
    3075{
    31     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    3276    if ((type < 0) || (type >= Nmodels)) {
    3377        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    3983pmModelRadius pmModelRadius_GetFunction (pmModelType type)
    4084{
    41     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    4285    if ((type < 0) || (type >= Nmodels)) {
    4386        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    4992pmModelLimits pmModelLimits_GetFunction (pmModelType type)
    5093{
    51     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    5294    if ((type < 0) || (type >= Nmodels)) {
    5395        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    59101pmModelGuessFunc pmModelGuessFunc_GetFunction (pmModelType type)
    60102{
    61     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    62103    if ((type < 0) || (type >= Nmodels)) {
    63104        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    69110pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type)
    70111{
    71     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    72112    if ((type < 0) || (type >= Nmodels)) {
    73113        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    79119pmModelFromPSFFunc pmModelFromPSFFunc_GetFunction (pmModelType type)
    80120{
    81     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    82121    if ((type < 0) || (type >= Nmodels)) {
    83122        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    89128psS32 pmModelParameterCount (pmModelType type)
    90129{
    91     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    92130    if ((type < 0) || (type >= Nmodels)) {
    93131        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    99137psS32 pmModelSetType (char *name)
    100138{
    101 
    102     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    103139    for (int i = 0; i < Nmodels; i++) {
    104140        if (!strcmp(models[i].name, name)) {
     
    111147char *pmModelGetType (pmModelType type)
    112148{
    113 
    114     int Nmodels = sizeof (models) / sizeof (pmModelGroup);
    115149    if ((type < 0) || (type >= Nmodels)) {
    116150        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
  • trunk/psModules/src/objects/pmModelGroup.h

    r5255 r5844  
    99 *  @author EAM, IfA
    1010 *
    11  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-10-10 19:53:40 $
     11 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-12-24 01:24:32 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    209209pmModelGroup;
    210210
     211// allocate a pmModelGroup to hold nModels entries
     212pmModelGroup *pmModelGroupAlloc (int nModels);
     213
     214// initialize the internal (static) model group with the default models
     215void pmModelGroupInit (void);
     216
     217// add a new model to the internal (static) model group
     218void pmModelGroupAdd (pmModelGroup *model);
     219
    211220# endif
  • trunk/psModules/src/objects/pmObjects.c

    r5765 r5844  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-12-12 21:14:38 $
     8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-12-24 01:24:32 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8585psVector containing the specified row of data from the psImage.
    8686 
    87 XXX: Is there a better way to do this? 
     87XXX: Is there a better way to do this?
    8888XXX EAM: does this really need to alloc a new vector???
    8989*****************************************************************************/
     
    271271    tmp->chisq = 0.0;
    272272    tmp->nIter = 0;
     273    tmp->radius = 0;
     274    tmp->status = PM_MODEL_UNTRIED;
     275
    273276    psS32 Nparams = pmModelParameterCount(type);
    274277    if (Nparams == 0) {
     
    850853    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
    851854        for (psS32 col = 0; col < source->pixels->numCols ; col++) {
    852             if ((source->mask != NULL) && (source->mask->data.U8[row][col]))
     855            if ((source->mask != NULL) && (source->mask->data.U8[row][col])) {
    853856                continue;
     857            }
    854858
    855859            psF32 xDiff = col + source->pixels->col0 - xPeak;
     
    858862            // XXX EAM : calculate xDiff, yDiff up front;
    859863            //           radius is just a function of (xDiff, yDiff)
    860             if (!VALID_RADIUS(xDiff, yDiff, R2))
     864            if (!VALID_RADIUS(xDiff, yDiff, R2)) {
    861865                continue;
     866            }
    862867
    863868            psF32 pDiff = source->pixels->data.F32[row][col] - sky;
     
    865870            // XXX EAM : check for valid S/N in pixel
    866871            // XXX EAM : should this limit be user-defined?
    867             if (pDiff / sqrt(source->weight->data.F32[row][col]) < 1)
     872            if (pDiff / sqrt(source->weight->data.F32[row][col]) < 1) {
    868873                continue;
     874            }
    869875
    870876            Sum += pDiff;
     
    970976
    971977/******************************************************************************
    972 pmSourcePSFClump(source, metadata): Find the likely PSF clump in the 
    973 sigma-x, sigma-y plane. return 0,0 clump in case of error. 
     978pmSourcePSFClump(source, metadata): Find the likely PSF clump in the
     979sigma-x, sigma-y plane. return 0,0 clump in case of error.
    974980*****************************************************************************/
    975981
     
    9941000        psImage *splane = NULL;
    9951001        int binX, binY;
     1002        bool status;
     1003
     1004        psF32 SX_MAX = psMetadataLookupF32 (&status, metadata, "MOMENTS_SX_MAX");
     1005        if (!status)
     1006            SX_MAX = 10.0;
     1007        psF32 SY_MAX = psMetadataLookupF32 (&status, metadata, "MOMENTS_SY_MAX");
     1008        if (!status)
     1009            SY_MAX = 10.0;
    9961010
    9971011        // construct a sigma-plane image
    9981012        // psImageAlloc does zero the data
    999         splane = psImageAlloc (NPIX/SCALE, NPIX/SCALE, PS_TYPE_F32);
     1013        splane = psImageAlloc (SX_MAX/SCALE, SY_MAX/SCALE, PS_TYPE_F32);
    10001014        for (int i = 0; i < splane->numRows; i++)
    10011015        {
     
    11311145XXX: How can this function ever return FALSE?
    11321146 
    1133 XXX EAM : add the saturated mask value to metadata 
     1147XXX EAM : add the saturated mask value to metadata
    11341148*****************************************************************************/
    11351149
     
    11461160    int Ncr      = 0;
    11471161    int Nsatstar = 0;
     1162    psRegion allArray = psRegionSet (0, 0, 0, 0);
    11481163
    11491164    psVector *starsn = psVectorAlloc (sources->n, PS_TYPE_F32);
     
    11771192
    11781193        // XXX EAM : can we use the value of SATURATE if mask is NULL?
    1179         //
    1180         // XXX: Must verify this region (the region argument was added to psImageCountPixelMask()
    1181         // after EAM wrote this code.
    1182         //
    1183         psRegion tmpRegion = psRegionSet(0, tmpSrc->mask->numCols, 0, tmpSrc->mask->numRows);
    1184         int Nsatpix = psImageCountPixelMask(tmpSrc->mask, tmpRegion, PSPHOT_MASK_SATURATED);
     1194        int Nsatpix = psImageCountPixelMask (tmpSrc->mask, allArray, PSPHOT_MASK_SATURATED);
    11851195
    11861196        // saturated star (size consistent with PSF or larger)
     
    12541264
    12551265/** pmSourceDefinePixels()
    1256  * 
     1266 *
    12571267 * Define psImage subarrays for the source located at coordinates x,y on the
    12581268 * image set defined by readout. The pixels defined by this operation consist of
     
    12661276 * example). This function should be used to define a region of interest around a
    12671277 * source, including both source and sky pixels.
    1268  * 
     1278 *
    12691279 * XXX: must code this.
    1270  * 
     1280 *
    12711281 */
    12721282bool pmSourceDefinePixels(
     
    13601370/******************************************************************************
    13611371pmSourceModelGuess(source, model): This function allocates a new
    1362 pmModel structure based on the given modelType specified in the argument list. 
    1363 The corresponding pmModelGuess function is returned, and used to 
    1364 supply the values of the params array in the pmModel structure. 
     1372pmModel structure based on the given modelType specified in the argument list.
     1373The corresponding pmModelGuess function is returned, and used to
     1374supply the values of the params array in the pmModel structure.
    13651375 
    13661376XXX: Many parameters are based on the src->moments structure, which is in
     
    15981608        psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n");
    15991609        psTrace(__func__, 3, "---- %s(false) end ----\n", __func__);
     1610        model->status = PM_MODEL_BADARGS;
    16001611        return(false);
    16011612    }
     
    16491660    }
    16501661
    1651     // XXX EAM: we need to do something (give an error?) if rc is false
    1652     // XXX EAM: psMinimizeLMChi2 does not check convergence
    1653 
    1654     // XXX models can go insane: reject these
    1655     onPic &= (params->data.F32[2] >= source->pixels->col0);
    1656     onPic &= (params->data.F32[2] <  source->pixels->col0 + source->pixels->numCols);
    1657     onPic &= (params->data.F32[3] >= source->pixels->row0);
    1658     onPic &= (params->data.F32[3] <  source->pixels->row0 + source->pixels->numRows);
    1659 
    1660     // XXX EAM: save the resulting chisq, nDOF, nIter
     1662    // save the resulting chisq, nDOF, nIter
    16611663    model->chisq = myMin->value;
    16621664    model->nIter = myMin->iter;
    16631665    model->nDOF  = y->n - nParams;
    16641666
    1665     // XXX EAM get the Gauss-Newton distance for fixed model parameters
     1667    // get the Gauss-Newton distance for fixed model parameters
    16661668    if (paramMask != NULL) {
    16671669        psVector *delta = psVectorAlloc (params->n, PS_TYPE_F64);
     
    16731675        }
    16741676        psFree (delta);
     1677    }
     1678
     1679    // set the model success or failure status
     1680    if (!fitStatus) {
     1681        model->status = PM_MODEL_NONCONVERGE;
     1682    } else {
     1683        model->status = PM_MODEL_SUCCESS;
     1684    }
     1685
     1686    // models can go insane: reject these
     1687    onPic &= (params->data.F32[2] >= source->pixels->col0);
     1688    onPic &= (params->data.F32[2] <  source->pixels->col0 + source->pixels->numCols);
     1689    onPic &= (params->data.F32[3] >= source->pixels->row0);
     1690    onPic &= (params->data.F32[3] <  source->pixels->row0 + source->pixels->numRows);
     1691    if (!onPic) {
     1692        model->status = PM_MODEL_OFFIMAGE;
    16751693    }
    16761694
     
    17321750        psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n");
    17331751        psTrace(__func__, 3, "---- %s(false) end ----\n", __func__);
     1752        model->status = PM_MODEL_BADARGS;
    17341753        return(false);
    17351754    }
     
    18101829    // XXX EAM: psMinimizeLMChi2 does not check convergence
    18111830
    1812     // XXX models can go insane: reject these
    1813     onPic &= (params->data.F32[2] >= source->pixels->col0);
    1814     onPic &= (params->data.F32[2] <  source->pixels->col0 + source->pixels->numCols);
    1815     onPic &= (params->data.F32[3] >= source->pixels->row0);
    1816     onPic &= (params->data.F32[3] <  source->pixels->row0 + source->pixels->numRows);
    1817 
    18181831    // XXX EAM: save the resulting chisq, nDOF, nIter
    18191832    model->chisq = myMin->value;
     
    18321845    }
    18331846
    1834     psFree(paramMask);
     1847    // set the model success or failure status
     1848    if (!fitStatus) {
     1849        model->status = PM_MODEL_NONCONVERGE;
     1850    } else {
     1851        model->status = PM_MODEL_SUCCESS;
     1852    }
     1853
     1854    // XXX models can go insane: reject these
     1855    onPic &= (params->data.F32[2] >= source->pixels->col0);
     1856    onPic &= (params->data.F32[2] <  source->pixels->col0 + source->pixels->numCols);
     1857    onPic &= (params->data.F32[3] >= source->pixels->row0);
     1858    onPic &= (params->data.F32[3] <  source->pixels->row0 + source->pixels->numRows);
     1859    if (!onPic) {
     1860        model->status = PM_MODEL_OFFIMAGE;
     1861    }
     1862
    18351863    psFree(x);
    18361864    psFree(y);
     1865    psFree(yErr);
    18371866    psFree(myMin);
     1867    psFree(covar);
     1868    psFree(paramMask);
    18381869
    18391870    rc = (onPic && fitStatus);
     
    18461877                             pmModel *model,
    18471878                             bool center,
    1848                              psS32 flag)
     1879                             bool sky,
     1880                             bool add
     1881                                )
    18491882{
    18501883    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
     
    18591892    psS32 imageCol;
    18601893    psS32 imageRow;
     1894    psF32 skyValue = params->data.F32[0];
     1895    psF32 pixelValue;
    18611896
    18621897    for (psS32 i = 0; i < image->numRows; i++) {
     
    18641899            if ((mask != NULL) && mask->data.U8[i][j])
    18651900                continue;
    1866             psF32 pixelValue;
     1901
    18671902            // XXX: Should you be adding the pixels for the entire subImage,
    18681903            // or a radius of pixels around it?
     
    18821917            x->data.F32[0] = (float) imageCol;
    18831918            x->data.F32[1] = (float) imageRow;
    1884             pixelValue = modelFunc (NULL, params, x);
    1885             // fprintf (stderr, "%f %f  %d %d  %f\n", x->data.F32[0], x->data.F32[1], i, j, pixelValue);
    1886 
    1887             if (flag == 1) {
    1888                 pixelValue = -pixelValue;
    1889             }
    1890 
    1891             // XXX: Must figure out how to calculate the image coordinates and
    1892             // how to use the boolean "center" flag.
    1893 
    1894             image->data.F32[i][j]+= pixelValue;
     1919
     1920            // set the appropriate pixel value for this coordinate
     1921            if (sky) {
     1922                pixelValue = modelFunc (NULL, params, x);
     1923            } else {
     1924                pixelValue = modelFunc (NULL, params, x) - skyValue;
     1925            }
     1926
     1927
     1928            // add or subtract the value
     1929            if (add
     1930               ) {
     1931                image->data.F32[i][j] += pixelValue;
     1932            }
     1933            else {
     1934                image->data.F32[i][j] -= pixelValue;
     1935            }
    18951936        }
    18961937    }
     
    19071948                      psImage *mask,
    19081949                      pmModel *model,
    1909                       bool center)
    1910 {
    1911     psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
    1912     psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, 0);
     1950                      bool center,
     1951                      bool sky)
     1952{
     1953    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
     1954    psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, sky, true);
    19131955    psTrace(__func__, 3, "---- %s(%d) end ----\n", __func__, rc);
    19141956    return(rc);
     
    19201962                      psImage *mask,
    19211963                      pmModel *model,
    1922                       bool center)
    1923 {
    1924     psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
    1925     psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, 1);
     1964                      bool center,
     1965                      bool sky)
     1966{
     1967    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
     1968    psBool rc = p_pmSourceAddOrSubModel(image, mask, model, center, sky, false);
    19261969    psTrace(__func__, 3, "---- %s(%d) end ----\n", __func__, rc);
    19271970    return(rc);
  • trunk/psModules/src/objects/pmObjects.h

    r5765 r5844  
    44 * images is one of the critical tasks of the IPP or any astronomical software
    55 * system. This file will define structures and functions related to the task
    6  * of source detection and measurement. The elements defined in this section 
     6 * of source detection and measurement. The elements defined in this section
    77 * are generally low-level components which can be connected together to
    88 * construct a complete object measurement suite.
     
    1010 *  @author GLG, MHPCC
    1111 *
    12  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-12-12 21:14:38 $
     12 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-12-24 01:24:32 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4545
    4646/** pmPeakType
    47  * 
     47 *
    4848 *  A peak pixel may have several features which may be determined when the
    4949 *  peak is found or measured. These are specified by the pmPeakType enum.
     
    5252 *  edge. The PM_PEAK_FLAT represents a peak pixel which has more than a specific
    5353 *  number of neighbors at the same value, within some tolarence:
    54  * 
     54 *
    5555 */
    5656typedef enum {
     
    6363
    6464/** pmPeak data structure
    65  * 
     65 *
    6666 *  A source has the capacity for several types of measurements. The
    6767 *  simplest measurement of a source is the location and flux of the peak pixel
    6868 *  associated with the source:
    69  * 
     69 *
    7070 */
    7171typedef struct
     
    8080
    8181/** pmMoments data structure
    82  * 
     82 *
    8383 * One of the simplest measurements which can be made quickly for an object
    8484 * are the object moments. We specify a structure to carry the moment information
    8585 * for a specific source:
    86  * 
     86 *
    8787 */
    8888typedef struct
     
    103103
    104104/** pmPSFClump data structure
    105  * 
     105 *
    106106 * A collection of object moment measurements can be used to determine
    107107 * approximate object classes. The key to this analysis is the location and
    108108 * statistics (in the second-moment plane,
    109  * 
     109 *
    110110 */
    111111typedef struct
     
    118118pmPSFClump;
    119119
     120// type of model carried by the pmModel structure
    120121typedef int pmModelType;
    121 #define PS_MODEL_GAUSS 0
    122 #define PS_MODEL_PGAUSS 1
    123 #define PS_MODEL_QGAUSS 2
    124 #define PS_MODEL_SGAUSS 3
    125 
     122
     123typedef enum {
     124    PM_MODEL_UNTRIED,               ///< model fit not yet attempted
     125    PM_MODEL_SUCCESS,               ///< model fit succeeded
     126    PM_MODEL_NONCONVERGE,           ///< model fit did not converge
     127    PM_MODEL_OFFIMAGE,              ///< model fit drove out of range
     128    PM_MODEL_BADARGS                ///< model fit called with invalid args
     129} pmModelStatus;
    126130
    127131/** pmModel data structure
    128  * 
     132 *
    129133 * Every source may have two types of models: a PSF model and a FLT (floating)
    130134 * model. The PSF model represents the best fit of the image PSF to the specific
     
    132136 * object by the PSF, not by the fit. The FLT model represents the best fit of
    133137 * the given model to the object, with all parameters floating in the fit.
    134  * 
     138 *
    135139 */
    136140typedef struct
     
    142146    int nDOF;    ///< number of degrees of freedom
    143147    int nIter;    ///< number of iterations to reach min
     148    int status;         ///< fit status
    144149    float radius;   ///< fit radius actually used
    145150}
     
    147152
    148153/** pmSourceType enumeration
    149  * 
     154 *
    150155 * A given source may be identified as most-likely to be one of several source
    151156 * types. The pmSource entry pmSourceType defines the current best-guess for this
    152157 * source.
    153  * 
     158 *
    154159 * XXX: The values given below are currently illustrative and will require
    155160 * some modification as the source classification code is developed. (TBD)
    156  * 
     161 *
    157162 */
    158163typedef enum {
     
    178183
    179184/** pmSource data structure
    180  * 
     185 *
    181186 *  This source has the capacity for several types of measurements. The
    182187 *  simplest measurement of a source is the location and flux of the peak pixel
    183188 *  associated with the source:
    184  * 
     189 *
    185190 */
    186191typedef struct
     
    194199    pmModel *modelFLT;   ///< FLT (floating) Model fit (parameters and type).
    195200    pmSourceType type;   ///< Best identification of object.
     201    float apMag;
     202    float fitMag;
    196203}
    197204pmSource;
     
    211218
    212219/** pmMomentsAlloc()
    213  * 
     220 *
    214221 */
    215222pmMoments *pmMomentsAlloc();
     
    217224
    218225/** pmModelAlloc()
    219  * 
     226 *
    220227 */
    221228pmModel *pmModelAlloc(pmModelType type);
     
    223230
    224231/** pmSourceAlloc()
    225  * 
     232 *
    226233 */
    227234pmSource  *pmSourceAlloc();
     
    229236
    230237/** pmFindVectorPeaks()
    231  * 
     238 *
    232239 * Find all local peaks in the given vector above the given threshold. A peak
    233240 * is defined as any element with a value greater than its two neighbors and with
     
    243250 * a vector containing the coordinates (element number) of the detected peaks
    244251 * (type psU32).
    245  * 
     252 *
    246253 */
    247254psVector *pmFindVectorPeaks(
     
    252259
    253260/** pmFindImagePeaks()
    254  * 
     261 *
    255262 * Find all local peaks in the given image above the given threshold. This
    256263 * function should find all row peaks using pmFindVectorPeaks, then test each row
     
    263270 * peaks at the (+x,+y) corner. When selecting the peaks, their type must also be
    264271 * set. The result of this function is an array of pmPeak entries.
    265  * 
     272 *
    266273 */
    267274psArray *pmFindImagePeaks(
     
    272279
    273280/** pmCullPeaks()
    274  * 
     281 *
    275282 * Eliminate peaks from the psList that have a peak value above the given
    276283 * maximum, or fall outside the valid region.
    277  * 
     284 *
    278285 */
    279286psList *pmCullPeaks(
     
    285292
    286293/** pmPeaksSubset()
    287  * 
     294 *
    288295 * Create a new peaks array, removing certain types of peaks from the input
    289296 * array of peaks based on the given criteria. Peaks should be eliminated if they
     
    291298 * the valid region.  The result of the function is a new array with a reduced
    292299 * number of peaks.
    293  * 
     300 *
    294301 */
    295302psArray *pmPeaksSubset(
     
    301308
    302309/** pmSourceDefinePixels()
    303  * 
     310 *
    304311 * Define psImage subarrays for the source located at coordinates x,y on the
    305312 * image set defined by readout. The pixels defined by this operation consist of
     
    313320 * example). This function should be used to define a region of interest around a
    314321 * source, including both source and sky pixels.
    315  * 
     322 *
    316323 * XXX: must code this.
    317  * 
     324 *
    318325 */
    319326// XXX: Uncommenting the pmReadout causes compile errors.
     
    328335
    329336/** pmSourceLocalSky()
    330  * 
     337 *
    331338 * Measure the local sky in the vicinity of the given source. The Radius
    332339 * defines the square aperture in which the moments will be measured. This
     
    338345 * This function allocates the pmMoments structure. The resulting sky is used to
    339346 * set the value of the pmMoments.sky element of the provided pmSource structure.
    340  * 
     347 *
    341348 */
    342349bool pmSourceLocalSky(
     
    348355
    349356/** pmSourceMoments()
    350  * 
     357 *
    351358 * Measure source moments for the given source, using the value of
    352359 * source.moments.sky provided as the local background value and the peak
     
    355362 * are measured within the given circular radius of the source.peak coordinates.
    356363 * The return value indicates the success (TRUE) of the operation.
    357  * 
     364 *
    358365 */
    359366bool pmSourceMoments(
     
    364371
    365372/** pmSourcePSFClump()
    366  * 
     373 *
    367374 * We use the source moments to make an initial, approximate source
    368375 * classification, and as part of the information needed to build a PSF model for
     
    373380 * similar. The function returns a pmPSFClump structure, representing the
    374381 * centroid and size of the clump in the sigma_x, sigma_y second-moment plane.
    375  * 
     382 *
    376383 * The goal is to identify and characterize the stellar clump within the
    377384 * sigma_x, sigma_y second-moment plane.  To do this, an image is constructed to
     
    384391 *  * used to calculate the median and standard deviation of the sigma_x, sigma_y
    385392 * values. These resulting values are returned via the pmPSFClump structure.
    386  * 
     393 *
    387394 * The return value indicates the success (TRUE) of the operation.
    388  * 
     395 *
    389396 * XXX: Limit the S/N of the candidate sources (part of Metadata)? (TBD).
    390397 * XXX: Save the clump parameters on the Metadata (TBD)
    391  * 
     398 *
    392399 */
    393400pmPSFClump pmSourcePSFClump(
     
    398405
    399406/** pmSourceRoughClass()
    400  * 
     407 *
    401408 * Based on the specified data values, make a guess at the source
    402409 * classification. The sources are provides as a psArray of pmSource entries.
     
    405412 * can be extracted from the metadata using the given keywords. Except as noted,
    406413 * the data type for these parameters are psF32.
    407  * 
     414 *
    408415 */
    409416bool pmSourceRoughClass(
     
    415422
    416423/** pmSourceModelGuess()
    417  * 
     424 *
    418425 * Convert available data to an initial guess for the given model. This
    419426 * function allocates a pmModel entry for the pmSource structure based on the
     
    421428 * are specified for each model below. The guess values are placed in the model
    422429 * parameters. The function returns TRUE on success or FALSE on failure.
    423  * 
     430 *
    424431 */
    425432pmModel *pmSourceModelGuess(
     
    430437
    431438/** pmContourType
    432  * 
     439 *
    433440 * Only one type is defined at present.
    434  * 
     441 *
    435442 */
    436443typedef enum {
     
    442449
    443450/** pmSourceContour()
    444  * 
     451 *
    445452 * Find points in a contour for the given source at the given level. If type
    446453 * is PM_CONTOUR_CRUDE, the contour is found by starting at the source peak,
     
    452459 * This function may be used as part of the model guess inputs.  Other contour
    453460 * types may be specified in the future for more refined contours (TBD)
    454  * 
     461 *
    455462 */
    456463psArray *pmSourceContour(
     
    463470
    464471/** pmSourceFitModel()
    465  * 
     472 *
    466473 * Fit the requested model to the specified source. The starting guess for the
    467474 * model is given by the input source.model parameter values. The pixels of
     
    469476 * function calls psMinimizeLMChi2() on the image data. The function returns TRUE
    470477 * on success or FALSE on failure.
    471  * 
     478 *
    472479 */
    473480bool pmSourceFitModel(
     
    479486
    480487/** pmModelFitStatus()
    481  * 
     488 *
    482489 * This function wraps the call to the model-specific function returned by
    483490 * pmModelFitStatusFunc_GetFunction.  The model-specific function examines the
    484491 * model parameters, parameter errors, Chisq, S/N, and other parameters available
    485492 * from model to decide if the particular fit was successful or not.
    486  * 
     493 *
    487494 * XXX: Must code this.
    488  * 
     495 *
    489496 */
    490497bool pmModelFitStatus(
     
    494501
    495502/** pmSourceAddModel()
    496  * 
     503 *
    497504 * Add the given source model flux to/from the provided image. The boolean
    498505 * option center selects if the source is re-centered to the image center or if
     
    501508 * is at most the pixel range specified by the source.pixels image. The success
    502509 * status is returned.
    503  * 
     510 *
    504511 */
    505512bool pmSourceAddModel(
     
    507514    psImage *mask,   ///< The image pixel mask (valid == 0)
    508515    pmModel *model,   ///< The input pmModel
    509     bool center    ///< A boolean flag that determines whether pixels are centered
     516    bool center,    ///< A boolean flag that determines whether pixels are centered
     517    bool sky        ///< A boolean flag that determines if the sky is subtracted
    510518);
    511519
    512520
    513521/** pmSourceSubModel()
    514  * 
     522 *
    515523 * Subtract the given source model flux to/from the provided image. The
    516524 * boolean option center selects if the source is re-centered to the image center
     
    519527 * image is at most the pixel range specified by the source.pixels image. The
    520528 * success status is returned.
    521  * 
     529 *
    522530 */
    523531bool pmSourceSubModel(
     
    525533    psImage *mask,   ///< The image pixel mask (valid == 0)
    526534    pmModel *model,   ///< The input pmModel
    527     bool center    ///< A boolean flag that determines whether pixels are centered
     535    bool center,    ///< A boolean flag that determines whether pixels are centered
     536    bool sky        ///< A boolean flag that determines if the sky is subtracted
    528537);
    529538
    530539
    531540/**
    532  * 
     541 *
    533542 * The function returns both the magnitude of the fit, defined as -2.5log(flux),
    534543 * where the flux is integrated under the model, theoretically from a radius of 0
     
    537546 * not excluded by the aperture mask. The model flux is calculated by calling the
    538547 * model-specific function provided by pmModelFlux_GetFunction.
    539  * 
     548 *
    540549 * XXX: must code this.
    541  * 
     550 *
    542551 */
    543552bool pmSourcePhotometry(
     
    551560
    552561/**
    553  * 
     562 *
    554563 * This function converts the source classification into the closest available
    555564 * approximation to the Dophot classification scheme:
    556  * 
     565 *
    557566 * PM_SOURCE_DEFECT: 8
    558567 * PM_SOURCE_SATURATED: 8
     
    569578 * PM_SOURCE_POOR_FIT_GAL: 2
    570579 * PM_SOURCE_OTHER: ?
    571  * 
     580 *
    572581 */
    573582int pmSourceDophotType(
     
    577586
    578587/** pmSourceSextractType()
    579  * 
     588 *
    580589 * This function converts the source classification into the closest available
    581590 * approximation to the Sextractor classification scheme. the correspondence is
    582591 * not yet defined (TBD) .
    583  * 
     592 *
    584593 * XXX: Must code this.
    585  * 
     594 *
    586595 */
    587596int pmSourceSextractType(
     
    590599
    591600/** pmSourceFitModel_v5()
    592  * 
     601 *
    593602 * Fit the requested model to the specified source. The starting guess for the
    594603 * model is given by the input source.model parameter values. The pixels of
     
    596605 * function calls psMinimizeLMChi2() on the image data. The function returns TRUE
    597606 * on success or FALSE on failure.
    598  * 
     607 *
    599608 */
    600609bool pmSourceFitModel_v5(
     
    606615
    607616/** pmSourceFitModel_v7()
    608  * 
     617 *
    609618 * Fit the requested model to the specified source. The starting guess for the
    610619 * model is given by the input source.model parameter values. The pixels of
     
    612621 * function calls psMinimizeLMChi2() on the image data. The function returns TRUE
    613622 * on success or FALSE on failure.
    614  * 
     623 *
    615624 */
    616625bool pmSourceFitModel_v7(
     
    622631
    623632/** pmSourcePhotometry()
    624  * 
     633 *
    625634 * XXX: Need descriptions
    626  * 
     635 *
    627636 */
    628637bool pmSourcePhotometry(
  • trunk/psModules/src/objects/pmPSF.c

    r5765 r5844  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-12-12 21:14:38 $
     8 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-12-24 01:24:32 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  • trunk/psModules/src/objects/pmPSFtry.c

    r5765 r5844  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2005-12-12 21:14:38 $
     7 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2005-12-24 01:24:32 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    176176
    177177    // XXX this function wants aperture radius for pmSourcePhotometry
    178     pmPSFtryMetric (psfTry, RADIUS);
     178    pmPSFtryMetric_Alt (psfTry, RADIUS);
    179179    psLogMsg ("psphot.pspsf", 3, "try model %s, ap-fit: %f +/- %f, sky bias: %f\n",
    180180              modelName,
     
    288288
    289289    // linear fit to rfBin, daBin
    290     psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 1);
     290    psPolynomial1D *poly = psPolynomial1DAlloc(1, PS_POLYNOMIAL_ORD);
     291    psStats *fitstat = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
     292    poly = psVectorClipFitPolynomial1D (poly, fitstat, maskB, 1, daBin, NULL, rfBin);
    291293
    292294    // XXX EAM : this is the intended API (cycle 7? cycle 8?)
    293     poly = psVectorFitPolynomial1D(poly, maskB, 1, daBin, NULL, rfBin);
     295    // poly = psVectorFitPolynomial1D(poly, maskB, 1, daBin, NULL, rfBin);
    294296
    295297    // XXX EAM : replace this when the above version is implemented
     
    314316    psFree (poly);
    315317    psFree (stats);
     318    psFree (fitstat);
    316319
    317320    return true;
    318321}
     322
     323bool pmPSFtryMetric_Alt (pmPSFtry *try
     324                         , float RADIUS)
     325{
     326
     327    // the measured (aperture - fit) magnitudes (dA == try->metric)
     328    //   depend on both the true ap-fit (dAo) and the bias in the sky measurement:
     329    //     dA = dAo + dsky/flux
     330    //   where flux is the flux of the star
     331    // we fit this trend to find the infinite flux aperture correction (dAo),
     332    //   the nominal sky bias (dsky), and the error on dAo
     333    // the values of dA are contaminated by stars with close neighbors in the aperture
     334    //   we use an outlier rejection to avoid this bias
     335
     336    // rflux = ten(0.4*fitMag);
     337    psVector *rflux = psVectorAlloc (try
     338                                     ->sources->n, PS_TYPE_F64);
     339    for (int i = 0; i < try
     340                ->sources->n; i++) {
     341            if (try
     342                    ->mask->data.U8[i] & PSFTRY_MASK_ALL) continue;
     343            rflux->data.F64[i] = pow(10.0, 0.4*try
     344                                     ->fitMag->data.F64[i]);
     345        }
     346
     347    // XXX EAM : try 3hi/1lo sigma clipping on the rflux vs metric fit
     348    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
     349
     350    // XXX EAM
     351    stats->min = 1.0;
     352    stats->max = 3.0;
     353    stats->clipIter = 3;
     354
     355    // linear clipped fit to rfBin, daBin
     356    psPolynomial1D *poly = psPolynomial1DAlloc (1, PS_POLYNOMIAL_ORD);
     357    poly = psVectorClipFitPolynomial1D (poly, stats, try
     358                                            ->mask, PSFTRY_MASK_ALL, try
     359                                                ->metric, NULL, rflux);
     360    fprintf (stderr, "fit stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
     361
     362    try
     363        ->psf->ApResid = poly->coeff[0];
     364    try
     365        ->psf->dApResid = stats->sampleStdev;
     366    try
     367        ->psf->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS));
     368
     369    fprintf (stderr, "*******************************************************************************\n");
     370
     371    FILE *f;
     372    f = fopen ("apresid.dat", "w");
     373    if (f == NULL)
     374        psAbort ("pmPSFtry", "can't open output file");
     375
     376    for (int i = 0; i < try
     377                ->sources->n; i++) {
     378            fprintf (f, "%3d %8.4f %12.5e %8.4f %3d\n", i, try
     379                         ->fitMag->data.F64[i], rflux->data.F64[i], try
     380                             ->metric->data.F64[i], try
     381                                 ->mask->data.U8[i]);
     382        }
     383    fclose (f);
     384
     385    psFree (rflux);
     386    psFree (poly);
     387    psFree (stats);
     388
     389    // psFree (daFit);
     390    // psFree (daResid);
     391
     392    return true;
     393}
  • trunk/psModules/src/objects/pmPSFtry.h

    r5762 r5844  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-12-12 20:32:44 $
     8 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-12-24 01:24:32 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818
    1919/**
    20  * 
     20 *
    2121 * This structure contains a pointer to the collection of sources which will
    2222 * be used to test the PSF model form. It lists the pmModelType type of model
     
    3838 * ultimate metric to intercompare multiple types of PSF models is the value of
    3939 * the aperture correction scatter.
    40  * 
     40 *
    4141 * XXX: There are many more members in the SDRS then in the prototype code.
    4242 * I stuck with the prototype code.
    43  * 
    44  * 
     43 *
     44 *
    4545 */
    4646typedef struct
     
    5858
    5959/** pmPSFtryMaskValues
    60  * 
     60 *
    6161 * The following datatype defines the masks used by the pmPSFtry analysis to
    6262 * identify sources which should or should not be included in the analysis.
    63  * 
     63 *
    6464 */
    6565enum {
     
    7474
    7575/** pmPSFtryAlloc()
    76  * 
     76 *
    7777 * Allocate a pmPSFtry data structure.
    78  * 
     78 *
    7979 */
    8080pmPSFtry *pmPSFtryAlloc(
     
    8585
    8686/** pmPSFtryModel()
    87  * 
     87 *
    8888 * This function takes the input collection of sources and performs a complete
    8989 * analysis to determine a PSF model of the given type (specified by model name).
    9090 * The result is a pmPSFtry with the results of the analysis.
    91  * 
     91 *
    9292 */
    9393pmPSFtry *pmPSFtryModel(
     
    9999
    100100/** pmPSFtryMetric()
    101  * 
     101 *
    102102 * This function is used to measure the PSF model metric for the set of
    103103 * results contained in the pmPSFtry structure.
    104  * 
     104 *
    105105 */
    106106bool pmPSFtryMetric(
     
    109109);
    110110
     111/** pmPSFtryMetric_Alt()
     112 *
     113 * This function is used to measure the PSF model metric for the set of
     114 * results contained in the pmPSFtry structure (alternative implementation).
     115 *
     116 */
     117bool pmPSFtryMetric_Alt(
     118    pmPSFtry *try
     119    ,                      ///< Add comment.
     120    float RADIUS                        ///< Add comment.
     121);
     122
    111123# endif
  • trunk/psModules/test/imsubtract/tst_pmSubtractBias.c

    r5587 r5844  
    1919 *  test03: Calculate a row overscan vector and subtract it from each
    2020 *  row in the input image.
    21  * test05: 
     21 * test05:
    2222 *
    2323 *  @author GLG, MHPCC
     
    2525 *  XXX: Memory leaks are not being detected.
    2626 *
    27  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    28  *  @date $Date: 2005-11-23 23:54:30 $
     27 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     28 *  @date $Date: 2005-12-24 01:24:36 $
    2929 *
    3030 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    326326        rc = pmSubtractBias(myReadout, NULL, NULL, PM_OVERSCAN_NONE, stat,
    327327                            0, PM_FIT_NONE, myBias);
    328     
     328 
    329329        for (i=0;i<numRows;i++) {
    330330            for (j=0;j<numCols;j++) {
     
    335335                    testStatus = 1;
    336336                }
    337     
     337 
    338338                // Restore myReadout for next test.
    339339                myReadout->image->data.F32[i][j] = (float) (i + j);
     
    627627    // Set overscan axis in the metadata.
    628628    //
    629     psBool rc;
     629    psBool rc = false;
    630630    if (overscanaxis == PM_OVERSCAN_ROWS) {
    631631        rc = psMetadataAddS32(myReadout->parent->concepts, PS_LIST_HEAD, "CELL.READDIR", 0, NULL, 1);
  • trunk/psModules/test/objects/verified/tst_pmObjects01.stdout

    r5258 r5844  
    11Testing pmPeakAlloc()...
    22Testing pmMomentsAlloc()...
    3 Testing pmModelAlloc(PS_MODEL_GAUSS)...
    4 Testing pmModelAlloc(PS_MODEL_GAUSS)...
    5 Testing pmModelAlloc(PS_MODEL_GAUSS)...
    6 Testing pmModelAlloc(PS_MODEL_GAUSS)...
    73----------------------------------------------------------------------------------
    84Calling pmFindVectorPeaks with NULL psVector.  Should generate error and return NULL.
Note: See TracChangeset for help on using the changeset viewer.