Changeset 15000 for trunk/psModules/src/objects/pmPSF.c
- Timestamp:
- Sep 24, 2007, 11:27:58 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmPSF.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmPSF.c
r14961 r15000 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.2 8$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-09-2 1 02:46:25$8 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-09-24 21:27:58 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 41 41 42 42 /*****************************************************************************/ 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 /*****************************************************************************/63 43 /* FUNCTION IMPLEMENTATION - PUBLIC */ 64 44 /*****************************************************************************/ 45 46 static void pmPSFOptionsFree (pmPSFOptions *options) { 47 48 if (!options) return; 49 50 psFree (options->stats); 51 return; 52 } 53 54 pmPSFOptions *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 } 65 77 66 78 /***************************************************************************** … … 74 86 75 87 psFree (psf->ChiTrend); 88 psFree (psf->psfTrendStats); 76 89 psFree (psf->ApTrend); 77 90 psFree (psf->FluxScale); … … 94 107 Object Normalization 95 108 *****************************************************************************/ 96 pmPSF *pmPSFAlloc (pm ModelType type, bool poissonErrors, psPolynomial2D *psfTrendMask)109 pmPSF *pmPSFAlloc (pmPSFOptions *options) 97 110 { 98 111 int Nparams; 99 112 100 113 pmPSF *psf = (pmPSF *) psAlloc(sizeof(pmPSF)); 101 102 psf->type = type; 114 psMemSetDeallocator(psf, (psFreeFunc) pmPSFFree); 115 116 psf->type = options->type; 103 117 psf->chisq = 0.0; 104 118 psf->ApResid = 0.0; … … 108 122 psf->nPSFstars = 0; 109 123 psf->nApResid = 0; 110 psf->poissonErrors = poissonErrors; 124 125 psf->poissonErrorsPhotLMM = options->poissonErrorsPhotLMM; 126 psf->poissonErrorsPhotLin = options->poissonErrorsPhotLin; 127 psf->poissonErrorsParams = options->poissonErrorsParams; 111 128 112 129 // the ApTrend components are (x, y). It may be represented with a polynomial or with a … … 121 138 psf->FluxScale = NULL; 122 139 123 if (psf->poissonErrors ) {140 if (psf->poissonErrorsPhotLMM) { 124 141 psf->ChiTrend = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 1); 125 142 } else { … … 133 150 psf->residuals = NULL; 134 151 135 Nparams = pmModelClassParameterCount ( type);152 Nparams = pmModelClassParameterCount (options->type); 136 153 if (!Nparams) { 137 154 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); … … 139 156 } 140 157 psf->params = psArrayAlloc(Nparams); 158 159 // save the trend stats on the psf for use in pmPSFFromPSFtry 160 psf->psfTrendStats = psMemIncrRefCounter (options->stats); 141 161 142 162 // the order of the PSF parameter (X,Y) fits is determined by the psfTrendMask polynomial … … 147 167 // PM_PAR_XPOS, etc) 148 168 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) { 150 184 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); 167 191 } 168 192 } 169 170 psMemSetDeallocator(psf, (psFreeFunc) pmPSFFree); 171 return(psf); 193 psFree (binning); 194 return psf; 172 195 } 173 196 … … 300 323 va_start(ap, sxy); 301 324 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); 305 332 306 333 psVector *par = psVectorAlloc (psf->params->n, PS_TYPE_F32); … … 311 338 psEllipsePol pol = pmPSF_ModelToFit(par->data.F32); 312 339 340 pmTrend2D *trend = NULL; 341 313 342 // 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; 323 351 324 352 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); 327 355 } 328 356 va_end(ap); 329 357 330 358 psFree (par); 331 psFree ( psfTrend);359 psFree (options); 332 360 return psf; 333 361 }
Note:
See TracChangeset
for help on using the changeset viewer.
