Commit b63054941a6bbd0422726cd1bb73399507b8dff3

Authored by Jürgen Knödlseder
1 parent 68f0f1c9

Use "import" instead of "from XXX import *"

scripts/cspull.py
... ... @@ -19,12 +19,9 @@
19 19 #
20 20 # ==========================================================================
21 21 import gammalib
22   -#import ctools
23   -#import obsutils
24 22 from ctools import obsutils
25 23 import sys
26 24 import csv
27   -#import math
28 25  
29 26  
30 27 # ============ #
... ...
scripts/cssens.py
... ... @@ -17,7 +17,7 @@
17 17 #
18 18 # The source is modelled as a point source
19 19 #
20   -# Copyright (C) 2011-2014 Juergen Knoedlseder
  20 +# Copyright (C) 2011-2015 Juergen Knoedlseder
21 21 #
22 22 # This program is free software: you can redistribute it and/or modify
23 23 # it under the terms of the GNU General Public License as published by
... ... @@ -33,8 +33,8 @@
33 33 # along with this program. If not, see <http://www.gnu.org/licenses/>.
34 34 #
35 35 # ==========================================================================
36   -from ctools import *
37   -from gammalib import *
  36 +import gammalib
  37 +from ctools import obsutils
38 38 import sys
39 39 import csv
40 40 import math
... ... @@ -43,7 +43,7 @@ import math
43 43 # ============ #
44 44 # cssens class #
45 45 # ============ #
46   -class cssens(GApplication):
  46 +class cssens(gammalib.GApplication):
47 47 """
48 48 This class implements the sensitivity computation script. It derives
49 49 from the GammaLib::GApplication class which provides support for parameter
... ... @@ -63,9 +63,9 @@ class cssens(GApplication):
63 63  
64 64 # Initialise application
65 65 if len(argv) == 0:
66   - GApplication.__init__(self, self.name, self.version)
  66 + gammalib.GApplication.__init__(self, self.name, self.version)
67 67 elif len(argv) ==1:
68   - GApplication.__init__(self, self.name, self.version, *argv)
  68 + gammalib.GApplication.__init__(self, self.name, self.version, *argv)
69 69 else:
70 70 raise TypeError("Invalid number of arguments given.")
71 71  
... ... @@ -97,31 +97,31 @@ class cssens(GApplication):
97 97 parfile = self.name+".par"
98 98  
99 99 try:
100   - pars = GApplicationPars(parfile)
  100 + pars = gammalib.GApplicationPars(parfile)
101 101 except:
102 102 # Signal if parfile was not found
103 103 sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n")
104 104  
105 105 # Create default parfile
106   - pars = GApplicationPars()
107   - pars.append(GApplicationPar("outfile","f","h","sensitivity.dat","","","Output file name"))
108   - pars.append(GApplicationPar("caldb","s","a","$CTOOLS/share/caldb/data/cta/dummy","","","Calibration database"))
109   - pars.append(GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function"))
110   - pars.append(GApplicationPar("type","s","a","point","","","Source model type (point/gauss/shell/disk)"))
111   - pars.append(GApplicationPar("offset","r","a","0.0","0.0","","Source offset angle (deg)"))
112   - pars.append(GApplicationPar("bkg","s","a","$CTOOLS/share/models/bkg_dummy.txt","","","Background model file function (none=power law for E)"))
113   - pars.append(GApplicationPar("duration","r","a","180000.0","","","Effective exposure time (s)"))
114   - pars.append(GApplicationPar("rad","r","a","5.0","","","Radius of ROI (deg)"))
115   - pars.append(GApplicationPar("enumbins","i","h","0","","","Number of energy bins (0=unbinned)"))
116   - pars.append(GApplicationPar("npix","i","h","200","","","Number of pixels for binned"))
117   - pars.append(GApplicationPar("binsz","r","h","0.05","","","Pixel size for binned (deg/pixel)"))
118   - pars.append(GApplicationPar("sigma","r","h","5.0","","","Significance threshold"))
119   - pars.append(GApplicationPar("ts_use","b","h","yes","","","Use TS?"))
120   - pars.append(GApplicationPar("index","r","h","-2.48","","","Assumed spectral index"))
121   - pars.append(GApplicationPar("radius","r","h","0.1","","","Extended source model radius"))
122   - pars.append(GApplicationPar("width","r","h","0.05","","","Extended source model width"))
123   - pars.append(GApplicationPar("max_iter","i","h","50","","","Maximum number of iterations"))
124   - pars.append(GApplicationPar("num_avg","i","h","3","","","Number of iterations for sliding average"))
  106 + pars = gammalib.GApplicationPars()
  107 + pars.append(gammalib.GApplicationPar("outfile","f","h","sensitivity.dat","","","Output file name"))
  108 + pars.append(gammalib.GApplicationPar("caldb","s","a","$CTOOLS/share/caldb/data/cta/dummy","","","Calibration database"))
  109 + pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function"))
  110 + pars.append(gammalib.GApplicationPar("type","s","a","point","","","Source model type (point/gauss/shell/disk)"))
  111 + pars.append(gammalib.GApplicationPar("offset","r","a","0.0","0.0","","Source offset angle (deg)"))
  112 + pars.append(gammalib.GApplicationPar("bkg","s","a","$CTOOLS/share/models/bkg_dummy.txt","","","Background model file function (none=power law for E)"))
  113 + pars.append(gammalib.GApplicationPar("duration","r","a","180000.0","","","Effective exposure time (s)"))
  114 + pars.append(gammalib.GApplicationPar("rad","r","a","5.0","","","Radius of ROI (deg)"))
  115 + pars.append(gammalib.GApplicationPar("enumbins","i","h","0","","","Number of energy bins (0=unbinned)"))
  116 + pars.append(gammalib.GApplicationPar("npix","i","h","200","","","Number of pixels for binned"))
  117 + pars.append(gammalib.GApplicationPar("binsz","r","h","0.05","","","Pixel size for binned (deg/pixel)"))
  118 + pars.append(gammalib.GApplicationPar("sigma","r","h","5.0","","","Significance threshold"))
  119 + pars.append(gammalib.GApplicationPar("ts_use","b","h","yes","","","Use TS?"))
  120 + pars.append(gammalib.GApplicationPar("index","r","h","-2.48","","","Assumed spectral index"))
  121 + pars.append(gammalib.GApplicationPar("radius","r","h","0.1","","","Extended source model radius"))
  122 + pars.append(gammalib.GApplicationPar("width","r","h","0.05","","","Extended source model width"))
  123 + pars.append(gammalib.GApplicationPar("max_iter","i","h","50","","","Maximum number of iterations"))
  124 + pars.append(gammalib.GApplicationPar("num_avg","i","h","3","","","Number of iterations for sliding average"))
125 125 pars.append_standard()
126 126 pars.save(parfile)
127 127  
... ... @@ -192,8 +192,8 @@ class cssens(GApplication):
192 192 # Initialise models. Note that we centre the point source at the Galactic
193 193 # center as our observation is also centred at the Galactic centre, so
194 194 # we're onaxis.
195   - bkg_model = GModels()
196   - full_model = GModels()
  195 + bkg_model = gammalib.GModels()
  196 + full_model = gammalib.GModels()
197 197 bkg_model.append(self.set_bkg_model())
198 198 full_model.append(self.set_bkg_model())
199 199 full_model.append(self.set_src_model(0.0, \
... ... @@ -263,10 +263,10 @@ class cssens(GApplication):
263 263 emax - Maximum energy [TeV] (default: 100.0)
264 264 """
265 265 # Allocate observation container
266   - obs = GObservations()
  266 + obs = gammalib.GObservations()
267 267  
268 268 # Set single pointing
269   - pntdir = GSkyDir()
  269 + pntdir = gammalib.GSkyDir()
270 270 pntdir.lb_deg(lpnt, bpnt)
271 271  
272 272 # Create CTA observation
... ... @@ -289,21 +289,21 @@ class cssens(GApplication):
289 289 fitidx - Fit spectral index (default: False)
290 290 """
291 291 # Define radial component
292   - radial = GCTAModelRadialGauss(3.0)
  292 + radial = gammalib.GCTAModelRadialGauss(3.0)
293 293  
294 294 # Define spectral component. If a background model is given then
295 295 # use a file function. Otherwise use a static power law.
296 296 if len(self.m_bkg) > 0:
297   - spectrum = GModelSpectralFunc(self.m_bkg, 1.0)
  297 + spectrum = gammalib.GModelSpectralFunc(self.m_bkg, 1.0)
298 298 else:
299   - spectrum = GModelSpectralPlaw(61.8e-6, -1.85, GEnergy(1.0, "TeV"))
  299 + spectrum = gammalib.GModelSpectralPlaw(61.8e-6, -1.85, gammalib.GEnergy(1.0, "TeV"))
300 300 if fitidx:
301 301 spectrum["Index"].free()
302 302 else:
303 303 spectrum["Index"].fix()
304 304  
305 305 # Create background model
306   - model = GCTAModelRadialAcceptance(radial, spectrum)
  306 + model = gammalib.GCTAModelRadialAcceptance(radial, spectrum)
307 307 model.name("Background")
308 308 model.instruments("CTA")
309 309  
... ... @@ -328,11 +328,11 @@ class cssens(GApplication):
328 328 fitidx - Fit index? (default: False)
329 329 """
330 330 # Set source location
331   - location = GSkyDir()
  331 + location = gammalib.GSkyDir()
332 332 location.lb_deg(l, b)
333 333  
334 334 # Set source spectrum
335   - spectrum = GModelSpectralPlaw(flux*5.7e-16, index, GEnergy(0.3, "TeV"))
  335 + spectrum = gammalib.GModelSpectralPlaw(flux*5.7e-16, index, gammalib.GEnergy(0.3, "TeV"))
336 336 if fitidx:
337 337 spectrum["Index"].free()
338 338 else:
... ... @@ -340,7 +340,7 @@ class cssens(GApplication):
340 340  
341 341 # Set source
342 342 if type == "point":
343   - spatial = GModelSpatialPointSource(location)
  343 + spatial = gammalib.GModelSpatialPointSource(location)
344 344 if fitpos:
345 345 spatial["RA"].free()
346 346 spatial["DEC"].free()
... ... @@ -348,7 +348,7 @@ class cssens(GApplication):
348 348 spatial["RA"].fix()
349 349 spatial["DEC"].fix()
350 350 elif type == "gauss":
351   - spatial = GModelSpatialRadialGauss(location, self.m_radius)
  351 + spatial = gammalib.GModelSpatialRadialGauss(location, self.m_radius)
352 352 if fitpos:
353 353 spatial["RA"].free()
354 354 spatial["DEC"].free()
... ... @@ -358,7 +358,7 @@ class cssens(GApplication):
358 358 spatial["DEC"].fix()
359 359 spatial["Sigma"].fix()
360 360 elif type == "disk":
361   - spatial = GModelSpatialRadialDisk(location, self.m_radius)
  361 + spatial = gammalib.GModelSpatialRadialDisk(location, self.m_radius)
362 362 if fitpos:
363 363 spatial["RA"].free()
364 364 spatial["DEC"].free()
... ... @@ -368,7 +368,7 @@ class cssens(GApplication):
368 368 spatial["DEC"].fix()
369 369 spatial["Radius"].fix()
370 370 elif type == "shell":
371   - spatial = GModelSpatialRadialShell(location, self.m_radius, self.m_width)
  371 + spatial = gammalib.GModelSpatialRadialShell(location, self.m_radius, self.m_width)
372 372 if fitpos:
373 373 spatial["RA"].free()
374 374 spatial["DEC"].free()
... ... @@ -382,7 +382,7 @@ class cssens(GApplication):
382 382 else:
383 383 self.log("ERROR: Unknown source type '"+type+"'.\n")
384 384 return None
385   - source = GModelSky(spatial, spectrum)
  385 + source = gammalib.GModelSky(spatial, spectrum)
386 386  
387 387 # Set source name
388 388 source.name("Test")
... ...
scripts/cstsdist.py
... ... @@ -19,8 +19,8 @@
19 19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20 #
21 21 # ==========================================================================
22   -from ctools import *
23   -from gammalib import *
  22 +import gammalib
  23 +from ctools import obsutils
24 24 import sys
25 25 import csv
26 26 import math
... ... @@ -29,7 +29,7 @@ import math
29 29 # ============== #
30 30 # cstsdist class #
31 31 # ============== #
32   -class cstsdist(GApplication):
  32 +class cstsdist(gammalib.GApplication):
33 33 """
34 34 This class implements the TS distribution generation script. It derives
35 35 from the GammaLib::GApplication class which provides support for parameter
... ... @@ -54,9 +54,9 @@ class cstsdist(GApplication):
54 54  
55 55 # Initialise application
56 56 if len(argv) == 0:
57   - GApplication.__init__(self, self.name, self.version)
  57 + gammalib.GApplication.__init__(self, self.name, self.version)
58 58 elif len(argv) ==1:
59   - GApplication.__init__(self, self.name, self.version, *argv)
  59 + gammalib.GApplication.__init__(self, self.name, self.version, *argv)
60 60 else:
61 61 raise TypeError("Invalid number of arguments given.")
62 62  
... ... @@ -87,28 +87,28 @@ class cstsdist(GApplication):
87 87 parfile = self.name+".par"
88 88  
89 89 try:
90   - pars = GApplicationPars(parfile)
  90 + pars = gammalib.GApplicationPars(parfile)
91 91 except:
92 92 # Signal if parfile was not found
93 93 sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n")
94 94  
95 95 # Create default parfile
96   - pars = GApplicationPars()
97   - pars.append(GApplicationPar("outfile","f","h","ts.dat","","","Output file name"))
98   - pars.append(GApplicationPar("ntrials","i","a","10","","","Number of trials"))
99   - pars.append(GApplicationPar("caldb","s","a","$GAMMALIB/share/caldb/cta","","","Calibration database"))
100   - pars.append(GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function"))
101   - pars.append(GApplicationPar("type","s","a","point","","","Source model type (point/gauss/shell/disk)"))
102   - pars.append(GApplicationPar("index","r","h","-2.48","","","Spectral index"))
103   - pars.append(GApplicationPar("offset","r","a","0.0","0.0","","Source offset angle (deg)"))
104   - pars.append(GApplicationPar("bkg","s","a","$GAMMALIB/share/models/bkg_dummy.txt","","","Background model file function (none=power law for E)"))
105   - pars.append(GApplicationPar("emin","r","a","0.1","0.0","","Lower energy limit (TeV)"))
106   - pars.append(GApplicationPar("emax","r","a","100.0","0.0","","Upper energy limit (TeV)"))
107   - pars.append(GApplicationPar("enumbins","i","a","0","","","Number of energy bins (0=unbinned)"))
108   - pars.append(GApplicationPar("duration","r","a","180000.0","","","Effective exposure time (s)"))
109   - pars.append(GApplicationPar("rad","r","h","5.0","","","Radius of ROI (deg)"))
110   - pars.append(GApplicationPar("npix","i","h","200","","","Number of pixels for binned"))
111   - pars.append(GApplicationPar("binsz","r","h","0.05","","","Pixel size for binned (deg/pixel)"))
  96 + pars = gammalib.GApplicationPars()
  97 + pars.append(gammalib.GApplicationPar("outfile","f","h","ts.dat","","","Output file name"))
  98 + pars.append(gammalib.GApplicationPar("ntrials","i","a","10","","","Number of trials"))
  99 + pars.append(gammalib.GApplicationPar("caldb","s","a","$GAMMALIB/share/caldb/cta","","","Calibration database"))
  100 + pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function"))
  101 + pars.append(gammalib.GApplicationPar("type","s","a","point","","","Source model type (point/gauss/shell/disk)"))
  102 + pars.append(gammalib.GApplicationPar("index","r","h","-2.48","","","Spectral index"))
  103 + pars.append(gammalib.GApplicationPar("offset","r","a","0.0","0.0","","Source offset angle (deg)"))
  104 + pars.append(gammalib.GApplicationPar("bkg","s","a","$GAMMALIB/share/models/bkg_dummy.txt","","","Background model file function (none=power law for E)"))
  105 + pars.append(gammalib.GApplicationPar("emin","r","a","0.1","0.0","","Lower energy limit (TeV)"))
  106 + pars.append(gammalib.GApplicationPar("emax","r","a","100.0","0.0","","Upper energy limit (TeV)"))
  107 + pars.append(gammalib.GApplicationPar("enumbins","i","a","0","","","Number of energy bins (0=unbinned)"))
  108 + pars.append(gammalib.GApplicationPar("duration","r","a","180000.0","","","Effective exposure time (s)"))
  109 + pars.append(gammalib.GApplicationPar("rad","r","h","5.0","","","Radius of ROI (deg)"))
  110 + pars.append(gammalib.GApplicationPar("npix","i","h","200","","","Number of pixels for binned"))
  111 + pars.append(gammalib.GApplicationPar("binsz","r","h","0.05","","","Pixel size for binned (deg/pixel)"))
112 112 pars.append_standard()
113 113 pars.save(parfile)
114 114  
... ... @@ -146,8 +146,8 @@ class cstsdist(GApplication):
146 146 # Initialise models. Note that we centre the point source at the Galactic
147 147 # center as our observation is also centred at the Galactic centre, so
148 148 # we're onaxis.
149   - self.bkg_model = GModels()
150   - self.full_model = GModels()
  149 + self.bkg_model = gammalib.GModels()
  150 + self.full_model = gammalib.GModels()
151 151 self.bkg_model.append(self.set_bkg_model())
152 152 self.full_model.append(self.set_bkg_model())
153 153 self.full_model.append(self.set_src_model(0.0, self.m_offset, \
... ... @@ -247,10 +247,10 @@ class cstsdist(GApplication):
247 247 emax - Maximum energy [TeV] (default: 100.0)
248 248 """
249 249 # Allocate observation container
250   - obs = GObservations()
  250 + obs = gammalib.GObservations()
251 251  
252 252 # Set single pointing
253   - pntdir = GSkyDir()
  253 + pntdir = gammalib.GSkyDir()
254 254 pntdir.lb_deg(lpnt, bpnt)
255 255  
256 256 # Create CTA observation
... ... @@ -269,17 +269,17 @@ class cstsdist(GApplication):
269 269 Setup CTA background model.
270 270 """
271 271 # Define radial component
272   - radial = GCTAModelRadialGauss(3.0)
  272 + radial = gammalib.GCTAModelRadialGauss(3.0)
273 273 if fitsigma:
274 274 radial["Sigma"].free()
275 275 else:
276 276 radial["Sigma"].fix()
277 277  
278 278 # Define spectral component
279   - spectrum = GModelSpectralFunc(self.m_bkg, 1.0)
  279 + spectrum = gammalib.GModelSpectralFunc(self.m_bkg, 1.0)
280 280  
281 281 # Create background model
282   - model = GCTAModelRadialAcceptance(radial, spectrum)
  282 + model = gammalib.GCTAModelRadialAcceptance(radial, spectrum)
283 283 model.name("Background")
284 284 model.instruments("CTA")
285 285  
... ... @@ -308,11 +308,11 @@ class cstsdist(GApplication):
308 308 fitidx - Fit index? (default: True)
309 309 """
310 310 # Set source location
311   - location = GSkyDir()
  311 + location = gammalib.GSkyDir()
312 312 location.lb_deg(l, b)
313 313  
314 314 # Set source spectrum
315   - spectrum = GModelSpectralPlaw(flux*5.7e-16, index, GEnergy(0.3, "TeV"))
  315 + spectrum = gammalib.GModelSpectralPlaw(flux*5.7e-16, index, gammalib.GEnergy(0.3, "TeV"))
316 316 if fitidx:
317 317 spectrum["Index"].free()
318 318 else:
... ... @@ -320,29 +320,29 @@ class cstsdist(GApplication):
320 320  
321 321 # Set source
322 322 if type == "point":
323   - spatial = GModelSpatialPointSource(location)
  323 + spatial = gammalib.GModelSpatialPointSource(location)
324 324 if fitpos:
325 325 spatial[0].free()
326 326 spatial[1].free()
327 327 elif type == "gauss":
328   - spatial = GModelSpatialRadialGauss(location, sigma)
  328 + spatial = gammalib.GModelSpatialRadialGauss(location, sigma)
329 329 if fitpos:
330 330 spatial[0].free()
331 331 spatial[1].free()
332 332 elif type == "disk":
333   - spatial = GModelSpatialRadialDisk(location, radius)
  333 + spatial = gammalib.GModelSpatialRadialDisk(location, radius)
334 334 if fitpos:
335 335 spatial[0].free()
336 336 spatial[1].free()
337 337 elif type == "shell":
338   - spatial = GModelSpatialRadialShell(location, radius, width)
  338 + spatial = gammalib.GModelSpatialRadialShell(location, radius, width)
339 339 if fitpos:
340 340 spatial[0].free()
341 341 spatial[1].free()
342 342 else:
343 343 self.log("ERROR: Unknown source type '"+type+"'.\n")
344 344 return None
345   - source = GModelSky(spatial, spectrum)
  345 + source = gammalib.GModelSky(spatial, spectrum)
346 346  
347 347 # Set source name
348 348 source.name("Test")
... ...