Commit 03ce9b01cb903a43ad0fbfeba08d7279a5cf35bf

Authored by Jürgen Knödlseder
1 parent 9de14b14

Add tmin and tmax parameters to csobsselect (#2297)

ChangeLog
1 -2018-01-23 1 +2018-01-24
2 2
3 * Version 1.5.0 released 3 * Version 1.5.0 released
4 ======================== 4 ========================
5 5
  6 + Add tmin and tmax parameters to csobsselect (#2297)
6 Change DATE_OBS, DATE_END, TIME_OBS and TIME_END FITS keywords into DATA-OBS, 7 Change DATE_OBS, DATE_END, TIME_OBS and TIME_END FITS keywords into DATA-OBS,
7 DATE-END, TIME-OBS and TIME-END 8 DATE-END, TIME-OBS and TIME-END
8 Add CUSTOM background method to csphagen script (#2284) 9 Add CUSTOM background method to csphagen script (#2284)
1 -23 January 2018 1 +24 January 2018
2 2
3 3
4 Introduction 4 Introduction
@@ -235,7 +235,7 @@ None @@ -235,7 +235,7 @@ None
235 235
236 csobsselect - Select observations 236 csobsselect - Select observations
237 --------------------------------- 237 ---------------------------------
238 -None 238 +Add tmin and tmax parameters to allow selection of observation by time (#2297).
239 239
240 240
241 csphagen - Generate On/Off observations 241 csphagen - Generate On/Off observations
cscripts/csobsselect.par
@@ -31,6 +31,8 @@ glat, r, a, -5.79,-90,90, "Galactic latitude of selection centre (deg)" @@ -31,6 +31,8 @@ glat, r, a, -5.79,-90,90, "Galactic latitude of selection centre (deg)"
31 rad, r, a, 5.0,0,180, "Radius of selection circle (deg)" 31 rad, r, a, 5.0,0,180, "Radius of selection circle (deg)"
32 width, r, a, 10.0,0,360, "Width of selection box (deg)" 32 width, r, a, 10.0,0,360, "Width of selection box (deg)"
33 height, r, a, 10.0,0,180, "Height of selection box (deg)" 33 height, r, a, 10.0,0,180, "Height of selection box (deg)"
  34 +tmin, t, a, NONE,,, "Start time (UTC string, JD, MJD or MET in seconds)"
  35 +tmax, t, a, NONE,,, "Stop time (UTC string, JD, MJD or MET in seconds)"
34 36
35 # 37 #
36 # Standard parameters 38 # Standard parameters
cscripts/csobsselect.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Selects observations from an observation definition XML file 3 # Selects observations from an observation definition XML file
4 # 4 #
5 -# Copyright (C) 2016-2017 Juergen Knoedlseder 5 +# Copyright (C) 2016-2018 Juergen Knoedlseder
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -68,6 +68,9 @@ class csobsselect(ctools.csobservation): @@ -68,6 +68,9 @@ class csobsselect(ctools.csobservation):
68 self['width'].real() 68 self['width'].real()
69 self['height'].real() 69 self['height'].real()
70 70
  71 + # Query time interval
  72 + self._get_gti()
  73 +
71 # Query ahead output model filename 74 # Query ahead output model filename
72 if self._read_ahead(): 75 if self._read_ahead():
73 self['outobs'].filename() 76 self['outobs'].filename()
@@ -83,7 +86,34 @@ class csobsselect(ctools.csobservation): @@ -83,7 +86,34 @@ class csobsselect(ctools.csobservation):
83 # Return 86 # Return
84 return 87 return
85 88
86 - def _select_observation(self, obs): 89 + def _log_selection(self, obs, msg):
  90 + """
  91 + Log observation selection
  92 +
  93 + Parameters
  94 + ----------
  95 + obs : `~gammalib.GObservation`
  96 + Observation
  97 + msg : str
  98 + Message
  99 + """
  100 + # Set observation name
  101 + if len(obs.name()) > 0:
  102 + name = obs.name()
  103 + else:
  104 + name = 'Observation'
  105 +
  106 + # Prepend obervation ID
  107 + if len(obs.id()) > 0:
  108 + msg = obs.id()+' '+msg
  109 +
  110 + # Log observation selection
  111 + self._log_value(gammalib.NORMAL, name, msg)
  112 +
  113 + # Return
  114 + return
  115 +
  116 + def _select_observation(self, obs, gti):
87 """ 117 """
88 Select observation 118 Select observation
89 119
@@ -91,6 +121,8 @@ class csobsselect(ctools.csobservation): @@ -91,6 +121,8 @@ class csobsselect(ctools.csobservation):
91 ---------- 121 ----------
92 obs : `~gammalib.GObservation` 122 obs : `~gammalib.GObservation`
93 Observation 123 Observation
  124 + gti : `~gammalib.GGti`
  125 + Good time intervals
94 126
95 Returns 127 Returns
96 ------- 128 -------
@@ -103,14 +135,27 @@ class csobsselect(ctools.csobservation): @@ -103,14 +135,27 @@ class csobsselect(ctools.csobservation):
103 # Continue only if observation is a CTA observation 135 # Continue only if observation is a CTA observation
104 if obs.classname() == 'GCTAObservation': 136 if obs.classname() == 'GCTAObservation':
105 137
106 - # Get selection type  
107 - pntselect = self['pntselect'].string() 138 + # Get observation start and stop time
  139 + obs_gti = obs.gti()
  140 + tstart = obs_gti.tstart()
  141 + tstop = obs_gti.tstop()
  142 +
  143 + # If the observation is not within the time selection then skip it
  144 + if gti.size() > 0 and not gti.contains(tstart) and \
  145 + not gti.contains(tstop):
  146 + self._log_selection(obs, 'outside time interval')
108 147
109 - # Dispatch according to selection type  
110 - if pntselect == 'CIRCLE':  
111 - select = self._select_circle(obs) 148 + # ... otherwise select spatially
112 else: 149 else:
113 - select = self._select_box(obs) 150 +
  151 + # Get selection type
  152 + pntselect = self['pntselect'].string()
  153 +
  154 + # Dispatch according to selection type
  155 + if pntselect == 'CIRCLE':
  156 + select = self._select_circle(obs)
  157 + else:
  158 + select = self._select_box(obs)
114 159
115 # Return selection flag 160 # Return selection flag
116 return select 161 return select
@@ -150,18 +195,8 @@ class csobsselect(ctools.csobservation): @@ -150,18 +195,8 @@ class csobsselect(ctools.csobservation):
150 select = False 195 select = False
151 msg = 'outside selection circle' 196 msg = 'outside selection circle'
152 197
153 - # Set observation name  
154 - if len(obs.name()) > 0:  
155 - name = obs.name()  
156 - else:  
157 - name = 'Observation'  
158 -  
159 - # Prepend obervation ID  
160 - if len(obs.id()) > 0:  
161 - msg = obs.id()+' '+msg  
162 -  
163 # Log observation selection 198 # Log observation selection
164 - self._log_value(gammalib.NORMAL, name, msg) 199 + self._log_selection(obs, msg)
165 200
166 # Return selection flag 201 # Return selection flag
167 return select 202 return select
@@ -240,18 +275,8 @@ class csobsselect(ctools.csobservation): @@ -240,18 +275,8 @@ class csobsselect(ctools.csobservation):
240 select = True 275 select = True
241 msg = 'inside selection box' 276 msg = 'inside selection box'
242 277
243 - # Set observation name  
244 - if len(obs.name()) > 0:  
245 - name = obs.name()  
246 - else:  
247 - name = 'Observation'  
248 -  
249 - # Prepend obervation ID  
250 - if len(obs.id()) > 0:  
251 - msg = obs.id()+' '+msg  
252 -  
253 # Log observation selection 278 # Log observation selection
254 - self._log_value(gammalib.NORMAL, name, msg) 279 + self._log_selection(obs, msg)
255 280
256 # Return selection flag 281 # Return selection flag
257 return select 282 return select
@@ -269,6 +294,9 @@ class csobsselect(ctools.csobservation): @@ -269,6 +294,9 @@ class csobsselect(ctools.csobservation):
269 # Get parameters 294 # Get parameters
270 self._get_parameters() 295 self._get_parameters()
271 296
  297 + # Get Good Time Interval (empty if no time selection is applied)
  298 + gti = self._get_gti()
  299 +
272 # Initialise empty observation container for selected observations 300 # Initialise empty observation container for selected observations
273 selected_obs = gammalib.GObservations() 301 selected_obs = gammalib.GObservations()
274 302
@@ -282,7 +310,7 @@ class csobsselect(ctools.csobservation): @@ -282,7 +310,7 @@ class csobsselect(ctools.csobservation):
282 for obs in self.obs(): 310 for obs in self.obs():
283 311
284 # If observation is selected then append observation 312 # If observation is selected then append observation
285 - if self._select_observation(obs): 313 + if self._select_observation(obs, gti):
286 selected_obs.append(obs) 314 selected_obs.append(obs)
287 315
288 # Copy selected observations into observation 316 # Copy selected observations into observation
doc/source/admin/release_history/1.5.rst
@@ -12,6 +12,9 @@ In particular, this release provides: @@ -12,6 +12,9 @@ In particular, this release provides:
12 12
13 * Support of classical IACT analysis 13 * Support of classical IACT analysis
14 * Specifcation of times in various formats (UTC, MJD, JD, MET) 14 * Specifcation of times in various formats (UTC, MJD, JD, MET)
  15 +* Spectrum generation for non-IACT data
  16 +* Generation of residual spectra
  17 +* Jupyter notebooks
15 18
16 19
17 Bug fixes 20 Bug fixes
@@ -28,6 +31,8 @@ Bug fixes @@ -28,6 +31,8 @@ Bug fixes
28 Improvements 31 Improvements
29 ------------ 32 ------------
30 33
  34 +* [`2297 <https://cta-redmine.irap.omp.eu/issues/2297>`_] -
  35 + Add ``tmin`` and ``tmax`` parameters to :ref:`csobsselect`
31 * [`2295 <https://cta-redmine.irap.omp.eu/issues/2295>`_] - 36 * [`2295 <https://cta-redmine.irap.omp.eu/issues/2295>`_] -
32 Add ``ctools::time_reference`` constant and remove ``ctools::time_reference()`` 37 Add ``ctools::time_reference`` constant and remove ``ctools::time_reference()``
33 method 38 method
@@ -78,6 +83,7 @@ New features @@ -78,6 +83,7 @@ New features
78 * [`1864 <https://cta-redmine.irap.omp.eu/issues/1864>`_] - 83 * [`1864 <https://cta-redmine.irap.omp.eu/issues/1864>`_] -
79 Use t-type parameters for all ``tmin`` and ``tmax`` parameters 84 Use t-type parameters for all ``tmin`` and ``tmax`` parameters
80 85
  86 +
81 Clean up 87 Clean up
82 -------- 88 --------
83 89
doc/source/users/reference_manual/csobsselect.rst
@@ -10,9 +10,9 @@ Synopsis @@ -10,9 +10,9 @@ Synopsis
10 -------- 10 --------
11 11
12 This script selects all observations from an observation definiton XML file that 12 This script selects all observations from an observation definiton XML file that
13 -have pointings within a specified selection region and writes these observations  
14 -into a new observation definition XML file. Possible selection regions are a  
15 -circle and a box, either in Galactic or Celestial coordinates. 13 +have pointings within a specified selection region and time interval and writes
  14 +these observations into a new observation definition XML file. Possible selection
  15 +regions are a circle and a box, either in Galactic or Celestial coordinates.
16 16
17 17
18 General parameters 18 General parameters
@@ -51,6 +51,16 @@ General parameters @@ -51,6 +51,16 @@ General parameters
51 ``height [real]`` 51 ``height [real]``
52 Height of selection box (degrees). 52 Height of selection box (degrees).
53 53
  54 +``tmin [time]``
  55 + Start time (UTC string, JD, MJD or time in seconds).
  56 + If ``INDEF``, ``NONE``, ``UNDEF`` or ``UNDEFINED`` is passed as value, no time
  57 + selection will be performed.
  58 +
  59 +``tmax [time]``
  60 + Stop time (UTC string, JD, MJD or time in seconds).
  61 + If ``INDEF``, ``NONE``, ``UNDEF`` or ``UNDEFINED`` is passed as value, no time
  62 + selection will be performed.
  63 +
54 64
55 Standard parameters 65 Standard parameters
56 ------------------- 66 -------------------
doc/source/users/tutorials/1dc/first_select_obs.rst
@@ -41,6 +41,7 @@ You do this with the :ref:`csobsselect` script by typing: @@ -41,6 +41,7 @@ You do this with the :ref:`csobsselect` script by typing:
41 Galactic longitude of selection centre (deg) (0-360) [184.56] 0.0 41 Galactic longitude of selection centre (deg) (0-360) [184.56] 0.0
42 Galactic latitude of selection centre (deg) (-90-90) [-5.79] 0.0 42 Galactic latitude of selection centre (deg) (-90-90) [-5.79] 0.0
43 Radius of selection circle (deg) (0-180) [5.0] 3.0 43 Radius of selection circle (deg) (0-180) [5.0] 3.0
  44 + Start time (UTC string, JD, MJD or MET in seconds) [NONE]
44 Output observation definition XML file [outobs.xml] obs.xml 45 Output observation definition XML file [outobs.xml] obs.xml
45 46
46 You selected ``CIRCLE`` as the shape of the pointing selection region, 47 You selected ``CIRCLE`` as the shape of the pointing selection region,
test/test_csobsselect.py
@@ -72,7 +72,7 @@ class Test(test): @@ -72,7 +72,7 @@ class Test(test):
72 cmd = csobsselect+' inobs="'+self._events+'"'+ \ 72 cmd = csobsselect+' inobs="'+self._events+'"'+ \
73 ' outobs="csobsselect_cmd1.xml"'+ \ 73 ' outobs="csobsselect_cmd1.xml"'+ \
74 ' pntselect="CIRCLE" coordsys="CEL" ra=83.63'+ \ 74 ' pntselect="CIRCLE" coordsys="CEL" ra=83.63'+ \
75 - ' dec=22.01 rad=5.0'+ \ 75 + ' dec=22.01 rad=5.0 tmin=NONE tmax=NONE'+ \
76 ' logfile="csobsselect_cmd1.log" chatter=1' 76 ' logfile="csobsselect_cmd1.log" chatter=1'
77 77
78 # Check if execution was successful 78 # Check if execution was successful
@@ -86,7 +86,7 @@ class Test(test): @@ -86,7 +86,7 @@ class Test(test):
86 cmd = csobsselect+' inobs="observation_that_does_not_exist.xml"'+ \ 86 cmd = csobsselect+' inobs="observation_that_does_not_exist.xml"'+ \
87 ' outobs="csobsselect_cmd2.xml"'+ \ 87 ' outobs="csobsselect_cmd2.xml"'+ \
88 ' pntselect="CIRCLE" coordsys="CEL" ra=83.63'+ \ 88 ' pntselect="CIRCLE" coordsys="CEL" ra=83.63'+ \
89 - ' dec=22.01 rad=5.0'+ \ 89 + ' dec=22.01 rad=5.0 tmin=NONE tmax=NONE'+ \
90 ' logfile="csobsselect_cmd2.log" debug=yes chatter=2' 90 ' logfile="csobsselect_cmd2.log" debug=yes chatter=2'
91 91
92 # Check if execution failed 92 # Check if execution failed
@@ -121,12 +121,14 @@ class Test(test): @@ -121,12 +121,14 @@ class Test(test):
121 121
122 # Now set csobsselect parameters 122 # Now set csobsselect parameters
123 obsselect['inobs'] = self._events 123 obsselect['inobs'] = self._events
124 - obsselect['outobs'] = 'csobsselect_py1.xml'  
125 obsselect['pntselect'] = 'CIRCLE' 124 obsselect['pntselect'] = 'CIRCLE'
126 obsselect['coordsys'] = 'CEL' 125 obsselect['coordsys'] = 'CEL'
127 obsselect['ra'] = 83.63 126 obsselect['ra'] = 83.63
128 obsselect['dec'] = 22.01 127 obsselect['dec'] = 22.01
129 obsselect['rad'] = 5.0 128 obsselect['rad'] = 5.0
  129 + obsselect['tmin'] = 'NONE'
  130 + obsselect['tmax'] = 'NONE'
  131 + obsselect['outobs'] = 'csobsselect_py1.xml'
130 obsselect['logfile'] = 'csobsselect_py1.log' 132 obsselect['logfile'] = 'csobsselect_py1.log'
131 obsselect['chatter'] = 2 133 obsselect['chatter'] = 2
132 134
@@ -139,12 +141,14 @@ class Test(test): @@ -139,12 +141,14 @@ class Test(test):
139 self._check_observation_file('csobsselect_py1.xml', 1) 141 self._check_observation_file('csobsselect_py1.xml', 1)
140 142
141 # Execute csobsselect script again, now in Galactic coordinates 143 # Execute csobsselect script again, now in Galactic coordinates
142 - obsselect['outobs'] = 'csobsselect_py2.xml'  
143 obsselect['pntselect'] = 'CIRCLE' 144 obsselect['pntselect'] = 'CIRCLE'
144 obsselect['coordsys'] = 'GAL' 145 obsselect['coordsys'] = 'GAL'
145 obsselect['glon'] = 184.56 146 obsselect['glon'] = 184.56
146 obsselect['glat'] = -5.79 147 obsselect['glat'] = -5.79
147 obsselect['rad'] = 5.0 148 obsselect['rad'] = 5.0
  149 + obsselect['tmin'] = 'NONE'
  150 + obsselect['tmax'] = 'NONE'
  151 + obsselect['outobs'] = 'csobsselect_py2.xml'
148 obsselect['logfile'] = 'csobsselect_py2.log' 152 obsselect['logfile'] = 'csobsselect_py2.log'
149 obsselect['chatter'] = 3 153 obsselect['chatter'] = 3
150 obsselect.logFileOpen() # Needed to get a new log file 154 obsselect.logFileOpen() # Needed to get a new log file
@@ -154,13 +158,15 @@ class Test(test): @@ -154,13 +158,15 @@ class Test(test):
154 self._check_observation_file('csobsselect_py2.xml', 1) 158 self._check_observation_file('csobsselect_py2.xml', 1)
155 159
156 # Execute csobsselect script again, now a box in Galactic coordinates 160 # Execute csobsselect script again, now a box in Galactic coordinates
157 - obsselect['outobs'] = 'csobsselect_py3.xml'  
158 obsselect['pntselect'] = 'BOX' 161 obsselect['pntselect'] = 'BOX'
159 obsselect['coordsys'] = 'GAL' 162 obsselect['coordsys'] = 'GAL'
160 obsselect['glon'] = 184.56 163 obsselect['glon'] = 184.56
161 obsselect['glat'] = -5.79 164 obsselect['glat'] = -5.79
162 obsselect['width'] = 5.0 165 obsselect['width'] = 5.0
163 obsselect['height'] = 5.0 166 obsselect['height'] = 5.0
  167 + obsselect['tmin'] = 'NONE'
  168 + obsselect['tmax'] = 'NONE'
  169 + obsselect['outobs'] = 'csobsselect_py3.xml'
164 obsselect['logfile'] = 'csobsselect_py3.log' 170 obsselect['logfile'] = 'csobsselect_py3.log'
165 obsselect['chatter'] = 4 171 obsselect['chatter'] = 4
166 obsselect.logFileOpen() # Needed to get a new log file 172 obsselect.logFileOpen() # Needed to get a new log file
@@ -170,13 +176,15 @@ class Test(test): @@ -170,13 +176,15 @@ class Test(test):
170 self._check_observation_file('csobsselect_py3.xml', 1) 176 self._check_observation_file('csobsselect_py3.xml', 1)
171 177
172 # Execute csobsselect script again, now a box in celestial coordinates 178 # Execute csobsselect script again, now a box in celestial coordinates
173 - obsselect['outobs'] = 'csobsselect_py4.xml'  
174 obsselect['pntselect'] = 'BOX' 179 obsselect['pntselect'] = 'BOX'
175 obsselect['coordsys'] = 'CEL' 180 obsselect['coordsys'] = 'CEL'
176 obsselect['ra'] = 83.63 181 obsselect['ra'] = 83.63
177 obsselect['dec'] = 22.01 182 obsselect['dec'] = 22.01
178 obsselect['width'] = 5.0 183 obsselect['width'] = 5.0
179 obsselect['height'] = 5.0 184 obsselect['height'] = 5.0
  185 + obsselect['tmin'] = 'NONE'
  186 + obsselect['tmax'] = 'NONE'
  187 + obsselect['outobs'] = 'csobsselect_py4.xml'
180 obsselect['logfile'] = 'csobsselect_py4.log' 188 obsselect['logfile'] = 'csobsselect_py4.log'
181 obsselect['chatter'] = 4 189 obsselect['chatter'] = 4
182 obsselect.logFileOpen() # Needed to get a new log file 190 obsselect.logFileOpen() # Needed to get a new log file
@@ -185,6 +193,24 @@ class Test(test): @@ -185,6 +193,24 @@ class Test(test):
185 # Check model file 193 # Check model file
186 self._check_observation_file('csobsselect_py4.xml', 1) 194 self._check_observation_file('csobsselect_py4.xml', 1)
187 195
  196 + # Execute csobsselect script again, now with time selection
  197 + obsselect['pntselect'] = 'BOX'
  198 + obsselect['coordsys'] = 'CEL'
  199 + obsselect['ra'] = 83.63
  200 + obsselect['dec'] = 22.01
  201 + obsselect['width'] = 5.0
  202 + obsselect['height'] = 5.0
  203 + obsselect['tmin'] = 0.0
  204 + obsselect['tmax'] = 100.0
  205 + obsselect['outobs'] = 'csobsselect_py5.xml'
  206 + obsselect['logfile'] = 'csobsselect_py5.log'
  207 + obsselect['chatter'] = 4
  208 + obsselect.logFileOpen() # Needed to get a new log file
  209 + obsselect.execute()
  210 +
  211 + # Check model file
  212 + self._check_observation_file('csobsselect_py5.xml', 0)
  213 +
188 # Return 214 # Return
189 return 215 return
190 216