Commit 699cd5ee3b15244fb29f7a2f29b9572a0083a7c4

Authored by Jürgen Knödlseder
1 parent 9dc564c7

The following scripts now have csobservation as base class: csebins, csmodelsele…

…ct, csobs2caldb, csobsinfo, csobsselect, and csphagen. The script cstsmapsplit has cslikelihood as base class.
cscripts/csebins.py
@@ -27,7 +27,7 @@ import ctools @@ -27,7 +27,7 @@ import ctools
27 # ============= # 27 # ============= #
28 # csebins class # 28 # csebins class #
29 # ============= # 29 # ============= #
30 -class csebins(ctools.cscript): 30 +class csebins(ctools.csobservation):
31 """ 31 """
32 Generates energy boundaries for stacked analysis 32 Generates energy boundaries for stacked analysis
33 """ 33 """
@@ -37,19 +37,12 @@ class csebins(ctools.cscript): @@ -37,19 +37,12 @@ class csebins(ctools.cscript):
37 """ 37 """
38 Constructor 38 Constructor
39 """ 39 """
40 - # Set name and version  
41 - self._name = 'csebins'  
42 - self._version = ctools.__version__ 40 + # Initialise application by calling the appropriate class constructor
  41 + self._init_csobservation('csebins', ctools.__version__, argv)
43 42
44 # Set members 43 # Set members
45 self._ebounds = gammalib.GEbounds() 44 self._ebounds = gammalib.GEbounds()
46 45
47 - # Initialise observation container from constructor arguments.  
48 - self._obs, argv = self._set_input_obs(argv)  
49 -  
50 - # Initialise script by calling the appropriate class constructor.  
51 - self._init_cscript(argv)  
52 -  
53 # Return 46 # Return
54 return 47 return
55 48
@@ -60,7 +53,7 @@ class csebins(ctools.cscript): @@ -60,7 +53,7 @@ class csebins(ctools.cscript):
60 Get parameters from parfile 53 Get parameters from parfile
61 """ 54 """
62 # Initialise observation container if it is currently empty 55 # Initialise observation container if it is currently empty
63 - if self._obs.size() == 0: 56 + if self.obs().size() == 0:
64 57
65 # Query "inobs" parameter 58 # Query "inobs" parameter
66 filename = self['inobs'].filename() 59 filename = self['inobs'].filename()
@@ -68,13 +61,13 @@ class csebins(ctools.cscript): @@ -68,13 +61,13 @@ class csebins(ctools.cscript):
68 # If an observation definition file was provided then load it, 61 # If an observation definition file was provided then load it,
69 # otherwise build a single observation with response information 62 # otherwise build a single observation with response information
70 if self._is_valid_filename(filename): 63 if self._is_valid_filename(filename):
71 - self._obs = gammalib.GObservations(filename) 64 + self.obs(gammalib.GObservations(filename))
72 else: 65 else:
73 cta = gammalib.GCTAObservation() 66 cta = gammalib.GCTAObservation()
74 caldb = gammalib.GCaldb('cta', self['caldb'].string()) 67 caldb = gammalib.GCaldb('cta', self['caldb'].string())
75 rsp = gammalib.GCTAResponseIrf(self['irf'].string(), caldb) 68 rsp = gammalib.GCTAResponseIrf(self['irf'].string(), caldb)
76 cta.response(rsp) 69 cta.response(rsp)
77 - self._obs.append(cta) 70 + self.obs().append(cta)
78 71
79 # Query input parameters 72 # Query input parameters
80 self['emin'].real() 73 self['emin'].real()
@@ -260,13 +253,13 @@ class csebins(ctools.cscript): @@ -260,13 +253,13 @@ class csebins(ctools.cscript):
260 self._get_parameters() 253 self._get_parameters()
261 254
262 # Write observation into logger 255 # Write observation into logger
263 - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') 256 + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation')
264 257
265 # Write header 258 # Write header
266 self._log_header1(gammalib.TERSE, 'Define energy boundaries') 259 self._log_header1(gammalib.TERSE, 'Define energy boundaries')
267 260
268 # Define energy boundaries for observation container 261 # Define energy boundaries for observation container
269 - self._set_ebounds(self._obs) 262 + self._set_ebounds(self.obs())
270 263
271 # Return 264 # Return
272 return 265 return
cscripts/csmodelselect.py
@@ -26,7 +26,7 @@ import ctools @@ -26,7 +26,7 @@ import ctools
26 # =================== # 26 # =================== #
27 # csmodelselect class # 27 # csmodelselect class #
28 # =================== # 28 # =================== #
29 -class csmodelselect(ctools.cscript): 29 +class csmodelselect(ctools.csobservation):
30 """ 30 """
31 Selects model from a model definition XML file 31 Selects model from a model definition XML file
32 """ 32 """
@@ -36,19 +36,13 @@ class csmodelselect(ctools.cscript): @@ -36,19 +36,13 @@ class csmodelselect(ctools.cscript):
36 """ 36 """
37 Constructor 37 Constructor
38 """ 38 """
  39 + # Initialise application by calling the appropriate class constructor
  40 + self._init_csobservation('csmodelselect', ctools.__version__, argv)
39 # Set name 41 # Set name
40 - self._name = 'csmodelselect'  
41 - self._version = ctools.__version__  
42 -  
43 - # Initialise observation container from constructor arguments  
44 - self._obs, argv = self._set_input_obs(argv)  
45 42
46 # Initialise class members 43 # Initialise class members
47 self._models = gammalib.GModels() 44 self._models = gammalib.GModels()
48 45
49 - # Initialise application by calling the appropriate class constructor  
50 - self._init_cscript(argv)  
51 -  
52 # Return 46 # Return
53 return 47 return
54 48
@@ -77,8 +71,8 @@ class csmodelselect(ctools.cscript): @@ -77,8 +71,8 @@ class csmodelselect(ctools.cscript):
77 71
78 # If there are no observations in container then get them from the 72 # If there are no observations in container then get them from the
79 # parameter file 73 # parameter file
80 - if self._obs.size() == 0:  
81 - self._obs = self._get_observations(False) 74 + if self.obs().size() == 0:
  75 + self.obs(self._get_observations(False))
82 76
83 # Get models 77 # Get models
84 self._models = gammalib.GModels(self['inmodel'].filename()) 78 self._models = gammalib.GModels(self['inmodel'].filename())
@@ -237,10 +231,10 @@ class csmodelselect(ctools.cscript): @@ -237,10 +231,10 @@ class csmodelselect(ctools.cscript):
237 models = gammalib.GModels() 231 models = gammalib.GModels()
238 232
239 # Write input observation container into logger 233 # Write input observation container into logger
240 - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') 234 + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation')
241 235
242 # Write input models into logger 236 # Write input models into logger
243 - self._log_models(gammalib.VERBOSE, self._models, 'Input model') 237 + self._log_models(gammalib.NORMAL, self._models, 'Input model')
244 238
245 # Write header 239 # Write header
246 self._log_header1(gammalib.NORMAL, 'Model selection') 240 self._log_header1(gammalib.NORMAL, 'Model selection')
@@ -250,7 +244,7 @@ class csmodelselect(ctools.cscript): @@ -250,7 +244,7 @@ class csmodelselect(ctools.cscript):
250 244
251 # If model should be selected then set model parameters and append 245 # If model should be selected then set model parameters and append
252 # model to the output container 246 # model to the output container
253 - if self._select_model(model, self._obs): 247 + if self._select_model(model, self.obs()):
254 248
255 # Set model parameters 249 # Set model parameters
256 model = self._set_model_parameters(model) 250 model = self._set_model_parameters(model)
@@ -262,7 +256,7 @@ class csmodelselect(ctools.cscript): @@ -262,7 +256,7 @@ class csmodelselect(ctools.cscript):
262 self._models = models 256 self._models = models
263 257
264 # Write selected models into logger 258 # Write selected models into logger
265 - self._log_models(gammalib.VERBOSE, self._models, 'Selected model') 259 + self._log_models(gammalib.NORMAL, self._models, 'Selected model')
266 260
267 # Return 261 # Return
268 return 262 return
cscripts/csobs2caldb.py
@@ -29,7 +29,7 @@ from cscripts import calutils @@ -29,7 +29,7 @@ from cscripts import calutils
29 # ================= # 29 # ================= #
30 # csobs2caldb class # 30 # csobs2caldb class #
31 # ================= # 31 # ================= #
32 -class csobs2caldb(ctools.cscript): 32 +class csobs2caldb(ctools.csobservation):
33 """ 33 """
34 Creates a calibration database entry for an IACT observation. 34 Creates a calibration database entry for an IACT observation.
35 35
@@ -46,9 +46,8 @@ class csobs2caldb(ctools.cscript): @@ -46,9 +46,8 @@ class csobs2caldb(ctools.cscript):
46 """ 46 """
47 Constructor 47 Constructor
48 """ 48 """
49 - # Set name and version  
50 - self._name = 'csobs2caldb'  
51 - self._version = ctools.__version__ 49 + # Initialise application by calling the appropriate class constructor
  50 + self._init_csobservation('csobs2caldb', ctools.__version__, argv)
52 51
53 # Initialise members 52 # Initialise members
54 self._observation = gammalib.GCTAObservation() 53 self._observation = gammalib.GCTAObservation()
@@ -61,12 +60,6 @@ class csobs2caldb(ctools.cscript): @@ -61,12 +60,6 @@ class csobs2caldb(ctools.cscript):
61 self._caldb_inx = gammalib.GFits() 60 self._caldb_inx = gammalib.GFits()
62 self._irf_fits = gammalib.GFits() 61 self._irf_fits = gammalib.GFits()
63 62
64 - # Initialise observation container from constructor arguments.  
65 - self._obs, argv = self._set_input_obs(argv)  
66 -  
67 - # Initialise script by calling the appropriate class constructor.  
68 - self._init_cscript(argv)  
69 -  
70 # Return 63 # Return
71 return 64 return
72 65
@@ -81,11 +74,11 @@ class csobs2caldb(ctools.cscript): @@ -81,11 +74,11 @@ class csobs2caldb(ctools.cscript):
81 """ 74 """
82 # Load observation container from "inobs" parameter in case that 75 # Load observation container from "inobs" parameter in case that
83 # the observation container is still empty. 76 # the observation container is still empty.
84 - if self._obs.is_empty():  
85 - self._obs = gammalib.GObservations(self['inobs'].filename()) 77 + if self.obs().is_empty():
  78 + self.obs(gammalib.GObservations(self['inobs'].filename()))
86 79
87 # Raise an exception if the observation container is empty 80 # Raise an exception if the observation container is empty
88 - if self._obs.is_empty(): 81 + if self.obs().is_empty():
89 raise ValueError('No or empty observation provided for ' 82 raise ValueError('No or empty observation provided for '
90 'parameter "inobs".') 83 'parameter "inobs".')
91 84
@@ -93,12 +86,12 @@ class csobs2caldb(ctools.cscript): @@ -93,12 +86,12 @@ class csobs2caldb(ctools.cscript):
93 index = self['index'].integer() 86 index = self['index'].integer()
94 87
95 # Raise an exception if the index is not valid 88 # Raise an exception if the index is not valid
96 - if index < 0 or index >= self._obs.size(): 89 + if index < 0 or index >= self.obs().size():
97 raise IndexError('Parameter "index=%d" outside the validity ' 90 raise IndexError('Parameter "index=%d" outside the validity '
98 - 'range [0,%d].' % (index, self._obs.size())) 91 + 'range [0,%d].' % (index, self.obs().size()))
99 92
100 # Get observation 93 # Get observation
101 - self._observation = self._obs[index] 94 + self._observation = self.obs()[index]
102 95
103 # Make sure we have a CTA observation 96 # Make sure we have a CTA observation
104 if not self._observation.classname() == 'GCTAObservation': 97 if not self._observation.classname() == 'GCTAObservation':
cscripts/csobsinfo.py
@@ -26,7 +26,7 @@ import ctools @@ -26,7 +26,7 @@ import ctools
26 # =============== # 26 # =============== #
27 # csobsinfo class # 27 # csobsinfo class #
28 # =============== # 28 # =============== #
29 -class csobsinfo(ctools.cscript): 29 +class csobsinfo(ctools.csobservation):
30 """ 30 """
31 Shows the content of an observation container 31 Shows the content of an observation container
32 """ 32 """
@@ -36,9 +36,8 @@ class csobsinfo(ctools.cscript): @@ -36,9 +36,8 @@ class csobsinfo(ctools.cscript):
36 """ 36 """
37 Constructor. 37 Constructor.
38 """ 38 """
39 - # Set name  
40 - self._name = 'csobsinfo'  
41 - self._version = ctools.__version__ 39 + # Initialise application by calling the appropriate class constructor
  40 + self._init_csobservation('csobsinfo', ctools.__version__, argv)
42 41
43 # Initialise class members 42 # Initialise class members
44 self._obj_dir = None 43 self._obj_dir = None
@@ -51,13 +50,6 @@ class csobsinfo(ctools.cscript): @@ -51,13 +50,6 @@ class csobsinfo(ctools.cscript):
51 self._ebounds = gammalib.GEbounds() 50 self._ebounds = gammalib.GEbounds()
52 self._gti = gammalib.GGti() 51 self._gti = gammalib.GGti()
53 52
54 - # Initialise observation container from constructor arguments.  
55 - self._obs, argv = self._set_input_obs(argv)  
56 -  
57 - # Initialise application by calling the appropriate class  
58 - # constructor.  
59 - self._init_cscript(argv)  
60 -  
61 # Return 53 # Return
62 return 54 return
63 55
@@ -68,9 +60,9 @@ class csobsinfo(ctools.cscript): @@ -68,9 +60,9 @@ class csobsinfo(ctools.cscript):
68 Get parameters from parfile and setup the observation 60 Get parameters from parfile and setup the observation
69 """ 61 """
70 # Get parameters 62 # Get parameters
71 - if self._obs.size() == 0: 63 + if self.obs().size() == 0:
72 self._require_inobs('csobsinfo::get_parameters') 64 self._require_inobs('csobsinfo::get_parameters')
73 - self._obs = self._get_observations(False) 65 + self.obs(self._get_observations(False))
74 66
75 # Initialise object position 67 # Initialise object position
76 self._obj_dir = gammalib.GSkyDir() 68 self._obj_dir = gammalib.GSkyDir()
@@ -127,10 +119,10 @@ class csobsinfo(ctools.cscript): @@ -127,10 +119,10 @@ class csobsinfo(ctools.cscript):
127 # Write header 119 # Write header
128 if self._logTerse(): 120 if self._logTerse():
129 self._log('\n') 121 self._log('\n')
130 - self._log.header1(gammalib.number('Observation', self._obs.size())) 122 + self._log.header1(gammalib.number('Observation', self.obs().size()))
131 123
132 # Loop over observations 124 # Loop over observations
133 - for obs in self._obs: 125 + for obs in self.obs():
134 126
135 # Skip non-CTA observations 127 # Skip non-CTA observations
136 if not obs.classname() == 'GCTAObservation': 128 if not obs.classname() == 'GCTAObservation':
cscripts/csobsselect.py
@@ -26,7 +26,7 @@ import ctools @@ -26,7 +26,7 @@ import ctools
26 # ================= # 26 # ================= #
27 # csobsselect class # 27 # csobsselect class #
28 # ================= # 28 # ================= #
29 -class csobsselect(ctools.cscript): 29 +class csobsselect(ctools.csobservation):
30 """ 30 """
31 Selects observations from an observation definition XML file 31 Selects observations from an observation definition XML file
32 """ 32 """
@@ -36,15 +36,8 @@ class csobsselect(ctools.cscript): @@ -36,15 +36,8 @@ class csobsselect(ctools.cscript):
36 """ 36 """
37 Constructor 37 Constructor
38 """ 38 """
39 - # Set name  
40 - self._name = 'csobsselect'  
41 - self._version = ctools.__version__  
42 -  
43 - # Initialise observation container from constructor arguments  
44 - self._obs, argv = self._set_input_obs(argv)  
45 -  
46 # Initialise application by calling the appropriate class constructor 39 # Initialise application by calling the appropriate class constructor
47 - self._init_cscript(argv) 40 + self._init_csobservation('csobsselect', ctools.__version__, argv)
48 41
49 # Return 42 # Return
50 return 43 return
@@ -57,9 +50,9 @@ class csobsselect(ctools.cscript): @@ -57,9 +50,9 @@ class csobsselect(ctools.cscript):
57 """ 50 """
58 # If there are no observations in container then query the inobs 51 # If there are no observations in container then query the inobs
59 # parameter 52 # parameter
60 - if self._obs.size() == 0: 53 + if self.obs().is_empty():
61 self['inobs'].filename() 54 self['inobs'].filename()
62 - 55 +
63 # Query relevant pointing selection parameters 56 # Query relevant pointing selection parameters
64 pntselect = self['pntselect'].string() 57 pntselect = self['pntselect'].string()
65 coordsys = self['coordsys'].string() 58 coordsys = self['coordsys'].string()
@@ -81,8 +74,8 @@ class csobsselect(ctools.cscript): @@ -81,8 +74,8 @@ class csobsselect(ctools.cscript):
81 74
82 # If there are no observations in container then get them from the 75 # If there are no observations in container then get them from the
83 # parameter file 76 # parameter file
84 - if self._obs.size() == 0:  
85 - self._obs = self._get_observations(False) 77 + if self.obs().is_empty():
  78 + self.obs(self._get_observations(False))
86 79
87 # Write input parameters into logger 80 # Write input parameters into logger
88 self._log_parameters(gammalib.TERSE) 81 self._log_parameters(gammalib.TERSE)
@@ -280,23 +273,23 @@ class csobsselect(ctools.cscript): @@ -280,23 +273,23 @@ class csobsselect(ctools.cscript):
280 selected_obs = gammalib.GObservations() 273 selected_obs = gammalib.GObservations()
281 274
282 # Write input observation container into logger 275 # Write input observation container into logger
283 - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') 276 + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation')
284 277
285 # Write header 278 # Write header
286 self._log_header1(gammalib.TERSE, 'Observation selection') 279 self._log_header1(gammalib.TERSE, 'Observation selection')
287 280
288 # Loop over observations 281 # Loop over observations
289 - for obs in self._obs: 282 + for obs in self.obs():
290 283
291 # If observation is selected then append observation 284 # If observation is selected then append observation
292 if self._select_observation(obs): 285 if self._select_observation(obs):
293 selected_obs.append(obs) 286 selected_obs.append(obs)
294 287
295 # Copy selected observations into observation 288 # Copy selected observations into observation
296 - self._obs = selected_obs 289 + self.obs(selected_obs)
297 290
298 # Write input observation container into logger 291 # Write input observation container into logger
299 - self._log_observations(gammalib.NORMAL, self._obs, 'Selected observation') 292 + self._log_observations(gammalib.NORMAL, self.obs(), 'Selected observation')
300 293
301 # Return 294 # Return
302 return 295 return
@@ -324,17 +317,11 @@ class csobsselect(ctools.cscript): @@ -324,17 +317,11 @@ class csobsselect(ctools.cscript):
324 outobs.url()) 317 outobs.url())
325 318
326 # Save observations 319 # Save observations
327 - self._obs.save(outobs) 320 + self.obs().save(outobs)
328 321
329 # Return 322 # Return
330 return 323 return
331 324
332 - def obs(self):  
333 - """  
334 - Return observation container  
335 - """  
336 - return self._obs  
337 -  
338 325
339 # ======================== # 326 # ======================== #
340 # Main routine entry point # 327 # Main routine entry point #
cscripts/csphagen.py
@@ -28,7 +28,7 @@ import sys @@ -28,7 +28,7 @@ import sys
28 # =============== # 28 # =============== #
29 # csfindobs class # 29 # csfindobs class #
30 # =============== # 30 # =============== #
31 -class csphagen(ctools.cscript): 31 +class csphagen(ctools.csobservation):
32 """ 32 """
33 Generate PHA, ARF and RMF files for classical IACT spectral analysis 33 Generate PHA, ARF and RMF files for classical IACT spectral analysis
34 """ 34 """
@@ -38,18 +38,10 @@ class csphagen(ctools.cscript): @@ -38,18 +38,10 @@ class csphagen(ctools.cscript):
38 """ 38 """
39 Constructor 39 Constructor
40 """ 40 """
41 - # Set name, version  
42 - self._name = 'csphagen'  
43 - self._version = ctools.__version__  
44 -  
45 - # Initialise observation container from constructor arguments  
46 - self._obs, argv = self._set_input_obs(argv)  
47 -  
48 # Initialise application by calling the appropriate class constructor 41 # Initialise application by calling the appropriate class constructor
49 - self._init_cscript(argv) 42 + self._init_csobservation('csphagen', ctools.__version__, argv)
50 43
51 # Initialise other variables 44 # Initialise other variables
52 - self._outobs = gammalib.GObservations()  
53 self._ebounds = gammalib.GEbounds() 45 self._ebounds = gammalib.GEbounds()
54 self._src_dir = gammalib.GSkyDir() 46 self._src_dir = gammalib.GSkyDir()
55 self._src_reg = gammalib.GSkyRegions() 47 self._src_reg = gammalib.GSkyRegions()
@@ -69,7 +61,7 @@ class csphagen(ctools.cscript): @@ -69,7 +61,7 @@ class csphagen(ctools.cscript):
69 """ 61 """
70 # Setup observations (require response and allow event list, don't 62 # Setup observations (require response and allow event list, don't
71 # allow counts cube) 63 # allow counts cube)
72 - self._setup_observations(self._obs, True, True, False) 64 + self._setup_observations(self.obs(), True, True, False)
73 65
74 # Set energy bounds 66 # Set energy bounds
75 self._ebounds = self._create_ebounds() 67 self._ebounds = self._create_ebounds()
@@ -114,8 +106,8 @@ class csphagen(ctools.cscript): @@ -114,8 +106,8 @@ class csphagen(ctools.cscript):
114 106
115 # If there are no observations in container then get them from the 107 # If there are no observations in container then get them from the
116 # parameter file 108 # parameter file
117 - if self._obs.size() == 0:  
118 - self._obs = self._get_observations(False) 109 + if self.obs().is_empty():
  110 + self.obs(self._get_observations(False))
119 111
120 # Write input parameters into logger 112 # Write input parameters into logger
121 self._log_parameters(gammalib.TERSE) 113 self._log_parameters(gammalib.TERSE)
@@ -200,18 +192,18 @@ class csphagen(ctools.cscript): @@ -200,18 +192,18 @@ class csphagen(ctools.cscript):
200 self._get_parameters() 192 self._get_parameters()
201 193
202 # Write observation into logger 194 # Write observation into logger
203 - self._log_observations(gammalib.NORMAL, self._obs, 'Observation') 195 + self._log_observations(gammalib.NORMAL, self.obs(), 'Observation')
204 196
205 # Write header 197 # Write header
206 self._log_header1(gammalib.NORMAL, 198 self._log_header1(gammalib.NORMAL,
207 'Generation of source and background spectra') 199 'Generation of source and background spectra')
208 200
209 # Initialise run variables 201 # Initialise run variables
210 - self._outobs = gammalib.GObservations() 202 + outobs = gammalib.GObservations()
211 self._bkg_regs = [] 203 self._bkg_regs = []
212 204
213 # Loop through observations and generate pha, arf, rmf files 205 # Loop through observations and generate pha, arf, rmf files
214 - for obs in self._obs: 206 + for obs in self.obs():
215 207
216 # Initialise background regions for this observation 208 # Initialise background regions for this observation
217 bkg_reg = gammalib.GSkyRegions() 209 bkg_reg = gammalib.GSkyRegions()
@@ -230,25 +222,28 @@ class csphagen(ctools.cscript): @@ -230,25 +222,28 @@ class csphagen(ctools.cscript):
230 self._src_reg, 222 self._src_reg,
231 bkg_reg) 223 bkg_reg)
232 onoff.id(obs.id()) 224 onoff.id(obs.id())
233 - self._outobs.append(onoff) 225 + outobs.append(onoff)
234 self._bkg_regs.append({'regions': bkg_reg, 'id': obs.id()}) 226 self._bkg_regs.append({'regions': bkg_reg, 'id': obs.id()})
235 else: 227 else:
236 self._log_string(gammalib.NORMAL, 'Observation %s not included ' 228 self._log_string(gammalib.NORMAL, 'Observation %s not included '
237 'in spectra generation' % (obs.id())) 229 'in spectra generation' % (obs.id()))
238 230
239 # Stack observations 231 # Stack observations
240 - if self._outobs.size() > 1 and self['stack'].boolean() == True: 232 + if outobs.size() > 1 and self['stack'].boolean() == True:
241 233
242 # Write header 234 # Write header
243 self._log_header1(gammalib.NORMAL, 'Stacking %d observations' % 235 self._log_header1(gammalib.NORMAL, 'Stacking %d observations' %
244 - (self._outobs.size())) 236 + (outobs.size()))
245 237
246 # Stack observations 238 # Stack observations
247 - stacked_obs = gammalib.GCTAOnOffObservation(self._outobs) 239 + stacked_obs = gammalib.GCTAOnOffObservation(outobs)
248 240
249 # Put stacked observations in output container 241 # Put stacked observations in output container
250 - self._outobs = gammalib.GObservations()  
251 - self._outobs.append(stacked_obs) 242 + outobs = gammalib.GObservations()
  243 + outobs.append(stacked_obs)
  244 +
  245 + # Set observation container
  246 + self.obs(outobs)
252 247
253 # Return 248 # Return
254 return 249 return
@@ -266,7 +261,7 @@ class csphagen(ctools.cscript): @@ -266,7 +261,7 @@ class csphagen(ctools.cscript):
266 clobber = self['clobber'].boolean() 261 clobber = self['clobber'].boolean()
267 262
268 # Loop over all observation in container 263 # Loop over all observation in container
269 - for obs in self._outobs: 264 + for obs in self.obs():
270 265
271 # Set filenames 266 # Set filenames
272 if self['stack'].boolean(): 267 if self['stack'].boolean():
@@ -274,7 +269,7 @@ class csphagen(ctools.cscript): @@ -274,7 +269,7 @@ class csphagen(ctools.cscript):
274 offname = prefix + '_stacked_pha_off.fits' 269 offname = prefix + '_stacked_pha_off.fits'
275 arfname = prefix + '_stacked_arf.fits' 270 arfname = prefix + '_stacked_arf.fits'
276 rmfname = prefix + '_stacked_rmf.fits' 271 rmfname = prefix + '_stacked_rmf.fits'
277 - elif self._outobs.size() > 1: 272 + elif self.obs().size() > 1:
278 onname = prefix + '_%s_pha_on.fits' % (obs.id()) 273 onname = prefix + '_%s_pha_on.fits' % (obs.id())
279 offname = prefix + '_%s_pha_off.fits' % (obs.id()) 274 offname = prefix + '_%s_pha_off.fits' % (obs.id())
280 arfname = prefix + '_%s_arf.fits' % (obs.id()) 275 arfname = prefix + '_%s_arf.fits' % (obs.id())
@@ -298,7 +293,7 @@ class csphagen(ctools.cscript): @@ -298,7 +293,7 @@ class csphagen(ctools.cscript):
298 self._log_value(gammalib.NORMAL, 'RMF file', arfname) 293 self._log_value(gammalib.NORMAL, 'RMF file', arfname)
299 294
300 # Save observation definition XML file 295 # Save observation definition XML file
301 - self._outobs.save(outobs) 296 + self.obs().save(outobs)
302 297
303 # Log file name 298 # Log file name
304 self._log_value(gammalib.NORMAL, 'Obs. definition XML file', outobs) 299 self._log_value(gammalib.NORMAL, 'Obs. definition XML file', outobs)
@@ -326,12 +321,6 @@ class csphagen(ctools.cscript): @@ -326,12 +321,6 @@ class csphagen(ctools.cscript):
326 # Return 321 # Return
327 return 322 return
328 323
329 - def obs(self):  
330 - """  
331 - Return observation container  
332 - """  
333 - return self._outobs  
334 -  
335 324
336 # ======================== # 325 # ======================== #
337 # Main routine entry point # 326 # Main routine entry point #
cscripts/csresmap.py
@@ -27,7 +27,7 @@ import ctools @@ -27,7 +27,7 @@ import ctools
27 # ============== # 27 # ============== #
28 # csresmap class # 28 # csresmap class #
29 # ============== # 29 # ============== #
30 -class csresmap(ctools.cscript): 30 +class csresmap(ctools.csobservation):
31 """ 31 """
32 Generates a residual map 32 Generates a residual map
33 """ 33 """
@@ -37,21 +37,14 @@ class csresmap(ctools.cscript): @@ -37,21 +37,14 @@ class csresmap(ctools.cscript):
37 """ 37 """
38 Constructor 38 Constructor
39 """ 39 """
40 - # Set name  
41 - self._name = 'csresmap'  
42 - self._version = ctools.__version__ 40 + # Initialise application by calling the appropriate class constructor
  41 + self._init_csobservation('csresmap', ctools.__version__, argv)
43 42
44 # Initialise class members 43 # Initialise class members
45 self._resmap = None 44 self._resmap = None
46 self._use_maps = False 45 self._use_maps = False
47 self._skip_binning = False 46 self._skip_binning = False
48 47
49 - # Initialise observation container from constructor arguments  
50 - self._obs, argv = self._set_input_obs(argv)  
51 -  
52 - # Initialise application by calling the appropriate class constructor  
53 - self._init_cscript(argv)  
54 -  
55 # Return 48 # Return
56 return 49 return
57 50
@@ -69,7 +62,7 @@ class csresmap(ctools.cscript): @@ -69,7 +62,7 @@ class csresmap(ctools.cscript):
69 # if the "inobs" parameter is a counts cube. If the "inobs" parameter 62 # if the "inobs" parameter is a counts cube. If the "inobs" parameter
70 # represents a FITS file and if this FITS file is a counts cube then 63 # represents a FITS file and if this FITS file is a counts cube then
71 # set self._skip_binning=True 64 # set self._skip_binning=True
72 - if self._obs.size() == 0 and self['inobs'].filename() != 'NONE': 65 + if self.obs().size() == 0 and self['inobs'].filename() != 'NONE':
73 filename = gammalib.GFilename(self['inobs'].filename()) 66 filename = gammalib.GFilename(self['inobs'].filename())
74 if filename.is_fits(): 67 if filename.is_fits():
75 cta = gammalib.GCTAObservation() 68 cta = gammalib.GCTAObservation()
@@ -88,20 +81,20 @@ class csresmap(ctools.cscript): @@ -88,20 +81,20 @@ class csresmap(ctools.cscript):
88 if not self._use_maps: 81 if not self._use_maps:
89 82
90 # Set observation if not done before 83 # Set observation if not done before
91 - if self._obs.size() == 0: 84 + if self.obs().size() == 0:
92 self._require_inobs('csresmap.get_parameters()') 85 self._require_inobs('csresmap.get_parameters()')
93 - self._obs = self._get_observations() 86 + self.obs(self._get_observations())
94 87
95 # If we have exactly one binned CTA observation then signal that 88 # If we have exactly one binned CTA observation then signal that
96 # the binning can be skipped 89 # the binning can be skipped
97 - if self._obs.size() == 1 and \  
98 - self._obs[0].classname() == 'GCTAObservation' and \  
99 - self._obs[0].eventtype() == 'CountsCube': 90 + if self.obs().size() == 1 and \
  91 + self.obs()[0].classname() == 'GCTAObservation' and \
  92 + self.obs()[0].eventtype() == 'CountsCube':
100 self._skip_binning = True 93 self._skip_binning = True
101 94
102 # Set models if we have none 95 # Set models if we have none
103 - if self._obs.models().size() == 0:  
104 - self._obs.models(self['inmodel'].filename()) 96 + if self.obs().models().size() == 0:
  97 + self.obs().models(self['inmodel'].filename())
105 98
106 # If no binning is provided in the observation then query now 99 # If no binning is provided in the observation then query now
107 # the counts cube binning parameters 100 # the counts cube binning parameters
@@ -153,7 +146,7 @@ class csresmap(ctools.cscript): @@ -153,7 +146,7 @@ class csresmap(ctools.cscript):
153 self._get_parameters() 146 self._get_parameters()
154 147
155 # Write observation into logger 148 # Write observation into logger
156 - self._log_observations(gammalib.NORMAL, self._obs, 'Observation') 149 + self._log_observations(gammalib.NORMAL, self.obs(), 'Observation')
157 150
158 # If a counts and model cube are specified then load them as sky map 151 # If a counts and model cube are specified then load them as sky map
159 if self._use_maps: 152 if self._use_maps:
@@ -166,7 +159,7 @@ class csresmap(ctools.cscript): @@ -166,7 +159,7 @@ class csresmap(ctools.cscript):
166 # Do not build counts cube if we have already one in the observation 159 # Do not build counts cube if we have already one in the observation
167 # container 160 # container
168 if self._skip_binning: 161 if self._skip_binning:
169 - cta_counts_cube = gammalib.GCTAEventCube(self._obs[0].events()) 162 + cta_counts_cube = gammalib.GCTAEventCube(self.obs()[0].events())
170 163
171 # ... otherwise generate one now from the event list 164 # ... otherwise generate one now from the event list
172 else: 165 else:
@@ -175,7 +168,7 @@ class csresmap(ctools.cscript): @@ -175,7 +168,7 @@ class csresmap(ctools.cscript):
175 self._log_header1(gammalib.TERSE, 'Generate binned map (ctbin)') 168 self._log_header1(gammalib.TERSE, 'Generate binned map (ctbin)')
176 169
177 # Create countsmap 170 # Create countsmap
178 - binning = ctools.ctbin(self._obs) 171 + binning = ctools.ctbin(self.obs())
179 binning['xref'] = self['xref'].real() 172 binning['xref'] = self['xref'].real()
180 binning['yref'] = self['yref'].real() 173 binning['yref'] = self['yref'].real()
181 binning['proj'] = self['proj'].string() 174 binning['proj'] = self['proj'].string()
@@ -184,7 +177,7 @@ class csresmap(ctools.cscript): @@ -184,7 +177,7 @@ class csresmap(ctools.cscript):
184 binning['nxpix'] = self['nxpix'].integer() 177 binning['nxpix'] = self['nxpix'].integer()
185 binning['nypix'] = self['nypix'].integer() 178 binning['nypix'] = self['nypix'].integer()
186 binning['binsz'] = self['binsz'].real() 179 binning['binsz'] = self['binsz'].real()
187 - if self['ebinalg'].string() == "FILE": 180 + if self['ebinalg'].string() == 'FILE':
188 binning['ebinfile'] = self['ebinfile'].filename().file() 181 binning['ebinfile'] = self['ebinfile'].filename().file()
189 else: 182 else:
190 binning['enumbins'] = self['enumbins'].integer() 183 binning['enumbins'] = self['enumbins'].integer()
@@ -205,7 +198,7 @@ class csresmap(ctools.cscript): @@ -205,7 +198,7 @@ class csresmap(ctools.cscript):
205 self._log_header1(gammalib.TERSE, 'Generate model map (ctmodel)') 198 self._log_header1(gammalib.TERSE, 'Generate model map (ctmodel)')
206 199
207 # Create model map 200 # Create model map
208 - model = ctools.ctmodel(self._obs) 201 + model = ctools.ctmodel(self.obs())
209 model.cube(cta_counts_cube) 202 model.cube(cta_counts_cube)
210 model['chatter'] = self['chatter'].integer() 203 model['chatter'] = self['chatter'].integer()
211 model['clobber'] = self['clobber'].boolean() 204 model['clobber'] = self['clobber'].boolean()
@@ -324,7 +317,7 @@ class csresmap(ctools.cscript): @@ -324,7 +317,7 @@ class csresmap(ctools.cscript):
324 317
325 # Set default name is user name is empty 318 # Set default name is user name is empty
326 if not name: 319 if not name:
327 - user_name = self._name 320 + user_name = self._name()
328 else: 321 else:
329 user_name = name 322 user_name = name
330 323
@@ -342,7 +335,7 @@ class csresmap(ctools.cscript): @@ -342,7 +335,7 @@ class csresmap(ctools.cscript):
342 Set model 335 Set model
343 """ 336 """
344 # Copy models 337 # Copy models
345 - self._obs.models(models) 338 + self.obs().models(models)
346 339
347 # Return 340 # Return
348 return 341 return
cscripts/cssens.py
@@ -596,7 +596,7 @@ class cssens(ctools.csobservation): @@ -596,7 +596,7 @@ class cssens(ctools.csobservation):
596 self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') 596 self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation')
597 597
598 # Write models into logger 598 # Write models into logger
599 - self._log_models(gammalib.TERSE, models, 'Input model') 599 + self._log_models(gammalib.NORMAL, models, 'Input model')
600 600
601 # Get sensitivity type 601 # Get sensitivity type
602 sensitivity_type = self['type'].string() 602 sensitivity_type = self['type'].string()
cscripts/csspec.py
@@ -66,7 +66,7 @@ class csspec(ctools.csobservation): @@ -66,7 +66,7 @@ class csspec(ctools.csobservation):
66 Get parameters from parfile and setup the observation 66 Get parameters from parfile and setup the observation
67 """ 67 """
68 # Set observation if not done before 68 # Set observation if not done before
69 - if self.obs().size() == 0: 69 + if self.obs().is_empty():
70 self._require_inobs('csspec::get_parameters()') 70 self._require_inobs('csspec::get_parameters()')
71 self.obs(self._get_observations()) 71 self.obs(self._get_observations())
72 72
@@ -74,7 +74,7 @@ class csspec(ctools.csobservation): @@ -74,7 +74,7 @@ class csspec(ctools.csobservation):
74 self._set_obs_statistic(gammalib.toupper(self['statistic'].string())) 74 self._set_obs_statistic(gammalib.toupper(self['statistic'].string()))
75 75
76 # Set models if we have none 76 # Set models if we have none
77 - if self.obs().models().size() == 0: 77 + if self.obs().models().is_empty():
78 self.obs().models(self['inmodel'].filename()) 78 self.obs().models(self['inmodel'].filename())
79 79
80 # Query source name 80 # Query source name
cscripts/cstsdist.py
@@ -227,7 +227,7 @@ class cstsdist(ctools.csobservation): @@ -227,7 +227,7 @@ class cstsdist(ctools.csobservation):
227 self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') 227 self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation')
228 228
229 # Write models into logger 229 # Write models into logger
230 - self._log_models(gammalib.TERSE, self.obs().models(), 'Input model') 230 + self._log_models(gammalib.NORMAL, self.obs().models(), 'Input model')
231 231
232 # Write header 232 # Write header
233 self._log_header1(gammalib.TERSE, 'Generate TS distribution') 233 self._log_header1(gammalib.TERSE, 'Generate TS distribution')
cscripts/cstsmapsplit.py
@@ -28,7 +28,7 @@ import ctools @@ -28,7 +28,7 @@ import ctools
28 # ================== # 28 # ================== #
29 # cstsmapsplit class # 29 # cstsmapsplit class #
30 # ================== # 30 # ================== #
31 -class cstsmapsplit(ctools.cscript): 31 +class cstsmapsplit(ctools.cslikelihood):
32 """ 32 """
33 Generates commands to split TS map computation 33 Generates commands to split TS map computation
34 34
@@ -44,10 +44,8 @@ class cstsmapsplit(ctools.cscript): @@ -44,10 +44,8 @@ class cstsmapsplit(ctools.cscript):
44 """ 44 """
45 Constructor 45 Constructor
46 """ 46 """
47 -  
48 - # Set name and version  
49 - self._name = 'cstsmapsplit'  
50 - self._version = ctools.__version__ 47 + # Initialise application by calling the appropriate class constructor
  48 + self._init_cslikelihood('cstsmapsplit', ctools.__version__, argv)
51 49
52 # Set data members 50 # Set data members
53 self._outmap = gammalib.GFilename() 51 self._outmap = gammalib.GFilename()
@@ -57,13 +55,6 @@ class cstsmapsplit(ctools.cscript): @@ -57,13 +55,6 @@ class cstsmapsplit(ctools.cscript):
57 self._map = gammalib.GSkyMap() 55 self._map = gammalib.GSkyMap()
58 self._cmd = [] 56 self._cmd = []
59 self._srcname = '' 57 self._srcname = ''
60 -  
61 - # Initialise observation container from constructor arguments.  
62 - self._obs, argv = self._set_input_obs(argv)  
63 -  
64 - # Initialise application by calling the appropriate class  
65 - # constructor.  
66 - self._init_cscript(argv)  
67 58
68 # Return 59 # Return
69 return 60 return
@@ -74,17 +65,16 @@ class cstsmapsplit(ctools.cscript): @@ -74,17 +65,16 @@ class cstsmapsplit(ctools.cscript):
74 """ 65 """
75 Get parameters from parfile and setup the observation 66 Get parameters from parfile and setup the observation
76 """ 67 """
77 -  
78 # If there are no observations in container then get some ... 68 # If there are no observations in container then get some ...
79 - if self._obs.size() == 0:  
80 - self._obs = self._get_observations() 69 + if self.obs().size() == 0:
  70 + self.obs(self._get_observations())
81 71
82 # Set models if we have none 72 # Set models if we have none
83 - if self._obs.models().size() == 0:  
84 - self._obs.models(self['inmodel'].filename()) 73 + if self.obs().models().size() == 0:
  74 + self.obs().models(self['inmodel'].filename())
85 75
86 # Get TS map paramters 76 # Get TS map paramters
87 - self._map = self._create_map(self._obs) 77 + self._map = self._create_map(self.obs())
88 self._srcname = self['srcname'].string() 78 self._srcname = self['srcname'].string()
89 self._outmap = self['outmap'].filename() 79 self._outmap = self['outmap'].filename()
90 80
@@ -108,30 +98,29 @@ class cstsmapsplit(ctools.cscript): @@ -108,30 +98,29 @@ class cstsmapsplit(ctools.cscript):
108 logl : float 98 logl : float
109 Log-likelihood of null hypothesis 99 Log-likelihood of null hypothesis
110 """ 100 """
111 -  
112 # Store original models 101 # Store original models
113 - models_orig = self._obs.models() 102 + models_orig = self.obs().models()
114 103
115 # Get models instance 104 # Get models instance
116 - models0 = self._obs.models() 105 + models0 = self.obs().models()
117 106
118 # Remove test source 107 # Remove test source
119 models0.remove(self._srcname) 108 models0.remove(self._srcname)
120 109
121 # Initialise optimizer 110 # Initialise optimizer
122 - opt = gammalib.GOptimizerLM() 111 + #opt = gammalib.GOptimizerLM()
123 112
124 # Set models for null hypothesis 113 # Set models for null hypothesis
125 - self._obs.models(models0) 114 + self.obs().models(models0)
126 115
127 # Optimise observation container 116 # Optimise observation container
128 - self._obs.optimize(opt) 117 + self.obs().optimize(self.opt())
129 118
130 # Set original models to container 119 # Set original models to container
131 - self._obs.models(models_orig) 120 + self.obs().models(models_orig)
132 121
133 # Return optimised log-likelihood of null hypothesis 122 # Return optimised log-likelihood of null hypothesis
134 - return -(opt.value()) 123 + return -(self.opt().value())
135 124
136 125
137 # Public methods 126 # Public methods
@@ -147,12 +136,8 @@ class cstsmapsplit(ctools.cscript): @@ -147,12 +136,8 @@ class cstsmapsplit(ctools.cscript):
147 self._get_parameters() 136 self._get_parameters()
148 137
149 # Write information into logger 138 # Write information into logger
150 - if self._logTerse():  
151 - self._log('\n')  
152 - self._log.header1('Test source')  
153 - model = self._obs.models()[self._srcname]  
154 - self._log(str(model))  
155 - self._log('\n') 139 + self._log_header1(gammalib.TERSE, 'Test source')
  140 + self._log_string(gammalib.TERSE, str(self.obs().models()[self._srcname]))
156 141
157 # Set log-likelihood to zero 142 # Set log-likelihood to zero
158 logL0 = 0.0 143 logL0 = 0.0
@@ -161,9 +146,7 @@ class cstsmapsplit(ctools.cscript): @@ -161,9 +146,7 @@ class cstsmapsplit(ctools.cscript):
161 if self._compute_null: 146 if self._compute_null:
162 147
163 # Write information into logger 148 # Write information into logger
164 - if self._logTerse():  
165 - self._log('\n')  
166 - self._log.header1('Compute null hypothesis') 149 + self._log_header1(gammalib.TERSE, 'Compute null hypothesis')
167 150
168 # Compute null hypothesis 151 # Compute null hypothesis
169 logL0 = self._compute_null_hypothesis() 152 logL0 = self._compute_null_hypothesis()