Commit 03ce9b01cb903a43ad0fbfeba08d7279a5cf35bf
1 parent
9de14b14
Add tmin and tmax parameters to csobsselect (#2297)
Showing
8 changed files
with
117 additions
and
43 deletions
ChangeLog
| 1 | -2018-01-23 | |
| 1 | +2018-01-24 | |
| 2 | 2 | |
| 3 | 3 | * Version 1.5.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Add tmin and tmax parameters to csobsselect (#2297) | |
| 6 | 7 | Change DATE_OBS, DATE_END, TIME_OBS and TIME_END FITS keywords into DATA-OBS, |
| 7 | 8 | DATE-END, TIME-OBS and TIME-END |
| 8 | 9 | Add CUSTOM background method to csphagen script (#2284) | ... | ... |
NEWS
| 1 | -23 January 2018 | |
| 1 | +24 January 2018 | |
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | Introduction |
| ... | ... | @@ -235,7 +235,7 @@ None |
| 235 | 235 | |
| 236 | 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 | 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 | 31 | rad, r, a, 5.0,0,180, "Radius of selection circle (deg)" |
| 32 | 32 | width, r, a, 10.0,0,360, "Width of selection box (deg)" |
| 33 | 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 | 38 | # Standard parameters | ... | ... |
cscripts/csobsselect.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 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 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -68,6 +68,9 @@ class csobsselect(ctools.csobservation): |
| 68 | 68 | self['width'].real() |
| 69 | 69 | self['height'].real() |
| 70 | 70 | |
| 71 | + # Query time interval | |
| 72 | + self._get_gti() | |
| 73 | + | |
| 71 | 74 | # Query ahead output model filename |
| 72 | 75 | if self._read_ahead(): |
| 73 | 76 | self['outobs'].filename() |
| ... | ... | @@ -83,7 +86,34 @@ class csobsselect(ctools.csobservation): |
| 83 | 86 | # Return |
| 84 | 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 | 118 | Select observation |
| 89 | 119 | |
| ... | ... | @@ -91,6 +121,8 @@ class csobsselect(ctools.csobservation): |
| 91 | 121 | ---------- |
| 92 | 122 | obs : `~gammalib.GObservation` |
| 93 | 123 | Observation |
| 124 | + gti : `~gammalib.GGti` | |
| 125 | + Good time intervals | |
| 94 | 126 | |
| 95 | 127 | Returns |
| 96 | 128 | ------- |
| ... | ... | @@ -103,14 +135,27 @@ class csobsselect(ctools.csobservation): |
| 103 | 135 | # Continue only if observation is a CTA observation |
| 104 | 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 | 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 | 160 | # Return selection flag |
| 116 | 161 | return select |
| ... | ... | @@ -150,18 +195,8 @@ class csobsselect(ctools.csobservation): |
| 150 | 195 | select = False |
| 151 | 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 | 198 | # Log observation selection |
| 164 | - self._log_value(gammalib.NORMAL, name, msg) | |
| 199 | + self._log_selection(obs, msg) | |
| 165 | 200 | |
| 166 | 201 | # Return selection flag |
| 167 | 202 | return select |
| ... | ... | @@ -240,18 +275,8 @@ class csobsselect(ctools.csobservation): |
| 240 | 275 | select = True |
| 241 | 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 | 278 | # Log observation selection |
| 254 | - self._log_value(gammalib.NORMAL, name, msg) | |
| 279 | + self._log_selection(obs, msg) | |
| 255 | 280 | |
| 256 | 281 | # Return selection flag |
| 257 | 282 | return select |
| ... | ... | @@ -269,6 +294,9 @@ class csobsselect(ctools.csobservation): |
| 269 | 294 | # Get parameters |
| 270 | 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 | 300 | # Initialise empty observation container for selected observations |
| 273 | 301 | selected_obs = gammalib.GObservations() |
| 274 | 302 | |
| ... | ... | @@ -282,7 +310,7 @@ class csobsselect(ctools.csobservation): |
| 282 | 310 | for obs in self.obs(): |
| 283 | 311 | |
| 284 | 312 | # If observation is selected then append observation |
| 285 | - if self._select_observation(obs): | |
| 313 | + if self._select_observation(obs, gti): | |
| 286 | 314 | selected_obs.append(obs) |
| 287 | 315 | |
| 288 | 316 | # Copy selected observations into observation | ... | ... |
doc/source/admin/release_history/1.5.rst
| ... | ... | @@ -12,6 +12,9 @@ In particular, this release provides: |
| 12 | 12 | |
| 13 | 13 | * Support of classical IACT analysis |
| 14 | 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 | 20 | Bug fixes |
| ... | ... | @@ -28,6 +31,8 @@ Bug fixes |
| 28 | 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 | 36 | * [`2295 <https://cta-redmine.irap.omp.eu/issues/2295>`_] - |
| 32 | 37 | Add ``ctools::time_reference`` constant and remove ``ctools::time_reference()`` |
| 33 | 38 | method |
| ... | ... | @@ -78,6 +83,7 @@ New features |
| 78 | 83 | * [`1864 <https://cta-redmine.irap.omp.eu/issues/1864>`_] - |
| 79 | 84 | Use t-type parameters for all ``tmin`` and ``tmax`` parameters |
| 80 | 85 | |
| 86 | + | |
| 81 | 87 | Clean up |
| 82 | 88 | -------- |
| 83 | 89 | ... | ... |
doc/source/users/reference_manual/csobsselect.rst
| ... | ... | @@ -10,9 +10,9 @@ Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | 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 | 18 | General parameters |
| ... | ... | @@ -51,6 +51,16 @@ General parameters |
| 51 | 51 | ``height [real]`` |
| 52 | 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 | 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 | 41 | Galactic longitude of selection centre (deg) (0-360) [184.56] 0.0 |
| 42 | 42 | Galactic latitude of selection centre (deg) (-90-90) [-5.79] 0.0 |
| 43 | 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 | 45 | Output observation definition XML file [outobs.xml] obs.xml |
| 45 | 46 | |
| 46 | 47 | You selected ``CIRCLE`` as the shape of the pointing selection region, | ... | ... |
test/test_csobsselect.py
| ... | ... | @@ -72,7 +72,7 @@ class Test(test): |
| 72 | 72 | cmd = csobsselect+' inobs="'+self._events+'"'+ \ |
| 73 | 73 | ' outobs="csobsselect_cmd1.xml"'+ \ |
| 74 | 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 | 76 | ' logfile="csobsselect_cmd1.log" chatter=1' |
| 77 | 77 | |
| 78 | 78 | # Check if execution was successful |
| ... | ... | @@ -86,7 +86,7 @@ class Test(test): |
| 86 | 86 | cmd = csobsselect+' inobs="observation_that_does_not_exist.xml"'+ \ |
| 87 | 87 | ' outobs="csobsselect_cmd2.xml"'+ \ |
| 88 | 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 | 90 | ' logfile="csobsselect_cmd2.log" debug=yes chatter=2' |
| 91 | 91 | |
| 92 | 92 | # Check if execution failed |
| ... | ... | @@ -121,12 +121,14 @@ class Test(test): |
| 121 | 121 | |
| 122 | 122 | # Now set csobsselect parameters |
| 123 | 123 | obsselect['inobs'] = self._events |
| 124 | - obsselect['outobs'] = 'csobsselect_py1.xml' | |
| 125 | 124 | obsselect['pntselect'] = 'CIRCLE' |
| 126 | 125 | obsselect['coordsys'] = 'CEL' |
| 127 | 126 | obsselect['ra'] = 83.63 |
| 128 | 127 | obsselect['dec'] = 22.01 |
| 129 | 128 | obsselect['rad'] = 5.0 |
| 129 | + obsselect['tmin'] = 'NONE' | |
| 130 | + obsselect['tmax'] = 'NONE' | |
| 131 | + obsselect['outobs'] = 'csobsselect_py1.xml' | |
| 130 | 132 | obsselect['logfile'] = 'csobsselect_py1.log' |
| 131 | 133 | obsselect['chatter'] = 2 |
| 132 | 134 | |
| ... | ... | @@ -139,12 +141,14 @@ class Test(test): |
| 139 | 141 | self._check_observation_file('csobsselect_py1.xml', 1) |
| 140 | 142 | |
| 141 | 143 | # Execute csobsselect script again, now in Galactic coordinates |
| 142 | - obsselect['outobs'] = 'csobsselect_py2.xml' | |
| 143 | 144 | obsselect['pntselect'] = 'CIRCLE' |
| 144 | 145 | obsselect['coordsys'] = 'GAL' |
| 145 | 146 | obsselect['glon'] = 184.56 |
| 146 | 147 | obsselect['glat'] = -5.79 |
| 147 | 148 | obsselect['rad'] = 5.0 |
| 149 | + obsselect['tmin'] = 'NONE' | |
| 150 | + obsselect['tmax'] = 'NONE' | |
| 151 | + obsselect['outobs'] = 'csobsselect_py2.xml' | |
| 148 | 152 | obsselect['logfile'] = 'csobsselect_py2.log' |
| 149 | 153 | obsselect['chatter'] = 3 |
| 150 | 154 | obsselect.logFileOpen() # Needed to get a new log file |
| ... | ... | @@ -154,13 +158,15 @@ class Test(test): |
| 154 | 158 | self._check_observation_file('csobsselect_py2.xml', 1) |
| 155 | 159 | |
| 156 | 160 | # Execute csobsselect script again, now a box in Galactic coordinates |
| 157 | - obsselect['outobs'] = 'csobsselect_py3.xml' | |
| 158 | 161 | obsselect['pntselect'] = 'BOX' |
| 159 | 162 | obsselect['coordsys'] = 'GAL' |
| 160 | 163 | obsselect['glon'] = 184.56 |
| 161 | 164 | obsselect['glat'] = -5.79 |
| 162 | 165 | obsselect['width'] = 5.0 |
| 163 | 166 | obsselect['height'] = 5.0 |
| 167 | + obsselect['tmin'] = 'NONE' | |
| 168 | + obsselect['tmax'] = 'NONE' | |
| 169 | + obsselect['outobs'] = 'csobsselect_py3.xml' | |
| 164 | 170 | obsselect['logfile'] = 'csobsselect_py3.log' |
| 165 | 171 | obsselect['chatter'] = 4 |
| 166 | 172 | obsselect.logFileOpen() # Needed to get a new log file |
| ... | ... | @@ -170,13 +176,15 @@ class Test(test): |
| 170 | 176 | self._check_observation_file('csobsselect_py3.xml', 1) |
| 171 | 177 | |
| 172 | 178 | # Execute csobsselect script again, now a box in celestial coordinates |
| 173 | - obsselect['outobs'] = 'csobsselect_py4.xml' | |
| 174 | 179 | obsselect['pntselect'] = 'BOX' |
| 175 | 180 | obsselect['coordsys'] = 'CEL' |
| 176 | 181 | obsselect['ra'] = 83.63 |
| 177 | 182 | obsselect['dec'] = 22.01 |
| 178 | 183 | obsselect['width'] = 5.0 |
| 179 | 184 | obsselect['height'] = 5.0 |
| 185 | + obsselect['tmin'] = 'NONE' | |
| 186 | + obsselect['tmax'] = 'NONE' | |
| 187 | + obsselect['outobs'] = 'csobsselect_py4.xml' | |
| 180 | 188 | obsselect['logfile'] = 'csobsselect_py4.log' |
| 181 | 189 | obsselect['chatter'] = 4 |
| 182 | 190 | obsselect.logFileOpen() # Needed to get a new log file |
| ... | ... | @@ -185,6 +193,24 @@ class Test(test): |
| 185 | 193 | # Check model file |
| 186 | 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 | 214 | # Return |
| 189 | 215 | return |
| 190 | 216 | ... | ... |