Commit 699cd5ee3b15244fb29f7a2f29b9572a0083a7c4
1 parent
9dc564c7
The following scripts now have csobservation as base class: csebins, csmodelsele…
…ct, csobs2caldb, csobsinfo, csobsselect, and csphagen. The script cstsmapsplit has cslikelihood as base class.
Showing
11 changed files
with
104 additions
and
180 deletions
cscripts/csebins.py
| ... | ... | @@ -27,7 +27,7 @@ import ctools |
| 27 | 27 | # ============= # |
| 28 | 28 | # csebins class # |
| 29 | 29 | # ============= # |
| 30 | -class csebins(ctools.cscript): | |
| 30 | +class csebins(ctools.csobservation): | |
| 31 | 31 | """ |
| 32 | 32 | Generates energy boundaries for stacked analysis |
| 33 | 33 | """ |
| ... | ... | @@ -37,19 +37,12 @@ class csebins(ctools.cscript): |
| 37 | 37 | """ |
| 38 | 38 | Constructor |
| 39 | 39 | """ |
| 40 | - # Set name and version | |
| 41 | - self._name = 'csebins' | |
| 42 | - self._version = ctools.__version__ | |
| 40 | + # Initialise application by calling the appropriate class constructor | |
| 41 | + self._init_csobservation('csebins', ctools.__version__, argv) | |
| 43 | 42 | |
| 44 | 43 | # Set members |
| 45 | 44 | self._ebounds = gammalib.GEbounds() |
| 46 | 45 | |
| 47 | - # Initialise observation container from constructor arguments. | |
| 48 | - self._obs, argv = self._set_input_obs(argv) | |
| 49 | - | |
| 50 | - # Initialise script by calling the appropriate class constructor. | |
| 51 | - self._init_cscript(argv) | |
| 52 | - | |
| 53 | 46 | # Return |
| 54 | 47 | return |
| 55 | 48 | |
| ... | ... | @@ -60,7 +53,7 @@ class csebins(ctools.cscript): |
| 60 | 53 | Get parameters from parfile |
| 61 | 54 | """ |
| 62 | 55 | # Initialise observation container if it is currently empty |
| 63 | - if self._obs.size() == 0: | |
| 56 | + if self.obs().size() == 0: | |
| 64 | 57 | |
| 65 | 58 | # Query "inobs" parameter |
| 66 | 59 | filename = self['inobs'].filename() |
| ... | ... | @@ -68,13 +61,13 @@ class csebins(ctools.cscript): |
| 68 | 61 | # If an observation definition file was provided then load it, |
| 69 | 62 | # otherwise build a single observation with response information |
| 70 | 63 | if self._is_valid_filename(filename): |
| 71 | - self._obs = gammalib.GObservations(filename) | |
| 64 | + self.obs(gammalib.GObservations(filename)) | |
| 72 | 65 | else: |
| 73 | 66 | cta = gammalib.GCTAObservation() |
| 74 | 67 | caldb = gammalib.GCaldb('cta', self['caldb'].string()) |
| 75 | 68 | rsp = gammalib.GCTAResponseIrf(self['irf'].string(), caldb) |
| 76 | 69 | cta.response(rsp) |
| 77 | - self._obs.append(cta) | |
| 70 | + self.obs().append(cta) | |
| 78 | 71 | |
| 79 | 72 | # Query input parameters |
| 80 | 73 | self['emin'].real() |
| ... | ... | @@ -260,13 +253,13 @@ class csebins(ctools.cscript): |
| 260 | 253 | self._get_parameters() |
| 261 | 254 | |
| 262 | 255 | # Write observation into logger |
| 263 | - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') | |
| 256 | + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') | |
| 264 | 257 | |
| 265 | 258 | # Write header |
| 266 | 259 | self._log_header1(gammalib.TERSE, 'Define energy boundaries') |
| 267 | 260 | |
| 268 | 261 | # Define energy boundaries for observation container |
| 269 | - self._set_ebounds(self._obs) | |
| 262 | + self._set_ebounds(self.obs()) | |
| 270 | 263 | |
| 271 | 264 | # Return |
| 272 | 265 | return | ... | ... |
cscripts/csmodelselect.py
| ... | ... | @@ -26,7 +26,7 @@ import ctools |
| 26 | 26 | # =================== # |
| 27 | 27 | # csmodelselect class # |
| 28 | 28 | # =================== # |
| 29 | -class csmodelselect(ctools.cscript): | |
| 29 | +class csmodelselect(ctools.csobservation): | |
| 30 | 30 | """ |
| 31 | 31 | Selects model from a model definition XML file |
| 32 | 32 | """ |
| ... | ... | @@ -36,19 +36,13 @@ class csmodelselect(ctools.cscript): |
| 36 | 36 | """ |
| 37 | 37 | Constructor |
| 38 | 38 | """ |
| 39 | + # Initialise application by calling the appropriate class constructor | |
| 40 | + self._init_csobservation('csmodelselect', ctools.__version__, argv) | |
| 39 | 41 | # Set name |
| 40 | - self._name = 'csmodelselect' | |
| 41 | - self._version = ctools.__version__ | |
| 42 | - | |
| 43 | - # Initialise observation container from constructor arguments | |
| 44 | - self._obs, argv = self._set_input_obs(argv) | |
| 45 | 42 | |
| 46 | 43 | # Initialise class members |
| 47 | 44 | self._models = gammalib.GModels() |
| 48 | 45 | |
| 49 | - # Initialise application by calling the appropriate class constructor | |
| 50 | - self._init_cscript(argv) | |
| 51 | - | |
| 52 | 46 | # Return |
| 53 | 47 | return |
| 54 | 48 | |
| ... | ... | @@ -77,8 +71,8 @@ class csmodelselect(ctools.cscript): |
| 77 | 71 | |
| 78 | 72 | # If there are no observations in container then get them from the |
| 79 | 73 | # parameter file |
| 80 | - if self._obs.size() == 0: | |
| 81 | - self._obs = self._get_observations(False) | |
| 74 | + if self.obs().size() == 0: | |
| 75 | + self.obs(self._get_observations(False)) | |
| 82 | 76 | |
| 83 | 77 | # Get models |
| 84 | 78 | self._models = gammalib.GModels(self['inmodel'].filename()) |
| ... | ... | @@ -237,10 +231,10 @@ class csmodelselect(ctools.cscript): |
| 237 | 231 | models = gammalib.GModels() |
| 238 | 232 | |
| 239 | 233 | # Write input observation container into logger |
| 240 | - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') | |
| 234 | + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') | |
| 241 | 235 | |
| 242 | 236 | # Write input models into logger |
| 243 | - self._log_models(gammalib.VERBOSE, self._models, 'Input model') | |
| 237 | + self._log_models(gammalib.NORMAL, self._models, 'Input model') | |
| 244 | 238 | |
| 245 | 239 | # Write header |
| 246 | 240 | self._log_header1(gammalib.NORMAL, 'Model selection') |
| ... | ... | @@ -250,7 +244,7 @@ class csmodelselect(ctools.cscript): |
| 250 | 244 | |
| 251 | 245 | # If model should be selected then set model parameters and append |
| 252 | 246 | # model to the output container |
| 253 | - if self._select_model(model, self._obs): | |
| 247 | + if self._select_model(model, self.obs()): | |
| 254 | 248 | |
| 255 | 249 | # Set model parameters |
| 256 | 250 | model = self._set_model_parameters(model) |
| ... | ... | @@ -262,7 +256,7 @@ class csmodelselect(ctools.cscript): |
| 262 | 256 | self._models = models |
| 263 | 257 | |
| 264 | 258 | # Write selected models into logger |
| 265 | - self._log_models(gammalib.VERBOSE, self._models, 'Selected model') | |
| 259 | + self._log_models(gammalib.NORMAL, self._models, 'Selected model') | |
| 266 | 260 | |
| 267 | 261 | # Return |
| 268 | 262 | return | ... | ... |
cscripts/csobs2caldb.py
| ... | ... | @@ -29,7 +29,7 @@ from cscripts import calutils |
| 29 | 29 | # ================= # |
| 30 | 30 | # csobs2caldb class # |
| 31 | 31 | # ================= # |
| 32 | -class csobs2caldb(ctools.cscript): | |
| 32 | +class csobs2caldb(ctools.csobservation): | |
| 33 | 33 | """ |
| 34 | 34 | Creates a calibration database entry for an IACT observation. |
| 35 | 35 | |
| ... | ... | @@ -46,9 +46,8 @@ class csobs2caldb(ctools.cscript): |
| 46 | 46 | """ |
| 47 | 47 | Constructor |
| 48 | 48 | """ |
| 49 | - # Set name and version | |
| 50 | - self._name = 'csobs2caldb' | |
| 51 | - self._version = ctools.__version__ | |
| 49 | + # Initialise application by calling the appropriate class constructor | |
| 50 | + self._init_csobservation('csobs2caldb', ctools.__version__, argv) | |
| 52 | 51 | |
| 53 | 52 | # Initialise members |
| 54 | 53 | self._observation = gammalib.GCTAObservation() |
| ... | ... | @@ -61,12 +60,6 @@ class csobs2caldb(ctools.cscript): |
| 61 | 60 | self._caldb_inx = gammalib.GFits() |
| 62 | 61 | self._irf_fits = gammalib.GFits() |
| 63 | 62 | |
| 64 | - # Initialise observation container from constructor arguments. | |
| 65 | - self._obs, argv = self._set_input_obs(argv) | |
| 66 | - | |
| 67 | - # Initialise script by calling the appropriate class constructor. | |
| 68 | - self._init_cscript(argv) | |
| 69 | - | |
| 70 | 63 | # Return |
| 71 | 64 | return |
| 72 | 65 | |
| ... | ... | @@ -81,11 +74,11 @@ class csobs2caldb(ctools.cscript): |
| 81 | 74 | """ |
| 82 | 75 | # Load observation container from "inobs" parameter in case that |
| 83 | 76 | # the observation container is still empty. |
| 84 | - if self._obs.is_empty(): | |
| 85 | - self._obs = gammalib.GObservations(self['inobs'].filename()) | |
| 77 | + if self.obs().is_empty(): | |
| 78 | + self.obs(gammalib.GObservations(self['inobs'].filename())) | |
| 86 | 79 | |
| 87 | 80 | # Raise an exception if the observation container is empty |
| 88 | - if self._obs.is_empty(): | |
| 81 | + if self.obs().is_empty(): | |
| 89 | 82 | raise ValueError('No or empty observation provided for ' |
| 90 | 83 | 'parameter "inobs".') |
| 91 | 84 | |
| ... | ... | @@ -93,12 +86,12 @@ class csobs2caldb(ctools.cscript): |
| 93 | 86 | index = self['index'].integer() |
| 94 | 87 | |
| 95 | 88 | # Raise an exception if the index is not valid |
| 96 | - if index < 0 or index >= self._obs.size(): | |
| 89 | + if index < 0 or index >= self.obs().size(): | |
| 97 | 90 | raise IndexError('Parameter "index=%d" outside the validity ' |
| 98 | - 'range [0,%d].' % (index, self._obs.size())) | |
| 91 | + 'range [0,%d].' % (index, self.obs().size())) | |
| 99 | 92 | |
| 100 | 93 | # Get observation |
| 101 | - self._observation = self._obs[index] | |
| 94 | + self._observation = self.obs()[index] | |
| 102 | 95 | |
| 103 | 96 | # Make sure we have a CTA observation |
| 104 | 97 | if not self._observation.classname() == 'GCTAObservation': | ... | ... |
cscripts/csobsinfo.py
| ... | ... | @@ -26,7 +26,7 @@ import ctools |
| 26 | 26 | # =============== # |
| 27 | 27 | # csobsinfo class # |
| 28 | 28 | # =============== # |
| 29 | -class csobsinfo(ctools.cscript): | |
| 29 | +class csobsinfo(ctools.csobservation): | |
| 30 | 30 | """ |
| 31 | 31 | Shows the content of an observation container |
| 32 | 32 | """ |
| ... | ... | @@ -36,9 +36,8 @@ class csobsinfo(ctools.cscript): |
| 36 | 36 | """ |
| 37 | 37 | Constructor. |
| 38 | 38 | """ |
| 39 | - # Set name | |
| 40 | - self._name = 'csobsinfo' | |
| 41 | - self._version = ctools.__version__ | |
| 39 | + # Initialise application by calling the appropriate class constructor | |
| 40 | + self._init_csobservation('csobsinfo', ctools.__version__, argv) | |
| 42 | 41 | |
| 43 | 42 | # Initialise class members |
| 44 | 43 | self._obj_dir = None |
| ... | ... | @@ -51,13 +50,6 @@ class csobsinfo(ctools.cscript): |
| 51 | 50 | self._ebounds = gammalib.GEbounds() |
| 52 | 51 | self._gti = gammalib.GGti() |
| 53 | 52 | |
| 54 | - # Initialise observation container from constructor arguments. | |
| 55 | - self._obs, argv = self._set_input_obs(argv) | |
| 56 | - | |
| 57 | - # Initialise application by calling the appropriate class | |
| 58 | - # constructor. | |
| 59 | - self._init_cscript(argv) | |
| 60 | - | |
| 61 | 53 | # Return |
| 62 | 54 | return |
| 63 | 55 | |
| ... | ... | @@ -68,9 +60,9 @@ class csobsinfo(ctools.cscript): |
| 68 | 60 | Get parameters from parfile and setup the observation |
| 69 | 61 | """ |
| 70 | 62 | # Get parameters |
| 71 | - if self._obs.size() == 0: | |
| 63 | + if self.obs().size() == 0: | |
| 72 | 64 | self._require_inobs('csobsinfo::get_parameters') |
| 73 | - self._obs = self._get_observations(False) | |
| 65 | + self.obs(self._get_observations(False)) | |
| 74 | 66 | |
| 75 | 67 | # Initialise object position |
| 76 | 68 | self._obj_dir = gammalib.GSkyDir() |
| ... | ... | @@ -127,10 +119,10 @@ class csobsinfo(ctools.cscript): |
| 127 | 119 | # Write header |
| 128 | 120 | if self._logTerse(): |
| 129 | 121 | self._log('\n') |
| 130 | - self._log.header1(gammalib.number('Observation', self._obs.size())) | |
| 122 | + self._log.header1(gammalib.number('Observation', self.obs().size())) | |
| 131 | 123 | |
| 132 | 124 | # Loop over observations |
| 133 | - for obs in self._obs: | |
| 125 | + for obs in self.obs(): | |
| 134 | 126 | |
| 135 | 127 | # Skip non-CTA observations |
| 136 | 128 | if not obs.classname() == 'GCTAObservation': | ... | ... |
cscripts/csobsselect.py
| ... | ... | @@ -26,7 +26,7 @@ import ctools |
| 26 | 26 | # ================= # |
| 27 | 27 | # csobsselect class # |
| 28 | 28 | # ================= # |
| 29 | -class csobsselect(ctools.cscript): | |
| 29 | +class csobsselect(ctools.csobservation): | |
| 30 | 30 | """ |
| 31 | 31 | Selects observations from an observation definition XML file |
| 32 | 32 | """ |
| ... | ... | @@ -36,15 +36,8 @@ class csobsselect(ctools.cscript): |
| 36 | 36 | """ |
| 37 | 37 | Constructor |
| 38 | 38 | """ |
| 39 | - # Set name | |
| 40 | - self._name = 'csobsselect' | |
| 41 | - self._version = ctools.__version__ | |
| 42 | - | |
| 43 | - # Initialise observation container from constructor arguments | |
| 44 | - self._obs, argv = self._set_input_obs(argv) | |
| 45 | - | |
| 46 | 39 | # Initialise application by calling the appropriate class constructor |
| 47 | - self._init_cscript(argv) | |
| 40 | + self._init_csobservation('csobsselect', ctools.__version__, argv) | |
| 48 | 41 | |
| 49 | 42 | # Return |
| 50 | 43 | return |
| ... | ... | @@ -57,9 +50,9 @@ class csobsselect(ctools.cscript): |
| 57 | 50 | """ |
| 58 | 51 | # If there are no observations in container then query the inobs |
| 59 | 52 | # parameter |
| 60 | - if self._obs.size() == 0: | |
| 53 | + if self.obs().is_empty(): | |
| 61 | 54 | self['inobs'].filename() |
| 62 | - | |
| 55 | + | |
| 63 | 56 | # Query relevant pointing selection parameters |
| 64 | 57 | pntselect = self['pntselect'].string() |
| 65 | 58 | coordsys = self['coordsys'].string() |
| ... | ... | @@ -81,8 +74,8 @@ class csobsselect(ctools.cscript): |
| 81 | 74 | |
| 82 | 75 | # If there are no observations in container then get them from the |
| 83 | 76 | # parameter file |
| 84 | - if self._obs.size() == 0: | |
| 85 | - self._obs = self._get_observations(False) | |
| 77 | + if self.obs().is_empty(): | |
| 78 | + self.obs(self._get_observations(False)) | |
| 86 | 79 | |
| 87 | 80 | # Write input parameters into logger |
| 88 | 81 | self._log_parameters(gammalib.TERSE) |
| ... | ... | @@ -280,23 +273,23 @@ class csobsselect(ctools.cscript): |
| 280 | 273 | selected_obs = gammalib.GObservations() |
| 281 | 274 | |
| 282 | 275 | # Write input observation container into logger |
| 283 | - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') | |
| 276 | + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') | |
| 284 | 277 | |
| 285 | 278 | # Write header |
| 286 | 279 | self._log_header1(gammalib.TERSE, 'Observation selection') |
| 287 | 280 | |
| 288 | 281 | # Loop over observations |
| 289 | - for obs in self._obs: | |
| 282 | + for obs in self.obs(): | |
| 290 | 283 | |
| 291 | 284 | # If observation is selected then append observation |
| 292 | 285 | if self._select_observation(obs): |
| 293 | 286 | selected_obs.append(obs) |
| 294 | 287 | |
| 295 | 288 | # Copy selected observations into observation |
| 296 | - self._obs = selected_obs | |
| 289 | + self.obs(selected_obs) | |
| 297 | 290 | |
| 298 | 291 | # Write input observation container into logger |
| 299 | - self._log_observations(gammalib.NORMAL, self._obs, 'Selected observation') | |
| 292 | + self._log_observations(gammalib.NORMAL, self.obs(), 'Selected observation') | |
| 300 | 293 | |
| 301 | 294 | # Return |
| 302 | 295 | return |
| ... | ... | @@ -324,17 +317,11 @@ class csobsselect(ctools.cscript): |
| 324 | 317 | outobs.url()) |
| 325 | 318 | |
| 326 | 319 | # Save observations |
| 327 | - self._obs.save(outobs) | |
| 320 | + self.obs().save(outobs) | |
| 328 | 321 | |
| 329 | 322 | # Return |
| 330 | 323 | return |
| 331 | 324 | |
| 332 | - def obs(self): | |
| 333 | - """ | |
| 334 | - Return observation container | |
| 335 | - """ | |
| 336 | - return self._obs | |
| 337 | - | |
| 338 | 325 | |
| 339 | 326 | # ======================== # |
| 340 | 327 | # Main routine entry point # | ... | ... |
cscripts/csphagen.py
| ... | ... | @@ -28,7 +28,7 @@ import sys |
| 28 | 28 | # =============== # |
| 29 | 29 | # csfindobs class # |
| 30 | 30 | # =============== # |
| 31 | -class csphagen(ctools.cscript): | |
| 31 | +class csphagen(ctools.csobservation): | |
| 32 | 32 | """ |
| 33 | 33 | Generate PHA, ARF and RMF files for classical IACT spectral analysis |
| 34 | 34 | """ |
| ... | ... | @@ -38,18 +38,10 @@ class csphagen(ctools.cscript): |
| 38 | 38 | """ |
| 39 | 39 | Constructor |
| 40 | 40 | """ |
| 41 | - # Set name, version | |
| 42 | - self._name = 'csphagen' | |
| 43 | - self._version = ctools.__version__ | |
| 44 | - | |
| 45 | - # Initialise observation container from constructor arguments | |
| 46 | - self._obs, argv = self._set_input_obs(argv) | |
| 47 | - | |
| 48 | 41 | # Initialise application by calling the appropriate class constructor |
| 49 | - self._init_cscript(argv) | |
| 42 | + self._init_csobservation('csphagen', ctools.__version__, argv) | |
| 50 | 43 | |
| 51 | 44 | # Initialise other variables |
| 52 | - self._outobs = gammalib.GObservations() | |
| 53 | 45 | self._ebounds = gammalib.GEbounds() |
| 54 | 46 | self._src_dir = gammalib.GSkyDir() |
| 55 | 47 | self._src_reg = gammalib.GSkyRegions() |
| ... | ... | @@ -69,7 +61,7 @@ class csphagen(ctools.cscript): |
| 69 | 61 | """ |
| 70 | 62 | # Setup observations (require response and allow event list, don't |
| 71 | 63 | # allow counts cube) |
| 72 | - self._setup_observations(self._obs, True, True, False) | |
| 64 | + self._setup_observations(self.obs(), True, True, False) | |
| 73 | 65 | |
| 74 | 66 | # Set energy bounds |
| 75 | 67 | self._ebounds = self._create_ebounds() |
| ... | ... | @@ -114,8 +106,8 @@ class csphagen(ctools.cscript): |
| 114 | 106 | |
| 115 | 107 | # If there are no observations in container then get them from the |
| 116 | 108 | # parameter file |
| 117 | - if self._obs.size() == 0: | |
| 118 | - self._obs = self._get_observations(False) | |
| 109 | + if self.obs().is_empty(): | |
| 110 | + self.obs(self._get_observations(False)) | |
| 119 | 111 | |
| 120 | 112 | # Write input parameters into logger |
| 121 | 113 | self._log_parameters(gammalib.TERSE) |
| ... | ... | @@ -200,18 +192,18 @@ class csphagen(ctools.cscript): |
| 200 | 192 | self._get_parameters() |
| 201 | 193 | |
| 202 | 194 | # Write observation into logger |
| 203 | - self._log_observations(gammalib.NORMAL, self._obs, 'Observation') | |
| 195 | + self._log_observations(gammalib.NORMAL, self.obs(), 'Observation') | |
| 204 | 196 | |
| 205 | 197 | # Write header |
| 206 | 198 | self._log_header1(gammalib.NORMAL, |
| 207 | 199 | 'Generation of source and background spectra') |
| 208 | 200 | |
| 209 | 201 | # Initialise run variables |
| 210 | - self._outobs = gammalib.GObservations() | |
| 202 | + outobs = gammalib.GObservations() | |
| 211 | 203 | self._bkg_regs = [] |
| 212 | 204 | |
| 213 | 205 | # Loop through observations and generate pha, arf, rmf files |
| 214 | - for obs in self._obs: | |
| 206 | + for obs in self.obs(): | |
| 215 | 207 | |
| 216 | 208 | # Initialise background regions for this observation |
| 217 | 209 | bkg_reg = gammalib.GSkyRegions() |
| ... | ... | @@ -230,25 +222,28 @@ class csphagen(ctools.cscript): |
| 230 | 222 | self._src_reg, |
| 231 | 223 | bkg_reg) |
| 232 | 224 | onoff.id(obs.id()) |
| 233 | - self._outobs.append(onoff) | |
| 225 | + outobs.append(onoff) | |
| 234 | 226 | self._bkg_regs.append({'regions': bkg_reg, 'id': obs.id()}) |
| 235 | 227 | else: |
| 236 | 228 | self._log_string(gammalib.NORMAL, 'Observation %s not included ' |
| 237 | 229 | 'in spectra generation' % (obs.id())) |
| 238 | 230 | |
| 239 | 231 | # Stack observations |
| 240 | - if self._outobs.size() > 1 and self['stack'].boolean() == True: | |
| 232 | + if outobs.size() > 1 and self['stack'].boolean() == True: | |
| 241 | 233 | |
| 242 | 234 | # Write header |
| 243 | 235 | self._log_header1(gammalib.NORMAL, 'Stacking %d observations' % |
| 244 | - (self._outobs.size())) | |
| 236 | + (outobs.size())) | |
| 245 | 237 | |
| 246 | 238 | # Stack observations |
| 247 | - stacked_obs = gammalib.GCTAOnOffObservation(self._outobs) | |
| 239 | + stacked_obs = gammalib.GCTAOnOffObservation(outobs) | |
| 248 | 240 | |
| 249 | 241 | # Put stacked observations in output container |
| 250 | - self._outobs = gammalib.GObservations() | |
| 251 | - self._outobs.append(stacked_obs) | |
| 242 | + outobs = gammalib.GObservations() | |
| 243 | + outobs.append(stacked_obs) | |
| 244 | + | |
| 245 | + # Set observation container | |
| 246 | + self.obs(outobs) | |
| 252 | 247 | |
| 253 | 248 | # Return |
| 254 | 249 | return |
| ... | ... | @@ -266,7 +261,7 @@ class csphagen(ctools.cscript): |
| 266 | 261 | clobber = self['clobber'].boolean() |
| 267 | 262 | |
| 268 | 263 | # Loop over all observation in container |
| 269 | - for obs in self._outobs: | |
| 264 | + for obs in self.obs(): | |
| 270 | 265 | |
| 271 | 266 | # Set filenames |
| 272 | 267 | if self['stack'].boolean(): |
| ... | ... | @@ -274,7 +269,7 @@ class csphagen(ctools.cscript): |
| 274 | 269 | offname = prefix + '_stacked_pha_off.fits' |
| 275 | 270 | arfname = prefix + '_stacked_arf.fits' |
| 276 | 271 | rmfname = prefix + '_stacked_rmf.fits' |
| 277 | - elif self._outobs.size() > 1: | |
| 272 | + elif self.obs().size() > 1: | |
| 278 | 273 | onname = prefix + '_%s_pha_on.fits' % (obs.id()) |
| 279 | 274 | offname = prefix + '_%s_pha_off.fits' % (obs.id()) |
| 280 | 275 | arfname = prefix + '_%s_arf.fits' % (obs.id()) |
| ... | ... | @@ -298,7 +293,7 @@ class csphagen(ctools.cscript): |
| 298 | 293 | self._log_value(gammalib.NORMAL, 'RMF file', arfname) |
| 299 | 294 | |
| 300 | 295 | # Save observation definition XML file |
| 301 | - self._outobs.save(outobs) | |
| 296 | + self.obs().save(outobs) | |
| 302 | 297 | |
| 303 | 298 | # Log file name |
| 304 | 299 | self._log_value(gammalib.NORMAL, 'Obs. definition XML file', outobs) |
| ... | ... | @@ -326,12 +321,6 @@ class csphagen(ctools.cscript): |
| 326 | 321 | # Return |
| 327 | 322 | return |
| 328 | 323 | |
| 329 | - def obs(self): | |
| 330 | - """ | |
| 331 | - Return observation container | |
| 332 | - """ | |
| 333 | - return self._outobs | |
| 334 | - | |
| 335 | 324 | |
| 336 | 325 | # ======================== # |
| 337 | 326 | # Main routine entry point # | ... | ... |
cscripts/csresmap.py
| ... | ... | @@ -27,7 +27,7 @@ import ctools |
| 27 | 27 | # ============== # |
| 28 | 28 | # csresmap class # |
| 29 | 29 | # ============== # |
| 30 | -class csresmap(ctools.cscript): | |
| 30 | +class csresmap(ctools.csobservation): | |
| 31 | 31 | """ |
| 32 | 32 | Generates a residual map |
| 33 | 33 | """ |
| ... | ... | @@ -37,21 +37,14 @@ class csresmap(ctools.cscript): |
| 37 | 37 | """ |
| 38 | 38 | Constructor |
| 39 | 39 | """ |
| 40 | - # Set name | |
| 41 | - self._name = 'csresmap' | |
| 42 | - self._version = ctools.__version__ | |
| 40 | + # Initialise application by calling the appropriate class constructor | |
| 41 | + self._init_csobservation('csresmap', ctools.__version__, argv) | |
| 43 | 42 | |
| 44 | 43 | # Initialise class members |
| 45 | 44 | self._resmap = None |
| 46 | 45 | self._use_maps = False |
| 47 | 46 | self._skip_binning = False |
| 48 | 47 | |
| 49 | - # Initialise observation container from constructor arguments | |
| 50 | - self._obs, argv = self._set_input_obs(argv) | |
| 51 | - | |
| 52 | - # Initialise application by calling the appropriate class constructor | |
| 53 | - self._init_cscript(argv) | |
| 54 | - | |
| 55 | 48 | # Return |
| 56 | 49 | return |
| 57 | 50 | |
| ... | ... | @@ -69,7 +62,7 @@ class csresmap(ctools.cscript): |
| 69 | 62 | # if the "inobs" parameter is a counts cube. If the "inobs" parameter |
| 70 | 63 | # represents a FITS file and if this FITS file is a counts cube then |
| 71 | 64 | # set self._skip_binning=True |
| 72 | - if self._obs.size() == 0 and self['inobs'].filename() != 'NONE': | |
| 65 | + if self.obs().size() == 0 and self['inobs'].filename() != 'NONE': | |
| 73 | 66 | filename = gammalib.GFilename(self['inobs'].filename()) |
| 74 | 67 | if filename.is_fits(): |
| 75 | 68 | cta = gammalib.GCTAObservation() |
| ... | ... | @@ -88,20 +81,20 @@ class csresmap(ctools.cscript): |
| 88 | 81 | if not self._use_maps: |
| 89 | 82 | |
| 90 | 83 | # Set observation if not done before |
| 91 | - if self._obs.size() == 0: | |
| 84 | + if self.obs().size() == 0: | |
| 92 | 85 | self._require_inobs('csresmap.get_parameters()') |
| 93 | - self._obs = self._get_observations() | |
| 86 | + self.obs(self._get_observations()) | |
| 94 | 87 | |
| 95 | 88 | # If we have exactly one binned CTA observation then signal that |
| 96 | 89 | # the binning can be skipped |
| 97 | - if self._obs.size() == 1 and \ | |
| 98 | - self._obs[0].classname() == 'GCTAObservation' and \ | |
| 99 | - self._obs[0].eventtype() == 'CountsCube': | |
| 90 | + if self.obs().size() == 1 and \ | |
| 91 | + self.obs()[0].classname() == 'GCTAObservation' and \ | |
| 92 | + self.obs()[0].eventtype() == 'CountsCube': | |
| 100 | 93 | self._skip_binning = True |
| 101 | 94 | |
| 102 | 95 | # Set models if we have none |
| 103 | - if self._obs.models().size() == 0: | |
| 104 | - self._obs.models(self['inmodel'].filename()) | |
| 96 | + if self.obs().models().size() == 0: | |
| 97 | + self.obs().models(self['inmodel'].filename()) | |
| 105 | 98 | |
| 106 | 99 | # If no binning is provided in the observation then query now |
| 107 | 100 | # the counts cube binning parameters |
| ... | ... | @@ -153,7 +146,7 @@ class csresmap(ctools.cscript): |
| 153 | 146 | self._get_parameters() |
| 154 | 147 | |
| 155 | 148 | # Write observation into logger |
| 156 | - self._log_observations(gammalib.NORMAL, self._obs, 'Observation') | |
| 149 | + self._log_observations(gammalib.NORMAL, self.obs(), 'Observation') | |
| 157 | 150 | |
| 158 | 151 | # If a counts and model cube are specified then load them as sky map |
| 159 | 152 | if self._use_maps: |
| ... | ... | @@ -166,7 +159,7 @@ class csresmap(ctools.cscript): |
| 166 | 159 | # Do not build counts cube if we have already one in the observation |
| 167 | 160 | # container |
| 168 | 161 | if self._skip_binning: |
| 169 | - cta_counts_cube = gammalib.GCTAEventCube(self._obs[0].events()) | |
| 162 | + cta_counts_cube = gammalib.GCTAEventCube(self.obs()[0].events()) | |
| 170 | 163 | |
| 171 | 164 | # ... otherwise generate one now from the event list |
| 172 | 165 | else: |
| ... | ... | @@ -175,7 +168,7 @@ class csresmap(ctools.cscript): |
| 175 | 168 | self._log_header1(gammalib.TERSE, 'Generate binned map (ctbin)') |
| 176 | 169 | |
| 177 | 170 | # Create countsmap |
| 178 | - binning = ctools.ctbin(self._obs) | |
| 171 | + binning = ctools.ctbin(self.obs()) | |
| 179 | 172 | binning['xref'] = self['xref'].real() |
| 180 | 173 | binning['yref'] = self['yref'].real() |
| 181 | 174 | binning['proj'] = self['proj'].string() |
| ... | ... | @@ -184,7 +177,7 @@ class csresmap(ctools.cscript): |
| 184 | 177 | binning['nxpix'] = self['nxpix'].integer() |
| 185 | 178 | binning['nypix'] = self['nypix'].integer() |
| 186 | 179 | binning['binsz'] = self['binsz'].real() |
| 187 | - if self['ebinalg'].string() == "FILE": | |
| 180 | + if self['ebinalg'].string() == 'FILE': | |
| 188 | 181 | binning['ebinfile'] = self['ebinfile'].filename().file() |
| 189 | 182 | else: |
| 190 | 183 | binning['enumbins'] = self['enumbins'].integer() |
| ... | ... | @@ -205,7 +198,7 @@ class csresmap(ctools.cscript): |
| 205 | 198 | self._log_header1(gammalib.TERSE, 'Generate model map (ctmodel)') |
| 206 | 199 | |
| 207 | 200 | # Create model map |
| 208 | - model = ctools.ctmodel(self._obs) | |
| 201 | + model = ctools.ctmodel(self.obs()) | |
| 209 | 202 | model.cube(cta_counts_cube) |
| 210 | 203 | model['chatter'] = self['chatter'].integer() |
| 211 | 204 | model['clobber'] = self['clobber'].boolean() |
| ... | ... | @@ -324,7 +317,7 @@ class csresmap(ctools.cscript): |
| 324 | 317 | |
| 325 | 318 | # Set default name is user name is empty |
| 326 | 319 | if not name: |
| 327 | - user_name = self._name | |
| 320 | + user_name = self._name() | |
| 328 | 321 | else: |
| 329 | 322 | user_name = name |
| 330 | 323 | |
| ... | ... | @@ -342,7 +335,7 @@ class csresmap(ctools.cscript): |
| 342 | 335 | Set model |
| 343 | 336 | """ |
| 344 | 337 | # Copy models |
| 345 | - self._obs.models(models) | |
| 338 | + self.obs().models(models) | |
| 346 | 339 | |
| 347 | 340 | # Return |
| 348 | 341 | return | ... | ... |
cscripts/cssens.py
| ... | ... | @@ -596,7 +596,7 @@ class cssens(ctools.csobservation): |
| 596 | 596 | self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') |
| 597 | 597 | |
| 598 | 598 | # Write models into logger |
| 599 | - self._log_models(gammalib.TERSE, models, 'Input model') | |
| 599 | + self._log_models(gammalib.NORMAL, models, 'Input model') | |
| 600 | 600 | |
| 601 | 601 | # Get sensitivity type |
| 602 | 602 | sensitivity_type = self['type'].string() | ... | ... |
cscripts/csspec.py
| ... | ... | @@ -66,7 +66,7 @@ class csspec(ctools.csobservation): |
| 66 | 66 | Get parameters from parfile and setup the observation |
| 67 | 67 | """ |
| 68 | 68 | # Set observation if not done before |
| 69 | - if self.obs().size() == 0: | |
| 69 | + if self.obs().is_empty(): | |
| 70 | 70 | self._require_inobs('csspec::get_parameters()') |
| 71 | 71 | self.obs(self._get_observations()) |
| 72 | 72 | |
| ... | ... | @@ -74,7 +74,7 @@ class csspec(ctools.csobservation): |
| 74 | 74 | self._set_obs_statistic(gammalib.toupper(self['statistic'].string())) |
| 75 | 75 | |
| 76 | 76 | # Set models if we have none |
| 77 | - if self.obs().models().size() == 0: | |
| 77 | + if self.obs().models().is_empty(): | |
| 78 | 78 | self.obs().models(self['inmodel'].filename()) |
| 79 | 79 | |
| 80 | 80 | # Query source name | ... | ... |
cscripts/cstsdist.py
| ... | ... | @@ -227,7 +227,7 @@ class cstsdist(ctools.csobservation): |
| 227 | 227 | self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') |
| 228 | 228 | |
| 229 | 229 | # Write models into logger |
| 230 | - self._log_models(gammalib.TERSE, self.obs().models(), 'Input model') | |
| 230 | + self._log_models(gammalib.NORMAL, self.obs().models(), 'Input model') | |
| 231 | 231 | |
| 232 | 232 | # Write header |
| 233 | 233 | self._log_header1(gammalib.TERSE, 'Generate TS distribution') | ... | ... |
cscripts/cstsmapsplit.py
| ... | ... | @@ -28,7 +28,7 @@ import ctools |
| 28 | 28 | # ================== # |
| 29 | 29 | # cstsmapsplit class # |
| 30 | 30 | # ================== # |
| 31 | -class cstsmapsplit(ctools.cscript): | |
| 31 | +class cstsmapsplit(ctools.cslikelihood): | |
| 32 | 32 | """ |
| 33 | 33 | Generates commands to split TS map computation |
| 34 | 34 | |
| ... | ... | @@ -44,10 +44,8 @@ class cstsmapsplit(ctools.cscript): |
| 44 | 44 | """ |
| 45 | 45 | Constructor |
| 46 | 46 | """ |
| 47 | - | |
| 48 | - # Set name and version | |
| 49 | - self._name = 'cstsmapsplit' | |
| 50 | - self._version = ctools.__version__ | |
| 47 | + # Initialise application by calling the appropriate class constructor | |
| 48 | + self._init_cslikelihood('cstsmapsplit', ctools.__version__, argv) | |
| 51 | 49 | |
| 52 | 50 | # Set data members |
| 53 | 51 | self._outmap = gammalib.GFilename() |
| ... | ... | @@ -57,13 +55,6 @@ class cstsmapsplit(ctools.cscript): |
| 57 | 55 | self._map = gammalib.GSkyMap() |
| 58 | 56 | self._cmd = [] |
| 59 | 57 | self._srcname = '' |
| 60 | - | |
| 61 | - # Initialise observation container from constructor arguments. | |
| 62 | - self._obs, argv = self._set_input_obs(argv) | |
| 63 | - | |
| 64 | - # Initialise application by calling the appropriate class | |
| 65 | - # constructor. | |
| 66 | - self._init_cscript(argv) | |
| 67 | 58 | |
| 68 | 59 | # Return |
| 69 | 60 | return |
| ... | ... | @@ -74,17 +65,16 @@ class cstsmapsplit(ctools.cscript): |
| 74 | 65 | """ |
| 75 | 66 | Get parameters from parfile and setup the observation |
| 76 | 67 | """ |
| 77 | - | |
| 78 | 68 | # If there are no observations in container then get some ... |
| 79 | - if self._obs.size() == 0: | |
| 80 | - self._obs = self._get_observations() | |
| 69 | + if self.obs().size() == 0: | |
| 70 | + self.obs(self._get_observations()) | |
| 81 | 71 | |
| 82 | 72 | # Set models if we have none |
| 83 | - if self._obs.models().size() == 0: | |
| 84 | - self._obs.models(self['inmodel'].filename()) | |
| 73 | + if self.obs().models().size() == 0: | |
| 74 | + self.obs().models(self['inmodel'].filename()) | |
| 85 | 75 | |
| 86 | 76 | # Get TS map paramters |
| 87 | - self._map = self._create_map(self._obs) | |
| 77 | + self._map = self._create_map(self.obs()) | |
| 88 | 78 | self._srcname = self['srcname'].string() |
| 89 | 79 | self._outmap = self['outmap'].filename() |
| 90 | 80 | |
| ... | ... | @@ -108,30 +98,29 @@ class cstsmapsplit(ctools.cscript): |
| 108 | 98 | logl : float |
| 109 | 99 | Log-likelihood of null hypothesis |
| 110 | 100 | """ |
| 111 | - | |
| 112 | 101 | # Store original models |
| 113 | - models_orig = self._obs.models() | |
| 102 | + models_orig = self.obs().models() | |
| 114 | 103 | |
| 115 | 104 | # Get models instance |
| 116 | - models0 = self._obs.models() | |
| 105 | + models0 = self.obs().models() | |
| 117 | 106 | |
| 118 | 107 | # Remove test source |
| 119 | 108 | models0.remove(self._srcname) |
| 120 | 109 | |
| 121 | 110 | # Initialise optimizer |
| 122 | - opt = gammalib.GOptimizerLM() | |
| 111 | + #opt = gammalib.GOptimizerLM() | |
| 123 | 112 | |
| 124 | 113 | # Set models for null hypothesis |
| 125 | - self._obs.models(models0) | |
| 114 | + self.obs().models(models0) | |
| 126 | 115 | |
| 127 | 116 | # Optimise observation container |
| 128 | - self._obs.optimize(opt) | |
| 117 | + self.obs().optimize(self.opt()) | |
| 129 | 118 | |
| 130 | 119 | # Set original models to container |
| 131 | - self._obs.models(models_orig) | |
| 120 | + self.obs().models(models_orig) | |
| 132 | 121 | |
| 133 | 122 | # Return optimised log-likelihood of null hypothesis |
| 134 | - return -(opt.value()) | |
| 123 | + return -(self.opt().value()) | |
| 135 | 124 | |
| 136 | 125 | |
| 137 | 126 | # Public methods |
| ... | ... | @@ -147,12 +136,8 @@ class cstsmapsplit(ctools.cscript): |
| 147 | 136 | self._get_parameters() |
| 148 | 137 | |
| 149 | 138 | # Write information into logger |
| 150 | - if self._logTerse(): | |
| 151 | - self._log('\n') | |
| 152 | - self._log.header1('Test source') | |
| 153 | - model = self._obs.models()[self._srcname] | |
| 154 | - self._log(str(model)) | |
| 155 | - self._log('\n') | |
| 139 | + self._log_header1(gammalib.TERSE, 'Test source') | |
| 140 | + self._log_string(gammalib.TERSE, str(self.obs().models()[self._srcname])) | |
| 156 | 141 | |
| 157 | 142 | # Set log-likelihood to zero |
| 158 | 143 | logL0 = 0.0 |
| ... | ... | @@ -161,9 +146,7 @@ class cstsmapsplit(ctools.cscript): |
| 161 | 146 | if self._compute_null: |
| 162 | 147 | |
| 163 | 148 | # Write information into logger |
| 164 | - if self._logTerse(): | |
| 165 | - self._log('\n') | |
| 166 | - self._log.header1('Compute null hypothesis') | |
| 149 | + self._log_header1(gammalib.TERSE, 'Compute null hypothesis') | |
| 167 | 150 | |
| 168 | 151 | # Compute null hypothesis |
| 169 | 152 | logL0 = self._compute_null_hypothesis() | ... | ... |