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 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 75 Parameters
76 76 ----------
... ... @@ -81,9 +81,12 @@ def get_arg_options(options, usage):
81 81  
82 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 90 # If there are no command line arguments then show usage string and
88 91 # exit
89 92 if len(sys.argv) < 1:
... ... @@ -96,13 +99,18 @@ def get_arg_options(options, usage):
96 99 # Loop over all arguments
97 100 while i < len(sys.argv):
98 101  
  102 + # Initialise that no option was found
  103 + option_found = False
  104 +
99 105 # Search for options
100 106 for option in options:
  107 +
  108 + # Do we have an option
101 109 if sys.argv[i] == option['option']:
102 110  
103 111 # If an option has been found then check if there is a
104 112 # following parameter and extract that parameter as a
105   - # string
  113 + # string. Quit in case that an exception occurs.
106 114 if len(sys.argv) > i+1:
107 115 i += 1
108 116 try:
... ... @@ -110,12 +118,23 @@ def get_arg_options(options, usage):
110 118 except:
111 119 print(usage)
112 120 sys.exit()
  121 +
  122 + # ... there is no following parameter, hence write out usage
  123 + # and quite
113 124 else:
114 125 print(usage)
115 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 136 # Next item
118 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 89  
90 90 # Set usage string
91 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 94 # Set default options
95 95 options = [{'option': '-n', 'value': '100'},
96 96 {'option': '-e', 'value': '0'},
97   - {'option': '-d', 'value': '180000.0'},
  97 + {'option': '-t', 'value': '180000.0'},
98 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 104 # Extract script parameters from options
105 105 ntrials = int(options[0]['value'])
... ...
examples/pipeline_binned_disk.py
1 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 5 # Copyright (C) 2015-2016 Juergen Knoedlseder
6 6 #
... ... @@ -18,94 +18,9 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
21   -import sys
22 21 import gammalib
23 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 134 print('* CTA binned analysis pipeline *')
220 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 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 154 # Setup model
232   - obs = setup_model(obs, model=datadir+'/crab.xml')
  155 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
233 156  
234 157 # Run analysis pipeline
235 158 run_pipeline(obs, model=datadir+'/crab.xml')
... ...
examples/pipeline_binned_mem.py
... ... @@ -18,94 +18,9 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
21   -import sys
22 21 import gammalib
23 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 105 print('* CTA binned analysis pipeline *')
191 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 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 125 # Setup model
203   - obs = setup_model(obs, model=datadir+'/crab.xml')
  126 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
204 127  
205 128 # Run analysis pipeline
206 129 run_pipeline(obs)
... ...
examples/pipeline_stacked_disk.py
... ... @@ -18,94 +18,9 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
21   -import sys
22 21 import gammalib
23 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 184 print('* CTA stacked analysis pipeline *')
270 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 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 204 # Setup model
282   - obs = setup_model(obs, model=datadir+'/crab.xml')
  205 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
283 206  
284 207 # Run analysis pipeline
285 208 run_pipeline(obs, model=datadir+'/crab.xml')
... ...
examples/pipeline_stacked_mem.py
... ... @@ -18,94 +18,9 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
21   -import sys
22 21 import gammalib
23 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 157 print('* CTA stacked analysis pipeline *')
243 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 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 177 # Setup model
255   - obs = setup_model(obs, model=datadir+'/crab.xml')
  178 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
256 179  
257 180 # Run analysis pipeline
258 181 run_pipeline(obs)
... ...
examples/pipeline_unbinned_disk.py
... ... @@ -18,94 +18,9 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
21   -import sys
22 21 import gammalib
23 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 108 print('* CTA unbinned analysis pipeline *')
194 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 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 128 # Setup model
206   - obs = setup_model(obs, model=datadir+'/crab.xml')
  129 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
207 130  
208 131 # Run analysis pipeline
209 132 run_pipeline(obs, model=datadir+'/crab.xml')
... ...
examples/pipeline_unbinned_mem.py
... ... @@ -18,94 +18,9 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
21   -import sys
22 21 import gammalib
23 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 90 print('* CTA unbinned analysis pipeline *')
176 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 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 110 # Setup model
188   - obs = setup_model(obs, model=datadir+'/crab.xml')
  111 + obs.models(gammalib.GModels(datadir+'/crab.xml'))
189 112  
190 113 # Run analysis pipeline
191 114 run_pipeline(obs)
... ...
test/test_examples.py.in
... ... @@ -186,7 +186,7 @@ class Test(gammalib.GPythonTestSuite):
186 186 """
187 187 # Execute script
188 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 191 # Return
192 192 return
... ... @@ -197,7 +197,7 @@ class Test(gammalib.GPythonTestSuite):
197 197 Test pipeline_binned_disk
198 198 """
199 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 202 # Return
203 203 return
... ... @@ -208,7 +208,7 @@ class Test(gammalib.GPythonTestSuite):
208 208 Test pipeline_binned_mem
209 209 """
210 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 213 # Return
214 214 return
... ... @@ -219,7 +219,7 @@ class Test(gammalib.GPythonTestSuite):
219 219 Test pipeline_stacked_disk
220 220 """
221 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 224 # Return
225 225 return
... ... @@ -230,7 +230,7 @@ class Test(gammalib.GPythonTestSuite):
230 230 Test pipeline_stacked_mem
231 231 """
232 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 235 # Return
236 236 return
... ... @@ -241,7 +241,7 @@ class Test(gammalib.GPythonTestSuite):
241 241 Test pipeline_unbinned_disk
242 242 """
243 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 246 # Return
247 247 return
... ... @@ -252,7 +252,7 @@ class Test(gammalib.GPythonTestSuite):
252 252 Test pipeline_unbinned_mem
253 253 """
254 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 257 # Return
258 258 return
... ...