Commit 30425a82be33aacfb038e606c125d0a649de03ff
1 parent
4d52937f
Add csobsselect script (#1881)
Showing
12 changed files
with
715 additions
and
8 deletions
ChangeLog
NEWS
| 1 | 1 | New Features and Important Changes in ctools 1.2.0 |
| 2 | 2 | |
| 3 | -22 November 2016 | |
| 3 | +23 November 2016 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | Introduction |
| ... | ... | @@ -222,6 +222,9 @@ refactoring (#1873). |
| 222 | 222 | Added csmodelselect script that allows selecting models from a model definition |
| 223 | 223 | XML file (#1879). |
| 224 | 224 | |
| 225 | +Added csobsselect script that allows selecting observations from an observation | |
| 226 | +definition XML file (#1881). | |
| 227 | + | |
| 225 | 228 | |
| 226 | 229 | Examples |
| 227 | 230 | -------- | ... | ... |
cscripts/Makefile.am
| ... | ... | @@ -30,6 +30,7 @@ pythonscripts = $(builddir)/__init__.py \ |
| 30 | 30 | $(srcdir)/csobs2caldb.py \ |
| 31 | 31 | $(srcdir)/csobsdef.py \ |
| 32 | 32 | $(srcdir)/csobsinfo.py \ |
| 33 | + $(srcdir)/csobsselect.py \ | |
| 33 | 34 | $(srcdir)/cspull.py \ |
| 34 | 35 | $(srcdir)/csresmap.py \ |
| 35 | 36 | $(srcdir)/csroot2caldb.py \ |
| ... | ... | @@ -58,6 +59,7 @@ parfiles = $(srcdir)/cscaldb.par \ |
| 58 | 59 | $(srcdir)/csobs2caldb.par \ |
| 59 | 60 | $(srcdir)/csobsdef.par \ |
| 60 | 61 | $(srcdir)/csobsinfo.par \ |
| 62 | + $(srcdir)/csobsselect.par \ | |
| 61 | 63 | $(srcdir)/cspull.par \ |
| 62 | 64 | $(srcdir)/csresmap.par \ |
| 63 | 65 | $(srcdir)/csroot2caldb.par \ |
| ... | ... | @@ -83,6 +85,7 @@ linkscripts = cscaldb \ |
| 83 | 85 | csobs2caldb \ |
| 84 | 86 | csobsdef \ |
| 85 | 87 | csobsinfo \ |
| 88 | + csobsselect \ | |
| 86 | 89 | cspull \ |
| 87 | 90 | csresmap \ |
| 88 | 91 | csroot2caldb \ | ... | ... |
cscripts/__init__.py.in
| ... | ... | @@ -33,6 +33,7 @@ __all__ = [ |
| 33 | 33 | "csobs2caldb", |
| 34 | 34 | "csobsdef", |
| 35 | 35 | "csobsinfo", |
| 36 | + "csobsselect", | |
| 36 | 37 | "cspull", |
| 37 | 38 | "csresmap", |
| 38 | 39 | "csroot2caldb", |
| ... | ... | @@ -64,6 +65,7 @@ from cscripts.csmodelselect import csmodelselect |
| 64 | 65 | from cscripts.csobs2caldb import csobs2caldb |
| 65 | 66 | from cscripts.csobsdef import csobsdef |
| 66 | 67 | from cscripts.csobsinfo import csobsinfo |
| 68 | +from cscripts.csobsselect import csobsselect | |
| 67 | 69 | from cscripts.cspull import cspull |
| 68 | 70 | from cscripts.csresmap import csresmap |
| 69 | 71 | from cscripts.csroot2caldb import csroot2caldb | ... | ... |
cscripts/csmodelselect.py
| ... | ... | @@ -28,7 +28,7 @@ import ctools |
| 28 | 28 | # =================== # |
| 29 | 29 | class csmodelselect(ctools.cscript): |
| 30 | 30 | """ |
| 31 | - Selects model from a model container | |
| 31 | + Selects model from a model definition XML file | |
| 32 | 32 | """ |
| 33 | 33 | |
| 34 | 34 | # Constructor |
| ... | ... | @@ -97,7 +97,7 @@ class csmodelselect(ctools.cscript): |
| 97 | 97 | ---------- |
| 98 | 98 | model : `~gammalib.GModel` |
| 99 | 99 | Model |
| 100 | - obs : `~gammalib.GObservation` | |
| 100 | + obs : `~gammalib.GObservations` | |
| 101 | 101 | Observation container |
| 102 | 102 | |
| 103 | 103 | Returns |
| ... | ... | @@ -237,7 +237,7 @@ class csmodelselect(ctools.cscript): |
| 237 | 237 | models = gammalib.GModels() |
| 238 | 238 | |
| 239 | 239 | # Write input observation container into logger |
| 240 | - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation'); | |
| 240 | + self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') | |
| 241 | 241 | |
| 242 | 242 | # Write input models into logger |
| 243 | 243 | self._log_models(gammalib.VERBOSE, self._models, 'Input model') | ... | ... |
cscripts/csobsselect.par
0 → 100644
| 1 | +############################################################################# | |
| 2 | +# # | |
| 3 | +# CTA Science Analysis Tools # | |
| 4 | +# # | |
| 5 | +# ------------------------------------------------------------------------- # | |
| 6 | +# # | |
| 7 | +# File: csobsselect.par # | |
| 8 | +# # | |
| 9 | +# Author: Juergen Knoedlseder # | |
| 10 | +# jknodlseder@irap.omp.eu # | |
| 11 | +# IRAP, Toulouse, France # | |
| 12 | +# # | |
| 13 | +# Purpose: Parameter file for the csobsselect script # | |
| 14 | +# # | |
| 15 | +############################################################################# | |
| 16 | +# | |
| 17 | +# Input and output parameters | |
| 18 | +#============================ | |
| 19 | +inobs, f, a, obs.xml,,, "Input event list or observation definition XML file" | |
| 20 | +outobs, f, a, outobs.xml,,, "Output observation definition XML file" | |
| 21 | + | |
| 22 | +# | |
| 23 | +# Script parameters | |
| 24 | +#================== | |
| 25 | +pntselect, s, a, CIRCLE,CIRCLE|BOX,, "Pointing selection region shape" | |
| 26 | +coordsys, s, a, CEL,CEL|GAL,, "Coordinate system (CEL - celestial, GAL - galactic)" | |
| 27 | +ra, r, a, 83.63,0,360, "Right Ascension of selection centre (deg)" | |
| 28 | +dec, r, a, 22.01,-90,90, "Declination of selection centre (deg)" | |
| 29 | +glon, r, a, 184.56,0,360, "Galactic longitude of selection centre (deg)" | |
| 30 | +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)" | |
| 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)" | |
| 34 | + | |
| 35 | +# | |
| 36 | +# Standard parameters | |
| 37 | +#==================== | |
| 38 | +chatter, i, h, 2,0,4, "Chattiness of output" | |
| 39 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | |
| 40 | +debug, b, h, no,,, "Debugging mode activated" | |
| 41 | +mode, s, h, ql,,, "Mode of automatic parameters" | |
| 42 | +logfile, f, h, csobsselect.log,,, "Log filename" | ... | ... |
cscripts/csobsselect.py
0 → 100755
| 1 | +#!/usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Selects observations from an observation definition XML file | |
| 4 | +# | |
| 5 | +# Copyright (C) 2016 Juergen Knoedlseder | |
| 6 | +# | |
| 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 | |
| 9 | +# the Free Software Foundation, either version 3 of the License, or | |
| 10 | +# (at your option) any later version. | |
| 11 | +# | |
| 12 | +# This program is distributed in the hope that it will be useful, | |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | +# GNU General Public License for more details. | |
| 16 | +# | |
| 17 | +# You should have received a copy of the GNU General Public License | |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 19 | +# | |
| 20 | +# ========================================================================== | |
| 21 | +import sys | |
| 22 | +import gammalib | |
| 23 | +import ctools | |
| 24 | + | |
| 25 | + | |
| 26 | +# ================= # | |
| 27 | +# csobsselect class # | |
| 28 | +# ================= # | |
| 29 | +class csobsselect(ctools.cscript): | |
| 30 | + """ | |
| 31 | + Selects observations from an observation definition XML file | |
| 32 | + """ | |
| 33 | + | |
| 34 | + # Constructor | |
| 35 | + def __init__(self, *argv): | |
| 36 | + """ | |
| 37 | + Constructor | |
| 38 | + """ | |
| 39 | + # Set name | |
| 40 | + self._name = 'csobsselect' | |
| 41 | + self._version = '1.2.0' | |
| 42 | + | |
| 43 | + # Initialise observation container from constructor arguments | |
| 44 | + self._obs, argv = self._set_input_obs(argv) | |
| 45 | + | |
| 46 | + # Initialise application by calling the appropriate class constructor | |
| 47 | + self._init_cscript(argv) | |
| 48 | + | |
| 49 | + # Return | |
| 50 | + return | |
| 51 | + | |
| 52 | + | |
| 53 | + # Private methods | |
| 54 | + def _get_parameters(self): | |
| 55 | + """ | |
| 56 | + Get parameters from parfile and setup observations | |
| 57 | + """ | |
| 58 | + # Query input parameters | |
| 59 | + self['inobs'].filename() | |
| 60 | + | |
| 61 | + # Query relevant pointing selection parameters | |
| 62 | + pntselect = self['pntselect'].string() | |
| 63 | + coordsys = self['coordsys'].string() | |
| 64 | + if coordsys == 'CEL': | |
| 65 | + self['ra'].real() | |
| 66 | + self['dec'].real() | |
| 67 | + else: | |
| 68 | + self['glon'].real() | |
| 69 | + self['glat'].real() | |
| 70 | + if pntselect == 'CIRCLE': | |
| 71 | + self['rad'].real() | |
| 72 | + else: | |
| 73 | + self['width'].real() | |
| 74 | + self['height'].real() | |
| 75 | + | |
| 76 | + # Query ahead output model filename | |
| 77 | + if self._read_ahead(): | |
| 78 | + self['outobs'].filename() | |
| 79 | + | |
| 80 | + # If there are no observations in container then get them from the | |
| 81 | + # parameter file | |
| 82 | + if self._obs.size() == 0: | |
| 83 | + self._obs = self._get_observations(False) | |
| 84 | + | |
| 85 | + # Write input parameters into logger | |
| 86 | + self._log_parameters(gammalib.TERSE) | |
| 87 | + | |
| 88 | + # Return | |
| 89 | + return | |
| 90 | + | |
| 91 | + def _select_observation(self, obs): | |
| 92 | + """ | |
| 93 | + Select observation | |
| 94 | + | |
| 95 | + Parameters | |
| 96 | + ---------- | |
| 97 | + obs : `~gammalib.GObservation` | |
| 98 | + Observation | |
| 99 | + | |
| 100 | + Returns | |
| 101 | + ------- | |
| 102 | + select : bool | |
| 103 | + Observation selection flag | |
| 104 | + """ | |
| 105 | + # Initialise selection flag | |
| 106 | + select = False | |
| 107 | + | |
| 108 | + # Continue only if observation is a CTA observation | |
| 109 | + if obs.classname() == 'GCTAObservation': | |
| 110 | + | |
| 111 | + # Get selection type | |
| 112 | + pntselect = self['pntselect'].string() | |
| 113 | + | |
| 114 | + # Dispatch according to selection type | |
| 115 | + if pntselect == 'CIRCLE': | |
| 116 | + select = self._select_circle(obs) | |
| 117 | + else: | |
| 118 | + select = self._select_box(obs) | |
| 119 | + | |
| 120 | + # Return selection flag | |
| 121 | + return select | |
| 122 | + | |
| 123 | + def _select_circle(self, obs): | |
| 124 | + """ | |
| 125 | + Select observation in a pointing circle | |
| 126 | + | |
| 127 | + Parameters | |
| 128 | + ---------- | |
| 129 | + obs : `~gammalib.GCTAObservation` | |
| 130 | + CTA observation | |
| 131 | + | |
| 132 | + Returns | |
| 133 | + ------- | |
| 134 | + select : bool | |
| 135 | + Observation selection flag | |
| 136 | + """ | |
| 137 | + # Get coordinate system of selection circle | |
| 138 | + coordsys = self['coordsys'].string() | |
| 139 | + | |
| 140 | + # Get pointing direction | |
| 141 | + pnt = obs.pointing().dir() | |
| 142 | + | |
| 143 | + # Set selection circle centre | |
| 144 | + centre = gammalib.GSkyDir() | |
| 145 | + if coordsys == 'CEL': | |
| 146 | + centre.radec_deg(self['ra'].real(), self['dec'].real()) | |
| 147 | + else: | |
| 148 | + centre.lb_deg(self['glon'].real(), self['glat'].real()) | |
| 149 | + | |
| 150 | + # Set selection flag according to distance | |
| 151 | + if centre.dist_deg(pnt) <= self['rad'].real(): | |
| 152 | + select = True | |
| 153 | + msg = 'inside selection circle' | |
| 154 | + else: | |
| 155 | + select = False | |
| 156 | + msg = 'outside selection circle' | |
| 157 | + | |
| 158 | + # Set observation name | |
| 159 | + if len(obs.name()) > 0: | |
| 160 | + name = obs.name() | |
| 161 | + else: | |
| 162 | + name = 'Observation' | |
| 163 | + | |
| 164 | + # Prepend obervation ID | |
| 165 | + if len(obs.id()) > 0: | |
| 166 | + msg = obs.id()+' '+msg | |
| 167 | + | |
| 168 | + # Log observation selection | |
| 169 | + self._log_value(gammalib.NORMAL, name, msg) | |
| 170 | + | |
| 171 | + # Return selection flag | |
| 172 | + return select | |
| 173 | + | |
| 174 | + def _select_box(self, obs): | |
| 175 | + """ | |
| 176 | + Select observation in a pointing box | |
| 177 | + | |
| 178 | + Parameters | |
| 179 | + ---------- | |
| 180 | + obs : `~gammalib.GCTAObservation` | |
| 181 | + CTA observation | |
| 182 | + | |
| 183 | + Returns | |
| 184 | + ------- | |
| 185 | + select : bool | |
| 186 | + Observation selection flag | |
| 187 | + """ | |
| 188 | + # Initialise selection flag | |
| 189 | + select = False | |
| 190 | + msg = 'outside selection box' | |
| 191 | + | |
| 192 | + # Get coordinate system of selection circle | |
| 193 | + coordsys = self['coordsys'].string() | |
| 194 | + | |
| 195 | + # Get pointing direction | |
| 196 | + pnt = obs.pointing().dir() | |
| 197 | + | |
| 198 | + # Get selection box width and height | |
| 199 | + width = self['width'].real() | |
| 200 | + height = self['height'].real() | |
| 201 | + | |
| 202 | + # Make selection for celestial coordinates ... | |
| 203 | + if coordsys == 'CEL': | |
| 204 | + | |
| 205 | + # Determine box boundaries | |
| 206 | + ra = self['ra'].real() | |
| 207 | + dec = self['dec'].real() | |
| 208 | + ra_min = ra - 0.5 * width | |
| 209 | + ra_max = ra + 0.5 * width | |
| 210 | + dec_min = dec - 0.5 * height | |
| 211 | + dec_max = dec + 0.5 * height | |
| 212 | + | |
| 213 | + # Check if pointing lies within boundaries | |
| 214 | + ra = pnt.ra_deg() | |
| 215 | + ra_plus = ra + 360.0 | |
| 216 | + ra_minus = ra - 360.0 | |
| 217 | + dec = pnt.dec_deg() | |
| 218 | + if dec >= dec_min and dec <= dec_max: | |
| 219 | + if ra >= ra_min and ra <= ra_max or \ | |
| 220 | + ra_plus >= ra_min and ra_plus <= ra_max or \ | |
| 221 | + ra_minus >= ra_min and ra_minus <= ra_max: | |
| 222 | + select = True | |
| 223 | + msg = 'inside selection box' | |
| 224 | + | |
| 225 | + # ... or galactic coordinates | |
| 226 | + else: | |
| 227 | + | |
| 228 | + # Determine box boundaries | |
| 229 | + glon = self['glon'].real() | |
| 230 | + glat = self['glat'].real() | |
| 231 | + glon_min = glon - 0.5 * width | |
| 232 | + glon_max = glon + 0.5 * width | |
| 233 | + glat_min = glat - 0.5 * height | |
| 234 | + glat_max = glat + 0.5 * height | |
| 235 | + | |
| 236 | + # Check if pointing lies within boundaries | |
| 237 | + glon = pnt.l_deg() | |
| 238 | + glon_plus = glon + 360.0 | |
| 239 | + glon_minus = glon - 360.0 | |
| 240 | + glat = pnt.b_deg() | |
| 241 | + if glat >= glat_min and glat <= glat_max: | |
| 242 | + if glon >= glon_min and glon <= glon_max or \ | |
| 243 | + glon_plus >= glon_min and glon_plus <= glon_max or \ | |
| 244 | + glon_minus >= glon_min and glon_minus <= glon_max: | |
| 245 | + select = True | |
| 246 | + msg = 'inside selection box' | |
| 247 | + | |
| 248 | + # Set observation name | |
| 249 | + if len(obs.name()) > 0: | |
| 250 | + name = obs.name() | |
| 251 | + else: | |
| 252 | + name = 'Observation' | |
| 253 | + | |
| 254 | + # Prepend obervation ID | |
| 255 | + if len(obs.id()) > 0: | |
| 256 | + msg = obs.id()+' '+msg | |
| 257 | + | |
| 258 | + # Log observation selection | |
| 259 | + self._log_value(gammalib.NORMAL, name, msg) | |
| 260 | + | |
| 261 | + # Return selection flag | |
| 262 | + return select | |
| 263 | + | |
| 264 | + | |
| 265 | + # Public methods | |
| 266 | + def run(self): | |
| 267 | + """ | |
| 268 | + Run the script | |
| 269 | + """ | |
| 270 | + # Switch screen logging on in debug mode | |
| 271 | + if self._logDebug(): | |
| 272 | + self._log.cout(True) | |
| 273 | + | |
| 274 | + # Get parameters | |
| 275 | + self._get_parameters() | |
| 276 | + | |
| 277 | + # Initialise empty observation container for selected observations | |
| 278 | + selected_obs = gammalib.GObservations() | |
| 279 | + | |
| 280 | + # Write input observation container into logger | |
| 281 | + self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') | |
| 282 | + | |
| 283 | + # Write header | |
| 284 | + self._log_header1(gammalib.NORMAL, 'Observation selection') | |
| 285 | + | |
| 286 | + # Loop over observations | |
| 287 | + for obs in self._obs: | |
| 288 | + | |
| 289 | + # If observation is selected then append observation | |
| 290 | + if self._select_observation(obs): | |
| 291 | + selected_obs.append(obs) | |
| 292 | + | |
| 293 | + # Copy selected observations into observation | |
| 294 | + self._obs = selected_obs | |
| 295 | + | |
| 296 | + # Write input observation container into logger | |
| 297 | + self._log_observations(gammalib.NORMAL, self._obs, 'Selected observation') | |
| 298 | + | |
| 299 | + # Return | |
| 300 | + return | |
| 301 | + | |
| 302 | + def save(self): | |
| 303 | + """ | |
| 304 | + Save observation definition XML file | |
| 305 | + """ | |
| 306 | + # Write header | |
| 307 | + self._log_header1(gammalib.TERSE, 'Save observations') | |
| 308 | + | |
| 309 | + # Get output filename | |
| 310 | + outobs = self['outobs'].filename() | |
| 311 | + | |
| 312 | + # If file exists and clobber flag is false then raise an exception | |
| 313 | + if outobs.exists() and not self._clobber: | |
| 314 | + msg = ('Cannot save "'+outobs.url()+'": File already exists. ' | |
| 315 | + 'Use parameter clobber=yes to allow overwriting of files.') | |
| 316 | + raise RuntimeError(msg) | |
| 317 | + | |
| 318 | + # Otherwise log filename and save file | |
| 319 | + else: | |
| 320 | + # Log filename | |
| 321 | + self._log_value(gammalib.NORMAL, 'Observation definition XML file', | |
| 322 | + outobs.url()) | |
| 323 | + | |
| 324 | + # Save observations | |
| 325 | + self._obs.save(outobs) | |
| 326 | + | |
| 327 | + # Return | |
| 328 | + return | |
| 329 | + | |
| 330 | + def execute(self): | |
| 331 | + """ | |
| 332 | + Execute the script | |
| 333 | + """ | |
| 334 | + # Open logfile | |
| 335 | + self.logFileOpen() | |
| 336 | + | |
| 337 | + # Read ahead output parameters | |
| 338 | + self._read_ahead(True) | |
| 339 | + | |
| 340 | + # Run the script | |
| 341 | + self.run() | |
| 342 | + | |
| 343 | + # Save observation definition file | |
| 344 | + self.save() | |
| 345 | + | |
| 346 | + # Return | |
| 347 | + return | |
| 348 | + | |
| 349 | + | |
| 350 | +# ======================== # | |
| 351 | +# Main routine entry point # | |
| 352 | +# ======================== # | |
| 353 | +if __name__ == '__main__': | |
| 354 | + | |
| 355 | + # Create instance of application | |
| 356 | + app = csobsselect(sys.argv) | |
| 357 | + | |
| 358 | + # Execute application | |
| 359 | + app.execute() | ... | ... |
doc/source/users/reference_manual/csmodelselect.rst
| ... | ... | @@ -30,10 +30,10 @@ General parameters |
| 30 | 30 | Output model definition XML file |
| 31 | 31 | |
| 32 | 32 | ``(roilimit = 4.5) [real]`` |
| 33 | - Maximum RoI radius (deg) | |
| 33 | + Maximum RoI radius (degrees) | |
| 34 | 34 | |
| 35 | 35 | ``(roimargin = 0.1) [real]`` |
| 36 | - Radial margin to be added to RoIs (deg) | |
| 36 | + Radial margin to be added to RoIs (degrees) | |
| 37 | 37 | |
| 38 | 38 | ``(ethres = 0.1) [real]`` |
| 39 | 39 | Energy threshold for source flux selection (TeV) |
| ... | ... | @@ -83,4 +83,4 @@ Standard parameters |
| 83 | 83 | Related tools or scripts |
| 84 | 84 | ------------------------ |
| 85 | 85 | |
| 86 | -None | |
| 86 | +:doc:`csobsselect` | ... | ... |
doc/source/users/reference_manual/csobsselect.rst
0 → 100644
| 1 | +.. _csobsselect: | |
| 2 | + | |
| 3 | +csobsselect | |
| 4 | +=========== | |
| 5 | + | |
| 6 | +Selects observations from an observation definition XML file. | |
| 7 | + | |
| 8 | + | |
| 9 | +Synopsis | |
| 10 | +-------- | |
| 11 | + | |
| 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. | |
| 16 | + | |
| 17 | + | |
| 18 | +General parameters | |
| 19 | +------------------ | |
| 20 | + | |
| 21 | +``inobs [file]`` | |
| 22 | + Input event list or observation definition XML file | |
| 23 | + | |
| 24 | +``outobs [file]`` | |
| 25 | + Output observation definition XML file | |
| 26 | + | |
| 27 | +``pntselect <CIRCLE|BOX> [string]`` | |
| 28 | + Pointing selection region shape | |
| 29 | + | |
| 30 | +``coordsys <CEL|GAL> [string]`` | |
| 31 | + Coordinate system (CEL - celestial, GAL - galactic) | |
| 32 | + | |
| 33 | +``ra [real]`` | |
| 34 | + Right Ascension of pointing selection centre (J2000, in degrees) | |
| 35 | + | |
| 36 | +``dec [real]`` | |
| 37 | + Declination of pointing selection centre (J2000, in degrees) | |
| 38 | + | |
| 39 | +``glon [real]`` | |
| 40 | + Galactic longitude of pointing selection centre (degrees) | |
| 41 | + | |
| 42 | +``glat [real]`` | |
| 43 | + Galactic latitude of pointing selection centre (degrees) | |
| 44 | + | |
| 45 | +``rad [real]`` | |
| 46 | + Radius of selection circle (degrees) | |
| 47 | + | |
| 48 | +``width [real]`` | |
| 49 | + Width of selection box (degrees) | |
| 50 | + | |
| 51 | +``height [real]`` | |
| 52 | + Height of selection box (degrees) | |
| 53 | + | |
| 54 | + | |
| 55 | +Standard parameters | |
| 56 | +------------------- | |
| 57 | + | |
| 58 | +``(chatter = 2) [integer]`` | |
| 59 | + Verbosity of the executable: | |
| 60 | + chatter = 0: no information will be logged | |
| 61 | + | |
| 62 | + chatter = 1: only errors will be logged | |
| 63 | + | |
| 64 | + chatter = 2: errors and actions will be logged | |
| 65 | + | |
| 66 | + chatter = 3: report about the task execution | |
| 67 | + | |
| 68 | + chatter = 4: detailed report about the task execution | |
| 69 | + | |
| 70 | +``(clobber = yes) [boolean]`` | |
| 71 | + Specifies whether an existing output model file should be overwritten | |
| 72 | + | |
| 73 | +``(debug = no) [boolean]`` | |
| 74 | + Enables debug mode. In debug mode the executable will dump any log file | |
| 75 | + output to the console | |
| 76 | + | |
| 77 | +``(mode = ql) [string]`` | |
| 78 | + Mode of automatic parameters (default is "ql", i.e. "query and learn") | |
| 79 | + | |
| 80 | +``(logfile = csobsselect.log) [filename]`` | |
| 81 | + Log filename | |
| 82 | + | |
| 83 | + | |
| 84 | +Related tools or scripts | |
| 85 | +------------------------ | |
| 86 | + | |
| 87 | +:doc:`csmodelselect` | |
| 88 | + | ... | ... |
doc/source/users/reference_manual/index.rst
| ... | ... | @@ -47,6 +47,7 @@ cscripts |
| 47 | 47 | csmodelselect --- Select models from model definition file <csmodelselect> |
| 48 | 48 | csobsdef --- Generates observation definition file <csobsdef> |
| 49 | 49 | csobsinfo --- Shows observation container content <csobsinfo> |
| 50 | + csobsselect --- Select observations from observation definition file <csobsselect> | |
| 50 | 51 | cspull --- Generates pull distribution <cspull> |
| 51 | 52 | csresmap --- Generates residual map <csresmap> |
| 52 | 53 | cssens --- Computes CTA sensitivity <cssens> | ... | ... |
test/test_csobsselect.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# This scripts performs unit tests for the csobsselect script | |
| 4 | +# | |
| 5 | +# Copyright (C) 2016 Juergen Knoedlseder | |
| 6 | +# | |
| 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 | |
| 9 | +# the Free Software Foundation, either version 3 of the License, or | |
| 10 | +# (at your option) any later version. | |
| 11 | +# | |
| 12 | +# This program is distributed in the hope that it will be useful, | |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | +# GNU General Public License for more details. | |
| 16 | +# | |
| 17 | +# You should have received a copy of the GNU General Public License | |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 19 | +# | |
| 20 | +# ========================================================================== | |
| 21 | +import os | |
| 22 | +import gammalib | |
| 23 | +import cscripts | |
| 24 | +from testing import test | |
| 25 | + | |
| 26 | + | |
| 27 | +# ================================= # | |
| 28 | +# Test class for csobsselect script # | |
| 29 | +# ================================= # | |
| 30 | +class Test(test): | |
| 31 | + """ | |
| 32 | + Test class for csobsselect script | |
| 33 | + | |
| 34 | + This test class makes unit tests for the csobsselect script by using it | |
| 35 | + from the command line and from Python. | |
| 36 | + """ | |
| 37 | + | |
| 38 | + # Constructor | |
| 39 | + def __init__(self): | |
| 40 | + """ | |
| 41 | + Constructor. | |
| 42 | + """ | |
| 43 | + # Call base class constructor | |
| 44 | + test.__init__(self) | |
| 45 | + | |
| 46 | + # Return | |
| 47 | + return | |
| 48 | + | |
| 49 | + # Set test functions | |
| 50 | + def set(self): | |
| 51 | + """ | |
| 52 | + Set all test functions. | |
| 53 | + """ | |
| 54 | + # Set test name | |
| 55 | + self.name('csobsselect') | |
| 56 | + | |
| 57 | + # Append tests | |
| 58 | + self.append(self._test_cmd, 'Test csobsselect on command line') | |
| 59 | + self.append(self._test_python, 'Test csobsselect from Python') | |
| 60 | + | |
| 61 | + # Return | |
| 62 | + return | |
| 63 | + | |
| 64 | + # Test csobsselect on command line | |
| 65 | + def _test_cmd(self): | |
| 66 | + """ | |
| 67 | + Test csobsselect on the command line | |
| 68 | + """ | |
| 69 | + # Set script name | |
| 70 | + csobsselect = self._script('csobsselect') | |
| 71 | + | |
| 72 | + # Setup csobsselect command | |
| 73 | + cmd = csobsselect+' inobs="'+self._events+'"'+ \ | |
| 74 | + ' outobs="csobsselect_cmd1.xml"'+ \ | |
| 75 | + ' pntselect="CIRCLE" coordsys="CEL" ra=83.63'+ \ | |
| 76 | + ' dec=22.01 rad=5.0'+ \ | |
| 77 | + ' logfile="csobsselect_cmd1.log" chatter=1' | |
| 78 | + | |
| 79 | + # Check if execution of wrong command fails | |
| 80 | + self.test_assert(self._execute('command_that_does_not_exist') != 0, | |
| 81 | + 'Self test of test script') | |
| 82 | + | |
| 83 | + # Check if execution was successful | |
| 84 | + self.test_assert(self._execute(cmd) == 0, | |
| 85 | + 'Check successful execution from command line') | |
| 86 | + | |
| 87 | + # Check observation definition file | |
| 88 | + self._check_observation_file('csobsselect_cmd1.xml', 1) | |
| 89 | + | |
| 90 | + # Setup csobsselect command | |
| 91 | + cmd = csobsselect+' inobs="observation_that_does_not_exist.xml"'+ \ | |
| 92 | + ' outobs="csobsselect_cmd2.xml"'+ \ | |
| 93 | + ' pntselect="CIRCLE" coordsys="CEL" ra=83.63'+ \ | |
| 94 | + ' dec=22.01 rad=5.0'+ \ | |
| 95 | + ' logfile="csobsselect_cmd2.log" chatter=2' | |
| 96 | + | |
| 97 | + # Check if execution failed | |
| 98 | + self.test_assert(self._execute(cmd) != 0, | |
| 99 | + 'Check invalid input file when executed from command line') | |
| 100 | + | |
| 101 | + # Return | |
| 102 | + return | |
| 103 | + | |
| 104 | + # Test csobsselect from Python | |
| 105 | + def _test_python(self): | |
| 106 | + """ | |
| 107 | + Test csobsselect from Python | |
| 108 | + """ | |
| 109 | + # Allocate empty csobsselect script | |
| 110 | + obsselect = cscripts.csobsselect() | |
| 111 | + | |
| 112 | + # Check that saving does not nothing | |
| 113 | + obsselect['outobs'] = 'csobsselect_py0.xml' | |
| 114 | + obsselect['logfile'] = 'csobsselect_py0.log' | |
| 115 | + obsselect.logFileOpen() | |
| 116 | + obsselect.save() | |
| 117 | + | |
| 118 | + # Check than an empty observation definition file has been created | |
| 119 | + self._check_observation_file('csobsselect_py0.xml', 0) | |
| 120 | + | |
| 121 | + # Check that clearing does not lead to an exception or segfault | |
| 122 | + obsselect.clear() | |
| 123 | + | |
| 124 | + # Now set csobsselect parameters | |
| 125 | + obsselect['inobs'] = self._events | |
| 126 | + obsselect['outobs'] = 'csobsselect_py1.xml' | |
| 127 | + obsselect['pntselect'] = 'CIRCLE' | |
| 128 | + obsselect['coordsys'] = 'CEL' | |
| 129 | + obsselect['ra'] = 83.63 | |
| 130 | + obsselect['dec'] = 22.01 | |
| 131 | + obsselect['rad'] = 5.0 | |
| 132 | + obsselect['logfile'] = 'csobsselect_py1.log' | |
| 133 | + obsselect['chatter'] = 2 | |
| 134 | + | |
| 135 | + # Run csobsselect script and save observations | |
| 136 | + obsselect.logFileOpen() # Make sure we get a log file | |
| 137 | + obsselect.run() | |
| 138 | + obsselect.save() | |
| 139 | + | |
| 140 | + # Check model file | |
| 141 | + self._check_observation_file('csobsselect_py1.xml', 1) | |
| 142 | + | |
| 143 | + # Execute csobsselect script again, now in Galactic coordinates | |
| 144 | + obsselect['outobs'] = 'csobsselect_py2.xml' | |
| 145 | + obsselect['pntselect'] = 'CIRCLE' | |
| 146 | + obsselect['coordsys'] = 'GAL' | |
| 147 | + obsselect['glon'] = 184.56 | |
| 148 | + obsselect['glat'] = -5.79 | |
| 149 | + obsselect['rad'] = 5.0 | |
| 150 | + obsselect['logfile'] = 'csobsselect_py2.log' | |
| 151 | + obsselect['chatter'] = 3 | |
| 152 | + obsselect.logFileOpen() # Needed to get a new log file | |
| 153 | + obsselect.execute() | |
| 154 | + | |
| 155 | + # Check model file | |
| 156 | + self._check_observation_file('csobsselect_py2.xml', 1) | |
| 157 | + | |
| 158 | + # Execute csobsselect script again, now a box in Galactic coordinates | |
| 159 | + obsselect['outobs'] = 'csobsselect_py3.xml' | |
| 160 | + obsselect['pntselect'] = 'BOX' | |
| 161 | + obsselect['coordsys'] = 'GAL' | |
| 162 | + obsselect['glon'] = 184.56 | |
| 163 | + obsselect['glat'] = -5.79 | |
| 164 | + obsselect['width'] = 5.0 | |
| 165 | + obsselect['height'] = 5.0 | |
| 166 | + obsselect['logfile'] = 'csobsselect_py3.log' | |
| 167 | + obsselect['chatter'] = 4 | |
| 168 | + obsselect.logFileOpen() # Needed to get a new log file | |
| 169 | + obsselect.execute() | |
| 170 | + | |
| 171 | + # Check model file | |
| 172 | + self._check_observation_file('csobsselect_py3.xml', 1) | |
| 173 | + | |
| 174 | + # Execute csobsselect script again, now a box in celestial coordinates | |
| 175 | + obsselect['outobs'] = 'csobsselect_py4.xml' | |
| 176 | + obsselect['pntselect'] = 'BOX' | |
| 177 | + obsselect['coordsys'] = 'CEL' | |
| 178 | + obsselect['ra'] = 83.63 | |
| 179 | + obsselect['dec'] = 22.01 | |
| 180 | + obsselect['width'] = 5.0 | |
| 181 | + obsselect['height'] = 5.0 | |
| 182 | + obsselect['logfile'] = 'csobsselect_py4.log' | |
| 183 | + obsselect['chatter'] = 4 | |
| 184 | + obsselect.logFileOpen() # Needed to get a new log file | |
| 185 | + obsselect.execute() | |
| 186 | + | |
| 187 | + # Check model file | |
| 188 | + self._check_observation_file('csobsselect_py4.xml', 1) | |
| 189 | + | |
| 190 | + # Return | |
| 191 | + return | |
| 192 | + | |
| 193 | + # Check observation definition file | |
| 194 | + def _check_observation_file(self, filename, number): | |
| 195 | + """ | |
| 196 | + Check observation definition file | |
| 197 | + """ | |
| 198 | + # Open observations | |
| 199 | + obs = gammalib.GObservations(filename) | |
| 200 | + | |
| 201 | + # Check number of models | |
| 202 | + self.test_value(obs.size(), number, 'Check for '+str(number)+ | |
| 203 | + ' observations in XML file') | |
| 204 | + | |
| 205 | + # Return | |
| 206 | + return | ... | ... |
test/test_python_cscripts.py
| ... | ... | @@ -34,6 +34,7 @@ import test_csmodelselect |
| 34 | 34 | import test_csobs2caldb |
| 35 | 35 | import test_csobsdef |
| 36 | 36 | import test_csobsinfo |
| 37 | +import test_csobsselect | |
| 37 | 38 | import test_cspull |
| 38 | 39 | import test_csresmap |
| 39 | 40 | import test_csroot2caldb |
| ... | ... | @@ -119,6 +120,7 @@ def test(installed=False, debug=False): |
| 119 | 120 | test_csobs2caldb.Test(), |
| 120 | 121 | test_csobsdef.Test(), |
| 121 | 122 | test_csobsinfo.Test(), |
| 123 | + test_csobsselect.Test(), | |
| 122 | 124 | test_cspull.Test(), |
| 123 | 125 | test_csresmap.Test(), |
| 124 | 126 | test_csroot2caldb.Test(), | ... | ... |