Commit 3cfed4b7ba30e222fcf88310fba289c7465ac013

Authored by Jürgen Knödlseder
1 parent 59a13a3d

Add unit tests for all example scripts

cscripts/Makefile.am
@@ -234,7 +234,8 @@ testdata = $(top_srcdir)/test/data/crab.xml \ @@ -234,7 +234,8 @@ testdata = $(top_srcdir)/test/data/crab.xml \
234 $(top_srcdir)/test/data/onoff_rmf1.fits.gz \ 234 $(top_srcdir)/test/data/onoff_rmf1.fits.gz \
235 $(top_srcdir)/test/data/onoff_rmf2.fits.gz \ 235 $(top_srcdir)/test/data/onoff_rmf2.fits.gz \
236 $(top_srcdir)/test/data/model_crab_radialacceptance.xml \ 236 $(top_srcdir)/test/data/model_crab_radialacceptance.xml \
237 - $(top_srcdir)/test/data/sigdist_map.fits.gz 237 + $(top_srcdir)/test/data/sigdist_map.fits.gz \
  238 + $(top_srcdir)/test/data/variability.fits.gz
238 239
239 # Test data to be distributed in $(pyexecdir)/cscripts/tests/data/iactdata 240 # Test data to be distributed in $(pyexecdir)/cscripts/tests/data/iactdata
240 testiactdata = $(top_srcdir)/test/data/iactdata/hdu-index.fits.gz \ 241 testiactdata = $(top_srcdir)/test/data/iactdata/hdu-index.fits.gz \
examples/README.md
@@ -41,12 +41,21 @@ the ctools. @@ -41,12 +41,21 @@ the ctools.
41 `show_pull_histogram.py` 41 `show_pull_histogram.py`
42 > Displays pull histograms generated by the cspull script. 42 > Displays pull histograms generated by the cspull script.
43 43
  44 +`show_residuals.py`
  45 +> Displays residuals generated by csresspec.
  46 +
44 `show_response.py` 47 `show_response.py`
45 > Displays one or several CTA response functions. 48 > Displays one or several CTA response functions.
46 49
  50 +`show_rmf.py`
  51 +> Displays Redistribution Matrix File.
  52 +
47 `show_sensitivity.py` 53 `show_sensitivity.py`
48 > Displays the sensitivity generated by the cssens script. 54 > Displays the sensitivity generated by the cssens script.
49 55
  56 +`show_significance_distribution.py`
  57 +> Displays distribution of significances in a given significance map.
  58 +
50 `show_spectrum.py` 59 `show_spectrum.py`
51 > Displays spectrum generated by the csspec script. 60 > Displays spectrum generated by the csspec script.
52 61
@@ -54,4 +63,4 @@ the ctools. @@ -54,4 +63,4 @@ the ctools.
54 > Displays Test Statistic histograms generated using the cstsdist script. 63 > Displays Test Statistic histograms generated using the cstsdist script.
55 64
56 `show_variability_evolution.py` 65 `show_variability_evolution.py`
57 -> Displays the results for a given source generated by the ctfindvar script.  
58 \ No newline at end of file 66 \ No newline at end of file
  67 +> Displays the results for a given source generated by the ctfindvar script.
examples/show_variability_evolution.py
@@ -83,10 +83,10 @@ def plot_variability_evolution(filename, plotfile, srcname): @@ -83,10 +83,10 @@ def plot_variability_evolution(filename, plotfile, srcname):
83 axarr[1].set_ylabel('Counts') 83 axarr[1].set_ylabel('Counts')
84 84
85 # Optionally save result in file 85 # Optionally save result in file
86 - if plotfile != "":  
87 - f.savefig(plotfile+".png")  
88 -  
89 - plt.show() 86 + if len(plotfile) > 0:
  87 + plt.savefig(plotfile)
  88 + else:
  89 + plt.show()
90 90
91 # Return 91 # Return
92 return 92 return
test/data/skymap_ring.fits
No preview for this file type
test/data/variability.fits.gz 0 → 100644
No preview for this file type
test/test_examples.py.in
@@ -95,12 +95,18 @@ class Test(gammalib.GPythonTestSuite): @@ -95,12 +95,18 @@ class Test(gammalib.GPythonTestSuite):
95 'Test show_butterfly.py') 95 'Test show_butterfly.py')
96 self.append(self.test_show_irf, 96 self.append(self.test_show_irf,
97 'Test show_irf.py') 97 'Test show_irf.py')
  98 + self.append(self.test_show_lightcurve,
  99 + 'Test show_lightcurve.py')
98 self.append(self.test_show_model, 100 self.append(self.test_show_model,
99 'Test show_model.py') 101 'Test show_model.py')
  102 + self.append(self.test_show_obs,
  103 + 'Test show_obs.py')
100 self.append(self.test_show_pha, 104 self.append(self.test_show_pha,
101 'Test show_pha.py') 105 'Test show_pha.py')
102 self.append(self.test_show_phases, 106 self.append(self.test_show_phases,
103 'Test show_phases.py') 107 'Test show_phases.py')
  108 + self.append(self.test_show_pointings,
  109 + 'Test show_pointings.py')
104 self.append(self.test_show_pull_evolution, 110 self.append(self.test_show_pull_evolution,
105 'Test show_pull_evolution.py') 111 'Test show_pull_evolution.py')
106 self.append(self.test_show_pull_histogram, 112 self.append(self.test_show_pull_histogram,
@@ -113,18 +119,14 @@ class Test(gammalib.GPythonTestSuite): @@ -113,18 +119,14 @@ class Test(gammalib.GPythonTestSuite):
113 'Test show_rmf.py') 119 'Test show_rmf.py')
114 self.append(self.test_show_sensitivity, 120 self.append(self.test_show_sensitivity,
115 'Test show_sensitivity.py') 121 'Test show_sensitivity.py')
  122 + self.append(self.test_show_significance_distribution,
  123 + 'Test show_significance_distribution.py')
116 self.append(self.test_show_spectrum, 124 self.append(self.test_show_spectrum,
117 'Test show_spectrum.py') 125 'Test show_spectrum.py')
118 - self.append(self.test_show_lightcurve,  
119 - 'Test show_lightcurve.py')  
120 self.append(self.test_show_ts_distribution, 126 self.append(self.test_show_ts_distribution,
121 - 'Test ts_distribution.py')  
122 - self.append(self.test_show_obs,  
123 - 'Test show_obs.py')  
124 - self.append(self.test_show_pointings,  
125 - 'Test show_pointings.py')  
126 - self.append(self.test_show_significance_distribution,  
127 - 'Test show_significance_distribution.py') 127 + 'Test show_ts_distribution.py')
  128 + self.append(self.test_show_variability_evolution,
  129 + 'Test show_variability_evolution.py')
128 130
129 # Return 131 # Return
130 return 132 return
@@ -148,155 +150,85 @@ class Test(gammalib.GPythonTestSuite): @@ -148,155 +150,85 @@ class Test(gammalib.GPythonTestSuite):
148 # Return 150 # Return
149 return 151 return
150 152
151 - # Test generate_prod3_irfs  
152 - def test_generate_prod3_irfs(self):  
153 - """  
154 - Test generate_prod3_irfs  
155 - """  
156 - # Execute script  
157 - self._execute_python('generate_prod3_irfs', args=self._datadir)  
158 -  
159 - # Return  
160 - return  
161 -  
162 - # Test make_spectrum  
163 - def test_make_spectrum(self): 153 + # Test show_butterfly
  154 + def test_show_butterfly(self):
164 """ 155 """
165 - Test make_spectrum 156 + Test show_butterfly
166 """ 157 """
167 # Set arguments 158 # Set arguments
168 - args = '-d %s -p example_spectrum.eps' % self._datadir 159 + args = '-p example_show_butterfly.eps %s/butterfly.txt' % self._datadir
169 160
170 # Execute script 161 # Execute script
171 - self._execute_python('make_spectrum', args=args) 162 + self._execute_python('show_butterfly', args=args)
172 163
173 # Return 164 # Return
174 return 165 return
175 166
176 - # Test make_ts_distributions  
177 - def test_make_ts_distributions(self): 167 + # Test show_irf
  168 + def test_show_irf(self):
178 """ 169 """
179 - Test make_ts_distributions 170 + Test show_irf
180 """ 171 """
181 # Set arguments 172 # Set arguments
182 - args = '-n 1 -e 0 -t 100 -d %s' % self._datadir  
183 -  
184 - # Execute script  
185 - self._execute_python('make_ts_distributions', args=args)  
186 -  
187 - # Return  
188 - return  
189 -  
190 - # Test pipeline_binned_disk  
191 - def test_pipeline_binned_disk(self):  
192 - """  
193 - Test pipeline_binned_disk  
194 - """  
195 - # Execute script  
196 - self._execute_python('pipeline_binned_disk', args='-d '+self._datadir)  
197 -  
198 - # Return  
199 - return  
200 -  
201 - # Test pipeline_binned_mem  
202 - def test_pipeline_binned_mem(self):  
203 - """  
204 - Test pipeline_binned_mem  
205 - """  
206 - # Execute script  
207 - self._execute_python('pipeline_binned_mem', args='-d '+self._datadir)  
208 -  
209 - # Return  
210 - return  
211 -  
212 - # Test pipeline_stacked_disk  
213 - def test_pipeline_stacked_disk(self):  
214 - """  
215 - Test pipeline_stacked_disk  
216 - """  
217 - # Execute script  
218 - self._execute_python('pipeline_stacked_disk', args='-d '+self._datadir)  
219 -  
220 - # Return  
221 - return 173 + args = '-p example_show_irf.eps prod2 South_0.5h'
222 174
223 - # Test pipeline_stacked_mem  
224 - def test_pipeline_stacked_mem(self):  
225 - """  
226 - Test pipeline_stacked_mem  
227 - """  
228 # Execute script 175 # Execute script
229 - self._execute_python('pipeline_stacked_mem', args='-d '+self._datadir) 176 + self._execute_python('show_irf', args=args)
230 177
231 # Return 178 # Return
232 return 179 return
233 180
234 - # Test pipeline_unbinned_disk  
235 - def test_pipeline_unbinned_disk(self): 181 + # Test show_lightcurve
  182 + def test_show_lightcurve(self):
236 """ 183 """
237 - Test pipeline_unbinned_disk 184 + Test show_lightcurve
238 """ 185 """
239 - # Execute script  
240 - self._execute_python('pipeline_unbinned_disk', args='-d '+self._datadir)  
241 -  
242 - # Return  
243 - return 186 + # Set arguments
  187 + args = '-p example_show_lightcurve.eps %s/lightcurve.fits' % self._datadir
244 188
245 - # Test pipeline_unbinned_mem  
246 - def test_pipeline_unbinned_mem(self):  
247 - """  
248 - Test pipeline_unbinned_mem  
249 - """  
250 # Execute script 189 # Execute script
251 - self._execute_python('pipeline_unbinned_mem', args='-d '+self._datadir) 190 + self._execute_python('show_lightcurve', args=args)
252 191
253 # Return 192 # Return
254 return 193 return
255 194
256 - # Test show_butterfly  
257 - def test_show_butterfly(self): 195 + # Test show_model
  196 + def test_show_model(self):
258 """ 197 """
259 - Test show_butterfly 198 + Test show_model
260 """ 199 """
261 # Set arguments 200 # Set arguments
262 - args = '-p example_show_butterfly.eps %s/butterfly.txt' % self._datadir 201 + args = '-n Crab -p example_show_model1.eps %s/crab.xml' % self._datadir
263 202
264 # Execute script 203 # Execute script
265 - self._execute_python('show_butterfly', args=args)  
266 -  
267 - # Return  
268 - return 204 + self._execute_python('show_model', args=args)
269 205
270 - # Test show_irf  
271 - def test_show_irf(self):  
272 - """  
273 - Test show_irf  
274 - """  
275 - # Set arguments  
276 - args = '-p example_show_irf.eps prod2 South_0.5h' 206 + # Set new arguments
  207 + args = '-p example_show_model2.eps %s/crab.xml' % self._datadir
277 208
278 # Execute script 209 # Execute script
279 - self._execute_python('show_irf', args=args) 210 + self._execute_python('show_model', args=args)
280 211
281 # Return 212 # Return
282 return 213 return
283 214
284 - # Test show_model  
285 - def test_show_model(self): 215 + # Test show_obs
  216 + def test_show_obs(self):
286 """ 217 """
287 - Test show_model 218 + Test show_obs
288 """ 219 """
289 # Set arguments 220 # Set arguments
290 - args = '-n Crab -p example_show_model1.eps %s/crab.xml' % self._datadir 221 + args = '-p example_show_obs1.eps %s/obs_unbinned.xml' % self._datadir
291 222
292 # Execute script 223 # Execute script
293 - self._execute_python('show_model', args=args) 224 + self._execute_python('show_obs', args=args)
294 225
295 - # Set new arguments  
296 - args = '-p example_show_model2.eps %s/crab.xml' % self._datadir 226 + # Set arguments
  227 + args = ('-ra 83.63 -dec 22.01 -p example_show_obs2.eps '
  228 + '%s/obs_unbinned.xml' % self._datadir)
297 229
298 # Execute script 230 # Execute script
299 - self._execute_python('show_model', args=args) 231 + self._execute_python('show_obs', args=args)
300 232
301 # Return 233 # Return
302 return 234 return
@@ -335,6 +267,20 @@ class Test(gammalib.GPythonTestSuite): @@ -335,6 +267,20 @@ class Test(gammalib.GPythonTestSuite):
335 # Return 267 # Return
336 return 268 return
337 269
  270 + # Test show_pointings
  271 + def test_show_pointings(self):
  272 + """
  273 + Test show_pointings
  274 + """
  275 + # Set arguments
  276 + args = '-p example_show_pointings.eps %s/obs_unbinned.xml' % self._datadir
  277 +
  278 + # Execute script
  279 + self._execute_python('show_pointings', args=args)
  280 +
  281 + # Return
  282 + return
  283 +
338 # Test show_pull_evolution 284 # Test show_pull_evolution
339 def test_show_pull_evolution(self): 285 def test_show_pull_evolution(self):
340 """ 286 """
@@ -443,30 +389,32 @@ class Test(gammalib.GPythonTestSuite): @@ -443,30 +389,32 @@ class Test(gammalib.GPythonTestSuite):
443 # Return 389 # Return
444 return 390 return
445 391
446 - # Test show_spectrum  
447 - def test_show_spectrum(self): 392 + # Test show_significance_distribution
  393 + def test_show_significance_distribution(self):
448 """ 394 """
449 - Test show_spectrum 395 + Test show_significance_distribution
450 """ 396 """
451 # Set arguments 397 # Set arguments
452 - args = '-p example_show_spectrum.eps %s/spectrum.fits' % self._datadir 398 + args = '-p example_show_significance_distribution.eps '+ \
  399 + '%s/sigdist_map.fits --exclude %s/sigdist_map.fits[EXCLUSION]' % \
  400 + (self._datadir, self._datadir)
453 401
454 # Execute script 402 # Execute script
455 - self._execute_python('show_spectrum', args=args) 403 + self._execute_python('show_significance_distribution', args=args)
456 404
457 # Return 405 # Return
458 return 406 return
459 407
460 - # Test show_lightcurve  
461 - def test_show_lightcurve(self): 408 + # Test show_spectrum
  409 + def test_show_spectrum(self):
462 """ 410 """
463 - Test show_lightcurve 411 + Test show_spectrum
464 """ 412 """
465 # Set arguments 413 # Set arguments
466 - args = '-p example_show_lightcurve.eps %s/lightcurve.fits' % self._datadir 414 + args = '-p example_show_spectrum.eps %s/spectrum.fits' % self._datadir
467 415
468 # Execute script 416 # Execute script
469 - self._execute_python('show_lightcurve', args=args) 417 + self._execute_python('show_spectrum', args=args)
470 418
471 # Return 419 # Return
472 return 420 return
@@ -493,53 +441,17 @@ class Test(gammalib.GPythonTestSuite): @@ -493,53 +441,17 @@ class Test(gammalib.GPythonTestSuite):
493 # Return 441 # Return
494 return 442 return
495 443
496 - # Test show_obs  
497 - def test_show_obs(self):  
498 - """  
499 - Test show_obs  
500 - """  
501 - # Set arguments  
502 - args = '-p example_show_obs1.eps %s/obs_unbinned.xml' % self._datadir  
503 -  
504 - # Execute script  
505 - self._execute_python('show_obs', args=args)  
506 -  
507 - # Set arguments  
508 - args = ('-ra 83.63 -dec 22.01 -p example_show_obs2.eps '  
509 - '%s/obs_unbinned.xml' % self._datadir)  
510 -  
511 - # Execute script  
512 - self._execute_python('show_obs', args=args)  
513 -  
514 - # Return  
515 - return  
516 -  
517 - # Test show_pointings  
518 - def test_show_pointings(self):  
519 - """  
520 - Test show_pointings  
521 - """  
522 - # Set arguments  
523 - args = '-p example_show_pointings.eps %s/obs_unbinned.xml' % self._datadir  
524 -  
525 - # Execute script  
526 - self._execute_python('show_pointings', args=args)  
527 -  
528 - # Return  
529 - return  
530 -  
531 - # Test show_significance_distribution  
532 - def test_show_significance_distribution(self): 444 + # Test show_variability_evolution
  445 + def test_show_variability_evolution(self):
533 """ 446 """
534 - Test show_significance_distribution 447 + Test show_variability_evolution
535 """ 448 """
536 # Set arguments 449 # Set arguments
537 - args = '-p example_show_significance_distribution.eps '+ \  
538 - '%s/sigdist_map.fits --exclude %s/sigdist_map.fits[EXCLUSION]' % \  
539 - (self._datadir, self._datadir) 450 + args = ('-p example_show_variability_evolution.eps %s/variability.fits' %
  451 + self._datadir)
540 452
541 # Execute script 453 # Execute script
542 - self._execute_python('show_significance_distribution', args=args) 454 + self._execute_python('show_variability_evolution', args=args)
543 455
544 # Return 456 # Return
545 return 457 return