Commit 5d64b0db41b98f76058c8a2972a8eab0cfbd3ad0

Authored by Jürgen Knödlseder
1 parent 37c64e1e

Adapt to removal of ctools::is_valid_filename() method

cscripts/csebins.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Generates energy boundaries for stacked analysis
4 4 #
5   -# Copyright (C) 2017 Juergen Knoedlseder
  5 +# Copyright (C) 2017-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
... ... @@ -55,13 +55,10 @@ class csebins(ctools.csobservation):
55 55 # Initialise observation container if it is currently empty
56 56 if self.obs().size() == 0:
57 57  
58   - # Query "inobs" parameter
59   - filename = self['inobs'].filename()
60   -
61 58 # If an observation definition file was provided then load it,
62 59 # otherwise build a single observation with response information
63   - if self._is_valid_filename(filename):
64   - self.obs(gammalib.GObservations(filename))
  60 + if self['inobs'].is_valid():
  61 + self.obs(gammalib.GObservations(self['inobs'].filename()))
65 62 else:
66 63 cta = gammalib.GCTAObservation()
67 64 caldb = gammalib.GCaldb('cta', self['caldb'].string())
... ...
cscripts/csiactcopy.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Copies IACT data from remote machine
4 4 #
5   -# Copyright (C) 2016-2017 Michael Mayer
  5 +# Copyright (C) 2016-2018 Michael Mayer
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
... ... @@ -74,7 +74,8 @@ class csiactcopy(ctools.cscript):
74 74 # Get parameters
75 75 self._prodname = self['prodname'].string()
76 76 self._outpath = gammalib.expand_env(self['outpath'].string())
77   - self._runlist = self['runlist'].filename()
  77 + if self['runlist'].is_valid():
  78 + self._runlist = self['runlist'].filename()
78 79  
79 80 # Write input parameters into logger
80 81 self._log_parameters(gammalib.TERSE)
... ... @@ -322,7 +323,7 @@ class csiactcopy(ctools.cscript):
322 323 for i in range(local_hdu.ncols()):
323 324  
324 325 # Get local and remote columns
325   - local_col = local_hdu[i]
  326 + local_col = local_hdu[i]
326 327 remote_col = remote_hdu[i]
327 328  
328 329 # Loop over entries and merge
... ... @@ -381,14 +382,14 @@ class csiactcopy(ctools.cscript):
381 382 self._log_value(gammalib.NORMAL, 'Number of observations',
382 383 len(runs))
383 384  
384   - # ... otherwise, if the runlist file is 'NONE' then leave the
  385 + # ... otherwise, if the runlist filename is empty then leave the
385 386 # run list empty. This implies copying all available data.
386   - elif filename == 'NONE':
  387 + elif filename.is_empty():
387 388 self._log_string(gammalib.NORMAL, 'Copy all available data')
388 389  
389 390 # ... otherwise raise an exception
390 391 else:
391   - msg = '*** ERROR: Runlist file "%s" not available' % filename
  392 + msg = '*** ERROR: Runlist file "%s" not available' % filename.url()
392 393 raise RuntimeError(msg)
393 394  
394 395 # Return run list
... ...
cscripts/csiactobs.py
... ... @@ -106,7 +106,7 @@ class csiactobs(ctools.cscript):
106 106 self._datapath = gammalib.expand_env(self._datapath)
107 107  
108 108 # Query input parameters
109   - self['inmodel'].filename()
  109 + self['inmodel'].query()
110 110  
111 111 # Read FITS production
112 112 self._prodname = self['prodname'].string()
... ... @@ -161,13 +161,17 @@ class csiactobs(ctools.cscript):
161 161 # Open master index file and look for prodname
162 162 master_file = os.path.join(self._datapath, self._master_indx)
163 163 if not os.path.isfile(master_file):
164   - raise RuntimeError('FITS data store not available. No master index file found. Make sure the file is copied from the server and your datapath is set correctly.')
  164 + raise RuntimeError('FITS data store not available. No master '
  165 + 'index file found. Make sure the file is '
  166 + 'copied from the server and your datapath '
  167 + 'is set correctly.')
165 168  
166 169 # Open and load JSON file
167 170 json_data = open(master_file).read()
168 171 data = json.loads(json_data)
169 172 if not 'datasets' in data:
170   - raise RuntimeError('Key "datasets" not available in master index file.')
  173 + raise RuntimeError('Key "datasets" not available in master '
  174 + 'index file.')
171 175  
172 176 # Get configurations
173 177 configs = data['datasets']
... ... @@ -190,14 +194,21 @@ class csiactobs(ctools.cscript):
190 194  
191 195 # Check index files
192 196 if self._hdu_index == '' or self._obs_index == '':
193   - raise RuntimeError('*** ERROR: FITS data store "'+self._prodname+'" not available. Run csiactdata to get a list of available storage names')
  197 + raise RuntimeError('*** ERROR: FITS data store "'+self._prodname+
  198 + '" not available. Run csiactdata to get a list '
  199 + 'of available storage names')
194 200  
195 201 # Check HDU names
196 202 filename = gammalib.GFilename(self._hdu_index+'[HDU_INDEX]')
197 203 if not filename.is_fits():
198   - raise RuntimeError('*** ERROR: HDU index file "'+self._hdu_index+'[HDU_INDEX]" for FITS data store "'+self._prodname+'" not available. Check your master index file or run csiactdata to get a list of available storage names.')
199   -
200   - # Check for existence of 'BKG_SCALE' in the observation index file if required
  204 + raise RuntimeError('*** ERROR: HDU index file "'+self._hdu_index+
  205 + '[HDU_INDEX]" for FITS data store "'+
  206 + self._prodname+'" not available. Check your '
  207 + 'master index file or run csiactdata to get '
  208 + 'a list of available storage names.')
  209 +
  210 + # Check for existence of 'BKG_SCALE' in the observation index file if
  211 + # required
201 212 if self._use_bkg_scale:
202 213  
203 214 # Create filename
... ... @@ -209,7 +220,8 @@ class csiactobs(ctools.cscript):
209 220 # Open FITS file
210 221 fits = gammalib.GFits(self._obs_index)
211 222  
212   - # Check if column "BKG_SCALE" is found and signal its possible usage
  223 + # Check if column "BKG_SCALE" is found and signal its possible
  224 + # usage
213 225 if not fits['OBS_INDEX'].contains('BKG_SCALE'):
214 226 self._use_bkg_scale = False
215 227  
... ... @@ -221,8 +233,8 @@ class csiactobs(ctools.cscript):
221 233 self._use_bkg_scale = False
222 234  
223 235 # Create base data directory from hdu index file location
224   - self._subdir = os.path.dirname(self._hdu_index)
225   - self._debug = False # Debugging in client tools
  236 + self._subdir = os.path.dirname(self._hdu_index)
  237 + self._debug = False # Debugging in client tools
226 238  
227 239 # Write input parameters into logger
228 240 self._log_parameters(gammalib.TERSE)
... ... @@ -230,7 +242,7 @@ class csiactobs(ctools.cscript):
230 242 # Return
231 243 return
232 244  
233   - def _background_spectrum(self, prefactor, index, emin = 0.01, emax = 100.0):
  245 + def _background_spectrum(self, prefactor, index, emin=0.01, emax=100.0):
234 246 """
235 247 Create a background spectrum model dependent on user parameters
236 248  
... ... @@ -419,8 +431,10 @@ class csiactobs(ctools.cscript):
419 431 """
420 432 # If there are models provided by "inmodels" then append them now to
421 433 # the model container
422   - filename = self['inmodel'].filename().url()
423   - if filename != '' and filename != 'NONE':
  434 + if self['inmodel'].is_valid():
  435 +
  436 + # Get filename
  437 + filename = self['inmodel'].filename().url()
424 438  
425 439 # Log header and input model file
426 440 self._log_header1(gammalib.TERSE, 'Append input models')
... ... @@ -505,8 +519,7 @@ class csiactobs(ctools.cscript):
505 519  
506 520 # Return filename
507 521 return filename
508   -
509   -
  522 +
510 523 def _is_present(self, filename, obs_id, filetype):
511 524 """
512 525 Checks if a filename is present
... ...
cscripts/cslightcrv.py
... ... @@ -120,7 +120,7 @@ class cslightcrv(ctools.csobservation):
120 120  
121 121 # Read ahead output parameters
122 122 if self._read_ahead():
123   - self['outfile'].filename()
  123 + self['outfile'].query()
124 124  
125 125 # Write input parameters into logger
126 126 self._log_parameters(gammalib.TERSE)
... ... @@ -592,11 +592,11 @@ class cslightcrv(ctools.csobservation):
592 592 # Write header
593 593 self._log_header1(gammalib.TERSE, 'Save light curve')
594 594  
595   - # Get light curve filename
596   - outfile = self['outfile'].filename()
  595 + # Continue only if filename is valid
  596 + if self['outfile'].is_valid():
597 597  
598   - # Continue only filename and residual map are valid
599   - if self._fits != None:
  598 + # Get light curve filename
  599 + outfile = self['outfile'].filename()
600 600  
601 601 # Log file name
602 602 self._log_value(gammalib.NORMAL, 'Light curve file', outfile.url())
... ...
cscripts/csmodelinfo.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Shows the content of a model container
4 4 #
5   -# Copyright (C) 2015-2017 Michael Mayer
  5 +# Copyright (C) 2015-2018 Michael Mayer
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
... ... @@ -75,7 +75,7 @@ class csmodelinfo(ctools.cscript):
75 75  
76 76 # Query ahead DS9 filename
77 77 if self._read_ahead():
78   - self['outds9file'].filename()
  78 + self['outds9file'].query()
79 79  
80 80 # Write input parameters into logger
81 81 self._log_parameters(gammalib.TERSE)
... ... @@ -122,9 +122,9 @@ class csmodelinfo(ctools.cscript):
122 122  
123 123 # Loop over models and initialise dictionaries with model names
124 124 for model in self._models:
125   - types[model.type()] = 0
  125 + types[model.type()] = 0
126 126 instruments[model.instruments()] = 0
127   - pars_at_limit[model.name()] = []
  127 + pars_at_limit[model.name()] = []
128 128  
129 129 # Loop over models again and fill values to be dumped
130 130 for model in self._models:
... ... @@ -244,12 +244,12 @@ class csmodelinfo(ctools.cscript):
244 244 """
245 245 Save models to ds9 region file
246 246 """
247   - # Get output filename
248   - ds9file = self['outds9file'].filename()
249   -
250 247 # Check if DS9 file is valid
251   - if ds9file != '' and ds9file != 'NONE':
252   -
  248 + if self['outds9file'].is_valid():
  249 +
  250 + # Get output filename
  251 + ds9file = self['outds9file'].filename()
  252 +
253 253 # Write header
254 254 self._log_header1(gammalib.TERSE, 'Save models in DS9 file')
255 255  
... ...
cscripts/csmodelmerge.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Merge model definition XML files
4 4 #
5   -# Copyright (C) 2015-2017 Michael Mayer
  5 +# Copyright (C) 2015-2018 Michael Mayer
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
... ...
cscripts/csmodelselect.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Selects model from a model 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
... ...
cscripts/csmodelsois.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Puts subset of sources in diffuse model cube
4 4 #
5   -# Copyright (C) 2017 Josh Cardenzana
  5 +# Copyright (C) 2017-2018 Josh Cardenzana
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
... ... @@ -73,7 +73,7 @@ class csmodelsois(ctools.cscript):
73 73  
74 74 # Read input parameters
75 75 ptsrcsig = self['ptsrcsig'].real()
76   -
  76 +
77 77 # Get the cube centre coordinates
78 78 self._cubegen['coordsys'].string(self['coordsys'].string())
79 79 if self['coordsys'].string() == 'CEL':
... ... @@ -88,7 +88,7 @@ class csmodelsois(ctools.cscript):
88 88 self._cubegen['nxpix'].integer(self['nxpix'].integer())
89 89 self._cubegen['nypix'].integer(self['nypix'].integer())
90 90 self._cubegen['proj'].string(self['proj'].string())
91   -
  91 +
92 92 # Get the energy binning parameters
93 93 self._cubegen['ebinalg'].string(self['ebinalg'].string())
94 94 if self['ebinalg'].string() == 'FILE':
... ... @@ -98,13 +98,13 @@ class csmodelsois(ctools.cscript):
98 98 self._cubegen['emax'].real(self['emax'].real())
99 99 self._cubegen['enumbins'].integer(self['enumbins'].integer())
100 100  
101   - # Get remaining hidden parameters
  101 + # Set point source significance
102 102 self._cubegen['ptsrcsig'].real(ptsrcsig)
103   -
  103 +
104 104 # Read optionally output cube filenames
105 105 if self._read_ahead():
106 106 self._cubegen['outcube'].filename(self['outcube'].filename())
107   - self['outmodel'].filename()
  107 + self['outmodel'].query()
108 108  
109 109 # Write parameters into logger
110 110 self._log_parameters(gammalib.TERSE)
... ... @@ -185,12 +185,12 @@ class csmodelsois(ctools.cscript):
185 185 """
186 186 # Save the generated cube if the cube and filename are not empty
187 187 if ((not self._cubegen.mapcube().cube().is_empty()) and
188   - self._is_valid_filename(self['outcube'].filename())):
  188 + self['outcube'].is_valid()):
189 189 self._cubegen.mapcube().save(self['outcube'].filename(),
190   - self['clobber'].boolean())
  190 + self['clobber'].boolean())
191 191  
192 192 # If requested, save the updated list of models
193   - if self._is_valid_filename(self['outmodel'].filename()):
  193 + if self['outmodel'].is_valid():
194 194  
195 195 # Generate a list of models that will be output to file
196 196 outmodels = gammalib.GModels(self._models)
... ...
cscripts/csobsdef.py
... ... @@ -107,7 +107,7 @@ class csobsdef(ctools.cscript):
107 107  
108 108 # Read ahead parameters
109 109 if self._read_ahead():
110   - self['outobs'].filename()
  110 + self['outobs'].query()
111 111  
112 112 # Write input parameters into logger
113 113 self._log_parameters(gammalib.TERSE)
... ... @@ -351,11 +351,11 @@ class csobsdef(ctools.cscript):
351 351 # Write header and filename into logger
352 352 self._log_header1(gammalib.TERSE, 'Save observation definition XML file')
353 353  
354   - # Get output filename in case it was not read ahead
355   - outobs = self['outobs'].filename()
356   -
357 354 # Check if observation definition XML file is valid
358   - if outobs.url() != 'NONE':
  355 + if self['outobs'].is_valid():
  356 +
  357 + # Get output filename in case it was not read ahead
  358 + outobs = self['outobs'].filename()
359 359  
360 360 # Log filename
361 361 self._log_value(gammalib.NORMAL, 'Observation XML file', outobs.url())
... ...
cscripts/csobsinfo.py
... ... @@ -76,7 +76,7 @@ class csobsinfo(ctools.csobservation):
76 76  
77 77 # Read ahead DS9 filename
78 78 if self._read_ahead():
79   - self['outds9file'].filename()
  79 + self['outds9file'].query()
80 80  
81 81 # Write input parameters into logger
82 82 self._log_parameters(gammalib.TERSE)
... ... @@ -317,12 +317,11 @@ class csobsinfo(ctools.csobservation):
317 317 observation container into a DS9 region file. If "NONE" is
318 318 specified for the "outds9file" parameter the method does nothing.
319 319 """
320   -
321   - # Get output filename in case it was not read ahead
322   - ds9file = self['outds9file'].filename()
323   -
324 320 # Check if DS9 file is valid
325   - if ds9file.url() != 'NONE':
  321 + if self['outds9file'].is_valid():
  322 +
  323 + # Get output filename in case it was not read ahead
  324 + ds9file = self['outds9file'].filename()
326 325  
327 326 # Write header
328 327 self._log_header1(gammalib.TERSE, 'Save pointings in DS9 file')
... ...
cscripts/csphagen.py
... ... @@ -161,11 +161,15 @@ class csphagen(ctools.csobservation):
161 161 self._setup_observations(self.obs(), True, True, False)
162 162  
163 163 # Get spatial component of source model if an input model is defined
164   - inmodel = self['inmodel'].filename()
165   - if not self['inmodel'].is_undefined():
  164 + if self['inmodel'].is_valid():
  165 + inmodel = self['inmodel'].filename()
166 166 models = gammalib.GModels(inmodel)
167 167 name = self['srcname'].string()
168 168 self._src_model = models[name].spatial().clone()
  169 + elif self.obs().models().size() > 0:
  170 + name = self['srcname'].string()
  171 + if self.obs().models().contains(name):
  172 + self._src_model = self.obs().models()[name].spatial()
169 173  
170 174 # Set energy bounds
171 175 self._ebounds = self._create_ebounds()
... ... @@ -174,7 +178,7 @@ class csphagen(ctools.csobservation):
174 178 self._src_reg = gammalib.GSkyRegions()
175 179  
176 180 # Exclusion map
177   - if not self['inexclusion'].is_undefined():
  181 + if self['inexclusion'].is_valid():
178 182 inexclusion = self['inexclusion'].filename()
179 183 self._excl_reg = gammalib.GSkyRegionMap(inexclusion)
180 184 self._has_exclusion = True
... ... @@ -416,7 +420,6 @@ class csphagen(ctools.csobservation):
416 420 for obs in self.obs():
417 421  
418 422 # Skip non CTA observations
419   - #if obs.instrument() != 'CTA':
420 423 if obs.classname() != 'GCTAObservation':
421 424 self._log_string(gammalib.NORMAL, 'Skip %s observation "%s"' % \
422 425 (obs.instrument(), obs.id()))
... ...
cscripts/csphasecrv.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Generates spectra as a function of phase
4 4 #
5   -# Copyright (C) 2017 Rolf Buehler
  5 +# Copyright (C) 2017-2018 Rolf Buehler
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
... ...
cscripts/csresmap.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Generates a residual map.
4 4 #
5   -# Copyright (C) 2014-2017 Michael Mayer
  5 +# Copyright (C) 2014-2018 Michael Mayer
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
... ... @@ -73,9 +73,7 @@ class csresmap(ctools.csobservation):
73 73 # If we have a counts cube, then ask whether we also have a model cube.
74 74 # If a model cube name is given then set self._use_maps=True
75 75 if self._skip_binning:
76   - modcube = self['modcube'].filename()
77   - if modcube != 'NONE':
78   - self._use_maps = True
  76 + self._use_maps = self['modcube'].is_valid()
79 77  
80 78 # If not two maps are given, proceed to set up observation
81 79 if not self._use_maps:
... ...
cscripts/csresspec.py
... ... @@ -85,9 +85,7 @@ class csresspec(ctools.csobservation):
85 85 # components is required, query for precomputed model file and set
86 86 # use_maps to True
87 87 if self.obs().size() == 1 and n_binned == 1 and not components:
88   - modcube = self['modcube'].filename()
89   - if modcube != 'NONE':
90   - self._use_maps = True
  88 + self._use_maps = self['modcube'].is_valid()
91 89  
92 90 # If there are unbinned observations query the energy binning parameters
93 91 if n_unbinned != 0:
... ... @@ -130,7 +128,7 @@ class csresspec(ctools.csobservation):
130 128 self['ra'].real()
131 129 self['dec'].real()
132 130 self['rad'].real()
133   - self['regfile'].filename()
  131 + self['regfile'].query()
134 132  
135 133 # Unless all observations are On/Off, or we are using precomputed model
136 134 # maps query whether to use energy dispersion
... ... @@ -358,11 +356,15 @@ class csresspec(ctools.csobservation):
358 356  
359 357 # Apply user mask
360 358 if self._mask:
  359 + if self['regfile'].is_valid():
  360 + regfile = self['regfile']
  361 + else:
  362 + regfile = 'NONE'
361 363 msg = 'Masking ROI requested by user'
362 364 self._log_string(gammalib.EXPLICIT, msg)
363 365 cube = self._masked_cube(cube, self['ra'], self['dec'],
364 366 self['rad'],
365   - regfile=self['regfile'])
  367 + regfile=regfile)
366 368  
367 369 # Extract skymap and clip at 0 to null masked areas
368 370 counts = cube.counts().copy()
... ... @@ -688,17 +690,14 @@ class csresspec(ctools.csobservation):
688 690 # Write header
689 691 self._log_header1(gammalib.TERSE, 'Save residuals')
690 692  
691   - # Continue only if FITS file is valid
692   - if self._fits != None:
693   -
694   - # Get outfile parameter
695   - outfile = self['outfile'].filename()
  693 + # Get outfile parameter
  694 + outfile = self['outfile'].filename()
696 695  
697   - # Log file name
698   - self._log_value(gammalib.NORMAL, 'Residuals file', outfile.url())
  696 + # Log file name
  697 + self._log_value(gammalib.NORMAL, 'Residuals file', outfile.url())
699 698  
700   - # Save residuals
701   - self._fits.saveto(outfile, self['clobber'].boolean())
  699 + # Save residuals
  700 + self._fits.saveto(outfile, self['clobber'].boolean())
702 701  
703 702 # Return
704 703 return
... ...
cscripts/cssens.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Computes the array sensitivity using the Test Statistic for a test source
4 4 #
5   -# Copyright (C) 2011-2017 Juergen Knoedlseder
  5 +# Copyright (C) 2011-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
... ... @@ -132,8 +132,7 @@ class cssens(ctools.csobservation):
132 132 Observation container
133 133 """
134 134 # If an observation was provided on input then load it from XML file
135   - filename = self['inobs'].filename()
136   - if filename != 'NONE' and filename != '':
  135 + if self['inobs'].is_valid():
137 136 obs = self._get_observations()
138 137  
139 138 # ... otherwise allocate a single observation
... ...
cscripts/cssrcdetect.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Detects sources in a sky map
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
... ... @@ -72,7 +72,7 @@ class cssrcdetect(ctools.cscript):
72 72 self['exclrad'].real()
73 73 self['fit_pos'].boolean()
74 74 self['fit_shape'].boolean()
75   -
  75 +
76 76 # Query ahead output model filename
77 77 if self._read_ahead():
78 78 self['outmodel'].filename()
... ...
cscripts/cstsdist.py
... ... @@ -73,12 +73,7 @@ class cstsdist(ctools.csobservation):
73 73 # Query parameters
74 74 self['edisp'].boolean()
75 75 self['ntrials'].integer()
76   -
77 76 self['debug'].boolean()
78   -
79   - # Read ahead output parameters
80   - #if self._read_ahead():
81   - # self['outfile'].filename()
82 77 self['outfile'].filename()
83 78  
84 79 # Write input parameters into logger
... ...
cscripts/cstsmapmerge.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Merge Test Statistic maps
4 4 #
5   -# Copyright (C) 2015-2017 Michael Mayer
  5 +# Copyright (C) 2015-2018 Michael Mayer
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
... ... @@ -274,7 +274,8 @@ class cstsmapmerge(ctools.cscript):
274 274 if not gammalib.GFilename(fitsfile).is_fits():
275 275  
276 276 # Log message
277   - self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +' (not a FITS file)')
  277 + self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +
  278 + ' (not a FITS file)')
278 279  
279 280 # Continue
280 281 continue
... ... @@ -292,8 +293,10 @@ class cstsmapmerge(ctools.cscript):
292 293 file0 = fitsfile
293 294  
294 295 # Log message
295   - pix_info = ' (%d TS pixels computed)' % self._get_number_of_ts_pixels(fitsfile)
296   - self._log_value(gammalib.TERSE, 'Initial TS map file', fitsfile + pix_info)
  296 + pix_info = ' (%d TS pixels computed)' % \
  297 + self._get_number_of_ts_pixels(fitsfile)
  298 + self._log_value(gammalib.TERSE, 'Initial TS map file',
  299 + fitsfile + pix_info)
297 300  
298 301 # Leave loop
299 302 break
... ... @@ -305,7 +308,8 @@ class cstsmapmerge(ctools.cscript):
305 308 fits.close()
306 309  
307 310 # Info message
308   - self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +' (no "STATUS MAP" extension)')
  311 + self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +
  312 + ' (no "STATUS MAP" extension)')
309 313  
310 314 # Continue
311 315 continue
... ... @@ -313,10 +317,9 @@ class cstsmapmerge(ctools.cscript):
313 317 # Signal if no suitable file was found
314 318 if file0 == '':
315 319 msg = 'None of the provided files seems to be a sliced ' + \
316   - 'TS map file (none has a "STATUS MAP" ' + \
317   - 'extension)'
  320 + 'TS map file (none has a "STATUS MAP" ' + \
  321 + 'extension)'
318 322 raise RuntimeError(msg)
319   -
320 323  
321 324 # ... otherwise merge files
322 325 else:
... ... @@ -338,7 +341,8 @@ class cstsmapmerge(ctools.cscript):
338 341  
339 342 # Skip if file is not FITS
340 343 if not gammalib.GFilename(fitsfile).is_fits():
341   - self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +' (not a FITS file)')
  344 + self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +
  345 + ' (not a FITS file)')
342 346 continue
343 347  
344 348 # Open FITS file
... ... @@ -347,15 +351,18 @@ class cstsmapmerge(ctools.cscript):
347 351 # Skip if file does not contain status map
348 352 if not fits.contains('STATUS MAP'):
349 353 fits.close()
350   - self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +' (no "STATUS MAP" extension)')
  354 + self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +
  355 + ' (no "STATUS MAP" extension)')
351 356 continue
352 357  
353 358 # Close FITS file
354 359 fits.close()
355 360  
356 361 # Logging
357   - pix_info = ' (%d TS pixels computed)' % self._get_number_of_ts_pixels(fitsfile)
358   - self._log_value(gammalib.TERSE, 'Merge TS map file', fitsfile + pix_info)
  362 + pix_info = ' (%d TS pixels computed)' % \
  363 + self._get_number_of_ts_pixels(fitsfile)
  364 + self._log_value(gammalib.TERSE, 'Merge TS map file',
  365 + fitsfile + pix_info)
359 366  
360 367 # Merge TS map
361 368 self._merge_ts_map(fitsfile)
... ...
cscripts/obsutils.py
... ... @@ -120,6 +120,8 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0,
120 120  
121 121 # Allocate csphagen application and set parameters
122 122 phagen = cscripts.csphagen(obssim.obs())
  123 + phagen['inmodel'] = 'NONE'
  124 + phagen['srcname'] = onsrc
123 125 phagen['ebinalg'] = 'LOG'
124 126 phagen['emin'] = emin
125 127 phagen['emax'] = emax
... ... @@ -187,9 +189,9 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0,
187 189 # Set stacked response
188 190 if edisp:
189 191 binning.obs()[0].response(response['expcube'],
190   - response['psfcube'],
191   - response['edispcube'],
192   - response['bkgcube'])
  192 + response['psfcube'],
  193 + response['edispcube'],
  194 + response['bkgcube'])
193 195 else:
194 196 binning.obs()[0].response(response['expcube'],
195 197 response['psfcube'],
... ... @@ -787,9 +789,26 @@ def get_onoff_obs(cls, obs):
787 789 if cls._logExplicit():
788 790 cls._log.header3('Creating On/Off observations')
789 791  
  792 + # Initialise inmodel, srcname and inexclusion
  793 + inmodel = 'NONE'
  794 + srcname = ''
  795 + inexclusion = 'NONE'
  796 +
  797 + # Set inmodel, srcname and inexclusion if possible
  798 + if 'inmodel' in cls:
  799 + if cls['inmodel'].is_valid():
  800 + inmodel = cls['inmodel'].value()
  801 + if 'srcname' in cls:
  802 + srcname = cls['srcname'].value()
  803 + if 'inexclusion' in cls:
  804 + if cls['inexclusion'].is_valid():
  805 + inexclusion = cls['inexclusion'].value()
  806 +
790 807 # Create On/Off observations
791 808 phagen = cscripts.csphagen(obs)
792   - phagen['inexclusion'] = cls['inexclusion'].value()
  809 + phagen['inmodel'] = inmodel
  810 + phagen['srcname'] = srcname
  811 + phagen['inexclusion'] = inexclusion
793 812 phagen['emin'] = cls['emin'].real()
794 813 phagen['emax'] = cls['emax'].real()
795 814 phagen['enumbins'] = cls['enumbins'].integer()
... ...
src/support/ctool.cpp
... ... @@ -1182,8 +1182,8 @@ std::string ctool::set_outfile_name(const std::string& filename)
1182 1182 bool ctool::is_stacked(void)
1183 1183 {
1184 1184 // First query the minimum and maximum energies
1185   - (*this)["emin"].query();
1186   - (*this)["emax"].query();
  1185 + (*this)["emin"].real();
  1186 + (*this)["emax"].real();
1187 1187  
1188 1188 // Now query the number of energy bins and set the stacked flag
1189 1189 bool stacked = ((*this)["enumbins"].integer() > 0) ? true : false;
... ... @@ -1191,13 +1191,13 @@ bool ctool::is_stacked(void)
1191 1191 // If a stacked analysis is requested then query the spatial definition
1192 1192 // of the cube
1193 1193 if (stacked) {
1194   - (*this)["coordsys"].query();
1195   - (*this)["proj"].query();
1196   - (*this)["xref"].query();
1197   - (*this)["yref"].query();
1198   - (*this)["nxpix"].query();
1199   - (*this)["nypix"].query();
1200   - (*this)["binsz"].query();
  1194 + (*this)["coordsys"].string();
  1195 + (*this)["proj"].string();
  1196 + (*this)["xref"].real();
  1197 + (*this)["yref"].real();
  1198 + (*this)["nxpix"].integer();
  1199 + (*this)["nypix"].integer();
  1200 + (*this)["binsz"].real();
1201 1201 }
1202 1202  
1203 1203 // Return stacked flag
... ... @@ -1229,22 +1229,22 @@ bool ctool::is_onoff(void)
1229 1229  
1230 1230 // Query csphagen parameters
1231 1231 (*this)["inexclusion"].query();
1232   - (*this)["emin"].query();
1233   - (*this)["emax"].query();
1234   - (*this)["enumbins"].query();
1235   - (*this)["coordsys"].query();
1236   - (*this)["xref"].query();
1237   - (*this)["yref"].query();
  1232 + (*this)["emin"].real();
  1233 + (*this)["emax"].real();
  1234 + (*this)["enumbins"].integer();
  1235 + (*this)["coordsys"].string();
  1236 + (*this)["xref"].real();
  1237 + (*this)["yref"].real();
1238 1238 if ((*this)["srcshape"].string() == "CIRCLE"){
1239   - (*this)["rad"].query();
  1239 + (*this)["rad"].real();
1240 1240 }
1241 1241 if ((*this)["bkgmethod"].string() == "REFLECTED"){
1242   - (*this)["bkgregmin"].query();
  1242 + (*this)["bkgregmin"].integer();
1243 1243 }
1244   - (*this)["maxoffset"].query();
1245   - (*this)["etruemin"].query();
1246   - (*this)["etruemax"].query();
1247   - (*this)["etruebins"].query();
  1244 + (*this)["maxoffset"].real();
  1245 + (*this)["etruemin"].real();
  1246 + (*this)["etruemax"].real();
  1247 + (*this)["etruebins"].integer();
1248 1248  
1249 1249 } // endif: method was ONOFF
1250 1250  
... ...