Changeset 14652 for trunk/psModules/src/objects/models/pmModel_PGAUSS.c
- Timestamp:
- Aug 23, 2007, 2:11:02 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/models/pmModel_PGAUSS.c
r14220 r14652 19 19 *****************************************************************************/ 20 20 21 # define PM_MODEL_FUNC pmModelFunc_PGAUSS 22 # define PM_MODEL_FLUX pmModelFlux_PGAUSS 23 # define PM_MODEL_GUESS pmModelGuess_PGAUSS 24 # define PM_MODEL_LIMITS pmModelLimits_PGAUSS 25 # define PM_MODEL_RADIUS pmModelRadius_PGAUSS 26 # define PM_MODEL_FROM_PSF pmModelFromPSF_PGAUSS 27 # define PM_MODEL_FIT_STATUS pmModelFitStatus_PGAUSS 21 # define PM_MODEL_FUNC pmModelFunc_PGAUSS 22 # define PM_MODEL_FLUX pmModelFlux_PGAUSS 23 # define PM_MODEL_GUESS pmModelGuess_PGAUSS 24 # define PM_MODEL_LIMITS pmModelLimits_PGAUSS 25 # define PM_MODEL_RADIUS pmModelRadius_PGAUSS 26 # define PM_MODEL_FROM_PSF pmModelFromPSF_PGAUSS 27 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_PGAUSS 28 # define PM_MODEL_FIT_STATUS pmModelFitStatus_PGAUSS 28 29 29 30 // the model is a function of the pixel coordinate (pixcoord[0,1] = x,y) … … 66 67 # define AR_RATIO 0.99 67 68 68 // we constraint limits by the min valid minor axis:69 # define MIN_MINOR_AXIS 0.570 71 // f3 = (s_b^-2 - s_a^-2); F3_SQ_MAX is MIN_MINOR_AXIS^-472 # define F3_SQ_MAX 16.073 74 static float saveParams[8];75 76 69 bool PM_MODEL_LIMITS (psMinConstraintMode mode, int nParam, float *params, float *beta) 77 70 { … … 150 143 psAbort("invalid parameter %d for param min test", nParam); 151 144 } 152 saveParams[nParam] = params[nParam];153 145 if (params[nParam] < params_min) { 154 146 params[nParam] = params_min; … … 184 176 psAbort("invalid parameter %d for param max test", nParam); 185 177 } 186 saveParams[nParam] = params[nParam];187 178 if (params[nParam] > params_max) { 188 179 params[nParam] = params_max; … … 263 254 psF64 PM_MODEL_RADIUS (const psVector *params, psF64 flux) 264 255 { 256 psF64 z, f; 257 int Nstep = 0; 265 258 psEllipseShape shape; 266 259 … … 280 273 // this estimates the radius assuming f(z) is roughly exp(-z) 281 274 psEllipseAxes axes = psEllipseShapeToAxes (shape, 20.0); 282 psF64 radius = axes.major * sqrt (2.0 * log(PAR[PM_PAR_I0] / flux)); 275 psF64 sigma = axes.major; 276 277 psF64 limit = flux / PAR[PM_PAR_I0]; 278 279 // use the fact that f is monotonically decreasing 280 z = 0; 281 Nstep = 0; 282 283 // choose a z value guaranteed to be beyond our limit 284 float z0 = pow((1.0 / limit), (1.0 / 3.0)); 285 float z1 = (1.0 / limit); 286 z1 = PS_MAX (z0, z1); 287 z0 = 0.0; 288 289 // perform a type of bisection to find the value 290 float f0 = 1.0 / (1 + z0 + z0*z0/2.0 + z0*z0*z0/6.0); 291 float f1 = 1.0 / (1 + z1 + z1*z1/2.0 + z1*z1*z1/6.0); 292 while ((Nstep < 10) && (fabs(z1 - z0) > 0.5)) { 293 z = 0.5*(z0 + z1); 294 f = 1.0 / (1 + z + z*z/2.0 + z*z*z/6.0); 295 if (f > limit) { 296 z0 = z; 297 f0 = f; 298 } else { 299 z1 = z; 300 f1 = f; 301 } 302 Nstep ++; 303 } 304 psF64 radius = sigma * sqrt (2.0 * z); 305 306 // psF64 radius = axes.major * sqrt (2.0 * log(PAR[PM_PAR_I0] / flux)); 283 307 284 308 if (isnan(radius)) … … 297 321 298 322 // we require these two parameters to exist 299 assert (psf->params _NEW->n > PM_PAR_YPOS);300 assert (psf->params _NEW->n > PM_PAR_XPOS);301 302 for (int i = 0; i < psf->params _NEW->n; i++) {303 if (psf->params _NEW->data[i] == NULL) {323 assert (psf->params->n > PM_PAR_YPOS); 324 assert (psf->params->n > PM_PAR_XPOS); 325 326 for (int i = 0; i < psf->params->n; i++) { 327 if (psf->params->data[i] == NULL) { 304 328 out[i] = in[i]; 305 329 } else { 306 psPolynomial2D *poly = psf->params _NEW->data[i];330 psPolynomial2D *poly = psf->params->data[i]; 307 331 out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]); 308 332 } … … 322 346 // apply the model limits here: this truncates excessive extrapolation 323 347 // XXX do we need to do this still? should we put in asserts to test? 324 for (int i = 0; i < psf->params _NEW->n; i++) {348 for (int i = 0; i < psf->params->n; i++) { 325 349 // apply the limits to all components or just the psf-model parameters? 326 if (psf->params _NEW->data[i] == NULL)350 if (psf->params->data[i] == NULL) 327 351 continue; 328 352 … … 339 363 } 340 364 365 // construct the PSF model from the FLT model and the psf 366 // XXX is this sufficiently general do be a global function, not a pmModelClass function? 367 bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io) 368 { 369 psF32 *PAR = model->params->data.F32; 370 371 // we require these two parameters to exist 372 assert (psf->params->n > PM_PAR_YPOS); 373 assert (psf->params->n > PM_PAR_XPOS); 374 375 PAR[PM_PAR_SKY] = 0.0; 376 PAR[PM_PAR_I0] = Io; 377 PAR[PM_PAR_XPOS] = Xo; 378 PAR[PM_PAR_YPOS] = Yo; 379 380 // supply the model-fitted parameters, or copy from the input 381 for (int i = 0; i < psf->params->n; i++) { 382 if (i == PM_PAR_SKY) continue; 383 if (i == PM_PAR_I0) continue; 384 if (i == PM_PAR_XPOS) continue; 385 if (i == PM_PAR_YPOS) continue; 386 psPolynomial2D *poly = psf->params->data[i]; 387 assert (poly); 388 PAR[i] = psPolynomial2DEval(poly, Xo, Yo); 389 } 390 391 // the 2D PSF model fits polarization terms (E0,E1,E2) 392 // convert to shape terms (SXX,SYY,SXY) 393 // XXX user-defined value for limit? 394 if (!pmPSF_FitToModel (PAR, 0.1)) { 395 psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo); 396 return false; 397 } 398 399 // apply the model limits here: this truncates excessive extrapolation 400 // XXX do we need to do this still? should we put in asserts to test? 401 for (int i = 0; i < psf->params->n; i++) { 402 // apply the limits to all components or just the psf-model parameters? 403 if (psf->params->data[i] == NULL) 404 continue; 405 406 bool status = true; 407 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL); 408 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL); 409 if (!status) { 410 psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo); 411 model->flags |= PM_MODEL_STATUS_LIMITS; 412 } 413 } 414 return(true); 415 } 416 341 417 bool PM_MODEL_FIT_STATUS (pmModel *model) 342 418 { … … 367 443 # undef PM_MODEL_RADIUS 368 444 # undef PM_MODEL_FROM_PSF 445 # undef PM_MODEL_PARAMS_FROM_PSF 369 446 # undef PM_MODEL_FIT_STATUS
Note:
See TracChangeset
for help on using the changeset viewer.
