diff --git a/.gitignore b/.gitignore index 15c3b77..ad3dd70 100644 --- a/.gitignore +++ b/.gitignore @@ -82,6 +82,7 @@ test/*.reg test/*.trs test/*.txt test/*.eps +test/*.jpg test/test_cscripts.sh test/test_examples.py test/reports/*.xml diff --git a/examples/show_obs.py b/examples/show_obs.py index 7482e50..c4fe817 100755 --- a/examples/show_obs.py +++ b/examples/show_obs.py @@ -2,9 +2,6 @@ # ========================================================================== # Display summary of observation definition XML file # -# Required 3rd party modules: -# - matplotlib -# # Copyright (C) 2016 Michael Mayer # # This program is free software: you can redistribute it and/or modify @@ -40,17 +37,14 @@ except: if __name__ == '__main__': # Print help if wrong number of arguments provided - if not len(sys.argv) > 1: - msg = 'Usage: inspect_obs.py \n' - msg += 'or\n' - msg += 'inspect_obs.py ' - sys.exit(msg) - - # Initialise flag if plots should be shown or saved - save = False - if 'save' in sys.argv: - save = True - + if len(sys.argv) < 2: + sys.exit('Usage: inspect_obs.py inobs.xml [ra] [dec] [file]') + + # Check if plotting in file is requested + plotfile = '' + if len(sys.argv) == 3: + plotfile = sys.argv[2] + # Get input observation XML file inobs = gammalib.GFilename(sys.argv[1]) @@ -65,10 +59,10 @@ if __name__ == '__main__': # Add offset if coordinates are provided if len(sys.argv) == 4: - ra = float(sys.argv[2]) + ra = float(sys.argv[2]) dec = float(sys.argv[3]) - info['ra'] = ra - info['dec'] = dec + info['ra'] = ra + info['dec'] = dec info['offset'] = True info['inobs'] = inobs.url() info['debug'] = True @@ -80,61 +74,64 @@ if __name__ == '__main__': offsets = info.offsets() ebounds = info.ebounds() gti = info.gti() - - # Plot zenith angle distribution + + # Create figure with subplots + nrows = 2 + ncols = 2 + if info['offset'].boolean() and ebounds.size() > 0: + ncols += 1 + iplot = 1 plt.figure() + plt.subplot(nrows, ncols, iplot) + + # Plot zenith angle distribution zmin = min(zeniths) zmax = max(zeniths) plt.hist(zeniths, bins=30, range=(zmin, zmax), fc='blue') plt.xlabel('Zenith Angle [deg]') plt.ylabel('Abundance') plt.title('Zenith angle distribution') - if save: - plt.savefig('Zenith angle distribution.eps') - + # Plot azimuth angle distribution - plt.figure() + iplot += 1 + plt.subplot(nrows, ncols, iplot) amin = min(azimuths) amax = max(azimuths) plt.hist(azimuths, bins=30, range=(amin, amax), fc='blue') plt.xlabel('Azimuth Angle (deg)') plt.ylabel('Abundance') plt.title('Azimuth distribution') - if save: - plt.savefig('Azimuth distribution.eps') - + # Plot offset if possible if info['offset'].boolean(): - plt.figure() + iplot += 1 + plt.subplot(nrows, ncols, iplot) omin = min(offsets) omax = max(offsets) plt.hist(offsets, bins=30, range=(omin, omax), fc='blue') plt.xlabel('Offset from (RA, DEC)=('+str(ra)+','+str(dec)+') (deg)') plt.ylabel('Abundance') plt.title('Offset distribution') - if save: - plt.savefig('Offset distribution.eps') - + # Plot energy thresholds if possible - if ebounds.size(): - + if ebounds.size() > 0: emin = [] emax = [] for i in range(ebounds.size()): emin.append(ebounds.emin(i).log10TeV()) emax.append(ebounds.emax(i).log10TeV()) - plt.figure() + iplot += 1 + plt.subplot(nrows, ncols, iplot) plt.hist(emin, bins=80, range=(-1.0, 2.0), fc='red', label='emin') plt.hist(emax, bins=80, range=(-1.0, 2.0), fc='blue', label='emax') plt.xlabel('Energy threshold (log10 (E/TeV))') plt.ylabel('Abundance') plt.legend(loc='upper left') plt.title('Energy threshold') - if save: - plt.savefig('Energy threshold.eps') - + # Plot observation point in time wrt zenith angle - plt.figure() + iplot += 1 + plt.subplot(nrows, ncols, iplot) times = [] for i in range(gti.size()): tmean = gti.tstart(i) + 0.5*(gti.tstart(i)-gti.tstart(i)) @@ -143,12 +140,9 @@ if __name__ == '__main__': plt.xlabel('Time (MJD)') plt.ylabel('Zenith Angle (deg)') plt.title('Observation time') - if save: - plt.savefig('Observation time.eps') - # Display plots if possible - if not save: - - # Show plots + # Show plots or save it into file + if len(plotfile) > 0: + plt.savefig(plotfile) + else: plt.show() - \ No newline at end of file diff --git a/test/test_examples.py.in b/test/test_examples.py.in index 94c39ec..ce572b1 100755 --- a/test/test_examples.py.in +++ b/test/test_examples.py.in @@ -129,8 +129,6 @@ class Test(gammalib.GPythonTestSuite): self._execute_python(script, args='gc', log='make_pointings_gc') self._execute_python(script, args='lmc', log='make_pointings_lmc') - #TODO: Do any testing - # Return return @@ -142,8 +140,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('generate_prod3_irfs') - #TODO: Do any testing - # Return return @@ -155,8 +151,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('make_spectrum', args='eps') - #TODO: Do any testing - # Return return @@ -168,8 +162,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('make_ts_distributions', args='-n 2 -e 0 -d 1800') - #TODO: Do any testing - # Return return @@ -181,8 +173,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('pipeline_binned_disk') - #TODO: Do any testing - # Return return @@ -194,8 +184,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('pipeline_binned_mem') - #TODO: Do any testing - # Return return @@ -207,8 +195,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('pipeline_stacked_disk') - #TODO: Do any testing - # Return return @@ -220,8 +206,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('pipeline_stacked_mem') - #TODO: Do any testing - # Return return @@ -233,8 +217,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('pipeline_unbinned_disk') - #TODO: Do any testing - # Return return @@ -246,8 +228,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('pipeline_unbinned_mem') - #TODO: Do any testing - # Return return @@ -261,8 +241,6 @@ class Test(gammalib.GPythonTestSuite): args='data/butterfly.txt ' 'example_show_butterfly.eps') - #TODO: Do any testing - # Return return @@ -275,8 +253,6 @@ class Test(gammalib.GPythonTestSuite): self._execute_python('show_model', args='data/crab.xml Crab example_show_model.eps') - #TODO: Do any testing - # Return return @@ -289,8 +265,6 @@ class Test(gammalib.GPythonTestSuite): self._execute_python('show_pha', args='data/pha.fits example_show_pha.eps') - #TODO: Do any testing - # Return return @@ -304,8 +278,6 @@ class Test(gammalib.GPythonTestSuite): args='data/pull.dat Pull_Crab_Prefactor ' 'example_show_pull_evolution.eps') - #TODO: Do any testing - # Return return @@ -319,8 +291,6 @@ class Test(gammalib.GPythonTestSuite): args='data/pull.dat Pull_Crab_Prefactor 50 ' 'example_show_pull_histogram.eps') - #TODO: Do any testing - # Return return @@ -332,8 +302,6 @@ class Test(gammalib.GPythonTestSuite): # Execute script self._execute_python('show_response', args='example_show_response.eps') - #TODO: Do any testing - # Return return @@ -347,8 +315,6 @@ class Test(gammalib.GPythonTestSuite): args='data/sensitivity.dat ' 'example_show_sensitivity.eps') - #TODO: Do any testing - # Return return @@ -362,8 +328,6 @@ class Test(gammalib.GPythonTestSuite): args='data/spectrum.fits ' 'example_show_spectrum.eps') - #TODO: Do any testing - # Return return @@ -377,8 +341,6 @@ class Test(gammalib.GPythonTestSuite): args='data/ts.dat -n 100 ' '-f example_show_ts_distribution.eps') - #TODO: Do any testing - # Return return @@ -389,13 +351,11 @@ class Test(gammalib.GPythonTestSuite): """ # Execute script self._execute_python('show_obs', - args='obs_selected.xml save') - - #TODO: Do any testing + args='obs_selected.xml example_show_one.jpg') # Return return - + # ======================== # # Main routine entry point #