IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 24, 2007, 11:27:58 AM (19 years ago)
Author:
eugene
Message:

update from eam_branch_20070921

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmPSF.c

    r14961 r15000  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-09-21 02:46:25 $
     8 *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-09-24 21:27:58 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4141
    4242/*****************************************************************************/
    43 /* DEFINE STATEMENTS                                                         */
    44 /*****************************************************************************/
    45 
    46 /*****************************************************************************/
    47 /* TYPE DEFINITIONS                                                          */
    48 /*****************************************************************************/
    49 
    50 /*****************************************************************************/
    51 /* GLOBAL VARIABLES                                                          */
    52 /*****************************************************************************/
    53 
    54 /*****************************************************************************/
    55 /* FILE STATIC VARIABLES                                                     */
    56 /*****************************************************************************/
    57 
    58 /*****************************************************************************/
    59 /* FUNCTION IMPLEMENTATION - LOCAL                                           */
    60 /*****************************************************************************/
    61 
    62 /*****************************************************************************/
    6343/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    6444/*****************************************************************************/
     45
     46static void pmPSFOptionsFree (pmPSFOptions *options) {
     47
     48    if (!options) return;
     49
     50    psFree (options->stats);
     51    return;
     52}
     53
     54pmPSFOptions *pmPSFOptionsAlloc () {
     55
     56    pmPSFOptions *options = (pmPSFOptions *) psAlloc(sizeof(pmPSFOptions));
     57    psMemSetDeallocator(options, (psFreeFunc) pmPSFOptionsFree);
     58
     59    options->type          = 0;
     60
     61    options->stats         = NULL;
     62
     63    options->psfTrendMode  = PM_TREND_NONE;
     64    options->psfTrendNx    = 0;
     65    options->psfTrendNy    = 0;
     66    options->psfFieldNx    = 0;
     67    options->psfFieldNy    = 0;
     68    options->psfFieldXo    = 0;
     69    options->psfFieldYo    = 0;
     70
     71    options->poissonErrorsPhotLMM = true;
     72    options->poissonErrorsPhotLin = false;
     73    options->poissonErrorsParams  = true;
     74
     75    return options;
     76}
    6577
    6678/*****************************************************************************
     
    7486
    7587    psFree (psf->ChiTrend);
     88    psFree (psf->psfTrendStats);
    7689    psFree (psf->ApTrend);
    7790    psFree (psf->FluxScale);
     
    94107 Object Normalization
    95108 *****************************************************************************/
    96 pmPSF *pmPSFAlloc (pmModelType type, bool poissonErrors, psPolynomial2D *psfTrendMask)
     109pmPSF *pmPSFAlloc (pmPSFOptions *options)
    97110{
    98111    int Nparams;
    99112
    100113    pmPSF *psf = (pmPSF *) psAlloc(sizeof(pmPSF));
    101 
    102     psf->type     = type;
     114    psMemSetDeallocator(psf, (psFreeFunc) pmPSFFree);
     115
     116    psf->type     = options->type;
    103117    psf->chisq    = 0.0;
    104118    psf->ApResid  = 0.0;
     
    108122    psf->nPSFstars  = 0;
    109123    psf->nApResid   = 0;
    110     psf->poissonErrors = poissonErrors;
     124
     125    psf->poissonErrorsPhotLMM = options->poissonErrorsPhotLMM;
     126    psf->poissonErrorsPhotLin = options->poissonErrorsPhotLin;
     127    psf->poissonErrorsParams = options->poissonErrorsParams;
    111128
    112129    // the ApTrend components are (x, y).  It may be represented with a polynomial or with a
     
    121138    psf->FluxScale = NULL;
    122139
    123     if (psf->poissonErrors) {
     140    if (psf->poissonErrorsPhotLMM) {
    124141        psf->ChiTrend = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 1);
    125142    } else {
     
    133150    psf->residuals = NULL;
    134151
    135     Nparams = pmModelClassParameterCount (type);
     152    Nparams = pmModelClassParameterCount (options->type);
    136153    if (!Nparams) {
    137154        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     
    139156    }
    140157    psf->params = psArrayAlloc(Nparams);
     158   
     159    // save the trend stats on the psf for use in pmPSFFromPSFtry
     160    psf->psfTrendStats = psMemIncrRefCounter (options->stats);
    141161
    142162    // the order of the PSF parameter (X,Y) fits is determined by the psfTrendMask polynomial
     
    147167    // PM_PAR_XPOS, etc)
    148168
    149     if (psfTrendMask) {
     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    psImageBinningSetScale (binning, PS_IMAGE_BINNING_CENTER);
     175    psImageBinningSetSkipByOffset (binning, options->psfFieldXo, options->psfFieldYo);
     176
     177    psf->fieldNx = options->psfFieldNx;
     178    psf->fieldNy = options->psfFieldNy;
     179    psf->fieldXo = options->psfFieldXo;
     180    psf->fieldYo = options->psfFieldYo;
     181
     182    // define the parameter trends
     183    if (options->psfTrendMode != PM_TREND_NONE) {
    150184        for (int i = 0; i < psf->params->n; i++) {
    151             if (i == PM_PAR_SKY)
    152                 continue;
    153             if (i == PM_PAR_I0)
    154                 continue;
    155             if (i == PM_PAR_XPOS)
    156                 continue;
    157             if (i == PM_PAR_YPOS)
    158                 continue;
    159 
    160             psPolynomial2D *param = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, psfTrendMask->nX, psfTrendMask->nY);
    161             for (int nx = 0; nx < param->nX + 1; nx++) {
    162                 for (int ny = 0; ny < param->nY + 1; ny++) {
    163                     param->mask[nx][ny] = psfTrendMask->mask[nx][ny];
    164                 }
    165             }
    166             psf->params->data[i] = param;
     185            if (i == PM_PAR_SKY) continue;
     186            if (i == PM_PAR_I0) continue;
     187            if (i == PM_PAR_XPOS) continue;
     188            if (i == PM_PAR_YPOS) continue;
     189
     190            psf->params->data[i] = pmTrend2DNoImageAlloc (options->psfTrendMode, binning, options->stats);
    167191        }
    168192    }
    169 
    170     psMemSetDeallocator(psf, (psFreeFunc) pmPSFFree);
    171     return(psf);
     193    psFree (binning);
     194    return psf;
    172195}
    173196
     
    300323    va_start(ap, sxy);
    301324
    302     pmModelType type = pmModelClassGetType (typeName);
    303     psPolynomial2D *psfTrend = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 0, 0);
    304     pmPSF *psf = pmPSFAlloc (type, true, psfTrend);
     325    pmPSFOptions *options = pmPSFOptionsAlloc ();
     326    options->type = pmModelClassGetType (typeName);
     327    options->psfTrendMode = PM_TREND_POLY_ORD;
     328    options->psfTrendNx = 0;
     329    options->psfTrendNy = 0;
     330
     331    pmPSF *psf = pmPSFAlloc (options);
    305332
    306333    psVector *par = psVectorAlloc (psf->params->n, PS_TYPE_F32);
     
    311338    psEllipsePol pol = pmPSF_ModelToFit(par->data.F32);
    312339
     340    pmTrend2D *trend = NULL;
     341
    313342    // set the psf shape parameters
    314     psPolynomial2D *poly = NULL;
    315     poly = psf->params->data[PM_PAR_E0];
    316     poly->coeff[0][0] = pol.e0;
    317 
    318     poly = psf->params->data[PM_PAR_E1];
    319     poly->coeff[0][0] = pol.e1;
    320 
    321     poly = psf->params->data[PM_PAR_E2];
    322     poly->coeff[0][0] = pol.e2;
     343    trend = psf->params->data[PM_PAR_E0];
     344    trend->poly->coeff[0][0] = pol.e0;
     345
     346    trend = psf->params->data[PM_PAR_E1];
     347    trend->poly->coeff[0][0] = pol.e1;
     348
     349    trend = psf->params->data[PM_PAR_E2];
     350    trend->poly->coeff[0][0] = pol.e2;
    323351
    324352    for (int i = PM_PAR_SXY + 1; i < psf->params->n; i++) {
    325         poly = psf->params->data[i];
    326         poly->coeff[0][0] = (psF32)va_arg(ap, psF64);
     353        trend = psf->params->data[i];
     354        trend->poly->coeff[0][0] = (psF32)va_arg(ap, psF64);
    327355    }
    328356    va_end(ap);
    329357
    330358    psFree (par);
    331     psFree (psfTrend);
     359    psFree (options);
    332360    return psf;
    333361}
Note: See TracChangeset for help on using the changeset viewer.