Commit 2897316901a3fd78e66d552edfabb8c83c22a46b

Authored by Jürgen Knödlseder
1 parent 3b94d0ca

Adapt to GammaLib 1.0.0

examples/make_binned_analysis.py
@@ -73,8 +73,8 @@ def pipeline_v1(): @@ -73,8 +73,8 @@ def pipeline_v1():
73 # Simulate events 73 # Simulate events
74 sim = ctools.ctobssim() 74 sim = ctools.ctobssim()
75 sim.logFileOpen() # We need this to explicitely open the log file in Python mode 75 sim.logFileOpen() # We need this to explicitely open the log file in Python mode
76 - sim["infile"].filename(model_name)  
77 - sim["outfile"].filename(events_name) 76 + sim["inmodel"].filename(model_name)
  77 + sim["outevents"].filename(events_name)
78 sim["caldb"].string(caldb) 78 sim["caldb"].string(caldb)
79 sim["irf"].string(irf) 79 sim["irf"].string(irf)
80 sim["ra"].real(ra) 80 sim["ra"].real(ra)
@@ -94,8 +94,8 @@ def pipeline_v1(): @@ -94,8 +94,8 @@ def pipeline_v1():
94 # Bin events into counts map 94 # Bin events into counts map
95 bin = ctools.ctbin() 95 bin = ctools.ctbin()
96 bin.logFileOpen() # We need this to explicitely open the log file in Python mode 96 bin.logFileOpen() # We need this to explicitely open the log file in Python mode
97 - bin["evfile"].filename(events_name)  
98 - bin["outfile"].filename(cntmap_name) 97 + bin["inobs"].filename(events_name)
  98 + bin["outcube"].filename(cntmap_name)
99 bin["ebinalg"].string("LOG") 99 bin["ebinalg"].string("LOG")
100 bin["emin"].real(emin) 100 bin["emin"].real(emin)
101 bin["emax"].real(emax) 101 bin["emax"].real(emax)
@@ -117,9 +117,9 @@ def pipeline_v1(): @@ -117,9 +117,9 @@ def pipeline_v1():
117 # Perform maximum likelihood fitting 117 # Perform maximum likelihood fitting
118 like = ctools.ctlike() 118 like = ctools.ctlike()
119 like.logFileOpen() # We need this to explicitely open the log file in Python mode 119 like.logFileOpen() # We need this to explicitely open the log file in Python mode
120 - like["infile"].filename(cntmap_name)  
121 - like["srcmdl"].filename(model_name)  
122 - like["outmdl"].filename(result_name) 120 + like["inobs"].filename(cntmap_name)
  121 + like["inmodel"].filename(model_name)
  122 + like["outmodel"].filename(result_name)
123 like["caldb"].string(caldb) 123 like["caldb"].string(caldb)
124 like["irf"].string(irf) 124 like["irf"].string(irf)
125 like.execute() 125 like.execute()
@@ -174,7 +174,7 @@ def pipeline_v2(): @@ -174,7 +174,7 @@ def pipeline_v2():
174 174
175 # Simulate events 175 # Simulate events
176 sim = ctools.ctobssim() 176 sim = ctools.ctobssim()
177 - sim["infile"].filename(model_name) 177 + sim["inmodel"].filename(model_name)
178 sim["caldb"].string(caldb) 178 sim["caldb"].string(caldb)
179 sim["irf"].string(irf) 179 sim["irf"].string(irf)
180 sim["ra"].real(ra) 180 sim["ra"].real(ra)
examples/make_cube_analysis.py
@@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
20 # ========================================================================== 20 # ==========================================================================
21 import ctools 21 import ctools
22 import gammalib 22 import gammalib
  23 +from ctools import obsutils
23 24
24 25
25 # ================= # 26 # ================= #
@@ -39,10 +40,10 @@ def pipeline(caldb = "dummy", \ @@ -39,10 +40,10 @@ def pipeline(caldb = "dummy", \
39 model - Source model 40 model - Source model
40 """ 41 """
41 # Set pointing pattern (4 pointings) 42 # Set pointing pattern (4 pointings)
42 - pointings = ctools.obsutils.set_obs_patterns("four", offset=2.0) 43 + pointings = obsutils.set_obs_patterns("four", offset=2.0)
43 44
44 # Set CTA observations (default: 1800 sec per pointing) 45 # Set CTA observations (default: 1800 sec per pointing)
45 - obs = ctools.obsutils.set_obs_list(pointings, caldb=caldb, irf=irf) 46 + obs = obsutils.set_obs_list(pointings, caldb=caldb, irf=irf)
46 47
47 # Load models 48 # Load models
48 models = gammalib.GModels(model) 49 models = gammalib.GModels(model)
@@ -56,7 +57,7 @@ def pipeline(caldb = "dummy", \ @@ -56,7 +57,7 @@ def pipeline(caldb = "dummy", \
56 # Run ctbin (builds stacked event cube) 57 # Run ctbin (builds stacked event cube)
57 bin = ctools.ctbin(sim.obs()) 58 bin = ctools.ctbin(sim.obs())
58 bin.logFileOpen() 59 bin.logFileOpen()
59 - bin["outfile"].filename("cntmap.fits") 60 + bin["outcube"].filename("cntmap.fits")
60 bin["ebinalg"].string("LOG") 61 bin["ebinalg"].string("LOG")
61 bin["emin"].real(0.1) 62 bin["emin"].real(0.1)
62 bin["emax"].real(100.0) 63 bin["emax"].real(100.0)
@@ -74,8 +75,8 @@ def pipeline(caldb = "dummy", \ @@ -74,8 +75,8 @@ def pipeline(caldb = "dummy", \
74 # Run ctexpcube (builds exposure cube) 75 # Run ctexpcube (builds exposure cube)
75 expcube = ctools.ctexpcube(sim.obs()) 76 expcube = ctools.ctexpcube(sim.obs())
76 expcube.logFileOpen() 77 expcube.logFileOpen()
77 - expcube["cntmap"].filename("cntmap.fits")  
78 - expcube["outfile"].filename("expcube.fits") 78 + expcube["incube"].filename("cntmap.fits")
  79 + expcube["outcube"].filename("expcube.fits")
79 expcube["caldb"].string(caldb) 80 expcube["caldb"].string(caldb)
80 expcube["irf"].string(irf) 81 expcube["irf"].string(irf)
81 expcube.execute() 82 expcube.execute()
@@ -83,8 +84,8 @@ def pipeline(caldb = "dummy", \ @@ -83,8 +84,8 @@ def pipeline(caldb = "dummy", \
83 # Run ctpsfcube (builds PSF cube) 84 # Run ctpsfcube (builds PSF cube)
84 psfcube = ctools.ctpsfcube(sim.obs()) 85 psfcube = ctools.ctpsfcube(sim.obs())
85 psfcube.logFileOpen() 86 psfcube.logFileOpen()
86 - psfcube["cntmap"].filename("NONE")  
87 - psfcube["outfile"].filename("psfcube.fits") 87 + psfcube["incube"].filename("NONE")
  88 + psfcube["outcube"].filename("psfcube.fits")
88 psfcube["caldb"].string(caldb) 89 psfcube["caldb"].string(caldb)
89 psfcube["irf"].string(irf) 90 psfcube["irf"].string(irf)
90 psfcube["ebinalg"].string("LOG") 91 psfcube["ebinalg"].string("LOG")
@@ -105,33 +106,23 @@ def pipeline(caldb = "dummy", \ @@ -105,33 +106,23 @@ def pipeline(caldb = "dummy", \
105 # Run ctbkgcube (builds background cube) 106 # Run ctbkgcube (builds background cube)
106 bkgcube = ctools.ctbkgcube(sim.obs()) 107 bkgcube = ctools.ctbkgcube(sim.obs())
107 bkgcube.logFileOpen() 108 bkgcube.logFileOpen()
108 - bkgcube["cntmap"].filename("cntmap.fits")  
109 - bkgcube["bkgmdl"].filename(model)  
110 - bkgcube["outfile"].filename("bkgcube.fits") 109 + bkgcube["incube"].filename("cntmap.fits")
  110 + bkgcube["inmodel"].filename(model)
  111 + bkgcube["outcube"].filename("bkgcube.fits")
  112 + bkgcube["outmodel"].filename("bkgcube.xml")
111 bkgcube.execute() 113 bkgcube.execute()
112 114
113 # Create observation container for stacked cube analysis 115 # Create observation container for stacked cube analysis
114 obs.clear() 116 obs.clear()
115 cta = gammalib.GCTAObservation("cntmap.fits", "expcube.fits", "psfcube.fits") 117 cta = gammalib.GCTAObservation("cntmap.fits", "expcube.fits", "psfcube.fits")
116 obs.append(cta) 118 obs.append(cta)
117 -  
118 - # Create model for stacked cube analysis  
119 - models = gammalib.GModels(model)  
120 - models.remove("Background")  
121 - spatial = gammalib.GModelSpatialDiffuseCube("bkgcube.fits")  
122 - spectral = gammalib.GModelSpectralConst()  
123 - background = gammalib.GCTAModelCubeBackground(spatial, spectral)  
124 - models.append(background)  
125 - models.save("cube_model.xml")  
126 -  
127 - # Append model to observation container  
128 - obs.models(models) 119 + obs.models(gammalib.GModels("bkgcube.xml"))
129 120
130 # Run ctlike 121 # Run ctlike
131 like = ctools.ctlike(obs) 122 like = ctools.ctlike(obs)
132 like.logFileOpen() 123 like.logFileOpen()
133 like["debug"].boolean(True) 124 like["debug"].boolean(True)
134 - like["outmdl"].filename("cube_results.xml") 125 + like["outmodel"].filename("cube_results.xml")
135 like.execute() 126 like.execute()
136 127
137 # Return 128 # Return
examples/make_spectrum.py
@@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
20 # ========================================================================== 20 # ==========================================================================
21 import gammalib 21 import gammalib
22 import ctools 22 import ctools
  23 +from ctools import obsutils
23 try: 24 try:
24 import matplotlib.pyplot as plt 25 import matplotlib.pyplot as plt
25 has_matplotlib = True 26 has_matplotlib = True
@@ -47,7 +48,7 @@ def make_spectrum(): @@ -47,7 +48,7 @@ def make_spectrum():
47 48
48 # Simulate events 49 # Simulate events
49 sim = ctools.ctobssim() 50 sim = ctools.ctobssim()
50 - sim["infile"].filename(model_name) 51 + sim["inmodel"].filename(model_name)
51 sim["caldb"].string(caldb) 52 sim["caldb"].string(caldb)
52 sim["irf"].string(irf) 53 sim["irf"].string(irf)
53 sim["ra"].real(ra) 54 sim["ra"].real(ra)
@@ -65,7 +66,7 @@ def make_spectrum(): @@ -65,7 +66,7 @@ def make_spectrum():
65 ebounds = gammalib.GEbounds(10, e_min, e_max) 66 ebounds = gammalib.GEbounds(10, e_min, e_max)
66 67
67 # Generate spectral points 68 # Generate spectral points
68 - spectrum = ctools.obsutils.spectrum(sim.obs(), "Crab", ebounds) 69 + spectrum = obsutils.spectrum(sim.obs(), "Crab", ebounds)
69 70
70 # Return spectrum 71 # Return spectrum
71 return spectrum 72 return spectrum
examples/make_ts_distributions.py
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 # Required 3rd party modules: 12 # Required 3rd party modules:
13 # - processing (optional) 13 # - processing (optional)
14 # 14 #
15 -# Copyright (C) 2011 Jurgen Knodlseder 15 +# Copyright (C) 2011-2015 Jurgen Knodlseder
16 # 16 #
17 # This program is free software: you can redistribute it and/or modify 17 # This program is free software: you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by 18 # it under the terms of the GNU General Public License as published by
@@ -28,8 +28,6 @@ @@ -28,8 +28,6 @@
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 import *  
32 -from gammalib import *  
33 from cstsdist import * 31 from cstsdist import *
34 import sys 32 import sys
35 import time 33 import time
examples/make_unbinned_analysis.py
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 # Required 3rd party modules: 7 # Required 3rd party modules:
8 # None 8 # None
9 # 9 #
10 -# Copyright (C) 2011-2014 Jurgen Knodlseder 10 +# Copyright (C) 2011-2015 Jurgen Knodlseder
11 # 11 #
12 # This program is free software: you can redistribute it and/or modify 12 # This program is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by 13 # it under the terms of the GNU General Public License as published by
@@ -23,9 +23,6 @@ @@ -23,9 +23,6 @@
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 -#from ctools import *  
27 -#from gammalib import *  
28 -#from math import *  
29 import gammalib 26 import gammalib
30 import ctools 27 import ctools
31 import math 28 import math
@@ -74,8 +71,8 @@ def pipeline_v1(): @@ -74,8 +71,8 @@ def pipeline_v1():
74 # Simulate events 71 # Simulate events
75 sim = ctools.ctobssim() 72 sim = ctools.ctobssim()
76 sim.logFileOpen() 73 sim.logFileOpen()
77 - sim["infile"].filename(model_name)  
78 - sim["outfile"].filename(events_name) 74 + sim["inmodel"].filename(model_name)
  75 + sim["outevents"].filename(events_name)
79 sim["caldb"].string(caldb) 76 sim["caldb"].string(caldb)
80 sim["irf"].string(irf) 77 sim["irf"].string(irf)
81 sim["ra"].real(ra) 78 sim["ra"].real(ra)
@@ -95,8 +92,8 @@ def pipeline_v1(): @@ -95,8 +92,8 @@ def pipeline_v1():
95 # Select events 92 # Select events
96 select = ctools.ctselect() 93 select = ctools.ctselect()
97 select.logFileOpen() 94 select.logFileOpen()
98 - select["infile"].filename(events_name)  
99 - select["outfile"].filename(selected_events_name) 95 + select["inobs"].filename(events_name)
  96 + select["outobs"].filename(selected_events_name)
100 select["ra"].real(ra) 97 select["ra"].real(ra)
101 select["dec"].real(dec) 98 select["dec"].real(dec)
102 select["rad"].real(rad_select) 99 select["rad"].real(rad_select)
@@ -114,9 +111,9 @@ def pipeline_v1(): @@ -114,9 +111,9 @@ def pipeline_v1():
114 # Perform maximum likelihood fitting 111 # Perform maximum likelihood fitting
115 like = ctools.ctlike() 112 like = ctools.ctlike()
116 like.logFileOpen() 113 like.logFileOpen()
117 - like["infile"].filename(selected_events_name)  
118 - like["srcmdl"].filename(model_name)  
119 - like["outmdl"].filename(result_name) 114 + like["inobs"].filename(selected_events_name)
  115 + like["inmodel"].filename(model_name)
  116 + like["outmodel"].filename(result_name)
120 like["caldb"].string(caldb) 117 like["caldb"].string(caldb)
121 like["irf"].string(irf) 118 like["irf"].string(irf)
122 like.execute() 119 like.execute()
@@ -164,7 +161,7 @@ def pipeline_v2(show_data): @@ -164,7 +161,7 @@ def pipeline_v2(show_data):
164 161
165 # Simulate events 162 # Simulate events
166 sim = ctools.ctobssim() 163 sim = ctools.ctobssim()
167 - sim["infile"].filename(model_name) 164 + sim["inmodel"].filename(model_name)
168 sim["caldb"].string(caldb) 165 sim["caldb"].string(caldb)
169 sim["irf"].string(irf) 166 sim["irf"].string(irf)
170 sim["ra"].real(ra) 167 sim["ra"].real(ra)
@@ -210,9 +207,6 @@ def pipeline_v2(show_data): @@ -210,9 +207,6 @@ def pipeline_v2(show_data):
210 print("Total wall time elapsed: "+str(wall_seconds)+" seconds") 207 print("Total wall time elapsed: "+str(wall_seconds)+" seconds")
211 print("Total CPU time used ...: "+str(cpu_seconds)+" seconds") 208 print("Total CPU time used ...: "+str(cpu_seconds)+" seconds")
212 209
213 - # Show model fitting results  
214 - #print like.obs().models()  
215 -  
216 # Optionally plot counts 210 # Optionally plot counts
217 if show_data: 211 if show_data:
218 if has_matplotlib: 212 if has_matplotlib:
examples/model_bgd.xml deleted
1 -<?xml version="1.0" standalone="no"?>  
2 -<source_library title="source library">  
3 - <source name="Background" type="RadialAcceptance" instrument="CTA">  
4 - <spectrum type="FileFunction" file="$CTOOLS/share/models/bkg_dummy.txt">  
5 - <parameter scale="1.0" name="Normalization" min="0.0" max="1000.0" value="1.0" free="1"/>  
6 - </spectrum>  
7 - <radialModel type="Gaussian">  
8 - <parameter name="Sigma" scale="1.0" value="3.0" min="0.01" max="10.0" free="1"/>  
9 - </radialModel>  
10 - </source>  
11 -</source_library>  
12 -