Changeset 14655
- Timestamp:
- Aug 23, 2007, 2:40:16 PM (19 years ago)
- Location:
- trunk/psphot
- Files:
-
- 23 edited
-
doc/notes.txt (modified) (2 diffs)
-
src/models/pmModel_STRAIL.c (modified) (6 diffs)
-
src/models/pmModel_TEST1.c (modified) (7 diffs)
-
src/pmFootprint.c (modified) (9 diffs)
-
src/pmFootprint.h (modified) (2 diffs)
-
src/psphot.c (modified) (1 diff)
-
src/psphot.h (modified) (1 diff)
-
src/psphotAddNoise.c (modified) (1 diff)
-
src/psphotChoosePSF.c (modified) (4 diffs)
-
src/psphotCleanup.c (modified) (1 diff)
-
src/psphotEvalFLT.c (modified) (1 diff)
-
src/psphotFakeSources.c (modified) (1 diff)
-
src/psphotFindPeaks.c (modified) (1 diff)
-
src/psphotGrowthCurve.c (modified) (3 diffs)
-
src/psphotModelGroupInit.c (modified) (1 diff)
-
src/psphotModelTest.c (modified) (3 diffs)
-
src/psphotPSFConvModel.c (modified) (3 diffs)
-
src/psphotPSFResiduals.c (modified) (1 diff)
-
src/psphotRadiusChecks.c (modified) (7 diffs)
-
src/psphotReadout.c (modified) (1 diff)
-
src/psphotReadoutCleanup.c (modified) (1 diff)
-
src/psphotSourceFits.c (modified) (1 diff)
-
src/psphotTestSourceOutput.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/doc/notes.txt
r10033 r14655 1 2 2007.08.17 3 4 I am working on a number of cleanup / fixes. I have made an overhaul 5 of the pmModel APIs, adding function pointers in the pmModel 6 structure to the class-specific utility functions (eg, 7 pmModel->modelFunc is the actual function which is evaluated). 8 9 TO DO: 10 11 * update pmSourceFitSet to be able to include more than one model 12 type (currently it assumes the sources are all, eg, PSFs). This is 13 now needed because the old implementation used the function lookups 14 which have been dropped. 15 16 * define a generic API set to handle 2D modelling of a scalar using 17 either polynomials (as the pmPSF code currently does) or an 18 image-based representation (as the psphot sky model currently 19 does). 20 21 The image-based representation can automatically step down from NxM 22 super pixels to a smaller number based on the density of 23 measurements. 24 25 Include ways to smooth and regularize the output result. 26 27 This mechanism can be applied to: psf parameters, aperture 28 residual, psf peak-to-flux variations, the psphot background 29 representation. 30 31 * generate and store the output radial profile for objects 32 33 * finish testing and incorportate the CR / EXT measurements 34 35 * adjustments to pixel center based on second derivatives : needed 36 for the sersic models. 37 38 * adjustments to pixel flux for extreme values (r ~ 0) : needed for 39 the sersic models. 40 41 * on psf stars : fall back on a Gaussian. 42 43 * OPTIMIZATIONS !! 44 45 * drop the model sky element : should only be in source->sky,dsky 46 47 2006.11.16 1 48 2 49 ensemble: … … 20 67 * solve for source amplitudes 21 68 * update models 22 23 2006.11.1624 69 25 70 * create psSparseBorder to solve matrix equations which have a large -
trunk/psphot/src/models/pmModel_STRAIL.c
r11702 r14655 12 12 *****************************************************************************/ 13 13 14 # define PM_MODEL_FUNC pmModelFunc_STRAIL 15 # define PM_MODEL_FLUX pmModelFlux_STRAIL 16 # define PM_MODEL_GUESS pmModelGuess_STRAIL 17 # define PM_MODEL_LIMITS pmModelLimits_STRAIL 18 # define PM_MODEL_RADIUS pmModelRadius_STRAIL 19 # define PM_MODEL_FROM_PSF pmModelFromPSF_STRAIL 20 # define PM_MODEL_FIT_STATUS pmModelFitStatus_STRAIL 14 # define PM_MODEL_FUNC pmModelFunc_STRAIL 15 # define PM_MODEL_FLUX pmModelFlux_STRAIL 16 # define PM_MODEL_GUESS pmModelGuess_STRAIL 17 # define PM_MODEL_LIMITS pmModelLimits_STRAIL 18 # define PM_MODEL_RADIUS pmModelRadius_STRAIL 19 # define PM_MODEL_FROM_PSF pmModelFromPSF_STRAIL 20 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_STRAIL 21 # define PM_MODEL_FIT_STATUS pmModelFitStatus_STRAIL 21 22 22 23 psF32 PM_MODEL_FUNC(psVector *deriv, … … 474 475 475 476 //fixed I think...no good way of guessing as far as I can tell 476 bool PM_MODEL_GUESS (pmModel *model, pmSource *source) {477 477 bool PM_MODEL_GUESS (pmModel *model, pmSource *source) 478 { 478 479 pmMoments *Smoments = source->moments; 479 480 psF32 *params = model->params->data.F32; … … 516 517 517 518 //fixed 518 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf) {519 519 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf) 520 { 520 521 psF32 *out = modelPSF->params->data.F32; 521 522 psF32 *in = modelFLT->params->data.F32; … … 529 530 530 531 for (int i = 4; i < 7; i++) { 531 psPolynomial2D *poly = psf->params _NEW->data[i-4];532 psPolynomial2D *poly = psf->params->data[i-4]; 532 533 out[i] = psPolynomial2DEval (poly, out[2], out[3]); 533 534 } … … 535 536 } 536 537 538 // construct the PSF model from the FLT model and the psf 539 // XXX is this sufficiently general do be a global function, not a pmModelClass function? 540 bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io) 541 { 542 psF32 *PAR = model->params->data.F32; 543 544 // we require these two parameters to exist 545 assert (psf->params->n > PM_PAR_YPOS); 546 assert (psf->params->n > PM_PAR_XPOS); 547 548 PAR[PM_PAR_SKY] = 0.0; 549 PAR[PM_PAR_I0] = Io; 550 PAR[PM_PAR_XPOS] = Xo; 551 PAR[PM_PAR_YPOS] = Yo; 552 553 // supply the model-fitted parameters, or copy from the input 554 for (int i = 0; i < psf->params->n; i++) { 555 if (i == PM_PAR_SKY) continue; 556 psPolynomial2D *poly = psf->params->data[i]; 557 assert (poly); 558 PAR[i] = psPolynomial2DEval(poly, Xo, Yo); 559 } 560 561 // the 2D PSF model fits polarization terms (E0,E1,E2) 562 // convert to shape terms (SXX,SYY,SXY) 563 // XXX user-defined value for limit? 564 if (!pmPSF_FitToModel (PAR, 0.1)) { 565 psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo); 566 return false; 567 } 568 569 // apply the model limits here: this truncates excessive extrapolation 570 // XXX do we need to do this still? should we put in asserts to test? 571 for (int i = 0; i < psf->params->n; i++) { 572 // apply the limits to all components or just the psf-model parameters? 573 if (psf->params->data[i] == NULL) 574 continue; 575 576 bool status = true; 577 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL); 578 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL); 579 if (!status) { 580 psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo); 581 model->flags |= PM_MODEL_STATUS_LIMITS; 582 } 583 } 584 return(true); 585 } 586 537 587 //done I think 538 bool PM_MODEL_FIT_STATUS (pmModel *model) {539 588 bool PM_MODEL_FIT_STATUS (pmModel *model) 589 { 540 590 psF32 dP; 541 591 bool status; … … 566 616 # undef PM_MODEL_RADIUS 567 617 # undef PM_MODEL_FROM_PSF 618 # undef PM_MODEL_PARAMS_FROM_PSF 568 619 # undef PM_MODEL_FIT_STATUS -
trunk/psphot/src/models/pmModel_TEST1.c
r11702 r14655 16 16 *****************************************************************************/ 17 17 18 # define PM_MODEL_FUNC pmModelFunc_TEST1 19 # define PM_MODEL_FLUX pmModelFlux_TEST1 20 # define PM_MODEL_GUESS pmModelGuess_TEST1 21 # define PM_MODEL_LIMITS pmModelLimits_TEST1 22 # define PM_MODEL_RADIUS pmModelRadius_TEST1 23 # define PM_MODEL_FROM_PSF pmModelFromPSF_TEST1 24 # define PM_MODEL_FIT_STATUS pmModelFitStatus_TEST1 25 26 // XXX consider changing to form PAR[SXY]*(1/PAR[SXX]^2 + 1/PAR[SYY]^2)*X*Y 27 // this would provide natural limits on PAR[SXY] of -0.25 : +0.25 18 # define PM_MODEL_FUNC pmModelFunc_TEST1 19 # define PM_MODEL_FLUX pmModelFlux_TEST1 20 # define PM_MODEL_GUESS pmModelGuess_TEST1 21 # define PM_MODEL_LIMITS pmModelLimits_TEST1 22 # define PM_MODEL_RADIUS pmModelRadius_TEST1 23 # define PM_MODEL_FROM_PSF pmModelFromPSF_TEST1 24 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_TEST1 25 # define PM_MODEL_FIT_STATUS pmModelFitStatus_TEST1 28 26 29 27 // the model is a function of the pixel coordinate (pixcoord[0,1] = x,y) 30 28 psF32 PM_MODEL_FUNC(psVector *deriv, 31 const psVector *params,32 const psVector *pixcoord)29 const psVector *params, 30 const psVector *pixcoord) 33 31 { 34 32 psF32 *PAR = params->data.F32; … … 127 125 bool PM_MODEL_GUESS (pmModel *model, pmSource *source) 128 126 { 129 130 127 pmMoments *moments = source->moments; 131 128 psF32 *PAR = model->params->data.F32; … … 160 157 norm = 0.0; 161 158 162 # define DZ 0.25159 # define DZ 0.25 163 160 164 161 float f0 = 1.0; … … 209 206 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf) 210 207 { 211 212 208 psF32 *out = modelPSF->params->data.F32; 213 209 psF32 *in = modelFLT->params->data.F32; 214 210 215 211 // we require these two parameters to exist 216 assert (psf->params _NEW->n > PM_PAR_YPOS);217 assert (psf->params _NEW->n > PM_PAR_XPOS);218 219 for (int i = 0; i < psf->params _NEW->n; i++) {220 if (psf->params _NEW->data[i] == NULL) {212 assert (psf->params->n > PM_PAR_YPOS); 213 assert (psf->params->n > PM_PAR_XPOS); 214 215 for (int i = 0; i < psf->params->n; i++) { 216 if (psf->params->data[i] == NULL) { 221 217 out[i] = in[i]; 222 218 } else { 223 psPolynomial2D *poly = psf->params _NEW->data[i];219 psPolynomial2D *poly = psf->params->data[i]; 224 220 out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]); 225 221 } … … 229 225 out[PM_PAR_SXY] = pmPSF_SXYtoModel (out); 230 226 227 return(true); 228 } 229 230 // construct the PSF model from the FLT model and the psf 231 // XXX is this sufficiently general do be a global function, not a pmModelClass function? 232 bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io) 233 { 234 psF32 *PAR = model->params->data.F32; 235 236 // we require these two parameters to exist 237 assert (psf->params->n > PM_PAR_YPOS); 238 assert (psf->params->n > PM_PAR_XPOS); 239 240 PAR[PM_PAR_SKY] = 0.0; 241 PAR[PM_PAR_I0] = Io; 242 PAR[PM_PAR_XPOS] = Xo; 243 PAR[PM_PAR_YPOS] = Yo; 244 245 // supply the model-fitted parameters, or copy from the input 246 for (int i = 0; i < psf->params->n; i++) { 247 if (i == PM_PAR_SKY) continue; 248 psPolynomial2D *poly = psf->params->data[i]; 249 assert (poly); 250 PAR[i] = psPolynomial2DEval(poly, Xo, Yo); 251 } 252 253 // the 2D PSF model fits polarization terms (E0,E1,E2) 254 // convert to shape terms (SXX,SYY,SXY) 255 // XXX user-defined value for limit? 256 if (!pmPSF_FitToModel (PAR, 0.1)) { 257 psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo); 258 return false; 259 } 260 261 // apply the model limits here: this truncates excessive extrapolation 262 // XXX do we need to do this still? should we put in asserts to test? 263 for (int i = 0; i < psf->params->n; i++) { 264 // apply the limits to all components or just the psf-model parameters? 265 if (psf->params->data[i] == NULL) 266 continue; 267 268 bool status = true; 269 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL); 270 status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL); 271 if (!status) { 272 psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo); 273 model->flags |= PM_MODEL_STATUS_LIMITS; 274 } 275 } 231 276 return(true); 232 277 } … … 237 282 bool PM_MODEL_FIT_STATUS (pmModel *model) 238 283 { 239 240 284 psF32 dP; 241 285 bool status; … … 265 309 # undef PM_MODEL_RADIUS 266 310 # undef PM_MODEL_FROM_PSF 311 # undef PM_MODEL_PARAMS_FROM_PSF 267 312 # undef PM_MODEL_FIT_STATUS -
trunk/psphot/src/pmFootprint.c
r14335 r14655 29 29 } 30 30 31 bool pm IsSpan(const psPtr ptr)31 bool pmSpanTest(const psPtr ptr) 32 32 { 33 33 return (psMemGetDeallocator(ptr) == (psFreeFunc)spanFree); … … 115 115 } 116 116 117 bool pm IsFootprint(const psPtr ptr) {117 bool pmFootprintTest(const psPtr ptr) { 118 118 return (psMemGetDeallocator(ptr) == (psFreeFunc)footprintFree); 119 119 } … … 762 762 // Set stop bits from peaks list 763 763 // 764 assert (peaks == NULL || peaks->n == 0 || pm IsPeak(peaks->data[0]));764 assert (peaks == NULL || peaks->n == 0 || pmPeakTest(peaks->data[0])); 765 765 if (peaks != NULL) { 766 766 for (int i = 0; i < peaks->n; i++) { … … 859 859 } 860 860 const pmFootprint *fp = footprints->data[0]; 861 assert(pm IsFootprint((const psPtr)fp));861 assert(pmFootprintTest((const psPtr)fp)); 862 862 const int numCols = fp->region.x1 - fp->region.x0 + 1; 863 863 const int numRows = fp->region.y1 - fp->region.y0 + 1; … … 884 884 psImage *pmSetFootprintID(const pmFootprint *fp, // the footprint to insert 885 885 const int id) { // the desired ID 886 assert(fp != NULL && pm IsFootprint((const psPtr)fp));886 assert(fp != NULL && pmFootprintTest((const psPtr)fp)); 887 887 const int numCols = fp->region.x1 - fp->region.x0 + 1; 888 888 const int numRows = fp->region.y1 - fp->region.y0 + 1; … … 910 910 psArray *pmGrowFootprintArray(const psArray *footprints, // footprints to grow 911 911 int r) { // how much to grow each footprint 912 assert (footprints->n == 0 || pm IsFootprint(footprints->data[0]));912 assert (footprints->n == 0 || pmFootprintTest(footprints->data[0])); 913 913 914 914 if (footprints->n == 0) { // we don't know the size of the footprint's region … … 964 964 const psArray *footprints2, // the other set 965 965 const int includePeaks) { // which peaks to set? 0x1 => footprints1, 0x2 => 2 966 assert (footprints1->n == 0 || pm IsFootprint(footprints1->data[0]));967 assert (footprints2->n == 0 || pm IsFootprint(footprints2->data[0]));966 assert (footprints1->n == 0 || pmFootprintTest(footprints1->data[0])); 967 assert (footprints2->n == 0 || pmFootprintTest(footprints2->data[0])); 968 968 969 969 if (footprints1->n == 0 || footprints2->n == 0) { // nothing to do but put copies on merged … … 1032 1032 const psArray *peaks) { // the pmPeaks 1033 1033 assert (footprints != NULL); 1034 assert (footprints->n == 0 || pm IsFootprint(footprints->data[0]));1034 assert (footprints->n == 0 || pmFootprintTest(footprints->data[0])); 1035 1035 assert (peaks != NULL); 1036 assert (peaks->n == 0 || pm IsPeak(peaks->data[0]));1036 assert (peaks->n == 0 || pmPeakTest(peaks->data[0])); 1037 1037 1038 1038 if (footprints->n == 0) { … … 1222 1222 psArray *pmFootprintArrayToPeaks(const psArray *footprints) { 1223 1223 assert(footprints != NULL); 1224 assert(footprints->n == 0 || pm IsFootprint(footprints->data[0]));1224 assert(footprints->n == 0 || pmFootprintTest(footprints->data[0])); 1225 1225 1226 1226 int npeak = 0; -
trunk/psphot/src/pmFootprint.h
r13442 r14655 11 11 12 12 pmSpan *pmSpanAlloc(int y, int x1, int x2); 13 bool pm IsSpan(const psPtr ptr);13 bool pmSpanTest(const psPtr ptr); 14 14 int pmSpanSortByYX (const void **a, const void **b); 15 15 … … 25 25 26 26 pmFootprint *pmFootprintAlloc(int nspan, const psImage *img); 27 bool pm IsFootprint(const psPtr ptr);27 bool pmFootprintTest(const psPtr ptr); 28 28 29 29 pmFootprint *pmFootprintNormalize(pmFootprint *fp); -
trunk/psphot/src/psphot.c
r14005 r14655 11 11 pmErrorRegister(); // register psModule's error codes/messages 12 12 psphotErrorRegister(); // register our error codes/messages 13 psphotModel GroupInit (); // load implementation-specific models13 psphotModelClassInit (); // load implementation-specific models 14 14 15 15 // load command-line arguments, options, and system config data -
trunk/psphot/src/psphot.h
r14338 r14655 51 51 52 52 // basic support functions 53 void psphotModel GroupInit (void);53 void psphotModelClassInit (void); 54 54 int pmPeakSortBySN (const void **a, const void **b); 55 55 int pmPeakSortByY (const void **a, const void **b); -
trunk/psphot/src/psphotAddNoise.c
r13900 r14655 68 68 69 69 // XXX if we use pmSourceOp, the size (and possibly Io) will not be respected 70 pmSourceOp (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, add, maskVal );70 pmSourceOp (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, add, maskVal, 0, 0); 71 71 72 72 // restore original values -
trunk/psphot/src/psphotChoosePSF.c
r13900 r14655 127 127 // print/dump psf parameters 128 128 if (psTraceGetLevel("psphot") >= 5) { 129 for (int i = PM_PAR_SXX; i < try->psf->params _NEW->n; i++) {130 psPolynomial2D *poly = try->psf->params _NEW->data[i];129 for (int i = PM_PAR_SXX; i < try->psf->params->n; i++) { 130 psPolynomial2D *poly = try->psf->params->data[i]; 131 131 for (int nx = 0; nx <= poly->nX; nx++) { 132 132 for (int ny = 0; ny <= poly->nY; ny++) { … … 295 295 } 296 296 297 char *modelName = pmModel GetType (psf->type);297 char *modelName = pmModelClassGetName (psf->type); 298 298 psLogMsg ("psphot.pspsf", PS_LOG_INFO, "select psf model: %f sec\n", psTimerMark ("psphot")); 299 299 psLogMsg ("psphot.pspsf", PS_LOG_INFO, "psf model %s, ApResid: %f +/- %f\n", modelName, psf->ApResid, psf->dApResid); … … 315 315 PS_ASSERT_PTR_NON_NULL(image, false); 316 316 317 pmModel *modelEXT = pmModelAlloc (psf->type); 318 PS_ASSERT_PTR_NON_NULL(modelEXT, false); 319 320 // make a model with unit central intensity at the image center 321 modelEXT->params->data.F32[PM_PAR_SKY] = 0; 322 modelEXT->params->data.F32[PM_PAR_I0] = 1; 323 modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*image->numCols; 324 modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*image->numRows; 325 326 // construct a PSF model at this coordinate 327 pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); 317 // construct a normalized PSF model at this coordinate (Io = 1.0) 318 pmModel *modelPSF = pmModelFromPSFforXY (psf, 0.5*image->numCols, 0.5*image->numRows, 1.0); 328 319 if (modelPSF == NULL) { 329 320 psError(PSPHOT_ERR_PSF, false, "Failed to estimate PSF model at image centre"); 330 psFree(modelEXT);331 321 return false; 332 322 } 333 323 334 // get the correct model-radius function335 pmModelRadius modelRadiusFunc = pmModelRadius_GetFunction (psf->type);336 337 324 // get the model full-width at half-max 338 psF64 FWHM_X = 2*model RadiusFunc(modelPSF->params, 0.5);325 psF64 FWHM_X = 2*modelPSF->modelRadius (modelPSF->params, 0.5); 339 326 340 327 // XXX make sure this is consistent with the re-definition of PM_PAR_SXX … … 351 338 psMetadataAddS32 (recipe, PS_LIST_TAIL, "NPSFSTAR", PS_META_REPLACE, "Number of stars used to make PSF", psf->nPSFstars); 352 339 psMetadataAddBool(recipe, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "Valid PSF Model?", true); 353 354 psFree (modelEXT);355 340 psFree (modelPSF); 356 341 -
trunk/psphot/src/psphotCleanup.c
r12805 r14655 7 7 psTimerStop (); 8 8 psMemCheckCorruption (stderr, true); 9 pmModel GroupCleanup ();9 pmModelClassCleanup (); 10 10 psTimeFinalize (); 11 11 pmConceptsDone (); -
trunk/psphot/src/psphotEvalFLT.c
r13804 r14655 37 37 } 38 38 39 keep = pmModelFitStatus(model);39 keep = model->modelFitStatus(model); 40 40 if (keep) return true; 41 41 -
trunk/psphot/src/psphotFakeSources.c
r12792 r14655 23 23 source->type = PM_SOURCE_TYPE_STAR; 24 24 25 pmModelType modelType = pmModel SetType ("PS_MODEL_QGAUSS");25 pmModelType modelType = pmModelClassGetType ("PS_MODEL_QGAUSS"); 26 26 source->modelPSF = pmSourceModelGuess (source, modelType); 27 27 sources->data[i] = source; -
trunk/psphot/src/psphotFindPeaks.c
r13900 r14655 95 95 96 96 // find the peaks in the smoothed image 97 psArray *peaks = pm FindImagePeaks(smooth_im, threshold);97 psArray *peaks = pmPeaksInImage (smooth_im, threshold); 98 98 if (peaks == NULL) { 99 99 // XXX this may also be due to a programming or config error -
trunk/psphot/src/psphotGrowthCurve.c
r13900 r14655 14 14 float radius; 15 15 16 // create template model17 pmModel *modelRef = pmModelAlloc(psf->type);18 19 16 // use the center of the center pixel of the image 20 17 xc = 0.5*readout->image->numCols + readout->image->col0 + 0.5; … … 23 20 dy = psf->growth->maxRadius + 1; 24 21 25 // assign the x and y coords to the image center 26 // create an object with center intensity of 1000 27 modelRef->params->data.F32[PM_PAR_SKY] = 0; 28 modelRef->params->data.F32[PM_PAR_I0] = 1000; 29 modelRef->params->data.F32[PM_PAR_XPOS] = xc; 30 modelRef->params->data.F32[PM_PAR_YPOS] = yc; 31 32 // create modelPSF from this model 33 pmModel *model = pmModelFromPSF (modelRef, psf); 22 // create normalized model object at xc,yc 23 pmModel *model = pmModelFromPSFforXY (psf, xc, yc, 1.0); 34 24 35 25 // measure the fitMag for this model … … 76 66 psFree (mask); 77 67 psFree (model); 78 psFree (modelRef);79 68 80 69 return true; -
trunk/psphot/src/psphotModelGroupInit.c
r12792 r14655 7 7 # include "models/pmModel_STRAIL.c" 8 8 9 static pmModel GroupuserModels[] = {10 {"PS_MODEL_TEST1", 7, pmModelFunc_TEST1, pmModelFlux_TEST1, pmModelRadius_TEST1, pmModelLimits_TEST1, pmModelGuess_TEST1, pmModelFromPSF_TEST1, pmModel FitStatus_TEST1},11 {"PS_MODEL_STRAIL", 9, pmModelFunc_STRAIL, pmModelFlux_STRAIL, pmModelRadius_STRAIL, pmModelLimits_STRAIL, pmModelGuess_STRAIL, pmModelFromPSF_STRAIL, pmModel FitStatus_STRAIL},9 static pmModelClass userModels[] = { 10 {"PS_MODEL_TEST1", 7, pmModelFunc_TEST1, pmModelFlux_TEST1, pmModelRadius_TEST1, pmModelLimits_TEST1, pmModelGuess_TEST1, pmModelFromPSF_TEST1, pmModelParamsFromPSF_TEST1, pmModelFitStatus_TEST1}, 11 {"PS_MODEL_STRAIL", 9, pmModelFunc_STRAIL, pmModelFlux_STRAIL, pmModelRadius_STRAIL, pmModelLimits_STRAIL, pmModelGuess_STRAIL, pmModelFromPSF_STRAIL, pmModelParamsFromPSF_STRAIL, pmModelFitStatus_STRAIL}, 12 12 }; 13 13 14 void psphotModel GroupInit (void)14 void psphotModelClassInit (void) 15 15 { 16 16 17 // if pmModel GroupInit returns false, we have already init'ed18 if (!pmModel GroupInit ()) return;17 // if pmModelClassInit returns false, we have already init'ed 18 if (!pmModelClassInit ()) return; 19 19 20 int Nmodels = sizeof (userModels) / sizeof (pmModel Group);20 int Nmodels = sizeof (userModels) / sizeof (pmModelClass); 21 21 for (int i = 0; i < Nmodels; i++) { 22 pmModel GroupAdd (&userModels[i]);22 pmModelClassAdd (&userModels[i]); 23 23 } 24 24 return; -
trunk/psphot/src/psphotModelTest.c
r14348 r14655 89 89 modelName = item->data.V; 90 90 } 91 modelType = pmModel SetType (modelName);91 modelType = pmModelClassGetType (modelName); 92 92 if (modelType < 0) psAbort("unknown model %s", modelName); 93 93 source->type = PM_SOURCE_TYPE_EXTENDED; … … 118 118 modelName = item->data.V; 119 119 } 120 modelType = pmModel SetType (modelName);120 modelType = pmModelClassGetType (modelName); 121 121 if (modelType < 0) psAbort("unknown model %s", modelName); 122 122 source->type = PM_SOURCE_TYPE_EXTENDED; … … 148 148 149 149 // if any parameters are defined by the user, take those values 150 int nParams = pmModel ParameterCount (modelType);150 int nParams = pmModelClassParameterCount (modelType); 151 151 psF32 *params = model->params->data.F32; 152 152 params[PM_PAR_XPOS] = xObj; // XXX use the user-supplied value, -
trunk/psphot/src/psphotPSFConvModel.c
r14348 r14655 58 58 psVector *dparams = modelConv->dparams; 59 59 60 // get the model function for this model61 pmModelFunc modelFunc = pmModelFunc_GetFunction (modelConv->type);62 if (!modelFunc)63 psAbort("invalid model function");64 65 // get the limits function for this model66 pmModelLimits checkLimits = pmModelLimits_GetFunction (modelConv->type);67 if (!checkLimits)68 psAbort("invalid model limits function");69 70 60 // create the minimization constraints 71 61 psMinConstraint *constraint = psMinConstraintAlloc(); 72 62 constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_U8); 73 constraint->checkLimits = checkLimits;63 constraint->checkLimits = modelConv->modelLimits; 74 64 75 65 // set parameter mask based on fitting mode … … 81 71 // force the floating parameters to fall within the contraint ranges 82 72 for (int i = 0; i < params->n; i++) { 83 checkLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);84 checkLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);73 modelConv->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL); 74 modelConv->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL); 85 75 } 86 76 … … 90 80 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); 91 81 92 bool fitStatus = psphotModelWithPSF_LMM (myMin, covar, params, constraint, source, psf, model Func);82 bool fitStatus = psphotModelWithPSF_LMM (myMin, covar, params, constraint, source, psf, modelConv->modelFunc); 93 83 for (int i = 0; i < dparams->n; i++) { 94 84 if (psTraceGetLevel("psphot") >= 4) { -
trunk/psphot/src/psphotPSFResiduals.c
r12792 r14655 12 12 if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue; 13 13 14 // XXX if a source is faint, it will not have moments measured. 15 // it must be modelled as a PSF. In this case, we need to use 16 // the peak centroid to get the coordinates and get the peak flux 17 // from the image? 18 19 // use the source moments, etc to guess basic model parameters 20 pmModel *modelEXT = pmSourceModelGuess (source, psf->type); 21 22 // XXX put this in a function of its own.. 23 if (modelEXT == NULL) { 24 psErrorClear (); // XXX need to clear the error from failing the model 25 modelEXT = pmModelAlloc(psf->type); 26 psF32 *PAR = modelEXT->params->data.F32; 27 PAR[PM_PAR_SKY] = 0; 28 // XXX get this from the image pixels 29 PAR[PM_PAR_I0] = source->peak->flux; 30 PAR[PM_PAR_XPOS] = source->peak->xf; 31 PAR[PM_PAR_YPOS] = source->peak->yf; 14 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 15 Xo = source->moments->x; 16 Yo = source->moments->y; 17 Io = source->peak->flux; 32 18 } else { 33 // these valuse are set in pmSourceModelGuess, should this rule be in there as well? 34 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 35 modelEXT->params->data.F32[PM_PAR_XPOS] = source->moments->x; 36 modelEXT->params->data.F32[PM_PAR_YPOS] = source->moments->y; 37 } else { 38 modelEXT->params->data.F32[PM_PAR_XPOS] = source->peak->xf; 39 modelEXT->params->data.F32[PM_PAR_YPOS] = source->peak->yf; 40 } 19 Xo = source->peak->xf; 20 Yo = source->peak->yf; 21 Io = source->peak->flux; 41 22 } 42 23 43 24 // set PSF parameters for this model (apply 2D shape model) 44 pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); 45 psFree (modelEXT); 25 pmModel *modelPSF = pmModelFromPSFforXY (psf, Xo, Yo, Io); 46 26 47 27 // XXX need to define the guess flux? -
trunk/psphot/src/psphotRadiusChecks.c
r13035 r14655 6 6 static float PSF_FIT_RADIUS = 0; // radius to use in fitting (ignored if <= 0, 7 7 // and a per-object radius is calculated) 8 static pmModelRadius modelRadiusPSF;9 8 10 9 bool psphotInitRadiusPSF(const psMetadata *recipe, … … 17 16 PSF_FIT_RADIUS = psMetadataLookupF32(&status, recipe, "PSF_FIT_RADIUS"); 18 17 19 // this function specifies the radius at this the model hits the given flux20 modelRadiusPSF = pmModelRadius_GetFunction (type);21 18 return true; 22 19 } … … 34 31 if (radiusFit <= 0) { // use fixed radius 35 32 if (moments == NULL) { 36 radiusFit = model RadiusPSF(model->params, PSF_FIT_NSIGMA*moments->dSky);33 radiusFit = model->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky); 37 34 } else { 38 radiusFit = model RadiusPSF(model->params, 1.0);35 radiusFit = model->modelRadius(model->params, 1.0); 39 36 } 40 37 } … … 62 59 63 60 // set the fit radius based on the object flux limit and the model 64 model->radiusFit = (RADIUS_TYPE) (model RadiusPSF(model->params, PSF_FIT_NSIGMA*moments->dSky) + dR + PSF_FIT_PADDING);61 model->radiusFit = (RADIUS_TYPE) (model->modelRadius (model->params, PSF_FIT_NSIGMA*moments->dSky) + dR + PSF_FIT_PADDING); 65 62 if (isnan(model->radiusFit)) psAbort("error in radius"); 66 63 … … 78 75 static float EXT_FIT_NSIGMA; 79 76 static float EXT_FIT_PADDING; 80 static pmModelRadius modelRadiusEXT;81 77 82 78 bool psphotInitRadiusEXT (psMetadata *recipe, pmModelType type) { … … 87 83 EXT_FIT_PADDING = psMetadataLookupF32 (&status, recipe, "EXT_FIT_PADDING"); 88 84 89 // this function specifies the radius at this the model hits the given flux90 modelRadiusEXT = pmModelRadius_GetFunction (type);91 85 return true; 92 86 } … … 101 95 102 96 // set the fit radius based on the object flux limit and the model 103 model->radiusFit = (RADIUS_TYPE) (model RadiusEXT(model->params, EXT_FIT_NSIGMA*moments->dSky) + EXT_FIT_PADDING);97 model->radiusFit = (RADIUS_TYPE) (model->modelRadius (model->params, EXT_FIT_NSIGMA*moments->dSky) + EXT_FIT_PADDING); 104 98 if (isnan(model->radiusFit)) psAbort("error in radius"); 105 99 -
trunk/psphot/src/psphotReadout.c
r14346 r14655 251 251 252 252 // plot positive sources 253 // psphotSourcePlots (readout, sources, recipe);253 psphotSourcePlots (readout, sources, recipe, maskVal); 254 254 255 255 // measure aperture photometry corrections -
trunk/psphot/src/psphotReadoutCleanup.c
r13835 r14655 57 57 if (psf) { 58 58 // save the psf for possible output. if there was already an entry, it was loaded from external sources 59 // the new one may have been updated or modified, so replace the existing entry 60 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE, "psphot psf", psf); 59 // the new one may have been updated or modified, so replace the existing entry. We 60 // are required to save it on the chip, but this will cause problems if we ever want to 61 // run psphot on an unmosaiced image 62 pmCell *cell = readout->parent; 63 pmChip *chip = cell->parent; 64 psMetadataAdd (chip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE, "psphot psf", psf); 61 65 } 62 66 -
trunk/psphot/src/psphotSourceFits.c
r13900 r14655 195 195 // extended source model descriptions 196 196 char *modelNameEXT = psMetadataLookupStr (&status, recipe, "EXT_MODEL"); 197 modelTypeEXT = pmModel SetType (modelNameEXT);197 modelTypeEXT = pmModelClassGetType (modelNameEXT); 198 198 psphotInitRadiusEXT (recipe, modelTypeEXT); 199 199 -
trunk/psphot/src/psphotTestSourceOutput.c
r12950 r14655 21 21 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 22 22 psVector *params = model->params; 23 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);24 23 psS32 imageCol; 25 24 psS32 imageRow; … … 68 67 // set the appropriate pixel value for this coordinate 69 68 if (mode & PSPHOT_ADD_MODEL) { 70 pixelValue = model Func (NULL, params, x) - skyValue;69 pixelValue = model->modelFunc (NULL, params, x) - skyValue; 71 70 } else { 72 71 pixelValue = 0.0;
Note:
See TracChangeset
for help on using the changeset viewer.
