Commit d46008b15a39effb2748fd93ceba6390c0ddb01e

Authored by Christoph Deil
1 parent 45cc2f23

Misc Python formatting / import fixes in examples

cscripts/cshessobs.py
@@ -374,8 +374,8 @@ class cshessobs(ctools.cscript): @@ -374,8 +374,8 @@ class cshessobs(ctools.cscript):
374 374
375 # Initialise empty xml file and append an observation list 375 # Initialise empty xml file and append an observation list
376 self.xml = gammalib.GXml() 376 self.xml = gammalib.GXml()
377 - self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\""));  
378 - lib = self.xml.element("observation_list", 0); 377 + self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\""))
  378 + lib = self.xml.element("observation_list", 0)
379 379
380 # Read runlist from file 380 # Read runlist from file
381 runlist = [] 381 runlist = []
cscripts/cspull.py
@@ -337,16 +337,16 @@ class cspull(ctools.cscript): @@ -337,16 +337,16 @@ class cspull(ctools.cscript):
337 """ 337 """
338 338
339 # Setup observation definition list 339 # Setup observation definition list
340 - obsdeflist = obsutils.set_obs_patterns(self.m_pattern, \  
341 - ra=self["ra"].real(), dec=self["dec"].real(), \ 340 + obsdeflist = obsutils.set_obs_patterns(self.m_pattern,
  341 + ra=self["ra"].real(), dec=self["dec"].real(),
342 offset=self["offset"].real()) 342 offset=self["offset"].real())
343 343
344 # Create list of observations 344 # Create list of observations
345 - obs = obsutils.set_obs_list(obsdeflist, \  
346 - tstart=self["tmin"].real(), duration=self["tmax"].real()-self["tmin"].real(), \  
347 - deadc=self["deadc"].real(), \  
348 - emin=self["emin"].real(), emax=self["emax"].real(), \  
349 - rad=self["rad"].real(), \ 345 + obs = obsutils.set_obs_list(obsdeflist,
  346 + tstart=self["tmin"].real(), duration=self["tmax"].real()-self["tmin"].real(),
  347 + deadc=self["deadc"].real(),
  348 + emin=self["emin"].real(), emax=self["emax"].real(),
  349 + rad=self["rad"].real(),
350 irf=self["irf"].string(), caldb=self["caldb"].string()) 350 irf=self["irf"].string(), caldb=self["caldb"].string())
351 351
352 # Return observation container 352 # Return observation container
@@ -366,14 +366,14 @@ class cspull(ctools.cscript): @@ -366,14 +366,14 @@ class cspull(ctools.cscript):
366 self.log.header2("Trial "+str(seed+1)) 366 self.log.header2("Trial "+str(seed+1))
367 367
368 # Simulate events 368 # Simulate events
369 - obs = obsutils.sim(self.obs, \  
370 - nbins=self.m_enumbins, \  
371 - seed=seed, \  
372 - binsz=self.m_binsz, \  
373 - npix=self.m_npix, \  
374 - edisp=self.m_edisp, \  
375 - log=self.m_log, \  
376 - debug=self.m_debug, \ 369 + obs = obsutils.sim(self.obs,
  370 + nbins=self.m_enumbins,
  371 + seed=seed,
  372 + binsz=self.m_binsz,
  373 + npix=self.m_npix,
  374 + edisp=self.m_edisp,
  375 + log=self.m_log,
  376 + debug=self.m_debug,
377 chatter=self.m_chatter) 377 chatter=self.m_chatter)
378 378
379 # If stacked, add stacked responses and model 379 # If stacked, add stacked responses and model
@@ -398,14 +398,14 @@ class cspull(ctools.cscript): @@ -398,14 +398,14 @@ class cspull(ctools.cscript):
398 models = obs.models() 398 models = obs.models()
399 for i in range(models.size()): 399 for i in range(models.size()):
400 model_name = models[i].name() 400 model_name = models[i].name()
401 - like = obsutils.cterror(obs, model_name, \  
402 - log=self.m_log, \ 401 + like = obsutils.cterror(obs, model_name,
  402 + log=self.m_log,
403 debug=self.m_debug, 403 debug=self.m_debug,
404 chatter=self.m_chatter) 404 chatter=self.m_chatter)
405 else: 405 else:
406 - like = obsutils.fit(obs, edisp=self.m_edisp, \  
407 - log=self.m_log, \  
408 - debug=self.m_debug, \ 406 + like = obsutils.fit(obs, edisp=self.m_edisp,
  407 + log=self.m_log,
  408 + debug=self.m_debug,
409 chatter=self.m_chatter) 409 chatter=self.m_chatter)
410 410
411 # Store results 411 # Store results
cscripts/cssens.py
@@ -166,8 +166,8 @@ class cssens(ctools.cscript): @@ -166,8 +166,8 @@ class cssens(ctools.cscript):
166 self.m_debug = self["debug"].boolean() # Debugging in client tools 166 self.m_debug = self["debug"].boolean() # Debugging in client tools
167 167
168 # Derive some parameters 168 # Derive some parameters
169 - self.m_ebounds = gammalib.GEbounds(self.m_bins, \  
170 - gammalib.GEnergy(self.m_emin, "TeV"), \ 169 + self.m_ebounds = gammalib.GEbounds(self.m_bins,
  170 + gammalib.GEnergy(self.m_emin, "TeV"),
171 gammalib.GEnergy(self.m_emax, "TeV")) 171 gammalib.GEnergy(self.m_emax, "TeV"))
172 172
173 # Return 173 # Return
@@ -200,7 +200,7 @@ class cssens(ctools.cscript): @@ -200,7 +200,7 @@ class cssens(ctools.cscript):
200 self.log("\n") 200 self.log("\n")
201 201
202 # Initialise script 202 # Initialise script
203 - colnames = ['loge', 'emin', 'emax', 'crab_flux', 'photon_flux', \ 203 + colnames = ['loge', 'emin', 'emax', 'crab_flux', 'photon_flux',
204 'energy_flux', 'sensitivity'] 204 'energy_flux', 'sensitivity']
205 results = [] 205 results = []
206 206
@@ -242,7 +242,7 @@ class cssens(ctools.cscript): @@ -242,7 +242,7 @@ class cssens(ctools.cscript):
242 raise gammalib.GException.invalid_value("cssens", msg) 242 raise gammalib.GException.invalid_value("cssens", msg)
243 243
244 # Determine sensitivity 244 # Determine sensitivity
245 - result = self.get_sensitivity(self.obs, emin, emax, \ 245 + result = self.get_sensitivity(self.obs, emin, emax,
246 bkg_model, full_model) 246 bkg_model, full_model)
247 247
248 # Write results 248 # Write results
@@ -297,8 +297,8 @@ class cssens(ctools.cscript): @@ -297,8 +297,8 @@ class cssens(ctools.cscript):
297 pntdir.lb_deg(lpnt, bpnt) 297 pntdir.lb_deg(lpnt, bpnt)
298 298
299 # Create CTA observation 299 # Create CTA observation
300 - run = obsutils.set_obs(pntdir, caldb=caldb, irf=irf, \  
301 - duration=duration, deadc=deadc, \ 300 + run = obsutils.set_obs(pntdir, caldb=caldb, irf=irf,
  301 + duration=duration, deadc=deadc,
302 emin=emin, emax=emax, rad=rad) 302 emin=emin, emax=emax, rad=rad)
303 303
304 # Append observation to container 304 # Append observation to container
@@ -464,8 +464,8 @@ class cssens(ctools.cscript): @@ -464,8 +464,8 @@ class cssens(ctools.cscript):
464 obs.models(src_model) 464 obs.models(src_model)
465 465
466 # Simulate events 466 # Simulate events
467 - sim = obsutils.sim(obs, nbins=self.m_enumbins, seed=iter, \  
468 - binsz=self.m_binsz, npix=self.m_npix, \ 467 + sim = obsutils.sim(obs, nbins=self.m_enumbins, seed=iter,
  468 + binsz=self.m_binsz, npix=self.m_npix,
469 log=self.m_log, debug=self.m_debug) 469 log=self.m_log, debug=self.m_debug)
470 470
471 # Determine number of events in simulation 471 # Determine number of events in simulation
cscripts/cstsdist.py
@@ -328,16 +328,19 @@ class cstsdist(ctools.cscript): @@ -328,16 +328,19 @@ class cstsdist(ctools.cscript):
328 """ 328 """
329 329
330 # Setup observation definition list 330 # Setup observation definition list
331 - obsdeflist = obsutils.set_obs_patterns(self.m_pattern, \  
332 - ra=self["ra"].real(), dec=self["dec"].real(), \ 331 + obsdeflist = obsutils.set_obs_patterns(self.m_pattern,
  332 + ra=self["ra"].real(),
  333 + dec=self["dec"].real(),
333 offset=self["offset"].real()) 334 offset=self["offset"].real())
334 335
335 # Create list of observations 336 # Create list of observations
336 - obs = obsutils.set_obs_list(obsdeflist, \  
337 - tstart=self["tmin"].real(), duration=self["tmax"].real()-self["tmin"].real(), \  
338 - deadc=self["deadc"].real(), \  
339 - emin=self["emin"].real(), emax=self["emax"].real(), \  
340 - rad=self["rad"].real(), \ 337 + obs = obsutils.set_obs_list(obsdeflist,
  338 + tstart=self["tmin"].real(),
  339 + duration=self["tmax"].real()-self["tmin"].real(),
  340 + deadc=self["deadc"].real(),
  341 + emin=self["emin"].real(),
  342 + emax=self["emax"].real(),
  343 + rad=self["rad"].real(),
341 irf=self["irf"].string(), caldb=self["caldb"].string()) 344 irf=self["irf"].string(), caldb=self["caldb"].string())
342 345
343 # Return observation container 346 # Return observation container
@@ -355,11 +358,11 @@ class cstsdist(ctools.cscript): @@ -355,11 +358,11 @@ class cstsdist(ctools.cscript):
355 self.log.header2("Trial "+str(seed+1)) 358 self.log.header2("Trial "+str(seed+1))
356 359
357 # Simulate events 360 # Simulate events
358 - sim = obsutils.sim(self.obs, \  
359 - nbins=self.m_enumbins, \  
360 - seed=seed, \  
361 - binsz=self.m_binsz, \  
362 - npix=self.m_npix, \ 361 + sim = obsutils.sim(self.obs,
  362 + nbins=self.m_enumbins,
  363 + seed=seed,
  364 + binsz=self.m_binsz,
  365 + npix=self.m_npix,
363 log=self.m_log, debug=self.m_debug) 366 log=self.m_log, debug=self.m_debug)
364 367
365 # Determine number of events in simulation 368 # Determine number of events in simulation
examples/benchmark_cta_analysis.py
@@ -20,7 +20,6 @@ @@ -20,7 +20,6 @@
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. 20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # 21 #
22 # ========================================================================== 22 # ==========================================================================
23 -import gammalib  
24 import ctools 23 import ctools
25 import time 24 import time
26 try: 25 try:
examples/check_models.py
@@ -24,114 +24,113 @@ @@ -24,114 +24,113 @@
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # 25 #
26 # ========================================================================== 26 # ==========================================================================
27 -import gammalib  
28 -import ctools  
29 import sys 27 import sys
  28 +import ctools
30 29
31 30
32 # ================= # 31 # ================= #
33 # Analysis pipeline # 32 # Analysis pipeline #
34 # ================= # 33 # ================= #
35 def pipeline(model_name): 34 def pipeline(model_name):
36 - """  
37 - Unbinned analysis pipeline - keep intermediate results in memory.  
38 - 35 + """
  36 + Unbinned analysis pipeline - keep intermediate results in memory.
  37 +
39 This function implements an analysis pipeline that successively calls 38 This function implements an analysis pipeline that successively calls
40 ctobssim, ctselect and ctlike without saving the intermediate results as 39 ctobssim, ctselect and ctlike without saving the intermediate results as
41 - FITS files on disk. All data is only hold in memory.  
42 - """  
43 - # Set script parameters  
44 - caldb = "prod2"  
45 - irf = "South_50h"  
46 - ra = 83.63  
47 - dec = 22.01  
48 - rad_sim = 10.0  
49 - tstart = 0.0  
50 - tstop = 1800.0  
51 - emin = 0.1  
52 - emax = 100.0  
53 - rad_select = 3.0  
54 -  
55 - # Write model name  
56 - print("*** Model: "+model_name+" ************************************")  
57 -  
58 - # Initialise timing  
59 - wall_seconds = 0.0  
60 - cpu_seconds = 0.0  
61 -  
62 - # Simulate events  
63 - sim = ctools.ctobssim()  
64 - sim["inmodel"] = model_name  
65 - sim["caldb"] = caldb  
66 - sim["irf"] = irf  
67 - sim["ra"] = ra  
68 - sim["dec"] = dec  
69 - sim["rad"] = rad_sim  
70 - sim["tmin"] = tstart  
71 - sim["tmax"] = tstop  
72 - sim["emin"] = emin  
73 - sim["emax"] = emax  
74 - sim.run()  
75 -  
76 - # Select events  
77 - select = ctools.ctselect(sim.obs())  
78 - select["ra"] = ra  
79 - select["dec"] = dec  
80 - select["rad"] = rad_select  
81 - select["tmin"] = tstart  
82 - select["tmax"] = tstop  
83 - select["emin"] = emin  
84 - select["emax"] = emax  
85 - select.run()  
86 -  
87 - # Perform maximum likelihood fitting  
88 - like = ctools.ctlike(select.obs())  
89 - like.run()  
90 -  
91 - # Show model fitting results  
92 - print(like.obs().models()[0])  
93 -  
94 - # Return  
95 - return 40 + FITS files on disk. All data is only hold in memory.
  41 + """
  42 + # Set script parameters
  43 + caldb = "prod2"
  44 + irf = "South_50h"
  45 + ra = 83.63
  46 + dec = 22.01
  47 + rad_sim = 10.0
  48 + tstart = 0.0
  49 + tstop = 1800.0
  50 + emin = 0.1
  51 + emax = 100.0
  52 + rad_select = 3.0
  53 +
  54 + # Write model name
  55 + print("*** Model: "+model_name+" ************************************")
  56 +
  57 + # Initialise timing
  58 + wall_seconds = 0.0
  59 + cpu_seconds = 0.0
  60 +
  61 + # Simulate events
  62 + sim = ctools.ctobssim()
  63 + sim["inmodel"] = model_name
  64 + sim["caldb"] = caldb
  65 + sim["irf"] = irf
  66 + sim["ra"] = ra
  67 + sim["dec"] = dec
  68 + sim["rad"] = rad_sim
  69 + sim["tmin"] = tstart
  70 + sim["tmax"] = tstop
  71 + sim["emin"] = emin
  72 + sim["emax"] = emax
  73 + sim.run()
  74 +
  75 + # Select events
  76 + select = ctools.ctselect(sim.obs())
  77 + select["ra"] = ra
  78 + select["dec"] = dec
  79 + select["rad"] = rad_select
  80 + select["tmin"] = tstart
  81 + select["tmax"] = tstop
  82 + select["emin"] = emin
  83 + select["emax"] = emax
  84 + select.run()
  85 +
  86 + # Perform maximum likelihood fitting
  87 + like = ctools.ctlike(select.obs())
  88 + like.run()
  89 +
  90 + # Show model fitting results
  91 + print(like.obs().models()[0])
  92 +
  93 + # Return
  94 + return
96 95
97 96
98 #==========================# 97 #==========================#
99 # Main routine entry point # 98 # Main routine entry point #
100 #==========================# 99 #==========================#
101 if __name__ == '__main__': 100 if __name__ == '__main__':
102 - """  
103 - Perform unbinned analyses for various models.  
104 - """  
105 - # Initialise flags  
106 - need_help = False  
107 -  
108 - # Test for command line arguments  
109 - print(sys.argv[0])  
110 - if (len(sys.argv) > 1):  
111 - if sys.argv[1] == "-h":  
112 - need_help = True  
113 - else:  
114 - need_help = True  
115 -  
116 - # Print help if needed and exit  
117 - if need_help:  
118 - print("Usage: check_models.py [OPTIONS]")  
119 - print(" -h Display this usage message")  
120 - sys.exit()  
121 -  
122 - # Dump header  
123 - print("*******************************************")  
124 - print("* Check models using an unbinned analysis *")  
125 - print("*******************************************")  
126 -  
127 - # Perform analysis for Crab model  
128 - pipeline("$CTOOLS/share/models/crab.xml")  
129 -  
130 - # Perform analysis for disk model  
131 - pipeline("$CTOOLS/share/models/disk.xml")  
132 -  
133 - # Perform analysis for Gaussian model  
134 - pipeline("$CTOOLS/share/models/gauss.xml")  
135 -  
136 - # Perform analysis for shell model  
137 - pipeline("$CTOOLS/share/models/shell.xml") 101 + """
  102 + Perform unbinned analyses for various models.
  103 + """
  104 + # Initialise flags
  105 + need_help = False
  106 +
  107 + # Test for command line arguments
  108 + print(sys.argv[0])
  109 + if (len(sys.argv) > 1):
  110 + if sys.argv[1] == "-h":
  111 + need_help = True
  112 + else:
  113 + need_help = True
  114 +
  115 + # Print help if needed and exit
  116 + if need_help:
  117 + print("Usage: check_models.py [OPTIONS]")
  118 + print(" -h Display this usage message")
  119 + sys.exit()
  120 +
  121 + # Dump header
  122 + print("*******************************************")
  123 + print("* Check models using an unbinned analysis *")
  124 + print("*******************************************")
  125 +
  126 + # Perform analysis for Crab model
  127 + pipeline("$CTOOLS/share/models/crab.xml")
  128 +
  129 + # Perform analysis for disk model
  130 + pipeline("$CTOOLS/share/models/disk.xml")
  131 +
  132 + # Perform analysis for Gaussian model
  133 + pipeline("$CTOOLS/share/models/gauss.xml")
  134 +
  135 + # Perform analysis for shell model
  136 + pipeline("$CTOOLS/share/models/shell.xml")
examples/make_pointings.py
@@ -23,9 +23,9 @@ @@ -23,9 +23,9 @@
23 # along with this program. If not, see <http://www.gnu.org/licenses/>. 23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # 24 #
25 # ========================================================================== 25 # ==========================================================================
26 -import gammalib  
27 import sys 26 import sys
28 import math 27 import math
  28 +import gammalib
29 29
30 30
31 # ============================================================ # 31 # ============================================================ #
@@ -82,8 +82,8 @@ def get_positions(xmin, xmax, ymin, ymax, step): @@ -82,8 +82,8 @@ def get_positions(xmin, xmax, ymin, ymax, step):
82 # ====================== # 82 # ====================== #
83 # Setup patch on the sky # 83 # Setup patch on the sky #
84 # ====================== # 84 # ====================== #
85 -def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, \  
86 - separation=3.0, hours=100.0, \ 85 +def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5,
  86 + separation=3.0, hours=100.0,
87 site=None, lst=True, autodec=0.0): 87 site=None, lst=True, autodec=0.0):
88 """ 88 """
89 Setup pointing patch on the sky. 89 Setup pointing patch on the sky.
@@ -147,11 +147,11 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, \ @@ -147,11 +147,11 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, \
147 147
148 # Dump statistics 148 # Dump statistics
149 print("Number of pointings: %d (%.2f sec)" % (n_pnt,duration)) 149 print("Number of pointings: %d (%.2f sec)" % (n_pnt,duration))
150 - print("South array .......: %.2f hours (%.2f%%)" % \  
151 - (exposure_south/3600.0, \ 150 + print("South array .......: %.2f hours (%.2f%%)" %
  151 + (exposure_south/3600.0,
152 100.0*exposure_south/(exposure_south+exposure_north))) 152 100.0*exposure_south/(exposure_south+exposure_north)))
153 - print("North array .......: %.2f hours (%.2f%%)" % \  
154 - (exposure_north/3600.0, \ 153 + print("North array .......: %.2f hours (%.2f%%)" %
  154 + (exposure_north/3600.0,
155 100.0*exposure_north/(exposure_south+exposure_north))) 155 100.0*exposure_north/(exposure_south+exposure_north)))
156 156
157 # Return observation definition 157 # Return observation definition
@@ -169,28 +169,28 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): @@ -169,28 +169,28 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True):
169 obsdef = [] 169 obsdef = []
170 170
171 # Add inner region South 171 # Add inner region South
172 - obsdef.extend(set_patch(lmin=-60.0, lmax=60.0, bmin=bmin, bmax=bmax, \  
173 - separation=separation, hours=780, \ 172 + obsdef.extend(set_patch(lmin=-60.0, lmax=60.0, bmin=bmin, bmax=bmax,
  173 + separation=separation, hours=780,
174 site="South", lst=lst)) 174 site="South", lst=lst))
175 175
176 # Add Vela & Carina region 176 # Add Vela & Carina region
177 - obsdef.extend(set_patch(lmin=240.0, lmax=300.0, bmin=bmin, bmax=bmax, \  
178 - separation=separation, hours=180, \ 177 + obsdef.extend(set_patch(lmin=240.0, lmax=300.0, bmin=bmin, bmax=bmax,
  178 + separation=separation, hours=180,
179 site="South", lst=lst)) 179 site="South", lst=lst))
180 180
181 # Add 210-240 region 181 # Add 210-240 region
182 - obsdef.extend(set_patch(lmin=210.0, lmax=240.0, bmin=bmin, bmax=bmax, \  
183 - separation=separation, hours=60, \ 182 + obsdef.extend(set_patch(lmin=210.0, lmax=240.0, bmin=bmin, bmax=bmax,
  183 + separation=separation, hours=60,
184 site="South", lst=lst)) 184 site="South", lst=lst))
185 185
186 # Add Cygnus, Perseus 186 # Add Cygnus, Perseus
187 - obsdef.extend(set_patch(lmin=60.0, lmax=150.0, bmin=bmin, bmax=bmax, \  
188 - separation=separation, hours=450, \ 187 + obsdef.extend(set_patch(lmin=60.0, lmax=150.0, bmin=bmin, bmax=bmax,
  188 + separation=separation, hours=450,
189 site="North", lst=lst)) 189 site="North", lst=lst))
190 190
191 # Add Anticentre 191 # Add Anticentre
192 - obsdef.extend(set_patch(lmin=150.0, lmax=210.0, bmin=bmin, bmax=bmax, \  
193 - separation=separation, hours=150, \ 192 + obsdef.extend(set_patch(lmin=150.0, lmax=210.0, bmin=bmin, bmax=bmax,
  193 + separation=separation, hours=150,
194 site="North", lst=lst)) 194 site="North", lst=lst))
195 195
196 # Return observation definition 196 # Return observation definition
@@ -208,8 +208,8 @@ def set_extgal(separation=3.0, lst=True): @@ -208,8 +208,8 @@ def set_extgal(separation=3.0, lst=True):
208 obsdef = [] 208 obsdef = []
209 209
210 # Set patch 210 # Set patch
211 - obsdef.extend(set_patch(lmin=-90.0, lmax=90.0, bmin=+5.0, bmax=+88.0, \  
212 - separation=separation, hours=1000, \ 211 + obsdef.extend(set_patch(lmin=-90.0, lmax=90.0, bmin=+5.0, bmax=+88.0,
  212 + separation=separation, hours=1000,
213 site="Automatic", lst=lst, autodec=10.0)) 213 site="Automatic", lst=lst, autodec=10.0))
214 214
215 # Return observation definition 215 # Return observation definition
@@ -227,13 +227,13 @@ def set_gc(lst=True): @@ -227,13 +227,13 @@ def set_gc(lst=True):
227 obsdef = [] 227 obsdef = []
228 228
229 # Central wobble 229 # Central wobble
230 - obsdef.extend(set_patch(lmin=-0.5, lmax=0.5, bmin=-0.5, bmax=0.5, \  
231 - separation=0.1, hours=525, \ 230 + obsdef.extend(set_patch(lmin=-0.5, lmax=0.5, bmin=-0.5, bmax=0.5,
  231 + separation=0.1, hours=525,
232 site="South", lst=lst)) 232 site="South", lst=lst))
233 233
234 # Extended region 234 # Extended region
235 - obsdef.extend(set_patch(lmin=-10.0, lmax=10.0, bmin=-10.0, bmax=10.0, \  
236 - separation=1.5, hours=300, \ 235 + obsdef.extend(set_patch(lmin=-10.0, lmax=10.0, bmin=-10.0, bmax=10.0,
  236 + separation=1.5, hours=300,
237 site="South", lst=lst)) 237 site="South", lst=lst))
238 238
239 # Return observation definition 239 # Return observation definition
@@ -322,7 +322,7 @@ def write_obsdef(filename, obsdef): @@ -322,7 +322,7 @@ def write_obsdef(filename, obsdef):
322 dec = obs["dec"] 322 dec = obs["dec"]
323 323
324 # Write information 324 # Write information
325 - file.write("%8.4f,%8.4f,%.4f,%s,%s\n" % \ 325 + file.write("%8.4f,%8.4f,%.4f,%s,%s\n" %
326 (ra, dec, obs['duration'], obs['caldb'], obs['irf'])) 326 (ra, dec, obs['duration'], obs['caldb'], obs['irf']))
327 327
328 # Close file 328 # Close file
@@ -387,5 +387,4 @@ if __name__ == &#39;__main__&#39;: @@ -387,5 +387,4 @@ if __name__ == &#39;__main__&#39;:
387 387
388 # Invalid pattern 388 # Invalid pattern
389 else: 389 else:
390 - print("Unknown option \""+obsname+"\"")  
391 - 390 + print('Unknown option "' + obsname + '"')
examples/make_pull_at_sensitivity_limit.py
@@ -24,11 +24,11 @@ @@ -24,11 +24,11 @@
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # 25 #
26 # ========================================================================== 26 # ==========================================================================
27 -from ctools import *  
28 -from gammalib import *  
29 -from cspull import *  
30 import sys 27 import sys
31 import time 28 import time
  29 +import csv
  30 +import gammalib
  31 +from cscripts import cspull
32 32
33 # Try importing processing module 33 # Try importing processing module
34 has_processing = False 34 has_processing = False
@@ -42,7 +42,7 @@ except: @@ -42,7 +42,7 @@ except:
42 # ======================== # 42 # ======================== #
43 # Create pull distribution # 43 # Create pull distribution #
44 # ======================== # 44 # ======================== #
45 -def create_pull(loge, emin, emax, models, ntrials=100, duration=180000.0, \ 45 +def create_pull(loge, emin, emax, models, ntrials=100, duration=180000.0,
46 enumbins=0, log=False): 46 enumbins=0, log=False):
47 """ 47 """
48 Create pull distribution 48 Create pull distribution
@@ -94,8 +94,8 @@ def create_model(flux, index=-2.48, fitidx=False): @@ -94,8 +94,8 @@ def create_model(flux, index=-2.48, fitidx=False):
94 flux - Flux in Crab units 94 flux - Flux in Crab units
95 """ 95 """
96 # Define background model 96 # Define background model
97 - bgd_radial = GCTAModelRadialGauss(3.0)  
98 - bgd_spectrum = GModelSpectralPlaw(61.8, -1.85) 97 + bgd_radial = gammalib.GCTAModelRadialGauss(3.0)
  98 + bgd_spectrum = gammalib.GModelSpectralPlaw(61.8, -1.85)
99 bgd_spectrum["Prefactor"].scale(1.0e-6) 99 bgd_spectrum["Prefactor"].scale(1.0e-6)
100 bgd_spectrum["PivotEnergy"].value(1.0) 100 bgd_spectrum["PivotEnergy"].value(1.0)
101 bgd_spectrum["PivotEnergy"].scale(1.0e6) 101 bgd_spectrum["PivotEnergy"].scale(1.0e6)
@@ -103,15 +103,15 @@ def create_model(flux, index=-2.48, fitidx=False): @@ -103,15 +103,15 @@ def create_model(flux, index=-2.48, fitidx=False):
103 bgd_spectrum["Index"].free() 103 bgd_spectrum["Index"].free()
104 else: 104 else:
105 bgd_spectrum["Index"].fix() 105 bgd_spectrum["Index"].fix()
106 - bgd_model = GCTAModelRadialAcceptance(bgd_radial, bgd_spectrum) 106 + bgd_model = gammalib.GCTAModelRadialAcceptance(bgd_radial, bgd_spectrum)
107 bgd_model.name("Background") 107 bgd_model.name("Background")
108 bgd_model.instruments("CTA") 108 bgd_model.instruments("CTA")
109 109
110 # Define source spectrum 110 # Define source spectrum
111 - location = GSkyDir() 111 + location = gammalib.GSkyDir()
112 location.radec_deg(83.6331, 22.0145) 112 location.radec_deg(83.6331, 22.0145)
113 - src_spatial = GModelSpatialPtsrc(location)  
114 - src_spectrum = GModelSpectralPlaw(flux, index) 113 + src_spatial = gammalib.GModelSpatialPtsrc(location)
  114 + src_spectrum = gammalib.GModelSpectralPlaw(flux, index)
115 src_spectrum["Prefactor"].scale(5.7e-16) 115 src_spectrum["Prefactor"].scale(5.7e-16)
116 src_spectrum["PivotEnergy"].value(0.3) 116 src_spectrum["PivotEnergy"].value(0.3)
117 src_spectrum["PivotEnergy"].scale(1.0e6) 117 src_spectrum["PivotEnergy"].scale(1.0e6)
@@ -119,11 +119,11 @@ def create_model(flux, index=-2.48, fitidx=False): @@ -119,11 +119,11 @@ def create_model(flux, index=-2.48, fitidx=False):
119 src_spectrum["Index"].free() 119 src_spectrum["Index"].free()
120 else: 120 else:
121 src_spectrum["Index"].fix() 121 src_spectrum["Index"].fix()
122 - src_model = GModelPointSource(src_spatial, src_spectrum) 122 + src_model = gammalib.GModelPointSource(src_spatial, src_spectrum)
123 src_model.name("Test") 123 src_model.name("Test")
124 124
125 # Add models to container 125 # Add models to container
126 - models = GModels() 126 + models = gammalib.GModels()
127 models.append(bgd_model) 127 models.append(bgd_model)
128 models.append(src_model) 128 models.append(src_model)
129 129
@@ -141,7 +141,11 @@ if __name__ == &#39;__main__&#39;: @@ -141,7 +141,11 @@ if __name__ == &#39;__main__&#39;:
141 cssens script. 141 cssens script.
142 """ 142 """
143 # Get input arguments 143 # Get input arguments
144 - usage = "make_pull_at_sensitivity_limit filename [max_threads]" 144 + usage = """
  145 + make_pull_at_sensitivity_limit filename [max_threads]
  146 +
  147 + Run cssens to create the input file.
  148 + """
145 if len(sys.argv) < 2 or len(sys.argv) > 3: 149 if len(sys.argv) < 2 or len(sys.argv) > 3:
146 print(usage) 150 print(usage)
147 sys.exit() 151 sys.exit()
examples/make_spectrum.py
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 # ========================================================================== 20 # ==========================================================================
21 import gammalib 21 import gammalib
22 import ctools 22 import ctools
23 -from ctools import obsutils 23 +from cscripts import obsutils
24 try: 24 try:
25 import matplotlib.pyplot as plt 25 import matplotlib.pyplot as plt
26 has_matplotlib = True 26 has_matplotlib = True
@@ -84,10 +84,10 @@ def plot_spectrum(spectrum): @@ -84,10 +84,10 @@ def plot_spectrum(spectrum):
84 plt.title("Crab spectrum") 84 plt.title("Crab spectrum")
85 85
86 # Plot spectrum 86 # Plot spectrum
87 - plt.loglog(spectrum['energy']['value'], \ 87 + plt.loglog(spectrum['energy']['value'],
88 spectrum['flux']['value'], 'ro', label='Crab') 88 spectrum['flux']['value'], 'ro', label='Crab')
89 - plt.errorbar(spectrum['energy']['value'], \  
90 - spectrum['flux']['value'], \ 89 + plt.errorbar(spectrum['energy']['value'],
  90 + spectrum['flux']['value'],
91 spectrum['flux']['ed_value'], ecolor='r') 91 spectrum['flux']['ed_value'], ecolor='r')
92 92
93 # Put labels 93 # Put labels
@@ -115,4 +115,3 @@ if __name__ == &#39;__main__&#39;: @@ -115,4 +115,3 @@ if __name__ == &#39;__main__&#39;:
115 # Plot spectrum 115 # Plot spectrum
116 if has_matplotlib: 116 if has_matplotlib:
117 plot_spectrum(spectrum) 117 plot_spectrum(spectrum)
118 -  
119 \ No newline at end of file 118 \ No newline at end of file
examples/make_survey.py
@@ -23,11 +23,12 @@ @@ -23,11 +23,12 @@
23 # along with this program. If not, see <http://www.gnu.org/licenses/>. 23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # 24 #
25 # ========================================================================== 25 # ==========================================================================
26 -import gammalib  
27 -from ctools import obsutils  
28 import os 26 import os
29 import glob 27 import glob
30 import sys 28 import sys
  29 +import math
  30 +import gammalib
  31 +from cscripts import obsutils
31 32
32 33
33 # =========== # 34 # =========== #
@@ -86,7 +87,7 @@ def plot_counts(obs): @@ -86,7 +87,7 @@ def plot_counts(obs):
86 counts[index] = counts[index] + 1.0 87 counts[index] = counts[index] + 1.0
87 88
88 # Create error bars 89 # Create error bars
89 - error = [sqrt(c) for c in counts] 90 + error = [math.sqrt(c) for c in counts]
90 91
91 # Plot spectrum 92 # Plot spectrum
92 plt.loglog(energy, counts, 'ro', label='data') 93 plt.loglog(energy, counts, 'ro', label='data')
@@ -140,7 +141,7 @@ def plot_counts(obs): @@ -140,7 +141,7 @@ def plot_counts(obs):
140 counts[index] = counts[index] + 1.0 141 counts[index] = counts[index] + 1.0
141 142
142 # Create error bars 143 # Create error bars
143 - error = [sqrt(c) for c in counts] 144 + error = [math.sqrt(c) for c in counts]
144 145
145 # Plot distribution 146 # Plot distribution
146 #plt.semilogy(offset2, counts, 'ro', label='data') 147 #plt.semilogy(offset2, counts, 'ro', label='data')
examples/make_ts_distributions.py
@@ -28,9 +28,9 @@ @@ -28,9 +28,9 @@
28 # along with this program. If not, see <http://www.gnu.org/licenses/>. 28 # along with this program. If not, see <http://www.gnu.org/licenses/>.
29 # 29 #
30 # ========================================================================== 30 # ==========================================================================
31 -from ctools.cstsdist import *  
32 import sys 31 import sys
33 import time 32 import time
  33 +from cscripts import cstsdist
34 34
35 # Try importing processing module 35 # Try importing processing module
36 has_processing = False 36 has_processing = False
@@ -44,7 +44,7 @@ except: @@ -44,7 +44,7 @@ except:
44 # ====================== # 44 # ====================== #
45 # Create TS distribution # 45 # Create TS distribution #
46 # ====================== # 46 # ====================== #
47 -def create_ts(loge, emin, emax, ntrials=100, duration=180000.0, \ 47 +def create_ts(loge, emin, emax, ntrials=100, duration=180000.0,
48 enumbins=0, log=False): 48 enumbins=0, log=False):
49 """ 49 """
50 Create TS distribution. 50 Create TS distribution.
@@ -110,9 +110,9 @@ if __name__ == &#39;__main__&#39;: @@ -110,9 +110,9 @@ if __name__ == &#39;__main__&#39;:
110 max_threads = 1 110 max_threads = 1
111 111
112 # Parameter dictionnary 112 # Parameter dictionnary
113 - pars = [{'option': '-n', 'value': ntrials}, \  
114 - {'option': '-e', 'value': enumbins}, \  
115 - {'option': '-d', 'value': duration}, \ 113 + pars = [{'option': '-n', 'value': ntrials},
  114 + {'option': '-e', 'value': enumbins},
  115 + {'option': '-d', 'value': duration},
116 {'option': '-m', 'value': max_threads}] 116 {'option': '-m', 'value': max_threads}]
117 117
118 # Gather parameters from command line 118 # Gather parameters from command line
@@ -165,7 +165,7 @@ if __name__ == &#39;__main__&#39;: @@ -165,7 +165,7 @@ if __name__ == &#39;__main__&#39;:
165 165
166 # Set arguments 166 # Set arguments
167 args = (loge, emin, emax) 167 args = (loge, emin, emax)
168 - kwargs = {'ntrials': ntrials, 'enumbins': enumbins, \ 168 + kwargs = {'ntrials': ntrials, 'enumbins': enumbins,
169 'duration': duration} 169 'duration': duration}
170 170
171 # Generate pull distribution 171 # Generate pull distribution
@@ -178,7 +178,7 @@ if __name__ == &#39;__main__&#39;: @@ -178,7 +178,7 @@ if __name__ == &#39;__main__&#39;:
178 178
179 # ... no 179 # ... no
180 else: 180 else:
181 - create_ts(loge, emin, emax, ntrials=ntrials, enumbins=enumbins, \ 181 + create_ts(loge, emin, emax, ntrials=ntrials, enumbins=enumbins,
182 duration=duration) 182 duration=duration)
183 183
184 # Processing support 184 # Processing support
examples/pipeline_binned_disk.py
@@ -27,15 +27,15 @@ @@ -27,15 +27,15 @@
27 # ========================================================================== 27 # ==========================================================================
28 import gammalib 28 import gammalib
29 import ctools 29 import ctools
30 -from ctools import obsutils 30 +from cscripts import obsutils
31 31
32 32
33 # ================== # 33 # ================== #
34 # Setup observations # 34 # Setup observations #
35 # ================== # 35 # ================== #
36 -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \  
37 - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, \  
38 - deadc=0.95, \ 36 +def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
  37 + emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
  38 + deadc=0.95,
39 caldb="prod2", irf="South_50h"): 39 caldb="prod2", irf="South_50h"):
40 """ 40 """
41 Returns an observation container. 41 Returns an observation container.
@@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \ @@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \
54 irf - Instrument response function (default: cta_dummy_irf) 54 irf - Instrument response function (default: cta_dummy_irf)
55 """ 55 """
56 # Set list of observations 56 # Set list of observations
57 - obs_def_list = obsutils.set_obs_patterns(pattern, \  
58 - ra=ra, \  
59 - dec=dec, \ 57 + obs_def_list = obsutils.set_obs_patterns(pattern,
  58 + ra=ra,
  59 + dec=dec,
60 offset=offset) 60 offset=offset)
61 61
62 # Get observation container 62 # Get observation container
63 - obs = obsutils.set_obs_list(obs_def_list, \  
64 - duration=duration, \  
65 - emin=emin, \  
66 - emax=emax, \  
67 - rad=rad, \  
68 - caldb=caldb, \ 63 + obs = obsutils.set_obs_list(obs_def_list,
  64 + duration=duration,
  65 + emin=emin,
  66 + emax=emax,
  67 + rad=rad,
  68 + caldb=caldb,
69 irf=irf) 69 irf=irf)
70 70
71 # Return observation container 71 # Return observation container
@@ -92,11 +92,11 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;): @@ -92,11 +92,11 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;):
92 # ================================ # 92 # ================================ #
93 # Simulation and analysis pipeline # 93 # Simulation and analysis pipeline #
94 # ================================ # 94 # ================================ #
95 -def run_pipeline(obs, emin=0.1, emax=100.0, \  
96 - enumbins=20, nxpix=200, nypix=200, binsz=0.02, \  
97 - coordsys="CEL", proj="CAR", \  
98 - model="${CTOOLS}/share/models/crab.xml", \  
99 - caldb="prod2", irf="South_50h", \ 95 +def run_pipeline(obs, emin=0.1, emax=100.0,
  96 + enumbins=20, nxpix=200, nypix=200, binsz=0.02,
  97 + coordsys="CEL", proj="CAR",
  98 + model="${CTOOLS}/share/models/crab.xml",
  99 + caldb="prod2", irf="South_50h",
100 debug=False): 100 debug=False):
101 """ 101 """
102 Simulation and binned analysis pipeline. 102 Simulation and binned analysis pipeline.
examples/pipeline_binned_mem.py
@@ -27,15 +27,15 @@ @@ -27,15 +27,15 @@
27 # ========================================================================== 27 # ==========================================================================
28 import gammalib 28 import gammalib
29 import ctools 29 import ctools
30 -from ctools import obsutils 30 +from cscripts import obsutils
31 31
32 32
33 # ================== # 33 # ================== #
34 # Setup observations # 34 # Setup observations #
35 # ================== # 35 # ================== #
36 -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \  
37 - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, \  
38 - deadc=0.95, \ 36 +def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
  37 + emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
  38 + deadc=0.95,
39 caldb="prod2", irf="South_50h"): 39 caldb="prod2", irf="South_50h"):
40 """ 40 """
41 Returns an observation container. 41 Returns an observation container.
@@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \ @@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \
54 irf - Instrument response function (default: cta_dummy_irf) 54 irf - Instrument response function (default: cta_dummy_irf)
55 """ 55 """
56 # Set list of observations 56 # Set list of observations
57 - obs_def_list = obsutils.set_obs_patterns(pattern, \  
58 - ra=ra, \  
59 - dec=dec, \ 57 + obs_def_list = obsutils.set_obs_patterns(pattern,
  58 + ra=ra,
  59 + dec=dec,
60 offset=offset) 60 offset=offset)
61 61
62 # Get observation container 62 # Get observation container
63 - obs = obsutils.set_obs_list(obs_def_list, \  
64 - duration=duration, \  
65 - emin=emin, \  
66 - emax=emax, \  
67 - rad=rad, \  
68 - caldb=caldb, \ 63 + obs = obsutils.set_obs_list(obs_def_list,
  64 + duration=duration,
  65 + emin=emin,
  66 + emax=emax,
  67 + rad=rad,
  68 + caldb=caldb,
69 irf=irf) 69 irf=irf)
70 70
71 # Return observation container 71 # Return observation container
@@ -92,8 +92,8 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;): @@ -92,8 +92,8 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;):
92 # ================================ # 92 # ================================ #
93 # Simulation and analysis pipeline # 93 # Simulation and analysis pipeline #
94 # ================================ # 94 # ================================ #
95 -def run_pipeline(obs, emin=0.1, emax=100.0, \  
96 - enumbins=20, nxpix=200, nypix=200, binsz=0.02, \ 95 +def run_pipeline(obs, emin=0.1, emax=100.0,
  96 + enumbins=20, nxpix=200, nypix=200, binsz=0.02,
97 coordsys="CEL", proj="CAR", debug=False): 97 coordsys="CEL", proj="CAR", debug=False):
98 """ 98 """
99 Simulation and binned analysis pipeline. 99 Simulation and binned analysis pipeline.
examples/pipeline_stacked_disk.py
@@ -27,15 +27,15 @@ @@ -27,15 +27,15 @@
27 # ========================================================================== 27 # ==========================================================================
28 import gammalib 28 import gammalib
29 import ctools 29 import ctools
30 -from ctools import obsutils 30 +from cscripts import obsutils
31 31
32 32
33 # ================== # 33 # ================== #
34 # Setup observations # 34 # Setup observations #
35 # ================== # 35 # ================== #
36 -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \  
37 - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, \  
38 - deadc=0.95, \ 36 +def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
  37 + emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
  38 + deadc=0.95,
39 caldb="prod2", irf="South_50h"): 39 caldb="prod2", irf="South_50h"):
40 """ 40 """
41 Returns an observation container. 41 Returns an observation container.
@@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \ @@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \
54 irf - Instrument response function (default: cta_dummy_irf) 54 irf - Instrument response function (default: cta_dummy_irf)
55 """ 55 """
56 # Set list of observations 56 # Set list of observations
57 - obs_def_list = obsutils.set_obs_patterns(pattern, \  
58 - ra=ra, \  
59 - dec=dec, \ 57 + obs_def_list = obsutils.set_obs_patterns(pattern,
  58 + ra=ra,
  59 + dec=dec,
60 offset=offset) 60 offset=offset)
61 61
62 # Get observation container 62 # Get observation container
63 - obs = obsutils.set_obs_list(obs_def_list, \  
64 - duration=duration, \  
65 - emin=emin, \  
66 - emax=emax, \  
67 - rad=rad, \  
68 - caldb=caldb, \ 63 + obs = obsutils.set_obs_list(obs_def_list,
  64 + duration=duration,
  65 + emin=emin,
  66 + emax=emax,
  67 + rad=rad,
  68 + caldb=caldb,
69 irf=irf) 69 irf=irf)
70 70
71 # Return observation container 71 # Return observation container
@@ -92,11 +92,11 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;): @@ -92,11 +92,11 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;):
92 # ================================ # 92 # ================================ #
93 # Simulation and analysis pipeline # 93 # Simulation and analysis pipeline #
94 # ================================ # 94 # ================================ #
95 -def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, \  
96 - enumbins=20, nxpix=200, nypix=200, binsz=0.02, \  
97 - coordsys="CEL", proj="CAR", \  
98 - model="${CTOOLS}/share/models/crab.xml", \  
99 - caldb="prod2", irf="South_50h", \ 95 +def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0,
  96 + enumbins=20, nxpix=200, nypix=200, binsz=0.02,
  97 + coordsys="CEL", proj="CAR",
  98 + model="${CTOOLS}/share/models/crab.xml",
  99 + caldb="prod2", irf="South_50h",
100 debug=False): 100 debug=False):
101 """ 101 """
102 Simulation and stacked analysis pipeline. 102 Simulation and stacked analysis pipeline.
examples/pipeline_stacked_mem.py
@@ -27,15 +27,15 @@ @@ -27,15 +27,15 @@
27 # ========================================================================== 27 # ==========================================================================
28 import gammalib 28 import gammalib
29 import ctools 29 import ctools
30 -from ctools import obsutils 30 +from cscripts import obsutils
31 31
32 32
33 # ================== # 33 # ================== #
34 # Setup observations # 34 # Setup observations #
35 # ================== # 35 # ================== #
36 -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \  
37 - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, \  
38 - deadc=0.95, \ 36 +def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
  37 + emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
  38 + deadc=0.95,
39 caldb="prod2", irf="South_50h"): 39 caldb="prod2", irf="South_50h"):
40 """ 40 """
41 Returns an observation container. 41 Returns an observation container.
@@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \ @@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \
54 irf - Instrument response function (default: cta_dummy_irf) 54 irf - Instrument response function (default: cta_dummy_irf)
55 """ 55 """
56 # Set list of observations 56 # Set list of observations
57 - obs_def_list = obsutils.set_obs_patterns(pattern, \  
58 - ra=ra, \  
59 - dec=dec, \ 57 + obs_def_list = obsutils.set_obs_patterns(pattern,
  58 + ra=ra,
  59 + dec=dec,
60 offset=offset) 60 offset=offset)
61 61
62 # Get observation container 62 # Get observation container
63 - obs = obsutils.set_obs_list(obs_def_list, \  
64 - duration=duration, \  
65 - emin=emin, \  
66 - emax=emax, \  
67 - rad=rad, \  
68 - caldb=caldb, \ 63 + obs = obsutils.set_obs_list(obs_def_list,
  64 + duration=duration,
  65 + emin=emin,
  66 + emax=emax,
  67 + rad=rad,
  68 + caldb=caldb,
69 irf=irf) 69 irf=irf)
70 70
71 # Return observation container 71 # Return observation container
@@ -92,8 +92,8 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;): @@ -92,8 +92,8 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;):
92 # ================================ # 92 # ================================ #
93 # Simulation and analysis pipeline # 93 # Simulation and analysis pipeline #
94 # ================================ # 94 # ================================ #
95 -def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, \  
96 - enumbins=20, nxpix=200, nypix=200, binsz=0.02, \ 95 +def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0,
  96 + enumbins=20, nxpix=200, nypix=200, binsz=0.02,
97 coordsys="CEL", proj="CAR", debug=False): 97 coordsys="CEL", proj="CAR", debug=False):
98 """ 98 """
99 Simulation and stacked analysis pipeline. 99 Simulation and stacked analysis pipeline.
examples/pipeline_unbinned_disk.py
@@ -27,15 +27,15 @@ @@ -27,15 +27,15 @@
27 # ========================================================================== 27 # ==========================================================================
28 import gammalib 28 import gammalib
29 import ctools 29 import ctools
30 -from ctools import obsutils 30 +from cscripts import obsutils
31 31
32 32
33 # ================== # 33 # ================== #
34 # Setup observations # 34 # Setup observations #
35 # ================== # 35 # ================== #
36 -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \  
37 - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, \  
38 - deadc=0.95, \ 36 +def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
  37 + emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
  38 + deadc=0.95,
39 caldb="prod2", irf="South_50h"): 39 caldb="prod2", irf="South_50h"):
40 """ 40 """
41 Returns an observation container. 41 Returns an observation container.
@@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \ @@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \
54 irf - Instrument response function (default: cta_dummy_irf) 54 irf - Instrument response function (default: cta_dummy_irf)
55 """ 55 """
56 # Set list of observations 56 # Set list of observations
57 - obs_def_list = obsutils.set_obs_patterns(pattern, \  
58 - ra=ra, \  
59 - dec=dec, \ 57 + obs_def_list = obsutils.set_obs_patterns(pattern,
  58 + ra=ra,
  59 + dec=dec,
60 offset=offset) 60 offset=offset)
61 61
62 # Get observation container 62 # Get observation container
63 - obs = obsutils.set_obs_list(obs_def_list, \  
64 - duration=duration, \  
65 - emin=emin, \  
66 - emax=emax, \  
67 - rad=rad, \  
68 - caldb=caldb, \ 63 + obs = obsutils.set_obs_list(obs_def_list,
  64 + duration=duration,
  65 + emin=emin,
  66 + emax=emax,
  67 + rad=rad,
  68 + caldb=caldb,
69 irf=irf) 69 irf=irf)
70 70
71 # Return observation container 71 # Return observation container
@@ -92,11 +92,11 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;): @@ -92,11 +92,11 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;):
92 # ================================ # 92 # ================================ #
93 # Simulation and analysis pipeline # 93 # Simulation and analysis pipeline #
94 # ================================ # 94 # ================================ #
95 -def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, \  
96 - emin=0.1, emax=100.0, \  
97 - tmin=0.0, tmax=0.0, \  
98 - model="${CTOOLS}/share/models/crab.xml", \  
99 - caldb="prod2", irf="South_50h", \ 95 +def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0,
  96 + emin=0.1, emax=100.0,
  97 + tmin=0.0, tmax=0.0,
  98 + model="${CTOOLS}/share/models/crab.xml",
  99 + caldb="prod2", irf="South_50h",
100 debug=False): 100 debug=False):
101 """ 101 """
102 Simulation and unbinned analysis pipeline. 102 Simulation and unbinned analysis pipeline.
examples/pipeline_unbinned_mem.py
@@ -27,15 +27,15 @@ @@ -27,15 +27,15 @@
27 # ========================================================================== 27 # ==========================================================================
28 import gammalib 28 import gammalib
29 import ctools 29 import ctools
30 -from ctools import obsutils 30 +from cscripts import obsutils
31 31
32 32
33 # ================== # 33 # ================== #
34 # Setup observations # 34 # Setup observations #
35 # ================== # 35 # ================== #
36 -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \  
37 - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, \  
38 - deadc=0.95, \ 36 +def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
  37 + emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
  38 + deadc=0.95,
39 caldb="prod2", irf="South_50h"): 39 caldb="prod2", irf="South_50h"):
40 """ 40 """
41 Returns an observation container. 41 Returns an observation container.
@@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \ @@ -54,18 +54,18 @@ def setup_observations(pattern=&quot;four&quot;, ra=83.63, dec=22.01, offset=1.5, \
54 irf - Instrument response function (default: cta_dummy_irf) 54 irf - Instrument response function (default: cta_dummy_irf)
55 """ 55 """
56 # Set list of observations 56 # Set list of observations
57 - obs_def_list = obsutils.set_obs_patterns(pattern, \  
58 - ra=ra, \  
59 - dec=dec, \ 57 + obs_def_list = obsutils.set_obs_patterns(pattern,
  58 + ra=ra,
  59 + dec=dec,
60 offset=offset) 60 offset=offset)
61 61
62 # Get observation container 62 # Get observation container
63 - obs = obsutils.set_obs_list(obs_def_list, \  
64 - duration=duration, \  
65 - emin=emin, \  
66 - emax=emax, \  
67 - rad=rad, \  
68 - caldb=caldb, \ 63 + obs = obsutils.set_obs_list(obs_def_list,
  64 + duration=duration,
  65 + emin=emin,
  66 + emax=emax,
  67 + rad=rad,
  68 + caldb=caldb,
69 irf=irf) 69 irf=irf)
70 70
71 # Return observation container 71 # Return observation container
@@ -92,9 +92,9 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;): @@ -92,9 +92,9 @@ def setup_model(obs, model=&quot;${CTOOLS}/share/models/crab.xml&quot;):
92 # ================================ # 92 # ================================ #
93 # Simulation and analysis pipeline # 93 # Simulation and analysis pipeline #
94 # ================================ # 94 # ================================ #
95 -def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, \  
96 - emin=0.1, emax=100.0, \  
97 - tmin=0.0, tmax=0.0, \ 95 +def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0,
  96 + emin=0.1, emax=100.0,
  97 + tmin=0.0, tmax=0.0,
98 debug=False): 98 debug=False):
99 """ 99 """
100 Simulation and unbinned analysis pipeline. 100 Simulation and unbinned analysis pipeline.
examples/show_pha.py
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 # ========================================================================== 24 # ==========================================================================
25 import sys 25 import sys
26 import math 26 import math
27 -from gammalib import * 27 +import gammalib
28 28
29 29
30 # ================= # 30 # ================= #
@@ -93,7 +93,7 @@ if __name__ == &#39;__main__&#39;: @@ -93,7 +93,7 @@ if __name__ == &#39;__main__&#39;:
93 filename = sys.argv[1] 93 filename = sys.argv[1]
94 94
95 # Load PHA spectrum 95 # Load PHA spectrum
96 - pha = GPha(filename) 96 + pha = gammalib.GPha(filename)
97 #print(pha) 97 #print(pha)
98 98
99 # Try importing matplotlib 99 # Try importing matplotlib
examples/show_response.py
@@ -265,18 +265,18 @@ if __name__ == &#39;__main__&#39;: @@ -265,18 +265,18 @@ if __name__ == &#39;__main__&#39;:
265 265
266 # Set response dictionary 266 # Set response dictionary
267 rsps = [ 267 rsps = [
268 - {'dbname': "dummy", \  
269 - 'rspname': "cta_dummy_irf", \  
270 - 'name': "Prod1 (Array E, MPIK)", \  
271 - 'color': "b"}, \  
272 - {'dbname': "e", \  
273 - 'rspname': "IFAE20120510_50h", \  
274 - 'name': "Prod1 (Array E, IFAE)", \  
275 - 'color': "g"}, \  
276 - {'dbname': "aar", \  
277 - 'rspname': "DESY20140105_50h", \  
278 - 'name': "Prod2 (Aar, DESY)", \  
279 - 'color': "r"} \ 268 + {'dbname': "dummy",
  269 + 'rspname': "cta_dummy_irf",
  270 + 'name': "Prod1 (Array E, MPIK)",
  271 + 'color': "b"},
  272 + {'dbname': "e",
  273 + 'rspname': "IFAE20120510_50h",
  274 + 'name': "Prod1 (Array E, IFAE)",
  275 + 'color': "g"},
  276 + {'dbname': "aar",
  277 + 'rspname': "DESY20140105_50h",
  278 + 'name': "Prod2 (Aar, DESY)",
  279 + 'color': "r"}
280 ] 280 ]
281 281
282 # Loop over all responses 282 # Loop over all responses
@@ -297,4 +297,3 @@ if __name__ == &#39;__main__&#39;: @@ -297,4 +297,3 @@ if __name__ == &#39;__main__&#39;:
297 297
298 # Show plot 298 # Show plot
299 plt.show() 299 plt.show()
300 -  
301 \ No newline at end of file 300 \ No newline at end of file
examples/show_ts_distribution.py
@@ -178,8 +178,8 @@ def dist_pdf(values, nbins, title): @@ -178,8 +178,8 @@ def dist_pdf(values, nbins, title):
178 nbins += 1 178 nbins += 1
179 179
180 # Create histogram 180 # Create histogram
181 - n, bins, patches = plt.hist(values, nbins, range=[min_value, max_value], \  
182 - align='mid', facecolor='green', \ 181 + n, bins, patches = plt.hist(values, nbins, range=[min_value, max_value],
  182 + align='mid', facecolor='green',
183 log=True, label="simulations") 183 log=True, label="simulations")
184 184
185 # Create expected distribution (onyl for positive TS). We compute the 185 # Create expected distribution (onyl for positive TS). We compute the
@@ -239,9 +239,9 @@ if __name__ == &#39;__main__&#39;: @@ -239,9 +239,9 @@ if __name__ == &#39;__main__&#39;:
239 plot = "pdf" 239 plot = "pdf"
240 240
241 # Parameter dictionnary 241 # Parameter dictionnary
242 - pars = [{'option': '-n', 'value': nbins}, \  
243 - {'option': '-c', 'value': tsname}, \  
244 - {'option': '-t', 'value': title}, \ 242 + pars = [{'option': '-n', 'value': nbins},
  243 + {'option': '-c', 'value': tsname},
  244 + {'option': '-t', 'value': title},
245 {'option': '-p', 'value': plot}] 245 {'option': '-p', 'value': plot}]
246 246
247 # Gather parameters from command line 247 # Gather parameters from command line
@@ -280,5 +280,3 @@ if __name__ == &#39;__main__&#39;: @@ -280,5 +280,3 @@ if __name__ == &#39;__main__&#39;:
280 dist_pdf(values, nbins, title) 280 dist_pdf(values, nbins, title)
281 else: 281 else:
282 dist_cdf(values, nbins, title) 282 dist_cdf(values, nbins, title)
283 -  
284 -  
285 \ No newline at end of file 283 \ No newline at end of file
examples/simulate_events.py
@@ -36,8 +36,8 @@ except: @@ -36,8 +36,8 @@ except:
36 # ======================== # 36 # ======================== #
37 # Create CTA observation # 37 # Create CTA observation #
38 # ======================== # 38 # ======================== #
39 -def createobs(ra=86.171648, dec=-1.4774586, rad=5.0, \  
40 - emin=0.1, emax=100.0, duration=360000.0, deadc=0.95, \ 39 +def createobs(ra=86.171648, dec=-1.4774586, rad=5.0,
  40 + emin=0.1, emax=100.0, duration=360000.0, deadc=0.95,
41 irf="South_50h", caldb="prod2"): 41 irf="South_50h", caldb="prod2"):
42 """ 42 """
43 Create CTA observation. 43 Create CTA observation.