Commit 69800b1c956e9a4bc64fe6efaffb4ee652ef60dd

Authored by Jürgen Knödlseder
1 parent 6e6c2ca9

Add show_residuals.py unit test

cscripts/Makefile.am
@@ -195,6 +195,7 @@ testdata = $(top_srcdir)/test/data/crab.xml \ @@ -195,6 +195,7 @@ testdata = $(top_srcdir)/test/data/crab.xml \
195 $(top_srcdir)/test/data/sensitivity_integral.dat \ 195 $(top_srcdir)/test/data/sensitivity_integral.dat \
196 $(top_srcdir)/test/data/skymap.fits \ 196 $(top_srcdir)/test/data/skymap.fits \
197 $(top_srcdir)/test/data/spectrum.fits \ 197 $(top_srcdir)/test/data/spectrum.fits \
  198 + $(top_srcdir)/test/data/residual.fits \
198 $(top_srcdir)/test/data/lightcurve.fits \ 199 $(top_srcdir)/test/data/lightcurve.fits \
199 $(top_srcdir)/test/data/ts.dat \ 200 $(top_srcdir)/test/data/ts.dat \
200 $(top_srcdir)/test/data/models_spatial.xml \ 201 $(top_srcdir)/test/data/models_spatial.xml \
cscripts/cslightcrv.py
@@ -558,12 +558,12 @@ class cslightcrv(ctools.csobservation): @@ -558,12 +558,12 @@ class cslightcrv(ctools.csobservation):
558 # fill results table with zeros 558 # fill results table with zeros
559 else: 559 else:
560 self._log_value(gammalib.TERSE, 'Warning', 560 self._log_value(gammalib.TERSE, 'Warning',
561 - 'No observations available in this time bin',  
562 - 'Skip bin.') 561 + 'No observations available in this time bin, '
  562 + 'skip bin.')
563 563
564 # Set all results to 0 564 # Set all results to 0
565 for par in pars: 565 for par in pars:
566 - result['values'][par] = 0.0 566 + result['values'][par] = 0.0
567 result['values']['e_' + par] = 0.0 567 result['values']['e_' + par] = 0.0
568 568
569 # Append result 569 # Append result
examples/show_residuals.py
@@ -286,7 +286,7 @@ def show_residuals(): @@ -286,7 +286,7 @@ def show_residuals():
286 Show residuals 286 Show residuals
287 """ 287 """
288 # Set usage string 288 # Set usage string
289 - usage = 'show_spectrum.py [-p plotfile] [-h hdu] [file]' 289 + usage = 'show_residual.py [-p plotfile] [-h hdu] [file]'
290 290
291 # Set default options 291 # Set default options
292 options = [{'option': '-p', 'value': ''}, 292 options = [{'option': '-p', 'value': ''},
@@ -297,7 +297,7 @@ def show_residuals(): @@ -297,7 +297,7 @@ def show_residuals():
297 297
298 # Extract script parameters from options 298 # Extract script parameters from options
299 plotfile = options[0]['value'] 299 plotfile = options[0]['value']
300 - hdu = options[1]['value'] 300 + hdu = options[1]['value']
301 301
302 # Show residuals 302 # Show residuals
303 plot_residuals(args[0], plotfile, hdu) 303 plot_residuals(args[0], plotfile, hdu)
test/data/residual.fits 0 → 100644
No preview for this file type
test/test_examples.py.in
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Performs unit tests for the ctools example scripts 3 # Performs unit tests for the ctools example scripts
4 # 4 #
5 -# Copyright (C) 2016-2017 Juergen Knoedlseder 5 +# Copyright (C) 2016-2018 Juergen Knoedlseder
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -89,26 +89,8 @@ class Test(gammalib.GPythonTestSuite): @@ -89,26 +89,8 @@ class Test(gammalib.GPythonTestSuite):
89 self.name('examples') 89 self.name('examples')
90 90
91 # Append tests 91 # Append tests
92 - #self.append(self.test_generate_prod3_irfs,  
93 - # 'Test generate_prod3_irfs.py')  
94 self.append(self.test_make_pointings, 92 self.append(self.test_make_pointings,
95 'Test make_pointings.py') 93 'Test make_pointings.py')
96 - #self.append(self.test_make_spectrum,  
97 - # 'Test make_spectrum.py')  
98 - #self.append(self.test_make_ts_distributions,  
99 - # 'Test make_ts_distributions.py')  
100 - #self.append(self.test_pipeline_binned_disk,  
101 - # 'Test pipeline_binned_disk.py')  
102 - #self.append(self.test_pipeline_binned_mem,  
103 - # 'Test pipeline_binned_mem.py')  
104 - #self.append(self.test_pipeline_stacked_disk,  
105 - # 'Test pipeline_stacked_disk.py')  
106 - #self.append(self.test_pipeline_stacked_mem,  
107 - # 'Test pipeline_stacked_mem.py')  
108 - #self.append(self.test_pipeline_unbinned_disk,  
109 - # 'Test pipeline_unbinned_disk.py')  
110 - #self.append(self.test_pipeline_unbinned_mem,  
111 - # 'Test pipeline_unbinned_mem.py')  
112 self.append(self.test_show_butterfly, 94 self.append(self.test_show_butterfly,
113 'Test show_butterfly.py') 95 'Test show_butterfly.py')
114 self.append(self.test_show_irf, 96 self.append(self.test_show_irf,
@@ -123,6 +105,8 @@ class Test(gammalib.GPythonTestSuite): @@ -123,6 +105,8 @@ class Test(gammalib.GPythonTestSuite):
123 'Test show_pull_evolution.py') 105 'Test show_pull_evolution.py')
124 self.append(self.test_show_pull_histogram, 106 self.append(self.test_show_pull_histogram,
125 'Test show_pull_histogram.py') 107 'Test show_pull_histogram.py')
  108 + self.append(self.test_show_residuals,
  109 + 'Test show_residuals.py')
126 self.append(self.test_show_response, 110 self.append(self.test_show_response,
127 'Test show_response.py') 111 'Test show_response.py')
128 self.append(self.test_show_sensitivity, 112 self.append(self.test_show_sensitivity,
@@ -384,6 +368,20 @@ class Test(gammalib.GPythonTestSuite): @@ -384,6 +368,20 @@ class Test(gammalib.GPythonTestSuite):
384 # Return 368 # Return
385 return 369 return
386 370
  371 + # Test show_residuals
  372 + def test_show_residuals(self):
  373 + """
  374 + Test show_residuals
  375 + """
  376 + # Set arguments
  377 + args = '-p example_show_residuals.eps %s/residual.fits' % self._datadir
  378 +
  379 + # Execute script
  380 + self._execute_python('show_residuals', args=args)
  381 +
  382 + # Return
  383 + return
  384 +
387 # Test show_response 385 # Test show_response
388 def test_show_response(self): 386 def test_show_response(self):
389 """ 387 """