Commit 15aa103bfa521c266dff806390545499ee374024

Authored by Jürgen Knödlseder
1 parent 1e11230e

Simplify pipeline example scripts (#1828)

cscripts/ioutils.py
@@ -65,12 +65,12 @@ def write_csv_row(outfile, row, colnames, colvalues): @@ -65,12 +65,12 @@ def write_csv_row(outfile, row, colnames, colvalues):
65 return 65 return
66 66
67 67
68 -# ============================== #  
69 -# Get options from argument list #  
70 -# ============================== #  
71 -def get_arg_options(options, usage): 68 +# ============================================ #
  69 +# Get arguments and options from argument list #
  70 +# ============================================ #
  71 +def get_args_options(options, usage):
72 """ 72 """
73 - Get options from argument list 73 + Get arguments and options from argument list
74 74
75 Parameters 75 Parameters
76 ---------- 76 ----------
@@ -81,9 +81,12 @@ def get_arg_options(options, usage): @@ -81,9 +81,12 @@ def get_arg_options(options, usage):
81 81
82 Returns 82 Returns
83 ------- 83 -------
84 - options : list of dict  
85 - Update list of options 84 + args, options : tuple of list and list of dict
  85 + Arguments and updated list of options
86 """ 86 """
  87 + # Initialise list of arguments
  88 + args = []
  89 +
87 # If there are no command line arguments then show usage string and 90 # If there are no command line arguments then show usage string and
88 # exit 91 # exit
89 if len(sys.argv) < 1: 92 if len(sys.argv) < 1:
@@ -96,13 +99,18 @@ def get_arg_options(options, usage): @@ -96,13 +99,18 @@ def get_arg_options(options, usage):
96 # Loop over all arguments 99 # Loop over all arguments
97 while i < len(sys.argv): 100 while i < len(sys.argv):
98 101
  102 + # Initialise that no option was found
  103 + option_found = False
  104 +
99 # Search for options 105 # Search for options
100 for option in options: 106 for option in options:
  107 +
  108 + # Do we have an option
101 if sys.argv[i] == option['option']: 109 if sys.argv[i] == option['option']:
102 110
103 # If an option has been found then check if there is a 111 # If an option has been found then check if there is a
104 # following parameter and extract that parameter as a 112 # following parameter and extract that parameter as a
105 - # string 113 + # string. Quit in case that an exception occurs.
106 if len(sys.argv) > i+1: 114 if len(sys.argv) > i+1:
107 i += 1 115 i += 1
108 try: 116 try:
@@ -110,12 +118,23 @@ def get_arg_options(options, usage): @@ -110,12 +118,23 @@ def get_arg_options(options, usage):
110 except: 118 except:
111 print(usage) 119 print(usage)
112 sys.exit() 120 sys.exit()
  121 +
  122 + # ... there is no following parameter, hence write out usage
  123 + # and quite
113 else: 124 else:
114 print(usage) 125 print(usage)
115 sys.exit() 126 sys.exit()
116 127
  128 + # We can break now as every option should only occur once
  129 + option_found = True
  130 + break
  131 +
  132 + # If no option was found then add the argument to list of arguments
  133 + if not option_found:
  134 + args.append(sys.argv[i])
  135 +
117 # Next item 136 # Next item
118 i += 1 137 i += 1
119 138
120 - # Return options  
121 - return options 139 + # Return arguments and options
  140 + return args, options
examples/make_ts_distributions.py
@@ -89,17 +89,17 @@ if __name__ == &#39;__main__&#39;: @@ -89,17 +89,17 @@ if __name__ == &#39;__main__&#39;:
89 89
90 # Set usage string 90 # Set usage string
91 usage = 'make_ts_distributions.py [-n ntrials] [-e enumbins]'\ 91 usage = 'make_ts_distributions.py [-n ntrials] [-e enumbins]'\
92 - ' [-d duration] [-m max_threads] [-p datadir]' 92 + ' [-t duration] [-m max_threads] [-d datadir]'
93 93
94 # Set default options 94 # Set default options
95 options = [{'option': '-n', 'value': '100'}, 95 options = [{'option': '-n', 'value': '100'},
96 {'option': '-e', 'value': '0'}, 96 {'option': '-e', 'value': '0'},
97 - {'option': '-d', 'value': '180000.0'}, 97 + {'option': '-t', 'value': '180000.0'},
98 {'option': '-m', 'value': '1'}, 98 {'option': '-m', 'value': '1'},
99 - {'option': '-p', 'value': 'data'}] 99 + {'option': '-d', 'value': 'data'}]
100 100
101 - # Get options from command line arguments  
102 - options = cscripts.ioutils.get_arg_options(options, usage) 101 + # Get arguments and options from command line arguments
  102 + args, options = cscripts.ioutils.get_args_options(options, usage)
103 103
104 # Extract script parameters from options 104 # Extract script parameters from options
105 ntrials = int(options[0]['value']) 105 ntrials = int(options[0]['value'])
examples/pipeline_binned_disk.py
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 # ========================================================================== 2 # ==========================================================================
3 -# Perform binned analysis of simulated CTA data. 3 +# Perform binned analysis of simulated CTA data
4 # 4 #
5 # Copyright (C) 2015-2016 Juergen Knoedlseder 5 # Copyright (C) 2015-2016 Juergen Knoedlseder
6 # 6 #
@@ -18,94 +18,9 @@ @@ -18,94 +18,9 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # 19 #
20 # ========================================================================== 20 # ==========================================================================
21 -import sys  
22 import gammalib 21 import gammalib
23 import ctools 22 import ctools
24 -from cscripts import obsutils  
25 -  
26 -  
27 -# ================== #  
28 -# Setup observations #  
29 -# ================== #  
30 -def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5,  
31 - emin=0.1, emax=100.0, rad=5.0, duration=180.0,  
32 - deadc=0.95, caldb='prod2', irf='South_0.5h'):  
33 - """  
34 - Returns an observation container  
35 -  
36 - Parameters  
37 - ----------  
38 - pattern : str, optional  
39 - Pointing pattern, either 'single' or 'four'  
40 - ra : float, optional  
41 - Right Ascension of pattern centre (deg)  
42 - dec : float, optional  
43 - Declination of pattern centre (deg)  
44 - offset : float, optional  
45 - Offset between observations of pattern (deg)  
46 - emin : float, optional  
47 - Minimum energy (TeV)  
48 - emax : float, optional  
49 - Maximum energy (TeV)  
50 - rad : float, optional  
51 - ROI radius used for analysis (deg)  
52 - duration : float, optional  
53 - Duration of one CTA observation (s)  
54 - deadc : float, optional  
55 - Deadtime correction factor  
56 - caldb : str, optional  
57 - Calibration database path  
58 - irf : str, optional  
59 - Instrument response function  
60 -  
61 - Returns  
62 - -------  
63 - obs : `~gammalib.GObservations`  
64 - Observation container  
65 - """  
66 - # Set list of observations  
67 - obs_def_list = obsutils.set_obs_patterns(pattern,  
68 - ra=ra,  
69 - dec=dec,  
70 - offset=offset)  
71 -  
72 - # Get observation container  
73 - obs = obsutils.set_obs_list(obs_def_list,  
74 - duration=duration,  
75 - emin=emin,  
76 - emax=emax,  
77 - rad=rad,  
78 - caldb=caldb,  
79 - irf=irf)  
80 -  
81 - # Return observation container  
82 - return obs  
83 -  
84 -  
85 -# =========== #  
86 -# Setup model #  
87 -# =========== #  
88 -def setup_model(obs, model='data/crab.xml'):  
89 - """  
90 - Setup model for analysis  
91 -  
92 - Parameters  
93 - ----------  
94 - obs : `~gammalib.GObservations`  
95 - Observation container  
96 - model : str, optional  
97 - Model definition XML file  
98 -  
99 - Returns  
100 - -------  
101 - obs : `~gammalib.GObservations`  
102 - Observation container  
103 - """  
104 - # Append model from file to observation container  
105 - obs.models(gammalib.GModels(model))  
106 -  
107 - # Return observation container  
108 - return obs 23 +import cscripts
109 24
110 25
111 # ================================ # 26 # ================================ #
@@ -219,17 +134,25 @@ if __name__ == &#39;__main__&#39;: @@ -219,17 +134,25 @@ if __name__ == &#39;__main__&#39;:
219 print('* CTA binned analysis pipeline *') 134 print('* CTA binned analysis pipeline *')
220 print('********************************************') 135 print('********************************************')
221 136
222 - # Get optional arguments  
223 - if len(sys.argv) == 2:  
224 - datadir = sys.argv[1]  
225 - else:  
226 - datadir = 'data' 137 + # Set usage string
  138 + usage = 'pipeline_binned_disk.py [-d datadir]'
  139 +
  140 + # Set default options
  141 + options = [{'option': '-d', 'value': 'data'}]
  142 +
  143 + # Get arguments and options from command line arguments
  144 + args, options = cscripts.ioutils.get_args_options(options, usage)
  145 +
  146 + # Extract script parameters from options
  147 + datadir = options[0]['value']
227 148
228 # Setup observations 149 # Setup observations
229 - obs = setup_observations() 150 + obs = cscripts.obsutils.set_observations(83.63, 22.01, 5.0, 0.0, 180.0,
  151 + 0.1, 100.0, 'South_0.5h', 'prod2',
  152 + pattern='four', offset=1.5)
230 153
231 # Setup model 154 # Setup model
232 - obs = setup_model(obs, model=datadir+'/crab.xml') 155 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
233 156
234 # Run analysis pipeline 157 # Run analysis pipeline
235 run_pipeline(obs, model=datadir+'/crab.xml') 158 run_pipeline(obs, model=datadir+'/crab.xml')
examples/pipeline_binned_mem.py
@@ -18,94 +18,9 @@ @@ -18,94 +18,9 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # 19 #
20 # ========================================================================== 20 # ==========================================================================
21 -import sys  
22 import gammalib 21 import gammalib
23 import ctools 22 import ctools
24 -from cscripts import obsutils  
25 -  
26 -  
27 -# ================== #  
28 -# Setup observations #  
29 -# ================== #  
30 -def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5,  
31 - emin=0.1, emax=100.0, rad=5.0, duration=180.0,  
32 - deadc=0.95, caldb='prod2', irf='South_0.5h'):  
33 - """  
34 - Returns an observation container  
35 -  
36 - Parameters  
37 - ----------  
38 - pattern : str, optional  
39 - Pointing pattern, either 'single' or 'four'  
40 - ra : float, optional  
41 - Right Ascension of pattern centre (deg)  
42 - dec : float, optional  
43 - Declination of pattern centre (deg)  
44 - offset : float, optional  
45 - Offset between observations of pattern (deg)  
46 - emin : float, optional  
47 - Minimum energy (TeV)  
48 - emax : float, optional  
49 - Maximum energy (TeV)  
50 - rad : float, optional  
51 - ROI radius used for analysis (deg)  
52 - duration : float, optional  
53 - Duration of one CTA observation (s)  
54 - deadc : float, optional  
55 - Deadtime correction factor  
56 - caldb : str, optional  
57 - Calibration database path  
58 - irf : str, optional  
59 - Instrument response function  
60 -  
61 - Returns  
62 - -------  
63 - obs : `~gammalib.GObservations`  
64 - Observation container  
65 - """  
66 - # Set list of observations  
67 - obs_def_list = obsutils.set_obs_patterns(pattern,  
68 - ra=ra,  
69 - dec=dec,  
70 - offset=offset)  
71 -  
72 - # Get observation container  
73 - obs = obsutils.set_obs_list(obs_def_list,  
74 - duration=duration,  
75 - emin=emin,  
76 - emax=emax,  
77 - rad=rad,  
78 - caldb=caldb,  
79 - irf=irf)  
80 -  
81 - # Return observation container  
82 - return obs  
83 -  
84 -  
85 -# =========== #  
86 -# Setup model #  
87 -# =========== #  
88 -def setup_model(obs, model='data/crab.xml'):  
89 - """  
90 - Setup model for analysis  
91 -  
92 - Parameters  
93 - ----------  
94 - obs : `~gammalib.GObservations`  
95 - Observation container  
96 - model : str, optional  
97 - Model definition XML file  
98 -  
99 - Returns  
100 - -------  
101 - obs : `~gammalib.GObservations`  
102 - Observation container  
103 - """  
104 - # Append model from file to observation container  
105 - obs.models(gammalib.GModels(model))  
106 -  
107 - # Return observation container  
108 - return obs 23 +import cscripts
109 24
110 25
111 # ================================ # 26 # ================================ #
@@ -190,17 +105,25 @@ if __name__ == &#39;__main__&#39;: @@ -190,17 +105,25 @@ if __name__ == &#39;__main__&#39;:
190 print('* CTA binned analysis pipeline *') 105 print('* CTA binned analysis pipeline *')
191 print('********************************************') 106 print('********************************************')
192 107
193 - # Get optional arguments  
194 - if len(sys.argv) == 2:  
195 - datadir = sys.argv[1]  
196 - else:  
197 - datadir = 'data' 108 + # Set usage string
  109 + usage = 'pipeline_binned_mem.py [-d datadir]'
  110 +
  111 + # Set default options
  112 + options = [{'option': '-d', 'value': 'data'}]
  113 +
  114 + # Get arguments and options from command line arguments
  115 + args, options = cscripts.ioutils.get_args_options(options, usage)
  116 +
  117 + # Extract script parameters from options
  118 + datadir = options[0]['value']
198 119
199 # Setup observations 120 # Setup observations
200 - obs = setup_observations() 121 + obs = cscripts.obsutils.set_observations(83.63, 22.01, 5.0, 0.0, 180.0,
  122 + 0.1, 100.0, 'South_0.5h', 'prod2',
  123 + pattern='four', offset=1.5)
201 124
202 # Setup model 125 # Setup model
203 - obs = setup_model(obs, model=datadir+'/crab.xml') 126 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
204 127
205 # Run analysis pipeline 128 # Run analysis pipeline
206 run_pipeline(obs) 129 run_pipeline(obs)
examples/pipeline_stacked_disk.py
@@ -18,94 +18,9 @@ @@ -18,94 +18,9 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # 19 #
20 # ========================================================================== 20 # ==========================================================================
21 -import sys  
22 import gammalib 21 import gammalib
23 import ctools 22 import ctools
24 -from cscripts import obsutils  
25 -  
26 -  
27 -# ================== #  
28 -# Setup observations #  
29 -# ================== #  
30 -def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5,  
31 - emin=0.1, emax=100.0, rad=5.0, duration=180.0,  
32 - deadc=0.95, caldb='prod2', irf='South_0.5h'):  
33 - """  
34 - Returns an observation container  
35 -  
36 - Parameters  
37 - ----------  
38 - pattern : str, optional  
39 - Pointing pattern, either 'single' or 'four'  
40 - ra : float, optional  
41 - Right Ascension of pattern centre (deg)  
42 - dec : float, optional  
43 - Declination of pattern centre (deg)  
44 - offset : float, optional  
45 - Offset between observations of pattern (deg)  
46 - emin : float, optional  
47 - Minimum energy (TeV)  
48 - emax : float, optional  
49 - Maximum energy (TeV)  
50 - rad : float, optional  
51 - ROI radius used for analysis (deg)  
52 - duration : float, optional  
53 - Duration of one CTA observation (s)  
54 - deadc : float, optional  
55 - Deadtime correction factor  
56 - caldb : str, optional  
57 - Calibration database path  
58 - irf : str, optional  
59 - Instrument response function  
60 -  
61 - Returns  
62 - -------  
63 - obs : `~gammalib.GObservations`  
64 - Observation container  
65 - """  
66 - # Set list of observations  
67 - obs_def_list = obsutils.set_obs_patterns(pattern,  
68 - ra=ra,  
69 - dec=dec,  
70 - offset=offset)  
71 -  
72 - # Get observation container  
73 - obs = obsutils.set_obs_list(obs_def_list,  
74 - duration=duration,  
75 - emin=emin,  
76 - emax=emax,  
77 - rad=rad,  
78 - caldb=caldb,  
79 - irf=irf)  
80 -  
81 - # Return observation container  
82 - return obs  
83 -  
84 -  
85 -# =========== #  
86 -# Setup model #  
87 -# =========== #  
88 -def setup_model(obs, model='data/crab.xml'):  
89 - """  
90 - Setup model for analysis  
91 -  
92 - Parameters  
93 - ----------  
94 - obs : `~gammalib.GObservations`  
95 - Observation container  
96 - model : str, optional  
97 - Model definition XML file  
98 -  
99 - Returns  
100 - -------  
101 - obs : `~gammalib.GObservations`  
102 - Observation container  
103 - """  
104 - # Append model from file to observation container  
105 - obs.models(gammalib.GModels(model))  
106 -  
107 - # Return observation container  
108 - return obs 23 +import cscripts
109 24
110 25
111 # ================================ # 26 # ================================ #
@@ -269,17 +184,25 @@ if __name__ == &#39;__main__&#39;: @@ -269,17 +184,25 @@ if __name__ == &#39;__main__&#39;:
269 print('* CTA stacked analysis pipeline *') 184 print('* CTA stacked analysis pipeline *')
270 print('********************************************') 185 print('********************************************')
271 186
272 - # Get optional arguments  
273 - if len(sys.argv) == 2:  
274 - datadir = sys.argv[1]  
275 - else:  
276 - datadir = 'data' 187 + # Set usage string
  188 + usage = 'pipeline_stacked_disk.py [-d datadir]'
  189 +
  190 + # Set default options
  191 + options = [{'option': '-d', 'value': 'data'}]
  192 +
  193 + # Get arguments and options from command line arguments
  194 + args, options = cscripts.ioutils.get_args_options(options, usage)
  195 +
  196 + # Extract script parameters from options
  197 + datadir = options[0]['value']
277 198
278 # Setup observations 199 # Setup observations
279 - obs = setup_observations() 200 + obs = cscripts.obsutils.set_observations(83.63, 22.01, 5.0, 0.0, 180.0,
  201 + 0.1, 100.0, 'South_0.5h', 'prod2',
  202 + pattern='four', offset=1.5)
280 203
281 # Setup model 204 # Setup model
282 - obs = setup_model(obs, model=datadir+'/crab.xml') 205 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
283 206
284 # Run analysis pipeline 207 # Run analysis pipeline
285 run_pipeline(obs, model=datadir+'/crab.xml') 208 run_pipeline(obs, model=datadir+'/crab.xml')
examples/pipeline_stacked_mem.py
@@ -18,94 +18,9 @@ @@ -18,94 +18,9 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # 19 #
20 # ========================================================================== 20 # ==========================================================================
21 -import sys  
22 import gammalib 21 import gammalib
23 import ctools 22 import ctools
24 -from cscripts import obsutils  
25 -  
26 -  
27 -# ================== #  
28 -# Setup observations #  
29 -# ================== #  
30 -def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5,  
31 - emin=0.1, emax=100.0, rad=5.0, duration=180.0,  
32 - deadc=0.95, caldb='prod2', irf='South_0.5h'):  
33 - """  
34 - Returns an observation container  
35 -  
36 - Parameters  
37 - ----------  
38 - pattern : str, optional  
39 - Pointing pattern, either 'single' or 'four'  
40 - ra : float, optional  
41 - Right Ascension of pattern centre (deg)  
42 - dec : float, optional  
43 - Declination of pattern centre (deg)  
44 - offset : float, optional  
45 - Offset between observations of pattern (deg)  
46 - emin : float, optional  
47 - Minimum energy (TeV)  
48 - emax : float, optional  
49 - Maximum energy (TeV)  
50 - rad : float, optional  
51 - ROI radius used for analysis (deg)  
52 - duration : float, optional  
53 - Duration of one CTA observation (s)  
54 - deadc : float, optional  
55 - Deadtime correction factor  
56 - caldb : str, optional  
57 - Calibration database path  
58 - irf : str, optional  
59 - Instrument response function  
60 -  
61 - Returns  
62 - -------  
63 - obs : `~gammalib.GObservations`  
64 - Observation container  
65 - """  
66 - # Set list of observations  
67 - obs_def_list = obsutils.set_obs_patterns(pattern,  
68 - ra=ra,  
69 - dec=dec,  
70 - offset=offset)  
71 -  
72 - # Get observation container  
73 - obs = obsutils.set_obs_list(obs_def_list,  
74 - duration=duration,  
75 - emin=emin,  
76 - emax=emax,  
77 - rad=rad,  
78 - caldb=caldb,  
79 - irf=irf)  
80 -  
81 - # Return observation container  
82 - return obs  
83 -  
84 -  
85 -# =========== #  
86 -# Setup model #  
87 -# =========== #  
88 -def setup_model(obs, model='data/crab.xml'):  
89 - """  
90 - Setup model for analysis  
91 -  
92 - Parameters  
93 - ----------  
94 - obs : `~gammalib.GObservations`  
95 - Observation container  
96 - model : str, optional  
97 - Model definition XML file  
98 -  
99 - Returns  
100 - -------  
101 - obs : `~gammalib.GObservations`  
102 - Observation container  
103 - """  
104 - # Append model from file to observation container  
105 - obs.models(gammalib.GModels(model))  
106 -  
107 - # Return observation container  
108 - return obs 23 +import cscripts
109 24
110 25
111 # ================================ # 26 # ================================ #
@@ -242,17 +157,25 @@ if __name__ == &#39;__main__&#39;: @@ -242,17 +157,25 @@ if __name__ == &#39;__main__&#39;:
242 print('* CTA stacked analysis pipeline *') 157 print('* CTA stacked analysis pipeline *')
243 print('********************************************') 158 print('********************************************')
244 159
245 - # Get optional arguments  
246 - if len(sys.argv) == 2:  
247 - datadir = sys.argv[1]  
248 - else:  
249 - datadir = 'data' 160 + # Set usage string
  161 + usage = 'pipeline_stacked_mem.py [-d datadir]'
  162 +
  163 + # Set default options
  164 + options = [{'option': '-d', 'value': 'data'}]
  165 +
  166 + # Get arguments and options from command line arguments
  167 + args, options = cscripts.ioutils.get_args_options(options, usage)
  168 +
  169 + # Extract script parameters from options
  170 + datadir = options[0]['value']
250 171
251 # Setup observations 172 # Setup observations
252 - obs = setup_observations() 173 + obs = cscripts.obsutils.set_observations(83.63, 22.01, 5.0, 0.0, 180.0,
  174 + 0.1, 100.0, 'South_0.5h', 'prod2',
  175 + pattern='four', offset=1.5)
253 176
254 # Setup model 177 # Setup model
255 - obs = setup_model(obs, model=datadir+'/crab.xml') 178 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
256 179
257 # Run analysis pipeline 180 # Run analysis pipeline
258 run_pipeline(obs) 181 run_pipeline(obs)
examples/pipeline_unbinned_disk.py
@@ -18,94 +18,9 @@ @@ -18,94 +18,9 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # 19 #
20 # ========================================================================== 20 # ==========================================================================
21 -import sys  
22 import gammalib 21 import gammalib
23 import ctools 22 import ctools
24 -from cscripts import obsutils  
25 -  
26 -  
27 -# ================== #  
28 -# Setup observations #  
29 -# ================== #  
30 -def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5,  
31 - emin=0.1, emax=100.0, rad=5.0, duration=180.0,  
32 - deadc=0.95, caldb='prod2', irf='South_0.5h'):  
33 - """  
34 - Returns an observation container  
35 -  
36 - Parameters  
37 - ----------  
38 - pattern : str, optional  
39 - Pointing pattern, either 'single' or 'four'  
40 - ra : float, optional  
41 - Right Ascension of pattern centre (deg)  
42 - dec : float, optional  
43 - Declination of pattern centre (deg)  
44 - offset : float, optional  
45 - Offset between observations of pattern (deg)  
46 - emin : float, optional  
47 - Minimum energy (TeV)  
48 - emax : float, optional  
49 - Maximum energy (TeV)  
50 - rad : float, optional  
51 - ROI radius used for analysis (deg)  
52 - duration : float, optional  
53 - Duration of one CTA observation (s)  
54 - deadc : float, optional  
55 - Deadtime correction factor  
56 - caldb : str, optional  
57 - Calibration database path  
58 - irf : str, optional  
59 - Instrument response function  
60 -  
61 - Returns  
62 - -------  
63 - obs : `~gammalib.GObservations`  
64 - Observation container  
65 - """  
66 - # Set list of observations  
67 - obs_def_list = obsutils.set_obs_patterns(pattern,  
68 - ra=ra,  
69 - dec=dec,  
70 - offset=offset)  
71 -  
72 - # Get observation container  
73 - obs = obsutils.set_obs_list(obs_def_list,  
74 - duration=duration,  
75 - emin=emin,  
76 - emax=emax,  
77 - rad=rad,  
78 - caldb=caldb,  
79 - irf=irf)  
80 -  
81 - # Return observation container  
82 - return obs  
83 -  
84 -  
85 -# =========== #  
86 -# Setup model #  
87 -# =========== #  
88 -def setup_model(obs, model='data/crab.xml'):  
89 - """  
90 - Setup model for analysis  
91 -  
92 - Parameters  
93 - ----------  
94 - obs : `~gammalib.GObservations`  
95 - Observation container  
96 - model : str, optional  
97 - Model definition XML file  
98 -  
99 - Returns  
100 - -------  
101 - obs : `~gammalib.GObservations`  
102 - Observation container  
103 - """  
104 - # Append model from file to observation container  
105 - obs.models(gammalib.GModels(model))  
106 -  
107 - # Return observation container  
108 - return obs 23 +import cscripts
109 24
110 25
111 # ================================ # 26 # ================================ #
@@ -193,17 +108,25 @@ if __name__ == &#39;__main__&#39;: @@ -193,17 +108,25 @@ if __name__ == &#39;__main__&#39;:
193 print('* CTA unbinned analysis pipeline *') 108 print('* CTA unbinned analysis pipeline *')
194 print('********************************************') 109 print('********************************************')
195 110
196 - # Get optional arguments  
197 - if len(sys.argv) == 2:  
198 - datadir = sys.argv[1]  
199 - else:  
200 - datadir = 'data' 111 + # Set usage string
  112 + usage = 'pipeline_unbinned_disk.py [-d datadir]'
  113 +
  114 + # Set default options
  115 + options = [{'option': '-d', 'value': 'data'}]
  116 +
  117 + # Get arguments and options from command line arguments
  118 + args, options = cscripts.ioutils.get_args_options(options, usage)
  119 +
  120 + # Extract script parameters from options
  121 + datadir = options[0]['value']
201 122
202 # Setup observations 123 # Setup observations
203 - obs = setup_observations() 124 + obs = cscripts.obsutils.set_observations(83.63, 22.01, 5.0, 0.0, 180.0,
  125 + 0.1, 100.0, 'South_0.5h', 'prod2',
  126 + pattern='four', offset=1.5)
204 127
205 # Setup model 128 # Setup model
206 - obs = setup_model(obs, model=datadir+'/crab.xml') 129 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
207 130
208 # Run analysis pipeline 131 # Run analysis pipeline
209 run_pipeline(obs, model=datadir+'/crab.xml') 132 run_pipeline(obs, model=datadir+'/crab.xml')
examples/pipeline_unbinned_mem.py
@@ -18,94 +18,9 @@ @@ -18,94 +18,9 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # 19 #
20 # ========================================================================== 20 # ==========================================================================
21 -import sys  
22 import gammalib 21 import gammalib
23 import ctools 22 import ctools
24 -from cscripts import obsutils  
25 -  
26 -  
27 -# ================== #  
28 -# Setup observations #  
29 -# ================== #  
30 -def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5,  
31 - emin=0.1, emax=100.0, rad=5.0, duration=180.0,  
32 - deadc=0.95, caldb='prod2', irf='South_0.5h'):  
33 - """  
34 - Returns an observation container  
35 -  
36 - Parameters  
37 - ----------  
38 - pattern : str, optional  
39 - Pointing pattern, either 'single' or 'four'  
40 - ra : float, optional  
41 - Right Ascension of pattern centre (deg)  
42 - dec : float, optional  
43 - Declination of pattern centre (deg)  
44 - offset : float, optional  
45 - Offset between observations of pattern (deg)  
46 - emin : float, optional  
47 - Minimum energy (TeV)  
48 - emax : float, optional  
49 - Maximum energy (TeV)  
50 - rad : float, optional  
51 - ROI radius used for analysis (deg)  
52 - duration : float, optional  
53 - Duration of one CTA observation (s)  
54 - deadc : float, optional  
55 - Deadtime correction factor  
56 - caldb : str, optional  
57 - Calibration database path  
58 - irf : str, optional  
59 - Instrument response function  
60 -  
61 - Returns  
62 - -------  
63 - obs : `~gammalib.GObservations`  
64 - Observation container  
65 - """  
66 - # Set list of observations  
67 - obs_def_list = obsutils.set_obs_patterns(pattern,  
68 - ra=ra,  
69 - dec=dec,  
70 - offset=offset)  
71 -  
72 - # Get observation container  
73 - obs = obsutils.set_obs_list(obs_def_list,  
74 - duration=duration,  
75 - emin=emin,  
76 - emax=emax,  
77 - rad=rad,  
78 - caldb=caldb,  
79 - irf=irf)  
80 -  
81 - # Return observation container  
82 - return obs  
83 -  
84 -  
85 -# =========== #  
86 -# Setup model #  
87 -# =========== #  
88 -def setup_model(obs, model='data/crab.xml'):  
89 - """  
90 - Setup model for analysis  
91 -  
92 - Parameters  
93 - ----------  
94 - obs : `~gammalib.GObservations`  
95 - Observation container  
96 - model : str, optional  
97 - Model definition XML file  
98 -  
99 - Returns  
100 - -------  
101 - obs : `~gammalib.GObservations`  
102 - Observation container  
103 - """  
104 - # Append model from file to observation container  
105 - obs.models(gammalib.GModels(model))  
106 -  
107 - # Return observation container  
108 - return obs 23 +import cscripts
109 24
110 25
111 # ================================ # 26 # ================================ #
@@ -175,17 +90,25 @@ if __name__ == &#39;__main__&#39;: @@ -175,17 +90,25 @@ if __name__ == &#39;__main__&#39;:
175 print('* CTA unbinned analysis pipeline *') 90 print('* CTA unbinned analysis pipeline *')
176 print('********************************************') 91 print('********************************************')
177 92
178 - # Get optional arguments  
179 - if len(sys.argv) == 2:  
180 - datadir = sys.argv[1]  
181 - else:  
182 - datadir = 'data' 93 + # Set usage string
  94 + usage = 'pipeline_unbinned_mem.py [-d datadir]'
  95 +
  96 + # Set default options
  97 + options = [{'option': '-d', 'value': 'data'}]
  98 +
  99 + # Get arguments and options from command line arguments
  100 + args, options = cscripts.ioutils.get_args_options(options, usage)
  101 +
  102 + # Extract script parameters from options
  103 + datadir = options[0]['value']
183 104
184 # Setup observations 105 # Setup observations
185 - obs = setup_observations() 106 + obs = cscripts.obsutils.set_observations(83.63, 22.01, 5.0, 0.0, 180.0,
  107 + 0.1, 100.0, 'South_0.5h', 'prod2',
  108 + pattern='four', offset=1.5)
186 109
187 # Setup model 110 # Setup model
188 - obs = setup_model(obs, model=datadir+'/crab.xml') 111 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
189 112
190 # Run analysis pipeline 113 # Run analysis pipeline
191 run_pipeline(obs) 114 run_pipeline(obs)
test/test_examples.py.in
@@ -186,7 +186,7 @@ class Test(gammalib.GPythonTestSuite): @@ -186,7 +186,7 @@ class Test(gammalib.GPythonTestSuite):
186 """ 186 """
187 # Execute script 187 # Execute script
188 self._execute_python('make_ts_distributions', 188 self._execute_python('make_ts_distributions',
189 - args='-n 2 -e 0 -d 1800 -p '+self._datadir) 189 + args='-n 2 -e 0 -t 1800 -d '+self._datadir)
190 190
191 # Return 191 # Return
192 return 192 return
@@ -197,7 +197,7 @@ class Test(gammalib.GPythonTestSuite): @@ -197,7 +197,7 @@ class Test(gammalib.GPythonTestSuite):
197 Test pipeline_binned_disk 197 Test pipeline_binned_disk
198 """ 198 """
199 # Execute script 199 # Execute script
200 - self._execute_python('pipeline_binned_disk', args=self._datadir) 200 + self._execute_python('pipeline_binned_disk', args='-d '+self._datadir)
201 201
202 # Return 202 # Return
203 return 203 return
@@ -208,7 +208,7 @@ class Test(gammalib.GPythonTestSuite): @@ -208,7 +208,7 @@ class Test(gammalib.GPythonTestSuite):
208 Test pipeline_binned_mem 208 Test pipeline_binned_mem
209 """ 209 """
210 # Execute script 210 # Execute script
211 - self._execute_python('pipeline_binned_mem', args=self._datadir) 211 + self._execute_python('pipeline_binned_mem', args='-d '+self._datadir)
212 212
213 # Return 213 # Return
214 return 214 return
@@ -219,7 +219,7 @@ class Test(gammalib.GPythonTestSuite): @@ -219,7 +219,7 @@ class Test(gammalib.GPythonTestSuite):
219 Test pipeline_stacked_disk 219 Test pipeline_stacked_disk
220 """ 220 """
221 # Execute script 221 # Execute script
222 - self._execute_python('pipeline_stacked_disk', args=self._datadir) 222 + self._execute_python('pipeline_stacked_disk', args='-d '+self._datadir)
223 223
224 # Return 224 # Return
225 return 225 return
@@ -230,7 +230,7 @@ class Test(gammalib.GPythonTestSuite): @@ -230,7 +230,7 @@ class Test(gammalib.GPythonTestSuite):
230 Test pipeline_stacked_mem 230 Test pipeline_stacked_mem
231 """ 231 """
232 # Execute script 232 # Execute script
233 - self._execute_python('pipeline_stacked_mem', args=self._datadir) 233 + self._execute_python('pipeline_stacked_mem', args='-d '+self._datadir)
234 234
235 # Return 235 # Return
236 return 236 return
@@ -241,7 +241,7 @@ class Test(gammalib.GPythonTestSuite): @@ -241,7 +241,7 @@ class Test(gammalib.GPythonTestSuite):
241 Test pipeline_unbinned_disk 241 Test pipeline_unbinned_disk
242 """ 242 """
243 # Execute script 243 # Execute script
244 - self._execute_python('pipeline_unbinned_disk', args=self._datadir) 244 + self._execute_python('pipeline_unbinned_disk', args='-d '+self._datadir)
245 245
246 # Return 246 # Return
247 return 247 return
@@ -252,7 +252,7 @@ class Test(gammalib.GPythonTestSuite): @@ -252,7 +252,7 @@ class Test(gammalib.GPythonTestSuite):
252 Test pipeline_unbinned_mem 252 Test pipeline_unbinned_mem
253 """ 253 """
254 # Execute script 254 # Execute script
255 - self._execute_python('pipeline_unbinned_mem', args=self._datadir) 255 + self._execute_python('pipeline_unbinned_mem', args='-d '+self._datadir)
256 256
257 # Return 257 # Return
258 return 258 return