diff --git a/cscripts/csebins.py b/cscripts/csebins.py index 2760cd2..57dedd4 100755 --- a/cscripts/csebins.py +++ b/cscripts/csebins.py @@ -2,7 +2,7 @@ # ========================================================================== # Generates energy boundaries for stacked analysis # -# Copyright (C) 2017 Juergen Knoedlseder +# Copyright (C) 2017-2018 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -55,13 +55,10 @@ class csebins(ctools.csobservation): # Initialise observation container if it is currently empty if self.obs().size() == 0: - # Query "inobs" parameter - filename = self['inobs'].filename() - # If an observation definition file was provided then load it, # otherwise build a single observation with response information - if self._is_valid_filename(filename): - self.obs(gammalib.GObservations(filename)) + if self['inobs'].is_valid(): + self.obs(gammalib.GObservations(self['inobs'].filename())) else: cta = gammalib.GCTAObservation() caldb = gammalib.GCaldb('cta', self['caldb'].string()) diff --git a/cscripts/csiactcopy.py b/cscripts/csiactcopy.py index 8d2b5b1..d5b4dae 100755 --- a/cscripts/csiactcopy.py +++ b/cscripts/csiactcopy.py @@ -2,7 +2,7 @@ # ========================================================================== # Copies IACT data from remote machine # -# Copyright (C) 2016-2017 Michael Mayer +# Copyright (C) 2016-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -74,7 +74,8 @@ class csiactcopy(ctools.cscript): # Get parameters self._prodname = self['prodname'].string() self._outpath = gammalib.expand_env(self['outpath'].string()) - self._runlist = self['runlist'].filename() + if self['runlist'].is_valid(): + self._runlist = self['runlist'].filename() # Write input parameters into logger self._log_parameters(gammalib.TERSE) @@ -322,7 +323,7 @@ class csiactcopy(ctools.cscript): for i in range(local_hdu.ncols()): # Get local and remote columns - local_col = local_hdu[i] + local_col = local_hdu[i] remote_col = remote_hdu[i] # Loop over entries and merge @@ -381,14 +382,14 @@ class csiactcopy(ctools.cscript): self._log_value(gammalib.NORMAL, 'Number of observations', len(runs)) - # ... otherwise, if the runlist file is 'NONE' then leave the + # ... otherwise, if the runlist filename is empty then leave the # run list empty. This implies copying all available data. - elif filename == 'NONE': + elif filename.is_empty(): self._log_string(gammalib.NORMAL, 'Copy all available data') # ... otherwise raise an exception else: - msg = '*** ERROR: Runlist file "%s" not available' % filename + msg = '*** ERROR: Runlist file "%s" not available' % filename.url() raise RuntimeError(msg) # Return run list diff --git a/cscripts/csiactobs.py b/cscripts/csiactobs.py index 39f42ce..98050dd 100755 --- a/cscripts/csiactobs.py +++ b/cscripts/csiactobs.py @@ -106,7 +106,7 @@ class csiactobs(ctools.cscript): self._datapath = gammalib.expand_env(self._datapath) # Query input parameters - self['inmodel'].filename() + self['inmodel'].query() # Read FITS production self._prodname = self['prodname'].string() @@ -161,13 +161,17 @@ class csiactobs(ctools.cscript): # Open master index file and look for prodname master_file = os.path.join(self._datapath, self._master_indx) if not os.path.isfile(master_file): - 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.') + 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.') # Open and load JSON file json_data = open(master_file).read() data = json.loads(json_data) if not 'datasets' in data: - raise RuntimeError('Key "datasets" not available in master index file.') + raise RuntimeError('Key "datasets" not available in master ' + 'index file.') # Get configurations configs = data['datasets'] @@ -190,14 +194,21 @@ class csiactobs(ctools.cscript): # Check index files if self._hdu_index == '' or self._obs_index == '': - raise RuntimeError('*** ERROR: FITS data store "'+self._prodname+'" not available. Run csiactdata to get a list of available storage names') + raise RuntimeError('*** ERROR: FITS data store "'+self._prodname+ + '" not available. Run csiactdata to get a list ' + 'of available storage names') # Check HDU names filename = gammalib.GFilename(self._hdu_index+'[HDU_INDEX]') if not filename.is_fits(): - 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.') - - # Check for existence of 'BKG_SCALE' in the observation index file if required + 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.') + + # Check for existence of 'BKG_SCALE' in the observation index file if + # required if self._use_bkg_scale: # Create filename @@ -209,7 +220,8 @@ class csiactobs(ctools.cscript): # Open FITS file fits = gammalib.GFits(self._obs_index) - # Check if column "BKG_SCALE" is found and signal its possible usage + # Check if column "BKG_SCALE" is found and signal its possible + # usage if not fits['OBS_INDEX'].contains('BKG_SCALE'): self._use_bkg_scale = False @@ -221,8 +233,8 @@ class csiactobs(ctools.cscript): self._use_bkg_scale = False # Create base data directory from hdu index file location - self._subdir = os.path.dirname(self._hdu_index) - self._debug = False # Debugging in client tools + self._subdir = os.path.dirname(self._hdu_index) + self._debug = False # Debugging in client tools # Write input parameters into logger self._log_parameters(gammalib.TERSE) @@ -230,7 +242,7 @@ class csiactobs(ctools.cscript): # Return return - def _background_spectrum(self, prefactor, index, emin = 0.01, emax = 100.0): + def _background_spectrum(self, prefactor, index, emin=0.01, emax=100.0): """ Create a background spectrum model dependent on user parameters @@ -419,8 +431,10 @@ class csiactobs(ctools.cscript): """ # If there are models provided by "inmodels" then append them now to # the model container - filename = self['inmodel'].filename().url() - if filename != '' and filename != 'NONE': + if self['inmodel'].is_valid(): + + # Get filename + filename = self['inmodel'].filename().url() # Log header and input model file self._log_header1(gammalib.TERSE, 'Append input models') @@ -505,8 +519,7 @@ class csiactobs(ctools.cscript): # Return filename return filename - - + def _is_present(self, filename, obs_id, filetype): """ Checks if a filename is present diff --git a/cscripts/cslightcrv.py b/cscripts/cslightcrv.py index d430d72..91c527c 100755 --- a/cscripts/cslightcrv.py +++ b/cscripts/cslightcrv.py @@ -120,7 +120,7 @@ class cslightcrv(ctools.csobservation): # Read ahead output parameters if self._read_ahead(): - self['outfile'].filename() + self['outfile'].query() # Write input parameters into logger self._log_parameters(gammalib.TERSE) @@ -592,11 +592,11 @@ class cslightcrv(ctools.csobservation): # Write header self._log_header1(gammalib.TERSE, 'Save light curve') - # Get light curve filename - outfile = self['outfile'].filename() + # Continue only if filename is valid + if self['outfile'].is_valid(): - # Continue only filename and residual map are valid - if self._fits != None: + # Get light curve filename + outfile = self['outfile'].filename() # Log file name self._log_value(gammalib.NORMAL, 'Light curve file', outfile.url()) diff --git a/cscripts/csmodelinfo.py b/cscripts/csmodelinfo.py index ac250fd..1002b89 100755 --- a/cscripts/csmodelinfo.py +++ b/cscripts/csmodelinfo.py @@ -2,7 +2,7 @@ # ========================================================================== # Shows the content of a model container # -# Copyright (C) 2015-2017 Michael Mayer +# Copyright (C) 2015-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -75,7 +75,7 @@ class csmodelinfo(ctools.cscript): # Query ahead DS9 filename if self._read_ahead(): - self['outds9file'].filename() + self['outds9file'].query() # Write input parameters into logger self._log_parameters(gammalib.TERSE) @@ -122,9 +122,9 @@ class csmodelinfo(ctools.cscript): # Loop over models and initialise dictionaries with model names for model in self._models: - types[model.type()] = 0 + types[model.type()] = 0 instruments[model.instruments()] = 0 - pars_at_limit[model.name()] = [] + pars_at_limit[model.name()] = [] # Loop over models again and fill values to be dumped for model in self._models: @@ -244,12 +244,12 @@ class csmodelinfo(ctools.cscript): """ Save models to ds9 region file """ - # Get output filename - ds9file = self['outds9file'].filename() - # Check if DS9 file is valid - if ds9file != '' and ds9file != 'NONE': - + if self['outds9file'].is_valid(): + + # Get output filename + ds9file = self['outds9file'].filename() + # Write header self._log_header1(gammalib.TERSE, 'Save models in DS9 file') diff --git a/cscripts/csmodelmerge.py b/cscripts/csmodelmerge.py index 661ae16..5a81961 100755 --- a/cscripts/csmodelmerge.py +++ b/cscripts/csmodelmerge.py @@ -2,7 +2,7 @@ # ========================================================================== # Merge model definition XML files # -# Copyright (C) 2015-2017 Michael Mayer +# Copyright (C) 2015-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/cscripts/csmodelselect.py b/cscripts/csmodelselect.py index affa6dc..a2e87e2 100755 --- a/cscripts/csmodelselect.py +++ b/cscripts/csmodelselect.py @@ -2,7 +2,7 @@ # ========================================================================== # Selects model from a model definition XML file # -# Copyright (C) 2016-2017 Juergen Knoedlseder +# Copyright (C) 2016-2018 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/cscripts/csmodelsois.py b/cscripts/csmodelsois.py index 46d518f..0f1a42d 100755 --- a/cscripts/csmodelsois.py +++ b/cscripts/csmodelsois.py @@ -2,7 +2,7 @@ # ========================================================================== # Puts subset of sources in diffuse model cube # -# Copyright (C) 2017 Josh Cardenzana +# Copyright (C) 2017-2018 Josh Cardenzana # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -73,7 +73,7 @@ class csmodelsois(ctools.cscript): # Read input parameters ptsrcsig = self['ptsrcsig'].real() - + # Get the cube centre coordinates self._cubegen['coordsys'].string(self['coordsys'].string()) if self['coordsys'].string() == 'CEL': @@ -88,7 +88,7 @@ class csmodelsois(ctools.cscript): self._cubegen['nxpix'].integer(self['nxpix'].integer()) self._cubegen['nypix'].integer(self['nypix'].integer()) self._cubegen['proj'].string(self['proj'].string()) - + # Get the energy binning parameters self._cubegen['ebinalg'].string(self['ebinalg'].string()) if self['ebinalg'].string() == 'FILE': @@ -98,13 +98,13 @@ class csmodelsois(ctools.cscript): self._cubegen['emax'].real(self['emax'].real()) self._cubegen['enumbins'].integer(self['enumbins'].integer()) - # Get remaining hidden parameters + # Set point source significance self._cubegen['ptsrcsig'].real(ptsrcsig) - + # Read optionally output cube filenames if self._read_ahead(): self._cubegen['outcube'].filename(self['outcube'].filename()) - self['outmodel'].filename() + self['outmodel'].query() # Write parameters into logger self._log_parameters(gammalib.TERSE) @@ -185,12 +185,12 @@ class csmodelsois(ctools.cscript): """ # Save the generated cube if the cube and filename are not empty if ((not self._cubegen.mapcube().cube().is_empty()) and - self._is_valid_filename(self['outcube'].filename())): + self['outcube'].is_valid()): self._cubegen.mapcube().save(self['outcube'].filename(), - self['clobber'].boolean()) + self['clobber'].boolean()) # If requested, save the updated list of models - if self._is_valid_filename(self['outmodel'].filename()): + if self['outmodel'].is_valid(): # Generate a list of models that will be output to file outmodels = gammalib.GModels(self._models) diff --git a/cscripts/csobsdef.py b/cscripts/csobsdef.py index 3e7c4b0..51aeb33 100755 --- a/cscripts/csobsdef.py +++ b/cscripts/csobsdef.py @@ -107,7 +107,7 @@ class csobsdef(ctools.cscript): # Read ahead parameters if self._read_ahead(): - self['outobs'].filename() + self['outobs'].query() # Write input parameters into logger self._log_parameters(gammalib.TERSE) @@ -351,11 +351,11 @@ class csobsdef(ctools.cscript): # Write header and filename into logger self._log_header1(gammalib.TERSE, 'Save observation definition XML file') - # Get output filename in case it was not read ahead - outobs = self['outobs'].filename() - # Check if observation definition XML file is valid - if outobs.url() != 'NONE': + if self['outobs'].is_valid(): + + # Get output filename in case it was not read ahead + outobs = self['outobs'].filename() # Log filename self._log_value(gammalib.NORMAL, 'Observation XML file', outobs.url()) diff --git a/cscripts/csobsinfo.py b/cscripts/csobsinfo.py index 4ae2d96..b6f5a92 100755 --- a/cscripts/csobsinfo.py +++ b/cscripts/csobsinfo.py @@ -76,7 +76,7 @@ class csobsinfo(ctools.csobservation): # Read ahead DS9 filename if self._read_ahead(): - self['outds9file'].filename() + self['outds9file'].query() # Write input parameters into logger self._log_parameters(gammalib.TERSE) @@ -317,12 +317,11 @@ class csobsinfo(ctools.csobservation): observation container into a DS9 region file. If "NONE" is specified for the "outds9file" parameter the method does nothing. """ - - # Get output filename in case it was not read ahead - ds9file = self['outds9file'].filename() - # Check if DS9 file is valid - if ds9file.url() != 'NONE': + if self['outds9file'].is_valid(): + + # Get output filename in case it was not read ahead + ds9file = self['outds9file'].filename() # Write header self._log_header1(gammalib.TERSE, 'Save pointings in DS9 file') diff --git a/cscripts/csphagen.py b/cscripts/csphagen.py index 4469266..22425e9 100755 --- a/cscripts/csphagen.py +++ b/cscripts/csphagen.py @@ -161,11 +161,15 @@ class csphagen(ctools.csobservation): self._setup_observations(self.obs(), True, True, False) # Get spatial component of source model if an input model is defined - inmodel = self['inmodel'].filename() - if not self['inmodel'].is_undefined(): + if self['inmodel'].is_valid(): + inmodel = self['inmodel'].filename() models = gammalib.GModels(inmodel) name = self['srcname'].string() self._src_model = models[name].spatial().clone() + elif self.obs().models().size() > 0: + name = self['srcname'].string() + if self.obs().models().contains(name): + self._src_model = self.obs().models()[name].spatial() # Set energy bounds self._ebounds = self._create_ebounds() @@ -174,7 +178,7 @@ class csphagen(ctools.csobservation): self._src_reg = gammalib.GSkyRegions() # Exclusion map - if not self['inexclusion'].is_undefined(): + if self['inexclusion'].is_valid(): inexclusion = self['inexclusion'].filename() self._excl_reg = gammalib.GSkyRegionMap(inexclusion) self._has_exclusion = True @@ -416,7 +420,6 @@ class csphagen(ctools.csobservation): for obs in self.obs(): # Skip non CTA observations - #if obs.instrument() != 'CTA': if obs.classname() != 'GCTAObservation': self._log_string(gammalib.NORMAL, 'Skip %s observation "%s"' % \ (obs.instrument(), obs.id())) diff --git a/cscripts/csphasecrv.py b/cscripts/csphasecrv.py index ff3804d..afcf896 100755 --- a/cscripts/csphasecrv.py +++ b/cscripts/csphasecrv.py @@ -2,7 +2,7 @@ # ========================================================================== # Generates spectra as a function of phase # -# Copyright (C) 2017 Rolf Buehler +# Copyright (C) 2017-2018 Rolf Buehler # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/cscripts/csresmap.py b/cscripts/csresmap.py index 5dabd68..4bbd2cc 100755 --- a/cscripts/csresmap.py +++ b/cscripts/csresmap.py @@ -2,7 +2,7 @@ # ========================================================================== # Generates a residual map. # -# Copyright (C) 2014-2017 Michael Mayer +# Copyright (C) 2014-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -73,9 +73,7 @@ class csresmap(ctools.csobservation): # If we have a counts cube, then ask whether we also have a model cube. # If a model cube name is given then set self._use_maps=True if self._skip_binning: - modcube = self['modcube'].filename() - if modcube != 'NONE': - self._use_maps = True + self._use_maps = self['modcube'].is_valid() # If not two maps are given, proceed to set up observation if not self._use_maps: diff --git a/cscripts/csresspec.py b/cscripts/csresspec.py index ad3f6b7..a6911d0 100755 --- a/cscripts/csresspec.py +++ b/cscripts/csresspec.py @@ -85,9 +85,7 @@ class csresspec(ctools.csobservation): # components is required, query for precomputed model file and set # use_maps to True if self.obs().size() == 1 and n_binned == 1 and not components: - modcube = self['modcube'].filename() - if modcube != 'NONE': - self._use_maps = True + self._use_maps = self['modcube'].is_valid() # If there are unbinned observations query the energy binning parameters if n_unbinned != 0: @@ -130,7 +128,7 @@ class csresspec(ctools.csobservation): self['ra'].real() self['dec'].real() self['rad'].real() - self['regfile'].filename() + self['regfile'].query() # Unless all observations are On/Off, or we are using precomputed model # maps query whether to use energy dispersion @@ -358,11 +356,15 @@ class csresspec(ctools.csobservation): # Apply user mask if self._mask: + if self['regfile'].is_valid(): + regfile = self['regfile'] + else: + regfile = 'NONE' msg = 'Masking ROI requested by user' self._log_string(gammalib.EXPLICIT, msg) cube = self._masked_cube(cube, self['ra'], self['dec'], self['rad'], - regfile=self['regfile']) + regfile=regfile) # Extract skymap and clip at 0 to null masked areas counts = cube.counts().copy() @@ -688,17 +690,14 @@ class csresspec(ctools.csobservation): # Write header self._log_header1(gammalib.TERSE, 'Save residuals') - # Continue only if FITS file is valid - if self._fits != None: - - # Get outfile parameter - outfile = self['outfile'].filename() + # Get outfile parameter + outfile = self['outfile'].filename() - # Log file name - self._log_value(gammalib.NORMAL, 'Residuals file', outfile.url()) + # Log file name + self._log_value(gammalib.NORMAL, 'Residuals file', outfile.url()) - # Save residuals - self._fits.saveto(outfile, self['clobber'].boolean()) + # Save residuals + self._fits.saveto(outfile, self['clobber'].boolean()) # Return return diff --git a/cscripts/cssens.py b/cscripts/cssens.py index e55589a..1b9e080 100755 --- a/cscripts/cssens.py +++ b/cscripts/cssens.py @@ -2,7 +2,7 @@ # ========================================================================== # Computes the array sensitivity using the Test Statistic for a test source # -# Copyright (C) 2011-2017 Juergen Knoedlseder +# Copyright (C) 2011-2018 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -132,8 +132,7 @@ class cssens(ctools.csobservation): Observation container """ # If an observation was provided on input then load it from XML file - filename = self['inobs'].filename() - if filename != 'NONE' and filename != '': + if self['inobs'].is_valid(): obs = self._get_observations() # ... otherwise allocate a single observation diff --git a/cscripts/cssrcdetect.py b/cscripts/cssrcdetect.py index af072a6..a5dbc9d 100755 --- a/cscripts/cssrcdetect.py +++ b/cscripts/cssrcdetect.py @@ -2,7 +2,7 @@ # ========================================================================== # Detects sources in a sky map # -# Copyright (C) 2016-2017 Juergen Knoedlseder +# Copyright (C) 2016-2018 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -72,7 +72,7 @@ class cssrcdetect(ctools.cscript): self['exclrad'].real() self['fit_pos'].boolean() self['fit_shape'].boolean() - + # Query ahead output model filename if self._read_ahead(): self['outmodel'].filename() diff --git a/cscripts/cstsdist.py b/cscripts/cstsdist.py index e31af55..bdc1b43 100755 --- a/cscripts/cstsdist.py +++ b/cscripts/cstsdist.py @@ -73,12 +73,7 @@ class cstsdist(ctools.csobservation): # Query parameters self['edisp'].boolean() self['ntrials'].integer() - self['debug'].boolean() - - # Read ahead output parameters - #if self._read_ahead(): - # self['outfile'].filename() self['outfile'].filename() # Write input parameters into logger diff --git a/cscripts/cstsmapmerge.py b/cscripts/cstsmapmerge.py index d6cd58f..8e9bbeb 100755 --- a/cscripts/cstsmapmerge.py +++ b/cscripts/cstsmapmerge.py @@ -2,7 +2,7 @@ # ========================================================================== # Merge Test Statistic maps # -# Copyright (C) 2015-2017 Michael Mayer +# Copyright (C) 2015-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -274,7 +274,8 @@ class cstsmapmerge(ctools.cscript): if not gammalib.GFilename(fitsfile).is_fits(): # Log message - self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +' (not a FITS file)') + self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile + + ' (not a FITS file)') # Continue continue @@ -292,8 +293,10 @@ class cstsmapmerge(ctools.cscript): file0 = fitsfile # Log message - pix_info = ' (%d TS pixels computed)' % self._get_number_of_ts_pixels(fitsfile) - self._log_value(gammalib.TERSE, 'Initial TS map file', fitsfile + pix_info) + pix_info = ' (%d TS pixels computed)' % \ + self._get_number_of_ts_pixels(fitsfile) + self._log_value(gammalib.TERSE, 'Initial TS map file', + fitsfile + pix_info) # Leave loop break @@ -305,7 +308,8 @@ class cstsmapmerge(ctools.cscript): fits.close() # Info message - self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +' (no "STATUS MAP" extension)') + self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile + + ' (no "STATUS MAP" extension)') # Continue continue @@ -313,10 +317,9 @@ class cstsmapmerge(ctools.cscript): # Signal if no suitable file was found if file0 == '': msg = 'None of the provided files seems to be a sliced ' + \ - 'TS map file (none has a "STATUS MAP" ' + \ - 'extension)' + 'TS map file (none has a "STATUS MAP" ' + \ + 'extension)' raise RuntimeError(msg) - # ... otherwise merge files else: @@ -338,7 +341,8 @@ class cstsmapmerge(ctools.cscript): # Skip if file is not FITS if not gammalib.GFilename(fitsfile).is_fits(): - self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +' (not a FITS file)') + self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile + + ' (not a FITS file)') continue # Open FITS file @@ -347,15 +351,18 @@ class cstsmapmerge(ctools.cscript): # Skip if file does not contain status map if not fits.contains('STATUS MAP'): fits.close() - self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile +' (no "STATUS MAP" extension)') + self._log_value(gammalib.EXPLICIT, 'Skip file', fitsfile + + ' (no "STATUS MAP" extension)') continue # Close FITS file fits.close() # Logging - pix_info = ' (%d TS pixels computed)' % self._get_number_of_ts_pixels(fitsfile) - self._log_value(gammalib.TERSE, 'Merge TS map file', fitsfile + pix_info) + pix_info = ' (%d TS pixels computed)' % \ + self._get_number_of_ts_pixels(fitsfile) + self._log_value(gammalib.TERSE, 'Merge TS map file', + fitsfile + pix_info) # Merge TS map self._merge_ts_map(fitsfile) diff --git a/cscripts/obsutils.py b/cscripts/obsutils.py index 9d80c96..6b24a1c 100755 --- a/cscripts/obsutils.py +++ b/cscripts/obsutils.py @@ -120,6 +120,8 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, # Allocate csphagen application and set parameters phagen = cscripts.csphagen(obssim.obs()) + phagen['inmodel'] = 'NONE' + phagen['srcname'] = onsrc phagen['ebinalg'] = 'LOG' phagen['emin'] = emin phagen['emax'] = emax @@ -187,9 +189,9 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, # Set stacked response if edisp: binning.obs()[0].response(response['expcube'], - response['psfcube'], - response['edispcube'], - response['bkgcube']) + response['psfcube'], + response['edispcube'], + response['bkgcube']) else: binning.obs()[0].response(response['expcube'], response['psfcube'], @@ -787,9 +789,26 @@ def get_onoff_obs(cls, obs): if cls._logExplicit(): cls._log.header3('Creating On/Off observations') + # Initialise inmodel, srcname and inexclusion + inmodel = 'NONE' + srcname = '' + inexclusion = 'NONE' + + # Set inmodel, srcname and inexclusion if possible + if 'inmodel' in cls: + if cls['inmodel'].is_valid(): + inmodel = cls['inmodel'].value() + if 'srcname' in cls: + srcname = cls['srcname'].value() + if 'inexclusion' in cls: + if cls['inexclusion'].is_valid(): + inexclusion = cls['inexclusion'].value() + # Create On/Off observations phagen = cscripts.csphagen(obs) - phagen['inexclusion'] = cls['inexclusion'].value() + phagen['inmodel'] = inmodel + phagen['srcname'] = srcname + phagen['inexclusion'] = inexclusion phagen['emin'] = cls['emin'].real() phagen['emax'] = cls['emax'].real() phagen['enumbins'] = cls['enumbins'].integer() diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index fb52f6d..d262cbf 100755 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -1182,8 +1182,8 @@ std::string ctool::set_outfile_name(const std::string& filename) bool ctool::is_stacked(void) { // First query the minimum and maximum energies - (*this)["emin"].query(); - (*this)["emax"].query(); + (*this)["emin"].real(); + (*this)["emax"].real(); // Now query the number of energy bins and set the stacked flag bool stacked = ((*this)["enumbins"].integer() > 0) ? true : false; @@ -1191,13 +1191,13 @@ bool ctool::is_stacked(void) // If a stacked analysis is requested then query the spatial definition // of the cube if (stacked) { - (*this)["coordsys"].query(); - (*this)["proj"].query(); - (*this)["xref"].query(); - (*this)["yref"].query(); - (*this)["nxpix"].query(); - (*this)["nypix"].query(); - (*this)["binsz"].query(); + (*this)["coordsys"].string(); + (*this)["proj"].string(); + (*this)["xref"].real(); + (*this)["yref"].real(); + (*this)["nxpix"].integer(); + (*this)["nypix"].integer(); + (*this)["binsz"].real(); } // Return stacked flag @@ -1229,22 +1229,22 @@ bool ctool::is_onoff(void) // Query csphagen parameters (*this)["inexclusion"].query(); - (*this)["emin"].query(); - (*this)["emax"].query(); - (*this)["enumbins"].query(); - (*this)["coordsys"].query(); - (*this)["xref"].query(); - (*this)["yref"].query(); + (*this)["emin"].real(); + (*this)["emax"].real(); + (*this)["enumbins"].integer(); + (*this)["coordsys"].string(); + (*this)["xref"].real(); + (*this)["yref"].real(); if ((*this)["srcshape"].string() == "CIRCLE"){ - (*this)["rad"].query(); + (*this)["rad"].real(); } if ((*this)["bkgmethod"].string() == "REFLECTED"){ - (*this)["bkgregmin"].query(); + (*this)["bkgregmin"].integer(); } - (*this)["maxoffset"].query(); - (*this)["etruemin"].query(); - (*this)["etruemax"].query(); - (*this)["etruebins"].query(); + (*this)["maxoffset"].real(); + (*this)["etruemin"].real(); + (*this)["etruemax"].real(); + (*this)["etruebins"].integer(); } // endif: method was ONOFF