IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14989


Ignore:
Timestamp:
Sep 23, 2007, 5:00:44 PM (19 years ago)
Author:
eugene
Message:

converted pmPSF to use pmTrend2D to represent psf parameters; updated PSF I/O to handle full pmTrend2D

Location:
branches/eam_branch_20070921/psModules/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070921/psModules/src/camera/pmFPAfileIO.c

    r14938 r14989  
    774774    }
    775775    pmFPAview *thisView = pmFPAAddSourceFromHeader (file->fpa, phu, file->format);
     776    assert (thisView); // XXX we are having some trouble with input psf files not having the Cell and fpa names matching.
    776777    psFree (thisView);
    777778    psFree (phu);
  • branches/eam_branch_20070921/psModules/src/objects/models/pmModel_GAUSS.c

    r14652 r14989  
    274274            out[i] = in[i];
    275275        } else {
    276             psPolynomial2D *poly = psf->params->data[i];
    277             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
     276            pmTrend2D *trend = psf->params->data[i];
     277            out[i] = pmTrend2DEval(trend, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    278278        }
    279279    }
     
    331331        if (i == PM_PAR_XPOS) continue;
    332332        if (i == PM_PAR_YPOS) continue;
    333         psPolynomial2D *poly = psf->params->data[i];
    334         assert (poly);
    335         PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     333        pmTrend2D *trend = psf->params->data[i];
     334        PAR[i] = pmTrend2DEval(trend, Xo, Yo);
    336335    }
    337336
  • branches/eam_branch_20070921/psModules/src/objects/models/pmModel_PGAUSS.c

    r14652 r14989  
    328328            out[i] = in[i];
    329329        } else {
    330             psPolynomial2D *poly = psf->params->data[i];
    331             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
     330            pmTrend2D *trend = psf->params->data[i];
     331            out[i] = pmTrend2DEval(trend, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    332332        }
    333333    }
     
    384384        if (i == PM_PAR_XPOS) continue;
    385385        if (i == PM_PAR_YPOS) continue;
    386         psPolynomial2D *poly = psf->params->data[i];
    387         assert (poly);
    388         PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     386        pmTrend2D *trend = psf->params->data[i];
     387        PAR[i] = pmTrend2DEval(trend, Xo, Yo);
    389388    }
    390389
  • branches/eam_branch_20070921/psModules/src/objects/models/pmModel_QGAUSS.c

    r14652 r14989  
    358358            out[i] = in[i];
    359359        } else {
    360             psPolynomial2D *poly = psf->params->data[i];
    361             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
     360            pmTrend2D *trend = psf->params->data[i];
     361            out[i] = pmTrend2DEval(trend, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    362362        }
    363363    }
     
    412412        if (i == PM_PAR_XPOS) continue;
    413413        if (i == PM_PAR_YPOS) continue;
    414         psPolynomial2D *poly = psf->params->data[i];
    415         assert (poly);
    416         PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     414        pmTrend2D *trend = psf->params->data[i];
     415        PAR[i] = pmTrend2DEval(trend, Xo, Yo);
    417416    }
    418417
  • branches/eam_branch_20070921/psModules/src/objects/models/pmModel_RGAUSS.c

    r14652 r14989  
    351351            out[i] = in[i];
    352352        } else {
    353             psPolynomial2D *poly = psf->params->data[i];
    354             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
     353            pmTrend2D *trend = psf->params->data[i];
     354            out[i] = pmTrend2DEval(trend, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    355355        }
    356356    }
     
    405405        if (i == PM_PAR_XPOS) continue;
    406406        if (i == PM_PAR_YPOS) continue;
    407         psPolynomial2D *poly = psf->params->data[i];
    408         assert (poly);
    409         PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     407        pmTrend2D *trend = psf->params->data[i];
     408        PAR[i] = pmTrend2DEval(trend, Xo, Yo);
    410409    }
    411410
  • branches/eam_branch_20070921/psModules/src/objects/models/pmModel_SERSIC.c

    r14669 r14989  
    343343            out[i] = in[i];
    344344        } else {
    345             psPolynomial2D *poly = psf->params->data[i];
    346             out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
     345            pmTrend2D *trend = psf->params->data[i];
     346            out[i] = pmTrend2DEval(trend, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    347347        }
    348348    }
     
    397397        if (i == PM_PAR_XPOS) continue;
    398398        if (i == PM_PAR_YPOS) continue;
    399         psPolynomial2D *poly = psf->params->data[i];
    400         assert (poly);
    401         PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     399        pmTrend2D *trend = psf->params->data[i];
     400        PAR[i] = pmTrend2DEval(trend, Xo, Yo);
    402401    }
    403402
  • branches/eam_branch_20070921/psModules/src/objects/pmPSF.c

    r14986 r14989  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.28.2.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-09-22 13:47:28 $
     8 *  @version $Revision: 1.28.2.5 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-09-24 03:00:44 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4848    if (!options) return;
    4949
    50     psFree (options->image);
    5150    psFree (options->stats);
    5251    return;
     
    6059    options->type          = 0;
    6160
    62     options->image         = NULL;
    6361    options->stats         = NULL;
    6462
     
    6664    options->psfTrendNx    = 0;
    6765    options->psfTrendNy    = 0;
     66    options->psfFieldNx    = 0;
     67    options->psfFieldNy    = 0;
     68    options->psfFieldXo    = 0;
     69    options->psfFieldYo    = 0;
    6870
    6971    options->poissonErrorsPhotLMM = true;
     
    8486
    8587    psFree (psf->ChiTrend);
     88    psFree (psf->psfTrendStats);
    8689    psFree (psf->ApTrend);
    8790    psFree (psf->FluxScale);
     
    164167    // PM_PAR_XPOS, etc)
    165168
    166     psf->Nx = options->image->numCols;
    167     psf->Ny = options->image->numRows;
     169    psImageBinning *binning = psImageBinningAlloc();
     170    binning->nXruff = options->psfTrendNx;
     171    binning->nYruff = options->psfTrendNy;
     172    binning->nXfine = options->psfFieldNx;
     173    binning->nYfine = options->psfFieldNy;
     174    psImageBinningSetSkipByOffset (binning, options->psfFieldXo, options->psfFieldYo);
     175
     176    psf->fieldNx = options->psfFieldNx;
     177    psf->fieldNy = options->psfFieldNy;
     178    psf->fieldXo = options->psfFieldXo;
     179    psf->fieldYo = options->psfFieldYo;
    168180
    169181    // define the parameter trends
     
    175187            if (i == PM_PAR_YPOS) continue;
    176188
    177             psf->params->data[i] = pmTrend2DAlloc (options->psfTrendMode, options->image, options->psfTrendNx, options->psfTrendNx, options->stats);
     189            psf->params->data[i] = pmTrend2DNoImageAlloc (options->psfTrendMode, binning, options->stats);
    178190        }
    179191    }
     192    psFree (binning);
    180193    return psf;
    181194}
  • branches/eam_branch_20070921/psModules/src/objects/pmPSF.h

    r14986 r14989  
    66 * @author EAM, IfA
    77 *
    8  * @version $Revision: 1.16.2.3 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2007-09-22 13:47:28 $
     8 * @version $Revision: 1.16.2.4 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2007-09-24 03:00:44 $
    1010 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1111 */
     
    4747    int nPSFstars;                      ///< number of stars used to measure PSF
    4848    int nApResid;                       ///< number of stars used to measure ApResid
    49     int Nx, Ny;                         ///< reference image dimensions
     49    int fieldNx;
     50    int fieldNy;
     51    int fieldXo;
     52    int fieldYo;
    5053    bool poissonErrorsPhotLMM;          ///< use poission errors for non-linear model fitting
    5154    bool poissonErrorsPhotLin;          ///< use poission errors for linear model fitting
     
    5861typedef struct {
    5962    pmModelType   type;
    60     psImage      *image;                // image for which the PSF is defined
    6163    psStats      *stats;                // psfTrend clipping stats
    6264    pmTrend2DMode psfTrendMode;
    6365    int           psfTrendNx;
    6466    int           psfTrendNy;
     67    int           psfFieldNx;
     68    int           psfFieldNy;
     69    int           psfFieldXo;
     70    int           psfFieldYo;
    6571    bool          poissonErrorsPhotLMM; ///< use poission errors for non-linear model fitting
    6672    bool          poissonErrorsPhotLin; ///< use poission errors for linear model fitting
    6773    bool          poissonErrorsParams; ///< use poission errors for model parameter fitting
    6874    float         radius;
    69    
    7075} pmPSFOptions;
    7176
  • branches/eam_branch_20070921/psModules/src/objects/pmPSF_IO.c

    r14986 r14989  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.22.2.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-09-22 13:47:28 $
     8 *  @version $Revision: 1.22.2.4 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-09-24 03:00:44 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    163163    if (!analysis) return false;
    164164
     165    // select the current recipe
     166    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT");
     167    if (!recipe) {
     168        psError(PS_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");
     169        return false;
     170    }
     171
    165172    // write a PHU? (only if input image is MEF)
    166173    // write a header? (only if this is the first readout for cell)
     
    260267        psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
    261268
    262         psMetadataAddS32 (header, PS_LIST_TAIL, "IMAXIS1", 0, "Image X Size", psf->Nx);
    263         psMetadataAddS32 (header, PS_LIST_TAIL, "IMAXIS2", 0, "Image Y Size", psf->Ny);
     269        psMetadataAddS32 (header, PS_LIST_TAIL, "IMAXIS1", 0, "Image X Size", psf->fieldNx);
     270        psMetadataAddS32 (header, PS_LIST_TAIL, "IMAXIS2", 0, "Image Y Size", psf->fieldNy);
     271        psMetadataAddS32 (header, PS_LIST_TAIL, "IMREF1",  0, "Image X Ref",  psf->fieldXo);
     272        psMetadataAddS32 (header, PS_LIST_TAIL, "IMREF2",  0, "Image Y Ref",  psf->fieldYo);
     273
     274        // extract PSF Clump info
     275        pmPSFClump psfClump;
     276
     277        psfClump.X  = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.X");   assert (status);
     278        psfClump.Y  = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.Y");   assert (status);
     279        psfClump.dX = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.DX");  assert (status);
     280        psfClump.dY = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.DY");  assert (status);
     281
     282        psMetadataAddF32 (header, PS_LIST_TAIL, "PSF_CLX", 0, "psf clump center", psfClump.X);
     283        psMetadataAddF32 (header, PS_LIST_TAIL, "PSF_CLY", 0, "psf clump center", psfClump.Y);
     284        psMetadataAddF32 (header, PS_LIST_TAIL, "PSF_CLDX", 0, "psf clump size", psfClump.dX);
     285        psMetadataAddF32 (header, PS_LIST_TAIL, "PSF_CLDY", 0, "psf clump size", psfClump.dY);
    264286
    265287        // save the dimensions of each parameter
     
    306328                // write the image components into a table: this is needed because they may each be a different size
    307329                psImageMap *map = trend->map;
    308                 for (int ix = 0; ix <= map->map->numCols; ix++) {
    309                     for (int iy = 0; iy <= map->map->numRows; iy++) {
     330                for (int ix = 0; ix < map->map->numCols; ix++) {
     331                    for (int iy = 0; iy < map->map->numRows; iy++) {
    310332                        psMetadata *row = psMetadataAlloc ();
    311333                        psMetadataAddS32 (row, PS_LIST_TAIL, "MODEL_TERM", 0, "", i);
     
    313335                        psMetadataAddS32 (row, PS_LIST_TAIL, "Y_POWER",    0, "", iy);
    314336                        psMetadataAddF32 (row, PS_LIST_TAIL, "VALUE",      0, "", map->map->data.F32[iy][ix]);
    315                         psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", map->error->data.F32[ix][iy]);
     337                        psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", map->error->data.F32[iy][ix]);
    316338                        psMetadataAddU8  (row, PS_LIST_TAIL, "MASK",       0, "", 0); // no cells are masked
    317339
     
    518540    psTrace ("psModules.objects", 5, "read psf model for %s\n", file->filename);
    519541
     542    // select the current recipe
     543    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT");
     544    if (!recipe) {
     545        psError(PS_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");
     546        return false;
     547    }
     548
    520549    // Menu of EXTNAME rules
    521550    psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES");
     
    560589    }
    561590
     591    // psf clump data
     592    pmPSFClump psfClump;
     593
     594    psfClump.X  = psMetadataLookupF32 (&status, header, "PSF_CLX" );  assert(status);
     595    psfClump.Y  = psMetadataLookupF32 (&status, header, "PSF_CLY" );  assert(status);
     596    psfClump.dX = psMetadataLookupF32 (&status, header, "PSF_CLDX");  assert(status);
     597    psfClump.dY = psMetadataLookupF32 (&status, header, "PSF_CLDY");  assert(status);
     598
     599    psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.X" , 0, "psf clump center", psfClump.X);
     600    psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.Y" , 0, "psf clump center", psfClump.Y);
     601    psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.DX", 0, "psf clump size",   psfClump.dX);
     602    psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.DY", 0, "psf clump size",   psfClump.dY);
     603
    562604    options->poissonErrorsPhotLMM = psMetadataLookupBool (&status, header, "ERR_LMM");
    563605    options->poissonErrorsPhotLin = psMetadataLookupBool (&status, header, "ERR_LIN");
    564606    options->poissonErrorsParams  = psMetadataLookupBool (&status, header, "ERR_PAR");
    565607
    566     // XXX this is a bit ad-hoc: determine the PSF trend mode by looking at one of the parameters
    567     // this could allow the psf model to use different trend modes for different parameters, but we
    568     // would need to change the alloc somewhat
     608    options->psfFieldNx = psMetadataLookupS32 (&status, header, "IMAXIS1");
     609    options->psfFieldNy = psMetadataLookupS32 (&status, header, "IMAXIS2");
     610    options->psfFieldXo = psMetadataLookupS32 (&status, header, "IMREF1");
     611    options->psfFieldYo = psMetadataLookupS32 (&status, header, "IMREF2");
     612
     613    psImageBinning *binning = psImageBinningAlloc();
     614    binning->nXfine = options->psfFieldNx;
     615    binning->nYfine = options->psfFieldNy;
    569616
    570617    // we determine the PSF parameter polynomials from the MD-defined polynomials
     
    576623        psAbort("mismatch model par count");
    577624
    578     int nXimage = psMetadataLookupS32 (&status, header, "IMAXIS1");
    579     int nYimage = psMetadataLookupS32 (&status, header, "IMAXIS2");
    580     // XXX don't require this to exist?  0,0 if not defined?
    581 
    582625    // load the trend mode and dimensions of each parameter
    583626    for (int i = 0; i < nPar; i++) {
    584627        char name[9];
    585628        snprintf (name, 9, "PAR%02d_NX", i);
    586         int nXorder = psMetadataLookupS32 (&status, header, name);
     629        binning->nXruff = psMetadataLookupS32 (&status, header, name);
    587630        if (!status) continue;          // not all parameters are defined
     631
    588632        snprintf (name, 9, "PAR%02d_NY", i);
    589         int nYorder = psMetadataLookupS32 (&status, header, name);
     633        binning->nYruff = psMetadataLookupS32 (&status, header, name);
    590634        if (!status) {
    591635            psError(PS_ERR_UNKNOWN, true, "inconsistent PSF header: NX defined for PAR %d, but not NY", i);
    592636            return false;
    593637        }
     638
    594639        snprintf (name, 9, "PAR%02d_MD", i);
    595640        char *modeName = psMetadataLookupStr (&status, header, name);
     
    599644        }
    600645        pmTrend2DMode psfTrendMode = pmTrend2DModeFromString (modeName);
    601         // XXX default to POLY_ORD if not defined?
    602 
    603         psf->params->data[i] = pmTrend2DFieldAlloc (psfTrendMode, nXimage, nYimage, nXorder, nYorder, NULL);
    604     }
     646        if (psfTrendMode == PM_TREND_NONE) {
     647            psfTrendMode = PM_TREND_POLY_ORD;
     648        }
     649
     650        psImageBinningSetSkipByOffset (binning, options->psfFieldXo, options->psfFieldYo);
     651        psf->params->data[i] = pmTrend2DNoImageAlloc (psfTrendMode, binning, NULL);
     652    }
     653    psFree (binning);
    605654
    606655    // other required information describing the PSF
     
    622671        int xPow = psMetadataLookupS32 (&status, row, "X_POWER");
    623672        int yPow = psMetadataLookupS32 (&status, row, "Y_POWER");
    624         // XXX sanity check here
    625673
    626674        pmTrend2D *trend = psf->params->data[iPar];
     
    632680        if (trend->mode == PM_TREND_MAP) {
    633681            psImageMap *map = trend->map;
     682            assert (map);
     683            assert (map->map);
     684            assert (map->error);
     685            assert (xPow >= 0);
     686            assert (yPow >= 0);
     687            assert (xPow < map->map->numCols);
     688            assert (yPow < map->map->numRows);
    634689            map->map->data.F32[yPow][xPow]    = psMetadataLookupF32 (&status, row, "VALUE");
    635690            map->error->data.F32[yPow][xPow]  = psMetadataLookupF32 (&status, row, "ERROR");
    636691        } else {
    637692            psPolynomial2D *poly = trend->poly;
     693            assert (poly);
     694            assert (xPow >= 0);
     695            assert (yPow >= 0);
     696            assert (xPow <= poly->nX);
     697            assert (yPow <= poly->nY);
    638698            poly->coeff[xPow][yPow]    = psMetadataLookupF32 (&status, row, "VALUE");
    639699            poly->coeffErr[xPow][yPow] = psMetadataLookupF32 (&status, row, "ERROR");
  • branches/eam_branch_20070921/psModules/src/objects/pmSourcePhotometry.c

    r14962 r14989  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-09-21 02:46:46 $
     5 *  @version $Revision: 1.31.2.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-09-24 03:00:44 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8181    // we must have a valid model
    8282    model = pmSourceGetModel (&isPSF, source);
    83     if (model == NULL)
    84         return false;
     83    if (model == NULL) {
     84        psTrace ("psModules.objects", 3, "fail mag : no valid model");
     85        return false;
     86    }
    8587
    8688    if (model->dparams->data.F32[PM_PAR_I0] > 0) {
     
    109111    // measure EXT model photometry
    110112    status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);
     113
    111114    // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
    112     if ((mode & PM_SOURCE_PHOT_APCORR) && isPSF && psf) {
    113         // convert to the equivalent 2D model?
     115    if ((mode & PM_SOURCE_PHOT_APCORR) && isPSF && psf && psf->ApTrend) {
    114116        source->psfMag += pmTrend2DEval (psf->ApTrend, x, y);
    115117    }
    116118
    117     if (!isfinite(SN) || (SN < AP_MIN_SN))
    118         return false;
     119    if (!isfinite(SN) || (SN < AP_MIN_SN)) {
     120        psTrace ("psModules.objects", 3, "fail mag : bad SN: %f (limit: %f)", SN, AP_MIN_SN);
     121        return false;
     122    }
    119123
    120124    // replace source flux
     
    209213    status = pmSourcePhotometryAper  (&source->apMag, model, flux, source->maskObj, maskVal);
    210214    if (!status) {
     215        psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag");
    211216        psErrorCode last = psErrorCodeLast();
    212217        if (last == PM_ERR_PHOTOM) {
  • branches/eam_branch_20070921/psModules/src/objects/pmTrend2D.c

    r14986 r14989  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.2.2.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-09-22 13:47:28 $
     5 *  @version $Revision: 1.2.2.4 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-09-24 03:00:44 $
    77 *
    88 *  Copyright 2004 Institute for Astronomy, University of Hawaii
     
    3232{
    3333    assert (image);
    34     assert (stats);
    35 
    36     pmTrend2D *trend = (pmTrend2D *) psAlloc(sizeof(pmTrend2D));
    37     psMemSetDeallocator(trend, (psFreeFunc) pmTrend2DFree);
    38 
    39     trend->map = NULL;
    40     trend->poly = NULL;
    41     trend->stats = psMemIncrRefCounter (stats);
    42     trend->mode = mode;
    43        
    44     switch (mode) {
    45       case PM_TREND_POLY_ORD:
    46         trend->poly = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXtrend, nYtrend);
    47         break;
    48 
    49       case PM_TREND_POLY_CHEB:
    50         trend->poly = psPolynomial2DAlloc (PS_POLYNOMIAL_CHEB, nXtrend, nYtrend);
    51         break;
    52 
    53       case PM_TREND_MAP: {
    54           // binning defines the map scale relationship
    55           psImageBinning *binning = psImageBinningAlloc();
    56           binning->nXruff = nXtrend;
    57           binning->nYruff = nYtrend;
    58           binning->nXfine = image->numCols;
    59           binning->nYfine = image->numRows;
    60 
    61           trend->map = psImageMapAlloc (image, binning, stats);
    62           psFree (binning);
    63           break;
    64       }
    65 
    66       default:
    67         psAbort ("error");
    68     }
    69     return (trend);
    70 }
    71 
    72 pmTrend2D *pmTrend2DFieldAlloc (pmTrend2DMode mode, int nXfield, int nYfield, int nXtrend, int nYtrend, psStats *stats)
    73 {
     34
    7435    pmTrend2D *trend = (pmTrend2D *) psAlloc(sizeof(pmTrend2D));
    7536    psMemSetDeallocator(trend, (psFreeFunc) pmTrend2DFree);
     
    10263          // binning defines the map scale relationship
    10364          psImageBinning *binning = psImageBinningAlloc();
     65          binning->nXruff = nXtrend;
     66          binning->nYruff = nYtrend;
     67          binning->nXfine = image->numCols;
     68          binning->nYfine = image->numRows;
     69
     70          trend->map = psImageMapAlloc (image, binning, stats);
     71          psFree (binning);
     72          break;
     73      }
     74
     75      default:
     76        psAbort ("error");
     77    }
     78    return (trend);
     79}
     80
     81pmTrend2D *pmTrend2DNoImageAlloc (pmTrend2DMode mode, psImageBinning *binning, psStats *stats)
     82{
     83    pmTrend2D *trend = (pmTrend2D *) psAlloc(sizeof(pmTrend2D));
     84    psMemSetDeallocator(trend, (psFreeFunc) pmTrend2DFree);
     85
     86    trend->map = NULL;
     87    trend->poly = NULL;
     88    trend->stats = psMemIncrRefCounter (stats);
     89    trend->mode = mode;
     90       
     91    switch (mode) {
     92      case PM_TREND_POLY_ORD:
     93        trend->poly = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, binning->nXruff, binning->nYruff);
     94        // set masking somehow
     95        for (int nx = 0; nx < trend->poly->nX + 1; nx++) {
     96            for (int ny = 0; ny < trend->poly->nY + 1; ny++) {
     97                if (nx + ny >= PS_MAX (trend->poly->nX, trend->poly->nY) + 1) {
     98                    trend->poly->mask[nx][ny] = 1;
     99                } else {
     100                    trend->poly->mask[nx][ny] = 0;
     101                }
     102            }
     103        }
     104        break;
     105
     106      case PM_TREND_POLY_CHEB:
     107        trend->poly = psPolynomial2DAlloc (PS_POLYNOMIAL_CHEB, binning->nXruff, binning->nYruff);
     108        break;
     109
     110      case PM_TREND_MAP: {
     111          // binning defines the map scale relationship
     112          trend->map = psImageMapNoImageAlloc (binning, stats);
     113          break;
     114      }
     115
     116      default:
     117        psAbort ("error");
     118    }
     119    return (trend);
     120}
     121
     122pmTrend2D *pmTrend2DFieldAlloc (pmTrend2DMode mode, int nXfield, int nYfield, int nXtrend, int nYtrend, psStats *stats)
     123{
     124    pmTrend2D *trend = (pmTrend2D *) psAlloc(sizeof(pmTrend2D));
     125    psMemSetDeallocator(trend, (psFreeFunc) pmTrend2DFree);
     126
     127    trend->map = NULL;
     128    trend->poly = NULL;
     129    trend->stats = psMemIncrRefCounter (stats);
     130    trend->mode = mode;
     131       
     132    switch (mode) {
     133      case PM_TREND_POLY_ORD:
     134        trend->poly = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXtrend, nYtrend);
     135        // set masking somehow
     136        for (int nx = 0; nx < trend->poly->nX + 1; nx++) {
     137            for (int ny = 0; ny < trend->poly->nY + 1; ny++) {
     138                if (nx + ny >= PS_MAX (trend->poly->nX, trend->poly->nY) + 1) {
     139                    trend->poly->mask[nx][ny] = 1;
     140                } else {
     141                    trend->poly->mask[nx][ny] = 0;
     142                }
     143            }
     144        }
     145        break;
     146
     147      case PM_TREND_POLY_CHEB:
     148        trend->poly = psPolynomial2DAlloc (PS_POLYNOMIAL_CHEB, nXtrend, nYtrend);
     149        break;
     150
     151      case PM_TREND_MAP: {
     152          // binning defines the map scale relationship
     153          psImageBinning *binning = psImageBinningAlloc();
    104154          binning->nXfine = nXfield;
    105155          binning->nYfine = nYfield;
     
    122172    bool status;
    123173
     174    assert (trend);
     175    assert (x);
     176    assert (y);
     177    assert (f);
     178
    124179    switch (trend->mode) {
    125180      case PM_TREND_POLY_ORD:
     
    147202    double result;
    148203
    149     if (!trend) return 0.0;
     204    assert (trend);
    150205
    151206    switch (trend->mode) {
     
    168223
    169224    psVector *result;
     225
     226    assert (trend);
     227    assert (x);
     228    assert (y);
    170229
    171230    switch (trend->mode) {
  • branches/eam_branch_20070921/psModules/src/objects/pmTrend2D.h

    r14980 r14989  
    55 * @author EAM, IfA
    66 *
    7  * @version $Revision: 1.2.2.2 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-09-22 02:20:11 $
     7 * @version $Revision: 1.2.2.3 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2007-09-24 03:00:44 $
    99 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1010 */
     
    3434pmTrend2D *pmTrend2DAlloc (pmTrend2DMode mode, psImage *image, int nXtrend, int nYtrend, psStats *stats);
    3535
     36pmTrend2D *pmTrend2DNoImageAlloc (pmTrend2DMode mode, psImageBinning *binning, psStats *stats);
     37
    3638// allocate a pmTrend2D tied to an abstract field with size nXfield,nYfield
    3739pmTrend2D *pmTrend2DFieldAlloc (pmTrend2DMode mode, int nXfield, int nYfield, int nXtrend, int nYtrend, psStats *stats);
Note: See TracChangeset for help on using the changeset viewer.