Changeset 30631
- Timestamp:
- Feb 14, 2011, 1:05:28 PM (15 years ago)
- Location:
- branches/czw_branch/20101203
- Files:
-
- 7 deleted
- 296 edited
- 23 copied
-
. (modified) (1 prop)
-
Ohana/src/addstar/include/addstar.h (modified) (1 diff)
-
Ohana/src/addstar/src/ReadStarsFITS.c (modified) (13 diffs)
-
Ohana/src/addstar/src/ReadStarsSDSS.c (modified) (2 diffs)
-
Ohana/src/addstar/src/ReadStarsTEXT.c (modified) (1 diff)
-
Ohana/src/addstar/src/StarOps.c (modified) (1 diff)
-
Ohana/src/addstar/src/calibrate.c (modified) (1 diff)
-
Ohana/src/addstar/src/fakeimage.c (modified) (2 diffs)
-
Ohana/src/addstar/src/get2mass_full.c (modified) (1 diff)
-
Ohana/src/addstar/src/resort_catalog.c (modified) (4 diffs)
-
Ohana/src/addstar/src/sky_tessalation.c (modified) (1 diff)
-
Ohana/src/dvomerge/doc/usage.txt (copied) (copied from trunk/Ohana/src/dvomerge/doc/usage.txt )
-
Ohana/src/dvomerge/src/dvoverify.c (modified) (5 diffs)
-
Ohana/src/dvomerge/src/help.c (modified) (1 diff)
-
Ohana/src/getstar/src/select_by_image.c (modified) (1 diff)
-
Ohana/src/imregister/imphot/dumpfits.c (modified) (1 diff)
-
Ohana/src/kapa2/include/prototypes.h (modified) (1 diff)
-
Ohana/src/kapa2/src/PSObjects.c (modified) (3 diffs)
-
Ohana/src/kapa2/src/UpdateStatusBox.c (modified) (5 diffs)
-
Ohana/src/kapa2/src/bDrawObjects.c (modified) (3 diffs)
-
Ohana/src/kapa2/src/hh_hms.c (modified) (3 diffs)
-
Ohana/src/libautocode/def/image-elixir.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image-loneos.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image-panstarrs-dev-0.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image-panstarrs-dev-1.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image-ps1-dev-1.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image-ps1-dev-2.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image-ps1-dev-3.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image-ps1-ref.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image-ps1-v1.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image-ps1-v2.d (modified) (1 diff)
-
Ohana/src/libautocode/def/image.d (modified) (3 diffs)
-
Ohana/src/libautocode/def/measure-ps1-v2.d (modified) (1 diff)
-
Ohana/src/libautocode/def/measure.d (modified) (2 diffs)
-
Ohana/src/libdvo/Makefile (modified) (2 diffs)
-
Ohana/src/libdvo/doc/dvo-images.txt (modified) (1 diff)
-
Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c (modified) (12 diffs)
-
Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c (modified) (12 diffs)
-
Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c (modified) (6 diffs)
-
Ohana/src/libdvo/src/dvo_convert_PS1_REF.c (modified) (12 diffs)
-
Ohana/src/libdvo/src/dvo_convert_PS1_V1.c (modified) (12 diffs)
-
Ohana/src/libdvo/src/dvo_convert_PS1_V2.c (modified) (15 diffs)
-
Ohana/src/libdvo/src/dvo_convert_elixir.c (modified) (12 diffs)
-
Ohana/src/libdvo/src/dvo_convert_loneos.c (modified) (10 diffs)
-
Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c (modified) (10 diffs)
-
Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c (modified) (10 diffs)
-
Ohana/src/libdvo/src/photfits.c (modified) (1 diff)
-
Ohana/src/libkapa/src/DrawRotString.c (modified) (3 diffs)
-
Ohana/src/libkapa/src/PSRotFont.c (modified) (3 diffs)
-
Ohana/src/libkapa/src/bDrawRotFont.c (modified) (3 diffs)
-
Ohana/src/libohana/include/ohana.h (modified) (1 diff)
-
Ohana/src/libohana/include/ohana_allocate.h (modified) (2 diffs)
-
Ohana/src/libohana/src/time.c (modified) (1 diff)
-
Ohana/src/opihi/cmd.astro/cgrid.c (modified) (1 diff)
-
Ohana/src/opihi/cmd.astro/region.c (modified) (2 diffs)
-
Ohana/src/opihi/cmd.astro/test (copied) (copied from trunk/Ohana/src/opihi/cmd.astro/test )
-
Ohana/src/opihi/cmd.astro/test/region.sh (copied) (copied from trunk/Ohana/src/opihi/cmd.astro/test/region.sh )
-
Ohana/src/opihi/cmd.data/limits.c (modified) (1 diff)
-
Ohana/src/opihi/cmd.data/match2d.c (modified) (6 diffs)
-
Ohana/src/opihi/cmd.data/reindex.c (modified) (3 diffs)
-
Ohana/src/opihi/cmd.data/subset.c (modified) (2 diffs)
-
Ohana/src/opihi/cmd.data/vstats.c (modified) (8 diffs)
-
Ohana/src/opihi/cmd.data/write_vectors.c (modified) (1 diff)
-
Ohana/src/opihi/doc/image-graph-overlay.txt (copied) (copied from trunk/Ohana/src/opihi/doc/image-graph-overlay.txt )
-
Ohana/src/opihi/dvo/avextract.c (modified) (2 diffs)
-
Ohana/src/opihi/dvo/dbExtractImages.c (modified) (2 diffs)
-
Ohana/src/opihi/dvo/dbExtractMeasures.c (modified) (3 diffs)
-
Ohana/src/opihi/dvo/dbFields.c (modified) (4 diffs)
-
Ohana/src/opihi/dvo/gimages.c (modified) (1 diff)
-
Ohana/src/opihi/dvo/gstar.c (modified) (3 diffs)
-
Ohana/src/opihi/dvo/images.c (modified) (1 diff)
-
Ohana/src/opihi/dvo/imextract.c (modified) (1 diff)
-
Ohana/src/opihi/dvo/imphot.c (modified) (4 diffs)
-
Ohana/src/opihi/dvo/mextract.c (modified) (1 diff)
-
Ohana/src/opihi/dvo/mmextract.c (modified) (2 diffs)
-
Ohana/src/opihi/dvo/photometry.c (modified) (3 diffs)
-
Ohana/src/opihi/dvo/skycat.c (modified) (2 diffs)
-
Ohana/src/opihi/include/dvoshell.h (modified) (3 diffs)
-
Ohana/src/opihi/include/shell.h (modified) (1 diff)
-
Ohana/src/opihi/lib.shell/VectorOps.c (modified) (1 diff)
-
Ohana/src/opihi/lib.shell/command.c (modified) (5 diffs)
-
Ohana/src/opihi/lib.shell/expand_vars.c (modified) (1 diff)
-
Ohana/src/opihi/lib.shell/parse.c (modified) (10 diffs)
-
Ohana/src/opihi/lib.shell/stack_math.c (modified) (4 diffs)
-
Ohana/src/photdbc/include/photdbc.h (modified) (2 diffs)
-
Ohana/src/photdbc/src/ConfigInit.c (modified) (2 diffs)
-
Ohana/src/photdbc/src/args.c (modified) (4 diffs)
-
Ohana/src/photdbc/src/find_images.c (modified) (1 diff)
-
Ohana/src/photdbc/src/initialize.c (modified) (2 diffs)
-
Ohana/src/photdbc/src/make_subcatalog.c (modified) (7 diffs)
-
Ohana/src/relastro/include/relastro.h (modified) (6 diffs)
-
Ohana/src/relastro/src/ConfigInit.c (modified) (1 diff)
-
Ohana/src/relastro/src/FitChip.c (modified) (6 diffs)
-
Ohana/src/relastro/src/GetAstromError.c (modified) (3 diffs)
-
Ohana/src/relastro/src/ImageOps.c (modified) (17 diffs)
-
Ohana/src/relastro/src/StarMaps.c (modified) (3 diffs)
-
Ohana/src/relastro/src/UpdateChips.c (modified) (3 diffs)
-
Ohana/src/relastro/src/UpdateObjectOffsets.c (modified) (1 diff)
-
Ohana/src/relastro/src/UpdateObjects.c (modified) (2 diffs)
-
Ohana/src/relastro/src/args.c (modified) (3 diffs)
-
Ohana/src/relastro/src/bcatalog.c (modified) (2 diffs)
-
Ohana/src/relastro/src/load_catalogs.c (modified) (1 diff)
-
Ohana/src/relastro/src/plotstuff.c (modified) (1 diff)
-
Ohana/src/relastro/src/relastro.c (modified) (1 diff)
-
Ohana/src/relastro/src/relastroVisual.c (modified) (21 diffs)
-
Ohana/src/relastro/src/select_images.c (modified) (8 diffs)
-
Ohana/src/relphot/Makefile (modified) (1 diff)
-
Ohana/src/relphot/include/relphot.h (modified) (4 diffs)
-
Ohana/src/relphot/src/ConfigInit.c (modified) (1 diff)
-
Ohana/src/relphot/src/ImageOps.c (modified) (5 diffs)
-
Ohana/src/relphot/src/MosaicOps.c (modified) (4 diffs)
-
Ohana/src/relphot/src/args.c (modified) (3 diffs)
-
Ohana/src/relphot/src/bcatalog.c (modified) (1 diff)
-
Ohana/src/relphot/src/help.c (copied) (copied from trunk/Ohana/src/relphot/src/help.c )
-
Ohana/src/relphot/src/initialize.c (modified) (1 diff)
-
Ohana/src/relphot/src/load_catalogs.c (modified) (2 diffs)
-
Ohana/src/relphot/src/load_images.c (modified) (3 diffs)
-
Ohana/src/relphot/src/relphot.c (modified) (1 diff)
-
Ohana/src/relphot/src/select_images.c (modified) (10 diffs)
-
Ohana/src/skycalc/Makefile (modified) (5 diffs)
-
Ohana/src/skycalc/src/sunriseset.c (copied) (copied from trunk/Ohana/src/skycalc/src/sunriseset.c )
-
Ohana/src/tools/src/roc.c (modified) (5 diffs)
-
PS-IPP-Config/lib/PS/IPP/Config.pm (modified) (2 diffs)
-
doc/psphot/psphot.tex (modified) (11 diffs)
-
ippScripts/scripts/diff_skycell.pl (modified) (3 diffs)
-
ippScripts/scripts/ipp_apply_burntool_single.pl (modified) (1 prop)
-
ippScripts/scripts/ipp_cleanup.pl (modified) (1 diff)
-
ippScripts/scripts/magic_destreak_cleanup.pl (modified) (4 diffs)
-
ippScripts/scripts/magic_process.pl (modified) (1 diff)
-
ippScripts/scripts/stack_skycell.pl (modified) (1 diff)
-
ippScripts/scripts/warp_skycell.pl (modified) (1 diff)
-
ippTasks/Makefile.am (modified) (1 diff)
-
ippTools/share/camtool_find_pendingimfile.sql (modified) (1 prop)
-
ippTools/share/pxadmin_create_tables.sql (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/difftool.c (modified) (2 diffs)
-
ippTools/src/magictool.c (modified) (1 prop)
-
ippTools/src/regtool.c (modified) (2 diffs)
-
ippconfig (modified) (1 prop)
-
ippconfig/gpc1/dvo.config (modified) (1 diff)
-
ippconfig/recipes/filerules-simple.mdc (modified) (1 diff)
-
ippconfig/recipes/ppSim.config (modified) (1 diff)
-
ippconfig/recipes/ppSub.config (modified) (4 diffs)
-
ippconfig/recipes/psphot.config (modified) (3 diffs)
-
ippconfig/simtest/camera.config (modified) (1 diff)
-
ippconfig/simtest/ppSub.config (modified) (2 diffs)
-
ppSim/src/Makefile.am (modified) (2 diffs)
-
ppSim/src/ppSimArguments.c (modified) (3 diffs)
-
ppSim/src/ppSimCreate.c (modified) (3 diffs)
-
ppSim/src/ppSimLoadForceSources.c (deleted)
-
ppSim/src/ppSimLoadSpots.c (deleted)
-
ppSim/src/ppSimLoop.c (modified) (3 diffs)
-
ppSim/src/ppSimMakeGalaxies.c (modified) (5 diffs)
-
ppSim/src/ppSimPhotom.c (deleted)
-
ppSim/src/ppSimPhotomFiles.c (deleted)
-
ppSim/src/ppSimPhotomReadout.c (deleted)
-
ppSim/src/ppSimPhotomReadoutFake.c (deleted)
-
ppSim/src/ppSimPhotomReadoutForce.c (deleted)
-
ppSim/src/ppSimSetPSF.c (modified) (2 diffs)
-
ppStack/src/Makefile.am (modified) (1 diff)
-
ppStack/src/ppStack.c (modified) (3 diffs)
-
ppStack/src/ppStack.h (modified) (5 diffs)
-
ppStack/src/ppStackArguments.c (modified) (2 diffs)
-
ppStack/src/ppStackCamera.c (modified) (1 diff)
-
ppStack/src/ppStackCleanup.c (modified) (3 diffs)
-
ppStack/src/ppStackCombineFinal.c (modified) (2 diffs)
-
ppStack/src/ppStackCombineInitial.c (modified) (1 diff)
-
ppStack/src/ppStackCombinePrepare.c (modified) (1 diff)
-
ppStack/src/ppStackConvolve.c (modified) (4 diffs)
-
ppStack/src/ppStackErrorCodes.c.in (modified) (2 diffs)
-
ppStack/src/ppStackFiles.c (modified) (3 diffs)
-
ppStack/src/ppStackFinish.c (modified) (4 diffs)
-
ppStack/src/ppStackJPEGs.c (copied) (copied from trunk/ppStack/src/ppStackJPEGs.c )
-
ppStack/src/ppStackLoop.c (modified) (2 diffs)
-
ppStack/src/ppStackLoop.h (modified) (3 diffs)
-
ppStack/src/ppStackMatch.c (modified) (2 diffs)
-
ppStack/src/ppStackOptions.c (modified) (2 diffs)
-
ppStack/src/ppStackOptions.h (modified) (1 diff)
-
ppStack/src/ppStackPSF.c (modified) (1 diff)
-
ppStack/src/ppStackPhotometry.c (modified) (1 diff)
-
ppStack/src/ppStackPrepare.c (modified) (1 diff)
-
ppStack/src/ppStackReadout.c (modified) (1 diff)
-
ppStack/src/ppStackReject.c (modified) (1 diff)
-
ppStack/src/ppStackSetup.c (modified) (1 diff)
-
ppStack/src/ppStackSources.c (modified) (1 diff)
-
ppStack/src/ppStackStats.c (copied) (copied from trunk/ppStack/src/ppStackStats.c )
-
ppStack/src/ppStackTarget.c (modified) (2 diffs)
-
ppStack/src/ppStackThread.c (modified) (1 diff)
-
ppStack/src/ppStackThread.h (modified) (1 diff)
-
ppStack/src/ppStackUpdateHeader.c (copied) (copied from trunk/ppStack/src/ppStackUpdateHeader.c )
-
ppStack/src/ppStackVersion.c (modified) (1 diff)
-
ppSub/src/ppSub.c (modified) (1 diff)
-
ppSub/src/ppSubFiles.c (modified) (9 diffs)
-
ppSub/src/ppSubInputDetections.c (modified) (2 diffs)
-
ppSub/src/ppSubLoop.c (modified) (3 diffs)
-
ppSub/src/ppSubMakePSF.c (modified) (3 diffs)
-
ppSub/src/ppSubMatchPSFs.c (modified) (7 diffs)
-
ppSub/src/ppSubReadoutForcedPhot.c (modified) (3 diffs)
-
ppSub/src/ppSubReadoutInverse.c (modified) (2 diffs)
-
ppSub/src/ppSubReadoutJpeg.c (modified) (1 diff)
-
ppSub/src/ppSubReadoutPhotometry.c (modified) (2 diffs)
-
ppSub/src/ppSubReadoutSubtract.c (modified) (5 diffs)
-
ppSub/src/ppSubSetMasks.c (modified) (4 diffs)
-
ppSub/src/ppSubThreshold.c (modified) (3 diffs)
-
ppSub/src/ppSubVarianceRescale.c (modified) (2 diffs)
-
ppTranslate/src/ppMopsMerge.c (modified) (1 diff)
-
psLib/src/imageops (modified) (1 prop)
-
psLib/src/imageops/psImageConvolve.c (modified) (6 diffs)
-
psLib/src/imageops/psImageConvolve.h (modified) (2 diffs)
-
psLib/src/imageops/psImageCovariance.c (modified) (1 diff)
-
psLib/src/sys/psLogMsg.c (modified) (3 diffs)
-
psLib/src/sys/psMemory.c (modified) (1 diff)
-
psLib/test/imageops/Makefile.am (modified) (1 diff)
-
psLib/test/imageops/samples (copied) (copied from trunk/psLib/test/imageops/samples )
-
psLib/test/imageops/samples/conv.sample1.001.fits (copied) (copied from trunk/psLib/test/imageops/samples/conv.sample1.001.fits )
-
psLib/test/imageops/samples/conv.sample1.002.fits (copied) (copied from trunk/psLib/test/imageops/samples/conv.sample1.002.fits )
-
psLib/test/imageops/samples/incovar.sample1.001.fits (copied) (copied from trunk/psLib/test/imageops/samples/incovar.sample1.001.fits )
-
psLib/test/imageops/samples/incovar.sample1.002.fits (copied) (copied from trunk/psLib/test/imageops/samples/incovar.sample1.002.fits )
-
psLib/test/imageops/tap_psImageCovariance.c (copied) (copied from trunk/psLib/test/imageops/tap_psImageCovariance.c )
-
psLib/test/math (modified) (1 prop)
-
psModules/src/extras/pmVisual.c (modified) (2 diffs)
-
psModules/src/extras/pmVisual.h (modified) (1 diff)
-
psModules/src/imcombine/Makefile.am (modified) (1 diff)
-
psModules/src/imcombine/pmReadoutCombine.c (modified) (1 diff)
-
psModules/src/imcombine/pmStackReject.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtraction.c (modified) (14 diffs)
-
psModules/src/imcombine/pmSubtraction.h (modified) (4 diffs)
-
psModules/src/imcombine/pmSubtractionAnalysis.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionDeconvolve.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionEquation.c (modified) (42 diffs)
-
psModules/src/imcombine/pmSubtractionEquation.h (modified) (3 diffs)
-
psModules/src/imcombine/pmSubtractionEquation.v0.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionHermitian.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionIO.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionKernels.c (modified) (18 diffs)
-
psModules/src/imcombine/pmSubtractionKernels.h (modified) (3 diffs)
-
psModules/src/imcombine/pmSubtractionMask.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionMatch.c (modified) (28 diffs)
-
psModules/src/imcombine/pmSubtractionMatch.h (modified) (3 diffs)
-
psModules/src/imcombine/pmSubtractionParams.c (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtractionStamps.c (modified) (12 diffs)
-
psModules/src/imcombine/pmSubtractionStamps.h (modified) (3 diffs)
-
psModules/src/imcombine/pmSubtractionThreads.c (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtractionTypes.h (copied) (copied from trunk/psModules/src/imcombine/pmSubtractionTypes.h )
-
psModules/src/imcombine/pmSubtractionVisual.c (modified) (13 diffs)
-
psModules/src/imcombine/pmSubtractionVisual.h (modified) (1 diff)
-
psModules/src/objects (modified) (1 prop)
-
psModules/src/objects/pmFootprint.c (modified) (1 diff)
-
psModules/src/objects/pmFootprint.h (modified) (1 diff)
-
psModules/src/objects/pmFootprintAssignPeaks.c (modified) (4 diffs)
-
psModules/src/objects/pmFootprintCullPeaks.c (modified) (3 diffs)
-
psModules/src/objects/pmModel.c (modified) (2 diffs)
-
psModules/src/objects/pmModel.h (modified) (1 diff)
-
psModules/src/objects/pmPCMdata.h (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) (1 diff)
-
psModules/src/objects/pmPSFtryModel.c (modified) (2 diffs)
-
psModules/src/objects/pmSource.c (modified) (10 diffs)
-
psModules/src/objects/pmSource.h (modified) (5 diffs)
-
psModules/src/objects/pmSourceExtendedPars.c (modified) (1 diff)
-
psModules/src/objects/pmSourceFitPCM.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO.c (modified) (13 diffs)
-
psModules/src/objects/pmSourceIO.h (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_CMF_PS1_DV1.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_CMF_PS1_DV2.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_CMF_PS1_SV1.c (modified) (7 diffs)
-
psModules/src/objects/pmSourceIO_CMF_PS1_V1.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_CMF_PS1_V2.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_CMF_PS1_V3.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_PS1_CAL_0.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_PS1_DEV_0.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_PS1_DEV_1.c (modified) (1 diff)
-
psModules/src/objects/pmSourceIO_SMPDATA.c (modified) (1 diff)
-
psModules/src/psmodules.h (modified) (1 diff)
-
psconfig/psbuild (modified) (5 diffs)
-
psphot (modified) (1 prop)
-
psphot/doc/notes.20101222.txt (copied) (copied from trunk/psphot/doc/notes.20101222.txt )
-
psphot/doc/stack.txt (modified) (1 diff)
-
psphot/src/Makefile.am (modified) (1 diff)
-
psphot/src/psphot.h (modified) (6 diffs)
-
psphot/src/psphotApResid.c (modified) (1 prop)
-
psphot/src/psphotBlendFit.c (modified) (1 diff)
-
psphot/src/psphotCheckStarDistribution.c (modified) (3 diffs)
-
psphot/src/psphotChoosePSF.c (modified) (16 diffs)
-
psphot/src/psphotExtendedSourceAnalysis.c (modified) (1 diff)
-
psphot/src/psphotExtendedSourceAnalysisByObject.c (modified) (1 diff)
-
psphot/src/psphotExtendedSourceFits.c (modified) (11 diffs)
-
psphot/src/psphotFindDetections.c (modified) (2 diffs)
-
psphot/src/psphotFindFootprints.c (modified) (1 diff)
-
psphot/src/psphotFitSourcesLinear.c (modified) (4 diffs)
-
psphot/src/psphotFitSourcesLinearStack.c (modified) (1 diff)
-
psphot/src/psphotImageQuality.c (modified) (2 diffs)
-
psphot/src/psphotMakeFluxScale.c (modified) (1 prop)
-
psphot/src/psphotMakePSFReadout.c (modified) (1 diff)
-
psphot/src/psphotMakeResiduals.c (modified) (2 diffs)
-
psphot/src/psphotMergeSources.c (modified) (1 diff)
-
psphot/src/psphotOutput.c (modified) (2 diffs)
-
psphot/src/psphotPetrosianAnalysis.c (modified) (1 diff)
-
psphot/src/psphotPetrosianProfile.c (modified) (1 diff)
-
psphot/src/psphotRadialApertures.c (modified) (8 diffs)
-
psphot/src/psphotRadialAperturesByObject.c (modified) (6 diffs)
-
psphot/src/psphotReadout.c (modified) (1 diff)
-
psphot/src/psphotReadoutFindPSF.c (modified) (1 diff)
-
psphot/src/psphotReadoutKnownSources.c (modified) (1 diff)
-
psphot/src/psphotReplaceUnfit.c (modified) (2 diffs)
-
psphot/src/psphotSetThreads.c (modified) (1 diff)
-
psphot/src/psphotSourceFits.c (modified) (2 diffs)
-
psphot/src/psphotSourceMatch.c (modified) (5 diffs)
-
psphot/src/psphotSourceSize.c (modified) (1 diff)
-
psphot/src/psphotStackArguments.c (modified) (1 diff)
-
psphot/src/psphotStackChisqImage.c (modified) (4 diffs)
-
psphot/src/psphotStackImageLoop.c (modified) (5 diffs)
-
psphot/src/psphotStackMatchPSFs.c (modified) (3 diffs)
-
psphot/src/psphotStackMatchPSFsNext.c (copied) (copied from trunk/psphot/src/psphotStackMatchPSFsNext.c )
-
psphot/src/psphotStackMatchPSFsUtils.c (modified) (2 diffs)
-
psphot/src/psphotStackPSF.c (modified) (2 diffs)
-
psphot/src/psphotStackParseCamera.c (modified) (6 diffs)
-
psphot/src/psphotStackReadout.c (modified) (7 diffs)
-
psphot/src/psphotVisual.c (modified) (4 diffs)
-
psphot/test/tap_psphot_deteff.pro (copied) (copied from trunk/psphot/test/tap_psphot_deteff.pro )
-
psphot/test/tap_psphot_diff.pro (copied) (copied from trunk/psphot/test/tap_psphot_diff.pro )
-
psphot/test/tap_psphot_diffsuite.pro (copied) (copied from trunk/psphot/test/tap_psphot_diffsuite.pro )
-
psphot/test/tap_psphot_stack.pro (copied) (copied from trunk/psphot/test/tap_psphot_stack.pro )
-
pstamp/scripts/pstamp_checkdependent.pl (modified) (5 diffs)
-
tools/roc.exposure (copied) (copied from trunk/tools/roc.exposure )
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20101203
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/Ohana/src/addstar/include/addstar.h
r30118 r30631 265 265 266 266 int InitStar PROTO((Stars *star)); 267 short ShortPixels PROTO((float pixels));268 short ShortDegree PROTO((float degrees));269 267 270 268 int args_skycells (int argc, char **argv); -
branches/czw_branch/20101203/Ohana/src/addstar/src/ReadStarsFITS.c
r30118 r30631 98 98 stars[i].measure.photFlags = (smpdata[i].dophot << 16); 99 99 100 stars[i].measure.FWx = ShortPixels (smpdata[i].fx);101 stars[i].measure.FWy = ShortPixels (smpdata[i].fy);102 stars[i].measure.theta = ShortDegree(smpdata[i].df);100 stars[i].measure.FWx = ToShortPixels (smpdata[i].fx); 101 stars[i].measure.FWy = ToShortPixels (smpdata[i].fy); 102 stars[i].measure.theta = ToShortDegrees (smpdata[i].df); 103 103 } 104 104 *nstars = Nstars; … … 127 127 stars[i].measure.Yccd = ps1data[i].Y; 128 128 129 stars[i].measure.dXccd = ShortPixels(ps1data[i].dX);130 stars[i].measure.dYccd = ShortPixels(ps1data[i].dY);129 stars[i].measure.dXccd = ToShortPixels(ps1data[i].dX); 130 stars[i].measure.dYccd = ToShortPixels(ps1data[i].dY); 131 131 132 132 if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) { … … 140 140 stars[i].measure.dSky = ps1data[i].dSky; 141 141 142 stars[i].measure.FWx = ShortPixels(ps1data[i].fx);143 stars[i].measure.FWy = ShortPixels(ps1data[i].fy);144 stars[i].measure.theta = ShortDegree(ps1data[i].df);142 stars[i].measure.FWx = ToShortPixels(ps1data[i].fx); 143 stars[i].measure.FWy = ToShortPixels(ps1data[i].fy); 144 stars[i].measure.theta = ToShortDegrees(ps1data[i].df); 145 145 146 146 stars[i].measure.psfChisq = ps1data[i].psfChisq; … … 176 176 stars[i].measure.Yccd = ps1data[i].Y; 177 177 178 stars[i].measure.dXccd = ShortPixels(ps1data[i].dX);179 stars[i].measure.dYccd = ShortPixels(ps1data[i].dY);178 stars[i].measure.dXccd = ToShortPixels(ps1data[i].dX); 179 stars[i].measure.dYccd = ToShortPixels(ps1data[i].dY); 180 180 181 181 if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) { … … 189 189 stars[i].measure.dSky = ps1data[i].dSky; 190 190 191 stars[i].measure.FWx = ShortPixels(ps1data[i].fx);192 stars[i].measure.FWy = ShortPixels(ps1data[i].fy);193 stars[i].measure.theta = ShortDegree(ps1data[i].df);191 stars[i].measure.FWx = ToShortPixels(ps1data[i].fx); 192 stars[i].measure.FWy = ToShortPixels(ps1data[i].fy); 193 stars[i].measure.theta = ToShortDegrees(ps1data[i].df); 194 194 195 195 stars[i].measure.psfChisq = ps1data[i].psfChisq; … … 238 238 stars[i].measure.Xccd = ps1data[i].X; 239 239 stars[i].measure.Yccd = ps1data[i].Y; 240 stars[i].measure.dXccd = ShortPixels(ps1data[i].dX);241 stars[i].measure.dYccd = ShortPixels(ps1data[i].dY);242 243 stars[i].measure.posangle = ShortDegree(ps1data[i].posangle);240 stars[i].measure.dXccd = ToShortPixels(ps1data[i].dX); 241 stars[i].measure.dYccd = ToShortPixels(ps1data[i].dY); 242 243 stars[i].measure.posangle = ToShortDegrees(ps1data[i].posangle); 244 244 stars[i].measure.pltscale = ps1data[i].pltscale; 245 245 … … 263 263 stars[i].measure.extNsigma = ps1data[i].extNsigma; 264 264 265 stars[i].measure.FWx = ShortPixels(ps1data[i].fx);266 stars[i].measure.FWy = ShortPixels(ps1data[i].fy);267 stars[i].measure.theta = ShortDegree(ps1data[i].df);268 269 stars[i].measure.Mxx = ShortPixels(ps1data[i].Mxx);270 stars[i].measure.Mxy = ShortPixels(ps1data[i].Mxy);271 stars[i].measure.Myy = ShortPixels(ps1data[i].Myy);265 stars[i].measure.FWx = ToShortPixels(ps1data[i].fx); 266 stars[i].measure.FWy = ToShortPixels(ps1data[i].fy); 267 stars[i].measure.theta = ToShortDegrees(ps1data[i].df); 268 269 stars[i].measure.Mxx = ToShortPixels(ps1data[i].Mxx); 270 stars[i].measure.Mxy = ToShortPixels(ps1data[i].Mxy); 271 stars[i].measure.Myy = ToShortPixels(ps1data[i].Myy); 272 272 273 273 stars[i].measure.photFlags = ps1data[i].flags; … … 314 314 stars[i].measure.Xccd = ps1data[i].X; 315 315 stars[i].measure.Yccd = ps1data[i].Y; 316 stars[i].measure.dXccd = ShortPixels(ps1data[i].dX);317 stars[i].measure.dYccd = ShortPixels(ps1data[i].dY);318 319 stars[i].measure.posangle = ShortDegree(ps1data[i].posangle);316 stars[i].measure.dXccd = ToShortPixels(ps1data[i].dX); 317 stars[i].measure.dYccd = ToShortPixels(ps1data[i].dY); 318 319 stars[i].measure.posangle = ToShortDegrees(ps1data[i].posangle); 320 320 stars[i].measure.pltscale = ps1data[i].pltscale; 321 321 … … 339 339 stars[i].measure.extNsigma = ps1data[i].extNsigma; 340 340 341 stars[i].measure.FWx = ShortPixels(ps1data[i].fx);342 stars[i].measure.FWy = ShortPixels(ps1data[i].fy);343 stars[i].measure.theta = ShortDegree(ps1data[i].df);344 345 stars[i].measure.Mxx = ShortPixels(ps1data[i].Mxx);346 stars[i].measure.Mxy = ShortPixels(ps1data[i].Mxy);347 stars[i].measure.Myy = ShortPixels(ps1data[i].Myy);341 stars[i].measure.FWx = ToShortPixels(ps1data[i].fx); 342 stars[i].measure.FWy = ToShortPixels(ps1data[i].fy); 343 stars[i].measure.theta = ToShortDegrees(ps1data[i].df); 344 345 stars[i].measure.Mxx = ToShortPixels(ps1data[i].Mxx); 346 stars[i].measure.Mxy = ToShortPixels(ps1data[i].Mxy); 347 stars[i].measure.Myy = ToShortPixels(ps1data[i].Myy); 348 348 349 349 stars[i].measure.photFlags = ps1data[i].flags; … … 382 382 stars[i].measure.Xccd = ps1data[i].X; 383 383 stars[i].measure.Yccd = ps1data[i].Y; 384 stars[i].measure.dXccd = ShortPixels(ps1data[i].dX);385 stars[i].measure.dYccd = ShortPixels(ps1data[i].dY);386 387 stars[i].measure.posangle = ShortDegree(ps1data[i].posangle);384 stars[i].measure.dXccd = ToShortPixels(ps1data[i].dX); 385 stars[i].measure.dYccd = ToShortPixels(ps1data[i].dY); 386 387 stars[i].measure.posangle = ToShortDegrees(ps1data[i].posangle); 388 388 stars[i].measure.pltscale = ps1data[i].pltscale; 389 389 … … 407 407 stars[i].measure.extNsigma = ps1data[i].extNsigma; 408 408 409 stars[i].measure.FWx = ShortPixels(ps1data[i].fx);410 stars[i].measure.FWy = ShortPixels(ps1data[i].fy);411 stars[i].measure.theta = ShortDegree(ps1data[i].df);412 413 stars[i].measure.Mxx = ShortPixels(ps1data[i].Mxx);414 stars[i].measure.Mxy = ShortPixels(ps1data[i].Mxy);415 stars[i].measure.Myy = ShortPixels(ps1data[i].Myy);409 stars[i].measure.FWx = ToShortPixels(ps1data[i].fx); 410 stars[i].measure.FWy = ToShortPixels(ps1data[i].fy); 411 stars[i].measure.theta = ToShortDegrees(ps1data[i].df); 412 413 stars[i].measure.Mxx = ToShortPixels(ps1data[i].Mxx); 414 stars[i].measure.Mxy = ToShortPixels(ps1data[i].Mxy); 415 stars[i].measure.Myy = ToShortPixels(ps1data[i].Myy); 416 416 417 417 stars[i].measure.photFlags = ps1data[i].flags; … … 450 450 stars[i].measure.Xccd = ps1data[i].X; 451 451 stars[i].measure.Yccd = ps1data[i].Y; 452 stars[i].measure.dXccd = ShortPixels(ps1data[i].dX);453 stars[i].measure.dYccd = ShortPixels(ps1data[i].dY);454 455 stars[i].measure.posangle = ShortDegree(ps1data[i].posangle);452 stars[i].measure.dXccd = ToShortPixels(ps1data[i].dX); 453 stars[i].measure.dYccd = ToShortPixels(ps1data[i].dY); 454 455 stars[i].measure.posangle = ToShortDegrees(ps1data[i].posangle); 456 456 stars[i].measure.pltscale = ps1data[i].pltscale; 457 457 … … 475 475 stars[i].measure.extNsigma = ps1data[i].extNsigma; 476 476 477 stars[i].measure.FWx = ShortPixels(ps1data[i].fx);478 stars[i].measure.FWy = ShortPixels(ps1data[i].fy);479 stars[i].measure.theta = ShortDegree(ps1data[i].df);480 481 stars[i].measure.Mxx = ShortPixels(ps1data[i].Mxx);482 stars[i].measure.Mxy = ShortPixels(ps1data[i].Mxy);483 stars[i].measure.Myy = ShortPixels(ps1data[i].Myy);477 stars[i].measure.FWx = ToShortPixels(ps1data[i].fx); 478 stars[i].measure.FWy = ToShortPixels(ps1data[i].fy); 479 stars[i].measure.theta = ToShortDegrees(ps1data[i].df); 480 481 stars[i].measure.Mxx = ToShortPixels(ps1data[i].Mxx); 482 stars[i].measure.Mxy = ToShortPixels(ps1data[i].Mxy); 483 stars[i].measure.Myy = ToShortPixels(ps1data[i].Myy); 484 484 485 485 stars[i].measure.photFlags = ps1data[i].flags; -
branches/czw_branch/20101203/Ohana/src/addstar/src/ReadStarsSDSS.c
r30118 r30631 159 159 stars[N].measure.Xccd = colc[N]; 160 160 stars[N].measure.Yccd = rowc[N]; 161 stars[N].measure.dXccd = ShortPixels(colcErr[N]);162 stars[N].measure.dYccd = ShortPixels(rowcErr[N]);161 stars[N].measure.dXccd = ToShortPixels(colcErr[N]); 162 stars[N].measure.dYccd = ToShortPixels(rowcErr[N]); 163 163 stars[N].measure.M = psfCounts[N] + ZeroPt - zeropt[j]; 164 164 stars[N].measure.dM = psfCountsErr[N]; … … 166 166 stars[N].measure.Sky = sky[N]; // adjust this to counts? 167 167 stars[N].measure.dSky = skyErr[N]; 168 stars[N].measure.FWx = ShortPixels(seeing[j]); // reported in arcsec?169 stars[N].measure.FWy = ShortPixels(seeing[j]);168 stars[N].measure.FWx = ToShortPixels(seeing[j]); // reported in arcsec? 169 stars[N].measure.FWy = ToShortPixels(seeing[j]); 170 170 if (prob_psf) { 171 171 stars[N].measure.psfChisq = prob_psf[N]; // XXX not really the correct value... -
branches/czw_branch/20101203/Ohana/src/addstar/src/ReadStarsTEXT.c
r21508 r30631 95 95 dparse (&df, 11, &buffer[j*BYTES_STAR]); 96 96 97 stars[N].measure.FWx = ShortPixels (fx);98 stars[N].measure.FWy = ShortPixels (fy);99 stars[N].measure.theta = ShortDegree(df);97 stars[N].measure.FWx = ToShortPixels (fx); 98 stars[N].measure.FWy = ToShortPixels (fy); 99 stars[N].measure.theta = ToShortDegrees (df); 100 100 } 101 101 } -
branches/czw_branch/20101203/Ohana/src/addstar/src/StarOps.c
r21508 r30631 9 9 return TRUE; 10 10 } 11 12 short ShortPixels (float pixels) {13 14 short value;15 16 value = 100*pixels;17 18 return value;19 }20 21 short ShortDegree (float degrees) {22 23 short value;24 25 value = (0xffff/360.0)*degrees;26 27 return value;28 } -
branches/czw_branch/20101203/Ohana/src/addstar/src/calibrate.c
r27435 r30631 225 225 image[0].Mcal = M1; 226 226 image[0].dMcal = M2 / sqrt (N); 227 image[0]. Mxxxx= N;227 image[0].nFitPhotom = N; 228 228 } else { 229 229 fprintf (stderr, "too few stars\n"); 230 230 image[0].Mcal = 10.000; 231 231 image[0].dMcal = 10.000; 232 image[0]. Mxxxx= 0;233 } 234 } 232 image[0].nFitPhotom = 0; 233 } 234 } -
branches/czw_branch/20101203/Ohana/src/addstar/src/fakeimage.c
r27435 r30631 134 134 135 135 image[i+1].nstar = 0; 136 image[i+1].Myyyy = 0;137 136 138 137 /* check if chip hits outer bounds of mosaic */ … … 191 190 image[0].flags = 0; 192 191 image[0].nstar = 0; 193 image[0].Myyyy = 0;194 192 195 193 // XXX need to set the imageID here -
branches/czw_branch/20101203/Ohana/src/addstar/src/get2mass_full.c
r23226 r30631 17 17 ptr = next2MASSfield (ptr); // dec (assumed to be already set) 18 18 ptr = next2MASSfield (ptr); // err_maj 19 star[0][0].measure.FWx = ShortPixels(strtod (ptr, NULL));19 star[0][0].measure.FWx = ToShortPixels(strtod (ptr, NULL)); 20 20 ptr = next2MASSfield (ptr); // err_min 21 star[0][0].measure.FWy = ShortPixels(strtod (ptr, NULL));21 star[0][0].measure.FWy = ToShortPixels(strtod (ptr, NULL)); 22 22 ptr = next2MASSfield (ptr); // err_ang 23 star[0][0].measure.theta = ShortPixels(strtod (ptr, NULL));23 star[0][0].measure.theta = ToShortPixels(strtod (ptr, NULL)); 24 24 25 25 star[2][0].measure.FWx = star[2][0].measure.FWx = star[0][0].measure.FWx; -
branches/czw_branch/20101203/Ohana/src/addstar/src/resort_catalog.c
r30586 r30631 39 39 tmp_ave = AVE[A]; AVE[A] = AVE[B]; AVE[B] = tmp_ave; \ 40 40 } 41 # define COMPARE(A,B)( MEAS[A] < MEAS[B])41 # define COMPARE(A,B)(AVE[A] < AVE[B]) 42 42 OHANA_SORT (N, COMPARE, SWAPFUNC); 43 43 # undef SWAPFUNC … … 96 96 } 97 97 98 // check that averageSeq is now in order 99 // for (i = 1; i < Nmeasure; i++) { 100 // if (averageSeq[i] < averageSeq[i-1]) { 101 // fprintf (stderr, "%d ", (int) i); 102 // } 103 // } 104 // fprintf (stderr, "\n"); 105 98 106 SortAveMeasMatch(measureSeq, averageSeq, Nmeasure); 99 107 // MARKTIME("sort : %f sec\n", dtime); 108 109 // check that averageSeq is now in order 110 // for (i = 1; i < Nmeasure; i++) { 111 // if (averageSeq[i] < averageSeq[i-1]) { 112 // fprintf (stderr, "%d ", (int) i); 113 // } 114 // } 115 // fprintf (stderr, "\n"); 100 116 101 117 // copy the measurements in the sorted order … … 116 132 for (i = 0; i < Nmeasure; i++) { 117 133 if (averageSeq[i] != currentAve) { 134 // we have hit the next entry in the list 118 135 average[currentAve].Nmeasure = N; 119 136 N = 0; … … 127 144 // MARKTIME("update Nmeasure : %f sec\n", dtime); 128 145 146 int NmeasureTotal = 0; 147 int measureOffsetOK = TRUE; 148 for (i = 0; i < catalog[0].Naverage; i++) { 149 NmeasureTotal += catalog[0].average[i].Nmeasure; 150 if (VERBOSE && !(NmeasureTotal <= catalog[0].Nmeasure)) { 151 fprintf (stderr, "too few measurements: %d %d %d\n", (int) i, NmeasureTotal, (int) catalog[0].Nmeasure); 152 } 153 measureOffsetOK &= (catalog[0].average[i].measureOffset < catalog[0].Nmeasure); 154 if (VERBOSE && !(catalog[0].average[i].measureOffset < catalog[0].Nmeasure)) { 155 fprintf (stderr, "offset too large: %d %d %d\n", (int) i, catalog[0].average[i].Nmeasure, (int) catalog[0].Nmeasure); 156 } 157 measureOffsetOK &= (catalog[0].average[i].measureOffset + catalog[0].average[i].Nmeasure <= catalog[0].Nmeasure); 158 if (VERBOSE && !(catalog[0].average[i].measureOffset + catalog[0].average[i].Nmeasure <= catalog[0].Nmeasure)) { 159 fprintf (stderr, "orrset + Nmeasure too large: %d + %d > %d %d\n", (int) i, catalog[0].average[i].measureOffset, catalog[0].average[i].Nmeasure, (int) catalog[0].Nmeasure); 160 } 161 } 162 163 if (!measureOffsetOK) { 164 fprintf (stderr, "ERROR: catalog %s has an invalid measureOffset\n", catalog[0].filename); 165 } 166 167 if (NmeasureTotal != catalog[0].Nmeasure) { 168 fprintf (stderr, "ERROR: catalog %s has an invalid Nmeasure\n", catalog[0].filename); 169 } 170 129 171 // MARKTIME(" match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeasure, (long long) Naverage); 172 173 catalog[0].sorted = TRUE; 130 174 131 175 FREE (measureSeq); -
branches/czw_branch/20101203/Ohana/src/addstar/src/sky_tessalation.c
r28673 r30631 338 338 image[0].photcode = 1; // this needs to be set more sensibly 339 339 340 image[0].Mx = xv[0]; image[0].My = yv[0]; 341 image[0].Mxxx = xv[1]; image[0].Mxyy = yv[1]; 342 image[0].Mxxy = xv[2]; image[0].Myyy = yv[2]; 340 // XXX these overload these value in a silly way 341 image[0].dXpixSys = xv[0]; image[0].dYpixSys = yv[0]; 342 image[0].dMagSys = xv[1]; image[0].nFitAstrom = yv[1]; 343 image[0].photom_map_id = xv[2]; image[0].astrom_map_id = yv[2]; 343 344 344 345 return (TRUE); -
branches/czw_branch/20101203/Ohana/src/dvomerge/src/dvoverify.c
r30118 r30631 9 9 10 10 int VerifyTableFile (char *filename); 11 int CheckCatalogIndexes (char *catdir, char *filename, SkyRegion *region); 11 12 12 13 # define DEBUG 0 14 15 int VERBOSE; 13 16 14 17 int main (int argc, char **argv) { … … 22 25 SkyRegion UserPatch; 23 26 // Catalog catalog; 27 28 VERBOSE = FALSE; 29 if ((N = get_argument (argc, argv, "-v"))) { 30 VERBOSE = TRUE; 31 remove_argument (N, &argc, argv); 32 } 24 33 25 34 // restrict to a portion of the sky … … 83 92 if (i % 1000 == 0) fprintf (stderr, "."); 84 93 85 sprintf (filename, "%s/%s.cpt", catdir, inlist[0].regions[i][0].name);86 if (!VerifyTableFile ( filename)) {94 // sprintf (filename, "%s/%s.cpt", catdir, inlist[0].regions[i][0].name); 95 if (!VerifyTableFile (inlist[0].filename[i])) { 87 96 Nbad ++; 88 97 } … … 95 104 sprintf (filename, "%s/%s.cpm", catdir, inlist[0].regions[i][0].name); 96 105 if (!VerifyTableFile (filename)) { 106 Nbad ++; 107 } 108 109 if (!CheckCatalogIndexes(catdir, inlist[0].filename[i], inlist[0].regions[i])){ 97 110 Nbad ++; 98 111 } … … 212 225 } 213 226 214 // gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow); 215 // gfits_scan(&cpmHeaderTBL, "NAXIS2", "%d", 1, &Nrows); 227 // CheckCatalogIndexes(catdir, inlist[0].regions[i][0].name); 228 229 int CheckCatalogIndexes (char *catdir, char *filename, SkyRegion *region) { 230 231 Catalog catalog; 232 int i, j, m, status; 233 234 status = TRUE; 235 236 // set the parameters which guide catalog open/load/create 237 catalog.filename = filename; 238 catalog.catformat = dvo_catalog_catformat (CATFORMAT); // set the default catformat from config data 239 catalog.catmode = dvo_catalog_catmode (CATMODE); // set the default catmode from config data 240 catalog.catflags = LOAD_AVES | LOAD_MEAS; 241 catalog.Nsecfilt = 0; 242 243 // an error exit status here is a significant error (disk I/O or file access) 244 if (!dvo_catalog_open (&catalog, region, VERBOSE, "r")) { 245 fprintf (stderr, "ERROR: failure to open catalog file %s\n", catalog.filename); 246 return FALSE; 247 } 248 249 // Naves_disk == 0 implies an empty catalog file, skip empty catalogs 250 if (catalog.Naves_disk == 0) { 251 dvo_catalog_unlock (&catalog); 252 dvo_catalog_free (&catalog); 253 return TRUE; 254 } 255 256 // if the table is SORTED, then the following can be checked 257 // check the following: 258 // measure[j].averef -> average[averef] 259 // measure[j].objID = average[averef].objID 260 // measure[j].catID = average[averef].catID 261 // measure[j].measureOffset < Nmeasure 262 // \sum average[].Nmeasure = Nmeasure 263 264 // if the table is NOT SORTED, we have a subset of checks we can make 265 if (!catalog.sorted) { 266 fprintf (stderr, "!"); 267 dvo_catalog_unlock (&catalog); 268 dvo_catalog_free (&catalog); 269 return TRUE; 270 } 271 272 int NmeasureTotal = 0; 273 int measureOffsetOK = TRUE; 274 for (i = 0; i < catalog.Naverage; i++) { 275 NmeasureTotal += catalog.average[i].Nmeasure; 276 if (VERBOSE && !(NmeasureTotal <= catalog.Nmeasure)) { 277 fprintf (stderr, "NmeasureTotal > catalog.Nmeasure: %d %d %d\n", i, catalog.average[i].Nmeasure, (int) catalog.Nmeasure); 278 } 279 measureOffsetOK &= (catalog.average[i].measureOffset < catalog.Nmeasure); 280 if (VERBOSE && !(catalog.average[i].measureOffset < catalog.Nmeasure)) { 281 fprintf (stderr, "measureOffset >= catalog.Nmeasure: %d %d %d\n", i, catalog.average[i].measureOffset, (int) catalog.Nmeasure); 282 } 283 measureOffsetOK &= (catalog.average[i].measureOffset + catalog.average[i].Nmeasure <= catalog.Nmeasure); 284 if (VERBOSE && !(catalog.average[i].measureOffset + catalog.average[i].Nmeasure <= catalog.Nmeasure)) { 285 fprintf (stderr, "measureOffset + Nmeasure > catalog.Nmeasure : %d %d %d\n", i, catalog.average[i].Nmeasure, (int) catalog.Nmeasure); 286 } 287 } 288 289 if (!measureOffsetOK) { 290 fprintf (stderr, "ERROR: catalog %s has an invalid measureOffset\n", catalog.filename); 291 status = FALSE; 292 } 293 294 if (NmeasureTotal != catalog.Nmeasure) { 295 fprintf (stderr, "ERROR: catalog %s has an invalid Nmeasure\n", catalog.filename); 296 status = FALSE; 297 } 298 299 if (!status) { 300 dvo_catalog_unlock (&catalog); 301 dvo_catalog_free (&catalog); 302 return (status); 303 } 304 305 int objIDsOK = TRUE; 306 int catIDsOK = TRUE; 307 int averefOK = TRUE; 308 309 for (i = 0; i < catalog.Naverage; i++) { 310 m = catalog.average[i].measureOffset; 311 for (j = 0; j < catalog.average[i].Nmeasure; j++) { 312 objIDsOK &= (catalog.average[i].objID == catalog.measure[m+j].objID); 313 catIDsOK &= (catalog.average[i].catID == catalog.measure[m+j].catID); 314 averefOK &= (catalog.measure[m+j].averef == i); 315 } 316 } 317 318 if (!objIDsOK) { 319 fprintf (stderr, "ERROR: catalog %s has invalid obj IDs\n", catalog.filename); 320 status = FALSE; 321 } 322 if (!catIDsOK) { 323 fprintf (stderr, "ERROR: catalog %s has invalid cat IDs\n", catalog.filename); 324 status = FALSE; 325 } 326 if (!averefOK) { 327 fprintf (stderr, "ERROR: catalog %s has invalid averef values\n", catalog.filename); 328 status = FALSE; 329 } 330 331 // for (i = 0; i < catalog.Naverage; i++) { 332 // m = catalog.average[i].measureOffset; 333 // for (j = 0; i < catalog.Nmeasure; i++) { 334 // objIDsOK &= (catalog.average[i].objID == catalog.measure[m+j].objID); 335 // catIDsOK &= (catalog.average[i].catID == catalog.measure[m+j].catID); 336 // averefOK &= (catalog.measure[m+j].averef = i); 337 // } 338 // } 339 340 dvo_catalog_unlock (&catalog); 341 dvo_catalog_free (&catalog); 342 343 return status; 344 } 345 346 // gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow); 347 // gfits_scan(&cpmHeaderTBL, "NAXIS2", "%d", 1, &Nrows); 216 348 217 349 -
branches/czw_branch/20101203/Ohana/src/dvomerge/src/help.c
r30118 r30631 37 37 fprintf (stderr, " dvomerge (input) into (output)\n"); 38 38 fprintf (stderr, " dvomerge (input) into (output) continue\n\n"); 39 fprintf (stderr, " dvomerge (input) into (output) from (list)\n\n"); 39 fprintf (stderr, " dvomerge (input) into (output) from (list)\n"); 40 fprintf (stderr, " dvomerge list implies 'continue' : list contains, eg, n1500/1688.00.cpt (one cpt per line)\n\n"); 40 41 fprintf (stderr, " merge DVO databases\n"); 41 42 fprintf (stderr, " optional flags:\n"); -
branches/czw_branch/20101203/Ohana/src/getstar/src/select_by_image.c
r12332 r30631 38 38 stars[N].Mgal = 0.001*(catalog[0].measure[i].Mgal - catalog[0].measure[i].dt); 39 39 40 stars[N].fx = 0.01*catalog[0].measure[i].FWx;41 stars[N].fy = stars[N].fx * 0.01*catalog[0].measure[i].fwy;42 stars[N].df = (360.0/255.0)*catalog[0].measure[i].theta;40 stars[N].fx = FromShortPixels(catalog[0].measure[i].FWx); 41 stars[N].fy = FromShortPixels(catalog[0].measure[i].FWy); 42 stars[N].df = FromShortDegrees(catalog[0].measure[i].theta); 43 43 stars[N].found = catalog[0].measure[i].flags; 44 44 -
branches/czw_branch/20101203/Ohana/src/imregister/imphot/dumpfits.c
r27435 r30631 118 118 XY_to_RD (&ra, &dec, 0.0, 0.0, &subset[0].coords); 119 119 airmass = subset[0].secz; 120 sky = subset[0].Myyyy + 0x8000;120 sky = 0.0; // subset[0].Myyyy + 0x8000; 121 121 122 122 /* we should get an error here if we don't construct this line correctly */ -
branches/czw_branch/20101203/Ohana/src/kapa2/include/prototypes.h
r30118 r30631 175 175 void DrawBitmap PROTO((Graphic *graphic, int x, int y, int dx, int dy, char *bitmap, int mode)); 176 176 void CrossHairs PROTO((Graphic *graphic, Picture *image)); 177 void hh_hms PROTO((char *line, double ra, double dec, char sep ));177 void hh_hms PROTO((char *line, double ra, double dec, char sep, int Nchar)); 178 178 179 179 int SetColormap PROTO((char *name)); -
branches/czw_branch/20101203/Ohana/src/kapa2/src/PSObjects.c
r27530 r30631 164 164 float *x, *y; 165 165 double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by; 166 double sx0, sy0, sx1, sy1, sxa ;166 double sx0, sy0, sx1, sy1, sxa, sya, sxo, syo; 167 167 double X0, X1, Y0, Y1; 168 168 … … 189 189 for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++); 190 190 if (i >= object[0].Npts) return; 191 192 /* first valid data point */ 193 sx0 = x[i]*mxi + y[i]*mxj + bx; 194 sy0 = x[i]*myi + y[i]*myj + by; 195 sx0 = MIN (MAX (sx0, X0), X1); 196 sy0 = MAX (MIN (sy0, Y0), Y1); 197 198 /* find the second valid datapoint */ 199 for (i++; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++); 200 if (i >= object[0].Npts) return; 201 202 /* second valid data point */ 203 sx1 = x[i]*mxi + y[i]*mxj + bx; 204 sy1 = x[i]*myi + y[i]*myj + by; 205 sx1 = MIN (MAX (sx1, X0), X1); 206 sy1 = MAX (MIN (sy1, Y0), Y1); 207 208 /* connect first point to second point */ 209 sxa = sx0 - 0.5*(sx1 - sx0); 210 sya = MAX (sy0, Y0); 211 DrawLine (sx0, sy0, sxa, sy0); 212 DrawLine (sxa, sy0, sxa, sya); 213 214 /* draw segment equal distance behind first point and down to x-axis */ 215 sxa = 0.5*(sx0 + sx1); 216 DrawLine (sx0, sy0, sxa, sy0); 217 DrawLine (sxa, sy0, sxa, sy1); 218 DrawLine (sxa, sy1, sx1, sy1); 219 sx0 = sx1; 220 sy0 = sy1; 221 222 /* continue with rest of points */ 223 sxo = syo = 0; 224 for (i++; i < object[0].Npts; i++) { 225 if (!(finite(x[i]) && finite(y[i]))) continue; 226 sx1 = x[i]*mxi + y[i]*mxj + bx; 227 sy1 = x[i]*myi + y[i]*myj + by; 228 sx1 = MIN (MAX (sx1, X0), X1); 229 sy1 = MAX (MIN (sy1, Y0), Y1); 230 sxa = 0.5*(sx0 + sx1); 231 DrawLine (sx0, sy0, sxa, sy0); 232 DrawLine (sxa, sy0, sxa, sy1); 233 DrawLine (sxa, sy1, sx1, sy1); 234 sxo = sx0; syo = sy0; 235 sx0 = sx1; sy0 = sy1; 236 } 237 238 /* draw segment equal distance after last point and down to x-axis */ 239 sxa = sx1 + 0.5*(sx1 - sxo); 240 sya = MAX (sy1, Y0); 241 DrawLine (sx1, sy1, sxa, sy1); 242 DrawLine (sxa, sy1, sxa, sya); 243 244 # if (0) 191 245 sx0 = x[i]*mxi + y[i]*mxj + bx; 192 246 sy0 = x[i]*myi + y[i]*myj + by; … … 207 261 sx0 = sx1; sy0 = sy1; 208 262 } 263 # endif 209 264 } 210 265 -
branches/czw_branch/20101203/Ohana/src/kapa2/src/UpdateStatusBox.c
r29539 r30631 20 20 21 21 bzero (line, 100); 22 s printf (line, "(%d x %d) @ %d ",22 snprintf (line, 100, "(%d x %d) @ %d ", 23 23 image[0].picture.dx, image[0].picture.dy, image[0].picture.expand); 24 24 XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, … … 26 26 27 27 bzero (line, 100); 28 s printf (line, "%-25s", image[0].image[0].file);28 snprintf (line, 100, "%-25s", image[0].image[0].file); 29 29 XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 30 30 image[0].text_x + PAD1, image[0].text_y + 5*textpad + 5*PAD1, line, strlen(line)); 31 31 32 32 bzero (line, 100); 33 s printf (line, "(%s) ", image[0].image[0].name);33 snprintf (line, 100, "(%s) ", image[0].image[0].name); 34 34 XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 35 35 image[0].text_x + PAD1, image[0].text_y + 6*textpad + 6*PAD1, line, 25); … … 45 45 46 46 if (image[0].HexValue) { 47 sprintf (line, "%04x", (int) z);47 snprintf (line, 100, "%04x", (int) z); 48 48 } else { 49 sprintf (line, "%22.3f", z);49 snprintf (line, 100, "%22.3f", z); 50 50 } 51 51 XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, … … 53 53 54 54 bzero (line, 100); 55 s printf (line, "%10.2f %10.2f", x, y);55 snprintf (line, 100, "%10.2f %10.2f", x, y); 56 56 XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 57 57 image[0].text_x + PAD1, image[0].text_y + 2*textpad + 2*PAD1, line, strlen(line)); … … 59 59 bzero (line, 100); 60 60 if (image[0].DecimalDegrees) { 61 s printf (line, "%10.6f %10.6f", ra, dec);61 snprintf (line, 100, "%10.6f %10.6f", ra, dec); 62 62 } else { 63 hh_hms (line, ra, dec, ':' );63 hh_hms (line, ra, dec, ':', 100); 64 64 } 65 65 66 XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 66 67 image[0].text_x + PAD1, image[0].text_y + 3*textpad + 3*PAD1, line, strlen(line)); -
branches/czw_branch/20101203/Ohana/src/kapa2/src/bDrawObjects.c
r30118 r30631 154 154 float *x, *y; 155 155 double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by; 156 double sx0, sy0, sx1, sy1, sxa ;156 double sx0, sy0, sx1, sy1, sxa, sya, sxo, syo; 157 157 double X0, X1, Y0, Y1; 158 158 … … 179 179 for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++); 180 180 if (i >= object[0].Npts) return; 181 182 /* first valid data point */ 183 sx0 = x[i]*mxi + y[i]*mxj + bx; 184 sy0 = x[i]*myi + y[i]*myj + by; 185 sx0 = MIN (MAX (sx0, X0), X1); 186 sy0 = MAX (MIN (sy0, Y0), Y1); 187 188 /* find the second valid datapoint */ 189 for (i++; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++); 190 if (i >= object[0].Npts) return; 191 192 /* second valid data point */ 193 sx1 = x[i]*mxi + y[i]*mxj + bx; 194 sy1 = x[i]*myi + y[i]*myj + by; 195 sx1 = MIN (MAX (sx1, X0), X1); 196 sy1 = MAX (MIN (sy1, Y0), Y1); 197 198 /* connect first point to second point */ 199 sxa = sx0 - 0.5*(sx1 - sx0); 200 sya = MAX (sy0, Y0); 201 DrawLine (buffer, sx0, sy0, sxa, sy0); 202 DrawLine (buffer, sxa, sy0, sxa, sya); 203 204 /* draw segment equal distance behind first point and down to x-axis */ 205 sxa = 0.5*(sx0 + sx1); 206 DrawLine (buffer, sx0, sy0, sxa, sy0); 207 DrawLine (buffer, sxa, sy0, sxa, sy1); 208 DrawLine (buffer, sxa, sy1, sx1, sy1); 209 sx0 = sx1; 210 sy0 = sy1; 211 212 /* continue with rest of points */ 213 sxo = syo = 0; 214 for (i++; i < object[0].Npts; i++) { 215 if (!(finite(x[i]) && finite(y[i]))) continue; 216 sx1 = x[i]*mxi + y[i]*mxj + bx; 217 sy1 = x[i]*myi + y[i]*myj + by; 218 sx1 = MIN (MAX (sx1, X0), X1); 219 sy1 = MAX (MIN (sy1, Y0), Y1); 220 sxa = 0.5*(sx0 + sx1); 221 DrawLine (buffer, sx0, sy0, sxa, sy0); 222 DrawLine (buffer, sxa, sy0, sxa, sy1); 223 DrawLine (buffer, sxa, sy1, sx1, sy1); 224 sxo = sx0; syo = sy0; 225 sx0 = sx1; sy0 = sy1; 226 } 227 228 /* draw segment equal distance after last point and down to x-axis */ 229 sxa = sx1 + 0.5*(sx1 - sxo); 230 sya = MAX (sy1, Y0); 231 DrawLine (buffer, sx1, sy1, sxa, sy1); 232 DrawLine (buffer, sxa, sy1, sxa, sya); 233 234 # if (0) 181 235 sx0 = x[i]*mxi + y[i]*mxj + bx; 182 236 sy0 = x[i]*myi + y[i]*myj + by; … … 197 251 sx0 = sx1; sy0 = sy1; 198 252 } 253 # endif 199 254 } 200 255 -
branches/czw_branch/20101203/Ohana/src/kapa2/src/hh_hms.c
r13320 r30631 1 1 # include "Ximage.h" 2 2 3 void hh_hms (char *line, double ra, double dec, char sep ) {3 void hh_hms (char *line, double ra, double dec, char sep, int Nchar) { 4 4 5 5 int h, m, flag; … … 13 13 s = 3600*(ra - h - m / 60.0); 14 14 if (flag > 0) 15 s printf (line, " %02d%c%02d%c%04.1f ", h, sep, m, sep, s);15 snprintf (line, Nchar, " %02d%c%02d%c%04.1f ", h, sep, m, sep, s); 16 16 else 17 s printf (line, "-%02d%c%02d%c%04.1f ", h, sep, m, sep, s);17 snprintf (line, Nchar, "-%02d%c%02d%c%04.1f ", h, sep, m, sep, s); 18 18 19 19 flag = SIGN(dec); … … 23 23 s = 3600*(dec - h - m / 60.0); 24 24 if (flag > 0) 25 s printf (&line[13], " %02d%c%02d%c%04.1f", h, sep, m, sep, s);25 snprintf (&line[13], Nchar, " %02d%c%02d%c%04.1f", h, sep, m, sep, s); 26 26 else 27 s printf (&line[13], "-%02d%c%02d%c%04.1f", h, sep, m, sep, s);27 snprintf (&line[13], Nchar, "-%02d%c%02d%c%04.1f", h, sep, m, sep, s); 28 28 } -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-elixir.d
r15034 r30631 43 43 FIELD ccdnum, CCDNUM, unsigned char, CCD ID number 44 44 FIELD dummy, DUMMY, char[20], unused 45 FIELD order, ORDER, short, Mrel 2D polynomical order 46 FIELD Mx, MX, short, Mrel polyterm47 FIELD My, MY, short, Mrel polyterm48 FIELD Mxx, MXX, short, Mrel polyterm49 FIELD Mxy, MXY, short, Mrel polyterm 50 FIELD Myy, MYY, short, Mrel polyterm51 FIELD Mxxx, MXXX, short, Mrel polyterm52 FIELD Mxxy, MXXY, short, Mrel polyterm 53 FIELD Mxyy, MXYY, short, Mrel polyterm54 FIELD Myyy, MYYY, short, Mrel polyterm55 FIELD Mxxxx, MXXXX, short, Mrel polyterm56 FIELD Mxxxy, MXXXY, short, Mrel polyterm 57 FIELD Mxxyy, MXXYY, short, Mrel polyterm58 FIELD Mxyyy, MXYYY, short, Mrel polyterm59 FIELD Myyyy, MYYYY, short, Mrel polyterm 45 46 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 47 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 48 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 49 50 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 51 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 52 53 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 54 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 55 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 56 57 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 58 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 59 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-loneos.d
r15034 r30631 43 43 FIELD ccdnum, CCDNUM, unsigned char, CCD ID number 44 44 FIELD dummy, DUMMY, char[20], unused 45 FIELD order, ORDER, short, Mrel 2D polynomical order 46 FIELD Mx, MX, short, Mrel polyterm47 FIELD My, MY, short, Mrel polyterm48 FIELD Mxx, MXX, short, Mrel polyterm49 FIELD Mxy, MXY, short, Mrel polyterm 50 FIELD Myy, MYY, short, Mrel polyterm51 FIELD Mxxx, MXXX, short, Mrel polyterm52 FIELD Mxxy, MXXY, short, Mrel polyterm 53 FIELD Mxyy, MXYY, short, Mrel polyterm54 FIELD Myyy, MYYY, short, Mrel polyterm55 FIELD Mxxxx, MXXXX, short, Mrel polyterm56 FIELD Mxxxy, MXXXY, short, Mrel polyterm 57 FIELD Mxxyy, MXXYY, short, Mrel polyterm58 FIELD Mxyyy, MXYYY, short, Mrel polyterm59 FIELD Myyyy, MYYYY, short, Mrel polyterm 45 46 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 47 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 48 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 49 50 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 51 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 52 53 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 54 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 55 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 56 57 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 58 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 59 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-panstarrs-dev-0.d
r15034 r30631 53 53 54 54 FIELD dummy, DUMMY, char[10], unused 55 FIELD order, ORDER, short, Mrel 2D polynomical order 56 FIELD Mx, MX, short, Mrel polyterm 57 FIELD My, MY, short, Mrel polyterm 58 FIELD Mxx, MXX, short, Mrel polyterm 59 FIELD Mxy, MXY, short, Mrel polyterm 60 FIELD Myy, MYY, short, Mrel polyterm 61 FIELD Mxxx, MXXX, short, Mrel polyterm 62 FIELD Mxxy, MXXY, short, Mrel polyterm 63 FIELD Mxyy, MXYY, short, Mrel polyterm 64 FIELD Myyy, MYYY, short, Mrel polyterm 65 FIELD Mxxxx, MXXXX, short, Mrel polyterm 66 FIELD Mxxxy, MXXXY, short, Mrel polyterm 67 FIELD Mxxyy, MXXYY, short, Mrel polyterm 68 FIELD Mxyyy, MXYYY, short, Mrel polyterm 69 FIELD Myyyy, MYYYY, short, Mrel polyterm 70 # 40 bytes 55 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 56 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 57 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 58 59 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 60 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 61 62 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 63 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 64 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 65 66 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 67 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 68 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-panstarrs-dev-1.d
r15034 r30631 53 53 54 54 FIELD dummy, DUMMY, char[10], unused 55 FIELD order, ORDER, short, Mrel 2D polynomical order 56 FIELD Mx, MX, short, Mrel polyterm 57 FIELD My, MY, short, Mrel polyterm 58 FIELD Mxx, MXX, short, Mrel polyterm 59 FIELD Mxy, MXY, short, Mrel polyterm 60 FIELD Myy, MYY, short, Mrel polyterm 61 FIELD Mxxx, MXXX, short, Mrel polyterm 62 FIELD Mxxy, MXXY, short, Mrel polyterm 63 FIELD Mxyy, MXYY, short, Mrel polyterm 64 FIELD Myyy, MYYY, short, Mrel polyterm 65 FIELD Mxxxx, MXXXX, short, Mrel polyterm 66 FIELD Mxxxy, MXXXY, short, Mrel polyterm 67 FIELD Mxxyy, MXXYY, short, Mrel polyterm 68 FIELD Mxyyy, MXYYY, short, Mrel polyterm 69 FIELD Myyyy, MYYYY, short, Mrel polyterm 70 # 40 bytes 55 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 56 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 57 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 58 59 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 60 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 61 62 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 63 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 64 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 65 66 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 67 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 68 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-ps1-dev-1.d
r15038 r30631 49 49 FIELD ccdnum, CCDNUM, unsigned char, CCD ID number 50 50 FIELD imageID, IMAGE_ID, unsigned int, image ID 51 FIELD dummy, DUMMY, char[14], unused 51 52 # 44 bytes 52 53 53 FIELD dummy, DUMMY, char[14], unused54 FIELD order, ORDER, short, Mrel 2D polynomical order55 FIELD Mx, MX, short, Mrel polyterm56 FIELD My, MY, short, Mrel polyterm57 FIELD Mxx, MXX, short, Mrel polyterm58 FIELD Mxy, MXY, short, Mrel polyterm59 FIELD Myy, MYY, short, Mrel polyterm60 FIELD Mxxx, MXXX, short, Mrel polyterm61 FIELD Mxxy, MXXY, short, Mrel polyterm62 FIELD Mxyy, MXYY, short, Mrel polyterm63 FIELD Myyy, MYYY, short, Mrel polyterm64 FIELD Mxxxx, MXXXX, short, Mrel polyterm65 FIELD Mxxxy, MXXXY, short, Mrel polyterm66 FIELD Mxxyy, MXXYY, short, Mrel polyterm67 FIELD Mxyyy, MXYYY, short, Mrel polyterm68 FIELD Myyyy, MYYYY, short, Mrel polyterm69 54 # 40 bytes 55 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 56 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 57 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 58 59 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 60 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 61 62 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 63 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 64 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 65 66 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 67 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 68 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-ps1-dev-2.d
r16810 r30631 53 53 # 48 bytes 54 54 55 FIELD order, ORDER, short, Mrel 2D polynomical order 56 FIELD Mx, MX, short, Mrel polyterm 57 FIELD My, MY, short, Mrel polyterm 58 FIELD Mxx, MXX, short, Mrel polyterm 59 FIELD Mxy, MXY, short, Mrel polyterm 60 FIELD Myy, MYY, short, Mrel polyterm 61 FIELD Mxxx, MXXX, short, Mrel polyterm 62 FIELD Mxxy, MXXY, short, Mrel polyterm 63 FIELD Mxyy, MXYY, short, Mrel polyterm 64 FIELD Myyy, MYYY, short, Mrel polyterm 65 FIELD Mxxxx, MXXXX, short, Mrel polyterm 66 FIELD Mxxxy, MXXXY, short, Mrel polyterm 67 FIELD Mxxyy, MXXYY, short, Mrel polyterm 68 FIELD Mxyyy, MXYYY, short, Mrel polyterm 69 FIELD Myyyy, MYYYY, short, Mrel polyterm 70 # 40 bytes 55 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 56 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 57 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 58 59 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 60 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 61 62 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 63 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 64 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 65 66 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 67 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 68 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-ps1-dev-3.d
r20362 r30631 54 54 # 48 bytes 55 55 56 FIELD order, ORDER, short, Mrel 2D polynomical order 57 FIELD Mx, MX, short, Mrel polyterm 58 FIELD My, MY, short, Mrel polyterm 59 FIELD Mxx, MXX, short, Mrel polyterm 60 FIELD Mxy, MXY, short, Mrel polyterm 61 FIELD Myy, MYY, short, Mrel polyterm 62 FIELD Mxxx, MXXX, short, Mrel polyterm 63 FIELD Mxxy, MXXY, short, Mrel polyterm 64 FIELD Mxyy, MXYY, short, Mrel polyterm 65 FIELD Myyy, MYYY, short, Mrel polyterm 66 FIELD Mxxxx, MXXXX, short, Mrel polyterm 67 FIELD Mxxxy, MXXXY, short, Mrel polyterm 68 FIELD Mxxyy, MXXYY, short, Mrel polyterm 69 FIELD Mxyyy, MXYYY, short, Mrel polyterm 70 FIELD Myyyy, MYYYY, short, Mrel polyterm 71 # 40 bytes 56 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 57 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 58 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 59 60 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 61 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 62 63 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 64 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 65 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 66 67 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 68 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 69 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-ps1-ref.d
r24746 r30631 55 55 # 48 bytes 56 56 57 FIELD order, ORDER, short, Mrel 2D polynomical order58 FIELD Mx, MX, short, Mrel polyterm59 FIELD My, MY, short, Mrel polyterm60 FIELD Mxx, MXX, short, Mrel polyterm61 FIELD Mxy, MXY, short, Mrel polyterm62 FIELD Myy, MYY, short, Mrel polyterm63 FIELD Mxxx, MXXX, short, Mrel polyterm64 FIELD Mxxy, MXXY, short, Mrel polyterm65 FIELD Mxyy, MXYY, short, Mrel polyterm66 FIELD Myyy, MYYY, short, Mrel polyterm67 FIELD Mxxxx, MXXXX, short, Mrel polyterm68 FIELD Mxxxy, MXXXY, short, Mrel polyterm69 FIELD Mxxyy, MXXYY, short, Mrel polyterm70 FIELD Mxyyy, MXYYY, short, Mrel polyterm71 FIELD Myyyy, MYYYY, short, Mrel polyterm72 57 # 40 bytes 58 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 59 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 60 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 61 62 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 63 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 64 65 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 66 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 67 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 68 69 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 70 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 71 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases 72 -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-ps1-v1.d
r21508 r30631 55 55 # 48 bytes 56 56 57 FIELD order, ORDER, short, Mrel 2D polynomical order 58 FIELD Mx, MX, short, Mrel polyterm 59 FIELD My, MY, short, Mrel polyterm 60 FIELD Mxx, MXX, short, Mrel polyterm 61 FIELD Mxy, MXY, short, Mrel polyterm 62 FIELD Myy, MYY, short, Mrel polyterm 63 FIELD Mxxx, MXXX, short, Mrel polyterm 64 FIELD Mxxy, MXXY, short, Mrel polyterm 65 FIELD Mxyy, MXYY, short, Mrel polyterm 66 FIELD Myyy, MYYY, short, Mrel polyterm 67 FIELD Mxxxx, MXXXX, short, Mrel polyterm 68 FIELD Mxxxy, MXXXY, short, Mrel polyterm 69 FIELD Mxxyy, MXXYY, short, Mrel polyterm 70 FIELD Mxyyy, MXYYY, short, Mrel polyterm 71 FIELD Myyyy, MYYYY, short, Mrel polyterm 72 # 40 bytes 57 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 58 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 59 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 60 61 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 62 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 63 64 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 65 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 66 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 67 68 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 69 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 70 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image-ps1-v2.d
r27579 r30631 60 60 # 48 bytes 61 61 62 FIELD order, ORDER, short, Mrel 2D polynomical order 63 FIELD Mx, MX, short, Mrel polyterm 64 FIELD My, MY, short, Mrel polyterm 65 FIELD Mxx, MXX, short, Mrel polyterm 66 FIELD Mxy, MXY, short, Mrel polyterm 67 FIELD Myy, MYY, short, Mrel polyterm 68 FIELD Mxxx, MXXX, short, Mrel polyterm 69 FIELD Mxxy, MXXY, short, Mrel polyterm 70 FIELD Mxyy, MXYY, short, Mrel polyterm 71 FIELD Myyy, MYYY, short, Mrel polyterm 72 FIELD Mxxxx, MXXXX, short, Mrel polyterm 73 FIELD Mxxxy, MXXXY, short, Mrel polyterm 74 FIELD Mxxyy, MXXYY, short, Mrel polyterm 75 FIELD Mxyyy, MXYYY, short, Mrel polyterm 76 FIELD Myyyy, MYYYY, short, Mrel polyterm 77 # 40 bytes 62 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 63 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 64 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 65 66 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 67 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 68 69 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 70 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 71 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 72 73 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 74 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 75 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases -
branches/czw_branch/20101203/Ohana/src/libautocode/def/image.d
r27579 r30631 1 STRUCT Image1 STRUCT Image 2 2 EXTNAME DVO_IMAGE 3 3 TYPE BINTABLE … … 6 6 7 7 # elements of the image structure 8 # careful of 8-byte boundaries 8 9 9 10 SUBSTRUCT coords, COORDS, Coords, astrometric data … … 60 61 # 48 bytes 61 62 62 FIELD order, ORDER, short, Mrel 2D polynomical order 63 FIELD Mx, MX, short, Mrel polyterm 64 FIELD My, MY, short, Mrel polyterm 65 FIELD Mxx, MXX, short, Mrel polyterm 66 FIELD Mxy, MXY, short, Mrel polyterm 67 FIELD Myy, MYY, short, Mrel polyterm 68 FIELD Mxxx, MXXX, short, Mrel polyterm 69 FIELD Mxxy, MXXY, short, Mrel polyterm 70 FIELD Mxyy, MXYY, short, Mrel polyterm 71 FIELD Myyy, MYYY, short, Mrel polyterm 72 FIELD Mxxxx, MXXXX, short, Mrel polyterm 73 FIELD Mxxxy, MXXXY, short, Mrel polyterm 74 FIELD Mxxyy, MXXYY, short, Mrel polyterm 75 FIELD Mxyyy, MXYYY, short, Mrel polyterm 76 FIELD Myyyy, MYYYY, short, Mrel polyterm 63 FIELD nLinkAstrom, NLINK_ASTROM, short, mean number of matched measurements for astrometry 64 FIELD nLinkPhotom, NLINK_PHOTOM, short, mean number of matched measurements for astrometry 65 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 66 67 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 68 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 69 70 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 71 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 72 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 73 74 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 75 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 76 # nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases 77 78 # old image structure: 79 # FIELD order, ORDER, short, Mrel 2D polynomical order 80 # FIELD Mx, MX, short, Mrel polyterm 81 # FIELD My, MY, short, Mrel polyterm 82 # FIELD Mxx, MXX, short, Mrel polyterm 83 # FIELD Mxy, MXY, short, Mrel polyterm 84 # FIELD Myy, MYY, short, Mrel polyterm 85 # FIELD Mxxx, MXXX, short, Mrel polyterm 86 # FIELD Mxxy, MXXY, short, Mrel polyterm 87 # FIELD Mxyy, MXYY, short, Mrel polyterm 88 # FIELD Myyy, MYYY, short, Mrel polyterm 89 # FIELD Mxxxx, MXXXX, short, Mrel polyterm 90 # FIELD Mxxxy, MXXXY, short, Mrel polyterm 91 # FIELD Mxxyy, MXXYY, short, Mrel polyterm 92 # FIELD Mxyyy, MXYYY, short, Mrel polyterm 93 # FIELD Myyyy, MYYYY, short, Mrel polyterm 77 94 # 40 bytes 78 95 79 96 # *** 20090206 : new fields : parentID, flags (was code char), changed name to 121 bytes. 80 # *** 20100331 : new fields : 97 # *** 20100331 : new fields : RAo, DECo. Radius 98 # *** 20110203 : replace the old zero point polynomial terms (Mx,My,... Mxxxx,Myyyy) with dummy1 - astrom_map_id -
branches/czw_branch/20101203/Ohana/src/libautocode/def/measure-ps1-v2.d
r27579 r30631 63 63 FIELD dXccd, X_CCD_ERR, short, X coord error on chip, 1/100 of pixels 64 64 FIELD dYccd, Y_CCD_ERR, short, Y coord error on chip, 1/100 of pixels 65 FIELD dRsys, POS_SYS_ERR, short, systematic error from astrom, 1/100 of pixels 65 66 66 FIELD pad, PAD, char[ 6], padding67 FIELD pad, PAD, char[4], padding 67 68 68 69 # local astrometry scales -
branches/czw_branch/20101203/Ohana/src/libautocode/def/measure.d
r21508 r30631 2 2 EXTNAME DVO_MEASURE 3 3 TYPE BINTABLE 4 SIZE 14 64 SIZE 148 5 5 DESCRIPTION DVO Detection Measurement Table 6 6 … … 59 59 FIELD dXccd, X_CCD_ERR, short, X coord error on chip, 1/100 of pixels 60 60 FIELD dYccd, Y_CCD_ERR, short, Y coord error on chip, 1/100 of pixels 61 FIELD dRsys, POS_SYS_ERR, short, systematic error from astrom, 1/100 of pixels 61 62 62 63 FIELD posangle, POSANGLE, short, position angle sky to chip, (0xffff/360) deg -
branches/czw_branch/20101203/Ohana/src/libdvo/Makefile
r27580 r30631 51 51 $(SRC)/mosaic_astrom.$(ARCH).o \ 52 52 $(SRC)/fits_db.$(ARCH).o \ 53 $(SRC)/photfits.$(ARCH).o \54 53 $(SRC)/dvo_image.$(ARCH).o \ 55 54 $(SRC)/dvo_image_raw.$(ARCH).o \ … … 77 76 $(SRC)/dvo_util.$(ARCH).o 78 77 79 # $(SRC)/dvo_convert_panstarrs.$(ARCH).o \ 80 # $(SRC)/dvo_convert_pmtest.$(ARCH).o \ 78 # $(SRC)/dvo_convert_panstarrs.$(ARCH).o 79 # $(SRC)/dvo_convert_pmtest.$(ARCH).o 80 # $(SRC)/photfits.$(ARCH).o 81 81 82 82 include ../libautocode/Makefile.Targets -
branches/czw_branch/20101203/Ohana/src/libdvo/doc/dvo-images.txt
r15240 r30631 1 1 2 the dvo image table is not extremely efficient. it is unsorted, and 3 spatial searches consist of complete scans of the table. 2 20110203 4 3 5 a spatial index could consist of five cardinal points for each square 6 image (4 corners and the center) or a central point and max radius. 7 table would consist each would be 4 The Image table (PS1_V2) has a bunch of fields that are not really 5 used by anything / much. I would like to re-use those bytes to 6 store information about the quality of the astrometric and 7 photometric calibrations. 8 9 The under-used fields are the 'photometric zero point variation' 10 polynomial terms (Mx, My, ... Mxxxx, Myyyy). 11 12 (I list the sourceID, which does not change, because the word-boundaries matter) 13 FIELD sourceID, SOURCE_ID, unsigned short, analysis source ID 14 FIELD order, ORDER, short, Mrel 2D polynomical order 15 FIELD Mx, MX, short, Mrel polyterm 16 FIELD My, MY, short, Mrel polyterm 17 18 FIELD Mxx, MXX, short, Mrel polyterm 19 FIELD Mxy, MXY, short, Mrel polyterm 20 FIELD Myy, MYY, short, Mrel polyterm 21 FIELD Mxxx, MXXX, short, Mrel polyterm 22 23 FIELD Mxxy, MXXY, short, Mrel polyterm 24 FIELD Mxyy, MXYY, short, Mrel polyterm 25 FIELD Myyy, MYYY, short, Mrel polyterm 26 FIELD Mxxxx, MXXXX, short, Mrel polyterm 27 28 FIELD Mxxxy, MXXXY, short, Mrel polyterm 29 FIELD Mxxyy, MXXYY, short, Mrel polyterm 30 FIELD Mxyyy, MXYYY, short, Mrel polyterm 31 FIELD Myyyy, MYYYY, short, Mrel polyterm 32 (30 bytes) 33 34 I am going to replace these with: 35 36 photom_map_id (int) : index to a 2D map of the zp variations (table and format not yet defined) 37 astrom_map_id (int) : index to a 2D map of the zp variations (table and format not yet defined) 38 dMagSys (float) : systematic photometric error (mag) 39 dXpixSys (float) : systematic astrometric error (pix) 40 dYpixSys (float) : systematic astrometric error (pix) 41 nFitAstrom (short) : number of stars used for astrometric calibration (saturate at 0x7fff) 42 nFitPhotom (short) : number of stars used for astrometric calibration (saturate at 0x7fff) 43 (24 bytes) 44 45 As for the existing uses of these fields: 46 47 The official use can just be dropped (replaced by the maps and 48 recalculated if needed -- no db actually uses them). There are a 49 few places in the code where these fields were overloaded: 50 51 Triangular Images : in the skycell creation code, there is an option 52 to create images which are the triangular projection centers for a 53 given subdivided geometric solid. This code was overloading the Mx, 54 My, and Mxxx through Myyy fields. I can invalidate any existing db 55 with triangles (probably none are needed) and repurpose some of the 56 fields above for these values. (addstar/src/sky_tesslation.c, opihi/dvo/images.c) 57 58 Mxxxx : some code was using Mxxxx to store nFitPhotom. Again, any 59 existing databases are unlikely to use that info (CFHT skyprobe 60 only). If I am clever, I can align the existing bytes so that the 61 old Mxxxx hits the new nFitPhotom. (addstar/src/calibrate.c, 62 dbExtractImages.c) 63 64 Myyyy : dbExtractImages.c expects this value to have (sky - 0x8000), 65 but that value is not actually set by any code. Ignore (replace?) 66 67 FIELD sourceID, SOURCE_ID, unsigned short, analysis source ID 68 FIELD dummy1, DUMMY1, short, place holder for byte boundaries 69 FIELD dummy2, DUMMY2, short, place holder for byte boundaries 70 FIELD dummy3, DUMMY3, short, place holder for byte boundaries 71 72 FIELD dXpixSys, XPIX_SYS_ERR, float, systematic astrometry error in X 73 FIELD dYpixSys, YPIX_SYS_ERR, float, systematic astrometry error in Y 74 75 FIELD dMagSys, MAG_SYS_ERR, float, systematic photometry error 76 FIELD nFitAstrom, N_FIT_ASTROM, short, number of stars used for astrometry cal 77 FIELD nFitPhotom, N_FIT_PHOTOM, short, number of stars used for photometry cal 78 79 FIELD photom_map_id, PHOTOM_MAP_ID, unsigned int, reference to 2D zero point map 80 FIELD astrom_map_id, ASTROM_MAP_ID, unsigned int, reference to 2D astrometry map 81 82 older: 83 84 the dvo image table is not extremely efficient. it is unsorted, and 85 spatial searches consist of complete scans of the table. 86 87 a spatial index could consist of five cardinal points for each 88 square image (4 corners and the center) or a central point and max 89 radius. 90 -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
r27580 r30631 8 8 Measure *out; 9 9 10 ALLOCATE (out, Measure, Nvalues);10 ALLOCATE_ZERO (out, Measure, Nvalues); 11 11 12 12 for (i = 0; i < Nvalues; i++) { … … 66 66 Measure_PS1_DEV_1 *out; 67 67 68 ALLOCATE (out, Measure_PS1_DEV_1, Nvalues);68 ALLOCATE_ZERO (out, Measure_PS1_DEV_1, Nvalues); 69 69 70 70 for (i = 0; i < Nvalues; i++) { … … 113 113 Average *out; 114 114 115 ALLOCATE (out, Average, Nvalues);115 ALLOCATE_ZERO (out, Average, Nvalues); 116 116 117 117 for (i = 0; i < Nvalues; i++) { … … 157 157 Average_PS1_DEV_1 *out; 158 158 159 ALLOCATE (out, Average_PS1_DEV_1, Nvalues);159 ALLOCATE_ZERO (out, Average_PS1_DEV_1, Nvalues); 160 160 161 161 for (i = 0; i < Nvalues; i++) { … … 191 191 SecFilt *out; 192 192 193 ALLOCATE (out, SecFilt, Nvalues);193 ALLOCATE_ZERO (out, SecFilt, Nvalues); 194 194 195 195 for (i = 0; i < Nvalues; i++) { … … 215 215 SecFilt_PS1_DEV_1 *out; 216 216 217 ALLOCATE (out, SecFilt_PS1_DEV_1, Nvalues);217 ALLOCATE_ZERO (out, SecFilt_PS1_DEV_1, Nvalues); 218 218 219 219 for (i = 0; i < Nvalues; i++) { … … 232 232 Image *out; 233 233 234 ALLOCATE (out, Image, Nvalues);234 ALLOCATE_ZERO (out, Image, Nvalues); 235 235 236 236 for (i = 0; i < Nvalues; i++) { … … 263 263 out[i].imageID = in[i].imageID; 264 264 265 out[i].order = in[i].order; 266 out[i].Mx = in[i].Mx; 267 out[i].My = in[i].My; 268 out[i].Mxx = in[i].Mxx; 269 out[i].Mxy = in[i].Mxy; 270 out[i].Myy = in[i].Myy; 271 out[i].Mxxx = in[i].Mxxx; 272 out[i].Mxxy = in[i].Mxxy; 273 out[i].Mxyy = in[i].Mxyy; 274 out[i].Myyy = in[i].Myyy; 275 out[i].Mxxxx = in[i].Mxxxx; 276 out[i].Mxxxy = in[i].Mxxxy; 277 out[i].Mxxyy = in[i].Mxxyy; 278 out[i].Mxyyy = in[i].Mxyyy; 279 out[i].Myyyy = in[i].Myyyy; 265 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 266 // with the following. (no real databases used those values -- see 267 // libdvo/doc/dvo-images.txt) 268 out[i].nLinkAstrom = in[i].nLinkAstrom; 269 out[i].nLinkPhotom = in[i].nLinkPhotom; 270 out[i].dummy3 = in[i].dummy3; 271 out[i].dXpixSys = in[i].dXpixSys; 272 out[i].dYpixSys = in[i].dYpixSys; 273 out[i].dMagSys = in[i].dMagSys; 274 out[i].nFitAstrom = in[i].nFitAstrom; 275 out[i].nFitPhotom = in[i].nFitPhotom; 276 out[i].photom_map_id = in[i].photom_map_id; 277 out[i].astrom_map_id = in[i].astrom_map_id; 280 278 281 279 // changed or added for PS1_DEV_2 … … 301 299 Image_PS1_DEV_1 *out; 302 300 303 ALLOCATE (out, Image_PS1_DEV_1, Nvalues);301 ALLOCATE_ZERO (out, Image_PS1_DEV_1, Nvalues); 304 302 305 303 for (i = 0; i < Nvalues; i++) { … … 332 330 out[i].imageID = in[i].imageID; 333 331 334 out[i].order = in[i].order; 335 out[i].Mx = in[i].Mx; 336 out[i].My = in[i].My; 337 out[i].Mxx = in[i].Mxx; 338 out[i].Mxy = in[i].Mxy; 339 out[i].Myy = in[i].Myy; 340 out[i].Mxxx = in[i].Mxxx; 341 out[i].Mxxy = in[i].Mxxy; 342 out[i].Mxyy = in[i].Mxyy; 343 out[i].Myyy = in[i].Myyy; 344 out[i].Mxxxx = in[i].Mxxxx; 345 out[i].Mxxxy = in[i].Mxxxy; 346 out[i].Mxxyy = in[i].Mxxyy; 347 out[i].Mxyyy = in[i].Mxyyy; 348 out[i].Myyyy = in[i].Myyyy; 332 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 333 // with the following. (no real databases used those values -- see 334 // libdvo/doc/dvo-images.txt) 335 out[i].nLinkAstrom = in[i].nLinkAstrom; 336 out[i].nLinkPhotom = in[i].nLinkPhotom; 337 out[i].dummy3 = in[i].dummy3; 338 out[i].dXpixSys = in[i].dXpixSys; 339 out[i].dYpixSys = in[i].dYpixSys; 340 out[i].dMagSys = in[i].dMagSys; 341 out[i].nFitAstrom = in[i].nFitAstrom; 342 out[i].nFitPhotom = in[i].nFitPhotom; 343 out[i].photom_map_id = in[i].photom_map_id; 344 out[i].astrom_map_id = in[i].astrom_map_id; 349 345 350 346 // changed or added for PS1_V1 … … 359 355 PhotCode *out; 360 356 361 ALLOCATE (out, PhotCode, Nvalues);357 ALLOCATE_ZERO (out, PhotCode, Nvalues); 362 358 363 359 for (i = 0; i < Nvalues; i++) { … … 398 394 PhotCode_PS1_DEV_1 *out; 399 395 400 ALLOCATE (out, PhotCode_PS1_DEV_1, Nvalues);396 ALLOCATE_ZERO (out, PhotCode_PS1_DEV_1, Nvalues); 401 397 402 398 for (i = 0; i < Nvalues; i++) { -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
r27580 r30631 8 8 Measure *out; 9 9 10 ALLOCATE (out, Measure, Nvalues);10 ALLOCATE_ZERO (out, Measure, Nvalues); 11 11 12 12 for (i = 0; i < Nvalues; i++) { … … 63 63 Measure_PS1_DEV_2 *out; 64 64 65 ALLOCATE (out, Measure_PS1_DEV_2, Nvalues);65 ALLOCATE_ZERO (out, Measure_PS1_DEV_2, Nvalues); 66 66 67 67 for (i = 0; i < Nvalues; i++) { … … 109 109 Average *out; 110 110 111 ALLOCATE (out, Average, Nvalues);111 ALLOCATE_ZERO (out, Average, Nvalues); 112 112 113 113 for (i = 0; i < Nvalues; i++) { … … 151 151 Average_PS1_DEV_2 *out; 152 152 153 ALLOCATE (out, Average_PS1_DEV_2, Nvalues);153 ALLOCATE_ZERO (out, Average_PS1_DEV_2, Nvalues); 154 154 155 155 for (i = 0; i < Nvalues; i++) { … … 185 185 SecFilt *out; 186 186 187 ALLOCATE (out, SecFilt, Nvalues);187 ALLOCATE_ZERO (out, SecFilt, Nvalues); 188 188 189 189 for (i = 0; i < Nvalues; i++) { … … 209 209 SecFilt_PS1_DEV_2 *out; 210 210 211 ALLOCATE (out, SecFilt_PS1_DEV_2, Nvalues);211 ALLOCATE_ZERO (out, SecFilt_PS1_DEV_2, Nvalues); 212 212 213 213 for (i = 0; i < Nvalues; i++) { … … 226 226 Image *out; 227 227 228 ALLOCATE (out, Image, Nvalues);228 ALLOCATE_ZERO (out, Image, Nvalues); 229 229 230 230 for (i = 0; i < Nvalues; i++) { … … 259 259 out[i].sourceID = in[i].sourceID; 260 260 261 out[i].order = in[i].order; 262 out[i].Mx = in[i].Mx; 263 out[i].My = in[i].My; 264 out[i].Mxx = in[i].Mxx; 265 out[i].Mxy = in[i].Mxy; 266 out[i].Myy = in[i].Myy; 267 out[i].Mxxx = in[i].Mxxx; 268 out[i].Mxxy = in[i].Mxxy; 269 out[i].Mxyy = in[i].Mxyy; 270 out[i].Myyy = in[i].Myyy; 271 out[i].Mxxxx = in[i].Mxxxx; 272 out[i].Mxxxy = in[i].Mxxxy; 273 out[i].Mxxyy = in[i].Mxxyy; 274 out[i].Mxyyy = in[i].Mxyyy; 275 out[i].Myyyy = in[i].Myyyy; 261 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 262 // with the following. (no real databases used those values -- see 263 // libdvo/doc/dvo-images.txt) 264 out[i].nLinkAstrom = in[i].nLinkAstrom; 265 out[i].nLinkPhotom = in[i].nLinkPhotom; 266 out[i].dummy3 = in[i].dummy3; 267 out[i].dXpixSys = in[i].dXpixSys; 268 out[i].dYpixSys = in[i].dYpixSys; 269 out[i].dMagSys = in[i].dMagSys; 270 out[i].nFitAstrom = in[i].nFitAstrom; 271 out[i].nFitPhotom = in[i].nFitPhotom; 272 out[i].photom_map_id = in[i].photom_map_id; 273 out[i].astrom_map_id = in[i].astrom_map_id; 276 274 277 275 // changed or added for PS1_V1 … … 292 290 Image_PS1_DEV_2 *out; 293 291 294 ALLOCATE (out, Image_PS1_DEV_2, Nvalues);292 ALLOCATE_ZERO (out, Image_PS1_DEV_2, Nvalues); 295 293 296 294 for (i = 0; i < Nvalues; i++) { … … 326 324 out[i].sourceID = in[i].sourceID; 327 325 328 out[i].order = in[i].order; 329 out[i].Mx = in[i].Mx; 330 out[i].My = in[i].My; 331 out[i].Mxx = in[i].Mxx; 332 out[i].Mxy = in[i].Mxy; 333 out[i].Myy = in[i].Myy; 334 out[i].Mxxx = in[i].Mxxx; 335 out[i].Mxxy = in[i].Mxxy; 336 out[i].Mxyy = in[i].Mxyy; 337 out[i].Myyy = in[i].Myyy; 338 out[i].Mxxxx = in[i].Mxxxx; 339 out[i].Mxxxy = in[i].Mxxxy; 340 out[i].Mxxyy = in[i].Mxxyy; 341 out[i].Mxyyy = in[i].Mxyyy; 342 out[i].Myyyy = in[i].Myyyy; 326 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 327 // with the following. (no real databases used those values -- see 328 // libdvo/doc/dvo-images.txt) 329 out[i].nLinkAstrom = in[i].nLinkAstrom; 330 out[i].nLinkPhotom = in[i].nLinkPhotom; 331 out[i].dummy3 = in[i].dummy3; 332 out[i].dXpixSys = in[i].dXpixSys; 333 out[i].dYpixSys = in[i].dYpixSys; 334 out[i].dMagSys = in[i].dMagSys; 335 out[i].nFitAstrom = in[i].nFitAstrom; 336 out[i].nFitPhotom = in[i].nFitPhotom; 337 out[i].photom_map_id = in[i].photom_map_id; 338 out[i].astrom_map_id = in[i].astrom_map_id; 343 339 344 340 // changed or added for PS1_V1 … … 353 349 PhotCode *out; 354 350 355 ALLOCATE (out, PhotCode, Nvalues);351 ALLOCATE_ZERO (out, PhotCode, Nvalues); 356 352 357 353 for (i = 0; i < Nvalues; i++) { … … 390 386 PhotCode_PS1_DEV_2 *out; 391 387 392 ALLOCATE (out, PhotCode_PS1_DEV_2, Nvalues);388 ALLOCATE_ZERO (out, PhotCode_PS1_DEV_2, Nvalues); 393 389 394 390 for (i = 0; i < Nvalues; i++) { -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c
r27491 r30631 10 10 Image *out; 11 11 12 ALLOCATE (out, Image, Nvalues);12 ALLOCATE_ZERO (out, Image, Nvalues); 13 13 14 14 for (i = 0; i < Nvalues; i++) { … … 43 43 out[i].sourceID = in[i].sourceID; 44 44 45 out[i].order = in[i].order; 46 out[i].Mx = in[i].Mx; 47 out[i].My = in[i].My; 48 out[i].Mxx = in[i].Mxx; 49 out[i].Mxy = in[i].Mxy; 50 out[i].Myy = in[i].Myy; 51 out[i].Mxxx = in[i].Mxxx; 52 out[i].Mxxy = in[i].Mxxy; 53 out[i].Mxyy = in[i].Mxyy; 54 out[i].Myyy = in[i].Myyy; 55 out[i].Mxxxx = in[i].Mxxxx; 56 out[i].Mxxxy = in[i].Mxxxy; 57 out[i].Mxxyy = in[i].Mxxyy; 58 out[i].Mxyyy = in[i].Mxyyy; 59 out[i].Myyyy = in[i].Myyyy; 45 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 46 // with the following. (no real databases used those values -- see 47 // libdvo/doc/dvo-images.txt) 48 out[i].nLinkAstrom = in[i].nLinkAstrom; 49 out[i].nLinkPhotom = in[i].nLinkPhotom; 50 out[i].dummy3 = in[i].dummy3; 51 out[i].dXpixSys = in[i].dXpixSys; 52 out[i].dYpixSys = in[i].dYpixSys; 53 out[i].dMagSys = in[i].dMagSys; 54 out[i].nFitAstrom = in[i].nFitAstrom; 55 out[i].nFitPhotom = in[i].nFitPhotom; 56 out[i].photom_map_id = in[i].photom_map_id; 57 out[i].astrom_map_id = in[i].astrom_map_id; 60 58 61 59 // changed or added for PS1_V1 … … 71 69 Image_PS1_DEV_3 *out; 72 70 73 ALLOCATE (out, Image_PS1_DEV_3, Nvalues);71 ALLOCATE_ZERO (out, Image_PS1_DEV_3, Nvalues); 74 72 75 73 for (i = 0; i < Nvalues; i++) { … … 104 102 out[i].sourceID = in[i].sourceID; 105 103 106 out[i].order = in[i].order; 107 out[i].Mx = in[i].Mx; 108 out[i].My = in[i].My; 109 out[i].Mxx = in[i].Mxx; 110 out[i].Mxy = in[i].Mxy; 111 out[i].Myy = in[i].Myy; 112 out[i].Mxxx = in[i].Mxxx; 113 out[i].Mxxy = in[i].Mxxy; 114 out[i].Mxyy = in[i].Mxyy; 115 out[i].Myyy = in[i].Myyy; 116 out[i].Mxxxx = in[i].Mxxxx; 117 out[i].Mxxxy = in[i].Mxxxy; 118 out[i].Mxxyy = in[i].Mxxyy; 119 out[i].Mxyyy = in[i].Mxyyy; 120 out[i].Myyyy = in[i].Myyyy; 104 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 105 // with the following. (no real databases used those values -- see 106 // libdvo/doc/dvo-images.txt) 107 out[i].nLinkAstrom = in[i].nLinkAstrom; 108 out[i].nLinkPhotom = in[i].nLinkPhotom; 109 out[i].dummy3 = in[i].dummy3; 110 out[i].dXpixSys = in[i].dXpixSys; 111 out[i].dYpixSys = in[i].dYpixSys; 112 out[i].dMagSys = in[i].dMagSys; 113 out[i].nFitAstrom = in[i].nFitAstrom; 114 out[i].nFitPhotom = in[i].nFitPhotom; 115 out[i].photom_map_id = in[i].photom_map_id; 116 out[i].astrom_map_id = in[i].astrom_map_id; 121 117 122 118 // changed or added for PS1_V1 … … 131 127 PhotCode *out; 132 128 133 ALLOCATE (out, PhotCode, Nvalues);129 ALLOCATE_ZERO (out, PhotCode, Nvalues); 134 130 135 131 for (i = 0; i < Nvalues; i++) { … … 167 163 PhotCode_PS1_DEV_3 *out; 168 164 169 ALLOCATE (out, PhotCode_PS1_DEV_3, Nvalues);165 ALLOCATE_ZERO (out, PhotCode_PS1_DEV_3, Nvalues); 170 166 171 167 for (i = 0; i < Nvalues; i++) { -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c
r27580 r30631 8 8 Measure *out; 9 9 10 ALLOCATE (out, Measure, Nvalues);10 ALLOCATE_ZERO (out, Measure, Nvalues); 11 11 12 12 for (i = 0; i < Nvalues; i++) { … … 61 61 Measure_PS1_REF *out; 62 62 63 ALLOCATE (out, Measure_PS1_REF, Nvalues);63 ALLOCATE_ZERO (out, Measure_PS1_REF, Nvalues); 64 64 65 65 for (i = 0; i < Nvalues; i++) { … … 84 84 Average *out; 85 85 86 ALLOCATE (out, Average, Nvalues);86 ALLOCATE_ZERO (out, Average, Nvalues); 87 87 88 88 for (i = 0; i < Nvalues; i++) { … … 124 124 Average_PS1_REF *out; 125 125 126 ALLOCATE (out, Average_PS1_REF, Nvalues);126 ALLOCATE_ZERO (out, Average_PS1_REF, Nvalues); 127 127 128 128 for (i = 0; i < Nvalues; i++) { … … 147 147 SecFilt *out; 148 148 149 ALLOCATE (out, SecFilt, Nvalues);149 ALLOCATE_ZERO (out, SecFilt, Nvalues); 150 150 151 151 for (i = 0; i < Nvalues; i++) { … … 169 169 SecFilt_PS1_REF *out; 170 170 171 ALLOCATE (out, SecFilt_PS1_REF, Nvalues);171 ALLOCATE_ZERO (out, SecFilt_PS1_REF, Nvalues); 172 172 173 173 for (i = 0; i < Nvalues; i++) { … … 183 183 Image *out; 184 184 185 ALLOCATE (out, Image, Nvalues);185 ALLOCATE_ZERO (out, Image, Nvalues); 186 186 187 187 for (i = 0; i < Nvalues; i++) { … … 218 218 out[i].sourceID = in[i].sourceID; 219 219 220 out[i].order = in[i].order; 221 out[i].Mx = in[i].Mx; 222 out[i].My = in[i].My; 223 out[i].Mxx = in[i].Mxx; 224 out[i].Mxy = in[i].Mxy; 225 out[i].Myy = in[i].Myy; 226 out[i].Mxxx = in[i].Mxxx; 227 out[i].Mxxy = in[i].Mxxy; 228 out[i].Mxyy = in[i].Mxyy; 229 out[i].Myyy = in[i].Myyy; 230 out[i].Mxxxx = in[i].Mxxxx; 231 out[i].Mxxxy = in[i].Mxxxy; 232 out[i].Mxxyy = in[i].Mxxyy; 233 out[i].Mxyyy = in[i].Mxyyy; 234 out[i].Myyyy = in[i].Myyyy; 220 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 221 // with the following. (no real databases used those values -- see 222 // libdvo/doc/dvo-images.txt) 223 out[i].nLinkAstrom = in[i].nLinkAstrom; 224 out[i].nLinkPhotom = in[i].nLinkPhotom; 225 out[i].dummy3 = in[i].dummy3; 226 out[i].dXpixSys = in[i].dXpixSys; 227 out[i].dYpixSys = in[i].dYpixSys; 228 out[i].dMagSys = in[i].dMagSys; 229 out[i].nFitAstrom = in[i].nFitAstrom; 230 out[i].nFitPhotom = in[i].nFitPhotom; 231 out[i].photom_map_id = in[i].photom_map_id; 232 out[i].astrom_map_id = in[i].astrom_map_id; 235 233 236 234 // changed or added for PS1_V2 … … 247 245 Image_PS1_REF *out; 248 246 249 ALLOCATE (out, Image_PS1_REF, Nvalues);247 ALLOCATE_ZERO (out, Image_PS1_REF, Nvalues); 250 248 251 249 for (i = 0; i < Nvalues; i++) { … … 282 280 out[i].sourceID = in[i].sourceID; 283 281 284 out[i].order = in[i].order; 285 out[i].Mx = in[i].Mx; 286 out[i].My = in[i].My; 287 out[i].Mxx = in[i].Mxx; 288 out[i].Mxy = in[i].Mxy; 289 out[i].Myy = in[i].Myy; 290 out[i].Mxxx = in[i].Mxxx; 291 out[i].Mxxy = in[i].Mxxy; 292 out[i].Mxyy = in[i].Mxyy; 293 out[i].Myyy = in[i].Myyy; 294 out[i].Mxxxx = in[i].Mxxxx; 295 out[i].Mxxxy = in[i].Mxxxy; 296 out[i].Mxxyy = in[i].Mxxyy; 297 out[i].Mxyyy = in[i].Mxyyy; 298 out[i].Myyyy = in[i].Myyyy; 282 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 283 // with the following. (no real databases used those values -- see 284 // libdvo/doc/dvo-images.txt) 285 out[i].nLinkAstrom = in[i].nLinkAstrom; 286 out[i].nLinkPhotom = in[i].nLinkPhotom; 287 out[i].dummy3 = in[i].dummy3; 288 out[i].dXpixSys = in[i].dXpixSys; 289 out[i].dYpixSys = in[i].dYpixSys; 290 out[i].dMagSys = in[i].dMagSys; 291 out[i].nFitAstrom = in[i].nFitAstrom; 292 out[i].nFitPhotom = in[i].nFitPhotom; 293 out[i].photom_map_id = in[i].photom_map_id; 294 out[i].astrom_map_id = in[i].astrom_map_id; 299 295 } 300 296 return (out); … … 306 302 PhotCode *out; 307 303 308 ALLOCATE (out, PhotCode, Nvalues);304 ALLOCATE_ZERO (out, PhotCode, Nvalues); 309 305 310 306 for (i = 0; i < Nvalues; i++) { … … 342 338 PhotCode_PS1_REF *out; 343 339 344 ALLOCATE (out, PhotCode_PS1_REF, Nvalues);340 ALLOCATE_ZERO (out, PhotCode_PS1_REF, Nvalues); 345 341 346 342 for (i = 0; i < Nvalues; i++) { -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
r27580 r30631 8 8 Measure *out; 9 9 10 ALLOCATE (out, Measure, Nvalues);10 ALLOCATE_ZERO (out, Measure, Nvalues); 11 11 12 12 for (i = 0; i < Nvalues; i++) { … … 61 61 Measure_PS1_V1 *out; 62 62 63 ALLOCATE (out, Measure_PS1_V1, Nvalues);63 ALLOCATE_ZERO (out, Measure_PS1_V1, Nvalues); 64 64 65 65 for (i = 0; i < Nvalues; i++) { … … 116 116 Average *out; 117 117 118 ALLOCATE (out, Average, Nvalues);118 ALLOCATE_ZERO (out, Average, Nvalues); 119 119 120 120 for (i = 0; i < Nvalues; i++) { … … 156 156 Average_PS1_V1 *out; 157 157 158 ALLOCATE (out, Average_PS1_V1, Nvalues);158 ALLOCATE_ZERO (out, Average_PS1_V1, Nvalues); 159 159 160 160 for (i = 0; i < Nvalues; i++) { … … 191 191 SecFilt *out; 192 192 193 ALLOCATE (out, SecFilt, Nvalues);193 ALLOCATE_ZERO (out, SecFilt, Nvalues); 194 194 195 195 for (i = 0; i < Nvalues; i++) { … … 213 213 SecFilt_PS1_V1 *out; 214 214 215 ALLOCATE (out, SecFilt_PS1_V1, Nvalues);215 ALLOCATE_ZERO (out, SecFilt_PS1_V1, Nvalues); 216 216 217 217 for (i = 0; i < Nvalues; i++) { … … 232 232 Image *out; 233 233 234 ALLOCATE (out, Image, Nvalues);234 ALLOCATE_ZERO (out, Image, Nvalues); 235 235 236 236 for (i = 0; i < Nvalues; i++) { … … 267 267 out[i].sourceID = in[i].sourceID; 268 268 269 out[i].order = in[i].order; 270 out[i].Mx = in[i].Mx; 271 out[i].My = in[i].My; 272 out[i].Mxx = in[i].Mxx; 273 out[i].Mxy = in[i].Mxy; 274 out[i].Myy = in[i].Myy; 275 out[i].Mxxx = in[i].Mxxx; 276 out[i].Mxxy = in[i].Mxxy; 277 out[i].Mxyy = in[i].Mxyy; 278 out[i].Myyy = in[i].Myyy; 279 out[i].Mxxxx = in[i].Mxxxx; 280 out[i].Mxxxy = in[i].Mxxxy; 281 out[i].Mxxyy = in[i].Mxxyy; 282 out[i].Mxyyy = in[i].Mxyyy; 283 out[i].Myyyy = in[i].Myyyy; 269 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 270 // with the following. (no real databases used those values -- see 271 // libdvo/doc/dvo-images.txt) 272 out[i].nLinkAstrom = in[i].nLinkAstrom; 273 out[i].nLinkPhotom = in[i].nLinkPhotom; 274 out[i].dummy3 = in[i].dummy3; 275 out[i].dXpixSys = in[i].dXpixSys; 276 out[i].dYpixSys = in[i].dYpixSys; 277 out[i].dMagSys = in[i].dMagSys; 278 out[i].nFitAstrom = in[i].nFitAstrom; 279 out[i].nFitPhotom = in[i].nFitPhotom; 280 out[i].photom_map_id = in[i].photom_map_id; 281 out[i].astrom_map_id = in[i].astrom_map_id; 284 282 285 283 // changed or added for PS1_V2 … … 297 295 Image_PS1_V1 *out; 298 296 299 ALLOCATE (out, Image_PS1_V1, Nvalues);297 ALLOCATE_ZERO (out, Image_PS1_V1, Nvalues); 300 298 301 299 for (i = 0; i < Nvalues; i++) { … … 333 331 out[i].sourceID = in[i].sourceID; 334 332 335 out[i].order = in[i].order; 336 out[i].Mx = in[i].Mx; 337 out[i].My = in[i].My; 338 out[i].Mxx = in[i].Mxx; 339 out[i].Mxy = in[i].Mxy; 340 out[i].Myy = in[i].Myy; 341 out[i].Mxxx = in[i].Mxxx; 342 out[i].Mxxy = in[i].Mxxy; 343 out[i].Mxyy = in[i].Mxyy; 344 out[i].Myyy = in[i].Myyy; 345 out[i].Mxxxx = in[i].Mxxxx; 346 out[i].Mxxxy = in[i].Mxxxy; 347 out[i].Mxxyy = in[i].Mxxyy; 348 out[i].Mxyyy = in[i].Mxyyy; 349 out[i].Myyyy = in[i].Myyyy; 333 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 334 // with the following. (no real databases used those values -- see 335 // libdvo/doc/dvo-images.txt) 336 out[i].nLinkAstrom = in[i].nLinkAstrom; 337 out[i].nLinkPhotom = in[i].nLinkPhotom; 338 out[i].dummy3 = in[i].dummy3; 339 out[i].dXpixSys = in[i].dXpixSys; 340 out[i].dYpixSys = in[i].dYpixSys; 341 out[i].dMagSys = in[i].dMagSys; 342 out[i].nFitAstrom = in[i].nFitAstrom; 343 out[i].nFitPhotom = in[i].nFitPhotom; 344 out[i].photom_map_id = in[i].photom_map_id; 345 out[i].astrom_map_id = in[i].astrom_map_id; 350 346 } 351 347 return (out); … … 357 353 PhotCode *out; 358 354 359 ALLOCATE (out, PhotCode, Nvalues);355 ALLOCATE_ZERO (out, PhotCode, Nvalues); 360 356 361 357 for (i = 0; i < Nvalues; i++) { … … 393 389 PhotCode_PS1_V1 *out; 394 390 395 ALLOCATE (out, PhotCode_PS1_V1, Nvalues);391 ALLOCATE_ZERO (out, PhotCode_PS1_V1, Nvalues); 396 392 397 393 for (i = 0; i < Nvalues; i++) { -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c
r27580 r30631 8 8 Measure *out; 9 9 10 ALLOCATE (out, Measure, Nvalues);10 ALLOCATE_ZERO (out, Measure, Nvalues); 11 11 12 12 for (i = 0; i < Nvalues; i++) { … … 47 47 out[i].dXccd = in[i].dXccd; 48 48 out[i].dYccd = in[i].dYccd; 49 out[i].dRsys = in[i].dRsys; 49 50 out[i].posangle = in[i].posangle; 50 51 out[i].pltscale = in[i].pltscale; … … 61 62 Measure_PS1_V2 *out; 62 63 63 ALLOCATE (out, Measure_PS1_V2, Nvalues);64 ALLOCATE_ZERO (out, Measure_PS1_V2, Nvalues); 64 65 65 66 for (i = 0; i < Nvalues; i++) { … … 100 101 out[i].dXccd = in[i].dXccd; 101 102 out[i].dYccd = in[i].dYccd; 102 memset(out[i].pad, 0, sizeof(out[i].pad));103 out[i].dRsys = in[i].dRsys; 103 104 out[i].posangle = in[i].posangle; 104 105 out[i].pltscale = in[i].pltscale; … … 116 117 Average *out; 117 118 118 ALLOCATE (out, Average, Nvalues);119 ALLOCATE_ZERO (out, Average, Nvalues); 119 120 120 121 for (i = 0; i < Nvalues; i++) { … … 156 157 Average_PS1_V2 *out; 157 158 158 ALLOCATE (out, Average_PS1_V2, Nvalues);159 ALLOCATE_ZERO (out, Average_PS1_V2, Nvalues); 159 160 160 161 for (i = 0; i < Nvalues; i++) { … … 195 196 SecFilt *out; 196 197 197 ALLOCATE (out, SecFilt, Nvalues);198 ALLOCATE_ZERO (out, SecFilt, Nvalues); 198 199 199 200 for (i = 0; i < Nvalues; i++) { … … 215 216 SecFilt_PS1_V2 *out; 216 217 217 ALLOCATE (out, SecFilt_PS1_V2, Nvalues);218 ALLOCATE_ZERO (out, SecFilt_PS1_V2, Nvalues); 218 219 219 220 for (i = 0; i < Nvalues; i++) { … … 235 236 Image *out; 236 237 237 ALLOCATE (out, Image, Nvalues);238 ALLOCATE_ZERO (out, Image, Nvalues); 238 239 239 240 for (i = 0; i < Nvalues; i++) { … … 275 276 out[i].sourceID = in[i].sourceID; 276 277 277 out[i].order = in[i].order; 278 out[i].Mx = in[i].Mx; 279 out[i].My = in[i].My; 280 out[i].Mxx = in[i].Mxx; 281 out[i].Mxy = in[i].Mxy; 282 out[i].Myy = in[i].Myy; 283 out[i].Mxxx = in[i].Mxxx; 284 out[i].Mxxy = in[i].Mxxy; 285 out[i].Mxyy = in[i].Mxyy; 286 out[i].Myyy = in[i].Myyy; 287 out[i].Mxxxx = in[i].Mxxxx; 288 out[i].Mxxxy = in[i].Mxxxy; 289 out[i].Mxxyy = in[i].Mxxyy; 290 out[i].Mxyyy = in[i].Mxyyy; 291 out[i].Myyyy = in[i].Myyyy; 278 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 279 // with the following. (no real databases used those values -- see 280 // libdvo/doc/dvo-images.txt) 281 out[i].nLinkAstrom = in[i].nLinkAstrom; 282 out[i].nLinkPhotom = in[i].nLinkPhotom; 283 out[i].dummy3 = in[i].dummy3; 284 out[i].dXpixSys = in[i].dXpixSys; 285 out[i].dYpixSys = in[i].dYpixSys; 286 out[i].dMagSys = in[i].dMagSys; 287 out[i].nFitAstrom = in[i].nFitAstrom; 288 out[i].nFitPhotom = in[i].nFitPhotom; 289 out[i].photom_map_id = in[i].photom_map_id; 290 out[i].astrom_map_id = in[i].astrom_map_id; 292 291 } 293 292 return (out); … … 299 298 Image_PS1_V2 *out; 300 299 301 ALLOCATE (out, Image_PS1_V2, Nvalues);300 ALLOCATE_ZERO (out, Image_PS1_V2, Nvalues); 302 301 303 302 for (i = 0; i < Nvalues; i++) { … … 339 338 out[i].sourceID = in[i].sourceID; 340 339 341 out[i].order = in[i].order; 342 out[i].Mx = in[i].Mx; 343 out[i].My = in[i].My; 344 out[i].Mxx = in[i].Mxx; 345 out[i].Mxy = in[i].Mxy; 346 out[i].Myy = in[i].Myy; 347 out[i].Mxxx = in[i].Mxxx; 348 out[i].Mxxy = in[i].Mxxy; 349 out[i].Mxyy = in[i].Mxyy; 350 out[i].Myyy = in[i].Myyy; 351 out[i].Mxxxx = in[i].Mxxxx; 352 out[i].Mxxxy = in[i].Mxxxy; 353 out[i].Mxxyy = in[i].Mxxyy; 354 out[i].Mxyyy = in[i].Mxyyy; 355 out[i].Myyyy = in[i].Myyyy; 340 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 341 // with the following. (no real databases used those values -- see 342 // libdvo/doc/dvo-images.txt) 343 out[i].nLinkAstrom = in[i].nLinkAstrom; 344 out[i].nLinkPhotom = in[i].nLinkPhotom; 345 out[i].dummy3 = in[i].dummy3; 346 out[i].dXpixSys = in[i].dXpixSys; 347 out[i].dYpixSys = in[i].dYpixSys; 348 out[i].dMagSys = in[i].dMagSys; 349 out[i].nFitAstrom = in[i].nFitAstrom; 350 out[i].nFitPhotom = in[i].nFitPhotom; 351 out[i].photom_map_id = in[i].photom_map_id; 352 out[i].astrom_map_id = in[i].astrom_map_id; 356 353 } 357 354 return (out); … … 363 360 PhotCode *out; 364 361 365 ALLOCATE (out, PhotCode, Nvalues);362 ALLOCATE_ZERO (out, PhotCode, Nvalues); 366 363 367 364 for (i = 0; i < Nvalues; i++) { … … 399 396 PhotCode_PS1_V2 *out; 400 397 401 ALLOCATE (out, PhotCode_PS1_V2, Nvalues);398 ALLOCATE_ZERO (out, PhotCode_PS1_V2, Nvalues); 402 399 403 400 for (i = 0; i < Nvalues; i++) { … … 407 404 out[i].code = in[i].code; 408 405 out[i].type = in[i].type; 409 memset(out[i].dummy, 0, sizeof(out[i].dummy));410 406 out[i].C = in[i].C; 411 407 out[i].dC = in[i].dC; -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_elixir.c
r27580 r30631 7 7 Measure *out; 8 8 9 ALLOCATE (out, Measure, Nvalues);9 ALLOCATE_ZERO (out, Measure, Nvalues); 10 10 11 11 for (i = 0; i < Nvalues; i++) { … … 74 74 Measure_Elixir *out; 75 75 76 ALLOCATE (out, Measure_Elixir, Nvalues);76 ALLOCATE_ZERO (out, Measure_Elixir, Nvalues); 77 77 78 78 for (i = 0; i < Nvalues; i++) { … … 113 113 Average *out; 114 114 115 ALLOCATE (out, Average, Nvalues);116 ALLOCATE (*primary, SecFilt, Nvalues);115 ALLOCATE_ZERO (out, Average, Nvalues); 116 ALLOCATE_ZERO (*primary, SecFilt, Nvalues); 117 117 118 118 for (i = 0; i < Nvalues; i++) { … … 168 168 Average_Elixir *out; 169 169 170 ALLOCATE (out, Average_Elixir, Nvalues);170 ALLOCATE_ZERO (out, Average_Elixir, Nvalues); 171 171 172 172 for (i = 0; i < Nvalues; i++) { … … 198 198 SecFilt *out; 199 199 200 ALLOCATE (out, SecFilt, Nvalues);200 ALLOCATE_ZERO (out, SecFilt, Nvalues); 201 201 202 202 for (i = 0; i < Nvalues; i++) { … … 225 225 SecFilt_Elixir *out; 226 226 227 ALLOCATE (out, SecFilt_Elixir, Nvalues);227 ALLOCATE_ZERO (out, SecFilt_Elixir, Nvalues); 228 228 229 229 for (i = 0; i < Nvalues; i++) { … … 243 243 Image *out; 244 244 245 ALLOCATE (out, Image, Nvalues);245 ALLOCATE_ZERO (out, Image, Nvalues); 246 246 247 247 for (i = 0; i < Nvalues; i++) { … … 266 266 out[i].ccdnum = in[i].ccdnum; 267 267 268 out[i].order = in[i].order; 269 out[i].Mx = in[i].Mx; 270 out[i].My = in[i].My; 271 out[i].Mxx = in[i].Mxx; 272 out[i].Mxy = in[i].Mxy; 273 out[i].Myy = in[i].Myy; 274 out[i].Mxxx = in[i].Mxxx; 275 out[i].Mxxy = in[i].Mxxy; 276 out[i].Mxyy = in[i].Mxyy; 277 out[i].Myyy = in[i].Myyy; 278 out[i].Mxxxx = in[i].Mxxxx; 279 out[i].Mxxxy = in[i].Mxxxy; 280 out[i].Mxxyy = in[i].Mxxyy; 281 out[i].Mxyyy = in[i].Mxyyy; 282 out[i].Myyyy = in[i].Myyyy; 268 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 269 // with the following. (no real databases used those values -- see 270 // libdvo/doc/dvo-images.txt) 271 out[i].nLinkAstrom = in[i].nLinkAstrom; 272 out[i].nLinkPhotom = in[i].nLinkPhotom; 273 out[i].dummy3 = in[i].dummy3; 274 out[i].dXpixSys = in[i].dXpixSys; 275 out[i].dYpixSys = in[i].dYpixSys; 276 out[i].dMagSys = in[i].dMagSys; 277 out[i].nFitAstrom = in[i].nFitAstrom; 278 out[i].nFitPhotom = in[i].nFitPhotom; 279 out[i].photom_map_id = in[i].photom_map_id; 280 out[i].astrom_map_id = in[i].astrom_map_id; 283 281 284 282 // added or changed for PANSTARRS_DEV_0 … … 314 312 Image_Elixir *out; 315 313 316 ALLOCATE (out, Image_Elixir, Nvalues);314 ALLOCATE_ZERO (out, Image_Elixir, Nvalues); 317 315 318 316 for (i = 0; i < Nvalues; i++) { … … 338 336 out[i].ccdnum = in[i].ccdnum; 339 337 340 out[i].order = in[i].order; 341 out[i].Mx = in[i].Mx; 342 out[i].My = in[i].My; 343 out[i].Mxx = in[i].Mxx; 344 out[i].Mxy = in[i].Mxy; 345 out[i].Myy = in[i].Myy; 346 out[i].Mxxx = in[i].Mxxx; 347 out[i].Mxxy = in[i].Mxxy; 348 out[i].Mxyy = in[i].Mxyy; 349 out[i].Myyy = in[i].Myyy; 350 out[i].Mxxxx = in[i].Mxxxx; 351 out[i].Mxxxy = in[i].Mxxxy; 352 out[i].Mxxyy = in[i].Mxxyy; 353 out[i].Mxyyy = in[i].Mxyyy; 354 out[i].Myyyy = in[i].Myyyy; 338 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 339 // with the following. (no real databases used those values -- see 340 // libdvo/doc/dvo-images.txt) 341 out[i].nLinkAstrom = in[i].nLinkAstrom; 342 out[i].nLinkPhotom = in[i].nLinkPhotom; 343 out[i].dummy3 = in[i].dummy3; 344 out[i].dXpixSys = in[i].dXpixSys; 345 out[i].dYpixSys = in[i].dYpixSys; 346 out[i].dMagSys = in[i].dMagSys; 347 out[i].nFitAstrom = in[i].nFitAstrom; 348 out[i].nFitPhotom = in[i].nFitPhotom; 349 out[i].photom_map_id = in[i].photom_map_id; 350 out[i].astrom_map_id = in[i].astrom_map_id; 355 351 356 352 // added or changed for PANSTARRS_DEV_0 … … 372 368 PhotCode *out; 373 369 374 ALLOCATE (out, PhotCode, Nvalues);370 ALLOCATE_ZERO (out, PhotCode, Nvalues); 375 371 376 372 for (i = 0; i < Nvalues; i++) { … … 412 408 PhotCode_Elixir *out; 413 409 414 ALLOCATE (out, PhotCode_Elixir, Nvalues);410 ALLOCATE_ZERO (out, PhotCode_Elixir, Nvalues); 415 411 416 412 for (i = 0; i < Nvalues; i++) { -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_loneos.c
r27580 r30631 7 7 Measure *out; 8 8 9 ALLOCATE (out, Measure, Nvalues);9 ALLOCATE_ZERO (out, Measure, Nvalues); 10 10 11 11 for (i = 0; i < Nvalues; i++) { … … 76 76 Measure_Loneos *out; 77 77 78 ALLOCATE (out, Measure_Loneos, Nvalues);78 ALLOCATE_ZERO (out, Measure_Loneos, Nvalues); 79 79 80 80 for (i = 0; i < Nvalues; i++) { … … 104 104 Average *out; 105 105 106 ALLOCATE (out, Average, Nvalues);107 ALLOCATE (*primary, SecFilt, Nvalues);106 ALLOCATE_ZERO (out, Average, Nvalues); 107 ALLOCATE_ZERO (*primary, SecFilt, Nvalues); 108 108 109 109 for (i = 0; i < Nvalues; i++) { … … 160 160 Average_Loneos *out; 161 161 162 ALLOCATE (out, Average_Loneos, Nvalues);162 ALLOCATE_ZERO (out, Average_Loneos, Nvalues); 163 163 164 164 for (i = 0; i < Nvalues; i++) { … … 189 189 SecFilt *out; 190 190 191 ALLOCATE (out, SecFilt, Nvalues);191 ALLOCATE_ZERO (out, SecFilt, Nvalues); 192 192 193 193 for (i = 0; i < Nvalues; i++) { … … 218 218 SecFilt_Loneos *out; 219 219 220 ALLOCATE (out, SecFilt_Loneos, Nvalues);220 ALLOCATE_ZERO (out, SecFilt_Loneos, Nvalues); 221 221 222 222 for (i = 0; i < Nvalues; i++) { … … 235 235 Image *out; 236 236 237 ALLOCATE (out, Image, Nvalues);237 ALLOCATE_ZERO (out, Image, Nvalues); 238 238 239 239 for (i = 0; i < Nvalues; i++) { … … 259 259 out[i].ccdnum = in[i].ccdnum; 260 260 261 out[i].order = in[i].order; 262 out[i].Mx = in[i].Mx; 263 out[i].My = in[i].My; 264 out[i].Mxx = in[i].Mxx; 265 out[i].Mxy = in[i].Mxy; 266 out[i].Myy = in[i].Myy; 267 out[i].Mxxx = in[i].Mxxx; 268 out[i].Mxxy = in[i].Mxxy; 269 out[i].Mxyy = in[i].Mxyy; 270 out[i].Myyy = in[i].Myyy; 271 out[i].Mxxxx = in[i].Mxxxx; 272 out[i].Mxxxy = in[i].Mxxxy; 273 out[i].Mxxyy = in[i].Mxxyy; 274 out[i].Mxyyy = in[i].Mxyyy; 275 out[i].Myyyy = in[i].Myyyy; 261 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 262 // with the following. (no real databases used those values -- see 263 // libdvo/doc/dvo-images.txt) 264 out[i].nLinkAstrom = in[i].nLinkAstrom; 265 out[i].nLinkPhotom = in[i].nLinkPhotom; 266 out[i].dummy3 = in[i].dummy3; 267 out[i].dXpixSys = in[i].dXpixSys; 268 out[i].dYpixSys = in[i].dYpixSys; 269 out[i].dMagSys = in[i].dMagSys; 270 out[i].nFitAstrom = in[i].nFitAstrom; 271 out[i].nFitPhotom = in[i].nFitPhotom; 272 out[i].photom_map_id = in[i].photom_map_id; 273 out[i].astrom_map_id = in[i].astrom_map_id; 276 274 277 275 // added or changed for PANSTARRS_DEV_0 … … 307 305 Image_Loneos *out; 308 306 309 ALLOCATE (out, Image_Loneos, Nvalues);307 ALLOCATE_ZERO (out, Image_Loneos, Nvalues); 310 308 311 309 for (i = 0; i < Nvalues; i++) { … … 331 329 out[i].ccdnum = in[i].ccdnum; 332 330 333 out[i].order = in[i].order; 334 out[i].Mx = in[i].Mx; 335 out[i].My = in[i].My; 336 out[i].Mxx = in[i].Mxx; 337 out[i].Mxy = in[i].Mxy; 338 out[i].Myy = in[i].Myy; 339 out[i].Mxxx = in[i].Mxxx; 340 out[i].Mxxy = in[i].Mxxy; 341 out[i].Mxyy = in[i].Mxyy; 342 out[i].Myyy = in[i].Myyy; 343 out[i].Mxxxx = in[i].Mxxxx; 344 out[i].Mxxxy = in[i].Mxxxy; 345 out[i].Mxxyy = in[i].Mxxyy; 346 out[i].Mxyyy = in[i].Mxyyy; 347 out[i].Myyyy = in[i].Myyyy; 331 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 332 // with the following. (no real databases used those values -- see 333 // libdvo/doc/dvo-images.txt) 334 out[i].nLinkAstrom = in[i].nLinkAstrom; 335 out[i].nLinkPhotom = in[i].nLinkPhotom; 336 out[i].dummy3 = in[i].dummy3; 337 out[i].dXpixSys = in[i].dXpixSys; 338 out[i].dYpixSys = in[i].dYpixSys; 339 out[i].dMagSys = in[i].dMagSys; 340 out[i].nFitAstrom = in[i].nFitAstrom; 341 out[i].nFitPhotom = in[i].nFitPhotom; 342 out[i].photom_map_id = in[i].photom_map_id; 343 out[i].astrom_map_id = in[i].astrom_map_id; 348 344 349 345 // added or changed for PANSTARRS_DEV_0 -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
r27580 r30631 7 7 Measure *out; 8 8 9 ALLOCATE (out, Measure, Nvalues);9 ALLOCATE_ZERO (out, Measure, Nvalues); 10 10 11 11 for (i = 0; i < Nvalues; i++) { … … 71 71 Measure_Panstarrs_DEV_0 *out; 72 72 73 ALLOCATE (out, Measure_Panstarrs_DEV_0, Nvalues);73 ALLOCATE_ZERO (out, Measure_Panstarrs_DEV_0, Nvalues); 74 74 75 75 for (i = 0; i < Nvalues; i++) { … … 120 120 Average *out; 121 121 122 ALLOCATE (out, Average, Nvalues);122 ALLOCATE_ZERO (out, Average, Nvalues); 123 123 124 124 for (i = 0; i < Nvalues; i++) { … … 165 165 Average_Panstarrs_DEV_0 *out; 166 166 167 ALLOCATE (out, Average_Panstarrs_DEV_0, Nvalues);167 ALLOCATE_ZERO (out, Average_Panstarrs_DEV_0, Nvalues); 168 168 169 169 for (i = 0; i < Nvalues; i++) { … … 200 200 SecFilt *out; 201 201 202 ALLOCATE (out, SecFilt, Nvalues);202 ALLOCATE_ZERO (out, SecFilt, Nvalues); 203 203 204 204 for (i = 0; i < Nvalues; i++) { … … 225 225 SecFilt_Panstarrs_DEV_0 *out; 226 226 227 ALLOCATE (out, SecFilt_Panstarrs_DEV_0, Nvalues);227 ALLOCATE_ZERO (out, SecFilt_Panstarrs_DEV_0, Nvalues); 228 228 229 229 for (i = 0; i < Nvalues; i++) { … … 243 243 Image *out; 244 244 245 ALLOCATE (out, Image, Nvalues);245 ALLOCATE_ZERO (out, Image, Nvalues); 246 246 247 247 for (i = 0; i < Nvalues; i++) { … … 273 273 out[i].ccdnum = in[i].ccdnum; 274 274 275 out[i].order = in[i].order; 276 out[i].Mx = in[i].Mx; 277 out[i].My = in[i].My; 278 out[i].Mxx = in[i].Mxx; 279 out[i].Mxy = in[i].Mxy; 280 out[i].Myy = in[i].Myy; 281 out[i].Mxxx = in[i].Mxxx; 282 out[i].Mxxy = in[i].Mxxy; 283 out[i].Mxyy = in[i].Mxyy; 284 out[i].Myyy = in[i].Myyy; 285 out[i].Mxxxx = in[i].Mxxxx; 286 out[i].Mxxxy = in[i].Mxxxy; 287 out[i].Mxxyy = in[i].Mxxyy; 288 out[i].Mxyyy = in[i].Mxyyy; 289 out[i].Myyyy = in[i].Myyyy; 275 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 276 // with the following. (no real databases used those values -- see 277 // libdvo/doc/dvo-images.txt) 278 out[i].nLinkAstrom = in[i].nLinkAstrom; 279 out[i].nLinkPhotom = in[i].nLinkPhotom; 280 out[i].dummy3 = in[i].dummy3; 281 out[i].dXpixSys = in[i].dXpixSys; 282 out[i].dYpixSys = in[i].dYpixSys; 283 out[i].dMagSys = in[i].dMagSys; 284 out[i].nFitAstrom = in[i].nFitAstrom; 285 out[i].nFitPhotom = in[i].nFitPhotom; 286 out[i].photom_map_id = in[i].photom_map_id; 287 out[i].astrom_map_id = in[i].astrom_map_id; 290 288 291 289 // changed or added for PS1_DEV_1 … … 314 312 Image_Panstarrs_DEV_0 *out; 315 313 316 ALLOCATE (out, Image_Panstarrs_DEV_0, Nvalues);314 ALLOCATE_ZERO (out, Image_Panstarrs_DEV_0, Nvalues); 317 315 318 316 for (i = 0; i < Nvalues; i++) { … … 344 342 out[i].ccdnum = in[i].ccdnum; 345 343 346 out[i].order = in[i].order; 347 out[i].Mx = in[i].Mx; 348 out[i].My = in[i].My; 349 out[i].Mxx = in[i].Mxx; 350 out[i].Mxy = in[i].Mxy; 351 out[i].Myy = in[i].Myy; 352 out[i].Mxxx = in[i].Mxxx; 353 out[i].Mxxy = in[i].Mxxy; 354 out[i].Mxyy = in[i].Mxyy; 355 out[i].Myyy = in[i].Myyy; 356 out[i].Mxxxx = in[i].Mxxxx; 357 out[i].Mxxxy = in[i].Mxxxy; 358 out[i].Mxxyy = in[i].Mxxyy; 359 out[i].Mxyyy = in[i].Mxyyy; 360 out[i].Myyyy = in[i].Myyyy; 344 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 345 // with the following. (no real databases used those values -- see 346 // libdvo/doc/dvo-images.txt) 347 out[i].nLinkAstrom = in[i].nLinkAstrom; 348 out[i].nLinkPhotom = in[i].nLinkPhotom; 349 out[i].dummy3 = in[i].dummy3; 350 out[i].dXpixSys = in[i].dXpixSys; 351 out[i].dYpixSys = in[i].dYpixSys; 352 out[i].dMagSys = in[i].dMagSys; 353 out[i].nFitAstrom = in[i].nFitAstrom; 354 out[i].nFitPhotom = in[i].nFitPhotom; 355 out[i].photom_map_id = in[i].photom_map_id; 356 out[i].astrom_map_id = in[i].astrom_map_id; 361 357 362 358 // changed or added for PS1_DEV_1 -
branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
r27580 r30631 7 7 Measure *out; 8 8 9 ALLOCATE (out, Measure, Nvalues);9 ALLOCATE_ZERO (out, Measure, Nvalues); 10 10 11 11 for (i = 0; i < Nvalues; i++) { … … 71 71 Measure_Panstarrs_DEV_1 *out; 72 72 73 ALLOCATE (out, Measure_Panstarrs_DEV_1, Nvalues);73 ALLOCATE_ZERO (out, Measure_Panstarrs_DEV_1, Nvalues); 74 74 75 75 for (i = 0; i < Nvalues; i++) { … … 120 120 Average *out; 121 121 122 ALLOCATE (out, Average, Nvalues);122 ALLOCATE_ZERO (out, Average, Nvalues); 123 123 124 124 for (i = 0; i < Nvalues; i++) { … … 165 165 Average_Panstarrs_DEV_1 *out; 166 166 167 ALLOCATE (out, Average_Panstarrs_DEV_1, Nvalues);167 ALLOCATE_ZERO (out, Average_Panstarrs_DEV_1, Nvalues); 168 168 169 169 for (i = 0; i < Nvalues; i++) { … … 200 200 SecFilt *out; 201 201 202 ALLOCATE (out, SecFilt, Nvalues);202 ALLOCATE_ZERO (out, SecFilt, Nvalues); 203 203 204 204 for (i = 0; i < Nvalues; i++) { … … 225 225 SecFilt_Panstarrs_DEV_1 *out; 226 226 227 ALLOCATE (out, SecFilt_Panstarrs_DEV_1, Nvalues);227 ALLOCATE_ZERO (out, SecFilt_Panstarrs_DEV_1, Nvalues); 228 228 229 229 for (i = 0; i < Nvalues; i++) { … … 243 243 Image *out; 244 244 245 ALLOCATE (out, Image, Nvalues);245 ALLOCATE_ZERO (out, Image, Nvalues); 246 246 247 247 for (i = 0; i < Nvalues; i++) { … … 273 273 out[i].ccdnum = in[i].ccdnum; 274 274 275 out[i].order = in[i].order; 276 out[i].Mx = in[i].Mx; 277 out[i].My = in[i].My; 278 out[i].Mxx = in[i].Mxx; 279 out[i].Mxy = in[i].Mxy; 280 out[i].Myy = in[i].Myy; 281 out[i].Mxxx = in[i].Mxxx; 282 out[i].Mxxy = in[i].Mxxy; 283 out[i].Mxyy = in[i].Mxyy; 284 out[i].Myyy = in[i].Myyy; 285 out[i].Mxxxx = in[i].Mxxxx; 286 out[i].Mxxxy = in[i].Mxxxy; 287 out[i].Mxxyy = in[i].Mxxyy; 288 out[i].Mxyyy = in[i].Mxyyy; 289 out[i].Myyyy = in[i].Myyyy; 275 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 276 // with the following. (no real databases used those values -- see 277 // libdvo/doc/dvo-images.txt) 278 out[i].nLinkAstrom = in[i].nLinkAstrom; 279 out[i].nLinkPhotom = in[i].nLinkPhotom; 280 out[i].dummy3 = in[i].dummy3; 281 out[i].dXpixSys = in[i].dXpixSys; 282 out[i].dYpixSys = in[i].dYpixSys; 283 out[i].dMagSys = in[i].dMagSys; 284 out[i].nFitAstrom = in[i].nFitAstrom; 285 out[i].nFitPhotom = in[i].nFitPhotom; 286 out[i].photom_map_id = in[i].photom_map_id; 287 out[i].astrom_map_id = in[i].astrom_map_id; 290 288 291 289 // changed or added for PS1_DEV_1 … … 314 312 Image_Panstarrs_DEV_1 *out; 315 313 316 ALLOCATE (out, Image_Panstarrs_DEV_1, Nvalues);314 ALLOCATE_ZERO (out, Image_Panstarrs_DEV_1, Nvalues); 317 315 318 316 for (i = 0; i < Nvalues; i++) { … … 344 342 out[i].ccdnum = in[i].ccdnum; 345 343 346 out[i].order = in[i].order; 347 out[i].Mx = in[i].Mx; 348 out[i].My = in[i].My; 349 out[i].Mxx = in[i].Mxx; 350 out[i].Mxy = in[i].Mxy; 351 out[i].Myy = in[i].Myy; 352 out[i].Mxxx = in[i].Mxxx; 353 out[i].Mxxy = in[i].Mxxy; 354 out[i].Mxyy = in[i].Mxyy; 355 out[i].Myyy = in[i].Myyy; 356 out[i].Mxxxx = in[i].Mxxxx; 357 out[i].Mxxxy = in[i].Mxxxy; 358 out[i].Mxxyy = in[i].Mxxyy; 359 out[i].Mxyyy = in[i].Mxyyy; 360 out[i].Myyyy = in[i].Myyyy; 344 // as of 2011.02.03, the old Mx,My,..., Mxxxx,Myyyy have been deprecated and replaced 345 // with the following. (no real databases used those values -- see 346 // libdvo/doc/dvo-images.txt) 347 out[i].nLinkAstrom = in[i].nLinkAstrom; 348 out[i].nLinkPhotom = in[i].nLinkPhotom; 349 out[i].dummy3 = in[i].dummy3; 350 out[i].dXpixSys = in[i].dXpixSys; 351 out[i].dYpixSys = in[i].dYpixSys; 352 out[i].dMagSys = in[i].dMagSys; 353 out[i].nFitAstrom = in[i].nFitAstrom; 354 out[i].nFitPhotom = in[i].nFitPhotom; 355 out[i].photom_map_id = in[i].photom_map_id; 356 out[i].astrom_map_id = in[i].astrom_map_id; 361 357 362 358 // changed or added for PS1_DEV_1 -
branches/czw_branch/20101203/Ohana/src/libdvo/src/photfits.c
r15509 r30631 2 2 # define MAX_ORDER 3 3 3 4 /*** * XXXX warning: these functions have not been corrected to handle5 the change of Mcal from millimags to mags6 I don't think most functions are using the Mcal polynomial terms in7 any case... ****/8 9 /* all terms of order > 0 are stored as 16bit floats 10 the zero-order term is stored as a short int (-32k,+32k)*/4 /*** This file contains deprecated functions which were used to implement the 2D zero point variations per image. 5 This code has not been used for a long time, and is not up-to-date wrt the change from 6 millimag shorts to mag floats for values in the db tables. As of 2011.02.03, these 7 structures are no longer used. There is now an (as yet unused) index in the image table 8 to a zero-point map table. Someday, we may need similarly named functions to interact 9 with the ZP map. for now, this file is not used in the build. 10 ***/ 11 11 12 12 /* convert double to low-precision short int */ -
branches/czw_branch/20101203/Ohana/src/libkapa/src/DrawRotString.c
r10073 r30631 27 27 unsigned char *bitmap; 28 28 char *currentname, basename[64]; 29 int i, dy, dx, N, X, Y, code ;29 int i, dy, dx, N, X, Y, code, protect; 30 30 int dX, Xoff, dY, Yoff, YoffBase; 31 31 int currentsize, basesize; … … 63 63 64 64 code = FALSE; 65 protect = FALSE; 65 66 66 67 YoffBase = Yoff; … … 70 71 if ((N < 0) || (N >= NROTCHARS)) continue; 71 72 73 if (N == 39) { // single-quote 74 protect = protect ? FALSE : TRUE; 75 } 76 72 77 /* check for special characters */ 73 if (!code ) {78 if (!code && !protect) { 74 79 if (N == 94) { 75 80 SetRotFont (currentname, (int)(0.8*currentsize)); -
branches/czw_branch/20101203/Ohana/src/libkapa/src/PSRotFont.c
r10073 r30631 7 7 8 8 char *segment, basename[64], *currentname; 9 int i, N, code ;9 int i, N, code, protect; 10 10 int dX, dY, Xoff, Yoff, X, Y, Nseg, NSEG, YoffBase; 11 11 double cs, sn, fscale, currentscale; … … 60 60 61 61 code = FALSE; 62 protect = FALSE; 63 62 64 YoffBase = 0; 63 65 /* accumulate string segments with common state */ … … 66 68 if ((N < 0) || (N >= NROTCHARS)) continue; 67 69 70 if (N == 39) { // single-quote 71 protect = protect ? FALSE : TRUE; 72 } 73 68 74 /* check for special characters */ 69 if (!code ) {75 if (!code && !protect) { 70 76 /* superscript character (^) */ 71 77 if (N == 94) { -
branches/czw_branch/20101203/Ohana/src/libkapa/src/bDrawRotFont.c
r30118 r30631 14 14 unsigned char *bitmap; 15 15 char *currentname, basename[64]; 16 int i, dy, dx, N, X, Y, code ;16 int i, dy, dx, N, X, Y, code, protect; 17 17 int dX, Xoff, dY, Yoff, YoffBase; 18 18 int currentsize, basesize; … … 53 53 54 54 code = FALSE; 55 protect = FALSE; 55 56 56 57 YoffBase = Yoff; … … 60 61 if ((N < 0) || (N >= NROTCHARS)) continue; 61 62 63 if (N == 39) { // single-quote 64 protect = protect ? FALSE : TRUE; 65 } 66 62 67 /* check for special characters */ 63 if (!code ) {68 if (!code && !protect) { 64 69 if (N == 94) { 65 70 SetRotFont (currentname, (int)(0.8*currentsize)); -
branches/czw_branch/20101203/Ohana/src/libohana/include/ohana.h
r29537 r30631 283 283 int ohana_str_to_radec PROTO((double *ra, double *dec, char *str1, char *str2)); 284 284 double ohana_normalize_angle PROTO((double angle)); 285 double ohana_normalize_angle_to_midpoint PROTO((double angle, double Rmid)); 285 286 286 287 int hstgsc_hms_to_deg PROTO((double *h0, double *h1, double *d0, double *d1, char *string)); 288 289 short ToShortPixels PROTO((float pixels)); 290 short ToShortDegrees PROTO((float degrees)); 291 float FromShortPixels PROTO((short value)); 292 float FromShortDegrees PROTO((float value)); 287 293 288 294 /* IO Buffer functions */ -
branches/czw_branch/20101203/Ohana/src/libohana/include/ohana_allocate.h
r12332 r30631 17 17 18 18 # define ALLOCATE(PTR,TYPE,SIZE) \ 19 PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE)) 19 { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE)) } 20 # define ALLOCATE_ZERO(PTR,TYPE,SIZE) \ 21 { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE)); memset (PTR, 0, (SIZE)*sizeof(TYPE)); } 20 22 # define REALLOCATE(PTR,TYPE,SIZE) \ 21 PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE));22 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) \23 if ((NCURR) >= (SIZE)) { SIZE += DELTA; \24 PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE));}25 # define FREE(PTR) if (PTR != NULL) { ohana_free (__FILE__, __LINE__, PTR);}26 # define free(PTR) ohana_free(__FILE__, __LINE__, PTR)23 { PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); } 24 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) { \ 25 if ((NCURR) >= (SIZE)) { SIZE += DELTA; \ 26 PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); } } 27 # define FREE(PTR) { if (PTR != NULL) { ohana_free (__FILE__, __LINE__, PTR); } } 28 # define free(PTR) { ohana_free(__FILE__, __LINE__, PTR); } 27 29 28 30 # else … … 33 35 34 36 # ifndef ALLOCATE 35 # define ALLOCATE(PTR,TYPE,SIZE) \ 36 PTR = (TYPE *) malloc ((unsigned)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \ 37 if (PTR == NULL) { \ 38 fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__);\ 39 exit (10); } 40 # define REALLOCATE(PTR,TYPE,SIZE) \ 37 # define ALLOCATE(PTR,TYPE,SIZE) { \ 38 PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \ 39 if (PTR == NULL) { \ 40 fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__); \ 41 exit (10); } } 42 43 # define ALLOCATE_ZERO(PTR,TYPE,SIZE) { \ 44 PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \ 45 if (PTR == NULL) { \ 46 fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__); \ 47 exit (10); \ 48 } memset (PTR, 0, (SIZE)*sizeof(TYPE)); } 49 50 # define REALLOCATE(PTR,TYPE,SIZE) { \ 41 51 PTR = (TYPE *) realloc(PTR,(unsigned)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \ 42 if (PTR == NULL) { \ 43 fprintf(stderr,"failed realloc at %d in %s\n", __LINE__, __FILE__);\ 44 exit (10); } 45 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) \ 46 if ((NCURR) >= (SIZE)) { \ 47 SIZE += DELTA; \ 52 if (PTR == NULL) { \ 53 fprintf(stderr,"failed realloc at %d in %s\n", __LINE__, __FILE__); \ 54 exit (10); } } 55 56 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) { \ 57 if ((NCURR) >= (SIZE)) { \ 58 SIZE += DELTA; \ 48 59 PTR = (TYPE *) realloc(PTR,(unsigned)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \ 49 if (PTR == NULL) { \ 50 fprintf(stderr,"failed realloc increment at %d in %s\n", __LINE__, __FILE__);\ 51 exit (10); } } 52 # define FREE(PTR) if (PTR != NULL) { free (PTR); } 60 if (PTR == NULL) { \ 61 fprintf(stderr,"failed realloc increment at %d in %s\n", __LINE__, __FILE__); \ 62 exit (10); } } } 63 64 # define FREE(PTR) { if (PTR != NULL) { free (PTR); } } 53 65 # endif /* ALLOCATE */ 54 66 -
branches/czw_branch/20101203/Ohana/src/libohana/src/time.c
r19935 r30631 468 468 return (result); 469 469 } 470 471 double ohana_normalize_angle_to_midpoint (double angle, double Rmid) { 472 473 double result; 474 475 // take an input angle and force the domain to be 0.0 - 360.0 476 // there are a few ways to do this: 477 478 // option 1: This is a potentially very slow method, also subject to round off errors 479 # if (0) 480 while (angle > 360.0) angle -= 360.0; 481 while (angle < 0.0) angle += 360.0; 482 # endif 483 484 // option 2: take sin & cos, apply atan2 (y, x) 485 # if (1) 486 double x, y; 487 488 x = cos(angle*RAD_DEG); 489 y = sin(angle*RAD_DEG); 490 491 result = DEG_RAD*atan2 (y, x); 492 if (result < Rmid - 180.0) result += 360.0; 493 if (result > Rmid + 180.0) result -= 360.0; 494 # endif 495 496 # if (0) 497 // option 3: 498 int nCircle = angle / 360.0; 499 result -= 360.0*nCircle; 500 if (result < 0.0) result += 360.0; 501 # endif 502 503 return (result); 504 } 505 506 short ToShortPixels (float pixels) { 507 508 short value; 509 510 value = 100*pixels; 511 512 return value; 513 } 514 515 short ToShortDegrees (float degrees) { 516 517 short value; 518 519 value = ((float)0xffff/360.0) * degrees; 520 521 return value; 522 } 523 524 float FromShortPixels (short value) { 525 526 float pixels; 527 528 pixels = value / 100.0; 529 530 return pixels; 531 } 532 533 float FromShortDegrees (float value) { 534 535 float degrees; 536 537 degrees = (360.0 / (float)0xffff) * value; 538 539 return degrees; 540 } -
branches/czw_branch/20101203/Ohana/src/opihi/cmd.astro/cgrid.c
r29001 r30631 98 98 99 99 if (argc != 1) { 100 gprint (GP_ERR, "USAGE: cgrid [style] \n");100 gprint (GP_ERR, "USAGE: cgrid [style] [-ra-by-hour] [-labels]\n"); 101 101 return (FALSE); 102 102 } -
branches/czw_branch/20101203/Ohana/src/opihi/cmd.astro/region.c
r30118 r30631 18 18 FREE (name); 19 19 20 NoClear = FALSE; 21 if ((N = get_argument (argc, argv, "-no-clear"))) { 22 remove_argument (N, &argc, argv); 23 NoClear = TRUE; 24 } 25 20 26 if ((N = get_argument (argc, argv, "-image"))) { 21 27 remove_argument (N, &argc, argv); 22 28 KapaGetImageCoords (kapa, &graphmode.coords); 23 29 KapaGetImageRange (kapa, &graphmode.xmin, &graphmode.xmax, &graphmode.ymax, &graphmode.ymin); 30 31 set_variable ("XMIN", graphmode.xmin); 32 set_variable ("XMAX", graphmode.xmax); 33 set_variable ("YMIN", graphmode.ymin); 34 set_variable ("YMAX", graphmode.ymax); 35 36 set_variable ("RMIN", Ra + graphmode.xmin); 37 set_variable ("RMAX", Ra + graphmode.xmax); 38 set_variable ("DMIN", Dec + graphmode.ymin); 39 set_variable ("DMAX", Dec + graphmode.ymax); 40 41 // if (!NoClear) KapaClearSections (kapa); 42 KapaSetLimits (kapa, &graphmode); 43 24 44 SetGraph (&graphmode); 25 45 return (TRUE); … … 45 65 remove_argument (N, &argc, argv); 46 66 graphmode.flipnorth = FALSE; 47 }48 49 NoClear = FALSE;50 if ((N = get_argument (argc, argv, "-no-clear"))) {51 remove_argument (N, &argc, argv);52 NoClear = TRUE;53 67 } 54 68 -
branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/limits.c
r29540 r30631 26 26 27 27 // XXX need an option to set the limits based on the current image bounds 28 if ((N = get_argument (argc, argv, "-image"))) { 29 remove_argument (N, &argc, argv); 30 KapaGetImageRange (kapa, &graphmode.xmin, &graphmode.xmax, &graphmode.ymax, &graphmode.ymin); 31 32 set_variable ("XMIN", graphmode.xmin); 33 set_variable ("XMAX", graphmode.xmax); 34 set_variable ("YMIN", graphmode.ymin); 35 set_variable ("YMAX", graphmode.ymax); 36 37 // if (!NoClear) KapaClearSections (kapa); 38 SetGraph (&graphmode); 39 KapaSetLimits (kapa, &graphmode); 40 return (TRUE); 41 // Set Region based on image 42 } 28 43 29 44 if (argc == 1) { -
branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/match2d.c
r27817 r30631 1 1 # include "data.h" 2 2 3 int find_matches2d (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index1, Vector *index2); 4 int find_matches2d_closest (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index); 3 5 4 6 // match2d (X1) (Y1) (X2) (Y2) (Radius) [-index1 (index1)] [-index2 (index2)] [-nomatch1 nomatch1] [-nomatch2 nomatch2] … … 6 8 int match2d (int argc, char **argv) { 7 9 8 int N ;10 int N, CLOSEST; 9 11 double Radius; 10 12 char *endptr; … … 12 14 Vector *index1, *index2; 13 15 16 CLOSEST = FALSE; 17 if ((N = get_argument (argc, argv, "-closest"))) { 18 remove_argument (N, &argc, argv); 19 CLOSEST = TRUE; 20 } 21 14 22 if ((N = get_argument (argc, argv, "-index1"))) { 15 23 remove_argument (N, &argc, argv); … … 30 38 if (argc != 6) { 31 39 gprint (GP_ERR, "USAGE: match2d X1 Y1 X2 Y2 Radius [-index1 (index1)] [-index2 (index2)] [-closest]\n"); 32 // gprint (GP_ERR, "USAGE: match2d X1 Y1 X2 Y2 Radius [-index1 (index1)] [-index2 (index2)] [-closest]\n"); 33 // gprint (GP_ERR, " if -closest is provided, index1 & index2 will have the same length as X1 and X2 (respectively)\n"); 34 // gprint (GP_ERR, " with either the index of the match or a value of -1 for non-matches\n"); 35 return (FALSE); 36 } 40 gprint (GP_ERR, " if -closest is provided, index1 & index2 will have the same length as X1 and X2 (respectively)\n"); 41 gprint (GP_ERR, " with either the index of the match or a value of -1 for non-matches\n"); 42 return (FALSE); 43 } 44 45 /* 46 we have two modes of operation: 47 48 without -closest, we are finding all matched pairs within the match radius. in this 49 case, the two index vectors have the same length, one entry per matched pair. 50 x1[index1],y1[index1] matches to x2[index2],y2[index2]. 51 52 with -closest selected, we are finding the closest element of set 1 to each of set 2 53 and vice versa. in this case, index1 is always the same length as x1,y1, while index2 54 is the same lengths as x2,y2. x2[index1],y2[index1] matches x1,y1 while 55 x1[index2],y1[index2] matches x2,y2 56 57 */ 37 58 38 59 if ((X1vec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); … … 61 82 } 62 83 63 find_matches2d (X1vec, Y1vec, X2vec, Y2vec, Radius, index1, index2); 84 if (CLOSEST) { 85 find_matches2d_closest (X1vec, Y1vec, X2vec, Y2vec, Radius, index1); 86 find_matches2d_closest (X2vec, Y2vec, X1vec, Y1vec, Radius, index2); 87 } else { 88 find_matches2d (X1vec, Y1vec, X2vec, Y2vec, Radius, index1, index2); 89 } 64 90 65 91 return (TRUE); … … 132 158 return (TRUE); 133 159 } 160 161 // find the elements of X2,Y2 which are closest to each element of X1,Y1 (-1 if no match) 162 int find_matches2d_closest (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index) { 163 164 off_t i, j, Jmin, Ji, I, J, *N1, *N2, NMATCH; 165 double dX, dY, dR, Radius2, Rmin; 166 167 NMATCH = X1->Nelements; 168 ResetVector (index, OPIHI_INT, NMATCH); 169 170 ALLOCATE (N1, off_t, X1->Nelements); 171 ALLOCATE (N2, off_t, X2->Nelements); 172 173 for (i = 0; i < X1->Nelements; i++) { N1[i] = i; } 174 for (i = 0; i < X2->Nelements; i++) { N2[i] = i; } 175 176 sort_coords_indexonly (X1->elements.Flt, Y1->elements.Flt, N1, X1->Nelements); 177 sort_coords_indexonly (X2->elements.Flt, Y2->elements.Flt, N2, X2->Nelements); 178 179 Radius2 = Radius*Radius; 180 181 // find the closest entry in list 2 to the current entry in list 1: 182 for (i = j = 0; (i < X1->Nelements) && (j < X2->Nelements);) { 183 I = N1[i]; 184 J = N2[j]; 185 186 dX = X1->elements.Flt[I] - X2->elements.Flt[J]; 187 188 if (dX <= -1.02*Radius) { 189 // no match in list 2 to this entry 190 index->elements.Int[I] = -1; 191 i++; 192 continue; 193 } 194 if (dX >= +1.02*Radius) { j++; continue; } 195 196 // look for closest matches of list2() to list1(i) 197 Jmin = -1; 198 Rmin = Radius2; 199 for (Ji = j; (dX > -1.02*Radius) && (Ji < X2->Nelements); Ji++) { 200 J = N2[Ji]; 201 dX = X1->elements.Flt[I] - X2->elements.Flt[J]; 202 dY = Y1->elements.Flt[I] - Y2->elements.Flt[J]; 203 dR = dX*dX + dY*dY; 204 if (dR > Radius2) continue; 205 if (dR < Rmin) { 206 Rmin = dR; 207 Jmin = J; 208 } 209 } 210 211 // no match in list 2 to this entry 212 if (Jmin == -1) { 213 index->elements.Int[I] = -1; 214 i++; 215 continue; 216 } 217 index->elements.Int[I] = Jmin; 218 i++; 219 } 220 index->Nelements = NMATCH; 221 222 free (N1); 223 free (N2); 224 225 return (TRUE); 226 } -
branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/reindex.c
r29540 r30631 5 5 int reindex (int argc, char **argv) { 6 6 7 int i, Npts, Nmax , valid;7 int i, Npts, Nmax; 8 8 Vector *ivec, *ovec, *xvec; 9 9 … … 11 11 Npts = 0; 12 12 13 valid = TRUE; 14 valid &= (argc >= 6); 15 valid &= !strcmp(argv[2], "="); 16 valid &= !strcmp(argv[4], "using"); 17 if (!valid) { 18 gprint (GP_ERR, "USAGE: reindex (out) = (in) using (index)\n"); 19 gprint (GP_ERR, " creates a new vectors (out) from (in) based on sequence in (index)\n"); 20 return (FALSE); 21 } 13 if (argc != 6) goto usage; 14 if (strcmp(argv[2], "=")) goto usage; 15 if (strcmp(argv[4], "using")) goto usage; 22 16 23 17 if ((ovec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto error; … … 63 57 DeleteVector (ovec); 64 58 return (FALSE); 59 60 usage: 61 gprint (GP_ERR, "USAGE: reindex (out) = (in) using (index)\n"); 62 gprint (GP_ERR, " creates a new vectors (out) from (in) based on sequence in (index)\n"); 63 return (FALSE); 65 64 } 66 65 -
branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/subset.c
r27491 r30631 34 34 35 35 // ovec matches ivec in type 36 ResetVector (ovec, ivec->type, MAX (tvec[0].Nelements, 1));36 ResetVector (ovec, ivec->type, tvec[0].Nelements); 37 37 38 38 // we have four cases: (ivec == flt or int) and (tvec == flt or int) … … 75 75 76 76 // free up unused memory 77 ResetVector (ovec, ivec->type, MAX (Npts, 1));77 ResetVector (ovec, ivec->type, Npts); 78 78 79 79 DeleteVector (tvec); -
branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/vstats.c
r21508 r30631 3 3 int vstats (int argc, char **argv) { 4 4 5 int i, N;6 double max, min, sum, var, dvar, mean, stdev;7 float IgnoreValue ;5 int i, iter, N, Nbin, Niter; 6 double max, min, pmin, pmax, sum, var, dvar, mean, stdev; 7 float IgnoreValue, Nsigma; 8 8 int Ignore, Quiet; 9 9 10 int *Nval, bin, Nmode, Nmed ;11 double dx, mode, median ;10 int *Nval, bin, Nmode, Nmed, Nused; 11 double dx, mode, median, threshold; 12 12 Vector *vec; 13 char *mask = NULL; 13 14 14 15 IgnoreValue = 0; … … 21 22 } 22 23 24 Niter = 1; 25 Nsigma = 3.0; 26 27 if ((N = get_argument (argc, argv, "-sigma-clip"))) { 28 remove_argument (N, &argc, argv); 29 Nsigma = atof(argv[N]); 30 Niter = 3; 31 remove_argument (N, &argc, argv); 32 } 33 34 if ((N = get_argument (argc, argv, "-iter"))) { 35 remove_argument (N, &argc, argv); 36 Niter = atoi(argv[N]); 37 remove_argument (N, &argc, argv); 38 } 39 23 40 Quiet = FALSE; 24 41 if ((N = get_argument (argc, argv, "-q"))) { … … 32 49 33 50 if (argc != 2) { 34 gprint (GP_ERR, "USAGE: vstat (vector)\n"); 51 gprint (GP_ERR, "USAGE: vstat (vector) [-ignore value] [-q] [-quiet] [-iter Niter] [-sigma-clip Nsigma]\n"); 52 gprint (GP_ERR, " default is 1 iteration without sigma clipping or 3 with sigma clipping\n"); 35 53 return (FALSE); 36 54 } … … 39 57 40 58 /* we need two passes, one for max, min, mean, sum, one for median, stdev, etc */ 59 60 // set a good / bad mask 61 ALLOCATE (mask, char, vec[0].Nelements); 62 if (vec[0].type == OPIHI_FLT) { 63 opihi_flt *X = vec[0].elements.Flt; 64 for (i = 0; i < vec[0].Nelements; i++, X++) { 65 mask[i] = 1; 66 if (!finite (*X)) continue; 67 if (Ignore && (*X == IgnoreValue)) continue; 68 mask[i] = 0; 69 } 70 } else { 71 opihi_int *X = vec[0].elements.Int; 72 for (i = 0; i < vec[0].Nelements; i++, X++) { 73 mask[i] = 1; 74 if (!finite (*X)) continue; 75 if (Ignore && (*X == IgnoreValue)) continue; 76 mask[i] = 0; 77 } 78 } 41 79 42 80 /* calculate max, min, mean, sum, npix */ … … 47 85 opihi_flt *X = vec[0].elements.Flt; 48 86 for (i = 0; i < vec[0].Nelements; i++, X++) { 49 if (!finite (*X)) continue; 50 if (Ignore && (*X == IgnoreValue)) continue; 87 if (mask[i]) continue; 51 88 max = MAX (*X, max); 52 89 min = MIN (*X, min); … … 57 94 opihi_int *X = vec[0].elements.Int; 58 95 for (i = 0; i < vec[0].Nelements; i++, X++) { 59 if (!finite (*X)) continue; 60 if (Ignore && (*X == IgnoreValue)) continue; 96 if (mask[i]) continue; 61 97 max = MAX (*X, max); 62 98 min = MIN (*X, min); … … 67 103 mean = sum / N; 68 104 69 /* calculate median and mode with resolution of (max - min) / 1000 */ 70 dx = (max - min) / 1000; 71 if (dx == 0) { 72 median = mode = min; 73 stdev = 0.0; 74 goto skip; 75 } 76 77 ALLOCATE (Nval, int, 1002); 78 bzero (Nval, 1000*sizeof(int)); 79 var = 0; 80 if (vec[0].type == OPIHI_FLT) { 81 opihi_flt *X = vec[0].elements.Flt; 82 for (i = 0; i < vec[0].Nelements; i++, X++) { 83 if (!finite (*X)) continue; 84 if (Ignore && (*X == IgnoreValue)) continue; 85 bin = MAX (0, MIN (1000, (*X - min) / dx)); 86 Nval[bin] ++; 87 dvar = (*X - mean); 88 var += dvar*dvar; 89 } 90 } else { 91 opihi_int *X = vec[0].elements.Int; 92 for (i = 0; i < vec[0].Nelements; i++, X++) { 93 if (!finite (*X)) continue; 94 if (Ignore && (*X == IgnoreValue)) continue; 95 bin = MAX (0, MIN (1000, (*X - min) / dx)); 96 Nval[bin] ++; 97 dvar = (*X - mean); 98 var += dvar*dvar; 99 } 100 } 101 stdev = sqrt (var / N); 102 103 Nmode = 0; 104 mode = Nval[Nmode]; 105 median = 0; 106 Nmed = -1; 107 for (i = 0; i < 1001; i++) { 108 if (Nmed == -1) { 109 median += Nval[i]; 110 if (median >= N / 2.0) { 111 Nmed = i; 112 median = i * dx + min; 105 // we do Niter passes; on each pass, we exclude entries > Nsigma from the median 106 pmin = min; 107 pmax = max; 108 109 stdev = mode = median = Nused = 0.0; 110 111 for (iter = 0; iter < Niter; iter ++) { 112 113 // reduce Nbin after the first iteration? 114 Nbin = 1000; 115 116 /* calculate median and mode with resolution of (max - min) / 1000 */ 117 dx = (pmax - pmin) / Nbin; 118 if (dx == 0) { 119 median = mode = min; 120 stdev = 0.0; 121 goto skip; 122 } 123 124 ALLOCATE (Nval, int, Nbin + 2); 125 bzero (Nval, Nbin*sizeof(int)); 126 var = 0; 127 if (vec[0].type == OPIHI_FLT) { 128 opihi_flt *X = vec[0].elements.Flt; 129 for (i = 0; i < vec[0].Nelements; i++, X++) { 130 if (mask[i]) continue; 131 bin = MAX (0, MIN (Nbin, (*X - pmin) / dx)); 132 Nval[bin] ++; 133 dvar = (*X - mean); 134 var += dvar*dvar; 135 } 136 } else { 137 opihi_int *X = vec[0].elements.Int; 138 for (i = 0; i < vec[0].Nelements; i++, X++) { 139 if (mask[i]) continue; 140 bin = MAX (0, MIN (Nbin, (*X - pmin) / dx)); 141 Nval[bin] ++; 142 dvar = (*X - mean); 143 var += dvar*dvar; 144 } 145 } 146 stdev = sqrt (var / N); 147 148 Nmode = 0; 149 mode = Nval[Nmode]; 150 median = 0; 151 Nmed = -1; 152 for (i = 0; i < Nbin + 1; i++) { 153 if (Nmed == -1) { 154 median += Nval[i]; 155 if (median >= N / 2.0) { 156 Nmed = i; 157 median = i * dx + pmin; 158 } 113 159 } 114 } 115 if (mode < Nval[i]) { 116 Nmode = i; 117 mode = Nval[Nmode]; 118 } 119 } 120 mode = Nmode * dx + min; 121 free (Nval); 160 if (mode < Nval[i]) { 161 Nmode = i; 162 mode = Nval[Nmode]; 163 } 164 } 165 mode = Nmode * dx + pmin; 166 free (Nval); 167 168 threshold = Nsigma * stdev; 169 170 // we are going to do another pass: mark the entries to skip 171 pmin = max; 172 pmax = min; 173 if (iter < Niter - 1) { 174 if (vec[0].type == OPIHI_FLT) { 175 opihi_flt *X = vec[0].elements.Flt; 176 for (i = 0; i < vec[0].Nelements; i++, X++) { 177 if (mask[i]) continue; 178 if (fabs(*X - median) > threshold) { 179 mask[i] = 1; 180 } else { 181 pmin = MIN (*X, pmin); 182 pmax = MAX (*X, pmax); 183 } 184 } 185 } else { 186 opihi_int *X = vec[0].elements.Int; 187 for (i = 0; i < vec[0].Nelements; i++, X++) { 188 if (mask[i]) continue; 189 if (fabs(*X - median) > threshold) { 190 mask[i] = 1; 191 } else { 192 pmin = MIN (*X, pmin); 193 pmax = MAX (*X, pmax); 194 } 195 } 196 } 197 } 198 // gprint (GP_ERR, "iter %d, mean: %g, stdev: %g, min: %g, max: %g, median: %g, mode: %g, Npts: %d\n", 199 // iter, mean, stdev, min, max, median, mode, N); 200 } 201 202 Nused = 0; 203 for (i = 0; i < vec[0].Nelements; i++) { 204 if (mask[i]) continue; 205 Nused ++; 206 } 122 207 123 208 skip: 209 FREE(mask); 210 124 211 if (!Quiet) { 125 212 gprint (GP_ERR, "mean: %g, stdev: %g, min: %g, max: %g, median: %g, mode: %g, Npts: %d\n", 126 mean, stdev, min, max, median, mode, N); 127 } 128 213 mean, stdev, min, max, median, mode, N); 214 } 215 216 set_variable ("PMIN", pmin); 217 set_variable ("PMAX", pmax); 129 218 set_variable ("MIN", min); 130 219 set_variable ("MAX", max); … … 134 223 set_variable ("TOTAL", sum); 135 224 set_int_variable ("NPIX", N); 225 set_int_variable ("NPTS", N); 226 set_int_variable ("NUSED", Nused); 136 227 set_variable ("SIGMA", stdev); 137 228 return (TRUE); -
branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/write_vectors.c
r20936 r30631 140 140 if (fmttype[j] == 'd') { 141 141 if (vec[j][0].type == OPIHI_FLT) { 142 fprintf (f, fmtlist[j], ( int)(vec[j][0].elements.Flt[i]));142 fprintf (f, fmtlist[j], (opihi_int)(vec[j][0].elements.Flt[i])); 143 143 } else { 144 fprintf (f, fmtlist[j], ( int)(vec[j][0].elements.Int[i]));144 fprintf (f, fmtlist[j], (opihi_int)(vec[j][0].elements.Int[i])); 145 145 } 146 146 } 147 147 if (fmttype[j] == 'f') { 148 148 if (vec[j][0].type == OPIHI_FLT) { 149 fprintf (f, fmtlist[j], ( float)(vec[j][0].elements.Flt[i]));149 fprintf (f, fmtlist[j], (opihi_flt)(vec[j][0].elements.Flt[i])); 150 150 } else { 151 fprintf (f, fmtlist[j], ( float)(vec[j][0].elements.Int[i]));151 fprintf (f, fmtlist[j], (opihi_flt)(vec[j][0].elements.Int[i])); 152 152 } 153 153 } -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/avextract.c
r28241 r30631 44 44 45 45 // parse skyregion options 46 if ((selection = SetRegionSelection (&argc, argv)) == NULL) goto escape; 46 if ((selection = SetRegionSelection (&argc, argv)) == NULL) { 47 print_error(); 48 goto escape; 49 } 47 50 48 51 // command-line is of the form: avextract field,field, field [where (field op value)...] … … 68 71 // construct the db Boolean math stack (frees cstack) 69 72 stack = dbRPN (Ncstack, cstack, &Nstack); 73 if (Ncstack && !Nstack) { 74 print_error(); 75 goto escape; 76 } 70 77 71 78 // add the skyregion limits to the where statement (or create) -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/dbExtractImages.c
r27587 r30631 241 241 242 242 case IMAGE_NCAL: 243 value.Int = image[N]. Mxxxx;243 value.Int = image[N].nFitPhotom; 244 244 break; 245 245 case IMAGE_SKY: 246 value.Flt = image[N].Myyyy + 0x8000;246 value.Flt = NAN; 247 247 break; 248 248 case IMAGE_FLAGS: … … 299 299 value.Flt = (field->ID == IMAGE_X_UR_FP) ? x : y; 300 300 break; 301 302 case IMAGE_X_ERR_SYS: 303 value.Flt = image[N].dXpixSys; 304 break; 305 case IMAGE_Y_ERR_SYS: 306 value.Flt = image[N].dXpixSys; 307 break; 308 case IMAGE_MAG_ERR_SYS: 309 value.Flt = image[N].dMagSys; 310 break; 311 312 case IMAGE_NFIT_PHOTOM: 313 value.Int = image[N].nFitPhotom; 314 break; 315 case IMAGE_NFIT_ASTROM: 316 value.Int = image[N].nFitAstrom; 317 break; 318 case IMAGE_NLINK_PHOTOM: 319 value.Int = image[N].nLinkPhotom; 320 break; 321 case IMAGE_NLINK_ASTROM: 322 value.Int = image[N].nLinkAstrom; 323 break; 301 324 } 302 325 return (value); -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/dbExtractMeasures.c
r28955 r30631 320 320 break; 321 321 case MEAS_FWHM: /* OK */ 322 value.Flt = 0.01*(measure[0].FWx + measure[0].FWy) / 2.0;322 value.Flt = FromShortPixels(measure[0].FWx + measure[0].FWy) / 2.0; 323 323 break; 324 324 case MEAS_FWHM_MAJ: /* OK */ 325 value.Flt = 0.01*measure[0].FWx;325 value.Flt = FromShortPixels(measure[0].FWx); 326 326 break; 327 327 case MEAS_FWHM_MIN: /* OK */ 328 value.Flt = 0.01*measure[0].FWy;328 value.Flt = FromShortPixels(measure[0].FWy); 329 329 break; 330 330 case MEAS_THETA: /* OK */ 331 value.Flt = measure[0].theta;331 value.Flt = FromShortDegrees(measure[0].theta); 332 332 break; 333 333 case MEAS_MXX: /* OK */ 334 value.Flt = measure[0].Mxx;334 value.Flt = FromShortPixels(measure[0].Mxx); 335 335 break; 336 336 case MEAS_MXY: /* OK */ 337 value.Flt = measure[0].Mxy;337 value.Flt = FromShortPixels(measure[0].Mxy); 338 338 break; 339 339 case MEAS_MYY: /* OK */ 340 value.Flt = measure[0].Myy;340 value.Flt = FromShortPixels(measure[0].Myy); 341 341 break; 342 342 case MEAS_DOPHOT: /* OK */ … … 382 382 break; 383 383 case MEAS_XCCD_ERR: /* OK */ 384 value.Flt = measure[0].dXccd / 100.0;384 value.Flt = FromShortPixels(measure[0].dXccd); 385 385 break; 386 386 case MEAS_YCCD_ERR: /* OK */ 387 value.Flt = measure[0].dYccd / 100.0; 387 value.Flt = FromShortPixels(measure[0].dYccd); 388 break; 389 case MEAS_POS_SYS_ERR: /* OK */ 390 value.Flt = FromShortPixels(measure[0].dRsys); 388 391 break; 389 392 case MEAS_XMOSAIC: /* OK */ … … 425 428 value.Flt = measure[0].psfQual; 426 429 break; 430 case MEAS_PSF_QF_PERFECT: /* OK */ 431 value.Flt = NAN; 432 break; 427 433 case MEAS_PSF_CHISQ: /* OK */ 428 434 value.Flt = measure[0].psfChisq; -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/dbFields.c
r28955 r30631 194 194 if (!strcasecmp (fieldName, "XCCD:ERR")) ESCAPE (MEAS_XCCD_ERR, MAG_NONE, OPIHI_FLT); 195 195 if (!strcasecmp (fieldName, "YCCD:ERR")) ESCAPE (MEAS_YCCD_ERR, MAG_NONE, OPIHI_FLT); 196 if (!strcasecmp (fieldName, "POS_SYS_ERR")) ESCAPE (MEAS_POS_SYS_ERR, MAG_NONE, OPIHI_FLT); 196 197 if (!strcasecmp (fieldName, "XMOSAIC")) ESCAPE (MEAS_XMOSAIC, MAG_NONE, OPIHI_FLT); 197 198 if (!strcasecmp (fieldName, "YMOSAIC")) ESCAPE (MEAS_YMOSAIC, MAG_NONE, OPIHI_FLT); … … 205 206 if (!strcasecmp (fieldName, "IMAGEID")) ESCAPE (MEAS_IMAGE_ID, MAG_NONE, OPIHI_INT); 206 207 if (!strcasecmp (fieldName, "PSF_QF")) ESCAPE (MEAS_PSF_QF, MAG_NONE, OPIHI_FLT); 208 if (!strcasecmp (fieldName, "PSF_QF_PERFECT")) ESCAPE (MEAS_PSF_QF_PERFECT, MAG_NONE, OPIHI_FLT); 207 209 if (!strcasecmp (fieldName, "PSF_CHISQ")) ESCAPE (MEAS_PSF_CHISQ, MAG_NONE, OPIHI_FLT); 208 210 if (!strcasecmp (fieldName, "PSF_NDOF")) ESCAPE (MEAS_PSF_NDOF, MAG_NONE, OPIHI_INT); … … 398 400 if (!strcasecmp (fieldName, "trate" )) ESCAPE (IMAGE_TRATE, MAG_NONE, OPIHI_FLT); 399 401 400 // XXX : these are mapped to ridiculous things: Myyyy + 0x8000 and Mxxxx401 402 if (!strcasecmp (fieldName, "ncal" )) ESCAPE (IMAGE_NCAL, MAG_NONE, OPIHI_INT); 402 if (!strcasecmp (fieldName, "sky" )) ESCAPE (IMAGE_SKY, MAG_NONE, OPIHI_FLT); 403 if (!strcasecmp (fieldName, "sky" )) ESCAPE (IMAGE_SKY, MAG_NONE, OPIHI_FLT); // deprecated for now 403 404 404 405 if (!strcasecmp (fieldName, "imflags" )) ESCAPE (IMAGE_FLAGS, MAG_NONE, OPIHI_INT); … … 427 428 if (!strcasecmp (fieldName, "Y_UR_FP" )) ESCAPE (IMAGE_Y_UR_FP, MAG_NONE, OPIHI_FLT); 428 429 430 if (!strcasecmp (fieldName, "dX_SYS" )) ESCAPE (IMAGE_X_ERR_SYS, MAG_NONE, OPIHI_FLT); 431 if (!strcasecmp (fieldName, "dY_SYS" )) ESCAPE (IMAGE_Y_ERR_SYS, MAG_NONE, OPIHI_FLT); 432 if (!strcasecmp (fieldName, "dM_SYS" )) ESCAPE (IMAGE_MAG_ERR_SYS,MAG_NONE, OPIHI_FLT); 433 if (!strcasecmp (fieldName, "NFIT_PHOTOM")) ESCAPE (IMAGE_NFIT_PHOTOM,MAG_NONE, OPIHI_INT); 434 if (!strcasecmp (fieldName, "NFIT_ASTROM")) ESCAPE (IMAGE_NFIT_ASTROM,MAG_NONE, OPIHI_INT); 435 if (!strcasecmp (fieldName, "NLINK_PHOTOM")) ESCAPE (IMAGE_NLINK_PHOTOM,MAG_NONE, OPIHI_INT); 436 if (!strcasecmp (fieldName, "NLINK_ASTROM")) ESCAPE (IMAGE_NLINK_ASTROM,MAG_NONE, OPIHI_INT); 437 429 438 // for words that don't parse, try a photcode 430 439 gprint (GP_ERR, "unknown field '%s' for image table in DVO database\n", fieldName); -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/gimages.c
r28958 r30631 201 201 } 202 202 203 /*** XXX we need to re-introduce the use of applyMcal 204 Mcal = applyMcal (&image[i], 2048.0, 2048.0); 205 ***/ 203 // XXX Mcal = applyMcal (&image[i], 2048.0, 2048.0); 206 204 207 205 got_spot: -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/gstar.c
r28326 r30631 222 222 gprint (GP_LOG, "%5d ", catalog.measure[m].photcode); 223 223 gprint (GP_LOG, "%-20s ", GetPhotcodeNamebyCode (catalog.measure[m].photcode)); 224 gprint (GP_LOG, "%5.2f ", 0.01*catalog.measure[m].FWx);225 gprint (GP_LOG, "%5.2f ", 0.01*catalog.measure[m].FWy);224 gprint (GP_LOG, "%5.2f ", FromShortPixels(catalog.measure[m].FWx)); 225 gprint (GP_LOG, "%5.2f ", FromShortPixels(catalog.measure[m].FWy)); 226 226 227 227 if (FULL_OUTPUT) { … … 233 233 gprint (GP_LOG, "%f ", catalog.measure[m].Xccd); 234 234 gprint (GP_LOG, "%f ", catalog.measure[m].Yccd); 235 gprint (GP_LOG, "% d ", catalog.measure[m].dXccd);236 gprint (GP_LOG, "% d ", catalog.measure[m].dYccd);235 gprint (GP_LOG, "%f ", FromShortPixels(catalog.measure[m].dXccd)); 236 gprint (GP_LOG, "%f ", FromShortPixels(catalog.measure[m].dYccd)); 237 237 gprint (GP_LOG, "%f ", catalog.measure[m].Sky); 238 238 gprint (GP_LOG, "%f ", catalog.measure[m].dSky); … … 244 244 gprint (GP_LOG, "%f ", catalog.measure[m].crNsigma); 245 245 gprint (GP_LOG, "%f ", catalog.measure[m].extNsigma); 246 gprint (GP_LOG, "%f ", (360.0/(float)0xffff)*catalog.measure[m].theta);246 gprint (GP_LOG, "%f ", FromShortDegrees(catalog.measure[m].theta)); 247 247 } 248 248 gprint (GP_LOG, "\n"); -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/images.c
r30118 r30631 223 223 goto got_type; 224 224 } 225 // For 'TrianglePts' (TRI-), we are using the Mx,My, etc terms to save the coordinates 226 // this means triangular images cannot carry photometric zero-point variations 225 // For 'TrianglePts' (TRI-), we are absurdly overloaded values otherwise not used 227 226 if (typehash == TrianglePts) { 228 227 Npts = 3; 229 x[0] = image[ i].Mx; y[0] = image[i].My;230 x[1] = image[ i].Mxxx; y[1] = image[i].Mxyy;231 x[2] = image[ i].Mxxy; y[2] = image[i].Myyy;228 x[0] = image[0].dXpixSys; y[0] = image[0].dYpixSys; 229 x[1] = image[0].dMagSys; y[1] = image[0].nFitAstrom; 230 x[2] = image[0].photom_map_id; y[2] = image[0].astrom_map_id; 232 231 goto got_type; 233 232 } -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/imextract.c
r28958 r30631 62 62 // construct the db Boolean math stack (frees cstack) 63 63 stack = dbRPN (Ncstack, cstack, &Nstack); 64 if (Ncstack && !Nstack) { 65 print_error(); 66 goto escape; 67 } 64 68 65 69 // add the skyregion limits to the where statement (or create) -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/imphot.c
r29540 r30631 9 9 char bufname[64]; 10 10 float *p; 11 double fx, fy, x, y , applyMcal();11 double fx, fy, x, y; 12 12 Image *image; 13 13 Buffer *buf; … … 63 63 for (y = 0; y < 200; y+=1.0) { 64 64 for (x = 0; x < 100; x+=1.0, p++) { 65 *p = applyMcal (&image[subset[0]], (fx*x), (fy*y)); 65 // *p = applyMcal (&image[subset[0]], (fx*x), (fy*y)); 66 *p = image[subset[0]].Mcal; 66 67 } 67 68 } … … 70 71 for (j = 0; j < Nsubset; j++) { 71 72 i = subset[j]; 73 gprint (GP_ERR, "%s: %f\n", image[i].name, image[i].Mcal); 74 75 // XXX old code when we had the option of a 2D zero point model 76 # if (0) 72 77 switch (image[i].order) { 73 78 case 0: … … 90 95 break; 91 96 } 97 # endif 92 98 } 93 99 -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/mextract.c
r28955 r30631 68 68 // construct the db Boolean math stack (frees cstack) 69 69 stack = dbRPN (Ncstack, cstack, &Nstack); 70 if ( (Ncstack > 0) && (Nstack < 1)) {70 if (Ncstack && !Nstack) { 71 71 print_error (); 72 72 goto escape; -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/mmextract.c
r28241 r30631 106 106 // construct the db Boolean math stack (frees cstack) 107 107 stack1 = dbRPN (Ncstack1, cstack1, &Nstack1); 108 if ( (Ncstack1 > 0) && (Nstack1 < 1)) {108 if (Ncstack1 && !Nstack1) { 109 109 print_error (); 110 110 goto escape; … … 113 113 // construct the db Boolean math stack (frees cstack) 114 114 stack2 = dbRPN (Ncstack2, cstack2, &Nstack2); 115 if ( (Ncstack2 > 0) && (Nstack2 < 1)) {115 if (Ncstack2 && !Nstack2) { 116 116 print_error (); 117 117 goto escape; -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/photometry.c
r28955 r30631 778 778 } else { 779 779 780 if ( 0.01 * measure[0].FWx < 3.0) return (FALSE);781 if ( 0.01 * measure[0].FWx > 10.0) return (FALSE);780 if (FromShortPixels(measure[0].FWx < 3.0)) return (FALSE); 781 if (FromShortPixels(measure[0].FWx > 10.0)) return (FALSE); 782 782 783 783 return (TRUE); … … 810 810 Nm = 0; 811 811 for (i = 0; i < average[0].Nmeasure; i++) { 812 fwhm = measure[i].FWx / 100.0;812 fwhm = FromShortPixels(measure[i].FWx); 813 813 switch (FWHMsign) { 814 814 case 0: … … 1166 1166 break; 1167 1167 case MEAS_FWHM: /* OK */ 1168 value = 0.01*measure[0].FWx;1168 value = FromShortPixels(measure[0].FWx); 1169 1169 break; 1170 1170 case MEAS_DB_FLAGS: /* ? */ -
branches/czw_branch/20101203/Ohana/src/opihi/dvo/skycat.c
r20936 r30631 36 36 37 37 if (argc != 1) { 38 gprint (GP_ERR, "USAGE: skycat [-all] \n");38 gprint (GP_ERR, "USAGE: skycat [-all] [-depth depth] [-v]\n"); 39 39 return (FALSE); 40 40 } … … 116 116 117 117 r = ohana_normalize_angle (r); 118 while (r < Rmin) { r += 360.0; } 119 while (r > Rmax) { r -= 360.0; } 118 120 119 121 if (*leftside == -1) { -
branches/czw_branch/20101203/Ohana/src/opihi/include/dvoshell.h
r28958 r30631 107 107 MEAS_XCCD_ERR, 108 108 MEAS_YCCD_ERR, 109 MEAS_POS_SYS_ERR, 109 110 MEAS_XMOSAIC, 110 111 MEAS_YMOSAIC, … … 116 117 MEAS_IMAGE_ID, 117 118 MEAS_PSF_QF, 119 MEAS_PSF_QF_PERFECT, 118 120 MEAS_PSF_CHISQ, 119 121 MEAS_PSF_NDOF, … … 218 220 IMAGE_Y_UL_FP, 219 221 IMAGE_Y_UR_FP, 222 IMAGE_X_ERR_SYS, 223 IMAGE_Y_ERR_SYS, 224 IMAGE_MAG_ERR_SYS, 225 IMAGE_NFIT_PHOTOM, 226 IMAGE_NFIT_ASTROM, 227 IMAGE_NLINK_PHOTOM, 228 IMAGE_NLINK_ASTROM 220 229 }; 221 230 -
branches/czw_branch/20101203/Ohana/src/opihi/include/shell.h
r27790 r30631 76 76 char *expand_vars PROTO((char *line)); 77 77 char *expand_vectors PROTO((char *line)); 78 char *parse PROTO(( char *line));78 char *parse PROTO((int *status, char *line)); 79 79 char **parse_commands PROTO((char *, int *)); 80 80 void welcome PROTO((void)); -
branches/czw_branch/20101203/Ohana/src/opihi/lib.shell/VectorOps.c
r20936 r30631 178 178 vec[0].Nelements = Nelements; 179 179 if (type == OPIHI_FLT) { 180 REALLOCATE (vec[0].elements.Flt, opihi_flt, Nelements);180 REALLOCATE (vec[0].elements.Flt, opihi_flt, MAX(1, Nelements)); 181 181 vec[0].type = OPIHI_FLT; 182 182 } else { 183 REALLOCATE (vec[0].elements.Int, opihi_int, Nelements);183 REALLOCATE (vec[0].elements.Int, opihi_int, MAX(1, Nelements)); 184 184 vec[0].type = OPIHI_INT; 185 185 } -
branches/czw_branch/20101203/Ohana/src/opihi/lib.shell/command.c
r27790 r30631 10 10 Command *cmd; 11 11 12 // rawline = NULL; 13 rawline = strcreate (line); 12 // the input line is never NULL 13 if (!line) { fprintf (stderr, "programming error\n"); abort(); } 14 15 rawline = strcreate (line); // used for error messages which should echo the unparsed line 14 16 15 17 /* force a space between ! and first word: !ls becomes ! ls */ … … 22 24 /* expand anything of the form $fred or $fred$sam, etc */ 23 25 line = expand_vars (line); /* line is freed here, new one allocated */ 26 if (!line) goto escape; 27 24 28 /* expand anything of the form fred[N] */ 25 29 line = expand_vectors (line); /* line is freed here, new one allocated */ 30 if (!line) goto escape; 26 31 27 32 // print the line with the variables and vectors expanded, but before evaluating … … 29 34 if (VERBOSE_SHELL == OPIHI_VERBOSE_ON) gprint (GP_ERR, "opihi: %s\n", line); 30 35 31 /* solve math expresions, assign variable, if needed */ 32 line = parse (line); /* line is freed here, new one allocated */ 33 /* any entry in line of the form {foo} returns value or tmp vector / buffer */ 36 /* solve math expresions, assign variable, if needed. any entry in line of the form {foo} 37 * returns value or tmp vector / buffer */ 38 line = parse (&status, line); /* line is freed here, new one allocated */ 39 if (!status) goto escape; 34 40 35 41 /* we may have reallocated line, return new pointer */ … … 39 45 if (argc == 0) { 40 46 FREE (rawline); 47 set_int_variable ("STATUS", TRUE); 41 48 return (TRUE); /* empty command or assignment */ 42 49 } … … 74 81 FREE (rawline); 75 82 return (status); 83 84 escape: 85 set_int_variable ("STATUS", FALSE); 86 87 # if (DEBUG) 88 gprint (GP_ERR, "command: %s, status: %d\n", line, FALSE); 89 # endif 90 91 FREE (rawline); 92 93 if (VERBOSE_SHELL != OPIHI_VERBOSE_OFF) gprint (GP_ERR, "error on line: %s\n", rawline); 94 95 // return the current value of line, in case it was modified 96 *outline = line; 97 return FALSE; 76 98 } 77 99 -
branches/czw_branch/20101203/Ohana/src/opihi/lib.shell/expand_vars.c
r15878 r30631 64 64 /* variable assignment (skip these variables) */ 65 65 if ((L == line) && (V1 != NULL)) { 66 if ((*V1 == '=') || !strcmp (V1, "++") || !strcmp (V1, "--")) { 66 int isAssignment; 67 68 isAssignment = FALSE; 69 isAssignment |= (V1[0] == '='); 70 isAssignment |= (V1[0] == '+') && (V1[1] == '='); 71 isAssignment |= (V1[0] == '-') && (V1[1] == '='); 72 isAssignment |= (V1[0] == '+') && (V1[1] == '+'); 73 isAssignment |= (V1[0] == '-') && (V1[1] == '-'); 74 75 if (isAssignment) { 67 76 *N = *L; 68 77 free (V0); -
branches/czw_branch/20101203/Ohana/src/opihi/lib.shell/parse.c
r27491 r30631 1 1 # include "opihi.h" 2 2 3 char *parse ( char *line) {3 char *parse (int *status, char *line) { 4 4 5 5 double fval; 6 6 float *fptr; 7 7 char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p; 8 int Nx, Ny, Nbytes, status, size, NLINE, isBuffer, inRange;8 int Nx, Ny, Nbytes, filestatus, size, NLINE, isBuffer, inRange; 9 9 FILE *f; 10 10 Vector *vec; 11 11 Buffer *buf; 12 13 *status = TRUE; 12 14 13 15 Ny = 0; … … 49 51 } 50 52 53 if (!strncmp (V1, "+=", 2)) { 54 V1 ++; 55 if (*V1 == 0) goto error; 56 V1 ++; 57 if (*V1 == 0) goto error; 58 59 val = get_variable (V0); 60 if (val == NULL) { 61 fval = 0.0; 62 } else { 63 fval = atof (val); 64 } 65 66 /* dvomath returns a new string, or NULL, with the result of the expression */ 67 val = dvomath (1, &V1, &size, 0); 68 if (val == NULL) goto error; 69 fval += atof(val); 70 // save the result 71 set_variable (V0, fval); 72 goto escape; 73 } 74 75 if (!strncmp (V1, "-=", 2)) { 76 V1 ++; 77 if (*V1 == 0) goto error; 78 V1 ++; 79 if (*V1 == 0) goto error; 80 81 val = get_variable (V0); 82 if (val == NULL) { 83 fval = 0.0; 84 } else { 85 fval = atof (val); 86 } 87 88 /* dvomath returns a new string, or NULL, with the result of the expression */ 89 val = dvomath (1, &V1, &size, 0); 90 if (val == NULL) goto error; 91 fval -= atof(val); 92 // save the result 93 set_variable (V0, fval); 94 goto escape; 95 } 96 51 97 /* not an assignement, syntax error */ 52 98 if (*V1 != '=') goto error; … … 73 119 Nbytes = fread (val, 1, 1023, f); 74 120 val[Nbytes] = 0; 75 status = pclose (f);121 filestatus = pclose (f); 76 122 free (B); 77 123 78 if ( status) gprint (GP_ERR, "warning: exit status of command %d\n",status);124 if (filestatus) gprint (GP_ERR, "warning: exit status of command %d\n", filestatus); 79 125 80 126 /* convert all but last return to ' '. drop last return */ … … 88 134 } 89 135 } 136 // save the resulting value 137 set_str_variable (V0, val); 138 goto escape; /* frees temp variables */ 139 } 140 141 /* simple variable assignment */ 142 /* dvomath returns a new string, or NULL, with the result of the expression */ 143 val = dvomath (1, &V1, &size, 0); 144 if (val == NULL) { 145 while (OHANA_WHITESPACE (*V1)) V1++; 146 val = strcreate (V1); 90 147 } 91 92 /* simple variable assignment */ 93 if (*V1 != '`') { 94 /* dvomath returns a new string, or NULL, with the result of the expression */ 95 val = dvomath (1, &V1, &size, 0); 96 if (val == NULL) { 97 while (OHANA_WHITESPACE (*V1)) V1++; 98 val = strcreate (V1); 99 } 100 } 101 /* both dvomath and command replacement create (char *) val */ 148 // save the result 102 149 set_str_variable (V0, val); 103 150 goto escape; /* frees temp variables */ … … 172 219 if (!inRange) { 173 220 gprint (GP_ERR, "no element %d,%d\n", Nx, Ny); 174 goto e scape;221 goto error; 175 222 } 176 223 if (Nx < 0) Nx += buf[0].header.Naxis[0]; … … 188 235 if (!inRange) { 189 236 gprint (GP_ERR, "no element %d\n", Nx); 190 goto e scape;237 goto error; 191 238 } 192 239 if (Nx < 0) Nx += vec[0].Nelements; … … 197 244 } 198 245 } 199 200 246 goto escape; 201 247 } … … 226 272 if (c1 == NULL) { 227 273 gprint (GP_ERR, "no close brackets!\n"); 228 goto e scape;274 goto error; 229 275 } 230 276 c2 = strchr (L, '{'); 231 277 if ((c2 != NULL) && (c2 < c1)) { 232 278 gprint (GP_ERR, "can't nest brackets!\n"); 233 goto e scape;279 goto error; 234 280 } 235 281 *c1 = 0; … … 240 286 if (val == NULL) { 241 287 print_error (); 242 goto e scape;288 goto error; 243 289 } 244 290 … … 257 303 258 304 REALLOCATE (newline, char, strlen (newline) + 1); 305 *status = TRUE; 259 306 return (newline); 260 307 261 308 error: 262 309 gprint (GP_ERR, "syntax error\n"); 263 264 escape: 310 // assignment or increment operation: free line and return NULL 265 311 if (line != (char *) NULL) free (line); 266 312 if (val != (char *) NULL) free (val); 267 313 if (V0 != (char *) NULL) free (V0); 314 *status = FALSE; 315 return NULL; 316 317 escape: 318 // assignment or increment operation: free line and return NULL 319 if (line != (char *) NULL) free (line); 320 if (val != (char *) NULL) free (val); 321 if (V0 != (char *) NULL) free (V0); 322 *status = TRUE; 268 323 return (NULL); 269 324 } -
branches/czw_branch/20101203/Ohana/src/opihi/lib.shell/stack_math.c
r27435 r30631 972 972 *out = OP; \ 973 973 } \ 974 clear_stack (V1); \ 975 return (TRUE); \ 974 goto escape; \ 976 975 } \ 977 976 if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) { \ … … 982 981 *out = OP; \ 983 982 } \ 984 clear_stack (V1); \ 985 return (TRUE); \ 983 goto escape; \ 986 984 } \ 987 985 if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) { \ … … 992 990 *out = OP; \ 993 991 } \ 994 clear_stack (V1); \ 995 return (TRUE); \ 992 goto escape; \ 996 993 } } 997 994 … … 1035 1032 # undef V_FUNC 1036 1033 1034 escape: 1035 1037 1036 if (V1[0].type == 'v') { 1038 1037 free (V1[0].vector[0].elements.Ptr); -
branches/czw_branch/20101203/Ohana/src/photdbc/include/photdbc.h
r30118 r30631 51 51 double DMGAIN; 52 52 double CHISQ_MAX; 53 double SIGMA_MIN_KEEP; 53 54 double SIGMA_MAX; 54 55 double AVE_SIGMA_LIM; 55 56 int NMEAS_MIN; 57 int NMEAS_MIN_FILTERED; 58 int NCODE_MIN; 56 59 double ZERO_POINT; 60 61 int ExcludeByMinSigma; 57 62 58 63 int ExcludeByInstMag; … … 65 70 SkyRegion REGION; 66 71 PhotCodeData photcodes; 72 73 char *PHOTCODE_DROP_LIST, *PHOTCODE_SKIP_LIST; 74 int NphotcodesDrop, NphotcodesSkip; 75 PhotCode **photcodesDrop, **photcodesSkip; 67 76 68 77 # define FLAG_AREA 0X0001 -
branches/czw_branch/20101203/Ohana/src/photdbc/src/ConfigInit.c
r28331 r30631 26 26 if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file); 27 27 28 WarnConfig (config, "PHOTDBC_JOIN_RADIUS", "%lf", 0, &JOIN_RADIUS); 28 // XXX join_stars (in photdbc.c) is currently disabled 29 // WarnConfig (config, "PHOTDBC_JOIN_RADIUS", "%lf", 0, &JOIN_RADIUS); 30 31 // XXX unique_measures (in photdbc.c) is currently disabled 29 32 // WarnConfig (config, "UNIQ_RADIUS", "%lf", 0, &UNIQ_RADIUS); 30 33 34 // XXX flag_measures (in photdbc.c) is currently disabled 31 35 // WarnConfig (config, "XMIN", "%lf", 0, &XMIN); 32 36 // WarnConfig (config, "XMAX", "%lf", 0, &XMAX); … … 37 41 // WarnConfig (config, "MMIN", "%lf", 0, &tmp); MMIN = 1000*tmp; 38 42 // WarnConfig (config, "MMAX", "%lf", 0, &tmp); MMAX = 1000*tmp; 43 // WarnConfig (config, "CHISQ_MAX", "%lf", 0, &CHISQ_MAX); 44 45 // XXX get_mags (in photdbc.c) is currently disabled 39 46 // WarnConfig (config, "DMSYS", "%lf", 0, &tmp); DMSYS = SQ(1000*tmp); 40 47 // WarnConfig (config, "DMGAIN", "%lf", 0, &DMGAIN); 41 // WarnConfig (config, "CHISQ_MAX", "%lf", 0, &CHISQ_MAX);42 48 43 49 ScanConfig (config, "SIGMA_MAX", "%lf", 0, &SIGMA_MAX); 44 50 ScanConfig (config, "AVE_SIGMA_LIM", "%lf", 0, &AVE_SIGMA_LIM); 45 51 ScanConfig (config, "NMEAS_MIN", "%d", 0, &NMEAS_MIN); 52 ScanConfig (config, "NMEAS_MIN_FILTERED", "%d", 0, &NMEAS_MIN_FILTERED); 46 53 47 54 WarnConfig (config, "GSCFILE", "%s", 0, GSCFILE); -
branches/czw_branch/20101203/Ohana/src/photdbc/src/args.c
r30118 r30631 19 19 ExcludeByInstMag = FALSE; 20 20 if ((N = get_argument (argc, argv, "-instmag"))) { 21 remove_argument (N, &argc, argv);22 21 ExcludeByInstMag = TRUE; 23 22 remove_argument (N, &argc, argv); … … 25 24 remove_argument (N, &argc, argv); 26 25 INST_MAG_MAX = atof(argv[N]); 26 remove_argument (N, &argc, argv); 27 } 28 29 ExcludeByMinSigma = FALSE; 30 if ((N = get_argument (argc, argv, "-min-sigma"))) { 31 ExcludeByMinSigma = TRUE; 32 remove_argument (N, &argc, argv); 33 SIGMA_MIN_KEEP = atof(argv[N]); 34 remove_argument (N, &argc, argv); 27 35 } 28 36 29 37 ExcludeByMaxMinMag = FALSE; 30 38 if ((N = get_argument (argc, argv, "-maxminmag"))) { 31 remove_argument (N, &argc, argv);32 39 ExcludeByMaxMinMag = TRUE; 33 40 remove_argument (N, &argc, argv); 34 41 MAX_MIN_MAG = atof(argv[N]); 42 remove_argument (N, &argc, argv); 35 43 } 36 44 … … 61 69 } 62 70 71 PHOTCODE_DROP_LIST = NULL; 72 if ((N = get_argument (argc, argv, "-photcode-drop"))) { 73 remove_argument (N, &argc, argv); 74 PHOTCODE_DROP_LIST = strcreate(argv[N]); 75 remove_argument (N, &argc, argv); 76 } 77 78 PHOTCODE_SKIP_LIST = NULL; 79 if ((N = get_argument (argc, argv, "-photcode-skip"))) { 80 remove_argument (N, &argc, argv); 81 PHOTCODE_SKIP_LIST = strcreate(argv[N]); 82 remove_argument (N, &argc, argv); 83 } 84 63 85 if (argc != 2) usage(); 64 86 … … 81 103 fprintf (stderr, "USAGE: photdbc (output)\n\n"); 82 104 fprintf (stderr, " this program takes an existing DVO database and makes a copy, applying a number of optional\n"); 83 fprintf (stderr, " filters in the process. \n ");84 fprintf (stderr, "\n"); 85 fprintf (stderr, " photdbc (output)\n ");86 fprintf (stderr, "\n"); 87 fprintf (stderr, " allowed filters / restrictions include:\n ");88 fprintf (stderr, "\n"); 105 fprintf (stderr, " filters in the process. \n\n"); 106 107 fprintf (stderr, " photdbc (output)\n\n"); 108 109 fprintf (stderr, " allowed filters / restrictions include:\n\n"); 110 89 111 fprintf (stderr, " -region Rmin Rmax Dmin Dmax : limit operation to the specified region \n"); 90 fprintf (stderr, " -join : join measurements between stars using JOIN_RADIUS\n"); 91 fprintf (stderr, " -ccdregion X Y X Y : only keep detections within the specified detector region\n"); 92 fprintf (stderr, " (can this be limited to specific photcodes? cameras? detectors?)\n"); 93 fprintf (stderr, " -photcode_limits code Mmin Mmax : allow multiples of these\n"); 94 fprintf (stderr, "\n"); 95 fprintf (stderr, " SIGMA_MAX\n"); 96 fprintf (stderr, " NMEAS_MIN\n"); 97 fprintf (stderr, " INST_MAG_MAX\n"); 98 fprintf (stderr, " INST_MAG_MIN\n"); 112 113 fprintf (stderr, " -photcode-drop : remove these photcodes from the output (REF or DEP only)\n"); 114 fprintf (stderr, " -photcode-skip : ignore these photcodes when assessing the validity (keep unless object is dropped)\n"); 115 116 fprintf (stderr, " -instmag (min) (max) : range of valid instrumental magnitudes (or measurements are dropped)\n"); 117 fprintf (stderr, " -min-sigma (sigma) : object must have one measurement error less than sigma or object is dropped\n"); 118 119 fprintf (stderr, " -maxminmag (mag) : object must have one magnitude less than this or object is dropped\n"); 120 121 fprintf (stderr, " option options:\n"); 122 fprintf (stderr, " -v : verbose mode\n"); 123 fprintf (stderr, " -params : list the current parameters\n\n"); 124 125 fprintf (stderr, "ptolemy.rc config values used by this program:\n"); 126 fprintf (stderr, " SIGMA_MAX : drop measurements with errors greater than this\n"); 127 fprintf (stderr, " NMEAS_MIN : drop objects with fewer measurements than this\n"); 128 fprintf (stderr, " NMEAS_MIN_FILTERED : drop objects with fewer measurements than this after filtering above\n"); 129 fprintf (stderr, " AVE_SIGMA_LIM : drop objects if all average mags are greater than this\n"); 130 99 131 exit (2); 100 132 } 133 134 // fprintf (stderr, " -join : join measurements between stars using JOIN_RADIUS\n"); 135 // fprintf (stderr, " -ccdregion X Y X Y : only keep detections within the specified detector region\n"); 136 // fprintf (stderr, " (can this be limited to specific photcodes? cameras? detectors?)\n"); 137 // fprintf (stderr, " -photcode_limits code Mmin Mmax : allow multiples of these\n"); -
branches/czw_branch/20101203/Ohana/src/photdbc/src/find_images.c
r29001 r30631 122 122 these are measurements from external sources, like USNO */ 123 123 124 assignMcal (&image[nimage], (double *) NULL, -1); 124 // assignMcal (&image[nimage], (double *) NULL, -1); 125 image[nimage].Mcal = 0; 125 126 image[nimage].code = ID_IMAGE_NEW; 126 127 -
branches/czw_branch/20101203/Ohana/src/photdbc/src/initialize.c
r30118 r30631 2 2 3 3 void initialize (int argc, char **argv) { 4 5 int NPHOTCODES; 6 char *codename, *ptr, *list; 4 7 5 8 /* are these set correctly? */ … … 11 14 ConfigInit (&argc, argv); 12 15 args (argc, argv); 16 17 NphotcodesDrop = 0; 18 photcodesDrop = NULL; 19 if (PHOTCODE_DROP_LIST != NULL) { 20 NPHOTCODES = 10; 21 ALLOCATE (photcodesDrop, PhotCode *, NPHOTCODES); 22 23 /* parse the comma-separated list of photcodesDrop */ 24 list = PHOTCODE_DROP_LIST; 25 while ((codename = strtok_r (list, ",", &ptr)) != NULL) { 26 list = NULL; // pass NULL on successive strtok_r calls 27 fprintf (stderr, "PHOTCODE_LIST: %s\n", PHOTCODE_DROP_LIST); 28 fprintf (stderr, "codename: %s\n", codename); 29 if ((photcodesDrop[NphotcodesDrop] = GetPhotcodebyName (codename)) == NULL) { 30 fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename); 31 exit (1); 32 } 33 NphotcodesDrop ++; 34 CHECK_REALLOCATE (photcodesDrop, PhotCode *, NPHOTCODES, NphotcodesDrop, 10); 35 } 36 } 37 38 NphotcodesSkip = 0; 39 photcodesSkip = NULL; 40 if (PHOTCODE_SKIP_LIST != NULL) { 41 NPHOTCODES = 10; 42 ALLOCATE (photcodesSkip, PhotCode *, NPHOTCODES); 43 44 /* parse the comma-separated list of photcodesSkip */ 45 list = PHOTCODE_SKIP_LIST; 46 while ((codename = strtok_r (list, ",", &ptr)) != NULL) { 47 list = NULL; // pass NULL on successive strtok_r calls 48 fprintf (stderr, "PHOTCODE_LIST: %s\n", PHOTCODE_SKIP_LIST); 49 fprintf (stderr, "codename: %s\n", codename); 50 if ((photcodesSkip[NphotcodesSkip] = GetPhotcodebyName (codename)) == NULL) { 51 fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename); 52 exit (1); 53 } 54 NphotcodesSkip ++; 55 CHECK_REALLOCATE (photcodesSkip, PhotCode *, NPHOTCODES, NphotcodesSkip, 10); 56 } 57 } 13 58 14 59 if (SHOW_PARAMS) { -
branches/czw_branch/20101203/Ohana/src/photdbc/src/make_subcatalog.c
r28331 r30631 5 5 int make_subcatalog (Catalog *subcatalog, Catalog *catalog) { 6 6 7 off_t i, j, offset; 7 int found; 8 off_t i, j, k, offset; 8 9 off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm, Nsecfilt; 9 double mag, minMag; 10 int keep; 10 double mag, minMag, minSigma; 11 int keep, *secSkip; 12 PhotCode *photcode; 11 13 12 14 Nsecfilt = GetPhotcodeNsecfilt (); 13 15 assert (catalog[0].Nsecfilt == Nsecfilt); 16 17 // set up a list of SEC entries to ignore when evaluating a source 18 ALLOCATE (secSkip, int, Nsecfilt); 19 for (i = 0; i < Nsecfilt; i++) { 20 secSkip[i] = FALSE; 21 photcode = GetPhotcodebyNsec(i); 22 for (k = 0; k < NphotcodesSkip; k++) { 23 if (photcodesSkip[k][0].code != photcode[0].code) continue; 24 secSkip[i] = TRUE; 25 } 26 } 14 27 15 28 /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */ … … 38 51 } 39 52 53 // exclude stars with too few measurements 54 if (NCODE_MIN) { 55 // drop if all of the allowed average photcodes have ncode < NCODE_MIN values 56 keep = FALSE; 57 for (j = 0; !keep && (j < Nsecfilt); j++) { 58 if (secSkip[j]) continue; 59 if (catalog[0].secfilt[Nsecfilt*i+j].Ncode >= NCODE_MIN) { 60 keep = TRUE; 61 } 62 } 63 if (!keep) continue; 64 } 65 40 66 /* assign average and secfilt values */ 41 67 subcatalog[0].average[Naverage] = catalog[0].average[i]; … … 45 71 } 46 72 47 minMag = 32; 73 minMag = 32; 74 minSigma = 32; 48 75 Nm = 0; 49 76 for (j = 0; j < catalog[0].average[i].Nmeasure; j++) { … … 52 79 53 80 # if 0 54 if (DropPhotcode) {55 ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[offset].photcode);56 if (ecode == photcode[0].code) continue;57 }58 81 if (DropNonStellar && catalog[0].measure[offset].dophot != 1) continue; 59 82 # endif 60 83 61 /* exclude measurements by measurement error */ 84 // remove certain photcodes from the output measurements 85 if (NphotcodesDrop > 0) { 86 found = FALSE; 87 for (k = 0; (k < NphotcodesSkip) && !found; k++) { 88 if (photcodesSkip[k][0].code == catalog[0].measure[offset].photcode) found = TRUE; 89 if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE; 90 } 91 if (found) continue; 92 } 93 94 // ignore certain photcodes to assess the measurements 95 if (NphotcodesSkip > 0) { 96 found = FALSE; 97 for (k = 0; (k < NphotcodesSkip) && !found; k++) { 98 if (photcodesSkip[k][0].code == catalog[0].measure[offset].photcode) found = TRUE; 99 if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(catalog[0].measure[offset].photcode)) found = TRUE; 100 } 101 if (found) goto keep; 102 } 103 104 // exclude measurements by measurement error -- drop exactly this measurement 62 105 if (SIGMA_MAX && (catalog[0].measure[offset].dM > SIGMA_MAX)) continue; 63 106 64 / * select measurements by mag limit */107 // select measurements by mag limit -- drop exactly this measurement 65 108 if (ExcludeByInstMag) { 66 109 mag = PhotInst (&catalog[0].measure[offset]); … … 69 112 } 70 113 114 // check measurements for this object -- drop object if no measurements pass 115 if (ExcludeByMinSigma) { 116 minSigma = MIN (minSigma, catalog[0].measure[offset].dM); 117 } 118 119 // check measurements for this object -- drop object if no measurements pass 71 120 if (ExcludeByMaxMinMag) { 72 121 mag = PhotSys (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]); 73 122 minMag = MIN (minMag, mag); 74 123 } 124 125 keep: 75 126 76 127 subcatalog[0].measure[Nmeasure] = catalog[0].measure[offset]; … … 90 141 } 91 142 92 // after measurement exclusion, exclude stars with too few measurements93 if ( Nm < NMEAS_MIN) {143 // exclude faint objects 144 if (ExcludeByMinSigma && (minSigma > SIGMA_MIN_KEEP)) { 94 145 Nmeasure -= Nm; 95 146 continue; 96 147 } 148 149 // after measurement exclusion, exclude stars with too few measurements 150 if (NMEAS_MIN_FILTERED && (Nm < NMEAS_MIN_FILTERED)) { 151 Nmeasure -= Nm; 152 continue; 153 } 154 97 155 subcatalog[0].average[Naverage].Nmissing = 0; 98 156 subcatalog[0].average[Naverage].Nmeasure = Nm; … … 122 180 return (TRUE); 123 181 } 182 183 /** 184 the purpose of this function is to create a subset database. there are several ways this could be done: 185 186 * reject all measurements from all objects that fail to meet some criteria (objects may lose measurements and/or be dropped) 187 188 * only reject an object if all measurements fail to meet some criteria (ie, keep all measurements if any measurement passes) 189 190 * only apply the keep / reject criteria to certain photcodes 191 192 193 *** 194 195 * options: 196 197 minimum value for nmeas : NMEAS_MIN 198 minimum value for nmeas : NMEAS_MIN_FILTERED 199 minimum value for ncode : NCODE_MIN (drop if all ncode < NCODE_MIN) (respect photcodes) 200 reject faint meas : SIGMA_MAX 201 reject faint source : SIGMA_MIN_KEEP (keep source source if its minimum dMag < this limit) 202 203 **/ -
branches/czw_branch/20101203/Ohana/src/relastro/include/relastro.h
r29001 r30631 26 26 double dPos; 27 27 int mask; 28 int Nmeas; 28 29 } StarData; 29 30 … … 94 95 95 96 double SIGMA_LIM; 96 int SRC_MEAS_TOOFEW; //catalog objects wich fewer detections then this are ignored97 int SRC_MEAS_TOOFEW; //catalog objects wich fewer detections then this are ignored 97 98 double MIN_ERROR; 99 100 int IMFIT_CLIP_NITER; // number of clipping iterations to perform in FitChip 101 double IMFIT_CLIP_NSIGMA; // number of sigma to clip in FitChip 102 double IMFIT_SYS_SIGMA_LIM; // max dMag for objects used to measure systematic scatter 98 103 99 104 double RADIUS; // match radius for high-speed objects … … 141 146 int FlagOutlier; 142 147 int CLIP_THRESH; 148 int USE_BASIC_CHECK; 143 149 144 150 FitMode FIT_MODE; … … 296 302 void fixImageRaw (Catalog *catalog, int Ncatalog, off_t im); 297 303 void FlagOutliers(Catalog *catalog); 298 int MeasFilterTest(Measure *measure );304 int MeasFilterTest(Measure *measure, int applySigmaLim); 299 305 300 306 int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon); … … 325 331 int UpdateObjectOffsets (SkyList *skylist); 326 332 327 int relastroVisualPlot RawRef(StarData *raw, StarData *ref, double dRmax, int numObj);328 int relastroVisualPlotScatter(double values[], double thresh, int npts);329 int relastroVisualPlotOutliers(Catalog *catalog, int offset, int Nmeasure, 330 StatType statsR, StatType statsD, double thresh);331 332 333 int relastroVisualPlotChipFit(StarData *raw, StarData *ref, double dRmax, int numObj); 334 // int relastroVisualPlotRawRef(StarData *raw, StarData *ref, double dRmax, int numObj); 335 // int relastroVisualPlotScatter(double values[], double thresh, int npts); 336 // int relastroVisualPlotOutliers(Catalog *catalog, int offset, int Nmeasure, StatType statsR, StatType statsD, double thresh); 337 void relastroSetVisual(int state); 338 int relastroGetVisual(void); 333 339 334 340 int FixProblemImages (SkyList *skylist); … … 352 358 int createStarMapPoints(); 353 359 int checkStarMap(int N); 360 361 int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit); -
branches/czw_branch/20101203/Ohana/src/relastro/src/ConfigInit.c
r29001 r30631 19 19 if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file); 20 20 21 GetConfig (config, "RELASTRO_SIGMA_LIM", "%lf", 0, &SIGMA_LIM);21 GetConfig (config, "RELASTRO_SIGMA_LIM", "%lf", 0, &SIGMA_LIM); // exclude measurements on this basis 22 22 GetConfig (config, "RELASTRO_SRC_MEAS_TOOFEW", "%d", 0, &SRC_MEAS_TOOFEW); 23 24 if (!ScanConfig (config, "RELASTRO_IMFIT_CLIP_NITER", "%d", 0, &IMFIT_CLIP_NITER)) IMFIT_CLIP_NITER = 3; 25 if (!ScanConfig (config, "RELASTRO_IMFIT_CLIP_NSIGMA", "%lf", 0, &IMFIT_CLIP_NSIGMA)) IMFIT_CLIP_NSIGMA = 3.0; 26 if (!ScanConfig (config, "RELASTRO_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01; 23 27 24 28 // XXX these are used in relphot to identify poor stars / images -- define -
branches/czw_branch/20101203/Ohana/src/relastro/src/FitChip.c
r29001 r30631 2 2 # include "relastroVisual.h" 3 3 4 // XXX make these user parameters5 # define FIT_CHIP_NITER 36 # define FIT_CHIP_NSIGMA 3.07 8 // XXX save the fit[0].Npts value in the image table?9 10 // XXX save measurements of the fit quality (scatter, chisq) in the image table11 12 4 int FitChip (StarData *raw, StarData *ref, int Nmatch, Image *image) { 13 5 14 int i, Nscatter, Niter, skip; 15 CoordFit *fit; 16 double dL, dM, dR, dRmax, *values; 17 18 ALLOCATE (values, double, Nmatch); 19 for (Niter = 0; Niter < FIT_CHIP_NITER; Niter ++) { 6 int i, NstatFull, Nstat, Niter, skip; 7 float dLsig, dMsig, dRsig; 8 float dLsigFull, dMsigFull, dRsigFull; 9 float dL, dM, dR, dRmax; 10 11 CoordFit *fit = NULL; 12 13 dRmax = 0.0; 14 15 for (Niter = 0; Niter < IMFIT_CLIP_NITER; Niter ++) { 16 17 // measure the scatter for the unmarked (good) measurements with dM < limit 18 // SIGMA_LIM here is redundant with ImageOps.c:915 19 GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nmatch, SIGMA_LIM); 20 dRmax = IMFIT_CLIP_NSIGMA*dRsig; 21 22 // (a) skip unfittable points 23 // (b) mark good and bad points for fit (in and outliers) 20 24 21 25 // measure the scatter distribution (use only the bright end detections) 22 for (i = Nscatter =0; i < Nmatch; i++) {26 for (i = 0; i < Nmatch; i++) { 23 27 if (raw[i].mask) continue; 24 if (isnan(raw[i].dMag) || raw[i].dMag > SIGMA_LIM) continue; 28 if (isnan(raw[i].dMag)) { 29 raw[i].mask |= 0x0004; 30 continue; 31 } 32 if (raw[i].dMag > SIGMA_LIM) { 33 raw[i].mask |= 0x0008; 34 continue; 35 } // is this redundant with ImageOps.c:915? 25 36 26 37 dL = raw[i].L - ref[i].L; 27 38 dM = raw[i].M - ref[i].M; 28 39 dR = hypot (dL, dM); 29 30 values[Nscatter] = dR; 31 Nscatter++; 32 } 33 34 if (Nscatter > 5) { 35 // for a 2D Gaussian, 40% of the points are within 1 sigma; dRmax is ~ 3 sigma 36 // XXX this test is not sensible for Nscatter < XXX (5?) 37 dsort (values, Nscatter); 38 dRmax = FIT_CHIP_NSIGMA*values[(int)(0.40*Nscatter)]; 39 relastroVisualPlotScatter(values, dRmax, Nscatter); 40 relastroVisualPlotRawRef(raw, ref, dRmax, Nmatch); 41 } else { 42 dRmax = 0; 43 } 40 if (dR > dRmax) { 41 raw[i].mask |= 0x0010; 42 continue; 43 } 44 } 45 46 // figures to assess the fitting process: 47 // x vs dx, x vs dy, y vs dx, y vs dy : 48 // residual vector field 49 // dx vs mag, dy vs mag 50 relastroVisualPlotChipFit(raw, ref, dRmax, Nmatch); 44 51 45 52 // fit the requested order polynomial … … 47 54 image[0].coords.Npolyterms = CHIPORDER; 48 55 } 56 if (fit) fit_free (fit); 49 57 fit = fit_init (image[0].coords.Npolyterms); 50 58 51 59 // generate the fit matches 52 60 for (i = 0; i < Nmatch; i++) { 53 if (raw[i].mask) { 54 continue; 55 } 56 if (isnan(raw[i].dMag) || raw[i].dMag > SIGMA_LIM) { 57 continue; 58 } 59 60 // only keep objects within dRmax 61 dL = raw[i].L - ref[i].L; 62 dM = raw[i].M - ref[i].M; 63 dR = hypot (dL, dM); 64 65 // fprintf (stderr, "fit %f %f -> %f %f : %f %f (%f vs %f) wt: %f\n", raw[i].X, raw[i].Y, ref[i].L, ref[i].M, raw[i].L, raw[i].M, dR, dRmax, raw[i].dPos); 66 67 if ((dRmax > 0.0) && (dR > dRmax)) continue; 68 61 if (raw[i].mask) continue; 69 62 fit_add (fit, raw[i].X, raw[i].Y, ref[i].L, ref[i].M, raw[i].dPos); 70 63 } … … 88 81 } 89 82 if (skip) { 90 if (VERBOSE ) fprintf (stderr, "insufficient measurements (%d) for requested order (%d)\n", fit[0].Npts, image[0].coords.Npolyterms);83 if (VERBOSE2) fprintf (stderr, "insufficient measurements (%d) for requested order (%d)\n", fit[0].Npts, image[0].coords.Npolyterms); 91 84 fit_free (fit); 92 free (values);93 85 image[0].flags |= ID_IMAGE_ASTROM_FEW; 94 86 return FALSE; 95 87 } 96 97 // fprintf (stderr, "scatter limit: %f based on %d detections; using %d of %d for fit\n", dRmax, Nscatter, fit[0].Npts, Nmatch);98 88 99 89 // measure the fit, update the coords & object coordinates … … 110 100 } 111 101 112 fit_free (fit);113 114 102 for (i = 0; i < Nmatch; i++) { 115 103 XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[0].coords); … … 118 106 } 119 107 120 free (values); 108 // count mask classes 109 int nMask1 = 0; 110 int nMask2 = 0; 111 int nMask3 = 0; 112 int nMask4 = 0; 113 int nMask5 = 0; 114 for (i = 0; i < Nmatch; i++) { 115 if (!raw[i].mask) continue; 116 if (raw[i].mask & 0x01) nMask1 ++; 117 if (raw[i].mask & 0x02) nMask2 ++; 118 if (raw[i].mask & 0x04) nMask3 ++; 119 if (raw[i].mask & 0x08) nMask4 ++; 120 if (raw[i].mask & 0x10) nMask5 ++; 121 } 122 123 GetScatterRawRef(&dLsigFull, &dMsigFull, &dRsigFull, &NstatFull, raw, ref, Nmatch, SIGMA_LIM); 124 GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nmatch, IMFIT_SYS_SIGMA_LIM); 125 126 int Nm = 0; 127 int Ns = 0; 128 for (i = 0; i < Nmatch; i++) { 129 if (raw[i].mask) continue; 130 Nm += raw[i].Nmeas; 131 Ns++; 132 } 133 image[0].nLinkAstrom = (Nm / Ns); 134 135 if (VERBOSE) fprintf (stderr, "fit sigma: %f (%f, %f) : full: %f (%f, %f), scatter limit: %f (%d full, %d bright, %d fit, %d all) (%d %d %d %d %d)\n", dRsig, dLsig, dMsig, dRsigFull, dLsigFull, dMsigFull, dRmax, NstatFull, Nstat, fit[0].Npts, Nmatch, nMask1, nMask2, nMask3, nMask4, nMask5); 136 137 image[0].dXpixSys = dLsig; 138 image[0].dYpixSys = dMsig; 139 image[0].nFitAstrom = fit[0].Npts; 140 141 if (fit) fit_free (fit); 142 121 143 return TRUE; 144 } 145 146 // measure the scatter distribution (limit selected objects by dMag) 147 int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit) { 148 149 int i, Ns; 150 float dL, dM, dLsum, dLsum2, dMsum, dMsum2, *dR; 151 152 ALLOCATE (dR, float, Nstars); 153 154 Ns = 0; 155 dLsum = dLsum2 = dMsum = dMsum2 = 0.0; 156 for (i = 0; i < Nstars; i++) { 157 if (raw[i].mask) continue; 158 if (isnan(raw[i].dMag)) continue; 159 if ((SigmaLimit > 0.0) && (raw[i].dMag > SigmaLimit)) continue; 160 161 dL = raw[i].L - ref[i].L; 162 dM = raw[i].M - ref[i].M; 163 164 dLsum += dL; 165 dLsum2 += dL*dL; 166 dMsum += dM; 167 dMsum2 += dM*dM; 168 169 dR[Ns] = hypot (dL, dM); 170 Ns++; 171 } 172 173 *dLsig = sqrt((dLsum2 / Ns) - SQ(dLsum/Ns)); 174 *dMsig = sqrt((dMsum2 / Ns) - SQ(dMsum/Ns)); 175 *nKeep = Ns; 176 177 if (Ns < 5) { 178 *dRsig = NAN; 179 free (dR); 180 return (FALSE); 181 } 182 183 // for a 2D Gaussian, 40% of the points are within R = 1 sigma 184 fsort (dR, Ns); 185 *dRsig = dR[(int)(0.40*Ns)]; 186 187 free (dR); 188 return (TRUE); 122 189 } 123 190 … … 162 229 fclose (f); 163 230 */ 231 -
branches/czw_branch/20101203/Ohana/src/relastro/src/GetAstromError.c
r30118 r30631 1 1 # include "relastro.h" 2 # define WEIGHTED_ERRORS 1 2 3 3 4 float GetAstromError (Measure *measure, int mode) { 4 //BIG HACKXXXXXXXX 5 return 0.1; 5 6 6 PhotCode *code; 7 float dPobs, dPsys, dPtotal, dM, AS, MS; 7 float dPobs, dPsys, dPtotal, dM, AS, MS, dX, dY; 8 9 if (!WEIGHTED_ERRORS) { 10 // if we don't understand the errors at all, this at least lets us get things roughly 11 // right: 12 return 0.1; 13 } 14 8 15 switch (mode) { 9 16 case ERROR_MODE_RA: 10 dPobs = measure[0].dXccd / 100.0; // need to redefine this as RAerr17 dPobs = FromShortPixels(measure[0].dXccd); // dXccd is a value in pixels 11 18 break; 12 19 case ERROR_MODE_DEC: 13 dPobs = measure[0].dYccd / 100.0; // need to redefine this as RAerr20 dPobs = FromShortPixels(measure[0].dYccd); // dYccd is a value in pixels 14 21 break; 15 22 case ERROR_MODE_POS: 16 dPobs = hypot (measure[0].dXccd, measure[0].dYccd) / 100.0; // need to redefine this as RAerr 23 dX = FromShortPixels(measure[0].dXccd); // dXccd is a value in pixels 24 dY = FromShortPixels(measure[0].dYccd); // dYccd is a value in pixels 25 dPobs = hypot (dX, dY); 17 26 break; 18 27 default: 19 28 abort(); 20 29 } 21 /* the astrometric errors are not being carried yet (but should be!) */22 /* we use the photometric mag error as a weighting term */23 30 24 31 code = GetPhotcodebyCode (measure[0].photcode); … … 27 34 dPsys = code[0].astromErrSys; 28 35 dM = measure[0].dM; 29 dPtotal = sqrt(SQ(dPsys) + AS*SQ(dPobs) + MS*SQ(dM)); 30 31 //XXX dXccd, dYccd are now working correctly 32 //dPtotal = AS * dPobs; 36 dPtotal = sqrt(SQ(dPsys) + SQ(AS*dPobs) + SQ(MS*dM)); 33 37 34 38 dPtotal = MAX (dPtotal, MIN_ERROR); … … 36 40 } 37 41 42 /* for a long time, psphot was either not reported position errors, or was reporting 43 * completely wrong astrometry errors. This function lets us handle, in the 44 * configuration, different strategies to generating a position error 45 * 46 * astrometry systematic error : this is the minimum expected per-position error. You 47 * should probably measure this from you data. watch out for the chicken and egg problem! 48 * 49 * astrometry error scale : this field lets you accept position errors in (say) pixels and 50 * convert them with this term to arcsec. AS : pixel scale in arcsec 51 * 52 * astrometry mag scale : this field lets you define position errors based on the 53 * photometry error. the scale factor should be something like a typical seeing number 54 * (in arcsec) for the given instrument 55 * 56 */ -
branches/czw_branch/20101203/Ohana/src/relastro/src/ImageOps.c
r29001 r30631 146 146 free (clist); 147 147 free (mlist); 148 free (Nlist); 149 free (NLIST); 148 150 } 149 151 … … 325 327 for (j = 0; j < average[0].Nmeasure; j++) { 326 328 off = average[0].measureOffset + j; 327 fprintf (stderr, " %f, %f\n", measure[off].dR, measure[off].dD);329 fprintf (stderr, "dR, dD, mag, dMag: %f, %f, %f, %f\n", measure[off].dR, measure[off].dD, measure[off].M, measure[off].dM); 328 330 } 329 331 return; … … 336 338 off_t i, m, c, n, nPos; 337 339 double X, Y, L, M, P, Q, R, D, dR, dD; 338 double dPos, DPOS_MAX_ASEC;340 double dPos, dPosSys, DPOS_MAX_ASEC; 339 341 340 342 Mosaic *mosaic; … … 359 361 } 360 362 361 // accumulate the rms position offsets. if this value, or any specific entry, is too362 // large, we will reset the image to the original coords at the end of the analysis363 363 // these are used to accumulate the rms position offsets. if this value, or any 364 // specific entry, is too large, we will reset the image to the original coords at the 365 // end of the analysis 364 366 dPos = 0.0; 365 367 nPos = 0; 368 369 // convert the image systematic error in pixels to a value in arcsec 370 { 371 double dLsig, dMsig; 372 double Ro, Do, Rx, Dx, dP0, dP1; 373 Coords *coords; 374 375 // these values are in pixels, but we to convert to arcsec 376 dLsig = image[0].dXpixSys; 377 dMsig = image[0].dYpixSys; 378 379 if (moscoords == NULL) { 380 coords = imcoords; 381 } else { 382 coords = moscoords; 383 } 384 XY_to_LM (&Ro, &Do, 0.0, 0.0, coords); 385 XY_to_LM (&Rx, &Dx, dLsig, 0.0, coords); 386 dP0 = 3600.0 * hypot(Rx - Ro, Dx - Do); // convert to arcsec 387 XY_to_LM (&Rx, &Dx, 0.0, dLsig, coords); 388 dP1 = 3600.0 * hypot(Rx - Ro, Dx - Do); // convert to arcsec 389 dPosSys = 0.5 * (dP0 + dP1); 390 } 366 391 367 392 for (i = 0; i < Nlist[im]; i++) { … … 390 415 // complain if the new location is far from the average location 391 416 // NOTE: This should never happen, or our StarMap tests are not working 392 if (fabs(dR) > 1.5*ADDSTAR_RADIUS) {417 if (fabs(dR) > 3.0*ADDSTAR_RADIUS) { 393 418 fprintf (stderr, "measurement is far from average location (R): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 394 419 dump_measures (&catalog[c].average[n], catalog[c].measure); 395 420 // abort (); 396 421 } 397 if (fabs(dD) > 1.5*ADDSTAR_RADIUS) {422 if (fabs(dD) > 3.0*ADDSTAR_RADIUS) { 398 423 fprintf (stderr, "measurement is far from average location (D): %f %f (%f %f)\n", catalog[c].average[n].R, catalog[c].average[n].D, dR, dD); 399 424 dump_measures (&catalog[c].average[n], catalog[c].measure); … … 418 443 catalog[c].measure[m].dR = dR; 419 444 catalog[c].measure[m].dD = dD; 420 445 421 446 if (catalog[c].measure[m].dR > +180.0*3600.0) { 422 447 // average on high end of boundary, move star up … … 429 454 catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R); 430 455 } 456 457 // set the systematic error for this image: 458 catalog[c].measure[m].dRsys = ToShortPixels(dPosSys); 431 459 } 432 460 … … 544 572 545 573 // an object with only one detection provides no information about the image calibration 546 //XXX this is already taken care of in bcatalog 547 raw[i].mask = FALSE; 548 int mask = FALSE; 574 // XXX this is already taken care of in bcatalog 575 raw[i].mask = 0x0000; 549 576 if (catalog[c].average[n].Nmeasure <= SRC_MEAS_TOOFEW) { 550 mask = TRUE;577 raw[i].mask |= 0x0001; 551 578 } 552 579 if (!finite(catalog[c].measure[m].dR) || !finite(catalog[c].measure[m].dD)) { 553 mask = TRUE; 554 } 555 556 raw[i].mask = mask; 557 580 raw[i].mask |= 0x0002; 581 } 582 raw[i].Nmeas = catalog[c].average[n].Nmeasure; // record so we can check how well connected an image is 558 583 559 584 switch (mode) { … … 685 710 686 711 // skip measurements based on user selected criteria 687 if (!MeasFilterTest(&catalog[0].measure[m] )) continue;712 if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue; 688 713 R[N] = catalog[0].measure[m].dR; 689 714 D[N] = catalog[0].measure[m].dD; … … 711 736 712 737 // skip measurements based on user selected criteria 713 if (!MeasFilterTest(&catalog[0].measure[m] )) continue;738 if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue; 714 739 715 740 x = catalog[0].measure[m].dR - statsR.median; … … 725 750 } 726 751 727 //examine results 728 relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, 729 catalog[0].average[j].Nmeasure, 730 statsR, statsD, Ns); 752 // examine results 753 // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns); 731 754 } 732 755 … … 784 807 785 808 // skip measurements based on user selected criteria 786 if (!MeasFilterTest(&catalog[0].measure[m] )) continue;809 if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue; 787 810 R[N] = catalog[0].measure[m].dR; 788 811 D[N] = catalog[0].measure[m].dD; … … 806 829 for (k = 0; k < catalog[0].average[j].Nmeasure; k++, m++) { 807 830 //skip bad measurements 808 if (!MeasFilterTest(&catalog[0].measure[m] )) continue;831 if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue; 809 832 x = catalog[0].measure[m].dR - statsR.median; 810 833 y = catalog[0].measure[m].dD - statsD.median; … … 838 861 for (k = 0; k < catalog[0].average[j].Nmeasure; k++, m++) { 839 862 //skip bad measurements 840 if (!MeasFilterTest(&catalog[0].measure[m] )) continue;863 if (!MeasFilterTest(&catalog[0].measure[m], FALSE)) continue; 841 864 x = catalog[0].measure[m].dR - statsR.median; 842 865 y = catalog[0].measure[m].dD - statsD.median; … … 852 875 } //done rejecting outliers 853 876 854 //examine results 855 relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, 856 catalog[0].average[j].Nmeasure, 857 statsR, statsD, Ns); 877 // examine results 878 // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns); 858 879 859 880 } //done looping over objects … … 871 892 872 893 /** Determine whether a measurement should be included in the analysis, based on supplied filter criteria */ 873 int MeasFilterTest(Measure *measure) { 894 // we only optionally apply the sigma limit: for object averages, this should not be used (should it?) 895 int MeasFilterTest(Measure *measure, int applySigmaLim) { 874 896 int found, k; 875 897 long mask; … … 917 939 918 940 /* select measurements by measurement error */ 919 if ((SIGMA_LIM > 0) && (measure[0].dM > SIGMA_LIM)) return FALSE; 941 if (applySigmaLim && (SIGMA_LIM > 0) && (measure[0].dM > SIGMA_LIM)) { 942 return FALSE; 943 } 920 944 921 945 /* select measurements by mag limit */ -
branches/czw_branch/20101203/Ohana/src/relastro/src/StarMaps.c
r29001 r30631 79 79 starmap[N].stars[ybin*NX_MAP + xbin] ++; 80 80 } 81 MARKTIME("assign stars to starmap bins: %f sec\n", dtime);81 if (VERBOSE2) { MARKTIME("assign stars to starmap bins: %f sec\n", dtime); } 82 82 83 83 return (TRUE); … … 117 117 } 118 118 119 if (VERBOSE ) fprintf (stderr, "starmap: %d points for image %s\n", starmap[i].Npoints, images[i].name);119 if (VERBOSE2) fprintf (stderr, "starmap: %d points for image %s\n", starmap[i].Npoints, images[i].name); 120 120 } 121 121 … … 145 145 } 146 146 147 if (VERBOSE ) fprintf (stderr, "max deviations for %s using %d pts : %f, %f\n", images[N].name, starmap[N].Npoints, dLmax, dMmax);147 if (VERBOSE2) fprintf (stderr, "max deviations for %s using %d pts : %f, %f\n", images[N].name, starmap[N].Npoints, dLmax, dMmax); 148 148 149 if (dLmax > DPOS_MAX) return (FALSE); 150 if (dMmax > DPOS_MAX) return (FALSE); 149 if (dLmax > DPOS_MAX) { 150 if (VERBOSE) fprintf (stderr, "max deviations for %s using %d pts : %f, %f\n", images[N].name, starmap[N].Npoints, dLmax, dMmax); 151 return (FALSE); 152 } 153 if (dMmax > DPOS_MAX) { 154 if (VERBOSE) fprintf (stderr, "max deviations for %s using %d pts : %f, %f\n", images[N].name, starmap[N].Npoints, dLmax, dMmax); 155 return (FALSE); 156 } 151 157 return (TRUE); 152 158 } -
branches/czw_branch/20101203/Ohana/src/relastro/src/UpdateChips.c
r29001 r30631 1 1 # include "relastro.h" 2 int plotChipFits (double *Ro, double *Do, char *mode, int Nimage); 3 int saveCenter (Image *image, double *Ro, double *Do, int im); 2 4 3 5 int UpdateChips (Catalog *catalog, int Ncatalog) { 4 6 7 int Nskip, Nmosaic, NnewFit, NoldFit; 8 5 9 /* we can measure new image parameters for each non-mosaic chip independently */ 6 off_t i, Nimage, Nraw, Nref ;10 off_t i, Nimage, Nraw, Nref, nFitAstr; 7 11 Image *image; 8 12 StarData *raw, *ref; 9 13 Coords *oldCoords; 14 float dXpixSys, dYpixSys; 15 double *Ro, *Do; 16 char *mode; 17 18 Nskip = Nmosaic = NnewFit = NoldFit = 0; 10 19 11 20 image = getimages (&Nimage); 12 21 22 // save fit results for summary plot 23 ALLOCATE (Ro, double, Nimage); 24 ALLOCATE (Do, double, Nimage); 25 ALLOCATE (mode, char, Nimage); 26 13 27 for (i = 0; i < Nimage; i++) { 14 28 15 29 /* skip all except WRP images */ 16 if (strcmp(&image[i].coords.ctype[4], "-WRP")) continue; 30 if (strcmp(&image[i].coords.ctype[4], "-WRP")) { 31 Nmosaic ++; 32 mode[i] = 0; 33 continue; 34 } 17 35 18 36 /* convert measure coordinates to raw entries */ 19 37 raw = getImageRaw (catalog, Ncatalog, i, &Nraw, MODE_MOSAIC); 20 if (!raw) continue; 38 if (!raw) { 39 Nskip ++; 40 mode[i] = 0; 41 continue; 42 } 21 43 22 44 /* convert average coordinates to ref entries */ 23 45 ref = getImageRef (catalog, Ncatalog, i, &Nref, MODE_MOSAIC); 24 if (!ref) continue; 46 if (!ref) { 47 Nskip ++; 48 mode[i] = 0; 49 continue; 50 } 25 51 26 52 // note that Nraw & Nref must be equal: if not, we made a programming error in one of these two functions. 27 53 assert (Nraw == Nref); 28 54 55 // save these in case of failure 29 56 saveCoords (&image[i].coords, i); 57 dXpixSys = image[i].dXpixSys; 58 dYpixSys = image[i].dYpixSys; 59 nFitAstr = image[i].nFitAstrom; 30 60 31 61 // FitChip does iterative, clipped fitting … … 33 63 if (!FitChip (raw, ref, Nraw, &image[i])) { 34 64 if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name, i, Nraw); 65 66 // restore status quo ante 35 67 oldCoords = getCoords (i); 36 68 memcpy (&image[i].coords, oldCoords, sizeof(Coords)); 69 image[i].dXpixSys = dXpixSys; 70 image[i].dYpixSys = dYpixSys; 71 image[i].nFitAstrom = nFitAstr; 72 73 saveCenter (image, &Ro[i], &Do[i], i); 74 mode[i] = 1; 75 NoldFit ++; 37 76 free (raw); 38 77 free (ref); … … 42 81 if (!checkStarMap (i)) { 43 82 if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name, i, Nraw); 83 // restore status quo ante 44 84 oldCoords = getCoords (i); 45 85 memcpy (&image[i].coords, oldCoords, sizeof(Coords)); 86 image[i].dXpixSys = dXpixSys; 87 image[i].dYpixSys = dYpixSys; 88 image[i].nFitAstrom = nFitAstr; 89 90 saveCenter (image, &Ro[i], &Do[i], i); 91 mode[i] = 2; 46 92 image[i].flags |= ID_IMAGE_ASTROM_POOR; 47 } 48 93 NoldFit ++; 94 free (raw); 95 free (ref); 96 continue; 97 } 98 99 saveCenter (image, &Ro[i], &Do[i], i); 100 mode[i] = 3; 101 NnewFit ++; 49 102 free (raw); 50 103 free (ref); 51 104 } 52 105 106 plotChipFits (Ro, Do, mode, Nimage); 107 108 fprintf (stderr, "UpdateChips: %d fitted, %d keep old, %d skipped, %d mosaic (skipped)\n", NnewFit, NoldFit, Nskip, Nmosaic); 53 109 return (TRUE); 54 110 } 55 111 112 int saveCenter (Image *image, double *Ro, double *Do, int im) { 113 114 Mosaic *mosaic; 115 Coords *moscoords, *imcoords; 116 double X, Y, L, M, P, Q, R, D; 117 118 moscoords = NULL; 119 if (!strcmp(&image[im].coords.ctype[4], "-WRP")) { 120 mosaic = getMosaicForImage (im); 121 if (mosaic == NULL) return FALSE; // if we cannot find the associated image, skip it 122 moscoords = &mosaic[0].coords; 123 } 124 imcoords = &image[im].coords; 125 126 if (!strcmp(&image[im].coords.ctype[4], "-WRP")) { 127 X = 0.5*image[im].NX; 128 Y = 0.5*image[im].NY; 129 } else { 130 X = 0.0; 131 Y = 0.0; 132 } 133 134 if (moscoords == NULL) { 135 // this is a Simple image (not a mosaic) 136 // note that for a Simple image, L,M = P,Q 137 XY_to_LM (&L, &M, X, Y, imcoords); 138 LM_to_RD (&R, &D, L, M, imcoords); 139 } else { 140 XY_to_LM (&L, &M, X, Y, imcoords); 141 XY_to_LM (&P, &Q, L, M, moscoords); 142 LM_to_RD (&R, &D, P, Q, moscoords); 143 } 144 145 double Rmid; 146 if (UserCatalog) { 147 Rmid = UserCatalogRA; 148 } else { 149 Rmid = 0.5*(UserPatch.Rmin + UserPatch.Rmax); 150 } 151 152 R = ohana_normalize_angle_to_midpoint (R, Rmid); 153 154 *Ro = R; 155 *Do = D; 156 157 return (TRUE); 158 } 159 160 int plotChipFits (double *Ro, double *Do, char *mode, int Nimage) { 161 162 static int kapa = -1; 163 164 int i, N; 165 double Rmin, Rmax, Dmin, Dmax; 166 float *xvec, *yvec; 167 Graphdata graphdata; 168 169 if (!relastroGetVisual()) return (TRUE); 170 171 if (kapa == -1) { 172 kapa = KapaOpenNamedSocket("kapa", "relastro"); 173 if (kapa == -1) { 174 fprintf (stderr, "can't open kapa window\n"); 175 return FALSE; 176 } 177 } 178 179 Rmin = +720; 180 Rmax = -720; 181 Dmin = +90; 182 Dmax = -90; 183 184 // find the R, D range 185 for (i = 0; i < Nimage; i++) { 186 if (!mode[i]) continue; 187 188 Rmin = MIN(Rmin, Ro[i]); 189 Rmax = MAX(Rmax, Ro[i]); 190 Dmin = MIN(Dmin, Do[i]); 191 Dmax = MAX(Dmax, Do[i]); 192 } 193 194 ALLOCATE (xvec, float, Nimage); 195 ALLOCATE (yvec, float, Nimage); 196 197 bzero (&graphdata, sizeof(Graphdata)); 198 plot_defaults (&graphdata); 199 graphdata.xmin = Rmin; 200 graphdata.xmax = Rmax; 201 graphdata.ymin = Dmin; 202 graphdata.ymax = Dmax; 203 graphdata.style = 2; 204 graphdata.size = 1; 205 206 KapaSetFont (kapa, "helvetica", 14); 207 KapaSetLimits (kapa, &graphdata); 208 KapaBox (kapa, &graphdata); 209 210 // *** good images *** 211 N = 0; 212 for (i = 0; i < Nimage; i++) { 213 if (mode[i] != 3) continue; 214 xvec[N] = Ro[i]; 215 yvec[N] = Do[i]; 216 N++; 217 } 218 graphdata.ptype = 7; 219 graphdata.color = KapaColorByName("black"); 220 KapaPrepPlot (kapa, N, &graphdata); 221 KapaPlotVector (kapa, N, xvec, "x"); 222 KapaPlotVector (kapa, N, yvec, "y"); 223 224 // *** reject fit *** 225 N = 0; 226 for (i = 0; i < Nimage; i++) { 227 if (mode[i] != 1) continue; 228 xvec[N] = Ro[i]; 229 yvec[N] = Do[i]; 230 N++; 231 } 232 graphdata.ptype = 3; 233 graphdata.color = KapaColorByName("red"); 234 KapaPrepPlot (kapa, N, &graphdata); 235 KapaPlotVector (kapa, N, xvec, "x"); 236 KapaPlotVector (kapa, N, yvec, "y"); 237 238 // *** divergent fit *** 239 N = 0; 240 for (i = 0; i < Nimage; i++) { 241 if (mode[i] != 2) continue; 242 xvec[N] = Ro[i]; 243 yvec[N] = Do[i]; 244 N++; 245 } 246 graphdata.ptype = 2; 247 graphdata.color = KapaColorByName("blue"); 248 KapaPrepPlot (kapa, N, &graphdata); 249 KapaPlotVector (kapa, N, xvec, "x"); 250 KapaPlotVector (kapa, N, yvec, "y"); 251 252 free (xvec); 253 free (yvec); 254 255 return (TRUE); 256 } 257 258 // XXX if (!FindMosaicForImage (image, Nimage, i)) { } -
branches/czw_branch/20101203/Ohana/src/relastro/src/UpdateObjectOffsets.c
r27581 r30631 40 40 UpdateMeasures (&catalog, 1); 41 41 42 UpdateObjects (&catalog, 1); 43 42 44 freeImageBins (1); 43 45 -
branches/czw_branch/20101203/Ohana/src/relastro/src/UpdateObjects.c
r30118 r30631 103 103 104 104 //does the measurement pass the supplied filtering constraints? 105 if (!MeasFilterTest(&catalog[i].measure[m] )) {105 if (!MeasFilterTest(&catalog[i].measure[m], FALSE)) { 106 106 catalog[i].measure[m].dbFlags &= ~ID_MEAS_USED_OBJ; 107 107 continue; … … 134 134 135 135 // dX, dY : error in arcsec -- 136 // dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA); 137 // dY[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC); 138 139 dX[N] = 0.1; 140 dY[N] = 0.1; 136 dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA); 137 dY[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC); 138 139 // add systematic error in quadrature, if desired 140 // only do this after the fit has converged (or you will never improve the poor images) 141 // if (INCLUDE_SYS_ERR) { 142 // float dRsys = FromShortPixels(catalog[i].measure[m].dRsys); 143 // dX[N] = hypot(dX[N], dRsys); 144 // dY[N] = hypot(dY[N], dRsys); 145 // } 146 147 // dX[N] = 0.1; 148 // dY[N] = 0.1; 149 141 150 dT[N] = catalog[i].measure[m].dt; 142 151 -
branches/czw_branch/20101203/Ohana/src/relastro/src/args.c
r28184 r30631 13 13 remove_argument (N, &argc, argv); 14 14 FIT_TARGET = TARGET_OBJECTS; 15 16 // check for object fitting modes (not valid for images) 17 if ((N = get_argument (argc, argv, "-pm"))) { 18 remove_argument (N, &argc, argv); 19 FIT_MODE = FIT_PM_ONLY; 20 } 21 if ((N = get_argument (argc, argv, "-par"))) { 22 remove_argument (N, &argc, argv); 23 FIT_MODE = FIT_PAR_ONLY; 24 } 25 if ((N = get_argument (argc, argv, "-pmpar"))) { 26 remove_argument (N, &argc, argv); 27 FIT_MODE = FIT_PM_AND_PAR; 28 } 29 } 15 } 16 17 // check for object fitting modes 18 if ((N = get_argument (argc, argv, "-pm"))) { 19 remove_argument (N, &argc, argv); 20 FIT_MODE = FIT_PM_ONLY; 21 } 22 if ((N = get_argument (argc, argv, "-par"))) { 23 remove_argument (N, &argc, argv); 24 FIT_MODE = FIT_PAR_ONLY; 25 } 26 if ((N = get_argument (argc, argv, "-pmpar"))) { 27 remove_argument (N, &argc, argv); 28 FIT_MODE = FIT_PM_AND_PAR; 29 } 30 30 31 if ((N = get_argument (argc, argv, "-high-speed"))) { 31 32 // XXX include a parallax / no-parallax option … … 93 94 usage (); 94 95 } 96 } 97 98 USE_BASIC_CHECK = FALSE; 99 if ((N = get_argument (argc, argv, "-basic-image-search"))) { 100 remove_argument (N, &argc, argv); 101 USE_BASIC_CHECK = TRUE; 95 102 } 96 103 … … 144 151 VERBOSE = VERBOSE2 = TRUE; 145 152 remove_argument (N, &argc, argv); 153 } 154 155 if ((N = get_argument (argc, argv, "-visual"))) { 156 remove_argument (N, &argc, argv); 157 relastroSetVisual(TRUE); 146 158 } 147 159 -
branches/czw_branch/20101203/Ohana/src/relastro/src/bcatalog.c
r29001 r30631 45 45 offset = catalog[0].average[i].measureOffset + j; 46 46 47 // filter objects based on user supplied criteria 48 if (!MeasFilterTest(&catalog[0].measure[offset] )) {47 // filter objects based on user supplied criteria, including SIGMA_LIM 48 if (!MeasFilterTest(&catalog[0].measure[offset], TRUE)) { 49 49 catalog[0].measure[offset].dbFlags &= ~ID_MEAS_USED_CHIP; 50 50 continue; … … 78 78 subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_AREA; 79 79 } 80 80 81 81 Nmeasure ++; 82 82 Nm ++; -
branches/czw_branch/20101203/Ohana/src/relastro/src/load_catalogs.c
r29001 r30631 26 26 pcatalog[0].Nsecfilt = GetPhotcodeNsecfilt (); 27 27 28 if (!dvo_catalog_open (pcatalog, skylist[0].regions[i], VERBOSE , "w")) {28 if (!dvo_catalog_open (pcatalog, skylist[0].regions[i], VERBOSE2, "w")) { 29 29 fprintf (stderr, "ERROR: failure reading catalog %s\n", pcatalog[0].filename); 30 30 exit (1); 31 31 } 32 if (VERBOSE && !pcatalog[0].Naves_disk) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename);32 if (VERBOSE2 && !pcatalog[0].Naves_disk) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename); 33 33 34 34 //outlier rejection -
branches/czw_branch/20101203/Ohana/src/relastro/src/plotstuff.c
r27588 r30631 146 146 graphdata[0].ymax = dUNDEF; 147 147 148 graphdata[0].ticktextPad = NAN; 149 graphdata[0].labelPadXm = NAN; 150 graphdata[0].labelPadXp = NAN; 151 graphdata[0].labelPadYm = NAN; 152 graphdata[0].labelPadYp = NAN; 153 graphdata[0].padXm = NAN; 154 graphdata[0].padXp = NAN; 155 graphdata[0].padYm = NAN; 156 graphdata[0].padYp = NAN; 148 157 } -
branches/czw_branch/20101203/Ohana/src/relastro/src/relastro.c
r29001 r30631 78 78 MARKTIME("update chips: %f sec\n", dtime); 79 79 } 80 // create summary plots of the process 81 // relastroVisualSummaryChips(); 80 82 break; 81 83 -
branches/czw_branch/20101203/Ohana/src/relastro/src/relastroVisual.c
r24308 r30631 11 11 #define KAPAY 700 12 12 13 static int kapa = -1;13 static int kapa1 = -1; 14 14 static int kapa2 = -1; 15 15 static int kapa3 = -1; 16 static int kapa4 = -1; 16 17 17 18 static int isVisual = FALSE; 18 static int plotRawRef = FALSE;19 static int plotScatter = FALSE;20 static int plotResid = FALSE;21 static int plotVector = FALSE;19 static int plotRawRef = TRUE; 20 // static int plotScatter = TRUE; 21 // static int plotResid = TRUE; 22 // static int plotVector = TRUE; 22 23 static int plotOutliers = TRUE; 23 24 … … 29 30 fprintf(stderr, "Failure to open kapa.\n"); 30 31 isVisual = 0; 31 return 0;32 return FALSE; 32 33 } 33 // KapaResize (*kapid, KAPAX, KAPAY); 34 } 35 return 1; 34 } 35 return TRUE; 36 36 } 37 37 … … 49 49 isVisual = 0; 50 50 } 51 return 1; 51 return TRUE; 52 } 53 54 void relastroSetVisual(int state) { 55 isVisual = state; 56 } 57 58 int relastroGetVisual(void) { 59 return isVisual; 52 60 } 53 61 … … 70 78 graphdata->xmax = xhi; 71 79 graphdata->ymax = yhi; 72 return 1; 73 } 74 75 static int residPlot(float x[], float y[], 76 float xVec[], float yVec[], 77 int npts, int *kapaID) { 78 if (!isVisual || !plotResid) return TRUE; 80 return TRUE; 81 } 82 83 /** 4-panel plot of x vs dx, y vs dx, x vs dy, y vs dy **/ 84 int relastroVisualRawRef(int *kapaID, float *x, float *y, float *dx, float *dy, float *dPos, int npts) { 85 79 86 Graphdata graphdata; 80 87 KapaSection section; … … 83 90 84 91 KapaInitGraph(&graphdata); 85 KapaClear Plots(*kapaID);92 KapaClearSections(*kapaID); 86 93 KapaSetFont(*kapaID, "helvetica", 14); 87 94 … … 89 96 section.x = 0.0; section.y = 0.0; 90 97 section.dx = .45, section.dy = .45; 98 section.bg = KapaColorByName("white"); 91 99 graphdata.ptype = 7; 92 100 graphdata.style = 2; 101 graphdata.etype |= 0x01; 93 102 94 103 KapaSetSection(*kapaID, §ion); 95 if(!scaleGraphdata(x, xVec, &graphdata, npts)) return 0;104 if(!scaleGraphdata(x, dx, &graphdata, npts)) return 0; 96 105 KapaSetLimits(*kapaID, &graphdata); 97 106 KapaBox(*kapaID, &graphdata); … … 100 109 KapaPrepPlot(*kapaID, npts, &graphdata); 101 110 KapaPlotVector(*kapaID, npts, x, "x"); 102 KapaPlotVector(*kapaID, npts, xVec, "y"); 111 KapaPlotVector(*kapaID, npts, dx, "y"); 112 KapaPlotVector(*kapaID, npts, dPos, "dym"); 113 KapaPlotVector(*kapaID, npts, dPos, "dyp"); 103 114 104 115 section.x = .5; section.y = 0; section.name="1"; 105 116 KapaSetSection(*kapaID, §ion); 106 if(!scaleGraphdata(x, yVec, &graphdata, npts)) return 0;117 if(!scaleGraphdata(x, dy, &graphdata, npts)) return 0; 107 118 KapaSetLimits(*kapaID, &graphdata); 108 119 KapaBox(*kapaID, &graphdata); … … 111 122 KapaPrepPlot(*kapaID, npts, &graphdata); 112 123 KapaPlotVector(*kapaID, npts, x, "x"); 113 KapaPlotVector(*kapaID, npts, yVec, "y"); 124 KapaPlotVector(*kapaID, npts, dy, "y"); 125 KapaPlotVector(*kapaID, npts, dPos, "dym"); 126 KapaPlotVector(*kapaID, npts, dPos, "dyp"); 114 127 115 128 section.x = .0; section.y = .5; section.name="2"; 116 129 KapaSetSection(*kapaID, §ion); 117 if(!scaleGraphdata(y, xVec, &graphdata, npts)) return 0;;130 if(!scaleGraphdata(y, dx, &graphdata, npts)) return 0;; 118 131 KapaSetLimits(*kapaID, &graphdata); 119 132 KapaBox(*kapaID, &graphdata); … … 122 135 KapaPrepPlot(*kapaID, npts, &graphdata); 123 136 KapaPlotVector(*kapaID, npts, y, "x"); 124 KapaPlotVector(*kapaID, npts, xVec, "y"); 137 KapaPlotVector(*kapaID, npts, dx, "y"); 138 KapaPlotVector(*kapaID, npts, dPos, "dym"); 139 KapaPlotVector(*kapaID, npts, dPos, "dyp"); 125 140 126 141 section.x = .5; section.y = .5; section.name="3"; 127 142 KapaSetSection(*kapaID, §ion); 128 if(!scaleGraphdata(y, yVec, &graphdata, npts)) return 0;143 if(!scaleGraphdata(y, dy, &graphdata, npts)) return 0; 129 144 KapaSetLimits(*kapaID, &graphdata); 130 145 KapaBox(*kapaID, &graphdata); … … 133 148 KapaPrepPlot(*kapaID, npts, &graphdata); 134 149 KapaPlotVector(*kapaID, npts, y, "x"); 135 KapaPlotVector(*kapaID, npts, yVec, "y"); 136 137 return 1; 138 } 139 140 141 /**Plot a vector field*/ 142 static int plotVectorField(float x[], float y[], 143 float xVec[], float yVec[], 144 int npts, int *kapaID, double maxVecLength) { 145 146 if(!plotVector) return 1; 150 KapaPlotVector(*kapaID, npts, dy, "y"); 151 KapaPlotVector(*kapaID, npts, dPos, "dym"); 152 KapaPlotVector(*kapaID, npts, dPos, "dyp"); 153 154 return TRUE; 155 } 156 157 158 /** Plot a vector field (circles at vector origin, scaled lines giving vector directions */ 159 int relastroVisualVectorField(int *kapaID, float *x, float *y, float *dx, float *dy, int npts, double maxVecLength) { 147 160 148 161 Graphdata graphdata; 149 float singleX[2], singleY[2];162 float *xVec, *yVec; 150 163 float vecScaleFactor; 151 164 float graphSize; 152 165 int i; 153 166 char plotTitle[50]; 154 sprintf(plotTitle, "Maximum Vector Size = %5.1e", maxVecLength); 155 167 168 if (!npts) return FALSE; 156 169 if (!initWindow(kapaID)) return 0; 157 170 171 snprintf(plotTitle, 50, "Maximum Vector Size = %5.1e", maxVecLength); 172 158 173 KapaInitGraph(&graphdata); 159 KapaClearPlots(*kapaID); 160 if(!scaleGraphdata(x, y, &graphdata, npts)) return 0; 174 KapaClearSections(*kapaID); 175 KapaSetFont(*kapaID, "helvetica", 14); 176 177 if (!scaleGraphdata(x, y, &graphdata, npts)) return 0; 161 178 162 179 graphSize = graphdata.xmax - graphdata.xmin; … … 164 181 graphSize = graphdata.ymax - graphdata.ymin; 165 182 } 166 167 183 vecScaleFactor = graphSize * 0.02 / (float)maxVecLength; 168 #ifdef TESTING 169 fprintf(stderr, "GraphSize: %e\n maxVecLength: %e\n vecScaleFactor: %e\n", 170 graphSize, maxVecLength, vecScaleFactor); 171 #endif 172 184 185 // fprintf(stderr, "GraphSize: %e\n maxVecLength: %e\n vecScaleFactor: %e\n", graphSize, maxVecLength, vecScaleFactor); 173 186 174 187 KapaSetFont (*kapaID, "helvetica", 14); … … 179 192 graphdata.ptype = 7; 180 193 graphdata.style = 2; 194 graphdata.color = KapaColorByName("black"); 181 195 KapaPrepPlot(*kapaID, npts, &graphdata); 182 196 KapaPlotVector(*kapaID, npts, x, "x"); 183 197 KapaPlotVector(*kapaID, npts, y, "y"); 184 198 185 //plot each vector individually 186 graphdata.ptype = 0; 187 graphdata.style = 0; 199 ALLOCATE (xVec, float, 2*npts); 200 ALLOCATE (yVec, float, 2*npts); 201 for (i = 0; i < npts; i++) { 202 xVec[2*i + 0] = x[i]; 203 yVec[2*i + 0] = y[i]; 204 xVec[2*i + 1] = x[i] + dx[i] * vecScaleFactor; 205 yVec[2*i + 1] = y[i] + dy[i] * vecScaleFactor; 206 } 207 208 graphdata.ptype = 100; // line segements by point pair 209 graphdata.style = 2; 188 210 graphdata.color = KapaColorByName("blue"); 189 for(i = 0; i < npts; i++) { 190 singleX[0] = x[i]; 191 singleY[0] = y[i]; 192 singleX[1] = x[i] + xVec[i] * vecScaleFactor; 193 singleY[1] = y[i] + yVec[i] * vecScaleFactor; 194 KapaPrepPlot(*kapaID, 2, &graphdata); 195 KapaPlotVector(*kapaID, 2, singleX, "x"); 196 KapaPlotVector(*kapaID, 2, singleY, "y"); 197 } 198 return 1; 199 } 200 201 int relastroVisualPlotScatter(double values[], double thresh, int npts) { 202 float *x, *data; 203 int i; 204 float xline[2], yline[2]; 205 if (!isVisual || !plotScatter) return 1; 206 if (!initWindow(&kapa2)) return 0; 207 208 ALLOCATE(x, float, npts); 209 ALLOCATE(data, float, npts); 210 211 for(i = 0; i < npts; i++) { 212 x[i] = i; 213 data[i] = (float) values[i]; 214 } 211 KapaPrepPlot (*kapaID, 2*npts, &graphdata); 212 KapaPlotVector(*kapaID, 2*npts, xVec, "x"); 213 KapaPlotVector(*kapaID, 2*npts, yVec, "y"); 214 215 free (xVec); 216 free (yVec); 217 return TRUE; 218 } 219 220 int relastroVisualPlotScatter(int *kapaID, float *dXfit, float *dYfit, float *mag, int npts) { 215 221 216 222 Graphdata graphdata; 217 223 KapaSection section; 218 section.x = 0; section.y = 0; section.dx = 1; section.dy = 1; 219 section.name = "junk";224 225 if (!initWindow(kapaID)) return 0; 220 226 221 227 KapaInitGraph(&graphdata); 222 KapaClearPlots(kapa2); 223 KapaSetSection(kapa2, §ion); 224 225 graphdata.ptype = 0; 226 graphdata.style = 0; 227 graphdata.xmin = 0; 228 graphdata.xmax = npts; 229 graphdata.ymin = 0; 230 graphdata.ymax = data[npts-1]; 231 232 KapaSetFont(kapa2, "helvetica", 14); 233 KapaSetLimits(kapa2, &graphdata); 234 KapaBox(kapa2, &graphdata); 235 KapaSendLabel( kapa2, "Object", KAPA_LABEL_XM); 236 KapaSendLabel( kapa2, "Offset(pixels)", KAPA_LABEL_YM); 237 KapaSendLabel( kapa2, "Astrometric Offset with fit cutoff", 238 KAPA_LABEL_XP); 239 KapaPrepPlot(kapa2, npts, &graphdata); 240 KapaPlotVector(kapa2, npts, x, "x"); 241 KapaPlotVector(kapa2, npts, data, "y"); 242 243 graphdata.color = KapaColorByName("red"); 244 KapaPrepPlot(kapa2, 2, &graphdata); 245 yline[0] = (float) thresh; 246 yline[1] = (float) thresh; 247 xline[0] = graphdata.xmin; 248 xline[1] = graphdata.xmax; 249 KapaPlotVector(kapa2, 2, xline, "x"); 250 KapaPlotVector(kapa2, 2, yline, "y"); 251 252 askUser(&plotScatter); 253 return 1; 254 } 255 256 228 KapaClearSections(*kapaID); 229 KapaSetFont(*kapaID, "helvetica", 14); 230 231 section.name = "a"; 232 section.x = 0.0; section.y = 0.0; section.dx = 1.0; section.dy = 0.5; 233 section.bg = KapaColorByName("white"); 234 KapaSetSection(*kapaID, §ion); 235 236 graphdata.ptype = 2; 237 graphdata.style = 2; 238 239 if(!scaleGraphdata(mag, dXfit, &graphdata, npts)) return 0; 240 KapaSetLimits(*kapaID, &graphdata); 241 KapaBox(*kapaID, &graphdata); 242 KapaSendLabel(*kapaID, "mag", KAPA_LABEL_XM); 243 KapaSendLabel(*kapaID, "dXfit", KAPA_LABEL_YM); 244 KapaPrepPlot(*kapaID, npts, &graphdata); 245 KapaPlotVector(*kapaID, npts, mag, "x"); 246 KapaPlotVector(*kapaID, npts, dXfit, "y"); 247 248 section.name = "b"; 249 section.x = 0.0; section.y = 0.5; section.dx = 1.0; section.dy = 0.5; 250 section.bg = KapaColorByName("white"); 251 KapaSetSection(*kapaID, §ion); 252 253 graphdata.ptype = 2; 254 graphdata.style = 2; 255 256 if(!scaleGraphdata(mag, dYfit, &graphdata, npts)) return 0; 257 KapaSetLimits(*kapaID, &graphdata); 258 KapaBox(*kapaID, &graphdata); 259 KapaSendLabel(*kapaID, "mag", KAPA_LABEL_XM); 260 KapaSendLabel(*kapaID, "dYfit", KAPA_LABEL_YM); 261 KapaPrepPlot(*kapaID, npts, &graphdata); 262 KapaPlotVector(*kapaID, npts, mag, "x"); 263 KapaPlotVector(*kapaID, npts, dYfit, "y"); 264 265 return TRUE; 266 } 257 267 258 268 /** plot raw vs ref (L, M). Only those whose distance is < drMax are used in fit*/ 259 int relastroVisualPlotRawRef(StarData *raw, StarData *ref, double dRmax, int numObj) { 260 261 if( !isVisual || !plotRawRef) return 1; 262 if( !initWindow(&kapa)) return 0; 269 int relastroVisualPlotFittedStars(int *kapaID, float *rawX, float *rawY, float *refX, float *refY, int numNoFit, float *rawXfit, float *rawYfit, float *refXfit, float *refYfit, int numFit) { 270 271 Graphdata graphdata; 272 273 if (!initWindow(kapaID)) return 0; 274 275 KapaInitGraph(&graphdata); 276 KapaClearPlots(*kapaID); 277 278 graphdata.ptype = 7; 279 graphdata.style = 2; 280 281 if(!scaleGraphdata(rawXfit, rawYfit, &graphdata, numFit)) { 282 fprintf(stderr, "Not enough finite points for plotting"); 283 return 0; 284 } 285 286 KapaSetFont(*kapaID, "helvetica", 14); 287 KapaSetLimits(*kapaID, &graphdata); 288 KapaBox(*kapaID, &graphdata); 289 KapaSendLabel( *kapaID, "X", KAPA_LABEL_XM); 290 KapaSendLabel( *kapaID, "Y", KAPA_LABEL_YM); 291 KapaSendLabel( *kapaID, "orange, red, green, blue: (raw, ref), (nofit, fit)", 292 KAPA_LABEL_XP); 293 294 graphdata.color = KapaColorByName("orange"); 295 graphdata.size = 1; 296 KapaPrepPlot(*kapaID, numNoFit, &graphdata); 297 KapaPlotVector(*kapaID, numNoFit, rawX, "x"); 298 KapaPlotVector(*kapaID, numNoFit, rawY, "y"); 299 300 graphdata.color = KapaColorByName("red"); 301 graphdata.size = 2; 302 KapaPrepPlot(*kapaID, numNoFit, &graphdata); 303 KapaPlotVector(*kapaID, numNoFit, refX, "x"); 304 KapaPlotVector(*kapaID, numNoFit, refY, "y"); 305 306 graphdata.color = KapaColorByName("green"); 307 graphdata.size = 1; 308 KapaPrepPlot(*kapaID, numFit, &graphdata); 309 KapaPlotVector(*kapaID, numFit, rawXfit, "x"); 310 KapaPlotVector(*kapaID, numFit, rawYfit, "y"); 311 312 graphdata.color = KapaColorByName("blue"); 313 graphdata.size = 2; 314 KapaPrepPlot(*kapaID, numFit, &graphdata); 315 KapaPlotVector(*kapaID, numFit, refXfit, "x"); 316 KapaPlotVector(*kapaID, numFit, refYfit, "y"); 317 318 return TRUE; 319 } 320 321 /** create various plots using the data in raw and ref **/ 322 int relastroVisualPlotChipFit(StarData *raw, StarData *ref, double dRmax, int numObj) { 263 323 264 324 float *rawX, *rawY, *refX, *refY; 265 325 float *rawXfit, *rawYfit, *refXfit, *refYfit; 266 326 float *magRaw, *magRef, *magRawfit, *magReffit; 267 float * xVec, *yVec;327 float *dXfit, *dYfit, *dPos; 268 328 int numFit = 0, numNoFit = 0; 269 329 double dL, dM, dR; 330 331 if (!isVisual) return TRUE; 270 332 271 333 ALLOCATE(rawX, float, numObj); … … 273 335 ALLOCATE(refX, float, numObj); 274 336 ALLOCATE(refY, float, numObj); 337 ALLOCATE(magRaw, float, numObj); 338 ALLOCATE(magRef, float, numObj); 339 275 340 ALLOCATE(rawXfit, float, numObj); 276 341 ALLOCATE(rawYfit, float, numObj); 277 342 ALLOCATE(refXfit, float, numObj); 278 343 ALLOCATE(refYfit, float, numObj); 279 ALLOCATE(magRaw, float, numObj);280 ALLOCATE(magRef, float, numObj);281 344 ALLOCATE(magRawfit, float, numObj); 282 345 ALLOCATE(magReffit, float, numObj); 346 ALLOCATE(dXfit, float, numObj); 347 ALLOCATE(dYfit, float, numObj); 348 ALLOCATE(dPos, float, numObj); 283 349 284 350 int i; 285 351 for(i = 0; i < numObj; i++) { 286 if (raw[i].mask) continue;352 if (raw[i].mask) continue; // XXX 287 353 288 354 dL = raw[i].L - ref[i].L; 289 355 dM = raw[i].M - ref[i].M; 290 356 dR = hypot (dL, dM); 357 358 // XXX change the selection to a mask-based thing 291 359 if (dR > dRmax) { 360 // UNFITTED values 292 361 rawX[numNoFit] = raw[i].X; 293 362 rawY[numNoFit] = raw[i].Y; … … 298 367 numNoFit++; 299 368 } else { 300 rawXfit[numFit] = raw[i].X; 301 rawYfit[numFit] = raw[i].Y; 302 refXfit[numFit] = ref[i].X; 303 refYfit[numFit] = ref[i].Y; 304 magRaw[numFit] = raw[i].Mag; 305 magRef[numFit] = ref[i].Mag; 369 // FITTED values 370 rawXfit[numFit] = raw[i].X; 371 rawYfit[numFit] = raw[i].Y; 372 refXfit[numFit] = ref[i].X; 373 refYfit[numFit] = ref[i].Y; 374 magRawfit[numFit] = raw[i].Mag; 375 magReffit[numFit] = ref[i].Mag; 376 dPos[numFit] = ref[i].dPos; 377 dXfit[numFit] = raw[i].X - ref[i].X; 378 dYfit[numFit] = raw[i].Y - ref[i].Y; 306 379 numFit++; 307 380 } … … 310 383 if (numFit == 0) return 0; 311 384 312 Graphdata graphdata; 313 314 KapaInitGraph(&graphdata); 315 KapaClearPlots(kapa); 316 317 graphdata.ptype = 7; 318 graphdata.style = 2; 319 320 if(!scaleGraphdata(rawXfit, rawYfit, &graphdata, numFit)) { 321 fprintf(stderr, "Not enough finite points for plotting"); 322 return 0; 323 } 324 325 KapaSetFont(kapa, "helvetica", 14); 326 KapaSetLimits(kapa, &graphdata); 327 KapaBox(kapa, &graphdata); 328 KapaSendLabel( kapa, "X", KAPA_LABEL_XM); 329 KapaSendLabel( kapa, "Y", KAPA_LABEL_YM); 330 KapaSendLabel( kapa, "orange, red, green, blue: (raw, ref), (nofit, fit)", 331 KAPA_LABEL_XP); 332 333 graphdata.color = KapaColorByName("orange"); 334 graphdata.size = 1; 335 KapaPrepPlot(kapa, numNoFit, &graphdata); 336 KapaPlotVector(kapa, numNoFit, rawX, "x"); 337 KapaPlotVector(kapa, numNoFit, rawY, "y"); 338 339 graphdata.color = KapaColorByName("red"); 340 graphdata.size = 2; 341 KapaPrepPlot(kapa, numNoFit, &graphdata); 342 KapaPlotVector(kapa, numNoFit, refX, "x"); 343 KapaPlotVector(kapa, numNoFit, refY, "y"); 344 345 graphdata.color = KapaColorByName("green"); 346 graphdata.size = 1; 347 KapaPrepPlot(kapa, numFit, &graphdata); 348 KapaPlotVector(kapa, numFit, rawXfit, "x"); 349 KapaPlotVector(kapa, numFit, rawYfit, "y"); 350 351 graphdata.color = KapaColorByName("blue"); 352 graphdata.size = 2; 353 KapaPrepPlot(kapa, numFit, &graphdata); 354 KapaPlotVector(kapa, numFit, refXfit, "x"); 355 KapaPlotVector(kapa, numFit, refYfit, "y"); 356 357 ALLOCATE(xVec, float, numFit); 358 ALLOCATE(yVec, float, numFit); 359 360 //plot the fitted objects as vectors 361 for(i = 0; i < numFit; i++) { 362 xVec[i] = rawXfit[i] - refXfit[i]; 363 yVec[i] = rawYfit[i] - refYfit[i]; 364 } 365 366 plotVectorField(rawXfit, rawYfit, xVec, yVec, numFit, &kapa3, dRmax); 367 if(!residPlot(rawXfit, rawYfit, xVec, yVec, numFit, &kapa2)) { 368 fprintf(stderr, "Unable to plot residuals"); 369 return 0; 370 } 371 372 FREE(xVec); 373 FREE(yVec); 385 // 4-panel plot of x vs dx, y vs dx, x vs dy, y vs dy 386 relastroVisualRawRef(&kapa1, rawXfit, rawYfit, dXfit, dYfit, dPos, numFit); 387 388 // vector line plot for the fit 389 relastroVisualVectorField(&kapa2, rawXfit, rawYfit, dXfit, dYfit, numFit, dRmax); 390 391 // dXfit, dYfit vs mag 392 relastroVisualPlotScatter(&kapa3, dXfit, dYfit, magRawfit, numFit); 393 394 // plot the positions of the fitted stars on the chip 395 relastroVisualPlotFittedStars(&kapa4, rawX, rawY, refX, refY, numNoFit, rawXfit, rawYfit, refXfit, refYfit, numFit); 374 396 375 397 askUser(&plotRawRef); 376 398 399 FREE(dXfit); 400 FREE(dYfit); 401 FREE(dPos); 377 402 FREE(rawX); 378 403 FREE(rawY); … … 388 413 FREE(magReffit); 389 414 390 return 1;415 return TRUE; 391 416 } 392 417 … … 403 428 KapaSection section; 404 429 405 if (!isVisual || !plotOutliers) return 1;406 if (!initWindow(&kapa )) return 0;430 if (!isVisual || !plotOutliers) return TRUE; 431 if (!initWindow(&kapa1)) return 0; 407 432 408 433 // populate vectors … … 426 451 for(i = 0; i < Nmeasure; i++, m++) { 427 452 meas = catalog[0].measure[m]; 428 if (!MeasFilterTest(&meas )) continue;453 if (!MeasFilterTest(&meas, FALSE)) continue; 429 454 xmin = MIN(xmin, meas.dR); 430 455 xmax = MAX(xmax, meas.dR); … … 459 484 section.x = 0; section.y = 0; section.dx = 1; section.dy = 1; 460 485 section.name = "junk"; 486 section.bg = KapaColorByName("white"); 461 487 462 488 KapaInitGraph(&graphdata); 463 KapaClearPlots(kapa );464 KapaSetFont(kapa , "helvetica", 14);489 KapaClearPlots(kapa1); 490 KapaSetFont(kapa1, "helvetica", 14); 465 491 466 492 graphdata.ptype = 7; … … 472 498 graphdata.ymax = ymax; 473 499 474 KapaSetSection(kapa , §ion);475 KapaSetLimits(kapa , &graphdata);476 KapaBox(kapa , &graphdata);477 478 KapaSendLabel( kapa , "RA (arcsec)", KAPA_LABEL_XM);479 KapaSendLabel( kapa , "Dec (arcsec)", KAPA_LABEL_YM);480 KapaSendLabel( kapa , "Points flagged as outliers (red)",500 KapaSetSection(kapa1, §ion); 501 KapaSetLimits(kapa1, &graphdata); 502 KapaBox(kapa1, &graphdata); 503 504 KapaSendLabel( kapa1, "RA (arcsec)", KAPA_LABEL_XM); 505 KapaSendLabel( kapa1, "Dec (arcsec)", KAPA_LABEL_YM); 506 KapaSendLabel( kapa1, "Points flagged as outliers (red)", 481 507 KAPA_LABEL_XP); 482 508 483 509 graphdata.color = KapaColorByName("green"); 484 KapaPrepPlot(kapa , Nin, &graphdata);485 KapaPlotVector(kapa , Nin, Rin, "x");486 KapaPlotVector(kapa , Nin, Din, "y");510 KapaPrepPlot(kapa1, Nin, &graphdata); 511 KapaPlotVector(kapa1, Nin, Rin, "x"); 512 KapaPlotVector(kapa1, Nin, Din, "y"); 487 513 488 514 graphdata.color = KapaColorByName("red"); 489 KapaPrepPlot(kapa , Nout, &graphdata);490 KapaPlotVector(kapa , Nout, Rout, "x");491 KapaPlotVector(kapa , Nout, Dout, "y");515 KapaPrepPlot(kapa1, Nout, &graphdata); 516 KapaPlotVector(kapa1, Nout, Rout, "x"); 517 KapaPlotVector(kapa1, Nout, Dout, "y"); 492 518 493 519 graphdata.color = KapaColorByName("black"); 494 520 graphdata.ptype = 0; 495 521 graphdata.style = 0; 496 KapaPrepPlot(kapa, 100, &graphdata); 497 KapaPlotVector(kapa, 100, xCirc, "x"); 498 KapaPlotVector(kapa, 100, yCirc, "y"); 499 500 501 522 KapaPrepPlot(kapa1, 100, &graphdata); 523 KapaPlotVector(kapa1, 100, xCirc, "x"); 524 KapaPlotVector(kapa1, 100, yCirc, "y"); 525 502 526 askUser(&plotOutliers); 503 527 … … 510 534 } 511 535 512 536 # if (0) 537 int relastroVisualSummaryChips() { 538 539 // plot the dXsys, dYsys histograms 540 541 // plot x vs dx, y vs dy, etc for all mosaics 542 543 // plot a map of median star scatter 544 545 } 546 # endif 547 -
branches/czw_branch/20101203/Ohana/src/relastro/src/select_images.c
r29001 r30631 15 15 void dsortindex (double *X, off_t *Y, int N); 16 16 off_t getRegionStartByRA (double R, double *Rref, off_t Nregions); 17 18 # define MARKTIME(MSG,...) { \ 19 float dtime; \ 20 gettimeofday (&stop, (void *) NULL); \ 21 dtime = DTIME (stop, start); \ 22 fprintf (stderr, MSG, __VA_ARGS__); } 17 23 18 24 Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) { … … 25 31 Coords tcoords; 26 32 SkyRegionCoords *skycoords; 27 33 struct timeval start, stop; 34 35 double RmaxSkyRegion, RminSkyRegion, RmidSkyRegion, DminSkyRegion, DmaxSkyRegion; 36 28 37 double *RmaxSky; 29 38 off_t *index; … … 40 49 return NULL; 41 50 } 51 52 gettimeofday (&start, (void *) NULL); 42 53 43 54 // the comparison is made in the catalog local projection. below we set crval1,2 … … 52 63 ALLOCATE (RmaxSky, double, skylist[0].Nregions); 53 64 ALLOCATE (index, off_t, skylist[0].Nregions); 65 66 RminSkyRegion = +360.0; 67 RmaxSkyRegion = -360.0; 68 DminSkyRegion = +90.0; 69 DmaxSkyRegion = -90.0; 54 70 55 71 /* compare with each region file */ … … 80 96 skycoords[i].Xc[3] -= dx; skycoords[i].Yc[3] += dy; 81 97 skycoords[i].Xc[4] -= dx; skycoords[i].Yc[4] -= dy; 82 } 98 99 RminSkyRegion = MIN(RminSkyRegion, skylist[0].regions[i][0].Rmin); 100 RmaxSkyRegion = MAX(RmaxSkyRegion, skylist[0].regions[i][0].Rmax); 101 DminSkyRegion = MIN(DminSkyRegion, skylist[0].regions[i][0].Dmin); 102 DmaxSkyRegion = MAX(DmaxSkyRegion, skylist[0].regions[i][0].Dmax); 103 } 104 RmidSkyRegion = 0.5*(RminSkyRegion + RmaxSkyRegion); 105 MARKTIME("create sky region coords: %f sec\n", dtime); 83 106 84 107 dsortindex (RmaxSky, index, skylist[0].Nregions); 108 MARKTIME("sort sky coords: %f sec\n", dtime); 85 109 86 110 if (VERBOSE) fprintf (stderr, "finding images\n"); 87 111 BuildChipMatch (timage, Ntimage); 112 MARKTIME("build chip match: %f sec\n", dtime); 88 113 89 114 nimage = 0; … … 124 149 } 125 150 126 /* define image corners */ 127 Xi[0] = 0; Yi[0] = 0; 128 Xi[1] = timage[i].NX; Yi[1] = 0; 129 Xi[2] = timage[i].NX; Yi[2] = timage[i].NY; 130 Xi[3] = 0; Yi[3] = timage[i].NY; 131 Xi[4] = 0; Yi[4] = 0; 151 /* define image corners - note the DIS images (mosaic phu) are special */ 152 if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) { 153 Xi[0] = -0.5*timage[i].NX; Yi[0] = -0.5*timage[i].NY; 154 Xi[1] = +0.5*timage[i].NX; Yi[1] = -0.5*timage[i].NY; 155 Xi[2] = +0.5*timage[i].NX; Yi[2] = +0.5*timage[i].NY; 156 Xi[3] = -0.5*timage[i].NX; Yi[3] = +0.5*timage[i].NY; 157 Xi[4] = -0.5*timage[i].NX; Yi[4] = -0.5*timage[i].NY; 158 } else { 159 Xi[0] = 0; Yi[0] = 0; 160 Xi[1] = timage[i].NX; Yi[1] = 0; 161 Xi[2] = timage[i].NX; Yi[2] = timage[i].NY; 162 Xi[3] = 0; Yi[3] = timage[i].NY; 163 Xi[4] = 0; Yi[4] = 0; 164 } 132 165 found = FALSE; 133 166 134 167 /* transform corners to ra,dec */ 135 168 double RminImage = 360.0; 169 double RmaxImage = 0.0; 170 double DminImage = +90.0; 171 double DmaxImage = -90.0; 172 // int leftside = FALSE; 136 173 for (j = 0; j < 5; j++) { 137 174 XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords); 175 Ri[j] = ohana_normalize_angle_to_midpoint (Ri[j], RmidSkyRegion); 176 138 177 RminImage = MIN(RminImage, Ri[j]); 139 } 178 RmaxImage = MAX(RmaxImage, Ri[j]); 179 DminImage = MIN(DminImage, Di[j]); 180 DmaxImage = MAX(DmaxImage, Di[j]); 181 } 182 if (RmaxImage - RminImage > 180.0) { 183 double tmp = RminImage; 184 RmaxImage = RminImage; 185 RminImage = tmp - 360.0; 186 } 187 188 // check that this image is even in range of the searched region 189 if (DminImage > DmaxSkyRegion) continue; 190 if (DmaxImage < DminSkyRegion) continue; 191 192 // the sky region RA is defined to be 0 - 360.0 193 if (RminImage > RmaxSkyRegion) continue; 194 if (RmaxImage < RminSkyRegion) continue; 195 196 // image overlaps region, keep it 197 if (USE_BASIC_CHECK) goto found_it; 140 198 141 199 // RA(nStart) is guaranteed to be < RminImage: … … 161 219 for (j = 0; (j < 4) && !found; j++) { 162 220 found = corner_check (&Xi[j], &Yi[j], &skycoords[m].Xc[0], &skycoords[m].Yc[0]); 221 if (found) goto found_it; 163 222 } 164 223 /* check if catalog corner inside image */ 165 224 for (j = 0; (j < 4) && !found; j++) { 166 225 found = corner_check (&skycoords[m].Xc[j], &skycoords[m].Yc[j], &Xi[0], &Yi[0]); 226 if (found) goto found_it; 167 227 } 168 228 /* check if edges cross */ … … 170 230 for (k = 0; (k < 4) && !found; k++) { 171 231 found = edge_check (&Xi[j], &Yi[j], &skycoords[m].Xc[k], &skycoords[m].Yc[k]); 232 if (found) goto found_it; 172 233 } 173 234 } 174 if (!found) continue; 175 176 image[nimage] = timage[i]; 177 /* always allow 'few' images to succeed, if possible */ 178 if (image[nimage].flags & ID_IMAGE_ASTROM_FEW) { 179 image[nimage].flags &= ~ID_IMAGE_ASTROM_FEW; 180 } 181 if (RESET) { 182 // XXX do we need / want to do this in relastro? 183 assignMcal (&image[nimage], (double *) NULL, -1); 184 image[nimage].dMcal = NAN; 185 image[nimage].flags &= ~badImage; 186 } 187 line_number[nimage] = i; 188 nimage ++; 189 if (nimage == NIMAGE) { 190 NIMAGE += 100; 191 REALLOCATE (image, Image, NIMAGE); 192 REALLOCATE (line_number, off_t, NIMAGE); 193 } 194 } 195 } 196 235 } 236 if (!found) continue; 237 238 found_it: 239 image[nimage] = timage[i]; 240 /* always allow 'few' images to succeed, if possible */ 241 if (image[nimage].flags & ID_IMAGE_ASTROM_FEW) { 242 image[nimage].flags &= ~ID_IMAGE_ASTROM_FEW; 243 } 244 if (RESET) { 245 // XXX do we need / want to do this in relastro? 246 // assignMcal (&image[nimage], (double *) NULL, -1); 247 // image[nimage].Mcal = NAN; 248 // image[nimage].dMcal = NAN; 249 image[nimage].flags &= ~badImage; 250 } 251 line_number[nimage] = i; 252 nimage ++; 253 if (nimage == NIMAGE) { 254 NIMAGE += 100; 255 REALLOCATE (image, Image, NIMAGE); 256 REALLOCATE (line_number, off_t, NIMAGE); 257 } 258 } 259 MARKTIME("finish image selection: %f sec\n", dtime); 260 197 261 if (VERBOSE) fprintf (stderr, "found "OFF_T_FMT" images\n", nimage); 198 262 -
branches/czw_branch/20101203/Ohana/src/relphot/Makefile
r17242 r30631 29 29 $(SRC)/StarOps.$(ARCH).o \ 30 30 $(SRC)/args.$(ARCH).o \ 31 $(SRC)/help.$(ARCH).o \ 31 32 $(SRC)/bcatalog.$(ARCH).o \ 32 33 $(SRC)/global_stats.$(ARCH).o \ -
branches/czw_branch/20101203/Ohana/src/relphot/include/relphot.h
r27586 r30631 13 13 float Mcal; 14 14 float dMcal; 15 float dMsys; 16 short nFitPhotom; 15 17 short Xm; 16 18 float secz; … … 50 52 double STAR_CHISQ; 51 53 double MIN_ERROR; 54 double IMFIT_SYS_SIGMA_LIM; 52 55 53 56 int VERBOSE; … … 103 106 SkyRegion UserPatch; 104 107 int UserPatchSelect; 108 109 int USE_BASIC_CHECK; 105 110 106 111 # ifdef GRID_V1 … … 215 220 void write_coords PROTO((Header *header, Coords *coords)); 216 221 int relphot_objects (void); 222 223 void relphot_usage (void); 224 void relphot_help (int argc, char **argv); -
branches/czw_branch/20101203/Ohana/src/relphot/src/ConfigInit.c
r25757 r30631 20 20 GetConfig (config, "MAG_LIM", "%lf", 0, &MAG_LIM); 21 21 GetConfig (config, "SIGMA_LIM", "%lf", 0, &SIGMA_LIM); 22 23 if (!ScanConfig (config, "RELPHOT_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01; 24 22 25 GetConfig (config, "STAR_SCATTER", "%lf", 0, &STAR_SCATTER); 23 26 GetConfig (config, "IMAGE_SCATTER", "%lf", 0, &IMAGE_SCATTER); -
branches/czw_branch/20101203/Ohana/src/relphot/src/ImageOps.c
r29001 r30631 124 124 free (clist); 125 125 free (mlist); 126 free (Nlist); 127 free (NLIST); 126 128 } 127 129 … … 299 301 300 302 off_t i, j, m, c, n, N, Nmax, mark, bad; 301 int Nfew, Nbad, Nmos, Ngrid, Nrel, Nsys ;302 float Msys, Mrel, Mmos, Mgrid ;303 int Nfew, Nbad, Nmos, Ngrid, Nrel, Nsys, Nbright; 304 float Msys, Mrel, Mmos, Mgrid, McalBright, McalBright2; 303 305 double *list, *dlist; 304 306 StatType stats; … … 318 320 319 321 Nfew = Nbad = Nmos = Ngrid = Nrel = Nsys = 0; 322 323 // counters to measure the bright-end scatter 324 McalBright = McalBright2 = 0.0; 325 Nbright = 0; 320 326 321 327 for (i = 0; i < Nimage; i++) { … … 361 367 list[N] = Msys - Mrel - Mmos - Mgrid; 362 368 dlist[N] = MAX (catalog[c].measure[m].dM, MIN_ERROR); 369 if (catalog[c].measure[m].dM < IMFIT_SYS_SIGMA_LIM) { 370 McalBright += list[N]; 371 McalBright2 += SQ(list[N]); 372 Nbright ++; 373 } 363 374 N++; 364 375 } … … 378 389 liststats (list, dlist, N, &stats); 379 390 image[i].Mcal = stats.mean; 380 image[i].dMcal = stats.sigma; 391 image[i].dMcal = stats.error; 392 image[i].dMagSys = stats.sigma; 393 image[i].nFitPhotom = N; 381 394 image[i].Xm = 100.0*log10(stats.chisq); 382 395 } -
branches/czw_branch/20101203/Ohana/src/relphot/src/MosaicOps.c
r29001 r30631 73 73 mosaic[Nmosaic].Mcal = 0.0; 74 74 mosaic[Nmosaic].dMcal = 0.0; 75 mosaic[Nmosaic].dMsys = 0.0; 75 76 mosaic[Nmosaic].Xm = 0.0; 76 77 mosaic[Nmosaic].flags = image[i].flags; … … 189 190 image[im].dMcal = mosaic[i].dMcal; 190 191 image[im].Xm = mosaic[i].Xm; 192 image[im].dMagSys = mosaic[i].dMsys; 193 image[im].nFitPhotom = mosaic[i].nFitPhotom; 191 194 image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW); 192 195 image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_POOR); … … 400 403 mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*Nlist[i]); 401 404 if (mark) { 402 fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), ("OFF_T_FMT" < %d) || ("OFF_T_FMT" < %f*"OFF_T_FMT")\n", image[imlist[i][0]].name, i, N, IMAGE_TOOFEW, N, IMAGE_GOOD_FRACTION, Nlist[i]);405 if (VERBOSE2) { fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), ("OFF_T_FMT" < %d) || ("OFF_T_FMT" < %f*"OFF_T_FMT")\n", image[imlist[i][0]].name, i, N, IMAGE_TOOFEW, N, IMAGE_GOOD_FRACTION, Nlist[i]); } 403 406 mosaic[i].flags |= ID_IMAGE_PHOTOM_FEW; 404 407 Nfew ++; … … 410 413 if (PoorImages) fprintf (stderr, "Mmos: %f %f %d "OFF_T_FMT"\n", stats.mean, stats.sigma, stats.Nmeas, N); 411 414 mosaic[i].Mcal = stats.mean; 412 mosaic[i].dMcal = stats.sigma; 415 mosaic[i].dMcal = stats.error; 416 mosaic[i].dMsys = stats.sigma; 417 mosaic[i].nFitPhotom = N; 413 418 mosaic[i].Xm = 100.0*log10(stats.chisq); 414 419 } -
branches/czw_branch/20101203/Ohana/src/relphot/src/args.c
r27586 r30631 1 1 # include "relphot.h" 2 void usage (void);3 2 4 3 int args (int argc, char **argv) { … … 53 52 } 54 53 54 USE_BASIC_CHECK = FALSE; 55 if ((N = get_argument (argc, argv, "-basic-image-search"))) { 56 remove_argument (N, &argc, argv); 57 USE_BASIC_CHECK = TRUE; 58 } 59 55 60 VERBOSE = VERBOSE2 = FALSE; 56 61 if ((N = get_argument (argc, argv, "-v"))) { … … 228 233 if (UpdateAverages && (argc == 1)) return TRUE; 229 234 if (UserPatchSelect && (argc == 2)) return TRUE; 230 if (argc != 3) usage ();235 if (argc != 3) relphot_usage (); 231 236 232 237 return TRUE; 233 238 } 234 235 void usage () {236 fprintf (stderr, "ERROR: USAGE: relphot (region) (photcode)\n");237 fprintf (stderr, " or: relphot (photcode) -region RA RA DEC DEC\n");238 fprintf (stderr, " or: relphot -averages -region RA RA DEC DEC\n");239 fprintf (stderr, " options: \n");240 fprintf (stderr, " -time (start) (stop)\n");241 fprintf (stderr, " -v : verbose output\n");242 fprintf (stderr, " -vv : more verbose output\n");243 fprintf (stderr, " -outroot (outroot)\n");244 fprintf (stderr, " -plot\n");245 fprintf (stderr, " -plotdelay (seconds)\n");246 fprintf (stderr, " -statmode (mode)\n");247 fprintf (stderr, " -refcode (name) : give extra weight to this photcode\n");248 fprintf (stderr, " -n (nloop)\n");249 fprintf (stderr, " -reset\n");250 fprintf (stderr, " -update\n");251 fprintf (stderr, " -params\n");252 fprintf (stderr, " -mosaic (mosaic)\n");253 fprintf (stderr, " -imfreeze\n");254 fprintf (stderr, " -grid\n");255 fprintf (stderr, " -area Xmin Xmax Ymin Ymax\n");256 fprintf (stderr, " -instmag min max\n");257 fprintf (stderr, " \n");258 exit (2);259 } -
branches/czw_branch/20101203/Ohana/src/relphot/src/bcatalog.c
r28660 r30631 119 119 120 120 if (VERBOSE) { 121 fprintf (stderr, "using "OFF_T_FMT" stars ("OFF_T_FMT" measures) of "OFF_T_FMT" for catalog \n",122 subcatalog[0].Naverage, subcatalog[0].Nmeasure, i);121 fprintf (stderr, "using "OFF_T_FMT" stars ("OFF_T_FMT" measures) of "OFF_T_FMT" for catalog %s\n", 122 subcatalog[0].Naverage, subcatalog[0].Nmeasure, i, catalog[0].filename); 123 123 fprintf (stderr, "rejections: %d code, %d time, %d dophot, %d mag, %d sigma, %d imag, %d few\n", 124 124 Ncode, Ntime, Ndophot, Nmag, Nsigma, Nimag, Nfew); -
branches/czw_branch/20101203/Ohana/src/relphot/src/initialize.c
r29001 r30631 5 5 int N; 6 6 7 relphot_help (argc, argv); 7 8 ConfigInit (&argc, argv); 8 9 args (argc, argv); -
branches/czw_branch/20101203/Ohana/src/relphot/src/load_catalogs.c
r29754 r30631 6 6 Catalog *catalog, tcatalog; 7 7 8 if (VERBOSE ) fprintf (stderr, "loading catalog data\n");8 if (VERBOSE2) fprintf (stderr, "loading catalog data\n"); 9 9 10 10 ALLOCATE (catalog, Catalog, skylist[0].Nregions); … … 22 22 tcatalog.Nsecfilt = GetPhotcodeNsecfilt (); // set the desired number in case we need to create the catalog 23 23 24 if (!dvo_catalog_open (&tcatalog, skylist[0].regions[i], VERBOSE , "r")) {24 if (!dvo_catalog_open (&tcatalog, skylist[0].regions[i], VERBOSE2, "r")) { 25 25 fprintf (stderr, "ERROR: failure reading catalog %s\n", tcatalog.filename); 26 26 exit (1); 27 27 } 28 if (VERBOSE && !tcatalog.Naves_disk) fprintf (stderr, "no data in %s, skipping\n", tcatalog.filename); 28 if (!tcatalog.Naves_disk) { 29 if (VERBOSE2) { fprintf (stderr, "no data in %s, skipping\n", tcatalog.filename); } 30 dvo_catalog_unlock (&tcatalog); 31 dvo_catalog_free (&tcatalog); 32 continue; 33 } 34 29 35 Nstar_total += tcatalog.Naverage; 30 36 Nmeas_total += tcatalog.Nmeasure; -
branches/czw_branch/20101203/Ohana/src/relphot/src/load_images.c
r29001 r30631 1 1 # include "relphot.h" 2 3 # define MARKTIME(MSG,...) { \ 4 float dtime; \ 5 gettimeofday (&stop, (void *) NULL); \ 6 dtime = DTIME (stop, start); \ 7 fprintf (stderr, MSG, __VA_ARGS__); } 2 8 3 9 SkyList *load_images (FITS_DB *db, char *regionName, SkyRegion *region, int RegionSelect) { … … 6 12 off_t Nimage, Nsubset, Nchar; 7 13 off_t *LineNumber; 14 struct timeval start, stop; 8 15 9 16 SkyTable *sky = NULL; 10 17 SkyList *skylist = NULL; 18 19 gettimeofday (&start, (void *) NULL); 11 20 12 21 // load the current sky table (layout of all SkyRegions) … … 29 38 exit (2); 30 39 } 40 MARKTIME("read image table: %f sec\n", dtime); 31 41 32 42 // select the images which overlap the selected sky regions 33 43 subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset); 44 MARKTIME("selected images: %f sec\n", dtime); 34 45 35 46 gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset); 47 MARKTIME("converted ftable to vtable: %f sec\n", dtime); 36 48 37 49 initImages (subset, Nsubset); 50 MARKTIME("init images: %f sec\n", dtime); 51 38 52 initMosaics (subset, Nsubset); 53 MARKTIME("init mosaics: %f sec\n", dtime); 39 54 40 55 return (skylist); -
branches/czw_branch/20101203/Ohana/src/relphot/src/relphot.c
r27480 r30631 85 85 if (PLOTSTUFF) { 86 86 plot_star_coords (catalog, Ncatalog); 87 plot_mosaic_fields (catalog);87 // plot_mosaic_fields (catalog); 88 88 } 89 89 -
branches/czw_branch/20101203/Ohana/src/relphot/src/select_images.c
r29001 r30631 15 15 void dsortindex (double *X, off_t *Y, int N); 16 16 off_t getRegionStartByRA (double R, double *Rref, off_t Nregions); 17 18 # define MARKTIME(MSG,...) { \ 19 float dtime; \ 20 gettimeofday (&stop, (void *) NULL); \ 21 dtime = DTIME (stop, start); \ 22 fprintf (stderr, MSG, __VA_ARGS__); } 17 23 18 24 Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage) { … … 25 31 Coords tcoords; 26 32 SkyRegionCoords *skycoords; 27 33 struct timeval start, stop; 34 35 double RmaxSkyRegion, RminSkyRegion, DminSkyRegion, DmaxSkyRegion, RmidSkyRegion; 36 28 37 double *RmaxSky; 29 38 off_t *index; … … 35 44 return NULL; 36 45 } 46 47 gettimeofday (&start, (void *) NULL); 37 48 38 49 // the comparison is made in the catalog local projection. below we set crval1,2 … … 47 58 ALLOCATE (RmaxSky, double, skylist[0].Nregions); 48 59 ALLOCATE (index, off_t, skylist[0].Nregions); 60 61 RminSkyRegion = +360.0; 62 RmaxSkyRegion = -360.0; 63 DminSkyRegion = +90.0; 64 DmaxSkyRegion = -90.0; 49 65 50 66 /* compare with each region file */ … … 75 91 skycoords[i].Xc[3] -= dx; skycoords[i].Yc[3] += dy; 76 92 skycoords[i].Xc[4] -= dx; skycoords[i].Yc[4] -= dy; 77 } 93 94 RminSkyRegion = MIN(RminSkyRegion, skylist[0].regions[i][0].Rmin); 95 RmaxSkyRegion = MAX(RmaxSkyRegion, skylist[0].regions[i][0].Rmax); 96 DminSkyRegion = MIN(DminSkyRegion, skylist[0].regions[i][0].Dmin); 97 DmaxSkyRegion = MAX(DmaxSkyRegion, skylist[0].regions[i][0].Dmax); 98 } 99 RmidSkyRegion = 0.5*(RminSkyRegion + RmaxSkyRegion); 100 MARKTIME("create sky region coords: %f sec\n", dtime); 78 101 79 102 dsortindex (RmaxSky, index, skylist[0].Nregions); 103 MARKTIME("sort sky coords: %f sec\n", dtime); 80 104 81 105 if (VERBOSE) fprintf (stderr, "finding images\n"); 82 106 BuildChipMatch (timage, Ntimage); 107 MARKTIME("build chip match: %f sec\n", dtime); 83 108 84 109 nimage = 0; … … 100 125 } 101 126 127 // this adds 1.3 sec for 3M images 102 128 if (!FindMosaicForImage (timage, Ntimage, i)) { 103 129 fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i); … … 113 139 found = FALSE; 114 140 115 /* transform corners to ra,dec */141 /* transform corners to ra,dec -- costs ~3sec for 3M images */ 116 142 double RminImage = 360.0; 143 double RmaxImage = 0.0; 144 double DminImage = +90.0; 145 double DmaxImage = -90.0; 117 146 for (j = 0; j < 5; j++) { 118 147 XY_to_RD (&Ri[j], &Di[j], Xi[j], Yi[j], &timage[i].coords); 148 Ri[j] = ohana_normalize_angle_to_midpoint (Ri[j], RmidSkyRegion); 149 119 150 RminImage = MIN(RminImage, Ri[j]); 120 } 121 122 // RA(nStart) is guaranteed to be < RminImage: 151 RmaxImage = MAX(RmaxImage, Ri[j]); 152 DminImage = MIN(DminImage, Di[j]); 153 DmaxImage = MAX(DmaxImage, Di[j]); 154 } 155 if (RmaxImage - RminImage > 180.0) { 156 double tmp = RminImage; 157 RmaxImage = RminImage; 158 RminImage = tmp - 360.0; 159 } 160 161 // check that this image is even in range of the searched region 162 if (DminImage > DmaxSkyRegion) continue; 163 if (DmaxImage < DminSkyRegion) continue; 164 165 // the sky region RA is defined to be 0 - 360.0 166 if (RminImage > RmaxSkyRegion) continue; 167 if (RmaxImage < RminSkyRegion) continue; 168 169 // image overlaps region, keep it 170 if (USE_BASIC_CHECK) goto found_it; 171 172 // RA(nStart) is guaranteed to be < RminImage: -- costs 0.5sec for 3M images 123 173 nStart = getRegionStartByRA (RminImage, RmaxSky, skylist[0].Nregions); 124 174 125 175 /* compare with each region file */ 126 for (iSky = 0; (iSky < skylist[0].Nregions) && !found; iSky++) {176 for (iSky = nStart; (iSky < skylist[0].Nregions) && !found; iSky++) { 127 177 128 178 m = index[iSky]; … … 142 192 for (j = 0; (j < 4) && !found; j++) { 143 193 found = corner_check (&Xi[j], &Yi[j], &skycoords[m].Xc[0], &skycoords[m].Yc[0]); 194 if (found) goto found_it; 144 195 } 145 196 /* check if catalog corner inside image */ 146 197 for (j = 0; (j < 4) && !found; j++) { 147 198 found = corner_check (&skycoords[m].Xc[j], &skycoords[m].Yc[j], &Xi[0], &Yi[0]); 199 if (found) goto found_it; 148 200 } 149 201 /* check if edges cross */ … … 151 203 for (k = 0; (k < 4) && !found; k++) { 152 204 found = edge_check (&Xi[j], &Yi[j], &skycoords[m].Xc[k], &skycoords[m].Yc[k]); 205 if (found) goto found_it; 153 206 } 154 207 } 155 if (!found) continue; 156 157 image[nimage] = timage[i]; 158 /* always allow 'few' images to succeed, if possible */ 159 if (image[nimage].flags & ID_IMAGE_PHOTOM_FEW) { 160 image[nimage].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR); 161 } 162 if (RESET) { 163 assignMcal (&image[nimage], (double *) NULL, -1); 164 image[nimage].dMcal = NAN; 165 image[nimage].flags &= ~ID_IMAGE_PHOTOM_POOR; 166 } 167 line_number[nimage] = i; 168 nimage ++; 169 if (nimage == NIMAGE) { 170 NIMAGE += 100; 171 REALLOCATE (image, Image, NIMAGE); 172 REALLOCATE (line_number, off_t, NIMAGE); 173 } 174 } 175 } 176 208 } 209 if (!found) continue; 210 211 found_it: 212 image[nimage] = timage[i]; 213 /* always allow 'few' images to succeed, if possible */ 214 if (image[nimage].flags & ID_IMAGE_PHOTOM_FEW) { 215 image[nimage].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR); 216 } 217 if (RESET) { 218 // XXX assignMcal (&image[nimage], (double *) NULL, -1); 219 // XXX this needs to be thought through a bit more 220 image[nimage].Mcal = 0.0; 221 image[nimage].dMcal = NAN; 222 image[nimage].flags &= ~ID_IMAGE_PHOTOM_POOR; 223 } 224 line_number[nimage] = i; 225 nimage ++; 226 if (nimage == NIMAGE) { 227 NIMAGE += 100; 228 REALLOCATE (image, Image, NIMAGE); 229 REALLOCATE (line_number, off_t, NIMAGE); 230 } 231 } 232 MARKTIME("finish image selection: %f sec\n", dtime); 233 177 234 if (VERBOSE) fprintf (stderr, "found "OFF_T_FMT" images\n", nimage); 178 235 … … 295 352 return (Nlo); 296 353 } 354 355 off_t getRegionStopByRA (double R, double *Rref, off_t Nregions) { 356 357 // use bisection to find the overlapping mosaic 358 359 off_t Nlo, Nhi, N; 360 361 // find the last mosaic before start 362 Nlo = 0; Nhi = Nregions; 363 while (Nhi - Nlo > 10) { 364 N = 0.5*(Nlo + Nhi); 365 if (Rref[N] < R) { 366 Nlo = MAX(N, 0); 367 } else { 368 Nhi = MIN(N, Nregions); 369 } 370 } 371 return (Nlo); 372 } -
branches/czw_branch/20101203/Ohana/src/skycalc/Makefile
r19681 r30631 20 20 libskycalc: $(DESTLIB)/libskycalc.a $(DESTLIB)/libskycalc.$(DLLTYPE) 21 21 22 all: libskycalc dusktime moondata sundata 22 all: libskycalc dusktime moondata sundata sunriseset 23 23 programs: all 24 24 … … 43 43 44 44 dusktime : $(BIN)/dusktime.$(ARCH) 45 sunriseset : $(BIN)/sunriseset.$(ARCH) 45 46 moondata : $(BIN)/moondata.$(ARCH) 46 47 sundata : $(BIN)/sundata.$(ARCH) … … 48 49 49 50 DUSKTIME = $(SRC)/dusktime.$(ARCH).o 51 SUNRISESET = $(SRC)/sunriseset.$(ARCH).o 50 52 MOONDATA = $(SRC)/moondata.$(ARCH).o 51 53 SUNDATA = $(SRC)/sundata.$(ARCH).o … … 53 55 54 56 $(DUSKTIME) : $(MYINCS) 57 $(SUNRISESET) : $(MYINCS) 55 58 $(MOONDATA) : $(MYINCS) 56 59 $(SUNDATA) : $(MYINCS) … … 58 61 59 62 $(BIN)/dusktime.$(ARCH) : $(DUSKTIME) 63 $(BIN)/sunriseset.$(ARCH) : $(SUNRISESET) 60 64 $(BIN)/moondata.$(ARCH) : $(MOONDATA) 61 65 $(BIN)/sundata.$(ARCH) : $(SUNDATA) 62 66 $(BIN)/sunmoon.$(ARCH) : $(SUNMOON) 63 67 64 INSTALL = dusktime moondata sundata sunmoon68 INSTALL = dusktime sunriseset moondata sundata sunmoon 65 69 66 70 # dependancy rules for binary code ######################### -
branches/czw_branch/20101203/Ohana/src/tools/src/roc.c
r30586 r30631 4 4 # include <regex.h> 5 5 6 // # define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } } 7 # define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); exit(1); } } 6 # define myAssert(LOGIC,...) { if (!(LOGIC)) { fprintf (stderr, __VA_ARGS__); abort(); } } 8 7 9 8 # define ROC_HEADER_SIZE 0x1000 … … 15 14 int roc_insert (int argc, char **argv); 16 15 int roc_delete (int argc, char **argv); 16 int roc_validate (int argc, char **argv); 17 17 18 int usage (void); 18 19 int print_block (char *header, int *header_size, int *Noff, char *format,...); … … 29 30 if (!strcasecmp(argv[1], "-insert")) roc_insert (argc, argv); 30 31 if (!strcasecmp(argv[1], "-delete")) roc_delete (argc, argv); 32 if (!strcasecmp(argv[1], "-validate")) roc_validate (argc, argv); 31 33 32 34 usage(); … … 302 304 } 303 305 306 int roc_validate (int argc, char **argv) { 307 308 int i, j, n, Ninput, Nblocks, header_size, Nbytes, Nread; 309 off_t *sizes, *bytes_read; 310 char value; 311 char *header, *line, *ptr; 312 char **inputName, *targetName; 313 char **inputData; 314 char *targetData; 315 FILE **input, *target; 316 317 if (argc != 3) usage(); 318 319 320 /* find the md5 sum for each input file (ADD LATER) 321 * find the size of the input files 322 * define the output file size = MAX(sizes) 323 * create the target file header 324 */ 325 326 // the output file 327 targetName = argv[2]; 328 329 target = fopen(targetName, "r"); 330 myAssert (target, "failed to open roc datafile %s\n",targetName); 331 332 ALLOCATE (line, char, 1024); 333 334 scan_line (target, line); 335 myAssert (!strncmp(line, "ROC Version 0", strlen("ROC Verion 0")), "invalid ROC file or format in %s",targetName); 336 337 scan_line (target, line); 338 sscanf (line, "HEADER SIZE %x", &header_size); 339 340 ALLOCATE (header, char, header_size); 341 342 // read the full header 343 fseeko (target, 0, SEEK_SET); 344 Nbytes = fread (header, 1, header_size, target); 345 myAssert (Nbytes == header_size, "failed to read header data\n"); 346 347 ptr = header; 348 ptr = strchr (ptr, '\n'); ptr ++; // ROC Version 349 ptr = strchr (ptr, '\n'); ptr ++; // HEADER SIZE 350 351 sscanf (ptr, "N_FILES %d", &Ninput); ptr = strchr (ptr, '\n'); ptr ++; 352 sscanf (ptr, "N_BLOCKS %d", &Nblocks); ptr = strchr (ptr, '\n'); ptr ++; 353 354 // the input files 355 ALLOCATE (inputName, char *, Ninput); 356 ALLOCATE (sizes, off_t, Ninput); 357 ALLOCATE (bytes_read, off_t, Ninput); 358 for (i = 0; i < Ninput; i++) { 359 ALLOCATE (inputName[i], char, 1024); 360 sscanf (ptr, "%*s : %s", inputName[i]); ptr = strchr (ptr, '\n'); ptr ++; 361 ptr = strchr (ptr, '\n'); ptr ++; // BASE 362 sscanf (ptr, "%*s : "OFF_T_FMT, &sizes[i]); ptr = strchr (ptr, '\n'); ptr ++; 363 ptr = strchr (ptr, '\n'); ptr ++; // MD5 364 bytes_read[i] = 0; 365 } 366 367 ALLOCATE (input, FILE *, Ninput); 368 for (i = 0; i < Ninput; i++) { 369 input[i] = fopen(inputName[i], "r"); 370 myAssert (input[i], "failed to open file %s in %s\n",inputName[i],targetName); 371 } 372 373 ALLOCATE (inputData, char *, Ninput); 374 ALLOCATE (targetData, char, ROC_BLOCKSIZE); 375 for (i = 0; i < Ninput; i++) { 376 ALLOCATE (inputData[i], char, ROC_BLOCKSIZE); 377 } 378 379 for (n = 0; n < Nblocks; n++) { 380 for (i = 0; i < Ninput; i++) { 381 Nread = MIN (ROC_BLOCKSIZE, sizes[i] - bytes_read[i]); 382 Nbytes = fread (inputData[i], 1, Nread, input[i]); 383 myAssert (Nbytes == Nread, "failed to read data file: %s read: %d expect: %d prev_read: %d block: %d in %s\n",inputName[i],Nbytes,Nread,(int) bytes_read[i],n,targetName); 384 if (Nread < ROC_BLOCKSIZE) { 385 // if we have reached the end of the file, fill in the rest with NULLs 386 memset (&inputData[i][Nread], 0, ROC_BLOCKSIZE - Nread); 387 } 388 bytes_read[i] += Nread; 389 } 390 Nbytes = fread (targetData, 1, ROC_BLOCKSIZE, target); 391 myAssert (Nbytes == ROC_BLOCKSIZE, "failed to read roc file: %s read: %d expect %d\n", targetName, Nbytes, ROC_BLOCKSIZE); 392 393 for (j = 0; j < ROC_BLOCKSIZE; j++) { 394 value = targetData[j]; 395 for (i = 0; i < Ninput; i++) { 396 value = value ^ inputData[i][j]; 397 } 398 myAssert(value == 0, "validation failed on block %d and byte %d in %s\n",n,j,targetName); 399 } 400 401 } 402 403 for (i = 0; i < Ninput; i++) { 404 fclose(input[i]); 405 } 406 407 fclose (target); 408 409 fprintf (stderr, "validation: %s appears correct.\n",targetName); 410 exit (0); 411 } 412 304 413 int roc_insert (int argc, char **argv) { 305 414 … … 334 443 fprintf (stderr, " -create (target) (input) (input) (input) ... [options]\n"); 335 444 fprintf (stderr, " -repair (target) (file #) (output\n"); 445 fprintf (stderr, " -validate (target)\n"); 336 446 fprintf (stderr, " -insert (target) (input)\n"); 337 447 fprintf (stderr, " -delete (target) (file)\n"); 448 338 449 exit (2); 339 450 } -
branches/czw_branch/20101203/PS-IPP-Config/lib/PS/IPP/Config.pm
r30586 r30631 1148 1148 if ($neb->storage_object_exists($output)) { 1149 1149 if ($delete_existing) { 1150 # avoid dead instances by moving the file before deleting it. 1151 # append current time to form new name 1152 my $todelete; 1153 eval { 1154 # parse the key so that we can compute the new name 1155 require Nebulous::Key; 1156 }; 1157 if ($@) { 1158 carp "Can't find Nebulous::Key"; 1159 $$r_error = $PS_EXIT_CONFIG_ERROR; 1160 return undef; 1161 } 1162 eval { 1163 # parse the key so that we can compute the new name 1164 my $neb_key = Nebulous::Key::parse_neb_key($output); 1165 die "parse_neb_key failed" if !$neb_key; 1166 my $path = $neb_key->path; 1167 die "neb_key has no path" if !$path; 1168 my $ticks = time(); 1169 $todelete = "ipp_trash/$path.$ticks"; 1170 $neb->move($output, $todelete); 1171 }; 1172 if ($@) { 1173 carp "nebulous move failed for $output"; 1150 $$r_error = $self->_kill_nebulous_file($output); 1151 if ($$r_error) { 1174 1152 $output = undef; 1175 $$r_error = $PS_EXIT_SYS_ERROR;1176 }1177 if ($todelete) {1178 eval {1179 $neb->delete($todelete);1180 };1181 if ($@) {1182 carp "nebulous delete for $todelete failed. Ignoring.\n";1183 $$r_error = $PS_EXIT_SYS_ERROR;1184 }1185 1153 } 1186 1154 } else { 1187 1155 # Make sure that there is only 1 instance. 1188 1189 1156 eval { 1190 1157 $neb->there_can_be_only_one($output); … … 1198 1165 } 1199 1166 return $output; 1167 } 1168 1169 # _kill_nebulous_file: reliably get a nebulous file out of way. 1170 # First move it to the trash then attempt to delete it. No failure if delete fails. 1171 # The file is in the trash. 1172 # Assumes that file is a nebulous file with a storage object that exists 1173 # Users should call kill_file() 1174 # Returns 0 on success otherwise and a PS_EXIT error code on failure 1175 sub _kill_nebulous_file { 1176 my $self = shift; 1177 my $filename = shift; 1178 my $neb = $self->nebulous; 1179 1180 # avoid dead instances by moving the file before deleting it. 1181 # append current time to form new name 1182 my $todelete; 1183 eval { 1184 # parse the key so that we can compute the new name 1185 require Nebulous::Key; 1186 }; 1187 if ($@) { 1188 carp "Can't find Nebulous::Key"; 1189 return $PS_EXIT_CONFIG_ERROR; 1190 } 1191 eval { 1192 # parse the key so that we can compute the new name 1193 my $neb_key = Nebulous::Key::parse_neb_key($filename); 1194 die "parse_neb_key failed" if !$neb_key; 1195 my $path = $neb_key->path; 1196 die "neb_key has no path" if !$path; 1197 my $ticks = time(); 1198 $todelete = "ipp_trash/$path.$ticks"; 1199 $neb->move($filename, $todelete); 1200 }; 1201 if ($@) { 1202 carp "nebulous move failed for $filename"; 1203 return $PS_EXIT_SYS_ERROR; 1204 } 1205 if ($todelete) { 1206 eval { 1207 $neb->delete($todelete); 1208 }; 1209 if ($@) { 1210 carp "nebulous delete for $todelete failed. Ignoring.\n"; 1211 return $PS_EXIT_SYS_ERROR; 1212 } 1213 } 1214 return 0; 1215 } 1216 1217 # user level interface to kill_file reliably get a file out of way. 1218 # 1219 # If a nebulous file, move it to the trash then attempt to delete it. 1220 # if non nebulous file just delete it. 1221 # Returns 0 on success otherwise and a PS_EXIT error code on failure 1222 1223 sub kill_file { 1224 my $self = shift; 1225 my $filename = shift; 1226 my $neb = $self->nebulous; 1227 1228 my $scheme = file_scheme($filename); 1229 if (!$scheme or ($scheme ne 'neb')) { 1230 if ($self->file_exists($filename)) { 1231 if (!$self->file_delete($filename)) { 1232 carp "failed to delete $filename"; 1233 return $PS_EXIT_SYS_ERROR; 1234 } 1235 } 1236 } elsif ($neb->storage_object_exists($filename)) { 1237 $self->_kill_nebulous_file($filename); 1238 } 1239 return 0; 1200 1240 } 1201 1241 -
branches/czw_branch/20101203/doc/psphot/psphot.tex
r21455 r30631 159 159 Python). 160 160 161 \note{discuss the psphot program varients} 162 161 163 \section{PSPhot Design Goals} 162 164 … … 276 278 \end{itemize} 277 279 278 Note that a given run of PSPhot \note{should} allow the user to279 perform any of these stages as an option. For example, the PSF model 280 may already be available from external information, in which case the 281 PSF modeling stage can be skipped. Or, when used as a library 282 function, the image may have already been loaded and the mask and 283 weight images constructed. In some implementations, it may be284 possible to skip the initial object detection stage because only 285 supplied sources are measured. These are only some of the possible286 configurations. The use of these different configurations depends on 287 the source of the image, the desired detail and speed of the 288 processing, and the levelof accuracy desired from the analysis.280 Note that a given run of PSPhot allows the user to perform many of 281 these stages only if needed. For example, the PSF model may already be 282 available from external information, in which case the PSF modeling 283 stage can be skipped. Or, when used as a library function, the image 284 may have already been loaded and the mask and weight images 285 constructed. In some implementations, it may be possible to skip the 286 initial object detection stage because only supplied sources are 287 measured. These are only some of the possible configurations. The 288 use of these different configurations depends on the source of the 289 image, the desired detail and speed of the processing, and the level 290 of accuracy desired from the analysis. 289 291 290 292 \subsection{Image Preparation} … … 292 294 The first step is to prepare the image for detection of the 293 295 astronomical objects. We need three separate images: the measured 294 flux, the corresponding noise level, and a mask defining which pixels295 are valid and which should be ignored. For the stand-alone program, 296 the input flux image is a required program argument. When it is 297 loaded, it is converted by default to 32-bit floating point296 flux, the corresponding variance image, and a mask defining which 297 pixels are valid and which should be ignored. For the stand-alone 298 program, the input flux image is a required program argument. When it 299 is loaded, it is converted by default to 32-bit floating point 298 300 representation. In the function-call form of PSPhot, the image must 299 301 be supplied by the user in 32-bit floating point format. The noise … … 307 309 automatically by PSPhot. 308 310 309 For the mask, we use an 8-bit image in which a value of 0 represents a 310 valid pixel. We use each of the 8 bits to define different reasons a 311 pixel should be ignored. This allows use to optionally respect or 311 \note{describe the use of the covariance image} 312 \note{describe the difference between 'bad' and 'suspect' pixels} 313 314 For the mask, we use a 16-bit image in which a value of 0 represents a 315 valid pixel. We use each of the 16 bits to define different reasons a 316 pixel should be ignored. This allows us to optionally respect or 312 317 ignore the mask depending on the circumstance. For example, in some 313 318 cases, we ignore saturated pixels completely while in other … … 325 330 \code{XMIN}, \code{XMAX}, \code{YMIN}, \code{YMAX}. 326 331 327 \note{Mask values are currently hard-wired numbers. We need a method 328 for user-defined mask values to be supplied. PSLib needs to have a 329 mask registration system.} 332 \note{discuss the mask.config file, in which the mask meanings are assigned to bit values} 330 333 331 334 The noise image, if not supplied is constructed by default from the … … 337 340 valid. For example, if the input flux image is the result of an image 338 341 stack with significantly variable number of input measurements per 339 pixel, it will necessary to supply a noise image which accurately342 pixel, it will be necessary to supply a noise image which accurately 340 343 represents the noise as a function of position in the image. 341 344 … … 343 346 344 347 The objects are initially detected by finding the location of local 345 peaks in the image. The flux image is smoothed with a very small 346 circularly symmetric kernel using a two-pass 1D Gaussian. At this 348 peaks in the image. The flux and variance images are smoothed with a 349 small circularly symmetric kernel using a two-pass 1D Gaussian 350 (\note{KEYWORD?}). The smoothed flux and variance images are combined 351 to generate a significance image in signal-to-noise units 352 \note{including correction for the covariance, if known}. At this 347 353 stage, the goal is only to detect the brighter sources, above a user 348 354 defined S/N limit (configuration keyword: \code{PEAK_NSIGMA}). The 349 355 detection efficiency for the brighter sources is not strongly 350 356 dependent on the form of this smoothing function. 351 352 \note{Is this smoothing needed? we could save time here by skipping353 it.}354 357 355 358 The local peaks in the smoothed image are found by first detecting … … 364 367 the maximum $X$ and $Y$ corners of the region. 365 368 366 \note{The current implementation ignores the S/N map in making the 367 peak detection. This code must be modified (a la Kaiser) to be used 368 for a peak-detection pass in a difference image or to re-find peaks in 369 the image after the modeled objects have been subtracted}. 369 \subsection{Footprints} 370 371 \note{need to describe the process of generating the source footprints 372 and then culling the insignificant peaks} 373 374 \subsubsection{Moments and related} 375 376 \note{disucss the Kron mags} 377 378 \note{this section is wrong: we no longer use S/N clipping, but a 379 Gaussian window function, chosed based on the measured moment} 370 380 371 381 Once a collection of peaks have been identified, basic properties of … … 391 401 392 402 \subsubsection{Determination of the Peak Coordinates and Errors} 403 404 \note{this section is wrong: it is a poor estimator of the source 405 position errors. we gave up a reverted to using the FWHM / (S/N)} 393 406 394 407 We use the 9 pixels which include the source peak to fit for the … … 605 618 the minimization values. PSPhot uses the first and second moments to 606 619 make a good guess for the centroid and shape parameters for the PSF 607 models. In order to minimize the impact of close neighbors, the noise 608 values used in the fit are enhanced by a fraction of the deviation of 609 the particular pixel value from the model guess. Any objects which 610 fail to converge in the fit are flagged as invalid. 620 models. \note{still true? In order to minimize the impact of close 621 neighbors, the noise values used in the fit are enhanced by a 622 fraction of the deviation of the particular pixel value from the 623 model guess.} Any objects which fail to converge in the fit are 624 flagged as invalid. 611 625 612 626 \note{does the noise enhancement introduce too much bias?} … … 1044 1058 1045 1059 \subsection{Difference Images} 1046 1047 \note{much of this discussion is theoretical: PSPhot can incorporate1048 these modifications, but it currently does not.}1049 1060 1050 1061 The noise map for a difference image must be generated from the two -
branches/czw_branch/20101203/ippScripts/scripts/diff_skycell.pl
r28593 r30631 117 117 } 118 118 119 # ppSub does (input) - (template) after PSF-match convolution. 120 # one of the files needs to be assigned to 'input' and the other to 'template'. 121 # if either of these is a WARP, then we can perform magic on it. If we are going to 122 # run magic, then we need to save the convolved version of the OTHER image 123 # (see magic_process.pl:155) 124 119 125 foreach my $file (@$files) { 120 126 if (defined $file->{template} and $file->{template}) { 121 # $template = $file->{uri};122 127 $templatePath = $file->{path_base}; 123 128 if ($file->{warp_id} == 0) { … … 142 147 $templateSources = "PSWARP.OUTPUT.SOURCES"; 143 148 $templateMagic = $file->{magicked}; 144 $saveRefConv = 1; 145 } 146 } else { 147 # $input = $file->{uri}; 149 $saveInConv = 1; 150 } 151 } else { 148 152 $inputPath = $file->{path_base}; 149 153 $inputMagic = $file->{magicked}; # if input is a stack the output can't be "magicked" … … 165 169 $inputVariance = "PSWARP.OUTPUT.VARIANCE"; 166 170 $inputSources = "PSWARP.OUTPUT.SOURCES"; 167 $save InConv = 1;171 $saveRefConv = 1; 168 172 } 169 173 } -
branches/czw_branch/20101203/ippScripts/scripts/ipp_apply_burntool_single.pl
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/czw_branch/20101203/ippScripts/scripts/ipp_apply_burntool_single.pl merged eligible /branches/eam_branches/ipp-20101205/ippScripts/scripts/ipp_apply_burntool_single.pl merged eligible /trunk/ippScripts/scripts/ipp_apply_burntool_single.pl merged eligible /branches/eam_branches/ipp-20101103/ippScripts/scripts/ipp_apply_burntool_single.pl 29657-29920
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/czw_branch/20101203/ippScripts/scripts/ipp_cleanup.pl
r30587 r30631 1900 1900 { 1901 1901 my $files = shift; # reference to a list of files to unlink 1902 # my $test_verbose = 1; 1903 1904 # if ($test_verbose == 1) { 1905 # open(TMPLOG,">>/tmp/czw.cleanup.log"); 1906 # flock(TMPLOG,2); 1907 # } 1908 1909 # this script is, of course, very dangerous. 1902 1910 1903 foreach my $file (@$files) { 1911 1904 print STDERR "unlinking $stage $stage_id $file"; 1912 unless ($ipprc->file_exists($file)) { 1913 print STDERR "\t File not found\n"; 1914 } 1915 else { 1916 print STDERR "\n"; 1917 } 1918 1919 # if ($test_verbose == 1) { 1920 # print TMPLOG "$stage $stage_id $file"; 1921 1922 # else { 1923 # print TMPLOG "\n"; 1924 # } 1925 # } 1926 1927 $ipprc->file_delete($file); 1928 } 1929 1930 # if ($test_verbose == 1) { 1931 # flock(TMPLOG,8); 1932 # close(TMPLOG); 1933 # } 1905 1906 my $error_code = $ipprc->kill_file($file); 1907 1908 &my_die("failed to kill $file", $stage, $stage_id, $PS_EXIT_CONFIG_ERROR) if $error_code; 1909 } 1934 1910 1935 1911 return 1; -
branches/czw_branch/20101203/ippScripts/scripts/magic_destreak_cleanup.pl
r30587 r30631 44 44 'magic_ds_id=s' => \$magic_ds_id,# Magic destreak run identifier 45 45 'camera=s' => \$camera, # camera for evaluating file rules 46 'stage=s' => \$stage, # camera for evaluating file rules46 'stage=s' => \$stage, # ipp stage for this magicDSRun 47 47 'save-temps' => \$save_temps, # Save temporary files? 48 48 'dbname=s' => \$dbname, # Database name … … 160 160 my $backup_path_base = $comp->{backup_path_base}; 161 161 my ($bimage, $bmask, $bch_mask, $bweight, $bsources, $bastrom); 162 my ($rimage, $rmask, $rch_mask, $rweight, $rsources, $rastrom);162 # my ($rimage, $rmask, $rch_mask, $rweight, $rsources, $rastrom); 163 163 164 164 if ($stage eq "chip") { … … 219 219 } 220 220 221 delete_files($bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask , $rch_mask);221 delete_files($bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask); 222 222 223 223 if ($stage eq "diff" and $warp_warp) { … … 252 252 foreach my $file (@_) { 253 253 if ($file) { 254 if ($ipprc->file_exists($file)) { 255 if (!$no_update) { 256 print STDERR "deleting $file\n" if $verbose; 257 $ipprc->file_delete($file, 1) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR); 258 } else { 259 print STDERR "skipping delete $file\n"; 260 } 261 } else { 262 print STDERR "$file not found\n" if $verbose; 263 } 254 my $error_code = $ipprc->kill_file($file); 255 my_die("Failed to delete $file", $magic_ds_id, $error_code) if $error_code; 264 256 } 265 257 } -
branches/czw_branch/20101203/ippScripts/scripts/magic_process.pl
r29625 r30631 151 151 &my_die("failed to resolve inputs", $magic_id, $node, $PS_EXIT_DATA_ERROR); 152 152 } 153 154 # to run magic on a diff image, we need the convolved version 155 # of the corresponding TEMPLATE image 156 # (see diff_skycell.pl:124) 153 157 154 158 my $diff_base = $innode->{diff_path_base}; # Base name for diff -
branches/czw_branch/20101203/ippScripts/scripts/stack_skycell.pl
r30419 r30631 270 270 $command .= " -image_id $image_id" if defined $image_id; 271 271 $command .= " -source_id $source_id" if defined $source_id; 272 273 $command .= " -stack_id $stack_id" if defined $stack_id; 274 $command .= " -skycell_id $skycell_id" if defined $skycell_id; 275 $command .= " -tess_id $tess_base" if defined $tess_base; 276 272 277 if ($run_state eq 'new') { 273 278 $command .= " -dumpconfig $configuration"; -
branches/czw_branch/20101203/ippScripts/scripts/warp_skycell.pl
r30587 r30631 159 159 my $outputWeight = prepare_output ("PSWARP.OUTPUT.VARIANCE", $outroot, $skycell_id, 1); 160 160 my $outputSources = prepare_output ("PSWARP.OUTPUT.SOURCES", $outroot, $skycell_id, 1); 161 my $outputPSF = prepare_output ("PSPHOT.PSF.SKY.SAVE", $outroot, 1);161 my $outputPSF = prepare_output ("PSPHOT.PSF.SKY.SAVE", $outroot, $skycell_id, 1); 162 162 my $outputBin1 = prepare_output ("PSWARP.BIN1", $outroot, $skycell_id, 1); 163 163 my $outputBin2 = prepare_output ("PSWARP.BIN2", $outroot, $skycell_id, 1); -
branches/czw_branch/20101203/ippTasks/Makefile.am
r30586 r30631 48 48 site.manoa.pro \ 49 49 site.mhpcc.pro \ 50 site.mhpcc_testing.pro \51 50 surveys.mhpcc.config \ 52 51 simtest.pro \ -
branches/czw_branch/20101203/ippTools/share/camtool_find_pendingimfile.sql
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20101205/ippTools/share/camtool_find_pendingimfile.sql (added) merged: 30102,30579,30585
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/ippTools/share/pxadmin_create_tables.sql
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20101205/ippTools/share/pxadmin_create_tables.sql (added) merged: 30102,30446,30579,30585
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/ippTools/src
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20101205/ippTools/src (added) merged: 30102,30446,30530,30579,30584-30585
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/ippTools/src/difftool.c
r30587 r30631 2095 2095 } 2096 2096 2097 query = pxDataGet("difftool_definestackstack_part1.sql");2097 2098 2098 if (pretend) { 2099 2099 // negative simple so the default is true … … 2109 2109 psArray *list = psArrayAllocEmpty(16); // List of runs defined, to print 2110 2110 for (long i = 0; i < output->n; i++) { 2111 query = pxDataGet("difftool_definestackstack_part1.sql"); 2112 2113 2111 2114 psMetadata *row = output->data[i]; // Output row from query 2112 2115 bool mdok; // Status of MD lookup -
branches/czw_branch/20101203/ippTools/src/magictool.c
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20101205/ippTools/src/magictool.c (added) merged: 30446,30579,30585 /trunk/ippTools/src/magictool.c merged: 30594
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/ippTools/src/regtool.c
r30587 r30631 320 320 psStringSubstitute(&query,dateobs_end,"@DATEOBS_END@"); 321 321 322 fprintf(stderr,"%s",query);322 // fprintf(stderr,"%s",query); 323 323 324 324 if (!p_psDBRunQuery(config->dbh, query)) { … … 345 345 } 346 346 347 fprintf (stderr, "found %ld rows\n", output->n);347 // fprintf (stderr, "found %ld rows\n", output->n); 348 348 if (!psArrayLength(output)) { 349 349 psTrace("regtool", PS_LOG_INFO, "no rows found"); -
branches/czw_branch/20101203/ippconfig
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20101205/ippconfig (added) merged: 30084-30085,30102,30197,30269,30309-30311,30323,30385,30399,30448-30449,30581,30585
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/ippconfig/gpc1/dvo.config
r28215 r30631 52 52 IMAGE_OFFSET 0.100 # mark images POOR if abs(delta(Mcal)) > IMAGE_OFFSET 53 53 STAR_CHISQ 10.0 # mark stars POOR if Xm > STAR_CHISQ 54 STAR_TOOFEW 3# mark star FEW if N(good) < STAR_TOOFEW54 STAR_TOOFEW 2 # mark star FEW if N(good) < STAR_TOOFEW 55 55 GRID_TOOFEW 10 # keep grid FROZEN if N(good) < GRID_TOOFEW 56 56 IMAGE_TOOFEW 10 # mark image FEW if N(good) < IMAGE_TOOFEW -
branches/czw_branch/20101203/ippconfig/recipes/filerules-simple.mdc
r30118 r30631 195 195 196 196 # outputs for psphotStack: 197 PSPHOT.CHISQ.IMAGE OUTPUT {OUTPUT}.chisq.im.fits IMAGE NONE FPA TRUE SIMPLE198 PSPHOT.CHISQ.MASK OUTPUT {OUTPUT}.chisq.mk.fits MASK NONE FPA TRUE SIMPLE199 PSPHOT.CHISQ.VARIANCE OUTPUT {OUTPUT}.chisq.wt.fits VARIANCE NONE FPA TRUE SIMPLE200 PSPHOT.STACK.OUTPUT.IMAGE OUTPUT {OUTPUT}.{FILE.ID}.im.fits IMAGE NONE FPA TRUE SIMPLE201 PSPHOT.STACK.OUTPUT.MASK OUTPUT {OUTPUT}.{FILE.ID}.mk.fits MASK NONE FPA TRUE SIMPLE202 PSPHOT.STACK.OUTPUT.VARIANCE OUTPUT {OUTPUT}.{FILE.ID}.wt.fits VARIANCE NONE FPA TRUE SIMPLE197 PSPHOT.CHISQ.IMAGE OUTPUT {OUTPUT}.chisq.im.fits IMAGE NONE FPA TRUE NONE 198 PSPHOT.CHISQ.MASK OUTPUT {OUTPUT}.chisq.mk.fits MASK NONE FPA TRUE NONE 199 PSPHOT.CHISQ.VARIANCE OUTPUT {OUTPUT}.chisq.wt.fits VARIANCE NONE FPA TRUE NONE 200 PSPHOT.STACK.OUTPUT.IMAGE OUTPUT {OUTPUT}.{FILE.ID}.im.fits IMAGE NONE FPA TRUE NONE 201 PSPHOT.STACK.OUTPUT.MASK OUTPUT {OUTPUT}.{FILE.ID}.mk.fits MASK NONE FPA TRUE NONE 202 PSPHOT.STACK.OUTPUT.VARIANCE OUTPUT {OUTPUT}.{FILE.ID}.wt.fits VARIANCE NONE FPA TRUE NONE 203 203 PSPHOT.STACK.OUTPUT OUTPUT {OUTPUT}.{FILE.ID}.cmf CMF NONE FPA TRUE NONE 204 204 -
branches/czw_branch/20101203/ippconfig/recipes/ppSim.config
r29005 r30631 128 128 ZEROPOINT F32 NAN # exposure time (seconds) 129 129 SKY.MAGS F32 NAN # exposure time (seconds) 130 131 SEEING.MAX F32 NAN # exposure time (seconds) 132 SEEING.RAMP BOOL F # exposure time (seconds) 130 133 131 134 FILTER STR NONE # exposure time (seconds) -
branches/czw_branch/20101203/ippconfig/recipes/ppSub.config
r30118 r30631 2 2 3 3 KERNEL.TYPE STR ISIS # Kernel type to use (POIS|ISIS|SPAM|FRIES|GUNK|RINGS) 4 KERNEL.SIZE S32 15# Kernel half-size (pixels)4 KERNEL.SIZE S32 20 # Kernel half-size (pixels) 5 5 SPATIAL.ORDER S32 1 # Spatial polynomial order 6 6 REGION.SIZE F32 0 # Iso-kernel region size (pixels) 7 7 SOURCE.RADIUS F32 3.0 # Source matching radius (pixels) 8 STAMP.SPACING F32 300 # Typical spacing between stamps (pixels)9 STAMP.FOOTPRINT S32 15# Size of stamps (pixels)8 STAMP.SPACING F32 200 # Typical spacing between stamps (pixels) 9 STAMP.FOOTPRINT S32 20 # Size of stamps (pixels) 10 10 STAMP.THRESHOLD F32 5 # Flux threshold for stamps (stdev above background) 11 11 STRIDE S32 128 # Size of convolution patches (pixels) … … 32 32 INPUT.MATCH.MIN.SN F32 10.0 33 33 34 ADD.NOT.SUBTRACT BOOL FALSE # add the images instead of subtracting (ie, image + ref, not image - ref) 35 34 36 LOW.THRESHOLD F32 20.0 # Mask pixels below this threshold (std dev) 35 37 POOR.FRACTION F32 0.20 # Maximum fraction of bad weight for poor pixels … … 40 42 @ISIS.ORDERS S32 6 4 2 # Polynomial orders for ISIS kernels 41 43 44 #@ISIS.WIDTHS F32 2.4 5.0 10.0 # Gaussian kernel FWHM values 45 #@ISIS.ORDERS S32 6 4 2 # Polynomial orders for ISIS kernels 46 42 47 # for autoscaling, the above kernel widths are multiplied by the factor max(FWHM_1,FWHM_2) / SCALE.REF 43 48 SCALE BOOL TRUE # Scale kernel parameters by the seeing? 44 SCALE.REF F32 6.0 # FWHM reference for kernel parameter scaling49 SCALE.REF F32 5.0 # FWHM reference for kernel parameter scaling 45 50 SCALE.MIN F32 0.5 # Minimum scale value 46 51 SCALE.MAX F32 2.0 # Maximum scale value … … 93 98 # DUAL convolution is more sensitive to the number of kernels 94 99 # do not provide as many orders as for SINGLE 95 @ISIS.WIDTHS F32 2.5 4.0 7.0 # Gaussian kernel FWHM values 100 # @ISIS.WIDTHS F32 2.4 5.0 10.0 # Gaussian kernel FWHM values 101 @ISIS.WIDTHS F32 1.5 3.0 6.0 # Gaussian kernel FWHM values 102 # @ISIS.WIDTHS F32 2.0 3.0 5.0 # Gaussian kernel FWHM values 103 # @ISIS.WIDTHS F32 2.1 4.2 8.4 # Gaussian kernel FWHM values 96 104 @ISIS.ORDERS S32 2 2 2 # Polynomial orders for ISIS kernels 97 105 98 SCALE.REF F32 12.0 # FWHM reference for kernel parameter scaling99 KERNEL.SIZE S32 24# Kernel half-size (pixels)100 STAMP.FOOTPRINT S32 24# Size of stamps (pixels)106 SCALE.REF F32 5.0 # FWHM reference for kernel parameter scaling 107 KERNEL.SIZE S32 15 # Kernel half-size (pixels) 108 STAMP.FOOTPRINT S32 15 # Size of stamps (pixels) 101 109 END 102 110 -
branches/czw_branch/20101203/ippconfig/recipes/psphot.config
r30118 r30631 199 199 # @RADIAL.ANNULAR.BINS.UPPER F32 5.0 10.0 20.0 40.0 80.0 160.0 200 200 201 # SDSS values: 202 @RADIAL.ANNULAR.BINS.LOWER F32 0.00 0.56 1.69 2.59 4.41 7.51 11.58 18.58 28.55 45.50 70.51 110.53 172.49 269.52 420.51 203 @RADIAL.ANNULAR.BINS.UPPER F32 0.56 1.69 2.59 4.41 7.51 11.58 18.58 28.55 45.50 70.51 110.53 172.49 269.52 420.51 652.50 201 # SDSS values (in SDSS pixels) 202 #@RADIAL.ANNULAR.BINS.LOWER F32 0.00 0.56 1.69 2.59 4.41 7.51 11.58 18.58 28.55 45.50 70.51 110.53 172.49 269.52 420.51 203 #@RADIAL.ANNULAR.BINS.UPPER F32 0.56 1.69 2.59 4.41 7.51 11.58 18.58 28.55 45.50 70.51 110.53 172.49 269.52 420.51 652.50 204 205 # PS1 values? (all SDSS @ PS1 0.2 arcsec pixel scales) 206 # @RADIAL.ANNULAR.BINS.LOWER F32 0.0 1.2 3.4 5.2 8.8 15.0 23.2 37.2 57.1 91.0 141.0 221.1 345.0 539.1 841.0 207 # @RADIAL.ANNULAR.BINS.UPPER F32 1.2 3.4 5.2 8.8 15.0 23.2 37.2 57.1 91.0 141.0 221.1 345.0 539.1 841.0 1305.0 208 209 # PS1 values? 210 @RADIAL.ANNULAR.BINS.LOWER F32 0.0 1.2 3.4 5.2 8.8 15.0 23.2 37.2 57.1 91.0 141.0 211 @RADIAL.ANNULAR.BINS.UPPER F32 1.2 3.4 5.2 8.8 15.0 23.2 37.2 57.1 91.0 141.0 221.1 204 212 205 213 # Extended source fit parameters … … 311 319 PSPHOT.STACK.MATCH.PSF BOOL T # convolved input images to common target PSF 312 320 PSPHOT.STACK.MATCH.PSF.SOURCE STR AUTO # which inputs to convolve? (RAW, CNV, AUTO) 313 PSPHOT.STACK.TARGET.PSF.AUTO BOOL T # automatically determine target PSF size? 314 PSPHOT.STACK.TARGET.PSF.FWHM F32 5.0 # FWHM of target PSF (if NOT AUTO sized; pixels) 321 PSPHOT.STACK.TARGET.PSF.AUTO BOOL F # automatically determine target PSF size? 322 @PSPHOT.STACK.TARGET.PSF.FWHM F32 6.5 9.0 # FWHM of target PSF (if NOT AUTO sized; pixels) 323 PSPHOT.STACK.USE.RAW BOOL T 315 324 316 325 RADIAL_APERTURES BOOL F # calculate flux in circular radial apertures? … … 338 347 EXTENDED_SOURCE_ANNULI BOOL TRUE 339 348 PSPHOT.STACK.MATCH.PSF.SOURCE STR AUTO # which inputs to convolve? (RAW, CNV, AUTO) 340 PSPHOT.STACK.TARGET.PSF.AUTO BOOL T# automatically determine target PSF size?341 PSPHOT.STACK.TARGET.PSF.FWHM F32 7.5# FWHM of target PSF (if NOT AUTO sized; pixels)349 PSPHOT.STACK.TARGET.PSF.AUTO BOOL F # automatically determine target PSF size? 350 @PSPHOT.STACK.TARGET.PSF.FWHM F32 5.0 6.5 8.0 # FWHM of target PSF (if NOT AUTO sized; pixels) 342 351 RADIAL_APERTURES BOOL T # calculate flux in circular radial apertures? 343 352 RADIAL_APERTURES_SN_LIM F32 0.0 # S/N limit for radial aperture calculation -
branches/czw_branch/20101203/ippconfig/simtest/camera.config
r30118 r30631 64 64 CMF.XSRC STR {CHIP.NAME}.xsrc # use .PSF and .EXT? 65 65 CMF.XFIT STR {CHIP.NAME}.xfit # use .PSF and .EXT? 66 CMF.XRAD STR {CHIP.NAME}.xrad # use .PSF and .EXT? 66 67 CMF.DETEFF STR {CHIP.NAME}.deteff 67 68 -
branches/czw_branch/20101203/ippconfig/simtest/ppSub.config
r26902 r30631 1 1 ### Recipe file for ppSub 2 2 3 STAMP.SPACING F32 100 # Typical spacing between stamps (pixels) 4 5 RENORM BOOL FALSE # Renormalize weight maps? 6 7 DUAL BOOL FALSE # Dual convolution? 3 STAMP.SPACING F32 25 # Typical spacing between stamps (pixels) 8 4 9 5 TEST.RADIAL METADATA … … 50 46 END 51 47 52 SPATIAL.ORDER S32 0 # Spatial polynomial order53 54 #STAMP.FOOTPRINT S32 25 # Size of stamps (pixels)55 #KERNEL.SIZE S32 25 # Kernel half-size (pixels) -
branches/czw_branch/20101203/ppSim/src/Makefile.am
r28125 r30631 47 47 ppSimUtils.c \ 48 48 ppSimLoop.c \ 49 ppSimLoadSpots.c \50 ppSimPhotom.c \51 ppSimPhotomFiles.c \52 ppSimLoadForceSources.c \53 49 ppSimMergeReadouts.c \ 54 50 ppSimDetections.c \ … … 59 55 ppSimBadCTE.c \ 60 56 ppSimVersion.c 61 62 # these functions have been broken by the API change in psphot (Jan 2010)63 # ppSimPhotomReadoutFake.c64 # ppSimPhotomReadoutForce.c65 57 66 58 ppSimSequence_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS) $(ppSim_CFLAGS) -
branches/czw_branch/20101203/ppSim/src/ppSimArguments.c
r29011 r30631 49 49 psMetadataAddF32(arguments, PS_LIST_TAIL, "-zp", 0, "Photometric zero point", NAN); 50 50 psMetadataAddF32(arguments, PS_LIST_TAIL, "-seeing", 0, "Seeing FWHM (arcsec)", NAN); 51 psMetadataAddF32(arguments, PS_LIST_TAIL, "-seeing-max", 0, "Seeing FWHM (arcsec) at end of ramp", NAN); 52 psMetadataAddBool(arguments, PS_LIST_TAIL, "-seeing-ramp", 0, "Use a seeing ramp", false); 51 53 psMetadataAddF32(arguments, PS_LIST_TAIL, "-starslum", 0, "Fake star luminosity function slope", NAN); 52 54 psMetadataAddF32(arguments, PS_LIST_TAIL, "-starsmag", 0, "Brightest magnitude for fake stars", NAN); … … 130 132 // 'seeing' is not required: we can load a psf-model instead; but if not, it is allowed 131 133 ppSimArgToRecipeF32(&status, options, "SEEING", arguments, "-seeing"); // seeing (FWHM in arcsec) 134 ppSimArgToRecipeF32(&status, options, "SEEING.MAX", arguments, "-seeing-max"); // seeing (FWHM in arcsec) 135 ppSimArgToRecipeBool(&status, options, "SEEING.RAMP", arguments, "-seeing-ramp"); // seeing (FWHM in arcsec) 132 136 133 137 // 'scale' is not required: we can use the WCS instead; but if not, it is allowed … … 227 231 psMetadataAddF32(options, PS_LIST_TAIL, "PA", 0, "Boresight position angle (radians)",pa * M_PI / 180.0); 228 232 233 if (psMetadataLookupBool(NULL, arguments, "-seeing-ramp")) { 234 float seeingMax = psMetadataLookupF32(NULL, arguments, "-seeing-max"); // seeing at ramp end 235 psMetadataAddF32(options, PS_LIST_TAIL, "SEEING.MAX", 0, "Seeing FWHM (arcsec)", seeingMax); 236 psMetadataAddBool(options, PS_LIST_TAIL, "SEEING.RAMP", 0, "use seeing ramp", true); 237 } 238 229 239 ppSimArgToRecipeF32(&status, options, "ZEROPOINT", arguments, "-zp"); // Zero point 230 240 } -
branches/czw_branch/20101203/ppSim/src/ppSimCreate.c
r29125 r30631 103 103 psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale); 104 104 105 float seeingMax = psMetadataLookupF32(&status, recipe, "SEEING.MAX"); 106 psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING.MAX", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeingMax / 2.0 / sqrt(2.0 * log(2.0)) / scale); 107 105 108 // if we have been supplied an input image, but no ra & dec, use the input image values 106 109 if (input) { … … 132 135 bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes 133 136 if (doPhotom) { 134 135 // XXX at the moment, we can perform photometry on the fake sources and the forced 136 // photometry positions, but not one or the other. Also, we only support photometry in 137 // the context of an image previously analysed by psphot. Add support for: 138 // * photometry of a pure fake image (requires peak detection and psf creation) 139 // * photometry of forced source positions without fake image (this might work, it just 140 // requires not generating any fake features). 141 142 if (!input) { 143 psError(PS_ERR_UNKNOWN, false, "input image not found; currently required for photometry"); 144 return NULL; 145 } 146 147 // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?) 148 pmFPAfile *fakeImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSIM.FAKE.CHIP"); 149 if (!fakeImage) { 150 psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.FAKE.CHIP")); 151 psFree(fpa); 152 return NULL; 153 } 154 if (fakeImage->type != PM_FPA_FILE_IMAGE) { 155 psError(PS_ERR_IO, true, "PPSIM.FAKE.CHIP is not of type IMAGE"); 156 psFree(fpa); 157 return NULL; 158 } 159 160 // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?) 161 pmFPAfile *forceImage = NULL; 162 if (input) { 163 forceImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPSIM.FORCE.CHIP"); 164 if (!forceImage) { 165 psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.FORCE.CHIP")); 166 psFree(fpa); 167 return NULL; 168 } 169 if (forceImage->type != PM_FPA_FILE_IMAGE) { 170 psError(PS_ERR_IO, true, "PPSIM.FORCE.CHIP is not of type IMAGE"); 171 psFree(fpa); 172 return NULL; 173 } 174 } 175 176 // define associated psphot input/output files 177 if (!ppSimPhotomFiles (config, fakeImage, forceImage)) { 178 psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot"); 179 psFree(fpa); 180 return NULL; 181 } 182 } else { 183 // have we supplied a psf model? this happens in ppSimPhotomFiles if we request a photometry 184 // analysis. however, even if we do not, a psf model may be used to generate the fake 185 // sources. 186 if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) { 187 // tie the psf file to the chipMosaic 188 pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF"); 189 if (!status) { 190 psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD"); 191 psFree(fpa); 192 return NULL; 193 } 194 } 137 psError(PS_ERR_UNKNOWN, false, "in-line photometry in ppSim had been deprecated"); 138 return NULL; 139 } 140 141 // have we supplied a psf model? this happens in ppSimPhotomFiles if we request a photometry 142 // analysis. however, even if we do not, a psf model may be used to generate the fake 143 // sources. 144 if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) { 145 // tie the psf file to the chipMosaic 146 pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF"); 147 if (!status) { 148 psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD"); 149 psFree(fpa); 150 return NULL; 151 } 195 152 } 196 153 … … 257 214 } 258 215 } 216 // XXX this is a hack, but I don't have a better way at the moment: assumes a single cell per chip 217 if (nx) { 218 psMetadataAddS32(chip->concepts, PS_LIST_TAIL, "CHIP.XSIZE", PS_META_REPLACE, "", nx); 219 } else { 220 nx = psMetadataLookupF32(&status, cell->concepts, "CELL.XSIZE"); 221 psMetadataAddS32(chip->concepts, PS_LIST_TAIL, "CHIP.XSIZE", PS_META_REPLACE, "", nx); 222 } 223 if (ny) { 224 psMetadataAddS32(chip->concepts, PS_LIST_TAIL, "CHIP.YSIZE", PS_META_REPLACE, "", ny); 225 } else { 226 ny = psMetadataLookupF32(&status, cell->concepts, "CELL.YSIZE"); 227 psMetadataAddS32(chip->concepts, PS_LIST_TAIL, "CHIP.YSIZE", PS_META_REPLACE, "", ny); 228 } 259 229 } 260 230 } -
branches/czw_branch/20101203/ppSim/src/ppSimLoop.c
r28125 r30631 42 42 if (type == PPSIM_TYPE_OBJECT) { 43 43 // Load forced-photometry positions (these are placed on fpa->analysis for use in ppSimPhotomReadout) 44 if (!ppSimLoadSpots (fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots");44 // if (!ppSimLoadSpots (fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots"); 45 45 46 46 // Load catalogue stars … … 58 58 59 59 pmFPAview *view = pmFPAviewAlloc(0);// View for iterating over FPA 60 61 // XXX if we include the psphot analysis, we will need to activate the correct pmFPAfiles62 // at the correct times. ppSim operates on PPSIM.OUTPUT and PPSIM.SOURCES63 60 64 61 // load any needed files (eg, input image, PSF) … … 209 206 210 207 // we perform photometry on the readouts of this chip in the output 211 if (!ppSimPhotom (config, view)) ESCAPE (PS_ERR_UNKNOWN, "problem performing photometry");208 // if (!ppSimPhotom (config, view)) ESCAPE (PS_ERR_UNKNOWN, "problem performing photometry"); 212 209 213 210 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { -
branches/czw_branch/20101203/ppSim/src/ppSimMakeGalaxies.c
r29011 r30631 28 28 float galaxyThetaMax = psMetadataLookupF32(&mdok, recipe, "GALAXY.THETA.MAX"); // Density of fakes 29 29 float galaxyThetaMin = psMetadataLookupF32(&mdok, recipe, "GALAXY.THETA.MIN"); // Density of fakes 30 galaxyThetaMax *= PS_RAD_DEG; 31 galaxyThetaMin *= PS_RAD_DEG; 30 32 31 33 float galaxyIndexMin = psMetadataLookupF32(&mdok, recipe, "GALAXY.INDEX.MIN"); // Density of fakes … … 95 97 96 98 int i = 0; 99 float refNorm = 1.0; 100 float ourNorm = 1.0; 97 101 98 102 for (long iy = 0.5*galaxyGridDY; iy < ySize; iy += galaxyGridDY) { … … 104 108 galaxy->y = iy; 105 109 106 galaxy->peak = 1000; 110 // galaxy->peak = 1000; 111 galaxy->peak = bright / 100.0; 112 // fprintf (stderr, "Io: %f\n", bright); 107 113 108 114 // galaxyIndex from user should be for function of this form: exp(-r^(1/n)) … … 111 117 float rndValue; 112 118 113 rndValue = galaxyGridRandom ? drand48() : i / num;119 rndValue = galaxyGridRandom ? drand48() : i / (float) num; 114 120 float index = (galaxyIndexMin + rndValue * galaxyIndexSlope); 115 121 galaxy->index = 0.5/index; // factor of 0.5 because the Sersic model creates exp(-z^n), not exp(-r^n) 116 122 117 rndValue = galaxyGridRandom ? drand48() : i / num;123 rndValue = galaxyGridRandom ? drand48() : i / (float) num; 118 124 float scale = (galaxyRmajorMin + rndValue * galaxyRmajorSlope); 119 125 … … 125 131 galaxy->Rmaj = scale; 126 132 127 rndValue = galaxyGridRandom ? drand48() : i / num;133 rndValue = galaxyGridRandom ? drand48() : i / (float) num; 128 134 galaxy->Rmin = (galaxyARatioMin + rndValue * galaxyARatioSlope) * galaxy->Rmaj; 129 135 130 rndValue = galaxyGridRandom ? drand48() : i / num;136 rndValue = galaxyGridRandom ? drand48() : i / (float) num; 131 137 galaxy->theta = (galaxyThetaMin + rndValue * galaxyThetaSlope); 132 133 // galaxy->peak *= Io; 138 139 if (i == 0) { 140 refNorm = Io*scale*scale; 141 } 142 ourNorm = refNorm / (Io*scale*scale); 143 galaxy->peak *= ourNorm; 134 144 135 145 if (0) { 136 fprintf (stderr, "Rmaj: %f, scale: %f, index: %f, bn: %f, Ro: %f, Io: %f \n", galaxy->Rmaj, scale, index, bn, fR, Io);146 fprintf (stderr, "Rmaj: %f, scale: %f, index: %f, bn: %f, Ro: %f, Io: %f, theta: %f\n", galaxy->Rmaj, scale, index, bn, fR, Io, galaxy->theta); 137 147 } 138 148 -
branches/czw_branch/20101203/ppSim/src/ppSimSetPSF.c
r26900 r30631 23 23 float theta = psMetadataLookupF32(&status, recipe, "PSF.THETA"); // Seeing SIGMA (pixels) 24 24 25 float seeingMax = psMetadataLookupF32(&status, recipe, "SEEING.MAX"); // Seeing SIGMA (pixels) 26 bool seeingRamp = psMetadataLookupBool(&status, recipe, "SEEING.RAMP"); // Seeing SIGMA (pixels) 27 25 28 char *psfModelName = psMetadataLookupStr(&status, recipe, "PSF.MODEL"); // Name of PSF model 26 29 if (psfModelName == NULL) { … … 39 42 int xSize = psMetadataLookupS32(NULL, chip->concepts, "CHIP.XSIZE"); 40 43 int ySize = psMetadataLookupS32(NULL, chip->concepts, "CHIP.YSIZE"); 41 xSize = 1000;42 ySize = 1000;43 44 44 // no spatial variation 45 options->psfTrendMode = PM_TREND_POLY_ORD; 46 options->psfTrendNx = 0; 47 options->psfTrendNy = 0; 48 options->psfFieldNx = xSize; 49 options->psfFieldNy = ySize; 45 if (seeingRamp) { 46 psEllipseAxes axes; 47 psEllipsePol pol; 48 psEllipsePol polMax; 50 49 51 // generate the psf 52 psf = pmPSFAlloc (options); 50 // try spatial variation 51 options->psfTrendMode = PM_TREND_POLY_ORD; 52 options->psfTrendNx = 1; 53 options->psfTrendNy = 1; 54 options->psfFieldNx = xSize; 55 options->psfFieldNy = ySize; 53 56 54 psEllipseAxes axes; 55 psEllipsePol pol;57 // generate the psf 58 psf = pmPSFAlloc (options); 56 59 57 // supply the semi-major axis (these are SIGMA values in PIXELS)58 axes.major = seeing;59 axes.minor = aRatio * seeing;60 axes.theta = theta * PS_RAD_DEG;60 // supply the semi-major axis (these are SIGMA values in PIXELS) 61 axes.major = seeing; 62 axes.minor = aRatio * seeing; 63 axes.theta = theta * PS_RAD_DEG; 61 64 62 pol = psEllipseAxesToPol (axes);65 pol = psEllipseAxesToPol (axes); 63 66 64 param = psf->params->data[PM_PAR_E0]; 65 param->poly->coeff[0][0] = pol.e0; 67 axes.major = seeingMax; 68 axes.minor = aRatio * seeingMax; 69 polMax = psEllipseAxesToPol (axes); 66 70 67 param = psf->params->data[PM_PAR_E1]; 68 param->poly->coeff[0][0] = pol.e1; 71 param = psf->params->data[PM_PAR_E0]; 72 param->poly->coeff[0][0] = pol.e0; 73 param->poly->coeff[1][0] = (polMax.e0 - pol.e0) / xSize; 74 param->poly->coeff[0][1] = (polMax.e0 - pol.e0) / ySize; 69 75 70 param = psf->params->data[PM_PAR_E2]; 71 param->poly->coeff[0][0] = pol.e2; 76 param = psf->params->data[PM_PAR_E1]; 77 param->poly->coeff[0][0] = pol.e1; 78 param->poly->coeff[1][0] = 0.0; 79 param->poly->coeff[0][1] = 0.0; 72 80 73 if (!strcasecmp (psfModelName, "PS_MODEL_QGAUSS")) { 74 param = psf->params->data[PM_PAR_7];75 param->poly->coeff[0][0] = 1.0;76 } 81 param = psf->params->data[PM_PAR_E2]; 82 param->poly->coeff[0][0] = pol.e2; 83 param->poly->coeff[1][0] = 0.0; 84 param->poly->coeff[0][1] = 0.0; 77 85 78 if (!strcasecmp (psfModelName, "PS_MODEL_RGAUSS")) { 79 param = psf->params->data[PM_PAR_7]; 80 param->poly->coeff[0][0] = 1.0; 86 if (!strcasecmp (psfModelName, "PS_MODEL_QGAUSS")) { 87 param = psf->params->data[PM_PAR_7]; 88 param->poly->coeff[0][0] = 1.0; 89 param->poly->coeff[1][0] = 0.0; 90 param->poly->coeff[0][1] = 0.0; 91 } 92 93 if (!strcasecmp (psfModelName, "PS_MODEL_RGAUSS")) { 94 param = psf->params->data[PM_PAR_7]; 95 param->poly->coeff[0][0] = 1.0; 96 param->poly->coeff[1][0] = 0.0; 97 param->poly->coeff[0][1] = 0.0; 98 } 99 100 } else { 101 psEllipseAxes axes; 102 psEllipsePol pol; 103 104 // no spatial variation 105 options->psfTrendMode = PM_TREND_POLY_ORD; 106 options->psfTrendNx = 0; 107 options->psfTrendNy = 0; 108 options->psfFieldNx = xSize; 109 options->psfFieldNy = ySize; 110 111 // generate the psf 112 psf = pmPSFAlloc (options); 113 114 // supply the semi-major axis (these are SIGMA values in PIXELS) 115 axes.major = seeing; 116 axes.minor = aRatio * seeing; 117 axes.theta = theta * PS_RAD_DEG; 118 119 pol = psEllipseAxesToPol (axes); 120 121 param = psf->params->data[PM_PAR_E0]; 122 param->poly->coeff[0][0] = pol.e0; 123 124 param = psf->params->data[PM_PAR_E1]; 125 param->poly->coeff[0][0] = pol.e1; 126 127 param = psf->params->data[PM_PAR_E2]; 128 param->poly->coeff[0][0] = pol.e2; 129 130 if (!strcasecmp (psfModelName, "PS_MODEL_QGAUSS")) { 131 param = psf->params->data[PM_PAR_7]; 132 param->poly->coeff[0][0] = 1.0; 133 } 134 135 if (!strcasecmp (psfModelName, "PS_MODEL_RGAUSS")) { 136 param = psf->params->data[PM_PAR_7]; 137 param->poly->coeff[0][0] = 1.0; 138 } 81 139 } 82 140 -
branches/czw_branch/20101203/ppStack/src/Makefile.am
r28253 r30631 49 49 ppStackFinish.c \ 50 50 ppStackTarget.c \ 51 ppStackUpdateHeader.c \ 52 ppStackJPEGs.c \ 53 ppStackStats.c \ 51 54 ppStackErrorCodes.c 52 55 -
branches/czw_branch/20101203/ppStack/src/ppStack.c
r29552 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 #include <psphot.h>9 10 1 #include "ppStack.h" 11 #include "ppStackLoop.h"12 13 #define TIMER_NAME "PPSTACK" // Name of timer14 2 15 3 int main(int argc, char *argv[]) 16 4 { 17 5 psLibInit(NULL); 18 psTimerStart( TIMER_NAME);6 psTimerStart("PPSTACK"); 19 7 psTimerStart("PPSTACK_STEPS"); 20 8 … … 23 11 psphotErrorRegister(); 24 12 13 ppStackOptions *options = NULL; // Options for stacking 14 25 15 pmConfig *config = pmConfigRead(&argc, argv, PPSTACK_RECIPE); // Configuration 26 ppStackOptions *options = NULL; // Options for stacking27 16 if (!config) { 28 goto die;17 ppStackCleanup(config, options); 29 18 } 30 19 … … 33 22 if (!pmModelClassInit()) { 34 23 psError(PPSTACK_ERR_PROG, false, "Unable to initialise model classes."); 35 goto die;24 ppStackCleanup(config, options); 36 25 } 37 26 38 27 if (!psphotInit()) { 39 28 psError(PPSTACK_ERR_PROG, false, "Error initialising psphot."); 40 goto die;29 ppStackCleanup(config, options); 41 30 } 42 31 43 (void)psTraceSetLevel("ppStack", 5);44 45 32 if (!ppStackArgumentsSetup(argc, argv, config)) { 46 goto die;33 ppStackCleanup(config, options); 47 34 } 48 35 49 36 if (!ppStackCamera(config)) { 50 goto die;37 ppStackCleanup(config, options); 51 38 } 52 39 53 40 if (!ppStackArgumentsParse(config)) { 54 goto die;41 ppStackCleanup(config, options); 55 42 } 56 43 57 44 options = ppStackOptionsAlloc(); 58 45 if (!ppStackLoop(config, options)) { 59 goto die;46 ppStackCleanup(config, options); 60 47 } 61 48 62 63 die: 64 // Common code for the death. 65 { 66 psExit exitValue = ppStackExitCode(PS_EXIT_SUCCESS); // Exit code 67 68 // Ensure everything closes 69 if (config) { 70 ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true); 71 ppStackFileActivation(config, PPSTACK_FILES_CONVOLVE, true); 72 ppStackFileActivation(config, PPSTACK_FILES_STACK, true); 73 ppStackFileActivation(config, PPSTACK_FILES_UNCONV, true); 74 ppStackFileActivation(config, PPSTACK_FILES_PHOT, true); 75 if (!ppStackFilesIterateUp(config)) { 76 psError(psErrorCodeLast(), false, "Unable to close files."); 77 exitValue = ppStackExitCode(exitValue); 78 pmFPAfileFreeSetStrict(false); 79 } 80 } 81 82 // Write out summary statistics 83 if (options && options->stats) { 84 85 psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, 86 "Bad data quality flag", options->quality); 87 psMetadataAddF32(options->stats, PS_LIST_TAIL, "TIME_STACK", 0, 88 "Total time", psTimerClear("PPSTACK_TOTAL")); 89 90 const char *statsMDC = psMetadataConfigFormat(options->stats); 91 if (!statsMDC || strlen(statsMDC) == 0) { 92 psError(PS_ERR_IO, false, "Unable to get statistics MDC file."); 93 return false; 94 } 95 if (fprintf(options->statsFile, "%s", statsMDC) != strlen(statsMDC)) { 96 psError(PS_ERR_IO, false, "Unable to write statistics MDC file."); 97 return false; 98 } 99 psFree(statsMDC); 100 if (fclose(options->statsFile) == EOF) { 101 psError(PS_ERR_IO, false, "Unable to close statistics MDC file."); 102 return false; 103 } 104 options->statsFile = NULL; 105 pmConfigRunFilenameAddWrite(config, "STATS", 106 psMetadataLookupStr(NULL, config->arguments, "STATS")); 107 } 108 psFree(options); 109 110 // Dump configuration 111 bool mdok; // Status of MD lookup 112 psString dump = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); // File for config 113 if (dump && !pmConfigDump(config, dump)) { 114 psError(psErrorCodeLast(), false, "Unable to dump configuration."); 115 exitValue = ppStackExitCode(exitValue); 116 } 117 118 psTrace("ppStack", 1, "Finished at %f sec\n", psTimerMark(TIMER_NAME)); 119 psTimerStop(); 120 121 psFree(config); 122 pmModelClassCleanup(); 123 pmConfigDone(); 124 psLibFinalize(); 125 pmVisualClose(); 126 pmVisualCleanup (); 127 128 exitValue = ppStackExitCode(exitValue); 129 exit(exitValue); 130 } 49 ppStackCleanup(config, options); 131 50 } 132 51 -
branches/czw_branch/20101203/ppStack/src/ppStack.h
r28253 r30631 1 #ifdef HAVE_CONFIG_H 2 #include <config.h> 3 #endif 4 5 #include <stdio.h> 6 #include <pslib.h> 7 #include <psmodules.h> 8 #include <ppStats.h> 9 #include <psphot.h> 10 1 11 #ifndef PPSTACK_H 2 12 #define PPSTACK_H … … 7 17 #include <pslib.h> 8 18 #include <psmodules.h> 9 10 #include "ppStackOptions.h"11 #include "ppStackErrorCodes.h"12 19 13 20 // Mask values for inputs … … 25 32 // List of files 26 33 typedef enum { 34 PPSTACK_FILES_NONE, // NOP list 27 35 PPSTACK_FILES_PREPARE, // Files for preparation 28 36 PPSTACK_FILES_TARGET, // Files for target generation … … 33 41 } ppStackFileList; 34 42 43 #include "ppStackOptions.h" 44 #include "ppStackThread.h" 45 #include "ppStackLoop.h" 46 #include "ppStackErrorCodes.h" 35 47 36 48 // Setup command-line arguments … … 180 192 ); 181 193 194 bool ppStackWriteVariance(const char *name, // Name of image 195 psMetadata *header, // Header 196 const psImage *variance, // Variance 197 const psImage *covariance, // Variance 198 pmConfig *config // Configuration 199 ); 200 182 201 /// Return an appropriate exit code based on the error code 183 202 psExit ppStackExitCode(psExit exitValue); 184 203 204 bool ppStackCleanup(pmConfig *config, ppStackOptions *options) PS_ATTR_NORETURN; 205 185 206 #endif -
branches/czw_branch/20101203/ppStack/src/ppStackArguments.c
r28617 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <string.h>7 #include <pslib.h>8 #include <psmodules.h>9 10 1 #include "ppStack.h" 11 2 … … 189 180 psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp-mask", 0, "Suffix for temporary masks", NULL); 190 181 psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp-variance", 0, "Suffix for temporary variance maps", NULL); 191 psMetadataAddBool(arguments, PS_LIST_TAIL, "-temp-delete", 0, 192 "Delete temporary files on completion?", false); 182 psMetadataAddBool(arguments, PS_LIST_TAIL, "-temp-delete", 0, "Delete temporary files on completion?", false); 193 183 psMetadataAddS32(arguments, PS_LIST_TAIL, "-threads", 0, "Number of threads to use", 0); 194 184 psMetadataAddBool(arguments, PS_LIST_TAIL, "-visual", 0, "visualisation", false); 195 185 186 psMetadataAddStr(arguments, PS_LIST_TAIL, "-stack_id", 0, "stack ID", NULL); 187 psMetadataAddStr(arguments, PS_LIST_TAIL, "-skycell_id", 0, "skycell ID", NULL); 188 psMetadataAddStr(arguments, PS_LIST_TAIL, "-tess_id", 0, "tessellation ID", NULL); 189 196 190 if (argc == 1) { 197 191 usage(argv[0], arguments, config); 192 } 193 194 // stack-type : used to define the stack for PSPS 195 if ((argNum = psArgumentGet (argc, argv, "-stack-type"))) { 196 if (argc <= argNum+1) { 197 psErrorStackPrint(stderr, "Expected to see an argument for -stack-type"); 198 exit(PS_EXIT_CONFIG_ERROR); 199 } 200 psArgumentRemove (argNum, &argc, argv); 201 if (strcasecmp(argv[argNum], "NIGHTLY") && strcasecmp(argv[argNum], "DEEP") && strcasecmp(argv[argNum], "BEST_IQ")) { 202 psErrorStackPrint(stderr, "Invalid option for -stack-type %s (must be one of NIGHTLY_STACK, DEEP_STACK, IQ_STACK)", argv[argNum]); 203 exit(PS_EXIT_CONFIG_ERROR); 204 } 205 psMetadataAddStr (arguments, PS_LIST_TAIL, "STACK_TYPE", PS_META_REPLACE, "Stack Type", argv[argNum]); 206 psArgumentRemove (argNum, &argc, argv); 207 } else { 208 psMetadataAddStr (arguments, PS_LIST_TAIL, "STACK_TYPE", PS_META_REPLACE, "Stack Type", "DEEP_STACK"); 198 209 } 199 210 -
branches/czw_branch/20101203/ppStack/src/ppStackCamera.c
r27989 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <string.h>7 #include <pslib.h>8 #include <psmodules.h>9 #include <psphot.h>10 11 1 #include "ppStack.h" 12 2 -
branches/czw_branch/20101203/ppStack/src/ppStackCleanup.c
r27427 r30631 1 #ifdef HAVE_CONFIG_H 2 #include <config.h> 3 #endif 1 #include "ppStack.h" 4 2 5 #include <stdio.h> 6 #include <pslib.h> 7 #include <psmodules.h> 8 #include <ppStats.h> 9 10 #include "ppStack.h" 11 #include "ppStackLoop.h" 12 13 14 bool ppStackCleanup(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config) 3 // ppStackCleanupFiles 4 bool ppStackCleanupFiles(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config, ppStackFileList stackFiles, ppStackFileList photFiles, bool closeJPEGs) 15 5 { 16 6 psAssert(stack, "Require stack"); … … 18 8 psAssert(config, "Require configuration"); 19 9 20 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe21 psAssert(recipe, "We've thrown an error on this before.");22 23 #if 024 // Ensure masked regions really look masked25 {26 psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad27 psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels28 if (!pmReadoutMaskApply(options->outRO, maskBad)) {29 psWarning("Unable to apply mask");30 }31 }32 #endif33 34 // Generate binned JPEGs35 {36 int bin1 = psMetadataLookupS32(NULL, recipe, "BIN1"); // First binning level37 int bin2 = psMetadataLookupS32(NULL, recipe, "BIN2"); // Second binning level38 39 // Target cells40 pmFPAview *view = pmFPAviewAlloc(0); // View to cells of interest41 view->chip = view->cell = 0;42 pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG1");43 pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG2");44 psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask45 psFree(view);46 47 pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts48 if (!pmReadoutRebin(ro1, options->outRO, maskValue, bin1, bin1) ||49 !pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) {50 psError(PPSTACK_ERR_DATA, false, "Unable to bin output.");51 psFree(ro1);52 psFree(ro2);53 return false;54 }55 psFree(ro1);56 psFree(ro2);57 }58 59 // Statistics on output60 if (options->stats) {61 psTrace("ppStack", 1, "Gathering statistics on stacked image....\n");62 psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad63 psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels64 65 pmFPAview *view = pmFPAviewAlloc(0); // View to readout66 view->chip = view->cell = view->readout = 0;67 68 ppStatsFPA(options->stats, options->outRO->parent->parent->parent, view, maskBad, config);69 70 psFree(view);71 }72 73 10 if (!ppStackFilesIterateUp(config)) { 74 11 psError(psErrorCodeLast(), false, "Unable to close files."); 75 12 return false; 76 13 } 77 ppStackFileActivation(config, PPSTACK_FILES_STACK, false);78 ppStackFileActivation(config, PPSTACK_FILES_PHOT, false);14 ppStackFileActivation(config, stackFiles, false); 15 ppStackFileActivation(config, photFiles, false); 79 16 80 17 // Ensure files are freed 81 { 82 options->outRO->data_exists = false; 83 options->outRO->parent->data_exists = false; 84 options->outRO->parent->parent->data_exists = false; 85 psFree(options->outRO); 86 options->outRO = NULL; 18 options->outRO->data_exists = false; 19 options->outRO->parent->data_exists = false; 20 options->outRO->parent->parent->data_exists = false; 21 psFree(options->outRO); 22 options->outRO = NULL; 87 23 88 options->expRO->data_exists = false;89 options->expRO->parent->data_exists = false;90 options->expRO->parent->parent->data_exists = false;91 psFree(options->expRO);92 options->expRO = NULL;24 options->expRO->data_exists = false; 25 options->expRO->parent->data_exists = false; 26 options->expRO->parent->parent->data_exists = false; 27 psFree(options->expRO); 28 options->expRO = NULL; 93 29 30 for (int i = 0; i < options->num; i++) { 31 pmCellFreeData(options->cells->data[i]); 32 } 33 34 if (closeJPEGs) { 35 // XXX move these close / free operations to the jpeg creation function 94 36 pmFPAview *view = pmFPAviewAlloc(0);// Pointer into FPA hierarchy 95 37 view->chip = view->cell = 0; // pmFPAviewFreeData doesn't want to deal with readouts … … 118 60 return true; 119 61 } 62 63 bool ppStackCleanup (pmConfig *config, ppStackOptions *options) { 64 65 psExit exitValue = ppStackExitCode(PS_EXIT_SUCCESS); // Exit code 66 67 // Ensure everything closes 68 if (config) { 69 ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true); 70 ppStackFileActivation(config, PPSTACK_FILES_CONVOLVE, true); 71 ppStackFileActivation(config, PPSTACK_FILES_STACK, true); 72 ppStackFileActivation(config, PPSTACK_FILES_UNCONV, true); 73 ppStackFileActivation(config, PPSTACK_FILES_PHOT, true); 74 if (!ppStackFilesIterateUp(config)) { 75 psError(psErrorCodeLast(), false, "Unable to close files."); 76 exitValue = ppStackExitCode(exitValue); 77 pmFPAfileFreeSetStrict(false); 78 } 79 } 80 81 // Write out summary statistics 82 if (options && options->stats) { 83 84 psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, "Bad data quality flag", options->quality); 85 psMetadataAddF32(options->stats, PS_LIST_TAIL, "TIME_STACK", 0, "Total time", psTimerClear("PPSTACK_TOTAL")); 86 87 const char *statsMDC = psMetadataConfigFormat(options->stats); 88 if (!statsMDC || strlen(statsMDC) == 0) { 89 psError(PS_ERR_IO, false, "Unable to get statistics MDC file."); 90 exitValue = ppStackExitCode(exitValue); 91 exit(exitValue); 92 } 93 if (fprintf(options->statsFile, "%s", statsMDC) != strlen(statsMDC)) { 94 psError(PS_ERR_IO, false, "Unable to write statistics MDC file."); 95 exitValue = ppStackExitCode(exitValue); 96 exit(exitValue); 97 } 98 psFree(statsMDC); 99 if (fclose(options->statsFile) == EOF) { 100 psError(PS_ERR_IO, false, "Unable to close statistics MDC file."); 101 exitValue = ppStackExitCode(exitValue); 102 exit(exitValue); 103 } 104 options->statsFile = NULL; 105 pmConfigRunFilenameAddWrite(config, "STATS", psMetadataLookupStr(NULL, config->arguments, "STATS")); 106 } 107 psFree(options); 108 109 // Dump configuration 110 bool mdok; // Status of MD lookup 111 psString dump = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); // File for config 112 if (dump && !pmConfigDump(config, dump)) { 113 psError(psErrorCodeLast(), false, "Unable to dump configuration."); 114 exitValue = ppStackExitCode(exitValue); 115 } 116 117 psTrace("ppStack", 1, "Finished at %f sec\n", psTimerMark("PPSTACK")); 118 psTimerStop(); 119 120 psFree(config); 121 pmModelClassCleanup(); 122 pmConfigDone(); 123 psLibFinalize(); 124 pmVisualClose(); 125 pmVisualCleanup (); 126 127 exitValue = ppStackExitCode(exitValue); 128 exit(exitValue); 129 } -
branches/czw_branch/20101203/ppStack/src/ppStackCombineFinal.c
r29552 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 9 1 #include "ppStack.h" 10 #include "ppStackLoop.h"11 12 #define WCS_TOLERANCE 0.001 // Tolerance for WCS13 2 14 3 //#define TESTING // Enable test output … … 107 96 } 108 97 109 // Propagate WCS110 bool wcsDone = false; // Have we done the WCS?111 for (int i = 0; i < options->num && !wcsDone; i++) {112 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {113 continue;114 }115 116 ppStackThread *thread = stack->threads->data[0]; // Representative stack117 pmReadout *inRO = thread->readouts->data[i]; // Template readout118 if (inRO && !wcsDone) {119 // Copy astrometry over120 wcsDone = true;121 pmHDU *inHDU = pmHDUFromCell(inRO->parent); // Template HDU122 pmHDU *outHDU = pmHDUFromCell(outRO->parent); // Output HDU123 pmChip *outChip = outRO->parent->parent; // Output chip124 pmFPA *outFPA = outChip->parent; // Output FPA125 if (!outHDU || !inHDU) {126 psWarning("Unable to find HDU at FPA level to copy astrometry.");127 } else {128 if (!pmAstromReadWCS(outFPA, outChip, inHDU->header, 1.0)) {129 psErrorClear();130 psWarning("Unable to read WCS astrometry from input FPA.");131 wcsDone = false;132 } else {133 if (!outHDU->header) {134 outHDU->header = psMetadataAlloc();135 }136 if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_TOLERANCE)) {137 psErrorClear();138 psWarning("Unable to write WCS astrometry to output FPA.");139 wcsDone = false;140 }141 }142 }143 }144 }145 146 // Put version information into the header147 pmHDU *hdu = pmHDUFromCell(outRO->parent);148 if (!hdu) {149 psError(PPSTACK_ERR_PROG, false, "Unable to find HDU for output.");150 return false;151 }152 if (!hdu->header) {153 hdu->header = psMetadataAlloc();154 }155 ppStackVersionHeader(hdu->header);156 157 158 98 #ifdef TESTING 159 99 static int pass = 0; // Pass through -
branches/czw_branch/20101203/ppStack/src/ppStackCombineInitial.c
r28405 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 9 1 #include "ppStack.h" 10 #include "ppStackLoop.h"11 2 12 3 //#define TESTING // Enable test output -
branches/czw_branch/20101203/ppStack/src/ppStackCombinePrepare.c
r27427 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 9 1 #include "ppStack.h" 10 #include "ppStackLoop.h"11 2 12 3 bool ppStackCombinePrepare(const char *outName, const char *expName, -
branches/czw_branch/20101203/ppStack/src/ppStackConvolve.c
r30586 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 9 1 #include "ppStack.h" 10 #include "ppStackLoop.h"11 2 12 3 //#define TESTING 13 14 4 15 5 // Update the value of a concept … … 20 10 item->data.F32 = VALUE; \ 21 11 } 22 23 24 12 25 13 bool ppStackConvolve(ppStackOptions *options, pmConfig *config) … … 69 57 ppStackFileActivationSingle(config, PPSTACK_FILES_CONVOLVE, true, i); 70 58 if (options->convolve) { 71 // XXX PPSTACK.CONV.KERNEL not defined unless convolve 72 // pmFPAfileActivate(config->files, true, "PPSTACK.CONV.KERNEL"); 59 // PPSTACK.CONV.KERNEL not defined unless convolve 73 60 pmFPAfileActivateSingle(config->files, true, "PPSTACK.CONV.KERNEL", i); // Activated file 74 61 } … … 191 178 } 192 179 psFree(maskHeader); 193 if (!ppStackWrite Image(options->convVariances->data[i], hdu->header, readout->variance, config)) {180 if (!ppStackWriteVariance(options->convVariances->data[i], hdu->header, readout->variance, readout->covariance->image, config)) { 194 181 psError(PPSTACK_ERR_IO, false, "Unable to write convolved variance %d", i); 195 182 psFree(fpaList); -
branches/czw_branch/20101203/ppStack/src/ppStackErrorCodes.c.in
r27004 r30631 1 #include "ppStack.h" 2 1 3 /** @file ppStackErrorCodes.c.in 2 4 * … … 10 12 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 13 */ 12 13 #include "pslib.h"14 #include "ppStackErrorCodes.h"15 14 16 15 /* -
branches/czw_branch/20101203/ppStack/src/ppStackFiles.c
r28253 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <unistd.h>7 #include <pslib.h>8 #include <psmodules.h>9 10 1 #include "ppStack.h" 11 2 12 13 3 // Here follows lists of files for activation/deactivation at various stages. Each must be NULL-terminated. 4 5 /// NOP list 6 static char *filesNOP[] = { NULL }; 14 7 15 8 /// Files required in preparation for convolution … … 41 34 { 42 35 switch (list) { 36 case PPSTACK_FILES_NONE: return filesNOP; 43 37 case PPSTACK_FILES_PREPARE: return filesPrepare; 44 38 case PPSTACK_FILES_TARGET: return filesTarget; … … 206 200 return true; 207 201 } 202 203 // Write an image to a FITS file 204 bool ppStackWriteVariance(const char *name, // Name of image 205 psMetadata *header, // Header 206 const psImage *variance, // Variance 207 const psImage *covariance, // Variance 208 pmConfig *config // Configuration 209 ) 210 { 211 assert(name); 212 assert(variance); 213 214 psString resolved = pmConfigConvertFilename(name, config, true, true); // Resolved file name 215 psFits *fits = psFitsOpen(resolved, "w"); 216 if (!fits) { 217 psError(PPSTACK_ERR_IO, false, "Unable to open FITS file %s to write image.", resolved); 218 psFree(resolved); 219 return false; 220 } 221 if (!psFitsWriteImage(fits, header, variance, 0, NULL)) { 222 psError(PPSTACK_ERR_IO, false, "Unable to write FITS image %s.", resolved); 223 psFitsClose(fits); 224 psFree(resolved); 225 return false; 226 } 227 if (covariance) { 228 psMetadata *tmphead = psMetadataAlloc(); 229 psMetadataAddS32(tmphead, PS_LIST_TAIL, "COVARIANCE.CENTRE.X", PS_META_REPLACE, "center", (int)(covariance->numCols / 2)); 230 psMetadataAddS32(tmphead, PS_LIST_TAIL, "COVARIANCE.CENTRE.Y", PS_META_REPLACE, "center", (int)(covariance->numRows / 2)); 231 if (!psFitsWriteImage(fits, tmphead, covariance, 0, "COVAR_SkyChip_SkyCell")) { 232 psError(PPSTACK_ERR_IO, false, "Unable to write FITS image %s.", resolved); 233 psFitsClose(fits); 234 psFree(resolved); 235 return false; 236 } 237 } 238 if (!psFitsClose(fits)) { 239 psError(PPSTACK_ERR_IO, false, "Unable to close FITS image %s.", resolved); 240 psFree(resolved); 241 return false; 242 } 243 psFree(resolved); 244 return true; 245 } -
branches/czw_branch/20101203/ppStack/src/ppStackFinish.c
r27906 r30631 1 #ifdef HAVE_CONFIG_H 2 #include <config.h> 3 #endif 1 #include "ppStack.h" 4 2 5 #include <stdio.h> 6 #include <unistd.h> 7 #include <pslib.h> 8 #include <psmodules.h> 9 #include <psphot.h> 10 11 #include "ppStack.h" 12 #include "ppStackLoop.h" 13 3 // this function unlinks the temporary files (if desired) 14 4 bool ppStackFinish(ppStackOptions *options, pmConfig *config) 15 5 { … … 32 22 } 33 23 34 psString imageResolved = pmConfigConvertFilename(options->convImages->data[i], 35 config, false, false); 36 psString maskResolved = pmConfigConvertFilename(options->convMasks->data[i], 37 config, false, false); 38 psString varianceResolved = pmConfigConvertFilename(options->convVariances->data[i], 39 config, false, false); 24 // XXX careful about repeatative resolution of nebulous names (though these are probably not neb names) 25 psString imageResolved = pmConfigConvertFilename(options->convImages->data[i], config, false, false); 26 psString maskResolved = pmConfigConvertFilename(options->convMasks->data[i], config, false, false); 27 psString varianceResolved = pmConfigConvertFilename(options->convVariances->data[i], config, false, false); 40 28 if (unlink(imageResolved) == -1 || unlink(maskResolved) == -1 || 41 29 unlink(varianceResolved) == -1) { … … 47 35 } 48 36 } 49 50 51 37 return true; 52 38 } … … 60 46 61 47 psErrorCode errorCode = psErrorCodeLast(); // Error code 62 if (errorCode != PS_ERR_NONE) { 63 psErrorStackPrint(stderr, "Unable to perform stack."); 64 pmFPAfileFreeSetStrict(false); 65 switch (errorCode) { 66 case PPSTACK_ERR_UNKNOWN: 67 case PS_ERR_UNKNOWN: 68 psLogMsg("ppStack", PS_LOG_WARN, "Unknown error code: %x", errorCode); 69 exitValue = PS_EXIT_UNKNOWN_ERROR; 70 break; 71 case PS_ERR_IO: 72 case PS_ERR_DB_CLIENT: 73 case PS_ERR_DB_SERVER: 74 case PS_ERR_BAD_FITS: 75 case PS_ERR_OS_CALL_FAILED: 76 case PM_ERR_SYS: 77 case PPSTACK_ERR_IO: 78 psLogMsg("ppStack", PS_LOG_WARN, "I/O error code: %x", errorCode); 79 exitValue = PS_EXIT_SYS_ERROR; 80 break; 81 case PS_ERR_BAD_PARAMETER_VALUE: 82 case PS_ERR_BAD_PARAMETER_TYPE: 83 case PS_ERR_BAD_PARAMETER_NULL: 84 case PS_ERR_BAD_PARAMETER_SIZE: 85 case PPSTACK_ERR_ARGUMENTS: 86 case PPSTACK_ERR_CONFIG: 87 psLogMsg("ppStack", PS_LOG_WARN, "Configuration error code: %x", errorCode); 88 exitValue = PS_EXIT_CONFIG_ERROR; 89 break; 90 case PPSTACK_ERR_PSF: 91 case PSPHOT_ERR_PSF: 92 case PM_ERR_STAMPS: 93 case PM_ERR_SMALL_AREA: 94 case PPSTACK_ERR_REJECTED: 95 case PPSTACK_ERR_DATA: 96 psLogMsg("ppStack", PS_LOG_WARN, "Data error code: %x", errorCode); 97 exitValue = PS_EXIT_DATA_ERROR; 98 break; 99 case PS_ERR_UNEXPECTED_NULL: 100 case PS_ERR_PROGRAMMING: 101 case PPSTACK_ERR_NOT_IMPLEMENTED: 102 case PPSTACK_ERR_PROG: 103 psLogMsg("ppStack", PS_LOG_WARN, "Programming error code: %x", errorCode); 104 exitValue = PS_EXIT_PROG_ERROR; 105 break; 106 default: 107 // It's a programming error if we're not dealing with the error correctly 108 psLogMsg("ppStack", PS_LOG_WARN, "Unrecognised error code: %x", errorCode); 109 exitValue = PS_EXIT_PROG_ERROR; 110 break; 111 } 48 if (errorCode == PS_ERR_NONE) { 49 return exitValue; 50 } 51 52 psErrorStackPrint(stderr, "Unable to perform stack."); 53 pmFPAfileFreeSetStrict(false); 54 switch (errorCode) { 55 case PPSTACK_ERR_UNKNOWN: 56 case PS_ERR_UNKNOWN: 57 psLogMsg("ppStack", PS_LOG_WARN, "Unknown error code: %x", errorCode); 58 exitValue = PS_EXIT_UNKNOWN_ERROR; 59 break; 60 case PS_ERR_IO: 61 case PS_ERR_DB_CLIENT: 62 case PS_ERR_DB_SERVER: 63 case PS_ERR_BAD_FITS: 64 case PS_ERR_OS_CALL_FAILED: 65 case PM_ERR_SYS: 66 case PPSTACK_ERR_IO: 67 psLogMsg("ppStack", PS_LOG_WARN, "I/O error code: %x", errorCode); 68 exitValue = PS_EXIT_SYS_ERROR; 69 break; 70 case PS_ERR_BAD_PARAMETER_VALUE: 71 case PS_ERR_BAD_PARAMETER_TYPE: 72 case PS_ERR_BAD_PARAMETER_NULL: 73 case PS_ERR_BAD_PARAMETER_SIZE: 74 case PPSTACK_ERR_ARGUMENTS: 75 case PPSTACK_ERR_CONFIG: 76 psLogMsg("ppStack", PS_LOG_WARN, "Configuration error code: %x", errorCode); 77 exitValue = PS_EXIT_CONFIG_ERROR; 78 break; 79 case PPSTACK_ERR_PSF: 80 case PSPHOT_ERR_PSF: 81 case PM_ERR_STAMPS: 82 case PM_ERR_SMALL_AREA: 83 case PPSTACK_ERR_REJECTED: 84 case PPSTACK_ERR_DATA: 85 psLogMsg("ppStack", PS_LOG_WARN, "Data error code: %x", errorCode); 86 exitValue = PS_EXIT_DATA_ERROR; 87 break; 88 case PS_ERR_UNEXPECTED_NULL: 89 case PS_ERR_PROGRAMMING: 90 case PPSTACK_ERR_NOT_IMPLEMENTED: 91 case PPSTACK_ERR_PROG: 92 psLogMsg("ppStack", PS_LOG_WARN, "Programming error code: %x", errorCode); 93 exitValue = PS_EXIT_PROG_ERROR; 94 break; 95 default: 96 // It's a programming error if we're not dealing with the error correctly 97 psLogMsg("ppStack", PS_LOG_WARN, "Unrecognised error code: %x", errorCode); 98 exitValue = PS_EXIT_PROG_ERROR; 99 break; 112 100 } 113 101 return exitValue; -
branches/czw_branch/20101203/ppStack/src/ppStackLoop.c
r29552 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 9 1 #include "ppStack.h" 10 #include "ppStackLoop.h" 2 3 // static functions are defined below 4 static int stackSummary(const ppStackOptions *options, const char *place); 5 6 bool ppStackLoop(pmConfig *config, ppStackOptions *options) 7 { 8 assert(config); 9 10 psTimerStart("PPSTACK_TOTAL"); 11 psTimerStart("PPSTACK_STEPS"); 12 13 // Setup 14 psTrace("ppStack", 1, "Setup....\n"); 15 if (!ppStackSetup(options, config)) { 16 psError(psErrorCodeLast(), false, "Unable to setup."); 17 return false; 18 } 19 psLogMsg("ppStack", PS_LOG_INFO, "Stage 0: Setup: %f sec", psTimerClear("PPSTACK_STEPS")); 20 ppStackMemDump("setup"); 21 22 // Preparation for stacking 23 psTrace("ppStack", 1, "Preparation for stacking: merging sources, determining target PSF....\n"); 24 25 if (!ppStackPrepare(options, config)) { 26 psError(psErrorCodeLast(), false, "Unable to prepare for stacking."); 27 return false; 28 } 29 psLogMsg("ppStack", PS_LOG_INFO, "Stage 1: Load Sources and Generate Target PSF: %f sec", psTimerClear("PPSTACK_STEPS")); 30 ppStackMemDump("prepare"); 31 if (options->quality) return true; // Can't do anything else 32 33 // Convolve inputs 34 psTrace("ppStack", 1, "Convolving inputs to target PSF....\n"); 35 if (!ppStackConvolve(options, config)) { 36 psError(psErrorCodeLast(), false, "Unable to convolve images."); 37 return false; 38 } 39 psLogMsg("ppStack", PS_LOG_INFO, "Stage 2: Generate Convolutions and Save: %f sec", psTimerClear("PPSTACK_STEPS")); 40 ppStackMemDump("convolve"); 41 if (options->quality) return true; // Can't do anything else 42 43 // Ensure sufficient inputs 44 { 45 int numGood = stackSummary(options, "initial combination"); 46 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe 47 bool safe = psMetadataLookupBool(NULL, recipe, "SAFE"); // Be safe when combining 48 if (safe && numGood <= 1) { 49 options->quality = PPSTACK_ERR_REJECTED; 50 psErrorStackPrint(stderr, "Insufficient inputs for combination with safety on"); 51 psErrorClear(); 52 psWarning("Insufficient inputs for combination with safety on"); 53 return true; 54 } 55 } 56 57 // Start threading 58 ppStackThreadInit(); 59 ppStackThreadData *stack = ppStackThreadDataSetup(options, config, true); 60 if (!stack) { 61 psError(psErrorCodeLast(), false, "Unable to initialise stack threads."); 62 return false; 63 } 64 65 // Prepare for combination 66 if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", PPSTACK_FILES_STACK, stack, options, config)) { 67 psError(psErrorCodeLast(), false, "Unable to prepare for combination."); 68 psFree(stack); 69 return false; 70 } 71 72 // Initial combination 73 psTrace("ppStack", 1, "Initial stack of convolved images....\n"); 74 if (!ppStackCombineInitial(stack, options, config)) { 75 psError(psErrorCodeLast(), false, "Unable to perform initial combination."); 76 psFree(stack); 77 return false; 78 } 79 ppStackMemDump("initial"); 80 psLogMsg("ppStack", PS_LOG_INFO, "Stage 3: Make Initial Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 81 82 // Done with stack inputs for now 83 // XXX is this where we are leaking?? 84 for (int i = 0; i < options->num; i++) { 85 pmCellFreeData(options->cells->data[i]); 86 } 87 psFree(stack); 88 89 // Pixel rejection 90 psTrace("ppStack", 1, "Reject pixels....\n"); 91 if (!ppStackReject(options, config)) { 92 psError(psErrorCodeLast(), false, "Unable to reject pixels."); 93 psFree(stack); 94 return false; 95 } 96 psLogMsg("ppStack", PS_LOG_INFO, "Stage 4: Pixel Rejection: %f sec", psTimerClear("PPSTACK_STEPS")); 97 98 // Check inputs 99 { 100 int numGood = stackSummary(options, "final combination"); 101 if (numGood <= 0) { 102 options->quality = PPSTACK_ERR_REJECTED; 103 psErrorStackPrint(stderr, "Insufficient inputs survived rejection stage"); 104 psErrorClear(); 105 psWarning("Insufficient inputs survived rejection stage"); 106 return true; 107 } 108 } 109 110 stack = ppStackThreadDataSetup(options, config, true); 111 if (!stack) { 112 psError(psErrorCodeLast(), false, "Unable to initialise stack threads."); 113 return false; 114 } 115 116 // Final combination 117 psTrace("ppStack", 2, "Final stack of convolved images....\n"); 118 if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true)) { 119 psError(psErrorCodeLast(), false, "Unable to perform final combination."); 120 psFree(stack); 121 return false; 122 } 123 psLogMsg("ppStack", PS_LOG_INFO, "Stage 5: Final Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 124 ppStackMemDump("final"); 125 126 // Photometry 127 psTrace("ppStack", 1, "Photometering stacked image....\n"); 128 if (!ppStackPhotometry(options, config)) { 129 psError(psErrorCodeLast(), false, "Unable to perform photometry."); 130 return false; 131 } 132 psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS")); 133 ppStackMemDump("photometry"); 134 135 // Update Header 136 if (!ppStackUpdateHeader(stack, options, config)) { 137 psError(psErrorCodeLast(), false, "Unable to update header."); 138 psFree(stack); 139 return false; 140 } 141 // Create JPEGS 142 if (!ppStackJPEGs(stack, options, config)) { 143 psError(psErrorCodeLast(), false, "Unable to make jpegs."); 144 psFree(stack); 145 return false; 146 } 147 // Assemble Stats 148 if (!ppStackStats(stack, options, config)) { 149 psError(psErrorCodeLast(), false, "Unable to assemble statistics."); 150 psFree(stack); 151 return false; 152 } 153 154 // Clean up 155 psTrace("ppStack", 2, "Cleaning up after combination....\n"); 156 if (!ppStackCleanupFiles(stack, options, config, PPSTACK_FILES_STACK, PPSTACK_FILES_PHOT, true)) { 157 psError(psErrorCodeLast(), false, "Unable to clean up."); 158 psFree(stack); 159 return false; 160 } 161 psFree(stack); 162 psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS")); 163 ppStackMemDump("cleanup"); 164 165 // Unconvolved stack --- it's cheap to calculate, compared to everything else! 166 // XXX unconvolved stack is currently using the convolved mask! oops! 167 if (options->convolve) { 168 // Start threading 169 ppStackThreadData *stack = ppStackThreadDataSetup(options, config, false); 170 if (!stack) { 171 psError(psErrorCodeLast(), false, "Unable to initialise stack threads."); 172 return false; 173 } 174 175 // Prepare for combination 176 if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", PPSTACK_FILES_UNCONV, 177 stack, options, config)) { 178 psError(psErrorCodeLast(), false, "Unable to prepare for combination."); 179 psFree(stack); 180 return false; 181 } 182 183 // generate the unconvolved stack 184 psTrace("ppStack", 2, "Stack of unconvolved images....\n"); 185 if (!ppStackCombineFinal(stack, options->origCovars, options, config, 186 false, true, false)) { 187 psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination."); 188 psFree(stack); 189 return false; 190 } 191 psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Unconvolved Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 192 ppStackMemDump("unconv"); 193 194 // Clean up unconvolved stack 195 psTrace("ppStack", 2, "Cleaning up after unconvolved stack....\n"); 196 if (!ppStackCleanupFiles(stack, options, config, PPSTACK_FILES_UNCONV, PPSTACK_FILES_NONE, false)) { 197 psError(psErrorCodeLast(), false, "Unable to clean up."); 198 psFree(stack); 199 return false; 200 } 201 psFree(stack); 202 } 203 psFree(options->cells); options->cells = NULL; 204 205 // Finish up 206 psTrace("ppStack", 1, "Finishing up....\n"); 207 if (!ppStackFinish(options, config)) { 208 psError(psErrorCodeLast(), false, "Unable to finish up."); 209 return false; 210 } 211 ppStackMemDump("finish"); 212 213 return true; 214 } 11 215 12 216 /// Print a summary of the inputs, and return the number of good inputs 13 static int stackSummary(const ppStackOptions *options, // Stack options, with input mask 14 const char *place // Place in code 15 ) 217 static int stackSummary(const ppStackOptions *options, const char *place) 16 218 { 17 219 int numGood = 0; // Number of good inputs … … 47 249 return numGood; 48 250 } 49 50 51 52 bool ppStackLoop(pmConfig *config, ppStackOptions *options)53 {54 assert(config);55 56 psTimerStart("PPSTACK_TOTAL");57 psTimerStart("PPSTACK_STEPS");58 59 // Setup60 psTrace("ppStack", 1, "Setup....\n");61 if (!ppStackSetup(options, config)) {62 psError(psErrorCodeLast(), false, "Unable to setup.");63 return false;64 }65 psLogMsg("ppStack", PS_LOG_INFO, "Stage 0: Setup: %f sec", psTimerClear("PPSTACK_STEPS"));66 ppStackMemDump("setup");67 68 69 // Preparation for stacking70 psTrace("ppStack", 1, "Preparation for stacking: merging sources, determining target PSF....\n");71 if (!ppStackPrepare(options, config)) {72 psError(psErrorCodeLast(), false, "Unable to prepare for stacking.");73 return false;74 }75 psLogMsg("ppStack", PS_LOG_INFO, "Stage 1: Load Sources and Generate Target PSF: %f sec",76 psTimerClear("PPSTACK_STEPS"));77 ppStackMemDump("prepare");78 if (options->quality) {79 // Can't do anything else80 return true;81 }82 83 // Convolve inputs84 psTrace("ppStack", 1, "Convolving inputs to target PSF....\n");85 if (!ppStackConvolve(options, config)) {86 psError(psErrorCodeLast(), false, "Unable to convolve images.");87 return false;88 }89 psLogMsg("ppStack", PS_LOG_INFO, "Stage 2: Generate Convolutions and Save: %f sec",90 psTimerClear("PPSTACK_STEPS"));91 ppStackMemDump("convolve");92 93 if (options->quality) {94 // Can't do anything else95 return true;96 }97 98 // Ensure sufficient inputs99 {100 int numGood = stackSummary(options, "initial combination");101 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe102 bool safe = psMetadataLookupBool(NULL, recipe, "SAFE"); // Be safe when combining103 if (safe && numGood <= 1) {104 options->quality = PPSTACK_ERR_REJECTED;105 psErrorStackPrint(stderr, "Insufficient inputs for combination with safety on");106 psErrorClear();107 psWarning("Insufficient inputs for combination with safety on");108 return true;109 }110 }111 112 // Start threading113 ppStackThreadInit();114 ppStackThreadData *stack = ppStackThreadDataSetup(options, config, true);115 if (!stack) {116 psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");117 return false;118 }119 120 // Prepare for combination121 if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", PPSTACK_FILES_STACK,122 stack, options, config)) {123 psError(psErrorCodeLast(), false, "Unable to prepare for combination.");124 psFree(stack);125 return false;126 }127 128 // Initial combination129 psTrace("ppStack", 1, "Initial stack of convolved images....\n");130 if (!ppStackCombineInitial(stack, options, config)) {131 psError(psErrorCodeLast(), false, "Unable to perform initial combination.");132 psFree(stack);133 return false;134 }135 ppStackMemDump("initial");136 psLogMsg("ppStack", PS_LOG_INFO, "Stage 3: Make Initial Stack: %f sec", psTimerClear("PPSTACK_STEPS"));137 138 // Done with stack inputs for now139 for (int i = 0; i < options->num; i++) {140 pmCellFreeData(options->cells->data[i]);141 }142 psFree(stack);143 144 // Pixel rejection145 psTrace("ppStack", 1, "Reject pixels....\n");146 if (!ppStackReject(options, config)) {147 psError(psErrorCodeLast(), false, "Unable to reject pixels.");148 psFree(stack);149 return false;150 }151 psLogMsg("ppStack", PS_LOG_INFO, "Stage 4: Pixel Rejection: %f sec", psTimerClear("PPSTACK_STEPS"));152 153 // Check inputs154 {155 int numGood = stackSummary(options, "final combination");156 if (numGood <= 0) {157 options->quality = PPSTACK_ERR_REJECTED;158 psErrorStackPrint(stderr, "Insufficient inputs survived rejection stage");159 psErrorClear();160 psWarning("Insufficient inputs survived rejection stage");161 return true;162 }163 }164 165 stack = ppStackThreadDataSetup(options, config, true);166 if (!stack) {167 psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");168 return false;169 }170 171 // Final combination172 psTrace("ppStack", 2, "Final stack of convolved images....\n");173 if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true)) {174 psError(psErrorCodeLast(), false, "Unable to perform final combination.");175 psFree(stack);176 return false;177 }178 psLogMsg("ppStack", PS_LOG_INFO, "Stage 5: Final Stack: %f sec", psTimerClear("PPSTACK_STEPS"));179 ppStackMemDump("final");180 181 // Photometry182 psTrace("ppStack", 1, "Photometering stacked image....\n");183 if (!ppStackPhotometry(options, config)) {184 psError(psErrorCodeLast(), false, "Unable to perform photometry.");185 return false;186 }187 psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS"));188 ppStackMemDump("photometry");189 190 // Clean up191 psTrace("ppStack", 2, "Cleaning up after combination....\n");192 if (!ppStackCleanup(stack, options, config)) {193 psError(psErrorCodeLast(), false, "Unable to clean up.");194 psFree(stack);195 return false;196 }197 for (int i = 0; i < options->num; i++) {198 pmCellFreeData(options->cells->data[i]);199 }200 psFree(stack);201 psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));202 ppStackMemDump("cleanup");203 204 #if 1205 // Unconvolved stack --- it's cheap to calculate, compared to everything else!206 // XXX unconvolved stack is currently using the convolved mask! oops!207 if (options->convolve) {208 // Start threading209 ppStackThreadData *stack = ppStackThreadDataSetup(options, config, false);210 if (!stack) {211 psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");212 return false;213 }214 215 // Prepare for combination216 if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", PPSTACK_FILES_UNCONV,217 stack, options, config)) {218 psError(psErrorCodeLast(), false, "Unable to prepare for combination.");219 psFree(stack);220 return false;221 }222 223 psTrace("ppStack", 2, "Stack of unconvolved images....\n");224 if (!ppStackCombineFinal(stack, options->origCovars, options, config,225 false, true, false)) {226 psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination.");227 psFree(stack);228 return false;229 }230 psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Unconvolved Stack: %f sec", psTimerClear("PPSTACK_STEPS"));231 ppStackMemDump("unconv");232 233 if (!ppStackFilesIterateUp(config)) {234 psError(psErrorCodeLast(), false, "Unable to close files.");235 psFree(stack);236 return false;237 }238 ppStackFileActivation(config, PPSTACK_FILES_UNCONV, false);239 options->outRO->data_exists = false;240 options->outRO->parent->data_exists = false;241 options->outRO->parent->parent->data_exists = false;242 psFree(options->outRO);243 options->outRO = NULL;244 options->expRO->data_exists = false;245 options->expRO->parent->data_exists = false;246 options->expRO->parent->parent->data_exists = false;247 psFree(options->expRO);248 options->expRO = NULL;249 250 for (int i = 0; i < options->num; i++) {251 pmCellFreeData(options->cells->data[i]);252 }253 psFree(stack);254 }255 psFree(options->cells); options->cells = NULL;256 #endif257 258 // Finish up259 psTrace("ppStack", 1, "Finishing up....\n");260 if (!ppStackFinish(options, config)) {261 psError(psErrorCodeLast(), false, "Unable to finish up.");262 return false;263 }264 ppStackMemDump("finish");265 266 return true;267 } -
branches/czw_branch/20101203/ppStack/src/ppStackLoop.h
r27427 r30631 1 1 #ifndef PPSTACK_LOOP_H 2 2 #define PPSTACK_LOOP_H 3 4 #include <pslib.h>5 #include <psmodules.h>6 7 #include "ppStackOptions.h"8 #include "ppStackThread.h"9 #include "ppStack.h"10 11 3 12 4 // Loop over the inputs, doing the combination … … 71 63 72 64 // Cleanup following combination 73 bool ppStackCleanup (65 bool ppStackCleanupFiles( 74 66 ppStackThreadData *stack, // Stack 75 67 ppStackOptions *options, // Options 76 pmConfig *config // Configuration 77 ); 68 pmConfig *config, // Configuration 69 ppStackFileList stackFiles, // cleanup these stack files 70 ppStackFileList photFiles, // cleanup these phot files (PHOT or NOP) 71 bool closeJPEGs // close the jpeg files? 72 ); 78 73 79 74 // Photometry … … 89 84 ); 90 85 86 87 bool ppStackUpdateHeader(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config); 88 bool ppStackJPEGs(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config); 89 bool ppStackStats(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config); 90 91 91 #endif -
branches/czw_branch/20101203/ppStack/src/ppStackMatch.c
r29552 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 #include <psphot.h>9 10 1 #include "ppStack.h" 11 2 … … 325 316 // Scale the input parameters 326 317 psVector *widthsCopy = psVectorCopy(NULL, widths, PS_TYPE_F32); // Copy of kernel widths 327 if (scale && !pmSubtractionParamsScale(&size, &footprint, widthsCopy, scaleRef, scaleMin, scaleMax)) { 328 psError(psErrorCodeLast(), false, "Unable to scale kernel parameters"); 329 psFree(fake); 330 psFree(optWidths); 331 psFree(conv); 332 psFree(widthsCopy); 333 if (threads > 0) { 334 pmSubtractionThreadsFinalize(); 335 } 336 return false; 337 } 318 319 pmSubtractionParamScaleOptions(scale, scaleRef, scaleMin, scaleMax); 320 321 // XXX EAM : the kernel scaling process has changed: the scale is now set 322 // inside pmSubtractionMatch after the normalization window is measured 323 324 // if (scale && !pmSubtractionParamsScale(&size, &footprint, widthsCopy, scaleRef, scaleMin, scaleMax)) { 325 // psError(psErrorCodeLast(), false, "Unable to scale kernel parameters"); 326 // psFree(fake); 327 // psFree(optWidths); 328 // psFree(conv); 329 // psFree(widthsCopy); 330 // if (threads > 0) { 331 // pmSubtractionThreadsFinalize(); 332 // } 333 // return false; 334 // } 338 335 339 336 if (!pmSubtractionMatch(NULL, conv, fake, readout, footprint, stride, regionSize, spacing, -
branches/czw_branch/20101203/ppStack/src/ppStackOptions.c
r27427 r30631 1 #ifdef HAVE_CONFIG_H 2 #include <config.h> 3 #endif 4 5 #include <pslib.h> 6 #include "ppStackLoop.h" 1 #include "ppStack.h" 7 2 8 3 static void stackOptionsFree(ppStackOptions *options) … … 36 31 psFree(options->inspect); 37 32 psFree(options->rejected); 33 38 34 return; 39 35 } -
branches/czw_branch/20101203/ppStack/src/ppStackOptions.h
r27427 r30631 1 1 #ifndef PPSTACK_OPTIONS_H 2 2 #define PPSTACK_OPTIONS_H 3 4 #include <pslib.h>5 #include <psmodules.h>6 3 7 4 /// Options for stacking process -
branches/czw_branch/20101203/ppStack/src/ppStackPSF.c
r29552 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 9 1 #include "ppStack.h" 10 2 -
branches/czw_branch/20101203/ppStack/src/ppStackPhotometry.c
r30118 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 #include <psphot.h>9 10 1 #include "ppStack.h" 11 #include "ppStackLoop.h"12 2 13 3 bool ppStackPhotometry(ppStackOptions *options, pmConfig *config) -
branches/czw_branch/20101203/ppStack/src/ppStackPrepare.c
r27446 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 9 1 #include "ppStack.h" 10 #include "ppStackLoop.h"11 2 12 3 #define PHOT_SOURCE_MASK (PM_SOURCE_MODE_FAIL | PM_SOURCE_MODE_SATSTAR | PM_SOURCE_MODE_BLEND | \ -
branches/czw_branch/20101203/ppStack/src/ppStackReadout.c
r29552 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 #include <psphot.h>9 10 #include "ppStackThread.h"11 1 #include "ppStack.h" 12 2 -
branches/czw_branch/20101203/ppStack/src/ppStackReject.c
r28405 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 9 1 #include "ppStack.h" 10 #include "ppStackLoop.h"11 2 12 3 // #define TESTING -
branches/czw_branch/20101203/ppStack/src/ppStackSetup.c
r27158 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <libgen.h>7 #include <pslib.h>8 #include <psmodules.h>9 10 1 #include "ppStack.h" 11 #include "ppStackLoop.h"12 2 13 3 #define BUFFER 16 // Buffer for name array 14 15 4 16 5 bool ppStackSetup(ppStackOptions *options, pmConfig *config) -
branches/czw_branch/20101203/ppStack/src/ppStackSources.c
r28144 r30631 1 #include <stdio.h>2 #include <math.h>3 #include <string.h>4 #include <pslib.h>5 #include <psmodules.h>6 7 1 #include "ppStack.h" 8 2 -
branches/czw_branch/20101203/ppStack/src/ppStackTarget.c
r28302 r30631 1 #include <stdio.h>2 #include <pslib.h>3 #include <psmodules.h>4 5 1 #include "ppStack.h" 6 2 … … 37 33 return psMemIncrRefCounter(sources); 38 34 } 35 exclusion = 2; 39 36 40 37 int num = sources->n; // Number of sources -
branches/czw_branch/20101203/ppStack/src/ppStackThread.c
r27427 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <unistd.h>7 #include <pslib.h>8 #include <psmodules.h>9 10 1 #include "ppStack.h" 11 #include "ppStackOptions.h"12 #include "ppStackThread.h"13 14 2 15 3 #define THREAD_WAIT 10000 // Microseconds to wait if thread is not available 16 17 4 18 5 static void stackThreadFree(ppStackThread *thread) -
branches/czw_branch/20101203/ppStack/src/ppStackThread.h
r26076 r30631 1 1 #ifndef PPSTACK_THREAD_H 2 2 #define PPSTACK_THREAD_H 3 4 #include <pslib.h>5 #include <psmodules.h>6 7 #include "ppStackOptions.h"8 3 9 4 // Thread for stacking chunks -
branches/czw_branch/20101203/ppStack/src/ppStackVersion.c
r28043 r30631 1 #ifdef HAVE_CONFIG_H2 #include <config.h>3 #endif4 5 #include <stdio.h>6 #include <pslib.h>7 #include <psmodules.h>8 #include <ppStats.h>9 #include <psphot.h>10 11 1 #include "ppStack.h" 12 2 #include "ppStackVersionDefinitions.h" -
branches/czw_branch/20101203/ppSub/src/ppSub.c
r29551 r30631 112 112 psLibFinalize(); 113 113 114 fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "ppSub"); 114 115 exitValue = ppSubExitCode(exitValue); 115 116 exit(exitValue); -
branches/czw_branch/20101203/ppSub/src/ppSubFiles.c
r27094 r30631 125 125 // FPA 126 126 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 127 psFree (view); 127 128 return false; 128 129 } … … 131 132 view->chip = 0; 132 133 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 134 psFree (view); 133 135 return false; 134 136 } … … 137 139 view->cell = 0; 138 140 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 141 psFree (view); 139 142 return false; 140 143 } … … 143 146 view->readout = 0; 144 147 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 145 return false; 146 } 147 148 ppSubFilesActivate(config, PPSUB_FILES_ALL, false); 149 148 psFree (view); 149 return false; 150 } 151 152 ppSubFilesActivate(config, PPSUB_FILES_ALL, false); 153 154 psFree (view); 150 155 return true; 151 156 } … … 162 167 // Readout 163 168 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 169 psFree (view); 164 170 return false; 165 171 } … … 168 174 view->readout = -1; 169 175 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 176 psFree (view); 170 177 return false; 171 178 } … … 174 181 view->cell = -1; 175 182 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 183 psFree (view); 176 184 return false; 177 185 } … … 180 188 view->chip = -1; 181 189 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 190 psFree (view); 182 191 return false; 183 192 } … … 222 231 ppSubFilesActivate(config, PPSUB_FILES_ALL, false); 223 232 233 psFree (view); 224 234 return true; 225 235 } -
branches/czw_branch/20101203/ppSub/src/ppSubInputDetections.c
r30118 r30631 118 118 if (!psMetadataCopy(sourcesHDU->header, imageHDU->header)) { 119 119 psError(PPSUB_ERR_PROG, false, "Unable to copy header"); 120 psFree(view); 120 121 return false; 121 122 } … … 130 131 if (!psphotCopyResults (foundDetections, sourcesFile, photFile, view)) { 131 132 psError(PPSUB_ERR_PROG, false, "Unable to copy psphot outputs"); 133 psFree(view); 132 134 return false; 133 135 } 134 136 // if no sources were found here, we report that back and let them handle it 135 137 138 psFree(view); 136 139 return true; 137 140 } -
branches/czw_branch/20101203/ppSub/src/ppSubLoop.c
r30118 r30631 26 26 pmReadout *out = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); 27 27 psphotSaveImage (NULL, out->image, name); 28 psFree(view); 28 29 return true; 29 30 } … … 111 112 goto ESCAPE; 112 113 } 114 113 115 if (data->quality) { 114 116 // Can't do anything at all … … 257 259 psError(psErrorCodeLast(), false, "Unable to generate mask statistics"); 258 260 success = false; 261 psFree(view); 259 262 goto ESCAPE; 260 263 } 264 psFree(view); 261 265 } 262 266 // dumpout(config, "diff.4.fits"); -
branches/czw_branch/20101203/ppSub/src/ppSubMakePSF.c
r30118 r30631 79 79 if (!detections || !detections->allSources) { 80 80 psError(PPSUB_ERR_CONFIG, true, "No sources from which to determine PSF."); 81 psFree(view); 81 82 return false; 82 83 } … … 86 87 // use flags to toss totally bogus entries? 87 88 psArray *goodSources = ppSubSelectPSFSources (sources); 89 88 90 if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", goodSources)) { 89 91 // This is likely a data quality issue … … 126 128 outputRO = pmReadoutAlloc(outputCell); 127 129 outputRO->image = psMemIncrRefCounter(inputRO->image); 130 psFree(outputRO); // I have a copy on the outputCell 128 131 } 129 132 -
branches/czw_branch/20101203/ppSub/src/ppSubMatchPSFs.c
r30118 r30631 78 78 return true; 79 79 } 80 81 80 psFree(view); 82 81 … … 127 126 if (!inSourceRO || !refSourceRO) { 128 127 psError(PPSUB_ERR_DATA, false, "Unable to scale kernel, since no sources were provided."); 128 psFree(view); 129 129 return false; 130 130 } … … 164 164 165 165 // is auto-scaling needed? 166 if (!psMetadataLookupBool(NULL, recipe, "SCALE")) { 167 // No scaling requested 168 psFree(view); 169 return true; 170 } 171 166 bool scale = psMetadataLookupBool(NULL, recipe, "SCALE"); 172 167 float scaleRef = psMetadataLookupF32(NULL, recipe, "SCALE.REF"); // Reference for scaling 173 168 float scaleMin = psMetadataLookupF32(NULL, recipe, "SCALE.MIN"); // Minimum for scaling 174 169 float scaleMax = psMetadataLookupF32(NULL, recipe, "SCALE.MAX"); // Maximum for scaling 175 if (!isfinite(scaleRef) || !isfinite(scaleMin) || !isfinite(scaleMax)) { 170 171 if (scale && (!isfinite(scaleRef) || !isfinite(scaleMin) || !isfinite(scaleMax))) { 176 172 psError(PPSUB_ERR_ARGUMENTS, false, 177 " Scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in recipe.",173 "auto-scale selected but scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in recipe.", 178 174 scaleRef, scaleMin, scaleMax); 179 175 return false; 180 176 } 181 177 182 if (!pmSubtractionParamsScale(kernelSize, stampSize, kernelWidths, scaleRef, scaleMin, scaleMax)) { 183 psError(PPSUB_ERR_DATA, false, "Unable to scale parameters."); 184 return false; 185 } 178 pmSubtractionParamScaleOptions(scale, scaleRef, scaleMin, scaleMax); 179 180 // if (!pmSubtractionParamsScale(kernelSize, stampSize, kernelWidths)) { 181 // psError(PPSUB_ERR_DATA, false, "Unable to scale parameters."); 182 // return false; 183 // } 186 184 187 185 return true; … … 221 219 pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.INPUT.CONV"); // Cell for convolved input 222 220 inConv = pmReadoutAlloc(cell); 221 psFree(inConv); 223 222 } 224 223 pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference convolved … … 226 225 pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.REF.CONV"); // Cell for convolved ref. 227 226 refConv = pmReadoutAlloc(cell); 227 psFree(refConv); 228 228 } 229 229 … … 380 380 381 381 if (inRO->covariance) { 382 psImageCovarianceTruncate(inRO->covariance, COVAR_FRAC); 382 psKernel *truncated = psImageCovarianceTruncate(inRO->covariance, COVAR_FRAC); 383 psFree(inRO->covariance); 384 inRO->covariance = truncated; 383 385 } 384 386 if (refRO->covariance) { 385 psImageCovarianceTruncate(refRO->covariance, COVAR_FRAC); 387 psKernel *truncated = psImageCovarianceTruncate(refRO->covariance, COVAR_FRAC); 388 psFree(refRO->covariance); 389 refRO->covariance = truncated; 386 390 } 387 391 … … 494 498 495 499 if (inConv->covariance) { 496 psImageCovarianceTruncate(inConv->covariance, COVAR_FRAC); 500 psKernel *truncated = psImageCovarianceTruncate(inConv->covariance, COVAR_FRAC); 501 psFree(inConv->covariance); 502 inConv->covariance = truncated; 497 503 } 498 504 if (refConv->covariance) { 499 psImageCovarianceTruncate(refConv->covariance, COVAR_FRAC); 505 psKernel *truncated = psImageCovarianceTruncate(refConv->covariance, COVAR_FRAC); 506 psFree(refConv->covariance); 507 refConv->covariance = truncated; 500 508 } 501 509 -
branches/czw_branch/20101203/ppSub/src/ppSubReadoutForcedPhot.c
r30118 r30631 61 61 // XXX remove the pixels from photFile? 62 62 // XXX other cleanup operations? 63 psFree(view); 63 64 return true; 64 65 } … … 89 90 if (!psphotCopyResults (&foundDetections, outputFile, photFile, view)) { 90 91 psError(PPSUB_ERR_PROG, false, "Unable to copy psphot outputs"); 92 psFree(view); 91 93 return false; 92 94 } … … 97 99 psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_PHOT", PS_META_REPLACE, "Time to do photometry", elapsed); 98 100 101 psFree(view); 99 102 return true; 100 103 } -
branches/czw_branch/20101203/ppSub/src/ppSubReadoutInverse.c
r27789 r30631 36 36 if (!pmAstromWriteWCS(invHDU->header, outFPA, outChip, WCS_TOLERANCE)) { 37 37 psError(psErrorCodeLast(), false, "Unable to write WCS astrometry to PPSUB.INVERSE."); 38 psFree(view); 38 39 return false; 39 40 } … … 41 42 if (!pmAstromReadWCS(invFPA, invChip, invHDU->header, 1.0)) { 42 43 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry."); 44 psFree(view); 43 45 return false; 44 46 } 45 47 48 psFree(view); 46 49 return true; 47 50 } -
branches/czw_branch/20101203/ppSub/src/ppSubReadoutJpeg.c
r26982 r30631 139 139 } 140 140 141 psFree(view); 141 142 return true; 142 143 } -
branches/czw_branch/20101203/ppSub/src/ppSubReadoutPhotometry.c
r30118 r30631 109 109 if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.DETECTIONS")) { 110 110 psError(PPSUB_ERR_PROG, false, "Unable to copy PSPHOT.DETECTIONS"); 111 psFree(view); 111 112 return false; 112 113 } 113 114 if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.HEADER")) { 114 115 psError(PPSUB_ERR_PROG, false, "Unable to copy PSPHOT.HEADER"); 116 psFree(view); 115 117 return false; 116 118 } 117 119 if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, PM_DETEFF_ANALYSIS)) { 118 120 psError(PPSUB_ERR_PROG, false, "Unable to copy Detection Efficiency"); 121 psFree(view); 119 122 return false; 120 123 } … … 128 131 } 129 132 133 psFree(view); 130 134 return true; 131 135 } 132 136 133 137 #ifdef TESTING 134 // Record data about sources: not everything gets into the output CMF files138 // Record data about sources: not everything gets into the output CMF files 135 139 { 136 140 pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources -
branches/czw_branch/20101203/ppSub/src/ppSubReadoutSubtract.c
r29003 r30631 31 31 32 32 bool reverse = psMetadataLookupBool(&mdok, config->arguments, "REVERSE"); // Reverse sense of subtraction? 33 bool addPair = psMetadataLookupBool(&mdok, recipe, "ADD.NOT.SUBTRACT"); // add instead of subtracting 33 34 34 35 pmFPAview *view = ppSubViewReadout(); // View to readout … … 47 48 // Do the actual subtraction 48 49 pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); 49 outRO->image = (psImage*)psBinaryOp(outRO->image, minuend->image, "-", subtrahend->image); 50 51 if (addPair) { 52 outRO->image = (psImage*)psBinaryOp(outRO->image, minuend->image, "+", subtrahend->image); 53 } else { 54 outRO->image = (psImage*)psBinaryOp(outRO->image, minuend->image, "-", subtrahend->image); 55 } 50 56 outRO->mask = (psImage*)psBinaryOp(outRO->mask, minuend->mask, "|", subtrahend->mask); 51 57 outRO->variance = (psImage*)psBinaryOp(outRO->variance, minuend->variance, "+", subtrahend->variance); … … 70 76 psFree(rng); 71 77 78 // XXX EAM : I suspect that the weighted averaging is giving the wrong answer for 79 // single-direction PSF matching (and maybe DUAL as well). I am testing the difference by 80 // generating A+B images instead of A-B images and then checking the significance of the 81 // sources in the image 82 72 83 // Combine the covariances 73 84 // These are weighted by the appropriate mean variance. This is probably not perfectly correct, but it … … 79 90 covarWeights->data.F32[0] = minuendVar; 80 91 covarWeights->data.F32[1] = subtrahendVar; 92 # if (0) 81 93 outRO->covariance = psImageCovarianceAverageWeighted(covars, covarWeights); 94 # else 95 outRO->covariance = psImageCovarianceAverage(covars); 96 # endif 82 97 psFree(covars); 83 98 psFree(covarWeights); … … 109 124 pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT"); // Output chip 110 125 psFree(view); 126 111 127 if (!outHDU || !inHDU) { 112 128 psError(PPSUB_ERR_PROG, true, "Unable to find HDU at FPA level to copy astrometry."); -
branches/czw_branch/20101203/ppSub/src/ppSubSetMasks.c
r29551 r30631 80 80 if (!pmReadoutMaskInvalid(inRO, maskValue, satValue)) { 81 81 psError(PPSUB_ERR_DATA, false, "Unable to mask non-finite pixels in input."); 82 psFree(view); 82 83 return false; 83 84 } 84 85 if (!pmReadoutMaskInvalid(refRO, maskValue, satValue)) { 85 86 psError(PPSUB_ERR_DATA, false, "Unable to mask non-finite pixels in reference."); 87 psFree(view); 86 88 return false; 87 89 } … … 94 96 if (interpMode == PS_INTERPOLATE_NONE) { 95 97 psError(PPSUB_ERR_CONFIG, false, "Unknown interpolation mode: %s", interpModeStr); 98 psFree(view); 96 99 return false; 97 100 } … … 104 107 if (!pmReadoutInterpolateBadPixels(inRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) { 105 108 psError(PPSUB_ERR_DATA, false, "Unable to interpolate bad pixels for input image."); 109 psFree(view); 106 110 return false; 107 111 } 108 112 if (!pmReadoutInterpolateBadPixels(refRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) { 109 113 psError(PPSUB_ERR_DATA, false, "Unable to interpolate bad pixels for reference image."); 114 psFree(view); 110 115 return false; 111 116 } … … 113 118 #endif 114 119 120 psFree(view); 115 121 return true; 116 122 } -
branches/czw_branch/20101203/ppSub/src/ppSubThreshold.c
r26982 r30631 98 98 if (!in) { 99 99 psError(PPSUB_ERR_UNKNOWN, false, "Unable to find readout."); 100 psFree(view); 100 101 return false; 101 102 } … … 104 105 if (!ref) { 105 106 psError(PPSUB_ERR_UNKNOWN, false, "Unable to find readout."); 107 psFree(view); 106 108 return false; 107 109 } … … 115 117 if (!lowThreshold(in, thresh, maskVal, maskThresh, region, "input convolved image")) { 116 118 psError(psErrorCodeLast(), false, "Unable to threshold input image."); 119 psFree(view); 117 120 return false; 118 121 } 119 122 if (!lowThreshold(ref, thresh, maskVal, maskThresh, region, "reference convolved image")) { 120 123 psError(psErrorCodeLast(), false, "Unable to threshold input image."); 124 psFree(view); 121 125 return false; 122 126 } -
branches/czw_branch/20101203/ppSub/src/ppSubVarianceRescale.c
r28121 r30631 57 57 // Nothing to renormalise 58 58 psWarning("Renormalisation of the variance requested, but no variance provided."); 59 psFree(view); 59 60 return true; 60 61 } … … 69 70 } 70 71 72 psFree(view); 71 73 return true; 72 74 } -
branches/czw_branch/20101203/ppTranslate/src/ppMopsMerge.c
r30587 r30631 165 165 if (num == 0) { 166 166 //All detections were NULL?! 167 psTrace("ppMops.merge", 3, "All % d detections were NULL\n", detections->n);167 psTrace("ppMops.merge", 3, "All %ld detections were NULL\n", detections->n); 168 168 return NULL; 169 169 } -
branches/czw_branch/20101203/psLib/src/imageops
- Property svn:mergeinfo deleted
-
branches/czw_branch/20101203/psLib/src/imageops/psImageConvolve.c
r28405 r30631 67 67 } 68 68 69 psKernel *psKernelAlloc(int xMin, int xMax, int yMin, int yMax) 69 psKernel *p_psKernelAlloc(const char *file, 70 unsigned int lineno, 71 const char *func, 72 int xMin, int xMax, int yMin, int yMax) 70 73 { 71 74 // Check the inputs to make sure max > min; if not, switch. … … 91 94 int numCols = xMax - xMin + 1; // Number of columns for kernel image 92 95 93 psKernel *kernel = p sAlloc(sizeof(psKernel)); // The kernel, to be returned96 psKernel *kernel = p_psAlloc(file, lineno, func, sizeof(psKernel)); // The kernel, to be returned 94 97 psMemSetDeallocator(kernel,(psFreeFunc)kernelFree); 95 98 … … 272 275 float threshold = sumKernel * (1.0 - frac); // Threshold for truncation 273 276 277 int truncateRadius = maxSize; // Truncation radius 278 bool truncate = false; 279 274 280 // Find truncation size 275 int truncate = 0; // Truncation radius 276 for (int radius = 1; truncate == 0 && radius < maxSize; radius++) { 281 for (int radius = 1; !truncate && (radius < maxSize); radius++) { 277 282 int uMin = PS_MAX(-radius, xMin); 278 283 int uMax = PS_MIN(radius, xMax); … … 290 295 } 291 296 } 297 // This is the truncation radius 292 298 if (sum > threshold) { 293 // This is the truncation radius 294 truncate = radius; 295 } 296 } 297 if (truncate == maxSize) { 298 // No truncation possible 299 truncate = true; 300 truncateRadius = radius; 301 } 302 } 303 304 // Do nothing if no truncation is possible 305 if (!truncate) { 299 306 return true; 300 307 } … … 302 309 // Truncate the kernel 303 310 { 304 int uMin = PS_MAX(-truncate , xMin);305 int uMax = PS_MIN(truncate , xMax);306 int vMin = PS_MAX(-truncate , yMin);307 int vMax = PS_MIN(truncate , yMax);308 int r2 = PS_SQR(truncate );311 int uMin = PS_MAX(-truncateRadius, xMin); 312 int uMax = PS_MIN(truncateRadius, xMax); 313 int vMin = PS_MAX(-truncateRadius, yMin); 314 int vMax = PS_MIN(truncateRadius, yMax); 315 int r2 = PS_SQR(truncateRadius); 309 316 for (int v = vMin; v <= vMax; v++) { 310 317 int v2 = PS_SQR(v); … … 317 324 } 318 325 } 319 kernel->xMin = PS_MAX(-truncate , kernel->xMin);320 kernel->xMax = PS_MIN(truncate , kernel->xMax);321 kernel->yMin = PS_MAX(-truncate , kernel->yMin);322 kernel->yMax = PS_MIN(truncate , kernel->yMax);326 kernel->xMin = PS_MAX(-truncateRadius, kernel->xMin); 327 kernel->xMax = PS_MIN(truncateRadius, kernel->xMax); 328 kernel->yMin = PS_MAX(-truncateRadius, kernel->yMin); 329 kernel->yMax = PS_MIN(truncateRadius, kernel->yMax); 323 330 324 331 return true; -
branches/czw_branch/20101203/psLib/src/imageops/psImageConvolve.h
r26892 r30631 84 84 /// @return psKernel* A new kernel object 85 85 /// 86 #ifdef DOXYGEN 86 87 psKernel *psKernelAlloc( 87 88 int xMin, ///< Most negative x index … … 89 90 int yMin, ///< Most negative y index 90 91 int yMax ///< Most positive y index 92 ); 93 #else // ifdef DOXYGEN 94 psKernel *p_psKernelAlloc( 95 const char *file, ///< File of caller 96 unsigned int lineno, ///< Line number of caller 97 const char *func, ///< Function name of caller 98 int xMin, ///< Most negative x index 99 int xMax, ///< Most positive x index 100 int yMin, ///< Most negative y index 101 int yMax ///< Most positive y index 91 102 ) PS_ATTR_MALLOC; 103 #define psKernelAlloc(xMin, xMax, yMin, yMax) \ 104 p_psKernelAlloc(__FILE__, __LINE__, __func__, (xMin), (xMax), (yMin), (yMax)) 105 #endif // ifdef DOXYGEN 92 106 93 107 /// Allocate a convolution kernel from a provided image -
branches/czw_branch/20101203/psLib/src/imageops/psImageCovariance.c
r28667 r30631 30 30 return covar; 31 31 } 32 33 /** 34 35 * changes from 28666 36 ** add scale to imageCovarianceCalculate (& multiply at return) 37 ** add scale to imageCovarianceCalculateThread 38 39 ** accumulate scale (sum kernel^2) in psImageCovarianceCalculate and pass to imageCovarianceCalculate 40 ** accumulate scale (sum kernel^2) in psImageCovarianceCalculateFactor and pass to imageCovarianceCalculate 41 42 **/ 32 43 33 44 /// Calculation of covariance matrix element when convolving -
branches/czw_branch/20101203/psLib/src/sys/psLogMsg.c
r28404 r30631 291 291 head_ptr += strlen(head_ptr); 292 292 } 293 // Hostname should be 20 characters. 293 294 // Hostname should be 10 characters. 294 295 if (logHost) { 295 296 if (head_ptr > head) { 296 297 *head_ptr++ = '|'; 297 298 } 298 maxLength -= snprintf(head_ptr, maxLength, " %-20s", hostname);299 maxLength -= snprintf(head_ptr, maxLength, " %s ", hostname); 299 300 head_ptr += strlen(head_ptr); 300 301 } … … 310 311 *head_ptr++ = '|'; 311 312 } 312 maxLength -= snprintf(head_ptr, maxLength, "%s ", name);313 maxLength -= snprintf(head_ptr, maxLength, "%s|\n", name); 313 314 314 315 head_ptr += strlen(head_ptr); 315 } 316 317 if (head_ptr > head) { 318 *head_ptr++ = '\n'; 319 } else if (!logMsg) { // no output desired 316 } else { 317 if (head_ptr > head) { 318 *head_ptr++ = '|'; 319 } 320 } 321 322 // rather than putting in a return for the message, let's only put in the return if we asked for the function name 323 if ((head_ptr == head) && !logMsg) { // no output desired 320 324 return; 321 325 } … … 332 336 char *line = strtok_r(msg, "\n", &msgPtr); 333 337 while (line) { 334 if(write(logFD, " ", 4)) {;} // ignore return value338 if(write(logFD, " ", PS_MIN(2*level, 10))) {;} // ignore return value 335 339 if(write(logFD, line, strlen(line))) {;} // ignore return value 336 340 if(write(logFD, "\n", 1)) {;} // ignore return value -
branches/czw_branch/20101203/psLib/src/sys/psMemory.c
r28401 r30631 626 626 nleak++; 627 627 628 if (fd != NULL) { 628 // only print a max of 500 leaks (make this an argument) 629 if ((nleak < 500) && (fd != NULL)) { 629 630 if (nleak == 1) { 630 631 fprintf(fd, "# func at (file:line) ID: X Ref: X\n"); -
branches/czw_branch/20101203/psLib/test/imageops/Makefile.am
r30118 r30631 26 26 tap_psImageMapFit \ 27 27 tap_psImageMapFit2 \ 28 tap_psImageMaskOps 28 tap_psImageMaskOps \ 29 tap_psImageCovariance 29 30 30 31 # tap_psImageShiftKernel -
branches/czw_branch/20101203/psLib/test/math
- Property svn:mergeinfo deleted
-
branches/czw_branch/20101203/psModules/src/extras/pmVisual.c
r29545 r30631 16 16 #include <pslib.h> 17 17 18 #include "pmHDU.h" 19 #include "pmFPA.h" 20 #include "pmFPAfile.h" 21 #include "pmAstrometryObjects.h" 22 #include "pmSubtractionStamps.h" 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" 39 #include "pmPSF.h" 40 #include "pmPSFtry.h" 41 42 #include "pmFPAExtent.h" 43 44 #include "pmAstrometryVisual.h" 45 #include "pmSubtractionVisual.h" 46 #include "pmStackVisual.h" 47 #include "pmSourceVisual.h" 18 bool pmSubtractionVisualClose(void); 19 bool pmAstromVisualClose(void); 20 bool pmSubtractionVisualClose(void); 21 bool pmStackVisualClose(void); 22 bool pmSourceVisualClose(void); 23 24 // #include "pmHDU.h" 25 // #include "pmFPA.h" 26 // #include "pmFPAfile.h" 27 // #include "pmAstrometryObjects.h" 28 // #include "pmSubtractionStamps.h" 29 // #include "pmTrend2D.h" 30 // #include "pmResiduals.h" 31 // #include "pmGrowthCurve.h" 32 // #include "pmSpan.h" 33 // #include "pmFootprintSpans.h" 34 // #include "pmFootprint.h" 35 // #include "pmPeaks.h" 36 // #include "pmMoments.h" 37 // #include "pmModelFuncs.h" 38 // #include "pmModel.h" 39 // #include "pmSourceMasks.h" 40 // #include "pmSourceExtendedPars.h" 41 // #include "pmSourceDiffStats.h" 42 // #include "pmSource.h" 43 // #include "pmSourceFitModel.h" 44 // #include "pmPSF.h" 45 // #include "pmPSFtry.h" 46 // #include "pmFPAExtent.h" 47 // #include "pmAstrometryVisual.h" 48 // #include "pmSubtractionVisual.h" 49 // #include "pmStackVisual.h" 50 // #include "pmSourceVisual.h" 48 51 49 52 # if (HAVE_KAPA) … … 306 309 } 307 310 311 bool pmVisualRangeImage (int kapaFD, psImage *inImage, const char *name, int channel, float min, float max) { 312 313 KiiImage image; 314 KapaImageData data; 315 Coords coords; 316 317 strcpy (coords.ctype, "RA---TAN"); 318 319 image.data2d = inImage->data.F32; 320 image.Nx = inImage->numCols; 321 image.Ny = inImage->numRows; 322 323 strcpy (data.name, name); 324 strcpy (data.file, name); 325 data.zero = min; 326 data.range = max - min; 327 data.logflux = 0; 328 329 KiiSetChannel (kapaFD, channel); 330 KiiNewPicture2D (kapaFD, &image, &data, &coords); 331 332 return true; 333 } 308 334 309 335 psImage* pmVisualImageToFloat(psImage *image) { -
branches/czw_branch/20101203/psModules/src/extras/pmVisual.h
r23242 r30631 64 64 const char *name, int channel, bool clip); 65 65 66 bool pmVisualRangeImage (int kapaFD, psImage *inImage, const char *name, int channel, float min, float max); 66 67 67 68 /** Calculate statistics on an image. -
branches/czw_branch/20101203/psModules/src/imcombine/Makefile.am
r26893 r30631 30 30 pmStackReject.h \ 31 31 pmSubtraction.h \ 32 pmSubtractionTypes.h \ 32 33 pmSubtractionAnalysis.h \ 33 34 pmSubtractionEquation.h \ -
branches/czw_branch/20101203/psModules/src/imcombine/pmReadoutCombine.c
r24907 r30631 33 33 params->blank = 0; 34 34 params->nKeep = 0; 35 params->frac High= 0.0;35 params->fracLow = 0.0; 36 36 params->fracHigh = 0.0; 37 37 params->iter = 1; -
branches/czw_branch/20101203/psModules/src/imcombine/pmStackReject.c
r28405 r30631 7 7 #include <pslib.h> 8 8 9 #include "pmFPA.h" 10 #include "pmSubtractionTypes.h" 9 11 #include "pmSubtraction.h" 10 12 #include "pmSubtractionThreads.h" -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtraction.c
r29777 r30631 20 20 #include "pmHDU.h" // Required for pmFPA.h 21 21 #include "pmFPA.h" 22 #include "pmSubtractionTypes.h" 22 23 #include "pmSubtractionStamps.h" 23 24 #include "pmSubtractionEquation.h" 24 25 #include "pmSubtractionVisual.h" 25 26 #include "pmSubtractionThreads.h" 27 28 bool psFitsWriteImageSimple (char *filename, psImage *image, psMetadata *header); 26 29 27 30 #include "pmSubtraction.h" … … 773 776 774 777 if (convolutions) { 775 // Already done776 778 return convolutions; 777 779 } … … 787 789 } 788 790 791 792 bool pmSubtractionConvolveStampThread(psThreadJob *job) 793 { 794 PS_ASSERT_THREAD_JOB_NON_NULL(job, false); 795 796 pmSubtractionStamp *stamp = job->args->data[0]; // List of stamps 797 pmSubtractionKernels *kernels = job->args->data[1]; // Kernels 798 int footprint = PS_SCALAR_VALUE(job->args->data[2], S32); // Stamp index 799 800 return pmSubtractionConvolveStamp(stamp, kernels, footprint); 801 } 789 802 790 803 bool pmSubtractionConvolveStamp (pmSubtractionStamp *stamp, pmSubtractionKernels *kernels, int footprint) … … 818 831 } 819 832 833 #ifdef TESTING 834 for (int j = 0; j < kernels->num; j++) { 835 if (stamp->convolutions1) { 836 psString convName = NULL; 837 psStringAppend(&convName, "conv1_%03d_%03d.fits", index, j); 838 psFits *fits = psFitsOpen(convName, "w"); 839 psFree(convName); 840 psKernel *conv = stamp->convolutions1->data[j]; 841 psFitsWriteImage(fits, NULL, conv->image, 0, NULL); 842 psFitsClose(fits); 843 } 844 845 if (stamp->convolutions2) { 846 psString convName = NULL; 847 psStringAppend(&convName, "conv2_%03d_%03d.fits", index, j); 848 psFits *fits = psFitsOpen(convName, "w"); 849 psFree(convName); 850 psKernel *conv = stamp->convolutions2->data[j]; 851 psFitsWriteImage(fits, NULL, conv->image, 0, NULL); 852 psFitsClose(fits); 853 } 854 } 855 #endif 856 820 857 return true; 821 858 } 822 859 860 bool pmSubtractionConvolveStamps(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels) 861 { 862 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); 863 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, false); 864 865 psTimerStart("pmSubtractionConvolveStamps"); 866 867 int footprint = stamps->footprint; // Half-size of stamps 868 869 // We iterate over each stamp and generate the convolution if needed. We do NOT need the 870 // convolution if (a) it has already been calculated or (b) the stamp is not available for 871 // use (available = USED or CALCULATE) 872 873 for (int i = 0; i < stamps->num; i++) { 874 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest 875 876 bool keep = false; 877 keep |= (stamp->status == PM_SUBTRACTION_STAMP_USED); 878 keep |= (stamp->status == PM_SUBTRACTION_STAMP_CALCULATE); 879 if (!keep) continue; 880 881 bool haveConvolutions = false; 882 if (kernels->mode == PM_SUBTRACTION_MODE_1) { 883 haveConvolutions = (stamp->convolutions1 != NULL); 884 } 885 if (kernels->mode == PM_SUBTRACTION_MODE_2) { 886 haveConvolutions = (stamp->convolutions2 != NULL); 887 } 888 if (kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 889 haveConvolutions = (stamp->convolutions1 != NULL) && (stamp->convolutions2 != NULL); 890 } 891 if (haveConvolutions) { 892 continue; 893 } 894 895 if (pmSubtractionThreaded()) { 896 psThreadJob *job = psThreadJobAlloc("PSMODULES_SUBTRACTION_CONVOLVE_STAMP"); 897 psArrayAdd(job->args, 1, stamp); 898 psArrayAdd(job->args, 1, kernels); 899 PS_ARRAY_ADD_SCALAR(job->args, footprint, PS_TYPE_S32); 900 if (!psThreadJobAddPending(job)) { 901 return false; 902 } 903 } else { 904 pmSubtractionConvolveStamp(stamp, kernels, footprint); 905 } 906 } 907 if (!psThreadPoolWait(true)) { 908 psError(psErrorCodeLast(), false, "Error waiting for threads."); 909 return false; 910 } 911 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Convolve stamps: %f sec", psTimerClear("pmSubtractionConvolveStamps")); 912 return true; 913 } 823 914 824 915 int pmSubtractionRejectStamps(pmSubtractionKernels *kernels, pmSubtractionStampList *stamps, 825 const psVector *deviations, psImage *subMask, float sigmaRej)916 pmSubtractionQuality *match, psImage *subMask, float sigmaRej) 826 917 { 827 918 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, false); 828 919 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, -1); 829 PS_ASSERT_VECTOR_NON_NULL(deviations, -1);830 PS_ASSERT_VECTOR_TYPE(deviations, PS_TYPE_F32, -1);831 920 PS_ASSERT_IMAGE_NON_EMPTY(subMask, -1); 832 921 PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_IMAGE_MASK, -1); 833 922 834 // I used to measure the rms deviation about zero, and use that as the sigma against which to clip, but 835 // the distribution is actually something like a chi^2 or Student's t, both of which become Gaussian-like 836 // with large N. Therefore, let's just treat this as a Gaussian distribution. 923 // Comment from PAP (r18287): I used to measure the rms deviation about zero, and use that as the 924 // sigma against which to clip, but the distribution is actually something like a chi^2 or 925 // Student's t, both of which become Gaussian-like with large N. Therefore, let's just 926 // treat this as a Gaussian distribution. 927 928 // Comment from EAM (r29777): The residual distribution is only chisq-like if the model is 929 // a good fit to the data. In the (likely) case that there is a systematic difference 930 // between the model and the data, the squared-residual distribution grows quadratically 931 // with increasing flux: the systematic residual flux is a constant factor times the source 932 // flux; the squared-residual is then of the form (k0 + k1*flux)^2, where k0 comes from the 933 // Gaussian distributed residual and k1*flux is the systematic residual error. 934 935 // By rejecting sources with the largest squared-residuals, the rejection biases against 936 // the brighter sources; in severe cases, this pushes the measurement to the weakest 937 // sources with the most noise. To account for this, let's fit a 2nd order polynomial to 938 // the distribution of flux vs squared-residual, subtract that fit, and reject sources 939 // which are significantly deviant from that distribution. 837 940 838 941 kernels->mean = NAN; … … 840 943 kernels->numStamps = -1; 841 944 842 int numStamps = 0; // Number of used stamps 843 psVector *mask = psVectorAlloc(stamps->num, PS_TYPE_VECTOR_MASK); // Mask, for statistics 844 psVectorInit(mask, 0); 845 for (int i = 0; i < stamps->num; i++) { 846 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest 847 if (stamp->status != PM_SUBTRACTION_STAMP_USED) { 848 mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff; 849 continue; 850 } 851 numStamps++; 852 } 853 psTrace("psModules.imcombine", 1, "Number of good stamps: %d\n", numStamps); 854 855 if (numStamps == 0) { 856 psError(PM_ERR_STAMPS, true, "No good stamps found."); 857 psFree(mask); 858 return -1; 859 } 860 861 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV | 862 PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_QUARTILE); // Statistics for deviatns 863 if (!psVectorStats(stats, deviations, NULL, mask, 0xff)) { 864 psError(PM_ERR_DATA, false, "Unable to measure statistics for deviations."); 945 psTrace("psModules.imcombine", 1, "Number of good stamps: %d\n", match->nGood); 946 947 // the chisq & flux vectors are calculated by pmSubtractionCalculateChisqAndMoments 948 949 // use 3hi/3lo sigma clipping on the chisq fit 950 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 951 stats->clipSigma = 5.0; 952 stats->clipIter = 2; 953 psPolynomial1D *model = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 2); 954 955 bool result = psVectorClipFitPolynomial1D(model, stats, match->stampMask, 0xff, match->chisq, NULL, match->fluxes); 956 if (!result) { 957 psError(PM_ERR_DATA, false, "Unable to measure statistics for deviations."); 958 psFree(model); 865 959 psFree(stats); 866 psFree(mask); 867 return -1; 868 } 869 psFree(mask); 870 871 // XXX raise an error? 960 return -1; 961 } 872 962 if (isnan(stats->sampleMean)) { 963 psError(PM_ERR_DATA, false, "Unable to measure statistics for deviations."); 964 psFree(model); 873 965 psFree(stats); 874 966 return -1; 875 967 } 876 968 877 double mean, rms; // Mean and RMS of deviations 878 if (numStamps < MIN_SAMPLE_STATS) { 879 mean = stats->sampleMean; 880 rms = stats->sampleStdev; 881 } else { 882 mean = stats->sampleMedian; 883 rms = 0.74 * (stats->sampleUQ - stats->sampleLQ); 884 } 885 psFree(stats); 886 887 psTrace("psModules.imcombine", 1, "Mean: %f\n", mean); 888 psTrace("psModules.imcombine", 1, "RMS deviation: %f\n", rms); 889 890 kernels->mean = mean; 891 kernels->rms = rms; 892 kernels->numStamps = numStamps; 893 894 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Mean deviation from %d stamps: %lf +/- %lf", 895 numStamps, mean, rms); 896 897 if (!isfinite(sigmaRej) || sigmaRej <= 0.0) { 898 // User just wanted to calculate and record the deviation for posterity 899 return 0; 900 } 901 902 float limit = sigmaRej * rms; // Limit on maximum deviation 903 psTrace("psModules.imcombine", 1, "Deviation limit: %f\n", limit); 904 969 kernels->mean = stats->sampleMean; 970 kernels->rms = stats->sampleStdev; 971 kernels->numStamps = stats->clippedNvalues; 972 973 psLogMsg ("pmPSFtry", 4, "chisq vs flux model: %e + %e flux + %e flux^2\n", model->coeff[0], model->coeff[1], model->coeff[2]); 974 psLogMsg ("pmPSFtry", 4, "chisq vs flux resid: %f +/- %f\n", stats->sampleMean, stats->sampleStdev); 975 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Mean deviation from %d stamps: %lf +/- %lf", kernels->numStamps, kernels->mean, kernels->rms); 905 976 906 977 psString ds9name = NULL; // Filename for ds9 region file … … 914 985 int numRejected = 0; // Number of stamps rejected 915 986 int numGood = 0; // Number of good stamps 916 double newMean = 0.0; // New mean917 987 psString log = NULL; // Log message 918 psStringAppend(&log, "Rejecting stamps, mean = %f, threshold = %f\n", mean, limit); 988 989 // save DS9 region files for the stamps and mark for rejection and replacement 919 990 for (int i = 0; i < stamps->num; i++) { 920 991 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest 921 if (stamp->status == PM_SUBTRACTION_STAMP_USED) { 992 if (stamp->status != PM_SUBTRACTION_STAMP_USED) { continue; } 993 if (match->stampMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 922 994 // Should we reject stars with low deviation? Well, if this is really a Gaussian-like 923 995 // distribution and they're low, then we have the right to ask why. Isn't it suspicious that … … 926 998 // subtract well, in which case very few (if any) stars will be legitimately rejected for being 927 999 // low. 928 if (fabsf(deviations->data.F32[i] - mean) > limit) { 929 // Mask out the stamp in the image so you it's not found again 930 psTrace("psModules.imcombine", 3, "Rejecting stamp %d (%d,%d)\n", i, 931 (int)(stamp->x - 0.5), (int)(stamp->y - 0.5)); 932 psStringAppend(&log, "Stamp %d (%d,%d): %f\n", i, 933 (int)(stamp->x - 0.5), (int)(stamp->y - 0.5), 934 fabsf(deviations->data.F32[i] - mean)); 935 numRejected++; 936 for (int y = stamp->y - footprint; y <= stamp->y + footprint; y++) { 937 for (int x = stamp->x - footprint; x <= stamp->x + footprint; x++) { 938 subMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= PM_SUBTRACTION_MASK_REJ; 939 } 940 } 941 pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "red"); 942 943 // Set stamp for replacement 944 stamp->x = 0; 945 stamp->y = 0; 946 stamp->xNorm = NAN; 947 stamp->yNorm = NAN; 948 stamp->status = PM_SUBTRACTION_STAMP_REJECTED; 949 // Recalculate convolutions 950 psFree(stamp->convolutions1); 951 psFree(stamp->convolutions2); 952 stamp->convolutions1 = stamp->convolutions2 = NULL; 953 psFree(stamp->image1); 954 psFree(stamp->image2); 955 psFree(stamp->weight); 956 stamp->image1 = stamp->image2 = stamp->weight = NULL; 957 psFree(stamp->matrix); 958 stamp->matrix = NULL; 959 psFree(stamp->vector); 960 stamp->vector = NULL; 961 } else { 962 numGood++; 963 newMean += deviations->data.F32[i]; 964 pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "green"); 965 } 966 } 967 } 968 newMean /= numGood; 1000 psTrace("psModules.imcombine", 3, "Rejecting stamp %d (%d,%d)\n", i, 1001 (int)(stamp->x - 0.5), (int)(stamp->y - 0.5)); 1002 psStringAppend(&log, "Stamp %d (%d,%d): %f : %f : %f\n", 1003 i, (int)(stamp->x - 0.5), (int)(stamp->y - 0.5), 1004 match->chisq->data.F32[i], match->fluxes->data.F32[i], match->chisq->data.F32[i] - psPolynomial1DEval(model, match->fluxes->data.F32[i])); 1005 numRejected++; 1006 for (int y = stamp->y - footprint; y <= stamp->y + footprint; y++) { 1007 for (int x = stamp->x - footprint; x <= stamp->x + footprint; x++) { 1008 subMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= PM_SUBTRACTION_MASK_REJ; 1009 } 1010 } 1011 pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "red"); 1012 1013 // Set stamp for replacement 1014 stamp->x = 0; 1015 stamp->y = 0; 1016 stamp->xNorm = NAN; 1017 stamp->yNorm = NAN; 1018 stamp->status = PM_SUBTRACTION_STAMP_REJECTED; 1019 // Recalculate convolutions 1020 psFree(stamp->convolutions1); 1021 psFree(stamp->convolutions2); 1022 stamp->convolutions1 = stamp->convolutions2 = NULL; 1023 psFree(stamp->image1); 1024 psFree(stamp->image2); 1025 psFree(stamp->weight); 1026 stamp->image1 = stamp->image2 = stamp->weight = NULL; 1027 psFree(stamp->matrix); 1028 stamp->matrix = NULL; 1029 psFree(stamp->vector); 1030 stamp->vector = NULL; 1031 } else { 1032 numGood++; 1033 pmSubtractionStampPrint(ds9, stamp->x, stamp->y, stamps->footprint, "green"); 1034 } 1035 } 969 1036 970 1037 if (numRejected == 0) { … … 978 1045 } 979 1046 1047 psFree(model); 1048 psFree(stats); 1049 980 1050 if (numRejected > 0) { 981 psLogMsg("psModules.imcombine", PS_LOG_INFO, 982 "%d good stamps; %d rejected.\nMean deviation: %lf --> %lf\n", 983 numGood, numRejected, mean, newMean); 1051 psLogMsg("psModules.imcombine", PS_LOG_INFO, "%d good stamps; %d rejected.\n", numGood, numRejected); 984 1052 } else { 985 psLogMsg("psModules.imcombine", PS_LOG_INFO, 986 "%d good stamps; 0 rejected.\nMean deviation: %lf\n", 987 numGood, mean); 1053 psLogMsg("psModules.imcombine", PS_LOG_INFO, "%d good stamps; 0 rejected.\n", numGood); 988 1054 } 989 1055 … … 1373 1439 psFree(kernelErr2); 1374 1440 1441 static int nOut1 = 0; 1442 static int nOut2 = 0; 1443 1375 1444 // Calculate covariances 1376 1445 // This can be fairly involved, so we only do it for a small number of instances … … 1386 1455 psKernelTruncate(kernel, covarFrac); 1387 1456 covars->data[i] = psImageCovarianceCalculate(kernel, ro1->covariance); 1457 if (0) { 1458 char name[128]; 1459 snprintf (name, 128, "covar.sample1.%03d.fits", nOut1); 1460 psKernel *cov = covars->data[i]; 1461 psFitsWriteImageSimple (name, cov->image, NULL); 1462 1463 snprintf (name, 128, "incovar.sample1.%03d.fits", nOut1); 1464 psFitsWriteImageSimple (name, ro1->covariance->image, NULL); 1465 1466 snprintf (name, 128, "conv.sample1.%03d.fits", nOut1); 1467 psFitsWriteImageSimple (name, kernel->image, NULL); 1468 1469 fprintf (stderr, "incov: %d,%d; kern: %d,%d, outcov: %d,%d\n", 1470 ro1->covariance->image->numCols, ro1->covariance->image->numRows, 1471 kernel->image->numCols, kernel->image->numRows, 1472 cov->image->numCols, cov->image->numRows); 1473 1474 nOut1 ++; 1475 } 1388 1476 psFree(kernel); 1389 1477 } … … 1407 1495 psKernelTruncate(kernel, covarFrac); 1408 1496 covars->data[i] = psImageCovarianceCalculate(kernel, ro2->covariance); 1497 if (0) { 1498 char name[128]; 1499 snprintf (name, 128, "covar.sample2.%03d.fits", nOut2); 1500 psKernel *cov = covars->data[i]; 1501 psFitsWriteImageSimple (name, cov->image, NULL); 1502 1503 snprintf (name, 128, "incovar.sample2.%03d.fits", nOut2); 1504 psFitsWriteImageSimple (name, ro2->covariance->image, NULL); 1505 1506 snprintf (name, 128, "conv.sample2.%03d.fits", nOut2); 1507 psFitsWriteImageSimple (name, kernel->image, NULL); 1508 1509 fprintf (stderr, "incov: %d,%d; kern: %d,%d, outcov: %d,%d\n", 1510 ro2->covariance->image->numCols, ro2->covariance->image->numRows, 1511 kernel->image->numCols, kernel->image->numRows, 1512 cov->image->numCols, cov->image->numRows); 1513 1514 nOut2 ++; 1515 } 1409 1516 psFree(kernel); 1410 1517 } … … 1422 1529 psImageCovarianceSetThreads(oldThreads); 1423 1530 1424 // Copy anything that wasn't convolved 1531 // Copy anything that wasn't convolved (they may have been allocated though, so free them) 1425 1532 switch (kernels->mode) { 1426 1533 case PM_SUBTRACTION_MODE_1: 1427 1534 if (out2) { 1535 psFree(out2->image); 1536 psFree(out2->variance); 1537 psFree(out2->mask); 1538 psFree(out2->covariance); 1428 1539 out2->image = psMemIncrRefCounter(ro2->image); 1429 1540 out2->variance = psMemIncrRefCounter(ro2->variance); … … 1434 1545 case PM_SUBTRACTION_MODE_2: 1435 1546 if (out1) { 1547 psFree(out1->image); 1548 psFree(out1->variance); 1549 psFree(out1->mask); 1550 psFree(out1->covariance); 1436 1551 out1->image = psMemIncrRefCounter(ro1->image); 1437 1552 out1->variance = psMemIncrRefCounter(ro1->variance); … … 1479 1594 return true; 1480 1595 } 1596 1597 static void pmSubtractionQualityFree(pmSubtractionQuality *quality) { 1598 1599 psFree (quality->fluxes); 1600 psFree (quality->chisq); 1601 psFree (quality->moments); 1602 psFree (quality->stampMask); 1603 } 1604 1605 pmSubtractionQuality *pmSubtractionQualityAlloc() { 1606 1607 pmSubtractionQuality *quality = psAlloc(sizeof(pmSubtractionQuality)); // Stamp list to return 1608 psMemSetDeallocator(quality, (psFreeFunc)pmSubtractionQualityFree); 1609 1610 quality->fluxes = NULL; 1611 quality->chisq = NULL; 1612 quality->moments = NULL; 1613 quality->stampMask = NULL; 1614 1615 quality->score = NAN; 1616 quality->mode = PM_SUBTRACTION_MODE_ERR; 1617 quality->spatialOrder = -1; 1618 quality->nGood = 0; 1619 1620 return quality; 1621 } -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtraction.h
r29601 r30631 14 14 #define PM_SUBTRACTION_H 15 15 16 #include <pslib.h> 17 18 #include <pmHDU.h> 19 #include <pmFPA.h> 20 #include <pmSubtractionKernels.h> 21 #include <pmSubtractionStamps.h> 16 // #include <pslib.h> 17 // #include <pmHDU.h> 18 // #include <pmFPA.h> 19 // #include <pmSubtractionKernels.h> 20 // #include <pmSubtractionStamps.h> 22 21 23 22 // if we use the original ppSub implementation, we subtract a central delta-function for all … … 30 29 /// @addtogroup imcombine Image Combinations 31 30 /// @{ 32 33 /// Mask values for the subtraction mask34 typedef enum {35 PM_SUBTRACTION_MASK_CLEAR = 0x00, // No masking36 PM_SUBTRACTION_MASK_BAD_1 = 0x01, // Image 1 is bad37 PM_SUBTRACTION_MASK_BAD_2 = 0x02, // Image 2 is bad38 PM_SUBTRACTION_MASK_CONVOLVE_1 = 0x04, // If image 1 is convolved, would be poor or bad39 PM_SUBTRACTION_MASK_CONVOLVE_2 = 0x08, // If image 2 is convolved, would be poor or bad40 PM_SUBTRACTION_MASK_CONVOLVE_BAD_1 = 0x10, // If image 1 is convolved, would be bad41 PM_SUBTRACTION_MASK_CONVOLVE_BAD_2 = 0x20, // If image 2 is convolved, would be bad42 PM_SUBTRACTION_MASK_BORDER = 0x40, // Image border43 PM_SUBTRACTION_MASK_REJ = 0x80, // Previously tried as a stamp, and rejected44 } pmSubtractionMasks;45 46 31 47 32 /// Number of terms in a polynomial … … 70 55 ); 71 56 57 bool pmSubtractionConvolveStamps(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels); 58 59 bool pmSubtractionConvolveStampThread(psThreadJob *job); 60 72 61 /// Reject stamps 73 62 int pmSubtractionRejectStamps(pmSubtractionKernels *kernels, ///< Kernel parameters to update 74 63 pmSubtractionStampList *stamps, ///< Stamps 75 const psVector *deviations, ///< Deviations for each stamp64 pmSubtractionQuality *match, ///< data on the subtraction quality 76 65 psImage *subMask, ///< Subtraction mask 77 66 float sigmaRej ///< Number of RMS deviations above zero at which to reject … … 167 156 bool pmSubtractionSetFWHMs(float fwhm1, float fwhm2); 168 157 158 pmSubtractionQuality *pmSubtractionQualityAlloc(); 159 169 160 /// @} 170 161 #endif -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionAnalysis.c
r29595 r30631 7 7 8 8 #include "pmFPA.h" 9 #include "pmSubtractionTypes.h" 9 10 #include "pmSubtraction.h" 10 11 #include "pmSubtractionKernels.h" -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionDeconvolve.c
r26893 r30631 10 10 11 11 #include "pmFPA.h" 12 #include "pmSubtractionTypes.h" 12 13 #include "pmSubtractionKernels.h" 13 14 #include "pmSubtractionDeconvolve.h" -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionEquation.c
r29598 r30631 8 8 9 9 #include "pmErrorCodes.h" 10 #include "pmVisual.h" 11 #include "pmFPA.h" 12 #include "pmSubtractionTypes.h" 10 13 #include "pmSubtraction.h" 11 14 #include "pmSubtractionKernels.h" … … 16 19 #include "pmSubtractionVisual.h" 17 20 18 //#define TESTING // TESTING output for debugging; may not work with threads! 19 20 //#define USE_WEIGHT // Include weight (1/variance) in equation? 21 22 // XXX TEST: 23 //# define USE_WINDOW // window to avoid neighbor contamination 21 //# define TESTING // TESTING output for debugging; may not work with threads! 22 # define USE_WEIGHT // Include weight (1/variance) in equation? 23 # define USE_WINDOW // window to avoid neighbor contamination 24 25 /* I believe we want to apply the WEIGHT to the chisq portions of the calculation (but not the WINDOW), 26 * and the WINDOW to the moments portiosn of the calculations (but not the WEIGHT) 27 * 28 */ 24 29 25 30 # define PENALTY false 26 31 # define MOMENTS (!PENALTY) 27 # define MOMENTS_PENALTY_SCALE 2 e-5 // XXX this value is not completely arbitrary, but I don't understand why it needs to be this value...32 # define MOMENTS_PENALTY_SCALE 20 // up-weight the moments somewhat 28 33 29 34 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 107 112 cc *= weight->kernel[y][x]; 108 113 } 109 if (window) { 114 // XXX NOTE: do NOT apply the window to the chisq portions of the calculation 115 if (false && window) { 110 116 cc *= window->kernel[y][x]; 111 117 } … … 138 144 rc *= wtVal; 139 145 } 140 if (window) { 146 // XXX NOTE: do NOT apply the window to the chisq portions of the calculation 147 if (false && window) { 141 148 float winVal = window->kernel[y][x]; 142 149 ic *= winVal; … … 173 180 } 174 181 182 # define RENORM_BY_FLUX 0 175 183 176 184 // Calculate the least-squares matrix and vector for dual convolution … … 268 276 for (int y = - footprint; y <= footprint; y++) { 269 277 for (int x = - footprint; x <= footprint; x++) { 278 279 // XXX NOTE: clipping low S/N pixels does not seem to work very well 280 if (false && weight) { 281 float i1 = image1->kernel[y][x]; 282 float i2 = image2->kernel[y][x]; 283 float sn = (i1 + i2) / sqrt (weight->kernel[y][x]); 284 if (sn < 0.5) continue; 285 } 286 270 287 double aa = iConv1->kernel[y][x] * jConv1->kernel[y][x] * PS_SQR(normValue); 271 288 double bb = iConv2->kernel[y][x] * jConv2->kernel[y][x]; 272 289 double ab = iConv1->kernel[y][x] * jConv2->kernel[y][x] * normValue; 273 if (weight) { 274 float wtVal = weight->kernel[y][x]; 275 aa *= wtVal; 276 bb *= wtVal; 277 ab *= wtVal; 278 } 279 if (window) { 280 float wtVal = window->kernel[y][x]; 281 aa *= wtVal; 282 bb *= wtVal; 283 ab *= wtVal; 284 } 285 sumAA += aa; 286 sumBB += bb; 287 sumAB += ab; 290 291 float wtVal = (weight) ? weight->kernel[y][x] : 1.0; 292 sumAA += wtVal*aa; 293 sumBB += wtVal*bb; 294 sumAB += wtVal*ab; 288 295 289 296 if (MOMENTS) { 290 MxxAA += x*x*aa; 291 MyyAA += y*y*aa; 292 MxxBB += x*x*bb; 293 MyyBB += y*y*bb; 297 float winVal = (window) ? window->kernel[y][x] : 1.0; 298 MxxAA += winVal*x*x*aa; 299 MyyAA += winVal*y*y*aa; 300 MxxBB += winVal*x*x*bb; 301 MyyBB += winVal*y*y*bb; 294 302 } 295 303 } 296 304 } 297 305 306 // XXX does normSquare1,2 mess up the relative scaling? 307 // XXX no: normSquare1,2 is the sum of the flux^2 for the source 298 308 if (MOMENTS) { 299 309 MxxAA /= stamp->normSquare1 * PS_SQR(normValue); … … 305 315 // XXX this makes the Chisq portion independent of the normalization and star flux 306 316 // but may be mis-scaling between stars of different fluxes 317 # if (RENORM_BY_FLUX) 307 318 sumAA /= PS_SQR(stamp->normI2); 308 319 sumAB /= PS_SQR(stamp->normI2); 309 320 sumBB /= PS_SQR(stamp->normI2); 321 # endif 310 322 311 323 // fprintf (stderr, "i,j : %d %d : M(xx,yy)(AA,BB) : %f %f %f %f\n", i, j, MxxAA, MyyAA, MxxBB, MyyBB); … … 328 340 matrix->data.F64[iIndex][jIndex] += kernels->penalty * MxxAA * MOMENTS_PENALTY_SCALE; 329 341 matrix->data.F64[iIndex][jIndex] += kernels->penalty * MyyAA * MOMENTS_PENALTY_SCALE; 330 331 342 matrix->data.F64[jIndex][iIndex] += kernels->penalty * MxxAA * MOMENTS_PENALTY_SCALE; 332 343 matrix->data.F64[jIndex][iIndex] += kernels->penalty * MyyAA * MOMENTS_PENALTY_SCALE; … … 334 345 matrix->data.F64[iIndex + numParams][jIndex + numParams] += kernels->penalty * MxxBB * MOMENTS_PENALTY_SCALE; 335 346 matrix->data.F64[iIndex + numParams][jIndex + numParams] += kernels->penalty * MyyBB * MOMENTS_PENALTY_SCALE; 336 337 347 matrix->data.F64[jIndex + numParams][iIndex + numParams] += kernels->penalty * MxxBB * MOMENTS_PENALTY_SCALE; 338 348 matrix->data.F64[jIndex + numParams][iIndex + numParams] += kernels->penalty * MyyBB * MOMENTS_PENALTY_SCALE; … … 354 364 ab *= weight->kernel[y][x]; 355 365 } 356 if (window) { 366 // XXX NOTE: do NOT apply the window to the chisq portions of the calculation 367 if (false && window) { 357 368 ab *= window->kernel[y][x]; 358 369 } … … 363 374 // XXX this makes the Chisq portion independent of the normalization and star flux 364 375 // but may be mis-scaling between stars of different fluxes 376 # if (RENORM_BY_FLUX) 365 377 sumAB /= PS_SQR(stamp->normI2); 378 # endif 366 379 367 380 // Spatial variation of kernel coeffs … … 391 404 float i2 = image2->kernel[y][x]; 392 405 406 // XXX NOTE: clipping low S/N pixels does not seem to work very well 407 if (false && weight) { 408 float sn = (i1 + i2) / sqrt (weight->kernel[y][x]); 409 if (sn < 0.5) continue; 410 } 411 393 412 double ai2 = a * i2 * normValue; 394 413 double bi2 = b * i2; … … 396 415 double bi1 = b * i1 * normValue; 397 416 398 if (weight) { 399 float wtVal = weight->kernel[y][x]; 400 ai2 *= wtVal; 401 bi2 *= wtVal; 402 ai1 *= wtVal; 403 bi1 *= wtVal; 404 } 405 if (window) { 406 float wtVal = window->kernel[y][x]; 407 ai2 *= wtVal; 408 bi2 *= wtVal; 409 ai1 *= wtVal; 410 bi1 *= wtVal; 411 } 412 sumAI2 += ai2; 413 sumBI2 += bi2; 414 sumAI1 += ai1; 415 sumBI1 += bi1; 417 float wtVal = (weight) ? weight->kernel[y][x] : 1.0; 418 sumAI2 += wtVal*ai2; 419 sumBI2 += wtVal*bi2; 420 sumAI1 += wtVal*ai1; 421 sumBI1 += wtVal*bi1; 416 422 417 423 if (MOMENTS) { 418 MxxAI1 += x*x*ai1; 419 MyyAI1 += y*y*ai1; 420 MxxBI2 += x*x*bi2; 421 MyyBI2 += y*y*bi2; 424 float winVal = (window) ? window->kernel[y][x] : 1.0; 425 MxxAI1 += winVal*x*x*ai1; 426 MyyAI1 += winVal*y*y*ai1; 427 MxxBI2 += winVal*x*x*bi2; 428 MyyBI2 += winVal*y*y*bi2; 422 429 } 423 430 } … … 435 442 // XXX this makes the Chisq portion independent of the normalization and star flux 436 443 // but may be mis-scaling between stars of different fluxes 444 # if (RENORM_BY_FLUX) 437 445 sumAI1 /= PS_SQR(stamp->normI2); 438 446 sumBI1 /= PS_SQR(stamp->normI2); 439 447 sumAI2 /= PS_SQR(stamp->normI2); 440 448 sumBI2 /= PS_SQR(stamp->normI2); 449 # endif 441 450 442 451 // Spatial variation … … 788 797 stamp->normSquare2 = normSquare2; 789 798 790 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "normValue: %f %f %f (%f %f)\n", normI1, normI2, stamp->norm, normSquare1, normSquare2);799 // psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "normValue: %f %f %f (%f %f)\n", normI1, normI2, stamp->norm, normSquare1, normSquare2); 791 800 792 801 return true; … … 800 809 pmSubtractionKernels *kernels = job->args->data[1]; // Kernels 801 810 int index = PS_SCALAR_VALUE(job->args->data[2], S32); // Stamp index 802 pmSubtractionEquationCalculationMode mode = PS_SCALAR_VALUE(job->args->data[3], S32); // calculation model 803 804 return pmSubtractionCalculateEquationStamp(stamps, kernels, index, mode); 805 } 806 807 bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels, 808 int index, const pmSubtractionEquationCalculationMode mode) 811 812 return pmSubtractionCalculateEquationStamp(stamps, kernels, index); 813 } 814 815 bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels, int index) 809 816 { 810 817 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); … … 833 840 psAssert(stamp->status == PM_SUBTRACTION_STAMP_CALCULATE, "We only operate on stamps with this state."); 834 841 835 // Generate convolutions: these are generated once and saved 836 if (!pmSubtractionConvolveStamp(stamp, kernels, footprint)) { 837 psError(psErrorCodeLast(), false, "Unable to convolve stamp %d.", index); 838 return NULL; 839 } 840 841 #ifdef TESTING 842 for (int j = 0; j < numKernels; j++) { 843 if (stamp->convolutions1) { 844 psString convName = NULL; 845 psStringAppend(&convName, "conv1_%03d_%03d.fits", index, j); 846 psFits *fits = psFitsOpen(convName, "w"); 847 psFree(convName); 848 psKernel *conv = stamp->convolutions1->data[j]; 849 psFitsWriteImage(fits, NULL, conv->image, 0, NULL); 850 psFitsClose(fits); 851 } 852 853 if (stamp->convolutions2) { 854 psString convName = NULL; 855 psStringAppend(&convName, "conv2_%03d_%03d.fits", index, j); 856 psFits *fits = psFitsOpen(convName, "w"); 857 psFree(convName); 858 psKernel *conv = stamp->convolutions2->data[j]; 859 psFitsWriteImage(fits, NULL, conv->image, 0, NULL); 860 psFitsClose(fits); 861 } 862 } 863 #endif 864 865 // XXX visualize the set of convolved stamps 866 867 psImage *polyValues = p_pmSubtractionPolynomial(NULL, spatialOrder, 868 stamp->xNorm, stamp->yNorm); // Polynomial terms 869 870 bool new = stamp->vector ? false : true; // Is this a new run? 842 psImage *polyValues = p_pmSubtractionPolynomial(NULL, spatialOrder, stamp->xNorm, stamp->yNorm); // Polynomial terms 843 844 // Is this a new run? Have we allocated the correct sized vector/matrix? 845 bool new = stamp->vector ? false : true; 846 if (!new && (stamp->vector->n != numParams)) { 847 psFree (stamp->vector); 848 psFree (stamp->matrix); 849 new = true; 850 } 851 871 852 if (new) { 872 853 stamp->matrix = psImageAlloc(numParams, numParams, PS_TYPE_F64); … … 941 922 } 942 923 943 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels, 944 const pmSubtractionEquationCalculationMode mode) 924 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels) 945 925 { 946 926 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); … … 953 933 for (int i = 0; i < stamps->num; i++) { 954 934 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest 935 955 936 if (stamp->status != PM_SUBTRACTION_STAMP_CALCULATE) { 956 937 continue; … … 969 950 psArrayAdd(job->args, 1, (pmSubtractionKernels*)kernels); // Casting away const to put on array 970 951 PS_ARRAY_ADD_SCALAR(job->args, i, PS_TYPE_S32); 971 PS_ARRAY_ADD_SCALAR(job->args, mode, PS_TYPE_S32);972 952 if (!psThreadJobAddPending(job)) { 973 953 return false; 974 954 } 975 955 } else { 976 pmSubtractionCalculateEquationStamp(stamps, kernels, i , mode);956 pmSubtractionCalculateEquationStamp(stamps, kernels, i); 977 957 } 978 958 } … … 983 963 } 984 964 985 pmSubtractionVisualPlotLeastSquares(stamps);986 965 pmSubtractionVisualShowKernels((pmSubtractionKernels *)kernels); 987 966 pmSubtractionVisualShowBasis(stamps); 988 989 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Calculate equation: %f sec", 990 psTimerClear("pmSubtractionCalculateEquation")); 991 967 pmSubtractionVisualPlotLeastSquares(stamps); 968 969 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Calculate equation: %f sec", psTimerClear("pmSubtractionCalculateEquation")); 992 970 993 971 return true; … … 998 976 bool psFitsWriteImageSimple (char *filename, psImage *image, psMetadata *header); 999 977 1000 psImage *p_pmSubSolve_wUt (psVector *w, psImage *U); 1001 psImage *p_pmSubSolve_VwUt (psImage *V, psImage *wUt); 1002 1003 bool p_pmSubSolve_SetWeights (psVector *wApply, psVector *w, psVector *wMask); 1004 1005 bool p_pmSubSolve_UtB (psVector **UtB, psImage *U, psVector *B); 1006 bool p_pmSubSolve_wUtB (psVector **wUtB, psVector *w, psVector *UtB); 1007 bool p_pmSubSolve_VwUtB (psVector **VwUtB, psImage *V, psVector *wUtB); 1008 1009 bool p_pmSubSolve_Ax (psVector **B, psImage *A, psVector *x); 1010 bool p_pmSubSolve_VdV (double *value, psVector *x, psVector *y); 1011 bool p_pmSubSolve_y2 (double *y2, pmSubtractionKernels *kernels, const pmSubtractionStampList *stamps); 1012 1013 psImage *p_pmSubSolve_Xvar (psImage *V, psVector *w); 1014 1015 double p_pmSubSolve_ChiSquare (pmSubtractionKernels *kernels, const pmSubtractionStampList *stamps); 1016 1017 bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels, 1018 const pmSubtractionStampList *stamps, 1019 const pmSubtractionEquationCalculationMode mode) 978 bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels, const pmSubtractionStampList *stamps) 1020 979 { 1021 980 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, false); 1022 981 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); 982 983 psTimerStart("pmSubtractionSolveEquation"); 1023 984 1024 985 // Check inputs … … 1042 1003 } 1043 1004 1005 if (stamp->vector->n != numParams) { 1006 fprintf (stderr, "mismatch length\n"); 1007 } 1044 1008 PS_ASSERT_VECTOR_NON_NULL(stamp->vector, false); 1045 1009 PS_ASSERT_VECTOR_SIZE(stamp->vector, (long)numParams, false); … … 1080 1044 } 1081 1045 1046 pmSubtractionVisualPlotLeastSquaresResid(stamps, sumMatrix, numStamps); 1047 1082 1048 #if 0 1083 1049 psImage *save = psImageCopy(NULL, sumMatrix, PS_TYPE_F32); … … 1087 1053 #endif 1088 1054 1055 // XXX TEST : print the matrix & vector 1056 if (0) { 1057 for (int iy = 0; iy < sumMatrix->numRows; iy++) { 1058 for (int ix = 0; ix < sumMatrix->numCols; ix++) { 1059 fprintf (stderr, "%e ", sumMatrix->data.F64[iy][ix]); 1060 } 1061 fprintf (stderr, " : %e\n", sumVector->data.F64[iy]); 1062 } 1063 } 1064 1065 psImage *invMatrix = NULL; 1089 1066 psVector *solution = NULL; // Solution to equation! 1090 1067 solution = psVectorAlloc(numParams, PS_TYPE_F64); … … 1094 1071 // solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN); 1095 1072 // SINGLE solution 1096 if (1) { 1097 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN); 1098 } else { 1099 psVector *PERM = NULL; 1100 psImage *LU = psMatrixLUDecomposition(NULL, &PERM, sumMatrix); 1101 solution = psMatrixLUSolution(solution, LU, sumVector, PERM); 1102 psFree (LU); 1103 psFree (PERM); 1104 } 1073 # if (1) 1074 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, 1e-10); 1075 invMatrix = psMatrixInvert(NULL, sumMatrix, NULL); 1076 # endif 1077 # if (0) 1078 psMatrixLUSolve(sumMatrixLU, sumVector); 1079 solution = psMemIncrRefCounter(sumVector); 1080 invMatrix = psMemIncrRefCounter(sumMatrix); 1081 # endif 1082 # if (0) 1083 psMatrixGJSolve(sumMatrix, sumVector); 1084 invMatrix = psMemIncrRefCounter(sumMatrix); 1085 solution = psMemIncrRefCounter(sumVector); 1086 # endif 1105 1087 1106 1088 # if (0) 1107 1089 for (int i = 0; i < solution->n; i++) { 1108 psLogMsg("psModules.imcombine", PS_LOG_DETAIL, "Single solution %d: %lf \n", i, solution->data.F64[i]);1090 psLogMsg("psModules.imcombine", PS_LOG_DETAIL, "Single solution %d: %lf +/- %lf\n", i, solution->data.F64[i], sqrt(fabs(invMatrix->data.F64[i][i]))); 1109 1091 } 1110 1092 # endif 1111 1093 1112 if (!kernels->solution1) { 1113 kernels->solution1 = psVectorAlloc(sumVector->n + 2, PS_TYPE_F64); // 1 for norm, 1 for bg 1114 psVectorInit(kernels->solution1, 0.0); 1115 } 1094 // ensure we have a solution vector of the right size 1095 kernels->solution1 = psVectorRecycle(kernels->solution1, sumVector->n + 2, PS_TYPE_F64); // 1 for norm, 1 for bg 1096 kernels->solution1err = psVectorRecycle(kernels->solution1err, sumVector->n + 2, PS_TYPE_F64); // 1 for norm, 1 for bg 1097 psVectorInit(kernels->solution1, 0.0); 1098 psVectorInit(kernels->solution1err, 0.0); 1116 1099 1117 1100 int numKernels = kernels->num; 1118 1101 int spatialOrder = kernels->spatialOrder; // Order of spatial variation 1119 1102 int numPoly = PM_SUBTRACTION_POLYTERMS(spatialOrder); // Number of polynomial terms 1103 1120 1104 for (int i = 0; i < numKernels * numPoly; i++) { 1121 1105 kernels->solution1->data.F64[i] = solution->data.F64[i]; 1106 kernels->solution1err->data.F64[i] = sqrt(invMatrix->data.F64[i][i]); 1122 1107 } 1123 1108 … … 1131 1116 psFree(sumVector); 1132 1117 psFree(sumMatrix); 1118 psFree(invMatrix); 1133 1119 1134 1120 } else { … … 1160 1146 } 1161 1147 1148 pmSubtractionVisualPlotLeastSquaresResid(stamps, sumMatrix, numStamps); 1149 1162 1150 #if 0 1163 1151 psImage *save = psImageCopy(NULL, sumMatrix, PS_TYPE_F32); … … 1171 1159 } 1172 1160 1161 // XXX TEST : print the matrix & vector 1162 if (0) { 1163 for (int iy = 0; iy < sumMatrix->numRows; iy++) { 1164 for (int ix = 0; ix < sumMatrix->numCols; ix++) { 1165 fprintf (stderr, "%e ", sumMatrix->data.F64[iy][ix]); 1166 } 1167 fprintf (stderr, " : %e\n", sumVector->data.F64[iy]); 1168 } 1169 } 1170 1171 psImage *invMatrix = NULL; 1173 1172 psVector *solution = NULL; // Solution to equation! 1174 1173 solution = psVectorAlloc(numParams, PS_TYPE_F64); … … 1176 1175 1177 1176 // DUAL solution 1178 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN); 1177 # if (1) 1178 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, 1e-10); 1179 invMatrix = psMatrixInvert(NULL, sumMatrix, NULL); 1180 # endif 1181 # if (0) 1182 psMatrixLUSolve(sumMatrix, sumVector); 1183 solution = psMemIncrRefCounter(sumVector); 1184 invMatrix = psMemIncrRefCounter(sumMatrix); 1185 # endif 1179 1186 1180 1187 #if (0) 1181 1188 for (int i = 0; i < solution->n; i++) { 1182 fprintf(stderr, "Dual solution %d: %lf \n", i, solution->data.F64[i]);1189 fprintf(stderr, "Dual solution %d: %lf +/- %lf\n", i, solution->data.F64[i], sqrt(invMatrix->data.F64[i][i])); 1183 1190 } 1184 1191 #endif 1185 1192 1186 if (!kernels->solution1) { 1187 kernels->solution1 = psVectorAlloc(numSolution1 + 2, PS_TYPE_F64); 1188 psVectorInit (kernels->solution1, 0.0); 1189 } 1190 if (!kernels->solution2) { 1191 kernels->solution2 = psVectorAlloc(numSolution2, PS_TYPE_F64); 1192 psVectorInit (kernels->solution2, 0.0); 1193 } 1193 // XXX TEST: manually set the coeffs to a desired solution 1194 // solution->data.F64[0] = +1.826; 1195 // solution->data.F64[1] = -0.115; 1196 // solution->data.F64[2] = 0.0; 1197 // solution->data.F64[3] = 0.0; 1198 1199 // ensure we have solution vectors of the right size 1200 kernels->solution1 = psVectorRecycle(kernels->solution1, numSolution1 + 2, PS_TYPE_F64); // 1 for norm, 1 for bg 1201 kernels->solution1err = psVectorRecycle(kernels->solution1err, numSolution1 + 2, PS_TYPE_F64); // 1 for norm, 1 for bg 1202 kernels->solution2 = psVectorRecycle(kernels->solution2, numSolution2, PS_TYPE_F64); // 1 for norm, 1 for bg 1203 kernels->solution2err = psVectorRecycle(kernels->solution2err, numSolution2, PS_TYPE_F64); // 1 for norm, 1 for bg 1204 1205 psVectorInit(kernels->solution1, 0.0); 1206 psVectorInit(kernels->solution1err, 0.0); 1207 psVectorInit(kernels->solution2, 0.0); 1208 psVectorInit(kernels->solution2err, 0.0); 1194 1209 1195 1210 // for DUAL convolution analysis, we apply the normalization to I1 as follows: … … 1205 1220 kernels->solution1->data.F64[i] = solution->data.F64[i] * stamps->normValue; 1206 1221 kernels->solution2->data.F64[i] = solution->data.F64[i + numSolution1]; 1222 1223 kernels->solution1err->data.F64[i] = sqrt(invMatrix->data.F64[i][i]) * stamps->normValue; 1224 int i2 = i + numSolution1; 1225 kernels->solution2err->data.F64[i] = sqrt(invMatrix->data.F64[i2][i2]); 1207 1226 } 1208 1227 … … 1213 1232 kernels->solution1->data.F64[bgIndex] = 0.0; 1214 1233 1234 psFree(solution); 1235 psFree(sumVector); 1215 1236 psFree(sumMatrix); 1216 psFree(sumVector); 1217 psFree(solution); 1237 psFree(invMatrix); 1218 1238 } 1219 1239 … … 1224 1244 if (psTraceGetLevel("psModules.imcombine") >= 7) { 1225 1245 for (int i = 0; i < kernels->solution1->n; i++) { 1226 psTrace("psModules.imcombine", 7, "Solution 1 %d: %f \n", i, kernels->solution1->data.F64[i]);1246 psTrace("psModules.imcombine", 7, "Solution 1 %d: %f +/- %f\n", i, kernels->solution1->data.F64[i], kernels->solution1err->data.F64[i]); 1227 1247 } 1228 1248 if (kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1229 1249 for (int i = 0; i < kernels->solution2->n; i++) { 1230 psTrace("psModules.imcombine", 7, "Solution 2 %d: %f \n", i, kernels->solution2->data.F64[i]);1250 psTrace("psModules.imcombine", 7, "Solution 2 %d: %f +/- %f\n", i, kernels->solution2->data.F64[i], kernels->solution2err->data.F64[i]); 1231 1251 } 1232 1252 } 1233 1253 } 1254 1255 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Solve equation: %f sec", psTimerClear("pmSubtractionSolveEquation")); 1234 1256 1235 1257 // pmSubtractionVisualPlotLeastSquares((pmSubtractionStampList *) stamps); //casting away const … … 1283 1305 } 1284 1306 1285 psVector *pmSubtractionCalculateDeviations(pmSubtractionStampList *stamps, 1286 pmSubtractionKernels *kernels) 1307 // given the convolved image(s) and the residual image, calculate the second moment(s) and the chisq 1308 bool pmSubtractionChisqStats(psVector *fluxesVector, psVector *chisqDVector, psVector *chisqRVector, psVector *momentVector, psVector *stampMask, psKernel *convolved1, psKernel *convolved2, psKernel *difference, psKernel *residual, psKernel *weight, psKernel *window) { 1309 1310 # ifndef USE_WEIGHT 1311 psAssert(weight == NULL, "impossible!"); 1312 # endif 1313 # ifndef USE_WINDOW 1314 psAssert(window == NULL, "impossible!"); 1315 # endif 1316 1317 int npix = 0; 1318 float chisqR = 0; 1319 float chisqD = 0; 1320 1321 // get the chisq 1322 for (int y = residual->yMin; y <= residual->yMax; y++) { 1323 for (int x = residual->xMin; x <= residual->xMax; x++) { 1324 float valueR = PS_SQR(residual->kernel[y][x]); 1325 if (weight) { 1326 valueR *= weight->kernel[y][x]; 1327 } 1328 // XXX NOTE: do NOT apply the window to the chisq portions of the calculation (that would bias the chisq) 1329 chisqR += valueR; 1330 1331 float valueD = PS_SQR(difference->kernel[y][x]); 1332 if (weight) { 1333 valueD *= weight->kernel[y][x]; 1334 } 1335 chisqD += valueD; 1336 npix ++; 1337 } 1338 } 1339 psVectorAppend(chisqRVector, chisqR / npix); 1340 psVectorAppend(chisqDVector, chisqD / npix); 1341 1342 float value1 = 0; 1343 float value2 = 0; 1344 float flux2 = 0; 1345 float fluxX = 0; 1346 float fluxY = 0; 1347 float fluxX2 = 0; 1348 float fluxY2 = 0; 1349 1350 float fluxC1 = 0; 1351 float fluxC2 = 0; 1352 1353 float moment = 0; 1354 1355 // get the moments from convolved1 1356 if (convolved1) { 1357 for (int y = residual->yMin; y <= residual->yMax; y++) { 1358 for (int x = residual->xMin; x <= residual->xMax; x++) { 1359 value1 = convolved1->kernel[y][x]; 1360 value2 = PS_SQR(value1); 1361 1362 if (window) { 1363 value1 *= window->kernel[y][x]; 1364 value2 *= window->kernel[y][x]; 1365 } 1366 1367 fluxC1 += value1; 1368 flux2 += value2; 1369 fluxX += x * value2; 1370 fluxY += y * value2; 1371 // fluxX2 += PS_SQR(x) * value2; 1372 // fluxY2 += PS_SQR(y) * value2; 1373 fluxX2 += PS_SQR(x) * value1; 1374 fluxY2 += PS_SQR(y) * value1; 1375 } 1376 } 1377 // float Mx = fluxX / flux2; 1378 // float My = fluxY / flux2; 1379 // float Mxx = fluxX2 / flux2; 1380 // float Myy = fluxY2 / flux2; 1381 float Mxx = fluxX2 / fluxC1; 1382 float Myy = fluxY2 / fluxC1; 1383 1384 // fprintf (stderr, "conv1, flux2: %f, Mx: %f, My: %f, Mxx: %f, Myy: %f, chisq: %f, npix: %d\n", flux2, Mx, My, Mxx, Myy, chisq, npix); 1385 moment += Mxx + Myy; 1386 } 1387 1388 // get the moments from convolved1 1389 if (convolved2) { 1390 for (int y = residual->yMin; y <= residual->yMax; y++) { 1391 for (int x = residual->xMin; x <= residual->xMax; x++) { 1392 value1 = convolved2->kernel[y][x]; 1393 value2 = PS_SQR(value1); 1394 1395 // XXX NOTE: do NOT apply the weight to the moments calculation 1396 if (false && weight) { 1397 value2 *= weight->kernel[y][x]; 1398 } 1399 if (window) { 1400 value1 *= window->kernel[y][x]; 1401 value2 *= window->kernel[y][x]; 1402 } 1403 1404 fluxC2 += value1; 1405 flux2 += value2; 1406 fluxX += x * value2; 1407 fluxY += y * value2; 1408 // fluxX2 += PS_SQR(x) * value2; 1409 // fluxY2 += PS_SQR(y) * value2; 1410 fluxX2 += PS_SQR(x) * value1; 1411 fluxY2 += PS_SQR(y) * value1; 1412 } 1413 } 1414 // float Mx = fluxX / flux2; 1415 // float My = fluxY / flux2; 1416 // float Mxx = fluxX2 / flux2; 1417 // float Myy = fluxY2 / flux2; 1418 float Mxx = fluxX2 / fluxC2; 1419 float Myy = fluxY2 / fluxC2; 1420 1421 // fprintf (stderr, "conv2, flux2: %f, Mx: %f, My: %f, Mxx: %f, Myy: %f, chisq: %f, npix: %d\n", flux2, Mx, My, Mxx, Myy, chisq, npix); 1422 moment += Mxx + Myy; 1423 } 1424 1425 float flux = fluxC1 + fluxC2; 1426 1427 if (convolved1 && convolved2) { 1428 moment *= 0.5; 1429 flux *= 0.5; 1430 } 1431 psVectorAppend(momentVector, moment); 1432 psVectorAppend(fluxesVector, flux); 1433 1434 // check that the last appended values are ok: 1435 int Nelem = fluxesVector->n - 1; 1436 bool valid = true; 1437 valid &= isfinite(chisqRVector->data.F32[Nelem]); 1438 valid &= isfinite(fluxesVector->data.F32[Nelem]); 1439 valid &= isfinite(momentVector->data.F32[Nelem]); 1440 if (valid) { 1441 psVectorAppend(stampMask, 0); 1442 } else { 1443 psVectorAppend(stampMask, 0x02); 1444 } 1445 return true; 1446 } 1447 1448 bool pmSubtractionCalculateChisqAndMoments(pmSubtractionQuality **bestMatch, 1449 pmSubtractionStampList *stamps, 1450 pmSubtractionKernels *kernels) 1287 1451 { 1288 1452 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, NULL); 1289 1453 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, NULL); 1290 1454 PM_ASSERT_SUBTRACTION_KERNELS_SOLUTION(kernels, NULL); 1455 1456 psTimerStart("pmSubtractionCalculateChisqAndMoments"); 1457 1458 // XXX need to save these somewhere 1459 psVector *fluxes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1460 psVector *chisqD = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1461 psVector *chisqR = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1462 psVector *moments = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1463 psVector *stampMask = psVectorAllocEmpty(stamps->num, PS_TYPE_VECTOR_MASK); 1464 1465 int footprint = stamps->footprint; // Half-size of stamps 1466 int numKernels = kernels->num; // Number of kernels 1467 1468 psImage *polyValues = NULL; // Polynomial values 1469 1470 // storage for the image (convolved2 is not used in SINGLE mode) 1471 psKernel *residual = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image 1472 psKernel *difference = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image 1473 psKernel *convolved1 = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image 1474 psKernel *convolved2 = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image 1475 1476 int nGood = 0; 1477 for (int i = 0; i < stamps->num; i++) { 1478 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // The stamp of interest 1479 if (stamp->status != PM_SUBTRACTION_STAMP_USED) { 1480 // mark this stamp as unused (note that we have to append NANs to the other vectors to keep the lengths in sync) 1481 psVectorAppend(moments, NAN); 1482 psVectorAppend(fluxes, NAN); 1483 psVectorAppend(chisqD, NAN); 1484 psVectorAppend(chisqR, NAN); 1485 psVectorAppend(stampMask, 0x01); 1486 continue; 1487 } 1488 nGood ++; 1489 1490 // Calculate coefficients of the kernel basis functions 1491 polyValues = p_pmSubtractionPolynomial(polyValues, kernels->spatialOrder, stamp->xNorm, stamp->yNorm); 1492 double norm = p_pmSubtractionSolutionNorm(kernels); // Normalisation 1493 double background = p_pmSubtractionSolutionBackground(kernels, polyValues);// Difference in background 1494 1495 // Calculate residuals 1496 psImageInit(residual->image, 0.0); 1497 psImageInit(difference->image, 0.0); 1498 1499 psKernel *weight = NULL; 1500 psKernel *window = NULL; 1501 1502 #ifdef USE_WEIGHT 1503 weight = stamp->weight; 1504 #endif 1505 #ifdef USE_WINDOW 1506 window = stamps->window; 1507 #endif 1508 1509 if (kernels->mode != PM_SUBTRACTION_MODE_DUAL) { 1510 1511 // the single-direction psf match code attempts to find the kernel such that: 1512 // source * kernel = target. we need to assign 'source' and 'target' correctly 1513 // depending on which of image1 or image2 we asked to be convolved. 1514 1515 psKernel *target; // Target postage stamp (convolve source to match the target) 1516 psKernel *source; // Source postage stamp (convolve source to match the target) 1517 psArray *convolutions; // Convolution postage stamps for each kernel basis function 1518 1519 // init the accumulation image 1520 psImageInit(convolved1->image, 0.0); 1521 1522 switch (kernels->mode) { 1523 case PM_SUBTRACTION_MODE_1: 1524 target = stamp->image2; 1525 source = stamp->image1; 1526 convolutions = stamp->convolutions1; 1527 break; 1528 case PM_SUBTRACTION_MODE_2: 1529 target = stamp->image1; 1530 source = stamp->image2; 1531 convolutions = stamp->convolutions2; 1532 break; 1533 default: 1534 psAbort("Unsupported subtraction mode: %x", kernels->mode); 1535 } 1536 1537 // generate the convolved source image (sum over kernels) 1538 for (int j = 0; j < numKernels; j++) { 1539 psKernel *convolution = convolutions->data[j]; // Convolution 1540 double coefficient = p_pmSubtractionSolutionCoeff(kernels, polyValues, j, false); // Coefficient 1541 for (int y = - footprint; y <= footprint; y++) { 1542 for (int x = - footprint; x <= footprint; x++) { 1543 convolved1->kernel[y][x] += convolution->kernel[y][x] * coefficient; 1544 } 1545 } 1546 } 1547 1548 // Generate the difference, residual, and convolved source images. Note the we 1549 // accumulate the convolution of (A-B), so we need to replace it to generate the 1550 // images of the convolved source image. 1551 for (int y = - footprint; y <= footprint; y++) { 1552 for (int x = - footprint; x <= footprint; x++) { 1553 difference->kernel[y][x] = target->kernel[y][x] - source->kernel[y][x] * norm - background; 1554 residual->kernel[y][x] = difference->kernel[y][x] - convolved1->kernel[y][x]; 1555 convolved1->kernel[y][x] += source->kernel[y][x] * norm; 1556 } 1557 } 1558 1559 // XXX if we want to have a weight and window, we'll need to pass through to here 1560 pmSubtractionChisqStats(fluxes, chisqD, chisqR, moments, stampMask, convolved1, NULL, difference, residual, weight, window); 1561 1562 } else { 1563 1564 // Dual convolution 1565 psArray *convolutions1 = stamp->convolutions1; // Convolutions of the first image 1566 psArray *convolutions2 = stamp->convolutions2; // Convolutions of the second image 1567 psKernel *image1 = stamp->image1; // The first image 1568 psKernel *image2 = stamp->image2; // The second image 1569 1570 // init the accumulation images 1571 psImageInit(convolved1->image, 0.0); 1572 psImageInit(convolved2->image, 0.0); 1573 1574 for (int j = 0; j < numKernels; j++) { 1575 psKernel *conv1 = convolutions1->data[j]; // Convolution of first image 1576 psKernel *conv2 = convolutions2->data[j]; // Convolution of second image 1577 double coeff1 = p_pmSubtractionSolutionCoeff(kernels, polyValues, j, false); // Coefficient 1 1578 double coeff2 = p_pmSubtractionSolutionCoeff(kernels, polyValues, j, true); // Coefficient 2 1579 1580 for (int y = - footprint; y <= footprint; y++) { 1581 for (int x = - footprint; x <= footprint; x++) { 1582 // NOTE sign for coeff2 1583 convolved1->kernel[y][x] += +conv1->kernel[y][x] * coeff1; 1584 convolved2->kernel[y][x] += -conv2->kernel[y][x] * coeff2; 1585 } 1586 } 1587 } 1588 1589 // Generate the difference, residual, and convolved source images. Note the we 1590 // accumulate the convolutions of (A-B), so we need to replace (A or B) to generate 1591 // the images of the convolved source images. 1592 for (int y = - footprint; y <= footprint; y++) { 1593 for (int x = - footprint; x <= footprint; x++) { 1594 difference->kernel[y][x] = image2->kernel[y][x] - image1->kernel[y][x] * norm - background; 1595 residual->kernel[y][x] = difference->kernel[y][x] + convolved2->kernel[y][x] - convolved1->kernel[y][x]; 1596 convolved1->kernel[y][x] += image1->kernel[y][x] * norm; 1597 convolved2->kernel[y][x] += image2->kernel[y][x]; 1598 } 1599 } 1600 1601 if (0) { 1602 psFitsWriteImageSimple("conv1.fits", convolved1->image, NULL); 1603 psFitsWriteImageSimple("conv2.fits", convolved2->image, NULL); 1604 psFitsWriteImageSimple("resid.fits", residual->image, NULL); 1605 pmVisualAskUser(NULL); 1606 } 1607 1608 pmSubtractionChisqStats(fluxes, chisqD, chisqR, moments, stampMask, convolved1, convolved2, difference, residual, weight, window); 1609 } 1610 } 1611 1612 // find the mean chisq and mean moment 1613 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 1614 psVectorStats (stats, chisqD, NULL, stampMask, 0xff); 1615 float chisqDValue = stats->sampleMean; 1616 1617 psStatsInit(stats); 1618 psVectorStats (stats, chisqR, NULL, stampMask, 0xff); 1619 float chisqRValue = stats->sampleMean; 1620 1621 psStatsInit(stats); 1622 psVectorStats (stats, moments, NULL, stampMask, 0xff); 1623 float momentValue = stats->sampleMean; 1624 1625 double sumKernel1 = 0.0, sumKernel2 = 0.0; // Sum of the kernel 1626 1627 // calculate the variance contribution from this smoothing kernel 1628 psKernel *modelKernel = pmSubtractionKernel(kernels, 0.0, 0.0, false); 1629 for (int y = modelKernel->yMin; y <= modelKernel->yMax; y++) { 1630 for (int x = modelKernel->xMin; x <= modelKernel->xMax; x++) { 1631 if (!isfinite(modelKernel->kernel[y][x])) { 1632 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Non-finite covariance matrix element in kernel at %d,%d", x, y); 1633 return NULL; 1634 } 1635 sumKernel1 += PS_SQR(modelKernel->kernel[y][x]); 1636 } 1637 } 1638 psFree (modelKernel); 1639 1640 if (kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1641 psKernel *modelKernel = pmSubtractionKernel(kernels, 0.0, 0.0, true); 1642 for (int y = modelKernel->yMin; y <= modelKernel->yMax; y++) { 1643 for (int x = modelKernel->xMin; x <= modelKernel->xMax; x++) { 1644 if (!isfinite(modelKernel->kernel[y][x])) { 1645 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Non-finite covariance matrix element in kernel at %d,%d", x, y); 1646 return NULL; 1647 } 1648 sumKernel2 += PS_SQR(modelKernel->kernel[y][x]); 1649 } 1650 } 1651 psFree (modelKernel); 1652 } else { 1653 sumKernel2 = 1.0; 1654 } 1655 1656 // if we modify the chisq value by the (sumKernel1 + sumKernel2), we account for the 1657 // smoothing coming from larger kernels adding additional spatial fit terms should be 1658 // penalized by increasing the score somewhat. the 0.01 value is not well-chosen. 1659 float orderFactor = 0.01 * kernels->spatialOrder; 1660 float score = 2.0 * chisqRValue / (sumKernel1 + sumKernel2) + orderFactor; 1661 psLogMsg("psModules.imcombine", PS_LOG_INFO, "chisq: %6.3f, chisqD: %6.3f, moment: %6.3f, sumKernel_1: %6.3f, sumKernel_2, score: %6.3f: %6.3f\n", chisqRValue, chisqDValue, momentValue, sumKernel1, sumKernel2, score); 1662 1663 // save this result if it is the first or the best (skip if bestMatch is NULL) 1664 if (bestMatch) { 1665 pmSubtractionQuality *match = *bestMatch; 1666 bool keep = false; 1667 if (match == NULL) { 1668 *bestMatch = match = pmSubtractionQualityAlloc(); 1669 keep = true; 1670 } else { 1671 if (score < match->score) { 1672 psFree(match->fluxes); 1673 psFree(match->chisq); 1674 psFree(match->moments); 1675 psFree(match->stampMask); 1676 keep = true; 1677 } 1678 } 1679 if (keep) { 1680 psLogMsg("psModules.imcombine", PS_LOG_INFO, "keeping order: %d, mode: %d, score: %f\n", kernels->spatialOrder, kernels->mode, score); 1681 match->score = score; 1682 match->spatialOrder = kernels->spatialOrder; 1683 match->mode = kernels->mode; 1684 match->nGood = nGood; 1685 match->fluxes = psMemIncrRefCounter(fluxes); 1686 match->chisq = psMemIncrRefCounter(chisqR); 1687 match->moments = psMemIncrRefCounter(moments); 1688 match->stampMask = psMemIncrRefCounter(stampMask); 1689 } 1690 } 1691 1692 pmSubtractionVisualPlotChisqAndMoments(fluxes, chisqR, moments); 1693 1694 psFree(stats); 1695 psFree(chisqR); 1696 psFree(chisqD); 1697 psFree(fluxes); 1698 psFree(moments); 1699 psFree(stampMask); 1700 1701 psFree(residual); 1702 psFree(difference); 1703 psFree(convolved1); 1704 psFree(convolved2); 1705 psFree(polyValues); 1706 1707 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Calculate Chisq and Moments: %f sec", psTimerClear("pmSubtractionCalculateChisqAndMoments")); 1708 1709 return true; 1710 } 1711 1712 // XXX for now, let's not use this, and let's instead just use values from pmSubtractionCalculateChisqAndMoments 1713 psVector *pmSubtractionCalculateDeviations(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels) 1714 { 1715 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, NULL); 1716 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, NULL); 1717 PM_ASSERT_SUBTRACTION_KERNELS_SOLUTION(kernels, NULL); 1718 1719 psTimerStart("pmSubtractionCalculateDeviations"); 1291 1720 1292 1721 psVector *deviations = psVectorAlloc(stamps->num, PS_TYPE_F32); // Mean deviation for stamps … … 1298 1727 psImage *polyValues = NULL; // Polynomial values 1299 1728 psKernel *residual = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image 1300 1301 // set up holding images for the visualization1302 pmSubtractionVisualShowFitInit (stamps);1303 1729 1304 1730 psVector *fResSigma = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); … … 1401 1827 } 1402 1828 1403 // XXX visualize the target, source, convolution and residual1404 pmSubtractionVisualShowFitAddStamp (target, source, residual, background, norm, i);1405 1406 1829 for (int y = - footprint; y <= footprint; y++) { 1407 1830 for (int x = - footprint; x <= footprint; x++) { … … 1438 1861 } 1439 1862 1440 // XXX visualize the target, source, convolution and residual1441 pmSubtractionVisualShowFitAddStamp (image2, image1, residual, background, norm, i);1442 1443 1863 for (int y = - footprint; y <= footprint; y++) { 1444 1864 for (int x = - footprint; x <= footprint; x++) { … … 1455 1875 } 1456 1876 1877 double flux = 0.0; 1457 1878 double deviation = 0.0; // Sum of differences 1458 1879 for (int y = - footprint; y <= footprint; y++) { … … 1460 1881 double dev = PS_SQR(residual->kernel[y][x]) * weight->kernel[y][x]; 1461 1882 deviation += dev; 1462 #ifdef TESTING 1463 residual->kernel[y][x] = dev; 1464 #endif 1883 flux += stamp->image1->kernel[y][x] + stamp->image2->kernel[y][x]; 1465 1884 } 1466 1885 } 1467 1886 deviations->data.F32[i] = devNorm * deviation; 1468 psTrace("psModules.imcombine", 5, "Deviation for stamp %d (%d,%d):%f\n",1469 i, (int)(stamp->x - 0.5), (int)(stamp->y - 0.5), deviations->data.F32[i] );1887 psTrace("psModules.imcombine", 5, "Deviation and Flux for stamp %d (%d,%d): %f %f\n", 1888 i, (int)(stamp->x - 0.5), (int)(stamp->y - 0.5), deviations->data.F32[i], flux); 1470 1889 psStringAppend(&log, "Stamp %d (%d,%d): %f\n", 1471 1890 i, (int)(stamp->x - 0.5), (int)(stamp->y - 0.5), deviations->data.F32[i]); 1472 1891 if (!isfinite(deviations->data.F32[i])) { 1473 1892 stamp->status = PM_SUBTRACTION_STAMP_REJECTED; 1474 psTrace("psModules.imcombine", 5, 1475 "Rejecting stamp %d (%d,%d) because of non-finite deviation\n", 1476 i, (int)(stamp->x - 0.5), (int)(stamp->y - 0.5)); 1893 psTrace("psModules.imcombine", 5, "Rejecting stamp %d (%d,%d) because of non-finite deviation\n", i, (int)(stamp->x - 0.5), (int)(stamp->y - 0.5)); 1477 1894 continue; 1478 1895 } 1479 1480 #ifdef TESTING1481 {1482 psString filename = NULL;1483 psStringAppend(&filename, "resid_%03d.fits", i);1484 psFits *fits = psFitsOpen(filename, "w");1485 psFree(filename);1486 psFitsWriteImage(fits, NULL, residual->image, 0, NULL);1487 psFitsClose(fits);1488 }1489 if (stamp->image1) {1490 psString filename = NULL;1491 psStringAppend(&filename, "stamp_image1_%03d.fits", i);1492 psFits *fits = psFitsOpen(filename, "w");1493 psFree(filename);1494 psFitsWriteImage(fits, NULL, stamp->image1->image, 0, NULL);1495 psFitsClose(fits);1496 }1497 if (stamp->image2) {1498 psString filename = NULL;1499 psStringAppend(&filename, "stamp_image2_%03d.fits", i);1500 psFits *fits = psFitsOpen(filename, "w");1501 psFree(filename);1502 psFitsWriteImage(fits, NULL, stamp->image2->image, 0, NULL);1503 psFitsClose(fits);1504 }1505 if (stamp->weight) {1506 psString filename = NULL;1507 psStringAppend(&filename, "stamp_weight_%03d.fits", i);1508 psFits *fits = psFitsOpen(filename, "w");1509 psFree(filename);1510 psFitsWriteImage(fits, NULL, stamp->weight->image, 0, NULL);1511 psFitsClose(fits);1512 }1513 #endif1514 1515 1896 } 1516 1897 1517 1898 psFree(keepStamps); 1518 1899 1519 psLogMsg("psModules.imcombine", PS_LOG_ DETAIL, "%s", log);1900 psLogMsg("psModules.imcombine", PS_LOG_MINUTIA, "%s", log); 1520 1901 psFree(log); 1521 1902 … … 1527 1908 psLogMsg("psModules.imcombine", PS_LOG_INFO, "normalization: %f, background: %f", norm, background); 1528 1909 1529 pmSubtractionVisualShowFit(norm);1530 pmSubtractionVisualPlotFit(kernels);1531 1532 1910 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 1533 1911 psVectorStats (stats, fResSigma, NULL, NULL, 0); … … 1560 1938 psFree(polyValues); 1561 1939 1940 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Calculate Deviations: %f sec", psTimerClear("pmSubtractionCalculateDeviations")); 1941 1562 1942 return deviations; 1563 }1564 1565 // we are supplied U, not Ut; w represents a diagonal matrix (also, we apply 1/w instead of w)1566 psImage *p_pmSubSolve_wUt (psVector *w, psImage *U) {1567 1568 psAssert (w->n == U->numCols, "w and U dimensions do not match");1569 1570 // wUt has dimensions transposed relative to Ut.1571 psImage *wUt = psImageAlloc (U->numRows, U->numCols, PS_TYPE_F64);1572 psImageInit (wUt, 0.0);1573 1574 for (int i = 0; i < wUt->numCols; i++) {1575 for (int j = 0; j < wUt->numRows; j++) {1576 if (!isfinite(w->data.F64[j])) continue;1577 if (w->data.F64[j] == 0.0) continue;1578 wUt->data.F64[j][i] = U->data.F64[i][j] / w->data.F64[j];1579 }1580 }1581 return wUt;1582 }1583 1584 // XXX this is just standard matrix multiplication: use psMatrixMultiply?1585 psImage *p_pmSubSolve_VwUt (psImage *V, psImage *wUt) {1586 1587 psAssert (V->numCols == wUt->numRows, "matrix dimensions do not match");1588 1589 psImage *Ainv = psImageAlloc (wUt->numCols, V->numRows, PS_TYPE_F64);1590 1591 for (int i = 0; i < Ainv->numCols; i++) {1592 for (int j = 0; j < Ainv->numRows; j++) {1593 double sum = 0.0;1594 for (int k = 0; k < V->numCols; k++) {1595 sum += V->data.F64[j][k] * wUt->data.F64[k][i];1596 }1597 Ainv->data.F64[j][i] = sum;1598 }1599 }1600 return Ainv;1601 }1602 1603 // we are supplied U, not Ut1604 bool p_pmSubSolve_UtB (psVector **UtB, psImage *U, psVector *B) {1605 1606 psAssert (U->numRows == B->n, "U and B dimensions do not match");1607 1608 UtB[0] = psVectorRecycle (UtB[0], U->numCols, PS_TYPE_F64);1609 1610 for (int i = 0; i < U->numCols; i++) {1611 double sum = 0.0;1612 for (int j = 0; j < U->numRows; j++) {1613 sum += B->data.F64[j] * U->data.F64[j][i];1614 }1615 UtB[0]->data.F64[i] = sum;1616 }1617 return true;1618 }1619 1620 // w is diagonal1621 bool p_pmSubSolve_wUtB (psVector **wUtB, psVector *w, psVector *UtB) {1622 1623 psAssert (w->n == UtB->n, "w and UtB dimensions do not match");1624 1625 // wUt has dimensions transposed relative to Ut.1626 wUtB[0] = psVectorRecycle (wUtB[0], w->n, PS_TYPE_F64);1627 psVectorInit (wUtB[0], 0.0);1628 1629 for (int i = 0; i < w->n; i++) {1630 if (!isfinite(w->data.F64[i])) continue;1631 if (w->data.F64[i] == 0.0) continue;1632 wUtB[0]->data.F64[i] = UtB->data.F64[i] / w->data.F64[i];1633 }1634 return true;1635 }1636 1637 // this is basically matrix * vector1638 bool p_pmSubSolve_VwUtB (psVector **VwUtB, psImage *V, psVector *wUtB) {1639 1640 psAssert (V->numCols == wUtB->n, "V and wUtB dimensions do not match");1641 1642 VwUtB[0] = psVectorRecycle (*VwUtB, V->numRows, PS_TYPE_F64);1643 1644 for (int j = 0; j < V->numRows; j++) {1645 double sum = 0.0;1646 for (int i = 0; i < V->numCols; i++) {1647 sum += V->data.F64[j][i] * wUtB->data.F64[i];1648 }1649 VwUtB[0]->data.F64[j] = sum;1650 }1651 return true;1652 }1653 1654 // this is basically matrix * vector1655 bool p_pmSubSolve_Ax (psVector **B, psImage *A, psVector *x) {1656 1657 psAssert (A->numCols == x->n, "A and x dimensions do not match");1658 1659 B[0] = psVectorRecycle (*B, A->numRows, PS_TYPE_F64);1660 1661 for (int j = 0; j < A->numRows; j++) {1662 double sum = 0.0;1663 for (int i = 0; i < A->numCols; i++) {1664 sum += A->data.F64[j][i] * x->data.F64[i];1665 }1666 B[0]->data.F64[j] = sum;1667 }1668 return true;1669 }1670 1671 // this is basically Vector * vector1672 bool p_pmSubSolve_VdV (double *value, psVector *x, psVector *y) {1673 1674 psAssert (x->n == y->n, "x and y dimensions do not match");1675 1676 double sum = 0.0;1677 for (int i = 0; i < x->n; i++) {1678 sum += x->data.F64[i] * y->data.F64[i];1679 }1680 *value = sum;1681 return true;1682 }1683 1684 bool p_pmSubSolve_y2 (double *y2, pmSubtractionKernels *kernels, const pmSubtractionStampList *stamps) {1685 1686 int footprint = stamps->footprint; // Half-size of stamps1687 1688 double sum = 0.0;1689 for (int i = 0; i < stamps->num; i++) {1690 1691 pmSubtractionStamp *stamp = stamps->stamps->data[i];1692 if (stamp->status != PM_SUBTRACTION_STAMP_USED) continue;1693 1694 psKernel *weight = NULL;1695 psKernel *window = NULL;1696 psKernel *input = NULL;1697 1698 #ifdef USE_WEIGHT1699 weight = stamp->weight;1700 #endif1701 #ifdef USE_WINDOW1702 window = stamps->window;1703 #endif1704 1705 switch (kernels->mode) {1706 // MODE_1 : convolve image 1 to match image 2 (and vice versa)1707 case PM_SUBTRACTION_MODE_1:1708 input = stamp->image2;1709 break;1710 case PM_SUBTRACTION_MODE_2:1711 input = stamp->image1;1712 break;1713 default:1714 psAbort ("programming error");1715 }1716 1717 for (int y = - footprint; y <= footprint; y++) {1718 for (int x = - footprint; x <= footprint; x++) {1719 double in = input->kernel[y][x];1720 double value = in*in;1721 if (weight) {1722 float wtVal = weight->kernel[y][x];1723 value *= wtVal;1724 }1725 if (window) {1726 float winVal = window->kernel[y][x];1727 value *= winVal;1728 }1729 sum += value;1730 }1731 }1732 }1733 *y2 = sum;1734 return true;1735 }1736 1737 double p_pmSubSolve_ChiSquare (pmSubtractionKernels *kernels, const pmSubtractionStampList *stamps) {1738 1739 int footprint = stamps->footprint; // Half-size of stamps1740 int numKernels = kernels->num; // Number of kernels1741 1742 double sum = 0.0;1743 1744 psKernel *residual = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image1745 psImageInit(residual->image, 0.0);1746 1747 psImage *polyValues = NULL; // Polynomial values1748 1749 for (int i = 0; i < stamps->num; i++) {1750 1751 pmSubtractionStamp *stamp = stamps->stamps->data[i];1752 if (stamp->status != PM_SUBTRACTION_STAMP_USED) continue;1753 1754 psKernel *weight = NULL;1755 psKernel *window = NULL;1756 psKernel *target = NULL;1757 psKernel *source = NULL;1758 1759 psArray *convolutions = NULL;1760 1761 #ifdef USE_WEIGHT1762 weight = stamp->weight;1763 #endif1764 #ifdef USE_WINDOW1765 window = stamps->window;1766 #endif1767 1768 switch (kernels->mode) {1769 // MODE_1 : convolve image 1 to match image 2 (and vice versa)1770 case PM_SUBTRACTION_MODE_1:1771 target = stamp->image2;1772 source = stamp->image1;1773 convolutions = stamp->convolutions1;1774 break;1775 case PM_SUBTRACTION_MODE_2:1776 target = stamp->image1;1777 source = stamp->image2;1778 convolutions = stamp->convolutions2;1779 break;1780 default:1781 psAbort ("programming error");1782 }1783 1784 // Calculate coefficients of the kernel basis functions1785 polyValues = p_pmSubtractionPolynomial(polyValues, kernels->spatialOrder, stamp->xNorm, stamp->yNorm);1786 double norm = p_pmSubtractionSolutionNorm(kernels); // Normalisation1787 double background = p_pmSubtractionSolutionBackground(kernels, polyValues);// Difference in background1788 1789 psImageInit(residual->image, 0.0);1790 for (int j = 0; j < numKernels; j++) {1791 psKernel *convolution = convolutions->data[j]; // Convolution1792 double coefficient = p_pmSubtractionSolutionCoeff(kernels, polyValues, j, false); // Coefficient1793 for (int y = - footprint; y <= footprint; y++) {1794 for (int x = - footprint; x <= footprint; x++) {1795 residual->kernel[y][x] -= convolution->kernel[y][x] * coefficient;1796 }1797 }1798 }1799 1800 for (int y = - footprint; y <= footprint; y++) {1801 for (int x = - footprint; x <= footprint; x++) {1802 double resid = target->kernel[y][x] - background - source->kernel[y][x] * norm + residual->kernel[y][x];1803 double value = PS_SQR(resid);1804 if (weight) {1805 float wtVal = weight->kernel[y][x];1806 value *= wtVal;1807 }1808 if (window) {1809 float winVal = window->kernel[y][x];1810 value *= winVal;1811 }1812 sum += value;1813 }1814 }1815 }1816 psFree (polyValues);1817 psFree (residual);1818 1819 return sum;1820 }1821 1822 bool p_pmSubSolve_SetWeights (psVector *wApply, psVector *w, psVector *wMask) {1823 1824 for (int i = 0; i < w->n; i++) {1825 wApply->data.F64[i] = wMask->data.U8[i] ? 0.0 : w->data.F64[i];1826 }1827 return true;1828 }1829 1830 // we are supplied V and w; w represents a diagonal matrix (also, we apply 1/w instead of w)1831 psImage *p_pmSubSolve_Xvar (psImage *V, psVector *w) {1832 1833 psAssert (w->n == V->numCols, "w and U dimensions do not match");1834 1835 psImage *Vn = psImageAlloc (V->numCols, V->numRows, PS_TYPE_F64);1836 psImageInit (Vn, 0.0);1837 1838 // generate Vn = V * w^{-1}1839 for (int j = 0; j < Vn->numRows; j++) {1840 for (int i = 0; i < Vn->numCols; i++) {1841 if (!isfinite(w->data.F64[i])) continue;1842 if (w->data.F64[i] == 0.0) continue;1843 Vn->data.F64[j][i] = V->data.F64[j][i] / w->data.F64[i];1844 }1845 }1846 1847 psImage *Xvar = psImageAlloc (V->numCols, V->numRows, PS_TYPE_F64);1848 psImageInit (Xvar, 0.0);1849 1850 // generate Xvar = Vn * Vn^T1851 for (int j = 0; j < Vn->numRows; j++) {1852 for (int i = 0; i < Vn->numCols; i++) {1853 double sum = 0.0;1854 for (int k = 0; k < Vn->numCols; k++) {1855 sum += Vn->data.F64[k][i]*Vn->data.F64[k][j];1856 }1857 Xvar->data.F64[j][i] = sum;1858 }1859 }1860 return Xvar;1861 1943 } 1862 1944 … … 1864 1946 // of the elements of an image A(x,y) = A->data.F64[y][x] = A_x,y, a matrix 1865 1947 // multiplication is: A_k,j * B_i,k = C_i,j 1866 1867 1948 1868 1949 bool psFitsWriteImageSimple (char *filename, psImage *image, psMetadata *header) { -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionEquation.h
r29543 r30631 4 4 #include "pmSubtractionStamps.h" 5 5 #include "pmSubtractionKernels.h" 6 7 typedef enum { 8 PM_SUBTRACTION_EQUATION_NONE = 0x00, 9 PM_SUBTRACTION_EQUATION_NORM = 0x01, 10 PM_SUBTRACTION_EQUATION_BG = 0x02, 11 PM_SUBTRACTION_EQUATION_KERNELS = 0x04, 12 PM_SUBTRACTION_EQUATION_ALL = 0x07, // value should be NORM | BG | KERNELS 13 } pmSubtractionEquationCalculationMode; 6 #include "pmSubtraction.h" 14 7 15 8 /// Execute a thread job to calculate the least-squares equation for a stamp … … 20 13 bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, ///< Stamps 21 14 pmSubtractionKernels *kernels, ///< Kernel parameters 22 int index, ///< Index of stamp 23 const pmSubtractionEquationCalculationMode mode 15 int index ///< Index of stamp 24 16 ); 25 17 26 18 /// Calculate the least-squares equation to match the image quality 27 19 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, ///< Stamps 28 pmSubtractionKernels *kernels, ///< Kernel parameters 29 const pmSubtractionEquationCalculationMode mode 20 pmSubtractionKernels *kernels ///< Kernel parameters 30 21 ); 31 22 32 23 /// Solve the least-squares equation to match the image quality 33 24 bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels, ///< Kernel parameters 34 const pmSubtractionStampList *stamps, ///< Stamps 35 const pmSubtractionEquationCalculationMode mode 25 const pmSubtractionStampList *stamps ///< Stamps 36 26 ); 37 27 … … 92 82 bool pmSubtractionCalculateMomentsKernel(double *Mxx, double *Myy, psKernel *image, int footprint, int window); 93 83 84 bool pmSubtractionChisqStats(psVector *fluxesVector, psVector *chisqDVector, psVector *chisqRVector, psVector *momentVector, psVector *stampMask, psKernel *convolved1, psKernel *convolved2, psKernel *difference, psKernel *residual, psKernel *weight, psKernel *window); 85 86 bool pmSubtractionCalculateChisqAndMoments(pmSubtractionQuality **bestMatch, pmSubtractionStampList *stamps, pmSubtractionKernels *kernels); 94 87 #endif -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionEquation.v0.c
r29543 r30631 9 9 #include "pmErrorCodes.h" 10 10 #include "pmSubtraction.h" 11 #include "pmSubtractionTypes.h" 11 12 #include "pmSubtractionKernels.h" 12 13 #include "pmSubtractionStamps.h" -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionHermitian.c
r26893 r30631 8 8 #include <pslib.h> 9 9 10 #include "pmSubtractionTypes.h" 10 11 #include "pmSubtractionHermitian.h" 11 12 -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionIO.c
r27321 r30631 12 12 #include "pmConceptsRead.h" 13 13 14 #include "pmSubtractionTypes.h" 14 15 #include "pmSubtraction.h" 15 16 #include "pmSubtractionKernels.h" -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionKernels.c
r29597 r30631 8 8 #include <pslib.h> 9 9 10 #include "pmFPA.h" 11 #include "pmSubtractionTypes.h" 10 12 #include "pmSubtraction.h" 11 13 #include "pmSubtractionKernels.h" … … 20 22 { 21 23 psFree(kernels->description); 24 psFree(kernels->fwhms); 25 psFree(kernels->orders); 22 26 psFree(kernels->u); 23 27 psFree(kernels->v); … … 30 34 psFree(kernels->solution1); 31 35 psFree(kernels->solution2); 36 psFree(kernels->solution1err); 37 psFree(kernels->solution2err); 32 38 psFree(kernels->sampleStamps); 33 39 } … … 419 425 420 426 int num = 0; // Number of basis functions 421 psString params = NULL; // List of parameters422 427 for (int i = 0; i < numGaussians; i++) { 423 428 int gaussOrder = orders->data.S32[i]; // Polynomial order to apply to Gaussian 424 psStringAppend(¶ms, "(%.1f,%d)", fwhms->data.F32[i], orders->data.S32[i]);425 429 num += (gaussOrder + 1) * (gaussOrder + 2) / 2; 426 430 } 427 431 428 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS, size, 429 spatialOrder, penalty, bounds, mode); // Kernels 430 psStringAppend(&kernels->description, "ISIS(%d,%s,%d,%.2e)", size, params, spatialOrder, penalty); 431 432 psLogMsg("psModules.imcombine", PS_LOG_INFO, "ISIS kernel: %s,%d --> %d elements", 433 params, spatialOrder, num); 434 psFree(params); 432 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS, size, fwhms, orders, spatialOrder, penalty, bounds, mode); // Kernels 433 pmSubtractionKernelsMakeDescription(kernels); 434 psLogMsg("psModules.imcombine", PS_LOG_INFO, "kernel: %s --> %d elements", kernels->description, num); 435 435 436 436 # if (!CENTRAL_DELTA && !ZERO_KERNEL_ZERO_FLUX) … … 503 503 504 504 int num = 0; // Number of basis functions 505 psString params = NULL; // List of parameters506 505 for (int i = 0; i < numGaussians; i++) { 507 506 int gaussOrder = orders->data.S32[i]; // Polynomial order to apply to Gaussian 508 psStringAppend(¶ms, "(%.1f,%d)", fwhms->data.F32[i], orders->data.S32[i]);509 507 num += (gaussOrder + 1) * (gaussOrder + 2) / 2; 510 508 num += (11 - gaussOrder - 1); // include all higher order radial terms 511 509 } 512 510 513 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS_RADIAL, size, 514 spatialOrder, penalty, bounds, mode); // Kernels 515 psStringAppend(&kernels->description, "ISIS_RADIAL(%d,%s,%d,%.2e)", size, params, spatialOrder, penalty); 516 517 psLogMsg("psModules.imcombine", PS_LOG_INFO, "ISIS_RADIAL kernel: %s,%d --> %d elements", params, spatialOrder, num); 518 psFree(params); 511 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS_RADIAL, size, fwhms, orders, spatialOrder, penalty, bounds, mode); // Kernels 512 pmSubtractionKernelsMakeDescription(kernels); 513 psLogMsg("psModules.imcombine", PS_LOG_INFO, "kernel: %s --> %d elements", kernels->description, num); 519 514 520 515 // Set the kernel parameters … … 569 564 570 565 int num = 0; // Number of basis functions 571 psString params = NULL; // List of parameters572 566 for (int i = 0; i < numGaussians; i++) { 573 567 int gaussOrder = orders->data.S32[i]; // Polynomial order to apply to Gaussian 574 psStringAppend(¶ms, "(%.1f,%d)", fwhms->data.F32[i], orders->data.S32[i]);575 568 num += (gaussOrder + 1) * (gaussOrder + 2) / 2; 576 569 } 577 570 578 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_HERM, size, 579 spatialOrder, penalty, bounds, mode); // Kernels 580 psStringAppend(&kernels->description, "HERM(%d,%s,%d,%.2e)", size, params, spatialOrder, penalty); 581 582 psLogMsg("psModules.imcombine", PS_LOG_INFO, "HERM kernel: %s,%d --> %d elements", 583 params, spatialOrder, num); 584 psFree(params); 571 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_HERM, size, fwhms, orders, spatialOrder, penalty, bounds, mode); // Kernels 572 pmSubtractionKernelsMakeDescription(kernels); 573 psLogMsg("psModules.imcombine", PS_LOG_INFO, "kernel: %s --> %d elements", kernels->description, num); 585 574 586 575 // Set the kernel parameters … … 627 616 628 617 int num = 0; // Number of basis functions 629 psString params = NULL; // List of parameters630 618 for (int i = 0; i < numGaussians; i++) { 631 619 int gaussOrder = orders->data.S32[i]; // Polynomial order to apply to Gaussian 632 psStringAppend(¶ms, "(%.1f,%d)", fwhms->data.F32[i], orders->data.S32[i]);633 620 num += PS_SQR(gaussOrder + 1); 634 621 } 635 622 636 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_DECONV_HERM, size, 637 spatialOrder, penalty, bounds, mode); // Kernels 638 psStringAppend(&kernels->description, "DECONV_HERM(%d,%s,%d,%.2e)", size, params, spatialOrder, penalty); 639 640 psLogMsg("psModules.imcombine", PS_LOG_INFO, "DECONVOLVED HERM kernel: %s,%d --> %d elements", params, spatialOrder, num); 641 psFree(params); 623 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_DECONV_HERM, size, fwhms, orders, spatialOrder, penalty, bounds, mode); // Kernels 624 pmSubtractionKernelsMakeDescription(kernels); 625 psLogMsg("psModules.imcombine", PS_LOG_INFO, "kernel: %s --> %d elements", kernels->description, num); 642 626 643 627 // XXXXX hard-wired reference sigma for now of 1.7 pix (== 4.0 pix fwhm == 1.0 arcsec in simtest) … … 713 697 714 698 pmSubtractionKernels *pmSubtractionKernelsAlloc(int numBasisFunctions, pmSubtractionKernelsType type, 715 int size, int spatialOrder, float penalty, psRegion bounds,699 int size, psVector *fwhms, psVector *orders, int spatialOrder, float penalty, psRegion bounds, 716 700 pmSubtractionMode mode) 717 701 { … … 722 706 kernels->description = NULL; 723 707 kernels->num = numBasisFunctions; 708 kernels->fwhms = psMemIncrRefCounter(fwhms); 709 kernels->orders = psMemIncrRefCounter(orders); 724 710 kernels->u = psVectorAlloc(numBasisFunctions, PS_TYPE_S32); 725 711 kernels->v = psVectorAlloc(numBasisFunctions, PS_TYPE_S32); … … 740 726 kernels->size = size; 741 727 kernels->inner = 0; 728 kernels->binning = 0; 729 kernels->ringsOrder = 0; 742 730 kernels->spatialOrder = spatialOrder; 743 731 kernels->bgOrder = 0; … … 745 733 kernels->solution1 = NULL; 746 734 kernels->solution2 = NULL; 735 kernels->solution1err = NULL; 736 kernels->solution2err = NULL; 747 737 kernels->mean = NAN; 748 738 kernels->rms = NAN; … … 823 813 int num = PS_SQR(2 * size + 1) - 1; // Number of basis functions 824 814 825 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(0, PM_SUBTRACTION_KERNEL_POIS, size, 826 spatialOrder, penalty, bounds, mode); // Kernels 827 psStringAppend(&kernels->description, "POIS(%d,%d,%.2e)", size, spatialOrder, penalty); 828 psLogMsg("psModules.imcombine", PS_LOG_INFO, "POIS kernel: %d,%d --> %d elements", 829 size, spatialOrder, num); 815 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(0, PM_SUBTRACTION_KERNEL_POIS, size, NULL, NULL, spatialOrder, penalty, bounds, mode); // Kernels 816 pmSubtractionKernelsMakeDescription(kernels); 817 psLogMsg("psModules.imcombine", PS_LOG_INFO, "kernel: %s --> %d elements", kernels->description, num); 830 818 831 819 if (!p_pmSubtractionKernelsAddGrid(kernels, 0, size)) { … … 871 859 psTrace("psModules.imcombine", 3, "Number of basis functions: %d\n", num); 872 860 873 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_SPAM, size, 874 spatialOrder, penalty, bounds, mode); // Kernels 861 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_SPAM, size, NULL, NULL, spatialOrder, penalty, bounds, mode); // Kernels 875 862 kernels->inner = inner; 876 psStringAppend(&kernels->description, "SPAM(%d,%d,%d,%d,%.2e)", size, inner, binning, spatialOrder, 877 penalty); 878 879 psLogMsg("psModules.imcombine", PS_LOG_INFO, "SPAM kernel: %d,%d,%d,%d --> %d elements", 880 size, inner, binning, spatialOrder, num); 863 kernels->binning = binning; 864 pmSubtractionKernelsMakeDescription(kernels); 865 psLogMsg("psModules.imcombine", PS_LOG_INFO, "kernel: %s --> %d elements", kernels->description, num); 881 866 882 867 kernels->uStop = psVectorAlloc(num, PS_TYPE_S32); … … 970 955 psTrace("psModules.imcombine", 3, "Number of basis functions: %d\n", num); 971 956 972 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_FRIES, size, 973 spatialOrder, penalty, bounds, mode); // Kernels 957 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_FRIES, size, NULL, NULL, spatialOrder, penalty, bounds, mode); // Kernels 974 958 kernels->inner = inner; 975 psStringAppend(&kernels->description, "FRIES(%d,%d,%d,%.2e)", size, inner, spatialOrder, penalty); 976 977 psLogMsg("psModules.imcombine", PS_LOG_INFO, "FRIES kernel: %d,%d,%d --> %d elements", 978 size, inner, spatialOrder, num); 959 pmSubtractionKernelsMakeDescription(kernels); 960 psLogMsg("psModules.imcombine", PS_LOG_INFO, "kernel: %s --> %d elements", kernels->description, num); 979 961 980 962 kernels->uStop = psVectorAlloc(num, PS_TYPE_S32); … … 1053 1035 PS_ASSERT_INT_LESS_THAN(inner, size, NULL); 1054 1036 1055 pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder, fwhms, orders, 1056 penalty, bounds, mode); // Kernels 1037 pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder, fwhms, orders, penalty, bounds, mode); // Kernels 1057 1038 kernels->type = PM_SUBTRACTION_KERNEL_GUNK; 1058 psStringPrepend(&kernels->description, "GUNK="); 1059 psStringAppend(&kernels->description, "+POIS(%d,%d)", inner, spatialOrder); 1039 kernels->inner = inner; 1040 pmSubtractionKernelsMakeDescription(kernels); 1041 psLogMsg("psModules.imcombine", PS_LOG_INFO, "kernel: %s --> %d elements", kernels->description, (int) kernels->num); 1060 1042 1061 1043 int numISIS = kernels->num; // Number of ISIS kernels … … 1100 1082 int num = numRings * numPoly; // Total number of basis functions 1101 1083 1102 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_RINGS, size, 1103 spatialOrder, penalty, bounds, mode); // Kernels 1084 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_RINGS, size, NULL, NULL, spatialOrder, penalty, bounds, mode); // Kernels 1104 1085 kernels->inner = inner; 1105 psStringAppend(&kernels->description, "RINGS(%d,%d,%d,%d,%.2e)", size, inner, ringsOrder, spatialOrder, 1106 penalty); 1107 1108 psLogMsg("psModules.imcombine", PS_LOG_INFO, "RINGS kernel: %d,%d,%d,%d --> %d elements", 1109 size, inner, ringsOrder, spatialOrder, num); 1086 kernels->ringsOrder = ringsOrder; 1087 pmSubtractionKernelsMakeDescription(kernels); 1088 psLogMsg("psModules.imcombine", PS_LOG_INFO, "kernel: %s --> %d elements", kernels->description, num); 1110 1089 1111 1090 // Set the Gaussian kernel parameters … … 1405 1384 } 1406 1385 1386 bool pmSubtractionKernelsMakeDescription(pmSubtractionKernels *kernels) { 1387 1388 // free if it exists 1389 psFree (kernels->description); 1390 1391 // generate the description parameter string 1392 psString params = NULL; 1393 if (kernels->fwhms) { 1394 for (int i = 0; i < kernels->fwhms->n; i++) { 1395 psStringAppend(¶ms, "(%.1f,%d)", kernels->fwhms->data.F32[i], kernels->orders->data.S32[i]); 1396 } 1397 } 1398 1399 switch (kernels->type) { 1400 case PM_SUBTRACTION_KERNEL_ISIS: 1401 psStringAppend (&kernels->description, "ISIS(%d,%s,%d,%.2e)", kernels->size, params, kernels->spatialOrder, kernels->penalty); 1402 break; 1403 1404 case PM_SUBTRACTION_KERNEL_ISIS_RADIAL: 1405 psStringAppend(&kernels->description, "ISIS_RADIAL(%d,%s,%d,%.2e)", kernels->size, params, kernels->spatialOrder, kernels->penalty); 1406 break; 1407 1408 case PM_SUBTRACTION_KERNEL_HERM: 1409 psStringAppend(&kernels->description, "HERM(%d,%s,%d,%.2e)", kernels->size, params, kernels->spatialOrder, kernels->penalty); 1410 break; 1411 1412 case PM_SUBTRACTION_KERNEL_DECONV_HERM: 1413 psStringAppend(&kernels->description, "DECONV_HERM(%d,%s,%d,%.2e)", kernels->size, params, kernels->spatialOrder, kernels->penalty); 1414 break; 1415 1416 case PM_SUBTRACTION_KERNEL_POIS: 1417 psStringAppend(&kernels->description, "POIS(%d,%d,%.2e)", kernels->size, kernels->spatialOrder, kernels->penalty); 1418 break; 1419 1420 case PM_SUBTRACTION_KERNEL_SPAM: 1421 psStringAppend(&kernels->description, "SPAM(%d,%d,%d,%d,%.2e)", kernels->size, kernels->inner, kernels->binning, kernels->spatialOrder, kernels->penalty); 1422 break; 1423 1424 case PM_SUBTRACTION_KERNEL_FRIES: 1425 psStringAppend(&kernels->description, "FRIES(%d,%d,%d,%.2e)", kernels->size, kernels->inner, kernels->spatialOrder, kernels->penalty); 1426 break; 1427 1428 // Grid United with Normal Kernel [description: GUNK=ISIS(...)+POIS(...)] 1429 case PM_SUBTRACTION_KERNEL_GUNK: 1430 psStringAppend(&kernels->description, "GUNK=ISIS(%d,%s,%d,%.2e)", kernels->size, params, kernels->spatialOrder, kernels->penalty); 1431 psStringAppend(&kernels->description, "+POIS(%d,%d)", kernels->inner, kernels->spatialOrder); 1432 break; 1433 1434 case PM_SUBTRACTION_KERNEL_RINGS: 1435 psStringAppend(&kernels->description, "RINGS(%d,%d,%d,%d,%.2e)", kernels->size, kernels->inner, kernels->ringsOrder, kernels->spatialOrder, kernels->penalty); 1436 break; 1437 1438 default: 1439 psAbort("unknown kernel"); 1440 } 1441 psFree (params); 1442 return true; 1443 } 1444 1407 1445 pmSubtractionKernels *pmSubtractionKernelsCopy(const pmSubtractionKernels *in) 1408 1446 { … … 1435 1473 out->solution1 = in->solution1 ? psVectorCopy(NULL, in->solution1, PS_TYPE_F64) : NULL; 1436 1474 out->solution2 = in->solution2 ? psVectorCopy(NULL, in->solution2, PS_TYPE_F64) : NULL; 1475 out->solution1err = in->solution1err ? psVectorCopy(NULL, in->solution1err, PS_TYPE_F64) : NULL; 1476 out->solution2err = in->solution2err ? psVectorCopy(NULL, in->solution2err, PS_TYPE_F64) : NULL; 1437 1477 out->sampleStamps = psMemIncrRefCounter(in->sampleStamps); 1438 1478 -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionKernels.h
r29601 r30631 2 2 #define PM_SUBTRACTION_KERNELS_H 3 3 4 #include <string.h> 5 #include <pslib.h> 6 7 /// Type of subtraction kernel 8 typedef enum { 9 PM_SUBTRACTION_KERNEL_NONE, ///< Nothing --- an error 10 PM_SUBTRACTION_KERNEL_POIS, ///< Pan-STARRS Optimal Image Subtraction --- delta functions 11 PM_SUBTRACTION_KERNEL_ISIS, ///< Traditional kernel --- gaussians modified by polynomials 12 PM_SUBTRACTION_KERNEL_ISIS_RADIAL, ///< ISIS + higher-order radial Hermitians 13 PM_SUBTRACTION_KERNEL_HERM, ///< Hermitian polynomial kernels 14 PM_SUBTRACTION_KERNEL_DECONV_HERM, ///< Deconvolved Hermitian polynomial kernels 15 PM_SUBTRACTION_KERNEL_SPAM, ///< Summed Pixels for Advanced Matching --- summed delta functions 16 PM_SUBTRACTION_KERNEL_FRIES, ///< Fibonacci Radius Increases Excellence of Subtraction 17 PM_SUBTRACTION_KERNEL_GUNK, ///< Grid United with Normal Kernel --- POIS and ISIS hybrid 18 PM_SUBTRACTION_KERNEL_RINGS, ///< Rings Instead of the Normal Gaussian Subtraction 19 } pmSubtractionKernelsType; 20 21 /// Modes --- specifies which image to convolve 22 typedef enum { 23 PM_SUBTRACTION_MODE_ERR, // Error in the mode 24 PM_SUBTRACTION_MODE_1, // Convolve image 1 25 PM_SUBTRACTION_MODE_2, // Convolve image 2 26 PM_SUBTRACTION_MODE_UNSURE, // Not sure yet which image to convolve so try to satisfy both 27 PM_SUBTRACTION_MODE_DUAL, // Dual convolution 28 } pmSubtractionMode; 29 30 /// Kernels specification 31 typedef struct { 32 pmSubtractionKernelsType type; ///< Type of kernels --- allowing the use of multiple kernels 33 psString description; ///< Description of the kernel parameters 34 int xMin, xMax, yMin, yMax; ///< Bounds of image (for normalisation) 35 long num; ///< Number of kernel components (not including the spatial ones) 36 psVector *u, *v; ///< Offset (for POIS) or polynomial order (for ISIS, HERM or DECONV_HERM) 37 psVector *widths; ///< Gaussian FWHMs (ISIS, HERM or DECONV_HERM) 38 psVector *uStop, *vStop; ///< Width of kernel element (SPAM,FRIES only) 39 psArray *preCalc; ///< Array of images containing pre-calculated kernel (for ISIS, HERM or DECONV_HERM) 40 float penalty; ///< Penalty for wideness 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. 44 int size; ///< The half-size of the kernel 45 int inner; ///< The size of an inner region 46 int spatialOrder; ///< The spatial order of the kernels 47 int bgOrder; ///< The order for the background fitting 48 pmSubtractionMode mode; ///< Mode for subtraction 49 psVector *solution1, *solution2; ///< Solution for the PSF matching 50 // Quality information 51 float mean, rms; ///< Mean and RMS of chi^2 from stamps 52 int numStamps; ///< Number of good stamps 53 float fResSigmaMean; ///< mean fractional stdev of residuals 54 float fResSigmaStdev; ///< stdev of fractional stdev of residuals 55 float fResOuterMean; ///< mean fractional positive swing in residuals 56 float fResOuterStdev; ///< stdev of fractional positive swing in residuals 57 float fResTotalMean; ///< mean fractional negative swing in residuals 58 float fResTotalStdev; ///< stdev of fractional negative swing in residuals 59 psArray *sampleStamps; ///< array of brightest set of stamps for output visualizations 60 } pmSubtractionKernels; 61 62 // pmSubtractionKernels->preCalc is an array of pmSubtractionKernelPreCalc structures 63 typedef struct { 64 psVector *uCoords; // used by RINGS 65 psVector *vCoords; // used by RINGS 66 psVector *poly; // used by RINGS 67 68 psVector *xKernel; // used by ISIS, HERM, DECONV_HERM 69 psVector *yKernel; // used by ISIS, HERM, DECONV_HERM 70 psKernel *kernel; // used by ISIS, HERM, DECONV_HERM 71 } pmSubtractionKernelPreCalc; 4 // #include <string.h> 5 // #include <pslib.h> 72 6 73 7 // Assertion to check pmSubtractionKernels … … 162 96 pmSubtractionKernelsType type, ///< Kernel type 163 97 int size, ///< Half-size of kernel 98 psVector *fwhms, ///< requested kernel basis function 99 psVector *orders, 164 100 int spatialOrder, ///< Order of spatial variations 165 101 float penalty, ///< Penalty for wideness … … 303 239 ); 304 240 241 bool pmSubtractionKernelsMakeDescription(pmSubtractionKernels *kernels); 242 243 305 244 /// Copy kernels 306 245 /// -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionMask.c
r27402 r30631 7 7 8 8 #include "pmErrorCodes.h" 9 #include "pmFPA.h" 10 #include "pmSubtractionTypes.h" 9 11 #include "pmSubtraction.h" 10 12 #include "pmSubtractionKernels.h" -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionMatch.c
r29596 r30631 11 11 #include "pmFPA.h" 12 12 #include "pmHDUUtils.h" 13 #include "pmSubtractionTypes.h" 14 #include "pmSubtraction.h" 13 15 #include "pmSubtractionParams.h" 14 16 #include "pmSubtractionKernels.h" 15 17 #include "pmSubtractionStamps.h" 16 18 #include "pmSubtractionEquation.h" 17 #include "pmSubtraction.h"18 19 #include "pmSubtractionAnalysis.h" 19 20 #include "pmSubtractionMask.h" … … 27 28 28 29 static bool useFFT = true; // Do convolutions using FFT 29 30 # define SUBMODE PM_SUBTRACTION_EQUATION_ALL31 30 32 31 //#define TESTING … … 59 58 } 60 59 61 62 static bool subtractionGetStamps(pmSubtractionStampList **stamps, // Stamps to read63 const pmReadout *ro1, // Readout 164 const pmReadout *ro2, // Readout 265 const psImage *subMask, // Mask for subtraction, or NULL66 psImage *variance, // Variance map67 const psRegion *region, // Region of interest68 float thresh1, // Threshold for stamp finding on readout 169 float thresh2, // Threshold for stamp finding on readout 270 float stampSpacing, // Spacing between stamps71 float normFrac, // Fraction of flux in window for normalisation window72 float sysError, // Relative systematic error in images73 float skyError, // Relative systematic error in images74 int size, // Kernel half-size75 int footprint, // Convolution footprint for stamps76 pmSubtractionMode mode // Mode for subtraction77 )78 {79 PS_ASSERT_PTR_NON_NULL(stamps, false);80 PM_ASSERT_READOUT_NON_NULL(ro1, false);81 PM_ASSERT_READOUT_NON_NULL(ro2, false);82 PS_ASSERT_IMAGE_NON_NULL(subMask, false);83 PS_ASSERT_IMAGE_NON_NULL(variance, false);84 PS_ASSERT_PTR_NON_NULL(region, false);85 86 psTrace("psModules.imcombine", 3, "Finding stamps...\n");87 88 psImage *image1 = ro1 ? ro1->image : NULL, *image2 = ro2 ? ro2->image : NULL; // Images of interest89 90 *stamps = pmSubtractionStampsFind(*stamps, image1, image2, subMask, region, thresh1, thresh2,91 size, footprint, stampSpacing, normFrac, sysError, skyError, mode);92 if (!*stamps) {93 psError(psErrorCodeLast(), false, "Unable to find stamps.");94 return false;95 }96 97 memCheck(" find stamps");98 99 psTrace("psModules.imcombine", 3, "Extracting stamps...\n");100 if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2->image, variance, size, *region)) {101 psError(psErrorCodeLast(), false, "Unable to extract stamps.");102 return false;103 }104 105 memCheck(" extract stamps");106 pmSubtractionVisualPlotStamps(*stamps, (pmReadout *) ro1);107 return true;108 }109 110 60 // Check input arguments 111 61 static bool subtractionMatchCheck(pmReadout *conv1, pmReadout *conv2, // Convolved images … … 123 73 float badFrac, // Maximum fraction of bad input pixels to accept 124 74 pmSubtractionMode subMode // Mode of subtraction 125 )75 ) 126 76 { 127 77 if (subMode != PM_SUBTRACTION_MODE_2) { … … 473 423 } 474 424 425 bool pmSubtractionMatchAttempt(pmSubtractionQuality **bestMatch, pmSubtractionKernels *kernels, pmSubtractionStampList *stamps, pmSubtractionMode mode, int spatialOrder, bool final) { 426 427 pmSubtractionMode nativeMode = kernels->mode; 428 pmSubtractionMode nativeOrder = kernels->spatialOrder; 429 430 kernels->mode = mode; 431 kernels->spatialOrder = spatialOrder; 432 433 // we always need to recalculate the matrix equation elements... 434 pmSubtractionStampsResetStatus(stamps); 435 436 psTrace("psModules.imcombine", 3, "Convolving stamps as needed...\n"); 437 if (!pmSubtractionConvolveStamps(stamps, kernels)) { 438 psError(psErrorCodeLast(), false, "Unable to convolve stamps."); 439 return false; 440 } 441 442 // step 1: generate the elements of the matrix equation Ax = B 443 psTrace("psModules.imcombine", 3, "Calculating kernel equations...\n"); 444 if (!pmSubtractionCalculateEquation(stamps, kernels)) { 445 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 446 return false; 447 } 448 449 // step 2: solve the matrix equation Ax = B 450 psTrace("psModules.imcombine", 3, "Solving kernel equations...\n"); 451 if (!pmSubtractionSolveEquation(kernels, stamps)) { 452 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 453 return false; 454 } 455 memCheck(" solve equation"); 456 457 // calculate the score for this model fit attempt 458 // XXX store the chisq, flux and moments for stamp rejection 459 pmSubtractionCalculateChisqAndMoments(bestMatch, stamps, kernels); // Stamp deviations 460 461 // display the input and model stamps 462 pmSubtractionVisualShowFit(stamps, kernels); 463 pmSubtractionVisualPlotFit(kernels); 464 pmSubtractionVisualPlotConvKernels(kernels); 465 466 // reset the kernel if desired (on final pass, do not reset) 467 if (!final) { 468 kernels->mode = nativeMode; 469 kernels->spatialOrder = nativeOrder; 470 } else { 471 pmSubtractionKernelsMakeDescription(kernels); 472 psLogMsg("psModules.imcombine", PS_LOG_INFO, "final kernel: %s", kernels->description); 473 } 474 return true; 475 } 475 476 476 477 bool pmSubtractionMatch(pmReadout *conv1, pmReadout *conv2, const pmReadout *ro1, const pmReadout *ro2, … … 478 479 const psArray *sources, const char *stampsName, 479 480 pmSubtractionKernelsType type, int size, int spatialOrder, 480 constpsVector *isisWidths, const psVector *isisOrders,481 psVector *isisWidths, const psVector *isisOrders, 481 482 int inner, int ringsOrder, int binning, float penalty, 482 483 bool optimum, const psVector *optFWHMs, int optOrder, float optThreshold, … … 559 560 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator 560 561 562 pmSubtractionQuality *bestMatch = NULL; 563 564 int N_TEST_MODES; 565 int N_TEST_ORDER = spatialOrder; 566 567 pmSubtractionMode TestModes[3]; 568 switch (subMode) { 569 case PM_SUBTRACTION_MODE_1: 570 N_TEST_MODES = 1; 571 TestModes[0] = PM_SUBTRACTION_MODE_1; 572 break; 573 case PM_SUBTRACTION_MODE_2: 574 N_TEST_MODES = 1; 575 TestModes[0] = PM_SUBTRACTION_MODE_2; 576 break; 577 case PM_SUBTRACTION_MODE_DUAL: 578 N_TEST_MODES = 3; 579 TestModes[0] = PM_SUBTRACTION_MODE_1; 580 TestModes[1] = PM_SUBTRACTION_MODE_2; 581 TestModes[2] = PM_SUBTRACTION_MODE_DUAL; 582 break; 583 default: 584 psError(psErrorCodeLast(), false, "For now, only modes 1, 2, and DUAL are supported."); 585 goto MATCH_ERROR; 586 } 587 561 588 memCheck("start"); 562 589 … … 628 655 regionString = psRegionToString(*region); 629 656 psLogMsg("psModules.imcombine", PS_LOG_DETAIL, "Iso-kernel region: %s out of %d,%d\n", 630 regionString, numCols, numRows);657 regionString, numCols, numRows); 631 658 632 659 if (stampsName && strlen(stampsName) > 0) { … … 640 667 } 641 668 642 // We get the stamps here; we will also attempt to get stamps at the first iteration, but it 643 // doesn't matter. 644 if (!subtractionGetStamps(&stamps, ro1, ro2, subMask, variance, region, stampThresh1, stampThresh2, 645 stampSpacing, normFrac, sysError, skyError, size, footprint, subMode)) { 646 goto MATCH_ERROR; 647 } 648 649 650 // generate the window function from the set of stamps 651 if (!pmSubtractionStampsGetWindow(stamps, size)) { 652 psError(psErrorCodeLast(), false, "Unable to get stamp window."); 653 goto MATCH_ERROR; 654 } 655 656 // Define kernel basis functions 657 if (optimum && (type == PM_SUBTRACTION_KERNEL_ISIS || type == PM_SUBTRACTION_KERNEL_GUNK)) { 658 kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, 659 optFWHMs, optOrder, stamps, footprint, 660 optThreshold, penalty, bounds, subMode); 661 if (!kernels) { 662 psErrorClear(); 663 psWarning("Unable to derive optimum ISIS kernel --- switching to default."); 664 } 665 } 666 if (kernels == NULL) { 667 // Not an ISIS/GUNK kernel, or the optimum kernel search failed 668 kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders, 669 inner, binning, ringsOrder, penalty, bounds, subMode); 670 } 671 672 memCheck("kernels"); 673 674 if (subMode == PM_SUBTRACTION_MODE_UNSURE) { 675 pmSubtractionMode newMode = pmSubtractionBestMode(&stamps, &kernels, subMask, rej); 676 switch (newMode) { 677 case PM_SUBTRACTION_MODE_1: 678 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Convolving image 1 to match image 2."); 679 break; 680 case PM_SUBTRACTION_MODE_2: 681 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Convolving image 2 to match image 1."); 682 break; 683 default: 684 psError(psErrorCodeLast(), false, "Unable to determine subtraction order."); 685 goto MATCH_ERROR; 686 } 687 subMode = newMode; 688 } 689 690 int numRejected = -1; // Number of rejected stamps in each iteration 691 for (int k = 0; k < iter && numRejected != 0; k++) { 692 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Iteration %d.", k); 693 694 if (!subtractionGetStamps(&stamps, ro1, ro2, subMask, variance, region, 695 stampThresh1, stampThresh2, stampSpacing, normFrac, 696 sysError, skyError, size, footprint, subMode)) { 697 goto MATCH_ERROR; 698 } 699 700 // generate the window function from the set of stamps 701 if (!pmSubtractionStampsGetWindow(stamps, size)) { 702 psError(psErrorCodeLast(), false, "Unable to get stamps window."); 703 goto MATCH_ERROR; 704 } 669 bool tryAgain = true; 670 while (tryAgain) { 671 // We get the stamps here; we will also attempt to get stamps at the first iteration, but it 672 // doesn't matter. 673 if (!pmSubtractionStampsSelect(&stamps, ro1, ro2, subMask, variance, region, stampThresh1, stampThresh2, 674 stampSpacing, normFrac, sysError, skyError, size, footprint, subMode)) { 675 goto MATCH_ERROR; 676 } 677 678 // generate the window function from the set of stamps 679 if (!pmSubtractionStampsGetWindow(&tryAgain, stamps, size)) { 680 // if we failed, it might be due to the desired normWindow being larger than the current footprint. 681 // in this case, just adjust the footprint and try again. 682 if (tryAgain) { 683 // keep the border constant 684 int border = footprint - size; 685 size = PS_MAX(stamps->normWindow1, stamps->normWindow2) + 2; 686 footprint = size + border; 687 688 // we need to reconstruct everything, so just free the stamps here and retry 689 psFree(stamps); 690 } else { 691 // unrecoverable error 692 psError(psErrorCodeLast(), false, "Unable to get stamp window."); 693 goto MATCH_ERROR; 694 } 695 } 696 } 697 698 // check on the kernel scaling -- if the kron-based radial moments are very different, adjust to match them 699 { 700 // float fwhm1; 701 // float fwhm2; 702 // pmSubtractionGetFWHMs(&fwhm1, &fwhm2); 703 // psAssert(isfinite(fwhm1), "fwhm 1 not set"); 704 // psAssert(isfinite(fwhm2), "fwhm 2 not set"); 705 706 // XXX this is BAD: depends on the relationship below: 707 // stamps->normWindow1 = 2.75*R1; 708 // stamps->normWindow2 = 2.75*R2; 709 float radMoment1 = stamps->normWindow1 / 2.75; 710 float radMoment2 = stamps->normWindow2 / 2.75; 711 pmSubtractionParamsScale(NULL, NULL, isisWidths, radMoment1, radMoment2); 712 713 // float maxFWHM = PS_MAX(fwhm1, fwhm2); 714 // float maxRadial = PS_MAX(radMoment1, radMoment2); 715 716 // if (fabs(2.0*(maxFWHM - maxRadial)/(maxFWHM + maxRadial)) > 0.25) { 717 // if (1) { 718 // 719 // float scale = maxRadial / maxFWHM; 720 // psLogMsg ("psModules.imcombine", PS_LOG_INFO, "Kron and FWHM scales are quite different, re-scale by %f to use Kron", scale); 721 // 722 // for (int i = 0; i < isisWidths->n; i++) { 723 // isisWidths->data.F32[i] *= scale; 724 // } 725 // } 726 } 727 728 // Define kernel basis functions 729 if (optimum && (type == PM_SUBTRACTION_KERNEL_ISIS || type == PM_SUBTRACTION_KERNEL_GUNK)) { 730 kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, 731 optFWHMs, optOrder, stamps, footprint, 732 optThreshold, penalty, bounds, subMode); 733 if (!kernels) { 734 psErrorClear(); 735 psWarning("Unable to derive optimum ISIS kernel --- switching to default."); 736 } 737 } 738 if (kernels == NULL) { 739 // Not an ISIS/GUNK kernel, or the optimum kernel search failed 740 kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders, 741 inner, binning, ringsOrder, penalty, bounds, subMode); 742 } 743 744 memCheck("kernels"); 745 746 if (subMode == PM_SUBTRACTION_MODE_UNSURE) { 747 pmSubtractionMode newMode = pmSubtractionBestMode(&stamps, &kernels, subMask, rej); 748 switch (newMode) { 749 case PM_SUBTRACTION_MODE_1: 750 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Convolving image 1 to match image 2."); 751 break; 752 case PM_SUBTRACTION_MODE_2: 753 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Convolving image 2 to match image 1."); 754 break; 755 default: 756 psError(psErrorCodeLast(), false, "Unable to determine subtraction order."); 757 goto MATCH_ERROR; 758 } 759 subMode = newMode; 760 } 761 762 int numRejected = -1; // Number of rejected stamps in each iteration 763 for (int k = 0; (k < iter) && (numRejected != 0); k++) { 764 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Iteration %d.", k); 765 766 bool tryAgain = true; 767 while (tryAgain) { 768 // We get the stamps here; we will also attempt to get stamps at the first iteration, but it 769 // doesn't matter. 770 if (!pmSubtractionStampsSelect(&stamps, ro1, ro2, subMask, variance, region, stampThresh1, stampThresh2, 771 stampSpacing, normFrac, sysError, skyError, size, footprint, subMode)) { 772 goto MATCH_ERROR; 773 } 774 775 // generate the window function from the set of stamps 776 if (!pmSubtractionStampsGetWindow(&tryAgain, stamps, size)) { 777 // if we failed, it might be due to the desired normWindow being larger than the current footprint. 778 // in this case, just adjust the footprint and try again. 779 if (tryAgain) { 780 footprint = PS_MAX(stamps->normWindow1, stamps->normWindow2) + 2; 781 782 // we need to reconstruct everything, so just free the stamps here and retry 783 psFree(stamps); 784 } else { 785 // unrecoverable error 786 psError(psErrorCodeLast(), false, "Unable to get stamp window."); 787 goto MATCH_ERROR; 788 } 789 } 790 } 705 791 706 792 // step 0 : calculate the normalizations, pass along to the next steps via stamps->normValue 707 psTrace("psModules.imcombine", 3, "Calculating normalization...\n"); 708 if (!pmSubtractionCalculateNormalization(stamps, kernels->mode)) { 709 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 710 goto MATCH_ERROR; 711 } 712 713 // step 0b : calculate the moments, pass along to the next steps via stamps->normValue 714 // XXX this step is now skipped -- delete 715 psTrace("psModules.imcombine", 3, "Calculating normalization...\n"); 716 if (!pmSubtractionCalculateMoments(kernels, stamps)) { 717 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 718 goto MATCH_ERROR; 719 } 720 721 // step 1: generate the elements of the matrix equation Ax = B 722 psTrace("psModules.imcombine", 3, "Calculating kernel equations...\n"); 723 if (!pmSubtractionCalculateEquation(stamps, kernels, SUBMODE)) { 724 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 725 goto MATCH_ERROR; 726 } 727 728 // step 2: solve the matrix equation Ax = B 729 psTrace("psModules.imcombine", 3, "Solving kernel equations...\n"); 730 if (!pmSubtractionSolveEquation(kernels, stamps, SUBMODE)) { 731 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 732 goto MATCH_ERROR; 733 } 734 memCheck(" solve equation"); 735 736 pmSubtractionVisualPlotConvKernels(kernels); 737 738 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations 739 if (!deviations) { 740 psError(psErrorCodeLast(), false, "Unable to calculate deviations."); 741 goto MATCH_ERROR; 742 } 743 memCheck(" calculate deviations"); 744 745 psTrace("psModules.imcombine", 3, "Rejecting stamps...\n"); 746 numRejected = pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, rej); 747 if (numRejected < 0) { 748 psError(psErrorCodeLast(), false, "Unable to reject stamps."); 749 psFree(deviations); 750 goto MATCH_ERROR; 751 } 752 psFree(deviations); 753 754 memCheck(" reject stamps"); 755 } 756 757 // if we hit the max number of iterations and we have rejected stamps, re-solve 758 if (numRejected > 0) { 759 760 // step 1: generate the elements of the matrix equation Ax = B 761 psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n"); 762 if (!pmSubtractionCalculateEquation(stamps, kernels, SUBMODE)) { 763 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 764 goto MATCH_ERROR; 765 } 766 767 // step 2: solve the matrix equation Ax = B 768 psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n"); 769 if (!pmSubtractionSolveEquation(kernels, stamps, SUBMODE)) { 770 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 771 goto MATCH_ERROR; 772 } 773 774 pmSubtractionVisualPlotConvKernels(kernels); 775 776 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations 777 if (!deviations) { 778 psError(psErrorCodeLast(), false, "Unable to calculate deviations."); 779 goto MATCH_ERROR; 780 } 781 pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, NAN); 782 psFree(deviations); 783 } 784 psFree(stamps); 785 stamps = NULL; 786 787 memCheck("solution"); 788 789 if (!pmSubtractionAnalysis(analysis, header, kernels, region, numCols, numRows)) { 790 psError(psErrorCodeLast(), false, "Unable to generate QA data"); 791 goto MATCH_ERROR; 792 } 793 memCheck("diag outputs"); 794 795 psTrace("psModules.imcombine", 2, "Convolving...\n"); 796 if (!pmSubtractionConvolve(conv1, conv2, ro1, ro2, subMask, stride, maskBad, maskPoor, poorFrac, 797 kernelError, covarFrac, region, kernels, true, useFFT)) { 798 psError(psErrorCodeLast(), false, "Unable to convolve image."); 799 goto MATCH_ERROR; 800 } 801 802 psFree(kernels); 803 kernels = NULL; 804 } 793 psTrace("psModules.imcombine", 3, "Calculating normalization...\n"); 794 if (!pmSubtractionCalculateNormalization(stamps, kernels->mode)) { 795 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 796 goto MATCH_ERROR; 797 } 798 799 // on each iteration, we start from scratch 800 psFree(bestMatch); 801 802 // choose the spatial order and subtraction direction (1, 2, dual) 803 // XXX need to make these respect recipe somewhat 804 for (int order = 0; order <= N_TEST_ORDER; order++) { 805 for (int j = 0; j < N_TEST_MODES; j++) { 806 if (!pmSubtractionMatchAttempt(&bestMatch, kernels, stamps, TestModes[j], order, false)) { 807 goto MATCH_ERROR; 808 } 809 } 810 } 811 812 // reject the deviant stamps based on the stats of the best match 813 psTrace("psModules.imcombine", 3, "Rejecting stamps...\n"); 814 numRejected = pmSubtractionRejectStamps(kernels, stamps, bestMatch, subMask, rej); 815 if (numRejected < 0) { 816 psError(psErrorCodeLast(), false, "Unable to reject stamps."); 817 goto MATCH_ERROR; 818 } 819 memCheck(" reject stamps"); 820 } 821 822 // apply the best fit so we are ready to roll 823 psLogMsg("psModules.imcombine", PS_LOG_INFO, "applying order: %d, mode: %d\n", bestMatch->spatialOrder, bestMatch->mode); 824 if (!pmSubtractionMatchAttempt(NULL, kernels, stamps, bestMatch->mode, bestMatch->spatialOrder, true)) { 825 goto MATCH_ERROR; 826 } 827 psFree(stamps); 828 psFree(bestMatch); 829 memCheck("solution"); 830 831 if (!pmSubtractionAnalysis(analysis, header, kernels, region, numCols, numRows)) { 832 psError(psErrorCodeLast(), false, "Unable to generate QA data"); 833 goto MATCH_ERROR; 834 } 835 memCheck("diag outputs"); 836 837 psTrace("psModules.imcombine", 2, "Convolving...\n"); 838 if (!pmSubtractionConvolve(conv1, conv2, ro1, ro2, subMask, stride, maskBad, maskPoor, poorFrac, 839 kernelError, covarFrac, region, kernels, true, useFFT)) { 840 psError(psErrorCodeLast(), false, "Unable to convolve image."); 841 goto MATCH_ERROR; 842 } 843 844 psFree(kernels); 845 kernels = NULL; 846 } 805 847 } 806 848 psFree(rng); … … 816 858 817 859 if (conv1 && !pmSubtractionBorder(conv1->image, conv1->variance, conv1->mask, size, maskBad)) { 818 psError(psErrorCodeLast(), false, "Unable to set border of convolved image.");819 goto MATCH_ERROR;860 psError(psErrorCodeLast(), false, "Unable to set border of convolved image."); 861 goto MATCH_ERROR; 820 862 } 821 863 if (conv2 && !pmSubtractionBorder(conv2->image, conv2->variance, conv2->mask, size, maskBad)) { 822 psError(psErrorCodeLast(), false, "Unable to set border of convolved image.");823 goto MATCH_ERROR;864 psError(psErrorCodeLast(), false, "Unable to set border of convolved image."); 865 goto MATCH_ERROR; 824 866 } 825 867 … … 832 874 #ifdef TESTING 833 875 { 834 if (subMode == PM_SUBTRACTION_MODE_1 || subMode == PM_SUBTRACTION_MODE_DUAL) {835 psFits *fits = psFitsOpen("convolved1.fits", "w");836 psFitsWriteImage(fits, NULL, conv1->image, 0, NULL);837 psFitsClose(fits);838 }839 840 if (subMode == PM_SUBTRACTION_MODE_2 || subMode == PM_SUBTRACTION_MODE_DUAL) {841 psFits *fits = psFitsOpen("convolved2.fits", "w");842 psFitsWriteImage(fits, NULL, conv2->image, 0, NULL);843 psFitsClose(fits);844 }876 if (subMode == PM_SUBTRACTION_MODE_1 || subMode == PM_SUBTRACTION_MODE_DUAL) { 877 psFits *fits = psFitsOpen("convolved1.fits", "w"); 878 psFitsWriteImage(fits, NULL, conv1->image, 0, NULL); 879 psFitsClose(fits); 880 } 881 882 if (subMode == PM_SUBTRACTION_MODE_2 || subMode == PM_SUBTRACTION_MODE_DUAL) { 883 psFits *fits = psFitsOpen("convolved2.fits", "w"); 884 psFitsWriteImage(fits, NULL, conv2->image, 0, NULL); 885 psFitsClose(fits); 886 } 845 887 } 846 888 #endif … … 858 900 psFree(variance); 859 901 psFree(rng); 902 psFree(bestMatch); 860 903 return false; 861 904 } … … 866 909 // increment). 867 910 static int subtractionOrderWidth(const psKernel *kernel, // Image 868 float bg, // Background in image869 int size, // Maximum size870 const psArray *models, // Buffer of models871 const psVector *modelSums // Buffer of model sums911 float bg, // Background in image 912 int size, // Maximum size 913 const psArray *models, // Buffer of models 914 const psVector *modelSums // Buffer of model sums 872 915 ) 873 916 { … … 882 925 psVector *chi2 = psVectorAlloc(size, PS_TYPE_F32); // chi^2 as a function of radius 883 926 for (int sigma = 0; sigma < size; sigma++) { 884 double sumFG = 0.0; // Sum for calculating the normalisation of the Gaussian885 psKernel *model = models->data[sigma]; // Model of interest886 for (int y = yMin; y <= yMax; y++) {887 for (int x = xMin; x <= xMax; x++) {888 sumFG += model->kernel[y][x] * (kernel->kernel[y][x] - bg);889 }890 }891 float norm = sumFG * modelSums->data.F64[sigma]; // Normalisation for Gaussian892 double sumDev2 = 0.0; // Sum of square deviations893 for (int y = yMin; y <= yMax; y++) {894 for (int x = xMin; x <= xMax; x++) {895 float dev = kernel->kernel[y][x] - bg - norm * model->kernel[y][x]; // Deviation896 sumDev2 += PS_SQR(dev);897 }898 }899 chi2->data.F32[sigma] = sumDev2;927 double sumFG = 0.0; // Sum for calculating the normalisation of the Gaussian 928 psKernel *model = models->data[sigma]; // Model of interest 929 for (int y = yMin; y <= yMax; y++) { 930 for (int x = xMin; x <= xMax; x++) { 931 sumFG += model->kernel[y][x] * (kernel->kernel[y][x] - bg); 932 } 933 } 934 float norm = sumFG * modelSums->data.F64[sigma]; // Normalisation for Gaussian 935 double sumDev2 = 0.0; // Sum of square deviations 936 for (int y = yMin; y <= yMax; y++) { 937 for (int x = xMin; x <= xMax; x++) { 938 float dev = kernel->kernel[y][x] - bg - norm * model->kernel[y][x]; // Deviation 939 sumDev2 += PS_SQR(dev); 940 } 941 } 942 chi2->data.F32[sigma] = sumDev2; 900 943 } 901 944 … … 904 947 float bestChi2 = INFINITY; // Best chi^2 905 948 for (int i = 0; i < size; i++) { 906 if (chi2->data.F32[i] < bestChi2) {907 bestChi2 = chi2->data.F32[i];908 bestIndex = i;909 }949 if (chi2->data.F32[i] < bestChi2) { 950 bestChi2 = chi2->data.F32[i]; 951 bestIndex = i; 952 } 910 953 } 911 954 psFree(chi2); … … 916 959 917 960 bool pmSubtractionOrderStamp(psVector *ratios, psVector *mask, const pmSubtractionStampList *stamps, 918 const psArray *models, const psVector *modelSums,919 int index, float bg1, float bg2)961 const psArray *models, const psVector *modelSums, 962 int index, float bg1, float bg2) 920 963 { 921 964 PS_ASSERT_VECTOR_NON_NULL(ratios, false); … … 931 974 pmSubtractionStamp *stamp = stamps->stamps->data[index]; // Stamp of interest 932 975 psAssert(stamp->status == PM_SUBTRACTION_STAMP_CALCULATE || stamp->status == PM_SUBTRACTION_STAMP_USED, 933 "We checked this earlier.");976 "We checked this earlier."); 934 977 935 978 // Widths of stars … … 938 981 939 982 if (width1 == 0 || width2 == 0) { 940 ratios->data.F32[index] = NAN;941 mask->data.PS_TYPE_VECTOR_MASK_DATA[index] = 0xff;983 ratios->data.F32[index] = NAN; 984 mask->data.PS_TYPE_VECTOR_MASK_DATA[index] = 0xff; 942 985 } else { 943 ratios->data.F32[index] = (float)width1 / (float)width2;944 mask->data.PS_TYPE_VECTOR_MASK_DATA[index] = 0;945 psTrace("psModules.imcombine", 3, "Stamp %d (%.1f,%.1f) widths: %d, %d --> %f\n",946 index, stamp->x, stamp->y, width1, width2, ratios->data.F32[index]);986 ratios->data.F32[index] = (float)width1 / (float)width2; 987 mask->data.PS_TYPE_VECTOR_MASK_DATA[index] = 0; 988 psTrace("psModules.imcombine", 3, "Stamp %d (%.1f,%.1f) widths: %d, %d --> %f\n", 989 index, stamp->x, stamp->y, width1, width2, ratios->data.F32[index]); 947 990 } 948 991 … … 978 1021 psVector *modelSums = psVectorAlloc(size, PS_TYPE_F64); // Gaussian model sums 979 1022 for (int sigma = 0; sigma < size; sigma++) { 980 psKernel *model = psKernelAlloc(-size, size, -size, size); // Gaussian model981 float invSigma2 = 1.0 / (float)PS_SQR(1 + sigma); // Inverse sigma squared982 double sumGG = 0.0; // Sum of square of Gaussian983 for (int y = -size; y <= size; y++) {984 int y2 = PS_SQR(y); // y squared985 for (int x = -size; x <= size; x++) {986 float rad2 = PS_SQR(x) + y2; // Radius squared987 float value = expf(-rad2 * invSigma2); // Model value988 model->kernel[y][x] = value;989 sumGG += PS_SQR(value);990 }991 }992 models->data[sigma] = model;993 modelSums->data.F64[sigma] = 1.0 / sumGG;1023 psKernel *model = psKernelAlloc(-size, size, -size, size); // Gaussian model 1024 float invSigma2 = 1.0 / (float)PS_SQR(1 + sigma); // Inverse sigma squared 1025 double sumGG = 0.0; // Sum of square of Gaussian 1026 for (int y = -size; y <= size; y++) { 1027 int y2 = PS_SQR(y); // y squared 1028 for (int x = -size; x <= size; x++) { 1029 float rad2 = PS_SQR(x) + y2; // Radius squared 1030 float value = expf(-rad2 * invSigma2); // Model value 1031 model->kernel[y][x] = value; 1032 sumGG += PS_SQR(value); 1033 } 1034 } 1035 models->data[sigma] = model; 1036 modelSums->data.F64[sigma] = 1.0 / sumGG; 994 1037 } 995 1038 996 1039 // Fit models to stamps 997 1040 for (int i = 0; i < stamps->num; i++) { 998 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest999 if (stamp->status != PM_SUBTRACTION_STAMP_CALCULATE && stamp->status != PM_SUBTRACTION_STAMP_USED) {1000 mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff;1001 continue;1002 }1003 1004 if (pmSubtractionThreaded()) {1005 psThreadJob *job = psThreadJobAlloc("PSMODULES_SUBTRACTION_ORDER");1006 psArrayAdd(job->args, 1, ratios);1007 psArrayAdd(job->args, 1, mask);1008 psArrayAdd(job->args, 1, stamps);1009 psArrayAdd(job->args, 1, models);1010 psArrayAdd(job->args, 1, modelSums);1011 PS_ARRAY_ADD_SCALAR(job->args, i, PS_TYPE_S32);1012 PS_ARRAY_ADD_SCALAR(job->args, bg1, PS_TYPE_F32);1013 PS_ARRAY_ADD_SCALAR(job->args, bg2, PS_TYPE_F32);1014 if (!psThreadJobAddPending(job)) {1015 return false;1016 }1017 } else {1018 if (!pmSubtractionOrderStamp(ratios, mask, stamps, models, modelSums, i, bg1, bg2)) {1019 psError(psErrorCodeLast(), false, "Unable to measure PSF width for stamp %d", i);1020 psFree(models);1021 psFree(modelSums);1022 psFree(ratios);1023 psFree(mask);1024 return false;1025 }1026 }1041 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest 1042 if (stamp->status != PM_SUBTRACTION_STAMP_CALCULATE && stamp->status != PM_SUBTRACTION_STAMP_USED) { 1043 mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff; 1044 continue; 1045 } 1046 1047 if (pmSubtractionThreaded()) { 1048 psThreadJob *job = psThreadJobAlloc("PSMODULES_SUBTRACTION_ORDER"); 1049 psArrayAdd(job->args, 1, ratios); 1050 psArrayAdd(job->args, 1, mask); 1051 psArrayAdd(job->args, 1, stamps); 1052 psArrayAdd(job->args, 1, models); 1053 psArrayAdd(job->args, 1, modelSums); 1054 PS_ARRAY_ADD_SCALAR(job->args, i, PS_TYPE_S32); 1055 PS_ARRAY_ADD_SCALAR(job->args, bg1, PS_TYPE_F32); 1056 PS_ARRAY_ADD_SCALAR(job->args, bg2, PS_TYPE_F32); 1057 if (!psThreadJobAddPending(job)) { 1058 return false; 1059 } 1060 } else { 1061 if (!pmSubtractionOrderStamp(ratios, mask, stamps, models, modelSums, i, bg1, bg2)) { 1062 psError(psErrorCodeLast(), false, "Unable to measure PSF width for stamp %d", i); 1063 psFree(models); 1064 psFree(modelSums); 1065 psFree(ratios); 1066 psFree(mask); 1067 return false; 1068 } 1069 } 1027 1070 } 1028 1071 1029 1072 if (!psThreadPoolWait(true)) { 1030 psError(psErrorCodeLast(), false, "Error waiting for threads.");1031 psFree(models);1032 psFree(modelSums);1033 psFree(ratios);1034 psFree(mask);1035 return false;1073 psError(psErrorCodeLast(), false, "Error waiting for threads."); 1074 psFree(models); 1075 psFree(modelSums); 1076 psFree(ratios); 1077 psFree(mask); 1078 return false; 1036 1079 } 1037 1080 … … 1041 1084 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); 1042 1085 if (!psVectorStats(stats, ratios, NULL, mask, 0xff)) { 1043 psError(psErrorCodeLast(), false, "Unable to calculate statistics for moments ratio.");1044 psFree(mask);1045 psFree(ratios);1046 psFree(stats);1047 return PM_SUBTRACTION_MODE_ERR;1086 psError(psErrorCodeLast(), false, "Unable to calculate statistics for moments ratio."); 1087 psFree(mask); 1088 psFree(ratios); 1089 psFree(stats); 1090 return PM_SUBTRACTION_MODE_ERR; 1048 1091 } 1049 1092 psFree(ratios); … … 1052 1095 // XXX raise an error here or not? 1053 1096 if (isnan(stats->robustMedian)) { 1054 psFree(stats);1055 return PM_SUBTRACTION_MODE_ERR;1097 psFree(stats); 1098 return PM_SUBTRACTION_MODE_ERR; 1056 1099 } 1057 1100 … … 1066 1109 // Test a subtraction mode by performing a single iteration 1067 1110 static bool subtractionModeTest(pmSubtractionStampList *stamps, // Stamps to use to find best mode 1068 pmSubtractionKernels *kernels, // Kernel description1069 const char *description, // Description for trace1070 psImage *subMask, // Subtraction mask1071 float rej // Rejection threshold1072 )1111 pmSubtractionKernels *kernels, // Kernel description 1112 const char *description, // Description for trace 1113 psImage *subMask, // Subtraction mask 1114 float rej // Rejection threshold 1115 ) 1073 1116 { 1074 1117 assert(stamps); 1075 1118 assert(kernels); 1076 1119 1120 psAbort("this function is not working"); 1121 # if (0) 1122 psTrace("psModules.imcombine", 3, "Convolving stamps as needed...\n"); 1123 if (!pmSubtractionConvolveStamps(stamps, kernels)) { 1124 psError(psErrorCodeLast(), false, "Unable to convolve stamps."); 1125 return false; 1126 } 1127 1077 1128 psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description); 1078 if (!pmSubtractionCalculateEquation(stamps, kernels , SUBMODE)) {1079 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");1080 return false;1129 if (!pmSubtractionCalculateEquation(stamps, kernels)) { 1130 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 1131 return false; 1081 1132 } 1082 1133 1083 1134 psTrace("psModules.imcombine", 3, "Solving %s normalization equation...\n", description); 1084 if (!pmSubtractionSolveEquation(kernels, stamps , SUBMODE)) {1085 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");1086 return false;1135 if (!pmSubtractionSolveEquation(kernels, stamps)) { 1136 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 1137 return false; 1087 1138 } 1088 1139 … … 1090 1141 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations 1091 1142 if (!deviations) { 1092 psError(psErrorCodeLast(), false, "Unable to calculate deviations."); 1093 return false; 1094 } 1095 1143 psError(psErrorCodeLast(), false, "Unable to calculate deviations."); 1144 return false; 1145 } 1146 1147 // XXX this needs to be made consistent with the modified 'reject stamps' function 1096 1148 psTrace("psModules.imcombine", 3, "Rejecting %s stamps...\n", description); 1097 1149 long numRejected = pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, rej); 1098 1150 if (numRejected < 0) { 1099 psError(psErrorCodeLast(), false, "Unable to reject stamps.");1100 psFree(deviations);1101 return false;1151 psError(psErrorCodeLast(), false, "Unable to reject stamps."); 1152 psFree(deviations); 1153 return false; 1102 1154 } 1103 1155 psFree(deviations); 1104 1156 1105 1157 if (numRejected > 0) { 1106 // Allow re-fit with reduced stamps set1107 psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description);1108 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_ALL)) {1109 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");1110 return false;1111 }1112 1113 psTrace("psModules.imcombine", 3, "Resolving %s equation...\n", description);1114 if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_ALL)) {1115 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");1116 return false;1117 }1118 psTrace("psModules.imcombine", 3, "Recalculate %s deviations...\n", description);1119 1120 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations1121 if (!deviations) {1122 psError(psErrorCodeLast(), false, "Unable to calculate deviations.");1123 return false;1124 }1125 psTrace("psModules.imcombine", 3, "Measuring %s quality...\n", description);1126 long numRejected = pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, NAN);1127 if (numRejected < 0) {1128 psError(psErrorCodeLast(), false, "Unable to reject stamps.");1129 psFree(deviations);1130 return false;1131 }1132 psFree(deviations);1133 } 1134 1158 // Allow re-fit with reduced stamps set 1159 psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description); 1160 if (!pmSubtractionCalculateEquation(stamps, kernels)) { 1161 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 1162 return false; 1163 } 1164 1165 psTrace("psModules.imcombine", 3, "Resolving %s equation...\n", description); 1166 if (!pmSubtractionSolveEquation(kernels, stamps)) { 1167 psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation."); 1168 return false; 1169 } 1170 psTrace("psModules.imcombine", 3, "Recalculate %s deviations...\n", description); 1171 1172 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations 1173 if (!deviations) { 1174 psError(psErrorCodeLast(), false, "Unable to calculate deviations."); 1175 return false; 1176 } 1177 psTrace("psModules.imcombine", 3, "Measuring %s quality...\n", description); 1178 long numRejected = pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, NAN); 1179 if (numRejected < 0) { 1180 psError(psErrorCodeLast(), false, "Unable to reject stamps."); 1181 psFree(deviations); 1182 return false; 1183 } 1184 psFree(deviations); 1185 } 1186 # endif 1135 1187 return true; 1136 1188 } … … 1138 1190 1139 1191 pmSubtractionMode pmSubtractionBestMode(pmSubtractionStampList **stamps, pmSubtractionKernels **kernels, 1140 const psImage *subMask, float rej)1192 const psImage *subMask, float rej) 1141 1193 { 1142 1194 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(*stamps, PM_SUBTRACTION_MODE_ERR); … … 1150 1202 1151 1203 if (!subtractionModeTest(stamps1, kernels1, "convolve 1", subMask1, rej)) { 1152 psError(psErrorCodeLast(), false, "Unable to test subtraction with convolution of image 1");1153 psFree(stamps1);1154 psFree(kernels1);1155 psFree(subMask1);1156 return PM_SUBTRACTION_MODE_ERR;1204 psError(psErrorCodeLast(), false, "Unable to test subtraction with convolution of image 1"); 1205 psFree(stamps1); 1206 psFree(kernels1); 1207 psFree(subMask1); 1208 return PM_SUBTRACTION_MODE_ERR; 1157 1209 } 1158 1210 psFree(subMask1); … … 1165 1217 1166 1218 if (!subtractionModeTest(stamps2, kernels2, "convolve 2", subMask2, rej)) { 1167 psError(psErrorCodeLast(), false, "Unable to test subtraction with convolution of image 2");1168 psFree(stamps2);1169 psFree(kernels2);1170 psFree(subMask2);1171 psFree(stamps1);1172 psFree(kernels1);1173 return PM_SUBTRACTION_MODE_ERR;1219 psError(psErrorCodeLast(), false, "Unable to test subtraction with convolution of image 2"); 1220 psFree(stamps2); 1221 psFree(kernels2); 1222 psFree(subMask2); 1223 psFree(stamps1); 1224 psFree(kernels1); 1225 return PM_SUBTRACTION_MODE_ERR; 1174 1226 } 1175 1227 psFree(subMask2); … … 1179 1231 pmSubtractionKernels *bestKernels = NULL; // Best choice for kernels 1180 1232 psLogMsg("psModules.imcombine", PS_LOG_INFO, 1181 "Image 1: %f +/- %f from %d stamps\nImage 2: %f +/- %f from %d stamps\n",1182 kernels1->mean, kernels1->rms, kernels1->numStamps,1183 kernels2->mean, kernels2->rms, kernels2->numStamps);1233 "Image 1: %f +/- %f from %d stamps\nImage 2: %f +/- %f from %d stamps\n", 1234 kernels1->mean, kernels1->rms, kernels1->numStamps, 1235 kernels2->mean, kernels2->rms, kernels2->numStamps); 1184 1236 1185 1237 if (kernels1->mean < kernels2->mean) { 1186 bestStamps = stamps1;1187 bestKernels = kernels1;1238 bestStamps = stamps1; 1239 bestKernels = kernels1; 1188 1240 } else { 1189 bestStamps = stamps2;1190 bestKernels = kernels2;1241 bestStamps = stamps2; 1242 bestKernels = kernels2; 1191 1243 } 1192 1244 … … 1204 1256 } 1205 1257 1206 1207 bool pmSubtractionParamsScale(int *kernelSize, int *stampSize, psVector *widths, 1208 float scaleRef, float scaleMin, float scaleMax) 1258 static float scaleRefOption = NAN; 1259 static float scaleMinOption = NAN; 1260 static float scaleMaxOption = NAN; 1261 static bool scaleOption = false; 1262 1263 bool pmSubtractionParamScaleOptions(bool scale, float scaleRef, float scaleMin, float scaleMax) { 1264 1265 if (scale) { 1266 PS_ASSERT_FLOAT_LARGER_THAN(scaleRef, 0.0, false); 1267 PS_ASSERT_FLOAT_LARGER_THAN(scaleMin, 0.0, false); 1268 PS_ASSERT_FLOAT_LARGER_THAN(scaleMax, 0.0, false); 1269 PS_ASSERT_FLOAT_LARGER_THAN(scaleMax, scaleMin, false); 1270 } 1271 1272 scaleRefOption = scaleRef; 1273 scaleMinOption = scaleMin; 1274 scaleMaxOption = scaleMax; 1275 scaleOption = scale; 1276 1277 return true; 1278 } 1279 1280 bool pmSubtractionParamsScale(int *kernelSize, int *stampSize, psVector *widths, float fwhm1, float fwhm2) 1209 1281 { 1210 PS_ASSERT_PTR_NON_NULL(kernelSize, false);1211 PS_ASSERT_PTR_NON_NULL(stampSize, false);1282 // PS_ASSERT_PTR_NON_NULL(kernelSize, false); 1283 // PS_ASSERT_PTR_NON_NULL(stampSize, false); 1212 1284 PS_ASSERT_VECTOR_NON_NULL(widths, false); 1213 1285 PS_ASSERT_VECTOR_TYPE(widths, PS_TYPE_F32, false); 1214 PS_ASSERT_FLOAT_LARGER_THAN(scaleRef, 0.0, false); 1215 PS_ASSERT_FLOAT_LARGER_THAN(scaleMin, 0.0, false); 1216 PS_ASSERT_FLOAT_LARGER_THAN(scaleMax, 0.0, false); 1217 PS_ASSERT_FLOAT_LARGER_THAN(scaleMax, scaleMin, false); 1218 1219 float fwhm1; 1220 float fwhm2; 1221 1222 pmSubtractionGetFWHMs(&fwhm1, &fwhm2); 1223 psAssert(isfinite(fwhm1), "fwhm 1 not set"); 1224 psAssert(isfinite(fwhm2), "fwhm 2 not set"); 1286 1287 if (!scaleOption) return true; 1288 1289 // pmSubtractionGetFWHMs(&fwhm1, &fwhm2); 1290 // psAssert(isfinite(fwhm1), "fwhm 1 not set"); 1291 // psAssert(isfinite(fwhm2), "fwhm 2 not set"); 1225 1292 1226 1293 // float diff = sqrtf(PS_SQR(PS_MAX(fwhm1, fwhm2)) - PS_SQR(PS_MIN(fwhm1, fwhm2))); // Difference 1227 float scale = PS_MAX(fwhm1, fwhm2) / scaleRef ; // Scaling factor1228 1229 if (isfinite(scaleMin ) && scale < scaleMin) {1230 scale = scaleMin;1231 } 1232 if (isfinite(scaleMax ) && scale > scaleMax) {1233 scale = scaleMax;1294 float scale = PS_MAX(fwhm1, fwhm2) / scaleRefOption; // Scaling factor 1295 1296 if (isfinite(scaleMinOption) && scale < scaleMinOption) { 1297 scale = scaleMinOption; 1298 } 1299 if (isfinite(scaleMaxOption) && scale > scaleMaxOption) { 1300 scale = scaleMaxOption; 1234 1301 } 1235 1302 1236 1303 for (int i = 0; i < widths->n; i++) { 1237 widths->data.F32[i] *= scale; 1238 } 1239 *kernelSize = *kernelSize * scale + 0.5; 1240 *stampSize = *stampSize * scale + 0.5; 1241 1242 psLogMsg("psModules.imcombine", PS_LOG_INFO, 1243 "Scaling kernel parameters by %f: %d %d", scale, *kernelSize, *stampSize); 1304 widths->data.F32[i] *= scale; 1305 } 1306 if (kernelSize) { 1307 *kernelSize = *kernelSize * scale + 0.5; 1308 } 1309 if (stampSize) { 1310 *stampSize = *stampSize * scale + 0.5; 1311 } 1312 1313 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Scaling kernel parameters by %f", scale); 1314 if (kernelSize) psLogMsg("psModules.imcombine", PS_LOG_INFO, " modified kernel size %d", *kernelSize); 1315 if (stampSize) psLogMsg("psModules.imcombine", PS_LOG_INFO, " modified stamp size %d", *stampSize); 1244 1316 1245 1317 return true; -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionMatch.h
r29543 r30631 8 8 #include <pmSubtractionKernels.h> 9 9 #include <pmSubtractionStamps.h> 10 #include <pmSubtraction.h> 10 11 11 12 /// Match two images … … 26 27 int size, ///< Kernel half-size 27 28 int order, ///< Spatial polynomial order 28 constpsVector *widths, ///< ISIS Gaussian widths29 psVector *widths, ///< ISIS Gaussian widths 29 30 const psVector *orders, ///< ISIS Polynomial orders 30 31 int inner, ///< Inner radius for various kernel types … … 100 101 101 102 /// Scale subtraction parameters according to the FWHMs of the inputs 102 bool pmSubtractionParamsScale( 103 int *kernelSize, ///< Half-size of the kernel 104 int *stampSize, ///< Half-size of the stamp (footprint) 105 psVector *widths, ///< ISIS widths 106 float scaleRef, ///< Reference width for scaling 107 float scaleMin, ///< Minimum scaling ratio, or NAN 108 float scaleMax ///< Maximum scaling ratio, or NAN 103 // bool pmSubtractionParamsScale( 104 // int *kernelSize, ///< Half-size of the kernel 105 // int *stampSize, ///< Half-size of the stamp (footprint) 106 // psVector *widths, ///< ISIS widths 107 // float scaleRef, ///< Reference width for scaling 108 // float scaleMin, ///< Minimum scaling ratio, or NAN 109 // float scaleMax ///< Maximum scaling ratio, or NAN 110 // ); 111 112 bool pmSubtractionParamsScale(int *kernelSize, int *stampSize, psVector *widths, float fwhm1, float fwhm2); 113 114 bool pmSubtractionParamScaleOptions(bool scale, float scaleRef, float scaleMin, float scaleMax); 115 116 bool pmSubtractionMatchAttempt( 117 pmSubtractionQuality **bestMatch, 118 pmSubtractionKernels *kernels, 119 pmSubtractionStampList *stamps, 120 pmSubtractionMode mode, 121 int spatialOrder, 122 bool final 109 123 ); 110 124 -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionParams.c
r27086 r30631 9 9 10 10 #include "pmErrorCodes.h" 11 #include "pmFPA.h" 12 #include "pmSubtractionTypes.h" 13 #include "pmSubtraction.h" 11 14 #include "pmSubtractionStamps.h" 12 #include "pmSubtraction.h"13 15 #include "pmSubtractionParams.h" 14 16 … … 16 18 17 19 #if 0 20 // XXX this was moved to pmSubtraction.c in r15443 -- delete 18 21 // Convolve the reference stamp by the kernel 19 22 static psKernel *convolveStamp(const pmSubtractionStamp *stamp, // Stamp to be convolved -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionStamps.c
r29543 r30631 27 27 #include "pmSource.h" 28 28 29 #include "pmSubtractionTypes.h" 29 30 #include "pmSubtraction.h" 30 31 #include "pmSubtractionStamps.h" 32 #include "pmSubtractionVisual.h" 31 33 32 34 #define STAMP_LIST_BUFFER 20 // Number of stamps to add to list at a time … … 122 124 if ((image1 && image1->data.F32[y][x] < thresh1) || 123 125 (image2 && image2->data.F32[y][x] < thresh2)) { 126 // fprintf (stderr, "%f,%f : thresh\n", xRaw, yRaw); 124 127 continue; 125 128 } … … 366 369 } 367 370 368 369 pmSubtractionStampList *pmSubtractionStampsFind(pmSubtractionStampList *stamps, const psImage *image1, 370 const psImage *image2, const psImage *subMask, 371 const psRegion *region, float thresh1, float thresh2, 372 int size, int footprint, float spacing, float normFrac, 373 float sysErr, float skyErr, pmSubtractionMode mode) 371 bool pmSubtractionStampsSelect(pmSubtractionStampList **stamps, // Stamps to read 372 const pmReadout *ro1, // Readout 1 373 const pmReadout *ro2, // Readout 2 374 const psImage *subMask, // Mask for subtraction, or NULL 375 psImage *variance, // Variance map 376 const psRegion *region, // Region of interest 377 float thresh1, // Threshold for stamp finding on readout 1 378 float thresh2, // Threshold for stamp finding on readout 2 379 float stampSpacing, // Spacing between stamps 380 float normFrac, // Fraction of flux in window for normalisation window 381 float sysError, // Relative systematic error in images 382 float skyError, // Relative systematic error in images 383 int size, // Kernel half-size 384 int footprint, // Convolution footprint for stamps 385 pmSubtractionMode mode // Mode for subtraction 386 ) 387 { 388 PS_ASSERT_PTR_NON_NULL(stamps, false); 389 PM_ASSERT_READOUT_NON_NULL(ro1, false); 390 PM_ASSERT_READOUT_NON_NULL(ro2, false); 391 PS_ASSERT_IMAGE_NON_NULL(subMask, false); 392 PS_ASSERT_IMAGE_NON_NULL(variance, false); 393 PS_ASSERT_PTR_NON_NULL(region, false); 394 395 psTrace("psModules.imcombine", 3, "Finding stamps...\n"); 396 397 psImage *image1 = ro1 ? ro1->image : NULL, *image2 = ro2 ? ro2->image : NULL; // Images of interest 398 399 *stamps = pmSubtractionStampsFind(*stamps, image1, image2, subMask, region, thresh1, thresh2, 400 size, footprint, stampSpacing, normFrac, sysError, skyError, mode); 401 if (!*stamps) { 402 psError(psErrorCodeLast(), false, "Unable to find stamps."); 403 return false; 404 } 405 406 psTrace("psModules.imcombine", 3, "Extracting stamps...\n"); 407 if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2->image, variance, size, *region)) { 408 psError(psErrorCodeLast(), false, "Unable to extract stamps."); 409 return false; 410 } 411 412 pmSubtractionVisualPlotStamps(*stamps, (pmReadout *) ro1); 413 return true; 414 } 415 416 pmSubtractionStampList *pmSubtractionStampsFind(pmSubtractionStampList *stamps, 417 const psImage *image1, 418 const psImage *image2, 419 const psImage *subMask, 420 const psRegion *region, 421 float thresh1, 422 float thresh2, 423 int size, 424 int footprint, 425 float spacing, 426 float normFrac, 427 float sysErr, 428 float skyErr, 429 pmSubtractionMode mode) 374 430 { 375 431 if (!image1 && !image2) { … … 429 485 stamps = pmSubtractionStampListAlloc(numCols, numRows, region, footprint, spacing, 430 486 normFrac, sysErr, skyErr); 487 } 488 489 // XXX TEST : dump all stars in the stamps here 490 if (0) { 491 FILE *f = fopen ("stamp.dat", "w"); 492 for (int i = 0; i < stamps->num; i++) { 493 psVector *xList = stamps->x->data[i]; 494 psVector *yList = stamps->y->data[i]; // Coordinate lists 495 psVector *fluxList = stamps->flux->data[i]; // List of stamp fluxes 496 497 for (int j = 0; j < xList->n; j++) { 498 fprintf (f, "%d %d %f %f %f\n", i, j, xList->data.F32[j], yList->data.F32[j], fluxList->data.F32[j]); 499 } 500 } 501 fclose (f); 431 502 } 432 503 … … 636 707 } 637 708 709 int nTotal = 0; 710 638 711 // Sort the list by flux, with the brightest last 639 712 for (int i = 0; i < numStamps; i++) { … … 662 735 stamps->y->data[i] = ySorted; 663 736 stamps->flux->data[i] = fluxSorted; 664 } 665 737 nTotal += num; 738 } 739 // fprintf (stderr, "nTotal %d\n", nTotal); 740 666 741 return stamps; 667 742 } 668 743 669 670 bool pmSubtractionStampsGetWindow(pmSubtractionStampList *stamps, int kernelSize) 744 // we are essentially using aperture photometry to determine the photometric match between the 745 // images. we need to choose an appropriate-sized aperture for this analysis. If it is too 746 // large, the measurement will be noisy (and possibly biased) due to the sky noise. If it is 747 // too small, or inconsistent, the measurement will be biased. We use Kron-mag like aperture 748 // scaled by the first radial moment. 749 bool pmSubtractionStampsGetWindow(bool *tryAgain, pmSubtractionStampList *stamps, int kernelSize) 671 750 { 672 751 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); 673 752 PS_ASSERT_INT_NONNEGATIVE(kernelSize, false); 674 753 754 // if we succeed, or fail with an unrecoverable error, do not try again 755 if (tryAgain) { 756 *tryAgain = false; 757 } 758 675 759 int size = stamps->footprint; // Size of postage stamps 676 760 761 // window for moments calculations downstream 762 psFree (stamps->window); 763 stamps->window = psKernelAlloc(-size, size, -size, size); 764 psImageInit(stamps->window->image, 0.0); 765 766 // window1 and window2 are mean stamp images used here to measure the 767 // first radial moment, and thus the normalization window 677 768 psFree (stamps->window1); 678 769 stamps->window1 = psKernelAlloc(-size, size, -size, size); … … 683 774 psImageInit(stamps->window2->image, 0.0); 684 775 685 // Generate a weighting window based on the fwhms (20% larger than the largest) 686 { 687 float fwhm1, fwhm2; 688 689 // XXX this is annoyingly hack-ish 690 pmSubtractionGetFWHMs(&fwhm1, &fwhm2); 691 692 float sigma = 1.5 * PS_MAX(fwhm1, fwhm2) / 2.35; 693 694 psFree (stamps->window); 695 stamps->window = psKernelAlloc(-size, size, -size, size); 696 psImageInit(stamps->window->image, 0.0); 697 698 for (int y = -size; y <= size; y++) { 699 for (int x = -size; x <= size; x++) { 700 stamps->window->kernel[y][x] = exp(-0.5*(x*x + y*y)/(sigma*sigma)); 701 } 702 } 776 // Generate an initial weighting window based on the fwhms (50% larger than the largest) 777 float fwhm1, fwhm2; 778 779 // XXX this is annoyingly hack-ish 780 pmSubtractionGetFWHMs(&fwhm1, &fwhm2); 781 782 float sigma = 1.5 * PS_MAX(fwhm1, fwhm2) / 2.35; 783 784 for (int y = -size; y <= size; y++) { 785 for (int x = -size; x <= size; x++) { 786 stamps->window->kernel[y][x] = exp(-0.5*(x*x + y*y)/(sigma*sigma)); 787 } 703 788 } 704 789 … … 790 875 psTrace("psModules.imcombine", 3, "Window total (2): %f, threshold: %f\n", sum2, (1.0 - stamps->normFrac) * sum2); 791 876 792 # if (1) 793 // this block attempts to calculate the radius based on the first radial moment 877 // attempt to calculate the normalization window based on the first radial moment 794 878 double Sr1 = 0.0; 795 879 double Sr2 = 0.0; … … 809 893 float R2 = Sr2 / Sf2; 810 894 811 stamps->normWindow1 = 2.0*R1; 812 stamps->normWindow2 = 2.0*R2; 813 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "Kron Radii: %f for 1, %f for 2\n", stamps->normWindow1, stamps->normWindow2); 814 815 # else 816 // XXX : this block attempts to calculate the radius by looking at the curve of growth (or something vaguely equivalent). 817 // It did not do very well (though a true curve-of-growth analysis might be better...) 818 bool done1 = false; 819 bool done2 = false; 820 double prior1 = 0.0; 821 double prior2 = 0.0; 822 double delta1o = 1.0; 823 double delta2o = 1.0; 824 for (int radius = 1; radius <= size && !(done1 && done2); radius++) { 825 double within1 = 0.0; 826 double within2 = 0.0; 827 for (int y = -radius; y <= radius; y++) { 828 for (int x = -radius; x <= radius; x++) { 829 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(radius)) { 830 within1 += stamps->window1->kernel[y][x]; 831 } 832 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(radius)) { 833 within2 += stamps->window2->kernel[y][x]; 834 } 835 } 836 } 837 double delta1 = (within1 - prior1) / within1; 838 if (!done1 && (fabs(delta1) < stamps->normFrac)) { 839 // interpolate to the radius at which delta2 is normFrac: 840 stamps->normWindow1 = radius - (stamps->normFrac - delta1) / (delta1o - delta1); 841 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "choosing %f (%d) for 1 (%f : %f)\n", stamps->normWindow1, radius, within1, delta1); 842 done1 = true; 843 } 844 double delta2 = (within2 - prior2) / within2; 845 if (!done2 && (fabs(delta2) < stamps->normFrac)) { 846 // interpolate to the radius at which delta2 is normFrac: 847 stamps->normWindow2 = radius - (stamps->normFrac - delta2) / (delta2o - delta2); 848 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "choosing %f (%d) for 2 (%f : %f)\n", stamps->normWindow2, radius, within2, delta2); 849 done2 = true; 850 } 851 psTrace("psModules.imcombine", 5, "Radius %d: %f (%f) and %f (%f)\n", radius, within1, delta1, within2, delta2); 852 853 prior1 = within1; 854 prior2 = within2; 855 delta1o = delta1; 856 delta2o = delta2; 857 858 // if (!done1 && (within1 > (1.0 - stamps->normFrac) * sum1)) { 859 // stamps->normWindow1 = radius; 860 // done1 = true; 861 // } 862 // if (!done2 && (within2 > (1.0 - stamps->normFrac) * sum2)) { 863 // stamps->normWindow2 = radius; 864 // done2 = true; 865 // } 866 867 } 868 # endif 869 870 psTrace("psModules.imcombine", 3, "Normalisation window radii set to %f and %f\n", stamps->normWindow1, stamps->normWindow2); 871 if (stamps->normWindow1 == 0 || stamps->normWindow1 >= size) { 895 // Compare the Kron Radii (R1 & R2) to above to the FWHMs : if they are too discrepant, we will need to rescale 896 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "Kron Radii vs FWHMs 1: fwhm: %f, kron %f\n", fwhm1, R1); 897 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "Kron Radii vs FWHMs 2: fwhm: %f, kron %f\n", fwhm2, R2); 898 899 // XXX CAREFUL : in pmSubtractionMatch.c:703, we rely on this factor of 2.75.. 900 stamps->normWindow1 = 2.75*R1; 901 stamps->normWindow2 = 2.75*R2; 902 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "Windows from Kron Radii: %f for 1, %f for 2\n", stamps->normWindow1, stamps->normWindow2); 903 904 // if the calculated normWindows are too large, we will fall off the stamps. In this case, we need to try again. 905 if ((stamps->normWindow1 > size) || (stamps->normWindow2 > size)) { 906 if (tryAgain) { 907 *tryAgain = true; 908 } 909 psFree (stats); 910 psFree (flux1); 911 psFree (flux2); 912 psFree (norm1); 913 psFree (norm2); 914 return false; 915 } 916 917 // this is an unrecoverable error : something really bogus in the data 918 if (stamps->normWindow1 == 0) { 872 919 psError(PM_ERR_STAMPS, true, "Unable to determine normalisation window size (1)."); 920 psFree (stats); 921 psFree (flux1); 922 psFree (flux2); 923 psFree (norm1); 924 psFree (norm2); 873 925 return false; 874 926 } 875 if (stamps->normWindow2 == 0 || stamps->normWindow2 >= size) {927 if (stamps->normWindow2 == 0) { 876 928 psError(PM_ERR_STAMPS, true, "Unable to determine normalisation window size (2)."); 929 psFree (stats); 930 psFree (flux1); 931 psFree (flux2); 932 psFree (norm1); 933 psFree (norm2); 877 934 return false; 935 } 936 937 // Generate a weighting window based on the kron radii 938 float radius = 2.0 * PS_MAX(R1, R2); 939 psImageInit(stamps->window->image, 0.0); 940 941 // we use a top-hat window for the moments analysis 942 for (int y = -size; y <= size; y++) { 943 for (int x = -size; x <= size; x++) { 944 if (hypot(x,y) > radius) continue; 945 stamps->window->kernel[y][x] = 1.0; 946 } 878 947 } 879 948 … … 890 959 } 891 960 } 892 893 #if 0894 {895 psFits *fits = NULL;896 fits = psFitsOpen ("window1.norm.fits", "w");897 psFitsWriteImage (fits, NULL, stamps->window1->image, 0, NULL);898 psFitsClose (fits);899 fits = psFitsOpen ("window2.norm.fits", "w");900 psFitsWriteImage (fits, NULL, stamps->window2->image, 0, NULL);901 psFitsClose (fits);902 }903 #endif904 961 905 962 psFree (stats); … … 1128 1185 continue; 1129 1186 } 1187 1188 // XXX this is somewhat arbitrary... 1189 if (source->errMag > 0.05) continue; 1190 if (fabs(source->psfMag - source->apMag) > 0.5) continue; 1191 1130 1192 if (source->modelPSF) { 1131 1193 x->data.F32[numOut] = source->modelPSF->params->data.F32[PM_PAR_XPOS]; … … 1135 1197 y->data.F32[numOut] = source->peak->yf; 1136 1198 } 1137 // fprintf (stderr, "stamp: %5.1f %5.1f\n", x->data.F32[numOut], y->data.F32[numOut]);1138 1199 numOut++; 1139 1200 } -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionStamps.h
r29543 r30631 1 1 #ifndef PM_SUBTRACTION_STAMPS_H 2 2 #define PM_SUBTRACTION_STAMPS_H 3 4 #include <pslib.h>5 6 #include "pmSubtractionKernels.h"7 8 /// Status of stamp9 typedef enum {10 PM_SUBTRACTION_STAMP_INIT, ///< Initial state11 PM_SUBTRACTION_STAMP_FOUND, ///< Found a suitable source for this stamp12 PM_SUBTRACTION_STAMP_CALCULATE, ///< Calculate matrix and vector values for this stamp13 PM_SUBTRACTION_STAMP_USED, ///< Use this stamp14 PM_SUBTRACTION_STAMP_REJECTED, ///< This stamp has been rejected15 PM_SUBTRACTION_STAMP_NONE ///< No stamp in this region16 } pmSubtractionStampStatus;17 18 /// A list of stamps19 typedef struct {20 long num; ///< Number of stamps21 psArray *stamps; ///< The stamps22 psArray *regions; ///< Regions for each stamp23 psArray *x, *y; ///< Coordinates for possible stamps (or NULL)24 psArray *flux; ///< Fluxes for possible stamps (or NULL)25 int footprint; ///< Half-size of stamps26 float normFrac; ///< Fraction of flux in window for normalisation window27 float normValue; ///< calculated normalization28 float normValue2; ///< calculated normalization29 psKernel *window1; ///< window function generated from ensemble of stamps (input 1)30 psKernel *window2; ///< window function generated from ensemble of stamps (input 2)31 psKernel *window; ///< weighting window function (sigma = 1.1 * MAX(fwhm))32 float normWindow1; ///< Size of window for measuring normalisation33 float normWindow2; ///< Size of window for measuring normalisation34 float sysErr; ///< Systematic error35 float skyErr; ///< increase effective readnoise36 } pmSubtractionStampList;37 3 38 4 /// Allocate a list of stamps … … 74 40 ); 75 41 76 77 /// A stamp for image subtraction78 typedef struct {79 float x, y; ///< Position80 float flux; ///< Flux81 float xNorm, yNorm; ///< Normalised position82 psKernel *image1; ///< Reference image postage stamp83 psKernel *image2; ///< Input image postage stamp84 psKernel *weight; ///< Weight image (1/variance) postage stamp, or NULL85 psArray *convolutions1; ///< Convolutions of image 1 for each kernel component, or NULL86 psArray *convolutions2; ///< Convolutions of image 2 for each kernel component, or NULL87 psImage *matrix; ///< Least-squares matrix, or NULL88 psVector *vector; ///< Least-squares vector, or NULL89 double norm; ///< Normalisation difference90 double normI1; ///< Sum(flux) for image 191 double normI2; ///< Sum(flux) for image 292 double normSquare1; ///< Sum(flux^2) for image 1 (used for penalty)93 double normSquare2; ///< Sum(flux^2) for image 2 (used for penalty)94 pmSubtractionStampStatus status; ///< Status of stamp95 psVector *MxxI1; ///< second moments of convolution images96 psVector *MyyI1; ///< second moments of convolution images97 psVector *MxxI2; ///< second moments of convolution images98 psVector *MyyI2; ///< second moments of convolution images99 double MxxI1raw;100 double MyyI1raw;101 double MxxI2raw;102 double MyyI2raw;103 } pmSubtractionStamp;104 105 42 /// Allocate a stamp 106 43 pmSubtractionStamp *pmSubtractionStampAlloc(void); 44 45 // find and extract the stamps 46 bool pmSubtractionStampsSelect(pmSubtractionStampList **stamps, // Stamps to read 47 const pmReadout *ro1, // Readout 1 48 const pmReadout *ro2, // Readout 2 49 const psImage *subMask, // Mask for subtraction, or NULL 50 psImage *variance, // Variance map 51 const psRegion *region, // Region of interest 52 float thresh1, // Threshold for stamp finding on readout 1 53 float thresh2, // Threshold for stamp finding on readout 2 54 float stampSpacing, // Spacing between stamps 55 float normFrac, // Fraction of flux in window for normalisation window 56 float sysError, // Relative systematic error in images 57 float skyError, // Relative systematic error in images 58 int size, // Kernel half-size 59 int footprint, // Convolution footprint for stamps 60 pmSubtractionMode mode // Mode for subtraction 61 ); 62 107 63 108 64 /// Find stamps on an image … … 172 128 /// Calculate the window and normalisation window from the stamps 173 129 bool pmSubtractionStampsGetWindow( 130 bool *tryAgain, ///< re-try with new stamp size? 174 131 pmSubtractionStampList *stamps, ///< List of stamps 175 132 int kernelSize ///< Half-size of kernel -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionThreads.c
r27365 r30631 6 6 #include <pslib.h> 7 7 8 #include "pmSubtractionTypes.h" 8 9 #include "pmSubtractionMatch.h" 9 10 #include "pmSubtractionEquation.h" … … 33 34 34 35 { 35 psThreadTask *task = psThreadTaskAlloc("PSMODULES_SUBTRACTION_CALCULATE_EQUATION", 4);36 psThreadTask *task = psThreadTaskAlloc("PSMODULES_SUBTRACTION_CALCULATE_EQUATION", 3); 36 37 task->function = &pmSubtractionCalculateEquationThread; 38 psThreadTaskAdd(task); 39 psFree(task); 40 } 41 42 { 43 psThreadTask *task = psThreadTaskAlloc("PSMODULES_SUBTRACTION_CONVOLVE_STAMP", 3); 44 task->function = &pmSubtractionConvolveStampThread; 37 45 psThreadTaskAdd(task); 38 46 psFree(task); -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionVisual.c
r29600 r30631 16 16 17 17 #include "pmKapaPlots.h" 18 #include "pmFPA.h" 19 #include "pmSubtractionTypes.h" 18 20 #include "pmSubtraction.h" 19 21 #include "pmSubtractionStamps.h" 20 22 #include "pmSubtractionEquation.h" 21 23 #include "pmSubtractionKernels.h" 24 #include "pmSubtractionVisual.h" 22 25 23 26 #include "pmVisual.h" … … 210 213 psImageOverlaySection(canvas, im, x0, y0, "="); 211 214 stampNum++; 215 216 // renormalize the section 217 float maxValue = 0; 218 for (int iy = 0; iy < im->numRows; iy++) { 219 for (int ix = 0; ix < im->numCols; ix++) { 220 maxValue = PS_MAX(maxValue, im->data.F64[iy][ix]); 221 } 222 } 223 if (maxValue == 0.0) continue; 224 for (int iy = 0; iy < im->numRows; iy++) { 225 for (int ix = 0; ix < im->numCols; ix++) { 226 canvas->data.F64[y0 + iy][x0 + ix] /= maxValue; 227 } 228 } 212 229 } 213 230 … … 231 248 } 232 249 250 /** Plot the least-squares matrix of each stamp */ 251 bool pmSubtractionVisualPlotLeastSquaresResid (const pmSubtractionStampList *stamps, psImage *matrixIn, int nUsed) { 252 253 if (!pmVisualTestLevel("ppsub.chisq", 1)) return true; 254 255 if (!plotLeastSquares) return true; 256 257 if (!pmVisualInitWindow (&kapa1, "PPSub:Images")) { 258 return false; 259 } 260 261 psImage *matrixNorm = psImageCopy(NULL, matrixIn, PS_TYPE_F64); 262 { 263 // renormalize the matrix 264 float maxValue = 0; 265 for (int iy = 0; iy < matrixNorm->numRows; iy++) { 266 for (int ix = 0; ix < matrixNorm->numCols; ix++) { 267 maxValue = PS_MAX(maxValue, matrixNorm->data.F64[iy][ix]); 268 } 269 } 270 for (int iy = 0; iy < matrixNorm->numRows; iy++) { 271 for (int ix = 0; ix < matrixNorm->numCols; ix++) { 272 matrixNorm->data.F64[iy][ix] /= maxValue; 273 } 274 } 275 } 276 277 // Find the stamp size 278 int imageMax = -1; 279 int numStamps = 0; 280 psElemType type = PS_TYPE_F64; 281 282 for(int i = 0; i < stamps->num; i++) { 283 pmSubtractionStamp *stamp = stamps->stamps->data[i]; 284 if (stamp == NULL) continue; 285 286 psImage *im = stamp->matrix; 287 if (im == NULL) continue; 288 289 imageMax = PS_MAX(imageMax, im->numCols); 290 imageMax = PS_MAX(imageMax, im->numRows); 291 numStamps++; 292 type = im->type.type; 293 } 294 if (imageMax == -1) return false; 295 296 int border = 15; 297 imageMax += border; 298 int tileRowCount = (int) ceil(sqrt(numStamps)); 299 int canvasX = tileRowCount * (imageMax); 300 int canvasY = tileRowCount * (imageMax); 301 psImage *canvas = psImageAlloc (canvasX, canvasY, type); 302 psImageInit (canvas, NAN); 303 304 // overlay the images 305 int stampNum = 0; 306 int stampListNum = 0; 307 while (stampNum < numStamps) { 308 int x0 = (imageMax) * (stampNum % tileRowCount); 309 int y0 = (imageMax) * (stampNum / tileRowCount); 310 311 pmSubtractionStamp *stamp = stamps->stamps->data[stampListNum++]; 312 if (stamp == NULL) continue; 313 314 psImage *im = stamp->matrix; 315 if (im == NULL) continue; 316 317 stampNum++; 318 319 if (stamp->status != PM_SUBTRACTION_STAMP_USED) continue; 320 321 // renormalize the section 322 float maxValue = 0; 323 for (int iy = 0; iy < im->numRows; iy++) { 324 for (int ix = 0; ix < im->numCols; ix++) { 325 maxValue = PS_MAX(maxValue, im->data.F64[iy][ix]); 326 } 327 } 328 if (maxValue == 0.0) continue; 329 for (int iy = 0; iy < im->numRows; iy++) { 330 for (int ix = 0; ix < im->numCols; ix++) { 331 canvas->data.F64[y0 + iy][x0 + ix] = (im->data.F64[iy][ix] / maxValue - matrixNorm->data.F64[iy][ix]) / matrixNorm->data.F64[iy][ix]; 332 } 333 } 334 } 335 336 psImage *canvas32 = pmVisualImageToFloat(canvas); 337 pmVisualRangeImage(kapa2, canvas32, "Least_Squares", 0, -100.0, 100.0); 338 339 if (0) { 340 static int count = 0; 341 char filename[64]; 342 sprintf (filename, "chisq.%02d.fits", count); 343 count ++; 344 psFits *fits = psFitsOpen (filename, "w"); 345 psFitsWriteImage (fits, NULL, canvas32, 0, NULL); 346 psFitsClose (fits); 347 } 348 349 pmVisualAskUser(&plotLeastSquares); 350 psFree(canvas); 351 psFree(canvas32); 352 return true; 353 } 354 233 355 bool pmSubtractionVisualShowSubtraction(psImage *image, psImage *ref, psImage *sub) { 234 356 … … 304 426 } 305 427 306 // XXX clear the overlay(s) (red at least!) 428 // clear the overlay (red at least!) 429 KiiEraseOverlay (kapa2, "red"); 307 430 308 431 // get the kernel sizes … … 337 460 int nKernels = 0; 338 461 462 // paste in the kernel images, scaled by sum2 339 463 if (maxStamp->convolutions1) { 340 464 // output image is a grid of NXsub by NYsub sub-images … … 359 483 int yPix = ySub * (2*footprint + 1 + 3) + footprint; 360 484 361 double sum = 0.0;362 485 double sum2 = 0.0; 363 486 for (int y = -footprint; y <= footprint; y++) { 364 487 for (int x = -footprint; x <= footprint; x++) { 365 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];366 sum += kernel->kernel[y][x];367 488 sum2 += PS_SQR(kernel->kernel[y][x]); 368 489 } 369 490 } 370 // fprintf (stderr, "kernel %d, sum %f, sum2: %e\n", i, sum, sum2); 491 float scale = sqrt(sum2) / PS_SQR(2*footprint + 1); 492 for (int y = -footprint; y <= footprint; y++) { 493 for (int x = -footprint; x <= footprint; x++) { 494 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x] / scale; 495 } 496 } 371 497 } 372 498 pmVisualScaleImage(kapa2, output, "Image", 0, true); … … 401 527 int yPix = ySub * (2*footprint + 1 + 3) + footprint; 402 528 403 double sum = 0.0;404 529 double sum2 = 0.0; 405 530 for (int y = -footprint; y <= footprint; y++) { 406 531 for (int x = -footprint; x <= footprint; x++) { 407 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];408 sum += kernel->kernel[y][x];409 532 sum2 += PS_SQR(kernel->kernel[y][x]); 410 533 } 411 534 } 412 // fprintf (stderr, "kernel %d, sum %f, sum2: %e\n", i, sum, sum2); 535 float scale = sqrt(sum2) / PS_SQR(2*footprint + 1); 536 for (int y = -footprint; y <= footprint; y++) { 537 for (int x = -footprint; x <= footprint; x++) { 538 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x] / scale; 539 } 540 } 413 541 } 414 542 pmVisualScaleImage(kapa2, output, "Image", 1, true); … … 468 596 KiiLoadOverlay (kapa2, overlay, Noverlay, "red"); 469 597 FREE (overlay); 470 return true;471 }472 473 static int footprint = 0;474 static int NX = 0;475 static int NY = 0;476 static psImage *sourceImage = NULL;477 static psImage *targetImage = NULL;478 static psImage *residualImage = NULL;479 static psImage *fresidualImage = NULL;480 static psImage *differenceImage = NULL;481 static psImage *convolutionImage = NULL;482 483 bool pmSubtractionVisualShowFitInit(pmSubtractionStampList *stamps) {484 485 if (!pmVisualTestLevel("ppsub.fit", 1)) return true;486 487 // generate 4 storage images large enough to hold the N stamps:488 489 footprint = stamps->footprint;490 491 float NXf = sqrt(stamps->num);492 NX = (int) NXf == NXf ? NXf : NXf + 1.0;493 494 float NYf = stamps->num / NX;495 NY = (int) NYf == NY ? NYf : NYf + 1.0;496 497 int NXpix = (2*footprint + 1) * NX;498 NXpix += (NX > 1) ? 3 * NX : 0;499 500 int NYpix = (2*footprint + 1) * NY;501 NYpix += (NY > 1) ? 3 * NY : 0;502 503 sourceImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);504 targetImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);505 residualImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);506 fresidualImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);507 differenceImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);508 convolutionImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);509 510 psImageInit (sourceImage, 0.0);511 psImageInit (targetImage, 0.0);512 psImageInit (residualImage, 0.0);513 psImageInit (fresidualImage, 0.0);514 psImageInit (differenceImage, 0.0);515 psImageInit (convolutionImage, 0.0);516 517 return true;518 }519 520 bool pmSubtractionVisualShowFitAddStamp(psKernel *target, psKernel *source, psKernel *convolution, double background, double norm, int index) {521 522 if (!pmVisualTestLevel("ppsub.stamp", 1)) return true;523 524 double sum;525 526 int NXoff = index % NX;527 int NYoff = index / NX;528 529 int NXpix = NXoff * (2*footprint + 1 + 3) + footprint;530 int NYpix = NYoff * (2*footprint + 1 + 3) + footprint;531 532 // insert the (target) kernel into the (target) image:533 sum = 0.0;534 for (int y = -footprint; y <= footprint; y++) {535 for (int x = -footprint; x <= footprint; x++) {536 targetImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x];537 sum += targetImage->data.F32[y + NYpix][x + NXpix];538 }539 }540 targetImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;541 542 // insert the (source) kernel into the (source) image:543 sum = 0.0;544 for (int y = -footprint; y <= footprint; y++) {545 for (int x = -footprint; x <= footprint; x++) {546 sourceImage->data.F32[y + NYpix][x + NXpix] = source->kernel[y][x];547 sum += sourceImage->data.F32[y + NYpix][x + NXpix];548 }549 }550 sourceImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;551 552 // insert the (convolution) kernel into the (convolution) image:553 sum = 0.0;554 for (int y = -footprint; y <= footprint; y++) {555 for (int x = -footprint; x <= footprint; x++) {556 convolutionImage->data.F32[y + NYpix][x + NXpix] = convolution->kernel[y][x];557 sum += convolutionImage->data.F32[y + NYpix][x + NXpix];558 }559 }560 convolutionImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;561 562 // insert the (difference) kernel into the (difference) image:563 sum = 0.0;564 for (int y = -footprint; y <= footprint; y++) {565 for (int x = -footprint; x <= footprint; x++) {566 differenceImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm;567 sum += differenceImage->data.F32[y + NYpix][x + NXpix];568 }569 }570 differenceImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;571 572 // insert the (residual) kernel into the (residual) image:573 sum = 0.0;574 for (int y = -footprint; y <= footprint; y++) {575 for (int x = -footprint; x <= footprint; x++) {576 residualImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm - convolution->kernel[y][x];577 sum += residualImage->data.F32[y + NYpix][x + NXpix];578 }579 }580 residualImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;581 582 // insert the (fresidual) kernel into the (fresidual) image:583 for (int y = -footprint; y <= footprint; y++) {584 for (int x = -footprint; x <= footprint; x++) {585 fresidualImage->data.F32[y + NYpix][x + NXpix] = residualImage->data.F32[y + NYpix][x + NXpix] / sqrt(PS_MAX(target->kernel[y][x], 100.0));586 }587 }588 598 return true; 589 599 } … … 611 621 } 612 622 613 bool pmSubtractionVisualShowFit(double norm) { 614 615 // for testing, dump the residual image and exit 616 if (0) { 617 psMetadata *header = psMetadataAlloc();618 psMetadataAddF32 (header, PS_LIST_TAIL, "NORM", 0, "Normalization", norm);619 psFits *fits = psFitsOpen("resid.fits", "w");620 psFitsWriteImage(fits, header, residualImage, 0, NULL);621 psFitsClose(fits);622 // exit (0); 623 } 623 static int footprint = 0; 624 static int NX = 0; 625 static int NY = 0; 626 static psImage *sourceImage = NULL; 627 static psImage *targetImage = NULL; 628 static psImage *residualImage = NULL; 629 static psImage *fresidualImage = NULL; 630 static psImage *differenceImage = NULL; 631 static psImage *convolutionImage = NULL; 632 633 bool pmSubtractionVisualShowFit(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels) { 624 634 625 635 if (!pmVisualTestLevel("ppsub.fit", 1)) return true; … … 627 637 if (!pmVisualInitWindow(&kapa1, "ppSub:Images")) return false; 628 638 if (!pmVisualInitWindow(&kapa2, "ppSub:Misc")) return false; 639 640 // set up holding images for the visualization 641 pmSubtractionVisualShowFitInit (stamps); 642 643 int numKernels = kernels->num; // Number of kernels 644 645 psImage *polyValues = NULL; // Polynomial values 646 psKernel *residual = psKernelAlloc(-stamps->footprint, stamps->footprint, -stamps->footprint, stamps->footprint); // Residual image 647 648 double norm = p_pmSubtractionSolutionNorm(kernels); // Normalisation 649 650 for (int i = 0; i < stamps->num; i++) { 651 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // The stamp of interest 652 if (stamp->status != PM_SUBTRACTION_STAMP_USED) { continue; } 653 654 // Calculate coefficients of the kernel basis functions 655 polyValues = p_pmSubtractionPolynomial(polyValues, kernels->spatialOrder, stamp->xNorm, stamp->yNorm); 656 double background = p_pmSubtractionSolutionBackground(kernels, polyValues); // Difference in background 657 658 psImageInit(residual->image, 0.0); 659 660 if (kernels->mode != PM_SUBTRACTION_MODE_DUAL) { 661 psKernel *target; // Target postage stamp 662 psKernel *source; // Source postage stamp 663 psArray *convolutions; // Convolution postage stamps for each kernel basis function 664 switch (kernels->mode) { 665 case PM_SUBTRACTION_MODE_1: 666 target = stamp->image2; 667 source = stamp->image1; 668 convolutions = stamp->convolutions1; 669 break; 670 case PM_SUBTRACTION_MODE_2: 671 target = stamp->image1; 672 source = stamp->image2; 673 convolutions = stamp->convolutions2; 674 break; 675 default: 676 psAbort("Unsupported subtraction mode: %x", kernels->mode); 677 } 678 679 for (int j = 0; j < numKernels; j++) { 680 psKernel *convolution = convolutions->data[j]; // Convolution 681 double coefficient = p_pmSubtractionSolutionCoeff(kernels, polyValues, j, false); // Coefficient 682 for (int y = - footprint; y <= footprint; y++) { 683 for (int x = - footprint; x <= footprint; x++) { 684 residual->kernel[y][x] += convolution->kernel[y][x] * coefficient; 685 } 686 } 687 } 688 // visualize the target, source, convolution and residual 689 pmSubtractionVisualShowFitAddStamp (target, source, residual, background, norm, i); 690 } else { 691 // Dual convolution 692 psArray *convolutions1 = stamp->convolutions1; // Convolutions of the first image 693 psArray *convolutions2 = stamp->convolutions2; // Convolutions of the second image 694 psKernel *image1 = stamp->image1; // The first image 695 psKernel *image2 = stamp->image2; // The second image 696 697 for (int j = 0; j < numKernels; j++) { 698 psKernel *conv1 = convolutions1->data[j]; // Convolution of first image 699 psKernel *conv2 = convolutions2->data[j]; // Convolution of second image 700 double coeff1 = p_pmSubtractionSolutionCoeff(kernels, polyValues, j, false); // Coefficient 1 701 double coeff2 = p_pmSubtractionSolutionCoeff(kernels, polyValues, j, true); // Coefficient 2 702 703 for (int y = - footprint; y <= footprint; y++) { 704 for (int x = - footprint; x <= footprint; x++) { 705 residual->kernel[y][x] += conv2->kernel[y][x] * coeff2 + conv1->kernel[y][x] * coeff1; 706 } 707 } 708 } 709 // visualize the target, source, convolution and residual 710 pmSubtractionVisualShowFitAddStamp (image2, image1, residual, background, norm, i); 711 } 712 } 713 pmSubtractionVisualShowFitImage(norm); 714 715 return true; 716 } 717 718 // generate 4 storage images large enough to hold the stamps: 719 bool pmSubtractionVisualShowFitInit(pmSubtractionStampList *stamps) { 720 721 footprint = stamps->footprint; 722 723 float NXf = sqrt(stamps->num); 724 NX = (int) NXf == NXf ? NXf : NXf + 1.0; 725 726 float NYf = stamps->num / NX; 727 NY = (int) NYf == NY ? NYf : NYf + 1.0; 728 729 int NXpix = (2*footprint + 1) * NX; 730 NXpix += (NX > 1) ? 3 * NX : 0; 731 732 int NYpix = (2*footprint + 1) * NY; 733 NYpix += (NY > 1) ? 3 * NY : 0; 734 735 sourceImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 736 targetImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 737 residualImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 738 fresidualImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 739 differenceImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 740 convolutionImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 741 742 psImageInit (sourceImage, 0.0); 743 psImageInit (targetImage, 0.0); 744 psImageInit (residualImage, 0.0); 745 psImageInit (fresidualImage, 0.0); 746 psImageInit (differenceImage, 0.0); 747 psImageInit (convolutionImage, 0.0); 748 749 return true; 750 } 751 752 bool pmSubtractionVisualShowFitAddStamp(psKernel *target, psKernel *source, psKernel *convolution, double background, double norm, int index) { 753 754 double sum; 755 756 int NXoff = index % NX; 757 int NYoff = index / NX; 758 759 int NXpix = NXoff * (2*footprint + 1 + 3) + footprint; 760 int NYpix = NYoff * (2*footprint + 1 + 3) + footprint; 761 762 // insert the (target) kernel into the (target) image: 763 sum = 0.0; 764 for (int y = -footprint; y <= footprint; y++) { 765 for (int x = -footprint; x <= footprint; x++) { 766 targetImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x]; 767 sum += targetImage->data.F32[y + NYpix][x + NXpix]; 768 } 769 } 770 targetImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; 771 772 // insert the (source) kernel into the (source) image: 773 sum = 0.0; 774 for (int y = -footprint; y <= footprint; y++) { 775 for (int x = -footprint; x <= footprint; x++) { 776 sourceImage->data.F32[y + NYpix][x + NXpix] = source->kernel[y][x]; 777 sum += sourceImage->data.F32[y + NYpix][x + NXpix]; 778 } 779 } 780 sourceImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; 781 782 // insert the (convolution) kernel into the (convolution) image: 783 sum = 0.0; 784 for (int y = -footprint; y <= footprint; y++) { 785 for (int x = -footprint; x <= footprint; x++) { 786 convolutionImage->data.F32[y + NYpix][x + NXpix] = convolution->kernel[y][x]; 787 sum += convolutionImage->data.F32[y + NYpix][x + NXpix]; 788 } 789 } 790 convolutionImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; 791 792 // insert the (difference) kernel into the (difference) image: 793 sum = 0.0; 794 for (int y = -footprint; y <= footprint; y++) { 795 for (int x = -footprint; x <= footprint; x++) { 796 differenceImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm; 797 sum += differenceImage->data.F32[y + NYpix][x + NXpix]; 798 } 799 } 800 differenceImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; 801 802 // insert the (residual) kernel into the (residual) image: 803 sum = 0.0; 804 for (int y = -footprint; y <= footprint; y++) { 805 for (int x = -footprint; x <= footprint; x++) { 806 residualImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm - convolution->kernel[y][x]; 807 sum += residualImage->data.F32[y + NYpix][x + NXpix]; 808 } 809 } 810 residualImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; 811 812 // insert the (fresidual) kernel into the (fresidual) image: 813 for (int y = -footprint; y <= footprint; y++) { 814 for (int x = -footprint; x <= footprint; x++) { 815 fresidualImage->data.F32[y + NYpix][x + NXpix] = residualImage->data.F32[y + NYpix][x + NXpix] / sqrt(PS_MAX(target->kernel[y][x], 100.0)); 816 } 817 } 818 return true; 819 } 820 821 bool pmSubtractionVisualShowFitImage(double norm) { 629 822 630 823 KiiEraseOverlay (kapa1, "red"); … … 673 866 psVector *x = psVectorAllocEmpty (kernels->num, PS_TYPE_F32); 674 867 psVector *y = psVectorAllocEmpty (kernels->num, PS_TYPE_F32); 868 psVector *dy = psVectorAllocEmpty (kernels->num, PS_TYPE_F32); 675 869 676 870 graphdata.xmin = -1.0; … … 685 879 x->data.F32[i] = i; 686 880 y->data.F32[i] = p_pmSubtractionSolutionCoeff(kernels, polyValues, i, false); 881 dy->data.F32[i] = kernels->solution1err->data.F64[i]; 687 882 graphdata.ymin = PS_MIN(graphdata.ymin, y->data.F32[i]); 688 883 graphdata.ymax = PS_MAX(graphdata.ymax, y->data.F32[i]); 689 884 } 690 x->n = y->n = kernels->num;885 x->n = y->n = dy->n = kernels->num; 691 886 692 887 float range; … … 709 904 graphdata.size = 0.5; 710 905 graphdata.style = 2; 906 graphdata.etype |= 0x01; 711 907 712 908 KapaPrepPlot (kapa3, x->n, &graphdata); 713 909 KapaPlotVector (kapa3, x->n, x->data.F32, "x"); 714 910 KapaPlotVector (kapa3, x->n, y->data.F32, "y"); 911 KapaPlotVector (kapa3, x->n, dy->data.F32, "dym"); 912 KapaPlotVector (kapa3, x->n, dy->data.F32, "dyp"); 715 913 716 914 psFree (x); 717 915 psFree (y); 916 psFree (dy); 718 917 psFree (polyValues); 918 919 pmVisualAskUser(NULL); 920 return true; 921 } 922 923 // plot log(flux) vs log(chisq), log(flux) vs log(moments), log(chisq) vs log(moments) 924 bool pmSubtractionVisualPlotChisqAndMoments(psVector *fluxes, psVector *chisq, psVector *moments) { 925 926 Graphdata graphdata; 927 KapaSection section; 928 929 if (!pmVisualTestLevel("ppsub.fit", 1)) return true; 930 931 if (!pmVisualInitWindow(&kapa3, "ppSub:plots")) return false; 932 933 KapaClearSections (kapa3); 934 KapaInitGraph (&graphdata); 935 KiiResize(kapa3, 1500, 500); 936 937 psVector *lchi = psVectorAlloc (fluxes->n, PS_TYPE_F32); 938 psVector *lflx = psVectorAlloc (fluxes->n, PS_TYPE_F32); 939 psVector *lMxx = psVectorAlloc (fluxes->n, PS_TYPE_F32); 940 941 // construct the plot vectors 942 for (int i = 0; i < fluxes->n; i++) { 943 lchi->data.F32[i] = log10(chisq->data.F32[i]); 944 lflx->data.F32[i] = log10(fluxes->data.F32[i]); 945 lMxx->data.F32[i] = log10(moments->data.F32[i]); 946 } 947 948 section.bg = KapaColorByName ("none"); // XXX probably should be 'none' 949 950 // section 1: lflux vs lchi 951 section.dx = 0.33; 952 section.dy = 1.00; 953 section.x = 0.00; 954 section.y = 0.00; 955 section.name = psStringCopy ("flux.v.chi"); 956 KapaSetSection (kapa3, §ion); 957 psFree (section.name); 958 959 graphdata.color = KapaColorByName ("black"); 960 pmVisualScaleGraphdata(&graphdata, lflx, lchi, false); 961 KapaSetLimits (kapa3, &graphdata); 962 963 KapaSetFont (kapa3, "helvetica", 14); 964 KapaBox (kapa3, &graphdata); 965 KapaSendLabel (kapa3, "log(flux)", KAPA_LABEL_XM); 966 KapaSendLabel (kapa3, "log(chisq)", KAPA_LABEL_YM); 967 968 graphdata.color = KapaColorByName ("black"); 969 graphdata.ptype = 2; 970 graphdata.size = 0.5; 971 graphdata.style = 2; 972 973 KapaPrepPlot (kapa3, lflx->n, &graphdata); 974 KapaPlotVector (kapa3, lflx->n, lflx->data.F32, "x"); 975 KapaPlotVector (kapa3, lflx->n, lchi->data.F32, "y"); 976 977 // section 2: lflux vs lMxx 978 section.dx = 0.33; 979 section.dy = 1.00; 980 section.x = 0.33; 981 section.y = 0.00; 982 section.name = psStringCopy ("flux.v.mom"); 983 KapaSetSection (kapa3, §ion); 984 psFree (section.name); 985 986 graphdata.color = KapaColorByName ("black"); 987 pmVisualScaleGraphdata(&graphdata, lflx, lMxx, false); 988 KapaSetLimits (kapa3, &graphdata); 989 990 KapaSetFont (kapa3, "helvetica", 14); 991 KapaBox (kapa3, &graphdata); 992 KapaSendLabel (kapa3, "log(flux)", KAPA_LABEL_XM); 993 KapaSendLabel (kapa3, "log(moments)", KAPA_LABEL_YM); 994 995 graphdata.color = KapaColorByName ("black"); 996 graphdata.ptype = 2; 997 graphdata.size = 0.5; 998 graphdata.style = 2; 999 1000 KapaPrepPlot (kapa3, lflx->n, &graphdata); 1001 KapaPlotVector (kapa3, lflx->n, lflx->data.F32, "x"); 1002 KapaPlotVector (kapa3, lflx->n, lMxx->data.F32, "y"); 1003 1004 // section 1: lflux vs lchi 1005 section.dx = 0.33; 1006 section.dy = 1.00; 1007 section.x = 0.66; 1008 section.y = 0.00; 1009 section.name = psStringCopy ("chi.v.mom"); 1010 KapaSetSection (kapa3, §ion); 1011 psFree (section.name); 1012 1013 graphdata.color = KapaColorByName ("black"); 1014 pmVisualScaleGraphdata(&graphdata, lchi, lMxx, false); 1015 KapaSetLimits (kapa3, &graphdata); 1016 1017 KapaSetFont (kapa3, "helvetica", 14); 1018 KapaBox (kapa3, &graphdata); 1019 KapaSendLabel (kapa3, "log(chisq)", KAPA_LABEL_XM); 1020 KapaSendLabel (kapa3, "log(moments)", KAPA_LABEL_YM); 1021 1022 graphdata.color = KapaColorByName ("black"); 1023 graphdata.ptype = 2; 1024 graphdata.size = 0.5; 1025 graphdata.style = 2; 1026 1027 KapaPrepPlot (kapa3, lflx->n, &graphdata); 1028 KapaPlotVector (kapa3, lflx->n, lchi->data.F32, "x"); 1029 KapaPlotVector (kapa3, lflx->n, lMxx->data.F32, "y"); 719 1030 720 1031 pmVisualAskUser(NULL); -
branches/czw_branch/20101203/psModules/src/imcombine/pmSubtractionVisual.h
r29601 r30631 6 6 bool pmSubtractionVisualPlotStamps(pmSubtractionStampList *stamps, pmReadout *ro); 7 7 bool pmSubtractionVisualPlotLeastSquares(pmSubtractionStampList *stamps); 8 bool pmSubtractionVisualPlotLeastSquaresResid (const pmSubtractionStampList *stamps, psImage *matrixIn, int nUsed); 8 9 bool pmSubtractionVisualShowSubtraction(psImage *image, psImage *ref, psImage *sub); 10 11 bool pmSubtractionVisualShowFit(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels); 9 12 bool pmSubtractionVisualShowFitInit(pmSubtractionStampList *stamps); 10 13 bool pmSubtractionVisualShowFitAddStamp(psKernel *target, psKernel *source, psKernel *convolution, double background, double norm, int index); 11 bool pmSubtractionVisualShowFit(double norm); 14 bool pmSubtractionVisualShowFitImage(double norm); 15 12 16 bool pmSubtractionVisualPlotFit(const pmSubtractionKernels *kernels); 13 17 bool pmSubtractionVisualShowKernels(pmSubtractionKernels *kernels); 14 18 bool pmSubtractionVisualShowBasis(pmSubtractionStampList *stamps); 19 bool pmSubtractionVisualPlotChisqAndMoments(psVector *fluxes, psVector *chisq, psVector *moments); 15 20 16 21 #endif -
branches/czw_branch/20101203/psModules/src/objects
- Property svn:mergeinfo deleted
-
branches/czw_branch/20101203/psModules/src/objects/pmFootprint.c
r29004 r30631 255 255 } 256 256 257 // create a new footprint with the same span set as the input footprint 258 pmFootprint *pmFootprintCopyData(pmFootprint *inFoot, psImage *image) { 259 260 pmFootprint *outFoot = pmFootprintAlloc(inFoot->nspans, image); 261 for (int i = 0; i < inFoot->nspans; i++) { 262 pmSpan *span = inFoot->spans->data[i]; 263 pmFootprintAddSpan(outFoot, span->y, span->x0, span->x1); 264 } 265 return outFoot; 266 } 267 257 268 /************************************************************************************************************/ -
branches/czw_branch/20101203/psModules/src/objects/pmFootprint.h
r29004 r30631 27 27 28 28 bool pmFootprintAllocEmptySpans (pmFootprint *footprint, int nSpans); 29 30 pmFootprint *pmFootprintCopyData(pmFootprint *inFoot, psImage *image); 29 31 30 32 pmFootprint *pmFootprintNormalize(pmFootprint *fp); -
branches/czw_branch/20101203/psModules/src/objects/pmFootprintAssignPeaks.c
r29004 r30631 24 24 /* 25 25 * Given a psArray of pmFootprints and another of pmPeaks, assign the peaks to the 26 * footprints in which th atfall; if they _don't_ fall in a footprint, add a suitable26 * footprints in which they fall; if they _don't_ fall in a footprint, add a suitable 27 27 * one to the list. 28 28 */ … … 83 83 84 84 // XXX are we allowed to have peak-less footprints?? 85 if (!fp->peaks->n) continue; 85 if (fp->peaks->n == 0) continue; 86 if (fp->peaks->n == 1) continue; 86 87 87 88 fp->peaks = psArraySort(fp->peaks, pmPeakSortBySN); 88 89 90 // XXX check for an assert on duplicates (I don't think they can happen, but 91 // let's double check for now) 92 93 for (int j = 1; j < fp->peaks->n; j++) { 94 psAssert (fp->peaks->data[j] != fp->peaks->data[j-1], "duplicate peak!"); 95 } 96 continue; 97 98 // XXX WHY am I culling duplicates? how can there be duplicates? 89 99 // XXX EAM : the algorithm below should be much faster than using psArrayRemove if 90 100 // the number of peaks in the footprint is large, or if there are no duplicates. … … 93 103 94 104 // track the number of good peaks in the footprint 95 int nGood = 1;105 int lastGood = 0; 96 106 97 107 // check for duplicates … … 100 110 // (if sorted list has A, B, A, B ...) 101 111 for (int j = 1; j < fp->peaks->n; j++) { 102 if (fp->peaks->data[j] == fp->peaks->data[ nGood]) {112 if (fp->peaks->data[j] == fp->peaks->data[lastGood]) { 103 113 // everything on the array has its own mem reference; free and drop this one 104 114 psFree (fp->peaks->data[j]); 105 115 fp->peaks->data[j] = NULL; 106 116 } else { 107 nGood ++;117 lastGood ++; 108 118 } 109 119 } 120 int nGood = lastGood + 1; 110 121 111 122 // no deleted peaks, go to next footprint -
branches/czw_branch/20101203/psModules/src/objects/pmFootprintCullPeaks.c
r29004 r30631 28 28 * Examine the peaks in a pmFootprint, and throw away the ones that are not sufficiently 29 29 * isolated. More precisely, for each peak find the highest coll that you'd have to traverse 30 * to reach a still higher peak --- and if that coll's more than nsigma DN below your30 * to reach a still higher peak --- and if that coll's more (less?) than nsigma DN below your 31 31 * starting point, discard the peak. 32 32 */ … … 99 99 float threshold = flux - nsigma_delta*stdev_pad; 100 100 101 if (isnan(threshold) || threshold < min_threshold) {101 if (isnan(threshold)) { 102 102 // min_threshold is assumed to be below the detection threshold, 103 103 // so all the peaks are pmFootprint, and this isn't the brightest … … 109 109 threshold = subImg->data.F32[y][x] - 10*FLT_EPSILON; 110 110 } 111 112 if (threshold < min_threshold) { 113 threshold = min_threshold; 114 } 111 115 112 116 // init peakFootprint here? -
branches/czw_branch/20101203/psModules/src/objects/pmModel.c
r29004 r30631 70 70 tmp->fitRadius = 0; 71 71 tmp->flags = PM_MODEL_STATUS_NONE; 72 tmp->residuals = NULL; // XXX should the model own this memory? 72 tmp->residuals = NULL; // do not free: the model does not own this memory 73 tmp->isPCM = false; 73 74 74 75 psS32 Nparams = pmModelClassParameterCount(type); … … 108 109 pmModel *pmModelCopy (pmModel *model) 109 110 { 110 PS_ASSERT_PTR_NON_NULL(model, NULL); 111 111 if (model == NULL) { 112 return NULL; 113 } 112 114 pmModel *new = pmModelAlloc (model->type); 113 115 -
branches/czw_branch/20101203/psModules/src/objects/pmModel.h
r29004 r30631 43 43 float fitRadius; ///< fit radius actually used 44 44 pmResiduals *residuals; ///< normalized PSF residuals 45 bool isPCM; ///< is this model fitted with PSF-convolution? 45 46 46 47 // functions for this model which depend on the model class -
branches/czw_branch/20101203/psModules/src/objects/pmPCMdata.h
r29004 r30631 83 83 pmPCMdata *pcm); 84 84 85 psKernel *pmPCMkernelFromPSF (pmSource *source, int nPix); 86 85 87 bool pmSourceModelGuessPCM (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal); 86 88 -
branches/czw_branch/20101203/psModules/src/objects/pmPSFtry.c
r29004 r30631 84 84 85 85 for (int i = 0; i < sources->n; i++) { 86 test->sources->data[i] = pmSourceCopy (sources->data[i]); 86 pmSource *sourceOld = sources->data[i]; 87 pmSource *sourceNew = pmSourceCopy (sourceOld); 88 89 // save a reference so we can get back to the original 90 // this is specifically used in psphotChooosePSF to unflag the candidate PSF sources 91 // which were not actually used to generate a PSF model 92 sourceNew->parent = sourceOld; 93 94 test->sources->data[i] = sourceNew; 87 95 } 88 96 -
branches/czw_branch/20101203/psModules/src/objects/pmPSFtryFitEXT.c
r29004 r30631 65 65 if (!source->moments) { 66 66 psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_EXT_FAIL; 67 psTrace ("psModules.objects", 4, "masking %d (%d,%d) : no moments\n", i, source->peak->x, source->peak->y); 67 68 continue; 68 69 } 69 70 if (!source->moments->nPixels) { 71 psTrace ("psModules.objects", 4, "masking %d (%d,%d) : no pixels\n", i, source->peak->x, source->peak->y); 70 72 psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_EXT_FAIL; 71 73 continue; … … 74 76 source->modelEXT = pmSourceModelGuess (source, options->type); 75 77 if (source->modelEXT == NULL) { 78 psTrace ("psModules.objects", 4, "masking %d (%d,%d) : failed to generate model guess\n", i, source->peak->x, source->peak->y); 76 79 psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_EXT_FAIL; 77 psTrace ("psModules.objects", 4, "masking %d (%d,%d) : failed to generate model guess\n", i, source->peak->x, source->peak->y);78 80 continue; 79 81 } … … 91 93 // exclude the poor fits 92 94 if (!status) { 95 psTrace ("psModules.objects", 4, "masking %d (%d,%d) : status is poor\n", i, source->peak->x, source->peak->y); 93 96 psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_EXT_FAIL; 94 psTrace ("psModules.objects", 4, "masking %d (%d,%d) : status is poor\n", i, source->peak->x, source->peak->y);95 97 continue; 96 98 } -
branches/czw_branch/20101203/psModules/src/objects/pmPSFtryFitPSF.c
r29004 r30631 81 81 if (source->modelPSF == NULL) { 82 82 psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_BAD_MODEL; 83 psTrace ("psModules.objects", 4, "dropping %d (%d,%d) : bad PSF fit\n", i, source->peak->x, source->peak->y); 83 84 continue; 84 85 } -
branches/czw_branch/20101203/psModules/src/objects/pmPSFtryModel.c
r30118 r30631 52 52 // mask values indicate the reason the source was rejected: 53 53 54 // XXX some test code (delete eventually) 55 // bool countMaskedSources(pmPSFtry *try, char *msg) { 56 // 57 // int N1 = 0; 58 // int N2 = 0; 59 // for (int i = 0; i < try->sources->n; i++) { 60 // pmSource *source = try->sources->data[i]; 61 // // fprintf (stderr, "%llx : %d\n", (long long int) source, (source->mode & PM_SOURCE_MODE_PSFSTAR)); 62 // if (source->mode & PM_SOURCE_MODE_PSFSTAR) { 63 // N1 ++; 64 // } 65 // if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 66 // N2 ++; 67 // } 68 // } 69 // fprintf (stderr, "%s : masked: %d or %d of %ld\n", msg, N1, N2, try->sources->n); 70 // return true; 71 // } 72 54 73 // generate a pmPSFtry with a copy of the test PSF sources 55 74 pmPSFtry *pmPSFtryModel (const psArray *sources, const char *modelName, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal) … … 203 222 chisq->data.F32[i] = 0.0; 204 223 mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff; 224 psTrace ("psModules.objects", 4, "dropping %d (%d,%d) : no PSF model\n", i, source->peak->x, source->peak->y); 205 225 } else { 206 226 flux->data.F32[i] = source->modelPSF->params->data.F32[PM_PAR_I0]; -
branches/czw_branch/20101203/psModules/src/objects/pmSource.c
r30118 r30631 61 61 psFree(tmp->moments); 62 62 psFree(tmp->diffStats); 63 psFree(tmp->radial );63 psFree(tmp->radialAper); 64 64 psFree(tmp->blends); 65 65 psTrace("psModules.objects", 10, "---- end ----\n"); … … 126 126 source->extpars = NULL; 127 127 source->diffStats = NULL; 128 source->radial = NULL; 128 source->radialAper = NULL; 129 source->parent = NULL; 129 130 130 131 source->region = psRegionSet(NAN, NAN, NAN, NAN); … … 159 160 affecting the original. This Copy can be used to allow multiple fit attempts on the same 160 161 object. The pixels, variance, and mask arrays all point to the same original subarrays. The 161 peak and moments point at the original values. 162 peak and moments point at the original values. The models, blends, and XXX are NOT copied 162 163 *****************************************************************************/ 163 164 pmSource *pmSourceCopy(pmSource *in) … … 167 168 } 168 169 pmSource *source = pmSourceAlloc (); 169 170 // keep the original ID so we can find map back to the original171 P_PM_SOURCE_SET_ID(source, in->id);172 170 173 171 // peak has the same values as the original … … 203 201 } 204 202 205 /******************************************************************************206 pmSourceCopyData(): this creates a new, duplicate source with the same parameters as the207 original (but is actually a new source at the same location)208 *****************************************************************************/209 pmSource *pmSourceCopyData(pmSource *in)210 {211 if (in == NULL) {212 return(NULL);213 }214 // this copy is used to allow multiple fit attempts on the215 // same object. the pixels, variance, and mask arrays all point to216 // the same original subarrays. the peak and moments point at217 // the original values.218 pmSource *source = pmSourceAlloc ();219 220 // this is actually the same peak as the original, is this the correct way to handle this?221 if (in->peak != NULL) {222 source->peak = pmPeakAlloc (in->peak->x, in->peak->y, in->peak->value, in->peak->type);223 source->peak->xf = in->peak->xf;224 source->peak->yf = in->peak->yf;225 source->peak->flux = in->peak->flux;226 source->peak->SN = in->peak->SN;227 }228 229 // copy the values in the moments structure230 if (in->moments != NULL) {231 source->moments = pmMomentsAlloc();232 *source->moments = *in->moments;233 }234 235 // These images are all views to the parent.236 // We want a new view, but pointing at the same pixels.237 source->pixels = psImageCopyView(NULL, in->pixels);238 source->variance = psImageCopyView(NULL, in->variance);239 source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL;240 241 // the maskObj is a unique mask array; create a new mask image242 source->maskObj = in->maskObj ? psImageCopy (NULL, in->maskObj, PS_TYPE_IMAGE_MASK) : NULL;243 244 source->type = in->type;245 source->mode = in->mode;246 source->imageID = in->imageID;247 248 return(source);249 }250 251 203 // x,y are defined in the parent image coords of readout->image 252 204 bool pmSourceDefinePixels(pmSource *mySource, … … 300 252 newRegion = psRegionForImage (readout->image, newRegion); 301 253 254 // re-define if required by region or absence of pixels 302 255 extend = false; 303 256 extend |= (int)(newRegion.x0) < (int)(mySource->region.x0); … … 335 288 } 336 289 return extend; 290 } 291 292 bool pmSourceRedefinePixelsByRegion(pmSource *mySource, 293 const pmReadout *readout, 294 psRegion newRegion) 295 { 296 PS_ASSERT_PTR_NON_NULL(mySource, false); 297 PS_ASSERT_PTR_NON_NULL(readout, false); 298 PS_ASSERT_PTR_NON_NULL(readout->image, false); 299 300 // re-create the subimage 301 psFree (mySource->pixels); 302 psFree (mySource->variance); 303 psFree (mySource->maskView); 304 305 mySource->pixels = psImageSubset(readout->image, newRegion); 306 mySource->variance = psImageSubset(readout->variance, newRegion); 307 mySource->maskView = psImageSubset(readout->mask, newRegion); 308 mySource->region = newRegion; 309 310 // re-copy the main mask pixels. NOTE: the user will need to reset the object mask 311 // pixels (eg, with psImageKeepCircle) 312 mySource->maskObj = psImageCopy (mySource->maskObj, mySource->maskView, PS_TYPE_IMAGE_MASK); 313 314 // drop the old modelFlux pixels and force the user to re-create 315 psFree (mySource->modelFlux); 316 mySource->modelFlux = NULL; 317 318 // drop the old psfImage pixels and force the user to re-create 319 psFree (mySource->psfImage); 320 mySource->psfImage = NULL; 321 322 return true; 337 323 } 338 324 … … 675 661 if ((source->moments->SN > PSF_SN_LIM) && (radius < PSF_CLUMP_NSIGMA)) { 676 662 source->type = PM_SOURCE_TYPE_STAR; 677 source-> mode |= PM_SOURCE_MODE_PSFSTAR;663 source->tmpFlags |= PM_SOURCE_TMPF_CANDIDATE_PSFSTAR; 678 664 Npsf ++; 679 665 continue; … … 934 920 } 935 921 936 // construct a realization of the source model 937 // XXX this function should optionally save an existing psf image from modelFlux 922 // construct a realization of the PSF model at the location of this source 938 923 bool pmSourceCachePSF (pmSource *source, psImageMaskType maskVal) { 939 924 PS_ASSERT_PTR_NON_NULL(source, false); … … 1020 1005 } 1021 1006 1022 if (!addNoise) { 1023 if (add) { 1024 status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 1025 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 1026 } else { 1027 status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 1028 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 1029 } 1007 if (add) { 1008 status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 1009 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 1010 } else { 1011 status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy); 1012 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 1030 1013 } 1031 1014 -
branches/czw_branch/20101203/psModules/src/objects/pmSource.h
r29546 r30631 35 35 PM_SOURCE_TMPF_SIZE_CR_CANDIDATE = 0x0008, 36 36 PM_SOURCE_TMPF_MOMENTS_MEASURED = 0x0010, 37 PM_SOURCE_TMPF_CANDIDATE_PSFSTAR = 0x0020, 37 38 } pmSourceTmpF; 38 39 … … 42 43 * simplest measurement of a source is the location and flux of the peak pixel 43 44 * associated with the source: 45 * 46 * a pmSource is the information about a (possible) blob of flux in a specific image. A source 47 * may represent an insignificant or undetected source. There may be multiple representations 48 * of an image (eg, alternate smoothed copies); sources on alternate images may have a pointer 49 * to the version on the primary image (source->parent). A set of sources on different, but 50 * related images (eg, multiple exposures or different filters) which (may) represent the same 51 * astronomical object are grouped together with the pmPhotObj type (set pmPhotObj.h). 52 * 53 * A single source may be fitted with multiple models (not at the same time!). The PSF model 54 * fit is a fit of the position (optionally) and the flux to the PSF model at the location of 55 * the source. Alternate model fits are extended source models. The best model fit is used to 56 * subtract the object from the image. 44 57 * 45 58 * XXX do I have to re-organize this (again!) to allow an arbitrary set of extended model fits?? … … 54 67 pmPeak *peak; ///< Description of peak pixel. 55 68 psImage *pixels; ///< Rectangular region including object pixels. 56 psImage *variance; ///< Image variance.69 psImage *variance; ///< Image variance. 57 70 psImage *maskObj; ///< unique mask for this object which marks included pixels associated with objects. 58 71 psImage *maskView; ///< view into global image mask for this object region 59 72 psImage *modelFlux; ///< cached copy of the best model for this source 60 psImage *psfImage; ///< cached copy of the psf model for this source73 psImage *psfImage; ///< cached copy of the psf model for this source 61 74 pmMoments *moments; ///< Basic moments measured for the object. 62 75 pmModel *modelPSF; ///< PSF Model fit (parameters and type) … … 89 102 pmSourceExtendedPars *extpars; ///< extended source parameters 90 103 pmSourceDiffStats *diffStats; ///< extra parameters for difference detections 91 pmSourceRadialApertures *radial; ///< radial flux in circular apertures 104 psArray *radialAper; ///< radial flux in circular apertures 105 pmSource *parent; ///< reference to the master source from which this is derived 92 106 int imageID; 93 107 }; … … 162 176 ); 163 177 178 bool pmSourceRedefinePixelsByRegion ( 179 pmSource *mySource, ///< source to be re-defined 180 const pmReadout *readout, ///< base the source on this readout 181 psRegion newRegion ///< region for source pixel definition 182 ); 183 164 184 /** pmSourcePSFClump() 165 185 * -
branches/czw_branch/20101203/psModules/src/objects/pmSourceExtendedPars.c
r28013 r30631 17 17 #endif 18 18 19 // #include <stdio.h>20 // #include <math.h>21 // #include <string.h>22 19 #include <pslib.h> 23 // #include "pmHDU.h"24 // #include "pmFPA.h"25 // #include "pmFPAMaskWeight.h"26 // #include "pmSpan.h"27 // #include "pmFootprint.h"28 // #include "pmPeaks.h"29 // #include "pmMoments.h"30 // #include "pmResiduals.h"31 // #include "pmGrowthCurve.h"32 // #include "pmTrend2D.h"33 // #include "pmPSF.h"34 // #include "pmModel.h"35 // #include "pmSource.h"36 20 #include "pmSourceExtendedPars.h" 37 21 -
branches/czw_branch/20101203/psModules/src/objects/pmSourceFitPCM.c
r29004 r30631 89 89 if (!fitStatus) pcm->modelConv->flags |= PM_MODEL_STATUS_NONCONVERGE; 90 90 91 // once we have fitted a model, we need to record that this model is a PCM model: 92 pcm->modelConv->isPCM = true; 93 91 94 // models can go insane: reject these 92 95 bool onPic = true; -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO.c
r29546 r30631 59 59 60 60 // lookup the EXTNAME values used for table data and image header segments 61 static bool sourceExtensions(psString *headname, // Extension name for header 62 psString *dataname, // Extension name for data 63 psString *deteffname, // Extension name for detection efficiency 64 psString *xsrcname, // Extension name for extended sources 65 psString *xfitname, // Extension name for extended fits 66 const pmFPAfile *file, // File of interest 67 const pmFPAview *view // View to level of interest 68 ) 61 bool pmSourceIOextnames(psString *headname, // Extension name for image header 62 psString *dataname, // Extension name for PSF table data 63 psString *deteffname, // Extension name for detection efficiency 64 psString *xsrcname, // Extension name for extended non-parametric measurements 65 psString *xfitname, // Extension name for extended fitted measurements 66 psString *xradname, // Extension name for radial apertures 67 const pmFPAfile *file, // File of interest 68 const pmFPAview *view // View to level of interest 69 ) 69 70 { 70 71 bool status; // Status of MD lookup … … 87 88 } 88 89 89 // EXTNAME for table data90 // EXTNAME for PSF table data 90 91 if (dataname) { 91 92 const char *rule = psMetadataLookupStr(&status, menu, "CMF.DATA"); … … 107 108 } 108 109 109 // EXTNAME for extended source data table110 // EXTNAME for extended source non-parametric measurements 110 111 if (xsrcname) { 111 112 const char *rule = psMetadataLookupStr(&status, menu, "CMF.XSRC"); … … 117 118 } 118 119 120 // EXTNAME for extended source fitted measurements 119 121 if (xfitname) { 120 // EXTNAME for extended source data table121 122 const char *rule = psMetadataLookupStr(&status, menu, "CMF.XFIT"); 122 123 if (!rule) { … … 125 126 } 126 127 *xfitname = pmFPAfileNameFromRule (rule, file, view); 128 } 129 130 // EXTNAME for radial apertures 131 if (xradname) { 132 const char *rule = psMetadataLookupStr(&status, menu, "CMF.XRAD"); 133 if (!rule) { 134 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.XRAD in EXTNAME.RULES in camera.config"); 135 return false; 136 } 137 *xradname = pmFPAfileNameFromRule (rule, file, view); 127 138 } 128 139 … … 344 355 status &= pmSourcesWrite_##TYPE##_XFIT (file->fits, readout, sources, file->header, xfitname); \ 345 356 } \ 357 if (xradname) { \ 358 status &= pmSourcesWrite_##TYPE##_XRAD (file->fits, readout, sources, file->header, xradname, recipe); \ 359 } \ 346 360 } 347 361 … … 449 463 bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS"); 450 464 bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS"); 465 bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES"); 451 466 452 467 // define the EXTNAME values for the different data segments: … … 456 471 psString xsrcname = NULL; 457 472 psString xfitname = NULL; 458 if (!sourceExtensions(&headname, &dataname, &deteffname, 459 XSRC_OUTPUT ? &xsrcname : NULL, 460 XFIT_OUTPUT ? &xfitname : NULL, 461 file, view)) { 473 psString xradname = NULL; 474 if (!pmSourceIOextnames(&headname, &dataname, &deteffname, 475 XSRC_OUTPUT ? &xsrcname : NULL, 476 XFIT_OUTPUT ? &xfitname : NULL, 477 XRAD_OUTPUT ? &xradname : NULL, 478 file, view)) { 462 479 return false; 463 480 } … … 539 556 psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname); 540 557 } 541 558 if (xradname) { 559 psMetadataAddStr (outhead, PS_LIST_TAIL, "XRADNAME", PS_META_REPLACE, "name of XRAD table extension", xradname); 560 } 542 561 543 562 // these are case-sensitive since the EXTYPE is case-sensitive … … 563 582 } 564 583 565 566 584 // write out the detection efficiency TABLE segments 567 585 if (deteffname) { … … 583 601 psFree (xsrcname); 584 602 psFree (xfitname); 603 psFree (xradname); 585 604 psFree (deteffname); 586 605 … … 593 612 psFree (xsrcname); 594 613 psFree (xfitname); 614 psFree (xradname); 595 615 psFree (deteffname); 596 616 return false; … … 939 959 psString dataname = NULL; 940 960 psString deteffname = NULL; 941 if (! sourceExtensions(&headname, &dataname, &deteffname, NULL, NULL, file, view)) {961 if (!pmSourceIOextnames(&headname, &dataname, &deteffname, NULL, NULL, NULL, file, view)) { 942 962 return false; 943 963 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO.h
r29546 r30631 30 30 bool pmSourcesWrite_SMPDATA_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 31 31 bool pmSourcesWrite_SMPDATA_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 32 bool pmSourcesWrite_SMPDATA_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 32 33 33 34 bool pmSourcesWrite_PS1_DEV_0(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 34 35 bool pmSourcesWrite_PS1_DEV_0_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 35 36 bool pmSourcesWrite_PS1_DEV_0_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 37 bool pmSourcesWrite_PS1_DEV_0_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 36 38 37 39 bool pmSourcesWrite_PS1_DEV_1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 38 40 bool pmSourcesWrite_PS1_DEV_1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 39 41 bool pmSourcesWrite_PS1_DEV_1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 42 bool pmSourcesWrite_PS1_DEV_1_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 40 43 41 44 bool pmSourcesWrite_PS1_CAL_0(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 42 45 bool pmSourcesWrite_PS1_CAL_0_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 43 46 bool pmSourcesWrite_PS1_CAL_0_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 47 bool pmSourcesWrite_PS1_CAL_0_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 44 48 45 49 bool pmSourcesWrite_CMF_PS1_V1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 46 50 bool pmSourcesWrite_CMF_PS1_V1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 47 51 bool pmSourcesWrite_CMF_PS1_V1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 52 bool pmSourcesWrite_CMF_PS1_V1_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 48 53 49 54 bool pmSourcesWrite_CMF_PS1_V2(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 50 55 bool pmSourcesWrite_CMF_PS1_V2_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 51 56 bool pmSourcesWrite_CMF_PS1_V2_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 57 bool pmSourcesWrite_CMF_PS1_V2_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 52 58 53 59 bool pmSourcesWrite_CMF_PS1_V3(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 54 60 bool pmSourcesWrite_CMF_PS1_V3_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 55 61 bool pmSourcesWrite_CMF_PS1_V3_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 62 bool pmSourcesWrite_CMF_PS1_V3_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 56 63 57 64 bool pmSourcesWrite_CMF_PS1_SV1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 58 65 bool pmSourcesWrite_CMF_PS1_SV1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 59 66 bool pmSourcesWrite_CMF_PS1_SV1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 67 bool pmSourcesWrite_CMF_PS1_SV1_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 60 68 61 69 bool pmSourcesWrite_CMF_PS1_DV1(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 62 70 bool pmSourcesWrite_CMF_PS1_DV1_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 63 71 bool pmSourcesWrite_CMF_PS1_DV1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 72 bool pmSourcesWrite_CMF_PS1_DV1_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 64 73 65 74 bool pmSourcesWrite_CMF_PS1_DV2(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe); 66 75 bool pmSourcesWrite_CMF_PS1_DV2_XSRC(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 67 76 bool pmSourcesWrite_CMF_PS1_DV2_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); 77 bool pmSourcesWrite_CMF_PS1_DV2_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); 68 78 69 79 psArray *pmSourcesReadCMP (char *filename, psMetadata *header); -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_CMF_PS1_DV1.c
r29004 r30631 676 676 return true; 677 677 } 678 679 bool pmSourcesWrite_CMF_PS1_DV1_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 680 { 681 return true; 682 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_CMF_PS1_DV2.c
r29620 r30631 737 737 return true; 738 738 } 739 740 bool pmSourcesWrite_CMF_PS1_DV2_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 741 { 742 return true; 743 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_CMF_PS1_SV1.c
r29019 r30631 20 20 21 21 #include "pmConfig.h" 22 #include "pmErrorCodes.h" 22 23 #include "pmDetrendDB.h" 23 24 … … 71 72 psF32 errMag, chisq, apRadius; 72 73 psS32 nPix, nDOF; 73 char keyword1[80], keyword2[80];74 74 75 75 pmChip *chip = readout->parent->parent; … … 103 103 table = psArrayAllocEmpty (sources->n); 104 104 105 # if (0) 105 106 // we use this just to define the output vectors (which must be present for all objects) 106 107 bool status = false; … … 118 119 psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword2, PS_META_REPLACE, "min radius for SB profile", radMax->data.F32[i]); 119 120 } 120 121 # endif 121 122 122 123 // we write out PSF-fits for all sources, regardless of quality. the source flags tell us the state … … 258 259 psMetadataAdd (row, PS_LIST_TAIL, "FLAGS2", PS_DATA_U32, "psphot analysis flags", source->mode2); 259 260 261 # if (0) 262 // XXX if we have raw radial apertures, write them out here 260 263 psVector *radFlux = psVectorAlloc(radMax->n, PS_TYPE_F32); 261 264 psVector *radFluxErr = psVectorAlloc(radMax->n, PS_TYPE_F32); … … 284 287 psFree (radFluxErr); 285 288 psFree (radFill); 289 # endif 286 290 287 291 // XXX not sure how to get this : need to load Nimages with weight? … … 781 785 return true; 782 786 } 787 788 // **** write out the radial flux values for the sources for a given matched-PSF image 789 // **** how do we distinguish the matched-PSF images from the non-matched version 790 bool pmSourcesWrite_CMF_PS1_SV1_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 791 { 792 793 psArray *table; 794 psMetadata *row; 795 psF32 xPos, yPos; 796 char keyword1[80], keyword2[80]; 797 798 // create a header to hold the output data 799 psMetadata *outhead = psMetadataAlloc (); 800 801 // write the links to the image header 802 psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "radial flux table extension", extname); 803 804 // we use this just to define the output vectors (which must be present for all objects) 805 bool status = false; 806 psVector *radMin = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.LOWER"); 807 psVector *radMax = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.UPPER"); 808 psAssert (radMax, "this must have been defined and tested earlier!"); 809 psAssert (radMax->n, "this must have been defined and tested earlier!"); 810 psAssert (radMin->n == radMax->n, "inconsistent annular bins"); 811 812 // write the radial profile apertures to header 813 for (int i = 0; i < radMax->n; i++) { 814 sprintf (keyword1, "RMIN_%02d", i); 815 sprintf (keyword2, "RMAX_%02d", i); 816 psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword1, PS_META_REPLACE, "min radius for SB profile", radMin->data.F32[i]); 817 psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword2, PS_META_REPLACE, "min radius for SB profile", radMax->data.F32[i]); 818 } 819 820 psVector *fwhmValues = psMetadataLookupVector(&status, readout->analysis, "STACK.PSF.FWHM.VALUES"); 821 if (!fwhmValues) { 822 psError (PM_ERR_CONFIG, true, "convolved or measured FWHM is not defined for this readout"); 823 return false; 824 } 825 826 // let's write these out in S/N order 827 sources = psArraySort (sources, pmSourceSortBySN); 828 829 table = psArrayAllocEmpty (sources->n); 830 831 // we write out all sources, regardless of quality. the source flags tell us the state 832 for (int i = 0; i < sources->n; i++) { 833 834 pmSource *source = sources->data[i]; 835 836 // skip sources without radial aper measurements (or insufficient) 837 if (source->radialAper == NULL) continue; 838 psAssert (source->radialAper->n == fwhmValues->n, "inconsistent radial aperture set"); 839 840 for (int entry = 0; entry < fwhmValues->n; entry++) { 841 842 // choose the convolved EXT model, if available, otherwise the simple one 843 pmSourceRadialApertures *radialAper = source->radialAper->data[entry]; 844 assert (radialAper); 845 846 bool useMoments = true; 847 useMoments = (useMoments && source->moments); // can't if there are no moments 848 useMoments = (useMoments && source->moments->nPixels); // can't if the moments were not measured 849 useMoments = (useMoments && !(source->mode && PM_SOURCE_MODE_MOMENTS_FAILURE)); // can't if the moments failed... 850 851 if (useMoments) { 852 xPos = source->moments->Mx; 853 yPos = source->moments->My; 854 } else { 855 xPos = source->peak->xf; 856 yPos = source->peak->yf; 857 } 858 859 row = psMetadataAlloc (); 860 861 // XXX we are not writing out the mode (flags) or the type (psf, ext, etc) 862 psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET", 0, "IPP detection identifier index", source->seq); 863 psMetadataAddF32 (row, PS_LIST_TAIL, "X_APER", 0, "Center of aperture measurements", xPos); 864 psMetadataAddF32 (row, PS_LIST_TAIL, "Y_APER", 0, "Center of aperture measurements", yPos); 865 psMetadataAddF32 (row, PS_LIST_TAIL, "PSF_FWHM", 0, "FWHM of matched PSF", fwhmValues->data.F32[entry]); 866 867 // XXX if we have raw radial apertures, write them out here 868 psVector *radFlux = psVectorAlloc(radMax->n, PS_TYPE_F32); 869 psVector *radFluxErr = psVectorAlloc(radMax->n, PS_TYPE_F32); 870 psVector *radFill = psVectorAlloc(radMax->n, PS_TYPE_F32); 871 psVectorInit (radFlux, NAN); 872 psVectorInit (radFluxErr, NAN); 873 psVectorInit (radFill, NAN); 874 if (!radialAper->flux) goto write_annuli; 875 if (!radialAper->fill) goto write_annuli; 876 psAssert (radialAper->flux->n <= radFlux->n, "inconsistent vector lengths"); 877 psAssert (radialAper->fill->n <= radFlux->n, "inconsistent vector lengths"); 878 879 // copy the data from fluxVal (which is not guaranteed to be the full length) to radFlux 880 for (int j = 0; j < radialAper->flux->n; j++) { 881 radFlux->data.F32[j] = radialAper->flux->data.F32[j]; 882 radFluxErr->data.F32[j] = radialAper->fluxErr->data.F32[j]; 883 radFill->data.F32[j] = radialAper->fill->data.F32[j]; 884 } 885 886 write_annuli: 887 psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX", PS_DATA_VECTOR, "flux within annuli", radFlux); 888 psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX_ERR", PS_DATA_VECTOR, "flux error in annuli", radFluxErr); 889 psMetadataAdd (row, PS_LIST_TAIL, "APER_FILL", PS_DATA_VECTOR, "fill factor of annuli", radFill); 890 psFree (radFlux); 891 psFree (radFluxErr); 892 psFree (radFill); 893 894 psArrayAdd (table, 100, row); 895 psFree (row); 896 } 897 } 898 899 if (table->n == 0) { 900 if (!psFitsWriteBlank (fits, outhead, extname)) { 901 psError(psErrorCodeLast(), false, "Unable to write empty sources file."); 902 psFree(outhead); 903 psFree(table); 904 return false; 905 } 906 psFree (outhead); 907 psFree (table); 908 return true; 909 } 910 911 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 912 if (!psFitsWriteTable (fits, outhead, table, extname)) { 913 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 914 psFree (outhead); 915 psFree(table); 916 return false; 917 } 918 psFree (outhead); 919 psFree (table); 920 return true; 921 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c
r29004 r30631 721 721 return false; 722 722 } 723 724 bool pmSourcesWrite_CMF_PS1_V1_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 725 { 726 return true; 727 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_CMF_PS1_V2.c
r29004 r30631 724 724 return true; 725 725 } 726 727 bool pmSourcesWrite_CMF_PS1_V2_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 728 { 729 return true; 730 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_CMF_PS1_V3.c
r29620 r30631 762 762 return true; 763 763 } 764 765 bool pmSourcesWrite_CMF_PS1_V3_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 766 { 767 return true; 768 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_PS1_CAL_0.c
r29004 r30631 702 702 return true; 703 703 } 704 705 bool pmSourcesWrite_PS1_CAL_0_XRAD (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 706 { 707 return true; 708 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_PS1_DEV_0.c
r29004 r30631 248 248 return true; 249 249 } 250 251 bool pmSourcesWrite_PS1_DEV_0_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 252 { 253 return true; 254 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_PS1_DEV_1.c
r29004 r30631 588 588 return true; 589 589 } 590 591 bool pmSourcesWrite_PS1_DEV_1_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 592 { 593 return true; 594 } -
branches/czw_branch/20101203/psModules/src/objects/pmSourceIO_SMPDATA.c
r29004 r30631 222 222 return true; 223 223 } 224 225 bool pmSourcesWrite_SMPDATA_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 226 { 227 return true; 228 } -
branches/czw_branch/20101203/psModules/src/psmodules.h
r29388 r30631 98 98 // the following headers are from psModule:imcombine 99 99 #include <pmStack.h> 100 #include <pmSubtractionTypes.h> 100 101 #include <pmStackReject.h> 101 102 #include <pmSubtraction.h> -
branches/czw_branch/20101203/psconfig/psbuild
r29559 r30631 13 13 $operations = 0; 14 14 $start = ""; 15 $start_after = ""; 15 16 $stop = ""; 16 17 $verbose = 0; … … 85 86 } 86 87 if ($ARGV[0] eq "-only") { 88 if ($start || $stop || $start_after) { die "do not mix -only (-start, -stop) or (-after, -stop)\n"; } 87 89 $start = $ARGV[1]; 88 90 $stop = $ARGV[1]; … … 90 92 } 91 93 if ($ARGV[0] eq "-start") { 94 if ($start || $start_after) { die "do not mix -only (-start, -stop) or (-after, -stop)\n"; } 92 95 $start = $ARGV[1]; 93 96 shift; shift; next; 94 97 } 98 if ($ARGV[0] eq "-after") { 99 if ($start || $start_after) { die "do not mix -only (-start, -stop) or (-after, -stop)\n"; } 100 $start_after = $ARGV[1]; 101 $start = "INVALID_VALUE"; # need to have a value to skip earlier entries 102 shift; shift; next; 103 } 95 104 if ($ARGV[0] eq "-stop") { 105 if ($stop) { die "do not mix -only (-start, -stop) or (-after, -stop)\n"; } 96 106 $stop = $ARGV[1]; 97 107 shift; shift; next; … … 258 268 $stop_now = 0; 259 269 for ($i = 0; !$stop_now && ($i < @module); $i++) { 260 if (($stop ne "") && ($stop eq $module[$i])) { $stop_now = 1; } 261 if (($start ne "") && ($start ne $module[$i])) { next; } 270 if ($stop && ($stop eq $module[$i])) { $stop_now = 1; } 271 if ($start_after && ($start_after eq $module[$i])) { $start = $module[$i+1]; next; } 272 if ($start && ($start ne $module[$i])) { next; } 262 273 $start = ""; 263 274 … … 348 359 chdir $homedir; 349 360 } 361 if ($start) { if ($start_after) { $start = $start_after; } &failure($start, "unknown -start or -after module $start\n"); } 362 if ($stop && !$stop_now) { &failure($start, "unknown -stop module $stop\n"); } 363 350 364 print "\033]0; ** psbuild: finished ** \007"; 351 365 exit 0; -
branches/czw_branch/20101203/psphot
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/psphot/doc/stack.txt
r28013 r30631 1 2 20101221 3 4 psphotStackReadout is now correctly subtracting the PSF models from 5 the images as it measures the radial aperture fluxes. 6 7 Some issues: 8 9 * the source properties get buggered up by the radial aperture flux 10 analysis (we need to re-determine the psf, re-create the source 11 pixels, and re-fit the models (linearly) to subtract them 12 correctly). 13 14 * the standard analysis sequence is not doing a second pass 15 16 * the choice of the best model is ambiguous 17 18 * the radial aperture (and source addition / subtraction) is only 19 using the PSF model 20 21 * make sure psphotEfficiency actually subtracts the inserted fake 22 sources 23 24 * XXX how does the PSF-convolved model work with changing psf models? 25 26 20101207 27 28 header fields for PSPS: 29 30 * stack needs to count # of inputs 31 * propagate the input header to the output image (DONE) 32 * save PSF parameters in header 33 * stack type is only known to the launcher 34 35 * what are we doing for the stack calibrations?? 36 37 skycellID : code 38 surveyID : code 39 filterID : code 40 stackMetaID : stack_id 41 photoCalID : photcode -> number 42 magSat : FSATUR saturation magnitude level ** not correctly set 43 completMag : FLIMIT 95% completion level in mag ** not correctly set 44 stackTypeID : STK_TYPE stack type identifier ** deep stack, nightly stack, best IQ stack? 45 refImageID : identifier of image used as reference for analysis 46 subtrImageID : N/A (stack) identifier of image subtracted to generate difference image 47 analVer : analysis version index ** index for tess_id + skycell_id + filter? 48 nP2Images : NINPUTS number of P2 images contributing to this cell ** missing from input stack 49 astroScat : astrometric scatter for chip ** measure scatter on stack creation? 50 photoScat : photometric scatter for chip ** internal scatter? 51 nAstroRef : number of astrometric reference sources ** (connected to above) 52 nPhoRef : number of photometric reference sources ** same 53 psfFwhm : PSF full width at half maximum ** 0.5(FWHM_MAJ + FWHM_MIN) 54 psfmodelID : * PSFMODEL PSF model identifier ** save the PSF model name in the header 55 psfWidMajor : * FWHM_MAJ PSF parameters 56 psfWidMinor : * FWHM_MIN PSF parameters 57 psfTheta : * ANGLE PSF parameters 58 psfExtra1 : * PSF_EXT1 PSF parameters ** (at field center?) 59 psfExtra2 : * PSF_EXT2 PSF parameters ** (not set for all models) 60 photoZero : local derived photometric zero point 61 photoColor : local derived photometric color term 62 ctype1 : * CTYPE1 name of astrometric projection in RA ** propagate from input stacks 63 ctype2 : * CTYPE2 name of astrometric projection in DEC 64 crval1 : * CRVAL1 RA corresponding to reference pixel 65 crval2 : * CRVAL2 DEC corresponding to reference pixel 66 crpix1 : * CRPIX1 reference pixel value for RA 67 crpix2 : * CRPIX2 reference pixel value for DEC 68 cdelt1 : * CDELT1 scale factor for RA 69 cdelt2 : * CDELT2 scale factor for DEC 70 pc001001 : * PC001001 elements of rotation/Dcale matrix 71 pc001002 : * PC001002 elements of rotation/Dcale matrix 72 pc002001 : * PC002001 elements of rotation/Dcale matrix 73 pc002002 : * PC002002 elements of rotation/Dcale matrix 74 polyOrder : * NPLYTERM polynomial order of astrometry fit ** default to 1 75 pca1x3y0 : * PCA1X3Y0 polynomial coefficients for the astrometric fit 76 pca1x2y1 : * PCA1X2Y1 polynomial coefficients for the astrometric fit 77 pca1x1y2 : * PCA1X1Y2 polynomial coefficients for the astrometric fit 78 pca1x0y3 : * PCA1X0Y3 polynomial coefficients for the astrometric fit 79 pca1x2y0 : * PCA1X2Y0 polynomial coefficients for the astrometric fit 80 pca1x1y1 : * PCA1X1Y1 polynomial coefficients for the astrometric fit 81 pca1x0y2 : * PCA1X0Y2 polynomial coefficients for the astrometric fit 82 pca2x3y0 : * PCA2X3Y0 polynomial coefficients for the astrometric fit 83 pca2x2y1 : * PCA2X2Y1 polynomial coefficients for the astrometric fit 84 pca2x1y2 : * PCA2X1Y2 polynomial coefficients for the astrometric fit 85 pca2x0y3 : * PCA2X0Y3 polynomial coefficients for the astrometric fit 86 pca2x2y0 : * PCA2X2Y0 polynomial coefficients for the astrometric fit 87 pca2x1y1 : * PCA2X1Y1 polynomial coefficients for the astrometric fit 88 pca2x0y2 : * PCA2X0Y2 polynomial coefficients for the astrometric fit 89 calibModNum : calibration modification number 90 dataRelease : Data release 1 91 2 92 20100506: -
branches/czw_branch/20101203/psphot/src/Makefile.am
r30118 r30631 98 98 psphotStackMatchPSFsUtils.c \ 99 99 psphotStackMatchPSFsPrepare.c \ 100 psphotStackMatchPSFsNext.c \ 100 101 psphotStackOptions.c \ 101 102 psphotStackObjects.c \ -
branches/czw_branch/20101203/psphot/src/psphot.h
r30118 r30631 75 75 bool psphotImageQualityReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 76 76 77 bool psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule );78 bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe );77 bool psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule, bool newSources); 78 bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool newSources); 79 79 80 80 bool psphotGuessModels (pmConfig *config, const pmFPAview *view, const char *filerule); … … 260 260 bool psphotVisualShowSourceSize (pmReadout *readout, psArray *sources); 261 261 bool psphotVisualPlotSourceSizeAlt (psMetadata *recipe, psMetadata *analysis, psArray *sources); 262 bool psphotVisualShowResidualImage (pmReadout *readout); 262 bool psphotVisualShowResidualImage (pmReadout *readout, bool reshow); 263 bool psphotVisualShowObjectRegions (pmReadout *readout, psMetadata *recipe, psArray *sources); 263 264 bool psphotVisualPlotApResid (psArray *sources, float mean, float error, bool useApMag); 264 265 bool psphotVisualPlotChisq (psArray *sources); … … 312 313 313 314 int psphotFileruleCount(const pmConfig *config, const char *filerule); 315 bool psphotFileruleCountSet(const pmConfig *config, const char *filerule, int num); 314 316 315 317 bool psphotAddKnownSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *inSources); … … 403 405 bool psphotStackMatchPSFsReadout (pmConfig *config, const pmFPAview *view, psphotStackOptions *options, int index); 404 406 bool psphotStackMatchPSFsPrepare (pmConfig *config, const pmFPAview *view, psphotStackOptions *options, int index); 407 bool psphotStackMatchPSFsNext (bool *smoothAgain, pmConfig *config, const pmFPAview *view, const char *filerule, int lastSize); 408 bool psphotStackMatchPSFsNextReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, psVector *fwhmValues, int lastSize); 405 409 406 410 // psphotStackMatchPSFsUtils … … 426 430 bool psphotRadialApertures (pmConfig *config, const pmFPAview *view, const char *filerule); 427 431 bool psphotRadialAperturesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 428 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax );432 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax, int entry); 429 433 430 434 bool psphotExtendedSourceAnalysisByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule); 431 bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule );435 bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule, int nMatchedPSF); 432 436 433 437 bool psphotStackObjectsUnifyPosition (psArray *objects); … … 440 444 bool psphotCleanInputs (pmConfig *config, const pmFPAview *view, const char *filerule); 441 445 446 bool psphotResetModels (pmConfig *config, const pmFPAview *view, const char *filerule); 447 bool psphotResetModelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 448 449 bool psphotRedefinePixels (pmConfig *config, const pmFPAview *view, const char *filerule); 450 bool psphotRedefinePixelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 451 452 bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc); 453 bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index); 454 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc); 455 442 456 #endif -
branches/czw_branch/20101203/psphot/src/psphotApResid.c
- Property svn:mergeinfo deleted
-
branches/czw_branch/20101203/psphot/src/psphotBlendFit.c
r30118 r30631 187 187 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); 188 188 189 psphotVisualShowResidualImage (readout); 189 psphotVisualShowResidualImage (readout, false); 190 psphotVisualShowObjectRegions (readout, recipe, sources); 190 191 psphotVisualShowFlags (sources); 191 192 -
branches/czw_branch/20101203/psphot/src/psphotCheckStarDistribution.c
r19909 r30631 34 34 pmSource *source = stars->data[i]; 35 35 if (source->peak == NULL) continue; 36 if (!(source-> mode & PM_SOURCE_MODE_PSFSTAR)) continue;36 if (!(source->tmpFlags & PM_SOURCE_TMPF_CANDIDATE_PSFSTAR)) continue; 37 37 38 38 int binX = psImageBinningGetRuffX (binning, source->peak->xf); … … 85 85 if (source->peak == NULL) continue; 86 86 if (source->moments == NULL) continue; 87 if (source-> mode & PM_SOURCE_MODE_PSFSTAR) continue;87 if (source->tmpFlags & PM_SOURCE_TMPF_CANDIDATE_PSFSTAR) continue; 88 88 if (source->mode & PM_SOURCE_MODE_SATSTAR) continue; 89 89 if (source->type != PM_SOURCE_TYPE_STAR) continue; … … 97 97 if (y > Ye) continue; 98 98 99 source-> mode |= PM_SOURCE_MODE_PSFSTAR;99 source->tmpFlags |= PM_SOURCE_TMPF_CANDIDATE_PSFSTAR; 100 100 psArrayAdd (stars, 200, source); 101 101 -
branches/czw_branch/20101203/psphot/src/psphotChoosePSF.c
r30118 r30631 2 2 3 3 // generate a PSF model for inputs without PSF models already loaded 4 bool psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule )4 bool psphotChoosePSF (pmConfig *config, const pmFPAview *view, const char *filerule, bool newSources) 5 5 { 6 6 bool status = true; … … 19 19 for (int i = 0; i < num; i++) { 20 20 if (i == chisqNum) continue; // skip chisq image 21 if (!psphotChoosePSFReadout (config, view, filerule, i, recipe )) {21 if (!psphotChoosePSFReadout (config, view, filerule, i, recipe, newSources)) { 22 22 psError (PSPHOT_ERR_CONFIG, false, "failed to choose a psf model for %s entry %d", filerule, i); 23 23 return false; … … 28 28 29 29 // try PSF models and select best option 30 bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe ) {30 bool psphotChoosePSFReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool newSources) { 31 31 32 32 bool status; … … 50 50 psAssert (detections, "missing detections?"); 51 51 52 psArray *sources = detections->newSources;52 psArray *sources = newSources ? detections->newSources : detections->allSources; 53 53 psAssert (sources, "missing sources?"); 54 54 … … 166 166 for (int i = 0; i < sources->n; i++) { 167 167 pmSource *source = sources->data[i]; 168 if (source-> mode & PM_SOURCE_MODE_PSFSTAR) {169 // keep NSTARS PSF stars , unmark the rest168 if (source->tmpFlags & PM_SOURCE_TMPF_CANDIDATE_PSFSTAR) { 169 // keep NSTARS PSF stars 170 170 if (stars->n < NSTARS) { 171 171 psArrayAdd (stars, 200, source); 172 } else {173 source->mode &= ~PM_SOURCE_MODE_PSFSTAR;174 172 } 175 173 } … … 214 212 psFree(options); 215 213 216 // unset the PSFSTAR flags (none are used): 217 for (int i = 0; i < sources->n; i++) { 218 pmSource *source = sources->data[i]; 219 source->mode &= ~PM_SOURCE_MODE_PSFSTAR; 220 } 214 // no sources are used as PSF stars 221 215 222 216 // XXX set sxx, etc from FWHM in recipe … … 292 286 psLogMsg ("psphot.pspsf", PS_LOG_INFO, "Using guess PSF model"); 293 287 294 // unset the PSFSTAR flags (none are used): 295 for (int i = 0; i < sources->n; i++) { 296 pmSource *source = sources->data[i]; 297 source->mode &= ~PM_SOURCE_MODE_PSFSTAR; 298 } 288 // no sources are used as PSF stars 299 289 300 290 // XXX set sxx, etc from FWHM in recipe … … 322 312 pmPSFtry *try = models->data[bestN]; 323 313 324 // unset the PSFSTAR flag for stars not used for PSF model 325 // XXX a more efficient way of achieving this would be to record a pair of arrays 326 // of the source index and the source id for the psf stars. but that would require we do 327 // not re-sort the source list in the meanwhile 328 int nDrop = 0; 314 // set the PSFSTAR flag for stars used for the PSF model 315 int nKeep = 0; 329 316 for (int i = 0; i < try->sources->n; i++) { 330 317 pmSource *source = try->sources->data[i]; 331 if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 332 // need to find this source in the original list (these are copies, not pointers) 333 for (int j = 0; j < sources->n; j++) { 334 pmSource *realSource = sources->data[j]; 335 if (realSource->id != source->id) continue; 336 realSource->mode &= ~PM_SOURCE_MODE_PSFSTAR; 337 source->mode &= ~PM_SOURCE_MODE_PSFSTAR; 338 nDrop ++; 339 break; 340 } 341 } 342 } 343 // fprintf (stderr, "drop %d stars as PSF stars\n", nDrop); 344 345 // XXX is this working? 346 // int N1 = 0; 347 // for (int i = 0; i < try->sources->n; i++) { 348 // pmSource *source = try->sources->data[i]; 349 // fprintf (stderr, "%llx : %d\n", (long long int) source, (source->mode & PM_SOURCE_MODE_PSFSTAR)); 350 // if (source->mode & PM_SOURCE_MODE_PSFSTAR) { 351 // N1 ++; 352 // } 353 // } 354 // int N2 = 0; 355 // for (int i = 0; i < sources->n; i++) { 356 // pmSource *source = sources->data[i]; 357 // fprintf (stderr, "%llx : %d\n", (long long int) source, (source->mode & PM_SOURCE_MODE_PSFSTAR)); 358 // if (source->mode & PM_SOURCE_MODE_PSFSTAR) { 359 // N2 ++; 360 // } 361 // } 362 // fprintf (stderr, "N1: %d, N2: %d\n", N1, N2); 318 if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue; 319 source->mode |= PM_SOURCE_MODE_PSFSTAR; 320 321 // this source was used: find the parent and set its PSFSTAR flag 322 pmSource *realSource = source->parent; 323 psAssert (realSource, "pmPSFtryAlloc should have set the parent pointers"); 324 realSource->mode |= PM_SOURCE_MODE_PSFSTAR; 325 nKeep ++; 326 } 327 psLogMsg ("psphot.pspsf", PS_LOG_DETAIL, "used %d of %ld candidate PSF objects\n", nKeep, try->sources->n); 363 328 364 329 // build a PSF residual image 330 // we need to use the 'try' set because they have the associated models defined 365 331 if (!psphotMakeResiduals (try->sources, recipe, try->psf, maskVal)) { 366 332 psError(PSPHOT_ERR_PSF, false, "Unable to construct residual table for PSF"); … … 386 352 } 387 353 388 // XXXtest dump of psf star data and psf-subtracted image354 // test dump of psf star data and psf-subtracted image 389 355 if (psTraceGetLevel("psphot.psfstars") > 5) { 390 356 psphotDumpPSFStars (readout, try, options->fitRadius, maskVal, markVal); … … 413 379 return false; 414 380 } 415 psFree (psf); // XXX double-check 416 417 // move into psphotChoosePSF 381 psFree (psf); 382 418 383 psphotVisualShowPSFModel (readout, psf); 419 384 … … 436 401 psVector *fwhmMajor = psVectorAllocEmpty (100, PS_DATA_F32); 437 402 psVector *fwhmMinor = psVectorAllocEmpty (100, PS_DATA_F32); 403 psVector *psfExtra1 = psVectorAllocEmpty (100, PS_DATA_F32); 404 psVector *psfExtra2 = psVectorAllocEmpty (100, PS_DATA_F32); 438 405 439 406 for (float ix = -0.4; ix <= +0.4; ix += 0.1) { … … 459 426 shape.sxy = modelPSF->params->data.F32[PM_PAR_SXY]; 460 427 axes = psEllipseShapeToAxes (shape, 20.0); 461 psFree (modelPSF);462 428 463 429 float FWHM_MINOR = FWHM_MAJOR * (axes.minor / axes.major); 464 430 if (!isfinite(FWHM_MAJOR) || !isfinite(FWHM_MINOR)) { 465 431 fprintf (stderr, "!"); 432 psFree (modelPSF); 466 433 continue; 467 434 } 468 435 psVectorAppend (fwhmMajor, FWHM_MAJOR); 469 436 psVectorAppend (fwhmMinor, FWHM_MINOR); 437 438 if (modelPSF->params->n >= 7) { 439 psVectorAppend (psfExtra1, modelPSF->params->data.F32[7]); 440 } 441 if (modelPSF->params->n >= 8) { 442 psVectorAppend (psfExtra2, modelPSF->params->data.F32[8]); 443 } 444 psFree (modelPSF); 470 445 } 471 446 } … … 474 449 if (!psVectorStats (stats, fwhmMajor, NULL, NULL, 0)) { 475 450 psError(PS_ERR_UNKNOWN, false, "failure to measure stats for FWHM MAJOR"); 476 return false;451 goto escape; 477 452 } 478 453 … … 486 461 if (!psVectorStats (stats, fwhmMinor, NULL, NULL, 0)) { 487 462 psError(PS_ERR_UNKNOWN, false, "failure to measure stats for FWHM MINOR"); 488 return false;463 goto escape; 489 464 } 490 465 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FWHM_MIN", PS_META_REPLACE, "PSF FWHM Minor axis (mean)", stats->sampleMean); … … 494 469 495 470 float fwhmMin = stats->sampleMean; // FWHM on minor axis 471 496 472 if (readout->parent) { 473 474 // we now have 2 possible measurements of the seeing : the PSF model based version and 475 // the Moments based value we need to define a definitive "CHIP.SEEING" value. This 476 // value is used by the PSF-matching programs (ppSub and ppStack). The moments-based 477 // value is probably more representative of the value needed by those tools (it is also 478 // more stable?) 479 bool status = false; 480 float fwhmMajorMoments = psMetadataLookupF32(&status, readout->analysis, "IQ_FW1"); 481 float fwhmMinorMoments = psMetadataLookupF32(&status, readout->analysis, "IQ_FW1"); 482 497 483 pmChip *chip = readout->parent->parent; // Parent chip 498 484 psAssert(chip, "Cell should be attached to a chip."); 499 485 psMetadataItem *item = psMetadataLookup(chip->concepts, "CHIP.SEEING"); // Item with chip 500 item->data.F32 = 0.5 * (fwhmMaj + fwhmMin); 486 item->data.F32 = 0.5 * (fwhmMajorMoments + fwhmMinorMoments); 487 488 psLogMsg ("psphot", PS_LOG_DETAIL, "fwhm (psf): %f,%f (moments): %f,%f", fwhmMaj, fwhmMin, fwhmMajorMoments, fwhmMinorMoments); 489 } 490 491 if (psfExtra1->n) { 492 if (!psVectorStats (stats, psfExtra1, NULL, NULL, 0)) { 493 psError(PS_ERR_UNKNOWN, false, "failure to measure stats for PSF EXTRA 1"); 494 goto escape; 495 } 496 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "PSF_EXT1", PS_META_REPLACE, "PSF extra param 1", stats->sampleMean); 497 } 498 499 if (psfExtra2->n) { 500 if (!psVectorStats (stats, psfExtra2, NULL, NULL, 0)) { 501 psError(PS_ERR_UNKNOWN, false, "failure to measure stats for PSF EXTRA 2"); 502 goto escape; 503 } 504 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "PSF_EXT2", PS_META_REPLACE, "PSF extra param 2", stats->sampleMean); 501 505 } 502 506 503 507 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "ANGLE", PS_META_REPLACE, "PSF angle", axes.theta); 504 508 psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NPSFSTAR", PS_META_REPLACE, "Number of stars used to make PSF", psf->nPSFstars); 505 psMetadataAddBool(readout->analysis, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "Valid PSF Model?", true); 509 510 char *psfModelName = pmModelClassGetName(psf->type); 511 psMetadataAddStr(readout->analysis, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "PSF Model Name", psfModelName); 512 psMetadataAddBool(readout->analysis, PS_LIST_TAIL, "PSF_OK", PS_META_REPLACE, "Valid PSF Model?", true); 513 514 int nParams = pmModelClassParameterCount(psf->type); 515 psMetadataAddS32(readout->analysis, PS_LIST_TAIL, "PSF_NPAR", PS_META_REPLACE, "Number of PSF parameters", nParams); 506 516 507 517 psFree (fwhmMajor); 508 518 psFree (fwhmMinor); 519 psFree (psfExtra1); 520 psFree (psfExtra2); 509 521 psFree (stats); 510 522 return true; 523 524 escape: 525 psFree (fwhmMajor); 526 psFree (fwhmMinor); 527 psFree (psfExtra1); 528 psFree (psfExtra2); 529 psFree (stats); 530 return false; 511 531 } 512 532 … … 568 588 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MN_LQ", PS_META_REPLACE, "PSF FWHM Minor axis (lower quartile)", 0); 569 589 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "FW_MN_UQ", PS_META_REPLACE, "PSF FWHM Minor axis (upper quartile)", 0); 570 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "ANGLE", PS_META_REPLACE, "PSF angle", FWHM_T); 571 psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NPSFSTAR", PS_META_REPLACE, "Number of stars used to make PSF", 0); 572 psMetadataAddBool(readout->analysis, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "Valid PSF Model?", false); 590 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "ANGLE", PS_META_REPLACE, "PSF angle", FWHM_T); 591 psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NPSFSTAR", PS_META_REPLACE, "Number of stars used to make PSF", 0); 592 psMetadataAddStr(readout->analysis, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "PSF Model Name", "NONE"); 593 psMetadataAddBool(readout->analysis, PS_LIST_TAIL, "PSF_OK", PS_META_REPLACE, "Valid PSF Model?", false); 573 594 574 595 return true; -
branches/czw_branch/20101203/psphot/src/psphotExtendedSourceAnalysis.c
r30118 r30631 173 173 psLogMsg ("psphot", PS_LOG_INFO, " %d kron\n", Nkron); 174 174 175 psphotVisualShowResidualImage (readout );175 psphotVisualShowResidualImage (readout, false); 176 176 177 177 if (doPetrosian) { -
branches/czw_branch/20101203/psphot/src/psphotExtendedSourceAnalysisByObject.c
r30118 r30631 53 53 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 54 54 psAssert (readout, "missing readout?"); 55 56 psLogMsg("psphot", PS_LOG_INFO, "petrosians for image %d", i); 57 psphotVisualShowImage(readout); 55 58 56 59 readouts->data[i] = psMemIncrRefCounter(readout); -
branches/czw_branch/20101203/psphot/src/psphotExtendedSourceFits.c
r30118 r30631 18 18 int num = psphotFileruleCount(config, filerule); 19 19 20 // skip the chisq image (optionally?) 21 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 22 if (!status) chisqNum = -1; 23 20 24 // loop over the available readouts 21 25 for (int i = 0; i < num; i++) { 26 if (i == chisqNum) continue; // skip chisq image 22 27 if (!psphotExtendedSourceFitsReadout (config, view, filerule, i, recipe)) { 23 28 psError (PSPHOT_ERR_CONFIG, false, "failed on to fit extended sources for %s entry %d", filerule, i); … … 37 42 int Nplain = 0; 38 43 int NplainPass = 0; 44 int Nfaint = 0; 39 45 40 46 psTimerStart ("psphot.extended"); … … 46 52 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 47 53 psAssert (readout, "missing readout?"); 54 55 psLogMsg("psphot", PS_LOG_INFO, "extended source fits for image %d", index); 56 psphotVisualShowImage(readout); 48 57 49 58 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); … … 167 176 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nplain 168 177 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for NplainPass 178 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfain 169 179 170 180 if (false && !psThreadJobAddPending(job)) { … … 189 199 scalar = job->args->data[11]; 190 200 NplainPass += scalar->data.S32; 201 scalar = job->args->data[12]; 202 Nfaint += scalar->data.S32; 191 203 psFree(job); 192 204 } … … 217 229 scalar = job->args->data[11]; 218 230 NplainPass += scalar->data.S32; 231 scalar = job->args->data[12]; 232 Nfaint += scalar->data.S32; 219 233 } 220 234 psFree(job); … … 227 241 psLogMsg ("psphot", PS_LOG_INFO, " %d convolved models (%d passed)\n", Nconvolve, NconvolvePass); 228 242 psLogMsg ("psphot", PS_LOG_INFO, " %d plain models (%d passed)\n", Nplain, NplainPass); 243 psLogMsg ("psphot", PS_LOG_INFO, " %d too faint to fit\n", Nfaint); 229 244 return true; 230 245 } … … 238 253 int NconvolvePass = 0; 239 254 int Nplain = 0; 255 int Nfaint = 0; 240 256 int NplainPass = 0; 241 257 bool savePics = false; … … 326 342 327 343 // array to store the pointers to the model flux images while the models are being fitted 328 psArray *modelFluxes = psArrayAllocEmpty ( 4);344 psArray *modelFluxes = psArrayAllocEmpty (models->list->n); 329 345 330 346 // allocate the array to store the model fits 331 347 if (source->modelFits == NULL) { 332 source->modelFits = psArrayAllocEmpty ( 4);348 source->modelFits = psArrayAllocEmpty (models->list->n); 333 349 } 334 350 … … 350 366 // limit selection to some SN limit 351 367 assert (source->peak); // how can a source not have a peak? 352 if (source->peak->SN < SNlim) continue; 368 if (source->peak->SN < SNlim) { 369 Nfaint ++; 370 continue; 371 } 353 372 354 373 // check on the model type … … 497 516 scalar->data.S32 = NplainPass; 498 517 518 scalar = job->args->data[12]; 519 scalar->data.S32 = Nfaint; 520 499 521 return true; 500 522 } -
branches/czw_branch/20101203/psphot/src/psphotFindDetections.c
r30118 r30631 86 86 psImage *significance = psphotSignificanceImage (readout, recipe, maskVal); 87 87 88 // display the significance image89 psphotVisualShowSignificance (significance, -1.0, PS_SQR(3.0*NSIGMA_PEAK));90 91 88 // display the log significance image 92 89 psphotVisualShowLogSignificance (significance, 0.0, 4.5); 90 91 // display the significance image 92 psphotVisualShowSignificance (significance, 0.98*threshold, 1.02*threshold); 93 93 94 94 // detect the peaks in the significance image … … 108 108 } 109 109 110 // XXX do a second (or third?) pass with rebinning (to detected more extended sources) 111 110 112 psFree (significance); 111 113 -
branches/czw_branch/20101203/psphot/src/psphotFindFootprints.c
r27673 r30631 21 21 psArray *footprints = pmFootprintsFind (significance, threshold, npixMin); 22 22 23 pmFootprintsAssignPeaks(footprints, detections->peaks); 24 // XXX handle the error conditions here 23 if (pmFootprintsAssignPeaks(footprints, detections->peaks) != PS_ERR_NONE) { 24 psAbort ("inconsistent peaks and footprints"); 25 } 25 26 26 27 // footprints now owns the peaks; after culling (below), we will rebuild the peaks array -
branches/czw_branch/20101203/psphot/src/psphotFitSourcesLinear.c
r30118 r30631 46 46 return false; 47 47 } 48 49 psphotVisualShowResidualImage (readout, (num > 0)); 50 psphotVisualShowPeaks (detections); 51 psphotVisualShowObjectRegions (readout, recipe, sources); 48 52 } 49 53 return true; … … 151 155 if (x > AnalysisRegion.x1) continue; 152 156 if (y > AnalysisRegion.y1) continue; 157 158 // check the integral of the model : is it large enough? 159 float modelSum = 0.0; 160 for (int iy = 0; iy < source->modelFlux->numRows; iy++) { 161 for (int ix = 0; ix < source->modelFlux->numCols; ix++) { 162 modelSum += source->modelFlux->data.F32[iy][ix]; 163 } 164 } 165 if (modelSum < 0.5) continue; // skip sources with no model constraint (somewhat arbitrary limit) 166 // if (modelSum < 0.01) continue; // skip sources with no model constraint (somewhat arbitrary limit) 167 if (modelSum < 0.8) { 168 fprintf (stderr, "low-sig model @ %f, %f (%f sum, %f peak)\n", 169 source->peak->xf, source->peak->yf, modelSum, source->peak->flux); 170 } 171 172 pmModel *model = pmSourceGetModel (NULL, source); 173 174 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 175 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, model->fitRadius, "OR", markVal); 153 176 154 177 source->mode |= PM_SOURCE_MODE_LINEAR_FIT; … … 270 293 model->params->data.F32[PM_PAR_I0] = norm->data.F32[i]; 271 294 model->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i]; 272 // XXX is the value of 'errors' modified by the sky fit?273 295 274 296 // subtract object … … 297 319 psLogMsg ("psphot.ensemble", PS_LOG_INFO, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot.linear")); 298 320 299 psphotVisualShowResidualImage (readout);300 321 psphotVisualPlotChisq (sources); 301 322 // psphotVisualShowFlags (sources); -
branches/czw_branch/20101203/psphot/src/psphotFitSourcesLinearStack.c
r29548 r30631 176 176 177 177 psLogMsg ("psphot.ensemble", PS_LOG_INFO, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot.linear")); 178 179 178 return true; 180 179 } -
branches/czw_branch/20101203/psphot/src/psphotImageQuality.c
r30118 r30631 79 79 // select by PSFSTAR mode? 80 80 // ?? 81 if (source->type != PM_SOURCE_TYPE_STAR || !(source-> mode & PM_SOURCE_MODE_PSFSTAR)) {81 if (source->type != PM_SOURCE_TYPE_STAR || !(source->tmpFlags & PM_SOURCE_TMPF_CANDIDATE_PSFSTAR)) { 82 82 psTrace("psphot", 10, "Ignoring source for image quality because not a good star"); 83 83 continue; … … 133 133 if (num == 0) { 134 134 psLogMsg ("psphot", PS_LOG_INFO, "no valid sources for image quality, skipping"); 135 psFree(FWHM_MAJOR); 136 psFree(FWHM_MINOR); 137 psFree(M2); 138 psFree(M2c); 139 psFree(M2s); 140 psFree(M3); 141 psFree(M4); 142 135 143 return true; 136 144 } -
branches/czw_branch/20101203/psphot/src/psphotMakeFluxScale.c
- Property svn:mergeinfo deleted
-
branches/czw_branch/20101203/psphot/src/psphotMakePSFReadout.c
r30118 r30631 60 60 // Use bright stellar objects to measure PSF. If we do not have enough stars to generate 61 61 // the PSF, build one from the SEEING guess and model class 62 if (!psphotChoosePSF (config, view, filerule )) {62 if (!psphotChoosePSF (config, view, filerule, true)) { 63 63 psLogMsg ("psphot", 3, "failure to construct a psf model"); 64 64 return psphotReadoutCleanup (config, view, filerule); -
branches/czw_branch/20101203/psphot/src/psphotMakeResiduals.c
r27532 r30631 136 136 psFree (interp); 137 137 } 138 xSize = PS_MIN(xSize, 2*radiusMax+3); 139 ySize = PS_MIN(ySize, 2*radiusMax+3); 140 138 141 pmResiduals *resid = pmResidualsAlloc (xSize, ySize, xBin, yBin); 139 142 psImageInit (resid->mask, 0); … … 316 319 psFree (B); 317 320 318 psLogMsg ("psphot.pspsf", PS_LOG_ MINUTIA, "generate residuals for %ld objects: %f sec\n", input->n, psTimerMark ("psphot.residuals"));321 psLogMsg ("psphot.pspsf", PS_LOG_DETAIL, "generate residuals for %ld objects: %f sec\n", input->n, psTimerMark ("psphot.residuals")); 319 322 320 323 psFree (xC); -
branches/czw_branch/20101203/psphot/src/psphotMergeSources.c
r30118 r30631 513 513 } 514 514 515 return true; 516 } 517 515 // loop over the sources, redefine their pixels to point at the new filerule image, 516 // copy the source data, and add a reference back to the original source 517 518 519 return true; 520 } 521 522 // create source children from ruleSrc for ruleOut 523 bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc) 524 { 525 bool status = true; 526 527 int num = psphotFileruleCount(config, ruleSrc); 528 529 // skip the chisq image because it is a duplicate of the detection version 530 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 531 if (!status) chisqNum = -1; 532 533 // loop over the available readouts 534 for (int i = 0; i < num; i++) { 535 if (i == chisqNum) continue; // skip chisq image 536 if (!psphotSourceChildrenReadout (config, view, ruleOut, ruleSrc, i)) { 537 psError (PSPHOT_ERR_CONFIG, false, "failed to copy sources from %s to %s entry %d", ruleSrc, ruleOut, i); 538 return false; 539 } 540 } 541 return true; 542 } 543 544 // create source children from ruleSrc for ruleOut for this entry. XXX currently, this is only 545 // used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be called 546 // repeatedly) 547 bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index) { 548 549 bool status; 550 551 // find the currently selected readout 552 pmFPAfile *fileSrc = pmFPAfileSelectSingle(config->files, ruleSrc, index); // File of interest 553 psAssert (fileSrc, "missing file?"); 554 555 pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa); 556 psAssert (readoutSrc, "missing readout?"); 557 558 pmDetections *detectionsSrc = psMetadataLookupPtr (&status, readoutSrc->analysis, "PSPHOT.DETECTIONS"); 559 psAssert (detectionsSrc, "missing detections?"); 560 561 psArray *sourcesSrc = detectionsSrc->allSources; 562 psAssert (sourcesSrc, "missing sources?"); 563 564 // find the currently selected readout 565 pmFPAfile *fileOut = pmFPAfileSelectSingle(config->files, ruleOut, index); // File of interest 566 psAssert (fileOut, "missing file?"); 567 568 pmReadout *readoutOut = pmFPAviewThisReadout(view, fileOut->fpa); 569 psAssert (readoutOut, "missing readout?"); 570 571 // generate a new detection structure for the output filerule 572 pmDetections *detectionsOut = psMetadataLookupPtr (&status, readoutOut->analysis, "PSPHOT.DETECTIONS"); 573 if (!detectionsOut) { 574 detectionsOut = pmDetectionsAlloc(); 575 detectionsOut->allSources = psArrayAllocEmpty (100); 576 // save detections on the readout->analysis 577 if (!psMetadataAddPtr (readoutOut->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detectionsOut)) { 578 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 579 return false; 580 } 581 psFree(detectionsOut); // a copy remains on the analysis metadata 582 } 583 584 // loop over the sources, redefine their pixels to point at the new filerule image, 585 // copy the source data, and add a reference back to the original source 586 587 // copy the sources from sourceSrcs to the new detection structure 588 for (int i = 0; i < sourcesSrc->n; i++) { 589 pmSource *sourceSrc = sourcesSrc->data[i]; 590 591 pmSource *sourceOut = pmSourceCopy(sourceSrc); 592 sourceOut->parent = sourceSrc; 593 594 // keep the original source flags 595 sourceOut->type = sourceSrc->type; 596 sourceOut->mode = sourceSrc->mode; 597 sourceOut->mode2 = sourceSrc->mode2; 598 sourceOut->tmpFlags = sourceSrc->tmpFlags; 599 600 // does this copy all model data? (NO) 601 sourceOut->modelPSF = pmModelCopy(sourceSrc->modelPSF); 602 sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT); 603 604 if (sourceSrc->modelFits) { 605 sourceOut->modelFits = psArrayAlloc(sourceSrc->modelFits->n); 606 for (int j = 0; j < sourceSrc->modelFits->n; j++) { 607 sourceOut->modelFits->data[j] = pmModelCopy(sourceSrc->modelFits->data[j]); 608 } 609 } 610 611 // drop the references to the original image pixels: 612 pmSourceFreePixels (sourceOut); 613 614 // allocate image, weight, mask for the new image for each peak 615 pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius); 616 617 // child sources have not been subtracted in this image, but this flag may be raised if 618 // they were subtracted in the parent's image 619 sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 620 621 psArrayAdd (detectionsOut->allSources, 100, sourceOut); 622 psFree (sourceOut); 623 } 624 psLogMsg ("psphot", 3, "%ld known sources supplied", detectionsOut->allSources->n); 625 626 627 return true; 628 } 629 630 // create source children associated with 'filerule' from the objectsSrc. XXX currently, this 631 // is only used by psphotStackReadout (sources go on allSources so that psphotChoosePSF can be 632 // called repeatedly) 633 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc) { 634 635 bool status; 636 637 int nImages = psphotFileruleCount(config, filerule); 638 639 // generate look-up arrays for detections and readouts 640 psArray *detArrays = psArrayAlloc(nImages); 641 psArray *readouts = psArrayAlloc(nImages); 642 643 for (int i = 0; i < nImages; i++) { 644 645 // find the currently selected readout 646 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest 647 psAssert (file, "missing file?"); 648 649 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 650 psAssert (readout, "missing readout?"); 651 652 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 653 if (!detections) { 654 detections = pmDetectionsAlloc(); 655 detections->allSources = psArrayAllocEmpty (100); 656 detections->peaks = psArrayAllocEmpty (100); 657 // save detections on the readout->analysis 658 if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detections)) { 659 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 660 return NULL; 661 } 662 psFree(detections); // a copy remains on the analysis metadata 663 psAssert (detections, "missing detections?"); 664 } 665 detArrays->data[i] = psMemIncrRefCounter(detections); 666 readouts->data[i] = psMemIncrRefCounter(readout); 667 } 668 669 psArray *objectsOut = psArrayAlloc(objectsSrc->n); 670 671 // copy all sources for each object 672 for (int k = 0; k < objectsSrc->n; k++) { 673 674 pmPhotObj *objectSrc = objectsSrc->data[k]; 675 if (!objectSrc) continue; 676 if (!objectSrc->sources) continue; 677 678 pmPhotObj *objectOut = pmPhotObjAlloc(); 679 objectsOut->data[k] = objectOut; 680 681 objectOut->SN = objectSrc->SN; 682 objectOut->x = objectSrc->x; 683 objectOut->y = objectSrc->y; 684 685 objectOut->sources = psArrayAlloc(objectSrc->sources->n); 686 687 // copy the sources from sourceSrcs to the new detection structure 688 // loop over the sources, redefine their pixels to point at the new filerule image, 689 // copy the source data, and add a reference back to the original source 690 for (int i = 0; i < objectSrc->sources->n; i++) { 691 692 pmSource *sourceSrc = objectSrc->sources->data[i]; 693 694 pmSource *sourceOut = pmSourceCopy(sourceSrc); 695 objectOut->sources->data[i] = sourceOut; 696 697 sourceOut->parent = sourceSrc; 698 699 // keep the original source flags 700 sourceOut->type = sourceSrc->type; 701 sourceOut->mode = sourceSrc->mode; 702 sourceOut->mode2 = sourceSrc->mode2; 703 sourceOut->tmpFlags = sourceSrc->tmpFlags; 704 705 // does this copy all model data? (NO) 706 sourceOut->modelPSF = pmModelCopy(sourceSrc->modelPSF); 707 sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT); 708 709 if (sourceSrc->modelFits) { 710 sourceOut->modelFits = psArrayAlloc(sourceSrc->modelFits->n); 711 for (int j = 0; j < sourceSrc->modelFits->n; j++) { 712 sourceOut->modelFits->data[j] = pmModelCopy(sourceSrc->modelFits->data[j]); 713 } 714 } 715 716 // drop the references to the original image pixels: 717 pmSourceFreePixels (sourceOut); 718 719 // set the output readotu 720 int index = sourceOut->imageID; 721 if (index >= readouts->n) continue; // skip the sources generated by the chisq image 722 pmReadout *readout = readouts->data[index]; 723 724 // allocate image, weight, mask for the new image for each peak 725 pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius); 726 727 // child sources have not been subtracted in this image, but this flag may be raised if 728 // they were subtracted in the parent's image 729 sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 730 731 // set the output detections: 732 pmDetections *detectionsOut = detArrays->data[index]; 733 psArrayAdd (detectionsOut->allSources, 100, sourceOut); 734 psArrayAdd (detectionsOut->peaks, 100, sourceOut->peak); 735 } 736 } 737 738 for (int i = 0; i < nImages; i++) { 739 pmDetections *detections = detArrays->data[i]; 740 psLogMsg ("psphot", 3, "%ld source children for image %d", detections->allSources->n, i); 741 } 742 743 psFree (detArrays); 744 psFree (readouts); 745 746 return objectsOut; 747 } 748 -
branches/czw_branch/20101203/psphot/src/psphotOutput.c
r30587 r30631 15 15 psFree (name); 16 16 return num; 17 } 18 19 // convert filerule to filerule.NUM and look up in the config->arguments metadata 20 bool psphotFileruleCountSet(const pmConfig *config, const char *filerule, int num) { 21 22 psString name = NULL; 23 psStringAppend(&name, "%s.NUM", filerule); 24 25 bool status = psMetadataAddS32(config->arguments, PS_LIST_TAIL, name, PS_META_REPLACE, "", num); 26 psFree (name); 27 28 return status; 17 29 } 18 30 … … 261 273 psMetadataItemSupplement (&status, header, analysis, "ANGLE"); 262 274 275 psMetadataItemSupplement (&status, header, analysis, "PSFMODEL"); 276 psMetadataItemSupplement (&status, header, analysis, "PSF_OK"); 277 263 278 // Image Quality measurements 264 279 psMetadataItemSupplement (&status, header, analysis, "IQ_NSTAR"); -
branches/czw_branch/20101203/psphot/src/psphotPetrosianAnalysis.c
r25755 r30631 64 64 } 65 65 66 psphotVisualShowResidualImage (readout );66 psphotVisualShowResidualImage (readout, false); 67 67 return true; 68 68 } -
branches/czw_branch/20101203/psphot/src/psphotPetrosianProfile.c
r25755 r30631 68 68 // XXX this will only work in the psphot context, not the psphotPetrosianStudy... 69 69 // XXX add the petrosian to the pmSource structure... 70 // psphotVisualShowResidualImage (readout);71 70 psphotVisualShowPetrosian (source, petrosian); 72 71 -
branches/czw_branch/20101203/psphot/src/psphotRadialApertures.c
r30118 r30631 102 102 if (source->peak->x > AnalysisRegion.x1) continue; 103 103 if (source->peak->y > AnalysisRegion.y1) continue; 104 105 // allocate pmSourceExtendedParameters, if not already defined 106 if (!source->radialAper) { 107 source->radialAper = psArrayAlloc(1); 108 } 104 109 105 110 // replace object in image … … 116 121 pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, 1.5*radius); 117 122 118 if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax )) {123 if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax, 0)) { 119 124 psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 120 125 } else { … … 130 135 } 131 136 132 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax) { 133 134 // allocate pmSourceExtendedParameters, if not already defined 135 if (!source->radial) { 136 source->radial = pmSourceRadialAperturesAlloc (); 137 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *aperRadii, int entry) { 138 139 // if we are a child source, save the results to the parent source radial aperture array 140 psArray *radialAperSet = source->radialAper; 141 if (source->parent) { 142 radialAperSet = source->parent->radialAper; 143 } 144 psAssert(radialAperSet, "this should be defined before calling"); 145 psAssert(radialAperSet->data[entry] == NULL, "why is this already defined?"); 146 147 pmSourceRadialApertures *radialAper = pmSourceRadialAperturesAlloc (); 148 radialAperSet->data[entry] = radialAper; 149 150 // storage for the derived pixel values 151 psVector *pixRadius2 = psVectorAllocEmpty(100, PS_TYPE_F32); 152 psVector *pixFlux = psVectorAllocEmpty(100, PS_TYPE_F32); 153 psVector *pixVar = psVectorAllocEmpty(100, PS_TYPE_F32); 154 155 // outer-most radius for initial truncation 156 float Rmax = aperRadii->data.F32[aperRadii->n - 1]; 157 float Rmax2 = PS_SQR(Rmax); 158 159 // store the R^2 values for the apertures 160 psVector *aperRadii2 = psVectorAlloc(aperRadii->n, PS_TYPE_F32); 161 for (int i = 0; i < aperRadii->n; i++) { 162 aperRadii2->data.F32[i] = PS_SQR(aperRadii->data.F32[i]); 163 } 164 165 // center of the apertures 166 float xCM = source->moments->Mx - 0.5 - source->pixels->col0; // coord of peak in subimage 167 float yCM = source->moments->My - 0.5 - source->pixels->row0; // coord of peak in subimage 168 169 // one pass through the pixels to select the valid pixels and calculate R^2 170 for (int iy = 0; iy < source->pixels->numRows; iy++) { 171 172 float yDiff = iy - yCM; 173 if (fabs(yDiff) > Rmax) continue; 174 175 float *vPix = source->pixels->data.F32[iy]; 176 float *vWgt = source->variance->data.F32[iy]; 177 psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy]; 178 179 for (int ix = 0; ix < source->pixels->numCols; ix++, vPix++, vWgt++) { 180 181 if (vMsk) { 182 if (*vMsk & maskVal) { 183 vMsk++; 184 continue; 185 } 186 vMsk++; 187 } 188 if (isnan(*vPix)) continue; 189 190 float xDiff = ix - xCM; 191 if (fabs(xDiff) > Rmax) continue; 192 193 // radius is just a function of (xDiff, yDiff) 194 float r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 195 if (r2 > Rmax2) continue; 196 197 psVectorAppend(pixRadius2, r2); 198 psVectorAppend(pixFlux, *vPix); 199 psVectorAppend(pixVar, *vWgt); 200 } 201 } 202 203 psVector *flux = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 204 psVector *fluxErr = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 205 psVector *fill = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 206 207 psVectorInit (flux, 0.0); 208 psVectorInit (fluxErr, 0.0); 209 psVectorInit (fill, 0.0); 210 211 float *rPix2 = pixRadius2->data.F32; 212 for (int i = 0; i < pixRadius2->n; i++, rPix2++) { 213 214 float *aRad2 = aperRadii2->data.F32; 215 for (int j = 0; (*rPix2 < *aRad2) && (j < aperRadii2->n); j++, aRad2++) { 216 flux->data.F32[j] += pixFlux->data.F32[i]; 217 fluxErr->data.F32[j] += pixVar->data.F32[i]; 218 fill->data.F32[j] += 1.0; 219 } 220 } 221 222 for (int i = 0; i < flux->n; i++) { 223 // calculate the total flux for bin 'nOut' 224 float Area = M_PI*aperRadii2->data.F32[i]; 225 fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]); 226 fill->data.F32[i] /= Area; 227 psTrace ("psphot", 5, "radial bins: %3d %5.1f : %8.1f +/- %7.2f : %4.2f %6.1f\n", 228 i, aperRadii->data.F32[i], flux->data.F32[i], fluxErr->data.F32[i], fill->data.F32[i], Area); 137 229 } 138 230 139 psVector *radius = psVectorAllocEmpty(100, PS_TYPE_F32); 231 radialAper->flux = flux; 232 radialAper->fluxErr = fluxErr; 233 radialAper->fill = fill; 234 235 psFree (aperRadii2); 236 psFree (pixRadius2); 237 psFree (pixFlux); 238 psFree (pixVar); 239 240 return true; 241 } 242 243 static int nCalls = 0; 244 static int nPass = 0; 245 static int nPix = 0; 246 247 bool psphotRadialApertureSource_With_Sort (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax, int entry) { 248 249 psAssert(source->radialAper->data[entry] == NULL, "why is this already defined?"); 250 251 pmSourceRadialApertures *radialAper = pmSourceRadialAperturesAlloc (); 252 source->radialAper->data[entry] = radialAper; 253 254 psVector *pixRadius = psVectorAllocEmpty(100, PS_TYPE_F32); 140 255 psVector *pixFlux = psVectorAllocEmpty(100, PS_TYPE_F32); 141 256 psVector *pixVar = psVectorAllocEmpty(100, PS_TYPE_F32); … … 144 259 for (int ix = 0; ix < source->pixels->numCols; ix++) { 145 260 146 // 0.5 PIX: get radius as a function of pixel coord261 // 0.5 PIX: get pixRadius as a function of pixel coord 147 262 float x = ix + 0.5 - source->peak->xf + source->pixels->col0; 148 263 float y = iy + 0.5 - source->peak->yf + source->pixels->row0; … … 150 265 float r = hypot(x, y); 151 266 152 psVectorAppend( radius, r);267 psVectorAppend(pixRadius, r); 153 268 psVectorAppend(pixFlux, source->pixels->data.F32[iy][ix]); 154 269 psVectorAppend(pixVar, source->variance->data.F32[iy][ix]); 155 } 156 } 157 psphotRadialAperturesSortFlux(radius, pixFlux, pixVar); 270 nPix ++; 271 // if (nPix % 10000 == 0) {fprintf (stderr, "?");} 272 } 273 } 274 psphotRadialAperturesSortFlux(pixRadius, pixFlux, pixVar); 158 275 159 276 psVector *flux = psVectorAllocEmpty(radMax->n, PS_TYPE_F32); // surface brightness of radial bin … … 174 291 175 292 // XXX assume (or enforce) that the bins are contiguous and non-overlapping (Rmax[i] = Rmin[i+1]) 176 for (int i = 0; !done && (i < radius->n); i++) {177 if ( radius->data.F32[i] > Rmax) {293 for (int i = 0; !done && (i < pixRadius->n); i++) { 294 if (pixRadius->data.F32[i] > Rmax) { 178 295 // calculate the total flux for bin 'nOut' 179 296 float Area = M_PI*PS_SQR(Rmax); … … 185 302 nOut, radMax->data.F32[nOut], flux->data.F32[nOut], fluxErr->data.F32[nOut], fill->data.F32[nOut], Area); 186 303 304 nPass ++; 305 // if (nPass % 1000 == 0) {fprintf (stderr, "!");} 306 187 307 nOut ++; 188 308 if (nOut >= radMax->n) break; … … 195 315 flux->n = fluxErr->n = fill->n = nOut; 196 316 197 psFree(source->radial->flux); 198 psFree(source->radial->fluxErr); 199 psFree(source->radial->fill); 200 201 source->radial->flux = flux; 202 source->radial->fluxErr = fluxErr; 203 source->radial->fill = fill; 204 205 psFree (radius); 317 radialAper->flux = flux; 318 radialAper->fluxErr = fluxErr; 319 radialAper->fill = fill; 320 321 psFree (pixRadius); 206 322 psFree (pixFlux); 207 323 psFree (pixVar); 208 324 325 nCalls ++; 326 // if (nCalls % 100 == 0) {fprintf (stderr, "*");} 209 327 return true; 210 328 } -
branches/czw_branch/20101203/psphot/src/psphotRadialAperturesByObject.c
r30118 r30631 3 3 // aperture-like measurements for extended sources 4 4 // flux in simple, circular apertures 5 bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule) { 5 6 // **** it looks like this function will re-point the source pixels at the specified FILERULE 7 // **** I need to distinguish PSF-matched images from raw 8 // **** save (somewhere) the PSF-matched PSF values 9 10 // this function measures the radial aperture fluxes for the set of readouts. this function 11 // may be called multiple times (presumably with different matched PSF sizes). we must have 12 // already added an entry to the readout->analysis identifying the FWHM of this version. 13 14 bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule, int nMatchedPSF) { 6 15 7 16 bool status; … … 28 37 psAssert (radMax, "annular bins (RADIAL.ANNULAR.BINS.UPPER) are not defined in the recipe"); 29 38 psAssert (radMax->n, "no valid annular bins (RADIAL.ANNULAR.BINS.UPPER) are define"); 39 float outerRadius = radMax->data.F32[radMax->n - 1]; 30 40 31 41 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 39 49 float SN_LIM = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM"); 40 50 51 // how many target PSFs do we want? 52 int nPSFsizes = 0; 53 { 54 psMetadataLookupF32 (&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); 55 if (status) { 56 nPSFsizes = 1; 57 } else { 58 psVector *fwhmValues = psMetadataLookupVector(&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); // Magnitude offsets 59 psAssert (status, "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM"); 60 nPSFsizes = fwhmValues->n; 61 } 62 } 63 41 64 // source analysis is done in S/N order (brightest first) 42 65 objects = psArraySort (objects, pmPhotObjSortBySN); … … 52 75 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 53 76 psAssert (readout, "missing readout?"); 77 78 psVector *fwhmValues = psMetadataLookupVector(&status, readout->analysis, "STACK.PSF.FWHM.VALUES"); 79 if (!fwhmValues) { 80 psError (PSPHOT_ERR_CONFIG, true, "convolved or measured FWHM is not defined for this readout"); 81 return false; 82 } 83 if (fwhmValues->n != nMatchedPSF + 1) { 84 psError (PSPHOT_ERR_CONFIG, true, "convolved or measured FWHM sequence is inconsistent this readout"); 85 return false; 86 } 87 psLogMsg ("psphot", PS_LOG_DETAIL, "PSF FWHM of %s : %f pixels\n", file->name, fwhmValues->data.F32[nMatchedPSF]); 54 88 55 89 readouts->data[i] = psMemIncrRefCounter(readout); … … 77 111 if (source->peak->SN < SN_LIM) continue; 78 112 113 int index = source->imageID; 114 if (index >= readouts->n) continue; // skip the sources generated by the chisq image 115 pmReadout *readout = readouts->data[index]; 116 117 // psLogMsg("psphot", PS_LOG_INFO, "radial apertures for %d", index); 118 // psphotVisualShowImage(readout); 119 120 // allocate pmSourceExtendedParameters, if not already defined 121 if (source->parent) { 122 if (!source->parent->radialAper) { 123 source->parent->radialAper = psArrayAlloc(nPSFsizes); 124 } 125 } else { 126 if (!source->radialAper) { 127 source->radialAper = psArrayAlloc(nPSFsizes); 128 } 129 } 130 79 131 // replace object in image 80 132 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { 81 133 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 82 134 } 135 136 // we need to change the view for the radial aperture analysis, but we want to recover exactly 137 // the original view; the following elements get destroyed by pmSourceRedefinePixels so save them: 138 psImage *oldMaskObj = psMemIncrRefCounter(source->maskObj); 139 psImage *oldModelFlux = psMemIncrRefCounter(source->modelFlux); 140 psImage *oldPSFimage = psMemIncrRefCounter(source->psfImage); 141 psRegion oldRegion = source->region; 142 83 143 Nradial ++; 84 144 85 int index = source->imageID;86 pmReadout *readout = readouts->data[index];145 // psLogMsg("psphot", PS_LOG_INFO, "radial apertures for %d", index); 146 // psphotVisualShowImage(readout); 87 147 88 148 // force source image to be a bit larger... 89 float radius = source->peak->xf - source->pixels->col0;90 radius = PS_MAX (radius, source->peak->yf - source->pixels->row0);91 radius = PS_MAX (radius, source->pixels->numRows - source->peak->yf + source->pixels->row0);92 radius = PS_MAX (radius, source->pixels->numCols - source->peak->xf + source->pixels->col0);93 pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, 1.5*radius);149 // float radius = source->peak->xf - source->pixels->col0; 150 // radius = PS_MAX (radius, source->peak->yf - source->pixels->row0); 151 // radius = PS_MAX (radius, source->pixels->numRows - source->peak->yf + source->pixels->row0); 152 // radius = PS_MAX (radius, source->pixels->numCols - source->peak->xf + source->pixels->col0); 153 pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, outerRadius + 2); 94 154 95 if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax )) {155 if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax, nMatchedPSF)) { 96 156 psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 97 157 } else { … … 99 159 } 100 160 161 pmSourceRedefinePixelsByRegion (source, readout, oldRegion); 162 psFree(source->maskObj); source->maskObj = oldMaskObj; 163 psFree(source->modelFlux); source->modelFlux = oldModelFlux; 164 psFree(source->psfImage); source->psfImage = oldPSFimage; 165 101 166 // re-subtract the object, leave local sky 102 167 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 168 169 // psLogMsg("psphot", PS_LOG_INFO, "radial apertures for %d", index); 170 // psphotVisualShowImage(readout); 103 171 } 104 172 } -
branches/czw_branch/20101203/psphot/src/psphotReadout.c
r30118 r30631 112 112 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 113 113 // this step is skipped 114 if (!psphotChoosePSF (config, view, filerule )) { // pass 1114 if (!psphotChoosePSF (config, view, filerule, true)) { // pass 1 115 115 psLogMsg ("psphot", 3, "failure to construct a psf model"); 116 116 return psphotReadoutCleanup (config, view, filerule); -
branches/czw_branch/20101203/psphot/src/psphotReadoutFindPSF.c
r30118 r30631 49 49 } 50 50 51 if (!psphotChoosePSF(config, view, filerule )) {51 if (!psphotChoosePSF(config, view, filerule, true)) { 52 52 psError(PSPHOT_ERR_PSF, false, "Failed to construct a psf model"); 53 53 return psphotReadoutCleanup (config, view, filerule); -
branches/czw_branch/20101203/psphot/src/psphotReadoutKnownSources.c
r30118 r30631 43 43 } 44 44 45 if (!psphotChoosePSF (config, view, filerule )) {45 if (!psphotChoosePSF (config, view, filerule, true)) { 46 46 psError(PSPHOT_ERR_PSF, false, "Failed to construct a psf model"); 47 47 return psphotReadoutCleanup (config, view, filerule); -
branches/czw_branch/20101203/psphot/src/psphotReplaceUnfit.c
r30118 r30631 75 75 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 76 76 } 77 78 psphotVisualShowImage(readout); 77 79 psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); 78 80 return true; … … 101 103 return true; 102 104 } 105 106 // modify the sources to point at the corresponding pixels for the given filerule 107 bool psphotRedefinePixels (pmConfig *config, const pmFPAview *view, const char *filerule) 108 { 109 bool status = true; 110 111 // select the appropriate recipe information 112 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 113 psAssert (recipe, "missing recipe?"); 114 115 int num = psphotFileruleCount(config, filerule); 116 117 // loop over the available readouts 118 for (int i = 0; i < num; i++) { 119 if (!psphotRedefinePixelsReadout (config, view, filerule, i, recipe)) { 120 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 121 return false; 122 } 123 } 124 return true; 125 } 126 127 bool psphotRedefinePixelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 128 129 bool status; 130 pmSource *source; 131 132 psTimerStart ("psphot.replace"); 133 134 // find the currently selected readout 135 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 136 psAssert (file, "missing file?"); 137 138 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 139 psAssert (readout, "missing readout?"); 140 141 // XXX the sources have already been copied (merge into here?) 142 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 143 psAssert (detections, "missing detections?"); 144 145 psArray *sources = detections->allSources; 146 psAssert (sources, "missing sources?"); 147 148 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 149 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 150 psAssert (maskVal, "missing mask value?"); 151 152 for (int i = 0; i < sources->n; i++) { 153 source = sources->data[i]; 154 155 // sources have not yet been subtracted in this image (but this flag may be raised) 156 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 157 158 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 159 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 160 float radius = source->modelPSF->fitRadius; 161 162 // force a redefine to this image 163 pmSourceFreePixels(source); 164 pmSourceRedefinePixels (source, readout, Xo, Yo, radius); 165 } 166 return true; 167 } 168 169 // for now, let's store the detections on the readout->analysis for each readout 170 bool psphotResetModels (pmConfig *config, const pmFPAview *view, const char *filerule) 171 { 172 bool status = true; 173 174 // select the appropriate recipe information 175 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 176 psAssert (recipe, "missing recipe?"); 177 178 int num = psphotFileruleCount(config, filerule); 179 180 // loop over the available readouts 181 for (int i = 0; i < num; i++) { 182 if (!psphotResetModelsReadout (config, view, filerule, i, recipe)) { 183 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 184 return false; 185 } 186 } 187 return true; 188 } 189 190 bool psphotResetModelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 191 192 bool status; 193 pmSource *source; 194 195 psTimerStart ("psphot.replace"); 196 197 // find the currently selected readout 198 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 199 psAssert (file, "missing file?"); 200 201 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 202 psAssert (readout, "missing readout?"); 203 204 // XXX the sources have already been copied (merge into here?) 205 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 206 psAssert (detections, "missing detections?"); 207 208 psArray *sources = detections->allSources; 209 psAssert (sources, "missing sources?"); 210 211 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 212 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 213 psAssert (maskVal, "missing mask value?"); 214 215 // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box) 216 int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE"); 217 assert (status); 218 219 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 220 psAssert (psf, "missing psf?"); 221 222 for (int i = 0; i < sources->n; i++) { 223 source = sources->data[i]; 224 225 // *** we need to cache the 'best' model, and we have 3 cases: 226 // 1) model is the psf model --> generate from the new psf 227 // 2) model is an unconvolved extended model --> just cache the copy (not perfect) 228 // 3) model is a convolved extended model --> re-generate 229 230 // use the 'best' model to cache the model (PSF or EXT : EXT may point at one of modelFits 231 bool isPSF = false; 232 pmModel *model = pmSourceGetModel(&isPSF, source); 233 float radius = model->fitRadius; // save for future use below 234 235 // regenerate the PSF if the model is a PSF, or if we need the PSF for a PCM 236 if (isPSF || model->isPCM) { 237 // the guess central intensity comes from the peak: 238 float Io = source->peak->flux; 239 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 240 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 241 242 // generate a model for this object with Io = 1.0 243 pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io); 244 if (modelPSF == NULL) { 245 psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo); 246 continue; 247 } 248 249 // set the source PSF model 250 psFree (source->modelPSF); 251 source->modelPSF = modelPSF; 252 source->modelPSF->fitRadius = radius; 253 } 254 255 if (model->isPCM) { 256 psAssert(false, "this section is not complete"); 257 258 pmSourceCachePSF (source, maskVal); 259 260 psKernel *psfKernel = pmPCMkernelFromPSF(source, psfSize); 261 if (!psfKernel) { 262 psWarning ("no psf kernel"); 263 } 264 265 // generate an image of the right size 266 psImage *rawModelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 267 psImageInit (rawModelFlux, 0.0); 268 269 // insert the model image normalized to 1.0 270 pmModelAdd (rawModelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal); 271 272 psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel); 273 274 psFree (psfKernel); 275 psFree (rawModelFlux); 276 } 277 278 pmSourceCacheModel (source, maskVal); // ALLOC x14 (!) 279 } 280 281 psLogMsg ("psphot.replace", PS_LOG_INFO, "subtracted models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); 282 return true; 283 } 284 -
branches/czw_branch/20101203/psphot/src/psphotSetThreads.c
r29004 r30631 35 35 psFree(task); 36 36 37 task = psThreadTaskAlloc("PSPHOT_EXTENDED_FIT", 1 2);37 task = psThreadTaskAlloc("PSPHOT_EXTENDED_FIT", 13); 38 38 task->function = &psphotExtendedSourceFits_Threaded; 39 39 psThreadTaskAdd(task); -
branches/czw_branch/20101203/psphot/src/psphotSourceFits.c
r29548 r30631 365 365 366 366 // copy most data from the primary source (modelEXT, blends stay NULL) 367 pmSource *newSrc = pmSourceCopy Data(source);367 pmSource *newSrc = pmSourceCopy (source); 368 368 newSrc->modelPSF = psMemIncrRefCounter (DBL->data[1]); 369 369 … … 385 385 psLogMsg ("psphot", 1, "PAR %d : %f +/- %f\n", i, source->modelPSF->params->data.F32[i], source->modelPSF->dparams->data.F32[i]); 386 386 } 387 psphotVisualShowResidualImage (readout );387 psphotVisualShowResidualImage (readout, false); 388 388 } 389 389 # endif -
branches/czw_branch/20101203/psphot/src/psphotSourceMatch.c
r30118 r30631 187 187 pmPhotObj *obj = objects->data[i]; 188 188 189 // we will find the input source with the max number of spans and reproduce that footprint 190 int nSpansMax = 0; 191 int iSpansMax = -1; 192 189 193 // mark the images for which sources have been found 190 194 psVectorInit (found, 0); … … 196 200 psAssert (index < found->n, "invalid index"); 197 201 202 if (src->peak && src->peak->footprint && src->peak->footprint->nspans > nSpansMax) { 203 nSpansMax = src->peak->footprint->nspans; 204 iSpansMax = j; 205 } 206 198 207 found->data.U8[index] = 1; 208 } 209 210 // we make a copy of the largest footprint; this will be used for all new sources associated with this object 211 pmFootprint *footprint = NULL; 212 if (iSpansMax != -1) { // copy the footprint info 213 pmSource *src = obj->sources->data[iSpansMax]; 214 psAssert(src->peak, "source does not exist?"); 215 psAssert(src->peak->footprint, "footprint does not exist"); 216 psAssert(src->peak->footprint->nspans == nSpansMax, "wrong footprint?"); 217 218 // we only care about the spans, do not worry about the image of this footprint 219 footprint = pmFootprintCopyData(src->peak->footprint, NULL); 199 220 } 200 221 … … 219 240 peak->dy = NAN; 220 241 221 // XXX assign to a footprint? 222 242 // assign to a footprint on this readout->image 243 peak->footprint = pmFootprintCopyData(footprint, readout->image); 244 245 // the peak does not claim ownership of the footprint (it does not free it). save a copy of this 246 // footprint on detections->footprints so we can free it later 247 psArrayAdd(detections->footprints, 100, peak->footprint); 248 psFree (peak->footprint); 249 223 250 // create a new source 224 251 pmSource *source = pmSourceAlloc(); … … 227 254 228 255 // add the peak 229 source->peak = p sMemIncrRefCounter(peak);256 source->peak = peak; 230 257 231 258 // allocate space for moments … … 239 266 psArrayAdd (detections->newSources, 100, source); 240 267 psFree (source); 241 psFree (peak);242 }268 } 269 psFree (footprint); 243 270 } 244 271 -
branches/czw_branch/20101203/psphot/src/psphotSourceSize.c
r30118 r30631 499 499 500 500 // clear the mask bit and set the circular mask pixels 501 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal)); 502 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal); 503 501 // psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal)); 502 // psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal); 504 503 pmSourceMagnitudes (source, psf, photMode, maskVal, markVal); 505 504 506 505 // clear the mask bit 507 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));506 // psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal)); 508 507 509 508 // re-subtract the object, leave local sky -
branches/czw_branch/20101203/psphot/src/psphotStackArguments.c
r28013 r30631 41 41 if ((N = psArgumentGet (argc, argv, "-break"))) { 42 42 if (argc <= N+1) { 43 psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);43 psErrorStackPrint(stderr, "Expected to see an argument for -break"); 44 44 exit(PS_EXIT_CONFIG_ERROR); 45 45 } -
branches/czw_branch/20101203/psphot/src/psphotStackChisqImage.c
r30118 r30631 6 6 7 7 // XXX supply filename or keep PSPHOT.INPUT fixed? 8 bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view, const char *ruleDet, const char *rule Cnv)8 bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view, const char *ruleDet, const char *ruleSrc) 9 9 { 10 10 psTimerStart ("psphot.chisq.image"); … … 27 27 28 28 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.CHISQ.NUM", PS_META_REPLACE, "", num); 29 30 // we need to increment the counter for ruleDet and ruleSrc: 29 31 num++; 30 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", num);31 32 32 33 // save the resulting image in the 'detection' set … … 35 36 return false; 36 37 } 38 psphotFileruleCountSet(config, ruleDet, num); 37 39 38 // save the resulting image in the 'convolved' set 39 if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, ruleCnv, PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) { 40 psError(PM_ERR_CONFIG, false, "could not add chisqFPA to config files"); 41 return false; 40 // also save the resulting image in the 'source' set (analysis set) 41 if (strcmp(ruleDet, ruleSrc)) { 42 if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, ruleSrc, PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) { 43 psError(PM_ERR_CONFIG, false, "could not add chisqFPA to config files"); 44 return false; 45 } 46 psphotFileruleCountSet(config, ruleSrc, num); 42 47 } 43 48 … … 119 124 psAssert (status, "programming error: must define PSPHOT.CHISQ.NUM"); 120 125 121 int inputNum = psphotFileruleCount(config, "PSPHOT.INPUT");126 int inputNum = psphotFileruleCount(config, filerule); 122 127 123 128 pmFPAfileRemoveSingle (config->files, filerule, chisqNum); 124 129 125 130 inputNum --; 126 ps MetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", inputNum);131 psphotFileruleCountSet(config, filerule, inputNum); 127 132 128 133 return true; -
branches/czw_branch/20101203/psphot/src/psphotStackImageLoop.c
r30118 r30631 101 101 */ 102 102 103 # define UPDATE_HEADER 0103 # define UPDATE_HEADER 1 104 104 105 105 bool GetAstrometryFPA (pmConfig *config, pmFPAview *view) { … … 174 174 pmChip *outChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output 175 175 176 # if (UPDATE_HEADER)177 176 pmHDU *outHDU = pmFPAviewThisHDU (view, output->fpa); 178 177 if (!outHDU) { 179 pmFPAAddSourceFromView(output->fpa, "name",view, output->format);178 pmFPAAddSourceFromView(output->fpa, view, output->format); 180 179 outHDU = pmFPAviewThisHDU (view, output->fpa); 181 180 psAssert (outHDU, "failed to make HDU"); 182 181 } 183 # endif 182 if (!outHDU->header) { 183 outHDU->header = psMetadataAlloc(); 184 } 184 185 185 186 if (bilevelAstrometry) { … … 188 189 continue; 189 190 } 190 # if (UPDATE_HEADER)191 191 if (!pmAstromWriteBilevelChip(outHDU->header, outChip, WCS_NONLIN_TOL)) { 192 192 psWarning("Unable to generate WCS header."); 193 193 continue; 194 194 } 195 # endif196 195 } else { 197 196 // we use a default FPA pixel scale of 1.0 … … 200 199 continue; 201 200 } 202 # if (UPDATE_HEADER) 203 if (UPDATE_HEADER && !pmAstromWriteWCS(outHDU->header, output->fpa, outChip, WCS_NONLIN_TOL)) { 201 if (!pmAstromWriteWCS(outHDU->header, output->fpa, outChip, WCS_NONLIN_TOL)) { 204 202 psWarning("Unable to generate WCS header."); 205 203 continue; 206 204 } 207 # endif208 205 } 209 206 } … … 225 222 psAssert (output, "missing file?"); 226 223 227 # if (UPDATE_HEADER)228 224 pmHDU *PHU = pmFPAviewThisPHU(view, output->fpa); 229 225 if (!PHU) { 230 pmFPAAddSourceFromView(output->fpa, "name",view, output->format);226 pmFPAAddSourceFromView(output->fpa, view, output->format); 231 227 PHU = pmFPAviewThisPHU (view, output->fpa); 232 228 psAssert (PHU, "failed to make PHU"); 233 229 } 230 if (!PHU->header) { 231 PHU->header = psMetadataAlloc(); 232 } 234 233 235 234 if (!pmAstromWriteBilevelMosaic(PHU->header, output->fpa, WCS_NONLIN_TOL)) { 236 235 psWarning("Unable to generate WCS header."); 237 236 } 238 # endif239 237 } 240 238 -
branches/czw_branch/20101203/psphot/src/psphotStackMatchPSFs.c
r30118 r30631 65 65 bool psphotStackMatchPSFsReadout (pmConfig *config, const pmFPAview *view, psphotStackOptions *options, int index) { 66 66 67 psImageMaskType maskValue; 68 psImageMaskType markValue; 69 70 // get the PSPHOT.MASK value from the config 71 if (!pmConfigMaskSetBits (&maskValue, &markValue, config)) { 72 psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values"); 73 return false; 74 } 75 67 76 pmFPAfile *fileSrc = psphotStackGetConvolveSource(config, options, index); 68 77 if (!fileSrc) { … … 84 93 85 94 // set NAN pixels to 'SAT' 86 // XXX replace this is pmReadoutMaskInvalid? 87 psImageMaskType maskVal = pmConfigMaskGet("SAT", config); 88 if (!pmReadoutMaskNonfinite(readoutSrc, maskVal)) { 95 psImageMaskType maskSat = pmConfigMaskGet("SAT", config); 96 if (!pmReadoutMaskInvalid(readoutSrc, maskValue, maskSat)) { 89 97 psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels in readout."); 90 98 return false; … … 95 103 matchKernel(config, readoutOut, readoutSrc, options, index); 96 104 saveMatchData(readoutOut, options, index); 97 // renormKernel(readoutCnv, options, index);98 } else {99 // only match the flux (NO! not for multi-filter, at least!)100 // XXX do not generate readoutCnv in this case?101 // float norm = powf(10.0, -0.4 * options->norm->data.F32[index]); // Normalisation102 // psBinaryOp(readoutRaw->image, readoutRaw->image, "*", psScalarAlloc(norm, PS_TYPE_F32));103 // psBinaryOp(readoutRaw->variance, readoutRaw->variance, "*", psScalarAlloc(PS_SQR(norm), PS_TYPE_F32));104 105 } 105 106 106 rescaleData(readoutOut, config, options, index); 107 107 108 // dumpImage(readoutOut, readoutSrc, index, "convolved"); 108 // save the output fwhm values in the readout->analysis. we may have / will have multiple output PSF sizes, 109 // so we save this in a vector. if the vector is not yet defined, create it 110 bool mdok = false; 111 psVector *fwhmValues = psMetadataLookupVector(&mdok, readoutOut->analysis, "STACK.PSF.FWHM.VALUES"); 112 if (!fwhmValues) { 113 fwhmValues = psVectorAllocEmpty(10, PS_TYPE_F32); 114 psMetadataAddVector(readoutOut->analysis, PS_LIST_TAIL, "STACK.PSF.FWHM.VALUES", PS_META_REPLACE, "PSF sizes", fwhmValues); 115 psFree(fwhmValues); // drops the extra copy 116 } 117 psVectorAppend(fwhmValues, options->targetSeeing); 109 118 110 119 return true; 111 120 } 112 113 114 # if (0)115 // Read previously produced kernel116 if (psMetadataLookupBool(NULL, config->arguments, "PPSTACK.DEBUG.STACK")) {117 loadKernel(config, readoutCnv, options, index);118 } else {119 matchKernel(config, readoutCnv, readoutRaw, options, index);120 }121 # endif -
branches/czw_branch/20101203/psphot/src/psphotStackMatchPSFsUtils.c
r29548 r30631 365 365 pmSubtractionSetFWHMs(options->inputSeeing->data.F32[index], options->targetSeeing); 366 366 367 if (scale && !pmSubtractionParamsScale(&size, &footprint, widthsCopy, scaleRef, scaleMin, scaleMax)) { 368 psError(psErrorCodeLast(), false, "Unable to scale kernel parameters"); 369 goto escape; 370 } 367 pmSubtractionParamScaleOptions(scale, scaleRef, scaleMin, scaleMax); 368 369 // if (scale && !pmSubtractionParamsScale(&size, &footprint, widthsCopy, scaleRef, scaleMin, scaleMax)) { 370 // psError(psErrorCodeLast(), false, "Unable to scale kernel parameters"); 371 // goto escape; 372 // } 371 373 372 374 if (!pmSubtractionMatch(NULL, readoutOut, fake, readoutSrc, footprint, stride, regionSize, spacing, threshold, stampSources, stampsName, type, size, order, widthsCopy, orders, inner, ringsOrder, binning, penalty, optimum, optWidths, optOrder, optThresh, iter, rej, normFrac, sysError, skyErr, kernelError, covarFrac, maskVal, maskBad, maskPoor, poorFrac, badFrac, PM_SUBTRACTION_MODE_2)) { … … 383 385 goto escape; 384 386 } 387 388 // save the PSF on the new readout->analysis: 389 // if (!psMetadataAddPtr (readoutOut->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot psf model", options->psf)) { 390 // psError (PSPHOT_ERR_UNKNOWN, false, "problem saving sources on readout"); 391 // return false; 392 // } 385 393 386 394 // dumpImage(readoutOut, readoutSrc, index, "conv"); -
branches/czw_branch/20101203/psphot/src/psphotStackPSF.c
r28013 r30631 12 12 bool autoPSF = psMetadataLookupBool (&mdok, psphotRecipe, "PSPHOT.STACK.TARGET.PSF.AUTO"); 13 13 14 // Get the recipe values 15 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "PPSTACK"); // ppStack recipe 16 psAssert(recipe, "We've thrown an error on this before."); 17 18 char *psfModel = psMetadataLookupStr(NULL, recipe, "PSF.MODEL"); // Model for PSF 19 14 20 if (autoPSF) { 15 // Get the recipe values16 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "PPSTACK"); // ppStack recipe17 psAssert(recipe, "We've thrown an error on this before.");18 19 21 int psfInstances = psMetadataLookupS32(NULL, recipe, "PSF.INSTANCES"); // Number of instances for PSF 20 22 float psfRadius = psMetadataLookupF32(NULL, recipe, "PSF.RADIUS"); // Radius for PSF 21 const char *psfModel = psMetadataLookupStr(NULL, recipe, "PSF.MODEL"); // Model for PSF22 23 int psfOrder = psMetadataLookupS32(NULL, recipe, "PSF.ORDER"); // Spatial order for PSF 23 24 … … 49 50 50 51 float targetFWHM = psMetadataLookupF32 (&mdok, psphotRecipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); 51 psAssert (isfinite(targetFWHM), "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM"); 52 if (!mdok) { 53 psVector *fwhmValues = psMetadataLookupVector(&mdok, psphotRecipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); // Magnitude offsets 54 psAssert (mdok, "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM"); 55 targetFWHM = fwhmValues->data.F32[0]; 56 } 52 57 53 58 float Sxx = sqrt(2.0)*targetFWHM / 2.35; 54 59 55 60 // XXX probably should make the model type (and par 7) optional from recipe 56 psf = pmPSFBuildSimple( "PS_MODEL_PS1_V1", Sxx, Sxx, 0.0, 1.0);61 psf = pmPSFBuildSimple(psfModel, Sxx, Sxx, 0.0, 1.0); 57 62 if (!psf) { 58 63 psError(PSPHOT_ERR_PSF, false, "Unable to build dummy PSF."); -
branches/czw_branch/20101203/psphot/src/psphotStackParseCamera.c
r29548 r30631 15 15 } 16 16 17 int nRaw = 0; 18 int nCnv = 0; 17 19 int nInputs = inputs->list->n; 18 20 for (int i = 0; i < nInputs; i++) { … … 57 59 } 58 60 } 61 nRaw ++; 59 62 } 60 63 … … 88 91 } 89 92 } 93 nCnv ++; 90 94 } 91 95 … … 95 99 } 96 100 101 // XXX what if they do not match in length 102 if (nCnv && nRaw) { 103 if (nCnv != nRaw) { 104 psError (PSPHOT_ERR_CONFIG, true, "if both RAW and CNV images are supplied, the number must match"); 105 return false; 106 } 107 } 108 97 109 psString sources = psMetadataLookupStr(&status, input, "SOURCES"); // Name of mask 98 // pmFPAfile *srcInputFile = rawInputFile ? rawInputFile : cnvInputFile;99 110 if (sources && strlen(sources) > 0) { 100 111 if (!defineFile(config, NULL, "PSPHOT.STACK.SOURCES", sources, PM_FPA_FILE_CMF)) { … … 107 118 // XXX output of these files should be optional 108 119 { 120 // pmFPAfile *srcInputFile = rawInputFile ? rawInputFile : cnvInputFile; 109 121 pmFPAfile *outputImage = pmFPAfileDefineOutput(config, NULL, "PSPHOT.STACK.OUTPUT.IMAGE"); 110 122 if (!outputImage) { … … 150 162 } 151 163 psMetadataRemoveKey(config->arguments, "FILENAMES"); 164 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.STACK.INPUT.RAW.NUM", PS_META_REPLACE, "number of inputs", nRaw); 165 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.STACK.INPUT.CNV.NUM", PS_META_REPLACE, "number of inputs", nCnv); 166 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.STACK.OUTPUT.IMAGE.NUM", PS_META_REPLACE, "number of inputs", nInputs); 152 167 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", nInputs); 153 168 -
branches/czw_branch/20101203/psphot/src/psphotStackReadout.c
r30118 r30631 1 1 # include "psphotInternal.h" 2 2 3 // we have 3 possible real filesets: 3 4 # define STACK_RAW "PSPHOT.STACK.INPUT.RAW" 4 # define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE" 5 # define STACK_CNV "PSPHOT.STACK.INPUT.CNV" 6 # define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE" /* the psf-matched image */ 7 8 // we have 3 files on which we operate: 9 // DET (detection image) : nominally RAW (optionally CNV?) 10 // SRC (source analysis image) : nominally CNV (optionally RAW) 11 // OUT (psf-matched images) : always OUT 12 13 bool psphotStackVisualFilerule(pmConfig *config, const pmFPAview *view, const char *filerule) { 14 15 bool status = false; 16 17 int num = psphotFileruleCount(config, filerule); 18 19 // select the appropriate recipe information 20 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 21 22 // loop over the available readouts 23 for (int i = 0; i < num; i++) { 24 25 // find the currently selected readout 26 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest 27 psAssert (file, "missing file?"); 28 29 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 30 psAssert (readout, "missing readout?"); 31 32 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 33 psAssert (detections, "missing detections?"); 34 35 psArray *sources = detections->allSources; 36 psAssert (sources, "missing sources?"); 37 38 psphotVisualShowResidualImage (readout, true); 39 psphotVisualShowObjectRegions (readout, recipe, sources); 40 } 41 return true; 42 } 5 43 6 44 bool psphotStackReadout (pmConfig *config, const pmFPAview *view) { … … 20 58 PS_ASSERT_PTR_NON_NULL (breakPt, false); 21 59 60 // XXX or do I set OUT to be a pmFPAfile pointing at the input of interest? 61 bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW"); 62 char *STACK_SRC = useRaw ? STACK_RAW : STACK_CNV; 63 char *STACK_DET = STACK_RAW; // XXX optionally allow this to be CNV? 64 22 65 // we have 3 relevant files: RAW, CNV, OUT 23 66 24 67 // set the photcode for each image 25 if (!psphotAddPhotcode (config, view, STACK_ OUT)) {68 if (!psphotAddPhotcode (config, view, STACK_SRC)) { 26 69 psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode"); 27 70 return false; … … 30 73 // Generate the mask and weight images 31 74 // XXX this should be done before we perform the convolutions 32 if (!psphotSetMaskAndVariance (config, view, STACK_ RAW)) {33 return psphotReadoutCleanup (config, view, STACK_ OUT);75 if (!psphotSetMaskAndVariance (config, view, STACK_DET)) { 76 return psphotReadoutCleanup (config, view, STACK_SRC); 34 77 } 35 78 if (!strcasecmp (breakPt, "NOTHING")) { 36 return psphotReadoutCleanup (config, view, STACK_ OUT);79 return psphotReadoutCleanup (config, view, STACK_SRC); 37 80 } 38 81 … … 40 83 // XXX I think this is not defined correctly for an array of images. 41 84 // XXX probably need to subtract the model (same model?) for both RAW and OUT 42 if (!psphotModelBackground (config, view, STACK_ RAW)) {43 return psphotReadoutCleanup (config, view, STACK_ OUT);44 } 45 if (!psphotSubtractBackground (config, view, STACK_ RAW)) {46 return psphotReadoutCleanup (config, view, STACK_ OUT);85 if (!psphotModelBackground (config, view, STACK_DET)) { 86 return psphotReadoutCleanup (config, view, STACK_SRC); 87 } 88 if (!psphotSubtractBackground (config, view, STACK_DET)) { 89 return psphotReadoutCleanup (config, view, STACK_SRC); 47 90 } 48 91 if (!strcasecmp (breakPt, "BACKMDL")) { 49 return psphotReadoutCleanup (config, view, STACK_OUT); 50 } 51 52 // load the psf model, if suppled. FWHM_X,FWHM_Y,etc are determined and saved on 53 // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT 54 if (!psphotLoadPSF (config, view, STACK_RAW)) { 55 psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model"); 56 return psphotReadoutCleanup (config, view, STACK_OUT); 57 } 58 59 if (!psphotStackChisqImage(config, view, STACK_RAW, STACK_OUT)) { 92 return psphotReadoutCleanup (config, view, STACK_SRC); 93 } 94 95 if (!psphotStackChisqImage(config, view, STACK_DET, STACK_SRC)) { 60 96 psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image"); 61 return psphotReadoutCleanup (config, view, STACK_ OUT);97 return psphotReadoutCleanup (config, view, STACK_SRC); 62 98 } 63 99 if (!strcasecmp (breakPt, "CHISQ")) { 64 return psphotReadoutCleanup (config, view, STACK_ OUT);100 return psphotReadoutCleanup (config, view, STACK_SRC); 65 101 } 66 102 67 103 // find the detections (by peak and/or footprint) in the image. 68 104 // This finds the detections on Chisq image as well as the individuals 69 if (!psphotFindDetections (config, view, STACK_ RAW, true)) { // pass 1105 if (!psphotFindDetections (config, view, STACK_DET, true)) { // pass 1 70 106 // this only happens if we had an error in psphotFindDetections 71 107 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 72 return psphotReadoutCleanup (config, view, STACK_OUT); 73 } 74 75 // copy the detections from RAW to OUT 76 if (!psphotCopySources (config, view, STACK_OUT, STACK_RAW)) { 77 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 78 return psphotReadoutCleanup (config, view, STACK_OUT); 108 return psphotReadoutCleanup (config, view, STACK_SRC); 109 } 110 111 // copy the detections from DET to SRC 112 if (strcmp(STACK_SRC, STACK_DET)) { 113 if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) { 114 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 115 return psphotReadoutCleanup (config, view, STACK_SRC); 116 } 79 117 } 80 118 81 119 // construct sources and measure basic stats (saved on detections->newSources) 82 // only run this on detections from the input images, not chisq image 83 if (!psphotSourceStats (config, view, STACK_OUT, true)) { // pass 1 120 if (!psphotSourceStats (config, view, STACK_SRC, true)) { // pass 1 84 121 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 85 return psphotReadoutCleanup (config, view, STACK_OUT); 122 return psphotReadoutCleanup (config, view, STACK_SRC); 123 } 124 125 if (!strcasecmp (breakPt, "TEST1")) { 126 return psphotReadoutCleanup (config, view, STACK_SRC); 86 127 } 87 128 88 129 // generate the objects (object unify the sources from the different images) 89 psArray *objects = psphotMatchSources (config, view, STACK_OUT); 130 // XXX this could just match the detections for the chisq image, and not bother measuring the 131 // source stats in that case... 132 psArray *objects = psphotMatchSources (config, view, STACK_SRC); 133 134 if (!strcasecmp (breakPt, "TEST2")) { 135 psFree(objects); 136 return psphotReadoutCleanup (config, view, STACK_SRC); 137 } 90 138 91 139 // construct sources for the newly-generated sources (from other images) 92 if (!psphotSourceStats (config, view, STACK_OUT, false)) { // pass 1 140 if (!psphotSourceStats (config, view, STACK_SRC, false)) { // pass 1 141 psFree(objects); 93 142 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 94 return psphotReadoutCleanup (config, view, STACK_ OUT);143 return psphotReadoutCleanup (config, view, STACK_SRC); 95 144 } 96 145 … … 98 147 // if (!psphotDeblendSatstars (config, view)) { 99 148 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 100 // return psphotReadoutCleanup (config, view, STACK_ OUT);149 // return psphotReadoutCleanup (config, view, STACK_SRC); 101 150 // } 102 151 … … 104 153 // if (!psphotBasicDeblend (config, view)) { 105 154 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis"); 106 // return psphotReadoutCleanup (config, view, STACK_ OUT);155 // return psphotReadoutCleanup (config, view, STACK_SRC); 107 156 // } 108 157 109 158 // classify sources based on moments, brightness 110 159 // only run this on detections from the input images, not chisq image 111 if (!psphotRoughClass (config, view, STACK_OUT)) { 160 if (!psphotRoughClass (config, view, STACK_SRC)) { 161 psFree(objects); 112 162 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 113 return psphotReadoutCleanup (config, view, STACK_ OUT);163 return psphotReadoutCleanup (config, view, STACK_SRC); 114 164 } 115 165 // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources) 116 166 // only run this on detections from the input images, not chisq image 117 if (!psphotImageQuality (config, view, STACK_OUT)) { // pass 1 167 if (!psphotImageQuality (config, view, STACK_SRC)) { // pass 1 168 psFree(objects); 118 169 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); 119 return psphotReadoutCleanup (config, view, STACK_ OUT);170 return psphotReadoutCleanup (config, view, STACK_SRC); 120 171 } 121 172 if (!strcasecmp (breakPt, "MOMENTS")) { 122 return psphotReadoutCleanup (config, view, STACK_OUT); 173 psFree(objects); 174 return psphotReadoutCleanup (config, view, STACK_SRC); 123 175 } 124 176 125 177 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 126 178 // this step is skipped 127 if (!psphotChoosePSF (config, view, STACK_OUT)) { // pass 1 179 if (!psphotChoosePSF (config, view, STACK_SRC, true)) { // pass 1 180 psFree(objects); 128 181 psLogMsg ("psphot", 3, "failure to construct a psf model"); 129 return psphotReadoutCleanup (config, view, STACK_ OUT);182 return psphotReadoutCleanup (config, view, STACK_SRC); 130 183 } 131 184 if (!strcasecmp (breakPt, "PSFMODEL")) { 132 return psphotReadoutCleanup (config, view, STACK_OUT); 185 psFree(objects); 186 return psphotReadoutCleanup (config, view, STACK_SRC); 133 187 } 134 188 135 189 // construct an initial model for each object, set the radius to fitRadius, set circular fit mask 136 psphotGuessModels (config, view, STACK_ OUT);190 psphotGuessModels (config, view, STACK_SRC); 137 191 138 192 // merge the newly selected sources into the existing list 139 193 // NOTE: merge OLD and NEW 140 psphotMergeSources (config, view, STACK_ OUT);194 psphotMergeSources (config, view, STACK_SRC); 141 195 142 196 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 143 197 psphotFitSourcesLinearStack (config, objects, FALSE); 198 psphotStackVisualFilerule(config, view, STACK_SRC); 144 199 145 200 // identify CRs and extended sources 146 psphotSourceSize (config, view, STACK_OUT, TRUE); 201 psphotSourceSize (config, view, STACK_SRC, TRUE); 202 203 // XXX do we want to do a preliminary (unconvolved) model fit here, and then 204 // do a second detection pass? (like standard psphot) 147 205 148 206 // measure aperture photometry corrections 149 if (!psphotApResid (config, view, STACK_ OUT)) {207 if (!psphotApResid (config, view, STACK_SRC)) { 150 208 psFree (objects); 151 209 psLogMsg ("psphot", 3, "failed on psphotApResid"); 152 return psphotReadoutCleanup (config, view, STACK_ OUT);210 return psphotReadoutCleanup (config, view, STACK_SRC); 153 211 } 154 212 155 213 psphotStackObjectsUnifyPosition (objects); 156 214 157 // measure circular, radial apertures (objects sorted by S/N)158 psphotRadialAperturesByObject (config, objects, view, STACK_OUT);159 160 215 // measure elliptical apertures, petrosians (objects sorted by S/N) 161 psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_ OUT); // pass 1 (detections->allSources)216 psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_SRC); // pass 1 (detections->allSources) 162 217 163 218 // measure non-linear extended source models (exponential, deVaucouleur, Sersic) (sources sorted by S/N) 164 psphotExtendedSourceFits (config, view, STACK_ OUT); // pass 1 (detections->allSources)219 psphotExtendedSourceFits (config, view, STACK_SRC); // pass 1 (detections->allSources) 165 220 166 221 // calculate source magnitudes 167 psphotMagnitudes(config, view, STACK_OUT); 222 psphotMagnitudes(config, view, STACK_SRC); 223 224 // create source children for the OUT filerule (for radial aperture photometry) 225 psArray *objectsRadial = psphotSourceChildrenByObject (config, view, STACK_OUT, objects); 226 if (!objectsRadial) { 227 psFree(objects); 228 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 229 return psphotReadoutCleanup (config, view, STACK_SRC); 230 } 231 232 bool smoothAgain = true; 233 for (int nMatchedPSF = 0; smoothAgain; nMatchedPSF++) { 234 235 // re-measure the PSF for the smoothed image (using entries in 'allSources') 236 psphotChoosePSF (config, view, STACK_OUT, false); 237 238 // this is necessary to update the models based on the new PSF 239 psphotResetModels (config, view, STACK_OUT); 240 241 // this is necessary to get the right normalization for the new models 242 psphotFitSourcesLinear (config, view, STACK_OUT, false); 243 244 // measure circular, radial apertures (objects sorted by S/N) 245 psphotRadialAperturesByObject (config, objectsRadial, view, STACK_OUT, nMatchedPSF); 246 247 // replace the flux in the image so it is returned to its original state 248 psphotReplaceAllSources (config, view, STACK_OUT); 249 250 // smooth to the next FWHM, or set 'smoothAgain' to false if no more 251 psphotStackMatchPSFsNext(&smoothAgain, config, view, STACK_OUT, nMatchedPSF); 252 } 168 253 169 254 if (0 && !psphotEfficiency(config, view, STACK_OUT)) { … … 176 261 177 262 // replace background in residual image 178 psphotSkyReplace (config, view, STACK_ RAW);263 psphotSkyReplace (config, view, STACK_DET); 179 264 180 265 // drop the references to the image pixels held by each source 181 psphotSourceFreePixels (config, view, STACK_OUT); 182 183 // remove chisq image from config->file:PSPHOT.INPUT (why?) 184 psphotStackRemoveChisqFromInputs(config, STACK_RAW); 266 // psphotSourceFreePixels (config, view, STACK_OUT); 267 psphotSourceFreePixels (config, view, STACK_SRC); 268 269 // remove chisq image from config->file:PSPHOT.INPUT 270 psphotStackRemoveChisqFromInputs(config, STACK_DET); 271 if (strcmp(STACK_SRC, STACK_DET)) { 272 psphotStackRemoveChisqFromInputs(config, STACK_SRC); 273 } 185 274 186 275 psFree (objects); 276 psFree (objectsRadial); 187 277 188 278 // create the exported-metadata and free local data 189 return psphotReadoutCleanup (config, view, STACK_ OUT);279 return psphotReadoutCleanup (config, view, STACK_SRC); 190 280 } 191 281 282 /* here is the process: 283 284 * we have three(*) images: 285 * RAW : unconvolved image stack 286 * CNV : input convolved image 287 288 * OUT : psf-matched output image (there may be more than one of 289 * these. we will generate the first matched image by selecting the 290 * target PSF and doing a full psf-maching process (as used by ppStack 291 * and ppSub). But, additional target output files should use a 292 * simple gaussian convolution kernel determind from therms of the 293 * current and the target). 294 295 * the output should be / could be one of the matched images, but not 296 * all. should we ensure the first gets written out, and ot save the 297 * others (or only optionally). 298 299 * by default, we probably only sve the cmf ffile outputs. 300 301 * load the RAW image (unconvolved stacks) 302 * add photcode to the output headers / readout->analysis 303 * generate mask and variance image (this is probably never needed in 304 practice: we always load an input mask & var. 305 * generate & subtract a model background for ?? (RAW? CNV? OUT? all?) 306 * load a PSF (probably not yet working) 307 308 * generate the CHISQ image from the RAW input images (why save on OUT?) 309 310 * find detections on RAW 311 312 * copy detections to OUT 313 314 * generate source stats (moments) for OUT 315 316 * match sources across inputs (on OUT?) 317 318 * generate source stats for the new constructions 319 320 * rough class (star, galaxy, cosmic, etc) 321 322 * Image quality 323 324 * generate PSF 325 326 * guess models 327 328 * merge sources (new -> old) 329 330 * linear fit to the psf 331 332 * find ApResid 333 334 * assign common positions 335 336 * radial apertures (** this should be on the PSF-matched images 337 338 * extended analysis (elliptical profile & petrosian) 339 340 * extended fits (sersic, etc) 341 342 * psphot magnitudes 343 344 345 ****** 346 347 the above is all wrong: first, we should be doing the full 348 morphology analysis (ExtendedAnalysis & ExtendedFits) on the CNV or 349 RAW image (as desired optionally), etc. 350 351 In the discussion below, 'BST' (best) means optionally RAW or CNV 352 353 * detection : RAW & CHISQ (of RAW) 354 * moments : used by psf analysis & classification (BST) 355 * rough class : uses moments, not pixels 356 * image quality : uses moments as well 357 * generate PSF : (BST) 358 * guess models (BST) 359 * linear fit (BST) 360 * find ApResid (BST) -- uses sources not pixels 361 * extended analysis (BST) 362 * extended fits (BST) 363 * detection efficiency (BST) 364 365 * somehow need to copy the sources so they point at the pixels on the 366 * OUT image 367 368 * foreach target PSF 369 * radial aperture 370 * convolve to next target PSF 371 372 * somehow need to organize the output file to have the values from 373 * the different PSFs in separate tables (with header info to 374 * specify the size of that PSF) 375 376 */ -
branches/czw_branch/20101203/psphot/src/psphotVisual.c
r29548 r30631 93 93 strcpy (coords.ctype, "RA---TAN"); 94 94 95 psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);96 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);97 if (!psImageBackground(stats, NULL, inImage, NULL, 0, rng)) {98 fprintf (stderr, "failed to get background values\n");99 return false;100 }101 102 95 image.Nx = inImage->numCols; 103 96 image.Ny = inImage->numRows; … … 125 118 free (image.data2d); 126 119 120 return true; 121 } 122 123 bool psphotVisualShowObjectRegions (pmReadout *readout, psMetadata *recipe, psArray *sources) { 124 125 KiiImage image; 126 KapaImageData data; 127 Coords coords; 128 129 bool status = false; 130 131 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 132 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 133 assert (maskVal); 134 135 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); // Mask value for bad pixels 136 assert (maskVal); 137 138 maskVal |= markVal; 139 140 if (!pmVisualTestLevel("psphot.image.objects", 2)) return true; 141 142 int kapa = psphotKapaChannel (1); 143 if (kapa == -1) return false; 144 145 strcpy (coords.ctype, "RA---TAN"); 146 147 psImage *inImage = readout->image; 148 psImage *inMask = readout->mask; 149 image.Nx = inImage->numCols; 150 image.Ny = inImage->numRows; 151 152 psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 153 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); 154 if (!psImageBackground(stats, NULL, inImage, inMask, 0xffff, rng)) { 155 fprintf (stderr, "failed to get background values\n"); 156 return false; 157 } 158 159 ALLOCATE (image.data2d, float *, image.Ny); 160 for (int iy = 0; iy < image.Ny; iy++) { 161 ALLOCATE (image.data2d[iy], float, image.Nx); 162 for (int ix = 0; ix < image.Nx; ix++) { 163 image.data2d[iy][ix] = 0; 164 } 165 } 166 167 // loop over sources and set unmasked pixels to 0 168 for (int i = 0; i < sources->n; i++) { 169 170 pmSource *source = sources->data[i]; 171 if (source == NULL) continue; 172 173 psImage *mask = source->maskObj; 174 if (mask == NULL) continue; 175 176 for (int iy = 0; iy < mask->numRows; iy++) { 177 int jy = iy + mask->row0; 178 if (jy < 0) continue; 179 if (jy >= inImage->numRows) continue; 180 for (int ix = 0; ix < mask->numCols; ix++) { 181 int jx = ix + mask->col0; 182 if (jx < 0) continue; 183 if (jx >= inImage->numCols) continue; 184 185 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) continue; 186 image.data2d[jy][jx] = 1; 187 } 188 } 189 } 190 191 for (int iy = 0; iy < image.Ny; iy++) { 192 for (int ix = 0; ix < image.Nx; ix++) { 193 image.data2d[iy][ix] = (image.data2d[iy][ix] == 0.0) ? NAN : inImage->data.F32[iy][ix]; 194 } 195 } 196 197 strcpy (data.name, "maskObj"); 198 strcpy (data.file, "maskObj"); 199 // data.zero = 0.0; 200 // data.range = 1.0; 201 data.zero = stats->robustMedian - stats->robustStdev; 202 data.range = 5*stats->robustStdev; 203 data.logflux = 0; 204 205 KiiSetChannel (kapa, 2); 206 KiiNewPicture2D (kapa, &image, &data, &coords); 207 208 for (int iy = 0; iy < image.Ny; iy++) { 209 free (image.data2d[iy]); 210 } 211 free (image.data2d); 212 127 213 psFree (stats); 128 214 psFree (rng); 129 215 216 pmVisualAskUser(NULL); 130 217 return true; 131 218 } … … 2401 2488 } 2402 2489 2403 bool psphotVisualShowResidualImage (pmReadout *readout) { 2490 // option to redo variance since in some cases we may have displayed a different image in the meanwhile 2491 bool psphotVisualShowResidualImage (pmReadout *readout, bool reshow) { 2404 2492 2405 2493 if (!pmVisualTestLevel("psphot.image.resid", 2)) return true; … … 2408 2496 if (myKapa == -1) return false; 2409 2497 2410 psphotVisualScaleImage (myKapa, readout->image, readout->mask, "resid", 1); 2498 if (reshow) { 2499 psphotVisualShowMask (myKapa, readout->mask, "mask", 2); 2500 psphotVisualScaleImage (myKapa, readout->variance, readout->mask, "variance", 1); 2501 } 2502 psphotVisualScaleImage (myKapa, readout->image, readout->mask, "resid", 0); 2411 2503 2412 2504 pmVisualAskUser(NULL); -
branches/czw_branch/20101203/pstamp/scripts/pstamp_checkdependent.pl
r30587 r30631 153 153 154 154 # assume the fault is transient. 155 # fault the dependent to give the fault a chance to correct itself 155 156 my_die("Component faulted on update dep_id: $dep_id", $PS_EXIT_SYS_ERROR); 156 157 } … … 410 411 411 412 if ($warp->{data_state} ne 'full') { 412 my $warp_status = check_states_warp($warp, 0,$rlabel, $need_magic);413 my $warp_status = check_states_warp($warp, $rlabel, $need_magic); 413 414 if ($warp_status eq $PSTAMP_GONE) { 414 415 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); … … 426 427 if ($warp1->{data_state} ne 'full') { 427 428 $warps_ready = 0; 428 $warp_status = check_states_warp($warp1, 0,$rlabel, $need_magic);429 $warp_status = check_states_warp($warp1, $rlabel, $need_magic); 429 430 if ($warp_status) { 430 431 if ($warp_status eq $PSTAMP_GONE) { … … 440 441 if ($warp2->{data_state} ne 'full') { 441 442 $warps_ready = 0; 442 $warp_status = check_states_warp($warp2, 0,$rlabel, $need_magic);443 $warp_status = check_states_warp($warp2, $rlabel, $need_magic); 443 444 if ($warp_status eq $PSTAMP_GONE) { 444 445 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); … … 493 494 494 495 if ($warp->{data_state} ne 'full') { 495 my $warp_status = check_states_warp($warp, 0,$rlabel, $need_magic);496 my $warp_status = check_states_warp($warp, $rlabel, $need_magic); 496 497 if ($warp_status eq $PSTAMP_GONE) { 497 498 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE);
Note:
See TracChangeset
for help on using the changeset viewer.
