Changeset 29004
- Timestamp:
- Aug 20, 2010, 1:14:11 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 133 edited
- 16 copied
-
psModules (modified) (1 prop)
-
psModules/src/camera/pmFPAfileIO.c (modified) (1 diff)
-
psModules/src/camera/pmReadoutFake.c (modified) (1 diff)
-
psModules/src/camera/pmReadoutFake.h (modified) (1 diff)
-
psModules/src/config/pmConfig.c (modified) (2 diffs)
-
psModules/src/detrend/pmMaskStats.c (modified) (2 diffs)
-
psModules/src/detrend/pmShutterCorrection.c (modified) (1 diff)
-
psModules/src/extras/Makefile.am (modified) (2 diffs)
-
psModules/src/extras/pmVisual.c (modified) (3 diffs)
-
psModules/src/extras/pmVisualUtils.c (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/extras/pmVisualUtils.c )
-
psModules/src/extras/pmVisualUtils.h (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/extras/pmVisualUtils.h )
-
psModules/src/imcombine/pmPSFEnvelope.c (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtraction.c (modified) (5 diffs)
-
psModules/src/imcombine/pmSubtraction.h (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtractionEquation.c (modified) (18 diffs)
-
psModules/src/imcombine/pmSubtractionEquation.h (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtractionKernels.c (modified) (19 diffs)
-
psModules/src/imcombine/pmSubtractionKernels.h (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtractionMatch.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionMatch.h (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionStamps.c (modified) (10 diffs)
-
psModules/src/imcombine/pmSubtractionStamps.h (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtractionVisual.c (modified) (11 diffs)
-
psModules/src/objects/Makefile.am (modified) (6 diffs)
-
psModules/src/objects/models/pmModel_DEV.c (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/models/pmModel_DEV.c )
-
psModules/src/objects/models/pmModel_DEV.h (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/models/pmModel_DEV.h )
-
psModules/src/objects/models/pmModel_EXP.c (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/models/pmModel_EXP.c )
-
psModules/src/objects/models/pmModel_EXP.h (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/models/pmModel_EXP.h )
-
psModules/src/objects/models/pmModel_GAUSS.c (modified) (5 diffs)
-
psModules/src/objects/models/pmModel_PGAUSS.c (modified) (3 diffs)
-
psModules/src/objects/models/pmModel_PS1_V1.c (modified) (4 diffs)
-
psModules/src/objects/models/pmModel_QGAUSS.c (modified) (3 diffs)
-
psModules/src/objects/models/pmModel_RGAUSS.c (modified) (4 diffs)
-
psModules/src/objects/models/pmModel_SERSIC.c (modified) (13 diffs)
-
psModules/src/objects/pmDetEff.c (modified) (1 diff)
-
psModules/src/objects/pmDetEff.h (modified) (1 diff)
-
psModules/src/objects/pmFootprint.c (modified) (1 diff)
-
psModules/src/objects/pmFootprint.h (modified) (1 diff)
-
psModules/src/objects/pmFootprintArrayGrow.c (modified) (1 diff)
-
psModules/src/objects/pmFootprintArraysMerge.c (modified) (1 diff)
-
psModules/src/objects/pmFootprintAssignPeaks.c (modified) (1 diff)
-
psModules/src/objects/pmFootprintCullPeaks.c (modified) (1 diff)
-
psModules/src/objects/pmFootprintFind.c (modified) (1 diff)
-
psModules/src/objects/pmFootprintFindAtPoint.c (modified) (1 diff)
-
psModules/src/objects/pmFootprintIDs.c (modified) (1 diff)
-
psModules/src/objects/pmFootprintSpans.c (modified) (1 diff)
-
psModules/src/objects/pmFootprintSpans.h (modified) (1 diff)
-
psModules/src/objects/pmGrowthCurve.c (modified) (1 diff)
-
psModules/src/objects/pmGrowthCurveGenerate.c (modified) (1 diff)
-
psModules/src/objects/pmModel.c (modified) (2 diffs)
-
psModules/src/objects/pmModel.h (modified) (3 diffs)
-
psModules/src/objects/pmModelClass.c (modified) (3 diffs)
-
psModules/src/objects/pmModelClass.h (modified) (1 diff)
-
psModules/src/objects/pmModelFuncs.h (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/pmModelFuncs.h )
-
psModules/src/objects/pmModelUtils.c (modified) (1 diff)
-
psModules/src/objects/pmMoments.c (modified) (1 diff)
-
psModules/src/objects/pmMoments.h (modified) (2 diffs)
-
psModules/src/objects/pmPCM_MinimizeChisq.c (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/pmPCM_MinimizeChisq.c )
-
psModules/src/objects/pmPCMdata.c (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/pmPCMdata.c )
-
psModules/src/objects/pmPCMdata.h (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/pmPCMdata.h )
-
psModules/src/objects/pmPSF.c (modified) (3 diffs)
-
psModules/src/objects/pmPSF.h (modified) (4 diffs)
-
psModules/src/objects/pmPSF_IO.c (modified) (1 diff)
-
psModules/src/objects/pmPSFtry.c (modified) (1 diff)
-
psModules/src/objects/pmPSFtryFitEXT.c (modified) (3 diffs)
-
psModules/src/objects/pmPSFtryFitPSF.c (modified) (4 diffs)
-
psModules/src/objects/pmPSFtryMakePSF.c (modified) (1 diff)
-
psModules/src/objects/pmPSFtryMetric.c (modified) (1 diff)
-
psModules/src/objects/pmPSFtryModel.c (modified) (2 diffs)
-
psModules/src/objects/pmPeaks.c (modified) (1 diff)
-
psModules/src/objects/pmPeaks.h (modified) (1 diff)
-
psModules/src/objects/pmPhotObj.c (modified) (2 diffs)
-
psModules/src/objects/pmPhotObj.h (modified) (2 diffs)
-
psModules/src/objects/pmSource.c (modified) (11 diffs)
-
psModules/src/objects/pmSource.h (modified) (6 diffs)
-
psModules/src/objects/pmSourceContour.c (modified) (1 diff)
-
psModules/src/objects/pmSourceDiffStats.c (modified) (1 diff)
-
psModules/src/objects/pmSourceDiffStats.h (modified) (1 diff)
-
psModules/src/objects/pmSourceFitModel.c (modified) (10 diffs)
-
psModules/src/objects/pmSourceFitModel.h (modified) (2 diffs)
-
psModules/src/objects/pmSourceFitPCM.c (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourceFitPCM.c )
-
psModules/src/objects/pmSourceFitSet.c (modified) (5 diffs)
-
psModules/src/objects/pmSourceFitSet.h (modified) (1 diff)
-
psModules/src/objects/pmSourceGroup.h (deleted)
-
psModules/src/objects/pmSourceGroups.c (modified) (1 diff)
-
psModules/src/objects/pmSourceGroups.h (modified) (1 diff)
-
psModules/src/objects/pmSourceIO.c (modified) (5 diffs)
-
psModules/src/objects/pmSourceIO.h (modified) (2 diffs)
-
psModules/src/objects/pmSourceIO_CMF_PS1_DV1.c (modified) (6 diffs)
-
psModules/src/objects/pmSourceIO_CMF_PS1_DV2.c (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourceIO_CMF_PS1_DV2.c )
-
psModules/src/objects/pmSourceIO_CMF_PS1_SV1.c (modified) (13 diffs)
-
psModules/src/objects/pmSourceIO_CMF_PS1_V1.c (modified) (6 diffs)
-
psModules/src/objects/pmSourceIO_CMF_PS1_V2.c (modified) (6 diffs)
-
psModules/src/objects/pmSourceIO_CMF_PS1_V3.c (copied) (copied from branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourceIO_CMF_PS1_V3.c )
-
psModules/src/objects/pmSourceIO_CMP.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_MatchedRefs.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_OBJ.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_PS1_CAL_0.c (modified) (5 diffs)
-
psModules/src/objects/pmSourceIO_PS1_DEV_0.c (modified) (5 diffs)
-
psModules/src/objects/pmSourceIO_PS1_DEV_1.c (modified) (7 diffs)
-
psModules/src/objects/pmSourceIO_RAW.c (modified) (3 diffs)
-
psModules/src/objects/pmSourceIO_SMPDATA.c (modified) (5 diffs)
-
psModules/src/objects/pmSourceIO_SX.c (modified) (1 diff)
-
psModules/src/objects/pmSourceMasks.h (modified) (1 diff)
-
psModules/src/objects/pmSourceMatch.c (modified) (1 diff)
-
psModules/src/objects/pmSourceMatch.h (modified) (1 diff)
-
psModules/src/objects/pmSourceMoments.c (modified) (11 diffs)
-
psModules/src/objects/pmSourcePhotometry.c (modified) (13 diffs)
-
psModules/src/objects/pmSourcePhotometry.h (modified) (1 diff)
-
psModules/src/objects/pmSourcePlotApResid.c (modified) (1 diff)
-
psModules/src/objects/pmSourcePlotMoments.c (modified) (1 diff)
-
psModules/src/objects/pmSourcePlotPSFModel.c (modified) (1 diff)
-
psModules/src/objects/pmSourceSky.c (modified) (1 diff)
-
psModules/src/objects/pmSourceUtils.c (modified) (1 diff)
-
psModules/src/objects/pmSourceVisual.c (modified) (7 diffs)
-
psModules/src/objects/pmSpan.h (modified) (1 diff)
-
psModules/src/objects/pmTrend2D.h (modified) (1 diff)
-
psModules/src/psmodules.h (modified) (4 diffs)
-
psphot (modified) (1 prop)
-
psphot/doc/notes.20100715.txt (copied) (copied from branches/eam_branches/ipp-20100621/psphot/doc/notes.20100715.txt )
-
psphot/doc/psf.load.txt (copied) (copied from branches/eam_branches/ipp-20100621/psphot/doc/psf.load.txt )
-
psphot/doc/visual.txt (copied) (copied from branches/eam_branches/ipp-20100621/psphot/doc/visual.txt )
-
psphot/src/Makefile.am (modified) (1 diff)
-
psphot/src/psphot.h (modified) (8 diffs)
-
psphot/src/psphotAddNoise.c (modified) (3 diffs)
-
psphot/src/psphotApResid.c (modified) (1 diff)
-
psphot/src/psphotArguments.c (modified) (1 diff)
-
psphot/src/psphotBlendFit.c (modified) (12 diffs)
-
psphot/src/psphotChoosePSF.c (modified) (4 diffs)
-
psphot/src/psphotEllipticalContour.c (modified) (1 diff)
-
psphot/src/psphotExtendedSourceAnalysis.c (modified) (1 diff)
-
psphot/src/psphotExtendedSourceFits.c (modified) (8 diffs)
-
psphot/src/psphotFindDetections.c (modified) (1 diff)
-
psphot/src/psphotFitSet.c (modified) (1 diff)
-
psphot/src/psphotFitSourcesLinear.c (modified) (2 diffs)
-
psphot/src/psphotFitSourcesLinearStack.c (modified) (1 diff)
-
psphot/src/psphotGuessModels.c (modified) (1 diff)
-
psphot/src/psphotLoadSRCTEXT.c (modified) (1 diff)
-
psphot/src/psphotMagnitudes.c (modified) (5 diffs)
-
psphot/src/psphotModelWithPSF.c (modified) (2 diffs)
-
psphot/src/psphotPSFConvModel.c (modified) (2 diffs)
-
psphot/src/psphotPetrosianVisual.c (modified) (5 diffs)
-
psphot/src/psphotRadiusChecks.c (modified) (9 diffs)
-
psphot/src/psphotReadout.c (modified) (1 diff)
-
psphot/src/psphotSetThreads.c (modified) (2 diffs)
-
psphot/src/psphotSignificanceImage.c (modified) (1 diff)
-
psphot/src/psphotSourceFits.c (modified) (23 diffs)
-
psphot/src/psphotSourceSize.c (modified) (8 diffs)
-
psphot/src/psphotSourceStats.c (modified) (4 diffs)
-
psphot/src/psphotVisual.c (modified) (46 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules
- Property svn:mergeinfo deleted
-
trunk/psModules/src/camera/pmFPAfileIO.c
r28340 r29004 24 24 #include "pmFPAfileFitsIO.h" 25 25 #include "pmFPAfileFringeIO.h" 26 27 #include "pmTrend2D.h" 28 #include "pmResiduals.h" 29 #include "pmGrowthCurve.h" 26 30 #include "pmSpan.h" 31 #include "pmFootprintSpans.h" 27 32 #include "pmFootprint.h" 28 33 #include "pmPeaks.h" 29 34 #include "pmMoments.h" 30 #include "pmResiduals.h" 31 #include "pmGrowthCurve.h" 32 #include "pmTrend2D.h" 35 #include "pmModelFuncs.h" 36 #include "pmModel.h" 37 #include "pmSourceMasks.h" 38 #include "pmSourceExtendedPars.h" 39 #include "pmSourceDiffStats.h" 40 #include "pmSource.h" 41 #include "pmSourceFitModel.h" 33 42 #include "pmPSF.h" 34 #include "pm Model.h"35 #include "pmSource.h" 43 #include "pmPSFtry.h" 44 36 45 #include "pmSourceIO.h" 37 #include "pmResiduals.h"38 46 #include "pmPSF_IO.h" 47 39 48 #include "pmAstrometryModel.h" 40 49 #include "pmAstrometryRefstars.h" -
trunk/psModules/src/camera/pmReadoutFake.c
r28405 r29004 10 10 #include "pmFPA.h" 11 11 12 #include "pmMoments.h" 12 13 #include "pmTrend2D.h" 13 14 #include "pmResiduals.h" 14 15 #include "pmGrowthCurve.h" 15 #include "pmTrend2D.h"16 #include "pmPSF.h"17 #include "pmModel.h"18 #include "pmModelClass.h"19 16 #include "pmSpan.h" 17 #include "pmFootprintSpans.h" 20 18 #include "pmFootprint.h" 21 19 #include "pmPeaks.h" 20 #include "pmMoments.h" 21 #include "pmModelFuncs.h" 22 #include "pmModel.h" 23 #include "pmModelUtils.h" 24 #include "pmModelClass.h" 25 #include "pmSourceMasks.h" 26 #include "pmSourceExtendedPars.h" 27 #include "pmSourceDiffStats.h" 22 28 #include "pmSource.h" 23 #include "pmSourceUtils.h" 24 #include "pmModelUtils.h" 29 #include "pmSourceFitModel.h" 30 #include "pmPSF.h" 31 #include "pmPSFtry.h" 32 25 33 #include "pmSourceGroups.h" 26 27 34 #include "pmReadoutFake.h" 28 35 -
trunk/psModules/src/camera/pmReadoutFake.h
r26450 r29004 2 2 #define PM_READOUT_FAKE_H 3 3 4 #include <pslib.h>5 #include <pmHDU.h>6 #include <pmFPA.h>7 8 #include <pmMoments.h>9 #include <pmResiduals.h>10 #include <pmGrowthCurve.h>11 #include <pmTrend2D.h>12 #include <pmPSF.h>13 #include <pmSourceMasks.h>4 // #include <pslib.h> 5 // #include <pmHDU.h> 6 // #include <pmFPA.h> 7 // 8 // #include <pmMoments.h> 9 // #include <pmResiduals.h> 10 // #include <pmGrowthCurve.h> 11 // #include <pmTrend2D.h> 12 // #include <pmPSF.h> 13 // #include <pmSourceMasks.h> 14 14 15 15 /// Set threading -
trunk/psModules/src/config/pmConfig.c
r28287 r29004 32 32 33 33 #include "pmConfig.h" 34 #include "pmVisualUtils.h" 34 35 35 36 #ifdef HAVE_NEBCLIENT … … 638 639 psArgumentVerbosity(argc, argv); 639 640 // XXX: substitute the string for the default log level for "2". 641 } 642 643 // Set the visualization levels 644 // argument format is: -visual (facil) (level) 645 while ((argNum = psArgumentGet(*argc, argv, "-visual"))) { 646 if ( (*argc < argNum + 3) ) { 647 psError(PS_ERR_IO, true, "-visual switch specified without facility and level."); 648 return NULL; 649 } 650 psArgumentRemove(argNum, argc, argv); 651 pmVisualSetLevel(argv[argNum], atoi(argv[argNum+1])); 652 psArgumentRemove(argNum, argc, argv); 653 psArgumentRemove(argNum, argc, argv); 654 } 655 if ((argNum = psArgumentGet(*argc, argv, "-visual-all"))) { 656 pmVisualSetLevel(".", 10); 657 psArgumentRemove(argNum, argc, argv); 658 } 659 if ((argNum = psArgumentGet(*argc, argv, "-visual-levels"))) { 660 pmVisualPrintLevels(stdout); 661 psArgumentRemove(argNum, argc, argv); 640 662 } 641 663 -
trunk/psModules/src/detrend/pmMaskStats.c
r28100 r29004 7 7 8 8 #include <pslib.h> 9 #include <psmodules.h>10 9 11 10 #include "pmHDU.h" … … 16 15 #include "pmFPAAstrometry.h" 17 16 17 #include "pmMaskStats.h" 18 18 19 19 #define ESCAPE { \ -
trunk/psModules/src/detrend/pmShutterCorrection.c
r28405 r29004 302 302 PS_ASSERT_PTR_NON_NULL(guess, NULL); 303 303 304 psMinimization *minInfo = psMinimizationAlloc(15, 0.1 ); // Minimization information304 psMinimization *minInfo = psMinimizationAlloc(15, 0.1, 1.0); // Minimization information 305 305 306 306 psVector *params = psVectorAlloc (3, PS_TYPE_F32); // Fitting parameters -
trunk/psModules/src/extras/Makefile.am
r27750 r29004 9 9 pmKapaPlots.c \ 10 10 pmVisual.c \ 11 pmVisualUtils.c \ 11 12 ippStages.c 12 13 … … 17 18 pmKapaPlots.h \ 18 19 pmVisual.h \ 20 pmVisualUtils.h \ 19 21 ippDiffMode.h \ 20 22 ippStages.h -
trunk/psModules/src/extras/pmVisual.c
r28129 r29004 21 21 #include "pmAstrometryObjects.h" 22 22 #include "pmSubtractionStamps.h" 23 23 24 #include "pmTrend2D.h" 25 #include "pmResiduals.h" 26 #include "pmGrowthCurve.h" 27 #include "pmSpan.h" 28 #include "pmFootprintSpans.h" 29 #include "pmFootprint.h" 30 #include "pmPeaks.h" 31 #include "pmMoments.h" 32 #include "pmModelFuncs.h" 33 #include "pmModel.h" 34 #include "pmSourceMasks.h" 35 #include "pmSourceExtendedPars.h" 36 #include "pmSourceDiffStats.h" 37 #include "pmSource.h" 38 #include "pmSourceFitModel.h" 24 39 #include "pmPSF.h" 25 40 #include "pmPSFtry.h" 26 #include "pmSource.h" 41 27 42 #include "pmFPAExtent.h" 28 29 # if (HAVE_KAPA)30 # include <kapa.h>31 # include "pmVisual.h"32 # include "pmKapaPlots.h"33 # define KAPAX 70034 # define KAPAY 70035 43 36 44 #include "pmAstrometryVisual.h" … … 38 46 #include "pmStackVisual.h" 39 47 #include "pmSourceVisual.h" 48 49 # if (HAVE_KAPA) 50 # include <kapa.h> 51 #include "pmVisual.h" 52 #include "pmKapaPlots.h" 53 54 # define KAPAX 700 55 # define KAPAY 700 40 56 41 57 //#define TESTING … … 102 118 103 119 /* Wait up to 1.0 second for a response, then continue */ 104 timeout.tv_sec = 2;120 timeout.tv_sec = 10; 105 121 timeout.tv_usec = 0; 106 122 -
trunk/psModules/src/imcombine/pmPSFEnvelope.c
r28332 r29004 10 10 #include "pmHDU.h" 11 11 #include "pmFPA.h" 12 #include "pmReadoutFake.h" 13 14 #include "pmMoments.h" 12 13 #include "pmTrend2D.h" 15 14 #include "pmResiduals.h" 16 15 #include "pmGrowthCurve.h" 17 #include "pmTrend2D.h"18 #include "pmPSF.h"19 #include "pmModel.h"20 #include "pmModelClass.h"21 #include "pmModelUtils.h"22 16 #include "pmSpan.h" 17 #include "pmFootprintSpans.h" 23 18 #include "pmFootprint.h" 24 19 #include "pmPeaks.h" 20 #include "pmMoments.h" 21 #include "pmModelFuncs.h" 22 #include "pmModel.h" 23 #include "pmModelUtils.h" 24 #include "pmModelClass.h" 25 #include "pmSourceMasks.h" 26 #include "pmSourceExtendedPars.h" 27 #include "pmSourceDiffStats.h" 25 28 #include "pmSource.h" 26 #include "pmSourceUtils.h"27 29 #include "pmSourceFitModel.h" 30 #include "pmPSF.h" 28 31 #include "pmPSFtry.h" 29 32 30 33 #include "pmReadoutFake.h" 31 34 #include "pmPSFEnvelope.h" 32 35 #include "pmStackVisual.h" … … 410 413 options->chiFluxTrend = false; // All sources have similar flux, so fitting a trend often fails 411 414 412 pmSourceFitModelInit(SOURCE_FIT_ITERATIONS, 0.01, VARIANCE_VAL, true); 415 // options which modify the behavior of the model fitting 416 options->fitOptions = pmSourceFitOptionsAlloc(); 417 options->fitOptions->nIter = SOURCE_FIT_ITERATIONS; 418 options->fitOptions->minTol = 0.01; 419 options->fitOptions->maxTol = 1.00; 420 options->fitOptions->poissonErrors = true; 421 options->fitOptions->weight = VARIANCE_VAL; 422 options->fitOptions->mode = PM_SOURCE_FIT_PSF; 423 413 424 pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT); // Important for getting a good stack target PSF 414 425 -
trunk/psModules/src/imcombine/pmSubtraction.c
r28667 r29004 33 33 #define USE_KERNEL_ERR // Use kernel error image? 34 34 #define NUM_COVAR_POS 5 // Number of positions for covariance calculation 35 36 // XXX we need to pass these fwhm values elsewhere. These should go on one of the structure, but 37 // things are too confusing to do that now. just save them here. 38 static float FWHM1 = NAN; 39 static float FWHM2 = NAN; 35 40 36 41 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 752 757 753 758 754 bool pmSubtractionConvolveStamp (pmSubtractionStamp *stamp, constpmSubtractionKernels *kernels, int footprint)759 bool pmSubtractionConvolveStamp (pmSubtractionStamp *stamp, pmSubtractionKernels *kernels, int footprint) 755 760 { 756 761 PS_ASSERT_PTR_NON_NULL(stamp, false); … … 774 779 stamp->convolutions1 = convolveStamp(stamp->convolutions1, stamp->image1, kernels, footprint); 775 780 stamp->convolutions2 = convolveStamp(stamp->convolutions2, stamp->image2, kernels, footprint); 781 if (!pmSubtractionKernelPenaltiesStamp(stamp, kernels)) { 782 psAbort("failure in penalties"); 783 } 776 784 break; 777 785 default: … … 1215 1223 bool threaded = pmSubtractionThreaded(); // Running threaded? 1216 1224 1225 // XXX This is no longer used 1217 1226 psImage *convMask = NULL; // Convolved mask image (common to inputs 1 and 2) 1218 1227 if (subMask) { … … 1413 1422 return true; 1414 1423 } 1424 1425 bool pmSubtractionGetFWHMs(float *fwhm1, float *fwhm2) { 1426 1427 *fwhm1 = FWHM1; 1428 *fwhm2 = FWHM2; 1429 return true; 1430 } 1431 1432 bool pmSubtractionSetFWHMs(float fwhm1, float fwhm2) { 1433 1434 FWHM1 = fwhm1; 1435 FWHM2 = fwhm2; 1436 return true; 1437 } -
trunk/psModules/src/imcombine/pmSubtraction.h
r26893 r29004 59 59 /// Convolve the reference stamp with the kernel components 60 60 bool pmSubtractionConvolveStamp(pmSubtractionStamp *stamp, ///< Stamp to convolve 61 constpmSubtractionKernels *kernels, ///< Kernel parameters61 pmSubtractionKernels *kernels, ///< Kernel parameters 62 62 int footprint ///< Half-size of region over which to calculate equation 63 63 ); … … 157 157 ); 158 158 159 bool pmSubtractionGetFWHMs(float *fwhm1, float *fwhm2); 160 bool pmSubtractionSetFWHMs(float fwhm1, float fwhm2); 161 159 162 /// @} 160 163 #endif -
trunk/psModules/src/imcombine/pmSubtractionEquation.c
r28405 r29004 38 38 const psImage *polyValues, // Spatial polynomial values 39 39 int footprint, // (Half-)Size of stamp 40 int normWindow, // Window (half-)size for normalisation measurement 40 int normWindow1, // Window (half-)size for normalisation measurement 41 int normWindow2, // Window (half-)size for normalisation measurement 41 42 const pmSubtractionEquationCalculationMode mode 42 43 ) … … 184 185 double one = 1.0; 185 186 186 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(normWindow )) {187 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(normWindow1)) { 187 188 normI1 += ref; 189 } 190 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(normWindow2)) { 188 191 normI2 += in; 189 192 } … … 214 217 215 218 *norm = normI2 / normI1; 219 220 fprintf (stderr, "normValue: %f %f %f\n", normI1, normI2, *norm); 216 221 217 222 if (mode & PM_SUBTRACTION_EQUATION_NORM) { … … 262 267 const psImage *polyValues, // Spatial polynomial values 263 268 int footprint, // (Half-)Size of stamp 264 int normWindow, // Window (half-)size for normalisation measurement 269 int normWindow1, // Window (half-)size for normalisation measurement 270 int normWindow2, // Window (half-)size for normalisation measurement 265 271 const pmSubtractionEquationCalculationMode mode 266 272 ) … … 492 498 double i1i2 = i1 * i2; 493 499 494 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(normWindow )) {500 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(normWindow1)) { 495 501 normI1 += i1; 502 } 503 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(normWindow2)) { 496 504 normI2 += i2; 497 505 } … … 522 530 523 531 *norm = normI2 / normI1; 532 fprintf (stderr, "normValue: %f %f %f\n", normI1, normI2, *norm); 524 533 525 534 if (mode & PM_SUBTRACTION_EQUATION_NORM) { … … 559 568 // Add in penalty term to least-squares vector 560 569 bool calculatePenalty(psImage *matrix, // Matrix to which to add in penalty term 561 psVector *vector, // Vector to which to add in penalty term562 const pmSubtractionKernels *kernels, // Kernel parameters563 float norm // Normalisation564 )570 psVector *vector, // Vector to which to add in penalty term 571 const pmSubtractionKernels *kernels, // Kernel parameters 572 float norm // Normalisation 573 ) 565 574 { 566 575 if (kernels->penalty == 0.0) { … … 568 577 } 569 578 570 psVector *penalties = kernels->penalties; // Penalties for each kernel component 579 psVector *penalties1 = kernels->penalties1; // Penalties for each kernel component (input) 580 psVector *penalties2 = kernels->penalties2; // Penalties for each kernel component (ref) 581 571 582 int spatialOrder = kernels->spatialOrder; // Order of spatial variations 572 583 int numKernels = kernels->num; // Number of kernel components … … 588 599 for (int xOrder = 0; xOrder <= spatialOrder - yOrder; xOrder++, index += numKernels) { 589 600 // Contribution to chi^2: a_i^2 P_i 590 psAssert(isfinite(penalties->data.F32[i]), "Invalid penalty"); 591 matrix->data.F64[index][index] += norm * penalties->data.F32[i]; 601 psAssert(isfinite(penalties1->data.F32[i]), "Invalid penalty"); 602 fprintf (stderr, "penalty: %f + %f (%f * %f)\n", matrix->data.F64[index][index], norm * penalties1->data.F32[i], norm, penalties1->data.F32[i]); 603 matrix->data.F64[index][index] += norm * penalties1->data.F32[i]; 592 604 if (kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 593 matrix->data.F64[index + numParams + 2][index + numParams + 2] += norm * penalties->data.F32[i]; 605 fprintf (stderr, "penalty: (x^%d y^%d fwhm %f) : %f + %f (%f * %f)\n", kernels->u->data.S32[index], kernels->v->data.S32[index], kernels->widths->data.F32[index], 606 matrix->data.F64[index + numParams + 2][index + numParams + 2], norm * penalties2->data.F32[i], norm, penalties2->data.F32[i]); 607 matrix->data.F64[index + numParams + 2][index + numParams + 2] += norm * penalties2->data.F32[i]; 594 608 // matrix[i][i] is ~ (k_i * I_1)(k_i * I_1) 595 609 // penalties scale with second moments … … 682 696 683 697 pmSubtractionStampList *stamps = job->args->data[0]; // List of stamps 684 constpmSubtractionKernels *kernels = job->args->data[1]; // Kernels698 pmSubtractionKernels *kernels = job->args->data[1]; // Kernels 685 699 int index = PS_SCALAR_VALUE(job->args->data[2], S32); // Stamp index 686 700 pmSubtractionEquationCalculationMode mode = PS_SCALAR_VALUE(job->args->data[3], S32); // calculation model … … 689 703 } 690 704 691 bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, constpmSubtractionKernels *kernels,705 bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels, 692 706 int index, const pmSubtractionEquationCalculationMode mode) 693 707 { … … 778 792 status = calculateMatrixVector(stamp->matrix, stamp->vector, &stamp->norm, stamp->image2, stamp->image1, 779 793 weight, window, stamp->convolutions1, kernels, 780 polyValues, footprint, stamps->normWindow , mode);794 polyValues, footprint, stamps->normWindow1, stamps->normWindow2, mode); 781 795 break; 782 796 case PM_SUBTRACTION_MODE_2: 783 797 status = calculateMatrixVector(stamp->matrix, stamp->vector, &stamp->norm, stamp->image1, stamp->image2, 784 798 weight, window, stamp->convolutions2, kernels, 785 polyValues, footprint, stamps->normWindow , mode);799 polyValues, footprint, stamps->normWindow2, stamps->normWindow1, mode); 786 800 break; 787 801 case PM_SUBTRACTION_MODE_DUAL: … … 789 803 stamp->image1, stamp->image2, 790 804 weight, window, stamp->convolutions1, stamp->convolutions2, 791 kernels, polyValues, footprint, stamps->normWindow , mode);805 kernels, polyValues, footprint, stamps->normWindow1, stamps->normWindow2, mode); 792 806 break; 793 807 default: … … 830 844 } 831 845 832 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, constpmSubtractionKernels *kernels,846 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels, 833 847 const pmSubtractionEquationCalculationMode mode) 834 848 { … … 996 1010 } 997 1011 1012 // double normValue = 1.0; 998 1013 double normValue = stats->robustMedian; 999 1014 // double bgValue = 0.0; … … 1023 1038 } 1024 1039 # endif 1040 1041 #if (1) 1042 for (int i = 0; i < solution->n; i++) { 1043 fprintf(stderr, "Single solution %d: %lf\n", i, solution->data.F64[i]); 1044 } 1045 #endif 1025 1046 1026 1047 if (!kernels->solution1) { … … 1096 1117 1097 1118 int normIndex = PM_SUBTRACTION_INDEX_NORM(kernels); // Index for normalisation 1098 calculatePenalty(sumMatrix, sumVector, kernels, sumMatrix->data.F64[normIndex][normIndex] / 100 0.0);1119 calculatePenalty(sumMatrix, sumVector, kernels, sumMatrix->data.F64[normIndex][normIndex] / 100.0); 1099 1120 #endif 1100 1121 … … 1177 1198 1178 1199 1179 #if def TESTING1200 #if (1) 1180 1201 for (int i = 0; i < solution->n; i++) { 1181 1202 fprintf(stderr, "Dual solution %d: %lf\n", i, solution->data.F64[i]); -
trunk/psModules/src/imcombine/pmSubtractionEquation.h
r26893 r29004 19 19 /// Calculate the least-squares equation to match the image quality for a single stamp 20 20 bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, ///< Stamps 21 constpmSubtractionKernels *kernels, ///< Kernel parameters21 pmSubtractionKernels *kernels, ///< Kernel parameters 22 22 int index, ///< Index of stamp 23 23 const pmSubtractionEquationCalculationMode mode … … 26 26 /// Calculate the least-squares equation to match the image quality 27 27 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, ///< Stamps 28 constpmSubtractionKernels *kernels, ///< Kernel parameters28 pmSubtractionKernels *kernels, ///< Kernel parameters 29 29 const pmSubtractionEquationCalculationMode mode 30 30 ); -
trunk/psModules/src/imcombine/pmSubtractionKernels.c
r27335 r29004 26 26 psFree(kernels->vStop); 27 27 psFree(kernels->preCalc); 28 psFree(kernels->penalties); 28 psFree(kernels->penalties1); 29 psFree(kernels->penalties2); 29 30 psFree(kernels->solution1); 30 31 psFree(kernels->solution2); … … 140 141 kernels->v = psVectorRealloc(kernels->v, start + numNew); 141 142 kernels->preCalc = psArrayRealloc(kernels->preCalc, start + numNew); 142 kernels->penalties = psVectorRealloc(kernels->penalties, start + numNew); 143 144 kernels->penalties1 = psVectorRealloc(kernels->penalties1, start + numNew); 145 kernels->penalties2 = psVectorRealloc(kernels->penalties2, start + numNew); 146 143 147 kernels->inner = start; 144 148 kernels->num += numNew; … … 156 160 kernels->v->data.S32[index] = v; 157 161 kernels->preCalc->data[index] = NULL; 158 kernels->penalties->data.F32[index] = kernels->penalty * PS_SQR(PS_SQR(u) + PS_SQR(v)); 159 psAssert (isfinite(kernels->penalties->data.F32[index]), "invalid penalty"); 162 163 // XXX this needs to be changed to use the *convolved* second moment 164 kernels->penalties1->data.F32[index] = kernels->penalty * PS_SQR(PS_SQR(u) + PS_SQR(v)); 165 psAssert (isfinite(kernels->penalties1->data.F32[index]), "invalid penalty"); 166 167 kernels->penalties2->data.F32[index] = kernels->penalty * PS_SQR(PS_SQR(u) + PS_SQR(v)); 168 psAssert (isfinite(kernels->penalties2->data.F32[index]), "invalid penalty"); 169 160 170 psTrace("psModules.imcombine", 7, "Kernel %d: %d %d\n", index, u, v); 161 171 } … … 166 176 kernels->v->n = start + numNew; 167 177 kernels->preCalc->n = start + numNew; 168 kernels->penalties->n = start + numNew; 178 179 kernels->penalties1->n = start + numNew; 180 kernels->penalties2->n = start + numNew; 169 181 170 182 return true; 171 183 } 172 184 173 bool pmSubtractionKernelPreCalcNormalize(pmSubtractionKernels *kernels, pmSubtractionKernelPreCalc *preCalc,174 int index, int size, int uOrder, int vOrder, float fwhm,175 bool AlardLuptonStyle, bool forceZeroNull)185 static bool pmSubtractionKernelPreCalcNormalize(pmSubtractionKernels *kernels, pmSubtractionKernelPreCalc *preCalc, 186 int index, int uOrder, int vOrder, float fwhm, 187 bool AlardLuptonStyle, bool forceZeroNull) 176 188 { 177 189 // we have 4 cases here: … … 182 194 183 195 // Calculate moments 184 double penalty = 0.0; // Moment, for penalty185 196 double sum = 0.0, sum2 = 0.0; // Sum of kernel component 186 197 float min = INFINITY, max = -INFINITY; // Minimum and maximum kernel value 187 for (int v = -size; v <= size; v++) { 188 for (int u = -size; u <= size; u++) { 198 199 for (int v = preCalc->kernel->yMin; v <= preCalc->kernel->yMax; v++) { 200 for (int u = preCalc->kernel->xMin; u <= preCalc->kernel->xMax; u++) { 189 201 double value = preCalc->kernel->kernel[v][u]; 190 202 double value2 = PS_SQR(value); 191 203 sum += value; 192 204 sum2 += value2; 193 penalty += value2 * PS_SQR((PS_SQR(u) + PS_SQR(v)));194 205 min = PS_MIN(value, min); 195 206 max = PS_MAX(value, max); … … 198 209 199 210 #if 0 200 fprintf(stderr, "%d raw: %lf, null: %f, min: %lf, max: %lf , moment: %lf\n", index, sum, preCalc->kernel->kernel[0][0], min, max, penalty);211 fprintf(stderr, "%d raw: %lf, null: %f, min: %lf, max: %lf\n", index, sum, preCalc->kernel->kernel[0][0], min, max); 201 212 #endif 202 213 … … 207 218 if (uOrder % 2 == 0 && vOrder % 2 == 0) { 208 219 // Even functions: normalise to unit sum and subtract null pixel so that sum is zero 209 scale2D = 1.0 / fabs(sum); 220 // Re-normalize 221 // scale2D = 1.0 / fabs(sum); 222 scale2D = 1.0 / sqrt(sum2); 210 223 zeroNull = true; 211 224 } else { … … 239 252 240 253 psBinaryOp(preCalc->kernel->image, preCalc->kernel->image, "*", psScalarAlloc(scale2D, PS_TYPE_F32)); 241 penalty *= 1.0 / sum2;242 254 243 255 if (zeroNull) { 244 preCalc->kernel->kernel[0][0] -= 1.0; 245 } 246 247 #if 0 256 // preCalc->kernel->kernel[0][0] -= 1.0; 257 preCalc->kernel->kernel[0][0] -= sum / sqrt (sum2); 258 } 259 260 #if 1 248 261 { 249 double sum = 0.0; // Sum of kernel component 262 double Sum = 0.0; // Sum of kernel component 263 double Sum2 = 0.0; // Sum of kernel component 250 264 float min = INFINITY, max = -INFINITY; // Minimum and maximum kernel value 251 for (int v = -size; v <= size; v++) { 252 for (int u = -size; u <= size; u++) { 253 sum += preCalc->kernel->kernel[v][u]; 265 for (int v = preCalc->kernel->yMin; v <= preCalc->kernel->yMax; v++) { 266 for (int u = preCalc->kernel->xMin; u <= preCalc->kernel->xMax; u++) { 267 double value = preCalc->kernel->kernel[v][u]; 268 Sum += value; 269 Sum2 += PS_SQR(value); 254 270 min = PS_MIN(preCalc->kernel->kernel[v][u], min); 255 271 max = PS_MAX(preCalc->kernel->kernel[v][u], max); 256 272 } 257 273 } 258 fprintf(stderr, "%d mod: %lf, null: %f, min: %lf, max: %lf, scale: %f\n", index, sum, preCalc->kernel->kernel[0][0], min, max, scale2D);274 fprintf(stderr, "%d sum: %lf, sum2: %lf, null: %f, min: %lf, max: %lf, scale: %f\n", index, Sum, Sum2, preCalc->kernel->kernel[0][0], min, max, scale2D); 259 275 } 260 276 #endif … … 267 283 } 268 284 kernels->preCalc->data[index] = preCalc; 269 kernels->penalties->data.F32[index] = kernels->penalty * penalty; 270 psAssert (isfinite(kernels->penalties->data.F32[index]), "invalid penalty"); 271 psTrace("psModules.imcombine", 7, "Kernel %d: %f %d %d %f\n", index, fwhm, uOrder, vOrder, penalty); 285 psTrace("psModules.imcombine", 7, "Kernel %d: %f %d %d\n", index, fwhm, uOrder, vOrder); 272 286 273 287 return true; … … 321 335 322 336 pmSubtractionKernelPreCalc *preCalc = pmSubtractionKernelPreCalcAlloc(PM_SUBTRACTION_KERNEL_ISIS, uOrder, vOrder, size, sigma); // structure to hold precalculated values 323 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, size,uOrder, vOrder, fwhms->data.F32[i], true, false);324 // pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, size,uOrder, vOrder, fwhms->data.F32[i], false, false);337 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, uOrder, vOrder, fwhms->data.F32[i], true, false); 338 // pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, uOrder, vOrder, fwhms->data.F32[i], false, false); 325 339 } 326 340 } … … 379 393 for (int vOrder = 0; vOrder <= orders->data.S32[i] - uOrder; vOrder++, index++) { 380 394 pmSubtractionKernelPreCalc *preCalc = pmSubtractionKernelPreCalcAlloc(PM_SUBTRACTION_KERNEL_ISIS, uOrder, vOrder, size, sigma); // structure to hold precalculated values 381 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, size,uOrder, vOrder, fwhms->data.F32[i], true, false);395 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, uOrder, vOrder, fwhms->data.F32[i], true, false); 382 396 } 383 397 } … … 385 399 // XXX modify size for hermitians to account for sqrt(2) in Hermitian definition (relative to ISIS Gaussian) 386 400 pmSubtractionKernelPreCalc *preCalc = pmSubtractionKernelPreCalcAlloc(PM_SUBTRACTION_KERNEL_ISIS_RADIAL, order, order, size, sigma / sqrt(2.0)); // structure to hold precalculated values 387 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, size,order, order, fwhms->data.F32[i], true, true);401 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, order, order, fwhms->data.F32[i], true, true); 388 402 } 389 403 } … … 437 451 for (int vOrder = 0; vOrder <= orders->data.S32[i] - uOrder; vOrder++, index++) { 438 452 pmSubtractionKernelPreCalc *preCalc = pmSubtractionKernelPreCalcAlloc(PM_SUBTRACTION_KERNEL_HERM, uOrder, vOrder, size, sigma); // structure to hold precalculated values 439 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, size,uOrder, vOrder, fwhms->data.F32[i], true, false);453 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, uOrder, vOrder, fwhms->data.F32[i], true, false); 440 454 } 441 455 } … … 506 520 507 521 // XXX do we use Alard-Lupton normalization (last param true) or not? 508 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, size,uOrder, vOrder, fwhms->data.F32[i], true, false);522 pmSubtractionKernelPreCalcNormalize (kernels, preCalc, index, uOrder, vOrder, fwhms->data.F32[i], true, false); 509 523 510 524 // XXXX test demo that deconvolved kernel is valid … … 572 586 kernels->preCalc = psArrayAlloc(numBasisFunctions); 573 587 kernels->penalty = penalty; 574 kernels->penalties = psVectorAlloc(numBasisFunctions, PS_TYPE_F32); 588 kernels->penalties1 = psVectorAlloc(numBasisFunctions, PS_TYPE_F32); 589 psVectorInit(kernels->penalties1, NAN); 590 kernels->penalties2 = psVectorAlloc(numBasisFunctions, PS_TYPE_F32); 591 psVectorInit(kernels->penalties2, NAN); 592 kernels->havePenalties = false; 575 593 kernels->size = size; 576 594 kernels->inner = 0; … … 771 789 772 790 psWarning("Kernel penalty for dual-convolution is not configured for SPAM kernels."); 773 psVectorInit(kernels->penalties, 0.0); 791 psVectorInit(kernels->penalties1, 0.0); 792 psVectorInit(kernels->penalties2, 0.0); 774 793 775 794 return kernels; … … 866 885 867 886 psWarning("Kernel penalty for dual-convolution is not configured for FRIES kernels."); 868 psVectorInit(kernels->penalties, 0.0); 887 psVectorInit(kernels->penalties1, 0.0); 888 psVectorInit(kernels->penalties2, 0.0); 869 889 870 890 return kernels; … … 1040 1060 kernels->u->data.S32[index] = uOrder; 1041 1061 kernels->v->data.S32[index] = vOrder; 1042 kernels->penalties->data.F32[index] = kernels->penalty * fabsf(moment); 1043 if (!isfinite(kernels->penalties->data.F32[index])) { 1062 1063 // XXX convert to use the convolved 2nd moment 1064 kernels->penalties1->data.F32[index] = kernels->penalty * fabsf(moment); 1065 if (!isfinite(kernels->penalties1->data.F32[index])) { 1066 psAbort ("invalid penalty"); 1067 } 1068 kernels->penalties2->data.F32[index] = kernels->penalty * fabsf(moment); 1069 if (!isfinite(kernels->penalties2->data.F32[index])) { 1044 1070 psAbort ("invalid penalty"); 1045 1071 } … … 1247 1273 out->preCalc = psMemIncrRefCounter(in->preCalc); 1248 1274 out->penalty = in->penalty; 1249 out->penalties = psMemIncrRefCounter(in->penalties); 1275 out->penalties1 = psMemIncrRefCounter(in->penalties1); 1276 out->penalties2 = psMemIncrRefCounter(in->penalties2); 1250 1277 out->uStop = psMemIncrRefCounter(in->uStop); 1251 1278 out->vStop = psMemIncrRefCounter(in->vStop); -
trunk/psModules/src/imcombine/pmSubtractionKernels.h
r26893 r29004 39 39 psArray *preCalc; ///< Array of images containing pre-calculated kernel (for ISIS, HERM or DECONV_HERM) 40 40 float penalty; ///< Penalty for wideness 41 psVector *penalties; ///< Penalty for each kernel component 41 psVector *penalties1; ///< Penalty for each kernel component 42 psVector *penalties2; ///< Penalty for each kernel component 43 bool havePenalties; ///< flag to test if we have already calculated the penalties or not. 42 44 int size; ///< The half-size of the kernel 43 45 int inner; ///< The size of an inner region … … 308 310 ); 309 311 310 311 312 #endif -
trunk/psModules/src/imcombine/pmSubtractionMatch.c
r28405 r29004 1304 1304 float scale = PS_MAX(fwhm1, fwhm2) / scaleRef; // Scaling factor 1305 1305 1306 // XXX save these values in a static for later use 1307 pmSubtractionSetFWHMs(fwhm1, fwhm2); 1308 1306 1309 if (isfinite(scaleMin) && scale < scaleMin) { 1307 1310 scale = scaleMin; -
trunk/psModules/src/imcombine/pmSubtractionMatch.h
r26893 r29004 110 110 ); 111 111 112 113 112 #endif -
trunk/psModules/src/imcombine/pmSubtractionStamps.c
r27402 r29004 7 7 #include <pslib.h> 8 8 9 #include "pmErrorCodes.h" 10 #include "pmHDU.h" 11 #include "pmFPA.h" 12 9 13 // All these includes required to get stamps out of an array of pmSources 10 #include "pmMoments.h" 14 #include "pmTrend2D.h" 15 #include "pmResiduals.h" 16 #include "pmGrowthCurve.h" 11 17 #include "pmSpan.h" 18 #include "pmFootprintSpans.h" 12 19 #include "pmFootprint.h" 13 20 #include "pmPeaks.h" 14 #include "pmResiduals.h" 15 #include "pmHDU.h" 16 #include "pmFPA.h" 17 #include "pmGrowthCurve.h" 18 #include "pmTrend2D.h" 19 #include "pmPSF.h" 21 #include "pmMoments.h" 22 #include "pmModelFuncs.h" 20 23 #include "pmModel.h" 24 #include "pmSourceMasks.h" 25 #include "pmSourceExtendedPars.h" 26 #include "pmSourceDiffStats.h" 21 27 #include "pmSource.h" 22 #include "pmErrorCodes.h"23 28 24 29 #include "pmSubtraction.h" … … 46 51 psFree(list->y); 47 52 psFree(list->flux); 48 psFree(list->window); 53 psFree(list->window1); 54 psFree(list->window2); 49 55 } 50 56 … … 225 231 list->y = NULL; 226 232 list->flux = NULL; 227 list->window = NULL;228 233 list->normFrac = normFrac; 229 list->normWindow = 0; 234 list->window1 = NULL; 235 list->window2 = NULL; 236 list->normWindow1 = 0; 237 list->normWindow2 = 0; 230 238 list->footprint = footprint; 231 239 list->sysErr = sysErr; … … 248 256 out->y = NULL; 249 257 out->flux = NULL; 250 out->window = psMemIncrRefCounter(in->window); 258 out->window1 = psMemIncrRefCounter(in->window1); 259 out->window2 = psMemIncrRefCounter(in->window2); 251 260 out->footprint = in->footprint; 252 out->normWindow = in->normWindow; 261 out->normWindow1 = in->normWindow1; 262 out->normWindow2 = in->normWindow2; 253 263 254 264 for (int i = 0; i < num; i++) { … … 638 648 int size = stamps->footprint; // Size of postage stamps 639 649 640 psFree (stamps->window); 641 stamps->window = psKernelAlloc(-size, size, -size, size); 642 psImageInit(stamps->window->image, 0.0); 650 psFree (stamps->window1); 651 stamps->window1 = psKernelAlloc(-size, size, -size, size); 652 psImageInit(stamps->window1->image, 0.0); 653 654 psFree (stamps->window2); 655 stamps->window2 = psKernelAlloc(-size, size, -size, size); 656 psImageInit(stamps->window2->image, 0.0); 643 657 644 658 // generate normalizations for each stamp … … 669 683 670 684 // generate the window pixels 671 double sum = 0.0; // Sum inside the window 672 float maxValue = 0.0; // Maximum value, for normalisation 685 double sum1 = 0.0; // Sum inside the window 686 double sum2 = 0.0; // Sum inside the window 687 float maxValue1 = 0.0; // Maximum value, for normalisation 688 float maxValue2 = 0.0; // Maximum value, for normalisation 673 689 for (int y = -size; y <= size; y++) { 674 690 for (int x = -size; x <= size; x++) { … … 691 707 } 692 708 float f1 = stats->robustMedian; 709 693 710 psStatsInit (stats); 694 711 if (!psVectorStats (stats, flux2, NULL, NULL, 0)) { … … 697 714 float f2 = stats->robustMedian; 698 715 699 stamps->window ->kernel[y][x] = f1 + f2;716 stamps->window1->kernel[y][x] = f1; 700 717 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(size)) { 701 sum += stamps->window->kernel[y][x]; 702 } 703 maxValue = PS_MAX(maxValue, stamps->window->kernel[y][x]); 704 } 705 } 706 707 psTrace("psModules.imcombine", 3, "Window total: %f, threshold: %f\n", 708 sum, (1.0 - stamps->normFrac) * sum); 709 bool done = false; 710 for (int radius = 1; radius <= size && !done; radius++) { 711 double within = 0.0; 718 sum1 += stamps->window1->kernel[y][x]; 719 } 720 maxValue1 = PS_MAX(maxValue1, stamps->window1->kernel[y][x]); 721 722 stamps->window2->kernel[y][x] = f2; 723 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(size)) { 724 sum2 += stamps->window2->kernel[y][x]; 725 } 726 maxValue2 = PS_MAX(maxValue2, stamps->window2->kernel[y][x]); 727 } 728 } 729 730 psTrace("psModules.imcombine", 3, "Window total (1): %f, threshold: %f\n", sum1, (1.0 - stamps->normFrac) * sum1); 731 psTrace("psModules.imcombine", 3, "Window total (2): %f, threshold: %f\n", sum2, (1.0 - stamps->normFrac) * sum2); 732 733 # if (0) 734 // this block attempts to calculate the radius based on the first radial moment 735 bool done1 = false; 736 bool done2 = false; 737 double prior1 = 0.0; 738 double prior2 = 0.0; 739 for (int y = -size; y <= size; y++) { 740 for (int x = -size; x <= size; x++) { 741 float r = hypot(x, y); 742 Sr1 += r * stamps->window1->kernel[y][x]; 743 Sr2 += r * stamps->window2->kernel[y][x]; 744 Sf1 += stamps->window1->kernel[y][x]; 745 Sf2 += stamps->window2->kernel[y][x]; 746 } 747 } 748 749 float R1 = Sr1 / Sf1; 750 float R2 = Sr2 / Sf2; 751 752 stamps->normWindow1 = 2.5*R1; 753 stamps->normWindow1 = 2.5*R2; 754 # else 755 // XXX : this block attempts to calculate the radius by looking at the curve of growth (or something vaguely equivalent). 756 // It did not do very well (though a true curve-of-growth analysis might be better...) 757 bool done1 = false; 758 bool done2 = false; 759 double prior1 = 0.0; 760 double prior2 = 0.0; 761 double delta1o = 1.0; 762 double delta2o = 1.0; 763 for (int radius = 1; radius <= size && !(done1 && done2); radius++) { 764 double within1 = 0.0; 765 double within2 = 0.0; 712 766 for (int y = -radius; y <= radius; y++) { 713 767 for (int x = -radius; x <= radius; x++) { 714 768 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(radius)) { 715 within += stamps->window->kernel[y][x];769 within1 += stamps->window1->kernel[y][x]; 716 770 } 717 } 718 } 719 psTrace("psModules.imcombine", 5, "Radius %d: %f\n", radius, within); 720 if (within > (1.0 - stamps->normFrac) * sum) { 721 stamps->normWindow = radius; 722 done = true; 723 } 724 } 725 726 psTrace("psModules.imcombine", 3, "Normalisation window radius set to %d\n", stamps->normWindow); 727 if (stamps->normWindow == 0 || stamps->normWindow >= size) { 728 psError(PM_ERR_STAMPS, true, "Unable to determine normalisation window size."); 771 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(radius)) { 772 within2 += stamps->window2->kernel[y][x]; 773 } 774 } 775 } 776 double delta1 = (within1 - prior1) / within1; 777 if (!done1 && (fabs(delta1) < stamps->normFrac)) { 778 // interpolate to the radius at which delta2 is normFrac: 779 stamps->normWindow1 = radius - (stamps->normFrac - delta1) / (delta1o - delta1); 780 fprintf (stderr, "choosing %f (%d) for 1 (%f : %f)\n", stamps->normWindow1, radius, within1, delta1); 781 done1 = true; 782 } 783 double delta2 = (within2 - prior2) / within2; 784 if (!done2 && (fabs(delta2) < stamps->normFrac)) { 785 // interpolate to the radius at which delta2 is normFrac: 786 stamps->normWindow2 = radius - (stamps->normFrac - delta2) / (delta2o - delta2); 787 fprintf (stderr, "choosing %f (%d) for 2 (%f : %f)\n", stamps->normWindow2, radius, within2, delta2); 788 done2 = true; 789 } 790 psTrace("psModules.imcombine", 5, "Radius %d: %f (%f) and %f (%f)\n", radius, within1, delta1, within2, delta2); 791 792 prior1 = within1; 793 prior2 = within2; 794 delta1o = delta1; 795 delta2o = delta2; 796 797 // if (!done1 && (within1 > (1.0 - stamps->normFrac) * sum1)) { 798 // stamps->normWindow1 = radius; 799 // done1 = true; 800 // } 801 // if (!done2 && (within2 > (1.0 - stamps->normFrac) * sum2)) { 802 // stamps->normWindow2 = radius; 803 // done2 = true; 804 // } 805 806 } 807 # endif 808 809 psTrace("psModules.imcombine", 3, "Normalisation window radii set to %f and %f\n", stamps->normWindow1, stamps->normWindow2); 810 if (stamps->normWindow1 == 0 || stamps->normWindow1 >= size) { 811 psError(PM_ERR_STAMPS, true, "Unable to determine normalisation window size (1)."); 812 return false; 813 } 814 if (stamps->normWindow2 == 0 || stamps->normWindow2 >= size) { 815 psError(PM_ERR_STAMPS, true, "Unable to determine normalisation window size (2)."); 729 816 return false; 730 817 } … … 733 820 for (int y = -size; y <= size; y++) { 734 821 for (int x = -size; x <= size; x++) { 735 stamps->window->kernel[y][x] /= maxValue; 736 } 737 } 738 739 #if 0 822 stamps->window1->kernel[y][x] /= maxValue1; 823 } 824 } 825 // re-normalize so chisquare values are sensible 826 for (int y = -size; y <= size; y++) { 827 for (int x = -size; x <= size; x++) { 828 stamps->window2->kernel[y][x] /= maxValue2; 829 } 830 } 831 832 #if 1 740 833 { 741 psFits *fits = psFitsOpen ("window.fits", "w"); 742 psFitsWriteImage (fits, NULL, stamps->window->image, 0, NULL); 834 psFits *fits = NULL; 835 fits = psFitsOpen ("window1.fits", "w"); 836 psFitsWriteImage (fits, NULL, stamps->window1->image, 0, NULL); 837 psFitsClose (fits); 838 fits = psFitsOpen ("window2.fits", "w"); 839 psFitsWriteImage (fits, NULL, stamps->window2->image, 0, NULL); 743 840 psFitsClose (fits); 744 841 } … … 747 844 psFree (stats); 748 845 psFree (flux1); 749 psFree (flux2);846 psFree (flux2); 750 847 psFree (norm1); 751 848 psFree (norm2); 752 849 return true; 850 } 851 852 static pthread_mutex_t getPenaltiesMutex = PTHREAD_MUTEX_INITIALIZER; 853 854 // kernels->penalty is an overall scaling factor (user-supplied) 855 bool pmSubtractionKernelPenaltiesStamp(pmSubtractionStamp *stamp, pmSubtractionKernels *kernels) 856 { 857 // we only need the penalties if we are doing dual convolution 858 if (kernels->mode != PM_SUBTRACTION_MODE_DUAL) return true; 859 860 // we only calculate the penalties once. 861 if (kernels->havePenalties) return true; 862 863 // in a threaded context, only one thread can calculate the penalties. attempt to grab a 864 // mutex before continuing 865 pthread_mutex_lock(&getPenaltiesMutex); 866 867 // did someone else already get the mutex and do this? 868 if (kernels->havePenalties) { 869 pthread_mutex_unlock(&getPenaltiesMutex); 870 return true; 871 } 872 873 for (int i = 0; i < kernels->num; i++) { 874 pmSubtractionKernelPenalties(stamp, kernels, i); 875 } 876 877 kernels->havePenalties = true; 878 pthread_mutex_unlock(&getPenaltiesMutex); 879 return true; 880 } 881 882 # define EMPIRICAL 0 883 884 // kernels->penalty is an overall scaling factor (user-supplied) 885 bool pmSubtractionKernelPenalties(pmSubtractionStamp *stamp, pmSubtractionKernels *kernels, int index) 886 { 887 float penalty1, penalty2; 888 float fwhm1, fwhm2; 889 890 // XXX this is annoyingly hack-ish 891 pmSubtractionGetFWHMs(&fwhm1, &fwhm2); 892 893 bool zeroNull = false; 894 int uOrder = kernels->u->data.S32[index]; 895 int vOrder = kernels->v->data.S32[index]; 896 if (uOrder % 2 == 0 && vOrder % 2 == 0) zeroNull = true; 897 898 if (EMPIRICAL) { 899 psKernel *convolution1 = stamp->convolutions1->data[index]; 900 penalty1 = pmSubtractionKernelPenaltySingle(convolution1, zeroNull); 901 902 psKernel *convolution2 = stamp->convolutions2->data[index]; 903 penalty2 = pmSubtractionKernelPenaltySingle(convolution2, zeroNull); 904 } else { 905 pmSubtractionKernelPreCalc *kernel = kernels->preCalc->data[index]; 906 float M2 = pmSubtractionKernelPenaltySingle(kernel->kernel, zeroNull); 907 908 penalty1 = M2 + PS_SQR(fwhm1 / 2.35); // rescale the unconvolved second-moment by the image second moment 909 penalty2 = M2 + PS_SQR(fwhm2 / 2.35); // rescale the unconvolved second-moment by the image second moment 910 } 911 kernels->penalties1->data.F32[index] = kernels->penalty * penalty1; 912 psAssert (isfinite(kernels->penalties1->data.F32[index]), "invalid penalty"); 913 914 kernels->penalties2->data.F32[index] = kernels->penalty * penalty2; 915 psAssert (isfinite(kernels->penalties2->data.F32[index]), "invalid penalty"); 916 917 fprintf(stderr, "penalty1: %f, penalty2: %f\n", penalty1, penalty2); 918 919 return true; 920 } 921 922 float pmSubtractionKernelPenaltySingle(psKernel *kernel, bool zeroNull) 923 { 924 // Calculate moments 925 double penalty = 0.0; // Moment, for penalty 926 double sum = 0.0, sum2 = 0.0; // Sum of kernel component 927 float min = INFINITY, max = -INFINITY; // Minimum and maximum kernel value 928 for (int v = kernel->yMin; v <= kernel->yMax; v++) { 929 for (int u = kernel->xMin; u <= kernel->xMax; u++) { 930 double value = kernel->kernel[v][u]; 931 if (false && zeroNull && (u == 0) && (v == 0)) { 932 value += 1.0; 933 } 934 double value2 = PS_SQR(value); 935 sum += value; 936 sum2 += value2; 937 penalty += value2 * PS_SQR((PS_SQR(u) + PS_SQR(v))); 938 min = PS_MIN(value, min); 939 max = PS_MAX(value, max); 940 } 941 } 942 penalty *= 1.0 / sum2; 943 944 if (1) { 945 fprintf(stderr, "min: %lf, max: %lf, moment: %lf, flux^2: %lf\n", min, max, penalty, sum2); 946 // psTrace("psModules.imcombine", 7, "Kernel %d: %f %d %d %f\n", index, fwhm, uOrder, vOrder, penalty); 947 } 948 949 return penalty; 753 950 } 754 951 -
trunk/psModules/src/imcombine/pmSubtractionStamps.h
r26893 r29004 24 24 psArray *flux; ///< Fluxes for possible stamps (or NULL) 25 25 int footprint; ///< Half-size of stamps 26 psKernel *window; ///< window function generated from ensemble of stamps27 26 float normFrac; ///< Fraction of flux in window for normalisation window 28 int normWindow; ///< Size of window for measuring normalisation 27 psKernel *window1; ///< window function generated from ensemble of stamps (input 1) 28 psKernel *window2; ///< window function generated from ensemble of stamps (input 2) 29 float normWindow1; ///< Size of window for measuring normalisation 30 float normWindow2; ///< Size of window for measuring normalisation 29 31 float sysErr; ///< Systematic error 30 32 float skyErr; ///< increase effective readnoise … … 195 197 bool pmSubtractionStampsResetStatus (pmSubtractionStampList *stamps); 196 198 199 200 bool pmSubtractionKernelPenaltiesStamp(pmSubtractionStamp *stamp, pmSubtractionKernels *kernels); 201 bool pmSubtractionKernelPenalties(pmSubtractionStamp *stamp, pmSubtractionKernels *kernels, int index); 202 float pmSubtractionKernelPenaltySingle(psKernel *kernel, bool zeroNull); 203 197 204 #endif -
trunk/psModules/src/imcombine/pmSubtractionVisual.c
r26893 r29004 21 21 22 22 #include "pmVisual.h" 23 #include "pmVisualUtils.h" 23 24 24 25 #include "pmHDU.h" … … 61 62 * @return true for success */ 62 63 bool pmSubtractionVisualPlotConvKernels(psImage *convKernels) { 63 if (!pmVisualIsVisual() || !plotConvKernels) return true; 64 65 if (!pmVisualTestLevel("ppsub.kernels", 1)) return true; 66 67 if (!plotConvKernels) return true; 68 64 69 if (!pmVisualInitWindow(&kapa1, "ppSub:Images")) { 65 70 return false; … … 75 80 @return true for success */ 76 81 bool pmSubtractionVisualPlotStamps(pmSubtractionStampList *stamps, pmReadout *ro) { 77 if (!pmVisualIsVisual() || !plotStamps) return true; 82 83 if (!pmVisualTestLevel("ppsub.stamps", 1)) return true; 84 85 if (!plotStamps) return true; 86 78 87 if (!pmVisualInitWindow (&kapa1, "ppSub:Images")) { 79 88 return false; … … 145 154 bool pmSubtractionVisualPlotLeastSquares (pmSubtractionStampList *stamps, bool dual) { 146 155 147 if (!pmVisualIsVisual() || !plotLeastSquares) return true; 156 if (!pmVisualTestLevel("ppsub.chisq", 1)) return true; 157 158 if (!plotLeastSquares) return true; 159 148 160 if (!pmVisualInitWindow (&kapa1, "PPSub:Images")) { 149 161 return false; … … 204 216 205 217 bool pmSubtractionVisualShowSubtraction(psImage *image, psImage *ref, psImage *sub) { 206 if (!pmVisualIsVisual() || !plotImage) return true; 218 219 if (!pmVisualTestLevel("ppsub.images.sub", 1)) return true; 220 221 if (!plotImage) return true; 222 207 223 if (!pmVisualInitWindow (&kapa1, "PPSub:Images")) { 208 224 return false; … … 218 234 bool pmSubtractionVisualShowKernels(pmSubtractionKernels *kernels) { 219 235 220 if (!pmVisualIsVisual()) return true; 236 if (!pmVisualTestLevel("ppsub.kernels.final", 1)) return true; 237 221 238 if (!pmVisualInitWindow (&kapa1, "PPSub:Images")) { 222 239 return false; … … 264 281 bool pmSubtractionVisualShowBasis(pmSubtractionStampList *stamps) { 265 282 266 if (!pmVisualIsVisual()) return true; 283 if (!pmVisualTestLevel("ppsub.basis", 1)) return true; 284 267 285 if (!pmVisualInitWindow (&kapa2, "ppSub:StampMasterImage")) { 268 286 return false; … … 425 443 bool pmSubtractionVisualShowFitInit(pmSubtractionStampList *stamps) { 426 444 427 if (!pmVisual IsVisual()) return true;445 if (!pmVisualTestLevel("ppsub.fit", 1)) return true; 428 446 429 447 // generate 4 storage images large enough to hold the N stamps: … … 462 480 bool pmSubtractionVisualShowFitAddStamp(psKernel *target, psKernel *source, psKernel *convolution, double background, double norm, int index) { 463 481 464 if (!pmVisual IsVisual()) return true;482 if (!pmVisualTestLevel("ppsub.stamp", 1)) return true; 465 483 466 484 double sum; … … 543 561 } 544 562 545 if (!pmVisualIsVisual()) return true; 563 if (!pmVisualTestLevel("ppsub.fit", 1)) return true; 564 546 565 if (!pmVisualInitWindow(&kapa1, "ppSub:Images")) return false; 547 566 if (!pmVisualInitWindow(&kapa2, "ppSub:Misc")) return false; … … 605 624 Graphdata graphdata; 606 625 607 if (!pmVisualIsVisual()) return true; 626 if (!pmVisualTestLevel("ppsub.fit", 1)) return true; 627 608 628 if (!pmVisualInitWindow(&kapa3, "ppSub:plots")) return false; 609 629 -
trunk/psModules/src/objects/Makefile.am
r28013 r29004 43 43 pmSourceIO_CMF_PS1_V1.c \ 44 44 pmSourceIO_CMF_PS1_V2.c \ 45 pmSourceIO_CMF_PS1_V3.c \ 45 46 pmSourceIO_CMF_PS1_SV1.c \ 46 47 pmSourceIO_CMF_PS1_DV1.c \ 48 pmSourceIO_CMF_PS1_DV2.c \ 47 49 pmSourceIO_MatchedRefs.c \ 48 50 pmSourcePlots.c \ … … 60 62 pmPSFtryFitPSF.c \ 61 63 pmPSFtryMetric.c \ 64 pmPCMdata.c \ 65 pmPCM_MinimizeChisq.c \ 66 pmSourceFitPCM.c \ 62 67 pmTrend2D.c \ 63 68 pmGrowthCurveGenerate.c \ … … 71 76 models/pmModel_QGAUSS.c \ 72 77 models/pmModel_RGAUSS.c \ 73 models/pmModel_SERSIC.c 78 models/pmModel_SERSIC.c \ 79 models/pmModel_EXP.c \ 80 models/pmModel_DEV.c 74 81 75 82 pkginclude_HEADERS = \ … … 80 87 pmPeaks.h \ 81 88 pmMoments.h \ 89 pmModelFuncs.h \ 82 90 pmModel.h \ 83 91 pmModelClass.h \ … … 101 109 pmPSF_IO.h \ 102 110 pmPSFtry.h \ 111 pmPCMdata.h \ 103 112 pmTrend2D.h \ 104 113 pmGrowthCurve.h \ … … 111 120 models/pmModel_QGAUSS.h \ 112 121 models/pmModel_RGAUSS.h \ 113 models/pmModel_SERSIC.h 122 models/pmModel_SERSIC.h \ 123 models/pmModel_EXP.h \ 124 models/pmModel_DEV.h 114 125 115 126 CLEANFILES = *~ -
trunk/psModules/src/objects/models/pmModel_GAUSS.c
r26916 r29004 21 21 #include <stdio.h> 22 22 #include <pslib.h> 23 23 #include "pmHDU.h" 24 #include "pmFPA.h" 25 26 #include "pmTrend2D.h" 27 #include "pmResiduals.h" 28 #include "pmGrowthCurve.h" 29 #include "pmSpan.h" 30 #include "pmFootprintSpans.h" 31 #include "pmFootprint.h" 32 #include "pmPeaks.h" 24 33 #include "pmMoments.h" 25 #include "pmPeaks.h" 34 #include "pmModelFuncs.h" 35 #include "pmModel.h" 36 #include "pmModelUtils.h" 37 #include "pmModelClass.h" 38 #include "pmSourceMasks.h" 39 #include "pmSourceExtendedPars.h" 40 #include "pmSourceDiffStats.h" 26 41 #include "pmSource.h" 27 #include "pmModel.h" 42 #include "pmSourceFitModel.h" 43 #include "pmPSF.h" 44 #include "pmPSFtry.h" 45 #include "pmDetections.h" 46 28 47 #include "pmModel_GAUSS.h" 29 48 49 # define PM_MODEL_NPARAM 7 30 50 # define PM_MODEL_FUNC pmModelFunc_GAUSS 31 51 # define PM_MODEL_FLUX pmModelFlux_GAUSS … … 83 103 dPAR[PM_PAR_XPOS] = q*(2*px/PAR[PM_PAR_SXX] + Y*PAR[PM_PAR_SXY]); 84 104 dPAR[PM_PAR_YPOS] = q*(2*py/PAR[PM_PAR_SYY] + X*PAR[PM_PAR_SXY]); 105 85 106 // the extra factor of 2 below is needed to avoid excessive swings 86 107 dPAR[PM_PAR_SXX] = +4.0*q*px*px/PAR[PM_PAR_SXX]; … … 102 123 return true; 103 124 } 104 psAssert(nParam >= 0 && nParam < = PM_PAR_7, "Parameter index is out of bounds");125 psAssert(nParam >= 0 && nParam < PM_MODEL_NPARAM, "Parameter index is out of bounds"); 105 126 106 127 // we need to calculate the limits for SXY specially … … 347 368 // this test is invalid if the parameters are derived 348 369 // from the PSF model 370 // XXX how is this used? it prevents forced photometry from ever being 'successful' 349 371 bool PM_MODEL_FIT_STATUS (pmModel *model) 350 372 { … … 394 416 return; 395 417 } 396 397 # undef PM_MODEL_FUNC398 # undef PM_MODEL_FLUX399 # undef PM_MODEL_GUESS400 # undef PM_MODEL_LIMITS401 # undef PM_MODEL_RADIUS402 # undef PM_MODEL_FROM_PSF403 # undef PM_MODEL_PARAMS_FROM_PSF404 # undef PM_MODEL_FIT_STATUS405 # undef PM_MODEL_SET_LIMITS -
trunk/psModules/src/objects/models/pmModel_PGAUSS.c
r27565 r29004 21 21 #include <stdio.h> 22 22 #include <pslib.h> 23 23 #include "pmHDU.h" 24 #include "pmFPA.h" 25 26 #include "pmTrend2D.h" 27 #include "pmResiduals.h" 28 #include "pmGrowthCurve.h" 29 #include "pmSpan.h" 30 #include "pmFootprintSpans.h" 31 #include "pmFootprint.h" 32 #include "pmPeaks.h" 24 33 #include "pmMoments.h" 25 #include "pmPeaks.h" 34 #include "pmModelFuncs.h" 35 #include "pmModel.h" 36 #include "pmModelUtils.h" 37 #include "pmModelClass.h" 38 #include "pmSourceMasks.h" 39 #include "pmSourceExtendedPars.h" 40 #include "pmSourceDiffStats.h" 26 41 #include "pmSource.h" 27 #include "pmModel.h" 42 #include "pmSourceFitModel.h" 43 #include "pmPSF.h" 44 #include "pmPSFtry.h" 45 #include "pmDetections.h" 46 28 47 #include "pmModel_PGAUSS.h" 29 48 49 # define PM_MODEL_NPARAM 7 30 50 # define PM_MODEL_FUNC pmModelFunc_PGAUSS 31 51 # define PM_MODEL_FLUX pmModelFlux_PGAUSS … … 103 123 return true; 104 124 } 105 psAssert(nParam >= 0 && nParam < = PM_PAR_7, "Parameter index is out of bounds");125 psAssert(nParam >= 0 && nParam < PM_MODEL_NPARAM, "Parameter index is out of bounds"); 106 126 107 127 // we need to calculate the limits for SXY specially … … 448 468 return; 449 469 } 450 451 # undef PM_MODEL_FUNC452 # undef PM_MODEL_FLUX453 # undef PM_MODEL_GUESS454 # undef PM_MODEL_LIMITS455 # undef PM_MODEL_RADIUS456 # undef PM_MODEL_FROM_PSF457 # undef PM_MODEL_PARAMS_FROM_PSF458 # undef PM_MODEL_FIT_STATUS459 # undef PM_MODEL_SET_LIMITS -
trunk/psModules/src/objects/models/pmModel_PS1_V1.c
r27565 r29004 22 22 #include <stdio.h> 23 23 #include <pslib.h> 24 24 #include "pmHDU.h" 25 #include "pmFPA.h" 26 27 #include "pmTrend2D.h" 28 #include "pmResiduals.h" 29 #include "pmGrowthCurve.h" 30 #include "pmSpan.h" 31 #include "pmFootprintSpans.h" 32 #include "pmFootprint.h" 33 #include "pmPeaks.h" 25 34 #include "pmMoments.h" 26 #include "pmPeaks.h" 35 #include "pmModelFuncs.h" 36 #include "pmModel.h" 37 #include "pmModelUtils.h" 38 #include "pmModelClass.h" 39 #include "pmSourceMasks.h" 40 #include "pmSourceExtendedPars.h" 41 #include "pmSourceDiffStats.h" 27 42 #include "pmSource.h" 28 #include "pmModel.h" 43 #include "pmSourceFitModel.h" 44 #include "pmPSF.h" 45 #include "pmPSFtry.h" 46 #include "pmDetections.h" 47 29 48 #include "pmModel_PS1_V1.h" 30 49 50 # define PM_MODEL_NPARAM 8 31 51 # define PM_MODEL_FUNC pmModelFunc_PS1_V1 32 52 # define PM_MODEL_FLUX pmModelFlux_PS1_V1 … … 122 142 return true; 123 143 } 124 psAssert(nParam >= 0 && nParam < = PM_PAR_7, "Parameter index is out of bounds");144 psAssert(nParam >= 0 && nParam < PM_MODEL_NPARAM, "Parameter index is out of bounds"); 125 145 126 146 // we need to calculate the limits for SXY specially … … 222 242 PAR[PM_PAR_SYY] = PS_MAX(0.5, M_SQRT2*shape.sy); 223 243 PAR[PM_PAR_SXY] = shape.sxy; 224 PAR[PM_PAR_7] = 1.0;244 PAR[PM_PAR_7] = 0.5; 225 245 226 246 return(true); … … 468 488 return; 469 489 } 470 471 # undef PM_MODEL_FUNC472 # undef PM_MODEL_FLUX473 # undef PM_MODEL_GUESS474 # undef PM_MODEL_LIMITS475 # undef PM_MODEL_RADIUS476 # undef PM_MODEL_FROM_PSF477 # undef PM_MODEL_PARAMS_FROM_PSF478 # undef PM_MODEL_FIT_STATUS479 # undef PM_MODEL_SET_LIMITS480 # undef ALPHA481 # undef ALPHA_M -
trunk/psModules/src/objects/models/pmModel_QGAUSS.c
r27565 r29004 22 22 #include <stdio.h> 23 23 #include <pslib.h> 24 24 #include "pmHDU.h" 25 #include "pmFPA.h" 26 27 #include "pmTrend2D.h" 28 #include "pmResiduals.h" 29 #include "pmGrowthCurve.h" 30 #include "pmSpan.h" 31 #include "pmFootprintSpans.h" 32 #include "pmFootprint.h" 33 #include "pmPeaks.h" 25 34 #include "pmMoments.h" 26 #include "pmPeaks.h" 35 #include "pmModelFuncs.h" 36 #include "pmModel.h" 37 #include "pmModelUtils.h" 38 #include "pmModelClass.h" 39 #include "pmSourceMasks.h" 40 #include "pmSourceExtendedPars.h" 41 #include "pmSourceDiffStats.h" 27 42 #include "pmSource.h" 28 #include "pmModel.h" 43 #include "pmSourceFitModel.h" 44 #include "pmPSF.h" 45 #include "pmPSFtry.h" 46 #include "pmDetections.h" 47 29 48 #include "pmModel_QGAUSS.h" 30 49 50 # define PM_MODEL_NPARAM 8 31 51 # define PM_MODEL_FUNC pmModelFunc_QGAUSS 32 52 # define PM_MODEL_FLUX pmModelFlux_QGAUSS … … 123 143 return true; 124 144 } 125 psAssert(nParam >= 0 && nParam < = PM_PAR_7, "Parameter index is out of bounds");145 psAssert(nParam >= 0 && nParam < PM_MODEL_NPARAM, "Parameter index is out of bounds"); 126 146 127 147 // we need to calculate the limits for SXY specially … … 469 489 return; 470 490 } 471 472 # undef PM_MODEL_FUNC473 # undef PM_MODEL_FLUX474 # undef PM_MODEL_GUESS475 # undef PM_MODEL_LIMITS476 # undef PM_MODEL_RADIUS477 # undef PM_MODEL_FROM_PSF478 # undef PM_MODEL_PARAMS_FROM_PSF479 # undef PM_MODEL_FIT_STATUS480 # undef PM_MODEL_SET_LIMITS481 # undef ALPHA482 # undef ALPHA_M -
trunk/psModules/src/objects/models/pmModel_RGAUSS.c
r27565 r29004 22 22 #include <stdio.h> 23 23 #include <pslib.h> 24 24 #include "pmHDU.h" 25 #include "pmFPA.h" 26 27 #include "pmTrend2D.h" 28 #include "pmResiduals.h" 29 #include "pmGrowthCurve.h" 30 #include "pmSpan.h" 31 #include "pmFootprintSpans.h" 32 #include "pmFootprint.h" 33 #include "pmPeaks.h" 25 34 #include "pmMoments.h" 26 #include "pmPeaks.h" 35 #include "pmModelFuncs.h" 36 #include "pmModel.h" 37 #include "pmModelUtils.h" 38 #include "pmModelClass.h" 39 #include "pmSourceMasks.h" 40 #include "pmSourceExtendedPars.h" 41 #include "pmSourceDiffStats.h" 27 42 #include "pmSource.h" 28 #include "pmModel.h" 43 #include "pmSourceFitModel.h" 44 #include "pmPSF.h" 45 #include "pmPSFtry.h" 46 #include "pmDetections.h" 47 29 48 #include "pmModel_RGAUSS.h" 30 49 50 # define PM_MODEL_NPARAM 8 31 51 # define PM_MODEL_FUNC pmModelFunc_RGAUSS 32 52 # define PM_MODEL_FLUX pmModelFlux_RGAUSS … … 112 132 return true; 113 133 } 114 psAssert(nParam >= 0 && nParam < = PM_PAR_7, "Parameter index is out of bounds");134 psAssert(nParam >= 0 && nParam < PM_MODEL_NPARAM, "Parameter index is out of bounds"); 115 135 116 136 // we need to calculate the limits for SXY specially … … 209 229 PAR[PM_PAR_XPOS] = peak->xf; 210 230 PAR[PM_PAR_YPOS] = peak->yf; 211 PAR[PM_PAR_SXX] = PS_MAX(0.5, M_SQRT2*shape.sx);212 PAR[PM_PAR_SYY] = PS_MAX(0.5, M_SQRT2*shape.sy);231 PAR[PM_PAR_SXX] = PS_MAX(0.5, shape.sx); 232 PAR[PM_PAR_SYY] = PS_MAX(0.5, shape.sy); 213 233 PAR[PM_PAR_SXY] = shape.sxy; 214 PAR[PM_PAR_7] = 2.25;234 PAR[PM_PAR_7] = 1.5; 215 235 216 236 return(true); … … 463 483 return; 464 484 } 465 466 # undef PM_MODEL_FUNC467 # undef PM_MODEL_FLUX468 # undef PM_MODEL_GUESS469 # undef PM_MODEL_LIMITS470 # undef PM_MODEL_RADIUS471 # undef PM_MODEL_FROM_PSF472 # undef PM_MODEL_PARAMS_FROM_PSF473 # undef PM_MODEL_FIT_STATUS474 # undef PM_MODEL_SET_LIMITS -
trunk/psModules/src/objects/models/pmModel_SERSIC.c
r26916 r29004 18 18 * PM_PAR_7 7 - normalized sersic parameter 19 19 20 note that a standard sersic model uses exp(-K*(z^(1/ n) - 1). the additional elements (K,20 note that a standard sersic model uses exp(-K*(z^(1/2n) - 1). the additional elements (K, 21 21 the -1 offset) are absorbed in this model by the normalization, the exponent, and the 22 22 radial scale. We fit the elements in this form, then re-normalize them on output. … … 25 25 #include <stdio.h> 26 26 #include <pslib.h> 27 27 #include "pmHDU.h" 28 #include "pmFPA.h" 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 35 #include "pmFootprint.h" 36 #include "pmPeaks.h" 28 37 #include "pmMoments.h" 29 #include "pmPeaks.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 30 45 #include "pmSource.h" 31 #include "pmModel.h" 46 #include "pmSourceFitModel.h" 47 #include "pmPSF.h" 48 #include "pmPSFtry.h" 49 #include "pmDetections.h" 50 32 51 #include "pmModel_SERSIC.h" 33 52 53 # define PM_MODEL_NPARAM 8 34 54 # define PM_MODEL_FUNC pmModelFunc_SERSIC 35 55 # define PM_MODEL_FLUX pmModelFlux_SERSIC … … 47 67 48 68 // Lax parameter limits 49 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.0 5, 0.05, -1.0, 0.05 };69 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.001, 0.001, -1.0, 0.05 }; 50 70 static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 4.0 }; 51 71 … … 84 104 assert (z >= 0); 85 105 86 psF32 f2 = pow(z,PAR[PM_PAR_7]); 87 psF32 f1 = exp(-f2); 106 float index = 0.5 / PAR[PM_PAR_7]; 107 float bn = 1.9992*index - 0.3271; 108 float Io = exp(bn); 109 110 psF32 f2 = bn*pow(z,PAR[PM_PAR_7]); 111 psF32 f1 = Io*exp(-f2); 88 112 psF32 z0 = PAR[PM_PAR_I0]*f1; 89 113 psF32 f0 = PAR[PM_PAR_SKY] + z0; … … 98 122 99 123 // gradient is infinite for z = 0; saturate at z = 0.01 100 psF32 z1 = (z < 0.01) ? z0* PAR[PM_PAR_7]*pow(0.01,PAR[PM_PAR_7] - 1.0) : z0*PAR[PM_PAR_7]*pow(z,PAR[PM_PAR_7] - 1.0);124 psF32 z1 = (z < 0.01) ? z0*bn*PAR[PM_PAR_7]*pow(0.01,PAR[PM_PAR_7] - 1.0) : z0*bn*PAR[PM_PAR_7]*pow(z,PAR[PM_PAR_7] - 1.0); 101 125 102 126 dPAR[PM_PAR_SKY] = +1.0; 103 127 dPAR[PM_PAR_I0] = +f1; 104 dPAR[PM_PAR_7] = (z == 0.0) ? 0.0 : -z0*f2*log(z); 128 dPAR[PM_PAR_7] = (z < 0.01) ? -z0*pow(0.01,PAR[PM_PAR_7])*log(0.01) : -z0*f2*log(z); 129 dPAR[PM_PAR_7] *= 3.0; 105 130 106 131 assert (isfinite(z1)); … … 109 134 dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0*px/PAR[PM_PAR_SXX] + Y*PAR[PM_PAR_SXY]); 110 135 dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0*py/PAR[PM_PAR_SYY] + X*PAR[PM_PAR_SXY]); 111 dPAR[PM_PAR_SXX] = +2.0*z1*px*px/PAR[PM_PAR_SXX]; 136 dPAR[PM_PAR_SXX] = +2.0*z1*px*px/PAR[PM_PAR_SXX]; // XXX : increase drag? 112 137 dPAR[PM_PAR_SYY] = +2.0*z1*py*py/PAR[PM_PAR_SYY]; 113 dPAR[PM_PAR_SXY] = -1.0*z1*X*Y;114 138 dPAR[PM_PAR_SXY] = -1.0*z1*X*Y; 115 139 } … … 127 151 return true; 128 152 } 129 psAssert(nParam >= 0 && nParam < = PM_PAR_7, "Parameter index is out of bounds");153 psAssert(nParam >= 0 && nParam < PM_MODEL_NPARAM, "Parameter index is out of bounds"); 130 154 131 155 // we need to calculate the limits for SXY specially … … 201 225 psF32 *PAR = model->params->data.F32; 202 226 227 // the other parameters depend on the guess for PAR_7 228 if (!isfinite(PAR[PM_PAR_7])) { 229 PAR[PM_PAR_7] = 0.25; 230 } 231 float index = 0.5 / PAR[PM_PAR_7]; 232 233 // the scale-length is a function of the moments and the index: 234 // Rmajor_guess = Rmajor_moments * Scale * Zero 235 float Scale = 0.70 + 0.053 * PAR[PM_PAR_7]; 236 float Zero = 1.16 - 0.615 * PAR[PM_PAR_7]; 237 203 238 psEllipseMoments emoments; 204 239 emoments.x2 = moments->Mxx; … … 213 248 if (!isfinite(axes.theta)) return false; 214 249 250 // set a lower limit to avoid absurd solutions.. 251 float Rmajor = PS_MAX(1.0, Scale * axes.major + Zero); 252 float Rminor = Rmajor * (axes.minor / axes.major); 253 254 fprintf (stderr, "guess index: %f : %f, %f -> %f, %f\n", index, axes.major, axes.minor, Rmajor, Rminor); 255 256 axes.major = Rmajor; 257 axes.minor = Rminor; 215 258 psEllipseShape shape = psEllipseAxesToShape (axes); 216 259 … … 219 262 if (!isfinite(shape.sxy)) return false; 220 263 264 float bn = 1.9992*index - 0.3271; 265 // float fR = 1.0 / (sqrt(2.0) * pow (bn, index)); 266 float Io = exp(0.5*bn); 267 268 // XXX do we need this factor of sqrt(2)? 269 // float Sxx = PS_MAX(0.5, M_SQRT2*shape.sx); 270 // float Syy = PS_MAX(0.5, M_SQRT2*shape.sy); 271 272 float Sxx = PS_MAX(0.5, shape.sx); 273 float Syy = PS_MAX(0.5, shape.sy); 274 221 275 PAR[PM_PAR_SKY] = 0.0; 222 PAR[PM_PAR_I0] = peak->flux ;276 PAR[PM_PAR_I0] = peak->flux / Io; 223 277 PAR[PM_PAR_XPOS] = peak->xf; 224 278 PAR[PM_PAR_YPOS] = peak->yf; 225 PAR[PM_PAR_SXX] = PS_MAX(0.5, M_SQRT2*shape.sx);226 PAR[PM_PAR_SYY] = PS_MAX(0.5, M_SQRT2*shape.sy);279 PAR[PM_PAR_SXX] = Sxx; 280 PAR[PM_PAR_SYY] = Syy; 227 281 PAR[PM_PAR_SXY] = shape.sxy; 228 PAR[PM_PAR_7] = 0.5;229 282 230 283 return(true); … … 254 307 float f1, f2; 255 308 for (z = DZ; z < 50; z += DZ) { 256 f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25)); 309 // f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25)); 310 f1 = exp(-pow(z,PAR[PM_PAR_7])); 257 311 z += DZ; 258 f2 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25));312 f2 = exp(-pow(z,PAR[PM_PAR_7])); 259 313 norm += f0 + 4*f1 + f2; 260 314 f0 = f2; … … 287 341 288 342 psEllipseAxes axes = psEllipseShapeToAxes (shape, 20.0); 289 psF64 sigma = axes.major; 290 291 psF64 limit = flux / PAR[PM_PAR_I0]; 292 293 psF64 z = pow (-log(limit), (1.0 / PAR[PM_PAR_7])); 294 psAssert (isfinite(z), "fix this code: z should not be nan for %f", PAR[PM_PAR_7]); 295 296 psF64 radius = sigma * sqrt (2.0 * z); 297 psAssert (isfinite(radius), "fix this code: radius should not be nan for %f, %f", PAR[PM_PAR_7], sigma); 298 299 if (isnan(radius)) 300 psAbort("error in code: radius is NaN"); 301 343 344 // f = Io exp(-z^n) -> z^n = ln(Io/f) 345 psF64 zn = log(PAR[PM_PAR_I0] / flux); 346 psF64 radius = axes.major * sqrt (2.0) * pow(zn, 0.5 / PAR[PM_PAR_7]); 347 348 fprintf (stderr, "sersic model %f %f, n %f, radius: %f, zn: %f, f/Io: %f, major: %f\n", PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], PAR[PM_PAR_7], radius, zn, flux/PAR[PM_PAR_I0], axes.major); 349 350 psAssert (isfinite(radius), "fix this code: z should not be nan for %f", PAR[PM_PAR_7]); 302 351 return (radius); 303 352 } … … 448 497 return; 449 498 } 450 451 # undef PM_MODEL_FUNC452 # undef PM_MODEL_FLUX453 # undef PM_MODEL_GUESS454 # undef PM_MODEL_LIMITS455 # undef PM_MODEL_RADIUS456 # undef PM_MODEL_FROM_PSF457 # undef PM_MODEL_PARAMS_FROM_PSF458 # undef PM_MODEL_FIT_STATUS459 # undef PM_MODEL_SET_LIMITS -
trunk/psModules/src/objects/pmDetEff.c
r25477 r29004 3 3 #endif 4 4 5 #include <string.h> 5 6 #include <pslib.h> 7 #include "pmHDU.h" 8 #include "pmFPA.h" 6 9 10 #include "pmTrend2D.h" 11 #include "pmResiduals.h" 12 #include "pmGrowthCurve.h" 13 #include "pmSpan.h" 14 #include "pmFootprintSpans.h" 15 #include "pmFootprint.h" 16 #include "pmPeaks.h" 17 #include "pmMoments.h" 18 #include "pmModelFuncs.h" 19 #include "pmModel.h" 20 #include "pmModelUtils.h" 21 #include "pmModelClass.h" 22 #include "pmSourceMasks.h" 23 #include "pmSourceExtendedPars.h" 24 #include "pmSourceDiffStats.h" 25 #include "pmSource.h" 26 #include "pmSourceFitModel.h" 27 #include "pmPSF.h" 28 #include "pmPSFtry.h" 29 #include "pmDetections.h" 7 30 #include "pmDetEff.h" 8 9 31 10 32 static void detEffFree(pmDetEff *de) -
trunk/psModules/src/objects/pmDetEff.h
r25383 r29004 1 1 #ifndef PM_DET_EFF_H 2 2 #define PM_DET_EFF_H 3 4 #include <pslib.h>5 #include <string.h>6 7 #include "pmFPA.h"8 3 9 4 #define PM_DETEFF_ANALYSIS "DETEFF" // Location of detection efficiency on pmReadout.analysis -
trunk/psModules/src/objects/pmFootprint.c
r27672 r29004 19 19 #include <pslib.h> 20 20 #include "pmSpan.h" 21 #include "pmFootprintSpans.h" 21 22 #include "pmFootprint.h" 22 23 #include "pmPeaks.h" -
trunk/psModules/src/objects/pmFootprint.h
r27672 r29004 10 10 #ifndef PM_FOOTPRINT_H 11 11 #define PM_FOOTPRINT_H 12 13 #include <pslib.h>14 #include "pmSpan.h"15 #include "pmFootprintSpans.h"16 12 17 13 typedef struct { -
trunk/psModules/src/objects/pmFootprintArrayGrow.c
r21183 r29004 18 18 #include <pslib.h> 19 19 #include "pmSpan.h" 20 #include "pmFootprintSpans.h" 20 21 #include "pmFootprint.h" 21 22 #include "pmPeaks.h" -
trunk/psModules/src/objects/pmFootprintArraysMerge.c
r24274 r29004 18 18 #include <pslib.h> 19 19 #include "pmSpan.h" 20 #include "pmFootprintSpans.h" 20 21 #include "pmFootprint.h" 21 22 #include "pmPeaks.h" -
trunk/psModules/src/objects/pmFootprintAssignPeaks.c
r20937 r29004 18 18 #include <pslib.h> 19 19 #include "pmSpan.h" 20 #include "pmFootprintSpans.h" 20 21 #include "pmFootprint.h" 21 22 #include "pmPeaks.h" -
trunk/psModules/src/objects/pmFootprintCullPeaks.c
r27672 r29004 19 19 #include <pslib.h> 20 20 #include "pmSpan.h" 21 #include "pmFootprintSpans.h" 21 22 #include "pmFootprint.h" 22 #include "pmFootprintSpans.h"23 23 #include "pmPeaks.h" 24 24 -
trunk/psModules/src/objects/pmFootprintFind.c
r20937 r29004 19 19 #include <pslib.h> 20 20 #include "pmSpan.h" 21 #include "pmFootprintSpans.h" 21 22 #include "pmFootprint.h" 22 23 #include "pmPeaks.h" -
trunk/psModules/src/objects/pmFootprintFindAtPoint.c
r27672 r29004 19 19 #include <pslib.h> 20 20 #include "pmSpan.h" 21 #include "pmFootprintSpans.h" 21 22 #include "pmFootprint.h" 22 23 #include "pmPeaks.h" 23 #include "pmFootprintSpans.h"24 24 25 25 /************************************************************************************************************/ -
trunk/psModules/src/objects/pmFootprintIDs.c
r27672 r29004 19 19 #include <pslib.h> 20 20 #include "pmSpan.h" 21 #include "pmFootprintSpans.h" 21 22 #include "pmFootprint.h" 22 23 #include "pmPeaks.h" -
trunk/psModules/src/objects/pmFootprintSpans.c
r27672 r29004 19 19 #include <pslib.h> 20 20 #include "pmSpan.h" 21 #include "pmFootprintSpans.h" 21 22 #include "pmFootprint.h" 22 23 #include "pmPeaks.h" 23 #include "pmFootprintSpans.h"24 24 25 25 static void pmStartSpanFree(pmStartSpan *sspan) { -
trunk/psModules/src/objects/pmFootprintSpans.h
r27672 r29004 10 10 #ifndef PM_FOOTPRINT_SPANS_H 11 11 #define PM_FOOTPRINT_SPANS_H 12 13 #include <pslib.h>14 #include "pmSpan.h"15 12 16 13 /* We define two helper structures used in building the pmFootprints: -
trunk/psModules/src/objects/pmGrowthCurve.c
r20937 r29004 20 20 #include "pmHDU.h" 21 21 #include "pmFPA.h" 22 23 #include "pmTrend2D.h" 24 #include "pmResiduals.h" 25 #include "pmGrowthCurve.h" 22 26 #include "pmSpan.h" 27 #include "pmFootprintSpans.h" 23 28 #include "pmFootprint.h" 24 29 #include "pmPeaks.h" 25 30 #include "pmMoments.h" 26 #include "pmResiduals.h" 27 #include "pmGrowthCurve.h" 28 #include "pmTrend2D.h" 31 #include "pmModelFuncs.h" 32 #include "pmModel.h" 33 #include "pmModelUtils.h" 34 #include "pmModelClass.h" 35 #include "pmSourceMasks.h" 36 #include "pmSourceExtendedPars.h" 37 #include "pmSourceDiffStats.h" 38 #include "pmSource.h" 39 #include "pmSourceFitModel.h" 29 40 #include "pmPSF.h" 30 #include "pmModel.h" 31 #include "pmSource.h" 41 #include "pmPSFtry.h" 42 #include "pmDetections.h" 43 32 44 #include "psVectorBracket.h" 33 45 -
trunk/psModules/src/objects/pmGrowthCurveGenerate.c
r27531 r29004 24 24 #include "pmHDU.h" 25 25 #include "pmFPA.h" 26 #include "pmFPAMaskWeight.h" 27 #include "psVectorBracket.h" 28 #include "pmErrorCodes.h" 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 26 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 27 35 #include "pmFootprint.h" 28 36 #include "pmPeaks.h" 29 37 #include "pmMoments.h" 30 #include "pmResiduals.h" 31 #include "pmGrowthCurve.h" 32 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 33 47 #include "pmPSF.h" 34 #include "pmModel.h" 35 #include "pmSource.h" 36 #include "pmModelClass.h" 37 #include "pmModelUtils.h" 48 #include "pmPSFtry.h" 49 #include "pmDetections.h" 50 38 51 #include "pmSourcePhotometry.h" 39 #include "pmFPAMaskWeight.h"40 #include "psVectorBracket.h"41 #include "pmErrorCodes.h"42 52 43 53 pmGrowthCurve *pmGrowthCurveForPosition (psImage *image, pmPSF *psf, bool ignore, psImageMaskType maskVal, psImageMaskType markVal, float xc, float yc); -
trunk/psModules/src/objects/pmModel.c
r25754 r29004 23 23 #include "pmHDU.h" 24 24 #include "pmFPA.h" 25 26 #include "pmTrend2D.h" 25 27 #include "pmResiduals.h" 26 28 #include "pmGrowthCurve.h" 27 #include "pmTrend2D.h" 28 #include "pmPSF.h" 29 #include "pmSpan.h" 30 #include "pmFootprintSpans.h" 31 #include "pmFootprint.h" 32 #include "pmPeaks.h" 33 #include "pmMoments.h" 34 #include "pmModelFuncs.h" 29 35 #include "pmModel.h" 30 36 #include "pmModelClass.h" … … 75 81 76 82 for (psS32 i = 0; i < tmp->params->n; i++) { 77 tmp->params->data.F32[i] = 0.0;78 tmp->dparams->data.F32[i] = 0.0;83 tmp->params->data.F32[i] = NAN; 84 tmp->dparams->data.F32[i] = NAN; 79 85 } 80 86 -
trunk/psModules/src/objects/pmModel.h
r26916 r29004 14 14 # define PM_MODEL_H 15 15 16 #include <pslib.h>17 #include "pmPSF.h"18 19 16 /// @addtogroup Objects Object Detection / Analysis Functions 20 17 /// @{ … … 22 19 /* pointers for the functions types below are supplied to each pmModel, and can be used by 23 20 the programmer without needing to know the model class */ 24 25 typedef enum {26 PM_MODEL_STATUS_NONE = 0x00, ///< model fit not yet attempted, no other info27 PM_MODEL_STATUS_FITTED = 0x01, ///< model fit completed28 PM_MODEL_STATUS_NONCONVERGE = 0x02, ///< model fit did not converge29 PM_MODEL_STATUS_OFFIMAGE = 0x04, ///< model fit drove out of range30 PM_MODEL_STATUS_BADARGS = 0x08, ///< model fit called with invalid args31 PM_MODEL_STATUS_LIMITS = 0x10 ///< model parameters hit limits32 } pmModelStatus;33 34 typedef enum {35 PM_MODEL_OP_NONE = 0x00,36 PM_MODEL_OP_FUNC = 0x01,37 PM_MODEL_OP_RES0 = 0x02,38 PM_MODEL_OP_RES1 = 0x04,39 PM_MODEL_OP_FULL = 0x07,40 PM_MODEL_OP_SKY = 0x08,41 PM_MODEL_OP_CENTER = 0x10,42 PM_MODEL_OP_NORM = 0x20,43 PM_MODEL_OP_NOISE = 0x40,44 } pmModelOpMode;45 46 /// Parameter limit types47 typedef enum {48 PM_MODEL_LIMITS_NONE, ///< Apply no limits: suitable for debugging49 PM_MODEL_LIMITS_IGNORE, ///< Ignore all limits: fit can go to town50 PM_MODEL_LIMITS_LAX, ///< Lax limits: attempting to reproduce even bad data51 PM_MODEL_LIMITS_MODERATE, ///< Moderate limits: cope with mildly bad data52 PM_MODEL_LIMITS_STRICT, ///< Strict limits: insist on good quality data53 } pmModelLimitsType;54 55 typedef struct pmModel pmModel;56 typedef struct pmSource pmSource;57 58 // This function is the model chi-square minimization function for this model.59 typedef psMinimizeLMChi2Func pmModelFunc;60 61 // This function sets the parameter limits for this model.62 typedef psMinimizeLMLimitFunc pmModelLimits;63 64 // This function returns the integrated flux for the given model parameters.65 typedef psF64 (*pmModelFlux)(const psVector *params);66 67 // This function returns the radius at which the given model and parameters68 // achieves the given flux.69 typedef psF64 (*pmModelRadius)(const psVector *params, double flux);70 71 // This function provides the model guess parameters based on the details of72 // the given source.73 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source);74 75 // This function constructs the PSF model for the given source based on the76 // supplied psf and the EXT model for the object.77 typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, const pmPSF *psf);78 79 // This function sets the model parameters based on the PSF for a given coordinate and central80 // intensity81 typedef bool (*pmModelParamsFromPSF)(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);82 83 // This function returns the success / failure status of the given model fit84 typedef bool (*pmModelFitStatusFunc)(pmModel *model);85 86 // This function sets the parameter limits for the given model87 typedef bool (*pmModelSetLimitsFunc)(pmModelLimitsType type);88 21 89 22 /** pmModel data structure … … 122 55 pmModelSetLimitsFunc modelSetLimits; 123 56 }; 124 125 /** Symbolic names for the elements of [d]params126 * Note: these are #defines not enums as a given element of [d]params127 * may/will correspond to different parameters in different contexts128 */129 #define PM_PAR_SKY 0 ///< Sky130 #define PM_PAR_I0 1 ///< Central intensity131 #define PM_PAR_XPOS 2 ///< X centre of object132 #define PM_PAR_YPOS 3 ///< Y centre of object133 #define PM_PAR_SXX 4 ///< shape X^2 moment134 #define PM_PAR_SYY 5 ///< shape Y^2 moment135 #define PM_PAR_SXY 6 ///< shape XY moment136 #define PM_PAR_7 7 ///< ??? Unknown parameter137 #define PM_PAR_8 8 ///< ??? Unknown parameter138 57 139 58 /** pmModelAlloc() -
trunk/psModules/src/objects/pmModelClass.c
r25754 r29004 23 23 #include "pmHDU.h" 24 24 #include "pmFPA.h" 25 26 #include "pmTrend2D.h" 27 #include "pmResiduals.h" 28 #include "pmGrowthCurve.h" 25 29 #include "pmSpan.h" 30 #include "pmFootprintSpans.h" 26 31 #include "pmFootprint.h" 27 32 #include "pmPeaks.h" 28 33 #include "pmMoments.h" 29 #include "pmResiduals.h" 30 #include "pmGrowthCurve.h" 31 #include "pmTrend2D.h" 32 #include "pmPSF.h" 34 #include "pmModelFuncs.h" 33 35 #include "pmModel.h" 34 #include "pm Source.h"36 #include "pmModelUtils.h" 35 37 #include "pmModelClass.h" 38 36 39 #include "pmErrorCodes.h" 37 40 … … 46 49 # include "models/pmModel_RGAUSS.h" 47 50 # include "models/pmModel_SERSIC.h" 51 # include "models/pmModel_EXP.h" 52 # include "models/pmModel_DEV.h" 48 53 49 54 static pmModelClass defaultModels[] = { … … 53 58 {"PS_MODEL_PS1_V1", 8, (pmModelFunc)pmModelFunc_PS1_V1, (pmModelFlux)pmModelFlux_PS1_V1, (pmModelRadius)pmModelRadius_PS1_V1, (pmModelLimits)pmModelLimits_PS1_V1, (pmModelGuessFunc)pmModelGuess_PS1_V1, (pmModelFromPSFFunc)pmModelFromPSF_PS1_V1, (pmModelParamsFromPSF)pmModelParamsFromPSF_PS1_V1, (pmModelFitStatusFunc)pmModelFitStatus_PS1_V1, (pmModelSetLimitsFunc)pmModelSetLimits_PS1_V1 }, 54 59 {"PS_MODEL_RGAUSS", 8, (pmModelFunc)pmModelFunc_RGAUSS, (pmModelFlux)pmModelFlux_RGAUSS, (pmModelRadius)pmModelRadius_RGAUSS, (pmModelLimits)pmModelLimits_RGAUSS, (pmModelGuessFunc)pmModelGuess_RGAUSS, (pmModelFromPSFFunc)pmModelFromPSF_RGAUSS, (pmModelParamsFromPSF)pmModelParamsFromPSF_RGAUSS, (pmModelFitStatusFunc)pmModelFitStatus_RGAUSS, (pmModelSetLimitsFunc)pmModelSetLimits_RGAUSS }, 55 {"PS_MODEL_SERSIC", 8, (pmModelFunc)pmModelFunc_SERSIC, (pmModelFlux)pmModelFlux_SERSIC, (pmModelRadius)pmModelRadius_SERSIC, (pmModelLimits)pmModelLimits_SERSIC, (pmModelGuessFunc)pmModelGuess_SERSIC, (pmModelFromPSFFunc)pmModelFromPSF_SERSIC, (pmModelParamsFromPSF)pmModelParamsFromPSF_SERSIC, (pmModelFitStatusFunc)pmModelFitStatus_SERSIC, (pmModelSetLimitsFunc)pmModelSetLimits_SERSIC } 60 {"PS_MODEL_SERSIC", 8, (pmModelFunc)pmModelFunc_SERSIC, (pmModelFlux)pmModelFlux_SERSIC, (pmModelRadius)pmModelRadius_SERSIC, (pmModelLimits)pmModelLimits_SERSIC, (pmModelGuessFunc)pmModelGuess_SERSIC, (pmModelFromPSFFunc)pmModelFromPSF_SERSIC, (pmModelParamsFromPSF)pmModelParamsFromPSF_SERSIC, (pmModelFitStatusFunc)pmModelFitStatus_SERSIC, (pmModelSetLimitsFunc)pmModelSetLimits_SERSIC }, 61 {"PS_MODEL_EXP", 7, (pmModelFunc)pmModelFunc_EXP, (pmModelFlux)pmModelFlux_EXP, (pmModelRadius)pmModelRadius_EXP, (pmModelLimits)pmModelLimits_EXP, (pmModelGuessFunc)pmModelGuess_EXP, (pmModelFromPSFFunc)pmModelFromPSF_EXP, (pmModelParamsFromPSF)pmModelParamsFromPSF_EXP, (pmModelFitStatusFunc)pmModelFitStatus_EXP, (pmModelSetLimitsFunc)pmModelSetLimits_EXP }, 62 {"PS_MODEL_DEV", 7, (pmModelFunc)pmModelFunc_DEV, (pmModelFlux)pmModelFlux_DEV, (pmModelRadius)pmModelRadius_DEV, (pmModelLimits)pmModelLimits_DEV, (pmModelGuessFunc)pmModelGuess_DEV, (pmModelFromPSFFunc)pmModelFromPSF_DEV, (pmModelParamsFromPSF)pmModelParamsFromPSF_DEV, (pmModelFitStatusFunc)pmModelFitStatus_DEV, (pmModelSetLimitsFunc)pmModelSetLimits_DEV }, 56 63 }; 57 64 -
trunk/psModules/src/objects/pmModelClass.h
r25738 r29004 28 28 # ifndef PM_MODEL_CLASS_H 29 29 # define PM_MODEL_CLASS_H 30 31 #include <pmModel.h>32 30 33 31 /// @addtogroup Objects Object Detection / Analysis Functions -
trunk/psModules/src/objects/pmModelUtils.c
r25754 r29004 22 22 #include "pmHDU.h" 23 23 #include "pmFPA.h" 24 25 #include "pmTrend2D.h" 24 26 #include "pmResiduals.h" 25 27 #include "pmGrowthCurve.h" 26 #include "pmTrend2D.h" 28 #include "pmSpan.h" 29 #include "pmFootprintSpans.h" 30 #include "pmFootprint.h" 31 #include "pmPeaks.h" 32 #include "pmMoments.h" 33 #include "pmModelFuncs.h" 34 #include "pmModel.h" 35 #include "pmModelUtils.h" 36 #include "pmModelClass.h" 37 #include "pmSourceMasks.h" 38 #include "pmSourceExtendedPars.h" 39 #include "pmSourceDiffStats.h" 40 #include "pmSource.h" 41 #include "pmSourceFitModel.h" 27 42 #include "pmPSF.h" 28 #include "pmModel.h" 43 29 44 #include "pmErrorCodes.h" 30 #include "pmModelUtils.h"31 45 32 46 /***************************************************************************** -
trunk/psModules/src/objects/pmMoments.c
r24498 r29004 29 29 psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__); 30 30 pmMoments *tmp = (pmMoments *) psAlloc(sizeof(pmMoments)); 31 32 tmp->Mrf = 0.0; 33 tmp->Mrh = 0.0; 34 tmp->KronFlux = 0.0; 35 tmp->KronFluxErr = 0.0; 36 37 tmp->KronFinner = 0.0; 38 tmp->KronFouter = 0.0; 39 31 40 tmp->Mx = 0.0; 32 41 tmp->My = 0.0; -
trunk/psModules/src/objects/pmMoments.h
r23487 r29004 24 24 typedef struct 25 25 { 26 float Mrf; ///< radial first moment 27 float Mrh; ///< radial half moment 28 26 29 float Mx; ///< X-coord of centroid. 27 30 float My; ///< Y-coord of centroid. … … 47 50 float SN; ///< approx signal-to-noise 48 51 int nPixels; ///< Number of pixels used. 52 53 float KronFlux; ///< Kron flux (flux in 2.5*Mrf) 54 float KronFluxErr; ///< Kron flux error 55 56 float KronFinner; ///< Kron flux (flux in 2.5*Mrf) 57 float KronFouter; ///< Kron flux (flux in 2.5*Mrf) 58 49 59 } 50 60 pmMoments; -
trunk/psModules/src/objects/pmPSF.c
r26893 r29004 25 25 #include "pmHDU.h" 26 26 #include "pmFPA.h" 27 #include "pmFPAMaskWeight.h" 28 #include "psVectorBracket.h" 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 27 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 28 35 #include "pmFootprint.h" 29 36 #include "pmPeaks.h" 30 37 #include "pmMoments.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 33 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 34 47 #include "pmPSF.h" 35 #include "pmModel.h" 36 #include "pmSource.h" 37 #include "pmModelClass.h" 38 #include "pmModelUtils.h" 39 #include "pmSourcePhotometry.h" 40 #include "pmFPAMaskWeight.h" 41 #include "psVectorBracket.h" 48 #include "pmPSFtry.h" 49 #include "pmDetections.h" 50 42 51 #include "pmErrorCodes.h" 43 52 … … 54 63 55 64 psFree (options->stats); 65 psFree (options->fitOptions); 56 66 return; 57 67 } … … 65 75 66 76 options->stats = NULL; 77 options->fitOptions = NULL; // XXX this has to be set before calling pmPSF fit functions 67 78 68 79 options->psfTrendMode = PM_TREND_NONE; -
trunk/psModules/src/objects/pmPSF.h
r26893 r29004 14 14 # define PM_PSF_H 15 15 16 #include <pslib.h>17 #include "pmTrend2D.h"18 #include "pmGrowthCurve.h"19 #include "pmResiduals.h"20 #include "pmFPA.h"21 22 16 /// @addtogroup Objects Object Detection / Analysis Functions 23 17 /// @{ 24 25 // type of model carried by the pmModel structure26 typedef int pmModelType;27 18 28 19 /** pmPSF data structure … … 38 29 * 39 30 */ 40 typedef struct{31 struct pmPSF { 41 32 pmModelType type; ///< PSF Model in use 42 33 psArray *params; ///< Model parameters (psPolynomial2D) … … 64 55 pmGrowthCurve *growth; ///< apMag vs Radius 65 56 pmResiduals *residuals; ///< normalized residual image (no spatial variation) 66 } pmPSF;57 }; 67 58 68 59 typedef struct { … … 82 73 float apRadius; 83 74 bool chiFluxTrend; // Fit a trend in Chi2 as a function of flux? 75 pmSourceFitOptions *fitOptions; 84 76 } pmPSFOptions; 85 77 -
trunk/psModules/src/objects/pmPSF_IO.c
r28449 r29004 38 38 #include "pmFPAfileFitsIO.h" 39 39 40 #include "pmTrend2D.h" 41 #include "pmResiduals.h" 42 #include "pmGrowthCurve.h" 40 43 #include "pmSpan.h" 44 #include "pmFootprintSpans.h" 41 45 #include "pmFootprint.h" 42 46 #include "pmPeaks.h" 43 47 #include "pmMoments.h" 44 #include "pmGrowthCurve.h" 45 #include "pmResiduals.h" 46 #include "pmTrend2D.h" 48 #include "pmModelFuncs.h" 49 #include "pmModel.h" 50 #include "pmModelUtils.h" 51 #include "pmModelClass.h" 52 #include "pmSourceMasks.h" 53 #include "pmSourceExtendedPars.h" 54 #include "pmSourceDiffStats.h" 55 #include "pmSource.h" 56 #include "pmSourceFitModel.h" 47 57 #include "pmPSF.h" 48 #include "pmModel.h" 58 #include "pmPSFtry.h" 59 #include "pmDetections.h" 60 49 61 #include "pmPSF_IO.h" 50 #include "pmSource.h"51 #include "pmModelClass.h"52 #include "pmModelUtils.h"53 62 #include "pmSourceIO.h" 54 63 -
trunk/psModules/src/objects/pmPSFtry.c
r25754 r29004 19 19 #include "pmFPA.h" 20 20 #include "pmFPAMaskWeight.h" 21 22 #include "pmTrend2D.h" 23 #include "pmResiduals.h" 24 #include "pmGrowthCurve.h" 21 25 #include "pmSpan.h" 26 #include "pmFootprintSpans.h" 22 27 #include "pmFootprint.h" 23 28 #include "pmPeaks.h" 24 29 #include "pmMoments.h" 25 #include "pmResiduals.h" 26 #include "pmGrowthCurve.h" 27 #include "pmTrend2D.h" 30 #include "pmModelFuncs.h" 31 #include "pmModel.h" 32 #include "pmModelUtils.h" 33 #include "pmModelClass.h" 34 #include "pmSourceMasks.h" 35 #include "pmSourceExtendedPars.h" 36 #include "pmSourceDiffStats.h" 37 #include "pmSource.h" 38 #include "pmSourceFitModel.h" 28 39 #include "pmPSF.h" 29 #include "pmModel.h"30 #include "pmSource.h"31 #include "pmSourceUtils.h"32 40 #include "pmPSFtry.h" 33 #include "pmModelClass.h" 34 #include "pmModelUtils.h" 35 #include "pmSourceFitModel.h" 41 #include "pmDetections.h" 42 36 43 #include "pmSourcePhotometry.h" 37 44 #include "pmSourceVisual.h" -
trunk/psModules/src/objects/pmPSFtryFitEXT.c
r25754 r29004 19 19 #include "pmFPA.h" 20 20 #include "pmFPAMaskWeight.h" 21 22 #include "pmTrend2D.h" 23 #include "pmResiduals.h" 24 #include "pmGrowthCurve.h" 21 25 #include "pmSpan.h" 26 #include "pmFootprintSpans.h" 22 27 #include "pmFootprint.h" 23 28 #include "pmPeaks.h" 24 29 #include "pmMoments.h" 25 #include "pmResiduals.h" 26 #include "pmGrowthCurve.h" 27 #include "pmTrend2D.h" 28 #include "pmPSF.h" 30 #include "pmModelFuncs.h" 29 31 #include "pmModel.h" 32 #include "pmModelUtils.h" 33 #include "pmModelClass.h" 34 #include "pmSourceMasks.h" 35 #include "pmSourceExtendedPars.h" 36 #include "pmSourceDiffStats.h" 30 37 #include "pmSource.h" 31 38 #include "pmSourceUtils.h" 39 #include "pmSourceFitModel.h" 40 #include "pmPSF.h" 32 41 #include "pmPSFtry.h" 33 #include "pmModelClass.h" 34 #include "pmModelUtils.h" 35 #include "pmSourceFitModel.h" 42 #include "pmDetections.h" 43 36 44 #include "pmSourcePhotometry.h" 37 45 #include "pmSourceVisual.h" … … 44 52 45 53 psTimerStart ("psf.fit"); 54 55 // in this segment, we are fitting the full PSF model class (shape unconstrained) 56 options->fitOptions->mode = PM_SOURCE_FIT_EXT; 46 57 47 58 // maskVal is used to test for rejected pixels, and must include markVal … … 73 84 74 85 // fit model as EXT, not PSF 75 status = pmSourceFitModel (source, source->modelEXT, PM_SOURCE_FIT_EXT, maskVal);86 status = pmSourceFitModel (source, source->modelEXT, options->fitOptions, maskVal); 76 87 77 88 // clear object mask to define valid pixels -
trunk/psModules/src/objects/pmPSFtryFitPSF.c
r26027 r29004 17 17 #include "pmFPA.h" 18 18 #include "pmFPAMaskWeight.h" 19 20 #include "pmTrend2D.h" 21 #include "pmResiduals.h" 22 #include "pmGrowthCurve.h" 19 23 #include "pmSpan.h" 24 #include "pmFootprintSpans.h" 20 25 #include "pmFootprint.h" 21 26 #include "pmPeaks.h" 22 27 #include "pmMoments.h" 23 #include "pmResiduals.h" 24 #include "pmGrowthCurve.h" 25 #include "pmTrend2D.h" 28 #include "pmModelFuncs.h" 29 #include "pmModel.h" 30 #include "pmModelUtils.h" 31 #include "pmModelClass.h" 32 #include "pmSourceMasks.h" 33 #include "pmSourceExtendedPars.h" 34 #include "pmSourceDiffStats.h" 35 #include "pmSource.h" 36 #include "pmSourceFitModel.h" 26 37 #include "pmPSF.h" 27 #include "pmModel.h"28 #include "pmSource.h"29 #include "pmSourceUtils.h"30 38 #include "pmPSFtry.h" 31 #include "pmModelClass.h" 32 #include "pmModelUtils.h" 33 #include "pmSourceFitModel.h" 39 #include "pmDetections.h" 40 34 41 #include "pmSourcePhotometry.h" 35 42 #include "pmSourceVisual.h" … … 42 49 43 50 psTimerStart ("psf.fit"); 51 52 // in this segment, we are fitting the fitted PSF model class (shape constrained) 53 options->fitOptions->mode = PM_SOURCE_FIT_PSF; 44 54 45 55 // maskVal is used to test for rejected pixels, and must include markVal … … 81 91 82 92 // fit the PSF model to the source 83 status = pmSourceFitModel (source, source->modelPSF, PM_SOURCE_FIT_NORM, maskVal);93 status = pmSourceFitModel (source, source->modelPSF, options->fitOptions, maskVal); 84 94 85 95 // skip poor fits … … 98 108 99 109 // This function calculates the psf and aperture magnitudes 100 status = pmSourceMagnitudes (source, psfTry->psf, PM_SOURCE_PHOT_INTERP, maskVal ); // raw PSF mag, AP mag110 status = pmSourceMagnitudes (source, psfTry->psf, PM_SOURCE_PHOT_INTERP, maskVal, markVal); // raw PSF mag, AP mag 101 111 if (!status || isnan(source->apMag)) { 102 112 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); // clear the circular mask -
trunk/psModules/src/objects/pmPSFtryMakePSF.c
r25754 r29004 18 18 #include "pmFPA.h" 19 19 #include "pmFPAMaskWeight.h" 20 21 #include "pmTrend2D.h" 22 #include "pmResiduals.h" 23 #include "pmGrowthCurve.h" 20 24 #include "pmSpan.h" 25 #include "pmFootprintSpans.h" 21 26 #include "pmFootprint.h" 22 27 #include "pmPeaks.h" 23 28 #include "pmMoments.h" 24 #include "pmResiduals.h" 25 #include "pmGrowthCurve.h" 26 #include "pmTrend2D.h" 29 #include "pmModelFuncs.h" 30 #include "pmModel.h" 31 #include "pmModelUtils.h" 32 #include "pmModelClass.h" 33 #include "pmSourceMasks.h" 34 #include "pmSourceExtendedPars.h" 35 #include "pmSourceDiffStats.h" 36 #include "pmSource.h" 37 #include "pmSourceFitModel.h" 27 38 #include "pmPSF.h" 28 #include "pmModel.h"29 #include "pmSource.h"30 #include "pmSourceUtils.h"31 39 #include "pmPSFtry.h" 32 #include "pmModelClass.h" 33 #include "pmModelUtils.h" 34 #include "pmSourceFitModel.h" 40 #include "pmDetections.h" 41 35 42 #include "pmSourcePhotometry.h" 36 43 #include "pmSourceVisual.h" -
trunk/psModules/src/objects/pmPSFtryMetric.c
r26260 r29004 18 18 #include "pmFPA.h" 19 19 #include "pmFPAMaskWeight.h" 20 21 #include "pmTrend2D.h" 22 #include "pmResiduals.h" 23 #include "pmGrowthCurve.h" 20 24 #include "pmSpan.h" 25 #include "pmFootprintSpans.h" 21 26 #include "pmFootprint.h" 22 27 #include "pmPeaks.h" 23 28 #include "pmMoments.h" 24 #include "pmResiduals.h" 25 #include "pmGrowthCurve.h" 26 #include "pmTrend2D.h" 29 #include "pmModelFuncs.h" 30 #include "pmModel.h" 31 #include "pmModelUtils.h" 32 #include "pmModelClass.h" 33 #include "pmSourceMasks.h" 34 #include "pmSourceExtendedPars.h" 35 #include "pmSourceDiffStats.h" 36 #include "pmSource.h" 37 #include "pmSourceFitModel.h" 27 38 #include "pmPSF.h" 28 #include "pmModel.h"29 #include "pmSource.h"30 #include "pmSourceUtils.h"31 39 #include "pmPSFtry.h" 32 #include "pmModelClass.h" 33 #include "pmModelUtils.h" 34 #include "pmSourceFitModel.h" 40 #include "pmDetections.h" 41 35 42 #include "pmSourcePhotometry.h" 36 43 #include "pmSourceVisual.h" -
trunk/psModules/src/objects/pmPSFtryModel.c
r27818 r29004 19 19 #include "pmFPA.h" 20 20 #include "pmFPAMaskWeight.h" 21 22 #include "pmTrend2D.h" 23 #include "pmResiduals.h" 24 #include "pmGrowthCurve.h" 21 25 #include "pmSpan.h" 26 #include "pmFootprintSpans.h" 22 27 #include "pmFootprint.h" 23 28 #include "pmPeaks.h" 24 29 #include "pmMoments.h" 25 #include "pmResiduals.h" 26 #include "pmGrowthCurve.h" 27 #include "pmTrend2D.h" 30 #include "pmModelFuncs.h" 31 #include "pmModel.h" 32 #include "pmModelUtils.h" 33 #include "pmModelClass.h" 34 #include "pmSourceMasks.h" 35 #include "pmSourceExtendedPars.h" 36 #include "pmSourceDiffStats.h" 37 #include "pmSource.h" 38 #include "pmSourceFitModel.h" 28 39 #include "pmPSF.h" 29 #include "pmModel.h"30 #include "pmSource.h"31 #include "pmSourceUtils.h"32 40 #include "pmPSFtry.h" 33 #include "pmModelClass.h" 34 #include "pmModelUtils.h" 35 #include "pmSourceFitModel.h" 36 #include "pmSourcePhotometry.h" 41 #include "pmDetections.h" 42 37 43 #include "pmSourceVisual.h" 38 44 … … 49 55 pmPSFtry *pmPSFtryModel (const psArray *sources, const char *modelName, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal) 50 56 { 57 assert (options->fitOptions); 58 51 59 // validate the requested model name 52 60 options->type = pmModelClassGetType (modelName); -
trunk/psModules/src/objects/pmPeaks.c
r26893 r29004 22 22 #include <pslib.h> 23 23 #include "pmSpan.h" 24 #include "pmFootprintSpans.h" 24 25 #include "pmFootprint.h" 25 26 #include "pmPeaks.h" -
trunk/psModules/src/objects/pmPeaks.h
r27657 r29004 17 17 # ifndef PM_PEAKS_H 18 18 # define PM_PEAKS_H 19 20 #include <pslib.h>21 #include "pmFootprint.h"22 19 23 20 /// @addtogroup Objects Object Detection / Analysis Functions -
trunk/psModules/src/objects/pmPhotObj.c
r28013 r29004 16 16 #include <string.h> 17 17 #include <pslib.h> 18 19 #include "pmHDU.h" 20 #include "pmFPA.h" 21 22 #include "pmTrend2D.h" 23 #include "pmResiduals.h" 24 #include "pmGrowthCurve.h" 25 #include "pmSpan.h" 26 #include "pmFootprintSpans.h" 27 #include "pmFootprint.h" 28 #include "pmPeaks.h" 29 #include "pmMoments.h" 30 #include "pmModelFuncs.h" 31 #include "pmModel.h" 32 #include "pmModelUtils.h" 33 #include "pmModelClass.h" 34 #include "pmSourceMasks.h" 35 #include "pmSourceExtendedPars.h" 36 #include "pmSourceDiffStats.h" 37 #include "pmSource.h" 38 18 39 #include "pmPhotObj.h" 19 #include "pmSource.h" 40 20 41 21 42 static void pmPhotObjFree (pmPhotObj *tmp) … … 82 103 return (0); 83 104 } 105 106 // sort by X (ascending) 107 int pmPhotObjSortByX (const void **a, const void **b) 108 { 109 pmPhotObj *objA = *(pmPhotObj **)a; 110 pmPhotObj *objB = *(pmPhotObj **)b; 111 112 psF32 fA = objA->x; 113 psF32 fB = objB->x; 114 115 psF32 diff = fA - fB; 116 if (diff > FLT_EPSILON) return (+1); 117 if (diff < FLT_EPSILON) return (-1); 118 return (0); 119 } -
trunk/psModules/src/objects/pmPhotObj.h
r28013 r29004 10 10 # ifndef PM_PHOT_OBJ_H 11 11 # define PM_PHOT_OBJ_H 12 13 #include <pslib.h>14 #include "pmPeaks.h"15 #include "pmModel.h"16 #include "pmMoments.h"17 12 18 13 /// @addtogroup Objects Object Detection / Analysis Functions … … 47 42 48 43 int pmPhotObjSortBySN (const void **a, const void **b); 44 int pmPhotObjSortByX (const void **a, const void **b); 49 45 50 46 /// @} -
trunk/psModules/src/objects/pmSource.c
r28013 r29004 23 23 #include "pmFPA.h" 24 24 #include "pmFPAMaskWeight.h" 25 26 #include "pmTrend2D.h" 27 #include "pmResiduals.h" 28 #include "pmGrowthCurve.h" 25 29 #include "pmSpan.h" 30 #include "pmFootprintSpans.h" 26 31 #include "pmFootprint.h" 27 32 #include "pmPeaks.h" 28 33 #include "pmMoments.h" 29 #include "pmResiduals.h" 30 #include "pmGrowthCurve.h" 31 #include "pmTrend2D.h" 32 #include "pmPSF.h" 34 #include "pmModelFuncs.h" 33 35 #include "pmModel.h" 36 #include "pmModelUtils.h" 37 #include "pmModelClass.h" 38 #include "pmSourceMasks.h" 39 #include "pmSourceExtendedPars.h" 40 #include "pmSourceDiffStats.h" 34 41 #include "pmSource.h" 35 42 … … 98 105 static int id = 1; 99 106 pmSource *source = (pmSource *) psAlloc(sizeof(pmSource)); 100 *(int *)&source->id = id++; 107 P_PM_SOURCE_SET_ID(source, id++); 108 101 109 source->seq = -1; 102 110 source->peak = NULL; … … 114 122 source->type = PM_SOURCE_TYPE_UNKNOWN; 115 123 source->mode = PM_SOURCE_MODE_DEFAULT; 124 source->mode2 = PM_SOURCE_MODE_DEFAULT; 116 125 source->tmpFlags = 0; 117 126 source->extpars = NULL; … … 131 140 source->sky = NAN; 132 141 source->skyErr = NAN; 133 source->pixWeight = NAN; 142 source->pixWeightNotBad = NAN; 143 source->pixWeightNotPoor = NAN; 134 144 135 145 source->psfChisq = NAN; … … 142 152 143 153 /****************************************************************************** 144 pmSourceCopy(): copy the pmSource structure and contents 145 XXX : are we OK with incrementing the ID? 154 pmSourceCopy(): copy the pmSource, yielding a copy of the source that can be used without 155 affecting the original. This Copy can be used to allow multiple fit attempts on the same 156 object. The pixels, variance, and mask arrays all point to the same original subarrays. The 157 peak and moments point at the original values. 146 158 *****************************************************************************/ 147 159 pmSource *pmSourceCopy(pmSource *in) 160 { 161 if (in == NULL) { 162 return(NULL); 163 } 164 pmSource *source = pmSourceAlloc (); 165 166 // keep the original ID so we can find map back to the original 167 P_PM_SOURCE_SET_ID(source, in->id); 168 169 // peak has the same values as the original 170 if (in->peak != NULL) { 171 source->peak = pmPeakAlloc (in->peak->x, in->peak->y, in->peak->value, in->peak->type); 172 source->peak->xf = in->peak->xf; 173 source->peak->yf = in->peak->yf; 174 source->peak->flux = in->peak->flux; 175 source->peak->SN = in->peak->SN; 176 } 177 178 // copy the values in the moments structure 179 if (in->moments != NULL) { 180 source->moments = pmMomentsAlloc(); 181 *source->moments = *in->moments; 182 } 183 184 // These images are all views to the parent. We want a new view, but pointing at the same 185 // pixels. Modifying these pixels (ie, subtracting the model) will affect the pixels seen 186 // by all copies. 187 source->pixels = psImageCopyView(NULL, in->pixels); 188 source->variance = psImageCopyView(NULL, in->variance); 189 source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL; 190 191 // the maskObj is a unique mask array; create a new mask image 192 source->maskObj = in->maskObj ? psImageCopy (NULL, in->maskObj, PS_TYPE_IMAGE_MASK) : NULL; 193 194 source->type = in->type; 195 source->mode = in->mode; 196 source->imageID = in->imageID; 197 198 return(source); 199 } 200 201 /****************************************************************************** 202 pmSourceCopyData(): this creates a new, duplicate source with the same parameters as the 203 original (but is actually a new source at the same location) 204 *****************************************************************************/ 205 pmSource *pmSourceCopyData(pmSource *in) 148 206 { 149 207 if (in == NULL) { … … 482 540 } 483 541 psfClump.X = stats->clippedMean; 484 psfClump.dX = stats->clippedStdev;542 psfClump.dX = hypot(stats->clippedStdev, PSF_CLUMP_GRID_SCALE); 485 543 486 544 if (!psVectorStats (stats, tmpSy, NULL, NULL, 0)) { … … 489 547 } 490 548 psfClump.Y = stats->clippedMean; 491 psfClump.dY = stats->clippedStdev;549 psfClump.dY = hypot(stats->clippedStdev, PSF_CLUMP_GRID_SCALE); 492 550 493 551 psTrace ("psModules.objects", 2, "clump X, Y: %f, %f\n", psfClump.X, psfClump.Y); … … 910 968 bool addNoise = mode & PM_MODEL_OP_NOISE; 911 969 912 if (source->modelFlux) { 970 // require the use of pmModelAddWithOffset if we are adding noise (because the model size and norm are rescaled) 971 if (!addNoise && source->modelFlux) { 913 972 // add in the pixels from the modelFlux image 914 973 int dX = source->modelFlux->col0 - source->pixels->col0; … … 931 990 932 991 psF32 **target = source->pixels->data.F32; 933 if (addNoise) {934 // when adding noise, we assume the shape and Io have been modified935 target = source->variance->data.F32;936 }937 992 938 993 for (int iy = 0; iy < source->modelFlux->numRows; iy++) { … … 949 1004 } 950 1005 } 951 if (!addNoise) { 952 if (add) { 953 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 954 } else { 955 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 956 } 1006 if (add) { 1007 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 1008 } else { 1009 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 957 1010 } 958 1011 return true; … … 973 1026 } 974 1027 } 1028 1029 return true; 1030 } 1031 1032 // should we call pmSourceCacheModel if it does not exist? 1033 bool pmSourceNoiseOp (pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy) 1034 { 1035 assert (mode & PM_MODEL_OP_NOISE); 1036 PS_ASSERT_PTR_NON_NULL(source, false); 1037 PS_ASSERT_PTR_NON_NULL(source->peak, false); 1038 1039 if (add) { 1040 psTrace ("psphot", 3, "adding noise to object at %f,%f\n", source->peak->xf, source->peak->yf); 1041 } else { 1042 psTrace ("psphot", 3, "removing noise from object at %f,%f\n", source->peak->xf, source->peak->yf); 1043 } 1044 1045 pmSourceNoiseOpModel (source->modelPSF, source, mode, FACTOR, SIZE, add, maskVal, dx, dy); 1046 1047 if (source->modelEXT) { 1048 pmSourceNoiseOpModel (source->modelEXT, source, mode, FACTOR, SIZE, add, maskVal, dx, dy); 1049 } 1050 1051 return true; 1052 } 1053 1054 bool pmSourceNoiseOpModel (pmModel *model, pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy) 1055 { 1056 bool status; 1057 psEllipseShape oldshape; 1058 psEllipseShape newshape; 1059 psEllipseAxes axes; 1060 1061 if (add) { 1062 psTrace ("psphot", 4, "adding noise for object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]); 1063 } else { 1064 psTrace ("psphot", 4, "remove noise for object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]); 1065 } 1066 1067 psF32 *PAR = model->params->data.F32; 1068 1069 // save original values 1070 float oldI0 = PAR[PM_PAR_I0]; 1071 oldshape.sx = PAR[PM_PAR_SXX]; 1072 oldshape.sy = PAR[PM_PAR_SYY]; 1073 oldshape.sxy = PAR[PM_PAR_SXY]; 1074 1075 // XXX can this be done more intelligently? 1076 if (oldI0 == 0.0) return false; 1077 if (!isfinite(oldI0)) return false; 1078 1079 // increase size and height of source 1080 axes = psEllipseShapeToAxes (oldshape, 20.0); 1081 axes.major *= SIZE; 1082 axes.minor *= SIZE; 1083 newshape = psEllipseAxesToShape (axes); 1084 PAR[PM_PAR_I0] = FACTOR*oldI0; 1085 PAR[PM_PAR_SXX] = newshape.sx; 1086 PAR[PM_PAR_SYY] = newshape.sy; 1087 PAR[PM_PAR_SXY] = newshape.sxy; 1088 1089 psImage *target = source->variance; 1090 1091 if (add) { 1092 status = pmModelAddWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy); 1093 } else { 1094 status = pmModelSubWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy); 1095 } 1096 1097 // restore original values 1098 PAR[PM_PAR_I0] = oldI0; 1099 PAR[PM_PAR_SXX] = oldshape.sx; 1100 PAR[PM_PAR_SYY] = oldshape.sy; 1101 PAR[PM_PAR_SXY] = oldshape.sxy; 975 1102 976 1103 return true; -
trunk/psModules/src/objects/pmSource.h
r28013 r29004 11 11 # define PM_SOURCE_H 12 12 13 #include <pslib.h>14 #include "pmPeaks.h"15 #include "pmModel.h"16 #include "pmMoments.h"17 #include "pmSourceExtendedPars.h"18 #include "pmSourceDiffStats.h"19 20 13 /// @addtogroup Objects Object Detection / Analysis Functions 21 14 /// @{ 22 23 #include <pmSourceMasks.h>24 15 25 16 /** pmSourceType enumeration … … 74 65 pmSourceType type; ///< Best identification of object. 75 66 pmSourceMode mode; ///< analysis flags set for object. 67 pmSourceMode2 mode2; ///< analysis flags set for object. 76 68 pmSourceTmpF tmpFlags; ///< internal-only flags 77 69 psArray *blends; ///< collection of sources thought to be confused with object … … 82 74 float errMag; ///< error in psfMag OR extMag (depending on type) 83 75 float apMag; ///< apMag corresponding to psfMag or extMag (depending on type) 84 float pixWeight; ///< model-weighted coverage of valid pixels 76 float apMagRaw; ///< raw mag in given aperture 77 float apRadius; ///< radius for aperture magnitude 78 79 float pixWeightNotBad; ///< PSF-weighted coverage of unmasked (not BAD) pixels 80 float pixWeightNotPoor; ///< PSF-weighted coverage of unmasked (not POOR) pixels 81 85 82 float psfChisq; ///< probability of PSF 86 83 float crNsigma; ///< Nsigma deviation from PSF to CR 87 84 float extNsigma; ///< Nsigma deviation from PSF to EXT 88 85 float sky, skyErr; ///< The sky and its error at the center of the object 89 float apRadius;90 86 psRegion region; ///< area on image covered by selected pixels 91 87 pmSourceExtendedPars *extpars; ///< extended source parameters … … 113 109 pmPSFClump; 114 110 111 // private macro to set the source ID (a const) 112 #define P_PM_SOURCE_SET_ID(S,V) { *(int *)&(S)->id = (V); } 115 113 116 114 /** pmSourceAlloc() … … 126 124 127 125 pmSource *pmSourceCopy(pmSource *source); 126 pmSource *pmSourceCopyData(pmSource *in); 128 127 129 128 // free just the pixels for a source, keeping derived data … … 242 241 bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psImageMaskType maskVal, int dx, int dy); 243 242 243 bool pmSourceNoiseOpModel (pmModel *model, pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy); 244 bool pmSourceNoiseOp (pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy); 245 244 246 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psImageMaskType maskVal, int dx, int dy); 245 247 bool pmSourceCacheModel (pmSource *source, psImageMaskType maskVal); -
trunk/psModules/src/objects/pmSourceContour.c
r24887 r29004 23 23 #include "pmHDU.h" 24 24 #include "pmFPA.h" 25 26 #include "pmTrend2D.h" 27 #include "pmResiduals.h" 28 #include "pmGrowthCurve.h" 25 29 #include "pmSpan.h" 30 #include "pmFootprintSpans.h" 26 31 #include "pmFootprint.h" 27 32 #include "pmPeaks.h" 28 33 #include "pmMoments.h" 29 #include "pmResiduals.h" 30 #include "pmGrowthCurve.h" 31 #include "pmTrend2D.h" 32 #include "pmPSF.h" 34 #include "pmModelFuncs.h" 33 35 #include "pmModel.h" 36 #include "pmModelUtils.h" 37 #include "pmModelClass.h" 38 #include "pmSourceMasks.h" 39 #include "pmSourceExtendedPars.h" 40 #include "pmSourceDiffStats.h" 34 41 #include "pmSource.h" 42 35 43 #include "pmSourceContour.h" 36 44 -
trunk/psModules/src/objects/pmSourceDiffStats.c
r27531 r29004 29 29 diffStats->nRatioAll = NAN; 30 30 diffStats->nGood = 0; 31 32 diffStats->SNp = NAN; 33 diffStats->SNm = NAN; 34 diffStats->Rp = NAN; 35 diffStats->Rm = NAN; 31 36 } 32 37 -
trunk/psModules/src/objects/pmSourceDiffStats.h
r27531 r29004 29 29 float nRatioAll; // = nGood / (nGood + nMask + nBad) 30 30 int nGood; // nGood as defined above 31 float SNp; // S/N of matched source in positive image 32 float SNm; // S/N of matched source in negative image 33 float Rp; // radius of matched source in positive image 34 float Rm; // radius of matched source in negative image 31 35 } pmSourceDiffStats; 32 36 -
trunk/psModules/src/objects/pmSourceFitModel.c
r26070 r29004 23 23 #include "pmHDU.h" 24 24 #include "pmFPA.h" 25 26 #include "pmTrend2D.h" 27 #include "pmResiduals.h" 28 #include "pmGrowthCurve.h" 25 29 #include "pmSpan.h" 30 #include "pmFootprintSpans.h" 26 31 #include "pmFootprint.h" 27 32 #include "pmPeaks.h" 28 33 #include "pmMoments.h" 29 #include "pmGrowthCurve.h" 30 #include "pmResiduals.h" 31 #include "pmTrend2D.h" 32 #include "pmPSF.h" 34 #include "pmModelFuncs.h" 33 35 #include "pmModel.h" 36 #include "pmModelUtils.h" 37 #include "pmModelClass.h" 38 #include "pmSourceMasks.h" 39 #include "pmSourceExtendedPars.h" 40 #include "pmSourceDiffStats.h" 34 41 #include "pmSource.h" 35 #include "pmModelClass.h"36 42 #include "pmSourceFitModel.h" 37 43 38 // save as static values so they may be set externally 39 static psF32 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = 15; 40 static psF32 PM_SOURCE_FIT_MODEL_TOLERANCE = 0.1; 41 static psF32 PM_SOURCE_FIT_MODEL_WEIGHT = 1.0; 42 static bool PM_SOURCE_FIT_MODEL_PIX_WEIGHTS = true; 43 44 bool pmSourceFitModelInit (float nIter, float tol, float weight, bool poissonErrors) 44 void pmSourceFitOptionsFree(pmSourceFitOptions *opt) 45 45 { 46 47 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = nIter; 48 PM_SOURCE_FIT_MODEL_TOLERANCE = tol; 49 PM_SOURCE_FIT_MODEL_WEIGHT = weight; 50 PM_SOURCE_FIT_MODEL_PIX_WEIGHTS = poissonErrors; 51 52 return true; 46 return; 47 } 48 49 pmSourceFitOptions *pmSourceFitOptionsAlloc(void) { 50 51 pmSourceFitOptions *opt = (pmSourceFitOptions *) psAlloc(sizeof(pmSourceFitOptions)); 52 psMemSetDeallocator(opt, (psFreeFunc) pmSourceFitOptionsFree); 53 54 opt->mode = PM_SOURCE_FIT_PSF; 55 opt->nIter = 15; 56 opt->minTol = 0.01; 57 opt->maxTol = 1.00; 58 opt->weight = 1.00; 59 opt->maxChisqDOF = NAN; 60 opt->poissonErrors = true; 61 62 return opt; 53 63 } 54 64 55 65 bool pmSourceFitModel (pmSource *source, 56 66 pmModel *model, 57 pmSourceFit Mode mode,67 pmSourceFitOptions *options, 58 68 psImageMaskType maskVal) 59 69 { … … 76 86 psVector *yErr = psVectorAllocEmpty(nPix, PS_TYPE_F32); 77 87 88 // XXX for a test, skip the central pixel in the sersic fit 89 bool skipCenter = false && (model->type == pmModelClassGetType("PS_MODEL_SERSIC")); 90 float Xo = model->params->data.F32[PM_PAR_XPOS]; 91 float Yo = model->params->data.F32[PM_PAR_YPOS]; 92 78 93 // fill in the coordinate and value entries 79 94 nPix = 0; … … 95 110 // skip nan values in image 96 111 if (!isfinite(source->variance->data.F32[i][j])) { 97 fprintf (stderr, "impossible! %x vs %x\n", source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j], maskVal); 98 continue; 99 } 100 101 psVector *coord = psVectorAlloc(2, PS_TYPE_F32); 112 fprintf (stderr, "impossible! %x vs %x\n", source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j], maskVal); 113 continue; 114 } 102 115 103 116 // Convert i/j to image space: 104 117 // 0.5 PIX: the coordinate values must be in pixel coords, not index 105 coord->data.F32[0] = (psF32) (j + 0.5 + source->pixels->col0); 106 coord->data.F32[1] = (psF32) (i + 0.5 + source->pixels->row0); 118 float Xv = (psF32) (j + 0.5 + source->pixels->col0); 119 float Yv = (psF32) (i + 0.5 + source->pixels->row0); 120 121 // XXX possible skip of center pixel: 122 if (skipCenter) { 123 float r = hypot(Xv - Xo, Yv - Yo); 124 if (r < 0.75) { 125 continue; 126 } 127 } 128 129 psVector *coord = psVectorAlloc(2, PS_TYPE_F32); 130 coord->data.F32[0] = Xv; 131 coord->data.F32[1] = Yv; 107 132 x->data[nPix] = (psPtr *) coord; 108 133 y->data.F32[nPix] = source->pixels->data.F32[i][j]; … … 111 136 // as variance to avoid the bias from systematic errors here we would just use the 112 137 // source sky variance 113 if ( PM_SOURCE_FIT_MODEL_PIX_WEIGHTS) {138 if (options->poissonErrors) { 114 139 yErr->data.F32[nPix] = 1.0 / source->variance->data.F32[i][j]; 115 140 } else { 116 yErr->data.F32[nPix] = 1.0 / PM_SOURCE_FIT_MODEL_WEIGHT;141 yErr->data.F32[nPix] = 1.0 / options->weight; 117 142 } 118 143 nPix++; … … 133 158 // set parameter mask based on fitting mode 134 159 int nParams = 0; 135 switch ( mode) {136 case PM_SOURCE_FIT_NORM:160 switch (options->mode) { 161 case PM_SOURCE_FIT_NORM: 137 162 // NORM-only model fits only source normalization (Io) 138 163 nParams = 1; … … 140 165 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0; 141 166 break; 142 case PM_SOURCE_FIT_PSF:167 case PM_SOURCE_FIT_PSF: 143 168 // PSF model only fits x,y,Io 144 169 nParams = 3; … … 148 173 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_YPOS] = 0; 149 174 break; 150 case PM_SOURCE_FIT_EXT:175 case PM_SOURCE_FIT_EXT: 151 176 // EXT model fits all params (except sky) 152 177 nParams = params->n - 1; … … 154 179 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1; 155 180 break; 156 default: 157 psAbort("invalid fitting mode"); 181 case PM_SOURCE_FIT_INDEX: 182 // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params 183 psVectorInit (constraint->paramMask, 1); 184 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0; 185 if (params->n == 7) { 186 nParams = 1; 187 } else { 188 nParams = 2; 189 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 0; 190 } 191 break; 192 case PM_SOURCE_FIT_NO_INDEX: 193 // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params 194 psVectorInit (constraint->paramMask, 0); 195 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1; 196 if (params->n == 7) { 197 nParams = params->n - 1; 198 } else { 199 nParams = params->n - 2; 200 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 1; 201 } 202 break; 203 default: 204 psAbort("invalid fitting mode"); 158 205 } 159 206 // force the floating parameters to fall within the contraint ranges 160 207 for (int i = 0; i < params->n; i++) { 161 model->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);162 model->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);208 model->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL); 209 model->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL); 163 210 } 164 211 … … 173 220 } 174 221 175 psMinimization *myMin = psMinimizationAlloc ( PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_TOLERANCE);222 psMinimization *myMin = psMinimizationAlloc (options->nIter, options->minTol, options->maxTol); 176 223 177 224 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); … … 194 241 model->flags |= PM_MODEL_STATUS_FITTED; 195 242 if (!fitStatus) model->flags |= PM_MODEL_STATUS_NONCONVERGE; 243 if (myMin->lastDelta > myMin->minTol) model->flags |= PM_MODEL_STATUS_WEAK_FIT; 196 244 197 245 // get the Gauss-Newton distance for fixed model parameters -
trunk/psModules/src/objects/pmSourceFitModel.h
r21183 r29004 19 19 PM_SOURCE_FIT_EXT, 20 20 PM_SOURCE_FIT_PSF_AND_SKY, 21 PM_SOURCE_FIT_EXT_AND_SKY 21 PM_SOURCE_FIT_EXT_AND_SKY, 22 PM_SOURCE_FIT_INDEX, 23 PM_SOURCE_FIT_NO_INDEX, 22 24 } pmSourceFitMode; 23 25 24 bool pmSourceFitModelInit( 25 float nIter, ///< max number of allowed iterations 26 float tol, ///< convergence criterion 27 float weight, ///< use this weight for constant-weight fits 28 bool poissonErrors // use poisson errors for fits? 29 ); 26 typedef struct { 27 pmSourceFitMode mode; ///< optionally fit all or a subset of parameters 28 float nIter; ///< max number of allowed iterations 29 float minTol; ///< convergence criterion 30 float maxTol; ///< convergence criterion 31 float maxChisqDOF; ///< convergence criterion 32 float weight; ///< use this weight for constant-weight fits 33 bool poissonErrors; ///< use poisson errors for fits? 34 } pmSourceFitOptions; 35 36 // the pmSourceFitOptions structure is used to control details of the fitting process 37 pmSourceFitOptions *pmSourceFitOptionsAlloc(void); 38 39 // bool pmSourceFitModelInit( 40 // pmSourceFitMode mode, ///< what parameter set should be fitted? 41 // float nIter, ///< max number of allowed iterations 42 // float tol, ///< convergence criterion 43 // float weight, ///< use this weight for constant-weight fits 44 // bool poissonErrors ///< use poisson errors for fits? 45 // ); 30 46 31 47 /** pmSourceFitModel() … … 38 54 */ 39 55 bool pmSourceFitModel( 40 pmSource *source, ///< The input pmSource41 pmModel *model, ///< model to be fitted42 pmSourceFit Mode mode,///< define parameters to be fitted56 pmSource *source, ///< The input pmSource 57 pmModel *model, ///< model to be fitted 58 pmSourceFitOptions *options, ///< define parameters to be fitted 43 59 psImageMaskType maskVal ///< Value to mask 44 60 ); 45 61 46 47 // initialize data for a group of object models 48 bool pmSourceFitSetInit (pmModelType type); 49 50 // clear data for a group of object models 51 void pmSourceFitSetClear (void); 52 53 // function used to set limits for a group of models 54 bool pmSourceFitSet_CheckLimits (psMinConstraintMode mode, int nParam, float *params, float *betas); 55 56 // function used to fit a group of object models 57 psF32 pmSourceFitSet_Function(psVector *deriv, 58 const psVector *params, 59 const psVector *x); 60 61 /** pmSourceFitSet() 62 * 63 * Fit the requested model to the specified source. The starting guess for the model is given 64 * by the input source.model parameter values. The pixels of interest are specified by the 65 * source.pixels and source.mask entries. This function calls psMinimizeLMChi2() on the image 66 * data. The function returns TRUE on success or FALSE on failure. 67 * 68 */ 69 bool pmSourceFitSet( 70 pmSource *source, ///< The input pmSource 71 psArray *modelSet, ///< model to be fitted 72 pmSourceFitMode mode, ///< define parameters to be fitted 73 psImageMaskType maskVal ///< Vale to mask 74 75 ); 62 // // initialize data for a group of object models 63 // bool pmSourceFitSetInit (pmModelType type); 64 // 65 // // clear data for a group of object models 66 // void pmSourceFitSetClear (void); 67 // 68 // // function used to set limits for a group of models 69 // bool pmSourceFitSet_CheckLimits (psMinConstraintMode mode, int nParam, float *params, float *betas); 70 // 71 // // function used to fit a group of object models 72 // psF32 pmSourceFitSet_Function(psVector *deriv, 73 // const psVector *params, 74 // const psVector *x); 75 // 76 // /** pmSourceFitSet() 77 // * 78 // * Fit the requested model to the specified source. The starting guess for the model is given 79 // * by the input source.model parameter values. The pixels of interest are specified by the 80 // * source.pixels and source.mask entries. This function calls psMinimizeLMChi2() on the image 81 // * data. The function returns TRUE on success or FALSE on failure. 82 // * 83 // */ 84 // bool pmSourceFitSet( 85 // pmSource *source, ///< The input pmSource 86 // psArray *modelSet, ///< model to be fitted 87 // pmSourceFitMode mode, ///< define parameters to be fitted 88 // psImageMaskType maskVal ///< Vale to mask 89 // 90 // ); 76 91 77 92 /// @} -
trunk/psModules/src/objects/pmSourceFitSet.c
r27903 r29004 22 22 #include "pmHDU.h" 23 23 #include "pmFPA.h" 24 25 #include "pmTrend2D.h" 26 #include "pmResiduals.h" 27 #include "pmGrowthCurve.h" 24 28 #include "pmSpan.h" 29 #include "pmFootprintSpans.h" 25 30 #include "pmFootprint.h" 26 31 #include "pmPeaks.h" 27 32 #include "pmMoments.h" 28 #include "pmGrowthCurve.h" 29 #include "pmResiduals.h" 30 #include "pmTrend2D.h" 31 #include "pmPSF.h" 33 #include "pmModelFuncs.h" 32 34 #include "pmModel.h" 35 #include "pmModelUtils.h" 36 #include "pmModelClass.h" 37 #include "pmSourceMasks.h" 38 #include "pmSourceExtendedPars.h" 39 #include "pmSourceDiffStats.h" 33 40 #include "pmSource.h" 34 #include "pmModelClass.h" 41 35 42 #include "pmSourceFitModel.h" 36 43 #include "pmSourceFitSet.h" 37 44 38 45 // save as static values so they may be set externally 39 static psF32 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = 15;40 static psF32 PM_SOURCE_FIT_MODEL_TOLERANCE = 0.1;41 static psF32 PM_SOURCE_FIT_MODEL_WEIGHT = 1.0;42 static bool PM_SOURCE_FIT_MODEL_PIX_WEIGHTS = true;46 // static psF32 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = 15; 47 // static psF32 PM_SOURCE_FIT_MODEL_TOLERANCE = 0.1; 48 // static psF32 PM_SOURCE_FIT_MODEL_WEIGHT = 1.0; 49 // static bool PM_SOURCE_FIT_MODEL_PIX_WEIGHTS = true; 43 50 44 51 /********************* Source Model Set Functions ***************************/ … … 429 436 bool pmSourceFitSet (pmSource *source, 430 437 psArray *modelSet, 431 pmSourceFitMode mode,438 pmSourceFitOptions *options, 432 439 psImageMaskType maskVal) 433 440 { … … 478 485 // as variance to avoid the bias from systematic errors here we would just use the 479 486 // source sky variance 480 if ( PM_SOURCE_FIT_MODEL_PIX_WEIGHTS) {481 yErr->data.F32[nPix] = 1.0 / source->variance->data.F32[i][j];482 } else {483 yErr->data.F32[nPix] = 1.0 / PM_SOURCE_FIT_MODEL_WEIGHT;484 }485 nPix++;486 }487 if (options->poissonErrors) { 488 yErr->data.F32[nPix] = 1.0 / source->variance->data.F32[i][j]; 489 } else { 490 yErr->data.F32[nPix] = 1.0 / options->weight; 491 } 492 nPix++; 493 } 487 494 } 488 495 x->n = nPix; … … 490 497 yErr->n = nPix; 491 498 492 // create the FitSet for this thread and set the initial parameter guesses499 // create the FitSet for this thread and set the initial parameter guesses 493 500 pmSourceFitSetData *thisSet = pmSourceFitSetDataSet(modelSet); 494 501 495 // define param and deriv vectors for complete set of parameters502 // define param and deriv vectors for complete set of parameters 496 503 psVector *params = psVectorAlloc (thisSet->nParamSet, PS_TYPE_F32); 497 504 498 // set the param and deriv vectors based on the curent values505 // set the param and deriv vectors based on the curent values 499 506 pmSourceFitSetJoin (NULL, params, thisSet); 500 507 501 // create the minimization constraints508 // create the minimization constraints 502 509 psMinConstraint *constraint = psMinConstraintAlloc(); 503 510 constraint->paramMask = psVectorAlloc (thisSet->nParamSet, PS_TYPE_VECTOR_MASK); 504 511 constraint->checkLimits = pmSourceFitSetCheckLimits; 505 512 506 pmSourceFitSetMasks (constraint, thisSet, mode);507 508 // force the floating parameters to fall within the contraint ranges513 pmSourceFitSetMasks (constraint, thisSet, options->mode); 514 515 // force the floating parameters to fall within the contraint ranges 509 516 for (int i = 0; i < params->n; i++) { 510 pmSourceFitSetCheckLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);511 pmSourceFitSetCheckLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);517 pmSourceFitSetCheckLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL); 518 pmSourceFitSetCheckLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL); 512 519 } 513 520 514 521 if (psTraceGetLevel("psModules.objects") >= 5) { 515 for (int i = 0; i < params->n; i++) {516 fprintf (stderr, "%d %f %d\n", i, params->data.F32[i], constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]);517 }522 for (int i = 0; i < params->n; i++) { 523 fprintf (stderr, "%d %f %d\n", i, params->data.F32[i], constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]); 524 } 518 525 } 519 526 520 527 if (nPix < thisSet->nParamSet + 1) { 521 psTrace (__func__, 4, "insufficient valid pixels\n");522 psTrace("psModules.objects", 10, "---- %s() end : fail pixels ----\n", __func__);523 for (int i = 0; i < modelSet->n; i++) {524 pmModel *model = modelSet->data[i];525 model->flags |= PM_MODEL_STATUS_BADARGS;526 }527 psFree (x);528 psFree (y);529 psFree (yErr);530 psFree (params);531 psFree(constraint);532 pmSourceFitSetDataClear(); // frees thisSet and removes if from the array of fitSets533 return(false);534 } 535 536 psMinimization *myMin = psMinimizationAlloc ( PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_TOLERANCE);528 psTrace (__func__, 4, "insufficient valid pixels\n"); 529 psTrace("psModules.objects", 10, "---- %s() end : fail pixels ----\n", __func__); 530 for (int i = 0; i < modelSet->n; i++) { 531 pmModel *model = modelSet->data[i]; 532 model->flags |= PM_MODEL_STATUS_BADARGS; 533 } 534 psFree (x); 535 psFree (y); 536 psFree (yErr); 537 psFree (params); 538 psFree(constraint); 539 pmSourceFitSetDataClear(); // frees thisSet and removes if from the array of fitSets 540 return(false); 541 } 542 543 psMinimization *myMin = psMinimizationAlloc (options->nIter, options->minTol, options->maxTol); 537 544 538 545 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); … … 540 547 fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, pmSourceFitSetFunction); 541 548 if (!fitStatus) { 542 psTrace("psModules.objects", 4, "Failed to fit model (%ld components)\n", modelSet->n);543 } 544 545 // parameter errors from the covariance matrix549 psTrace("psModules.objects", 4, "Failed to fit model (%ld components)\n", modelSet->n); 550 } 551 552 // parameter errors from the covariance matrix 546 553 psVector *dparams = psVectorAlloc (thisSet->nParamSet, PS_TYPE_F32); 547 554 for (int i = 0; i < dparams->n; i++) { 548 if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])549 continue;550 dparams->data.F32[i] = sqrt(covar->data.F32[i][i]);551 } 552 553 // get the Gauss-Newton distance for fixed model parameters555 if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) 556 continue; 557 dparams->data.F32[i] = sqrt(covar->data.F32[i][i]); 558 } 559 560 // get the Gauss-Newton distance for fixed model parameters 554 561 if (constraint->paramMask != NULL) { 555 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F32);556 psVector *altmask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK);557 altmask->data.PS_TYPE_VECTOR_MASK_DATA[0] = 1;558 for (int i = 1; i < dparams->n; i++) {559 altmask->data.PS_TYPE_VECTOR_MASK_DATA[i] = (constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) ? 0 : 1;560 }561 psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSetFunction);562 563 for (int i = 0; i < dparams->n; i++) {564 if (!constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])565 continue;566 // note that delta is the value *subtracted* from the parameter567 // to get the new guess. for dparams to represent the direction568 // of motion, we need to take -delta569 dparams->data.F32[i] = -delta->data.F32[i];570 }571 psFree (delta);572 psFree (altmask);562 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F32); 563 psVector *altmask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK); 564 altmask->data.PS_TYPE_VECTOR_MASK_DATA[0] = 1; 565 for (int i = 1; i < dparams->n; i++) { 566 altmask->data.PS_TYPE_VECTOR_MASK_DATA[i] = (constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) ? 0 : 1; 567 } 568 psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSetFunction); 569 570 for (int i = 0; i < dparams->n; i++) { 571 if (!constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) 572 continue; 573 // note that delta is the value *subtracted* from the parameter 574 // to get the new guess. for dparams to represent the direction 575 // of motion, we need to take -delta 576 dparams->data.F32[i] = -delta->data.F32[i]; 577 } 578 psFree (delta); 579 psFree (altmask); 573 580 } 574 581 -
trunk/psModules/src/objects/pmSourceFitSet.h
r23487 r29004 56 56 pmSource *source, ///< The input pmSource 57 57 psArray *modelSet, ///< model to be fitted 58 pmSourceFit Mode mode, ///< define parameters to be fitted58 pmSourceFitOptions *options, ///< define options for fitting process 59 59 psImageMaskType maskVal ///< Vale to mask 60 60 -
trunk/psModules/src/objects/pmSourceGroups.c
r26450 r29004 6 6 #include <pslib.h> 7 7 8 #include "pmHDU.h" 8 9 #include "pmFPA.h" 10 11 #include "pmTrend2D.h" 12 #include "pmResiduals.h" 13 #include "pmGrowthCurve.h" 14 #include "pmSpan.h" 15 #include "pmFootprintSpans.h" 16 #include "pmFootprint.h" 17 #include "pmPeaks.h" 18 #include "pmMoments.h" 19 #include "pmModelFuncs.h" 20 #include "pmModel.h" 21 #include "pmModelUtils.h" 22 #include "pmModelClass.h" 23 #include "pmSourceMasks.h" 24 #include "pmSourceExtendedPars.h" 25 #include "pmSourceDiffStats.h" 9 26 #include "pmSource.h" 27 #include "pmSourceFitModel.h" 28 #include "pmPSF.h" 29 #include "pmPSFtry.h" 30 #include "pmDetections.h" 31 10 32 #include "pmSourceGroups.h" 11 33 -
trunk/psModules/src/objects/pmSourceGroups.h
r26182 r29004 1 1 #ifndef PM_SOURCE_GROUPS_H 2 2 #define PM_SOURCE_GROUPS_H 3 4 #include <pslib.h>5 6 #include "pmFPA.h"7 3 8 4 /// Groups of sources -
trunk/psModules/src/objects/pmSourceIO.c
r28013 r29004 31 31 #include "pmConceptsRead.h" 32 32 33 #include "pmTrend2D.h" 34 #include "pmResiduals.h" 35 #include "pmGrowthCurve.h" 33 36 #include "pmSpan.h" 37 #include "pmFootprintSpans.h" 34 38 #include "pmFootprint.h" 35 39 #include "pmPeaks.h" 36 40 #include "pmMoments.h" 37 #include "pmGrowthCurve.h" 38 #include "pmResiduals.h" 39 #include "pmTrend2D.h" 41 #include "pmModelFuncs.h" 42 #include "pmModel.h" 43 #include "pmModelUtils.h" 44 #include "pmModelClass.h" 45 #include "pmSourceMasks.h" 46 #include "pmSourceExtendedPars.h" 47 #include "pmSourceDiffStats.h" 48 #include "pmSource.h" 49 #include "pmSourceFitModel.h" 40 50 #include "pmPSF.h" 41 #include "pmModel.h" 51 #include "pmPSFtry.h" 52 42 53 #include "pmDetections.h" 43 #include "pmSource.h"44 #include "pmModelClass.h"45 54 #include "pmDetEff.h" 46 55 #include "pmSourceIO.h" … … 326 335 } 327 336 337 # define PM_SOURCES_WRITE(NAME,TYPE) \ 338 if (!strcmp (exttype, NAME)) { \ 339 status &= pmSourcesWrite_##TYPE(file->fits, readout, sources, file->header, outhead, dataname, recipe); \ 340 if (xsrcname) { \ 341 status &= pmSourcesWrite_##TYPE##_XSRC(file->fits, readout, sources, file->header, xsrcname, recipe); \ 342 } \ 343 if (xfitname) { \ 344 status &= pmSourcesWrite_##TYPE##_XFIT (file->fits, readout, sources, file->header, xfitname); \ 345 } \ 346 } 347 328 348 // write out all readout-level Objects files for this cell 329 349 bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) … … 360 380 } 361 381 382 // the older types (RAW, OBJ, SX, CMP) are for backwards compatibility -- deprecate eventually? 362 383 switch (file->type) { 363 384 case PM_FPA_FILE_RAW: … … 518 539 psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname); 519 540 } 520 521 // XXX these are case-sensitive since the EXTYPE is case-sensitive 541 542 543 // these are case-sensitive since the EXTYPE is case-sensitive 522 544 status = true; 523 if (!strcmp (exttype, "SMPDATA")) { 524 status &= pmSourcesWrite_SMPDATA (file->fits, sources, file->header, outhead, dataname); 525 } 526 if (!strcmp (exttype, "PS1_DEV_0")) { 527 status &= pmSourcesWrite_PS1_DEV_0 (file->fits, sources, file->header, outhead, dataname); 528 } 529 if (!strcmp (exttype, "PS1_DEV_1")) { 530 status &= pmSourcesWrite_PS1_DEV_1 (file->fits, sources, file->header, outhead, dataname); 531 } 532 if (!strcmp (exttype, "PS1_CAL_0")) { 533 status &= pmSourcesWrite_PS1_CAL_0 (file->fits, readout, sources, file->header, outhead, dataname); 534 } 535 if (!strcmp (exttype, "PS1_V1")) { 536 status &= pmSourcesWrite_CMF_PS1_V1 (file->fits, readout, sources, file->header, outhead, dataname); 537 } 538 if (!strcmp (exttype, "PS1_V2")) { 539 status &= pmSourcesWrite_CMF_PS1_V2 (file->fits, readout, sources, file->header, outhead, dataname); 540 } 541 if (!strcmp (exttype, "PS1_SV1")) { 542 status &= pmSourcesWrite_CMF_PS1_SV1 (file->fits, readout, sources, file->header, outhead, dataname, recipe); 543 } 544 if (!strcmp (exttype, "PS1_DV1")) { 545 status &= pmSourcesWrite_CMF_PS1_DV1 (file->fits, readout, sources, file->header, outhead, dataname); 546 } 547 548 if (xsrcname) { 549 if (!strcmp (exttype, "PS1_DEV_1")) { 550 status &= pmSourcesWrite_PS1_DEV_1_XSRC (file->fits, sources, xsrcname, recipe); 551 } 552 if (!strcmp (exttype, "PS1_CAL_0")) { 553 status &= pmSourcesWrite_PS1_CAL_0_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 554 } 555 if (!strcmp (exttype, "PS1_V1")) { 556 status &= pmSourcesWrite_CMF_PS1_V1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 557 } 558 if (!strcmp (exttype, "PS1_V2")) { 559 status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 560 } 561 if (!strcmp (exttype, "PS1_SV1")) { 562 status &= pmSourcesWrite_CMF_PS1_SV1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 563 } 564 if (!strcmp (exttype, "PS1_DV1")) { 565 status &= pmSourcesWrite_CMF_PS1_DV1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 566 } 567 } 568 if (xfitname) { 569 if (!strcmp (exttype, "PS1_DEV_1")) { 570 status &= pmSourcesWrite_PS1_DEV_1_XFIT (file->fits, sources, xfitname); 571 } 572 if (!strcmp (exttype, "PS1_CAL_0")) { 573 status &= pmSourcesWrite_PS1_CAL_0_XFIT (file->fits, readout, sources, file->header, xfitname); 574 } 575 if (!strcmp (exttype, "PS1_V1")) { 576 status &= pmSourcesWrite_CMF_PS1_V1_XFIT (file->fits, readout, sources, xfitname); 577 } 578 if (!strcmp (exttype, "PS1_V2")) { 579 status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, readout, sources, xfitname); 580 } 581 if (!strcmp (exttype, "PS1_SV1")) { 582 status &= pmSourcesWrite_CMF_PS1_SV1_XFIT (file->fits, readout, sources, xfitname); 583 } 584 if (!strcmp (exttype, "PS1_DV1")) { 585 status &= pmSourcesWrite_CMF_PS1_DV1_XFIT (file->fits, readout, sources, xfitname); 586 } 587 } 545 PM_SOURCES_WRITE("SMPDATA", SMPDATA); 546 PM_SOURCES_WRITE("PS1_DEV_0", PS1_DEV_0); 547 PM_SOURCES_WRITE("PS1_DEV_1", PS1_DEV_1); 548 PM_SOURCES_WRITE("PS1_CAL_0", PS1_CAL_0); 549 PM_SOURCES_WRITE("PS1_V1", CMF_PS1_V1); 550 PM_SOURCES_WRITE("PS1_V2", CMF_PS1_V2); 551 PM_SOURCES_WRITE("PS1_V3", CMF_PS1_V3); 552 PM_SOURCES_WRITE("PS1_SV1", CMF_PS1_SV1); 553 PM_SOURCES_WRITE("PS1_DV1", CMF_PS1_DV1); 554 PM_SOURCES_WRITE("PS1_DV2", CMF_PS1_DV2); 555 588 556 psFree (outhead); 589 557 psFree (exttype); … … 1039 1007 sources = pmSourcesRead_CMF_PS1_DV1 (file->fits, hdu->header); 1040 1008 } 1009 if (!strcmp (exttype, "PS1_DV2")) { 1010 sources = pmSourcesRead_CMF_PS1_DV2 (file->fits, hdu->header); 1011 } 1041 1012 1042 1013 if (!pmReadoutReadDetEff(file->fits, readout, deteffname)) { -
trunk/psModules/src/objects/pmSourceIO.h
r28013 r29004 24 24 bool pmSourcesWriteCMP (psArray *sources, char *filename, psMetadata *header); 25 25 26 bool pmSourcesWrite_SMPDATA (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname); 27 bool pmSourcesWrite_PS1_DEV_0 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname); 26 bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, pmConfig *config); 28 27 29 bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname); 30 bool pmSourcesWrite_PS1_DEV_1_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe); 31 bool pmSourcesWrite_PS1_DEV_1_XFIT (psFits *fits, psArray *sources, char *extname); 28 // All of these functions need to use the same API, even if not all elements are used in a specific case 29 bool pmSourcesWrite_SMPDATA(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 30 bool pmSourcesWrite_SMPDATA_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 31 bool pmSourcesWrite_SMPDATA_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 32 32 33 bool pmSourcesWrite_PS1_ CAL_0 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);34 bool pmSourcesWrite_PS1_ CAL_0_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);35 bool pmSourcesWrite_PS1_ CAL_0_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname);33 bool pmSourcesWrite_PS1_DEV_0(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 34 bool pmSourcesWrite_PS1_DEV_0_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 35 bool pmSourcesWrite_PS1_DEV_0_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 36 36 37 bool pmSourcesWrite_ CMF_PS1_V1 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);38 bool pmSourcesWrite_ CMF_PS1_V1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);39 bool pmSourcesWrite_ CMF_PS1_V1_XFIT (psFits *fits, pmReadout *readout, psArray *sources, char *extname);37 bool pmSourcesWrite_PS1_DEV_1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 38 bool pmSourcesWrite_PS1_DEV_1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 39 bool pmSourcesWrite_PS1_DEV_1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 40 40 41 bool pmSourcesWrite_ CMF_PS1_V2 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);42 bool pmSourcesWrite_ CMF_PS1_V2_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);43 bool pmSourcesWrite_ CMF_PS1_V2_XFIT (psFits *fits, pmReadout *readout, psArray *sources, char *extname);41 bool pmSourcesWrite_PS1_CAL_0(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 42 bool pmSourcesWrite_PS1_CAL_0_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 43 bool pmSourcesWrite_PS1_CAL_0_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 44 44 45 bool pmSourcesWrite_CMF_PS1_ SV1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe);46 bool pmSourcesWrite_CMF_PS1_ SV1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);47 bool pmSourcesWrite_CMF_PS1_ SV1_XFIT (psFits *fits, pmReadout *readout, psArray *sources, char *extname);45 bool pmSourcesWrite_CMF_PS1_V1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 46 bool pmSourcesWrite_CMF_PS1_V1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 47 bool pmSourcesWrite_CMF_PS1_V1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 48 48 49 bool pmSourcesWrite_CMF_PS1_ DV1 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);50 bool pmSourcesWrite_CMF_PS1_ DV1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);51 bool pmSourcesWrite_CMF_PS1_ DV1_XFIT (psFits *fits, pmReadout *readout, psArray *sources, char *extname);49 bool pmSourcesWrite_CMF_PS1_V2(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 50 bool pmSourcesWrite_CMF_PS1_V2_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 51 bool pmSourcesWrite_CMF_PS1_V2_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 52 52 53 bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, pmConfig *config); 53 bool pmSourcesWrite_CMF_PS1_V3(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 54 bool pmSourcesWrite_CMF_PS1_V3_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 55 bool pmSourcesWrite_CMF_PS1_V3_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 56 57 bool pmSourcesWrite_CMF_PS1_SV1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 58 bool pmSourcesWrite_CMF_PS1_SV1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 59 bool pmSourcesWrite_CMF_PS1_SV1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 60 61 bool pmSourcesWrite_CMF_PS1_DV1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 62 bool pmSourcesWrite_CMF_PS1_DV1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 63 bool pmSourcesWrite_CMF_PS1_DV1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 64 65 bool pmSourcesWrite_CMF_PS1_DV2(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 66 bool pmSourcesWrite_CMF_PS1_DV2_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 67 bool pmSourcesWrite_CMF_PS1_DV2_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 54 68 55 69 psArray *pmSourcesReadCMP (char *filename, psMetadata *header); … … 63 77 psArray *pmSourcesRead_CMF_PS1_SV1 (psFits *fits, psMetadata *header); 64 78 psArray *pmSourcesRead_CMF_PS1_DV1 (psFits *fits, psMetadata *header); 79 psArray *pmSourcesRead_CMF_PS1_DV2 (psFits *fits, psMetadata *header); 65 80 66 81 bool pmSourcesWritePSFs (psArray *sources, char *filename); -
trunk/psModules/src/objects/pmSourceIO_CMF_PS1_DV1.c
r28013 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 … … 47 56 // This version has elements intended for difference images & forced photometry: 48 57 // diffStats entries (good for dipoles); flux + flux error (for insignificant detections) 49 bool pmSourcesWrite_CMF_PS1_DV1 (psFits *fits, pmReadout *readout, psArray *sources, 50 psMetadata *imageHeader, psMetadata *tableHeader, char *extname) 58 bool pmSourcesWrite_CMF_PS1_DV1 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe) 51 59 { 52 60 PS_ASSERT_PTR_NON_NULL(fits, false); … … 194 202 psMetadataAdd (row, PS_LIST_TAIL, "PSF_MINOR", PS_DATA_F32, "PSF width (minor axis)", axes.minor); 195 203 psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA", PS_DATA_F32, "PSF orientation angle", axes.theta); 196 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeight );204 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeightNotBad); 197 205 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NDOF", PS_DATA_S32, "degrees of freedom", nDOF); 198 206 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX", PS_DATA_S32, "number of pixels in fit", nPix); … … 324 332 source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE); 325 333 source->peak->flux = peakFlux; 334 source->peak->xf = PAR[PM_PAR_XPOS]; // more accurate position 335 source->peak->yf = PAR[PM_PAR_YPOS]; // more accurate position 326 336 source->peak->dx = dPAR[PM_PAR_XPOS]; 327 337 source->peak->dy = dPAR[PM_PAR_YPOS]; 328 source->peak->SN = sqrt(source->peak->flux); // XXX a proxy: various functions sort by peak S/N 329 330 source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF"); 338 if (isfinite (source->errMag) && (source->errMag > 0.0)) { 339 source->peak->SN = 1.0 / source->errMag; 340 } else { 341 source->peak->SN = sqrt(source->peak->flux); // an alternate proxy: various functions sort by peak S/N 342 } 343 344 source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF"); 331 345 source->crNsigma = psMetadataLookupF32 (&status, row, "CR_NSIGMA"); 332 346 source->extNsigma = psMetadataLookupF32 (&status, row, "EXT_NSIGMA"); … … 536 550 537 551 // XXX this layout is still the same as PS1_DEV_1 538 bool pmSourcesWrite_CMF_PS1_DV1_XFIT (psFits *fits, pmReadout *readout, psArray *sources, char *extname)552 bool pmSourcesWrite_CMF_PS1_DV1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname) 539 553 { 540 554 … … 585 599 assert (model); 586 600 601 // skip models which were not actually fitted 602 if (model->flags & PM_MODEL_STATUS_BADARGS) continue; 603 587 604 PAR = model->params->data.F32; 588 605 dPAR = model->dparams->data.F32; -
trunk/psModules/src/objects/pmSourceIO_CMF_PS1_SV1.c
r28013 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 … … 46 55 47 56 // NOTE: this output function is intended for psphotStack analysis: it includes per-psf radial fluxes 48 // XXX currently inthe 'read' function is NOT consistent with the 'write' function (does not read radial fluxes)57 // XXX currently, the 'read' function is NOT consistent with the 'write' function (does not read radial fluxes) 49 58 50 59 bool pmSourcesWrite_CMF_PS1_SV1 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe) … … 62 71 psF32 errMag, chisq, apRadius; 63 72 psS32 nPix, nDOF; 73 char keyword1[80], keyword2[80]; 64 74 65 75 pmChip *chip = readout->parent->parent; … … 95 105 // we use this just to define the output vectors (which must be present for all objects) 96 106 bool status = false; 107 psVector *radMin = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.LOWER"); 97 108 psVector *radMax = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.UPPER"); 98 109 psAssert (radMax, "this must have been defined and tested earlier!"); 99 110 psAssert (radMax->n, "this must have been defined and tested earlier!"); 111 psAssert (radMin->n == radMax->n, "inconsistent annular bins"); 112 113 // write the radial profile apertures to header 114 for (int i = 0; i < radMax->n; i++) { 115 sprintf (keyword1, "RMIN_%02d", i); 116 sprintf (keyword2, "RMAX_%02d", i); 117 psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword1, PS_META_REPLACE, "min radius for SB profile", radMin->data.F32[i]); 118 psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword2, PS_META_REPLACE, "min radius for SB profile", radMax->data.F32[i]); 119 } 120 100 121 101 122 // we write out PSF-fits for all sources, regardless of quality. the source flags tell us the state … … 193 214 psMetadataAdd (row, PS_LIST_TAIL, "PSF_MINOR", PS_DATA_F32, "PSF width (minor axis)", axes.minor); 194 215 psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA", PS_DATA_F32, "PSF orientation angle", axes.theta); 195 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeight); 216 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor (bad)", source->pixWeightNotBad); 217 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF_PERFECT", PS_DATA_F32, "PSF coverage/quality factor (poor)", source->pixWeightNotPoor); 196 218 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NDOF", PS_DATA_S32, "degrees of freedom", nDOF); 197 219 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX", PS_DATA_S32, "number of pixels in fit", nPix); 198 220 199 221 // distinguish moments measure from window vs S/N > XX ?? 200 float mxx = source->moments ? source->moments->Mxx : NAN; 201 float mxy = source->moments ? source->moments->Mxy : NAN; 202 float myy = source->moments ? source->moments->Myy : NAN; 203 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX", PS_DATA_F32, "second moments (X^2)", mxx); 204 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY", PS_DATA_F32, "second moments (X*Y)", mxy); 205 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY", PS_DATA_F32, "second moments (Y*Y)", myy); 206 207 psMetadataAdd (row, PS_LIST_TAIL, "FLAGS", PS_DATA_U32, "psphot analysis flags", source->mode); 222 float Mxx = source->moments ? source->moments->Mxx : NAN; 223 float Mxy = source->moments ? source->moments->Mxy : NAN; 224 float Myy = source->moments ? source->moments->Myy : NAN; 225 226 float Mrf = source->moments ? source->moments->Mrf : NAN; 227 float Mrh = source->moments ? source->moments->Mrh : NAN; 228 float Krf = source->moments ? source->moments->KronFlux : NAN; 229 float dKrf = source->moments ? source->moments->KronFluxErr : NAN; 230 231 float Kinner = source->moments ? source->moments->KronFinner : NAN; 232 float Kouter = source->moments ? source->moments->KronFouter : NAN; 233 234 float M_c3 = source->moments ? 1.0*source->moments->Mxxx - 3.0*source->moments->Mxyy : NAN; 235 float M_s3 = source->moments ? 3.0*source->moments->Mxxy - 1.0*source->moments->Myyy : NAN; 236 float M_c4 = source->moments ? 1.0*source->moments->Mxxxx - 6.0*source->moments->Mxxyy + 1.0*source->moments->Myyyy : NAN; 237 float M_s4 = source->moments ? 4.0*source->moments->Mxxxy - 4.0*source->moments->Mxyyy : NAN; 238 239 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX", PS_DATA_F32, "second moments (X^2)", Mxx); 240 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY", PS_DATA_F32, "second moments (X*Y)", Mxy); 241 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY", PS_DATA_F32, "second moments (Y*Y)", Myy); 242 243 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M3C", PS_DATA_F32, "third momemt cos theta", M_c3); 244 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M3S", PS_DATA_F32, "third momemt sin theta", M_s3); 245 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M4C", PS_DATA_F32, "fourth momemt cos theta", M_c4); 246 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M4S", PS_DATA_F32, "fourth momemt sin theta", M_s4); 247 248 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1", PS_DATA_F32, "first radial moment", Mrf); 249 psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_RH", PS_DATA_F32, "half radial moment", Mrh); 250 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX", PS_DATA_F32, "Kron Flux (in 2.5 R1)", Krf); 251 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_ERR", PS_DATA_F32, "Kron Flux Error", dKrf); 252 253 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER", PS_DATA_F32, "Kron Flux (in 2.5 R1)", Kinner); 254 psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER", PS_DATA_F32, "Kron Flux (in 2.5 R1)", Kouter); 255 256 psMetadataAdd (row, PS_LIST_TAIL, "FLAGS", PS_DATA_U32, "psphot analysis flags", source->mode); 257 psMetadataAdd (row, PS_LIST_TAIL, "FLAGS2", PS_DATA_U32, "psphot analysis flags", source->mode2); 208 258 209 259 psVector *radFlux = psVectorAlloc(radMax->n, PS_TYPE_F32); … … 352 402 source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE); 353 403 source->peak->flux = peakFlux; 404 source->peak->xf = PAR[PM_PAR_XPOS]; // more accurate position 405 source->peak->yf = PAR[PM_PAR_YPOS]; // more accurate position 354 406 source->peak->dx = dPAR[PM_PAR_XPOS]; 355 407 source->peak->dy = dPAR[PM_PAR_YPOS]; 356 source->peak->SN = sqrt(source->peak->flux); // XXX a proxy: various functions sort by peak S/N 357 358 source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF"); 408 if (isfinite (source->errMag) && (source->errMag > 0.0)) { 409 source->peak->SN = 1.0 / source->errMag; 410 } else { 411 source->peak->SN = sqrt(source->peak->flux); // an alternate proxy: various functions sort by peak S/N 412 } 413 414 source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF"); 415 source->pixWeightNotPoor = psMetadataLookupF32 (&status, row, "PSF_QF_PERFECT"); 359 416 source->crNsigma = psMetadataLookupF32 (&status, row, "CR_NSIGMA"); 360 417 source->extNsigma = psMetadataLookupF32 (&status, row, "EXT_NSIGMA"); … … 371 428 source->moments->Myy = psMetadataLookupF32 (&status, row, "MOMENTS_YY"); 372 429 430 source->moments->Mrf = psMetadataLookupF32 (&status, row, "MOMENTS_R1"); 431 source->moments->Mrh = psMetadataLookupF32 (&status, row, "MOMENTS_RH"); 432 source->moments->KronFlux = psMetadataLookupF32 (&status, row, "KRON_FLUX"); 433 source->moments->KronFluxErr = psMetadataLookupF32 (&status, row, "KRON_FLUX_ERR"); 434 435 source->moments->KronFinner = psMetadataLookupF32 (&status, row, "KRON_FLUX_INNER"); 436 source->moments->KronFouter = psMetadataLookupF32 (&status, row, "KRON_FLUX_OUTER"); 437 438 // XXX we do not save all of the 3rd and 4th moment parameters. when we load in data, 439 // we are storing enough information so the output will be consistent with the input 440 source->moments->Mxxx = +1.0 * psMetadataLookupF32 (&status, row, "MOMENTS_M3C"); 441 source->moments->Mxxy = 0.0; 442 source->moments->Mxyy = 0.0; 443 source->moments->Myyy = -1.0 * psMetadataLookupF32 (&status, row, "MOMENTS_M3S"); 444 445 source->moments->Mxxxx = +1.00 * psMetadataLookupF32 (&status, row, "MOMENTS_M4C"); 446 source->moments->Mxxxy = 0.0; 447 source->moments->Mxxyy = 0.0; 448 source->moments->Mxyyy = -0.25 * psMetadataLookupF32 (&status, row, "MOMENTS_M4S"); 449 source->moments->Myyyy = 0.0; 450 373 451 source->mode = psMetadataLookupU32 (&status, row, "FLAGS"); 452 source->mode2 = psMetadataLookupU32 (&status, row, "FLAGS2"); 374 453 assert (status); 375 454 … … 391 470 psF32 xErr, yErr; 392 471 int nRow = -1; 472 char keyword1[80], keyword2[80]; 393 473 394 474 // create a header to hold the output data … … 422 502 bool doAnnuli = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI"); 423 503 bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN"); 424 // bool doIsophotal = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ISOPHOTAL");425 // bool doKron = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_KRON");426 504 427 505 psVector *radMin = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.LOWER"); … … 429 507 psAssert (radMin->n == radMax->n, "inconsistent annular bins"); 430 508 431 // int nRadialBins = 0; 432 // if (doAnnuli) { 433 // // get the max count of radial bins 434 // for (int i = 0; i < sources->n; i++) { 435 // pmSource *source = sources->data[i]; 436 // if (!source->extpars) continue; 437 // if (!source->extpars->radProfile ) continue; 438 // if (!source->extpars->radProfile->binSB) continue; 439 // nRadialBins = PS_MAX(nRadialBins, source->extpars->radProfile->binSB->n); 440 // } 441 // } 509 // write the radial profile apertures to header 510 for (int i = 0; i < radMax->n; i++) { 511 sprintf (keyword1, "RMIN_%02d", i); 512 sprintf (keyword2, "RMAX_%02d", i); 513 psMetadataAddF32 (outhead, PS_LIST_TAIL, keyword1, PS_META_REPLACE, "min radius for SB profile", radMin->data.F32[i]); 514 psMetadataAddF32 (outhead, PS_LIST_TAIL, keyword2, PS_META_REPLACE, "min radius for SB profile", radMax->data.F32[i]); 515 } 442 516 443 517 // we write out all sources, regardless of quality. the source flags tell us the state 444 518 for (int i = 0; i < sources->n; i++) { 445 // skip source if it is not a ext sourc446 // XXX we have two places that extended source parameters are measured:447 // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,448 // psphotFitEXT, which does the simple extended source model fit (not psf-convolved)449 // should we require both?450 451 519 pmSource *source = sources->data[i]; 452 520 … … 514 582 } 515 583 516 # if (0)517 // Kron measurements518 if (doKron) {519 pmSourceKronValues *kron = source->extpars->kron;520 if (kron) {521 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG", PS_DATA_F32, "Kron Magnitude", kron->mag);522 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR", PS_DATA_F32, "Kron Magnitude Error", kron->magErr);523 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS", PS_DATA_F32, "Kron Radius", kron->rad);524 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error", kron->radErr);525 } else {526 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG", PS_DATA_F32, "Kron Magnitude", NAN);527 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR", PS_DATA_F32, "Kron Magnitude Error", NAN);528 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS", PS_DATA_F32, "Kron Radius", NAN);529 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error", NAN);530 }531 }532 533 // Isophot measurements534 // XXX insert header data: isophotal level535 if (doIsophotal) {536 pmSourceIsophotalValues *isophot = source->extpars->isophot;537 if (isophot) {538 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG", PS_DATA_F32, "Isophot Magnitude", isophot->mag);539 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR", PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);540 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS", PS_DATA_F32, "Isophot Radius", isophot->rad);541 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error", isophot->radErr);542 } else {543 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG", PS_DATA_F32, "Isophot Magnitude", NAN);544 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR", PS_DATA_F32, "Isophot Magnitude Error", NAN);545 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS", PS_DATA_F32, "Isophot Radius", NAN);546 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error", NAN);547 }548 }549 # endif550 551 584 // Flux Annuli (if we have extended source measurements, we have these. only optionally save them) 552 585 if (doAnnuli) { … … 616 649 617 650 // XXX this layout is still the same as PS1_DEV_1 618 bool pmSourcesWrite_CMF_PS1_SV1_XFIT (psFits *fits, pmReadout *readout, psArray *sources, char *extname)651 bool pmSourcesWrite_CMF_PS1_SV1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname) 619 652 { 620 653 … … 665 698 assert (model); 666 699 700 // skip models which were not actually fitted 701 if (model->flags & PM_MODEL_STATUS_BADARGS) continue; 702 667 703 PAR = model->params->data.F32; 668 704 dPAR = model->dparams->data.F32; -
trunk/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c
r27818 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 … … 45 54 // followed by a zero-size matrix, followed by the table data 46 55 47 bool pmSourcesWrite_CMF_PS1_V1 (psFits *fits, pmReadout *readout, psArray *sources, 48 psMetadata *imageHeader, psMetadata *tableHeader, char *extname) 56 bool pmSourcesWrite_CMF_PS1_V1 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe) 49 57 { 50 58 PS_ASSERT_PTR_NON_NULL(fits, false); … … 184 192 psMetadataAdd (row, PS_LIST_TAIL, "PSF_MINOR", PS_DATA_F32, "PSF width (minor axis)", axes.minor); 185 193 psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA", PS_DATA_F32, "PSF orientation angle", axes.theta); 186 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeight );194 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeightNotBad); 187 195 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NDOF", PS_DATA_S32, "degrees of freedom", nDOF); 188 196 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX", PS_DATA_S32, "number of pixels in fit", nPix); … … 310 318 source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE); 311 319 source->peak->flux = peakFlux; 320 source->peak->xf = PAR[PM_PAR_XPOS]; // more accurate position 321 source->peak->yf = PAR[PM_PAR_YPOS]; // more accurate position 312 322 source->peak->dx = dPAR[PM_PAR_XPOS]; 313 323 source->peak->dy = dPAR[PM_PAR_YPOS]; 314 315 source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF"); 324 if (isfinite (source->errMag) && (source->errMag > 0.0)) { 325 source->peak->SN = 1.0 / source->errMag; 326 } else { 327 source->peak->SN = sqrt(source->peak->flux); // an alternate proxy: various functions sort by peak S/N 328 } 329 330 source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF"); 316 331 source->crNsigma = psMetadataLookupF32 (&status, row, "CR_NSIGMA"); 317 332 source->extNsigma = psMetadataLookupF32 (&status, row, "EXT_NSIGMA"); … … 516 531 517 532 // XXX this layout is still the same as PS1_DEV_1 518 bool pmSourcesWrite_CMF_PS1_V1_XFIT (psFits *fits, pmReadout *readout, psArray *sources, char *extname)533 bool pmSourcesWrite_CMF_PS1_V1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname) 519 534 { 520 535 … … 565 580 assert (model); 566 581 582 // skip models which were not actually fitted 583 if (model->flags & PM_MODEL_STATUS_BADARGS) continue; 584 567 585 PAR = model->params->data.F32; 568 586 dPAR = model->dparams->data.F32; -
trunk/psModules/src/objects/pmSourceIO_CMF_PS1_V2.c
r27818 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 … … 45 54 // followed by a zero-size matrix, followed by the table data 46 55 47 bool pmSourcesWrite_CMF_PS1_V2 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname )56 bool pmSourcesWrite_CMF_PS1_V2 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe) 48 57 { 49 58 PS_ASSERT_PTR_NON_NULL(fits, false); … … 182 191 psMetadataAdd (row, PS_LIST_TAIL, "PSF_MINOR", PS_DATA_F32, "PSF width (minor axis)", axes.minor); 183 192 psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA", PS_DATA_F32, "PSF orientation angle", axes.theta); 184 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeight );193 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeightNotBad); 185 194 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NDOF", PS_DATA_S32, "degrees of freedom", nDOF); 186 195 psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX", PS_DATA_S32, "number of pixels in fit", nPix); … … 314 323 source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE); 315 324 source->peak->flux = peakFlux; 325 source->peak->xf = PAR[PM_PAR_XPOS]; // more accurate position 326 source->peak->yf = PAR[PM_PAR_YPOS]; // more accurate position 316 327 source->peak->dx = dPAR[PM_PAR_XPOS]; 317 328 source->peak->dy = dPAR[PM_PAR_YPOS]; 318 source->peak->SN = sqrt(source->peak->flux); // XXX a proxy: various functions sort by peak S/N 319 320 source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF"); 329 if (isfinite (source->errMag) && (source->errMag > 0.0)) { 330 source->peak->SN = 1.0 / source->errMag; 331 } else { 332 source->peak->SN = sqrt(source->peak->flux); // an alternate proxy: various functions sort by peak S/N 333 } 334 335 source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF"); 321 336 source->crNsigma = psMetadataLookupF32 (&status, row, "CR_NSIGMA"); 322 337 source->extNsigma = psMetadataLookupF32 (&status, row, "EXT_NSIGMA"); … … 578 593 579 594 // XXX this layout is still the same as PS1_DEV_1 580 bool pmSourcesWrite_CMF_PS1_V2_XFIT (psFits *fits, pmReadout *readout, psArray *sources, char *extname)595 bool pmSourcesWrite_CMF_PS1_V2_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname) 581 596 { 582 597 … … 627 642 assert (model); 628 643 644 // skip models which were not actually fitted 645 if (model->flags & PM_MODEL_STATUS_BADARGS) continue; 646 629 647 PAR = model->params->data.F32; 630 648 dPAR = model->dparams->data.F32; -
trunk/psModules/src/objects/pmSourceIO_CMP.c
r20937 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 -
trunk/psModules/src/objects/pmSourceIO_MatchedRefs.c
r27177 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 51 42 52 #include "pmAstrometryObjects.h" 43 53 #include "pmAstrometryWCS.h" -
trunk/psModules/src/objects/pmSourceIO_OBJ.c
r20937 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 -
trunk/psModules/src/objects/pmSourceIO_PS1_CAL_0.c
r25979 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 … … 49 58 // XXX how do I generate the source tables which I need to send to PSPS? 50 59 51 bool pmSourcesWrite_PS1_CAL_0 (psFits *fits, pmReadout *readout, psArray *sources, 52 psMetadata *imageHeader, psMetadata *tableHeader, char *extname) 60 bool pmSourcesWrite_PS1_CAL_0 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe) 53 61 { 54 62 PS_ASSERT_PTR_NON_NULL(fits, false); … … 180 188 psMetadataAdd (row, PS_LIST_TAIL, "PSF_WIDTH_Y", PS_DATA_F32, "PSF width in y coordinate", axes.minor); 181 189 psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA", PS_DATA_F32, "PSF orientation angle", axes.theta); 182 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeight );190 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeightNotBad); 183 191 184 192 // XXX not sure how to get this : need to load Nimages with weight? … … 289 297 source->peak->dx = dPAR[PM_PAR_XPOS]; 290 298 source->peak->dy = dPAR[PM_PAR_YPOS]; 291 292 source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF"); 299 source->peak->xf = PAR[PM_PAR_XPOS]; // more accurate position 300 source->peak->yf = PAR[PM_PAR_YPOS]; // more accurate position 301 302 source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF"); 293 303 294 304 // note that some older versions used PSF_PROBABILITY: this was not well defined. … … 597 607 assert (model); 598 608 609 // skip models which were not actually fitted 610 if (model->flags & PM_MODEL_STATUS_BADARGS) continue; 611 599 612 PAR = model->params->data.F32; 600 613 dPAR = model->dparams->data.F32; -
trunk/psModules/src/objects/pmSourceIO_PS1_DEV_0.c
r25979 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 … … 49 58 // XXX how do I generate the source tables which I need to send to PSPS? 50 59 // XXX: input parameter imageHeader is never used. 51 bool pmSourcesWrite_PS1_DEV_0 (psFits *fits, psArray *sources, psMetadata *imageHeader, 52 psMetadata *tableHeader, char *extname) 60 bool pmSourcesWrite_PS1_DEV_0 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe) 53 61 { 54 62 PS_ASSERT_PTR_NON_NULL(fits, false); … … 117 125 psMetadataAdd (row, PS_LIST_TAIL, "PSF_WIDTH_Y", PS_DATA_F32, "PSF width in y coordinate", axes.minor); 118 126 psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA", PS_DATA_F32, "PSF orientation angle", axes.theta); 119 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeight );127 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeightNotBad); 120 128 // XXX not sure how to get this : need to load Nimages with weight 121 129 psMetadataAdd (row, PS_LIST_TAIL, "N_FRAMES", PS_DATA_U16, "Number of frames overlapping source center", nImageOverlap); … … 215 223 source->peak->dx = dPAR[PM_PAR_XPOS]; 216 224 source->peak->dy = dPAR[PM_PAR_YPOS]; 217 218 source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF"); 225 source->peak->xf = PAR[PM_PAR_XPOS]; // more accurate position 226 source->peak->yf = PAR[PM_PAR_YPOS]; // more accurate position 227 228 source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF"); 219 229 220 230 // XXX other values saved but not loaded? … … 228 238 return (sources); 229 239 } 240 241 bool pmSourcesWrite_PS1_DEV_0_XSRC (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 242 { 243 return true; 244 } 245 246 bool pmSourcesWrite_PS1_DEV_0_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname) 247 { 248 return true; 249 } -
trunk/psModules/src/objects/pmSourceIO_PS1_DEV_1.c
r25979 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 … … 47 56 // this output format is valid for psphot analysis of an image, and does not include calibrated 48 57 // values derived in the DVO database. 49 // XXX how do I generate the source tables which I need to send to PSPS? 50 51 bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, 52 psMetadata *imageHeader, psMetadata *tableHeader, char *extname) 58 59 bool pmSourcesWrite_PS1_DEV_1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe) 53 60 { 54 61 PS_ASSERT_PTR_NON_NULL(fits, false); … … 142 149 psMetadataAdd (row, PS_LIST_TAIL, "PSF_WIDTH_Y", PS_DATA_F32, "PSF width in y coordinate", axes.minor); 143 150 psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA", PS_DATA_F32, "PSF orientation angle", axes.theta); 144 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeight );151 psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF", PS_DATA_F32, "PSF coverage/quality factor", source->pixWeightNotBad); 145 152 146 153 // XXX not sure how to get this : need to load Nimages with weight? … … 259 266 source->peak->dx = dPAR[PM_PAR_XPOS]; 260 267 source->peak->dy = dPAR[PM_PAR_YPOS]; 261 262 source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF"); 268 source->peak->xf = PAR[PM_PAR_XPOS]; // more accurate position 269 source->peak->yf = PAR[PM_PAR_YPOS]; // more accurate position 270 271 source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF"); 263 272 264 273 // note that some older versions used PSF_PROBABILITY: this was not well defined. … … 281 290 } 282 291 283 bool pmSourcesWrite_PS1_DEV_1_XSRC (psFits *fits, p sArray *sources, char *extname, psMetadata *recipe)292 bool pmSourcesWrite_PS1_DEV_1_XSRC (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 284 293 { 285 294 … … 453 462 } 454 463 455 bool pmSourcesWrite_PS1_DEV_1_XFIT (psFits *fits, psArray *sources, char *extname)464 bool pmSourcesWrite_PS1_DEV_1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname) 456 465 { 457 466 … … 502 511 assert (model); 503 512 513 // skip models which were not actually fitted 514 if (model->flags & PM_MODEL_STATUS_BADARGS) continue; 515 504 516 PAR = model->params->data.F32; 505 517 dPAR = model->dparams->data.F32; -
trunk/psModules/src/objects/pmSourceIO_RAW.c
r25754 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 41 #include "pmSourcePhotometry.h" 48 #include "pmPSFtry.h" 49 42 50 #include "pmSourceIO.h" 43 51 … … 120 128 source[0].peak->SN, 121 129 source[0].apRadius, 122 source[0].pixWeight ,130 source[0].pixWeightNotBad, 123 131 model[0].nDOF, 124 132 model[0].nIter); … … 182 190 source[0].peak->SN, 183 191 source[0].apRadius, 184 source[0].pixWeight ,192 source[0].pixWeightNotBad, 185 193 model[0].nDOF, 186 194 model[0].nIter); -
trunk/psModules/src/objects/pmSourceIO_SMPDATA.c
r25979 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmResiduals.h" 35 #include "pmGrowthCurve.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 … … 45 54 // followed by a zero-size matrix, followed by the table data 46 55 // XXX: input parameter imageHeader is never used 47 bool pmSourcesWrite_SMPDATA (psFits *fits, psArray *sources, psMetadata *imageHeader, 48 psMetadata *tableHeader, char *extname) 56 bool pmSourcesWrite_SMPDATA (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe) 49 57 { 50 58 PS_ASSERT_PTR_NON_NULL(fits, false); … … 106 114 psMetadataAdd (row, PS_LIST_TAIL, "THETA", PS_DATA_F32, "", axes.theta); 107 115 psMetadataAdd (row, PS_LIST_TAIL, "DOPHOT", PS_DATA_U8, "", type); 108 psMetadataAdd (row, PS_LIST_TAIL, "WEIGHT", PS_DATA_U8, "", PS_MIN (255, PS_MAX(0, 255*source->pixWeight )));116 psMetadataAdd (row, PS_LIST_TAIL, "WEIGHT", PS_DATA_U8, "", PS_MIN (255, PS_MAX(0, 255*source->pixWeightNotBad))); 109 117 psMetadataAdd (row, PS_LIST_TAIL, "DUMMY", PS_DATA_U16, "", 0); 110 118 … … 189 197 source->apMag = psMetadataLookupF32 (&status, row, "MAG_AP") - ZERO_POINT; 190 198 191 source->pixWeight = psMetadataLookupU8 (&status, row, "WEIGHT")/255.0;199 source->pixWeightNotBad = psMetadataLookupU8 (&status, row, "WEIGHT")/255.0; 192 200 int dophot = psMetadataLookupU8 (&status, row, "DOPHOT"); 193 201 pmSourceSetDophotType (source, dophot); … … 204 212 return (sources); 205 213 } 214 215 bool pmSourcesWrite_SMPDATA_XSRC (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 216 { 217 return true; 218 } 219 220 bool pmSourcesWrite_SMPDATA_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname) 221 { 222 return true; 223 } -
trunk/psModules/src/objects/pmSourceIO_SX.c
r20937 r29004 28 28 #include "pmFPAfile.h" 29 29 30 #include "pmTrend2D.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 30 33 #include "pmSpan.h" 34 #include "pmFootprintSpans.h" 31 35 #include "pmFootprint.h" 32 36 #include "pmPeaks.h" 33 37 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 38 #include "pmModelFuncs.h" 39 #include "pmModel.h" 40 #include "pmModelUtils.h" 41 #include "pmModelClass.h" 42 #include "pmSourceMasks.h" 43 #include "pmSourceExtendedPars.h" 44 #include "pmSourceDiffStats.h" 45 #include "pmSource.h" 46 #include "pmSourceFitModel.h" 37 47 #include "pmPSF.h" 38 #include "pmModel.h" 39 #include "pmSource.h" 40 #include "pmModelClass.h" 48 #include "pmPSFtry.h" 49 41 50 #include "pmSourceIO.h" 42 51 -
trunk/psModules/src/objects/pmSourceMasks.h
r24694 r29004 39 39 } pmSourceMode; 40 40 41 // Bit flags to distinguish analysis results 42 // When adding to or subtracting from this list, please also modify pmSourceMaskHeader 43 typedef enum { 44 PM_SOURCE_MODE2_DEFAULT = 0x00000000, ///< Initial value: resets all bits 45 PM_SOURCE_MODE2_DIFF_WITH_SINGLE = 0x00000001, ///< diff source matched to a single positive detection 46 PM_SOURCE_MODE2_DIFF_WITH_DOUBLE = 0x00000002, ///< diff source matched to positive detections in both images 47 } pmSourceMode2; 41 48 42 49 /// Populate header with mask values -
trunk/psModules/src/objects/pmSourceMatch.c
r28518 r29004 6 6 #include <string.h> 7 7 #include <pslib.h> 8 8 #include "pmHDU.h" 9 #include "pmFPA.h" 10 11 #include "pmTrend2D.h" 12 #include "pmResiduals.h" 13 #include "pmGrowthCurve.h" 14 #include "pmSpan.h" 15 #include "pmFootprintSpans.h" 16 #include "pmFootprint.h" 17 #include "pmPeaks.h" 18 #include "pmMoments.h" 19 #include "pmModelFuncs.h" 20 #include "pmModel.h" 21 #include "pmModelUtils.h" 22 #include "pmModelClass.h" 23 #include "pmSourceMasks.h" 24 #include "pmSourceExtendedPars.h" 25 #include "pmSourceDiffStats.h" 9 26 #include "pmSource.h" 27 #include "pmSourceFitModel.h" 28 #include "pmPSF.h" 29 #include "pmPSFtry.h" 30 #include "pmDetections.h" 31 10 32 #include "pmErrorCodes.h" 11 33 -
trunk/psModules/src/objects/pmSourceMatch.h
r26076 r29004 1 1 #ifndef PM_SOURCE_MATCH_H 2 2 #define PM_SOURCE_MATCH_H 3 4 #include <pslib.h>5 3 6 4 /// Mask values for matched sources -
trunk/psModules/src/objects/pmSourceMoments.c
r27531 r29004 22 22 #include <strings.h> 23 23 #include <pslib.h> 24 24 25 #include "pmHDU.h" 25 26 #include "pmFPA.h" 26 #include "pmFPAMaskWeight.h" 27 28 #include "pmTrend2D.h" 29 #include "pmResiduals.h" 30 #include "pmGrowthCurve.h" 27 31 #include "pmSpan.h" 32 #include "pmFootprintSpans.h" 28 33 #include "pmFootprint.h" 29 34 #include "pmPeaks.h" 30 35 #include "pmMoments.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 33 #include "pmTrend2D.h" 34 #include "pmPSF.h" 36 #include "pmModelFuncs.h" 35 37 #include "pmModel.h" 38 #include "pmModelUtils.h" 39 #include "pmModelClass.h" 40 #include "pmSourceMasks.h" 41 #include "pmSourceExtendedPars.h" 42 #include "pmSourceDiffStats.h" 36 43 #include "pmSource.h" 37 44 … … 54 61 # define VALID_RADIUS(X,Y,RAD2) (((RAD2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0) 55 62 63 static bool beVerbose = false; 64 void pmSourceMomentsSetVerbose(bool state){ beVerbose = state; } 65 56 66 bool pmSourceMoments(pmSource *source, psF32 radius, psF32 sigma, psF32 minSN, psImageMaskType maskVal) 57 67 { … … 61 71 PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false); 62 72 63 // use sky from moments if defined, 0.0 otherwise 73 // use sky from moments if defined, 0.0 otherwise 74 75 // XXX this value comes from the sky model at the source center, and tends to over-estimate 76 // the sky in the vicinity of bright sources. we are better off assuming the model worked 77 // well: 64 78 psF32 sky = 0.0; 65 if (source->moments == NULL) {66 source->moments = pmMomentsAlloc();67 } else {68 sky = source->moments->Sky;69 }79 // XXX if (source->moments == NULL) { 80 // XXX source->moments = pmMomentsAlloc(); 81 // XXX } else { 82 // XXX sky = source->moments->Sky; 83 // XXX } 70 84 71 85 // First Pass: calculate the first moments (these are subtracted from the coordinates below) … … 131 145 psF32 wDiff = *vWgt; 132 146 133 // skip pixels below specified significance level. this is allowed, but should be 134 // avoided -- the over-weights the wings of bright stars compared to those of faint 135 // stars. 136 if (PS_SQR(pDiff) < minSN2*wDiff) continue; 137 // if (pDiff < 0) continue; // XXX : MWV says I should include < 0.0 valued points... 147 // skip pixels below specified significance level. for a PSFs, this 148 // over-weights the wings of bright stars compared to those of faint stars. 149 // for the estimator used for extended source analysis (where the window 150 // function is allowed to be arbitrarily large), we need to clip to avoid 151 // negative second moments. 152 if (PS_SQR(pDiff) < minSN2*wDiff) continue; // 153 if ((minSN > 0.0) && (pDiff < 0)) continue; // 138 154 139 155 // Apply a Gaussian window function. Be careful with the window function. S/N … … 197 213 // Xn = SUM (x - xc)^n * (z - sky) 198 214 215 psF32 RF = 0.0; 216 psF32 RH = 0.0; 217 psF32 RS = 0.0; 199 218 psF32 XX = 0.0; 200 219 psF32 XY = 0.0; … … 244 263 if (r > radius) continue; 245 264 246 psF32 pDiff = *vPix - sky; 265 psF32 fDiff = *vPix - sky; 266 psF32 pDiff = fDiff; 247 267 psF32 wDiff = *vWgt; 248 268 … … 257 277 if (sigma > 0.0) { 258 278 // XXX a lot of extra flops; can we do pre-calculate? 259 psF32 z = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2; 279 // XXX we were re-calculating r2 (maybe the compiler caught this?) 280 // psF32 z = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2; 281 psF32 z = r2 * rsigma2; 260 282 assert (z >= 0.0); 261 283 psF32 weight = exp(-z); … … 266 288 267 289 Sum += pDiff; 290 291 # if (1) 292 # if (0) 293 if (fDiff < 0) continue; 294 # endif 295 psF32 rf = r * fDiff; 296 psF32 rh = sqrt(r) * fDiff; 297 psF32 rs = fDiff; 298 # else 299 psF32 rf = r * pDiff; 300 psF32 rh = sqrt(r) * pDiff; 301 psF32 rs = pDiff; 302 # endif 268 303 269 304 psF32 x = xDiff * pDiff; … … 284 319 psF32 xyyy = xDiff * yyy / r2; 285 320 psF32 yyyy = yDiff * yyy / r2; 321 322 RF += rf; 323 RH += rh; 324 RS += rs; 286 325 287 326 XX += xx; … … 302 341 } 303 342 343 source->moments->Mrf = RF/RS; 344 source->moments->Mrh = RH/RS; 345 304 346 source->moments->Mxx = XX/Sum; 305 347 source->moments->Mxy = XY/Sum; … … 317 359 source->moments->Myyyy = YYYY/Sum; 318 360 319 // if (source->moments->Mxx < 0) { 320 // fprintf (stderr, "error: neg second moment??\n"); 321 // } 322 // if (source->moments->Myy < 0) { 323 // fprintf (stderr, "error: neg second moment??\n"); 324 // } 325 326 psTrace ("psModules.objects", 4, "Mxx: %f Mxy: %f Myy: %f Mxxx: %f Mxxy: %f Mxyy: %f Myyy: %f Mxxxx: %f Mxxxy: %f Mxxyy: %f Mxyyy: %f Mxyyy: %f\n", 361 // Calculate the Kron magnitude (make this block optional?) 362 // float radKron = 2.5*source->moments->Mrf; 363 float radKinner = 1.0*source->moments->Mrf; 364 float radKron = 2.5*source->moments->Mrf; 365 float radKouter = 4.0*source->moments->Mrf; 366 367 int nKronPix = 0; 368 Sum = Var = 0.0; 369 float SumInner = 0.0; 370 float SumOuter = 0.0; 371 372 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 373 374 psF32 yDiff = row - yCM; 375 if (fabs(yDiff) > radKron) continue; 376 377 psF32 *vPix = source->pixels->data.F32[row]; 378 psF32 *vWgt = source->variance->data.F32[row]; 379 psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row]; 380 381 for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) { 382 if (vMsk) { 383 if (*vMsk & maskVal) { 384 vMsk++; 385 continue; 386 } 387 vMsk++; 388 } 389 if (isnan(*vPix)) continue; 390 391 psF32 xDiff = col - xCM; 392 if (fabs(xDiff) > radKron) continue; 393 394 // radKron is just a function of (xDiff, yDiff) 395 psF32 r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 396 psF32 r = sqrt(r2); 397 398 psF32 pDiff = *vPix - sky; 399 psF32 wDiff = *vWgt; 400 401 // skip pixels below specified significance level. this is allowed, but should be 402 // avoided -- the over-weights the wings of bright stars compared to those of faint 403 // stars. 404 if (PS_SQR(pDiff) < minSN2*wDiff) continue; 405 406 if (r < radKron) { 407 Sum += pDiff; 408 Var += wDiff; 409 nKronPix ++; 410 // if (beVerbose) fprintf (stderr, "mome: %d %d %f %f %f\n", col, row, sky, *vPix, Sum); 411 } 412 413 if ((r > radKinner) && (r < radKron)) { 414 SumInner += pDiff; 415 } 416 if ((r > radKron) && (r < radKouter)) { 417 SumOuter += pDiff; 418 } 419 } 420 } 421 source->moments->KronFlux = Sum; 422 source->moments->KronFinner = SumInner; 423 source->moments->KronFouter = SumOuter; 424 source->moments->KronFluxErr = sqrt(Var); 425 426 psTrace ("psModules.objects", 4, "Mrf: %f KronFlux: %f Mxx: %f Mxy: %f Myy: %f Mxxx: %f Mxxy: %f Mxyy: %f Myyy: %f Mxxxx: %f Mxxxy: %f Mxxyy: %f Mxyyy: %f Mxyyy: %f\n", 427 source->moments->Mrf, source->moments->KronFlux, 327 428 source->moments->Mxx, source->moments->Mxy, source->moments->Myy, 328 429 source->moments->Mxxx, source->moments->Mxxy, source->moments->Mxyy, source->moments->Myyy, -
trunk/psModules/src/objects/pmSourcePhotometry.c
r28517 r29004 22 22 #include "pmFPA.h" 23 23 #include "pmFPAMaskWeight.h" 24 25 #include "pmTrend2D.h" 26 #include "pmResiduals.h" 27 #include "pmGrowthCurve.h" 24 28 #include "pmSpan.h" 29 #include "pmFootprintSpans.h" 25 30 #include "pmFootprint.h" 26 31 #include "pmPeaks.h" 27 32 #include "pmMoments.h" 28 #include "pmGrowthCurve.h" 29 #include "pmResiduals.h" 30 #include "pmTrend2D.h" 33 #include "pmModelFuncs.h" 34 #include "pmModel.h" 35 #include "pmModelUtils.h" 36 #include "pmModelClass.h" 37 #include "pmSourceMasks.h" 38 #include "pmSourceExtendedPars.h" 39 #include "pmSourceDiffStats.h" 40 #include "pmSource.h" 41 #include "pmSourceFitModel.h" 31 42 #include "pmPSF.h" 32 #include "pmModel.h" 33 #include "pmSource.h" 34 #include "pmModelClass.h" 43 #include "pmPSFtry.h" 44 35 45 #include "pmSourcePhotometry.h" 36 46 … … 66 76 67 77 // XXX masked region should be (optionally) elliptical 68 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal )78 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal) 69 79 { 70 80 PS_ASSERT_PTR_NON_NULL(source, false); … … 122 132 for (int i = 0; i < source->modelFits->n; i++) { 123 133 pmModel *model = source->modelFits->data[i]; 134 if (model->flags & PM_MODEL_STATUS_BADARGS) continue; 124 135 status = pmSourcePhotometryModel (&model->mag, NULL, model); 125 136 if (model == source->modelEXT) foundEXT = true; … … 145 156 // measure the contribution of included pixels 146 157 if (mode & PM_SOURCE_PHOT_WEIGHT) { 147 pmSourcePixelWeight (&source->pixWeight , model, source->maskObj, maskVal);158 pmSourcePixelWeight (&source->pixWeightNotBad, &source->pixWeightNotPoor, model, source->maskObj, maskVal, markVal); 148 159 } 149 160 150 161 // measure the contribution of included pixels 151 162 if (mode & PM_SOURCE_PHOT_DIFFSTATS) { 152 pmSourceMeasureDiffStats (source, maskVal );163 pmSourceMeasureDiffStats (source, maskVal, markVal); 153 164 } 154 165 … … 191 202 192 203 // measure object aperture photometry 193 status = pmSourcePhotometryAper (&source->apMag , model, flux, mask, maskVal);204 status = pmSourcePhotometryAper (&source->apMagRaw, model, flux, mask, maskVal); 194 205 if (!status) { 195 206 psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag"); … … 199 210 // if the aper mag is NAN, the flux < 0. this can happen for sources near the 200 211 // detection limits (esp near bright neighbors) 212 source->apMag = source->apMagRaw; 201 213 if (isfinite (source->apMag) && isPSF && psf) { 202 214 if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) { 203 source->apMag +=pmGrowthCurveCorrect (psf->growth, source->apRadius);215 source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius); 204 216 } 205 217 if (mode & PM_SOURCE_PHOT_APCORR) { 206 218 // XXX this should be removed -- we no longer fit for the 'sky bias' 219 // XXX is this happening??? 207 220 rflux = pow (10.0, 0.4*source->psfMag); 221 psAssert (psf->skyBias == 0.0, "sky bias not 0"); 222 psAssert (psf->skySat == 0.0, "sky sat not 0"); 208 223 source->apMag -= PS_SQR(source->apRadius)*rflux * psf->skyBias + psf->skySat / rflux; 209 224 } … … 257 272 PS_ASSERT_PTR_NON_NULL(image, false); 258 273 PS_ASSERT_PTR_NON_NULL(mask, false); 259 PS_ASSERT_PTR_NON_NULL(model, false); 274 275 if (DO_SKY) { 276 PS_ASSERT_PTR_NON_NULL(model, false); 277 } 260 278 261 279 float apSum = 0; … … 271 289 psF32 **imData = image->data.F32; 272 290 psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA; 291 int nAperPix = 0; 273 292 274 293 // measure apMag 275 for (int i x = 0; ix < image->numCols; ix++) {276 for (int iy = 0; iy < image->numRows; iy++) {294 for (int iy = 0; iy < image->numRows; iy++) { 295 for (int ix = 0; ix < image->numCols; ix++) { 277 296 if (mkData[iy][ix] & maskVal) 278 297 continue; 279 298 apSum += imData[iy][ix] - sky; 299 nAperPix ++; 300 // fprintf (stderr, "aper: %d %d %f %f %f\n", ix, iy, sky, imData[iy][ix], apSum); 280 301 } 281 302 } … … 290 311 291 312 // return source aperture magnitude 292 bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *mask, psImageMaskType maskVal) 293 { 294 PS_ASSERT_PTR_NON_NULL(pixWeight, false); 313 bool pmSourcePixelWeight (float *pixWeightNotBad, float *pixWeightNotPoor, pmModel *model, psImage *mask, psImageMaskType maskVal, psImageMaskType markVal) 314 { 315 PS_ASSERT_PTR_NON_NULL(pixWeightNotBad, false); 316 PS_ASSERT_PTR_NON_NULL(pixWeightNotPoor, false); 295 317 PS_ASSERT_PTR_NON_NULL(mask, false); 296 318 PS_ASSERT_PTR_NON_NULL(model, false); 297 319 298 320 float modelSum = 0; 299 float validSum = 0; 321 float notBadSum = 0; 322 float notPoorSum = 0; 300 323 float sky = 0; 301 324 float value; … … 305 328 int dY, DY, NY; 306 329 307 *pixWeight = 0.0; 330 *pixWeightNotBad = 0.0; 331 *pixWeightNotPoor = 0.0; 308 332 309 333 // we only care about the value of the object model, not the local sky … … 345 369 346 370 // for the full model, add all points 347 value = model->modelFunc (NULL, params, coord) - sky;371 value = fabs(model->modelFunc (NULL, params, coord) - sky); 348 372 modelSum += value; 349 373 350 374 // include count only the unmasked pixels within the image area 351 if (mx < 0) 352 continue; 353 if (my < 0) 354 continue; 355 if (mx >= NX) 356 continue; 357 if (my >= NY) 358 continue; 359 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal) 360 continue; 361 362 validSum += value; 375 if (mx < 0) continue; 376 if (my < 0) continue; 377 if (mx >= NX) continue; 378 if (my >= NY) continue; 379 380 if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) { 381 notBadSum += value; 382 } 383 if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & ~markVal)) { 384 notPoorSum += value; 385 } 363 386 } 364 387 } 365 388 psFree (coord); 366 389 367 if (validSum <= 0) 368 return false; 369 370 *pixWeight = validSum / modelSum; 390 *pixWeightNotBad = notBadSum / modelSum; 391 *pixWeightNotPoor = notPoorSum / modelSum; 392 371 393 return (true); 372 394 } … … 374 396 # define FLUX_LIMIT 3.0 375 397 376 // return source aperture magnitude377 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal )398 // measure stats that may be using in difference images for distinguishing real sources from bad residuals 399 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) 378 400 { 379 401 PS_ASSERT_PTR_NON_NULL(source, false); … … 399 421 for (int iy = 0; iy < flux->numRows; iy++) { 400 422 for (int ix = 0; ix < flux->numCols; ix++) { 423 // only count up the stats in the unmarked region (ie, the aperture) 424 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & markVal) { 425 continue; 426 } 401 427 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) { 402 428 nMask ++; -
trunk/psModules/src/objects/pmSourcePhotometry.h
r28426 r29004 52 52 53 53 bool pmSourceMagnitudesInit (psMetadata *config); 54 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal); 55 bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *mask, psImageMaskType maskVal); 54 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal); 55 56 bool pmSourcePixelWeight (float *pixWeightNotBad, float *pixWeightNotPoor, pmModel *model, psImage *mask, psImageMaskType maskVal, psImageMaskType markVal); 57 56 58 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psImageMaskType maskVal, const float covarFactor); 57 59 58 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal );60 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal); 59 61 60 62 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal); -
trunk/psModules/src/objects/pmSourcePlotApResid.c
r26893 r29004 25 25 #include "pmFPAview.h" 26 26 #include "pmFPAfile.h" 27 28 #include "pmTrend2D.h" 29 #include "pmResiduals.h" 30 #include "pmGrowthCurve.h" 27 31 #include "pmSpan.h" 32 #include "pmFootprintSpans.h" 28 33 #include "pmFootprint.h" 29 34 #include "pmPeaks.h" 30 35 #include "pmMoments.h" 31 #include "pmResiduals.h" 32 #include "pmGrowthCurve.h" 33 #include "pmTrend2D.h" 36 #include "pmModelFuncs.h" 37 #include "pmModel.h" 38 #include "pmModelUtils.h" 39 #include "pmModelClass.h" 40 #include "pmSourceMasks.h" 41 #include "pmSourceExtendedPars.h" 42 #include "pmSourceDiffStats.h" 43 #include "pmSource.h" 44 #include "pmSourceFitModel.h" 34 45 #include "pmPSF.h" 35 #include "pmModel.h"36 46 #include "pmDetections.h" 37 #include "pmSource.h" 47 38 48 #include "pmSourcePlots.h" 39 49 #include "pmKapaPlots.h" -
trunk/psModules/src/objects/pmSourcePlotMoments.c
r26893 r29004 28 28 #include "pmFPAview.h" 29 29 #include "pmFPAfile.h" 30 31 #include "pmTrend2D.h" 32 #include "pmResiduals.h" 33 #include "pmGrowthCurve.h" 30 34 #include "pmSpan.h" 35 #include "pmFootprintSpans.h" 31 36 #include "pmFootprint.h" 32 37 #include "pmPeaks.h" 33 38 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 39 #include "pmModelFuncs.h" 40 #include "pmModel.h" 41 #include "pmModelUtils.h" 42 #include "pmModelClass.h" 43 #include "pmSourceMasks.h" 44 #include "pmSourceExtendedPars.h" 45 #include "pmSourceDiffStats.h" 46 #include "pmSource.h" 47 #include "pmSourceFitModel.h" 37 48 #include "pmPSF.h" 38 #include "pmModel.h"39 49 #include "pmDetections.h" 40 #include "pmSource.h"41 50 #include "pmSourcePlots.h" 42 51 #include "pmKapaPlots.h" -
trunk/psModules/src/objects/pmSourcePlotPSFModel.c
r26893 r29004 28 28 #include "pmFPAview.h" 29 29 #include "pmFPAfile.h" 30 31 32 #include "pmTrend2D.h" 33 #include "pmResiduals.h" 34 #include "pmGrowthCurve.h" 30 35 #include "pmSpan.h" 36 #include "pmFootprintSpans.h" 31 37 #include "pmFootprint.h" 32 38 #include "pmPeaks.h" 33 39 #include "pmMoments.h" 34 #include "pmGrowthCurve.h" 35 #include "pmResiduals.h" 36 #include "pmTrend2D.h" 40 #include "pmModelFuncs.h" 41 #include "pmModel.h" 42 #include "pmModelUtils.h" 43 #include "pmModelClass.h" 44 #include "pmSourceMasks.h" 45 #include "pmSourceExtendedPars.h" 46 #include "pmSourceDiffStats.h" 47 #include "pmSource.h" 48 #include "pmSourceFitModel.h" 37 49 #include "pmPSF.h" 38 #include "pmModel.h"39 50 #include "pmDetections.h" 40 #include "pmSource.h"41 51 #include "pmSourcePlots.h" 42 52 #include "pmKapaPlots.h" -
trunk/psModules/src/objects/pmSourceSky.c
r23187 r29004 21 21 #include <string.h> 22 22 #include <pslib.h> 23 23 24 #include "pmHDU.h" 24 25 #include "pmFPA.h" 25 #include "pmFPAMaskWeight.h" 26 27 #include "pmTrend2D.h" 28 #include "pmResiduals.h" 29 #include "pmGrowthCurve.h" 26 30 #include "pmSpan.h" 31 #include "pmFootprintSpans.h" 27 32 #include "pmFootprint.h" 28 33 #include "pmPeaks.h" 29 34 #include "pmMoments.h" 30 #include "pmResiduals.h" 31 #include "pmGrowthCurve.h" 32 #include "pmTrend2D.h" 33 #include "pmPSF.h" 35 #include "pmModelFuncs.h" 34 36 #include "pmModel.h" 37 #include "pmModelUtils.h" 38 #include "pmModelClass.h" 39 #include "pmSourceMasks.h" 40 #include "pmSourceExtendedPars.h" 41 #include "pmSourceDiffStats.h" 35 42 #include "pmSource.h" 43 36 44 #include "pmSourceSky.h" 37 45 -
trunk/psModules/src/objects/pmSourceUtils.c
r24578 r29004 21 21 #include <string.h> 22 22 #include <pslib.h> 23 23 24 #include "pmHDU.h" 24 25 #include "pmFPA.h" 25 #include "pmFPAMaskWeight.h" 26 27 #include "pmTrend2D.h" 28 #include "pmResiduals.h" 29 #include "pmGrowthCurve.h" 26 30 #include "pmSpan.h" 31 #include "pmFootprintSpans.h" 27 32 #include "pmFootprint.h" 28 33 #include "pmPeaks.h" 29 34 #include "pmMoments.h" 30 #include "pmResiduals.h" 31 #include "pmGrowthCurve.h" 32 #include "pmTrend2D.h" 33 #include "pmPSF.h" 35 #include "pmModelFuncs.h" 34 36 #include "pmModel.h" 37 #include "pmModelUtils.h" 38 #include "pmModelClass.h" 39 #include "pmSourceMasks.h" 40 #include "pmSourceExtendedPars.h" 41 #include "pmSourceDiffStats.h" 35 42 #include "pmSource.h" 43 36 44 #include "pmSourceUtils.h" 37 45 -
trunk/psModules/src/objects/pmSourceVisual.c
r26260 r29004 4 4 5 5 #include <pslib.h> 6 #include "pmHDU.h" 7 #include "pmFPA.h" 8 6 9 #include "pmTrend2D.h" 10 #include "pmResiduals.h" 11 #include "pmGrowthCurve.h" 12 #include "pmSpan.h" 13 #include "pmFootprintSpans.h" 14 #include "pmFootprint.h" 15 #include "pmPeaks.h" 16 #include "pmMoments.h" 17 #include "pmModelFuncs.h" 18 #include "pmModel.h" 19 #include "pmModelUtils.h" 20 #include "pmModelClass.h" 21 #include "pmSourceMasks.h" 22 #include "pmSourceExtendedPars.h" 23 #include "pmSourceDiffStats.h" 24 #include "pmSource.h" 25 #include "pmSourceFitModel.h" 7 26 #include "pmPSF.h" 8 27 #include "pmPSFtry.h" 9 #include "pmSource.h" 28 #include "pmDetections.h" 29 10 30 #include "pmSourceVisual.h" 11 31 … … 13 33 #include <kapa.h> 14 34 #include "pmVisual.h" 35 #include "pmVisualUtils.h" 15 36 16 37 // functions used to visualize the analysis as it goes … … 34 55 Graphdata graphdata; 35 56 36 if (!pmVisual IsVisual()) return true;57 if (!pmVisualTestLevel("psphot.psf.metric", 2)) return true; 37 58 38 59 if (kapa1 == -1) { … … 118 139 Graphdata graphdata; 119 140 120 if (!pmVisual IsVisual()) return true;141 if (!pmVisualTestLevel("psphot.psf.subpix", 3)) return true; 121 142 122 143 if (kapa1 == -1) { … … 280 301 bool pmSourceVisualShowModelFits (pmPSF *psf, psArray *sources, psImageMaskType maskVal) { 281 302 282 if (!pmVisual IsVisual()) return true;303 if (!pmVisualTestLevel("psphot.psf.fits", 2)) return true; 283 304 284 305 if (kapa2 == -1) { … … 360 381 bool pmSourceVisualShowModelFit (pmSource *source) { 361 382 362 if (!pmVisualIsVisual()) return true; 383 if (!pmVisualTestLevel("psphot.psf.fitresid", 2)) return true; 384 363 385 if (!source->pixels) return false; 364 386 if (!source->modelFlux) return false; … … 404 426 Graphdata graphdata; 405 427 406 if (!pmVisualIsVisual() || !plotPSF) return true; 428 if (!plotPSF) return true; 429 if (!pmVisualTestLevel("psphot.psf.resid", 2)) return true; 407 430 408 431 if (kapa1 == -1) { -
trunk/psModules/src/objects/pmSpan.h
r20945 r29004 10 10 # ifndef PM_SPAN_H 11 11 # define PM_SPAN_H 12 13 #include <pslib.h>14 12 15 13 /// @addtogroup Objects Object Detection / Analysis Functions -
trunk/psModules/src/objects/pmTrend2D.h
r25754 r29004 12 12 # ifndef PM_TREND_2D_H 13 13 # define PM_TREND_2D_H 14 15 #include <pslib.h>16 14 17 15 /// @addtogroup Objects Object Detection / Analysis Functions -
trunk/psModules/src/psmodules.h
r28043 r29004 10 10 #include <pmKapaPlots.h> 11 11 #include <pmVisual.h> 12 #include <pmVisualUtils.h> 12 13 #include <ippStages.h> 13 14 #include <ippDiffMode.h> … … 113 114 114 115 // the following headers are from psModule:objects 116 #include <pmTrend2D.h> 117 #include <pmResiduals.h> 118 #include <pmGrowthCurve.h> 119 115 120 #include <pmSpan.h> 116 121 #include <pmFootprintSpans.h> … … 119 124 #include <pmDetections.h> 120 125 #include <pmMoments.h> 126 127 #include <pmModelFuncs.h> 128 #include <pmModel.h> 129 130 #include <pmSourceMasks.h> 121 131 #include <pmSourceExtendedPars.h> 122 132 #include <pmSourceDiffStats.h> 123 #include <pmResiduals.h> 124 #include <pmGrowthCurve.h> 125 #include <pmTrend2D.h> 133 #include <pmSource.h> 134 #include <pmSourceFitModel.h> 126 135 #include <pmPSF.h> 127 #include <pmModel.h> 128 #include <pmSourceMasks.h> 129 #include <pmSource.h> 136 #include <pmPSFtry.h> 130 137 #include <pmPhotObj.h> 131 138 #include <pmSourceUtils.h> 132 139 #include <pmSourceIO.h> 133 140 #include <pmSourceSky.h> 134 #include <pmSourceFitModel.h>135 141 #include <pmSourceFitSet.h> 136 142 #include <pmSourceContour.h> 137 143 #include <pmSourcePlots.h> 138 144 #include <pmPSF_IO.h> 139 #include <pmPSFtry.h>140 145 #include <pmModelClass.h> 141 146 #include <pmModelUtils.h> … … 144 149 #include <pmSourceMatch.h> 145 150 #include <pmDetEff.h> 151 #include <pmPCMdata.h> 146 152 147 153 // The following headers are from random locations, here because they cross bounds -
trunk/psphot
- Property svn:mergeinfo deleted
-
trunk/psphot/src/Makefile.am
r28013 r29004 163 163 psphotOutput.c \ 164 164 psphotFakeSources.c \ 165 psphotModelWithPSF.c \166 165 psphotExtendedSourceAnalysis.c \ 167 166 psphotExtendedSourceAnalysisByObject.c \ 168 167 psphotExtendedSourceFits.c \ 169 168 psphotKernelFromPSF.c \ 170 psphotPSFConvModel.c \171 169 psphotFitSet.c \ 172 170 psphotSourceFreePixels.c \ -
trunk/psphot/src/psphot.h
r28013 r29004 12 12 13 13 #define PSPHOT_RECIPE_PSF_FAKE_ALLOW "PSF.FAKE.ALLOW" // Name for recipe component permitting fake PSFs 14 15 // pmPCMData : PSF Convolved Model data storage structure16 typedef struct {17 psImage *model;18 psArray *dmodels;19 psImage *modelConv;20 psArray *dmodelsConv;21 } pmPCMData;22 14 23 15 // top-level psphot functions … … 114 106 bool psphotExtendedSourceFits (pmConfig *config, const pmFPAview *view, const char *filerule); 115 107 bool psphotExtendedSourceFitsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 108 bool psphotExtendedSourceFits_Threaded (psThreadJob *job); 116 109 117 110 bool psphotApResid (pmConfig *config, const pmFPAview *view, const char *filerule); … … 188 181 189 182 // functions to set the correct source pixels 190 bool psphotInitRadiusPSF(const psMetadata *recipe, const psMetadata *analysis, const pmModelType type); 183 bool psphotInitRadiusPSF (psMetadata *recipe, pmReadout *readout); 184 bool psphotInitRadiusEXT (psMetadata *recipe, pmReadout *readout); 191 185 192 186 bool psphotCheckRadiusPSF (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal); 193 187 bool psphotCheckRadiusPSFBlend (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal, float dR); 194 bool psphotInitRadiusEXT (psMetadata *recipe, pmModelType type); 195 bool psphotCheckRadiusEXT (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal); 196 float psphotSetRadiusEXT (pmReadout *readout, pmSource *source, psImageMaskType markVal); 188 bool psphotSetRadiusFootprint (float *radius, pmReadout *readout, pmSource *source, psImageMaskType markVal, float factor); 189 bool psphotSetRadiusModel (pmModel *model, pmReadout *readout, pmSource *source, psImageMaskType markVal, bool deep); 197 190 198 191 bool psphotDumpMoments (psMetadata *recipe, psArray *sources); … … 210 203 // functions to support the source fitting process 211 204 bool psphotInitLimitsPSF (psMetadata *recipe, pmReadout *readout); 212 bool psphotInitLimitsEXT (psMetadata *recipe );213 bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, p sImageMaskType maskVal, psImageMaskType markVal);214 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources, pmPSF *psf, p sImageMaskType maskVal, psImageMaskType markVal);215 bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, p sImageMaskType maskVal, psImageMaskType markVal);216 pmModel *psphotFitEXT (pmReadout *readout, pmSource *source, pm ModelType modelType, psImageMaskType maskVal, psImageMaskType markVal);217 psArray *psphotFitDBL (pmReadout *readout, pmSource *source, p sImageMaskType maskVal, psImageMaskType markVal);205 bool psphotInitLimitsEXT (psMetadata *recipe, pmReadout *readout); 206 bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal); 207 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal); 208 bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal); 209 pmModel *psphotFitEXT (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal); 210 psArray *psphotFitDBL (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal); 218 211 219 212 // functions to support simultaneous multi-source fitting … … 252 245 bool psphotVisualShowBackground (pmConfig *config, const pmFPAview *view, pmReadout *readout); 253 246 bool psphotVisualShowSignificance (psImage *image, float min, float max); 247 bool psphotVisualShowLogSignificance (psImage *image, float min, float max); 254 248 bool psphotVisualShowPeaks (pmDetections *detections); 255 249 bool psphotVisualShowFootprints (pmDetections *detections); … … 292 286 bool psphotRadialBins (psMetadata *recipe, pmSource *source, float radiusMax, float skynoise); 293 287 294 // structures & functions to support psf-convolved model fitting295 296 // psf-convolved model fitting297 bool psphotModelWithPSF_LMM (298 psMinimization *min,299 psImage *covar,300 psVector *params,301 psMinConstraint *constraint,302 pmSource *source,303 const psKernel *psf,304 psMinimizeLMChi2Func func);305 306 psF32 psphotModelWithPSF_SetABX(307 psImage *alpha,308 psVector *beta,309 const psVector *params,310 const psVector *paramMask,311 pmPCMData *pcm,312 const pmSource *source,313 const psKernel *psf,314 psMinimizeLMChi2Func func);315 316 pmPCMData *pmPCMDataAlloc (317 const psVector *params,318 const psVector *paramMask,319 pmSource *source);320 321 psImage *pmPCMDataSaveImage (pmPCMData *pcm);322 323 288 int psphotKapaOpen (void); 324 289 bool psphotKapaClose (void); … … 364 329 365 330 bool psphotFitSourcesLinearStack (pmConfig *config, psArray *objects, bool final); 366 int pmPhotObjSortBySN (const void **a, const void **b);367 int pmPhotObjSortByX (const void **a, const void **b);368 331 369 332 typedef enum { … … 462 425 bool psphotStackObjectsUnifyPosition (psArray *objects); 463 426 427 bool psphotFitSersicIndex (pmModel *model, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal); 428 429 bool psphotFitSersicIndexPCM (pmPCMdata *pcm, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize); 430 pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize); 431 464 432 #endif -
trunk/psphot/src/psphotAddNoise.c
r28013 r29004 34 34 35 35 bool status = false; 36 psEllipseShape oldshape;37 psEllipseShape newshape;38 psEllipseAxes axes;39 36 40 37 // find the currently selected readout … … 86 83 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 87 84 88 // select appropriate model 89 pmModel *model = pmSourceGetModel (NULL, source); 90 if (model == NULL) continue; // model must be defined 91 92 if (add) { 93 psTrace ("psphot", 4, "adding noise for object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]); 94 } else { 95 psTrace ("psphot", 4, "remove noise for object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]); 96 } 97 98 psF32 *PAR = model->params->data.F32; 99 100 // save original values 101 float oldI0 = PAR[PM_PAR_I0]; 102 oldshape.sx = PAR[PM_PAR_SXX]; 103 oldshape.sy = PAR[PM_PAR_SYY]; 104 oldshape.sxy = PAR[PM_PAR_SXY]; 105 106 // XXX can this be done more intelligently? 107 if (oldI0 == 0.0) continue; 108 if (!isfinite(oldI0)) continue; 109 110 // increase size and height of source 111 axes = psEllipseShapeToAxes (oldshape, 20.0); 112 axes.major *= SIZE; 113 axes.minor *= SIZE; 114 newshape = psEllipseAxesToShape (axes); 115 PAR[PM_PAR_I0] = FACTOR*oldI0; 116 PAR[PM_PAR_SXX] = newshape.sx; 117 PAR[PM_PAR_SYY] = newshape.sy; 118 PAR[PM_PAR_SXY] = newshape.sxy; 119 120 // XXX if we use pmSourceOp, the size (and possibly Io) will not be respected 121 pmSourceOp (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, add, maskVal, 0, 0); 122 123 // restore original values 124 PAR[PM_PAR_I0] = oldI0; 125 PAR[PM_PAR_SXX] = oldshape.sx; 126 PAR[PM_PAR_SYY] = oldshape.sy; 127 PAR[PM_PAR_SXY] = oldshape.sxy; 85 pmSourceNoiseOp (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, FACTOR, SIZE, add, maskVal, 0, 0); 128 86 } 129 87 if (add) { … … 132 90 psLogMsg ("psphot.noise", PS_LOG_INFO, "sub noise for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.noise")); 133 91 } 92 134 93 return true; 135 94 } -
trunk/psphot/src/psphotApResid.c
r28524 r29004 459 459 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal); 460 460 461 bool status = pmSourceMagnitudes (source, psf, photMode, maskVal );461 bool status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal); 462 462 463 463 // clear the mask bit -
trunk/psphot/src/psphotArguments.c
r25985 r29004 176 176 } 177 177 178 // visual : interactive display mode179 if ((N = psArgumentGet (argc, argv, "-visual"))) {180 psArgumentRemove (N, &argc, argv);181 pmVisualSetVisual(true);182 }183 184 178 // break : used from recipe throughout psphotReadout 185 179 if ((N = psArgumentGet (argc, argv, "-break"))) { -
trunk/psphot/src/psphotBlendFit.c
r28405 r29004 65 65 assert (status && fitIter > 0); 66 66 67 float fitTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_TOL"); // Fit tolerance 68 assert (status && isfinite(fitTol) && fitTol > 0); 67 float fitMinTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MIN_TOL"); // Fit tolerance 68 assert (status && isfinite(fitMinTol) && fitMinTol > 0); 69 70 float fitMaxTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_TOL"); // Fit tolerance 71 assert (status && isfinite(fitMaxTol) && fitMaxTol > 0); 69 72 70 73 bool poisson = psMetadataLookupBool(&status, recipe, "POISSON.ERRORS.PHOT.LMM"); // Poisson errors? 71 74 assert (status); 72 75 76 float maxChisqDOF = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_CHISQ"); // Fit tolerance 77 73 78 float skySig = psMetadataLookupF32(&status, recipe, "SKY_SIG"); 74 79 assert (status && isfinite(skySig) && skySig > 0); 75 80 76 81 // Define source fitting parameters for extended source fits 77 pmSourceFitModelInit(fitIter, fitTol, PS_SQR(skySig), poisson); 82 pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc(); 83 fitOptions->nIter = fitIter; 84 fitOptions->minTol = fitMinTol; 85 fitOptions->maxTol = fitMaxTol; 86 fitOptions->maxChisqDOF = maxChisqDOF; 87 fitOptions->poissonErrors = poisson; 88 fitOptions->weight = PS_SQR(skySig); 89 fitOptions->mode = PM_SOURCE_FIT_PSF; 78 90 79 91 psphotInitLimitsPSF (recipe, readout); 80 psphotInitLimitsEXT (recipe );81 psphotInitRadiusPSF (recipe, readout ->analysis, psf->type);92 psphotInitLimitsEXT (recipe, readout); 93 psphotInitRadiusPSF (recipe, readout); 82 94 83 95 // starts the timer, sets up the array of fitSets … … 88 100 if (!sources->n) { 89 101 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend"); 102 psFree (fitOptions); 90 103 return true; 91 104 } … … 112 125 psArrayAdd(job->args, 1, psf); 113 126 psArrayAdd(job->args, 1, newSources); // return for new sources 127 psArrayAdd(job->args, 1, fitOptions); // default fit options 114 128 psFree (newSources); 115 129 … … 121 135 if (!psThreadJobAddPending(job)) { 122 136 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 137 psFree (fitOptions); 123 138 return NULL; 124 139 } 125 126 # if (0)127 {128 int nfit = 0;129 int npsf = 0;130 int next = 0;131 int nfail = 0;132 psArray *newSources = psArrayAllocEmpty(16);133 134 if (!psphotBlendFit_Unthreaded (&nfit, &npsf, &next, &nfail, readout, recipe, cells->data[j], psf, newSources)) {135 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");136 return NULL;137 }138 Nfit += nfit;139 Npsf += npsf;140 Next += next;141 Nfail += nfail;142 143 // add these back onto sources144 for (int k = 0; k < newSources->n; k++) {145 psArrayAdd (sources, 16, newSources->data[k]);146 }147 psFree (newSources);148 }149 # endif150 140 } 151 141 … … 153 143 if (!psThreadPoolWait (false)) { 154 144 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 145 psFree (fitOptions); 155 146 return NULL; 156 147 } … … 163 154 } else { 164 155 psScalar *scalar = NULL; 165 scalar = job->args->data[ 5];156 scalar = job->args->data[6]; 166 157 Nfit += scalar->data.S32; 167 scalar = job->args->data[ 6];158 scalar = job->args->data[7]; 168 159 Npsf += scalar->data.S32; 169 scalar = job->args->data[ 7];160 scalar = job->args->data[8]; 170 161 Next += scalar->data.S32; 171 scalar = job->args->data[ 8];162 scalar = job->args->data[9]; 172 163 Nfail += scalar->data.S32; 173 164 … … 186 177 psphotSaveImage (NULL, readout->image, "image.v2.fits"); 187 178 } 179 psFree (fitOptions); 188 180 189 181 psLogMsg ("psphot.psphotBlendFit", PS_LOG_INFO, "fit models: %f sec for %d objects (%d psf, %d ext, %d failed, %ld skipped)\n", psTimerMark ("psphot.fit.nonlinear"), Nfit, Npsf, Next, Nfail, sources->n - Nfit); … … 204 196 psScalar *scalar = NULL; 205 197 206 pmReadout *readout = job->args->data[0]; 207 psMetadata *recipe = job->args->data[1]; 208 psArray *sources = job->args->data[2]; 209 pmPSF *psf = job->args->data[3]; 210 psArray *newSources = job->args->data[4]; 198 pmReadout *readout = job->args->data[0]; 199 psMetadata *recipe = job->args->data[1]; 200 psArray *sources = job->args->data[2]; 201 pmPSF *psf = job->args->data[3]; 202 psArray *newSources = job->args->data[4]; 203 pmSourceFitOptions *fitOptions = job->args->data[5]; 211 204 212 205 // bit-masks to test for good/bad pixels … … 269 262 Nfit ++; 270 263 264 if (0) { 265 psF32 Mxx = source->moments->Mxx; 266 psF32 Myy = source->moments->Myy; 267 fprintf (stderr, "1: Mxx: %f, Myy: %f\n", Mxx, Myy); 268 } 269 271 270 // try fitting PSFs or extended sources depending on source->mode 272 271 // these functions subtract the resulting fitted source 273 272 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 274 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {273 if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) { 275 274 source->type = PM_SOURCE_TYPE_EXTENDED; 276 275 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); … … 280 279 } 281 280 } else { 282 if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {281 if (psphotFitBlend (readout, source, psf, fitOptions, maskVal, markVal)) { 283 282 source->type = PM_SOURCE_TYPE_STAR; 284 283 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); … … 289 288 } 290 289 290 if (0) { 291 psF32 Mxx = source->moments->Mxx; 292 psF32 Myy = source->moments->Myy; 293 fprintf (stderr, "2: Mxx: %f, Myy: %f\n", Mxx, Myy); 294 } 295 291 296 psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf); 292 297 Nfail ++; … … 298 303 299 304 // change the value of a scalar on the array (wrap this and put it in psArray.h) 300 scalar = job->args->data[ 5];305 scalar = job->args->data[6]; 301 306 scalar->data.S32 = Nfit; 302 307 303 scalar = job->args->data[ 6];308 scalar = job->args->data[7]; 304 309 scalar->data.S32 = Npsf; 305 310 306 scalar = job->args->data[ 7];311 scalar = job->args->data[8]; 307 312 scalar->data.S32 = Next; 308 313 309 scalar = job->args->data[ 8];314 scalar = job->args->data[9]; 310 315 scalar->data.S32 = Nfail; 311 316 -
trunk/psphot/src/psphotChoosePSF.c
r28013 r29004 74 74 75 75 // structure to store user options defining the psf 76 pmPSFOptions *options = pmPSFOptionsAlloc ();76 pmPSFOptions *options = pmPSFOptionsAlloc(); 77 77 78 78 // load user options from the recipe. no need to check existence -- they are … … 138 138 return false; 139 139 } 140 float fitTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance 141 if (!status || !isfinite(fitTol) || fitTol <= 0) { 142 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "PSF_FIT_TOL is not positive"); 143 return false; 144 } 145 pmSourceFitModelInit(fitIter, fitTol, PS_SQR(SKY_SIG), options->poissonErrorsPhotLMM); 146 140 float fitMinTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_MIN_TOL"); // Fit tolerance 141 if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) { 142 fitMinTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance 143 if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) { 144 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "PSF_FIT_MIN_TOL (and PSF_FIT_TOL) not defined or positive"); 145 return false; 146 } 147 } 148 float fitMaxTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_MAX_TOL"); // Fit tolerance 149 if (!status || !isfinite(fitMaxTol) || fitMaxTol <= 0) { 150 fitMaxTol = 1.0; 151 } 152 float maxChisqDOF = psMetadataLookupF32 (&status, recipe, "PSF_FIT_MAX_CHISQ"); // Fit tolerance 153 154 // options which modify the behavior of the model fitting 155 options->fitOptions = pmSourceFitOptionsAlloc(); 156 options->fitOptions->nIter = fitIter; 157 options->fitOptions->minTol = fitMinTol; 158 options->fitOptions->maxTol = fitMaxTol; 159 options->fitOptions->maxChisqDOF = maxChisqDOF; 160 options->fitOptions->poissonErrors = options->poissonErrorsPhotLMM; 161 options->fitOptions->weight = PS_SQR(SKY_SIG); 162 options->fitOptions->mode = PM_SOURCE_FIT_PSF; 163 147 164 psArray *stars = psArrayAllocEmpty (sources->n); 148 165 … … 227 244 228 245 // try each model option listed in config 246 // pmPSFtryModel makes a local copy of the sources -- those points are not the same as those for 'sources' 229 247 for (int i = 0; i < modelNames->n; i++) { 230 248 char *modelName = modelNames->data[i]; … … 304 322 305 323 // unset the PSFSTAR flag for stars not used for PSF model 324 // XXX a more efficient way of achieving this would be to record a pair of arrays 325 // of the source index and the source id for the psf stars. but that would require we do 326 // not re-sort the source list in the meanwhile 327 int nDrop = 0; 306 328 for (int i = 0; i < try->sources->n; i++) { 307 329 pmSource *source = try->sources->data[i]; 308 330 if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 309 source->mode &= ~PM_SOURCE_MODE_PSFSTAR; 310 } 311 } 331 // need to find this source in the original list (these are copies, not pointers) 332 for (int j = 0; j < sources->n; j++) { 333 pmSource *realSource = sources->data[j]; 334 if (realSource->id != source->id) continue; 335 realSource->mode &= ~PM_SOURCE_MODE_PSFSTAR; 336 source->mode &= ~PM_SOURCE_MODE_PSFSTAR; 337 nDrop ++; 338 break; 339 } 340 } 341 } 342 // fprintf (stderr, "drop %d stars as PSF stars\n", nDrop); 343 344 // XXX is this working? 345 // int N1 = 0; 346 // for (int i = 0; i < try->sources->n; i++) { 347 // pmSource *source = try->sources->data[i]; 348 // fprintf (stderr, "%llx : %d\n", (long long int) source, (source->mode & PM_SOURCE_MODE_PSFSTAR)); 349 // if (source->mode & PM_SOURCE_MODE_PSFSTAR) { 350 // N1 ++; 351 // } 352 // } 353 // int N2 = 0; 354 // for (int i = 0; i < sources->n; i++) { 355 // pmSource *source = sources->data[i]; 356 // fprintf (stderr, "%llx : %d\n", (long long int) source, (source->mode & PM_SOURCE_MODE_PSFSTAR)); 357 // if (source->mode & PM_SOURCE_MODE_PSFSTAR) { 358 // N2 ++; 359 // } 360 // } 361 // fprintf (stderr, "N1: %d, N2: %d\n", N1, N2); 312 362 313 363 // build a PSF residual image -
trunk/psphot/src/psphotEllipticalContour.c
r27819 r29004 82 82 params->data.F32[PAR_RMIN] = Rmin; 83 83 84 psMinimization *myMin = psMinimizationAlloc (25, 0.0 01);84 psMinimization *myMin = psMinimizationAlloc (25, 0.01, 1.00); 85 85 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); 86 86 -
trunk/psphot/src/psphotExtendedSourceAnalysis.c
r28013 r29004 157 157 } 158 158 159 # if (0)160 // Isophotal Mags161 if (doIsophotal) {162 if (!psphotIsophotal (source, recipe, maskVal)) {163 psTrace ("psphot", 5, "failed to measure isophotal mags for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);164 } else {165 psTrace ("psphot", 5, "measured isophotal mags for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);166 Nisophot ++;167 source->mode |= PM_SOURCE_MODE_EXTENDED_STATS;168 }169 }170 // Kron Mags171 if (doKron) {172 if (!psphotKron (source, recipe, maskVal)) {173 psTrace ("psphot", 5, "failed to measure kron mags for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);174 } else {175 psTrace ("psphot", 5, "measure kron mags for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);176 Nkron ++;177 source->mode |= PM_SOURCE_MODE_EXTENDED_STATS;178 }179 }180 # endif181 182 159 // re-subtract the object, leave local sky 183 160 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); -
trunk/psphot/src/psphotExtendedSourceFits.c
r28013 r29004 31 31 // non-linear model fitting for extended sources 32 32 bool psphotExtendedSourceFitsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 33 34 bool status; 35 int Next = 0; 36 int Nconvolve = 0; 37 int NconvolvePass = 0; 38 int Nplain = 0; 39 int NplainPass = 0; 40 41 psTimerStart ("psphot.extended"); 42 43 // find the currently selected readout 44 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 45 psAssert (file, "missing file?"); 46 47 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 48 psAssert (readout, "missing readout?"); 49 50 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 51 psAssert (detections, "missing detections?"); 52 53 psArray *sources = detections->allSources; 54 psAssert (sources, "missing sources?"); 55 56 if (!sources->n) { 57 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping source size"); 58 return true; 59 } 60 61 // determine the number of allowed threads 62 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 63 if (!status) { 64 nThreads = 0; 65 } 66 67 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 68 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 69 assert (maskVal); 70 71 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); // Mask value for bad pixels 72 assert (markVal); 73 74 // maskVal is used to test for rejected pixels, and must include markVal 75 maskVal |= markVal; 76 77 // select the collection of desired models 78 psMetadata *models = psMetadataLookupMetadata (&status, recipe, "EXTENDED_SOURCE_MODELS"); 79 if (!status) { 80 psWarning ("extended source model fits requested but model model is missing (EXTENDED_SOURCE_MODELS)\n"); 81 return true; 82 } 83 if (models->list->n == 0) { 84 psWarning ("extended source model fits requested but no models are specified\n"); 85 return true; 86 } 87 88 // validate the model entries 89 psMetadataIterator *iter = psMetadataIteratorAlloc (models, PS_LIST_HEAD, NULL); 90 psMetadataItem *item = NULL; 91 while ((item = psMetadataGetAndIncrement (iter)) != NULL) { 92 93 if (item->type != PS_DATA_METADATA) { 94 psAbort ("Invalid type for EXTENDED_SOURCE_MODEL entry %s, not a metadata folder", item->name); 95 // XXX we could cull the bad entries or build a validated model folder 96 } 97 98 psMetadata *model = (psMetadata *) item->data.md; 99 100 // check on the model type 101 char *modelName = psMetadataLookupStr (&status, model, "MODEL"); 102 int modelType = pmModelClassGetType (modelName); 103 if (modelType < 0) { 104 psAbort ("Unknown model class for EXTENDED_SOURCE_MODEL entry %s: %s", item->name, modelName); 105 } 106 psMetadataAddS32 (model, PS_LIST_TAIL, "MODEL_TYPE", PS_META_REPLACE, "", modelType); 107 108 // check on the SNLIM, set a float value 109 char *SNword = psMetadataLookupStr (&status, model, "SNLIM"); 110 if (!status) { 111 psAbort("SNLIM not defined for extended source model %s\n", item->name); 112 } 113 float SNlim = atof (SNword); 114 psMetadataAddF32 (model, PS_LIST_TAIL, "SNLIM_VALUE", PS_META_REPLACE, "", SNlim); 115 116 // check on the PSF-Convolution status 117 char *convolvedWord = psMetadataLookupStr (&status, model, "PSF_CONVOLVED"); 118 if (!status || (strcasecmp (convolvedWord, "true") && strcasecmp (convolvedWord, "false"))) { 119 psAbort ("PSF_CONVOLVED entry invalid or missing for EXTENDED_SOURCE_MODEL entry %s", item->name); 120 } 121 bool convolved = !strcasecmp (convolvedWord, "true"); 122 psMetadataAddBool (model, PS_LIST_TAIL, "PSF_CONVOLVED_VALUE", PS_META_REPLACE, "", convolved); 123 } 124 psFree (iter); 125 126 // option to limit analysis to a specific region 127 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 128 psRegion *AnalysisRegion = psRegionAlloc(0,0,0,0); 129 *AnalysisRegion = psRegionForImage(readout->image, psRegionFromString (region)); 130 if (psRegionIsNaN (*AnalysisRegion)) psAbort("analysis region mis-defined"); 131 132 // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box) 133 int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE"); 134 assert (status); 135 136 // source analysis is done in S/N order (brightest first) 137 sources = psArraySort (sources, pmSourceSortBySN); 138 139 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 140 int Cx = 1, Cy = 1; 141 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 142 143 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 144 145 for (int i = 0; i < cellGroups->n; i++) { 146 147 psArray *cells = cellGroups->data[i]; 148 149 for (int j = 0; j < cells->n; j++) { 150 151 // allocate a job -- if threads are not defined, this just runs the job 152 psThreadJob *job = psThreadJobAlloc ("PSPHOT_EXTENDED_FIT"); 153 154 psArrayAdd(job->args, 1, readout); 155 psArrayAdd(job->args, 1, cells->data[j]); // sources 156 psArrayAdd(job->args, 1, models); 157 psArrayAdd(job->args, 1, AnalysisRegion); // XXX make a pointer 158 159 PS_ARRAY_ADD_SCALAR(job->args, psfSize, PS_TYPE_S32); 160 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 161 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 162 163 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 164 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nconvolve 165 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for NconvolvePass 166 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nplain 167 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for NplainPass 168 169 if (!psThreadJobAddPending(job)) { 170 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 171 psFree(AnalysisRegion); 172 return false; 173 } 174 } 175 176 // wait for the threads to finish and manage results 177 if (!psThreadPoolWait (false)) { 178 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 179 psFree(AnalysisRegion); 180 return false; 181 } 182 183 // we have only supplied one type of job, so we can assume the types here 184 psThreadJob *job = NULL; 185 while ((job = psThreadJobGetDone()) != NULL) { 186 if (job->args->n < 1) { 187 fprintf (stderr, "error with job\n"); 188 } else { 189 psScalar *scalar = NULL; 190 scalar = job->args->data[7]; 191 Next += scalar->data.S32; 192 scalar = job->args->data[8]; 193 Nconvolve += scalar->data.S32; 194 scalar = job->args->data[9]; 195 NconvolvePass += scalar->data.S32; 196 scalar = job->args->data[10]; 197 Nplain += scalar->data.S32; 198 scalar = job->args->data[11]; 199 NplainPass += scalar->data.S32; 200 } 201 psFree(job); 202 } 203 } 204 psFree (cellGroups); 205 psFree(AnalysisRegion); 206 207 psLogMsg ("psphot", PS_LOG_INFO, "extended source analysis: %f sec for %d objects\n", psTimerMark ("psphot.extended"), Next); 208 psLogMsg ("psphot", PS_LOG_INFO, " %d convolved models (%d passed)\n", Nconvolve, NconvolvePass); 209 psLogMsg ("psphot", PS_LOG_INFO, " %d plain models (%d passed)\n", Nplain, NplainPass); 210 return true; 211 } 212 213 // non-linear model fitting for extended sources 214 bool psphotExtendedSourceFits_Threaded (psThreadJob *job) { 33 215 34 216 bool status; … … 39 221 int NplainPass = 0; 40 222 bool savePics = false; 41 42 // find the currently selected readout 43 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 44 psAssert (file, "missing file?"); 45 46 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 47 psAssert (readout, "missing readout?"); 48 49 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 50 psAssert (detections, "missing detections?"); 51 52 psArray *sources = detections->allSources; 53 psAssert (sources, "missing sources?"); 54 55 if (!sources->n) { 56 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping source size"); 57 return true; 58 } 59 60 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 61 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 62 assert (maskVal); 63 64 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); // Mask value for bad pixels 65 assert (markVal); 66 67 // maskVal is used to test for rejected pixels, and must include markVal 68 maskVal |= markVal; 69 70 // select the collection of desired models 71 psMetadata *models = psMetadataLookupMetadata (&status, recipe, "EXTENDED_SOURCE_MODELS"); 72 if (!status) { 73 psWarning ("extended source model fits requested but model model is missing (EXTENDED_SOURCE_MODELS)\n"); 74 return true; 75 } 76 if (models->list->n == 0) { 77 psWarning ("extended source model fits requested but no models are specified\n"); 78 return true; 79 } 80 81 // validate the model entries 82 psMetadataIterator *iter = psMetadataIteratorAlloc (models, PS_LIST_HEAD, NULL); 83 psMetadataItem *item = NULL; 84 while ((item = psMetadataGetAndIncrement (iter)) != NULL) { 85 86 if (item->type != PS_DATA_METADATA) { 87 psAbort ("Invalid type for EXTENDED_SOURCE_MODEL entry %s, not a metadata folder", item->name); 88 // XXX we could cull the bad entries or build a validated model folder 89 } 90 91 psMetadata *model = (psMetadata *) item->data.md; 92 93 // check on the model type 94 char *modelName = psMetadataLookupStr (&status, model, "MODEL"); 95 int modelType = pmModelClassGetType (modelName); 96 if (modelType < 0) { 97 psAbort ("Unknown model class for EXTENDED_SOURCE_MODEL entry %s: %s", item->name, modelName); 98 } 99 psMetadataAddS32 (model, PS_LIST_TAIL, "MODEL_TYPE", PS_META_REPLACE, "", modelType); 100 101 // check on the SNLIM, set a float value 102 char *SNword = psMetadataLookupStr (&status, model, "SNLIM"); 103 if (!status) { 104 psAbort("SNLIM not defined for extended source model %s\n", item->name); 105 } 106 float SNlim = atof (SNword); 107 psMetadataAddF32 (model, PS_LIST_TAIL, "SNLIM_VALUE", PS_META_REPLACE, "", SNlim); 108 109 // check on the PSF-Convolution status 110 char *convolvedWord = psMetadataLookupStr (&status, model, "PSF_CONVOLVED"); 111 if (!status || (strcasecmp (convolvedWord, "true") && strcasecmp (convolvedWord, "false"))) { 112 psAbort ("PSF_CONVOLVED entry invalid or missing for EXTENDED_SOURCE_MODEL entry %s", item->name); 113 } 114 bool convolved = !strcasecmp (convolvedWord, "true"); 115 psMetadataAddBool (model, PS_LIST_TAIL, "PSF_CONVOLVED_VALUE", PS_META_REPLACE, "", convolved); 116 } 117 psFree (iter); 118 119 // option to limit analysis to a specific region 120 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 121 psRegion AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 122 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 123 124 // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box) 125 int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE"); 126 assert (status); 127 128 // source analysis is done in S/N order (brightest first) 129 sources = psArraySort (sources, pmSourceSortBySN); 223 float radius; 224 psScalar *scalar = NULL; 225 226 // arguments: readout, sources, models, region, psfSize, maskVal, markVal 227 pmReadout *readout = job->args->data[0]; 228 psArray *sources = job->args->data[1]; 229 psMetadata *models = job->args->data[2]; 230 psRegion *region = job->args->data[3]; 231 int psfSize = PS_SCALAR_VALUE(job->args->data[4],PS_TYPE_IMAGE_MASK_DATA); 232 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[5],PS_TYPE_IMAGE_MASK_DATA); 233 psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA); 234 235 // Define source fitting parameters for extended source fits 236 pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc(); 237 fitOptions->mode = PM_SOURCE_FIT_EXT; 238 // XXX for now, use the defaults for the rest: 239 // fitOptions->nIter = fitIter; 240 // fitOptions->tol = fitTol; 241 // fitOptions->poissonErrors = poisson; 242 // fitOptions->weight = PS_SQR(skySig); 130 243 131 244 // choose the sources of interest … … 140 253 141 254 // XXX this should use peak? 142 if (source->peak->x < AnalysisRegion.x0) continue;143 if (source->peak->y < AnalysisRegion.y0) continue;144 if (source->peak->x > AnalysisRegion.x1) continue;145 if (source->peak->y > AnalysisRegion.y1) continue;255 if (source->peak->x < region->x0) continue; 256 if (source->peak->y < region->y0) continue; 257 if (source->peak->x > region->x1) continue; 258 if (source->peak->y > region->y1) continue; 146 259 147 260 // if model is NULL, we don't have a starting guess … … 154 267 } 155 268 Next ++; 269 270 // set the radius based on the footprint (also sets the mask pixels) 271 if (!psphotSetRadiusFootprint(&radius, readout, source, markVal, 1.0)) { 272 psFree (fitOptions) 273 return false; 274 } 275 276 // XXX note that this changes the source moments that are published... 277 // recalculate the source moments using the larger extended-source moments radius 278 // at this stage, skip Gaussian windowing, and do not clip pixels by S/N 279 // this uses the footprint to judge both radius and aperture? 280 // XXX save the psf-based moments for output 281 if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) { 282 // subtract the best fit from the object, leave local sky 283 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 284 // XXX raise an error of some kind 285 continue; 286 } 156 287 157 288 // save the modelFlux here in case we need to subtract it (for failure) … … 201 332 pmModel *modelFit = NULL; 202 333 if (convolved) { 203 modelFit = psphot PSFConvModel (readout, source, modelType, maskVal, markVal, psfSize);334 modelFit = psphotFitPCM (readout, source, fitOptions, modelType, maskVal, markVal, psfSize); 204 335 if (!modelFit) { 205 336 psTrace ("psphot", 5, "failed to fit psf-conv model for object at %f, %f", source->moments->Mx, source->moments->My); … … 215 346 psFree (source->modelFlux); 216 347 source->modelFlux = NULL; 217 modelFit = psphotFitEXT (readout, source, modelType, maskVal, markVal);348 modelFit = psphotFitEXT (readout, source, fitOptions, modelType, maskVal, markVal); 218 349 if (!modelFit) { 219 350 psTrace ("psphot", 5, "failed to fit plain model for object at %f, %f", source->moments->Mx, source->moments->My); … … 233 364 234 365 // test for fit quality / result 366 modelFit->fitRadius = radius; 235 367 psArrayAdd (source->modelFits, 4, modelFit); 236 368 … … 311 443 } 312 444 } 313 314 psLogMsg ("psphot", PS_LOG_INFO, "extended source analysis: %f sec for %d objects\n", psTimerMark ("psphot"), Next); 315 psLogMsg ("psphot", PS_LOG_INFO, " %d convolved models (%d passed)\n", Nconvolve, NconvolvePass); 316 psLogMsg ("psphot", PS_LOG_INFO, " %d plain models (%d passed)\n", Nplain, NplainPass); 445 psFree (fitOptions); 446 447 // change the value of a scalar on the array (wrap this and put it in psArray.h) 448 scalar = job->args->data[7]; 449 scalar->data.S32 = Next; 450 451 scalar = job->args->data[8]; 452 scalar->data.S32 = Nconvolve; 453 454 scalar = job->args->data[9]; 455 scalar->data.S32 = NconvolvePass; 456 457 scalar = job->args->data[10]; 458 scalar->data.S32 = Nplain; 459 460 scalar = job->args->data[11]; 461 scalar->data.S32 = NplainPass; 462 317 463 return true; 318 464 } -
trunk/psphot/src/psphotFindDetections.c
r28013 r29004 90 90 psphotVisualShowSignificance (significance, -1.0, PS_SQR(3.0*NSIGMA_PEAK)); 91 91 92 // XXX getting some strange results from significance image 93 if (0) { 94 psImage *lsig = (psImage *) psUnaryOp (NULL, significance, "log"); 95 psphotVisualShowSignificance (lsig, 0.0, 4.0); 96 psFree (lsig); 97 } 92 // display the log significance image 93 psphotVisualShowLogSignificance (significance, 0.0, 4.5); 98 94 99 95 // detect the peaks in the significance image -
trunk/psphot/src/psphotFitSet.c
r21183 r29004 24 24 } 25 25 26 // Define source fitting parameters for extended source fits 27 pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc(); 28 fitOptions->mode = PM_SOURCE_FIT_EXT; 29 // XXX for now, use the defaults for the rest: 30 // fitOptions->nIter = fitIter; 31 // fitOptions->tol = fitTol; 32 // fitOptions->poissonErrors = poisson; 33 // fitOptions->weight = PS_SQR(skySig); 34 26 35 // XXX pmSourceFitSet must cache the modelFlux? 27 pmSourceFitSet (source, modelSet, mode, maskVal);36 pmSourceFitSet (source, modelSet, fitOptions, maskVal); 28 37 29 38 // write out positive object -
trunk/psphot/src/psphotFitSourcesLinear.c
r28426 r29004 100 100 if (!status) { 101 101 SKY_FIT_LINEAR = false; 102 } 103 104 float MIN_VALID_FLUX = psMetadataLookupF32(&status, recipe, "PSF_FIT_MIN_VALID_FLUX"); 105 if (!status) { 106 MIN_VALID_FLUX = 1e-8; 107 } 108 float MAX_VALID_FLUX = psMetadataLookupF32(&status, recipe, "PSF_FIT_MAX_VALID_FLUX"); 109 if (!status) { 110 MAX_VALID_FLUX = 1e+8; 102 111 } 103 112 … … 228 237 229 238 psSparseConstraint constraint; 230 constraint.paramMin = 0.0;231 constraint.paramMax = 1e8;232 constraint.paramDelta = 1e 8;239 constraint.paramMin = MIN_VALID_FLUX; 240 constraint.paramMax = MAX_VALID_FLUX; 241 constraint.paramDelta = 1e7; 233 242 234 243 // solve for normalization terms (need include local sky?) -
trunk/psphot/src/psphotFitSourcesLinearStack.c
r28426 r29004 170 170 return true; 171 171 } 172 173 // sort by X (ascending)174 int pmPhotObjSortByX (const void **a, const void **b)175 {176 pmPhotObj *objA = *(pmPhotObj **)a;177 pmPhotObj *objB = *(pmPhotObj **)b;178 179 psF32 fA = objA->x;180 psF32 fB = objB->x;181 182 psF32 diff = fA - fB;183 if (diff > FLT_EPSILON) return (+1);184 if (diff < FLT_EPSILON) return (-1);185 return (0);186 } -
trunk/psphot/src/psphotGuessModels.c
r28405 r29004 80 80 81 81 // setup the PSF fit radius details 82 psphotInitRadiusPSF (recipe, readout ->analysis, psf->type);82 psphotInitRadiusPSF (recipe, readout); 83 83 84 84 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) -
trunk/psphot/src/psphotLoadSRCTEXT.c
r25983 r29004 84 84 source->peak->yf = PAR[PM_PAR_YPOS]; // but we know the pixel coordinate 85 85 86 source->pixWeight = 1.0; 86 source->pixWeightNotBad = 1.0; 87 source->pixWeightNotPoor = 1.0; 87 88 source->crNsigma = 0.0; 88 89 source->extNsigma = 0.0; -
trunk/psphot/src/psphotMagnitudes.c
r28405 r29004 124 124 return false; 125 125 } 126 127 # if (0)128 int nap = 0;129 if (!psphotMagnitudes_Unthreaded (&nap, cells->data[j], psf, binning, backModel, backStdev, photMode, maskVal)) {130 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");131 return false;132 }133 Nap += nap;134 # endif135 126 } 136 127 … … 186 177 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal); 187 178 188 status = pmSourceMagnitudes (source, psf, photMode, maskVal ); // maskVal includes markVal179 status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal); 189 180 if (status && isfinite(source->apMag)) Nap ++; 190 181 … … 268 259 psArrayAdd(job->args, 1, cells->data[j]); // sources 269 260 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 261 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 270 262 271 263 if (!psThreadJobAddPending(job)) { … … 304 296 psArray *sources = job->args->data[0]; 305 297 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[1],PS_TYPE_IMAGE_MASK_DATA); 298 psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[2],PS_TYPE_IMAGE_MASK_DATA); 306 299 307 300 for (int i = 0; i < sources->n; i++) { … … 312 305 if (model == NULL) { 313 306 psTrace ("psphot", 3, "fail mag : no valid model"); 314 source->pixWeight = NAN; 307 source->pixWeightNotBad = NAN; 308 source->pixWeightNotPoor = NAN; 315 309 continue; 316 310 } 317 311 318 status = pmSourcePixelWeight (&source->pixWeight , model, source->maskObj, maskVal);312 status = pmSourcePixelWeight (&source->pixWeightNotBad, &source->pixWeightNotPoor, model, source->maskObj, maskVal, markVal); 319 313 if (!status) { 320 314 psTrace ("psphot", 3, "fail to measure pixel weight"); 321 source->pixWeight = NAN; 315 source->pixWeightNotBad = NAN; 316 source->pixWeightNotPoor = NAN; 322 317 continue; 323 318 } -
trunk/psphot/src/psphotModelWithPSF.c
r21366 r29004 73 73 74 74 // iterate until the tolerance is reached, or give up 75 while ((min->iter < min->maxIter) && ((min->lastDelta > min-> tol) || !isfinite(min->lastDelta))) {75 while ((min->iter < min->maxIter) && ((min->lastDelta > min->minTol) || !isfinite(min->lastDelta))) { 76 76 psTrace("psphot", 5, "Iteration number %d. (max iterations is %d).\n", min->iter, min->maxIter); 77 psTrace("psphot", 5, "Last delta is %f. Min-> tol is %f.\n", min->lastDelta, min->tol);77 psTrace("psphot", 5, "Last delta is %f. Min->minTol is %f.\n", min->lastDelta, min->minTol); 78 78 79 79 … … 166 166 psFree(pcm); 167 167 168 if (min->iter == min->maxIter) {169 psTrace("psphot", 3, "---- end (false) ----\n");170 return(false);171 }172 173 psTrace("psphot", 3, "---- end (true) ----\n");174 return( true);168 // if the last improvement was at least as good as maxTol, accept the fit: 169 if (min->lastDelta <= min->maxTol) { 170 psTrace("psphot", 6, "---- end (true) ----\n"); 171 return(true); 172 } 173 psTrace("psphot", 6, "---- end (false) ----\n"); 174 return(false); 175 175 } 176 176 -
trunk/psphot/src/psphotPSFConvModel.c
r26894 r29004 4 4 // save as static values so they may be set externally 5 5 static psF32 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = 15; 6 static psF32 PM_SOURCE_FIT_MODEL_TOLERANCE = 0.1; 6 static psF32 PM_SOURCE_FIT_MODEL_MIN_TOL = 0.1; 7 static psF32 PM_SOURCE_FIT_MODEL_MAX_TOL = 2.0; 7 8 8 9 // input source has both modelPSF and modelEXT. on successful exit, we set the 9 10 // modelConv to contain the fitted parameters, and the modelFlux to contain the 10 11 // convolved model image. 11 pmModel *psphotPSFConvModel (pmReadout *readout, pmSource *source, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 12 13 // XXX need to generalize this -- number of fitted parameters must be flexible based on the fitOptions 14 15 pmModel *psphotPSFConvModel (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 12 16 13 17 // maskVal is used to test for rejected pixels, and must include markVal … … 90 94 91 95 // set up the minimization process 92 psMinimization *myMin = psMinimizationAlloc (PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_ TOLERANCE);96 psMinimization *myMin = psMinimizationAlloc (PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_MIN_TOL, PM_SOURCE_FIT_MODEL_MAX_TOL); 93 97 94 98 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); -
trunk/psphot/src/psphotPetrosianVisual.c
r27819 r29004 1 1 # include "psphotInternal.h" 2 # define FORCE_VISUAL 03 2 4 3 // this function displays representative images as the psphot analysis progresses: … … 54 53 Graphdata graphdata; 55 54 56 // return true; 57 if (!FORCE_VISUAL && !pmVisualIsVisual()) return true; 55 if (!pmVisualTestLevel("psphot.petro.byangle", 2)) return true; 58 56 59 57 if (kapa2 == -1) { … … 101 99 Graphdata graphdata; 102 100 103 // return true; 104 if (!FORCE_VISUAL && !pmVisualIsVisual()) return true; 101 if (!pmVisualTestLevel("psphot.petro.radii", 2)) return true; 105 102 106 103 if (kapa == -1) { … … 173 170 KapaSection section; 174 171 175 if (! FORCE_VISUAL && !pmVisualIsVisual()) return true;172 if (!pmVisualTestLevel("psphot.petro.stats", 2)) return true; 176 173 177 174 if (kapa2 == -1) { … … 311 308 Graphdata graphdata; 312 309 313 if (! FORCE_VISUAL && !pmVisualIsVisual()) return true;310 if (!pmVisualTestLevel("psphot.petro.ellipse", 2)) return true; 314 311 315 312 if (kapa == -1) { -
trunk/psphot/src/psphotRadiusChecks.c
r28418 r29004 8 8 // and a per-object radius is calculated) 9 9 10 bool psphotInitRadiusPSF( const psMetadata *recipe, const psMetadata *analysis, const pmModelType type) {10 bool psphotInitRadiusPSF(psMetadata *recipe, pmReadout *readout) { 11 11 12 12 bool status = true; … … 15 15 PSF_FIT_PADDING = psMetadataLookupF32(&status, recipe, "PSF_FIT_PADDING"); 16 16 17 PSF_FIT_RADIUS = psMetadataLookupF32(&status, analysis, "PSF_FIT_RADIUS");17 PSF_FIT_RADIUS = psMetadataLookupF32(&status, readout->analysis, "PSF_FIT_RADIUS"); 18 18 if (!status) { 19 19 PSF_FIT_RADIUS = psMetadataLookupF32(&status, recipe, "PSF_FIT_RADIUS"); 20 20 } 21 21 22 PSF_APERTURE = psMetadataLookupF32(&status, analysis, "PSF_APERTURE");22 PSF_APERTURE = psMetadataLookupF32(&status, readout->analysis, "PSF_APERTURE"); 23 23 if (!status) { 24 24 PSF_APERTURE = psMetadataLookupF32(&status, recipe, "PSF_APERTURE"); … … 28 28 29 29 if (PSF_FIT_RADIUS == 0.0) { 30 float gaussSigma = psMetadataLookupF32(&status, analysis, "MOMENTS_GAUSS_SIGMA");30 float gaussSigma = psMetadataLookupF32(&status, readout->analysis, "MOMENTS_GAUSS_SIGMA"); 31 31 if (!status) { 32 32 gaussSigma = psMetadataLookupF32(&status, recipe, "MOMENTS_GAUSS_SIGMA"); … … 37 37 38 38 if (PSF_APERTURE == 0.0) { 39 float gaussSigma = psMetadataLookupF32(&status, analysis, "MOMENTS_GAUSS_SIGMA");39 float gaussSigma = psMetadataLookupF32(&status, readout->analysis, "MOMENTS_GAUSS_SIGMA"); 40 40 if (!status) { 41 41 gaussSigma = psMetadataLookupF32(&status, recipe, "MOMENTS_GAUSS_SIGMA"); … … 122 122 } 123 123 124 static float EXT_FIT_SKY_SIG; 124 125 static float EXT_FIT_NSIGMA; 125 126 static float EXT_FIT_PADDING; 126 127 static float EXT_FIT_MAX_RADIUS; 127 128 128 bool psphotInitRadiusEXT (psMetadata *recipe, pm ModelType type) {129 bool psphotInitRadiusEXT (psMetadata *recipe, pmReadout *readout) { 129 130 130 131 bool status; … … 134 135 EXT_FIT_MAX_RADIUS = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_RADIUS"); 135 136 137 float skyMean = psMetadataLookupF32 (&status, readout->analysis, "SKY_MEAN"); 138 float skyStdev = psMetadataLookupF32 (&status, readout->analysis, "SKY_STDEV"); 139 140 fprintf (stderr, "sky: %f +/- %f\n", skyMean, skyStdev); 141 142 EXT_FIT_SKY_SIG = skyStdev; 143 136 144 return true; 137 145 } 138 146 139 147 // call this function whenever you (re)-define the EXT model 140 float psphotSetRadiusEXT (pmReadout *readout, pmSource *source, psImageMaskType markVal) {148 bool psphotSetRadiusFootprint (float *radius, pmReadout *readout, pmSource *source, psImageMaskType markVal, float factor) { 141 149 142 150 psAssert (source, "source not defined??"); … … 146 154 147 155 // set the radius based on the footprint: 148 if (!peak->footprint) goto escape;156 if (!peak->footprint) return false; 149 157 pmFootprint *footprint = peak->footprint; 150 if (!footprint->spans) goto escape;151 if (footprint->spans->n < 1) goto escape;158 if (!footprint->spans) return false; 159 if (footprint->spans->n < 1) return false; 152 160 153 161 // find the max radius 154 float ra dius = 0.0;162 float rawRadius = 0.0; 155 163 for (int j = 0; j < footprint->spans->n; j++) { 156 164 pmSpan *span = footprint->spans->data[j]; … … 160 168 float dX1 = span->x1 - peak->xf; 161 169 162 radius = PS_MAX (radius, hypot(dY, dX0)); 163 radius = PS_MAX (radius, hypot(dY, dX1)); 164 } 165 166 radius += EXT_FIT_PADDING; 167 if (isnan(radius)) psAbort("error in radius"); 168 169 radius = PS_MIN (radius, EXT_FIT_MAX_RADIUS); 170 rawRadius = PS_MAX (rawRadius, hypot(dY, dX0)); 171 rawRadius = PS_MAX (rawRadius, hypot(dY, dX1)); 172 } 173 if (isnan(rawRadius)) return false; 174 rawRadius = PS_MIN (factor*rawRadius + EXT_FIT_PADDING, EXT_FIT_MAX_RADIUS); 170 175 171 176 // redefine the pixels if needed 172 pmSourceRedefinePixels (source, readout, peak->xf, peak->yf, radius); 173 174 // set the mask to flag the excluded pixels 175 psImageKeepCircle (source->maskObj, peak->xf, peak->yf, radius, "OR", markVal); 176 return radius; 177 178 escape: 179 return NAN; 180 // bool result = psphotCheckRadiusEXT (readout, source, model, markVal); 181 // return result; 177 pmSourceRedefinePixels (source, readout, peak->xf, peak->yf, rawRadius); 178 179 // set the mask to flag the excluded pixels 180 psImageKeepCircle (source->maskObj, peak->xf, peak->yf, rawRadius, "OR", markVal); 181 182 *radius = rawRadius; 183 return true; 182 184 } 183 185 184 186 // alternative EXT radius based on model guess (for use without footprints) 185 bool psphotCheckRadiusEXT (pmReadout *readout, pmSource *source, pmModel *model, psImageMaskType markVal) { 186 187 psAbort ("do not use this function"); 187 bool psphotSetRadiusModel (pmModel *model, pmReadout *readout, pmSource *source, psImageMaskType markVal, bool deep) { 188 188 189 189 psF32 *PAR = model->params->data.F32; … … 193 193 194 194 // set the fit radius based on the object flux limit and the model 195 float rawRadius = model->modelRadius (model->params, EXT_FIT_NSIGMA*moments->dSky); 196 197 model->fitRadius = rawRadius + EXT_FIT_PADDING; 198 if (isnan(model->fitRadius)) psAbort("error in radius"); 195 float flux = deep ? EXT_FIT_NSIGMA*EXT_FIT_SKY_SIG : 0.1 * model->params->data.F32[PM_PAR_I0]; 196 197 float rawRadius = model->modelRadius (model->params, flux); 198 if (isnan(rawRadius)) return false; 199 200 rawRadius = PS_MIN (rawRadius + EXT_FIT_PADDING, EXT_FIT_MAX_RADIUS); 201 model->fitRadius = rawRadius; 199 202 200 203 // redefine the pixels if needed 201 bool status =pmSourceRedefinePixels (source, readout, PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], model->fitRadius);204 pmSourceRedefinePixels (source, readout, PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], model->fitRadius); 202 205 203 206 // set the mask to flag the excluded pixels 204 207 psImageKeepCircle (source->maskObj, PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], model->fitRadius, "OR", markVal); 205 return status;206 } 208 return true; 209 } -
trunk/psphot/src/psphotReadout.c
r28398 r29004 53 53 } 54 54 55 // load the psf model, if suppled. FWHM_X,FWHM_Y,etc are determined and saved on 56 // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT 55 // load the psf model, if suppled. FWHM_MAJ,FWHM_MIN,etc are determined and saved on 56 // readout->analysis. XXX Note: this function currently only works with a single 57 // PSPHOT.INPUT 57 58 if (!psphotLoadPSF (config, view)) { // ??? need to supply 2 ? 58 59 psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model"); -
trunk/psphot/src/psphotSetThreads.c
r26894 r29004 15 15 psFree(task); 16 16 17 task = psThreadTaskAlloc("PSPHOT_PSF_WEIGHTS", 2);17 task = psThreadTaskAlloc("PSPHOT_PSF_WEIGHTS", 3); 18 18 task->function = &psphotPSFWeights_Threaded; 19 19 psThreadTaskAdd(task); … … 30 30 psFree(task); 31 31 32 task = psThreadTaskAlloc("PSPHOT_BLEND_FIT", 9);32 task = psThreadTaskAlloc("PSPHOT_BLEND_FIT", 10); 33 33 task->function = &psphotBlendFit_Threaded; 34 psThreadTaskAdd(task); 35 psFree(task); 36 37 task = psThreadTaskAlloc("PSPHOT_EXTENDED_FIT", 12); 38 task->function = &psphotExtendedSourceFits_Threaded; 34 39 psThreadTaskAdd(task); 35 40 psFree(task); -
trunk/psphot/src/psphotSignificanceImage.c
r28667 r29004 97 97 smooth_im->data.F32[j][i] = 0.0; 98 98 } else { 99 smooth_im->data.F32[j][i] = factor * PS_SQR(value) / smooth_wt->data.F32[j][i]; 99 float v2 = value + PS_SQR(value/1000.0); 100 smooth_im->data.F32[j][i] = factor * PS_SQR(v2) / smooth_wt->data.F32[j][i]; 100 101 } 101 102 } -
trunk/psphot/src/psphotSourceFits.c
r26894 r29004 2 2 3 3 // given a source with an existing modelPSF, attempt a full PSF fit, subtract if successful 4 // XXX this function does not call pmSourceFitModelInit : fix this?5 4 6 5 static int NfitPSF = 0; … … 8 7 static int NfitDBL = 0; 9 8 static int NfitEXT = 0; 9 static int NfitPCM = 0; 10 10 11 11 bool psphotFitInit (int nThreads) { … … 18 18 19 19 psLogMsg ("psphot.pspsf", PS_LOG_INFO, "fitted %5d psf, %5d blend, %5d ext, %5d dbl : %6.2f sec\n", 20 NfitPSF, NfitBlend, NfitEXT, NfitDBL, psTimerMark ("psphot.fits"));21 return true; 22 } 23 24 bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, p sImageMaskType maskVal, psImageMaskType markVal) {20 NfitPSF, NfitBlend, NfitEXT, NfitDBL, psTimerMark ("psphot.fits")); 21 return true; 22 } 23 24 bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) { 25 25 26 26 float x, y, dR; 27 28 pmSourceFitOptions options = *fitOptions; 27 29 28 30 // maskVal is used to test for rejected pixels, and must include markVal … … 31 33 // if this source is not a possible blend, just fit as PSF 32 34 if ((source->blends == NULL) || (source->mode & PM_SOURCE_MODE_SATSTAR)) { 33 bool status = psphotFitPSF (readout, source, psf, maskVal, markVal);35 bool status = psphotFitPSF (readout, source, psf, fitOptions, maskVal, markVal); 34 36 return status; 35 37 } … … 91 93 92 94 // fit PSF model 93 pmSourceFitSet (source, modelSet, PM_SOURCE_FIT_PSF, maskVal); 95 options.mode = PM_SOURCE_FIT_PSF; 96 pmSourceFitSet (source, modelSet, &options, maskVal); 94 97 95 98 // clear the circular mask … … 154 157 } 155 158 156 bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, p sImageMaskType maskVal, psImageMaskType markVal) {159 bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) { 157 160 158 161 double chiTrend; 162 pmSourceFitOptions options = *fitOptions; 159 163 160 164 // maskVal is used to test for rejected pixels, and must include markVal … … 171 175 172 176 // fit PSF model (set/unset the pixel mask) 173 pmSourceFitModel (source, PSF, PM_SOURCE_FIT_PSF, maskVal); 177 options.mode = PM_SOURCE_FIT_PSF; 178 pmSourceFitModel (source, PSF, &options, maskVal); 174 179 175 180 if (!isfinite(PSF->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); … … 199 204 } 200 205 206 // save a local, static copy of the EXT model type so we don't have to lookup for each object 201 207 static pmModelType modelTypeEXT; 202 208 203 bool psphotInitLimitsEXT (psMetadata *recipe ) {209 bool psphotInitLimitsEXT (psMetadata *recipe, pmReadout *readout) { 204 210 205 211 bool status; … … 208 214 char *modelNameEXT = psMetadataLookupStr (&status, recipe, "EXT_MODEL"); 209 215 modelTypeEXT = pmModelClassGetType (modelNameEXT); 210 psphotInitRadiusEXT (recipe, modelTypeEXT); 211 212 return true; 213 } 214 215 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *newSources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) { 216 216 217 psphotInitRadiusEXT (recipe, readout); 218 219 return true; 220 } 221 222 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *newSources, pmPSF *psf, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) { 223 224 float radius; 217 225 bool okEXT, okDBL; 218 226 float chiEXT, chiDBL; … … 222 230 pmModel *EXT = NULL; 223 231 psArray *DBL = NULL; 232 pmMoments psfMoments; 224 233 225 234 // skip the source if we don't think it is extended 235 // XXX are these robust, or do we have better info from the source-size analysis?? 226 236 if (source->type == PM_SOURCE_TYPE_UNKNOWN) return false; 227 237 if (source->type == PM_SOURCE_TYPE_DEFECT) return false; … … 229 239 230 240 // set the radius based on the footprint (also sets the mask pixels) 231 float radius = psphotSetRadiusEXT (readout, source, markVal);241 if (!psphotSetRadiusFootprint(&radius, readout, source, markVal, 1.0)) return false; 232 242 233 243 // XXX note that this changes the source moments that are published... 244 // XXX all published moments should use the same measurement 234 245 // recalculate the source moments using the larger extended-source moments radius 235 246 // at this stage, skip Gaussian windowing, and do not clip pixels by S/N 236 247 // this uses the footprint to judge both radius and aperture? 237 if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) return false; 248 // XXX save the psf-based moments for output 249 psfMoments = *source->moments; 250 if (!pmSourceMoments (source, radius, 0.0, 0.5, maskVal)) { 251 *source->moments = psfMoments; 252 return false; 253 } 238 254 239 255 psTrace ("psphot", 5, "trying blob...\n"); … … 244 260 // this temporary source is used as a place-holder by the psphotEval functions below 245 261 tmpSrc = pmSourceAlloc (); 246 247 // XXX need to handle failures better here 248 EXT = psphotFitEXT (readout, source, modelTypeEXT, maskVal, markVal); 249 if (!EXT) goto escape; 250 if (!isfinite(EXT->params->data.F32[PM_PAR_I0])) goto escape; 251 252 okEXT = psphotEvalEXT (tmpSrc, EXT); 253 chiEXT = EXT ? EXT->chisq / EXT->nDOF : NAN; 254 255 // DBL will always be defined, but DBL->data[n] might not 256 DBL = psphotFitDBL (readout, source, maskVal, markVal); 257 if (!DBL) goto escape; 258 if (!DBL->n) goto escape; 259 260 okDBL = psphotEvalDBL (tmpSrc, DBL->data[0]); 261 okDBL &= psphotEvalDBL (tmpSrc, DBL->data[1]); 262 // XXX should I keep / save the flags set in the eval functions? 262 { 263 // DBL will always be defined, but DBL->data[n] might not 264 DBL = psphotFitDBL (readout, source, fitOptions, maskVal, markVal); 265 if (!DBL) goto escape; 266 if (!DBL->n) goto escape; 267 268 okDBL = psphotEvalDBL (tmpSrc, DBL->data[0]); 269 okDBL &= psphotEvalDBL (tmpSrc, DBL->data[1]); 270 // XXX should I keep / save the flags set in the eval functions? 271 272 // correct first model chisqs for flux trend 273 chiDBL = NAN; 274 ONE = DBL->data[0]; 275 if (ONE) { 276 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 277 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]); 278 ONE->chisqNorm = ONE->chisq / chiTrend; 279 chiDBL = ONE->chisq / ONE->nDOF; // save chisq for double-star/galaxy comparison 280 ONE->fitRadius = radius; 281 } 282 283 // correct second model chisqs for flux trend 284 ONE = DBL->data[1]; 285 if (ONE) { 286 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit"); 287 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]); 288 ONE->chisqNorm = ONE->chisq / chiTrend; 289 ONE->fitRadius = radius; 290 } 291 } 292 293 { 294 // XXX need to handle failures better here 295 EXT = psphotFitEXT (readout, source, fitOptions, modelTypeEXT, maskVal, markVal); 296 if (!EXT) goto escape; 297 if (!isfinite(EXT->params->data.F32[PM_PAR_I0])) goto escape; 298 299 okEXT = psphotEvalEXT (tmpSrc, EXT); 300 chiEXT = EXT ? EXT->chisq / EXT->nDOF : NAN; 301 } 263 302 264 303 // clear the circular mask 265 304 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 266 267 // correct first model chisqs for flux trend268 chiDBL = NAN;269 ONE = DBL->data[0];270 if (ONE) {271 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit");272 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]);273 ONE->chisqNorm = ONE->chisq / chiTrend;274 chiDBL = ONE->chisq / ONE->nDOF; // save chisq for double-star/galaxy comparison275 }276 277 // correct second model chisqs for flux trend278 ONE = DBL->data[1];279 if (ONE) {280 if (!isfinite(ONE->params->data.F32[PM_PAR_I0])) psAbort("nan in fit");281 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]);282 ONE->chisqNorm = ONE->chisq / chiTrend;283 }284 305 285 306 psFree (tmpSrc); … … 298 319 299 320 // both models failed; reject them both 300 // XXX -- change type flags to psf in this case and keep original moments? 321 // XXX -- change type flags to psf in this case, and make sure we subtract it? 322 // reset the psf moments 323 *source->moments = psfMoments; 324 301 325 psFree (EXT); 302 326 psFree (DBL); … … 308 332 309 333 // save new model 334 // XXX save the correct radius... 310 335 source->modelEXT = EXT; 311 source->modelEXT->fitRadius = radius;312 336 source->type = PM_SOURCE_TYPE_EXTENDED; 313 337 source->mode |= PM_SOURCE_MODE_EXTMODEL; … … 327 351 # endif 328 352 353 // reset the psf moments 354 *source->moments = psfMoments; 329 355 return true; 330 356 … … 337 363 source->modelPSF = psMemIncrRefCounter (DBL->data[0]); 338 364 source->mode |= PM_SOURCE_MODE_PAIR; 339 source->modelPSF->fitRadius = radius;340 365 341 366 // copy most data from the primary source (modelEXT, blends stay NULL) 342 pmSource *newSrc = pmSourceCopy (source);367 pmSource *newSrc = pmSourceCopyData (source); 343 368 newSrc->modelPSF = psMemIncrRefCounter (DBL->data[1]); 344 newSrc->modelPSF->fitRadius = radius;345 369 346 370 // build cached models and subtract … … 365 389 # endif 366 390 391 // reset the (original) psf moments 392 *source->moments = psfMoments; 393 *newSrc->moments = psfMoments; 394 367 395 psArrayAdd (newSources, 100, newSrc); 368 396 psFree (newSrc); … … 371 399 372 400 escape: 401 // reset the psf moments 402 *source->moments = psfMoments; 373 403 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 374 404 psFree (tmpSrc); … … 379 409 380 410 // fit a double PSF source to an extended blob 381 psArray *psphotFitDBL (pmReadout *readout, pmSource *source, p sImageMaskType maskVal, psImageMaskType markVal) {411 psArray *psphotFitDBL (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) { 382 412 383 413 float dx, dy; … … 387 417 psEllipseMoments moments; 388 418 psArray *modelSet; 419 420 pmSourceFitOptions options = *fitOptions; 389 421 390 422 NfitDBL ++; … … 403 435 axes = psEllipseMomentsToAxes (moments, 20.0); 404 436 437 if (isnan(axes.major)) return NULL; 438 if (isnan(axes.minor)) return NULL; 439 if (isnan(axes.theta)) return NULL; 440 405 441 // XXX this is really arbitrary: 4 pixel separation? 406 442 dx = 2 * cos (axes.theta); … … 426 462 427 463 // fit PSF model (set/unset the pixel mask) 428 pmSourceFitSet (source, modelSet, PM_SOURCE_FIT_PSF, maskVal); 464 options.mode = PM_SOURCE_FIT_PSF; 465 pmSourceFitSet (source, modelSet, &options, maskVal); 429 466 return (modelSet); 430 467 } 431 468 432 pmModel *psphotFitEXT (pmReadout *readout, pmSource *source, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal) { 469 pmModel *psphotFitEXT (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal) { 470 471 if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) { 472 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); 473 } 474 475 pmSourceFitOptions options = *fitOptions; 433 476 434 477 NfitEXT ++; … … 438 481 439 482 // use the source moments, etc to guess basic model parameters 440 pmModel * EXT= pmSourceModelGuess (source, modelType);441 if (! EXT) {483 pmModel *model = pmSourceModelGuess (source, modelType); 484 if (!model) { 442 485 psTrace ("psphot", 5, "failed to generate a model for source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); 443 486 return NULL; 444 487 } 445 488 489 // for sersic models, use a grid search to choose an index, then float the params there 490 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { 491 // for the test fits, use a somewhat smaller radius 492 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 0.5); 493 psphotFitSersicIndex (model, readout, source, fitOptions, maskVal, markVal); 494 } 495 496 if (!psphotSetRadiusModel (model, readout, source, markVal, true)) { 497 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 1.0); 498 } 499 500 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { 501 options.mode = PM_SOURCE_FIT_NO_INDEX; 502 } else { 503 options.mode = PM_SOURCE_FIT_EXT; 504 } 505 506 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); 507 pmSourceFitModel (source, model, &options, maskVal); 508 fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 509 510 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); 511 return (model); 512 } 513 514 pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 515 446 516 if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) { 447 517 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); 448 518 } 449 519 520 pmSourceFitOptions options = *fitOptions; 521 522 NfitPCM ++; 523 524 // maskVal is used to test for rejected pixels, and must include markVal 525 maskVal |= markVal; 526 527 // allocate the model 528 pmModel *model = pmModelAlloc(modelType); 529 if (!model) { 530 return NULL; 531 } 532 533 pmPCMdata *pcm = pmPCMinit (source, &options, model, maskVal, psfSize); 534 if (!pcm) { 535 psTrace ("psphot", 5, "failed to generate a model for source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); 536 model->flags |= PM_MODEL_STATUS_BADARGS; // XXX this is probably already set in pmPCMinit 537 return model; 538 } 539 540 // use the source moments, etc to guess basic model parameters 541 if (!pmSourceModelGuessPCM (pcm, source, maskVal, markVal)) { 542 psFree (pcm); 543 model->flags |= PM_MODEL_STATUS_BADARGS; 544 return model; 545 } 546 547 // for sersic models, use a grid search to choose an index, then float the params there 548 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { 549 // for the test fits, use a somewhat smaller radius 550 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 0.5); 551 552 if (!psphotFitSersicIndexPCM (pcm, readout, source, fitOptions, maskVal, markVal, psfSize)) { 553 model->flags |= PM_MODEL_STATUS_BADARGS; 554 return model; 555 } 556 } 557 558 if (!psphotSetRadiusModel (model, readout, source, markVal, true)) { 559 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 1.0); 560 } 561 562 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { 563 options.mode = PM_SOURCE_FIT_NO_INDEX; 564 } else { 565 options.mode = PM_SOURCE_FIT_EXT; 566 } 567 // update the pcm elements if we have changed the circumstance (options.mode or source->pixels) 568 pmPCMupdate(pcm, source, &options, model); 569 570 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); 571 pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize); 572 fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 573 574 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); 575 psFree (pcm); 576 577 return model; 578 } 579 580 // note that these should be 1/2n of the standard sersic index 581 float indexGuess[] = {0.5, 0.33, 0.25, 0.167, 0.125, 0.083}; 582 # define N_INDEX_GUESS 6 583 584 // A sersic model is very sensitive to the index. attempt to find the index first by grid search in just the index 585 // for a sersic model, attempt to fit just the index and normalization with a modest number of iterations 586 bool psphotFitSersicIndex (pmModel *model, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) { 587 588 assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC")); 589 590 pmSourceFitOptions options = *fitOptions; 591 450 592 // fit EXT (not PSF) model (set/unset the pixel mask) 451 pmSourceFitModel (source, EXT, PM_SOURCE_FIT_EXT, maskVal); 452 return (EXT); 453 } 593 options.mode = PM_SOURCE_FIT_NO_INDEX; 594 options.nIter = 4; 595 596 int iMin = -1; 597 float xMin = NAN; 598 float chiSquare[N_INDEX_GUESS]; 599 600 for (int i = 0; i < N_INDEX_GUESS; i++) { 601 model->params->data.F32[PM_PAR_7] = indexGuess[i]; 602 603 if (!model->modelGuess(model, source)) { 604 model->flags |= PM_MODEL_STATUS_BADARGS; 605 return false; 606 } 607 608 // each time we change the model guess, we need to adjust the radius 609 // XXX this did not work : we do not need such a large radius -- just uses moments-based radius 610 if (false && !psphotSetRadiusModel (model, readout, source, markVal, false)) { 611 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 0.5); 612 } 613 614 pmSourceFitModel (source, model, &options, maskVal); 615 fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 616 617 chiSquare[i] = model->chisqNorm; 618 if (i == 0) { 619 xMin = chiSquare[i]; 620 iMin = i; 621 } else { 622 if (chiSquare[i] < xMin) { 623 xMin = chiSquare[i]; 624 iMin = i; 625 } 626 } 627 } 628 assert (iMin >= 0); 629 630 model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it 631 model->params->data.F32[PM_PAR_7] = indexGuess[iMin]; 632 model->modelGuess(model, source); 633 634 // each time we change the model guess, we need to adjust the radius 635 // if (!psphotSetRadiusModel (model, readout, source, markVal, true)) { 636 // psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal); 637 // } 638 639 return true; 640 } 641 642 // A sersic model is very sensitive to the index. attempt to find the index first by grid search in just the index 643 // for a sersic model, attempt to fit just the index and normalization with a modest number of iterations 644 bool psphotFitSersicIndexPCM (pmPCMdata *pcm, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 645 646 pmModel *model = pcm->modelConv; 647 648 assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC")); 649 650 pmSourceFitOptions options = *fitOptions; 651 652 // fit EXT (not PSF) model (set/unset the pixel mask) 653 options.mode = PM_SOURCE_FIT_NO_INDEX; 654 options.nIter = 4; 655 656 // update the pcm elements if we have changed the circumstance (here, options.mode) 657 pmPCMupdate(pcm, source, &options, model); 658 659 int iMin = -1; 660 float xMin = NAN; 661 float chiSquare[N_INDEX_GUESS]; 662 663 for (int i = 0; i < N_INDEX_GUESS; i++) { 664 model->params->data.F32[PM_PAR_7] = indexGuess[i]; 665 666 if (!model->modelGuess(model, source)) { 667 model->flags |= PM_MODEL_STATUS_BADARGS; 668 return false; 669 } 670 671 // each time we change the model guess, we need to adjust the radius 672 // XXX this did not work : we do not need such a large radius -- just uses moments-based radius 673 if (false && !psphotSetRadiusModel (model, readout, source, markVal, false)) { 674 psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 0.5); 675 } 676 677 pmSourceFitModel (source, model, &options, maskVal); 678 fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 679 680 // pmSourceModelGuessPCM(pcm, source, maskVal, markVal); 681 // pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize); 682 683 chiSquare[i] = model->chisq; 684 if (i == 0) { 685 xMin = chiSquare[i]; 686 iMin = i; 687 } else { 688 if (chiSquare[i] < xMin) { 689 xMin = chiSquare[i]; 690 iMin = i; 691 } 692 } 693 } 694 assert (iMin >= 0); 695 696 model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it 697 model->params->data.F32[PM_PAR_7] = indexGuess[iMin]; 698 699 pmSourceModelGuessPCM(pcm, source, maskVal, markVal); 700 701 return true; 702 } -
trunk/psphot/src/psphotSourceSize.c
r28013 r29004 1 1 # include "psphotInternal.h" 2 2 # include <gsl/gsl_sf_gamma.h> 3 4 # define KRON 1 3 5 4 6 typedef struct { … … 168 170 psVector *ApErr = psVectorAllocEmpty (100, PS_TYPE_F32); 169 171 172 psImageMaskType markVal = options->markVal; 170 173 psImageMaskType maskVal = options->maskVal | options->markVal; 171 174 … … 189 192 190 193 // XXX can we test if psfMag is set and calculate only if needed? 191 pmSourceMagnitudes (source, psf, photMode, maskVal ); // maskVal includes markVal194 pmSourceMagnitudes (source, psf, photMode, maskVal, markVal); 192 195 193 196 // clear the mask bit … … 197 200 pmSourceSub (source, PM_MODEL_OP_FULL, options->maskVal); 198 201 202 // XXX test: switch to kron flux 203 # if (KRON) 204 float apMag = -2.5*log10(source->moments->KronFlux); 205 # else 199 206 float apMag = -2.5*log10(source->moments->Sum); 207 # endif 200 208 float dMag = source->psfMag - apMag; 201 209 … … 288 296 pmSourcePhotometryMode photMode = PM_SOURCE_PHOT_WEIGHT; 289 297 298 psImageMaskType markVal = options->markVal; 290 299 psImageMaskType maskVal = options->maskVal | options->markVal; 291 300 … … 335 344 336 345 // XXX can we test if psfMag is set and calculate only if needed? 337 pmSourceMagnitudes (source, psf, photMode, maskVal ); // maskVal includes markVal346 pmSourceMagnitudes (source, psf, photMode, maskVal, markVal); 338 347 339 348 // clear the mask bit … … 343 352 pmSourceSub (source, PM_MODEL_OP_FULL, options->maskVal); 344 353 354 # if (KRON) 355 float apMag = -2.5*log10(source->moments->KronFlux); 356 # else 345 357 float apMag = -2.5*log10(source->moments->Sum); 358 # endif 346 359 float dMag = source->psfMag - apMag; 347 360 348 361 // set nSigma to include both systematic and poisson error terms 349 362 // XXX the 'poisson error' contribution for size is probably wrong... 350 float nSigmaMAG = (dMag - options->ApResid) / hypot(source->errMag, options->ApSysErr); 363 // XXX add in a hard floor on the Ap Sys Err (to be a bit generous) 364 float nSigmaMAG = (dMag - options->ApResid) / hypot(source->errMag, hypot(options->ApSysErr, 0.025)); 351 365 float nSigmaMXX = (Mxx - psfClump->X) / hypot(psfClump->dX, psfClump->X*psfClump->X*source->errMag); 352 366 float nSigmaMYY = (Myy - psfClump->Y) / hypot(psfClump->dY, psfClump->Y*psfClump->Y*source->errMag); 353 367 354 // partially-masked sources are more likely to be mis-measured PSFs 368 fprintf (stderr, "%f %f : Mxx: %f, Myy: %f, dx: %f, dy: %f, psfMag: %f, apMag: %f, dMag: %f, errMag: %f, nSigmaMag: %f, nSigmaMxx: %f, nSigmaMyy: %f\n", 369 source->peak->xf, source->peak->yf, Mxx, Myy, source->peak->xf - source->moments->Mx, source->peak->yf - source->moments->My, 370 source->psfMag, apMag, dMag, source->errMag, nSigmaMAG, nSigmaMXX, nSigmaMYY); 371 372 // XXX double check on ths stuff!! partially-masked sources are more likely to be mis-measured PSFs 355 373 float sizeBias = 1.0; 356 if (source->pixWeight < 0.9) { 374 if (source->pixWeightNotBad < 0.9) { 375 sizeBias = 3.0; 376 } 377 if (source->pixWeightNotPoor < 0.9) { 357 378 sizeBias = 3.0; 358 379 } … … 389 410 if (isCR) { 390 411 psTrace("psphotSourceClassRegion.CR",4,"CLASS: %g %g %f\t%g %g %g %g %g %g\t%g %g\t%g CR\t%g %g\n", 391 source->peak->xf,source->peak->yf,source->pixWeight ,Mxx,Myy,psfClump->X,psfClump->Y,psfClump->dX,psfClump->dY,apMag,dMag,nSigmaMAG,412 source->peak->xf,source->peak->yf,source->pixWeightNotBad,Mxx,Myy,psfClump->X,psfClump->Y,psfClump->dX,psfClump->dY,apMag,dMag,nSigmaMAG, 392 413 options->nSigmaApResid,sizeBias*options->nSigmaMoments); 393 414 source->mode |= PM_SOURCE_MODE_DEFECT; -
trunk/psphot/src/psphotSourceStats.c
r28419 r29004 1 1 # include "psphotInternal.h" 2 void pmSourceMomentsSetVerbose(bool state); 2 3 3 4 // convert detections to sources and measure their basic properties (moments, local sky, sky … … 369 370 maskVal |= markVal; 370 371 372 // XXX test : pmSourceMomentsSetVerbose(true); 373 371 374 // threaded measurement of the sources moments 372 375 int Nfail = 0; … … 408 411 // measure basic source moments (no S/N clipping on input pixels) 409 412 status = pmSourceMoments (source, RADIUS, SIGMA, 0.0, maskVal); 413 // XXX moments / aperture test: 414 if (0) { 415 // clear the mask bit and set the circular mask pixels 416 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 417 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, 4.0*source->moments->Mrf, "OR", markVal); 418 419 float apMag = NAN; 420 pmSourcePhotometryAper (&apMag, NULL, source->pixels, source->maskObj, maskVal); 421 fprintf (stderr, "apMag: %f, kronMag: %f\n", apMag, -2.5*log10(source->moments->KronFlux)); 422 423 // clear the mask bit 424 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 425 } 410 426 if (status) { 411 427 Nmoments ++; … … 502 518 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX); 503 519 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY); 504 psphotVisualPlotMoments (recipe, analysis, sources); 520 if (pmVisualTestLevel("psphot.moments.full", 2)) { 521 psphotVisualPlotMoments (recipe, analysis, sources); 522 } 505 523 #endif 506 524 -
trunk/psphot/src/psphotVisual.c
r28128 r29004 66 66 int myKapa = psphotKapaChannel (channel); 67 67 if (!(strcasecmp (overlay, "all"))) { 68 KiiEraseOverlay (myKapa, "red");69 KiiEraseOverlay (myKapa, "green");70 KiiEraseOverlay (myKapa, "blue");71 KiiEraseOverlay (myKapa, "yellow");72 return true;68 KiiEraseOverlay (myKapa, "red"); 69 KiiEraseOverlay (myKapa, "green"); 70 KiiEraseOverlay (myKapa, "blue"); 71 KiiEraseOverlay (myKapa, "yellow"); 72 return true; 73 73 } 74 74 KiiEraseOverlay (myKapa, overlay); … … 182 182 bool psphotVisualShowImage (pmReadout *readout) { 183 183 184 if (!pmVisual IsVisual()) return true;184 if (!pmVisualTestLevel("psphot.image", 1)) return true; 185 185 186 186 int kapa = psphotKapaChannel (1); … … 199 199 pmReadout *backgnd; 200 200 201 if (! DEBUG && !pmVisualIsVisual()) return true;201 if (!pmVisualTestLevel("psphot.image.backgnd", 2)) return true; 202 202 203 203 int kapa = psphotKapaChannel (1); … … 208 208 209 209 if (file->mode == PM_FPA_MODE_INTERNAL) { 210 backgnd = file->readout;210 backgnd = file->readout; 211 211 } else { 212 backgnd = pmFPAviewThisReadout (view, file->fpa);212 backgnd = pmFPAviewThisReadout (view, file->fpa); 213 213 } 214 214 … … 222 222 bool psphotVisualShowSignificance (psImage *image, float min, float max) { 223 223 224 if (! DEBUG && !pmVisualIsVisual()) return true;224 if (!pmVisualTestLevel("psphot.image.signif", 2)) return true; 225 225 226 226 int kapa = psphotKapaChannel (1); … … 233 233 } 234 234 235 bool psphotVisualShowLogSignificance (psImage *image, float min, float max) { 236 237 if (!pmVisualTestLevel("psphot.image.logsignif", 3)) return true; 238 239 int kapa = psphotKapaChannel (1); 240 if (kapa == -1) return false; 241 242 psImage *lsig = (psImage *) psUnaryOp (NULL, image, "log"); 243 psphotVisualRangeImage (kapa, lsig, "log-signif", 2, min, max); 244 psFree (lsig); 245 246 pmVisualAskUser(NULL); 247 return true; 248 } 249 250 // XXX : requires psphotVisualShowImage 235 251 bool psphotVisualShowPeaks (pmDetections *detections) { 236 252 … … 238 254 KiiOverlay *overlay; 239 255 240 if (! DEBUG && !pmVisualIsVisual()) return true;256 if (!pmVisualTestLevel("psphot.objects.peaks", 1)) return true; 241 257 242 258 int kapa = psphotKapaChannel (1); … … 252 268 for (int i = 0; i < peaks->n; i++) { 253 269 254 pmPeak *peak = peaks->data[i];255 if (peak == NULL) continue;256 257 overlay[Noverlay].type = KII_OVERLAY_BOX;258 overlay[Noverlay].x = peak->xf;259 overlay[Noverlay].y = peak->yf;260 overlay[Noverlay].dx = 2.0;261 overlay[Noverlay].dy = 2.0;262 overlay[Noverlay].angle = 0.0;263 overlay[Noverlay].text = NULL;264 Noverlay ++;270 pmPeak *peak = peaks->data[i]; 271 if (peak == NULL) continue; 272 273 overlay[Noverlay].type = KII_OVERLAY_BOX; 274 overlay[Noverlay].x = peak->xf; 275 overlay[Noverlay].y = peak->yf; 276 overlay[Noverlay].dx = 2.0; 277 overlay[Noverlay].dy = 2.0; 278 overlay[Noverlay].angle = 0.0; 279 overlay[Noverlay].text = NULL; 280 Noverlay ++; 265 281 } 266 282 … … 272 288 } 273 289 290 // XXX : requires psphotVisualShowImage 274 291 bool psphotVisualShowFootprints (pmDetections *detections) { 275 292 … … 277 294 KiiOverlay *overlay; 278 295 279 if (! DEBUG && !pmVisualIsVisual()) return true;296 if (!pmVisualTestLevel("psphot.objects.footprints", 3)) return true; 280 297 281 298 int kapa = psphotKapaChannel (1); … … 292 309 for (int i = 0; i < footprints->n; i++) { 293 310 294 pmSpan *span = NULL;295 296 pmFootprint *footprint = footprints->data[i];297 if (footprint == NULL) continue;298 if (footprint->spans == NULL) continue;299 if (footprint->spans->n < 1) continue;300 301 // draw the top302 // XXX need to allow top (and bottom) to have more than one span303 span = footprint->spans->data[0];304 overlay[Noverlay].type = KII_OVERLAY_LINE;305 overlay[Noverlay].x = span->x0;306 overlay[Noverlay].y = span->y;307 overlay[Noverlay].dx = span->x1 - span->x0;308 overlay[Noverlay].dy = 0;309 overlay[Noverlay].angle = 0.0;310 overlay[Noverlay].text = NULL;311 Noverlay ++;312 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);313 314 int ys = span->y;315 int x0s = span->x0;316 int x1s = span->x1;317 318 // draw the outer span edges319 for (int j = 1; j < footprint->spans->n; j++) {320 pmSpan *span1 = footprint->spans->data[j];321 322 int ye = span1->y;323 int x0e = span1->x0;324 int x1e = span1->x1;325 326 // we cannot have two discontinuous spans on the top or bottom, right? (no, probably not right)327 // find all of the spans in this row and generate x0e, x01:328 for (int k = j + 1; k < footprint->spans->n; k++) {329 pmSpan *span2 = footprint->spans->data[k];330 if (span2->y > span1->y) break;331 x0e = PS_MIN (x0e, span2->x0);332 x1e = PS_MAX (x1e, span2->x1);333 j++;334 }335 336 overlay[Noverlay].type = KII_OVERLAY_LINE;337 overlay[Noverlay].x = x0s;338 overlay[Noverlay].y = ys;339 overlay[Noverlay].dx = x0e - x0s;340 overlay[Noverlay].dy = ye - ys;341 overlay[Noverlay].angle = 0.0;342 overlay[Noverlay].text = NULL;343 Noverlay ++;344 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);345 346 overlay[Noverlay].type = KII_OVERLAY_LINE;347 overlay[Noverlay].x = x1s;348 overlay[Noverlay].y = ys;349 overlay[Noverlay].dx = x1e - x1s;350 overlay[Noverlay].dy = ye - ys;351 overlay[Noverlay].angle = 0.0;352 overlay[Noverlay].text = NULL;353 Noverlay ++;354 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);355 356 ys = ye;357 x0s = x0e;358 x1s = x1e;359 }360 361 // draw the bottom362 span = footprint->spans->data[footprint->spans->n - 1];363 overlay[Noverlay].type = KII_OVERLAY_LINE;364 overlay[Noverlay].x = span->x0;365 overlay[Noverlay].y = span->y;366 overlay[Noverlay].dx = span->x1 - span->x0;367 overlay[Noverlay].dy = 0;368 overlay[Noverlay].angle = 0.0;369 overlay[Noverlay].text = NULL;370 Noverlay ++;371 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);311 pmSpan *span = NULL; 312 313 pmFootprint *footprint = footprints->data[i]; 314 if (footprint == NULL) continue; 315 if (footprint->spans == NULL) continue; 316 if (footprint->spans->n < 1) continue; 317 318 // draw the top 319 // XXX need to allow top (and bottom) to have more than one span 320 span = footprint->spans->data[0]; 321 overlay[Noverlay].type = KII_OVERLAY_LINE; 322 overlay[Noverlay].x = span->x0; 323 overlay[Noverlay].y = span->y; 324 overlay[Noverlay].dx = span->x1 - span->x0; 325 overlay[Noverlay].dy = 0; 326 overlay[Noverlay].angle = 0.0; 327 overlay[Noverlay].text = NULL; 328 Noverlay ++; 329 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 330 331 int ys = span->y; 332 int x0s = span->x0; 333 int x1s = span->x1; 334 335 // draw the outer span edges 336 for (int j = 1; j < footprint->spans->n; j++) { 337 pmSpan *span1 = footprint->spans->data[j]; 338 339 int ye = span1->y; 340 int x0e = span1->x0; 341 int x1e = span1->x1; 342 343 // we cannot have two discontinuous spans on the top or bottom, right? (no, probably not right) 344 // find all of the spans in this row and generate x0e, x01: 345 for (int k = j + 1; k < footprint->spans->n; k++) { 346 pmSpan *span2 = footprint->spans->data[k]; 347 if (span2->y > span1->y) break; 348 x0e = PS_MIN (x0e, span2->x0); 349 x1e = PS_MAX (x1e, span2->x1); 350 j++; 351 } 352 353 overlay[Noverlay].type = KII_OVERLAY_LINE; 354 overlay[Noverlay].x = x0s; 355 overlay[Noverlay].y = ys; 356 overlay[Noverlay].dx = x0e - x0s; 357 overlay[Noverlay].dy = ye - ys; 358 overlay[Noverlay].angle = 0.0; 359 overlay[Noverlay].text = NULL; 360 Noverlay ++; 361 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 362 363 overlay[Noverlay].type = KII_OVERLAY_LINE; 364 overlay[Noverlay].x = x1s; 365 overlay[Noverlay].y = ys; 366 overlay[Noverlay].dx = x1e - x1s; 367 overlay[Noverlay].dy = ye - ys; 368 overlay[Noverlay].angle = 0.0; 369 overlay[Noverlay].text = NULL; 370 Noverlay ++; 371 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 372 373 ys = ye; 374 x0s = x0e; 375 x1s = x1e; 376 } 377 378 // draw the bottom 379 span = footprint->spans->data[footprint->spans->n - 1]; 380 overlay[Noverlay].type = KII_OVERLAY_LINE; 381 overlay[Noverlay].x = span->x0; 382 overlay[Noverlay].y = span->y; 383 overlay[Noverlay].dx = span->x1 - span->x0; 384 overlay[Noverlay].dy = 0; 385 overlay[Noverlay].angle = 0.0; 386 overlay[Noverlay].text = NULL; 387 Noverlay ++; 388 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 372 389 } 373 390 … … 379 396 } 380 397 398 // XXX : requires psphotVisualShowImage 381 399 bool psphotVisualShowMoments (psArray *sources) { 382 400 … … 387 405 psEllipseAxes axes; 388 406 389 if (! DEBUG && !pmVisualIsVisual()) return true;407 if (!pmVisualTestLevel("psphot.objects.moments", 2)) return true; 390 408 391 409 int kapa = psphotKapaChannel (1); … … 401 419 for (int i = 0; i < sources->n; i++) { 402 420 403 pmSource *source = sources->data[i];404 if (source == NULL) continue;405 406 pmMoments *moments = source->moments;407 if (moments == NULL) continue;408 409 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;410 overlay[Noverlay].x = moments->Mx;411 overlay[Noverlay].y = moments->My;412 413 emoments.x2 = moments->Mxx;414 emoments.xy = moments->Mxy;415 emoments.y2 = moments->Myy;416 417 axes = psEllipseMomentsToAxes (emoments, 20.0);418 419 overlay[Noverlay].dx = 2.0*axes.major;420 overlay[Noverlay].dy = 2.0*axes.minor;421 422 overlay[Noverlay].angle = axes.theta * PS_DEG_RAD;423 424 overlay[Noverlay].text = NULL;425 Noverlay ++;421 pmSource *source = sources->data[i]; 422 if (source == NULL) continue; 423 424 pmMoments *moments = source->moments; 425 if (moments == NULL) continue; 426 427 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 428 overlay[Noverlay].x = moments->Mx; 429 overlay[Noverlay].y = moments->My; 430 431 emoments.x2 = moments->Mxx; 432 emoments.xy = moments->Mxy; 433 emoments.y2 = moments->Myy; 434 435 axes = psEllipseMomentsToAxes (emoments, 20.0); 436 437 overlay[Noverlay].dx = 2.0*axes.major; 438 overlay[Noverlay].dy = 2.0*axes.minor; 439 440 overlay[Noverlay].angle = axes.theta * PS_DEG_RAD; 441 442 overlay[Noverlay].text = NULL; 443 Noverlay ++; 426 444 } 427 445 … … 439 457 KapaSection section; 440 458 441 if (! DEBUG && !pmVisualIsVisual()) return true;459 if (!pmVisualTestLevel("psphot.moments", 1)) return true; 442 460 443 461 int myKapa = psphotKapaChannel (2); … … 456 474 float Ymin = 1000.0, Ymax = 0.0; 457 475 { 458 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");459 for (int n = 0; n < nRegions; n++) {460 461 char regionName[64];462 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);463 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);464 465 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");466 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");467 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");468 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");469 470 float X0 = psfX - 4.0*psfdX;471 float X1 = psfX + 4.0*psfdX;472 float Y0 = psfY - 4.0*psfdY;473 float Y1 = psfY + 4.0*psfdY;474 475 if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); }476 if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); }477 if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); }478 if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); }479 }476 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS"); 477 for (int n = 0; n < nRegions; n++) { 478 479 char regionName[64]; 480 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n); 481 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 482 483 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 484 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); 485 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); 486 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); 487 488 float X0 = psfX - 4.0*psfdX; 489 float X1 = psfX + 4.0*psfdX; 490 float Y0 = psfY - 4.0*psfdY; 491 float Y1 = psfY + 4.0*psfdY; 492 493 if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); } 494 if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); } 495 if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); } 496 if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); } 497 } 480 498 } 481 499 Xmin = PS_MAX(Xmin, -0.1); … … 498 516 int nF = 0; 499 517 for (int i = 0; i < sources->n; i++) { 500 pmSource *source = sources->data[i];501 if (source->moments == NULL)502 continue;503 504 xFaint->data.F32[nF] = source->moments->Mxx;505 yFaint->data.F32[nF] = source->moments->Myy;506 mFaint->data.F32[nF] = -2.5*log10(source->moments->Sum);507 nF++;508 509 // XXX make this a user-defined cutoff510 if (source->moments->SN < SN_LIM)511 continue;512 513 xBright->data.F32[nB] = source->moments->Mxx;514 yBright->data.F32[nB] = source->moments->Myy;515 mBright->data.F32[nB] = -2.5*log10(source->moments->Sum);516 nB++;518 pmSource *source = sources->data[i]; 519 if (source->moments == NULL) 520 continue; 521 522 xFaint->data.F32[nF] = source->moments->Mxx; 523 yFaint->data.F32[nF] = source->moments->Myy; 524 mFaint->data.F32[nF] = -2.5*log10(source->moments->Sum); 525 nF++; 526 527 // XXX make this a user-defined cutoff 528 if (source->moments->SN < SN_LIM) 529 continue; 530 531 xBright->data.F32[nB] = source->moments->Mxx; 532 yBright->data.F32[nB] = source->moments->Myy; 533 mBright->data.F32[nB] = -2.5*log10(source->moments->Sum); 534 nB++; 517 535 } 518 536 xFaint->n = nF; … … 652 670 // draw N circles to outline the clumps 653 671 { 654 KapaSelectSection (myKapa, "MxxMyy");655 656 // draw a circle centered on psfX,Y with size of the psf limit657 psVector *xLimit = psVectorAlloc (120, PS_TYPE_F32);658 psVector *yLimit = psVectorAlloc (120, PS_TYPE_F32);659 660 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");661 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");662 663 graphdata.color = KapaColorByName ("blue");664 graphdata.style = 0;665 666 graphdata.xmin = Xmin;667 graphdata.ymin = Ymin;668 graphdata.xmax = Xmax;669 graphdata.ymax = Ymax;670 KapaSetLimits (myKapa, &graphdata);671 672 for (int n = 0; n < nRegions; n++) {673 674 char regionName[64];675 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);676 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);677 678 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");679 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");680 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");681 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");682 float Rx = psfdX * PSF_CLUMP_NSIGMA;683 float Ry = psfdY * PSF_CLUMP_NSIGMA;684 685 for (int i = 0; i < xLimit->n; i++) {686 xLimit->data.F32[i] = Rx*cos(i*2.0*M_PI/120.0) + psfX;687 yLimit->data.F32[i] = Ry*sin(i*2.0*M_PI/120.0) + psfY;688 }689 KapaPrepPlot (myKapa, xLimit->n, &graphdata);690 KapaPlotVector (myKapa, xLimit->n, xLimit->data.F32, "x");691 KapaPlotVector (myKapa, yLimit->n, yLimit->data.F32, "y");692 }693 psFree (xLimit);694 psFree (yLimit);672 KapaSelectSection (myKapa, "MxxMyy"); 673 674 // draw a circle centered on psfX,Y with size of the psf limit 675 psVector *xLimit = psVectorAlloc (120, PS_TYPE_F32); 676 psVector *yLimit = psVectorAlloc (120, PS_TYPE_F32); 677 678 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS"); 679 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA"); 680 681 graphdata.color = KapaColorByName ("blue"); 682 graphdata.style = 0; 683 684 graphdata.xmin = Xmin; 685 graphdata.ymin = Ymin; 686 graphdata.xmax = Xmax; 687 graphdata.ymax = Ymax; 688 KapaSetLimits (myKapa, &graphdata); 689 690 for (int n = 0; n < nRegions; n++) { 691 692 char regionName[64]; 693 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n); 694 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 695 696 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 697 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); 698 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); 699 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); 700 float Rx = psfdX * PSF_CLUMP_NSIGMA; 701 float Ry = psfdY * PSF_CLUMP_NSIGMA; 702 703 for (int i = 0; i < xLimit->n; i++) { 704 xLimit->data.F32[i] = Rx*cos(i*2.0*M_PI/120.0) + psfX; 705 yLimit->data.F32[i] = Ry*sin(i*2.0*M_PI/120.0) + psfY; 706 } 707 KapaPrepPlot (myKapa, xLimit->n, &graphdata); 708 KapaPlotVector (myKapa, xLimit->n, xLimit->data.F32, "x"); 709 KapaPlotVector (myKapa, yLimit->n, yLimit->data.F32, "y"); 710 } 711 psFree (xLimit); 712 psFree (yLimit); 695 713 } 696 714 … … 721 739 for (int i = 0; i < sources->n; i++) { 722 740 723 pmSource *source = sources->data[i];724 if (source == NULL) continue;725 726 if (source->type != type) continue;727 if (mode && !(source->mode & mode)) continue;728 729 pmMoments *moments = source->moments;730 if (moments == NULL) continue;731 732 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;733 overlay[Noverlay].x = moments->Mx;734 overlay[Noverlay].y = moments->My;735 736 emoments.x2 = moments->Mxx;737 emoments.y2 = moments->Myy;738 emoments.xy = moments->Mxy;739 740 axes = psEllipseMomentsToAxes (emoments, 20.0);741 742 overlay[Noverlay].dx = 2.0*axes.major;743 overlay[Noverlay].dy = 2.0*axes.minor;744 overlay[Noverlay].angle = axes.theta * PS_DEG_RAD;745 overlay[Noverlay].text = NULL;746 Noverlay ++;741 pmSource *source = sources->data[i]; 742 if (source == NULL) continue; 743 744 if (source->type != type) continue; 745 if (mode && !(source->mode & mode)) continue; 746 747 pmMoments *moments = source->moments; 748 if (moments == NULL) continue; 749 750 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 751 overlay[Noverlay].x = moments->Mx; 752 overlay[Noverlay].y = moments->My; 753 754 emoments.x2 = moments->Mxx; 755 emoments.y2 = moments->Myy; 756 emoments.xy = moments->Mxy; 757 758 axes = psEllipseMomentsToAxes (emoments, 20.0); 759 760 overlay[Noverlay].dx = 2.0*axes.major; 761 overlay[Noverlay].dy = 2.0*axes.minor; 762 overlay[Noverlay].angle = axes.theta * PS_DEG_RAD; 763 overlay[Noverlay].text = NULL; 764 Noverlay ++; 747 765 } 748 766 … … 753 771 } 754 772 773 // XXX : requires psphotVisualShowImage 755 774 bool psphotVisualShowRoughClass (psArray *sources) { 756 775 757 if (! DEBUG && !pmVisualIsVisual()) return true;776 if (!pmVisualTestLevel("psphot.objects.size", 3)) return true; 758 777 759 778 int myKapa = psphotKapaChannel (1); … … 776 795 bool psphotVisualShowPSFModel (pmReadout *readout, pmPSF *psf) { 777 796 778 if (! DEBUG && !pmVisualIsVisual()) return true;797 if (!pmVisualTestLevel("psphot.psf.model", 1)) return true; 779 798 780 799 int myKapa = psphotKapaChannel (3); … … 797 816 // generate a fake model at each of the 3x3 image grid positions 798 817 for (int x = -2; x <= +2; x ++) { 799 for (int y = -2; y <= +2; y ++) {800 // use the center of the center pixel of the image801 float xc = (int)((0.5 + 0.225*x)*readout->image->numCols) + readout->image->col0 + 0.5;802 float yc = (int)((0.5 + 0.225*y)*readout->image->numRows) + readout->image->row0 + 0.5;803 804 // assign the x and y coords to the image center805 // create an object with center intensity of 1000806 modelRef->params->data.F32[PM_PAR_SKY] = 0;807 modelRef->params->data.F32[PM_PAR_I0] = 1000;808 modelRef->params->data.F32[PM_PAR_XPOS] = xc;809 modelRef->params->data.F32[PM_PAR_YPOS] = yc;810 811 // create modelPSF from this model812 pmModel *model = pmModelFromPSF (modelRef, psf);813 if (!model) continue;814 815 // place the reference object in the image center816 // no need to mask the source here817 // XXX should we measure this for the analytical model only or the full model?818 pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, x*DX, y*DY);819 pmModelAddWithOffset (funMosaic, NULL, model, PM_MODEL_OP_FUNC | PM_MODEL_OP_CENTER, 0, x*DX, y*DY);820 pmModelAddWithOffset (resMosaic, NULL, model, PM_MODEL_OP_RES0 | PM_MODEL_OP_RES1 | PM_MODEL_OP_CENTER, 0, x*DX, y*DY);821 psFree (model);822 }818 for (int y = -2; y <= +2; y ++) { 819 // use the center of the center pixel of the image 820 float xc = (int)((0.5 + 0.225*x)*readout->image->numCols) + readout->image->col0 + 0.5; 821 float yc = (int)((0.5 + 0.225*y)*readout->image->numRows) + readout->image->row0 + 0.5; 822 823 // assign the x and y coords to the image center 824 // create an object with center intensity of 1000 825 modelRef->params->data.F32[PM_PAR_SKY] = 0; 826 modelRef->params->data.F32[PM_PAR_I0] = 1000; 827 modelRef->params->data.F32[PM_PAR_XPOS] = xc; 828 modelRef->params->data.F32[PM_PAR_YPOS] = yc; 829 830 // create modelPSF from this model 831 pmModel *model = pmModelFromPSF (modelRef, psf); 832 if (!model) continue; 833 834 // place the reference object in the image center 835 // no need to mask the source here 836 // XXX should we measure this for the analytical model only or the full model? 837 pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, x*DX, y*DY); 838 pmModelAddWithOffset (funMosaic, NULL, model, PM_MODEL_OP_FUNC | PM_MODEL_OP_CENTER, 0, x*DX, y*DY); 839 pmModelAddWithOffset (resMosaic, NULL, model, PM_MODEL_OP_RES0 | PM_MODEL_OP_RES1 | PM_MODEL_OP_CENTER, 0, x*DX, y*DY); 840 psFree (model); 841 } 823 842 } 824 843 … … 842 861 bool status; 843 862 844 if (! DEBUG && !pmVisualIsVisual()) return true;863 if (!pmVisualTestLevel("psphot.psf.stars", 2)) return true; 845 864 846 865 int myKapa = psphotKapaChannel (3); … … 871 890 for (int i = 0; i < sources->n; i++) { 872 891 873 pmSource *source = sources->data[i];874 875 bool keep = false;876 keep |= (source->mode & PM_SOURCE_MODE_PSFSTAR);877 if (!keep) continue;878 879 // how does this subimage get placed into the output image?880 // DX = source->pixels->numCols881 // DY = source->pixels->numRows882 883 if (dX + DX > NX) {884 // too wide for the rest of this row885 if (dX == 0) {886 // alone on this row887 NY += DY;888 dX = 0;889 dY = 0;890 } else {891 // start the next row892 NY += dY;893 dX = DX;894 dY = DY;895 }896 } else {897 // extend this row898 dX += DX;899 dY = PS_MAX (dY, DY);900 }892 pmSource *source = sources->data[i]; 893 894 bool keep = false; 895 keep |= (source->mode & PM_SOURCE_MODE_PSFSTAR); 896 if (!keep) continue; 897 898 // how does this subimage get placed into the output image? 899 // DX = source->pixels->numCols 900 // DY = source->pixels->numRows 901 902 if (dX + DX > NX) { 903 // too wide for the rest of this row 904 if (dX == 0) { 905 // alone on this row 906 NY += DY; 907 dX = 0; 908 dY = 0; 909 } else { 910 // start the next row 911 NY += dY; 912 dX = DX; 913 dY = DY; 914 } 915 } else { 916 // extend this row 917 dX += DX; 918 dY = PS_MAX (dY, DY); 919 } 901 920 } 902 921 NY += DY; … … 918 937 for (int i = 0; i < sources->n; i++) { 919 938 920 pmSource *source = sources->data[i];921 922 bool keep = false;923 if (source->mode & PM_SOURCE_MODE_PSFSTAR) {924 nPSF ++;925 keep = true;926 }927 if (!keep) continue;928 929 if (Xo + DX > NX) {930 // too wide for the rest of this row931 if (Xo == 0) {932 // place source alone on this row933 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);934 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);935 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true);936 937 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);938 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true);939 940 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);941 942 Yo += DY;943 Xo = 0;944 dY = 0;945 } else {946 // start the next row947 Yo += dY;948 Xo = 0;949 950 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);951 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);952 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true);953 954 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);955 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true);956 957 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);958 959 Xo = DX;960 dY = DY;961 }962 } else {963 // extend this row964 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);965 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);966 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true);967 968 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);969 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true);970 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);971 972 Xo += DX;973 dY = PS_MAX (dY, DY);974 }939 pmSource *source = sources->data[i]; 940 941 bool keep = false; 942 if (source->mode & PM_SOURCE_MODE_PSFSTAR) { 943 nPSF ++; 944 keep = true; 945 } 946 if (!keep) continue; 947 948 if (Xo + DX > NX) { 949 // too wide for the rest of this row 950 if (Xo == 0) { 951 // place source alone on this row 952 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 953 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 954 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true); 955 956 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 957 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true); 958 959 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 960 961 Yo += DY; 962 Xo = 0; 963 dY = 0; 964 } else { 965 // start the next row 966 Yo += dY; 967 Xo = 0; 968 969 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 970 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 971 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true); 972 973 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 974 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true); 975 976 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 977 978 Xo = DX; 979 dY = DY; 980 } 981 } else { 982 // extend this row 983 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 984 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 985 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true); 986 987 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 988 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true); 989 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 990 991 Xo += DX; 992 dY = PS_MAX (dY, DY); 993 } 975 994 } 976 995 … … 994 1013 bool status; 995 1014 996 if (! DEBUG && !pmVisualIsVisual()) return true;1015 if (!pmVisualTestLevel("psphot.psf.sat", 3)) return true; 997 1016 998 1017 int myKapa = psphotKapaChannel (3); … … 1023 1042 for (int i = 0; i < sources->n; i++) { 1024 1043 1025 pmSource *source = sources->data[i];1026 1027 // only show "real" saturated stars (not defects)1028 if (!(source->mode & PM_SOURCE_MODE_SATSTAR)) continue;;1029 if (source->mode & PM_SOURCE_MODE_DEFECT) continue;;1030 1031 // how does this subimage get placed into the output image?1032 // DX = source->pixels->numCols1033 // DY = source->pixels->numRows1034 1035 if (dX + DX > NX) {1036 // too wide for the rest of this row1037 if (dX == 0) {1038 // alone on this row1039 NY += DY;1040 dX = 0;1041 dY = 0;1042 } else {1043 // start the next row1044 NY += dY;1045 dX = DX;1046 dY = DY;1047 }1048 } else {1049 // extend this row1050 dX += DX;1051 dY = PS_MAX (dY, DY);1052 }1044 pmSource *source = sources->data[i]; 1045 1046 // only show "real" saturated stars (not defects) 1047 if (!(source->mode & PM_SOURCE_MODE_SATSTAR)) continue;; 1048 if (source->mode & PM_SOURCE_MODE_DEFECT) continue;; 1049 1050 // how does this subimage get placed into the output image? 1051 // DX = source->pixels->numCols 1052 // DY = source->pixels->numRows 1053 1054 if (dX + DX > NX) { 1055 // too wide for the rest of this row 1056 if (dX == 0) { 1057 // alone on this row 1058 NY += DY; 1059 dX = 0; 1060 dY = 0; 1061 } else { 1062 // start the next row 1063 NY += dY; 1064 dX = DX; 1065 dY = DY; 1066 } 1067 } else { 1068 // extend this row 1069 dX += DX; 1070 dY = PS_MAX (dY, DY); 1071 } 1053 1072 } 1054 1073 NY += DY; … … 1068 1087 for (int i = 0; i < sources->n; i++) { 1069 1088 1070 pmSource *source = sources->data[i];1071 1072 // only show "real" saturated stars (not defects)1073 if (!(source->mode & PM_SOURCE_MODE_SATSTAR)) continue;;1074 if (source->mode & PM_SOURCE_MODE_DEFECT) continue;;1075 nSAT ++;1076 1077 if (Xo + DX > NX) {1078 // too wide for the rest of this row1079 if (Xo == 0) {1080 // place source alone on this row1081 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);1082 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);1083 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false);1084 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);1085 1086 Yo += DY;1087 Xo = 0;1088 dY = 0;1089 } else {1090 // start the next row1091 Yo += dY;1092 Xo = 0;1093 1094 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);1095 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);1096 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false);1097 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);1098 1099 Xo = DX;1100 dY = DY;1101 }1102 } else {1103 // extend this row1104 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);1105 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);1106 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false);1107 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);1108 1109 Xo += DX;1110 dY = PS_MAX (dY, DY);1111 }1089 pmSource *source = sources->data[i]; 1090 1091 // only show "real" saturated stars (not defects) 1092 if (!(source->mode & PM_SOURCE_MODE_SATSTAR)) continue;; 1093 if (source->mode & PM_SOURCE_MODE_DEFECT) continue;; 1094 nSAT ++; 1095 1096 if (Xo + DX > NX) { 1097 // too wide for the rest of this row 1098 if (Xo == 0) { 1099 // place source alone on this row 1100 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 1101 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 1102 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false); 1103 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 1104 1105 Yo += DY; 1106 Xo = 0; 1107 dY = 0; 1108 } else { 1109 // start the next row 1110 Yo += dY; 1111 Xo = 0; 1112 1113 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 1114 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 1115 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false); 1116 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 1117 1118 Xo = DX; 1119 dY = DY; 1120 } 1121 } else { 1122 // extend this row 1123 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 1124 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 1125 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false); 1126 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 1127 1128 Xo += DX; 1129 dY = PS_MAX (dY, DY); 1130 } 1112 1131 } 1113 1132 … … 1151 1170 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS] - source->pixels->row0; 1152 1171 for (int iy = 0; iy < source->pixels->numRows; iy++) { 1153 for (int ix = 0; ix < source->pixels->numCols; ix++) {1154 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) {1155 rb->data.F32[nb] = hypot (ix + 0.5 - Xo, iy + 0.5 - Yo) ;1156 // rb->data.F32[nb] = hypot (ix - Xo, iy - Yo) ;1157 Rb->data.F32[nb] = log10(rb->data.F32[nb]);1158 fb->data.F32[nb] = log10(source->pixels->data.F32[iy][ix]);1159 nb++;1160 } else {1161 rg->data.F32[ng] = hypot (ix + 0.5 - Xo, iy + 0.5 - Yo) ;1162 // rg->data.F32[ng] = hypot (ix - Xo, iy - Yo) ;1163 Rg->data.F32[ng] = log10(rg->data.F32[ng]);1164 fg->data.F32[ng] = log10(source->pixels->data.F32[iy][ix]);1165 ng++;1166 }1167 }1172 for (int ix = 0; ix < source->pixels->numCols; ix++) { 1173 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) { 1174 rb->data.F32[nb] = hypot (ix + 0.5 - Xo, iy + 0.5 - Yo) ; 1175 // rb->data.F32[nb] = hypot (ix - Xo, iy - Yo) ; 1176 Rb->data.F32[nb] = log10(rb->data.F32[nb]); 1177 fb->data.F32[nb] = log10(source->pixels->data.F32[iy][ix]); 1178 nb++; 1179 } else { 1180 rg->data.F32[ng] = hypot (ix + 0.5 - Xo, iy + 0.5 - Yo) ; 1181 // rg->data.F32[ng] = hypot (ix - Xo, iy - Yo) ; 1182 Rg->data.F32[ng] = log10(rg->data.F32[ng]); 1183 fg->data.F32[ng] = log10(source->pixels->data.F32[iy][ix]); 1184 ng++; 1185 } 1186 } 1168 1187 } 1169 1188 … … 1358 1377 KapaSection section; // put the positive profile in one and the residuals in another? 1359 1378 1360 if (! DEBUG && !pmVisualIsVisual()) return true;1379 if (!pmVisualTestLevel("psphot.profiles", 3)) return true; 1361 1380 1362 1381 int myKapa = psphotKapaChannel (2); … … 1394 1413 for (int i = 0; i < sources->n; i++) { 1395 1414 1396 pmSource *source = sources->data[i];1397 if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;1398 1399 psphotVisualPlotRadialProfile (myKapa, source, maskVal);1400 1401 // pause and wait for user input:1402 // continue, save (provide name), ??1403 char key[10];1404 fprintf (stdout, "[e]rase and continue? [o]verplot and continue? [s]kip rest of stars? : ");1405 if (!fgets(key, 8, stdin)) {1406 psWarning("Unable to read option");1407 }1408 if (key[0] == 'e') {1409 KapaClearPlots (myKapa);1410 }1411 if (key[0] == 's') {1412 break;1413 }1415 pmSource *source = sources->data[i]; 1416 if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue; 1417 1418 psphotVisualPlotRadialProfile (myKapa, source, maskVal); 1419 1420 // pause and wait for user input: 1421 // continue, save (provide name), ?? 1422 char key[10]; 1423 fprintf (stdout, "[e]rase and continue? [o]verplot and continue? [s]kip rest of stars? : "); 1424 if (!fgets(key, 8, stdin)) { 1425 psWarning("Unable to read option"); 1426 } 1427 if (key[0] == 'e') { 1428 KapaClearPlots (myKapa); 1429 } 1430 if (key[0] == 's') { 1431 break; 1432 } 1414 1433 } 1415 1434 … … 1429 1448 return true; 1430 1449 1431 if (! DEBUG && !pmVisualIsVisual()) return true;1450 if (!pmVisualTestLevel("psphot.objects.flags", 3)) return true; 1432 1451 1433 1452 int myKapa = psphotKapaChannel (1); … … 1445 1464 for (int i = 0; i < sources->n; i++) { 1446 1465 1447 float Xo, Yo, Rmaj, Rmin, cs, sn;1448 1449 pmSource *source = sources->data[i];1450 if (source == NULL) continue;1451 1452 pmMoments *moments = source->moments;1453 if (0) {1454 emoments.x2 = moments->Mxx;1455 emoments.y2 = moments->Myy;1456 emoments.xy = moments->Mxy;1457 Xo = moments->Mx;1458 Yo = moments->My;1459 1460 axes = psEllipseMomentsToAxes (emoments, 20.0);1461 Rmaj = 2.0*axes.major;1462 Rmin = 2.0*axes.minor;1463 cs = cos(axes.theta);1464 sn = sin(axes.theta);1465 } else {1466 Rmaj = Rmin = 5.0;1467 cs = 1.0;1468 sn = 0.0;1469 Xo = source->peak->xf;1470 Yo = source->peak->yf;1471 }1472 1473 unsigned short int flagMask = 0x01;1474 for (int j = 0; j < 8; j++) {1475 if (source->mode & flagMask) {1476 overlayE[NoverlayE].type = KII_OVERLAY_LINE;1477 overlayE[NoverlayE].x = Xo;1478 overlayE[NoverlayE].y = Yo;1479 1480 float phi = j*M_PI/4.0;1481 overlayE[NoverlayE].dx = +Rmaj*cos(phi)*cs - Rmin*sin(phi)*sn;1482 overlayE[NoverlayE].dy = +Rmaj*cos(phi)*sn + Rmin*sin(phi)*cs;1483 overlayE[NoverlayE].angle = 0;1484 overlayE[NoverlayE].text = NULL;1485 NoverlayE ++;1486 CHECK_REALLOCATE (overlayE, KiiOverlay, NOVERLAYE, NoverlayE, 100);1487 }1488 flagMask <<= 1;1489 1490 if (source->mode & flagMask) {1491 overlayO[NoverlayO].type = KII_OVERLAY_LINE;1492 overlayO[NoverlayO].x = Xo + 1;1493 overlayO[NoverlayO].y = Yo;1494 1495 float phi = j*M_PI/4.0;1496 overlayO[NoverlayO].dx = +Rmaj*cos(phi)*cs - Rmin*sin(phi)*sn;1497 overlayO[NoverlayO].dy = +Rmaj*cos(phi)*sn + Rmin*sin(phi)*cs;1498 overlayO[NoverlayO].angle = 0;1499 overlayO[NoverlayO].text = NULL;1500 NoverlayO ++;1501 CHECK_REALLOCATE (overlayO, KiiOverlay, NOVERLAYO, NoverlayO, 100);1502 }1503 flagMask <<= 1;1504 }1466 float Xo, Yo, Rmaj, Rmin, cs, sn; 1467 1468 pmSource *source = sources->data[i]; 1469 if (source == NULL) continue; 1470 1471 pmMoments *moments = source->moments; 1472 if (0) { 1473 emoments.x2 = moments->Mxx; 1474 emoments.y2 = moments->Myy; 1475 emoments.xy = moments->Mxy; 1476 Xo = moments->Mx; 1477 Yo = moments->My; 1478 1479 axes = psEllipseMomentsToAxes (emoments, 20.0); 1480 Rmaj = 2.0*axes.major; 1481 Rmin = 2.0*axes.minor; 1482 cs = cos(axes.theta); 1483 sn = sin(axes.theta); 1484 } else { 1485 Rmaj = Rmin = 5.0; 1486 cs = 1.0; 1487 sn = 0.0; 1488 Xo = source->peak->xf; 1489 Yo = source->peak->yf; 1490 } 1491 1492 unsigned short int flagMask = 0x01; 1493 for (int j = 0; j < 8; j++) { 1494 if (source->mode & flagMask) { 1495 overlayE[NoverlayE].type = KII_OVERLAY_LINE; 1496 overlayE[NoverlayE].x = Xo; 1497 overlayE[NoverlayE].y = Yo; 1498 1499 float phi = j*M_PI/4.0; 1500 overlayE[NoverlayE].dx = +Rmaj*cos(phi)*cs - Rmin*sin(phi)*sn; 1501 overlayE[NoverlayE].dy = +Rmaj*cos(phi)*sn + Rmin*sin(phi)*cs; 1502 overlayE[NoverlayE].angle = 0; 1503 overlayE[NoverlayE].text = NULL; 1504 NoverlayE ++; 1505 CHECK_REALLOCATE (overlayE, KiiOverlay, NOVERLAYE, NoverlayE, 100); 1506 } 1507 flagMask <<= 1; 1508 1509 if (source->mode & flagMask) { 1510 overlayO[NoverlayO].type = KII_OVERLAY_LINE; 1511 overlayO[NoverlayO].x = Xo + 1; 1512 overlayO[NoverlayO].y = Yo; 1513 1514 float phi = j*M_PI/4.0; 1515 overlayO[NoverlayO].dx = +Rmaj*cos(phi)*cs - Rmin*sin(phi)*sn; 1516 overlayO[NoverlayO].dy = +Rmaj*cos(phi)*sn + Rmin*sin(phi)*cs; 1517 overlayO[NoverlayO].angle = 0; 1518 overlayO[NoverlayO].text = NULL; 1519 NoverlayO ++; 1520 CHECK_REALLOCATE (overlayO, KiiOverlay, NOVERLAYO, NoverlayO, 100); 1521 } 1522 flagMask <<= 1; 1523 } 1505 1524 } 1506 1525 … … 1531 1550 for (int i = 0; i < sources->n; i++) { 1532 1551 1533 pmSource *source = sources->data[i];1534 if (source == NULL) continue;1535 1536 if (mode) {1537 if (keep) {1538 if (!(source->mode & mode)) continue;1539 } else {1540 if (source->mode & mode) continue;1541 }1542 }1543 1544 pmMoments *moments = source->moments;1545 if (moments == NULL) continue;1546 1547 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;1548 overlay[Noverlay].x = moments->Mx;1549 overlay[Noverlay].y = moments->My;1550 1551 emoments.x2 = moments->Mxx;1552 emoments.y2 = moments->Myy;1553 emoments.xy = moments->Mxy;1554 1555 axes = psEllipseMomentsToAxes (emoments, 20.0);1556 1557 overlay[Noverlay].dx = scale*2.0*axes.major;1558 overlay[Noverlay].dy = scale*2.0*axes.minor;1559 overlay[Noverlay].angle = axes.theta * PS_DEG_RAD;1560 overlay[Noverlay].text = NULL;1561 Noverlay ++;1552 pmSource *source = sources->data[i]; 1553 if (source == NULL) continue; 1554 1555 if (mode) { 1556 if (keep) { 1557 if (!(source->mode & mode)) continue; 1558 } else { 1559 if (source->mode & mode) continue; 1560 } 1561 } 1562 1563 pmMoments *moments = source->moments; 1564 if (moments == NULL) continue; 1565 1566 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 1567 overlay[Noverlay].x = moments->Mx; 1568 overlay[Noverlay].y = moments->My; 1569 1570 emoments.x2 = moments->Mxx; 1571 emoments.y2 = moments->Myy; 1572 emoments.xy = moments->Mxy; 1573 1574 axes = psEllipseMomentsToAxes (emoments, 20.0); 1575 1576 overlay[Noverlay].dx = scale*2.0*axes.major; 1577 overlay[Noverlay].dy = scale*2.0*axes.minor; 1578 overlay[Noverlay].angle = axes.theta * PS_DEG_RAD; 1579 overlay[Noverlay].text = NULL; 1580 Noverlay ++; 1562 1581 } 1563 1582 … … 1570 1589 bool psphotVisualShowSourceSize (pmReadout *readout, psArray *sources) { 1571 1590 1572 if (! DEBUG && !pmVisualIsVisual()) return true;1591 if (!pmVisualTestLevel("psphot.objects.size", 2)) return true; 1573 1592 1574 1593 int myKapa = psphotKapaChannel (1); … … 1597 1616 KapaSection section; 1598 1617 1599 if (! DEBUG && !pmVisualIsVisual()) return true;1618 if (!pmVisualTestLevel("psphot.size", 2)) return true; 1600 1619 1601 1620 int myKapa = psphotKapaChannel (2); … … 1612 1631 float Ymin = 1000.0, Ymax = 0.0; 1613 1632 { 1614 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");1615 for (int n = 0; n < nRegions; n++) {1616 1617 char regionName[64];1618 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);1619 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);1620 1621 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");1622 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");1623 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");1624 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");1625 1626 float X0 = psfX - 10.0*psfdX;1627 float X1 = psfX + 10.0*psfdX;1628 float Y0 = psfY - 10.0*psfdY;1629 float Y1 = psfY + 10.0*psfdY;1630 1631 if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); }1632 if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); }1633 if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); }1634 if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); }1635 }1633 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS"); 1634 for (int n = 0; n < nRegions; n++) { 1635 1636 char regionName[64]; 1637 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n); 1638 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 1639 1640 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 1641 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); 1642 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); 1643 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); 1644 1645 float X0 = psfX - 10.0*psfdX; 1646 float X1 = psfX + 10.0*psfdX; 1647 float Y0 = psfY - 10.0*psfdY; 1648 float Y1 = psfY + 10.0*psfdY; 1649 1650 if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); } 1651 if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); } 1652 if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); } 1653 if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); } 1654 } 1636 1655 } 1637 1656 Xmin = PS_MAX(Xmin, -0.1); … … 1677 1696 int nCR = 0; 1678 1697 for (int i = 0; i < sources->n; i++) { 1679 pmSource *source = sources->data[i];1680 if (source->moments == NULL) continue;1698 pmSource *source = sources->data[i]; 1699 if (source->moments == NULL) continue; 1681 1700 1682 1701 // only plot the measured sources... 1683 if (!(source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED)) continue;1684 1685 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) {1686 xCR->data.F32[nCR] = source->moments->Mxx;1687 yCR->data.F32[nCR] = source->moments->Myy;1688 mCR->data.F32[nCR] = -2.5*log10(source->moments->Sum);1689 sCR->data.F32[nCR] = source->extNsigma;1690 nCR++;1691 }1692 if (source->mode & PM_SOURCE_MODE_SATSTAR) {1693 xSAT->data.F32[nSAT] = source->moments->Mxx;1694 ySAT->data.F32[nSAT] = source->moments->Myy;1695 mSAT->data.F32[nSAT] = -2.5*log10(source->moments->Sum);1696 sSAT->data.F32[nSAT] = source->extNsigma;1697 nSAT++;1698 }1699 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {1700 xEXT->data.F32[nEXT] = source->moments->Mxx;1701 yEXT->data.F32[nEXT] = source->moments->Myy;1702 mEXT->data.F32[nEXT] = -2.5*log10(source->moments->Sum);1703 sEXT->data.F32[nEXT] = source->extNsigma;1704 nEXT++;1705 continue;1706 }1707 if (source->mode & PM_SOURCE_MODE_DEFECT) {1708 xDEF->data.F32[nDEF] = source->moments->Mxx;1709 yDEF->data.F32[nDEF] = source->moments->Myy;1710 mDEF->data.F32[nDEF] = -2.5*log10(source->moments->Sum);1711 sDEF->data.F32[nDEF] = source->extNsigma;1712 nDEF++;1713 continue;1714 }1715 if (source->errMag > 0.1) {1716 xLOW->data.F32[nLOW] = source->moments->Mxx;1717 yLOW->data.F32[nLOW] = source->moments->Myy;1718 mLOW->data.F32[nLOW] = -2.5*log10(source->moments->Sum);1719 sLOW->data.F32[nLOW] = source->extNsigma;1720 nLOW++;1721 continue;1722 }1723 xPSF->data.F32[nPSF] = source->moments->Mxx;1724 yPSF->data.F32[nPSF] = source->moments->Myy;1725 mPSF->data.F32[nPSF] = -2.5*log10(source->moments->Sum);1726 sPSF->data.F32[nPSF] = source->extNsigma;1727 nPSF++;1702 if (!(source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED)) continue; 1703 1704 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) { 1705 xCR->data.F32[nCR] = source->moments->Mxx; 1706 yCR->data.F32[nCR] = source->moments->Myy; 1707 mCR->data.F32[nCR] = -2.5*log10(source->moments->Sum); 1708 sCR->data.F32[nCR] = source->extNsigma; 1709 nCR++; 1710 } 1711 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 1712 xSAT->data.F32[nSAT] = source->moments->Mxx; 1713 ySAT->data.F32[nSAT] = source->moments->Myy; 1714 mSAT->data.F32[nSAT] = -2.5*log10(source->moments->Sum); 1715 sSAT->data.F32[nSAT] = source->extNsigma; 1716 nSAT++; 1717 } 1718 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 1719 xEXT->data.F32[nEXT] = source->moments->Mxx; 1720 yEXT->data.F32[nEXT] = source->moments->Myy; 1721 mEXT->data.F32[nEXT] = -2.5*log10(source->moments->Sum); 1722 sEXT->data.F32[nEXT] = source->extNsigma; 1723 nEXT++; 1724 continue; 1725 } 1726 if (source->mode & PM_SOURCE_MODE_DEFECT) { 1727 xDEF->data.F32[nDEF] = source->moments->Mxx; 1728 yDEF->data.F32[nDEF] = source->moments->Myy; 1729 mDEF->data.F32[nDEF] = -2.5*log10(source->moments->Sum); 1730 sDEF->data.F32[nDEF] = source->extNsigma; 1731 nDEF++; 1732 continue; 1733 } 1734 if (source->errMag > 0.1) { 1735 xLOW->data.F32[nLOW] = source->moments->Mxx; 1736 yLOW->data.F32[nLOW] = source->moments->Myy; 1737 mLOW->data.F32[nLOW] = -2.5*log10(source->moments->Sum); 1738 sLOW->data.F32[nLOW] = source->extNsigma; 1739 nLOW++; 1740 continue; 1741 } 1742 xPSF->data.F32[nPSF] = source->moments->Mxx; 1743 yPSF->data.F32[nPSF] = source->moments->Myy; 1744 mPSF->data.F32[nPSF] = -2.5*log10(source->moments->Sum); 1745 sPSF->data.F32[nPSF] = source->extNsigma; 1746 nPSF++; 1728 1747 } 1729 1748 … … 2029 2048 // draw N circles to outline the clumps 2030 2049 { 2031 KapaSelectSection (myKapa, "MxxMyy");2032 2033 // draw a circle centered on psfX,Y with size of the psf limit2034 psVector *xLimit = psVectorAlloc (120, PS_TYPE_F32);2035 psVector *yLimit = psVectorAlloc (120, PS_TYPE_F32);2036 2037 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS");2038 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");2039 2040 graphdata.color = KapaColorByName ("blue");2041 graphdata.style = 0;2042 2043 graphdata.xmin = Xmin;2044 graphdata.ymin = Ymin;2045 graphdata.xmax = Xmax;2046 graphdata.ymax = Ymax;2047 KapaSetLimits (myKapa, &graphdata);2048 2049 for (int n = 0; n < nRegions; n++) {2050 2051 char regionName[64];2052 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);2053 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);2054 2055 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");2056 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");2057 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");2058 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");2059 float Rx = psfdX * PSF_CLUMP_NSIGMA;2060 float Ry = psfdY * PSF_CLUMP_NSIGMA;2061 2062 for (int i = 0; i < xLimit->n; i++) {2063 xLimit->data.F32[i] = Rx*cos(i*2.0*M_PI/120.0) + psfX;2064 yLimit->data.F32[i] = Ry*sin(i*2.0*M_PI/120.0) + psfY;2065 }2066 KapaPrepPlot (myKapa, xLimit->n, &graphdata);2067 KapaPlotVector (myKapa, xLimit->n, xLimit->data.F32, "x");2068 KapaPlotVector (myKapa, yLimit->n, yLimit->data.F32, "y");2069 }2070 psFree (xLimit);2071 psFree (yLimit);2050 KapaSelectSection (myKapa, "MxxMyy"); 2051 2052 // draw a circle centered on psfX,Y with size of the psf limit 2053 psVector *xLimit = psVectorAlloc (120, PS_TYPE_F32); 2054 psVector *yLimit = psVectorAlloc (120, PS_TYPE_F32); 2055 2056 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS"); 2057 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA"); 2058 2059 graphdata.color = KapaColorByName ("blue"); 2060 graphdata.style = 0; 2061 2062 graphdata.xmin = Xmin; 2063 graphdata.ymin = Ymin; 2064 graphdata.xmax = Xmax; 2065 graphdata.ymax = Ymax; 2066 KapaSetLimits (myKapa, &graphdata); 2067 2068 for (int n = 0; n < nRegions; n++) { 2069 2070 char regionName[64]; 2071 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n); 2072 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 2073 2074 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 2075 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); 2076 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); 2077 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); 2078 float Rx = psfdX * PSF_CLUMP_NSIGMA; 2079 float Ry = psfdY * PSF_CLUMP_NSIGMA; 2080 2081 for (int i = 0; i < xLimit->n; i++) { 2082 xLimit->data.F32[i] = Rx*cos(i*2.0*M_PI/120.0) + psfX; 2083 yLimit->data.F32[i] = Ry*sin(i*2.0*M_PI/120.0) + psfY; 2084 } 2085 KapaPrepPlot (myKapa, xLimit->n, &graphdata); 2086 KapaPlotVector (myKapa, xLimit->n, xLimit->data.F32, "x"); 2087 KapaPlotVector (myKapa, yLimit->n, yLimit->data.F32, "y"); 2088 } 2089 psFree (xLimit); 2090 psFree (yLimit); 2072 2091 } 2073 2092 … … 2108 2127 bool psphotVisualShowResidualImage (pmReadout *readout) { 2109 2128 2110 if (! DEBUG && !pmVisualIsVisual()) return true;2129 if (!pmVisualTestLevel("psphot.image.resid", 2)) return true; 2111 2130 2112 2131 int myKapa = psphotKapaChannel (1); … … 2124 2143 float lineX[2], lineY[2]; 2125 2144 2126 if (! DEBUG && !pmVisualIsVisual()) return true;2145 if (!pmVisualTestLevel("psphot.apresid", 1)) return true; 2127 2146 2128 2147 int myKapa = psphotKapaChannel (2); … … 2144 2163 int n = 0; 2145 2164 for (int i = 0; i < sources->n; i++) { 2146 pmSource *source = sources->data[i];2147 if (!source) continue;2148 if (source->type != PM_SOURCE_TYPE_STAR) continue;2149 if (!isfinite (source->apMag)) continue;2150 if (!isfinite (source->psfMag)) continue;2151 2152 x->data.F32[n] = source->psfMag;2153 y->data.F32[n] = source->apMag - source->psfMag;2154 dy->data.F32[n] = source->errMag;2155 graphdata.xmin = PS_MIN(graphdata.xmin, x->data.F32[n]);2156 graphdata.xmax = PS_MAX(graphdata.xmax, x->data.F32[n]);2157 graphdata.ymin = PS_MIN(graphdata.ymin, y->data.F32[n]);2158 graphdata.ymax = PS_MAX(graphdata.ymax, y->data.F32[n]);2159 2160 n++;2165 pmSource *source = sources->data[i]; 2166 if (!source) continue; 2167 if (source->type != PM_SOURCE_TYPE_STAR) continue; 2168 if (!isfinite (source->apMag)) continue; 2169 if (!isfinite (source->psfMag)) continue; 2170 2171 x->data.F32[n] = source->psfMag; 2172 y->data.F32[n] = source->apMag - source->psfMag; 2173 dy->data.F32[n] = source->errMag; 2174 graphdata.xmin = PS_MIN(graphdata.xmin, x->data.F32[n]); 2175 graphdata.xmax = PS_MAX(graphdata.xmax, x->data.F32[n]); 2176 graphdata.ymin = PS_MIN(graphdata.ymin, y->data.F32[n]); 2177 graphdata.ymax = PS_MAX(graphdata.ymax, y->data.F32[n]); 2178 2179 n++; 2161 2180 } 2162 2181 x->n = y->n = dy->n = n; … … 2242 2261 Graphdata graphdata; 2243 2262 2244 if (! DEBUG && !pmVisualIsVisual()) return true;2263 if (!pmVisualTestLevel("psphot.chisq", 1)) return true; 2245 2264 2246 2265 int myKapa = psphotKapaChannel (2); … … 2263 2282 int n = 0; 2264 2283 for (int i = 0; i < sources->n; i++) { 2265 pmSource *source = sources->data[i];2266 if (!source) continue;2267 if (source->type != PM_SOURCE_TYPE_STAR) continue;2268 if (!source->moments) continue;2269 if (!isfinite(source->moments->Sum)) continue;2270 if (!source->modelPSF) continue;2271 if (!isfinite(source->modelPSF->chisq)) continue;2272 2273 x->data.F32[n] = -2.5*log10(source->moments->Sum);2274 y->data.F32[n] = source->modelPSF->chisq / source->modelPSF->nDOF;2275 graphdata.xmin = PS_MIN(graphdata.xmin, x->data.F32[n]);2276 graphdata.xmax = PS_MAX(graphdata.xmax, x->data.F32[n]);2277 graphdata.ymin = PS_MIN(graphdata.ymin, y->data.F32[n]);2278 graphdata.ymax = PS_MAX(graphdata.ymax, y->data.F32[n]);2279 2280 fprintf (f, "%d %d %f %f\n", i, n, x->data.F32[n], y->data.F32[n]);2281 2282 n++;2284 pmSource *source = sources->data[i]; 2285 if (!source) continue; 2286 if (source->type != PM_SOURCE_TYPE_STAR) continue; 2287 if (!source->moments) continue; 2288 if (!isfinite(source->moments->Sum)) continue; 2289 if (!source->modelPSF) continue; 2290 if (!isfinite(source->modelPSF->chisq)) continue; 2291 2292 x->data.F32[n] = -2.5*log10(source->moments->Sum); 2293 y->data.F32[n] = source->modelPSF->chisq / source->modelPSF->nDOF; 2294 graphdata.xmin = PS_MIN(graphdata.xmin, x->data.F32[n]); 2295 graphdata.xmax = PS_MAX(graphdata.xmax, x->data.F32[n]); 2296 graphdata.ymin = PS_MIN(graphdata.ymin, y->data.F32[n]); 2297 graphdata.ymax = PS_MAX(graphdata.ymax, y->data.F32[n]); 2298 2299 fprintf (f, "%d %d %f %f\n", i, n, x->data.F32[n], y->data.F32[n]); 2300 2301 n++; 2283 2302 } 2284 2303 x->n = y->n = n; … … 2326 2345 KiiOverlay *overlay; 2327 2346 2328 if (! DEBUG && !pmVisualIsVisual()) return true;2347 if (!pmVisualTestLevel("psphot.objects.petro", 2)) return true; 2329 2348 2330 2349 int kapa = psphotKapaChannel (1); … … 2336 2355 2337 2356 for (int i = 0; i < sources->n; i++) { 2338 pmSource *source = sources->data[i];2339 2340 if (!source) continue;2341 if (!source->extpars) continue;2342 if (!source->extpars->petProfile) continue;2343 2344 float petrosianRadius = source->extpars->petrosianRadius;2357 pmSource *source = sources->data[i]; 2358 2359 if (!source) continue; 2360 if (!source->extpars) continue; 2361 if (!source->extpars->petProfile) continue; 2362 2363 float petrosianRadius = source->extpars->petrosianRadius; 2345 2364 psEllipseAxes *axes = &source->extpars->axes; 2346 2365 2347 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;2348 overlay[Noverlay].x = source->peak->xf;2349 overlay[Noverlay].y = source->peak->yf;2350 overlay[Noverlay].dx = 1.0*petrosianRadius;2351 overlay[Noverlay].dy = 1.0*petrosianRadius*axes->minor/axes->major;2352 overlay[Noverlay].angle = axes->theta * PS_DEG_RAD;2353 overlay[Noverlay].text = NULL;2354 Noverlay ++;2355 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);2356 2357 // overlay[Noverlay].type = KII_OVERLAY_CIRCLE;2358 // overlay[Noverlay].x = source->peak->xf;2359 // overlay[Noverlay].y = source->peak->yf;2360 // overlay[Noverlay].dx = 2.0*petrosianRadius;2361 // overlay[Noverlay].dy = 2.0*petrosianRadius*axes->minor/axes->major;2362 // overlay[Noverlay].angle = axes->theta * PS_DEG_RAD;2363 // overlay[Noverlay].text = NULL;2364 // Noverlay ++;2365 // CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);2366 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 2367 overlay[Noverlay].x = source->peak->xf; 2368 overlay[Noverlay].y = source->peak->yf; 2369 overlay[Noverlay].dx = 1.0*petrosianRadius; 2370 overlay[Noverlay].dy = 1.0*petrosianRadius*axes->minor/axes->major; 2371 overlay[Noverlay].angle = axes->theta * PS_DEG_RAD; 2372 overlay[Noverlay].text = NULL; 2373 Noverlay ++; 2374 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 2375 2376 // overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 2377 // overlay[Noverlay].x = source->peak->xf; 2378 // overlay[Noverlay].y = source->peak->yf; 2379 // overlay[Noverlay].dx = 2.0*petrosianRadius; 2380 // overlay[Noverlay].dy = 2.0*petrosianRadius*axes->minor/axes->major; 2381 // overlay[Noverlay].angle = axes->theta * PS_DEG_RAD; 2382 // overlay[Noverlay].text = NULL; 2383 // Noverlay ++; 2384 // CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 2366 2385 } 2367 2386
Note:
See TracChangeset
for help on using the changeset viewer.
