From e0d308239555e1f7377a4540ea5e1e1d737a6079 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sat, 21 Oct 2017 01:30:02 +0200 Subject: [PATCH] Solve some minor issues --- cscripts/csmodelsois.py | 83 ++++++++++++++++++++++++++++++++++++----------------------------------------------- cscripts/csobsdef.py | 4 ++-- cscripts/csphagen.py | 4 +++- cscripts/csphasecrv.py | 9 +++++---- cscripts/cspull.py | 1 - cscripts/cssens.py | 4 ---- cscripts/cssrcdetect.py | 2 +- cscripts/ioutils.py | 2 +- cscripts/modutils.py | 4 ++-- cscripts/obsutils.py | 26 +++++++++++++------------- examples/make_pointings.py | 2 +- examples/make_spectrum.py | 2 +- examples/make_ts_distributions.py | 11 +++++------ examples/pipeline_binned_disk.py | 2 +- examples/pipeline_binned_mem.py | 2 +- examples/pipeline_stacked_disk.py | 2 +- examples/pipeline_stacked_mem.py | 2 +- examples/pipeline_unbinned_disk.py | 2 +- examples/pipeline_unbinned_mem.py | 2 +- examples/show_irf.py | 12 +++++------- examples/show_pull_evolution.py | 3 +-- examples/show_pull_histogram.py | 7 +++---- examples/show_response.py | 10 +++++----- examples/show_ts_distribution.py | 14 +++++++------- pyext/ctool.i | 12 ++++++------ src/ctskymap/ctskymap.cpp | 2 +- src/support/ctool.cpp | 11 +++++++---- src/support/ctool.hpp | 6 +++--- test/science_verification.py | 6 +++--- test/test_cscaldb.py | 2 +- test/test_csiactdata.py | 2 +- test/test_csinfo.py | 6 +++--- test/test_csmodelinfo.py | 2 +- test/test_csmodelselect.py | 1 - test/test_csmodelsois.py | 1 - test/test_csobsinfo.py | 2 +- test/test_csobsselect.py | 1 - test/test_csroot2caldb.py | 2 +- test/test_cssrcdetect.py | 1 - test/test_ctbutterfly.py | 3 +-- test/test_cterror.py | 1 - test/test_ctlike.py | 1 - test/test_ctmapcube.py | 1 - test/test_ctobssim.py | 10 +++++----- test/test_ctphase.py | 48 ++++++++++++++++++++++++------------------------ test/test_ctulimit.py | 14 +------------- test/test_examples.py.in | 3 --- 47 files changed, 156 insertions(+), 194 deletions(-) diff --git a/cscripts/csmodelsois.py b/cscripts/csmodelsois.py index a3745a3..cac3f46 100755 --- a/cscripts/csmodelsois.py +++ b/cscripts/csmodelsois.py @@ -55,7 +55,9 @@ class csmodelsois(ctools.cscript): self._version = ctools.__version__ # Initialize parameters - self._init_members() + self._cubegen = ctools.ctmapcube() + self._models = gammalib.GModels() + self._cubemodels = gammalib.GModels() # Initialise application by calling the appropriate class constructor self._init_cscript(argv) @@ -65,18 +67,6 @@ class csmodelsois(ctools.cscript): # Private methods - def _init_members(self): - """ - Initialize the parameters for this object - """ - # Initialise parameters - self.cubegen = ctools.ctmapcube() # Implements ctmapcube for generate the cube - self.m_models = gammalib.GModels() # Stores the full list of input models - self.cubemodels = gammalib.GModels() # Stores the list of models to be written to file - - # Return - return - def _get_parameters(self): """ Get parameters from parfile @@ -89,39 +79,39 @@ class csmodelsois(ctools.cscript): ptsrcsig = self['ptsrcsig'].real() # Get the cube centre coordinates - self.cubegen['coordsys'].string(self['coordsys'].string()) + self._cubegen['coordsys'].string(self['coordsys'].string()) if self['coordsys'].string() == 'CEL': - self.cubegen['xref'].real(self['ra'].real()) - self.cubegen['yref'].real(self['dec'].real()) + self._cubegen['xref'].real(self['ra'].real()) + self._cubegen['yref'].real(self['dec'].real()) else: - self.cubegen['xref'].real(self['glon'].real()) - self.cubegen['yref'].real(self['glat'].real()) + self._cubegen['xref'].real(self['glon'].real()) + self._cubegen['yref'].real(self['glat'].real()) # Get spatial binning parameters - self.cubegen['binsz'].real(self['binsz'].real()) - self.cubegen['nxpix'].integer(self['nxpix'].integer()) - self.cubegen['nypix'].integer(self['nypix'].integer()) - self.cubegen['proj'].string(self['proj'].string()) + self._cubegen['binsz'].real(self['binsz'].real()) + 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()) + self._cubegen['ebinalg'].string(self['ebinalg'].string()) if self['ebinalg'].string() == 'FILE': - self.cubegen['ebinfile'].filename(self['ebinfile'].filename()) + self._cubegen['ebinfile'].filename(self['ebinfile'].filename()) else: - self.cubegen['emin'].real(self['emin'].real()) - self.cubegen['emax'].real(self['emax'].real()) - self.cubegen['enumbins'].integer(self['enumbins'].integer()) + self._cubegen['emin'].real(self['emin'].real()) + self._cubegen['emax'].real(self['emax'].real()) + self._cubegen['enumbins'].integer(self['enumbins'].integer()) # Get remaining hidden parameters - self.cubegen['ptsrcsig'].real(ptsrcsig) + self._cubegen['ptsrcsig'].real(ptsrcsig) # Read optionally output cube filenames if self._read_ahead(): - self.cubegen['outcube'].filename(self['outcube'].filename()) + self._cubegen['outcube'].filename(self['outcube'].filename()) self['outmodel'].filename() # Write parameters into logger - self._log_parameters(gammalib.TERSE); + self._log_parameters(gammalib.TERSE) return @@ -133,28 +123,27 @@ class csmodelsois(ctools.cscript): sources = self['soilist'].string().split(',') # Load the model into a model container - if (self.m_models.size() == 0): - self.m_models = gammalib.GModels(self['inmodel'].filename()) + if (self._models.size() == 0): + self._models = gammalib.GModels(self['inmodel'].filename()) # Store a copy of the models - self.cubemodels = self.m_models.copy() + self._cubemodels = self._models.copy() # Loop through models and pull out all models not in the list - models2remove = [] - for model in self.m_models: + for model in self._models: # If model is not a sky model then continue if model.classname() != 'GModelSky': - self.cubemodels.remove(model.name()) + self._cubemodels.remove(model.name()) # ... otherwise, if model is in list of sources the remove it # from the container elif model.name() in sources: - self.cubemodels.remove(model.name()) + self._cubemodels.remove(model.name()) # Log the number of models to be put into the cube self._log_value(self['chatter'].integer(), 'Numner of cube models', - self.cubemodels.size()) + self._cubemodels.size()) # Return return @@ -176,16 +165,16 @@ class csmodelsois(ctools.cscript): self._gen_cubemodel() # Only run if there still models to be filled into the cube - if not self.cubemodels.is_empty(): + if not self._cubemodels.is_empty(): # Log action self._log_string(gammalib.NORMAL, 'Generating model cube') # Fill the cube models into the ctmapcube object - self.cubegen.models(self.cubemodels) + self._cubegen.models(self._cubemodels) # Run the map generating method - self.cubegen.run() + self._cubegen.run() else: self._log_string(gammalib.NORMAL, @@ -199,19 +188,19 @@ class csmodelsois(ctools.cscript): Save the cube and optionally the updated XML model file """ # Save the generated cube if the cube and filename are not empty - if ((not self.cubegen.mapcube().cube().is_empty()) and + if ((not self._cubegen.mapcube().cube().is_empty()) and self._is_valid_filename(self['outcube'].filename())): - self.cubegen.mapcube().save(self['outcube'].filename(), + self._cubegen.mapcube().save(self['outcube'].filename(), self['clobber'].boolean()) # If requested, save the updated list of models if self._is_valid_filename(self['outmodel'].filename()): # Generate a list of models that will be output to file - outmodels = gammalib.GModels(self.m_models) + outmodels = gammalib.GModels(self._models) # Remove all models used in the generated cube - for model in self.cubemodels: + for model in self._cubemodels: outmodels.remove(model.name()) # Generate the actual cube model @@ -236,7 +225,7 @@ class csmodelsois(ctools.cscript): Return the mapcube generated by the underlying 'ctmapcube' object """ # Return - return self.cubegen.mapcube() + return self._cubegen.mapcube() def cubemodelname(self): """ @@ -255,7 +244,7 @@ class csmodelsois(ctools.cscript): Model container """ # Set models - self.m_models = models + self._models = models # Return return diff --git a/cscripts/csobsdef.py b/cscripts/csobsdef.py index f1a2d7e..a451c45 100755 --- a/cscripts/csobsdef.py +++ b/cscripts/csobsdef.py @@ -119,7 +119,7 @@ class csobsdef(ctools.cscript): # Return return - def _set_response(self, obs, caldb, irf): + def _set_irf(self, obs, caldb, irf): """ Set response for an observation @@ -258,7 +258,7 @@ class csobsdef(ctools.cscript): else: irf = self['irf'].string() if caldb != '' and irf != '': - obs = self._set_response(obs, caldb, irf) + obs = self._set_irf(obs, caldb, irf) # Set deadtime correction factor. If no information is provided # then use the user parameter value "deadc". diff --git a/cscripts/csphagen.py b/cscripts/csphagen.py index dc59eef..39ffe2e 100755 --- a/cscripts/csphagen.py +++ b/cscripts/csphagen.py @@ -39,7 +39,7 @@ class csphagen(ctools.cscript): Constructor """ # Set name, version - self._name = 'csphagen' + self._name = 'csphagen' self._version = ctools.__version__ # Initialise observation container from constructor arguments @@ -56,6 +56,8 @@ class csphagen(ctools.cscript): self._bkg_regs = [] self._excl_reg = None self._has_exclusion = False + self._srcshape = '' + self._rad = 0.0 # Return return diff --git a/cscripts/csphasecrv.py b/cscripts/csphasecrv.py index 7b3b3be..66ba450 100755 --- a/cscripts/csphasecrv.py +++ b/cscripts/csphasecrv.py @@ -62,10 +62,11 @@ class csphasecrv(ctools.cscript): # Initialise some members. Phases are stored in a nested list # [[ph1min,ph1max], [ph2min,ph2max],..] - self._srcname = '' - self._phbins = [[0.0,1.0]] - self._stacked = False - self._fits = gammalib.GFits() + self._srcname = '' + self._phbins = [[0.0,1.0]] + self._stacked = False + self._fits = gammalib.GFits() + self._fitmodels = {} # Initialise observation container from constructor arguments. self._obs, argv = self._set_input_obs(argv) diff --git a/cscripts/cspull.py b/cscripts/cspull.py index 775da83..062a945 100755 --- a/cscripts/cspull.py +++ b/cscripts/cspull.py @@ -19,7 +19,6 @@ # # ========================================================================== import sys -import math import gammalib import ctools from cscripts import obsutils diff --git a/cscripts/cssens.py b/cscripts/cssens.py index 6aa8e82..d25f258 100755 --- a/cscripts/cssens.py +++ b/cscripts/cssens.py @@ -19,7 +19,6 @@ # # ========================================================================== import sys -import csv import math import gammalib import ctools @@ -387,9 +386,6 @@ class cssens(ctools.cscript): energy = gammalib.GEnergy(e_mean, 'TeV') sensitivity = source.spectral().eval(energy) * e_mean*erg_mean*1.0e6 - # Assess quality based on a comparison between Npred and Nevents - quality = npred - nevents - # Write fit results into logger name = 'Iteration %d' % iterations value = ('TS=%10.4f Sim=%9.4f mCrab Fit=%9.4f mCrab ' diff --git a/cscripts/cssrcdetect.py b/cscripts/cssrcdetect.py index 60d2e68..c9fc73a 100755 --- a/cscripts/cssrcdetect.py +++ b/cscripts/cssrcdetect.py @@ -319,7 +319,7 @@ class cssrcdetect(ctools.cscript): # Get fit parameters fit_pos = self['fit_pos'].boolean() - fit_shape = self['fit_shape'].boolean() + #fit_shape = self['fit_shape'].boolean() # Loop over all parameters for par in spatial: diff --git a/cscripts/ioutils.py b/cscripts/ioutils.py index 8dae0a6..bb7b096 100755 --- a/cscripts/ioutils.py +++ b/cscripts/ioutils.py @@ -20,7 +20,7 @@ import csv import sys import gammalib -import ctools +#import ctools # ========================= # diff --git a/cscripts/modutils.py b/cscripts/modutils.py index e49d037..b0a92ed 100755 --- a/cscripts/modutils.py +++ b/cscripts/modutils.py @@ -17,8 +17,8 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib -import ctools +#import gammalib +#import ctools # ============================================ # diff --git a/cscripts/obsutils.py b/cscripts/obsutils.py index d886a78..5035009 100755 --- a/cscripts/obsutils.py +++ b/cscripts/obsutils.py @@ -76,21 +76,21 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, Observation container filled with simulated events """ # Allocate ctobssim application and set parameters - sim = ctools.ctobssim(obs) - sim['seed'] = seed - sim['edisp'] = edisp - sim['chatter'] = chatter - sim['debug'] = debug + obssim = ctools.ctobssim(obs) + obssim['seed'] = seed + obssim['edisp'] = edisp + obssim['chatter'] = chatter + obssim['debug'] = debug # Optionally open the log file if log: - sim.logFileOpen() + obssim.logFileOpen() # Run ctobssim application. This will loop over all observations in the # container and simulation the events for each observation. Note that # events are not added together, they still apply to each observation # separately. - sim.run() + obssim.run() # Binned option? if nbins > 0: @@ -101,12 +101,12 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, if emin == None or emax == None: emin = 1.0e30 emax = 0.0 - for run in sim.obs(): + for run in obssim.obs(): emin = min(run.events().ebounds().emin().TeV(), emin) emax = max(run.events().ebounds().emax().TeV(), emax) # Allocate ctbin application and set parameters - bin = ctools.ctbin(sim.obs()) + bin = ctools.ctbin(obssim.obs()) bin['ebinalg'] = 'LOG' bin['emin'] = emin bin['emax'] = emax @@ -130,10 +130,10 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, # If we have multiple input observations then create stacked response # cubes and append them to the observation - if len(sim.obs()) > 1: + if len(obssim.obs()) > 1: # Get stacked response (use pointing for map centre) - response = get_stacked_response(sim.obs(), None, None, + response = get_stacked_response(obssim.obs(), None, None, binsz=binsz, nxpix=npix, nypix=npix, emin=emin, emax=emax, enumbins=nbins, edisp=edisp, @@ -166,10 +166,10 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, # Make a deep copy of the observation that will be returned # (the ctobssim object will go out of scope one the function is # left) - obs = sim.obs().copy() + obs = obssim.obs().copy() # Delete the simulation - del sim + del obssim # Return observation container return obs diff --git a/examples/make_pointings.py b/examples/make_pointings.py index 9299d95..d879e8e 100755 --- a/examples/make_pointings.py +++ b/examples/make_pointings.py @@ -301,7 +301,7 @@ def set_irf(site, obs, caldb, lst=True): # Compute Right Ascension and Declination of pointing pnt = gammalib.GSkyDir() pnt.lb_deg(obs['lon'], obs['lat']) - ra = pnt.ra_deg() + #ra = pnt.ra_deg() dec = pnt.dec_deg() # Set geographic latitude of array diff --git a/examples/make_spectrum.py b/examples/make_spectrum.py index 759602f..2aae62e 100755 --- a/examples/make_spectrum.py +++ b/examples/make_spectrum.py @@ -204,7 +204,7 @@ def make_spectrum(): {'option': '-p', 'value': ''}] # Get arguments and options from command line arguments - args, options = cscripts.ioutils.get_args_options(options, usage) + _, options = cscripts.ioutils.get_args_options(options, usage) # Extract script parameters from options datadir = options[0]['value'] diff --git a/examples/make_ts_distributions.py b/examples/make_ts_distributions.py index 880ccce..8ae5132 100755 --- a/examples/make_ts_distributions.py +++ b/examples/make_ts_distributions.py @@ -18,7 +18,6 @@ # along with this program. If not, see . # # ========================================================================== -import sys import cscripts @@ -101,13 +100,13 @@ def make_ts_distribution(): {'option': '-d', 'value': 'data'}] # Get arguments and options from command line arguments - args, options = cscripts.ioutils.get_args_options(options, usage) + _, options = cscripts.ioutils.get_args_options(options, usage) # Extract script parameters from options ntrials = int(options[0]['value']) enumbins = int(options[1]['value']) duration = float(options[2]['value']) - max_threads = int(options[3]['value']) + #max_threads = int(options[3]['value']) datadir = options[4]['value'] # Loop over energy bands. The energy bands are those that are also @@ -116,7 +115,7 @@ def make_ts_distribution(): # Set energies loge = -1.7 + ieng * 0.2 - emean = pow(10.0, loge) + #emean = pow(10.0, loge) emin = pow(10.0, loge-0.1) emax = pow(10.0, loge+0.1) if loge < 0: @@ -125,8 +124,8 @@ def make_ts_distribution(): loge = 'p'+str(abs(loge)) # Create TS - create_ts(datadir, loge, emin, emax, ntrials=ntrials, enumbins=enumbins, - duration=duration) + create_ts(datadir, loge, emin, emax, ntrials=ntrials, + enumbins=enumbins, duration=duration) # Return return diff --git a/examples/pipeline_binned_disk.py b/examples/pipeline_binned_disk.py index e0043bd..6cb2b43 100755 --- a/examples/pipeline_binned_disk.py +++ b/examples/pipeline_binned_disk.py @@ -138,7 +138,7 @@ def pipeline_binned_disk(): options = [{'option': '-d', 'value': 'data'}] # Get arguments and options from command line arguments - args, options = cscripts.ioutils.get_args_options(options, usage) + _, options = cscripts.ioutils.get_args_options(options, usage) # Extract script parameters from options datadir = options[0]['value'] diff --git a/examples/pipeline_binned_mem.py b/examples/pipeline_binned_mem.py index 176420b..4d356f1 100755 --- a/examples/pipeline_binned_mem.py +++ b/examples/pipeline_binned_mem.py @@ -109,7 +109,7 @@ def pipeline_binned_mem(): options = [{'option': '-d', 'value': 'data'}] # Get arguments and options from command line arguments - args, options = cscripts.ioutils.get_args_options(options, usage) + _, options = cscripts.ioutils.get_args_options(options, usage) # Extract script parameters from options datadir = options[0]['value'] diff --git a/examples/pipeline_stacked_disk.py b/examples/pipeline_stacked_disk.py index 30f7970..bbd5f5a 100755 --- a/examples/pipeline_stacked_disk.py +++ b/examples/pipeline_stacked_disk.py @@ -188,7 +188,7 @@ def pipeline_stacked_disk(): options = [{'option': '-d', 'value': 'data'}] # Get arguments and options from command line arguments - args, options = cscripts.ioutils.get_args_options(options, usage) + _, options = cscripts.ioutils.get_args_options(options, usage) # Extract script parameters from options datadir = options[0]['value'] diff --git a/examples/pipeline_stacked_mem.py b/examples/pipeline_stacked_mem.py index 798984a..73e6b6b 100755 --- a/examples/pipeline_stacked_mem.py +++ b/examples/pipeline_stacked_mem.py @@ -161,7 +161,7 @@ def pipeline_stacked_mem(): options = [{'option': '-d', 'value': 'data'}] # Get arguments and options from command line arguments - args, options = cscripts.ioutils.get_args_options(options, usage) + _, options = cscripts.ioutils.get_args_options(options, usage) # Extract script parameters from options datadir = options[0]['value'] diff --git a/examples/pipeline_unbinned_disk.py b/examples/pipeline_unbinned_disk.py index c1f61b1..52473e4 100755 --- a/examples/pipeline_unbinned_disk.py +++ b/examples/pipeline_unbinned_disk.py @@ -112,7 +112,7 @@ def pipeline_unbinned_disk(): options = [{'option': '-d', 'value': 'data'}] # Get arguments and options from command line arguments - args, options = cscripts.ioutils.get_args_options(options, usage) + _, options = cscripts.ioutils.get_args_options(options, usage) # Extract script parameters from options datadir = options[0]['value'] diff --git a/examples/pipeline_unbinned_mem.py b/examples/pipeline_unbinned_mem.py index baf8a90..68ee239 100755 --- a/examples/pipeline_unbinned_mem.py +++ b/examples/pipeline_unbinned_mem.py @@ -94,7 +94,7 @@ def pipeline_unbinned_mem(): options = [{'option': '-d', 'value': 'data'}] # Get arguments and options from command line arguments - args, options = cscripts.ioutils.get_args_options(options, usage) + _, options = cscripts.ioutils.get_args_options(options, usage) # Extract script parameters from options datadir = options[0]['value'] diff --git a/examples/show_irf.py b/examples/show_irf.py index 0635d03..b40b4ec 100755 --- a/examples/show_irf.py +++ b/examples/show_irf.py @@ -226,15 +226,13 @@ def plot_psf(sub, psf, emin=None, emax=None, tmin=None, tmax=None, # ====================== # # Plot energy dispersion # # ====================== # -def plot_edisp(sub, edisp, emin=None, emax=None, tmin=None, tmax=None, +def plot_edisp(edisp, emin=None, emax=None, tmin=None, tmax=None, nengs=100, nthetas=100): """ Plot Background template Parameters ---------- - sub : figure - Subplot edisp : `~gammalib.GCTAEdisp2D` Instrument Response Function emin : float, optional @@ -296,8 +294,8 @@ def plot_edisp(sub, edisp, emin=None, emax=None, tmin=None, tmax=None, row_std = [] # Compute detx and dety - detx = theta*gammalib.deg2rad - dety = 0.0 + #detx = theta*gammalib.deg2rad + #dety = 0.0 # Loop over energies for logenergy in logenergies: @@ -551,8 +549,8 @@ def plot_irf(irf, emin, emax, tmin, tmax, plotfile): plot_bkg(ax3, irf.background(), emin=emin, emax=emax, tmin=tmin, tmax=tmax) # Plot Edisp - ax4 = fig.add_subplot(234) - plot_edisp(ax4, irf.edisp(), emin=emin, emax=emax, tmin=tmin, tmax=tmax) + fig.add_subplot(234) + plot_edisp(irf.edisp(), emin=emin, emax=emax, tmin=tmin, tmax=tmax) # Show plots or save it into file if len(plotfile) > 0: diff --git a/examples/show_pull_evolution.py b/examples/show_pull_evolution.py index 1f048ee..4920388 100755 --- a/examples/show_pull_evolution.py +++ b/examples/show_pull_evolution.py @@ -2,7 +2,7 @@ # ========================================================================== # Shows the evolution of the mean and rms pull # -# Copyright (C) 2015-2016 Juergen Knoedlseder +# Copyright (C) 2015-2017 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 @@ -19,7 +19,6 @@ # # ========================================================================== import sys -import csv import cscripts try: import matplotlib.pyplot as plt diff --git a/examples/show_pull_histogram.py b/examples/show_pull_histogram.py index ef580de..76efec8 100755 --- a/examples/show_pull_histogram.py +++ b/examples/show_pull_histogram.py @@ -2,7 +2,7 @@ # ========================================================================== # Shows the pull histogram # -# Copyright (C) 2011-2016 Juergen Knoedlseder +# Copyright (C) 2011-2017 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 @@ -19,7 +19,6 @@ # # ========================================================================== import sys -import csv import cscripts try: import matplotlib.pyplot as plt @@ -58,8 +57,8 @@ def plot_pull_histogram(filename, parname, nbins, plotfile): values = np.array(cscripts.ioutils.read_pull_values(filename, parname)) # Create histogram - n, bins, patches = plt.hist(values, nbins, range=[-4.0,4.0], - normed=True, facecolor='green') + _, bins, _ = plt.hist(values, nbins, range=[-4.0,4.0], + normed=True, facecolor='green') # Create expected distribution y = mlab.normpdf(bins, 0.0, 1.0) diff --git a/examples/show_response.py b/examples/show_response.py index 0386108..bc7290b 100755 --- a/examples/show_response.py +++ b/examples/show_response.py @@ -2,7 +2,7 @@ # ========================================================================== # Shows one or several CTA response functions. # -# Copyright (C) 2014-2016 Juergen Knoedlseder +# Copyright (C) 2014-2017 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 @@ -54,9 +54,9 @@ def sigma_lima(Non, Noff, alpha=0.2): """ # Compute sensitivity in Gaussian sigma alpha1 = alpha + 1.0 - sum = Non + Noff - arg1 = Non / sum - arg2 = Noff / sum + Ntotal = Non + Noff + arg1 = Non / Ntotal + arg2 = Noff / Ntotal term1 = Non * math.log((alpha1/alpha)*arg1) term2 = Noff * math.log(alpha1*arg2) sigma = math.sqrt(2.0 * (term1 + term2)) @@ -425,7 +425,7 @@ def show_response(): options = [{'option': '-p', 'value': ''}] # Get arguments and options from command line arguments - args, options = cscripts.ioutils.get_args_options(options, usage) + _, options = cscripts.ioutils.get_args_options(options, usage) # Extract script parameters from options plotfile = options[0]['value'] diff --git a/examples/show_ts_distribution.py b/examples/show_ts_distribution.py index ac5a670..0a89da8 100755 --- a/examples/show_ts_distribution.py +++ b/examples/show_ts_distribution.py @@ -2,7 +2,7 @@ # ========================================================================== # Display TS distribution generated by cstsdist # -# Copyright (C) 2011-2016 Jurgen Knodlseder +# Copyright (C) 2011-2017 Jurgen Knodlseder # # 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 @@ -165,7 +165,7 @@ def dist_cdf(values, nbins, title, plotfile, expect=''): for i in range(nbins): x_min = min_value+i*binsize x_max = min_value+(i+1)*binsize - x_val = 0.5*(x_min+x_max) + #x_val = 0.5*(x_min+x_max) y_val = 0.0 for ts in values: if ts > x_min: @@ -235,9 +235,9 @@ def dist_pdf(values, nbins, title, plotfile, expect=''): nbins += 1 # Create histogram - n, bins, patches = plt.hist(values, nbins, range=[min_value, max_value], - align='mid', facecolor='green', - log=True, label='simulations') + _, bins, _ = plt.hist(values, nbins, range=[min_value, max_value], + align='mid', facecolor='green', + log=True, label='simulations') # Create expected distribution (only for positive TS). We compute the # full and half of the distribution, as for positively constrained @@ -250,8 +250,8 @@ def dist_pdf(values, nbins, title, plotfile, expect=''): x.append(0.0) y_full.append(len(values)) y_half.append(0.5*len(values)) - for bin in bins: - ts = bin + 0.5*width + for i in bins: + ts = i + 0.5*width if ts > 0: y = norm*math.pow(ts,-0.5)*math.exp(-0.5*ts) x.append(ts) diff --git a/pyext/ctool.i b/pyext/ctool.i index a7cfc9b..34abfbc 100644 --- a/pyext/ctool.i +++ b/pyext/ctool.i @@ -91,7 +91,7 @@ public: %rename(_create_map) create_map; %rename(_create_cube) create_cube; %rename(_create_cta_obs) create_cta_obs; - %rename(_require_inobs) require_inobs; + //%rename(_require_inobs) require_inobs; %rename(_require_inobs_nocube) require_inobs_nocube; %rename(_get_roi) get_roi; %rename(_get_ebounds) get_ebounds; @@ -99,14 +99,14 @@ public: %rename(_get_pointing) get_pointing; %rename(_get_skydir) get_skydir; %rename(_set_outfile_name) set_outfile_name; - %rename(_is_stacked) is_stacked; + //%rename(_is_stacked) is_stacked; %rename(_set_response) set_response; %rename(_set_edisp) set_edisp; %rename(_restore_edisp) restore_edisp; %rename(_set_obs_response) set_obs_response; %rename(_set_obs_bounds) set_obs_bounds; %rename(_get_mean_pointing) get_mean_pointing; - %rename(_get_current_rss) get_current_rss; + //%rename(_get_current_rss) get_current_rss; %rename(_get_obs_header) get_obs_header; %rename(_insert_energy_boundaries) insert_energy_boundaries; %rename(_cube_layer_usage) cube_layer_usage; @@ -133,7 +133,7 @@ public: GCTAObservation create_cta_obs(void); // Protected methods that check user parameters - void require_inobs(const std::string& method); + //void require_inobs(const std::string& method); void require_inobs_nocube(const std::string& method); // Protected methods that extract user parameters @@ -145,7 +145,7 @@ public: std::string set_outfile_name(const std::string& filename); // Protected methods that query user parameters - bool is_stacked(void); + //bool is_stacked(void); // Protected support methods void set_response(GObservations& obs); @@ -156,7 +156,7 @@ public: void set_obs_bounds(GObservations& obs); GObservations get_observations(const bool& get_response = true); GSkyDir get_mean_pointing(const GObservations& obs); - size_t get_current_rss(void); + //size_t get_current_rss(void); std::string get_obs_header(const GObservation* obs) const; GEnergies insert_energy_boundaries(const GEnergies& energies, const GCTAObservation& obs); diff --git a/src/ctskymap/ctskymap.cpp b/src/ctskymap/ctskymap.cpp index c6e0c46..5114cd9 100644 --- a/src/ctskymap/ctskymap.cpp +++ b/src/ctskymap/ctskymap.cpp @@ -600,8 +600,8 @@ void ctskymap::map_events(GCTAObservation* obs) // If RoI is valid then skip if instrument direction is not within RoI if (roi.is_valid() && !roi.contains(*inst)) { - continue; num_outside_roi++; + continue; } // Fill event in skymap diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index 3f6dc4b..a6cc8ac 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -810,6 +810,7 @@ GCTAObservation ctool::create_cta_obs(void) * @todo This method is only used by csobsinfo, csresmap and csspec. We * should try to get rid of it ***************************************************************************/ +/* void ctool::require_inobs(const std::string& method) { // Get inobs filename @@ -828,6 +829,7 @@ void ctool::require_inobs(const std::string& method) // Return return; } +*/ /***********************************************************************//** @@ -1168,6 +1170,7 @@ std::string ctool::set_outfile_name(const std::string& filename) * Using this method assures that the parameters are always queried in the * same order. ***************************************************************************/ +/* bool ctool::is_stacked(void) { // First query the minimum and maximum energies @@ -1192,6 +1195,7 @@ bool ctool::is_stacked(void) // Return stacked flag return stacked; } +*/ /***********************************************************************//** @@ -1455,9 +1459,6 @@ void ctool::set_obs_response(GCTAObservation* obs) // Attach response to observation obs->response(response); - // Signal response availability - has_response = true; - } // endif: no response information was available // Return @@ -1705,6 +1706,7 @@ GSkyDir ctool::get_mean_pointing(const GObservations& obs) * @todo This method is currently not used and can be removed if we do not * use it ***************************************************************************/ +/* size_t ctool::get_current_rss(void) { // Initialize resident set size @@ -1745,6 +1747,7 @@ size_t ctool::get_current_rss(void) // Return resident set size return rss; } +*/ /***********************************************************************//** @@ -2129,7 +2132,6 @@ void ctool::provide_help(void) const { // Allocate line buffer const int n = 1000; - char line[n]; // Build help file name std::string helpfile = name()+".txt"; @@ -2148,6 +2150,7 @@ void ctool::provide_help(void) const std::string fname = std::string(ptr) + "/share/help/" + helpfile; FILE* fptr = fopen(fname.c_str(), "r"); if (fptr != NULL) { + char line[n]; while (fgets(line, n, fptr) != NULL) { std::cout << std::string(line); } diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index 26a6aea..744d3e3 100644 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -90,7 +90,7 @@ protected: GCTAObservation create_cta_obs(void); // Protected methods that check user parameters - void require_inobs(const std::string& method); + //void require_inobs(const std::string& method); void require_inobs_nolist(const std::string& method); void require_inobs_nocube(const std::string& method); @@ -103,7 +103,7 @@ protected: std::string set_outfile_name(const std::string& filename); // Protected methods that query user parameters - bool is_stacked(void); + //bool is_stacked(void); // Protected methods for logging void log_observations(const GChatter& chatter, @@ -122,7 +122,7 @@ protected: void set_obs_bounds(GObservations& obs); GObservations get_observations(const bool& get_response = true); GSkyDir get_mean_pointing(const GObservations& obs); - size_t get_current_rss(void); + //size_t get_current_rss(void); std::string get_obs_header(const GObservation* obs) const; GEnergies insert_energy_boundaries(const GEnergies& energies, const GCTAObservation& obs); diff --git a/test/science_verification.py b/test/science_verification.py index 79e42cd..5f61848 100755 --- a/test/science_verification.py +++ b/test/science_verification.py @@ -32,7 +32,7 @@ import csv import math import sys import gammalib -import ctools +#import ctools import cscripts @@ -100,7 +100,7 @@ def generate_pull_distribution(model, obs='NONE', trials=100, \ Name of pull distribution output file """ # Derive parameters - head, tail = os.path.split(model) + _, tail = os.path.split(model) inmodel = model + '.xml' outfile = 'cspull_' + tail + '.dat' @@ -164,7 +164,7 @@ def analyse_pull_distribution(filename): # Read rows first = True - index = -1 + #index = -1 samples = 0.0 for row in reader: diff --git a/test/test_cscaldb.py b/test/test_cscaldb.py index 3f38627..a7072a9 100755 --- a/test/test_cscaldb.py +++ b/test/test_cscaldb.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib +#import gammalib import cscripts from testing import test diff --git a/test/test_csiactdata.py b/test/test_csiactdata.py index b868f21..f1df681 100755 --- a/test/test_csiactdata.py +++ b/test/test_csiactdata.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib +#import gammalib import cscripts from testing import test diff --git a/test/test_csinfo.py b/test/test_csinfo.py index b6d9435..8184ebe 100755 --- a/test/test_csinfo.py +++ b/test/test_csinfo.py @@ -2,7 +2,7 @@ # ========================================================================== # This scripts performs unit tests for the csinfo script. # -# Copyright (C) 2016 Juergen Knoedlseder +# Copyright (C) 2016-2017 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 @@ -18,8 +18,8 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib -import cscripts +#import gammalib +#import cscripts from testing import test diff --git a/test/test_csmodelinfo.py b/test/test_csmodelinfo.py index 2f54825..864f4ef 100755 --- a/test/test_csmodelinfo.py +++ b/test/test_csmodelinfo.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib +#import gammalib import cscripts from testing import test diff --git a/test/test_csmodelselect.py b/test/test_csmodelselect.py index a4ea44d..661671e 100755 --- a/test/test_csmodelselect.py +++ b/test/test_csmodelselect.py @@ -18,7 +18,6 @@ # along with this program. If not, see . # # ========================================================================== -import os import gammalib import cscripts from testing import test diff --git a/test/test_csmodelsois.py b/test/test_csmodelsois.py index 451187b..944583b 100755 --- a/test/test_csmodelsois.py +++ b/test/test_csmodelsois.py @@ -246,7 +246,6 @@ class Test(test): """ # Get energies (this forces loading in case the map cube is not # loaded) - energies = cube.energies() self.test_value(len(cube.energies()), nmaps, 'Check number of energies') # Check dimensions diff --git a/test/test_csobsinfo.py b/test/test_csobsinfo.py index 96f75f9..55990ce 100755 --- a/test/test_csobsinfo.py +++ b/test/test_csobsinfo.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib +#import gammalib import cscripts from testing import test diff --git a/test/test_csobsselect.py b/test/test_csobsselect.py index 52c4f24..97b7ffc 100755 --- a/test/test_csobsselect.py +++ b/test/test_csobsselect.py @@ -18,7 +18,6 @@ # along with this program. If not, see . # # ========================================================================== -import os import gammalib import cscripts from testing import test diff --git a/test/test_csroot2caldb.py b/test/test_csroot2caldb.py index 06828c1..d494b2a 100644 --- a/test/test_csroot2caldb.py +++ b/test/test_csroot2caldb.py @@ -19,7 +19,7 @@ # # ========================================================================== import os -import gammalib +#import gammalib import cscripts from testing import test diff --git a/test/test_cssrcdetect.py b/test/test_cssrcdetect.py index df55c7b..d68e6b4 100755 --- a/test/test_cssrcdetect.py +++ b/test/test_cssrcdetect.py @@ -18,7 +18,6 @@ # along with this program. If not, see . # # ========================================================================== -import os import gammalib import cscripts from testing import test diff --git a/test/test_ctbutterfly.py b/test/test_ctbutterfly.py index 181fc58..f15206c 100755 --- a/test/test_ctbutterfly.py +++ b/test/test_ctbutterfly.py @@ -18,7 +18,6 @@ # along with this program. If not, see . # # ========================================================================== -import os import gammalib import ctools from testing import test @@ -151,7 +150,7 @@ class Test(test): self._check_result_file('ctbutterfly_py2.dat') # Recover observation container - obs = butterfly.obs() + #obs = butterfly.obs() # TODO: Do someting test on observation container diff --git a/test/test_cterror.py b/test/test_cterror.py index 6dd8c21..b83f81a 100755 --- a/test/test_cterror.py +++ b/test/test_cterror.py @@ -18,7 +18,6 @@ # along with this program. If not, see . # # ========================================================================== -import os import gammalib import ctools from testing import test diff --git a/test/test_ctlike.py b/test/test_ctlike.py index b35a9f5..fcc6c92 100755 --- a/test/test_ctlike.py +++ b/test/test_ctlike.py @@ -18,7 +18,6 @@ # along with this program. If not, see . # # ========================================================================== -import os import gammalib import ctools from testing import test diff --git a/test/test_ctmapcube.py b/test/test_ctmapcube.py index 2dc7213..879cb1f 100644 --- a/test/test_ctmapcube.py +++ b/test/test_ctmapcube.py @@ -248,7 +248,6 @@ class Test(test): """ # Get energies (this forces loading in case the map cube is not # loaded) - energies = cube.energies() self.test_value(len(cube.energies()), nmaps, 'Check number of energies') # Check dimensions diff --git a/test/test_ctobssim.py b/test/test_ctobssim.py index 0c7e6c3..c4ac25a 100755 --- a/test/test_ctobssim.py +++ b/test/test_ctobssim.py @@ -239,14 +239,14 @@ class Test(test): return # Check observation - def _test_observation(self, ctobssim, nobs=1, + def _test_observation(self, obssim, nobs=1, pnts=[{'ra': 83.63, 'dec': 22.01}]): """ Test content of an observation Parameters ---------- - ctobssim : `~ctools.ctobssim` + obssim : `~ctools.ctobssim` ctobssim instance nobs : int Number of observations @@ -254,10 +254,10 @@ class Test(test): List of pointing dictionaries """ # Test observation container - self.test_value(ctobssim.obs().size(), nobs, + self.test_value(obssim.obs().size(), nobs, 'There is one observation') - for i in range(ctobssim.obs().size()): - obs = gammalib.GCTAObservation(ctobssim.obs()[i]) + for i in range(obssim.obs().size()): + obs = gammalib.GCTAObservation(obssim.obs()[i]) pnt = obs.pointing() self.test_assert(obs.instrument() == 'CTA', 'Observation is CTA observation') diff --git a/test/test_ctphase.py b/test/test_ctphase.py index aecb54a..c4b5172 100644 --- a/test/test_ctphase.py +++ b/test/test_ctphase.py @@ -206,14 +206,14 @@ class Test(test): # Test invalid source name self.test_try('Test ctphase with invalid source name') try: - test = ctools.ctphase() - test['inobs'] = self._events - test['inmodel'] = self._model_file - test['srcname'] = 'Venus' - test['outobs'] = 'ctphase_py5.fits' - test['logfile'] = 'ctphase_py5.log' - test.logFileOpen() - test.execute() + phase = ctools.ctphase() + phase['inobs'] = self._events + phase['inmodel'] = self._model_file + phase['srcname'] = 'Venus' + phase['outobs'] = 'ctphase_py5.fits' + phase['logfile'] = 'ctphase_py5.log' + phase.logFileOpen() + phase.execute() self.test_try_failure('Exception not thrown') except (ValueError): self.test_try_success() @@ -221,14 +221,14 @@ class Test(test): # Test invalid model type self.test_try('Test ctphase with invalid model') try: - test = ctools.ctphase() - test['inobs'] = self._events - test['inmodel'] = self._model - test['srcname'] = 'Background' - test['outobs'] = 'ctphase_py6.fits' - test['logfile'] = 'ctphase_py6.log' - test.logFileOpen() - test.execute() + phase = ctools.ctphase() + phase['inobs'] = self._events + phase['inmodel'] = self._model + phase['srcname'] = 'Background' + phase['outobs'] = 'ctphase_py6.fits' + phase['logfile'] = 'ctphase_py6.log' + phase.logFileOpen() + phase.execute() self.test_try_failure('Exception not thrown') except (ValueError): self.test_try_success() @@ -236,14 +236,14 @@ class Test(test): # Test invalid model without temporal phase curve model self.test_try('Test ctphase with invalid model') try: - test = ctools.ctphase() - test['inobs'] = self._events - test['inmodel'] = self._model - test['srcname'] = 'Crab' - test['outobs'] = 'ctphase_py7.fits' - test['logfile'] = 'ctphase_py7.log' - test.logFileOpen() - test.execute() + phase = ctools.ctphase() + phase['inobs'] = self._events + phase['inmodel'] = self._model + phase['srcname'] = 'Crab' + phase['outobs'] = 'ctphase_py7.fits' + phase['logfile'] = 'ctphase_py7.log' + phase.logFileOpen() + phase.execute() self.test_try_failure('Exception not thrown') except (ValueError): self.test_try_success() diff --git a/test/test_ctulimit.py b/test/test_ctulimit.py index d4190e3..eeabb6e 100755 --- a/test/test_ctulimit.py +++ b/test/test_ctulimit.py @@ -18,8 +18,7 @@ # along with this program. If not, see . # # ========================================================================== -import os -import gammalib +#import gammalib import ctools from testing import test @@ -79,9 +78,6 @@ class Test(test): self.test_assert(self._execute(cmd) == 0, 'Check successful execution from command line') - # Check result file - self._check_result_file('ctulimit_cmd1.log') - # Setup ctulimit command cmd = ctulimit+' inobs="event_file_that_does_not_exist.fits"'+ \ ' inmodel="'+self._model+'" srcname="Crab"'+ \ @@ -255,11 +251,3 @@ class Test(test): # Return return - - # Check result file - def _check_result_file(self, filename): - """ - Check result file - """ - # Return - return diff --git a/test/test_examples.py.in b/test/test_examples.py.in index d631e81..7486ed7 100755 --- a/test/test_examples.py.in +++ b/test/test_examples.py.in @@ -19,10 +19,7 @@ # # ========================================================================== import os -import sys import gammalib -import ctools -import cscripts # =============================================== # -- libgit2 0.21.4