Changeset 4954
- Timestamp:
- Sep 6, 2005, 5:33:01 PM (21 years ago)
- Location:
- trunk/psphot
- Files:
-
- 12 added
- 3 deleted
- 21 edited
-
Makefile (modified) (3 diffs)
-
doc/notes.txt (modified) (1 diff)
-
doc/psphot.txt (modified) (1 diff)
-
src/fitsource.c (deleted)
-
src/fs_args.c (deleted)
-
src/models (added)
-
src/models/pmModel_GAUSS.c (added)
-
src/models/pmModel_PGAUSS.c (added)
-
src/models/pmModel_QGAUSS.c (added)
-
src/models/pmModel_RGAUSS.c (added)
-
src/models/pmModel_SGAUSS.c (added)
-
src/models/pmModel_TGAUSS.c (added)
-
src/models/pmModel_WAUSS.c (added)
-
src/models/pmModel_ZGAUSS.c (added)
-
src/onesource.c (deleted)
-
src/pmModelInit.c (added)
-
src/pmObjects_EAM.c (modified) (51 diffs)
-
src/pmObjects_EAM.h (modified) (3 diffs)
-
src/pmPeaksSigmaLimit.c (modified) (1 diff)
-
src/pmSourceUtils.c (modified) (1 diff)
-
src/psEllipse.c (added)
-
src/psEllipse.h (added)
-
src/psImageData.c (modified) (1 diff)
-
src/psLibUtils.c (modified) (15 diffs)
-
src/psLine.c (modified) (1 diff)
-
src/psMinimize.c (modified) (1 diff)
-
src/psModulesUtils.c (modified) (4 diffs)
-
src/psPolynomials.c (modified) (16 diffs)
-
src/psphot.h (modified) (5 diffs)
-
src/psphotApplyPSF.c (modified) (1 diff)
-
src/psphotArguments.c (modified) (1 diff)
-
src/psphotFitGalaxies.c (modified) (2 diffs)
-
src/psphotOutput.c (modified) (2 diffs)
-
src/psphotSetup.c (modified) (1 diff)
-
src/psphotSourceStats.c (modified) (1 diff)
-
src/pspsf.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/Makefile
r4946 r4954 14 14 15 15 INCS = $(IPSLIB) 16 LIBS = -lpsmodule $(LPSLIB) 17 CFLAGS = $(INCS) -std=c99 16 # LIBS = -lpsmodule $(LPSLIB) 17 LIBS = $(LPSLIB) 18 CFLAGS = $(INCS) -std=c99 -Wall -Werror 18 19 LFLAGS = $(LIBS) 19 20 … … 30 31 $(SRC)/psphotMarkPSF.$(ARCH).o \ 31 32 $(SRC)/psphotSubtractPSF.$(ARCH).o \ 33 $(SRC)/psphotSortBySN.$(ARCH).o \ 32 34 $(SRC)/pspsf.$(ARCH).o \ 33 35 $(SRC)/psLibUtils.$(ARCH).o \ … … 39 41 $(SRC)/psMinimize.$(ARCH).o \ 40 42 $(SRC)/psImageData.$(ARCH).o \ 41 $(SRC)/psphotSortBySN.$(ARCH).o 43 $(SRC)/psEllipse.$(ARCH).o \ 44 $(SRC)/pmModelInit.$(ARCH).o \ 45 $(SRC)/pmObjects_EAM.$(ARCH).o 42 46 43 47 FITSOURCE = \ -
trunk/psphot/doc/notes.txt
r4947 r4954 1 1 2 2 Notes on psphot 3 4 2005.09.06 5 6 I have built a working version of PSPhot using my own copy of the 7 pmObjects.[ch] files. I need to minimize the difference between the 8 v0.7.0, v0.5.0, and my own version of pmObjects.c 9 10 changes v0.5.0 / v0.7.0 / EAM 11 - changed all ps* to pm* 12 - fixed naming for local static functions (eg modelFree not p_psModelFree) 13 - dropped all hard-coded model names (vs v0.7.0) 14 - using current psMemSetDellocator name 15 - added noise image to pmSource 16 - converted old asserts to new asserts (PS_.._CHECK..) 17 - add return from error in pmFindImagePeaks 18 - allow isItInThisRegion to have NULL region (true) 19 - fixed subImages to correspond to region definition (end is 20 exclusive) in LocalSky and SetPixelCircle 21 - dropped old, redundant code in pmSourceLocalSky 22 - fixed pmSourceMoments use of mask (0 is valid, not 1) 23 - added pmSourceMoments validity tests (numPixels, Sum, centroid shift) 24 - added correction for Sxy (XY/Sum - x*y) 25 - added pmSourcePSFClump function (and pmPSFClump structure) 26 - allow missing sources in pmSourcePSFClump (not all peaks yield 27 sources) 28 - moved pmSourceRoughClass metadata lookups out of inner loop 29 - added saturated pixel test using pmImageCountPixelMask 30 - various redefinitions of initial classes 31 - dropped old, redundant code in pmSourceSetPixelsCircle 32 - mask image set to type psU8 (was psF32) 33 - abstract object model functions for pmSourceModelGuess 34 - converted evalModel to a public function psModelEval, modified params 35 - pmSourceFitModel operates on a specified model 36 - pmSourceFitModel had option to apply/ignore PSF information 37 - pmSourceFitModel calculates yErr 38 - pmSourceFitModel calculates the covariance matrix 39 - added paramMask to pmSourceFitModel 40 - pmSourceFitModel_EAM uses covar to carry in beta and param 41 limits... 42 - pmSourceFitModel requires solution to stay within image 43 - pmSourceFitModel calculates and saves chisq, nIter, nDOF 44 - pmSourceFitModel uses GaussNewtonDelta for frozen params 45 - added mask to pmSourceAdd, pmSourceSub 46 - model abstractions in pmSourceAdd, pmSourceSub 47 - fixed 'center' option in pmSourceAdd/Sub 48 49 - pmSourceFitModel calculates sqrt(var), psMinimize calculates sq(sqrt(var)) 50 - pmSourceContour is using the model flux, not the image flux 51 - does psImageAlloc zero the image? if so, drop init routine 52 from pmSourcePSFClump 53 - pmSourceRoughClass uses RDNOISE, GAIN to calculate SN: should use 54 the source->noise image? part of pmSourceMoments? 55 - pmSourceMoments_EAM uses macro for checkRegion 56 - pmObjects_EAM.c uses some hardcoded mask values (LocalSky) 57 - why does LocalSky_EAM not need subImageMask->col0 = subImage->col0?? 58 - psGetRowVectorFromImage should be in psLib (in psLibUtils) 59 - pmSourceSetPixelsCircle and pmSourceLocalSky probably could use 60 the psImageMaskRegion, etc functions. 61 - pmSourceSetPixelsCircle uses a hard-coded mask value 62 - 3 63 4 64 2005.09.05 -
trunk/psphot/doc/psphot.txt
r4115 r4954 1 1 2 psphot is a stand-alone program which implements the Pan-STARRS IPP 3 object detection and analysis functions for using with individual 4 images. 2 Defined APIs: 5 3 4 pmMoments *pmMomentsAlloc(); 5 pmModel *pmModelAlloc(); 6 pmSource *pmSourceAlloc(); 7 psVector *pmFindVectorPeaks() 8 psArray *pmFindImagePeaks() 9 psList *pmCullPeaks() 10 pmSource *pmSourceLocalSky() 11 bool pmSourceMoments() 12 pmPSFClump pmSourcePSFClump() 13 bool pmSourceRoughClass() 14 bool pmSourceSetPixelsCircle() 15 pmModel *pmSourceModelGuess() 16 psArray *pmSourceContour() 17 bool pmSourceFitModel() 18 bool pmSourceAddModel() 19 bool pmSourceSubModel() 20 int pmModelParameterCount (); 21 char *pmModelGetType (); 22 pmModelType pmModelSetType (); 23 pmModelFunc pmModelFunc_GetFunction (); 24 pmModelFlux pmModelFlux_GetFunction (); 25 pmModelRadius pmModelRadius_GetFunction (); 26 pmModelLimits pmModelLimits_GetFunction (); 27 pmModelGuessFunc pmModelGuessFunc_GetFunction (); 28 pmModelFromPSFFunc pmModelFromPSFFunc_GetFunction (); 29 pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (); 30 31 model function abstractions: 32 typedef psMinimizeLMChi2Func pmModelFunc; 33 typedef psF64 (*pmModelFlux)(const psVector *params); 34 typedef psF64 (*pmModelRadius)(const psVector *params, double flux); 35 typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max); 36 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source); 37 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf); 38 typedef bool (*pmModelFitStatusFunc)(pmModel *model); -
trunk/psphot/src/pmObjects_EAM.c
r4950 r4954 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-09-0 6 08:05:08$8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-09-07 03:33:01 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 66 66 pmModelAlloc(): Allocate the pmModel structure, along with its parameters, 67 67 and initialize the type member. Initialize the params to 0.0. 68 XXX EAM: changing params and dparams to psVector 69 XXX EAM: simplifying code with psModelParameterCount 68 XXX EAM: simplifying code with pmModelParameterCount 70 69 *****************************************************************************/ 71 70 pmModel *pmModelAlloc(pmModelType type) … … 76 75 tmp->chisq = 0.0; 77 76 tmp->nIter = 0; 78 psS32 Nparams = p sModelParameterCount (type);77 psS32 Nparams = pmModelParameterCount (type); 79 78 if (Nparams == 0) { 80 psError(PS_ERR_UNKNOWN, true, "Undefined p sModelType");79 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 81 80 return(NULL); 82 81 } … … 167 166 // 168 167 if ((vector->data.F32[0] > vector->data.F32[1]) && 169 (vector->data.F32[0] > threshold)) {168 (vector->data.F32[0] > threshold)) { 170 169 count++; 171 170 } … … 176 175 for (psU32 i = 1; i < n-1 ; i++) { 177 176 if ((vector->data.F32[i] > vector->data.F32[i-1]) && 178 (vector->data.F32[i] > vector->data.F32[i+1]) &&179 (vector->data.F32[i] > threshold)) {177 (vector->data.F32[i] > vector->data.F32[i+1]) && 178 (vector->data.F32[i] > threshold)) { 180 179 count++; 181 180 } … … 186 185 // 187 186 if ((vector->data.F32[n-1] > vector->data.F32[n-2]) && 188 (vector->data.F32[n-1] > threshold)) {187 (vector->data.F32[n-1] > threshold)) { 189 188 count++; 190 189 } … … 201 200 // 202 201 if ((vector->data.F32[0] > vector->data.F32[1]) && 203 (vector->data.F32[0] > threshold)) {202 (vector->data.F32[0] > threshold)) { 204 203 tmpVector->data.U32[count++] = 0; 205 204 } … … 210 209 for (psU32 i = 1; i < (n-1) ; i++) { 211 210 if ((vector->data.F32[i] > vector->data.F32[i-1]) && 212 (vector->data.F32[i] > vector->data.F32[i+1]) &&213 (vector->data.F32[i] > threshold)) {211 (vector->data.F32[i] > vector->data.F32[i+1]) && 212 (vector->data.F32[i] > threshold)) { 214 213 tmpVector->data.U32[count++] = i; 215 214 } … … 220 219 // 221 220 if ((vector->data.F32[n-1] > vector->data.F32[n-2]) && 222 (vector->data.F32[n-1] > threshold)) {221 (vector->data.F32[n-1] > threshold)) { 223 222 tmpVector->data.U32[count++] = n-1; 224 223 } … … 319 318 if (col == 0) { 320 319 if ( (image->data.F32[row][col] > image->data.F32[row][col+1]) && 321 (image->data.F32[row][col] > image->data.F32[row+1][col]) &&322 (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) {320 (image->data.F32[row][col] > image->data.F32[row+1][col]) && 321 (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) { 323 322 324 323 if (image->data.F32[row][col] > threshold) { … … 328 327 } else if (col < (image->numCols - 1)) { 329 328 if ( (image->data.F32[row][col] >= image->data.F32[row][col-1]) && 330 (image->data.F32[row][col] > image->data.F32[row][col+1]) &&331 (image->data.F32[row][col] >= image->data.F32[row+1][col-1]) &&332 (image->data.F32[row][col] > image->data.F32[row+1][col]) &&333 (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) {329 (image->data.F32[row][col] > image->data.F32[row][col+1]) && 330 (image->data.F32[row][col] >= image->data.F32[row+1][col-1]) && 331 (image->data.F32[row][col] > image->data.F32[row+1][col]) && 332 (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) { 334 333 if (image->data.F32[row][col] > threshold) { 335 334 list = myListAddPeak(list, row, col, image->data.F32[row][col], PM_PEAK_EDGE); … … 339 338 } else if (col == (image->numCols - 1)) { 340 339 if ( (image->data.F32[row][col] >= image->data.F32[row][col-1]) && 341 (image->data.F32[row][col] > image->data.F32[row+1][col]) &&342 (image->data.F32[row][col] >= image->data.F32[row+1][col-1])) {340 (image->data.F32[row][col] > image->data.F32[row+1][col]) && 341 (image->data.F32[row][col] >= image->data.F32[row+1][col-1])) { 343 342 if (image->data.F32[row][col] > threshold) { 344 343 list = myListAddPeak(list, row, col, image->data.F32[row][col], PM_PEAK_EDGE); … … 375 374 // If col==0, then we can not read col-1 pixels 376 375 if ((image->data.F32[row][col] > image->data.F32[row-1][col]) && 377 (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) &&378 (image->data.F32[row][col] >= image->data.F32[row][col+1]) &&379 (image->data.F32[row][col] >= image->data.F32[row+1][col]) &&380 (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) {376 (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) && 377 (image->data.F32[row][col] >= image->data.F32[row][col+1]) && 378 (image->data.F32[row][col] >= image->data.F32[row+1][col]) && 379 (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) { 381 380 myType = PM_PEAK_EDGE; 382 381 list = myListAddPeak(list, row, col, image->data.F32[row][col], myType); … … 385 384 // This is an interior pixel 386 385 if ((image->data.F32[row][col] >= image->data.F32[row-1][col-1]) && 387 (image->data.F32[row][col] > image->data.F32[row-1][col]) &&388 (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) &&389 (image->data.F32[row][col] > image->data.F32[row][col-1]) &&390 (image->data.F32[row][col] >= image->data.F32[row][col+1]) &&391 (image->data.F32[row][col] >= image->data.F32[row+1][col-1]) &&392 (image->data.F32[row][col] >= image->data.F32[row+1][col]) &&393 (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) {386 (image->data.F32[row][col] > image->data.F32[row-1][col]) && 387 (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) && 388 (image->data.F32[row][col] > image->data.F32[row][col-1]) && 389 (image->data.F32[row][col] >= image->data.F32[row][col+1]) && 390 (image->data.F32[row][col] >= image->data.F32[row+1][col-1]) && 391 (image->data.F32[row][col] >= image->data.F32[row+1][col]) && 392 (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) { 394 393 if (image->data.F32[row][col] > threshold) { 395 394 if ((image->data.F32[row][col] > image->data.F32[row-1][col-1]) && 396 (image->data.F32[row][col] > image->data.F32[row-1][col]) &&397 (image->data.F32[row][col] > image->data.F32[row-1][col+1]) &&398 (image->data.F32[row][col] > image->data.F32[row][col-1]) &&399 (image->data.F32[row][col] > image->data.F32[row][col+1]) &&400 (image->data.F32[row][col] > image->data.F32[row+1][col-1]) &&401 (image->data.F32[row][col] > image->data.F32[row+1][col]) &&402 (image->data.F32[row][col] > image->data.F32[row+1][col+1])) {395 (image->data.F32[row][col] > image->data.F32[row-1][col]) && 396 (image->data.F32[row][col] > image->data.F32[row-1][col+1]) && 397 (image->data.F32[row][col] > image->data.F32[row][col-1]) && 398 (image->data.F32[row][col] > image->data.F32[row][col+1]) && 399 (image->data.F32[row][col] > image->data.F32[row+1][col-1]) && 400 (image->data.F32[row][col] > image->data.F32[row+1][col]) && 401 (image->data.F32[row][col] > image->data.F32[row+1][col+1])) { 403 402 myType = PM_PEAK_LONE; 404 403 } 405 404 406 405 if ((image->data.F32[row][col] == image->data.F32[row-1][col-1]) || 407 (image->data.F32[row][col] == image->data.F32[row-1][col]) ||408 (image->data.F32[row][col] == image->data.F32[row-1][col+1]) ||409 (image->data.F32[row][col] == image->data.F32[row][col-1]) ||410 (image->data.F32[row][col] == image->data.F32[row][col+1]) ||411 (image->data.F32[row][col] == image->data.F32[row+1][col-1]) ||412 (image->data.F32[row][col] == image->data.F32[row+1][col]) ||413 (image->data.F32[row][col] == image->data.F32[row+1][col+1])) {406 (image->data.F32[row][col] == image->data.F32[row-1][col]) || 407 (image->data.F32[row][col] == image->data.F32[row-1][col+1]) || 408 (image->data.F32[row][col] == image->data.F32[row][col-1]) || 409 (image->data.F32[row][col] == image->data.F32[row][col+1]) || 410 (image->data.F32[row][col] == image->data.F32[row+1][col-1]) || 411 (image->data.F32[row][col] == image->data.F32[row+1][col]) || 412 (image->data.F32[row][col] == image->data.F32[row+1][col+1])) { 414 413 myType = PM_PEAK_FLAT; 415 414 } … … 421 420 // If col==numCols - 1, then we can not read col+1 pixels 422 421 if ((image->data.F32[row][col] >= image->data.F32[row-1][col-1]) && 423 (image->data.F32[row][col] > image->data.F32[row-1][col]) &&424 (image->data.F32[row][col] > image->data.F32[row][col-1]) &&425 (image->data.F32[row][col] >= image->data.F32[row][col+1]) &&426 (image->data.F32[row][col] >= image->data.F32[row+1][col-1]) &&427 (image->data.F32[row][col] >= image->data.F32[row+1][col])) {422 (image->data.F32[row][col] > image->data.F32[row-1][col]) && 423 (image->data.F32[row][col] > image->data.F32[row][col-1]) && 424 (image->data.F32[row][col] >= image->data.F32[row][col+1]) && 425 (image->data.F32[row][col] >= image->data.F32[row+1][col-1]) && 426 (image->data.F32[row][col] >= image->data.F32[row+1][col])) { 428 427 myType = PM_PEAK_EDGE; 429 428 list = myListAddPeak(list, row, col, image->data.F32[row][col], myType); … … 448 447 if (col == 0) { 449 448 if ( (image->data.F32[row][col] > image->data.F32[row-1][col]) && 450 (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) &&451 (image->data.F32[row][col] > image->data.F32[row][col+1])) {449 (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) && 450 (image->data.F32[row][col] > image->data.F32[row][col+1])) { 452 451 if (image->data.F32[row][col] > threshold) { 453 452 list = myListAddPeak(list, row, col, image->data.F32[row][col], PM_PEAK_EDGE); … … 456 455 } else if (col < (image->numCols - 1)) { 457 456 if ( (image->data.F32[row][col] >= image->data.F32[row-1][col-1]) && 458 (image->data.F32[row][col] > image->data.F32[row-1][col]) &&459 (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) &&460 (image->data.F32[row][col] > image->data.F32[row][col-1]) &&461 (image->data.F32[row][col] >= image->data.F32[row][col+1])) {457 (image->data.F32[row][col] > image->data.F32[row-1][col]) && 458 (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) && 459 (image->data.F32[row][col] > image->data.F32[row][col-1]) && 460 (image->data.F32[row][col] >= image->data.F32[row][col+1])) { 462 461 if (image->data.F32[row][col] > threshold) { 463 462 list = myListAddPeak(list, row, col, image->data.F32[row][col], PM_PEAK_EDGE); … … 467 466 } else if (col == (image->numCols - 1)) { 468 467 if ( (image->data.F32[row][col] >= image->data.F32[row-1][col-1]) && 469 (image->data.F32[row][col] > image->data.F32[row-1][col]) &&470 (image->data.F32[row][col] > image->data.F32[row][col-1])) {468 (image->data.F32[row][col] > image->data.F32[row-1][col]) && 469 (image->data.F32[row][col] > image->data.F32[row][col-1])) { 471 470 if (image->data.F32[row][col] > threshold) { 472 471 list = myListAddPeak(list, row, col, image->data.F32[row][col], PM_PEAK_EDGE); … … 495 494 (y >= valid->y0) && 496 495 (y <= valid->y1)) { 497 return(true);496 return(true); 498 497 } 499 498 … … 511 510 512 511 XXX: changed API to create a NEW output psArray (should change name as well) 512 513 XXX: Do we free the psList elements of those culled peaks? 514 515 XXX EAM : do we still need pmCullPeaks, or only pmPeaksSubset? 513 516 *****************************************************************************/ 514 517 psList *pmCullPeaks(psList *peaks, … … 517 520 { 518 521 PS_ASSERT_PTR_NON_NULL(peaks, NULL); 519 // PS_ASSERT_PTR_NON_NULL(valid, NULL);520 522 521 523 psListElem *tmpListElem = (psListElem *) peaks->head; … … 526 528 pmPeak *tmpPeak = (pmPeak *) tmpListElem->data; 527 529 if ((tmpPeak->counts > maxValue) || 528 ((valid != NULL) &&529 (true == isItInThisRegion(valid, tmpPeak->x, tmpPeak->y)))) {530 ((valid != NULL) && 531 (true == isItInThisRegion(valid, tmpPeak->x, tmpPeak->y)))) { 530 532 psListRemoveData(peaks, (psPtr) tmpPeak); 531 533 } … … 625 627 // XXX EAM : I added this code to stay on the image. So did George 626 628 // XXX EAM : EndRow is *exclusive* of pixel region (ie, last pixel + 1) 629 // XXX EAM : dropped the Annulus width (not needed) 630 // XXX EAM : dropped off-boundary tests (not needed) 627 631 psS32 SubImageStartRow = PS_MAX (0, SubImageCenterRow - outerRadiusS32); 628 632 psS32 SubImageEndRow = PS_MIN (image->numRows, SubImageCenterRow + outerRadiusS32 + 1); 629 633 psS32 SubImageStartCol = PS_MAX (0, SubImageCenterCol - outerRadiusS32); 630 634 psS32 SubImageEndCol = PS_MIN (image->numCols, SubImageCenterCol + outerRadiusS32 + 1); 631 // AnulusWidth == number of pixels width in the annulus. We add one since632 // the pixels at the inner AND outher radius are included.633 // XXX EAM : not used : psS32 AnulusWidth = 1 + (outerRadiusS32 - innerRadiusS32);634 // Example: assume an outer/inner radius of 20/10. Then the subimage635 // should have width/length of 40. An 18-by-18 interior region will636 // be masked.637 // printf("pmSourceLocalSky(): innerRadiusS32 is %d\n", innerRadiusS32);638 // printf("pmSourceLocalSky(): outerRadiusS32 is %d\n", outerRadiusS32);639 // printf("pmSourceLocalSky(): AnulusWidth is %d\n", AnulusWidth);640 641 // XXX EAM : these tests should not be needed: we can never hit this error because of above642 # if (1)643 644 if (SubImageStartRow < 0) {645 psError(PS_ERR_UNKNOWN, true, "Sub image startRow is outside image boundaries (%d).\n",646 SubImageStartRow);647 return(NULL);648 }649 if (SubImageEndRow > image->numRows) {650 psError(PS_ERR_UNKNOWN, true, "Sub image endRow is outside image boundaries (%d).\n",651 SubImageEndRow);652 return(NULL);653 }654 if (SubImageStartCol < 0) {655 psError(PS_ERR_UNKNOWN, true, "Sub image startCol is outside image boundaries (%d).\n",656 SubImageStartCol);657 return(NULL);658 }659 if (SubImageEndCol > image->numCols) {660 psError(PS_ERR_UNKNOWN, true, "Sub image endCol is outside image boundaries (%d).\n",661 SubImageEndCol);662 return(NULL);663 }664 # endif665 666 635 // 667 636 // Grab a subimage of the original image of size (2 * outerRadius). 668 637 // 669 // XXX: Must fix for new psImageSubset 670 // psImage *subImage = psImageSubset((psImage *) image, 671 // SubImageStartCol, 672 // SubImageStartRow, 673 // SubImageEndCol, 674 // SubImageEndRow); 675 // printf("pmSourceLocalSky: subimage width/length is (%d, %d)\n", subImage->numCols, subImage->numRows); 676 psRegion tmpRegion = psRegionSet(SubImageStartCol, 677 SubImageEndCol, 678 SubImageStartRow, 679 SubImageEndRow); 680 psImage *subImage = psImageSubset((psImage *) image, tmpRegion); 681 // XXX EAM : can merge these: psImageSubset (image, psRegionSet ()); 638 // XXX EAM : merged psImageSubset & psRegionSet 639 // XXX EAM : cast for image is needed because of const (above) 640 psImage *subImage = psImageSubset((psImage *) image, psRegionSet(SubImageStartCol, 641 SubImageEndCol, 642 SubImageStartRow, 643 SubImageEndRow)); 682 644 683 645 psImage *subImageMask = psImageAlloc(subImage->numCols, … … 685 647 PS_TYPE_U8); 686 648 // XXX EAM : for consistency, mask needs col0,row0 set to match image 687 subImageMask->col0 = subImage->col0; 688 subImageMask->row0 = subImage->row0; 689 690 // 691 // Loop through the subimage mask, initialize mask to 1 (invalid pixel) 649 // XXX EAM : CONFLICT between psLib and code requirement. FIX PSLIB!!! 650 // subImageMask->col0 = subImage->col0; 651 // subImageMask->row0 = subImage->row0; 652 psAbort ("pmObjects", "must fix this error before psphot will work!!!\n"); 653 654 // 655 // Loop through the subimage mask, initialize mask to 0x01 (invalid pixel) 692 656 // XXX EAM : use PSPHOT_MASK_INVALID? 693 657 // 694 658 for (psS32 row = 0 ; row < subImageMask->numRows; row++) { 695 659 for (psS32 col = 0 ; col < subImageMask->numCols; col++) { 696 subImageMask->data.U8[row][col] = 1;660 subImageMask->data.U8[row][col] = 0x01; 697 661 } 698 662 } … … 702 666 // XXX this uses a static mask value of 0 703 667 // XXX EAM : this was wrong: it masked the wrong pixels at the edge of the image 668 // XXX EAM : this masks the pixels in the center region 669 // XXX EAM : should we be using psImageMaskRegion ??? 704 670 psS32 StartRow = PS_MAX (0, SubImageCenterRow - subImageMask->row0 - innerRadiusS32); 705 671 psS32 EndRow = PS_MIN (subImageMask->numRows, SubImageCenterRow - subImageMask->row0 + innerRadiusS32 + 1); … … 712 678 } 713 679 714 680 // XXX EAM : make this trace information?? 715 681 // for (psS32 row = 0 ; row < subImage->numRows; row++) { 716 682 // for (psS32 col = 0 ; col < subImage->numCols; col++) { … … 800 766 XXX: mask values? 801 767 *****************************************************************************/ 802 bool pmSourceMoments(p sSource *source,768 bool pmSourceMoments(pmSource *source, 803 769 psF32 radius) 804 770 { … … 849 815 psS32 imgColCoord = col + source->pixels->col0; 850 816 psS32 imgRowCoord = row + source->pixels->row0; 851 if ( CheckRadius(source->peak,817 if (checkRadius(source->peak, 852 818 radius, 853 819 imgColCoord, … … 874 840 // XXX EAM - the limit is a bit arbitrary. make it user defined? 875 841 if ((numPixels < 3) || (Sum <= 0)) { 876 psTrace (".psModules.pmSourceMoments", 5, "no valid pixels for source\n");877 return (false);842 psTrace (".psModules.pmSourceMoments", 5, "no valid pixels for source\n"); 843 return (false); 878 844 } 879 845 … … 890 856 y = Y1/Sum; 891 857 if ((fabs(x) > radius) || (fabs(y) > radius)) { 892 psTrace (".psModules.pmSourceMoments", 5,893 "large centroid swing; invalid peak %d, %d\n",894 source->peak->x, source->peak->y);895 return (false);858 psTrace (".psModules.pmSourceMoments", 5, 859 "large centroid swing; invalid peak %d, %d\n", 860 source->peak->x, source->peak->y); 861 return (false); 896 862 } 897 863 … … 914 880 915 881 return(true); 916 917 // XXX EAM : the following code should be the same as above, but it is not very stable: ignore it918 # if (0)919 //920 // second loop: get the difference sums921 //922 X2 = Y2 = 0;923 for (psS32 row = 0; row < source->pixels->numRows ; row++) {924 for (psS32 col = 0; col < source->pixels->numCols ; col++) {925 if ((source->mask != NULL) && (source->mask->data.U8[row][col] != 0)) {926 psS32 imgColCoord = col + source->pixels->col0;927 psS32 imgRowCoord = row + source->pixels->row0;928 if (checkRadius(source->peak,929 radius,930 imgColCoord,931 imgRowCoord)) {932 psF32 xDiff = (psF32) (imgColCoord - source->peak->x);933 psF32 yDiff = (psF32) (imgRowCoord - source->peak->y);934 psF32 pDiff = source->pixels->data.F32[row][col] - sky;935 936 Sum+= pDiff;937 X2+= PS_SQR(xDiff - x) * pDiff;938 Y2+= PS_SQR(yDiff - y) * pDiff;939 }940 }941 }942 }943 944 //945 // second moment X = sqrt (X2/Sum)946 //947 source->moments->Sx = (X2/Sum);948 source->moments->Sy = (Y2/Sum);949 return(true);950 # endif951 882 } 952 883 … … 990 921 { 991 922 992 # define NPIX 10993 # define SCALE 0.1923 # define NPIX 10 924 # define SCALE 0.1 994 925 995 926 psArray *peaks = NULL; … … 997 928 pmPSFClump psfClump = emptyClump; 998 929 999 // PS_PTR_CHECK_NULL(sources, emptyClump);1000 // PS_PTR_CHECK_NULL(metadata, emptyClump);930 PS_ASSERT_PTR_NON_NULL(sources, emptyClump); 931 PS_ASSERT_PTR_NON_NULL(metadata, emptyClump); 1001 932 1002 933 // find the sigmaX, sigmaY clump … … 1010 941 splane = psImageAlloc (NPIX/SCALE, NPIX/SCALE, PS_TYPE_F32); 1011 942 for (int i = 0; i < splane->numRows; i++) { 1012 memset (splane->data.F32[i], 0, splane->numCols*sizeof(PS_TYPE_F32));943 memset (splane->data.F32[i], 0, splane->numCols*sizeof(PS_TYPE_F32)); 1013 944 } 1014 945 … … 1139 1070 1140 1071 XXX: How can this function ever return FALSE? 1072 1073 XXX EAM : add the saturated mask value to metadata 1141 1074 *****************************************************************************/ 1142 1075 … … 1178 1111 psF32 A = 4 * M_PI * sigX * sigY; 1179 1112 psF32 B = tmpSrc->moments->Sky; 1180 psF32 RT = PS_SQRT_F32(S + (A * B) + (A * PS_SQR(RDNOISE) / PS_SQRT_F32(GAIN)));1181 psF32 SN = (S * PS_SQRT_F32(GAIN) / RT);1113 psF32 RT = sqrt(S + (A * B) + (A * PS_SQR(RDNOISE) / sqrt(GAIN))); 1114 psF32 SN = (S * sqrt(GAIN) / RT); 1182 1115 tmpSrc->moments->SN = SN; 1183 1116 1184 // XXX EAM : can we use the value of SATIRATE if mask is NULL? 1185 int Nsatpix = pmCountSatPixels (tmpSrc->mask); 1117 // XXX EAM : can we use the value of SATURATE if mask is NULL? 1118 # define MASK_SATURATED 0x02 1119 int Nsatpix = psImageCountPixelMask (tmpSrc->mask, MASK_SATURATED); 1186 1120 1187 1121 // saturated star (size consistent with PSF or larger) … … 1253 1187 } 1254 1188 1255 int pmCountSatPixels (psImage *image)1256 {1257 int Nsatpix = 0;1258 1259 for (int i = 0; i < image->numRows; i++) {1260 for (int j = 0; j < image->numCols; j++) {1261 if (image->data.U8[i][j] & 0x02) {1262 Nsatpix ++;1263 }1264 }1265 }1266 return (Nsatpix);1267 }1268 1269 1189 /****************************************************************************** 1270 1190 pmSourceSetPixelsCircle(source, image, radius) … … 1286 1206 PS_ASSERT_PTR_NON_NULL(source, false); 1287 1207 PS_ASSERT_PTR_NON_NULL(source->moments, false); 1288 //PS_ASSERT_PTR_NON_NULL(source->peak, false);1208 PS_ASSERT_PTR_NON_NULL(source->peak, false); 1289 1209 PS_FLOAT_COMPARE(0.0, radius, false); 1290 1210 … … 1305 1225 psS32 SubImageEndCol = PS_MIN (image->numCols, SubImageCenterCol + radiusS32 + 1); 1306 1226 1307 // XXX EAM : this should not be needed: we can never hit this error1308 # if (1)1309 1310 if (SubImageStartRow < 0) {1311 psError(PS_ERR_UNKNOWN, true, "Sub image startRow is outside image boundaries (%d).\n",1312 SubImageStartRow);1313 return(false);1314 }1315 if (SubImageEndRow > image->numRows) {1316 psError(PS_ERR_UNKNOWN, true, "Sub image endRow is outside image boundaries (%d).\n",1317 SubImageEndRow);1318 return(false);1319 }1320 if (SubImageStartCol < 0) {1321 psError(PS_ERR_UNKNOWN, true, "Sub image startCol is outside image boundaries (%d).\n",1322 SubImageStartCol);1323 return(false);1324 }1325 if (SubImageEndCol > image->numCols) {1326 psError(PS_ERR_UNKNOWN, true, "Sub image endCol is outside image boundaries (%d).\n",1327 SubImageEndCol);1328 return(false);1329 }1330 # endif1331 1332 1227 // XXX: Must recycle image. 1333 1228 // XXX EAM: this message reflects a programming error we know about. … … 1338 1233 psFree(source->pixels); 1339 1234 } 1340 // XXX: Must fix this. psImageSubset() has different parameters in latest CVS.1341 // source->pixels = psImageSubset((psImage *) image,1342 // SubImageStartCol,1343 // SubImageStartRow,1344 // SubImageEndCol,1345 // SubImageEndRow);1346 1235 source->pixels = psImageSubset((psImage *) image, psRegionSet(SubImageStartCol, 1347 1236 SubImageStartRow, … … 1390 1279 functions will be in image, not subImage coords. Remember this. 1391 1280 *****************************************************************************/ 1392 psModel *pmSourceModelGuess(psSource *source, 1393 psModelType modelType) 1394 { 1395 PS_PTR_CHECK_NULL(source, false); 1396 PS_PTR_CHECK_NULL(source->moments, false); 1397 PS_PTR_CHECK_NULL(source->peak, false); 1398 1399 psModel *model = psModelAlloc(modelType); 1400 1401 psModelGuessFunc modelGuessFunc = psModelGuessFunc_GetFunction (modelType); 1281 pmModel *pmSourceModelGuess(pmSource *source, 1282 pmModelType modelType) 1283 { 1284 PS_ASSERT_PTR_NON_NULL(source->moments, false); 1285 PS_ASSERT_PTR_NON_NULL(source->peak, false); 1286 1287 pmModel *model = pmModelAlloc(modelType); 1288 1289 pmModelGuessFunc modelGuessFunc = pmModelGuessFunc_GetFunction (modelType); 1402 1290 modelGuessFunc (model, source); 1403 1291 return(model); … … 1425 1313 testing. Try to reproduce that and debug. 1426 1314 *****************************************************************************/ 1427 static psF32 evalModel(pmSource *src, 1428 psU32 row, 1429 psU32 col) 1430 { 1431 PS_ASSERT_PTR_NON_NULL(src, false); 1432 PS_ASSERT_PTR_NON_NULL(src->modelPSF, false); 1433 PS_ASSERT_PTR_NON_NULL(src->modelPSF->params, false); 1434 1435 XXX EAM : I've made this a public function 1436 XXX EAM : this now uses a psModel as the input 1437 XXX EAM : it was using src->type to find the model, not model->type 1438 *****************************************************************************/ 1439 psF32 psModelEval(psModel *model, psImage *image, psS32 col, psS32 row) 1440 { 1441 PS_PTR_CHECK_NULL(image, false); 1442 PS_PTR_CHECK_NULL(model, false); 1443 PS_PTR_CHECK_NULL(model->params, false); 1315 1316 // XXX EAM : I have made this a public function 1317 // XXX EAM : this now uses a pmModel as the input 1318 // XXX EAM : it was using src->type to find the model, not model->type 1319 psF32 pmModelEval(pmModel *model, psImage *image, psS32 col, psS32 row) 1320 { 1321 PS_ASSERT_PTR_NON_NULL(image, false); 1322 PS_ASSERT_PTR_NON_NULL(model, false); 1323 PS_ASSERT_PTR_NON_NULL(model->params, false); 1444 1324 1445 1325 // Allocate the x coordinate structure and convert row/col to image space. … … 1449 1329 x->data.F32[1] = (psF32) (row + image->row0); 1450 1330 psF32 tmpF; 1451 p sModelFunc modelFunc;1452 1453 modelFunc = p sModelFunc_GetFunction (model->type);1331 pmModelFunc modelFunc; 1332 1333 modelFunc = pmModelFunc_GetFunction (model->type); 1454 1334 tmpF = modelFunc (NULL, model->params, x); 1455 1335 psFree(x); … … 1491 1371 } 1492 1372 1493 // XXX EAM : i changed this to match p sModelEval above, but see1373 // XXX EAM : i changed this to match pmModelEval above, but see 1494 1374 // XXX EAM the note below in pmSourceContour 1495 psF32 oldValue = p sModelEval(source->modelFLT, source->pixels, subCol, subRow);1375 psF32 oldValue = pmModelEval(source->modelFLT, source->pixels, subCol, subRow); 1496 1376 if (oldValue == level) { 1497 1377 return(((psF32) (subCol + source->pixels->col0))); … … 1514 1394 1515 1395 while (subCol != lastColumn) { 1516 psF32 newValue = p sModelEval(source->modelFLT, source->pixels, subCol, subRow);1396 psF32 newValue = pmModelEval(source->modelFLT, source->pixels, subCol, subRow); 1517 1397 if (oldValue == level) { 1518 1398 return((psF32) (subCol + source->pixels->col0)); … … 1674 1554 // tests below could be conditions (!NULL) 1675 1555 1676 p sModelFunc modelFunc = psModelFunc_GetFunction (model->type);1556 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type); 1677 1557 1678 1558 psVector *params = model->params; … … 1694 1574 } 1695 1575 if (count < nParams + 1) { 1696 psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n");1697 return(false);1576 psTrace (".pmObjects.pmSourceFitModel", 4, "insufficient valid pixels\n"); 1577 return(false); 1698 1578 } 1699 1579 … … 1722 1602 1723 1603 psMinimization *myMin = psMinimizationAlloc(PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, 1724 PM_SOURCE_FIT_MODEL_TOLERANCE);1604 PM_SOURCE_FIT_MODEL_TOLERANCE); 1725 1605 1726 1606 // PSF model only fits first 4 parameters, FLT model fits all 1727 1607 if (PSF) { 1728 paramMask = psVectorAlloc (params->n, PS_TYPE_U8);1729 for (int i = 0; i < 4; i++) {1730 paramMask->data.U8[i] = 0;1731 }1732 for (int i = 4; i < paramMask->n; i++) {1733 paramMask->data.U8[i] = 1;1734 }1608 paramMask = psVectorAlloc (params->n, PS_TYPE_U8); 1609 for (int i = 0; i < 4; i++) { 1610 paramMask->data.U8[i] = 0; 1611 } 1612 for (int i = 4; i < paramMask->n; i++) { 1613 paramMask->data.U8[i] = 1; 1614 } 1735 1615 } 1736 1616 … … 1782 1662 bool p_pmSourceAddOrSubModel(psImage *image, 1783 1663 psImage *mask, 1784 p sModel *model,1664 pmModel *model, 1785 1665 bool center, 1786 1666 psS32 flag) 1787 1667 { 1788 1668 1789 // XXX EAM : convert to ASSERTS 1790 // PS_PTR_CHECK_NULL(model, false); 1791 // PS_IMAGE_CHECK_NULL(image, false); 1792 // PS_IMAGE_CHECK_TYPE(image, PS_TYPE_F32, false); 1669 PS_ASSERT_PTR_NON_NULL(model, false); 1670 PS_ASSERT_IMAGE_NON_NULL(image, false); 1671 PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, false); 1793 1672 1794 1673 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 1795 1674 psVector *params = model->params; 1796 p sModelFunc modelFunc = psModelFunc_GetFunction (model->type);1675 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type); 1797 1676 psS32 imageCol; 1798 1677 psS32 imageRow; … … 1842 1721 bool pmSourceAddModel(psImage *image, 1843 1722 psImage *mask, 1844 p sModel *model,1723 pmModel *model, 1845 1724 bool center) 1846 1725 { … … 1852 1731 bool pmSourceSubModel(psImage *image, 1853 1732 psImage *mask, 1854 p sModel *model,1733 pmModel *model, 1855 1734 bool center) 1856 1735 { -
trunk/psphot/src/pmObjects_EAM.h
r4949 r4954 1 1 /** @file pmObjects.h 2 * 3 * This file will ... 4 * 5 * @author GLG, MHPCC 6 * 7 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-09-07 03:33:01 $ 9 * 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 11 * 12 */ 13 14 #if !defined(PM_OBJECTS_H) 15 #define PM_OBJECTS_H 16 17 #if HAVE_CONFIG_H 18 #include <config.h> 19 #endif 20 21 #include<stdio.h> 22 #include<math.h> 23 #include "pslib.h" 24 25 // XXX EAM : this function should be added to psLib 26 int psImageCountPixelMask (psImage *mask, psU8 value); 27 28 // XXX EAM : bug : missing from psLib/*.h 29 bool psMinimizeGaussNewtonDelta (psVector *delta, 30 const psVector *params, 31 const psVector *paramMask, 32 const psArray *x, 33 const psVector *y, 34 const psVector *yErr, 35 psMinimizeLMChi2Func func); 36 37 // XXX EAM : switch to psPoly when ready 38 psF64 Polynomial2DEval(const psPolynomial2D* myPoly, psF64 x, psF64 y); 39 40 // XXX EAM : psEllipse needs to be be included in psLib 41 # include "psEllipse.h" 42 43 /** pmPeakType 44 * 45 * A peak pixel may have several features which may be determined when the 46 * peak is found or measured. These are specified by the pmPeakType enum. 47 * PM_PEAK_LONE represents a single pixel which is higher than its 8 immediate 48 * neighbors. The PM_PEAK_EDGE represents a peak pixel which touching the image 49 * edge. The PM_PEAK_FLAT represents a peak pixel which has more than a specific 50 * number of neighbors at the same value, within some tolarence: 51 * 52 */ 53 typedef enum { 54 PM_PEAK_LONE, ///< Isolated peak. 55 PM_PEAK_EDGE, ///< Peak on edge. 56 PM_PEAK_FLAT, ///< Peak has equal-value neighbors. 57 PM_PEAK_UNDEF ///< Undefined. 58 } pmPeakType; 59 60 /** pmPeak data structure 61 * 62 * 63 * 64 */ 65 typedef struct 66 { 67 int x; ///< X-coordinate of peak pixel. 68 int y; ///< Y-coordinate of peak pixel. 69 float counts; ///< Value of peak pixel (above sky?). 70 pmPeakType class; ///< Description of peak. 71 } 72 pmPeak; 73 74 /** pmMoments data structure 75 * 76 * 77 * 78 */ 79 typedef struct 80 { 81 float x; ///< X-coord of centroid. 82 float y; ///< Y-coord of centroid. 83 float Sx; ///< x-second moment. 84 float Sy; ///< y-second moment. 85 float Sxy; ///< xy cross moment. 86 float Sum; ///< Pixel sum above sky (background). 87 float Peak; ///< Peak counts above sky. 88 float Sky; ///< Sky level (background). 89 float SN; ///< approx signal-to-noise 90 int nPixels; ///< Number of pixels used. 91 } pmMoments; 92 93 typedef int pmModelType; 94 95 /** pmPSFClump data structure 96 * 97 * 98 * 99 */ 2 100 typedef struct 3 101 { … … 8 106 } pmPSFClump; 9 107 10 typedef struct 11 { 12 float x; ///< X-coord of centroid. 13 float y; ///< Y-coord of centroid. 14 float Sx; ///< x-second moment. 15 float Sy; ///< y-second moment. 16 float Sxy; ///< xy cross moment. 17 float Sum; ///< Pixel sum above sky (background). 18 float Peak; ///< Peak counts above sky. 19 float Sky; ///< Sky level (background). 20 float SN; 21 int nPixels; ///< Number of pixels used. 22 } 23 pmMoments; 24 25 typedef psS32 pmModelType; 26 27 typedef struct 28 { 29 pmModelType type; ///< Model to be used. 30 psVector *params; ///< Paramater values. 31 psVector *dparams; ///< Parameter errors. 32 float radius; ///< fit radius actually used 33 float chisq; ///< Fit chi-squared. 34 int nDOF; ///< number of degrees of freedom 35 int nIter; ///< number of iterations to reach min 108 /** pmModel data structure 109 * 110 * 111 * 112 */ 113 typedef struct 114 { 115 pmModelType type; ///< Model to be used. 116 psVector *params; ///< Paramater values. 117 psVector *dparams; ///< Parameter errors. 118 float chisq; ///< Fit chi-squared. 119 int nDOF; ///< number of degrees of freedom 120 int nIter; ///< number of iterations to reach min 121 float radius; ///< fit radius actually used 36 122 } 37 123 pmModel; 38 124 125 /** pmSourceType enumeration 126 * 127 * 128 * 129 */ 39 130 typedef enum { 40 131 PS_SOURCE_DEFECT, … … 58 149 } pmSourceType; 59 150 60 typedef struct 61 { 62 pmPeak *peak; ///< Description of peak pixel. 63 psImage *pixels; ///< Rectangular region including object pixels. 64 psImage *noise; ///< Mask which marks pixels associated with objects. 65 psImage *mask; ///< Mask which marks pixels associated with objects. 66 pmMoments *moments; ///< Basic moments measure for the object. 67 pmModel *modelPSF; ///< PSF Model fit (parameters and type) 68 pmModel *modelFLT; ///< FLT Model fit (parameters and type). 69 pmSourceType type; ///< Best identification of object. 151 /** pmSource data structure 152 * 153 * This source has the capacity for several types of measurements. The 154 * simplest measurement of a source is the location and flux of the peak pixel 155 * associated with the source: 156 * 157 */ 158 typedef struct 159 { 160 pmPeak *peak; ///< Description of peak pixel. 161 psImage *pixels; ///< Rectangular region including object pixels. 162 psImage *noise; ///< Mask which marks pixels associated with objects. 163 psImage *mask; ///< Mask which marks pixels associated with objects. 164 pmMoments *moments; ///< Basic moments measure for the object. 165 pmModel *modelPSF; ///< PSF Model fit (parameters and type) 166 pmModel *modelFLT; ///< FLT Model fit (parameters and type). 167 pmSourceType type; ///< Best identification of object. 70 168 } 71 169 pmSource; 72 170 73 // XXX EAM function to return pmModel 74 typedef psMinimizeLMChi2Func pmModelFunc; 75 typedef psF64 (*pmModelFlux)(const psVector *params); 76 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source); 77 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf); 78 typedef psF64 (*pmModelRadius)(const psVector *params, double flux); 79 80 typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max); 81 typedef bool (*pmModelFitStatusFunc)(pmModel *model); 82 83 // XXX EAM structure to carry model options 84 typedef struct { 85 char *name; 86 int nParams; 87 pmModelFunc modelFunc; 88 pmModelFlux modelFlux; 89 pmModelRadius modelRadius; 90 pmModelLimits modelLimits; 91 pmModelGuessFunc modelGuessFunc; 92 pmModelFromPSFFunc modelFromPSFFunc; 93 pmModelFitStatusFunc modelFitStatusFunc; 94 } pmModelGroup; 95 96 // XXX EAM : strucures to define elliptical shape parameters 97 typedef struct { 98 double major; 99 double minor; 100 double theta; 101 } EllipseAxes; 102 103 typedef struct { 104 double x2; 105 double y2; 106 double xy; 107 } EllipseMoments; 108 109 typedef struct { 110 double sx; 111 double sy; 112 double sxy; 113 } EllipseShape; 114 115 EllipseAxes EllipseMomentsToAxes (EllipseMoments moments); 116 EllipseShape EllipseAxesToShape (EllipseAxes axes); 117 EllipseAxes EllipseShapeToAxes (EllipseShape shape); 171 /** pmPSF data structure 172 * 173 * 174 * 175 */ 176 typedef struct 177 { 178 pmModelType type; ///< PSF Model in use 179 psArray *params; ///< Model parameters (psPolynomial2D) 180 float chisq; ///< PSF goodness statistic 181 int nPSFstars; ///< number of stars used to measure PSF 182 } 183 pmPSF; 184 185 pmPeak *pmPeakAlloc( 186 int x, ///< Row-coordinate in image space 187 int y, ///< Col-coordinate in image space 188 float counts, ///< The value of the peak pixel 189 pmPeakType class ///< The type of peak pixel 190 ); 191 192 pmMoments *pmMomentsAlloc(); 193 pmModel *pmModelAlloc(pmModelType type); 194 pmSource *pmSourceAlloc(); 195 196 /****************************************************************************** 197 pmFindVectorPeaks(vector, threshold): Find all local peaks in the given vector 198 above the given threshold. Returns a vector of type PS_TYPE_U32 containing 199 the location (x value) of all peaks. 200 *****************************************************************************/ 201 psVector *pmFindVectorPeaks( 202 const psVector *vector, ///< The input vector (float) 203 float threshold ///< Threshold above which to find a peak 204 ); 205 206 /****************************************************************************** 207 pmFindImagePeaks(image, threshold): Find all local peaks in the given psImage 208 above the given threshold. Returns a psList containing the location (x/y 209 value) of all peaks. 210 *****************************************************************************/ 211 psArray *pmFindImagePeaks( 212 const psImage *image, ///< The input image where peaks will be found (float) 213 float threshold ///< Threshold above which to find a peak 214 ); 215 216 /****************************************************************************** 217 pmCullPeaks(peaks, maxValue, valid): eliminate peaks from the psList that have 218 a peak value above the given maximum, or fall outside the valid region. 219 *****************************************************************************/ 220 psList *pmCullPeaks( 221 psList *peaks, ///< The psList of peaks to be culled 222 float maxValue, ///< Cull peaks above this value 223 const psRegion *valid ///< Cull peaks otside this psRegion 224 ); 225 226 /****************************************************************************** 227 pmSource *pmSourceLocalSky(image, peak, innerRadius, outerRadius): 228 229 *****************************************************************************/ 230 pmSource *pmSourceLocalSky( 231 const psImage *image, ///< The input image (float) 232 const pmPeak *peak, ///< The peak for which the pmSource struct is created. 233 psStatsOptions statsOptions, ///< The statistic used in calculating the background sky 234 float innerRadius, ///< The inner radius of the suqare annulus for calculating sky 235 float outerRadius ///< The outer radius of the suqare annulus for calculating sky 236 ); 237 238 /****************************************************************************** 239 *****************************************************************************/ 240 bool pmSourceMoments( 241 pmSource *source, ///< The input pmSource for which moments will be computed 242 float radius ///< Use a circle of pixels around the peak 243 ); 118 244 119 245 /****************************************************************************** 120 246 pmSourcePSFClump(pmArray *source, psMetaDeta *metadata): find the source PSF clump 121 *****************************************************************************/ 122 pmPSFClump pmSourcePSFClump(psArray *source, ///< The input psSource 123 psMetadata *metadata ///< Contains classification parameters 124 ); 247 *****************************************************************************/ 248 pmPSFClump pmSourcePSFClump( 249 psArray *source, ///< The input pmSource 250 psMetadata *metadata ///< Contains classification parameters 251 ); 125 252 126 253 /****************************************************************************** 127 254 pmSourceRoughClass(pmArray *source, psMetaDeta *metadata): make a guess at the 128 255 source classification. 129 *****************************************************************************/ 130 bool pmSourceRoughClass(psArray *source, ///< The input psSource 131 psMetadata *metadata, ///< Contains classification parameters 132 pmPSFClump clump ///< Statistics about the PSF clump 133 ); 134 135 pmModel *pmSourceModelGuess(pmSource *source, ///< The input psSource 136 pmModelType model ///< The type of model to be created. 137 ); 138 139 // XXX EAM : added utility functions 140 pmModelType pmModelSetType (char *name); 141 pmModelFunc pmModelFunc_GetFunction (pmModelType type); 142 pmModelFlux pmModelFlux_GetFunction (pmModelType type); 143 pmModelGuessFunc pmModelGuessFunc_GetFunction (pmModelType type); 144 pmModelFromPSFFunc pmModelFromPSFFunc_GetFunction (pmModelType type); 145 pmModelRadius pmModelRadius_GetFunction (pmModelType type); 146 char *pmModelGetType (pmModelType type); 147 psS32 pmModelParameterCount (pmModelType type); 148 pmModelLimits pmModelLimits_GetFunction (pmModelType type); 149 pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type); 150 int pmCountSatPixels (psImage *image); 151 152 pmMoments *pmMomentsAlloc(); 153 pmModel *pmModelAlloc(pmModelType type); 154 pmSource *pmSourceAlloc(); 256 *****************************************************************************/ 257 bool pmSourceRoughClass( 258 psArray *source, ///< The input pmSource 259 psMetadata *metadata, ///< Contains classification parameters 260 pmPSFClump clump ///< Statistics about the PSF clump 261 ); 262 263 /****************************************************************************** 264 pmSourceSetPixelCircle(source, image, radius) 265 *****************************************************************************/ 266 bool pmSourceSetPixelsCircle( 267 pmSource *source, ///< The input pmSource 268 const psImage *image, ///< The input image (float) 269 float radius ///< The radius of the circle 270 ); 271 272 /****************************************************************************** 273 *****************************************************************************/ 274 pmModel *pmSourceModelGuess( 275 pmSource *source, ///< The input pmSource 276 pmModelType model ///< The type of model to be created. 277 ); 278 279 /****************************************************************************** 280 *****************************************************************************/ 281 typedef enum { 282 PS_CONTOUR_CRUDE, 283 } pmContourType; 284 285 psArray *pmSourceContour( 286 pmSource *source, ///< The input pmSource 287 const psImage *image, ///< The input image (float) (this arg should be removed) 288 float level, ///< The level of the contour 289 pmContourType mode ///< Currently this must be PS_CONTOUR_CRUDE 290 ); 291 292 /****************************************************************************** 293 *****************************************************************************/ 294 bool pmSourceFitModel( 295 pmSource *source, ///< The input pmSource 296 pmModel *model, ///< model to be fitted 297 const bool PSF ///< Treat model as PSF or FLT? 298 ); 299 300 /****************************************************************************** 301 *****************************************************************************/ 302 bool pmSourceAddModel( 303 psImage *image, ///< The output image (float) 304 psImage *mask, ///< The image pixel mask (valid == 0) 305 pmModel *model, ///< The input pmModel 306 bool center ///< A boolean flag that determines whether pixels are centered 307 ); 308 309 /****************************************************************************** 310 *****************************************************************************/ 311 bool pmSourceSubModel( 312 psImage *image, ///< The output image (float) 313 psImage *mask, ///< The image pixel mask (valid == 0) 314 pmModel *model, ///< The input pmModel 315 bool center ///< A boolean flag that determines whether pixels are centered 316 ); 317 318 /** 319 * 320 * The object model functions are defined to allow for the flexible addition 321 * of new object models. Every object model, with parameters represented by 322 * pmModel, has an associated set of functions which provide necessary support 323 * operations. A set of abstract functions allow the programmer to select the 324 * approriate function or property for a specific named object model. 325 * 326 */ 327 328 /** 329 * 330 * This function is the model chi-square minimization function for this model. 331 * 332 */ 333 typedef psMinimizeLMChi2Func pmModelFunc; 334 335 336 /** 337 * 338 * This function returns the integrated flux for the given model parameters. 339 */ 340 typedef psF64 (*pmModelFlux)(const psVector *params); 341 342 343 /** 344 * 345 * This function returns the radius at which the given model and parameters 346 * achieves the given flux. 347 * 348 */ 349 typedef psF64 (*pmModelRadius)(const psVector *params, double flux); 350 351 /** 352 * 353 * This function sets the model parameter limits vectors for the given model 354 * 355 */ 356 typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max); 357 358 /** 359 * 360 * This function provides the model guess parameters based on the details of 361 * the given source. 362 * 363 */ 364 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source); 365 366 367 /** 368 * 369 * This function constructs the PSF model for the given source based on the 370 * supplied psf and the FLT model for the object. 371 * 372 */ 373 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf); 374 375 376 /** 377 * 378 * This function returns the success / failure status of the given model fit 379 * 380 */ 381 typedef bool (*pmModelFitStatusFunc)(pmModel *model); 382 383 /** 384 * 385 * Each of the function types above has a corresponding function which returns 386 * the function given the model type: 387 * 388 */ 389 pmModelFunc pmModelFunc_GetFunction (pmModelType type); 390 pmModelFlux pmModelFlux_GetFunction (pmModelType type); 391 pmModelRadius pmModelRadius_GetFunction (pmModelType type); 392 pmModelLimits pmModelLimits_GetFunction (pmModelType type); 393 pmModelGuessFunc pmModelGuessFunc_GetFunction (pmModelType type); 394 pmModelFromPSFFunc pmModelFromPSFFunc_GetFunction (pmModelType type); 395 pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type); 396 397 // pmModelGroup utility functions 398 int pmModelParameterCount (pmModelType type); 399 char *pmModelGetType (pmModelType type); 400 pmModelType pmModelSetType (char *name); 401 402 // structure to carry model group functions 403 typedef struct { 404 char *name; 405 int nParams; 406 pmModelFunc modelFunc; 407 pmModelFlux modelFlux; 408 pmModelRadius modelRadius; 409 pmModelLimits modelLimits; 410 pmModelGuessFunc modelGuessFunc; 411 pmModelFromPSFFunc modelFromPSFFunc; 412 pmModelFitStatusFunc modelFitStatusFunc; 413 } pmModelGroup; 414 415 #endif -
trunk/psphot/src/pmPeaksSigmaLimit.c
r4946 r4954 16 16 17 17 psImage *smooth = psImageCopy (NULL, imdata->image, PS_TYPE_F32); 18 psImageSmooth (smooth, SIGMA, NSIGMA);18 psImageSmooth_EAM (smooth, SIGMA, NSIGMA); 19 19 psLogMsg ("psphot", 4, "smooth: %f sec\n", psTimerMark ("psphot")); 20 20 -
trunk/psphot/src/pmSourceUtils.c
r4949 r4954 7 7 psF32 Radius) 8 8 { 9 psRegion *srcRegion;9 psRegion srcRegion; 10 10 11 11 // Grab a subimage of the original image of size (2 * outerRadius). 12 srcRegion = psRegion Square (x, y, Radius);13 srcRegion = psRegionForImage ( srcRegion, imdata->image,srcRegion);12 srcRegion = psRegionForSquare (x, y, Radius); 13 srcRegion = psRegionForImage (imdata->image, &srcRegion); 14 14 15 // use these when psImageSubset is updated 16 // psImage *subImage = psImageSubset(imdata->image, srcRegion); 17 // psImage *subImageMask = psImageSubset(imdata->mask, srcRegion); 18 // psImage *subImageNoise = psImageSubset(imdata->noise, srcRegion); 15 mySource->pixels = psImageSubset(imdata->image, srcRegion); 16 mySource->noise = psImageSubset(imdata->noise, srcRegion); 17 mySource->mask = psImageSubset(imdata->mask, srcRegion); 19 18 20 mySource->pixels = psImageSubset(imdata->image, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);21 mySource->noise = psImageSubset(imdata->noise, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);22 mySource->mask = psImageSubset(imdata->mask, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);23 24 psFree (srcRegion);25 19 return(mySource); 26 20 } -
trunk/psphot/src/psImageData.c
r4946 r4954 20 20 imdata->mask = mask; 21 21 22 p _psMemSetDeallocator(imdata, (psFreeFcn) psImageDataFree);22 psMemSetDeallocator(imdata, (psFreeFunc) psImageDataFree); 23 23 return (imdata); 24 24 } -
trunk/psphot/src/psLibUtils.c
r4946 r4954 1 # include "psphot.h" 1 # include <strings.h> // for strncasecmp 2 # include <pslib.h> 3 4 // XXX EAM : this is NOT included in the C99 headers ?? 5 FILE *fdopen(int fildes, const char *mode); 2 6 3 7 // XXX EAM : these utility functions should be added back into PSLib … … 29 33 if (timers == NULL) timers = psHashAlloc (16); 30 34 31 start = psTimeGet Time(PS_TIME_UTC);35 start = psTimeGetNow (PS_TIME_UTC); 32 36 psHashAdd (timers, name, start); 33 37 psFree (start); … … 47 51 if (start == NULL) return (0); 48 52 49 mark = psTimeGet Time(PS_TIME_UTC);53 mark = psTimeGetNow (PS_TIME_UTC); 50 54 delta = psTimeDelta (mark, start); 51 55 psFree (mark); … … 53 57 54 58 return (delta); 59 } 60 61 // find the location of the specified argument 62 int psArgumentGet (int argc, char **argv, char *arg) { 63 64 int i; 65 66 for (i = 0; i < argc; i++) { 67 if (!strcmp(argv[i], arg)) 68 return (i); 69 } 70 71 return ((int)NULL); 72 } 73 74 // remove the specified argument (by location) 75 int psArgumentRemove (int N, int *argc, char **argv) { 76 77 int i; 78 79 if ((N != (int)NULL) && (N != 0)) { 80 (*argc)--; 81 for (i = N; i < *argc; i++) { 82 argv[i] = argv[i+1]; 83 } 84 } 85 86 return (N); 55 87 } 56 88 … … 114 146 } 115 147 116 // find the location of the specified argument117 int psArgumentGet (int argc, char **argv, char *arg) {118 119 int i;120 121 for (i = 0; i < argc; i++) {122 if (!strcmp(argv[i], arg))123 return (i);124 }125 126 return ((int)NULL);127 }128 129 // remove the specified argument (by location)130 int psArgumentRemove (int N, int *argc, char **argv) {131 132 int i;133 134 if ((N != (int)NULL) && (N != 0)) {135 (*argc)--;136 for (i = N; i < *argc; i++) {137 argv[i] = argv[i+1];138 }139 }140 141 return (N);142 }143 144 148 // alternate implementation of this function from pmObjects.c 149 // XXX EAM : move this to pmObjects_EAM.c 145 150 psVector *psGetRowVectorFromImage(psImage *image, 146 151 psU32 row) 147 152 { 148 PS_ IMAGE_CHECK_NULL(image, NULL);149 PS_ IMAGE_CHECK_TYPE(image, PS_TYPE_F32, NULL);153 PS_ASSERT_IMAGE_NON_NULL(image, NULL); 154 PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL); 150 155 151 156 psVector *tmpVector = psVectorAlloc(image->numCols, PS_TYPE_F32); … … 201 206 } 202 207 203 void psImageSmooth (psImage *image, float sigma, float Nsigma) { 208 // XXX EAM : this is now in psLib 209 void psImageSmooth_EAM (psImage *image, float sigma, float Nsigma) { 204 210 205 211 int Nx, Ny, Npixel, Nrange; … … 314 320 } 315 321 322 // count number of pixels with given mask value 323 int psImageCountPixelMask (psImage *mask, psU8 value) 324 { 325 int Npixels = 0; 326 327 for (int i = 0; i < mask->numRows; i++) { 328 for (int j = 0; j < mask->numCols; j++) { 329 if (mask->data.U8[i][j] & value) { 330 Npixels ++; 331 } 332 } 333 } 334 return (Npixels); 335 } 336 316 337 // define a square region centered on the given coordinate 338 // XXX EAM : this is now in psLib 339 # if (0) 317 340 psRegion *psRegionSquare (psF32 x, psF32 y, psF32 radius) { 318 341 psRegion *region; … … 321 344 return (region); 322 345 } 346 # endif 323 347 324 348 // set actual region based on image parameters: … … 327 351 // frame, which means the negative values should subtract from Nx,Ny of 328 352 // the parent, not the child. but, we don't carry the dimensions of the 329 // parent in the psImage container. for now, us the child Nx,Ny 330 // force range to be on this subimage 331 // XXX EAM : this needs to be changes to use psRegion rather than psRegion* 353 // parent in the psImage container. for now, use the child Nx,Ny 354 // force range to be on this subimage 355 // XXX EAM : this needs to be changed to use psRegion rather than psRegion* 356 // XXX EAM : this is now in psLib 357 # if (0) 332 358 psRegion *psRegionForImage (psRegion *out, psImage *image, psRegion *in) { 333 359 … … 356 382 return (out); 357 383 } 384 # endif 358 385 359 386 // mask the area contained by the region 360 387 // the region is defined wrt the parent image 388 // XXX EAM : this is now in psLib 389 # if (0) 361 390 void psImageMaskRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) { 362 391 … … 375 404 } 376 405 } 406 # endif 377 407 378 408 // mask the area not contained by the region 379 409 // the region is defined wrt the parent image 410 // XXX EAM : this is now in psLib 411 # if (0) 380 412 void psImageKeepRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) { 381 413 … … 396 428 } 397 429 } 430 # endif 398 431 399 432 // mask the area contained by the region 400 433 // the region is defined wrt the parent image 434 // XXX EAM : this is now in psLib 435 # if (0) 401 436 void psImageMaskCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) { 402 437 … … 419 454 } 420 455 } 456 # endif 421 457 422 458 // mask the area contained by the region 423 459 // the region is defined wrt the parent image 460 // XXX EAM : this is now in psLib 461 # if (0) 424 462 void psImageKeepCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) { 425 463 … … 442 480 } 443 481 } 482 # endif 444 483 445 484 psVector *psVectorCreate (double lower, double upper, double delta, psElemType type) { … … 455 494 return (out); 456 495 } 496 497 // XXX EAM a utility function 498 bool p_psVectorPrintRow (int fd, psVector *a, char *name) 499 { 500 501 FILE *f; 502 f = fdopen(fd, "a+"); 503 fprintf (f, "vector: %s\n", name); 504 505 for (int i = 0; i < a[0].n; i++) { 506 fprintf (f, "%f ", p_psVectorGetElementF64(a, i)); 507 } 508 fprintf (f, "\n"); 509 fclose(f); 510 return (true); 511 } 512 // XXX EAM is the use of fdopen here a good way to do this? -
trunk/psphot/src/psLine.c
r4946 r4954 14 14 psLine *line; 15 15 line = psAlloc (sizeof(psLine)); 16 p _psMemSetDeallocator(line, (psFreeFcn) psLineFree);16 psMemSetDeallocator(line, (psFreeFunc) psLineFree); 17 17 18 18 line->Nline = 0; -
trunk/psphot/src/psMinimize.c
r4946 r4954 13 13 psMinimizeLMChi2Func func) 14 14 { 15 PS_PTR_CHECK_NULL(min, NULL);16 PS_VECTOR_CHECK_NULL(params, NULL);17 PS_VECTOR_CHECK_EMPTY(params, NULL);18 PS_PTR_CHECK_NULL(x, NULL);19 PS_VECTOR_CHECK_NULL(y, NULL);20 PS_VECTOR_CHECK_EMPTY(y, NULL);21 PS_VECTOR_CHECK_SIZE_EQUAL(x, y, NULL);22 PS_PTR_CHECK_NULL(func, NULL);15 // PS_PTR_CHECK_NULL(min, NULL); 16 // PS_VECTOR_CHECK_NULL(params, NULL); 17 // PS_VECTOR_CHECK_EMPTY(params, NULL); 18 // PS_PTR_CHECK_NULL(x, NULL); 19 // PS_VECTOR_CHECK_NULL(y, NULL); 20 // PS_VECTOR_CHECK_EMPTY(y, NULL); 21 // PS_VECTOR_CHECK_SIZE_EQUAL(x, y, NULL); 22 // PS_PTR_CHECK_NULL(func, NULL); 23 23 24 24 // this function has test and current values for several things -
trunk/psphot/src/psModulesUtils.c
r4949 r4954 11 11 psImage *image = source->pixels; 12 12 psImage *mask = source->mask; 13 psPeak *peak = source->peak; 14 psRegion *srcRegion; 15 16 srcRegion = psRegionSquare (peak->x, peak->y, Radius); 17 srcRegion = psRegionForImage (srcRegion, mask, srcRegion); 18 psImageMaskRegion (mask, srcRegion, OR, 0x80); 19 13 pmPeak *peak = source->peak; 14 psRegion srcRegion; 15 16 // XXX EAM : psRegionXXX funcs need value not ptr 17 18 srcRegion = psRegionForSquare (peak->x, peak->y, Radius); 19 srcRegion = psRegionForImage (mask, &srcRegion); 20 21 psImageMaskRegion (mask, &srcRegion, "OR", PSPHOT_MASK_MARKED); 20 22 psStats *myStats = psStatsAlloc(statsOptions); 21 23 myStats = psImageStats(myStats, image, mask, 0xff); 22 psImageMaskRegion (mask, srcRegion, AND, 0x7f);24 psImageMaskRegion (mask, &srcRegion, "AND", ~PSPHOT_MASK_MARKED); 23 25 24 26 psF64 tmpF64; 25 27 p_psGetStatValue(myStats, &tmpF64); 26 27 28 psFree (myStats); 28 psFree (srcRegion);29 29 30 30 if (isnan(tmpF64)) return (false); … … 40 40 const bool PSF) 41 41 { 42 PS_PTR_CHECK_NULL(source, false);43 PS_PTR_CHECK_NULL(source->moments, false);44 PS_PTR_CHECK_NULL(source->peak, false);45 PS_PTR_CHECK_NULL(source->pixels, false);46 PS_PTR_CHECK_NULL(source->mask, false);47 PS_PTR_CHECK_NULL(source->noise, false);42 // PS_PTR_CHECK_NULL(source, false); 43 // PS_PTR_CHECK_NULL(source->moments, false); 44 // PS_PTR_CHECK_NULL(source->peak, false); 45 // PS_PTR_CHECK_NULL(source->pixels, false); 46 // PS_PTR_CHECK_NULL(source->mask, false); 47 // PS_PTR_CHECK_NULL(source->noise, false); 48 48 psBool fitStatus = true; 49 49 psBool onPic = true; … … 188 188 189 189 XXX: mask values? 190 191 XXX EAM : this version clips input pixels on S/N 190 192 *****************************************************************************/ 191 193 # define VALID_RADIUS(X,Y) (((R2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0) … … 194 196 psF32 radius) 195 197 { 196 PS_PTR_CHECK_NULL(source, NULL);197 PS_PTR_CHECK_NULL(source->peak, NULL);198 PS_PTR_CHECK_NULL(source->pixels, NULL);199 PS_PTR_CHECK_NULL(source->noise, NULL);198 // PS_PTR_CHECK_NULL(source, NULL); 199 // PS_PTR_CHECK_NULL(source->peak, NULL); 200 // PS_PTR_CHECK_NULL(source->pixels, NULL); 201 // PS_PTR_CHECK_NULL(source->noise, NULL); 200 202 PS_FLOAT_COMPARE(0.0, radius, NULL); 201 203 -
trunk/psphot/src/psPolynomials.c
r4901 r4954 1 1 # include "psphot.h" 2 3 // XXX EAM : this file defines alternate versions of the polynomial fitting 4 // functions. these differ from psLib v.0.5.0 in the definition 5 // of nOrder (here we use nOrder in the mathematical sense, not 6 // like IRAF. ie, a linear function is of nOrder 1) 7 // psLib v 0.7.0 should be in sync with out defintion of nOrder 8 // If so, we can drop these functions and use the psLib versions. 2 9 3 10 // write out the terms of the given 1D polynomial … … 9 16 } 10 17 11 psF 32 Polynomial1DEval_EAM(psF32x, const psPolynomial1D* myPoly)18 psF64 Polynomial1DEval_EAM(psF64 x, const psPolynomial1D* myPoly) 12 19 { 13 20 psS32 loop_x = 0; 14 psF 32polySum = 0.0;15 psF 32xSum = 1.0;21 psF64 polySum = 0.0; 22 psF64 xSum = 1.0; 16 23 17 24 for (loop_x = 0; loop_x < myPoly->n + 1; loop_x++) { … … 28 35 const psVector *x) 29 36 { 30 PS_POLY_CHECK_NULL(myPoly, NULL);31 PS_VECTOR_CHECK_NULL(x, NULL);32 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL);37 // PS_POLY_CHECK_NULL(myPoly, NULL); 38 // PS_VECTOR_CHECK_NULL(x, NULL); 39 // PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 33 40 34 41 psVector *tmp; … … 56 63 psPolynomialType type) 57 64 { 58 PS_INT_CHECK_NON_NEGATIVE(nOrder, NULL);65 // PS_INT_CHECK_NON_NEGATIVE(nOrder, NULL); 59 66 60 67 psS32 i = 0; … … 65 72 newPoly->type = type; 66 73 newPoly->n = nOrder; 67 newPoly->coeff = (psF 32 *)psAlloc(nTerm * sizeof(psF32));68 newPoly->coeffErr = (psF 32 *)psAlloc(nTerm * sizeof(psF32));74 newPoly->coeff = (psF64 *)psAlloc(nTerm * sizeof(psF64)); 75 newPoly->coeffErr = (psF64 *)psAlloc(nTerm * sizeof(psF64)); 69 76 newPoly->mask = (psU8 *)psAlloc(nTerm * sizeof(psU8)); 70 77 for (i = 0; i < nTerm; i++) { … … 73 80 newPoly->mask[i] = 0; 74 81 } 75 p _psMemSetDeallocator(newPoly, (psFreeFcn) psPolynomial1DFree);82 psMemSetDeallocator(newPoly, (psFreeFunc) psPolynomial1DFree); 76 83 return(newPoly); 77 84 } … … 120 127 // dump minutiae 121 128 # ifndef PS_NO_TRACE 129 # if (0) 130 // XXX EAM : change from FILE to fd breaks this code: 122 131 if (psTraceGetLevel (".psLib.dataManip.VectorFitPolynomial1DOrd") >= 5) { 123 132 FILE *f = psTraceGetDestination (); … … 127 136 } 128 137 } 138 # endif 129 139 # endif 130 140 … … 214 224 215 225 { 216 PS_POLY_CHECK_NULL(myPoly, NULL);217 PS_VECTOR_CHECK_NULL(x, NULL);218 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL);219 PS_VECTOR_CHECK_NULL(y, NULL);220 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL);226 // PS_POLY_CHECK_NULL(myPoly, NULL); 227 // PS_VECTOR_CHECK_NULL(x, NULL); 228 // PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F32, NULL); 229 // PS_VECTOR_CHECK_NULL(y, NULL); 230 // PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F32, NULL); 221 231 222 232 psVector *tmp; … … 246 256 247 257 { 248 PS_POLY_CHECK_NULL(myPoly, NULL);249 PS_VECTOR_CHECK_NULL(x, NULL);250 PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL);251 PS_VECTOR_CHECK_NULL(y, NULL);252 PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL);258 // PS_POLY_CHECK_NULL(myPoly, NULL); 259 // PS_VECTOR_CHECK_NULL(x, NULL); 260 // PS_VECTOR_CHECK_TYPE(x, PS_TYPE_F64, NULL); 261 // PS_VECTOR_CHECK_NULL(y, NULL); 262 // PS_VECTOR_CHECK_TYPE(y, PS_TYPE_F64, NULL); 253 263 254 264 psVector *tmp; … … 291 301 psPolynomialType type) 292 302 { 293 PS_INT_CHECK_NON_NEGATIVE(nXorder, NULL);294 PS_INT_CHECK_NON_NEGATIVE(nYorder, NULL);303 // PS_INT_CHECK_NON_NEGATIVE(nXorder, NULL); 304 // PS_INT_CHECK_NON_NEGATIVE(nYorder, NULL); 295 305 296 306 psS32 x = 0; … … 305 315 newPoly->nY = nYorder; 306 316 307 newPoly->coeff = (psF32 **)psAlloc(nXterm * sizeof(psF32 *)); 308 newPoly->coeffErr = (psF32 **)psAlloc(nXterm * sizeof(psF32 *)); 309 newPoly->mask = (psU8 **)psAlloc(nXterm * sizeof(psU8 *)); 317 newPoly->coeff = (psF64 **)psAlloc(nXterm * sizeof(psF64 *)); 318 newPoly->coeffErr = (psF64 **)psAlloc(nXterm * sizeof(psF64 *)); 319 newPoly->mask = (char **)psAlloc(nXterm * sizeof(char *)); 320 // XXX EAM : this is an error in the definition of the polynomial mask 321 // (should be psU8 not char) 310 322 for (x = 0; x < nXterm; x++) { 311 newPoly->coeff[x] = (psF 32 *)psAlloc(nYterm * sizeof(psF32));312 newPoly->coeffErr[x] = (psF 32 *)psAlloc(nYterm * sizeof(psF32));313 newPoly->mask[x] = ( psU8 *)psAlloc(nYterm * sizeof(psU8));323 newPoly->coeff[x] = (psF64 *)psAlloc(nYterm * sizeof(psF64)); 324 newPoly->coeffErr[x] = (psF64 *)psAlloc(nYterm * sizeof(psF64)); 325 newPoly->mask[x] = (char *)psAlloc(nYterm * sizeof(char)); 314 326 } 315 327 for (x = 0; x < nXterm; x++) { … … 320 332 } 321 333 } 322 p _psMemSetDeallocator(newPoly, (psFreeFcn) psPolynomial2DFree);334 psMemSetDeallocator(newPoly, (psFreeFunc) psPolynomial2DFree); 323 335 return(newPoly); 324 336 } … … 510 522 const psVector* dz) 511 523 { 512 PS_VECTOR_CHECK_NULL(mask, NULL);513 PS_VECTOR_CHECK_NULL(x, NULL);514 PS_VECTOR_CHECK_NULL(y, NULL);515 PS_VECTOR_CHECK_NULL(z, NULL);516 PS_VECTOR_CHECK_NULL(dz, NULL);524 // PS_VECTOR_CHECK_NULL(mask, NULL); 525 // PS_VECTOR_CHECK_NULL(x, NULL); 526 // PS_VECTOR_CHECK_NULL(y, NULL); 527 // PS_VECTOR_CHECK_NULL(z, NULL); 528 // PS_VECTOR_CHECK_NULL(dz, NULL); 517 529 518 530 psVector *zFit = NULL; … … 548 560 // XXX EAM : VectorFitPolynomial2DOrd and Polynomial2DEvalVector require different types (F32 vs F64) 549 561 550 # if (0) // moved to psLib 551 // XXX EAM : this version uses myPoly->nX as Norder, not Nterms 552 psF32 Polynomial2DEval(const psPolynomial2D* myPoly, 553 psF32 x, 554 psF32 y) 555 { 556 PS_POLY_CHECK_NULL(myPoly, NAN); 562 psF64 Polynomial2DEval(const psPolynomial2D* myPoly, 563 psF64 x, 564 psF64 y) 565 { 566 // PS_POLY_CHECK_NULL(myPoly, NAN); 557 567 558 568 psS32 loop_x = 0; 559 569 psS32 loop_y = 0; 560 psF 32polySum = 0.0;561 psF 32xSum = 1.0;562 psF 32ySum = 1.0;570 psF64 polySum = 0.0; 571 psF64 xSum = 1.0; 572 psF64 ySum = 1.0; 563 573 564 574 // XXX EAM : nX is order, not nTerms … … 577 587 return(polySum); 578 588 } 579 # endif580 -
trunk/psphot/src/psphot.h
r4949 r4954 1 # include <stdio.h> 2 # include <strings.h> // for strcasecmp 3 # include <unistd.h> // for unlink 1 4 # include <pslib.h> 2 // # include <pmObjects.h>3 // my additions and modifications:4 5 # include "pmObjects_EAM.h" 5 # include <string.h>6 # include <strings.h>7 # include <unistd.h>8 # include <stdlib.h>9 # include <math.h>10 11 // # define M_PI 3.14159265358979323846264338328 /* pi */12 6 13 7 typedef struct { 14 psImage *image;15 psImage *mask;16 psImage *noise;17 psMetadata *header;8 psImage *image; 9 psImage *mask; 10 psImage *noise; 11 psMetadata *header; 18 12 } psImageData; 19 13 20 14 // data to test a given PSF model type 21 15 typedef struct { 22 pmModelType modelType;23 pmPSF *psf;24 psArray *sources; // pointers to the original sources25 psArray *modelFLT; // model fits, floating parameters26 psArray *modelPSF; // model fits, PSF parameters27 psVector *mask;28 psVector *metric;29 psVector *fitMag;30 float ApResid;31 float dApResid;32 float skyBias;16 pmModelType modelType; 17 pmPSF *psf; 18 psArray *sources; // pointers to the original sources 19 psArray *modelFLT; // model fits, floating parameters 20 psArray *modelPSF; // model fits, PSF parameters 21 psVector *mask; 22 psVector *metric; 23 psVector *fitMag; 24 float ApResid; 25 float dApResid; 26 float skyBias; 33 27 } pmPSF_Test; 34 28 35 29 // structure to carry a dynamic string 36 30 typedef struct { 37 int NLINE;38 int Nline;39 char *line;31 int NLINE; 32 int Nline; 33 char *line; 40 34 } psLine; 41 35 … … 43 37 PSPHOT_MASK_INVALID = 0x01, 44 38 PSPHOT_MASK_SATURATED = 0x02, 45 PSPHOT_MASK_ KEEP= 0x08,39 PSPHOT_MASK_MARKED = 0x08, 46 40 } MaskValues; 47 48 // used by mask operations49 # define AND true50 # define OR false51 41 52 42 # define psMemCopy(A)(psMemIncrRefCounter((A))) … … 116 106 psF32 pmConfigLookupF32 (bool *status, psMetadata *config, psMetadata *header, char *name); 117 107 psVector *psVectorCreate (double lower, double upper, double delta, psElemType type); 118 //void psImageMaskRegion (psImage *image, psRegion *region, bool logical_and, int maskValue);119 //void psImageKeepRegion (psImage *image, psRegion *region, bool logical_and, int maskValue);120 //void psImageMaskCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue);121 //void psImageKeepCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue);122 108 psVector *psGetRowVectorFromImage(psImage *image, psU32 row); 109 int psImageCountPixelMask (psImage *mask, psU8 value); 123 110 124 111 // basic image functions 125 112 bool psImageInit (psImage *image,...); 126 //void psImageSmooth (psImage *image, float sigma, float Nsigma); 127 //psRegion *psRegionForImage (psRegion *out, psImage *image, psRegion *in); 128 psRegion *psRegionSquare (psF32 x, psF32 y, psF32 radius); 113 void psImageSmooth_EAM (psImage *image, float sigma, float Nsigma); 129 114 int psphotSaveImage (psMetadata *header, psImage *image, char *filename); 130 115 … … 135 120 136 121 // polynomial functions 137 psF 32 Polynomial2DEval(const psPolynomial2D* myPoly, psF32 x, psF32y);122 psF64 Polynomial2DEval(const psPolynomial2D* myPoly, psF64 x, psF64 y); 138 123 psImage *psBuildSums2D(psImage* sums,psF64 x,psF64 y,psS32 nXterm, psS32 nYterm); 139 124 psPolynomial2D *VectorFitPolynomial2DOrd_EAM(psPolynomial2D* myPoly, psVector* mask, const psVector* x, const psVector* y, const psVector* z, const psVector* zErr); … … 143 128 psPolynomial2D *RobustFit2D(psPolynomial2D* poly, psVector* mask, const psVector* x, const psVector* y, const psVector* z, const psVector* zErr); 144 129 psVector *Polynomial2DEvalVector(const psPolynomial2D *myPoly, const psVector *x,const psVector *y); 130 145 131 psVector *psBuildSums1D(psVector* sums, psF64 x,psS32 nTerm); 146 132 void psPolynomial1DDump (psPolynomial1D *poly); 147 psF 32 Polynomial1DEval_EAM(psF32x, const psPolynomial1D* myPoly);133 psF64 Polynomial1DEval_EAM(psF64 x, const psPolynomial1D* myPoly); 148 134 psVector *Polynomial1DEvalVector_EAM(const psPolynomial1D *myPoly, const psVector *x); 149 135 psPolynomial1D *Polynomial1DAlloc(psS32 nOrder, psPolynomialType type); 150 136 psPolynomial1D *VectorFitPolynomial1DOrd_EAM(psPolynomial1D* myPoly, psVector* mask, const psVector* x, const psVector* y, const psVector* yErr); 151 137 152 // fitsource 153 bool onesource (psImageData *imdata, psMetadata *config, char *modelName, float x, float y); 154 psMetadata *fs_args (int *argc, char **argv); 155 int fs_usage (); 156 bool DumpImage (psImage *image, char *filename); 138 // XXX EAM : bug : missing from psLib/*.h 139 bool psMinimizeGaussNewtonDelta (psVector *delta, 140 const psVector *params, 141 const psVector *paramMask, 142 const psArray *x, 143 const psVector *y, 144 const psVector *yErr, 145 psMinimizeLMChi2Func func); 146 147 // not included in the .h file? 148 bool p_psVectorPrint ( 149 int fd, ///< output file descriptor 150 psVector *a, ///< vector to print 151 char *name ///< name of vector (for title) 152 ); 153 154 bool p_psVectorPrintRow (int fd, psVector *a, char *name); -
trunk/psphot/src/psphotApplyPSF.c
r4949 r4954 66 66 67 67 // fit PSF model (set/unset the pixel mask) 68 psImageKeepCircle (source->mask, x, y, model->radius, " or", PSPHOT_MASK_KEEP);68 psImageKeepCircle (source->mask, x, y, model->radius, "OR", PSPHOT_MASK_MARKED); 69 69 status = pmSourceFitModel (source, model, true); 70 psImageKeepCircle (source->mask, x, y, model->radius, " and", ~PSPHOT_MASK_KEEP);70 psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PSPHOT_MASK_MARKED); 71 71 if (!status || (model->params->data.F32[1] < 0)) { 72 72 psLogMsg ("psphot", 3, "PSF fit failed for %f, %f (%d iterations)\n", x, y, model->nIter); -
trunk/psphot/src/psphotArguments.c
r4946 r4954 43 43 psMetadata *config = psMetadataAlloc (); 44 44 psMetadataAdd (config, PS_LIST_HEAD, "PSF_MODEL", PS_META_MULTI, "folder for psf model entries", NULL); 45 config = psMetadata ParseConfig(config, &Nfail, argv[3], FALSE);45 config = psMetadataConfigParse (config, &Nfail, argv[3], FALSE); 46 46 fprintf (stderr, "loaded config...\n"); 47 47 -
trunk/psphot/src/psphotFitGalaxies.c
r4949 r4954 50 50 51 51 // recalculate the source moments using the larger galaxy moments radius 52 status = pmSourceMoments (source, GAL_MOMENTS_RAD); 52 // XXX EAM : 0.5.0 code used _EAM version 53 // status = pmSourceMoments (source, GAL_MOMENTS_RAD); 54 status = pmSourceMoments_EAM (source, GAL_MOMENTS_RAD); 53 55 if (!status) { 54 56 source->type = PS_SOURCE_DROP_GALAXY; // better choice? … … 74 76 75 77 // fit FLT (not PSF) model (set/unset the pixel mask) 76 psImageKeepCircle (source->mask, x, y, model->radius, OR, PSPHOT_MASK_KEEP); 78 psImageKeepCircle (source->mask, x, y, model->radius, "OR", PSPHOT_MASK_MARKED); 79 // XXX EAM : 0.5.0 code used _EAM version 80 // status = pmSourceFitModel (source, model, false); 77 81 status = pmSourceFitModel (source, model, false); 78 psImageKeepCircle (source->mask, x, y, model->radius, AND, ~PSPHOT_MASK_KEEP);82 psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PSPHOT_MASK_MARKED); 79 83 if (!status) { 80 84 // if the fit fails, we need to change the classification -
trunk/psphot/src/psphotOutput.c
r4949 r4954 372 372 373 373 // write the peaks to an output file 374 bool p sPeaksWriteText (psArray *sources, char *filename) {374 bool pmPeaksWriteText (psArray *sources, char *filename) { 375 375 376 376 int i; 377 377 FILE *f; 378 p sPeak *peak;378 pmPeak *peak; 379 379 380 380 f = fopen (filename, "w"); 381 381 if (f == NULL) { 382 psLogMsg ("p sPeaksWriteText", 3, "can't open output file for peaks%s\n", filename);383 return false; 384 } 385 386 for (i = 0; i < sources->n; i++) { 387 peak = (p sPeak *) sources->data[i];382 psLogMsg ("pmPeaksWriteText", 3, "can't open output file for peaks%s\n", filename); 383 return false; 384 } 385 386 for (i = 0; i < sources->n; i++) { 387 peak = (pmPeak *) sources->data[i]; 388 388 if (peak == NULL) continue; 389 389 fprintf (f, "%5d %5d %7.1f\n", … … 638 638 unlink (filename); 639 639 psFits *fits = psFitsAlloc (filename); 640 psFitsWriteImage (fits, header, image, 0 , NULL);640 psFitsWriteImage (fits, header, image, 0); 641 641 psFree (fits); 642 642 return (TRUE); -
trunk/psphot/src/psphotSetup.c
r4949 r4954 75 75 psRegion keep = psRegionSet (XMIN, XMAX, YMIN, YMAX); 76 76 keep = psRegionForImage (image, &keep); 77 psImageKeepRegion (mask, &keep, OR, PSPHOT_MASK_INVALID);77 psImageKeepRegion (mask, &keep, "OR", PSPHOT_MASK_INVALID); 78 78 // XXX EAM : psRegionForImage should not take psRegion *keep 79 79 -
trunk/psphot/src/psphotSourceStats.c
r4949 r4954 35 35 36 36 // measure basic source moments 37 status = pmSourceMoments (source, RADIUS); 37 // XXX EAM : choose between these two versions 38 status = pmSourceMoments_EAM (source, RADIUS); 38 39 if (!status) { 39 40 psFree (source); -
trunk/psphot/src/pspsf.c
r4949 r4954 31 31 } 32 32 33 p _psMemSetDeallocator(psf, (psFreeFcn) pmPSFFree);33 psMemSetDeallocator(psf, (psFreeFunc) pmPSFFree); 34 34 return(psf); 35 35 } … … 74 74 } 75 75 76 p _psMemSetDeallocator(test, (psFreeFcn) pmPSF_TestFree);76 psMemSetDeallocator(test, (psFreeFunc) pmPSF_TestFree); 77 77 return (test); 78 78 } … … 106 106 // set temporary object mask and fit object 107 107 // fit model as FLT, not PSF 108 psImageKeepCircle (source->mask, x, y, RADIUS, OR, 0x80);108 psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PSPHOT_MASK_MARKED); 109 109 status = pmSourceFitModel (source, model, false); 110 psImageKeepCircle (source->mask, x, y, RADIUS, AND, 0x7f);110 psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PSPHOT_MASK_MARKED); 111 111 112 112 // exclude the poor fits … … 142 142 y = source->peak->y; 143 143 144 psImageKeepCircle (source->mask, x, y, RADIUS, OR, 0x80);144 psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PSPHOT_MASK_MARKED); 145 145 status = pmSourceFitModel (source, modelPSF, true); 146 146 … … 168 168 169 169 next_source: 170 psImageKeepCircle (source->mask, x, y, RADIUS, AND, 0x7f);170 psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PSPHOT_MASK_MARKED); 171 171 172 172 }
Note:
See TracChangeset
for help on using the changeset viewer.
