From 3cfed4b7ba30e222fcf88310fba289c7465ac013 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 29 Mar 2019 15:46:07 +0100 Subject: [PATCH] Add unit tests for all example scripts --- cscripts/Makefile.am | 3 ++- examples/README.md | 11 ++++++++++- examples/show_variability_evolution.py | 8 ++++---- test/data/skymap_ring.fits | Bin 51840 -> 0 bytes test/data/variability.fits.gz | Bin 0 -> 1896 bytes test/test_examples.py.in | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------- 6 files changed, 92 insertions(+), 170 deletions(-) create mode 100644 test/data/variability.fits.gz diff --git a/cscripts/Makefile.am b/cscripts/Makefile.am index 9ab52b7..651d69d 100755 --- a/cscripts/Makefile.am +++ b/cscripts/Makefile.am @@ -234,7 +234,8 @@ testdata = $(top_srcdir)/test/data/crab.xml \ $(top_srcdir)/test/data/onoff_rmf1.fits.gz \ $(top_srcdir)/test/data/onoff_rmf2.fits.gz \ $(top_srcdir)/test/data/model_crab_radialacceptance.xml \ - $(top_srcdir)/test/data/sigdist_map.fits.gz + $(top_srcdir)/test/data/sigdist_map.fits.gz \ + $(top_srcdir)/test/data/variability.fits.gz # Test data to be distributed in $(pyexecdir)/cscripts/tests/data/iactdata testiactdata = $(top_srcdir)/test/data/iactdata/hdu-index.fits.gz \ diff --git a/examples/README.md b/examples/README.md index eb37522..4305468 100755 --- a/examples/README.md +++ b/examples/README.md @@ -41,12 +41,21 @@ the ctools. `show_pull_histogram.py` > Displays pull histograms generated by the cspull script. +`show_residuals.py` +> Displays residuals generated by csresspec. + `show_response.py` > Displays one or several CTA response functions. +`show_rmf.py` +> Displays Redistribution Matrix File. + `show_sensitivity.py` > Displays the sensitivity generated by the cssens script. +`show_significance_distribution.py` +> Displays distribution of significances in a given significance map. + `show_spectrum.py` > Displays spectrum generated by the csspec script. @@ -54,4 +63,4 @@ the ctools. > Displays Test Statistic histograms generated using the cstsdist script. `show_variability_evolution.py` -> Displays the results for a given source generated by the ctfindvar script. \ No newline at end of file +> Displays the results for a given source generated by the ctfindvar script. diff --git a/examples/show_variability_evolution.py b/examples/show_variability_evolution.py index 9f9adf1..e1adfc8 100755 --- a/examples/show_variability_evolution.py +++ b/examples/show_variability_evolution.py @@ -83,10 +83,10 @@ def plot_variability_evolution(filename, plotfile, srcname): axarr[1].set_ylabel('Counts') # Optionally save result in file - if plotfile != "": - f.savefig(plotfile+".png") - - plt.show() + if len(plotfile) > 0: + plt.savefig(plotfile) + else: + plt.show() # Return return diff --git a/test/data/skymap_ring.fits b/test/data/skymap_ring.fits index f3cd4c1..e8cb731 100644 Binary files a/test/data/skymap_ring.fits and b/test/data/skymap_ring.fits differ diff --git a/test/data/variability.fits.gz b/test/data/variability.fits.gz new file mode 100644 index 0000000..3518955 Binary files /dev/null and b/test/data/variability.fits.gz differ diff --git a/test/test_examples.py.in b/test/test_examples.py.in index 641f6a8..3606a18 100755 --- a/test/test_examples.py.in +++ b/test/test_examples.py.in @@ -95,12 +95,18 @@ class Test(gammalib.GPythonTestSuite): 'Test show_butterfly.py') self.append(self.test_show_irf, 'Test show_irf.py') + self.append(self.test_show_lightcurve, + 'Test show_lightcurve.py') self.append(self.test_show_model, 'Test show_model.py') + self.append(self.test_show_obs, + 'Test show_obs.py') self.append(self.test_show_pha, 'Test show_pha.py') self.append(self.test_show_phases, 'Test show_phases.py') + self.append(self.test_show_pointings, + 'Test show_pointings.py') self.append(self.test_show_pull_evolution, 'Test show_pull_evolution.py') self.append(self.test_show_pull_histogram, @@ -113,18 +119,14 @@ class Test(gammalib.GPythonTestSuite): 'Test show_rmf.py') self.append(self.test_show_sensitivity, 'Test show_sensitivity.py') + self.append(self.test_show_significance_distribution, + 'Test show_significance_distribution.py') self.append(self.test_show_spectrum, 'Test show_spectrum.py') - self.append(self.test_show_lightcurve, - 'Test show_lightcurve.py') self.append(self.test_show_ts_distribution, - 'Test ts_distribution.py') - self.append(self.test_show_obs, - 'Test show_obs.py') - self.append(self.test_show_pointings, - 'Test show_pointings.py') - self.append(self.test_show_significance_distribution, - 'Test show_significance_distribution.py') + 'Test show_ts_distribution.py') + self.append(self.test_show_variability_evolution, + 'Test show_variability_evolution.py') # Return return @@ -148,155 +150,85 @@ class Test(gammalib.GPythonTestSuite): # Return return - # Test generate_prod3_irfs - def test_generate_prod3_irfs(self): - """ - Test generate_prod3_irfs - """ - # Execute script - self._execute_python('generate_prod3_irfs', args=self._datadir) - - # Return - return - - # Test make_spectrum - def test_make_spectrum(self): + # Test show_butterfly + def test_show_butterfly(self): """ - Test make_spectrum + Test show_butterfly """ # Set arguments - args = '-d %s -p example_spectrum.eps' % self._datadir + args = '-p example_show_butterfly.eps %s/butterfly.txt' % self._datadir # Execute script - self._execute_python('make_spectrum', args=args) + self._execute_python('show_butterfly', args=args) # Return return - # Test make_ts_distributions - def test_make_ts_distributions(self): + # Test show_irf + def test_show_irf(self): """ - Test make_ts_distributions + Test show_irf """ # Set arguments - args = '-n 1 -e 0 -t 100 -d %s' % self._datadir - - # Execute script - self._execute_python('make_ts_distributions', args=args) - - # Return - return - - # Test pipeline_binned_disk - def test_pipeline_binned_disk(self): - """ - Test pipeline_binned_disk - """ - # Execute script - self._execute_python('pipeline_binned_disk', args='-d '+self._datadir) - - # Return - return - - # Test pipeline_binned_mem - def test_pipeline_binned_mem(self): - """ - Test pipeline_binned_mem - """ - # Execute script - self._execute_python('pipeline_binned_mem', args='-d '+self._datadir) - - # Return - return - - # Test pipeline_stacked_disk - def test_pipeline_stacked_disk(self): - """ - Test pipeline_stacked_disk - """ - # Execute script - self._execute_python('pipeline_stacked_disk', args='-d '+self._datadir) - - # Return - return + args = '-p example_show_irf.eps prod2 South_0.5h' - # Test pipeline_stacked_mem - def test_pipeline_stacked_mem(self): - """ - Test pipeline_stacked_mem - """ # Execute script - self._execute_python('pipeline_stacked_mem', args='-d '+self._datadir) + self._execute_python('show_irf', args=args) # Return return - # Test pipeline_unbinned_disk - def test_pipeline_unbinned_disk(self): + # Test show_lightcurve + def test_show_lightcurve(self): """ - Test pipeline_unbinned_disk + Test show_lightcurve """ - # Execute script - self._execute_python('pipeline_unbinned_disk', args='-d '+self._datadir) - - # Return - return + # Set arguments + args = '-p example_show_lightcurve.eps %s/lightcurve.fits' % self._datadir - # Test pipeline_unbinned_mem - def test_pipeline_unbinned_mem(self): - """ - Test pipeline_unbinned_mem - """ # Execute script - self._execute_python('pipeline_unbinned_mem', args='-d '+self._datadir) + self._execute_python('show_lightcurve', args=args) # Return return - # Test show_butterfly - def test_show_butterfly(self): + # Test show_model + def test_show_model(self): """ - Test show_butterfly + Test show_model """ # Set arguments - args = '-p example_show_butterfly.eps %s/butterfly.txt' % self._datadir + args = '-n Crab -p example_show_model1.eps %s/crab.xml' % self._datadir # Execute script - self._execute_python('show_butterfly', args=args) - - # Return - return + self._execute_python('show_model', args=args) - # Test show_irf - def test_show_irf(self): - """ - Test show_irf - """ - # Set arguments - args = '-p example_show_irf.eps prod2 South_0.5h' + # Set new arguments + args = '-p example_show_model2.eps %s/crab.xml' % self._datadir # Execute script - self._execute_python('show_irf', args=args) + self._execute_python('show_model', args=args) # Return return - # Test show_model - def test_show_model(self): + # Test show_obs + def test_show_obs(self): """ - Test show_model + Test show_obs """ # Set arguments - args = '-n Crab -p example_show_model1.eps %s/crab.xml' % self._datadir + args = '-p example_show_obs1.eps %s/obs_unbinned.xml' % self._datadir # Execute script - self._execute_python('show_model', args=args) + self._execute_python('show_obs', args=args) - # Set new arguments - args = '-p example_show_model2.eps %s/crab.xml' % self._datadir + # Set arguments + args = ('-ra 83.63 -dec 22.01 -p example_show_obs2.eps ' + '%s/obs_unbinned.xml' % self._datadir) # Execute script - self._execute_python('show_model', args=args) + self._execute_python('show_obs', args=args) # Return return @@ -335,6 +267,20 @@ class Test(gammalib.GPythonTestSuite): # Return return + # Test show_pointings + def test_show_pointings(self): + """ + Test show_pointings + """ + # Set arguments + args = '-p example_show_pointings.eps %s/obs_unbinned.xml' % self._datadir + + # Execute script + self._execute_python('show_pointings', args=args) + + # Return + return + # Test show_pull_evolution def test_show_pull_evolution(self): """ @@ -443,30 +389,32 @@ class Test(gammalib.GPythonTestSuite): # Return return - # Test show_spectrum - def test_show_spectrum(self): + # Test show_significance_distribution + def test_show_significance_distribution(self): """ - Test show_spectrum + Test show_significance_distribution """ # Set arguments - args = '-p example_show_spectrum.eps %s/spectrum.fits' % self._datadir + args = '-p example_show_significance_distribution.eps '+ \ + '%s/sigdist_map.fits --exclude %s/sigdist_map.fits[EXCLUSION]' % \ + (self._datadir, self._datadir) # Execute script - self._execute_python('show_spectrum', args=args) + self._execute_python('show_significance_distribution', args=args) # Return return - # Test show_lightcurve - def test_show_lightcurve(self): + # Test show_spectrum + def test_show_spectrum(self): """ - Test show_lightcurve + Test show_spectrum """ # Set arguments - args = '-p example_show_lightcurve.eps %s/lightcurve.fits' % self._datadir + args = '-p example_show_spectrum.eps %s/spectrum.fits' % self._datadir # Execute script - self._execute_python('show_lightcurve', args=args) + self._execute_python('show_spectrum', args=args) # Return return @@ -493,53 +441,17 @@ class Test(gammalib.GPythonTestSuite): # Return return - # Test show_obs - def test_show_obs(self): - """ - Test show_obs - """ - # Set arguments - args = '-p example_show_obs1.eps %s/obs_unbinned.xml' % self._datadir - - # Execute script - self._execute_python('show_obs', args=args) - - # Set arguments - args = ('-ra 83.63 -dec 22.01 -p example_show_obs2.eps ' - '%s/obs_unbinned.xml' % self._datadir) - - # Execute script - self._execute_python('show_obs', args=args) - - # Return - return - - # Test show_pointings - def test_show_pointings(self): - """ - Test show_pointings - """ - # Set arguments - args = '-p example_show_pointings.eps %s/obs_unbinned.xml' % self._datadir - - # Execute script - self._execute_python('show_pointings', args=args) - - # Return - return - - # Test show_significance_distribution - def test_show_significance_distribution(self): + # Test show_variability_evolution + def test_show_variability_evolution(self): """ - Test show_significance_distribution + Test show_variability_evolution """ # Set arguments - args = '-p example_show_significance_distribution.eps '+ \ - '%s/sigdist_map.fits --exclude %s/sigdist_map.fits[EXCLUSION]' % \ - (self._datadir, self._datadir) + args = ('-p example_show_variability_evolution.eps %s/variability.fits' % + self._datadir) # Execute script - self._execute_python('show_significance_distribution', args=args) + self._execute_python('show_variability_evolution', args=args) # Return return -- libgit2 0.21.4