IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6439


Ignore:
Timestamp:
Feb 16, 2006, 4:48:25 PM (20 years ago)
Author:
magnier
Message:

added local sky variance, modified to work with the new psMinimizeLMChi2

Location:
branches/eam_rel9_p0/psModules/src/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_rel9_p0/psModules/src/objects/pmObjects.c

    r6380 r6439  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.5.4.7 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-02-08 07:16:49 $
     8 *  @version $Revision: 1.5.4.8 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-02-17 02:48:25 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    786786        return(false);
    787787    }
    788     source->moments = pmMomentsAlloc();
     788    if (source->moments == NULL) {
     789        source->moments = pmMomentsAlloc();
     790    }
    789791    source->moments->Sky = (psF32) tmpF64;
     792    psTrace(__func__, 3, "---- %s(true) end ----\n", __func__);
     793    return (true);
     794}
     795
     796// A complementary function to pmSourceLocalSky: calculate the local median variance
     797bool pmSourceLocalSkyVariance(
     798    pmSource *source,
     799    psStatsOptions statsOptions,
     800    psF32 Radius)
     801{
     802    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
     803    PS_ASSERT_PTR_NON_NULL(source, false);
     804    PS_ASSERT_IMAGE_NON_NULL(source->weight, false);
     805    PS_ASSERT_IMAGE_NON_NULL(source->mask, false);
     806    PS_ASSERT_PTR_NON_NULL(source->peak, false);
     807    PS_ASSERT_INT_POSITIVE(Radius, false);
     808    PS_ASSERT_INT_NONNEGATIVE(Radius, false);
     809
     810    psImage *image = source->weight;
     811    psImage *mask  = source->mask;
     812    pmPeak *peak  = source->peak;
     813    psRegion srcRegion;
     814
     815    srcRegion = psRegionForSquare(peak->x, peak->y, Radius);
     816    srcRegion = psRegionForImage(mask, srcRegion);
     817
     818    psImageMaskRegion(mask, srcRegion, "OR", PSPHOT_MASK_MARKED);
     819    psStats *myStats = psStatsAlloc(statsOptions);
     820    myStats = psImageStats(myStats, image, mask, 0xff);
     821    psImageMaskRegion(mask, srcRegion, "AND", ~PSPHOT_MASK_MARKED);
     822
     823    psF64 tmpF64;
     824    p_psGetStatValue(myStats, &tmpF64);
     825    psFree(myStats);
     826
     827    if (isnan(tmpF64)) {
     828        psTrace(__func__, 3, "---- %s(false) end ----\n", __func__);
     829        return(false);
     830    }
     831    if (source->moments == NULL) {
     832        source->moments = pmMomentsAlloc();
     833    }
     834    source->moments->dSky = (psF32) tmpF64;
    790835    psTrace(__func__, 3, "---- %s(true) end ----\n", __func__);
    791836    return (true);
     
    13371382    PS_ASSERT_PTR_NON_NULL(source->moments, false);
    13381383    PS_ASSERT_PTR_NON_NULL(source->peak, false);
    1339     PS_FLOAT_COMPARE(0.0, radius, false);
     1384    PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(radius, 0.0, false);
    13401385
    13411386    //
     
    16711716    yErr->n = nPix;
    16721717
     1718    // XXX EAM : the new minimization API supplies the constraints as a struct
    16731719    psMinimization *myMin = psMinimizationAlloc(PM_SOURCE_FIT_MODEL_NUM_ITERATIONS,
    16741720                            PM_SOURCE_FIT_MODEL_TOLERANCE);
     1721    psMinConstrain *constrain = psMinConstrainAlloc();
    16751722
    16761723    // PSF model only fits first 4 parameters, EXT model fits all
     
    16841731        }
    16851732    }
     1733    constrain->paramMask = paramMask;
    16861734
    16871735    // Set the parameter range checks
    16881736    pmModelLimits modelLimits = pmModelLimits_GetFunction (model->type);
    1689     psVector *beta_lim = NULL;
    1690     psVector *params_min = NULL;
    1691     psVector *params_max = NULL;
    1692 
    1693     // XXX EAM : in this implementation, I pass in the limits with the covar matrix.
    1694     //           in the SDRS, I define a new psMinimization which will take these in
    1695     psImage *covar = psImageAlloc (params->n, 3, PS_TYPE_F64);
    1696     modelLimits (&beta_lim, &params_min, &params_max);
    1697     for (int i = 0; i < params->n; i++) {
    1698         covar->data.F64[0][i] = beta_lim->data.F32[i];
    1699         covar->data.F64[1][i] = params_min->data.F32[i];
    1700         covar->data.F64[2][i] = params_max->data.F32[i];
    1701     }
     1737    modelLimits (&constrain->paramDelta, &constrain->paramMin, &constrain->paramMax);
     1738
     1739    psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F64);
    17021740
    17031741    psTrace (".pmObjects.pmSourceFitModel", 5, "fitting function\n");
    1704     fitStatus = psMinimizeLMChi2(myMin, covar, params, paramMask, x, y, yErr, modelFunc);
     1742
     1743    fitStatus = psMinimizeLMChi2(myMin, covar, params, constrain, x, y, yErr, modelFunc);
    17051744    for (int i = 0; i < dparams->n; i++) {
    17061745        if ((paramMask != NULL) && paramMask->data.U8[i])
     
    17491788    psFree(myMin);
    17501789    psFree(covar);
    1751     psFree(paramMask);
    1752     psFree(params_min);
    1753     psFree(params_max);
    1754     psFree(beta_lim);
     1790    psFree(constrain->paramMask);
     1791    psFree(constrain->paramMin);
     1792    psFree(constrain->paramMax);
     1793    psFree(constrain->paramDelta);
     1794    psFree(constrain);
    17551795
    17561796    rc = (onPic && fitStatus);
  • branches/eam_rel9_p0/psModules/src/objects/pmObjects.h

    r6380 r6439  
    1010 *  @author GLG, MHPCC
    1111 *
    12  *  @version $Revision: 1.4.4.7 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-02-08 07:16:49 $
     12 *  @version $Revision: 1.4.4.8 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-02-17 02:48:23 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8888typedef struct
    8989{
    90     float x;    ///< X-coord of centroid.
    91     float y;    ///< Y-coord of centroid.
     90    float x;     ///< X-coord of centroid.
     91    float y;     ///< Y-coord of centroid.
    9292    float Sx;    ///< x-second moment.
    9393    float Sy;    ///< y-second moment.
    94     float Sxy;    ///< xy cross moment.
    95     float Sum;    ///< Pixel sum above sky (background).
    96     float Peak;    ///< Peak counts above sky.
    97     float Sky;    ///< Sky level (background).
     94    float Sxy;   ///< xy cross moment.
     95    float Sum;   ///< Pixel sum above sky (background).
     96    float Peak;  ///< Peak counts above sky.
     97    float Sky;   ///< Sky level (background).
     98    float dSky;  ///< local Sky variance
    9899    float SN;    ///< approx signal-to-noise
    99     int nPixels;   ///< Number of pixels used.
     100    int nPixels; ///< Number of pixels used.
    100101}
    101102pmMoments;
     
    360361
    361362
     363// A complementary function to pmSourceLocalSky: calculate the local sky variance
     364bool pmSourceLocalSkyVariance(
     365    pmSource *source,   ///< The input image (float)
     366    psStatsOptions statsOptions, ///< The statistic used in calculating the background sky
     367    float Radius   ///< The inner radius of the square annulus to exclude
     368);
     369
    362370/** pmSourceMoments()
    363371 *
Note: See TracChangeset for help on using the changeset viewer.