Changeset 14652
- Timestamp:
- Aug 23, 2007, 2:11:02 PM (19 years ago)
- Location:
- trunk/psModules/src/objects
- Files:
-
- 7 added
- 35 edited
-
Makefile.am (modified) (3 diffs)
-
models/pmModel_GAUSS.c (modified) (9 diffs)
-
models/pmModel_PGAUSS.c (modified) (10 diffs)
-
models/pmModel_QGAUSS.c (modified) (5 diffs)
-
models/pmModel_RGAUSS.c (modified) (5 diffs)
-
models/pmModel_SERSIC.c (modified) (5 diffs)
-
pmGrowthCurve.c (modified) (2 diffs)
-
pmModel.c (modified) (14 diffs)
-
pmModel.h (modified) (7 diffs)
-
pmModelClass.c (added)
-
pmModelClass.h (added)
-
pmModelGroup.c (modified) (3 diffs)
-
pmModelGroup.h (modified) (4 diffs)
-
pmModelUtils.c (modified) (3 diffs)
-
pmModelUtils.h (added)
-
pmPSF.c (modified) (10 diffs)
-
pmPSF.h (modified) (4 diffs)
-
pmPSF_IO.c (modified) (29 diffs)
-
pmPSF_IO.h (modified) (2 diffs)
-
pmPSFtry.c (modified) (7 diffs)
-
pmPeaks.c (modified) (14 diffs)
-
pmPeaks.h (modified) (5 diffs)
-
pmSource.c (modified) (7 diffs)
-
pmSource.h (modified) (5 diffs)
-
pmSourceContour.c (modified) (2 diffs)
-
pmSourceFitModel.c (modified) (7 diffs)
-
pmSourceFitSet.c (added)
-
pmSourceFitSet.h (added)
-
pmSourceIO.c (modified) (2 diffs)
-
pmSourceIO_CMP.c (modified) (3 diffs)
-
pmSourceIO_OBJ.c (modified) (2 diffs)
-
pmSourceIO_PS1_DEV_0.c (modified) (3 diffs)
-
pmSourceIO_RAW.c (modified) (2 diffs)
-
pmSourceIO_SMPDATA.c (modified) (3 diffs)
-
pmSourceIO_SX.c (modified) (2 diffs)
-
pmSourcePhotometry.c (modified) (5 diffs)
-
pmSourcePlotApResid.c (modified) (2 diffs)
-
pmSourcePlotMoments.c (modified) (2 diffs)
-
pmSourcePlotPSFModel.c (modified) (2 diffs)
-
pmSourceSky.c (modified) (2 diffs)
-
pmSourceUtils.c (added)
-
pmSourceUtils.h (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/Makefile.am
r14472 r14652 7 7 pmMoments.c \ 8 8 pmModel.c \ 9 pmModelGroup.c \ 9 pmModelClass.c \ 10 pmModelUtils.c \ 10 11 pmSource.c \ 12 pmSourceUtils.c \ 11 13 pmSourceSky.c \ 12 14 pmSourceContour.c \ 13 15 pmSourceFitModel.c \ 16 pmSourceFitSet.c \ 14 17 pmSourcePhotometry.c \ 15 18 pmSourceIO.c \ … … 31 34 32 35 EXTRA_DIST = \ 33 models/pmModel_GAUSS.c \34 models/pmModel_PGAUSS.c \35 models/pmModel_QGAUSS.c \36 models/pmModel_SGAUSS.c \37 models/pmModel_RGAUSS.c \38 models/pmModel_SERSIC.c36 models/pmModel_GAUSS.c \ 37 models/pmModel_PGAUSS.c \ 38 models/pmModel_QGAUSS.c \ 39 models/pmModel_SGAUSS.c \ 40 models/pmModel_RGAUSS.c \ 41 models/pmModel_SERSIC.c 39 42 40 43 pkginclude_HEADERS = \ … … 42 45 pmMoments.h \ 43 46 pmModel.h \ 44 pmModelGroup.h \ 47 pmModelClass.h \ 48 pmModelUtils.h \ 45 49 pmSource.h \ 50 pmSourceUtils.h \ 46 51 pmSourceSky.h \ 47 52 pmSourceContour.h \ 48 53 pmSourceFitModel.h \ 54 pmSourceFitSet.h \ 49 55 pmSourcePhotometry.h \ 50 56 pmSourceIO.h \ -
trunk/psModules/src/objects/models/pmModel_GAUSS.c
r14220 r14652 19 19 *****************************************************************************/ 20 20 21 # define PM_MODEL_FUNC pmModelFunc_GAUSS 22 # define PM_MODEL_FLUX pmModelFlux_GAUSS 23 # define PM_MODEL_GUESS pmModelGuess_GAUSS 24 # define PM_MODEL_LIMITS pmModelLimits_GAUSS 25 # define PM_MODEL_RADIUS pmModelRadius_GAUSS 26 # define PM_MODEL_FROM_PSF pmModelFromPSF_GAUSS 27 # define PM_MODEL_FIT_STATUS pmModelFitStatus_GAUSS 28 21 # define PM_MODEL_FUNC pmModelFunc_GAUSS 22 # define PM_MODEL_FLUX pmModelFlux_GAUSS 23 # define PM_MODEL_GUESS pmModelGuess_GAUSS 24 # define PM_MODEL_LIMITS pmModelLimits_GAUSS 25 # define PM_MODEL_RADIUS pmModelRadius_GAUSS 26 # define PM_MODEL_FROM_PSF pmModelFromPSF_GAUSS 27 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_GAUSS 28 # define PM_MODEL_FIT_STATUS pmModelFitStatus_GAUSS 29 30 // the model is a function of the pixel coordinate (pixcoord[0,1] = x,y) 29 31 psF32 PM_MODEL_FUNC(psVector *deriv, 30 32 const psVector *params, … … 38 40 psF32 py = Y / PAR[PM_PAR_SYY]; 39 41 psF32 z = PS_SQR(px) + PS_SQR(py) + PAR[PM_PAR_SXY]*X*Y; 42 assert (z >= 0.0); 43 40 44 psF32 r = exp(-z); 41 45 psF32 q = PAR[PM_PAR_I0]*r; … … 61 65 # define AR_MAX 20.0 62 66 # define AR_RATIO 0.99 67 63 68 bool PM_MODEL_LIMITS (psMinConstraintMode mode, int nParam, float *params, float *beta) 64 69 { … … 93 98 break; 94 99 case PM_PAR_SXX: 95 beta_lim = 0.5;100 beta_lim = 2.0; 96 101 break; 97 102 case PM_PAR_SYY: 98 beta_lim = 0.5;103 beta_lim = 2.0; 99 104 break; 100 105 case PM_PAR_SXY: … … 257 262 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf) 258 263 { 259 260 264 psF32 *out = modelPSF->params->data.F32; 261 265 psF32 *in = modelFLT->params->data.F32; 262 266 263 267 // we require these two parameters to exist 264 assert (psf->params _NEW->n > PM_PAR_YPOS);265 assert (psf->params _NEW->n > PM_PAR_XPOS);268 assert (psf->params->n > PM_PAR_YPOS); 269 assert (psf->params->n > PM_PAR_XPOS); 266 270 267 271 // supply the model-fitted parameters, or copy from the input 268 for (int i = 0; i < psf->params _NEW->n; i++) {269 if (psf->params _NEW->data[i] == NULL) {272 for (int i = 0; i < psf->params->n; i++) { 273 if (psf->params->data[i] == NULL) { 270 274 out[i] = in[i]; 271 275 } else { 272 psPolynomial2D *poly = psf->params _NEW->data[i];276 psPolynomial2D *poly = psf->params->data[i]; 273 277 out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]); 274 278 } … … 289 293 // apply the model limits here: this truncates excessive extrapolation 290 294 // XXX do we need to do this still? should we put in asserts to test? 291 for (int i = 0; i < psf->params _NEW->n; i++) {295 for (int i = 0; i < psf->params->n; i++) { 292 296 // apply the limits to all components or just the psf-model parameters? 293 if (psf->params _NEW->data[i] == NULL)297 if (psf->params->data[i] == NULL) 294 298 continue; 295 299 … … 306 310 } 307 311 312 // construct the PSF model from the FLT model and the psf 313 // XXX is this sufficiently general do be a global function, not a pmModelClass function? 314 bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io) 315 { 316 psF32 *PAR = model->params->data.F32; 317 318 // we require these two parameters to exist 319 assert (psf->params->n > PM_PAR_YPOS); 320 assert (psf->params->n > PM_PAR_XPOS); 321 322 PAR[PM_PAR_SKY] = 0.0; 323 PAR[PM_PAR_I0] = Io; 324 PAR[PM_PAR_XPOS] = Xo; 325 PAR[PM_PAR_YPOS] = Yo; 326 327 // supply the model-fitted parameters, or copy from the input 328 for (int i = 0; i < psf->params->n; i++) { 329 if (i == PM_PAR_SKY) continue; 330 if (i == PM_PAR_I0) continue; 331 if (i == PM_PAR_XPOS) continue; 332 if (i == PM_PAR_YPOS) continue; 333 psPolynomial2D *poly = psf->params->data[i]; 334 assert (poly); 335 PAR[i] = psPolynomial2DEval(poly, Xo, Yo); 336 } 337 338 // the 2D PSF model fits polarization terms (E0,E1,E2) 339 // convert to shape terms (SXX,SYY,SXY) 340 // XXX user-defined value for limit? 341 if (!pmPSF_FitToModel (PAR, 0.1)) { 342 psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo); 343 return false; 344 } 345 346 // apply the model limits here: this truncates excessive extrapolation 347 // XXX do we need to do this still? should we put in asserts to test? 348 for (int i = 0; i < psf->params->n; i++) { 349 // apply the limits to all components or just the psf-model parameters? 350 if (psf->params->data[i] == NULL) 351 continue; 352 353 bool status = true; 354 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL); 355 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL); 356 if (!status) { 357 psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo); 358 model->flags |= PM_MODEL_STATUS_LIMITS; 359 } 360 } 361 return(true); 362 } 363 308 364 // check the status of the fitted model 309 365 // this test is invalid if the parameters are derived … … 311 367 bool PM_MODEL_FIT_STATUS (pmModel *model) 312 368 { 313 314 369 psF32 dP; 315 370 bool status; … … 339 394 # undef PM_MODEL_RADIUS 340 395 # undef PM_MODEL_FROM_PSF 396 # undef PM_MODEL_PARAMS_FROM_PSF 341 397 # undef PM_MODEL_FIT_STATUS -
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 -
trunk/psModules/src/objects/models/pmModel_QGAUSS.c
r14344 r14652 20 20 *****************************************************************************/ 21 21 22 # define PM_MODEL_FUNC pmModelFunc_QGAUSS 23 # define PM_MODEL_FLUX pmModelFlux_QGAUSS 24 # define PM_MODEL_GUESS pmModelGuess_QGAUSS 25 # define PM_MODEL_LIMITS pmModelLimits_QGAUSS 26 # define PM_MODEL_RADIUS pmModelRadius_QGAUSS 27 # define PM_MODEL_FROM_PSF pmModelFromPSF_QGAUSS 28 # define PM_MODEL_FIT_STATUS pmModelFitStatus_QGAUSS 22 # define PM_MODEL_FUNC pmModelFunc_QGAUSS 23 # define PM_MODEL_FLUX pmModelFlux_QGAUSS 24 # define PM_MODEL_GUESS pmModelGuess_QGAUSS 25 # define PM_MODEL_LIMITS pmModelLimits_QGAUSS 26 # define PM_MODEL_RADIUS pmModelRadius_QGAUSS 27 # define PM_MODEL_FROM_PSF pmModelFromPSF_QGAUSS 28 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_QGAUSS 29 # define PM_MODEL_FIT_STATUS pmModelFitStatus_QGAUSS 29 30 30 31 psF32 PM_MODEL_FUNC (psVector *deriv, … … 350 351 351 352 // we require these two parameters to exist 352 assert (psf->params _NEW->n > PM_PAR_YPOS);353 assert (psf->params _NEW->n > PM_PAR_XPOS);354 355 for (int i = 0; i < psf->params _NEW->n; i++) {356 if (psf->params _NEW->data[i] == NULL) {353 assert (psf->params->n > PM_PAR_YPOS); 354 assert (psf->params->n > PM_PAR_XPOS); 355 356 for (int i = 0; i < psf->params->n; i++) { 357 if (psf->params->data[i] == NULL) { 357 358 out[i] = in[i]; 358 359 } else { 359 psPolynomial2D *poly = psf->params _NEW->data[i];360 psPolynomial2D *poly = psf->params->data[i]; 360 361 out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]); 361 362 } … … 372 373 // apply the model limits here: this truncates excessive extrapolation 373 374 // XXX do we need to do this still? should we put in asserts to test? 374 for (int i = 0; i < psf->params _NEW->n; i++) {375 for (int i = 0; i < psf->params->n; i++) { 375 376 // apply the limits to all components or just the psf-model parameters? 376 if (psf->params _NEW->data[i] == NULL)377 if (psf->params->data[i] == NULL) 377 378 continue; 378 379 … … 390 391 } 391 392 393 // construct the PSF model from the FLT model and the psf 394 // XXX is this sufficiently general do be a global function, not a pmModelClass function? 395 bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io) 396 { 397 psF32 *PAR = model->params->data.F32; 398 399 // we require these two parameters to exist 400 assert (psf->params->n > PM_PAR_YPOS); 401 assert (psf->params->n > PM_PAR_XPOS); 402 403 PAR[PM_PAR_SKY] = 0.0; 404 PAR[PM_PAR_I0] = Io; 405 PAR[PM_PAR_XPOS] = Xo; 406 PAR[PM_PAR_YPOS] = Yo; 407 408 // supply the model-fitted parameters, or copy from the input 409 for (int i = 0; i < psf->params->n; i++) { 410 if (i == PM_PAR_SKY) continue; 411 if (i == PM_PAR_I0) continue; 412 if (i == PM_PAR_XPOS) continue; 413 if (i == PM_PAR_YPOS) continue; 414 psPolynomial2D *poly = psf->params->data[i]; 415 assert (poly); 416 PAR[i] = psPolynomial2DEval(poly, Xo, Yo); 417 } 418 419 // the 2D PSF model fits polarization terms (E0,E1,E2) 420 // convert to shape terms (SXX,SYY,SXY) 421 // XXX user-defined value for limit? 422 if (!pmPSF_FitToModel (PAR, 0.1)) { 423 psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo); 424 return false; 425 } 426 427 // apply the model limits here: this truncates excessive extrapolation 428 // XXX do we need to do this still? should we put in asserts to test? 429 for (int i = 0; i < psf->params->n; i++) { 430 // apply the limits to all components or just the psf-model parameters? 431 if (psf->params->data[i] == NULL) 432 continue; 433 434 bool status = true; 435 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL); 436 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL); 437 if (!status) { 438 psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo); 439 model->flags |= PM_MODEL_STATUS_LIMITS; 440 } 441 } 442 return(true); 443 } 444 392 445 bool PM_MODEL_FIT_STATUS (pmModel *model) 393 446 { … … 418 471 # undef PM_MODEL_RADIUS 419 472 # undef PM_MODEL_FROM_PSF 473 # undef PM_MODEL_PARAMS_FROM_PSF 420 474 # undef PM_MODEL_FIT_STATUS -
trunk/psModules/src/objects/models/pmModel_RGAUSS.c
r14323 r14652 20 20 *****************************************************************************/ 21 21 22 # define PM_MODEL_FUNC pmModelFunc_RGAUSS 23 # define PM_MODEL_FLUX pmModelFlux_RGAUSS 24 # define PM_MODEL_GUESS pmModelGuess_RGAUSS 25 # define PM_MODEL_LIMITS pmModelLimits_RGAUSS 26 # define PM_MODEL_RADIUS pmModelRadius_RGAUSS 27 # define PM_MODEL_FROM_PSF pmModelFromPSF_RGAUSS 28 # define PM_MODEL_FIT_STATUS pmModelFitStatus_RGAUSS 22 # define PM_MODEL_FUNC pmModelFunc_RGAUSS 23 # define PM_MODEL_FLUX pmModelFlux_RGAUSS 24 # define PM_MODEL_GUESS pmModelGuess_RGAUSS 25 # define PM_MODEL_LIMITS pmModelLimits_RGAUSS 26 # define PM_MODEL_RADIUS pmModelRadius_RGAUSS 27 # define PM_MODEL_FROM_PSF pmModelFromPSF_RGAUSS 28 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_RGAUSS 29 # define PM_MODEL_FIT_STATUS pmModelFitStatus_RGAUSS 29 30 30 31 psF32 PM_MODEL_FUNC (psVector *deriv, … … 343 344 344 345 // we require these two parameters to exist 345 assert (psf->params _NEW->n > PM_PAR_YPOS);346 assert (psf->params _NEW->n > PM_PAR_XPOS);347 348 for (int i = 0; i < psf->params _NEW->n; i++) {349 if (psf->params _NEW->data[i] == NULL) {346 assert (psf->params->n > PM_PAR_YPOS); 347 assert (psf->params->n > PM_PAR_XPOS); 348 349 for (int i = 0; i < psf->params->n; i++) { 350 if (psf->params->data[i] == NULL) { 350 351 out[i] = in[i]; 351 352 } else { 352 psPolynomial2D *poly = psf->params _NEW->data[i];353 psPolynomial2D *poly = psf->params->data[i]; 353 354 out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]); 354 355 } … … 365 366 // apply the model limits here: this truncates excessive extrapolation 366 367 // XXX do we need to do this still? should we put in asserts to test? 367 for (int i = 0; i < psf->params _NEW->n; i++) {368 for (int i = 0; i < psf->params->n; i++) { 368 369 // apply the limits to all components or just the psf-model parameters? 369 if (psf->params _NEW->data[i] == NULL)370 if (psf->params->data[i] == NULL) 370 371 continue; 371 372 … … 383 384 } 384 385 386 // construct the PSF model from the FLT model and the psf 387 // XXX is this sufficiently general do be a global function, not a pmModelClass function? 388 bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io) 389 { 390 psF32 *PAR = model->params->data.F32; 391 392 // we require these two parameters to exist 393 assert (psf->params->n > PM_PAR_YPOS); 394 assert (psf->params->n > PM_PAR_XPOS); 395 396 PAR[PM_PAR_SKY] = 0.0; 397 PAR[PM_PAR_I0] = Io; 398 PAR[PM_PAR_XPOS] = Xo; 399 PAR[PM_PAR_YPOS] = Yo; 400 401 // supply the model-fitted parameters, or copy from the input 402 for (int i = 0; i < psf->params->n; i++) { 403 if (i == PM_PAR_SKY) continue; 404 if (i == PM_PAR_I0) continue; 405 if (i == PM_PAR_XPOS) continue; 406 if (i == PM_PAR_YPOS) continue; 407 psPolynomial2D *poly = psf->params->data[i]; 408 assert (poly); 409 PAR[i] = psPolynomial2DEval(poly, Xo, Yo); 410 } 411 412 // the 2D PSF model fits polarization terms (E0,E1,E2) 413 // convert to shape terms (SXX,SYY,SXY) 414 // XXX user-defined value for limit? 415 if (!pmPSF_FitToModel (PAR, 0.1)) { 416 psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo); 417 return false; 418 } 419 420 // apply the model limits here: this truncates excessive extrapolation 421 // XXX do we need to do this still? should we put in asserts to test? 422 for (int i = 0; i < psf->params->n; i++) { 423 // apply the limits to all components or just the psf-model parameters? 424 if (psf->params->data[i] == NULL) 425 continue; 426 427 bool status = true; 428 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL); 429 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL); 430 if (!status) { 431 psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo); 432 model->flags |= PM_MODEL_STATUS_LIMITS; 433 } 434 } 435 return(true); 436 } 437 385 438 bool PM_MODEL_FIT_STATUS (pmModel *model) 386 439 { … … 411 464 # undef PM_MODEL_RADIUS 412 465 # undef PM_MODEL_FROM_PSF 466 # undef PM_MODEL_PARAMS_FROM_PSF 413 467 # undef PM_MODEL_FIT_STATUS -
trunk/psModules/src/objects/models/pmModel_SERSIC.c
r14345 r14652 23 23 *****************************************************************************/ 24 24 25 # define PM_MODEL_FUNC pmModelFunc_SERSIC 26 # define PM_MODEL_FLUX pmModelFlux_SERSIC 27 # define PM_MODEL_GUESS pmModelGuess_SERSIC 28 # define PM_MODEL_LIMITS pmModelLimits_SERSIC 29 # define PM_MODEL_RADIUS pmModelRadius_SERSIC 30 # define PM_MODEL_FROM_PSF pmModelFromPSF_SERSIC 31 # define PM_MODEL_FIT_STATUS pmModelFitStatus_SERSIC 25 # define PM_MODEL_FUNC pmModelFunc_SERSIC 26 # define PM_MODEL_FLUX pmModelFlux_SERSIC 27 # define PM_MODEL_GUESS pmModelGuess_SERSIC 28 # define PM_MODEL_LIMITS pmModelLimits_SERSIC 29 # define PM_MODEL_RADIUS pmModelRadius_SERSIC 30 # define PM_MODEL_FROM_PSF pmModelFromPSF_SERSIC 31 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_SERSIC 32 # define PM_MODEL_FIT_STATUS pmModelFitStatus_SERSIC 32 33 33 34 psF32 PM_MODEL_FUNC (psVector *deriv, … … 360 361 361 362 // we require these two parameters to exist 362 assert (psf->params _NEW->n > PM_PAR_YPOS);363 assert (psf->params _NEW->n > PM_PAR_XPOS);364 365 for (int i = 0; i < psf->params _NEW->n; i++) {366 if (psf->params _NEW->data[i] == NULL) {363 assert (psf->params->n > PM_PAR_YPOS); 364 assert (psf->params->n > PM_PAR_XPOS); 365 366 for (int i = 0; i < psf->params->n; i++) { 367 if (psf->params->data[i] == NULL) { 367 368 out[i] = in[i]; 368 369 } else { 369 psPolynomial2D *poly = psf->params _NEW->data[i];370 psPolynomial2D *poly = psf->params->data[i]; 370 371 out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]); 371 372 } … … 382 383 // apply the model limits here: this truncates excessive extrapolation 383 384 // XXX do we need to do this still? should we put in asserts to test? 384 for (int i = 0; i < psf->params _NEW->n; i++) {385 for (int i = 0; i < psf->params->n; i++) { 385 386 // apply the limits to all components or just the psf-model parameters? 386 if (psf->params _NEW->data[i] == NULL)387 if (psf->params->data[i] == NULL) 387 388 continue; 388 389 … … 400 401 } 401 402 403 // construct the PSF model from the FLT model and the psf 404 // XXX is this sufficiently general do be a global function, not a pmModelClass function? 405 bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io) 406 { 407 psF32 *PAR = model->params->data.F32; 408 409 // we require these two parameters to exist 410 assert (psf->params->n > PM_PAR_YPOS); 411 assert (psf->params->n > PM_PAR_XPOS); 412 413 PAR[PM_PAR_SKY] = 0.0; 414 PAR[PM_PAR_I0] = Io; 415 PAR[PM_PAR_XPOS] = Xo; 416 PAR[PM_PAR_YPOS] = Yo; 417 418 // supply the model-fitted parameters, or copy from the input 419 for (int i = 0; i < psf->params->n; i++) { 420 if (i == PM_PAR_SKY) continue; 421 if (i == PM_PAR_I0) continue; 422 if (i == PM_PAR_XPOS) continue; 423 if (i == PM_PAR_YPOS) continue; 424 psPolynomial2D *poly = psf->params->data[i]; 425 assert (poly); 426 PAR[i] = psPolynomial2DEval(poly, Xo, Yo); 427 } 428 429 // the 2D PSF model fits polarization terms (E0,E1,E2) 430 // convert to shape terms (SXX,SYY,SXY) 431 // XXX user-defined value for limit? 432 if (!pmPSF_FitToModel (PAR, 0.1)) { 433 psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo); 434 return false; 435 } 436 437 // apply the model limits here: this truncates excessive extrapolation 438 // XXX do we need to do this still? should we put in asserts to test? 439 for (int i = 0; i < psf->params->n; i++) { 440 // apply the limits to all components or just the psf-model parameters? 441 if (psf->params->data[i] == NULL) 442 continue; 443 444 bool status = true; 445 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL); 446 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL); 447 if (!status) { 448 psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo); 449 model->flags |= PM_MODEL_STATUS_LIMITS; 450 } 451 } 452 return(true); 453 } 454 402 455 bool PM_MODEL_FIT_STATUS (pmModel *model) 403 456 { … … 428 481 # undef PM_MODEL_RADIUS 429 482 # undef PM_MODEL_FROM_PSF 483 # undef PM_MODEL_PARAMS_FROM_PSF 430 484 # undef PM_MODEL_FIT_STATUS -
trunk/psModules/src/objects/pmGrowthCurve.c
r12949 r14652 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 4-21 19:47:14$7 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-08-24 00:11:02 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 23 #include "pmMoments.h" 24 24 #include "pmResiduals.h" 25 #include "pmGrowthCurve.h" 26 #include "pmPSF.h" 25 27 #include "pmModel.h" 26 28 #include "pmSource.h" 27 #include "pmGrowthCurve.h"28 #include "pmPSF.h"29 29 #include "psVectorBracket.h" 30 30 -
trunk/psModules/src/objects/pmModel.c
r13898 r14652 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 6-20 02:22:26$8 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 21 21 #include <string.h> 22 22 #include <pslib.h> 23 #include "pmHDU.h" 24 #include "pmFPA.h" 23 25 #include "pmResiduals.h" 26 #include "pmGrowthCurve.h" 27 #include "pmPSF.h" 24 28 #include "pmModel.h" 25 26 /* The following types and functions need to be known by pmModel.c and are defined in 27 pmModelGroup.h. The use of pmSource and other types in pmModelGroup.h prevent us from 28 directly including it here ***/ 29 30 typedef psMinimizeLMChi2Func pmModelFunc; 31 typedef bool (*pmModelFitStatusFunc)(pmModel *model); 32 pmModelFunc pmModelFunc_GetFunction (pmModelType type); 33 pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type); 34 int pmModelParameterCount(pmModelType type); 29 #include "pmModelClass.h" 35 30 36 31 static void modelFree(pmModel *tmp) … … 45 40 pmModelAlloc(): Allocate the pmModel structure, along with its parameters, 46 41 and initialize the type member. Initialize the params to 0.0. 47 XXX EAM: simplifying code with pmModelParameterCount48 42 *****************************************************************************/ 49 43 pmModel *pmModelAlloc(pmModelType type) … … 53 47 pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel)); 54 48 psMemSetDeallocator(tmp, (psFreeFunc) modelFree); 49 50 pmModelClass *class = pmModelClassSelect (type); 51 if (class == NULL) { 52 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 53 return(NULL); 54 } 55 55 56 56 tmp->type = type; … … 62 62 tmp->residuals = NULL; // XXX should the model own this memory? 63 63 64 psS32 Nparams = pmModelParameterCount(type); 65 if (Nparams == 0) { 66 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 67 return(NULL); 68 } 64 psS32 Nparams = pmModelClassParameterCount(type); 65 assert (Nparams); 69 66 70 67 tmp->params = psVectorAlloc(Nparams, PS_TYPE_F32); 71 68 tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32); 69 assert (tmp->params); 70 assert (tmp->dparams); 72 71 73 72 for (psS32 i = 0; i < tmp->params->n; i++) { … … 75 74 tmp->dparams->data.F32[i] = 0.0; 76 75 } 76 77 tmp->modelFunc = class->modelFunc; 78 tmp->modelFlux = class->modelFlux; 79 tmp->modelRadius = class->modelRadius; 80 tmp->modelLimits = class->modelLimits; 81 tmp->modelGuess = class->modelGuess; 82 tmp->modelFromPSF = class->modelFromPSF; 83 tmp->modelParamsFromPSF = class->modelParamsFromPSF; 84 tmp->modelFitStatus = class->modelFitStatus; 77 85 78 86 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); … … 92 100 new->radiusFit = model->radiusFit; 93 101 94 // XXX note that model->residuals is just a reference95 new->residuals = model->residuals;96 97 102 for (int i = 0; i < new->params->n; i++) { 98 103 new->params->data.F32[i] = model->params->data.F32[i]; 99 104 new->dparams->data.F32[i] = model->dparams->data.F32[i]; 100 105 } 106 107 // note that model->residuals is just a reference 108 new->residuals = model->residuals; 101 109 102 110 return (new); … … 123 131 x->data.F32[1] = (psF32) (row + image->row0); 124 132 psF32 tmpF; 125 pmModelFunc modelFunc; 126 127 modelFunc = pmModelFunc_GetFunction (model->type); 128 tmpF = modelFunc (NULL, model->params, x); 133 134 tmpF = model->modelFunc (NULL, model->params, x); 135 psFree(x); 136 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); 137 return(tmpF); 138 } 139 140 psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, psS32 col, psS32 row, int dx, int dy) 141 { 142 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 143 PS_ASSERT_PTR_NON_NULL(image, false); 144 PS_ASSERT_PTR_NON_NULL(model, false); 145 PS_ASSERT_PTR_NON_NULL(model->params, false); 146 147 // Allocate the x coordinate structure and convert row/col to image space. 148 // 149 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 150 x->data.F32[0] = (psF32) (col + image->col0 + dx); 151 x->data.F32[1] = (psF32) (row + image->row0 + dy); 152 psF32 tmpF; 153 154 tmpF = model->modelFunc (NULL, model->params, x); 129 155 psFree(x); 130 156 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); … … 137 163 pmModelOpMode mode, 138 164 bool add, 139 psMaskType maskVal 165 psMaskType maskVal, 166 int dx, 167 int dy 140 168 ) 141 169 { … … 148 176 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 149 177 psVector *params = model->params; 150 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type); 178 151 179 psS32 imageCol; 152 180 psS32 imageRow; … … 209 237 // Convert i/j to image coord space: 210 238 // XXX should we use using 0.5 pixel offset? 211 imageCol = ix + image->col0 ;212 imageRow = iy + image->row0 ;239 imageCol = ix + image->col0 + dx; 240 imageRow = iy + image->row0 + dy; 213 241 214 242 x->data.F32[0] = (float) imageCol; … … 219 247 // add in the desired components for this coordinate 220 248 if (mode & PM_MODEL_OP_FUNC) { 221 pixelValue += model Func (NULL, params, x);249 pixelValue += model->modelFunc (NULL, params, x); 222 250 } 223 251 … … 280 308 { 281 309 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 282 psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal );310 psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, 0.0, 0.0); 283 311 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 284 312 return(rc); … … 294 322 { 295 323 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 296 psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal );324 psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, 0.0, 0.0); 297 325 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 298 326 return(rc); 299 327 } 300 328 301 // check for success of model fit 302 bool pmModelFitStatus (pmModel *model) 303 { 304 305 bool status; 306 307 pmModelFitStatusFunc statusFunc = pmModelFitStatusFunc_GetFunction (model->type); 308 status = statusFunc (model); 309 310 return (status); 311 } 312 329 /****************************************************************************** 330 *****************************************************************************/ 331 bool pmModelAddWithOffset(psImage *image, 332 psImage *mask, 333 pmModel *model, 334 pmModelOpMode mode, 335 psMaskType maskVal, 336 int dx, 337 int dy) 338 { 339 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 340 psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, dx, dy); 341 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 342 return(rc); 343 } 344 345 /****************************************************************************** 346 *****************************************************************************/ 347 bool pmModelSubWithOffset(psImage *image, 348 psImage *mask, 349 pmModel *model, 350 pmModelOpMode mode, 351 psMaskType maskVal, 352 int dx, 353 int dy) 354 { 355 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 356 psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, dx, dy); 357 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 358 return(rc); 359 } -
trunk/psModules/src/objects/pmModel.h
r13898 r14652 1 /* @file pm Objects.h1 /* @file pmModel.h 2 2 * @brief Functions to define and manipulate object models 3 3 * … … 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 6-20 02:22:26$7 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-08-24 00:11:02 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 17 17 /// @{ 18 18 19 / / type of model carried by the pmModel structure20 typedef int pmModelType; 19 /* pointers for the functions types below are supplied to each pmModel, and can be used by 20 the programmer without needing to know the model class */ 21 21 22 22 typedef enum { … … 41 41 } pmModelOpMode; 42 42 43 typedef struct pmModel pmModel; 44 typedef struct pmSource pmSource; 45 46 // This function is the model chi-square minimization function for this model. 47 typedef psMinimizeLMChi2Func pmModelFunc; 48 49 // This function sets the parameter limits for this model. 50 typedef psMinimizeLMLimitFunc pmModelLimits; 51 52 // This function returns the integrated flux for the given model parameters. 53 typedef psF64 (*pmModelFlux)(const psVector *params); 54 55 // This function returns the radius at which the given model and parameters 56 // achieves the given flux. 57 typedef psF64 (*pmModelRadius)(const psVector *params, double flux); 58 59 // This function provides the model guess parameters based on the details of 60 // the given source. 61 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source); 62 63 // This function constructs the PSF model for the given source based on the 64 // supplied psf and the EXT model for the object. 65 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf); 66 67 // This function sets the model parameters based on the PSF for a given coordinate and central 68 // intensity 69 typedef bool (*pmModelParamsFromPSF)(pmModel *model, pmPSF *psf, float Xo, float Yo, float Io); 70 71 // This function returns the success / failure status of the given model fit 72 typedef bool (*pmModelFitStatusFunc)(pmModel *model); 73 43 74 /** pmModel data structure 44 75 * … … 50 81 * 51 82 */ 52 typedef struct 53 { 83 struct pmModel { 54 84 pmModelType type; ///< Model to be used. 55 85 psVector *params; ///< Paramater values. … … 62 92 float radiusFit; ///< fit radius actually used 63 93 pmResiduals *residuals; ///< normalized PSF residuals 64 }65 pmModel;66 94 67 /* XXX we are currently saving the residuals with the pmModel. It might be better to save this 68 * in the pmSource. we may want an API to Add/Sub a pmModel (analytical model only) or a 69 * pmSource (analytical + residuals). 70 */ 95 // functions for this model which depend on the model class 96 pmModelFunc modelFunc; 97 pmModelFlux modelFlux; 98 pmModelRadius modelRadius; 99 pmModelLimits modelLimits; 100 pmModelGuessFunc modelGuess; 101 pmModelFromPSFFunc modelFromPSF; 102 pmModelParamsFromPSF modelParamsFromPSF; 103 pmModelFitStatusFunc modelFitStatus; 104 }; 71 105 72 106 /** Symbolic names for the elements of [d]params … … 130 164 ); 131 165 166 bool pmModelAddWithOffset(psImage *image, 167 psImage *mask, 168 pmModel *model, 169 pmModelOpMode mode, 170 psMaskType maskVal, 171 int dx, 172 int dy); 173 174 bool pmModelSubWithOffset(psImage *image, 175 psImage *mask, 176 pmModel *model, 177 pmModelOpMode mode, 178 psMaskType maskVal, 179 int dx, 180 int dy); 181 132 182 /** pmModelFitStatus() 133 183 * -
trunk/psModules/src/objects/pmModelGroup.c
r14325 r14652 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.1 7$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 7-20 00:31:43$8 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 28 #include "pmResiduals.h" 29 29 #include "pmModel.h" 30 #include "pmResiduals.h"31 #include "pmPSF.h"32 #include "pmSource.h"33 30 #include "pmModelGroup.h" 34 31 #include "pmErrorCodes.h" … … 198 195 return (models[type].name); 199 196 } 200 201 /******************************************************************************202 pmSourceModelGuess(source, model): This function allocates a new203 pmModel structure based on the given modelType specified in the argument list.204 The corresponding pmModelGuess function is returned, and used to205 supply the values of the params array in the pmModel structure.206 207 XXX: Many parameters are based on the src->moments structure, which is in208 image, not subImage coords. Therefore, the calls to the model evaluation209 functions will be in image, not subImage coords. Remember this.210 *****************************************************************************/211 pmModel *pmSourceModelGuess(pmSource *source,212 pmModelType modelType)213 {214 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);215 PS_ASSERT_PTR_NON_NULL(source, NULL);216 PS_ASSERT_PTR_NON_NULL(source->moments, NULL);217 PS_ASSERT_PTR_NON_NULL(source->peak, NULL);218 219 pmModel *model = pmModelAlloc(modelType);220 221 pmModelGuessFunc modelGuessFunc = pmModelGuessFunc_GetFunction(modelType);222 if (!modelGuessFunc(model, source)) {223 psFree (model);224 return NULL;225 }226 227 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);228 return(model);229 }230 -
trunk/psModules/src/objects/pmModelGroup.h
r11253 r14652 1 1 /* @file pmModelGroup.h 2 2 * 3 * The object model function types are defined to allow for the flexible addition 4 * of new object models. Every object model, with parameters represented by 5 * pmModel, has an associated set of functions which provide necessary support 6 * operations. A set of abstract functions allow the programmer to select the 7 * approriate function or property for a specific named object model. 3 * The object model function types are desined to allow for the flexible addition of new object 4 * models. Every object model, with parameters represented by pmModel, has an associated set of 5 * functions which provide necessary support operations. A set of abstract functions allow the 6 * programmer to select the approriate function or property for a specific named object model. 7 * 8 * Every model instance belongs to a class of models, defined by the value of 9 * the pmModelType type entry. Various functions need access to information about 10 * each of the models. Some of this information varies from model to model, and 11 * may depend on the current parameter values or other data quantities. In order 12 * to keep the code from requiring the information about each model to be coded 13 * into the low-level fitting routines, we define a collection of functions which 14 * allow us to abstract this type of model-dependent information. These generic 15 * functions take the model type and return the corresponding function pointer 16 * for the specified model. Each model is defined by creating this collection of 17 * specific functions, and placing them in a single file for each model. We 18 * define the following structure to carry the collection of information about 19 * the models. 8 20 * 9 21 * @author EAM, IfA 10 22 * 11 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-0 1-24 02:54:15$23 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 24 * @date $Date: 2007-08-24 00:11:02 $ 13 25 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 14 26 */ … … 23 35 typedef psMinimizeLMChi2Func pmModelFunc; 24 36 25 // This function is the model chi-square minimization functionfor this model.37 // This function sets the parameter limits for this model. 26 38 typedef psMinimizeLMLimitFunc pmModelLimits; 27 39 … … 29 41 typedef psF64 (*pmModelFlux)(const psVector *params); 30 42 31 32 43 // This function returns the radius at which the given model and parameters 33 44 // achieves the given flux. 34 45 typedef psF64 (*pmModelRadius)(const psVector *params, double flux); 35 46 36 /* This function sets the model parameter limits vectors for the given model 37 */ 38 // typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max); 39 40 /* This function provides the model guess parameters based on the details of 41 * the given source. 42 */ 47 // This function provides the model guess parameters based on the details of 48 // the given source. 43 49 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source); 44 50 45 46 /* This function constructs the PSF model for the given source based on the 47 * supplied psf and the EXT model for the object. 48 */ 51 // This function constructs the PSF model for the given source based on the 52 // supplied psf and the EXT model for the object. 49 53 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf); 50 54 51 /* This function returns the success / failure status of the given model fit 52 */ 55 // This function sets the model parameters based on the PSF for a given coordinate and central 56 // intensity 57 typedef bool (*pmModelParamsFromPSF)(pmModel *model, pmPSF *psf, float Xo, float Yo, float Io); 58 59 // This function returns the success / failure status of the given model fit 53 60 typedef bool (*pmModelFitStatusFunc)(pmModel *model); 54 61 55 /* Every model instance belongs to a class of models, defined by the value of56 * the pmModelType type entry. Various functions need access to information about57 * each of the models. Some of this information varies from model to model, and58 * may depend on the current parameter values or other data quantities. In order59 * to keep the code from requiring the information about each model to be coded60 * into the low-level fitting routines, we define a collection of functions which61 * allow us to abstract this type of model-dependent information. These generic62 * functions take the model type and return the corresponding function pointer63 * for the specified model. Each model is defined by creating this collection of64 * specific functions, and placing them in a single file for each model. We65 * define the following structure to carry the collection of information about66 * the models.67 */68 62 typedef struct 69 63 { … … 76 70 pmModelGuessFunc modelGuessFunc; 77 71 pmModelFromPSFFunc modelFromPSFFunc; 72 pmModelParamsFromPSF modelParamsFromPSF; 78 73 pmModelFitStatusFunc modelFitStatusFunc; 79 74 } -
trunk/psModules/src/objects/pmModelUtils.c
r14530 r14652 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-08- 16 18:33:37$7 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-08-24 00:11:02 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 20 20 #include <string.h> 21 21 #include <pslib.h> 22 #include "pmHDU.h" 23 #include "pmFPA.h" 22 24 #include "pmResiduals.h" 25 #include "pmGrowthCurve.h" 26 #include "pmPSF.h" 23 27 #include "pmModel.h" 28 #include "pmErrorCodes.h" 29 #include "pmModelUtils.h" 24 30 25 // instantiate a model for the PSF at this location (normalized or not?) 26 // NOTE: psf and (x,y) are defined wrt chip coordinates 27 pmModel *pmModelFromPSFforXY (pmPSF *psf, float x, float y, float flux) { 28 29 assert (psf); 30 31 // allocate a new pmModel to hold the PSF version 32 pmModel *modelEXT = pmModelAlloc (psf->type); 33 34 modelEXT->params->data.F32[PM_PAR_SKY] = 0.0; 35 modelEXT->params->data.F32[PM_PAR_I0] = 1.0; 36 modelEXT->params->data.F32[PM_PAR_XPOS] = x; 37 modelEXT->params->data.F32[PM_PAR_YPOS] = y; 38 39 // find function used to set the model parameters 40 pmModelFromPSFFunc modelFromPSFFunc = pmModelFromPSFFunc_GetFunction (psf->type); 41 31 /***************************************************************************** 32 pmModelFromPSF (*modelEXT, *psf): use the model position parameters to 33 construct a realization of the PSF model at the object coordinates 34 *****************************************************************************/ 35 pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf) 36 { 42 37 // allocate a new pmModel to hold the PSF version 43 38 pmModel *modelPSF = pmModelAlloc (psf->type); 44 39 45 // adjust the normalization:46 pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);47 normFlux = modelFluxFunc (model->params);48 assert (isfinite(normFlux));49 assert (normFlux > 0);50 51 // set the correct normalization52 modelEXT->params->data.F32[PM_PAR_I0] = flux / normFlux;53 54 40 // set model parameters for this source based on PSF information 55 if (!model FromPSFFunc(modelPSF, modelEXT, psf)) {41 if (!modelEXT->modelFromPSF (modelPSF, modelEXT, psf)) { 56 42 psError(PM_ERR_PSF, false, "Failed to set model params from PSF"); 57 43 psFree(modelPSF); … … 60 46 // XXX note that model->residuals is just a reference 61 47 modelPSF->residuals = psf->residuals; 62 psFree (modelEXT);63 48 64 49 return (modelPSF); 65 50 } 66 51 67 pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, pmSourceType type) { 52 // instantiate a model for the PSF at this location with peak flux 53 // NOTE: psf and (Xo,Yo) are defined wrt chip coordinates 54 pmModel *pmModelFromPSFforXY (pmPSF *psf, float Xo, float Yo, float Io) { 68 55 69 pmSource *source = pmSourceAlloc ();56 assert (psf); 70 57 71 // use the model centroid for the peak 72 switch (type) { 73 case PM_SOURCE_TYPE_STAR: 74 source->modelPSF = model; 75 break; 76 case PM_SOURCE_TYPE_EXTENDED: 77 source->modelEXT = model; 78 break; 79 default: 80 psAbort ("psphot", "error"); 58 // allocate a new pmModel to hold the PSF version 59 pmModel *modelPSF = pmModelAlloc (psf->type); 60 61 // set model parameters for this source based on PSF information 62 if (!modelPSF->modelParamsFromPSF (modelPSF, psf, Xo, Yo, Io)) { 63 psError(PM_ERR_PSF, false, "Failed to set model params from PSF"); 64 psFree(modelPSF); 65 return NULL; 81 66 } 82 67 83 source->peak = pmPeakAlloc (); 68 // XXX note that model->residuals is just a reference 69 modelPSF->residuals = psf->residuals; 84 70 85 float x = model->params->data.F32[PM_PAR_XPOS];86 float y = model->params->data.F32[PM_PAR_YPOS]; 71 return (modelPSF); 72 } 87 73 88 // XXX need to define the radius in some rational way 89 // XXX x,y are defined wrt readout->image parent, but the model 90 // parameters are defined wrt chip coordinates 91 pmSourceDefinePixels (source, readout, x, y, radius); 74 // set this model to have the requested flux 75 bool pmModelSetFlux (pmModel *model, float flux) { 92 76 93 return (source); 77 // set Io to be 1.0 78 model->params->data.F32[PM_PAR_I0] = 1.0; 79 80 // determine the normalized flux 81 float normFlux = model->modelFlux (model->params); 82 assert (isfinite(normFlux)); 83 assert (normFlux > 0); 84 85 // set the desired normalization 86 model->params->data.F32[PM_PAR_I0] = flux / normFlux; 87 88 return true; 94 89 } -
trunk/psModules/src/objects/pmPSF.c
r13898 r14652 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.2 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 6-20 02:22:26$8 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 28 #include "pmMoments.h" 29 29 #include "pmResiduals.h" 30 #include "pmGrowthCurve.h" 31 #include "pmPSF.h" 30 32 #include "pmModel.h" 31 33 #include "pmSource.h" 32 #include "pmGrowthCurve.h" 33 #include "pmPSF.h" 34 #include "pmModelGroup.h" 34 #include "pmModelClass.h" 35 #include "pmModelUtils.h" 35 36 #include "pmSourcePhotometry.h" 36 37 #include "pmFPAMaskWeight.h" … … 74 75 psFree (psf->ApTrend); 75 76 psFree (psf->growth); 76 psFree (psf->params _NEW);77 psFree (psf->params); 77 78 psFree (psf->residuals); 78 79 return; … … 103 104 psf->skyBias = 0.0; 104 105 psf->skySat = 0.0; 106 psf->nPSFstars = 0; 107 psf->nApResid = 0; 105 108 psf->poissonErrors = poissonErrors; 106 109 … … 124 127 psf->residuals = NULL; 125 128 126 Nparams = pmModel ParameterCount (type);129 Nparams = pmModelClassParameterCount (type); 127 130 if (!Nparams) { 128 131 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 129 132 return(NULL); 130 133 } 131 psf->params _NEW= psArrayAlloc(Nparams);134 psf->params = psArrayAlloc(Nparams); 132 135 133 136 // the order of the PSF parameter (X,Y) fits is determined by the psfTrendMask polynomial … … 139 142 140 143 if (psfTrendMask) { 141 for (int i = 0; i < psf->params _NEW->n; i++) {144 for (int i = 0; i < psf->params->n; i++) { 142 145 if (i == PM_PAR_SKY) 143 146 continue; … … 155 158 } 156 159 } 157 psf->params _NEW->data[i] = param;160 psf->params->data[i] = param; 158 161 } 159 162 } … … 161 164 psMemSetDeallocator(psf, (psFreeFunc) pmPSFFree); 162 165 return(psf); 163 }164 165 /*****************************************************************************166 pmModelFromPSF (*modelEXT, *psf): use the model position parameters to167 construct a realization of the PSF model at the object coordinates168 *****************************************************************************/169 pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)170 {171 172 // need to define the relationship between the modelEXT and modelPSF ?173 174 // find function used to set the model parameters175 pmModelFromPSFFunc modelFromPSFFunc = pmModelFromPSFFunc_GetFunction (psf->type);176 177 // allocate a new pmModel to hold the PSF version178 pmModel *modelPSF = pmModelAlloc (psf->type);179 180 // set model parameters for this source based on PSF information181 if (!modelFromPSFFunc (modelPSF, modelEXT, psf)) {182 psError(PM_ERR_PSF, false, "Failed to set model params from PSF");183 psFree(modelPSF);184 return NULL;185 }186 // XXX note that model->residuals is just a reference187 modelPSF->residuals = psf->residuals;188 189 return (modelPSF);190 166 } 191 167 … … 335 311 va_start(ap, sxy); 336 312 337 pmModelType type = pmModel SetType (typeName);313 pmModelType type = pmModelClassGetType (typeName); 338 314 psPolynomial2D *psfTrend = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 0, 0); 339 315 pmPSF *psf = pmPSFAlloc (type, true, psfTrend); 340 316 341 psVector *par = psVectorAlloc (psf->params _NEW->n, PS_TYPE_F32);317 psVector *par = psVectorAlloc (psf->params->n, PS_TYPE_F32); 342 318 par->data.F32[PM_PAR_SXX] = sxx; 343 319 par->data.F32[PM_PAR_SYY] = syy; … … 348 324 // set the psf shape parameters 349 325 psPolynomial2D *poly = NULL; 350 poly = psf->params _NEW->data[PM_PAR_E0];326 poly = psf->params->data[PM_PAR_E0]; 351 327 poly->coeff[0][0] = pol.e0; 352 328 353 poly = psf->params _NEW->data[PM_PAR_E1];329 poly = psf->params->data[PM_PAR_E1]; 354 330 poly->coeff[0][0] = pol.e1; 355 331 356 poly = psf->params _NEW->data[PM_PAR_E2];332 poly = psf->params->data[PM_PAR_E2]; 357 333 poly->coeff[0][0] = pol.e2; 358 334 359 for (int i = PM_PAR_SXY + 1; i < psf->params _NEW->n; i++) {360 poly = psf->params _NEW->data[i];335 for (int i = PM_PAR_SXY + 1; i < psf->params->n; i++) { 336 poly = psf->params->data[i]; 361 337 poly->coeff[0][0] = (psF32)va_arg(ap, psF64); 362 338 } -
trunk/psModules/src/objects/pmPSF.h
r13898 r14652 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 6-20 02:22:26$8 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 11 11 */ … … 16 16 /// @addtogroup Objects Object Detection / Analysis Functions 17 17 /// @{ 18 19 // type of model carried by the pmModel structure 20 typedef int pmModelType; 18 21 19 22 typedef enum { … … 44 47 typedef struct 45 48 { 46 pmModelType type; ///< PSF Model in use 47 psArray *params_NEW; ///< Model parameters (psPolynomial2D) 48 // XXXXX I am changing params: we will allocate elements for the 49 // unfitted elements (So, Io, Xo, Yo) and leave them as NULL 50 // I am using a new name to catch all refs to params with gcc 49 pmModelType type; ///< PSF Model in use 50 psArray *params; ///< Model parameters (psPolynomial2D) 51 51 psPolynomial1D *ChiTrend; ///< Chisq vs flux fit (correction for systematic errors) 52 52 psPolynomial4D *ApTrend; ///< ApResid vs (x,y,rflux) (rflux = ten(0.4*mInst)) … … 79 79 ); 80 80 81 /**82 *83 * This function constructs a pmModel instance based on the pmPSF description84 * of the PSF. The input is a pmModel with at least the values of the centroid85 * coordinates (possibly normalization if this is needed) defined. The values of86 * the PSF-dependent parameters are specified for the specific realization based87 * on the coordinates of the object.88 *89 */90 pmModel *pmModelFromPSF(91 pmModel *model, ///< Add comment92 pmPSF *psf ///< Add comment93 );94 95 81 bool pmPSFMaskApTrend (psPolynomial4D *trend, pmPSFApTrendOptions option); 96 82 -
trunk/psModules/src/objects/pmPSF_IO.c
r14207 r14652 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 7-14 03:20:22 $8 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 40 40 #include "pmGrowthCurve.h" 41 41 #include "pmResiduals.h" 42 #include "pmPSF.h" 42 43 #include "pmModel.h" 43 #include "pmPSF.h"44 44 #include "pmPSF_IO.h" 45 45 #include "pmSource.h" 46 #include "pmModel Group.h"46 #include "pmModelClass.h" 47 47 #include "pmSourceIO.h" 48 48 49 bool pm FPAviewCheckDataStatusForPSFmodel(const pmFPAview *view, const pmFPAfile *file)49 bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file) 50 50 { 51 51 pmFPA *fpa = file->fpa; 52 52 53 53 if (view->chip == -1) { 54 bool exists = pm FPACheckDataStatusForPSFmodel(fpa);54 bool exists = pmPSFmodelCheckDataStatusForFPA (fpa); 55 55 return exists; 56 56 } … … 62 62 63 63 if (view->cell == -1) { 64 bool exists = pm ChipCheckDataStatusForPSFmodel(chip);64 bool exists = pmPSFmodelCheckDataStatusForChip (chip); 65 65 return exists; 66 66 } … … 69 69 return false; 70 70 } 71 pmCell *cell = chip->cells->data[view->cell]; 72 73 if (view->readout == -1) { 74 bool exists = pmCellCheckDataStatusForPSFmodel (cell); 75 return exists; 76 } 77 78 if (view->readout >= cell->readouts->n) { 79 psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n); 80 return false; 81 } 82 pmReadout *readout = cell->readouts->data[view->readout]; 83 84 return pmReadoutCheckDataStatusForPSFmodel (readout); 85 } 86 87 bool pmFPACheckDataStatusForPSFmodel (const pmFPA *fpa) { 71 psError(PS_ERR_IO, false, "PSF only valid at the chip level"); 72 return false; 73 } 74 75 bool pmPSFmodelCheckDataStatusForFPA (const pmFPA *fpa) { 88 76 89 77 for (int i = 0; i < fpa->chips->n; i++) { 90 78 pmChip *chip = fpa->chips->data[i]; 91 79 if (!chip) continue; 92 if (pm ChipCheckDataStatusForPSFmodel(chip)) return true;80 if (pmPSFmodelCheckDataStatusForChip (chip)) return true; 93 81 } 94 82 return false; 95 83 } 96 84 97 bool pmChipCheckDataStatusForPSFmodel (const pmChip *chip) { 98 99 for (int i = 0; i < chip->cells->n; i++) { 100 pmCell *cell = chip->cells->data[i]; 101 if (!cell) continue; 102 if (pmCellCheckDataStatusForPSFmodel (cell)) return true; 103 } 104 return false; 105 } 106 107 bool pmCellCheckDataStatusForPSFmodel (const pmCell *cell) { 108 109 for (int i = 0; i < cell->readouts->n; i++) { 110 pmReadout *readout = cell->readouts->data[i]; 111 if (!readout) continue; 112 if (pmReadoutCheckDataStatusForPSFmodel (readout)) return true; 113 } 114 return false; 115 } 116 117 bool pmReadoutCheckDataStatusForPSFmodel (const pmReadout *readout) { 85 bool pmPSFmodelCheckDataStatusForChip (const pmChip *chip) { 118 86 119 87 bool status; 120 88 121 89 // select the psf of interest 122 pmPSF *psf = psMetadataLookupPtr(&status, readout->analysis, "PSPHOT.PSF");90 pmPSF *psf = psMetadataLookupPtr(&status, chip->analysis, "PSPHOT.PSF"); 123 91 return psf ? true : false; 124 92 } 125 93 126 bool pm FPAviewWritePSFmodel(const pmFPAview *view, pmFPAfile *file, const pmConfig *config)94 bool pmPSFmodelWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 127 95 { 128 96 … … 130 98 131 99 if (view->chip == -1) { 132 if (!pm FPAWritePSFmodel(fpa, view, file, config)) {100 if (!pmPSFmodelWriteFPA(fpa, view, file, config)) { 133 101 psError(PS_ERR_IO, false, "Failed to write PSF for fpa"); 134 102 return false; … … 143 111 144 112 if (view->cell == -1) { 145 if (!pm ChipWritePSFmodel(chip, view, file, config)) {113 if (!pmPSFmodelWriteChip (chip, view, file, config)) { 146 114 psError(PS_ERR_IO, false, "Failed to write PSF for chip"); 147 115 return false; … … 150 118 } 151 119 152 if (view->cell >= chip->cells->n) { 153 return false; 154 } 155 pmCell *cell = chip->cells->data[view->cell]; 156 157 if (view->readout == -1) { 158 if (!pmCellWritePSFmodel (cell, view, file, config)) { 159 psError(PS_ERR_IO, false, "Failed to write PSF for cell"); 160 return false; 161 } 162 return true; 163 } 164 165 if (view->readout >= cell->readouts->n) { 166 return false; 167 } 168 pmReadout *readout = cell->readouts->data[view->readout]; 169 170 if (!pmReadoutWritePSFmodel (readout, view, file, config)) { 171 psError(PS_ERR_IO, false, "Failed to write PSF for readout"); 172 return false; 173 } 174 return true; 120 psError(PS_ERR_IO, false, "PSF must be written at the chip level"); 121 return false; 175 122 } 176 123 177 124 // read in all chip-level PSFmodel files for this FPA 178 bool pm FPAWritePSFmodel(pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)125 bool pmPSFmodelWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 179 126 { 180 127 181 128 for (int i = 0; i < fpa->chips->n; i++) { 182 129 pmChip *chip = fpa->chips->data[i]; 183 if (!pm ChipWritePSFmodel(chip, view, file, config)) {130 if (!pmPSFmodelWriteChip (chip, view, file, config)) { 184 131 psError(PS_ERR_IO, false, "Failed to write PSF for %dth chip", i); 185 132 return false; … … 190 137 191 138 // read in all cell-level PSFmodel files for this chip 192 bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 193 { 194 for (int i = 0; i < chip->cells->n; i++) { 195 pmCell *cell = chip->cells->data[i]; 196 if (!pmCellWritePSFmodel (cell, view, file, config)) { 197 psError(PS_ERR_IO, false, "Failed to write PSF for %dth cell", i); 198 return false; 199 } 139 bool pmPSFmodelWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 140 { 141 if (!pmPSFmodelWrite (chip->analysis, view, file, config)) { 142 psError(PS_ERR_IO, false, "Failed to write PSF for chip"); 143 return false; 200 144 } 201 145 return true; 202 146 } 203 147 204 // read in all readout-level PSFmodel files for this cell 205 bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 206 { 207 for (int i = 0; i < cell->readouts->n; i++) { 208 pmReadout *readout = cell->readouts->data[i]; 209 if (!pmReadoutWritePSFmodel (readout, view, file, config)) { 210 psError(PS_ERR_IO, false, "Failed to write PSF for %dth readout", i); 211 return false; 212 } 213 } 214 return true; 215 } 216 217 // for each Readout (ie, analysed image), we write out 148 // for a pmPSF supplied on the analysis metadata, we write out 218 149 // - image header : FITS Image NAXIS = 0 219 150 // - psf table (+header) : FITS Table 220 151 // - psf resid (+header) : FITS Image 221 152 // if needed, we also write out a PHU blank header 222 bool pm ReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)153 bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 223 154 { 224 155 bool status; 225 156 pmHDU *hdu; 226 157 char *headName, *tableName, *residName; 158 159 if (!analysis) return false; 227 160 228 161 // write a PHU? (only if input image is MEF) … … 300 233 301 234 // select the psf of interest 302 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");235 pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF"); 303 236 if (!psf) { 304 psError(PS_ERR_UNKNOWN, true, "missing PSF for this readout");237 psError(PS_ERR_UNKNOWN, true, "missing PSF for this analysis metadata"); 305 238 psFree (tableName); 306 239 psFree (residName); … … 313 246 psMetadata *header = psMetadataAlloc(); 314 247 315 char *modelName = pmModel GetType (psf->type);248 char *modelName = pmModelClassGetName (psf->type); 316 249 psMetadataAddStr (header, PS_LIST_TAIL, "PSF_NAME", 0, "PSF model name", modelName); 317 250 318 251 psMetadataAddBool (header, PS_LIST_TAIL, "POISSON", 0, "Use Poisson errors in fits?", psf->poissonErrors); 319 252 320 int nPar = pmModel ParameterCount (psf->type) ;253 int nPar = pmModelClassParameterCount (psf->type) ; 321 254 psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar); 322 255 … … 324 257 for (int i = 0; i < nPar; i++) { 325 258 char name[9]; 326 psPolynomial2D *poly = psf->params _NEW->data[i];259 psPolynomial2D *poly = psf->params->data[i]; 327 260 if (poly == NULL) continue; 328 261 snprintf (name, 9, "PAR%02d_NX", i); … … 344 277 psArray *psfTable = psArrayAllocEmpty (100); 345 278 for (int i = 0; i < nPar; i++) { 346 psPolynomial2D *poly = psf->params _NEW->data[i];279 psPolynomial2D *poly = psf->params->data[i]; 347 280 if (poly == NULL) continue; // skip unset parameters (eg, XPOS) 348 281 for (int ix = 0; ix <= poly->nX; ix++) { … … 445 378 446 379 // if this file needs to have a PHU written out, write one 447 bool pmPSF _WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {380 bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) { 448 381 449 382 // not needed if already written … … 487 420 } 488 421 489 bool pm FPAviewReadPSFmodel(const pmFPAview *view, pmFPAfile *file, const pmConfig *config)422 bool pmPSFmodelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 490 423 { 491 424 … … 493 426 494 427 if (view->chip == -1) { 495 return pm FPAReadPSFmodel(fpa, view, file, config);428 return pmPSFmodelReadFPA(fpa, view, file, config); 496 429 } 497 430 … … 502 435 503 436 if (view->cell == -1) { 504 return pmChipReadPSFmodel(chip, view, file, config); 505 } 506 507 if (view->cell >= chip->cells->n) { 508 psAbort("Programming error: view does not apply to FPA."); 509 } 510 pmCell *cell = chip->cells->data[view->cell]; 511 512 if (view->readout == -1) { 513 return pmCellReadPSFmodel(cell, view, file, config); 514 } 515 516 if (view->readout >= cell->readouts->n) { 517 psAbort("Programming error: view does not apply to FPA."); 518 } 519 pmReadout *readout = cell->readouts->data[view->readout]; 520 521 return pmReadoutReadPSFmodel(readout, view, file, config); 437 return pmPSFmodelReadChip(chip, view, file, config); 438 } 439 440 psError(PS_ERR_IO, false, "PSF must be read at the chip level"); 441 return false; 522 442 } 523 443 524 444 // read in all chip-level PSFmodel files for this FPA 525 bool pm FPAReadPSFmodel(pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)445 bool pmPSFmodelReadFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 526 446 { 527 447 bool success = true; // Was everything successful? 528 448 for (int i = 0; i < fpa->chips->n; i++) { 529 449 pmChip *chip = fpa->chips->data[i]; 530 success &= pm ChipReadPSFmodel(chip, view, file, config);450 success &= pmPSFmodelReadChip(chip, view, file, config); 531 451 } 532 452 return success; … … 534 454 535 455 // read in all cell-level PSFmodel files for this chip 536 bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 537 { 538 bool success = true; // Was everything successful? 539 for (int i = 0; i < chip->cells->n; i++) { 540 pmCell *cell = chip->cells->data[i]; 541 success &= pmCellReadPSFmodel (cell, view, file, config); 542 } 543 return success; 544 } 545 546 // read in all readout-level PSFmodel files for this cell 547 bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 548 { 549 bool success = true; // Was everything successful? 550 for (int i = 0; i < cell->readouts->n; i++) { 551 pmReadout *readout = cell->readouts->data[i]; 552 success &= pmReadoutReadPSFmodel(readout, view, file, config); 553 } 554 return success; 456 bool pmPSFmodelReadChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 457 { 458 if (!pmPSFmodelRead (chip->analysis, view, file, config)) { 459 psError(PS_ERR_IO, false, "Failed to write PSF for chip"); 460 return false; 461 } 462 return true; 555 463 } 556 464 557 465 // for each Readout (ie, analysed image), we write out: header + table with PSF model parameters, 558 466 // and header + image for the PSF residual images 559 bool pm ReadoutReadPSFmodel(pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)467 bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 560 468 { 561 469 bool status; … … 599 507 // load the PSF model parameters from the FITS table 600 508 char *modelName = psMetadataLookupStr (&status, header, "PSF_NAME"); 601 pmModelType type = pmModel SetType (modelName);509 pmModelType type = pmModelClassGetType (modelName); 602 510 if (type == -1) { 603 511 psError(PS_ERR_UNKNOWN, true, "invalid model name %s in psf file %s", modelName, file->filename); … … 612 520 // check the number of expected parameters 613 521 int nPar = psMetadataLookupS32 (&status, header, "PSF_NPAR"); 614 if (nPar != pmModel ParameterCount (psf->type))522 if (nPar != pmModelClassParameterCount (psf->type)) 615 523 psAbort("mismatch model par count"); 616 524 … … 627 535 return false; 628 536 } 629 psf->params _NEW->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);537 psf->params->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder); 630 538 } 631 539 … … 650 558 // XXX sanity check here 651 559 652 psPolynomial2D *poly = psf->params _NEW->data[iPar];560 psPolynomial2D *poly = psf->params->data[iPar]; 653 561 if (poly == NULL) { 654 562 psError(PS_ERR_UNKNOWN, true, "values for parameter %d, but missing NX", iPar); … … 698 606 } 699 607 700 psMetadataAdd ( readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf);608 psMetadataAdd (analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf); 701 609 psFree (psf); 702 610 … … 708 616 } 709 617 710 /************ old support functions, deprecate? **************/ 711 618 // create a psMetadata representation (human-readable) of a psf model 712 619 psMetadata *pmPSFtoMetadata (psMetadata *metadata, pmPSF *psf) 713 620 { … … 717 624 } 718 625 719 char *modelName = pmModel GetType (psf->type);626 char *modelName = pmModelClassGetName (psf->type); 720 627 psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NAME", PS_DATA_STRING, "PSF model name", modelName); 721 628 722 int nPar = pmModel ParameterCount (psf->type) ;629 int nPar = pmModelClassParameterCount (psf->type) ; 723 630 psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NPAR", PS_DATA_S32, "PSF model parameter count", nPar); 724 631 725 632 for (int i = 0; i < nPar; i++) { 726 psPolynomial2D *poly = psf->params _NEW->data[i];633 psPolynomial2D *poly = psf->params->data[i]; 727 634 if (poly == NULL) 728 635 continue; … … 742 649 } 743 650 651 // parse a psMetadata representation (human-readable) of a psf model 744 652 pmPSF *pmPSFfromMetadata (psMetadata *metadata) 745 653 { … … 749 657 750 658 char *modelName = psMetadataLookupPtr (&status, metadata, "PSF_MODEL_NAME"); 751 pmModelType type = pmModel SetType (modelName);659 pmModelType type = pmModelClassGetType (modelName); 752 660 753 661 bool poissonErrors = psMetadataLookupPtr (&status, metadata, "PSF_POISSON_ERRORS"); … … 759 667 760 668 int nPar = psMetadataLookupS32 (&status, metadata, "PSF_MODEL_NPAR"); 761 if (nPar != pmModel ParameterCount (psf->type))669 if (nPar != pmModelClassParameterCount (psf->type)) 762 670 psAbort("mismatch model par count"); 763 671 … … 770 678 continue; 771 679 psPolynomial2D *poly = psPolynomial2DfromMetadata (folder); 772 psFree (psf->params _NEW->data[i]);773 psf->params _NEW->data[i] = poly;680 psFree (psf->params->data[i]); 681 psf->params->data[i] = poly; 774 682 } 775 683 sprintf (keyword, "APTREND"); … … 789 697 return (psf); 790 698 } 791 792 // read in all readout-level Objects files for this cell793 bool pmReadoutWritePSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)794 {795 bool status;796 char *filename;797 char *realname;798 799 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");800 801 switch (file->type) {802 case PM_FPA_FILE_PSF:803 filename = pmFPAfileNameFromRule (file->filerule, file, view);804 bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;805 realname = pmConfigConvertFilename (filename, config, create);806 807 psMetadata *psfData = pmPSFtoMetadata (NULL, psf);808 psMetadataConfigWrite (psfData, realname);809 psFree (psfData);810 psFree (realname);811 psFree (filename);812 return true;813 814 default:815 fprintf (stderr, "warning: type mismatch\n");816 break;817 }818 return false;819 }820 821 // read in all readout-level Objects files for this cell822 bool pmReadoutReadPSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)823 {824 825 unsigned int Nfail;826 char *filename;827 char *realname;828 829 switch (file->type) {830 case PM_FPA_FILE_PSF:831 filename = pmFPAfileNameFromRule (file->filerule, file, view);832 bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;833 realname = pmConfigConvertFilename (filename, config, create);834 835 psMetadata *psfData = psMetadataConfigRead(NULL, &Nfail, realname, FALSE);836 pmPSF *psf = pmPSFfromMetadata (psfData);837 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf);838 839 psFree (psf);840 psFree (psfData);841 psFree (realname);842 psFree (filename);843 844 return true;845 846 default:847 fprintf (stderr, "warning: type mismatch\n");848 break;849 }850 return false;851 }852 -
trunk/psModules/src/objects/pmPSF_IO.h
r14207 r14652 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 7-14 03:20:22 $8 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 11 11 */ … … 17 17 /// @{ 18 18 19 bool pmPSFmodelWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 20 bool pmPSFmodelWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 21 bool pmPSFmodelWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 22 bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 23 24 bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 25 26 bool pmPSFmodelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 27 bool pmPSFmodelReadFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 28 bool pmPSFmodelReadChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 29 bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config); 30 31 bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file); 32 bool pmPSFmodelCheckDataStatusForFPA (const pmFPA *fpa); 33 bool pmPSFmodelCheckDataStatusForChip (const pmChip *chip); 34 19 35 psMetadata *pmPSFtoMetadata (psMetadata *metadata, pmPSF *psf); 20 36 pmPSF *pmPSFfromMetadata (psMetadata *metadata); 21 bool pmFPAviewWritePSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);22 bool pmFPAWritePSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);23 bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);24 bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);25 bool pmReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);26 27 bool pmPSF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);28 29 bool pmFPAviewReadPSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);30 bool pmFPAReadPSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);31 bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);32 bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);33 bool pmReadoutReadPSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);34 35 bool pmFPAviewCheckDataStatusForPSFmodel (const pmFPAview *view, const pmFPAfile *file);36 bool pmFPACheckDataStatusForPSFmodel (const pmFPA *fpa);37 bool pmChipCheckDataStatusForPSFmodel (const pmChip *chip);38 bool pmCellCheckDataStatusForPSFmodel (const pmCell *cell);39 bool pmReadoutCheckDataStatusForPSFmodel (const pmReadout *readout);40 37 41 38 /// @} -
trunk/psModules/src/objects/pmPSFtry.c
r13898 r14652 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1.4 3$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 6-20 02:22:26$7 * @version $Revision: 1.44 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-08-24 00:11:02 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 23 #include "pmMoments.h" 24 24 #include "pmResiduals.h" 25 #include "pmGrowthCurve.h" 26 #include "pmPSF.h" 25 27 #include "pmModel.h" 26 28 #include "pmSource.h" 27 #include "pmGrowthCurve.h" 28 #include "pmPSF.h" 29 #include "pmSourceUtils.h" 29 30 #include "pmPSFtry.h" 30 #include "pmModelGroup.h" 31 #include "pmModelClass.h" 32 #include "pmModelUtils.h" 31 33 #include "pmSourceFitModel.h" 32 34 #include "pmSourcePhotometry.h" … … 59 61 60 62 // validate the requested model name 61 pmModelType type = pmModel SetType (modelName);63 pmModelType type = pmModelClassGetType (modelName); 62 64 if (type == -1) { 63 65 psError (PS_ERR_UNKNOWN, true, "invalid model name %s", modelName); … … 412 414 // This way, the parameters masked by one of the fits will be applied to the others 413 415 for (int i = 0; i < stats->clipIter; i++) { 414 psVectorClipFitPolynomial2D (psf->params _NEW->data[PM_PAR_E0], stats, psfTry->mask, 0xff, e0, dz, x, y);416 psVectorClipFitPolynomial2D (psf->params->data[PM_PAR_E0], stats, psfTry->mask, 0xff, e0, dz, x, y); 415 417 psTrace ("psModules.pmPSFtry", 4, "clipped E0 : keeping %ld of %ld\n", stats->clippedNvalues, e0->n); 416 psVectorClipFitPolynomial2D (psf->params _NEW->data[PM_PAR_E1], stats, psfTry->mask, 0xff, e1, dz, x, y);418 psVectorClipFitPolynomial2D (psf->params->data[PM_PAR_E1], stats, psfTry->mask, 0xff, e1, dz, x, y); 417 419 psTrace ("psModules.pmPSFtry", 4, "clipped E1 : keeping %ld of %ld\n", stats->clippedNvalues, e1->n); 418 psVectorClipFitPolynomial2D (psf->params _NEW->data[PM_PAR_E2], stats, psfTry->mask, 0xff, e2, dz, x, y);420 psVectorClipFitPolynomial2D (psf->params->data[PM_PAR_E2], stats, psfTry->mask, 0xff, e2, dz, x, y); 419 421 psTrace ("psModules.pmPSFtry", 4, "clipped E2 : keeping %ld of %ld\n", stats->clippedNvalues, e2->n); 420 422 } … … 436 438 437 439 // skip the unfitted parameters (X, Y, Io, Sky) and the shape parameters (SXX, SYY, SXY) 438 for (int i = 0; i < psf->params _NEW->n; i++) {440 for (int i = 0; i < psf->params->n; i++) { 439 441 switch (i) { 440 442 case PM_PAR_SKY: … … 461 463 // the mask is carried from previous steps and updated with this operation 462 464 // the weight is either the flux error or NULL, depending on 'applyWeights' 463 if (!psVectorClipFitPolynomial2D(psf->params _NEW->data[i], stats, psfTry->mask, 0xff, z, NULL, x, y)) {465 if (!psVectorClipFitPolynomial2D(psf->params->data[i], stats, psfTry->mask, 0xff, z, NULL, x, y)) { 464 466 psError(PS_ERR_UNKNOWN, false, "failed to build psf model for parameter %d", i); 465 467 psFree(stats); … … 489 491 fprintf (f, "%f %f : ", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]); 490 492 491 for (int i = 0; i < psf->params _NEW->n; i++) {492 if (psf->params _NEW->data[i] == NULL)493 for (int i = 0; i < psf->params->n; i++) { 494 if (psf->params->data[i] == NULL) 493 495 continue; 494 496 fprintf (f, "%f %f : ", model->params->data.F32[i], modelPSF->params->data.F32[i]); -
trunk/psModules/src/objects/pmPeaks.c
r13034 r14652 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 4-26 01:20:29$8 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 35 35 pmPeakType type) 36 36 { 37 psTrace( __func__, 5, "---- begin ----\n");37 psTrace("psModules.objects", 5, "---- begin ----\n"); 38 38 39 39 if (peaks == NULL) { … … 67 67 psFree (peak); 68 68 69 psTrace( __func__, 5, "---- end ----\n");69 psTrace("psModules.objects", 5, "---- end ----\n"); 70 70 return(peaks); 71 71 } … … 118 118 *****************************************************************************/ 119 119 static void peakFree(pmPeak *tmp) 120 {} // used by pm IsPeak()120 {} // used by pmPeakTest() 121 121 122 122 pmPeak *pmPeakAlloc(psS32 x, … … 145 145 } 146 146 147 bool pm IsPeak(const psPtr ptr)147 bool pmPeakTest(const psPtr ptr) 148 148 { 149 149 return (psMemGetDeallocator(ptr) == (psFreeFunc)peakFree); … … 193 193 194 194 /****************************************************************************** 195 pm FindVectorPeaks(vector, threshold): Find all local peaks in the given vector195 pmPeaksInVector(vector, threshold): Find all local peaks in the given vector 196 196 above the given threshold. Returns a vector of type PS_TYPE_U32 containing 197 197 the location (x value) of all peaks. … … 203 203 Depending upon actual use, this may need to be optimized. 204 204 *****************************************************************************/ 205 psVector *pm FindVectorPeaks(const psVector *vector,206 psF32 threshold)205 psVector *pmPeaksInVector(const psVector *vector, 206 psF32 threshold) 207 207 { 208 208 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); … … 295 295 296 296 /****************************************************************************** 297 pm FindImagePeaks(image, threshold): Find all local peaks in the given psImage297 pmPeaksInImage(image, threshold): Find all local peaks in the given psImage 298 298 above the given threshold. Returns a psArray containing location (x/y value) 299 299 of all peaks. … … 309 309 310 310 *****************************************************************************/ 311 psArray *pm FindImagePeaks(const psImage *image, psF32 threshold)311 psArray *pmPeaksInImage(const psImage *image, psF32 threshold) 312 312 { 313 313 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); … … 327 327 row = 0; 328 328 tmpRow = getRowVectorFromImage((psImage *) image, row); 329 psVector *row1 = pm FindVectorPeaks(tmpRow, threshold);330 // pm FindVectorPeaksreturns coords in the vector, not corrected for col0329 psVector *row1 = pmPeaksInVector(tmpRow, threshold); 330 // pmPeaksInVector returns coords in the vector, not corrected for col0 331 331 332 332 for (psU32 i = 0 ; i < row1->n ; i++ ) { … … 382 382 for (row = 1 ; row < (image->numRows - 1) ; row++) { 383 383 tmpRow = getRowVectorFromImage((psImage *) image, row); 384 row1 = pm FindVectorPeaks(tmpRow, threshold);384 row1 = pmPeaksInVector(tmpRow, threshold); 385 385 386 386 // Step through all local peaks in this row. … … 461 461 row = image->numRows - 1; 462 462 tmpRow = getRowVectorFromImage((psImage *) image, row); 463 row1 = pm FindVectorPeaks(tmpRow, threshold);463 row1 = pmPeaksInVector(tmpRow, threshold); 464 464 for (psU32 i = 0 ; i < row1->n ; i++ ) { 465 465 col = row1->data.U32[i]; … … 501 501 } 502 502 503 504 /****************************************************************************** 505 psCullPeaks(peaks, maxValue, valid): eliminate peaks from the psArray that have 506 a peak value above the given maximum, or fall outside the valid region. 507 508 XXX: Should the sky value be used when comparing the maximum? 509 510 XXX: warning message if valid is NULL? 511 512 XXX: changed API to create a NEW output psArray (should change name as well) 513 514 XXX: Do we free the psList elements of those culled peaks? 515 516 XXX EAM : do we still need pmCullPeaks, or only pmPeaksSubset? 517 *****************************************************************************/ 518 psList *pmCullPeaks(psList *peaks, 519 psF32 maxValue, 520 const psRegion valid) 521 { 522 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 523 PS_ASSERT_PTR_NON_NULL(peaks, NULL); 524 525 psListElem *tmpListElem = (psListElem *) peaks->head; 526 psS32 indexNum = 0; 527 528 // printf("pmCullPeaks(): list size is %d\n", peaks->size); 529 while (tmpListElem != NULL) { 530 pmPeak *tmpPeak = (pmPeak *) tmpListElem->data; 531 if ((tmpPeak->value > maxValue) || 532 (true == isItInThisRegion(valid, tmpPeak->x, tmpPeak->y))) { 533 psListRemoveData(peaks, (psPtr) tmpPeak); 534 } 535 536 indexNum++; 537 tmpListElem = tmpListElem->next; 538 } 539 540 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); 541 return(peaks); 542 } 543 544 // XXX EAM: I changed this to return a new, subset array 545 // rather than alter the existing one 546 // XXX: Fix the *valid pointer. 503 // return a new array of peaks which are in the valid region and below threshold 504 // XXX this function is unused and probably could be dropped 547 505 psArray *pmPeaksSubset( 548 506 psArray *peaks, … … 555 513 psArray *output = psArrayAllocEmpty (200); 556 514 557 psTrace (" .pmObjects.pmCullPeaks", 3, "list size is %ld\n", peaks->n);515 psTrace ("psModules.objects", 3, "list size is %ld\n", peaks->n); 558 516 559 517 for (int i = 0; i < peaks->n; i++) { -
trunk/psModules/src/objects/pmPeaks.h
r11253 r14652 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-0 1-24 02:54:15$12 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-08-24 00:11:02 $ 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 15 */ … … 72 72 ); 73 73 74 bool pm IsPeak(const psPtr ptr);74 bool pmPeakTest(const psPtr ptr); 75 75 76 /** pm FindVectorPeaks()76 /** pmPeaksInVector() 77 77 * 78 78 * Find all local peaks in the given vector above the given threshold. A peak … … 91 91 * 92 92 */ 93 psVector *pm FindVectorPeaks(93 psVector *pmPeaksInVector( 94 94 const psVector *vector, ///< The input vector (float) 95 95 float threshold ///< Threshold above which to find a peak … … 97 97 98 98 99 /** pm FindImagePeaks()99 /** pmPeaksInImage() 100 100 * 101 101 * Find all local peaks in the given image above the given threshold. This … … 111 111 * 112 112 */ 113 psArray *pm FindImagePeaks(113 psArray *pmPeaksInImage( 114 114 const psImage *image, ///< The input image where peaks will be found (float) 115 115 float threshold ///< Threshold above which to find a peak -
trunk/psModules/src/objects/pmSource.c
r14529 r14652 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-08- 16 18:33:00$8 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 27 27 #include "pmMoments.h" 28 28 #include "pmResiduals.h" 29 #include "pmGrowthCurve.h" 30 #include "pmPSF.h" 29 31 #include "pmModel.h" 30 32 #include "pmSource.h" … … 113 115 } 114 116 115 bool pm IsSource(const psPtr ptr)117 bool pmSourceTest(const psPtr ptr) 116 118 { 117 119 return (psMemGetDeallocator(ptr) == (psFreeFunc)sourceFree); … … 337 339 return emptyClump; 338 340 } 339 peaks = pm FindImagePeaks(splane, stats[0].max / 2);341 peaks = pmPeaksInImage (splane, stats[0].max / 2); 340 342 psTrace ("psModules.objects", 2, "clump threshold is %f\n", stats[0].max/2); 341 343 … … 797 799 798 800 // should we call pmSourceCacheModel if it does not exist? 799 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal ) {801 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal, int dx, int dy) { 800 802 801 803 bool status; … … 856 858 target = source->weight; 857 859 } 860 858 861 if (add) { 859 status = pmModelAdd (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);862 status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 860 863 } else { 861 status = pmModelSub (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);864 status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 862 865 } 863 866 … … 866 869 867 870 bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psMaskType maskVal) { 868 return pmSourceOp (source, mode, true, maskVal );871 return pmSourceOp (source, mode, true, maskVal, 0, 0); 869 872 } 870 873 871 874 bool pmSourceSub (pmSource *source, pmModelOpMode mode, psMaskType maskVal) { 872 return pmSourceOp (source, mode, false, maskVal); 875 return pmSourceOp (source, mode, false, maskVal, 0, 0); 876 } 877 878 bool pmSourceAddWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy) { 879 return pmSourceOp (source, mode, true, maskVal, dx, dy); 880 } 881 882 bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy) { 883 return pmSourceOp (source, mode, false, maskVal, dx, dy); 873 884 } 874 885 -
trunk/psModules/src/objects/pmSource.h
r14505 r14652 3 3 * @author EAM, IfA; GLG, MHPCC 4 4 * 5 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-08- 15 20:21:18$5 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-08-24 00:11:02 $ 7 7 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 8 8 */ … … 57 57 * 58 58 */ 59 typedef struct 60 { 59 struct pmSource { 61 60 const int id; ///< Unique ID for object 62 61 pmPeak *peak; ///< Description of peak pixel. … … 81 80 psRegion region; ///< area on image covered by selected pixels 82 81 float sky, skyErr; ///< The sky and its error at the center of the object 83 } 84 pmSource; 82 }; 85 83 86 84 /** pmPSFClump data structure … … 114 112 void pmSourceFreePixels(pmSource *source); 115 113 116 bool pm IsSource(const psPtr ptr);114 bool pmSourceTest(const psPtr ptr); 117 115 118 116 /** pmSourceDefinePixels() … … 218 216 bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psMaskType maskVal); 219 217 bool pmSourceSub (pmSource *source, pmModelOpMode mode, psMaskType maskVal); 220 221 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal); 218 bool pmSourceAddWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy); 219 bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy); 220 221 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal, int dx, int dy); 222 222 bool pmSourceCacheModel (pmSource *source, psMaskType maskVal); 223 223 bool pmSourceCachePSF (pmSource *source, psMaskType maskVal); -
trunk/psModules/src/objects/pmSourceContour.c
r12949 r14652 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 4-21 19:47:14$8 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 26 #include "pmMoments.h" 27 27 #include "pmResiduals.h" 28 #include "pmGrowthCurve.h" 29 #include "pmPSF.h" 28 30 #include "pmModel.h" 29 31 #include "pmSource.h" -
trunk/psModules/src/objects/pmSourceFitModel.c
r13932 r14652 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 6-21 22:58:11$8 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 27 27 #include "pmGrowthCurve.h" 28 28 #include "pmResiduals.h" 29 #include "pmPSF.h" 29 30 #include "pmModel.h" 30 #include "pmPSF.h"31 31 #include "pmSource.h" 32 #include "pmModel Group.h"32 #include "pmModelClass.h" 33 33 #include "pmSourceFitModel.h" 34 34 … … 116 116 psVector *dparams = model->dparams; 117 117 118 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);119 if (!modelFunc)120 psAbort("invalid model function");121 pmModelLimits checkLimits = pmModelLimits_GetFunction (model->type);122 if (!checkLimits)123 psAbort("invalid model limits function");124 125 118 // create the minimization constraints 126 119 psMinConstraint *constraint = psMinConstraintAlloc(); 127 120 constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_U8); 128 constraint->checkLimits = checkLimits;121 constraint->checkLimits = model->modelLimits; 129 122 130 123 // set parameter mask based on fitting mode … … 156 149 // force the floating parameters to fall within the contraint ranges 157 150 for (int i = 0; i < params->n; i++) { 158 checkLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);159 checkLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);151 model->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL); 152 model->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL); 160 153 } 161 154 … … 174 167 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); 175 168 176 fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, model Func);169 fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, model->modelFunc); 177 170 for (int i = 0; i < dparams->n; i++) { 178 171 if (psTraceGetLevel("psModules.objects") >= 4) { … … 201 194 altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1; 202 195 } 203 psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, model Func);196 psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, model->modelFunc); 204 197 for (int i = 0; i < dparams->n; i++) { 205 198 if (!constraint->paramMask->data.U8[i]) … … 237 230 } 238 231 239 /********************* Source Model Set Functions ***************************/240 241 // these static variables are used by one pass of pmSourceFitSet to store242 // data for a model set. If we are going to make psphot thread-safe, these243 // will have to go in a structure of their own or be allocated once per thread244 // sky, p1.1, p1.2, p1.3,... p1.n, p2.1, p2.2,245 // nPar = nSrc*(nOnePar - 1) + 1246 static pmModelFunc oneModelFunc;247 static pmModelLimits oneCheckLimits;248 static psVector *onePar;249 static psVector *oneDeriv;250 static int nOnePar;251 252 bool pmSourceFitSetInit (pmModelType type)253 {254 255 oneModelFunc = pmModelFunc_GetFunction (type);256 oneCheckLimits = pmModelLimits_GetFunction (type);257 nOnePar = pmModelParameterCount (type);258 259 onePar = psVectorAlloc (nOnePar, PS_DATA_F32);260 oneDeriv = psVectorAlloc (nOnePar, PS_DATA_F32);261 262 return true;263 }264 265 void pmSourceFitSetClear (void)266 {267 268 psFree (onePar);269 psFree (oneDeriv);270 return;271 }272 273 bool pmSourceFitSet_CheckLimits (psMinConstraintMode mode, int nParam, float *params, float *betas)274 {275 // convert the value of nParam into corresponding single model parameter entry276 // convert params into corresponding single model parameter pointer277 278 int nParamSingle = (nParam - 1) % (nOnePar - 1) + 1;279 float *paramSingle = params + nParam - nParamSingle;280 float *betaSingle = betas + nParam - nParamSingle;281 bool status = oneCheckLimits (mode, nParamSingle, paramSingle, betaSingle);282 return status;283 }284 285 psF32 pmSourceFitSet_Function(psVector *deriv,286 const psVector *params,287 const psVector *x)288 {289 290 psF32 value;291 psF32 model;292 293 psF32 *PAR = onePar->data.F32;294 psF32 *dPAR = oneDeriv->data.F32;295 296 psF32 *pars = params->data.F32;297 psF32 *dpars = (deriv == NULL) ? NULL : deriv->data.F32;298 299 int nSrc = (params->n - 1) / (nOnePar - 1);300 301 PAR[0] = model = pars[0];302 for (int i = 0; i < nSrc; i++) {303 int nOff = i*nOnePar - i;304 for (int n = 1; n < nOnePar; n++) {305 PAR[n] = pars[nOff + n];306 }307 if (deriv == NULL) {308 value = oneModelFunc (NULL, onePar, x);309 } else {310 value = oneModelFunc (oneDeriv, onePar, x);311 for (int n = 1; n < nOnePar; n++) {312 dpars[nOff + n] = dPAR[n];313 }314 }315 model += value;316 }317 if (deriv != NULL) {318 dpars[0] = dPAR[0]*2.0;319 }320 return (model);321 }322 323 /*324 i: 0 1 2325 n: 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6326 i*6 + n: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18327 */328 329 bool pmSourceFitSet (pmSource *source,330 psArray *modelSet,331 pmSourceFitMode mode,332 psMaskType maskVal)333 {334 psTrace("psModules.objects", 3, "---- %s begin ----\n", __func__);335 PS_ASSERT_PTR_NON_NULL(source, false);336 PS_ASSERT_PTR_NON_NULL(source->pixels, false);337 PS_ASSERT_PTR_NON_NULL(source->maskObj, false);338 PS_ASSERT_PTR_NON_NULL(source->weight, false);339 340 psBool fitStatus = true;341 psBool onPic = true;342 psBool rc = true;343 344 // maximum number of valid pixels345 psS32 nPix = source->pixels->numRows * source->pixels->numCols;346 347 // construct the coordinate and value entries348 psArray *x = psArrayAllocEmpty(nPix);349 psVector *y = psVectorAllocEmpty(nPix, PS_TYPE_F32);350 psVector *yErr = psVectorAllocEmpty(nPix, PS_TYPE_F32);351 352 // fill in the coordinate and value entries353 nPix = 0;354 for (psS32 i = 0; i < source->pixels->numRows; i++) {355 for (psS32 j = 0; j < source->pixels->numCols; j++) {356 // skip masked points357 if (source->maskObj->data.U8[i][j] & maskVal) {358 continue;359 }360 // skip zero-weight points361 if (source->weight->data.F32[i][j] == 0) {362 continue;363 }364 // skip nan values in image365 if (!isfinite(source->pixels->data.F32[i][j])) {366 continue;367 }368 369 psVector *coord = psVectorAlloc(2, PS_TYPE_F32);370 371 // Convert i/j to image space:372 coord->data.F32[0] = (psF32) (j + source->pixels->col0);373 coord->data.F32[1] = (psF32) (i + source->pixels->row0);374 x->data[nPix] = (psPtr *) coord;375 y->data.F32[nPix] = source->pixels->data.F32[i][j];376 377 // psMinimizeLMChi2 takes wt = 1/dY^2. suggestion from RHL is to use the local sky378 // as weight to avoid the bias from systematic errors here we would just use the379 // source sky variance380 if (PM_SOURCE_FIT_MODEL_PIX_WEIGHTS) {381 yErr->data.F32[nPix] = 1.0 / source->weight->data.F32[i][j];382 } else {383 yErr->data.F32[nPix] = 1.0 / PM_SOURCE_FIT_MODEL_WEIGHT;384 }385 nPix++;386 }387 }388 x->n = nPix;389 y->n = nPix;390 yErr->n = nPix;391 392 // base values on first model (all models must be identical)393 pmModel *model = modelSet->data[0];394 395 // determine number of model parameters396 int nSrc = modelSet->n;397 int nPar = model->params->n - 1; // number of object parameters (excluding sky)398 399 // define parameter vectors for source set400 psVector *params = psVectorAlloc (nSrc*nPar + 1, PS_TYPE_F32);401 psVector *dparams = psVectorAlloc (nSrc*nPar + 1, PS_TYPE_F32);402 403 // set the static variables404 pmSourceFitSetInit (model->type);405 406 // create the minimization constraints407 psMinConstraint *constraint = psMinConstraintAlloc();408 constraint->paramMask = psVectorAlloc (nSrc*nPar + 1, PS_TYPE_U8);409 constraint->checkLimits = pmSourceFitSet_CheckLimits;410 411 // set the parameter guesses for the multiple models412 // first the value for the single sky parameter413 params->data.F32[0] = model->params->data.F32[0];414 415 // next, the values for the source parameters416 for (int i = 0; i < nSrc; i++) {417 model = modelSet->data[i];418 for (int n = 1; n < nPar + 1; n++) {419 params->data.F32[i*nPar + n] = model->params->data.F32[n];420 }421 }422 423 if (psTraceGetLevel("psModules.objects") >= 5) {424 for (int i = 0; i < params->n; i++) {425 fprintf (stderr, "%d %f %d\n", i, params->data.F32[i], constraint->paramMask->data.U8[i]);426 }427 }428 429 // set the parameter masks based on the fitting mode430 int nParams = 0;431 switch (mode) {432 case PM_SOURCE_FIT_NORM:433 // NORM-only model fits only source normalization (Io)434 nParams = nSrc;435 psVectorInit (constraint->paramMask, 1);436 for (int i = 0; i < nSrc; i++) {437 constraint->paramMask->data.U8[1 + i*nPar] = 0;438 }439 break;440 case PM_SOURCE_FIT_PSF:441 // PSF model only fits x,y,Io442 nParams = 3*nSrc;443 psVectorInit (constraint->paramMask, 1);444 for (int i = 0; i < nSrc; i++) {445 constraint->paramMask->data.U8[1 + i*nPar] = 0;446 constraint->paramMask->data.U8[2 + i*nPar] = 0;447 constraint->paramMask->data.U8[3 + i*nPar] = 0;448 }449 break;450 case PM_SOURCE_FIT_EXT:451 // EXT model fits all params (except sky)452 nParams = nPar*nSrc;453 psVectorInit (constraint->paramMask, 0);454 constraint->paramMask->data.U8[0] = 1;455 break;456 default:457 psAbort("invalid fitting mode");458 }459 460 // force the floating parameters to fall within the contraint ranges461 for (int i = 0; i < params->n; i++) {462 pmSourceFitSet_CheckLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);463 pmSourceFitSet_CheckLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);464 }465 466 if (nPix < nParams + 1) {467 psTrace (__func__, 4, "insufficient valid pixels\n");468 psTrace("psModules.objects", 3, "---- %s() end : fail pixels ----\n", __func__);469 model->flags |= PM_MODEL_STATUS_BADARGS;470 psFree (x);471 psFree (y);472 psFree (yErr);473 psFree (params);474 psFree (dparams);475 psFree(constraint);476 pmSourceFitSetClear ();477 return(false);478 }479 480 psMinimization *myMin = psMinimizationAlloc (PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_TOLERANCE);481 482 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);483 484 fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, pmSourceFitSet_Function);485 if (!fitStatus) {486 psTrace("psModules.objects", 4, "Failed to fit model (%d)\n", nSrc);487 }488 489 // parameter errors from the covariance matrix490 for (int i = 0; i < dparams->n; i++) {491 if ((constraint->paramMask != NULL) && constraint->paramMask->data.U8[i])492 continue;493 dparams->data.F32[i] = sqrt(covar->data.F32[i][i]);494 }495 496 // get the Gauss-Newton distance for fixed model parameters497 if (constraint->paramMask != NULL) {498 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F32);499 psVector *altmask = psVectorAlloc (params->n, PS_TYPE_U8);500 altmask->data.U8[0] = 1;501 for (int i = 1; i < dparams->n; i++) {502 altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1;503 }504 psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSet_Function);505 for (int i = 0; i < dparams->n; i++) {506 if (!constraint->paramMask->data.U8[i])507 continue;508 // note that delta is the value *subtracted* from the parameter509 // to get the new guess. for dparams to represent the direction510 // of motion, we need to take -delta511 dparams->data.F32[i] = -delta->data.F32[i];512 }513 psFree (delta);514 psFree (altmask);515 }516 517 // assign back the parameters to the models518 for (int i = 0; i < nSrc; i++) {519 model = modelSet->data[i];520 model->params->data.F32[0] = params->data.F32[0];521 for (int n = 1; n < nPar + 1; n++) {522 if (psTraceGetLevel("psModules.objects") >= 4) {523 fprintf (stderr, "%f ", params->data.F32[i*nPar + n]);524 }525 model->params->data.F32[n] = params->data.F32[i*nPar + n];526 model->dparams->data.F32[n] = dparams->data.F32[i*nPar + n];527 }528 psTrace ("psModules.objects", 4, " src %d", i);529 530 // save the resulting chisq, nDOF, nIter531 // these are not unique for any one source532 model->chisq = myMin->value;533 model->nIter = myMin->iter;534 model->nDOF = y->n - nParams;535 536 // set the model success or failure status537 model->flags |= PM_MODEL_STATUS_FITTED;538 if (!fitStatus) model->flags |= PM_MODEL_STATUS_NONCONVERGE;539 540 // models can go insane: reject these541 onPic &= (model->params->data.F32[PM_PAR_XPOS] >= source->pixels->col0);542 onPic &= (model->params->data.F32[PM_PAR_XPOS] < source->pixels->col0 + source->pixels->numCols);543 onPic &= (model->params->data.F32[PM_PAR_XPOS] >= source->pixels->row0);544 onPic &= (model->params->data.F32[PM_PAR_XPOS] < source->pixels->row0 + source->pixels->numRows);545 if (!onPic) model->flags |= PM_MODEL_STATUS_OFFIMAGE;546 }547 psTrace ("psModules.objects", 4, "niter: %d, chisq: %f", myMin->iter, myMin->value);548 549 source->mode |= PM_SOURCE_MODE_FITTED;550 551 psFree(x);552 psFree(y);553 psFree(yErr);554 psFree(myMin);555 psFree(covar);556 psFree(constraint);557 psFree(params);558 psFree(dparams);559 560 // free static memory used by pmSourceFitSet561 pmSourceFitSetClear ();562 563 rc = (onPic && fitStatus);564 psTrace (__func__, 5, "onPic: %d, fitStatus: %d, nIter: %d, chisq: %f, nDof: %d\n", onPic, fitStatus, model->nIter, model->chisq, model->nDOF);565 psTrace("psModules.objects", 5, "---- %s end (%d) ----\n", __func__, rc);566 return(rc);567 }568 -
trunk/psModules/src/objects/pmSourceIO.c
r14208 r14652 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1.4 5$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 7-14 03:20:44$5 * @version $Revision: 1.46 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-08-24 00:11:02 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 34 34 #include "pmGrowthCurve.h" 35 35 #include "pmResiduals.h" 36 #include "pmPSF.h" 36 37 #include "pmModel.h" 37 #include "pmPSF.h"38 38 #include "pmSource.h" 39 #include "pmModel Group.h"39 #include "pmModelClass.h" 40 40 #include "pmSourceIO.h" 41 41 -
trunk/psModules/src/objects/pmSourceIO_CMP.c
r13137 r14652 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 5-03 00:13:03$5 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-08-24 00:11:02 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 #include "pmGrowthCurve.h" 33 33 #include "pmResiduals.h" 34 #include "pmPSF.h" 34 35 #include "pmModel.h" 35 #include "pmPSF.h"36 36 #include "pmSource.h" 37 #include "pmModel Group.h"37 #include "pmModelClass.h" 38 38 #include "pmSourceIO.h" 39 39 … … 154 154 155 155 // define PSF model type 156 int modelType = pmModel SetType ("PS_MODEL_GAUSS");156 int modelType = pmModelClassGetType ("PS_MODEL_GAUSS"); 157 157 158 158 char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME"); 159 159 if (PSF_NAME != NULL) { 160 modelType = pmModel SetType (PSF_NAME);160 modelType = pmModelClassGetType (PSF_NAME); 161 161 } 162 162 -
trunk/psModules/src/objects/pmSourceIO_OBJ.c
r13137 r14652 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 5-03 00:13:03$5 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-08-24 00:11:02 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 #include "pmGrowthCurve.h" 33 33 #include "pmResiduals.h" 34 #include "pmPSF.h" 34 35 #include "pmModel.h" 35 #include "pmPSF.h"36 36 #include "pmSource.h" 37 #include "pmModel Group.h"37 #include "pmModelClass.h" 38 38 #include "pmSourceIO.h" 39 39 -
trunk/psModules/src/objects/pmSourceIO_PS1_DEV_0.c
r13139 r14652 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 5-03 00:13:42 $5 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-08-24 00:11:02 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 #include "pmGrowthCurve.h" 33 33 #include "pmResiduals.h" 34 #include "pmPSF.h" 34 35 #include "pmModel.h" 35 #include "pmPSF.h"36 36 #include "pmSource.h" 37 #include "pmModel Group.h"37 #include "pmModelClass.h" 38 38 #include "pmSourceIO.h" 39 39 … … 152 152 153 153 // define PSF model type 154 int modelType = pmModel SetType ("PS_MODEL_GAUSS");154 int modelType = pmModelClassGetType ("PS_MODEL_GAUSS"); 155 155 156 156 char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME"); 157 157 if (PSF_NAME != NULL) { 158 modelType = pmModel SetType (PSF_NAME);158 modelType = pmModelClassGetType (PSF_NAME); 159 159 } 160 160 -
trunk/psModules/src/objects/pmSourceIO_RAW.c
r12949 r14652 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 4-21 19:47:14$5 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-08-24 00:11:02 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 #include "pmGrowthCurve.h" 33 33 #include "pmResiduals.h" 34 #include "pmPSF.h" 34 35 #include "pmModel.h" 35 #include "pmPSF.h"36 36 #include "pmSource.h" 37 #include "pmModel Group.h"37 #include "pmModelClass.h" 38 38 #include "pmSourcePhotometry.h" 39 39 #include "pmSourceIO.h" -
trunk/psModules/src/objects/pmSourceIO_SMPDATA.c
r13139 r14652 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 5-03 00:13:42 $5 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-08-24 00:11:02 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 30 30 #include "pmPeaks.h" 31 31 #include "pmMoments.h" 32 #include "pmResiduals.h" 32 33 #include "pmGrowthCurve.h" 33 #include "pm Residuals.h"34 #include "pmPSF.h" 34 35 #include "pmModel.h" 35 #include "pmPSF.h"36 36 #include "pmSource.h" 37 #include "pmModel Group.h"37 #include "pmModelClass.h" 38 38 #include "pmSourceIO.h" 39 39 … … 132 132 133 133 // define PSF model type 134 int modelType = pmModel SetType ("PS_MODEL_GAUSS");134 int modelType = pmModelClassGetType ("PS_MODEL_GAUSS"); 135 135 136 136 char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME"); 137 137 if (PSF_NAME != NULL) { 138 modelType = pmModel SetType (PSF_NAME);138 modelType = pmModelClassGetType (PSF_NAME); 139 139 } 140 140 -
trunk/psModules/src/objects/pmSourceIO_SX.c
r13064 r14652 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 4-27 22:14:08$5 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-08-24 00:11:02 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 #include "pmGrowthCurve.h" 33 33 #include "pmResiduals.h" 34 #include "pmPSF.h" 34 35 #include "pmModel.h" 35 #include "pmPSF.h"36 36 #include "pmSource.h" 37 #include "pmModel Group.h"37 #include "pmModelClass.h" 38 38 #include "pmSourceIO.h" 39 39 -
trunk/psModules/src/objects/pmSourcePhotometry.c
r13898 r14652 3 3 * @author EAM, IfA; GLG, MHPCC 4 4 * 5 * @version $Revision: 1.2 8$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 6-20 02:22:26$5 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-08-24 00:11:02 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 26 #include "pmGrowthCurve.h" 27 27 #include "pmResiduals.h" 28 #include "pmPSF.h" 28 29 #include "pmModel.h" 29 #include "pmPSF.h"30 30 #include "pmSource.h" 31 #include "pmModel Group.h"31 #include "pmModelClass.h" 32 32 #include "pmSourcePhotometry.h" 33 33 … … 250 250 251 251 // measure fitMag 252 pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type); 253 fitSum = modelFluxFunc (model->params); 252 fitSum = model->modelFlux (model->params); 254 253 if (fitSum <= 0) 255 254 return false; … … 324 323 325 324 // the model function returns the source flux at a position 326 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);327 325 psVector *coord = psVectorAlloc(2, PS_TYPE_F32); 328 326 … … 354 352 355 353 // for the full model, add all points 356 value = model Func (NULL, params, coord) - sky;354 value = model->modelFunc (NULL, params, coord) - sky; 357 355 modelSum += value; 358 356 -
trunk/psModules/src/objects/pmSourcePlotApResid.c
r13473 r14652 4 4 * @author EAM, IfA 5 5 * 6 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $7 * @date $Date: 2007-0 5-22 21:45:48$6 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-08-24 00:11:02 $ 8 8 * Copyright 2006 IfA, University of Hawaii 9 9 */ … … 27 27 #include "pmPeaks.h" 28 28 #include "pmMoments.h" 29 #include "pmResiduals.h" 29 30 #include "pmGrowthCurve.h" 30 #include "pm Residuals.h"31 #include "pmPSF.h" 31 32 #include "pmModel.h" 32 #include "pmPSF.h"33 33 #include "pmSource.h" 34 34 #include "pmSourcePlots.h" -
trunk/psModules/src/objects/pmSourcePlotMoments.c
r13473 r14652 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 5-22 21:45:48$7 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-08-24 00:11:02 $ 9 9 * 10 10 * Copyright 2006 IfA, University of Hawaii … … 32 32 #include "pmGrowthCurve.h" 33 33 #include "pmResiduals.h" 34 #include "pmPSF.h" 34 35 #include "pmModel.h" 35 #include "pmPSF.h"36 36 #include "pmSource.h" 37 37 #include "pmSourcePlots.h" -
trunk/psModules/src/objects/pmSourcePlotPSFModel.c
r13473 r14652 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 5-22 21:45:48$7 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-08-24 00:11:02 $ 9 9 * 10 10 * Copyright 2006 IfA, University of Hawaii … … 32 32 #include "pmGrowthCurve.h" 33 33 #include "pmResiduals.h" 34 #include "pmPSF.h" 34 35 #include "pmModel.h" 35 #include "pmPSF.h"36 36 #include "pmSource.h" 37 37 #include "pmSourcePlots.h" -
trunk/psModules/src/objects/pmSourceSky.c
r13898 r14652 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 6-20 02:22:26$8 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 27 27 #include "pmMoments.h" 28 28 #include "pmResiduals.h" 29 #include "pmGrowthCurve.h" 30 #include "pmPSF.h" 29 31 #include "pmModel.h" 30 32 #include "pmSource.h"
Note:
See TracChangeset
for help on using the changeset viewer.
