IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14778


Ignore:
Timestamp:
Sep 7, 2007, 10:24:34 AM (19 years ago)
Author:
magnier
Message:

adding fitting, evaluation functions

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

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070830/psModules/src/objects/pmTrend2D.c

    r14731 r14778  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-09-04 18:35:51 $
     5 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-09-07 20:24:34 $
    77 *
    88 *  Copyright 2004 Institute for Astronomy, University of Hawaii
     
    2222        return;
    2323
     24    psFree (trend->stats);
    2425    psFree (trend->poly);
    2526    psFree (trend->map);
     
    2728}
    2829
    29 pmTrend2D *pmTrend2DAlloc (pmTrend2DMode mode, int nXout, int nYout, int nXtrend, int nYtrend, psStats *stats)
     30pmTrend2D *pmTrend2DAlloc (pmTrend2DMode mode, psImage *image, int nXtrend, int nYtrend, psStats *stats)
    3031{
    3132    pmTrend2D *trend = (pmTrend2D *) psAlloc(sizeof(pmTrend2D));
     
    3536    trend->poly = NULL;
    3637    trend->stats = psMemIncrRefCounter (stats);
     38    trend->mode = mode;
    3739       
    3840    switch (mode) {
     
    4547        break;
    4648
    47       case PM_TREND_MAP:
    48         // XXX *** I need the output image dimensions here!
     49      case PM_TREND_MAP: {
     50          // binning defines the map scale relationship
     51          psImageBinning *binning = psImageBinningAlloc();
     52          binning->nXfine = image->numCols;
     53          binning->nYfine = image->numRows;
     54          binning->nXruff = nXtrend;
     55          binning->nYruff = nYtrend;
    4956
    50         // function is defined over the range 0-1000, 0-1000
    51         psImageBinning *binning = psImageBinningAlloc();
    52         binning->nXfine = nXout;
    53         binning->nYfine = nYout;
    54         binning->nXruff = nXtrend;
    55         binning->nYruff = nYtrend;
    56 
    57         trend->map = psImageMapAlloc (NULL, binning, stats);
    58         psFree (binning);
    59         break;
     57          trend->map = psImageMapAlloc (image, binning, stats);
     58          psFree (binning);
     59          break;
     60      }
    6061
    6162      default:
     
    6465    return (trend);
    6566}
     67
     68pmTrend2D *pmTrend2DFieldAlloc (pmTrend2DMode mode, int nXfield, int nYfield, int nXtrend, int nYtrend, psStats *stats)
     69{
     70    pmTrend2D *trend = (pmTrend2D *) psAlloc(sizeof(pmTrend2D));
     71    psMemSetDeallocator(trend, (psFreeFunc) pmTrend2DFree);
     72
     73    trend->map = NULL;
     74    trend->poly = NULL;
     75    trend->stats = psMemIncrRefCounter (stats);
     76    trend->mode = mode;
     77       
     78    switch (mode) {
     79      case PM_TREND_POLY_ORD:
     80        trend->poly = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXtrend, nYtrend);
     81        break;
     82
     83      case PM_TREND_POLY_CHEB:
     84        trend->poly = psPolynomial2DAlloc (PS_POLYNOMIAL_CHEB, nXtrend, nYtrend);
     85        break;
     86
     87      case PM_TREND_MAP: {
     88          // binning defines the map scale relationship
     89          psImageBinning *binning = psImageBinningAlloc();
     90          binning->nXfine = nXfield;
     91          binning->nYfine = nYfield;
     92          binning->nXruff = nXtrend;
     93          binning->nYruff = nYtrend;
     94
     95          trend->map = psImageMapAlloc (NULL, binning, stats);
     96          psFree (binning);
     97          break;
     98      }
     99
     100      default:
     101        psAbort ("error");
     102    }
     103    return (trend);
     104}
     105
     106bool pmTrend2DFit (pmTrend2D *trend, psVector *x, psVector *y, psVector *f, psVector *df) {
     107
     108    bool status;
     109
     110    psVector *mask = psVectorAlloc (x->n, PS_TYPE_MASK);
     111
     112    switch (trend->mode) {
     113      case PM_TREND_POLY_ORD:
     114      case PM_TREND_POLY_CHEB:
     115        status = psVectorClipFitPolynomial2D (trend->poly, trend->stats, mask, 0xff, f, df, x, y);
     116        // we can use the API here which adjusts the polynomial order based on the number
     117        // of points in the image, and potentially based on the fractional range of the
     118        // data?
     119        break;
     120
     121      case PM_TREND_MAP:
     122        // XXX supply fraction from trend elements
     123        status = psImageMapGenerateScale (trend->map, x, y, f, df, 0.1);
     124        break;
     125
     126      default:
     127        psAbort ("error");
     128    }
     129    psFree (mask);
     130    return status;
     131}
     132
     133double pmTrend2DEval (pmTrend2D *trend, float x, float y) {
     134
     135    double result;
     136
     137    if (!trend) return 0.0;
     138
     139    switch (trend->mode) {
     140      case PM_TREND_POLY_ORD:
     141      case PM_TREND_POLY_CHEB:
     142        result = psPolynomial2DEval (trend->poly, x, y);
     143        break;
     144
     145      case PM_TREND_MAP:
     146        result = psImageMapEval (trend->map, x, y);
     147        break;
     148
     149      default:
     150        psAbort ("error");
     151    }
     152    return result;
     153}
     154
     155psVector *pmTrend2DEvalVector (pmTrend2D *trend, psVector *x, psVector *y) {
     156
     157    psVector *result;
     158
     159    switch (trend->mode) {
     160      case PM_TREND_POLY_ORD:
     161      case PM_TREND_POLY_CHEB:
     162        result = psPolynomial2DEvalVector (trend->poly, x, y);
     163        break;
     164
     165      case PM_TREND_MAP:
     166        result = psImageMapEvalVector (trend->map, x, y);
     167        break;
     168
     169      default:
     170        psAbort ("error");
     171    }
     172    return result;
     173}
  • branches/eam_branch_20070830/psModules/src/objects/pmTrend2D.h

    r14731 r14778  
    55 * @author EAM, IfA
    66 *
    7  * @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-09-04 18:35:51 $
     7 * @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2007-09-07 20:24:34 $
    99 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1010 */
     
    1717
    1818typedef enum {
    19   PM_TREND_POLY_ORD,
    20   PM_TREND_POLY_CHEB,
    21   PM_TREND_MAP,
     19    PM_TREND_POLY_ORD,
     20    PM_TREND_POLY_CHEB,
     21    PM_TREND_MAP,
    2222} pmTrend2DMode;
    2323
    2424typedef struct {
    25   psPolynomial2D *poly;
    26   psImageMap *map;
    27   pmTrend2DMode mode; // POLY_ORD, POLY_CHEB, MAP
     25    psPolynomial2D *poly;
     26    psImageMap *map;
     27    psStats *stats;
     28    pmTrend2DMode mode; // POLY_ORD, POLY_CHEB, MAP
    2829} pmTrend2D;
    2930
    30 // allocate a pmTrend2D structure.  nX,nY is order for the polynomials, max number of grid cells for
     31// allocate a pmTrend2D structure tied to an image dimensions.  nXtrend,nYtrend is the order for the polynomials, max number of grid cells for
    3132// psImageMap
    32 pmTrend2D *pmTrend2DAlloc (pmTrend2DMode mode, int nXout, int nYout, int nXtrend, int nYtrend, psStats *stats);
     33pmTrend2D *pmTrend2DAlloc (pmTrend2DMode mode, psImage *image, int nXtrend, int nYtrend, psStats *stats);
     34
     35// allocate a pmTrend2D tied to an abstract field with size nXfield,nYfield
     36pmTrend2D *pmTrend2DFieldAlloc (pmTrend2DMode mode, int nXfield, int nYfield, int nXtrend, int nYtrend, psStats *stats);
    3337
    3438bool pmTrend2DFit (pmTrend2D *trend, psVector *x, psVector *y, psVector *f, psVector *df);
    3539
     40double pmTrend2DEval (pmTrend2D *trend, float x, float y);
     41psVector *pmTrend2DEvalVector (pmTrend2D *trend, psVector *x, psVector *y);
     42
    3643/// @}
    3744# endif
Note: See TracChangeset for help on using the changeset viewer.