IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

changes from eam_rel9_b1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.