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 234 $(top_srcdir)/test/data/onoff_rmf1.fits.gz \
235 235 $(top_srcdir)/test/data/onoff_rmf2.fits.gz \
236 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 240 # Test data to be distributed in $(pyexecdir)/cscripts/tests/data/iactdata
240 241 testiactdata = $(top_srcdir)/test/data/iactdata/hdu-index.fits.gz \
... ...
examples/README.md
... ... @@ -41,12 +41,21 @@ the ctools.
41 41 `show_pull_histogram.py`
42 42 > Displays pull histograms generated by the cspull script.
43 43  
  44 +`show_residuals.py`
  45 +> Displays residuals generated by csresspec.
  46 +
44 47 `show_response.py`
45 48 > Displays one or several CTA response functions.
46 49  
  50 +`show_rmf.py`
  51 +> Displays Redistribution Matrix File.
  52 +
47 53 `show_sensitivity.py`
48 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 59 `show_spectrum.py`
51 60 > Displays spectrum generated by the csspec script.
52 61  
... ... @@ -54,4 +63,4 @@ the ctools.
54 63 > Displays Test Statistic histograms generated using the cstsdist script.
55 64  
56 65 `show_variability_evolution.py`
57   -> Displays the results for a given source generated by the ctfindvar script.
58 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 83 axarr[1].set_ylabel('Counts')
84 84  
85 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 91 # Return
92 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 95 'Test show_butterfly.py')
96 96 self.append(self.test_show_irf,
97 97 'Test show_irf.py')
  98 + self.append(self.test_show_lightcurve,
  99 + 'Test show_lightcurve.py')
98 100 self.append(self.test_show_model,
99 101 'Test show_model.py')
  102 + self.append(self.test_show_obs,
  103 + 'Test show_obs.py')
100 104 self.append(self.test_show_pha,
101 105 'Test show_pha.py')
102 106 self.append(self.test_show_phases,
103 107 'Test show_phases.py')
  108 + self.append(self.test_show_pointings,
  109 + 'Test show_pointings.py')
104 110 self.append(self.test_show_pull_evolution,
105 111 'Test show_pull_evolution.py')
106 112 self.append(self.test_show_pull_histogram,
... ... @@ -113,18 +119,14 @@ class Test(gammalib.GPythonTestSuite):
113 119 'Test show_rmf.py')
114 120 self.append(self.test_show_sensitivity,
115 121 'Test show_sensitivity.py')
  122 + self.append(self.test_show_significance_distribution,
  123 + 'Test show_significance_distribution.py')
116 124 self.append(self.test_show_spectrum,
117 125 'Test show_spectrum.py')
118   - self.append(self.test_show_lightcurve,
119   - 'Test show_lightcurve.py')
120 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 131 # Return
130 132 return
... ... @@ -148,155 +150,85 @@ class Test(gammalib.GPythonTestSuite):
148 150 # Return
149 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 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 161 # Execute script
171   - self._execute_python('make_spectrum', args=args)
  162 + self._execute_python('show_butterfly', args=args)
172 163  
173 164 # Return
174 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 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 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 178 # Return
232 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 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 192 # Return
254 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 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 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 209 # Execute script
279   - self._execute_python('show_irf', args=args)
  210 + self._execute_python('show_model', args=args)
280 211  
281 212 # Return
282 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 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 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 230 # Execute script
299   - self._execute_python('show_model', args=args)
  231 + self._execute_python('show_obs', args=args)
300 232  
301 233 # Return
302 234 return
... ... @@ -335,6 +267,20 @@ class Test(gammalib.GPythonTestSuite):
335 267 # Return
336 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 284 # Test show_pull_evolution
339 285 def test_show_pull_evolution(self):
340 286 """
... ... @@ -443,30 +389,32 @@ class Test(gammalib.GPythonTestSuite):
443 389 # Return
444 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 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 402 # Execute script
455   - self._execute_python('show_spectrum', args=args)
  403 + self._execute_python('show_significance_distribution', args=args)
456 404  
457 405 # Return
458 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 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 416 # Execute script
469   - self._execute_python('show_lightcurve', args=args)
  417 + self._execute_python('show_spectrum', args=args)
470 418  
471 419 # Return
472 420 return
... ... @@ -493,53 +441,17 @@ class Test(gammalib.GPythonTestSuite):
493 441 # Return
494 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 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 453 # Execute script
542   - self._execute_python('show_significance_distribution', args=args)
  454 + self._execute_python('show_variability_evolution', args=args)
543 455  
544 456 # Return
545 457 return
... ...