Commit a7a3be59f887fe655ac09149db8bb665ee50c537

Authored by Jürgen Knödlseder
1 parent a03d24de

Enhance ctobssim.

src/ctbin/ctbin.cpp
... ... @@ -70,7 +70,7 @@ ctbin::ctbin(void) : ctool(CTBIN_NAME, CTBIN_VERSION)
70 70 *
71 71 * param[in] obs Observation container.
72 72 *
73   - * Constructs a ctbin tool from an observation container.
  73 + * Constructs ctbin tool from an observation container.
74 74 ***************************************************************************/
75 75 ctbin::ctbin(const GObservations& obs) : ctool(CTBIN_NAME, CTBIN_VERSION)
76 76 {
... ... @@ -92,7 +92,8 @@ ctbin::ctbin(const GObservations& obs) : ctool(CTBIN_NAME, CTBIN_VERSION)
92 92 * @param[in] argc Number of arguments in command line.
93 93 * @param[in] argv Array of command line arguments.
94 94 *
95   - * Constructs ctbin tool from command line arguments.
  95 + * Constructs ctbin tool using command line arguments for user parameter
  96 + * setting.
96 97 ***************************************************************************/
97 98 ctbin::ctbin(int argc, char *argv[]) :
98 99 ctool(CTBIN_NAME, CTBIN_VERSION, argc, argv)
... ... @@ -149,7 +150,7 @@ ctbin::~ctbin(void)
149 150 /***********************************************************************//**
150 151 * @brief Assignment operator
151 152 *
152   - * @param[in] app Application.
  153 + * @param[in] app ctbin tool.
153 154 * @return ctbin tool.
154 155 *
155 156 * Assigns ctbin tool.
... ... @@ -240,14 +241,7 @@ void ctbin::run(void)
240 241  
241 242 // Write header for observation
242 243 if (logTerse()) {
243   - std::string header = m_obs[i]->instrument() + " observation";
244   - if (!m_obs[i]->name().empty()) {
245   - header += " \"" + m_obs[i]->name() + "\"";
246   - }
247   - if (!m_obs[i]->id().empty()) {
248   - header += " (id=" + m_obs[i]->id() +")";
249   - }
250   - log.header3(header);
  244 + log.header3(get_obs_header(m_obs[i]));
251 245 }
252 246  
253 247 // Get CTA observation
... ... @@ -328,8 +322,8 @@ void ctbin::save(void)
328 322  
329 323 // Log filename
330 324 if (logTerse()) {
331   - log << "Save counts cube into file \""+m_outcube+"\".";
332   - log << std::endl;
  325 + log << gammalib::parformat("Counts cube file");
  326 + log << m_outcube.url() << std::endl;
333 327 }
334 328  
335 329 // Save cube
... ...
src/ctobssim/ctobssim.cpp
... ... @@ -60,6 +60,8 @@ const double g_roi_margin = 0.5; //!&lt; Simulation radius margin (degrees)
60 60  
61 61 /***********************************************************************//**
62 62 * @brief Void constructor
  63 + *
  64 + * Constructs an empty ctobssim tool.
63 65 ***************************************************************************/
64 66 ctobssim::ctobssim(void) : ctool(CTOBSSIM_NAME, CTOBSSIM_VERSION)
65 67 {
... ... @@ -76,7 +78,7 @@ ctobssim::ctobssim(void) : ctool(CTOBSSIM_NAME, CTOBSSIM_VERSION)
76 78 *
77 79 * @param[in] obs Observation container.
78 80 *
79   - * Constructs application by initialising from an observation container.
  81 + * Constructs ctobssim tool from an observation container.
80 82 ***************************************************************************/
81 83 ctobssim::ctobssim(const GObservations& obs) :
82 84 ctool(CTOBSSIM_NAME, CTOBSSIM_VERSION)
... ... @@ -98,7 +100,8 @@ ctobssim::ctobssim(const GObservations&amp; obs) :
98 100 * @param[in] argc Number of arguments in command line.
99 101 * @param[in] argv Array of command line arguments.
100 102 *
101   - * Constructs application using command line arguments for parameter setting.
  103 + * Constructs ctobssim tool using command line arguments for user parameter
  104 + * setting.
102 105 ***************************************************************************/
103 106 ctobssim::ctobssim(int argc, char *argv[]) :
104 107 ctool(CTOBSSIM_NAME, CTOBSSIM_VERSION, argc, argv)
... ... @@ -115,6 +118,8 @@ ctobssim::ctobssim(int argc, char *argv[]) :
115 118 * @brief Copy constructor
116 119 *
117 120 * @param[in] app Application.
  121 + *
  122 + * Constructs ctobssim tool from another ctobssim instance.
118 123 ***************************************************************************/
119 124 ctobssim::ctobssim(const ctobssim& app) : ctool(app)
120 125 {
... ... @@ -131,6 +136,8 @@ ctobssim::ctobssim(const ctobssim&amp; app) : ctool(app)
131 136  
132 137 /***********************************************************************//**
133 138 * @brief Destructor
  139 + *
  140 + * Destructs ctobssim tool.
134 141 ***************************************************************************/
135 142 ctobssim::~ctobssim(void)
136 143 {
... ... @@ -151,8 +158,10 @@ ctobssim::~ctobssim(void)
151 158 /***********************************************************************//**
152 159 * @brief Assignment operator
153 160 *
154   - * @param[in] app Application.
155   - * @return Application.
  161 + * @param[in] app ctobssim tool.
  162 + * @return ctobssim tool.
  163 + *
  164 + * Assigns ctobssim tool.
156 165 ***************************************************************************/
157 166 ctobssim& ctobssim::operator=(const ctobssim& app)
158 167 {
... ... @@ -185,7 +194,9 @@ ctobssim&amp; ctobssim::operator=(const ctobssim&amp; app)
185 194 ==========================================================================*/
186 195  
187 196 /***********************************************************************//**
188   - * @brief Clear application
  197 + * @brief Clear ctobssim tool
  198 + *
  199 + * Clears ctobssim tool.
189 200 ***************************************************************************/
190 201 void ctobssim::clear(void)
191 202 {
... ... @@ -205,10 +216,10 @@ void ctobssim::clear(void)
205 216  
206 217  
207 218 /***********************************************************************//**
208   - * @brief Simulate event data
  219 + * @brief Run the ctobssim tool.
209 220 *
210   - * This method runs the simulation. Results are not saved by this method.
211   - * Invoke "save" to save the results.
  221 + * Gets the user parameters, loops over all CTA observations in the
  222 + * observation container, and simulate events for each observation.
212 223 ***************************************************************************/
213 224 void ctobssim::run(void)
214 225 {
... ... @@ -286,24 +297,14 @@ void ctobssim::run(void)
286 297 // Write observation(s) into logger
287 298 if (logTerse()) {
288 299 log << std::endl;
289   - if (m_obs.size() > 1) {
290   - log.header1("Observations");
291   - }
292   - else {
293   - log.header1("Observation");
294   - }
  300 + log.header1(gammalib::number("Observation", m_obs.size()));
295 301 log << m_obs << std::endl;
296 302 }
297 303  
298 304 // Write header
299 305 if (logTerse()) {
300 306 log << std::endl;
301   - if (m_obs.size() > 1) {
302   - log.header1("Simulate observations");
303   - }
304   - else {
305   - log.header1("Simulate observation");
306   - }
  307 + log.header1(gammalib::number("Simulate observation", m_obs.size()));
307 308 }
308 309  
309 310 // From here on the code can be parallelized if OpenMP support
... ... @@ -334,14 +335,7 @@ void ctobssim::run(void)
334 335  
335 336 // Write header for observation
336 337 if (logTerse()) {
337   - std::string header = m_obs[i]->instrument() + " observation";
338   - if (m_obs[i]->name().length() > 1) {
339   - header += " \"" + m_obs[i]->name() + "\"";
340   - }
341   - if (m_obs[i]->id().length() > 1) {
342   - header += " (id=" + m_obs[i]->id() +")";
343   - }
344   - wrklog.header3(header);
  338 + wrklog.header3(get_obs_header(m_obs[i]));
345 339 }
346 340  
347 341 // Get pointer on CTA observation
... ... @@ -1455,8 +1449,8 @@ void ctobssim::save_fits(void)
1455 1449  
1456 1450 // Log filename
1457 1451 if (logTerse()) {
1458   - log << "Save event list into file \""+m_outevents+"\".";
1459   - log << std::endl;
  1452 + log << gammalib::parformat("Event list file");
  1453 + log << m_outevents << std::endl;
1460 1454 }
1461 1455  
1462 1456 // Save observation into FITS file
... ... @@ -1483,7 +1477,7 @@ void ctobssim::save_xml(void)
1483 1477 {
1484 1478 // Get output filename and prefix
1485 1479 m_outevents = (*this)["outevents"].filename();
1486   - m_prefix = (*this)["prefix"].string();
  1480 + m_prefix = (*this)["prefix"].string();
1487 1481  
1488 1482 // Issue warning if output filename has no .xml suffix
1489 1483 std::string suffix = gammalib::tolower(m_outevents.substr(m_outevents.length()-4,4));
... ... @@ -1513,15 +1507,16 @@ void ctobssim::save_xml(void)
1513 1507 if (obs->events()->size() != 0) {
1514 1508  
1515 1509 // Set event output file name
1516   - std::string outfile = m_prefix + gammalib::str(i) + ".fits";
  1510 + std::string outfile = m_prefix + gammalib::str(i) +
  1511 + ".fits";
1517 1512  
1518 1513 // Store output file name in observation
1519 1514 obs->eventfile(outfile);
1520 1515  
1521 1516 // Log filename
1522 1517 if (logTerse()) {
1523   - log << "Save event list into file \""+outfile+"\".";
1524   - log << std::endl;
  1518 + log << gammalib::parformat("Event list file");
  1519 + log << outfile << std::endl;
1525 1520 }
1526 1521  
1527 1522 // Save observation into FITS file
... ...
src/ctobssim/ctobssim.par
... ... @@ -7,7 +7,7 @@
7 7 # File: ctobssim.par #
8 8 # Version: 1.1.0 #
9 9 # #
10   -# Author: Jurgen Knodlseder #
  10 +# Author: Juergen Knoedlseder #
11 11 # Jurgen.Knodlseder@irap.omp.eu #
12 12 # IRAP #
13 13 # #
... ... @@ -17,13 +17,13 @@
17 17 #
18 18 # General parameters
19 19 #===================
20   -inobs, f, h, "NONE",,, "Input event list or observation definition XML file"
21   -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Input model XML file"
22   -caldb, s, a, "prod2",,, "Calibration database"
23   -irf, s, a, "South_0.5h",,, "Instrument response function"
  20 +inobs, f, h, NONE,,, "Input event list or observation definition XML file"
  21 +inmodel, f, a, $CTOOLS/share/models/crab.xml,,, "Input model XML file"
  22 +caldb, s, a, prod2,,, "Calibration database"
  23 +irf, s, a, South_0.5h,,, "Instrument response function"
24 24 edisp, b, h, no,,, "Apply energy dispersion?"
25   -outevents, f, a, "events.fits",,, "Output event data file or observation definition XML file"
26   -prefix, s, h, "sim_events_",,, "Prefix for event lists in observation definition XML file"
  25 +outevents, f, a, events.fits,,, "Output event data file or observation definition XML file"
  26 +prefix, s, h, sim_events_,,, "Prefix for event lists in observation definition XML file"
27 27  
28 28 #
29 29 # Simulation parameters
... ... @@ -38,7 +38,7 @@ emin, r, a, 0.1,,, &quot;Lower energy limit (TeV)&quot;
38 38 emax, r, a, 100.0,,, "Upper energy limit (TeV)"
39 39 deadc, r, h, 0.95,0,1, "Average deadtime correction factor"
40 40 maxrate, r, h, 1.0e6,,, "Maximum photon rate"
41   -eslices, i, h, 10,1,100,"Number of energy slices"
  41 +eslices, i, h, 10,1,100, "Number of energy slices"
42 42  
43 43 #
44 44 # Standard parameters
... ... @@ -46,5 +46,5 @@ eslices, i, h, 10,1,100,&quot;Number of energy slices&quot;
46 46 chatter, i, h, 2,0,4, "Chattiness of output"
47 47 clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
48 48 debug, b, h, no,,, "Debugging mode activated"
49   -mode, s, h, "ql",,, "Mode of automatic parameters"
50   -logfile, f, h, "ctobssim.log",,, "Log filename"
  49 +mode, s, h, ql,,, "Mode of automatic parameters"
  50 +logfile, f, h, ctobssim.log,,, "Log filename"
... ...
test/test_ctbin.py
... ... @@ -22,9 +22,9 @@ import gammalib
22 22 import ctools
23 23  
24 24  
25   -# ========================= #
26   -# Test class for ctbin tool #
27   -# ========================= #
  25 +# =========================== #
  26 +# Test class for ctbin module #
  27 +# =========================== #
28 28 class Test(gammalib.GPythonTestSuite):
29 29 """
30 30 Test class for ctbin module.
... ... @@ -39,7 +39,7 @@ class Test(gammalib.GPythonTestSuite):
39 39 gammalib.GPythonTestSuite.__init__(self)
40 40  
41 41 # Set members
42   - self.events_name = "data/crab_events.fits"
  42 + self._events_name = "data/crab_events.fits"
43 43  
44 44 # Return
45 45 return
... ... @@ -65,7 +65,7 @@ class Test(gammalib.GPythonTestSuite):
65 65 """
66 66 # Set-up ctbin
67 67 bin = ctools.ctbin()
68   - bin["inobs"] = self.events_name
  68 + bin["inobs"] = self._events_name
69 69 bin["outcube"] = "cntmap.fits"
70 70 bin["ebinalg"] = "LOG"
71 71 bin["emin"] = 0.1
... ... @@ -111,20 +111,14 @@ class Test(gammalib.GPythonTestSuite):
111 111 #Please specify a valid parameter name.
112 112  
113 113 # Save counts cube
114   - self.test_try("Save counts cube")
115   - try:
116   - bin.save()
117   - self.test_try_success()
118   - except:
119   - msg = "Exception occured in saving counts cube."
120   - self.test_try_failure(msg)
  114 + bin.save()
121 115  
122 116 # Load counts cube and check content.
123 117 evt = gammalib.GCTAEventCube("cntmap.fits")
124 118 self._test_cube(evt, 5542)
125 119  
126 120 # Prepare observation container for stacked analysis
127   - cta = gammalib.GCTAObservation(self.events_name)
  121 + cta = gammalib.GCTAObservation(self._events_name)
128 122 obs = gammalib.GObservations()
129 123 cta.id("0001")
130 124 obs.append(cta)
... ...
test/test_ctobssim.py
1 1 #! /usr/bin/env python
2 2 # ==========================================================================
3   -# This scripts performs unit tests for the ctobssim tool.
  3 +# This scripts performs unit tests for the ctobssim module.
4 4 #
5 5 # Copyright (C) 2014-2016 Juergen Knoedlseder
6 6 #
... ... @@ -20,15 +20,17 @@
20 20 # ==========================================================================
21 21 import gammalib
22 22 import ctools
  23 +from cscripts import obsutils
23 24  
24 25  
25   -# ============================ #
26   -# Test class for ctobssim tool #
27   -# ============================ #
  26 +# ============================== #
  27 +# Test class for ctobssim module #
  28 +# ============================== #
28 29 class Test(gammalib.GPythonTestSuite):
29 30 """
30   - Test class for ctobssim tool.
  31 + Test class for ctobssim module.
31 32 """
  33 +
32 34 # Constructor
33 35 def __init__(self):
34 36 """
... ... @@ -38,9 +40,9 @@ class Test(gammalib.GPythonTestSuite):
38 40 gammalib.GPythonTestSuite.__init__(self)
39 41  
40 42 # Set members
41   - self.model_name = "data/crab.xml"
42   - self.caldb = "irf"
43   - self.irf = "cta_dummy_irf"
  43 + self._model_name = "data/crab.xml"
  44 + self._caldb = "irf"
  45 + self._irf = "cta_dummy_irf"
44 46  
45 47 # Return
46 48 return
... ... @@ -54,23 +56,23 @@ class Test(gammalib.GPythonTestSuite):
54 56 self.name("ctobssim")
55 57  
56 58 # Append tests
57   - self.append(self.test_functional, "Test ctobssim functionality")
58   - self.append(self.test_container, "Test ctobssim on observation container")
  59 + self.append(self._test_ctobssim, "Test ctobssim")
  60 + #self.append(self._test_container, "Test ctobssim on observation container")
59 61  
60 62 # Return
61 63 return
62 64  
63   - # Test ctobssim functionnality
64   - def test_functional(self):
  65 + # Test ctobssim
  66 + def _test_ctobssim(self):
65 67 """
66   - Test ctobssim functionnality.
  68 + Test ctobssim.
67 69 """
68 70 # Set-up ctobssim
69 71 sim = ctools.ctobssim()
70   - sim["inmodel"] = self.model_name
  72 + sim["inmodel"] = self._model_name
71 73 sim["outevents"] = "events.fits"
72   - sim["caldb"] = self.caldb
73   - sim["irf"] = self.irf
  74 + sim["caldb"] = self._caldb
  75 + sim["irf"] = self._irf
74 76 sim["ra"] = 83.63
75 77 sim["dec"] = 22.01
76 78 sim["rad"] = 10.0
... ... @@ -80,154 +82,123 @@ class Test(gammalib.GPythonTestSuite):
80 82 sim["emax"] = 100.0
81 83  
82 84 # Run tool
83   - self.test_try("Run ctobssim")
84   - try:
85   - sim.run()
86   - self.test_try_success()
87   - #except Exception as e:
88   - # msg = "Exception occured in ctobssim: %s." % (e,)
89   - except:
90   - msg = "Exception occured in ctobssim."
91   - self.test_try_failure(msg)
  85 + sim.run()
92 86  
93   - # Retrieve observation and check content
94   - obs = gammalib.GCTAObservation(sim.obs()[0])
95   - pnt = obs.pointing()
96   - evt = obs.events()
97   - self.test_assert(obs.instrument() == "CTA", "Observation not a CTA observation")
98   - self.test_value(sim.obs().size(), 1, "There is not a single observation")
99   - self.test_value(obs.ontime(), 1800.0, 1.0e-6, "Ontime is not 1800 sec")
100   - self.test_value(obs.livetime(), 1710.0, 1.0e-6, "Livetime is not 1710 sec")
101   - self.test_value(pnt.dir().ra_deg(), 83.63, 1.0e-6, "ROI Right Ascension is not 83.63 deg")
102   - self.test_value(pnt.dir().dec_deg(), 22.01, 1.0e-6, "ROI Declination is not 22.01 deg")
103   - self.test_value(evt.size(), 4119, "Number of events is not 4119")
  87 + # Check content of observation
  88 + self._test_observation(sim)
  89 + self._test_list(sim.obs()[0].events(), 4119)
104 90  
105 91 # Save events
106   - self.test_try("Save events")
107   - try:
108   - sim.save()
109   - self.test_try_success()
110   - #except Exception as e:
111   - # msg = "Exception occured in saving events: %s." % (e,)
112   - except:
113   - msg = "Exception occured in saving events."
114   - self.test_try_failure(msg)
  92 + sim.save()
  93 +
  94 + # Load counts cube and check content.
  95 + evt = gammalib.GCTAEventList("events.fits")
  96 + self._test_list(evt, 4119)
115 97  
116   - # Test ctobssim on observation container
117   - def test_container(self):
118   - """
119   - Test ctobssim on observation container.
120   - """
121 98 # Set-up observation container
122   - obs = self.set_obs(4)
  99 + pnts = [{'ra': 83.63, 'dec': 21.01},
  100 + {'ra': 84.63, 'dec': 22.01},
  101 + {'ra': 83.63, 'dec': 23.01},
  102 + {'ra': 82.63, 'dec': 22.01}]
  103 + obs = obsutils.set_obs_list(pnts, caldb=self._caldb, irf=self._irf)
123 104  
124   - # Set-up ctobssim
  105 + # Set-up ctobssim from observation container
125 106 sim = ctools.ctobssim(obs)
126 107 sim["outevents"] = "sim_events.xml"
127   - sim["inmodel"] = self.model_name
  108 + sim["inmodel"] = self._model_name
  109 +
128 110 # Run tool
129   - self.test_try("Run ctobssim")
130   - try:
131   - sim.run()
132   - self.test_try_success()
133   - #except Exception as e:
134   - # msg = "Exception occured in ctobssim: %s." % (e,)
135   - except:
136   - msg = "Exception occured in ctobssim."
137   - self.test_try_failure(msg)
  111 + sim.run()
138 112  
139 113 # Retrieve observation and check content
140   - self.test_value(sim.obs().size(), 4, "There are not 4 observations")
  114 + self._test_observation(sim, nobs=4, pnts=pnts)
  115 + self._test_list(sim.obs()[0].events(), 4063)
  116 + self._test_list(sim.obs()[1].events(), 4059)
  117 + self._test_list(sim.obs()[2].events(), 4010)
  118 + self._test_list(sim.obs()[3].events(), 4138)
141 119  
142 120 # Save events
143   - self.test_try("Save events")
  121 + sim.save()
  122 +
  123 + # Load events
  124 + obs = gammalib.GObservations("sim_events.xml")
  125 +
  126 + # Retrieve observation and check content
  127 + self._test_list(obs[0].events(), 4063)
  128 + self._test_list(obs[1].events(), 4059)
  129 + self._test_list(obs[2].events(), 4010)
  130 + self._test_list(obs[3].events(), 4138)
  131 +
  132 + # Set-up ctobssim with invalid event file
  133 + sim = ctools.ctobssim()
  134 + sim["inmodel"] = "model_file_that_does_not_exist.xml"
  135 + sim["outevents"] = "events.fits"
  136 + sim["caldb"] = self._caldb
  137 + sim["irf"] = self._irf
  138 + sim["ra"] = 83.63
  139 + sim["dec"] = 22.01
  140 + sim["rad"] = 10.0
  141 + sim["tmin"] = 0.0
  142 + sim["tmax"] = 1800.0
  143 + sim["emin"] = 0.1
  144 + sim["emax"] = 100.0
  145 +
  146 + # Run ctbin tool
  147 + self.test_try("Run ctobssim with invalid model file")
144 148 try:
145   - sim.save()
146   - self.test_try_success()
147   - #except Exception as e:
148   - # msg = "Exception occured in saving events: %s." % (e,)
  149 + sim.run()
  150 + self.test_try_failure()
149 151 except:
150   - msg = "Exception occured in saving events."
151   - self.test_try_failure(msg)
  152 + self.test_try_success()
  153 +
  154 + # Return
  155 + return
152 156  
153   - # Setup observation container
154   - def set_obs(self, number):
  157 + # Check observation
  158 + def _test_observation(self, ctobssim, nobs=1,
  159 + pnts=[{'ra': 83.63, 'dec': 22.01}]):
155 160 """
156   - Setup observation container.
  161 + Test content of an observation.
  162 +
  163 + Args:
  164 + ctobssim: ctobssim instance
  165 +
  166 + Kwargs:
  167 + nobs: Number of observations
  168 + pnts: List of pointing dictionaries
157 169 """
158   - # Initialise empty observation container
159   - obs = gammalib.GObservations()
160   -
161   - # Initialise first time and identifier
162   - tstart = 0.0
163   - offset = -float(number)/2.0
164   -
165   - # Loop over number of observations
166   - for i in range(number):
167   - id = "%6.6d" % i
168   - obs_cta = self.set_one_obs(id, offset)
169   - offset += 1.0
170   - tstart += 1830.0
171   - obs.append(obs_cta)
172   -
173   - # Return observation container
174   - return obs
175   -
176   - # Setup one observation
177   - def set_one_obs(self, id, offset, \
178   - tstart=0.0, duration=1800.0, deadc=0.95, \
179   - emin=0.1, emax=100.0, rad=5.0, \
180   - irf="cta_dummy_irf", caldb="dummy"):
  170 + # Test observation container
  171 + self.test_value(ctobssim.obs().size(), nobs,
  172 + "There is one observation")
  173 + for i in range(ctobssim.obs().size()):
  174 + obs = gammalib.GCTAObservation(ctobssim.obs()[i])
  175 + pnt = obs.pointing()
  176 + self.test_assert(obs.instrument() == "CTA",
  177 + "Observation is CTA observation")
  178 + self.test_value(obs.ontime(), 1800.0, 1.0e-6,
  179 + "Ontime is 1800 sec")
  180 + self.test_value(obs.livetime(), 1710.0, 1.0e-6,
  181 + "Livetime is 1710 sec")
  182 + self.test_value(pnt.dir().ra_deg(), pnts[i]['ra'], 1.0e-6,
  183 + "Pointing Right Ascension is "+str(pnts[i]['ra'])+" deg")
  184 + self.test_value(pnt.dir().dec_deg(), pnts[i]['dec'], 1.0e-6,
  185 + "Pointing Declination is "+str(pnts[i]['dec'])+" deg")
  186 +
  187 + # Return
  188 + return
  189 +
  190 + # Check event list
  191 + def _test_list(self, list, nevents):
181 192 """
182   - Setup one observation for test purposes.
  193 + Test content of event list."
  194 +
  195 + Args:
  196 + list: Event list
  197 + nevents: Expected number of events.
183 198 """
184   - # Allocate CTA observation
185   - obs_cta = gammalib.GCTAObservation()
186   -
187   - # Set calibration database
188   - db = gammalib.GCaldb()
189   - if (gammalib.dir_exists(self.caldb)):
190   - db.rootdir(self.caldb)
191   - else:
192   - db.open("cta", self.caldb)
193   -
194   - # Set pointing direction
195   - pntdir = gammalib.GSkyDir()
196   - pntdir.radec_deg(83.63, 22.01+offset)
197   - pnt = gammalib.GCTAPointing()
198   - pnt.dir(pntdir)
199   - obs_cta.pointing(pnt)
200   -
201   - # Set ROI
202   - roi = gammalib.GCTARoi()
203   - instdir = gammalib.GCTAInstDir()
204   - instdir.dir(pntdir)
205   - roi.centre(instdir)
206   - roi.radius(rad)
207   -
208   - # Set GTI
209   - gti = gammalib.GGti()
210   - gti.append(gammalib.GTime(tstart), gammalib.GTime(tstart+duration))
211   -
212   - # Set energy boundaries
213   - ebounds = gammalib.GEbounds(gammalib.GEnergy(emin, "TeV"), \
214   - gammalib.GEnergy(emax, "TeV"))
215   -
216   - # Allocate event list
217   - events = gammalib.GCTAEventList()
218   - events.roi(roi)
219   - events.gti(gti)
220   - events.ebounds(ebounds)
221   - obs_cta.events(events)
222   -
223   - # Set instrument response
224   - obs_cta.response(self.irf, db)
225   -
226   - # Set ontime, livetime, and deadtime correction factor
227   - obs_cta.ontime(duration)
228   - obs_cta.livetime(duration*deadc)
229   - obs_cta.deadc(deadc)
230   - obs_cta.id(id)
231   -
232   - # Return CTA observation
233   - return obs_cta
  199 + # Test event list
  200 + self.test_value(list.size(), nevents, str(nevents)+" elements")
  201 + self.test_value(list.number(), nevents, str(nevents)+" events")
  202 +
  203 + # Return
  204 + return
... ...