IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30029


Ignore:
Timestamp:
Dec 14, 2010, 9:01:22 AM (15 years ago)
Author:
eugene
Message:

update to use modified psImageMapFit APIs

Location:
branches/eam_branches/ipp-20101205/psModules/src/objects
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/psModules/src/objects/pmPSFtry.h

    r25754 r30029  
    100100bool pmPSFtryFitEXT (pmPSFtry *psfTry, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal);
    101101
    102 bool pmPSFtryMakePSF (pmPSFtry *psfTry);
     102bool pmPSFtryMakePSF (bool *goodFit, pmPSFtry *psfTry);
    103103
    104104bool pmPSFtryFitPSF (pmPSFtry *psfTry, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal);
     
    123123);
    124124
    125 bool pmPSFFitShapeParams (pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask);
     125bool pmPSFFitShapeParams (bool *goodFit, pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask);
    126126
    127127float psVectorSystematicError (psVector *residuals, psVector *errors, float clipFraction);
  • branches/eam_branches/ipp-20101205/psModules/src/objects/pmPSFtryMakePSF.c

    r29004 r30029  
    5050Note: some of the array entries may be NULL (failed fits); ignore them.
    5151 *****************************************************************************/
    52 bool pmPSFtryMakePSF (pmPSFtry *psfTry)
     52bool pmPSFtryMakePSF (bool *goodFit, pmPSFtry *psfTry)
    5353{
    5454    PS_ASSERT_PTR_NON_NULL(psfTry, false);
     
    7474
    7575    // fit the shape parameters (SXX, SYY, SXY) as a function of position
    76     if (!pmPSFFitShapeParams (psf, psfTry->sources, x, y, srcMask)) {
     76    if (!pmPSFFitShapeParams (goodFit, psf, psfTry->sources, x, y, srcMask)) {
    7777        psFree(x);
    7878        psFree(y);
    7979        return false;
     80    }
     81    if (!goodFit) {
     82        psWarning ("poor fit to PSF shape parameters for trend order %d, %d, skipping\n", psf->trendNx, psf->trendNy);
     83        psFree(x);
     84        psFree(y);
     85        return true;
    8086    }
    8187
     
    115121        // the mask is carried from previous steps and updated with this operation
    116122        // the weight is either the flux error or NULL, depending on 'psf->poissonErrorParams'
    117         if (!pmTrend2DFit (trend, srcMask, 0xff, x, y, z, NULL)) {
     123        if (!pmTrend2DFit (goodFit, trend, srcMask, 0xff, x, y, z, NULL)) {
    118124            psError(PS_ERR_UNKNOWN, false, "failed to build psf model for parameter %d", i);
    119125            psFree(x);
     
    122128            return false;
    123129        }
     130        if (!goodFit) {
     131            // if we do not get a good fit (but do not actually hit an error),
     132            // tell the calling program to try something else
     133            psWarning ("poor fit to PSF parameter %d for trend order %d, %d, skipping\n", i, psf->trendNx, psf->trendNy);
     134            psFree(x);
     135            psFree(y);
     136            psFree(z);
     137            return true;
     138        }
    124139        if (trend->mode == PM_TREND_MAP) {
    125140            // p_psImagePrint (2, trend->map->map, "param N Before"); // XXX TEST:
     
    163178
    164179// fit the shape parameters using the supplied order (pmPSF->trendNx,trendNy)
    165 bool pmPSFFitShapeParams (pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask) {
     180bool pmPSFFitShapeParams (bool *goodFit, pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask) {
    166181
    167182    // we are doing a robust fit.  after each pass, we drop points which are more deviant than
     
    219234        trend = psf->params->data[PM_PAR_E0];
    220235        trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here
    221         status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e0, NULL);
     236        status &= pmTrend2DFit (goodFit, trend, srcMask, 0xff, x, y, e0, NULL);
     237        if (!goodFit) {
     238            psFree (e0);
     239            psFree (e1);
     240            psFree (e2);
     241            return true;
     242        }
    222243        mean = psStatsGetValue (trend->stats, meanOption);
    223244        stdev = psStatsGetValue (trend->stats, stdevOption);
     
    228249        trend = psf->params->data[PM_PAR_E1];
    229250        trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here
    230         status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e1, NULL);
     251        status &= pmTrend2DFit (goodFit, trend, srcMask, 0xff, x, y, e1, NULL);
     252        if (!goodFit) {
     253            psFree (e0);
     254            psFree (e1);
     255            psFree (e2);
     256            return true;
     257        }
    231258        mean = psStatsGetValue (trend->stats, meanOption);
    232259        stdev = psStatsGetValue (trend->stats, stdevOption);
     
    237264        trend = psf->params->data[PM_PAR_E2];
    238265        trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here
    239         status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e2, NULL);
     266        status &= pmTrend2DFit (goodFit, trend, srcMask, 0xff, x, y, e2, NULL);
     267        if (!goodFit) {
     268            psFree (e0);
     269            psFree (e1);
     270            psFree (e2);
     271            return true;
     272        }
    240273        mean = psStatsGetValue (trend->stats, meanOption);
    241274        stdev = psStatsGetValue (trend->stats, stdevOption);
     
    246279        if (!status) {
    247280            psError (PS_ERR_UNKNOWN, true, "failed to fit PSF shape params");
     281            psFree (e0);
     282            psFree (e1);
     283            psFree (e2);
    248284            return false;
    249285        }
  • branches/eam_branches/ipp-20101205/psModules/src/objects/pmPSFtryModel.c

    r29004 r30029  
    136136
    137137        // stage 2: construct a psf (pmPSF) from this collection of model fits, including the 2D variation
    138         if (!pmPSFtryMakePSF (psfTry)) {
     138        bool goodFit = false;
     139        if (!pmPSFtryMakePSF (&goodFit, psfTry)) {
    139140            psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
    140141            psFree(psfTry);
    141142            return NULL;
    142143        }
     144        if (!goodFit) {
     145            psWarning ("poor psf fit for order %d, skipping\n", i);
     146            continue;
     147        }
    143148
    144149        // stage 3: refit with fixed shape parameters, measure pmPSFtry->metric
     
    169174    }
    170175    psFree (srcMask);
     176
     177    if (!minPSF) {
     178        psError(PS_ERR_UNKNOWN, false, "failed to construct a valid psf model from the sources");
     179        psFree(psfTry);
     180        return NULL;
     181    }
    171182
    172183    // keep the ones matching the min systematic error:
  • branches/eam_branches/ipp-20101205/psModules/src/objects/pmTrend2D.c

    r30020 r30029  
    179179}
    180180
    181 bool pmTrend2DFit(pmTrend2D *trend, psVector *mask, psVectorMaskType maskVal, const psVector *x,
     181bool pmTrend2DFit(bool *goodFit, pmTrend2D *trend, psVector *mask, psVectorMaskType maskVal, const psVector *x,
    182182                  const psVector *y, const psVector *f, const psVector *df)
    183183{
     
    189189
    190190    bool status = false;
    191     bool goodFit = false;
     191    *goodFit = false;
     192    // for the psImageMap fit, it is possible to have valid data but no valid solution for
     193    // example, an isolated cell may not be reached from other cells, making the solution
     194    // degenerate.  psImageMapFit should probably handle this case, but until it does, we allow
     195    // it to fail on the result, but not yield an error (goodFit = false).
     196    // psVectorClipFitPolynomial2D can not fail in this way (really?), so goodFit is always
     197    // true
    192198
    193199    switch (trend->mode) {
     
    198204        // of points in the image, and potentially based on the fractional range of the
    199205        // data?
     206        *goodFit = true;
    200207        break;
    201208
     
    203210        // XXX supply fraction from trend elements
    204211        // XXX need to add the API which adjusts the scale
    205         status = psImageMapClipFit(&goodFit, trend->map, trend->stats, mask, maskVal, x, y, f, df);
     212        status = psImageMapClipFit(goodFit, trend->map, trend->stats, mask, maskVal, x, y, f, df);
    206213        break;
    207214
  • branches/eam_branches/ipp-20101205/psModules/src/objects/pmTrend2D.h

    r29004 r30029  
    7676    );
    7777
    78 bool pmTrend2DFit(pmTrend2D *trend,
     78bool pmTrend2DFit(bool *goodFit,
     79                  pmTrend2D *trend,
    7980                  psVector *mask,       // Warning: mask is modified!
    8081                  psVectorMaskType maskVal,
Note: See TracChangeset for help on using the changeset viewer.