From 839513724e3fd67e3daa467319a631bbebe987da Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sun, 22 Oct 2017 18:19:25 +0200 Subject: [PATCH] Rename built-in variables in Python scripts --- cscripts/csresmap.py | 38 +++++++++++++++++++------------------- cscripts/csspec.py | 20 ++++++++++---------- cscripts/cssrcdetect.py | 90 +++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------- cscripts/csworkflow.py | 30 +++++++++++++++--------------- cscripts/obsutils.py | 48 ++++++++++++++++++++++++------------------------ examples/make_pointings.py | 24 ++++++++++++------------ examples/pipeline_binned_disk.py | 34 +++++++++++++++++----------------- examples/pipeline_binned_mem.py | 26 +++++++++++++------------- examples/pipeline_stacked_disk.py | 32 ++++++++++++++++---------------- examples/pipeline_stacked_mem.py | 34 +++++++++++++++++----------------- pyext/setup.py.in | 22 +++++++++++----------- test/test_ctbin.py | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------- test/test_ctobssim.py | 8 ++++---- test/test_obsutils.py | 6 +++--- 14 files changed, 263 insertions(+), 263 deletions(-) diff --git a/cscripts/csresmap.py b/cscripts/csresmap.py index c6c3ca6..fd16675 100755 --- a/cscripts/csresmap.py +++ b/cscripts/csresmap.py @@ -175,28 +175,28 @@ class csresmap(ctools.cscript): self._log_header1(gammalib.TERSE, 'Generate binned map (ctbin)') # Create countsmap - bin = ctools.ctbin(self._obs) - bin['xref'] = self['xref'].real() - bin['yref'] = self['yref'].real() - bin['proj'] = self['proj'].string() - bin['coordsys'] = self['coordsys'].string() - bin['ebinalg'] = self['ebinalg'].string() - bin['nxpix'] = self['nxpix'].integer() - bin['nypix'] = self['nypix'].integer() - bin['binsz'] = self['binsz'].real() + binning = ctools.ctbin(self._obs) + binning['xref'] = self['xref'].real() + binning['yref'] = self['yref'].real() + binning['proj'] = self['proj'].string() + binning['coordsys'] = self['coordsys'].string() + binning['ebinalg'] = self['ebinalg'].string() + binning['nxpix'] = self['nxpix'].integer() + binning['nypix'] = self['nypix'].integer() + binning['binsz'] = self['binsz'].real() if self['ebinalg'].string() == "FILE": - bin['ebinfile'] = self['ebinfile'].filename().file() + binning['ebinfile'] = self['ebinfile'].filename().file() else: - bin['enumbins'] = self['enumbins'].integer() - bin['emin'] = self['emin'].real() - bin['emax'] = self['emax'].real() - bin['chatter'] = self['chatter'].integer() - bin['clobber'] = self['clobber'].boolean() - bin['debug'] = self['debug'].boolean() - bin.run() + binning['enumbins'] = self['enumbins'].integer() + binning['emin'] = self['emin'].real() + binning['emax'] = self['emax'].real() + binning['chatter'] = self['chatter'].integer() + binning['clobber'] = self['clobber'].boolean() + binning['debug'] = self['debug'].boolean() + binning.run() # Retrieve counts cube - cta_counts_cube = bin.cube() + cta_counts_cube = binning.cube() # Assign GCTAEventCube to skymap countmap = cta_counts_cube.counts() @@ -218,7 +218,7 @@ class csresmap(ctools.cscript): # Store counts map as residual map. Note that we need a special # construct here to avoid memory leaks. This seems to be a SWIG feature - # as SWIG creates a new object when calling bin.cube() + # as SWIG creates a new object when calling binning.cube() self._resmap = countmap.copy() self._resmap.stack_maps() modelmap.stack_maps() diff --git a/cscripts/csspec.py b/cscripts/csspec.py index 0b97b8c..9c80f8e 100755 --- a/cscripts/csspec.py +++ b/cscripts/csspec.py @@ -363,15 +363,15 @@ class csspec(ctools.cslikelihood): # Make sure that all nodes are positive for i in range(spectrum.nodes()): - par = spectrum[i*2+1] - value = par.value() - min = 1.0e-30 * value - if min <= 0.0: - min = 1.0e-50 - if min < value: - value = min + par = spectrum[i*2+1] + value = par.value() + minimum = 1.0e-30 * value + if minimum <= 0.0: + minimum = 1.0e-50 + if minimum < value: + value = minimum par.value(value) - par.min(min) + par.min(minimum) # Set spectral component of source model model.spectral(spectrum) @@ -459,10 +459,10 @@ class csspec(ctools.cslikelihood): rmf[idst_true, idst_reco] = obs.rmf()[isrc_true, isrc_reco] # Set On/Off observations - id = obs.id() + obsid = obs.id() statistic = obs.statistic() obs = gammalib.GCTAOnOffObservation(pha_on, pha_off, arf, rmf) - obs.id(id) + obs.id(obsid) obs.statistic(statistic) # Return observation diff --git a/cscripts/cssrcdetect.py b/cscripts/cssrcdetect.py index c9fc73a..f26a37e 100755 --- a/cscripts/cssrcdetect.py +++ b/cscripts/cssrcdetect.py @@ -117,23 +117,23 @@ class cssrcdetect(ctools.cscript): self._log_value(gammalib.NORMAL, 'Map threshold', threshold) # Get maximum value and corresponding sky direction - value, dir = self._find_maximum(counts, threshold=threshold) + value, pos = self._find_maximum(counts, threshold=threshold) # If maximum found then log maximum and add model - if dir is not None: + if pos is not None: # Set source name name = 'Src%3.3d' % (i+1) # Log maximum self._log_value(gammalib.NORMAL, 'Map maximum', str(value)) - self._log_value(gammalib.NORMAL, name+' position', str(dir)) + self._log_value(gammalib.NORMAL, name+' position', str(pos)) # Add model - self._add_model(dir, name) + self._add_model(pos, name) # Remove maximum from map - counts = self._remove_maximum(counts, dir, mean, + counts = self._remove_maximum(counts, pos, mean, radius=self['exclrad'].real()) # ... otherwise log that no maximum was found and break iterations @@ -149,44 +149,44 @@ class cssrcdetect(ctools.cscript): # Return return - def _find_maximum(self, map, threshold=0.0): + def _find_maximum(self, skymap, threshold=0.0): """ Find maximum in a sky map Parameters ---------- - map : `~gammalib.GSkyMap()` + skymap : `~gammalib.GSkyMap()` Sky map threshold : float, optional Threshold for maximum value Returns ------- - value, dir : tuple of float and `~gammalib.GSkyDir()` + value, pos : tuple of float and `~gammalib.GSkyDir()` Maximum sky map value and corresponding sky direction """ # Initialise maximum pixel value and sky direction value = threshold - dir = None + pos = None # Loop over all pixels and find maximum - for i in range(map.npix()): - if map[i] > value: - value = map[i] - dir = map.inx2dir(i) + for i in range(skymap.npix()): + if skymap[i] > value: + value = skymap[i] + pos = skymap.inx2dir(i) # Return sky direction of maximum - return value, dir + return value, pos - def _remove_maximum(self, map, dir, value=0.0, radius=0.1): + def _remove_maximum(self, skymap, pos, value=0.0, radius=0.1): """ Remove maximum from sky map by replacing pixels with a given value Parameters ---------- - map : `~gammalib.GSkyMap()` + skymap : `~gammalib.GSkyMap()` Sky map - dir : `~gammalib.GSkyDir()` + pos : `~gammalib.GSkyDir()` Sky direction of maximum value : float, optional Replacement value @@ -195,28 +195,28 @@ class cssrcdetect(ctools.cscript): Returns ------- - map : `~gammalib.GSkyMap()` + skymap : `~gammalib.GSkyMap()` Sky map with maximum removed """ # Copy skymap - map_copy = map.copy() + skymap_copy = skymap.copy() # Loop over all pixels and find maximum - for i in range(map_copy.npix()): - mapdir = map_copy.inx2dir(i) - if mapdir.dist_deg(dir) < radius: - map_copy[i] = value + for i in range(skymap_copy.npix()): + skymap_dir = skymap_copy.inx2dir(i) + if skymap_dir.dist_deg(pos) < radius: + skymap_copy[i] = value # Return copy of map - return map_copy + return skymap_copy - def _map_moments(self, map): + def _map_moments(self, skymap): """ Determine moments of sky map pixels Parameters ---------- - map : `~gammalib.GSkyMap()` + skymap : `~gammalib.GSkyMap()` Sky map Returns @@ -229,32 +229,32 @@ class cssrcdetect(ctools.cscript): std = 0.0 # Loop over all pixels - for i in range(map.npix()): - mean += map[i] - std += map[i]*map[i] + for i in range(skymap.npix()): + mean += skymap[i] + std += skymap[i]*skymap[i] # Compute mean and standard deviation - mean /= float(map.npix()) - std /= float(map.npix()) + mean /= float(skymap.npix()) + std /= float(skymap.npix()) std -= mean * mean std = math.sqrt(std) # Return mean and standard deviation return mean, std - def _add_model(self, dir, name): + def _add_model(self, pos, name): """ Add model to model container Parameters ---------- - dir : `~gammalib.GSkyDir()` + pos : `~gammalib.GSkyDir()` Sky direction of model name : str Model name """ # Set point source model - model = self._set_ptsrc(dir) + model = self._set_ptsrc(pos) # Set model name model.name(name) @@ -265,13 +265,13 @@ class cssrcdetect(ctools.cscript): # Return return - def _set_bkg(self, type): + def _set_bkg(self, modeltype): """ Set background model Parameters ---------- - type : str + modeltype : str Model type ('IRF', 'AEFF' or 'CUBE') Returns @@ -284,11 +284,11 @@ class cssrcdetect(ctools.cscript): gammalib.GEnergy(1.0, 'TeV')) # Set background model - if type == 'IRF': + if modeltype == 'IRF': model = gammalib.GCTAModelIrfBackground(spectral) - elif type == 'AEFF': + elif modeltype == 'AEFF': model = gammalib.GCTAModelAeffBackground(spectral) - elif type == 'CUBE': + elif modeltype == 'CUBE': model = gammalib.GCTAModelCubeBackground(spectral) else: model = None @@ -300,13 +300,13 @@ class cssrcdetect(ctools.cscript): # Return model return model - def _set_ptsrc(self, dir): + def _set_ptsrc(self, pos): """ Set point source model Parameters ---------- - dir : `~gammalib.GSkyDir()` + pos : `~gammalib.GSkyDir()` Sky direction of model Returns @@ -315,7 +315,7 @@ class cssrcdetect(ctools.cscript): Point source model """ # Set spatial component - spatial = gammalib.GModelSpatialPointSource(dir) + spatial = gammalib.GModelSpatialPointSource(pos) # Get fit parameters fit_pos = self['fit_pos'].boolean() @@ -348,7 +348,7 @@ class cssrcdetect(ctools.cscript): Returns ------- - map : `~gammalib.GSkyMap()` + skymap : `~gammalib.GSkyMap()` Sky map """ # Get skymap filename @@ -358,13 +358,13 @@ class cssrcdetect(ctools.cscript): fits = gammalib.GFits(inmap) # Extract primary extension as sky map - map = gammalib.GSkyMap(fits.image(0)) + skymap = gammalib.GSkyMap(fits.image(0)) # Close sky map file fits.close() # Return - return map + return skymap # Public methods diff --git a/cscripts/csworkflow.py b/cscripts/csworkflow.py index a777c9f..6ff6710 100755 --- a/cscripts/csworkflow.py +++ b/cscripts/csworkflow.py @@ -114,10 +114,10 @@ class csworkflow(ctools.cscript): actor_inputs = actor.element('input') num_inputs = actor_inputs.elements('parameter') for k in range(num_inputs): - input = actor_inputs.element('parameter', k) - input_name = input.attribute('name') - input_value = input.attribute('value') - input_actor = input.attribute('actor') + input_par = actor_inputs.element('parameter', k) + input_name = input_par.attribute('name') + input_value = input_par.attribute('value') + input_actor = input_par.attribute('actor') parameter = {'name': input_name, \ 'value': input_value, \ 'actor': input_actor} @@ -131,10 +131,10 @@ class csworkflow(ctools.cscript): actor_output = actor.element('output') num_outputs = actor_output.elements('parameter') for k in range(num_outputs): - output = actor_output.element('parameter', k) - output_name = output.attribute('name') - output_value = output.attribute('value') - output_actor = output.attribute('actor') + output_par = actor_output.element('parameter', k) + output_name = output_par.attribute('name') + output_value = output_par.attribute('value') + output_actor = output_par.attribute('actor') parameter = {'name': output_name, \ 'value': output_value, \ 'actor': output_actor} @@ -263,25 +263,25 @@ class csworkflow(ctools.cscript): return # Create actor tool object - object = eval(tool_eval) + tool = eval(tool_eval) # Set actor input parameters pars = actor['input_parameters'] for par in pars: - app_par = object[par['name']] + app_par = tool[par['name']] app_par.value(self._get_parameter_value(par)) - object[par['name']] = app_par + tool[par['name']] = app_par # Set actor output parameters pars = actor['output_parameters'] for par in pars: - app_par = object[par['name']] + app_par = tool[par['name']] app_par.value(self._get_parameter_value(par)) - object[par['name']] = app_par + tool[par['name']] = app_par # Execute actor - object.logFileOpen() - object.execute() + tool.logFileOpen() + tool.execute() # Return return diff --git a/cscripts/obsutils.py b/cscripts/obsutils.py index 5035009..4674ab9 100755 --- a/cscripts/obsutils.py +++ b/cscripts/obsutils.py @@ -106,27 +106,27 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, emax = max(run.events().ebounds().emax().TeV(), emax) # Allocate ctbin application and set parameters - bin = ctools.ctbin(obssim.obs()) - bin['ebinalg'] = 'LOG' - bin['emin'] = emin - bin['emax'] = emax - bin['enumbins'] = nbins - bin['usepnt'] = True # Use pointing for map centre - bin['nxpix'] = npix - bin['nypix'] = npix - bin['binsz'] = binsz - bin['coordsys'] = coord - bin['proj'] = proj - bin['chatter'] = chatter - bin['debug'] = debug + binning = ctools.ctbin(obssim.obs()) + binning['ebinalg'] = 'LOG' + binning['emin'] = emin + binning['emax'] = emax + binning['enumbins'] = nbins + binning['usepnt'] = True # Use pointing for map centre + binning['nxpix'] = npix + binning['nypix'] = npix + binning['binsz'] = binsz + binning['coordsys'] = coord + binning['proj'] = proj + binning['chatter'] = chatter + binning['debug'] = debug # Optionally open the log file if log: - bin.logFileOpen() + binning.logFileOpen() # Run ctbin application. This will loop over all observations in # the container and bin the events in counts maps - bin.run() + binning.run() # If we have multiple input observations then create stacked response # cubes and append them to the observation @@ -144,22 +144,22 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, # Set stacked response if edisp: - bin.obs()[0].response(response['expcube'], - response['psfcube'], - response['edispcube'], - response['bkgcube']) + binning.obs()[0].response(response['expcube'], + response['psfcube'], + response['edispcube'], + response['bkgcube']) else: - bin.obs()[0].response(response['expcube'], - response['psfcube'], - response['bkgcube']) + binning.obs()[0].response(response['expcube'], + response['psfcube'], + response['bkgcube']) # Set new models - bin.obs().models(response['models']) + binning.obs().models(response['models']) # Make a deep copy of the observation that will be returned # (the ctbin object will go out of scope one the function is # left) - obs = bin.obs().copy() + obs = binning.obs().copy() else: diff --git a/examples/make_pointings.py b/examples/make_pointings.py index d879e8e..3a4878b 100755 --- a/examples/make_pointings.py +++ b/examples/make_pointings.py @@ -576,13 +576,13 @@ def write_obsdef(filename, obsdef, idstart): First identifier of observation definition file """ # Open file - file = open(filename, 'w') + f = open(filename, 'w') # Write header - file.write('id,ra,dec,tmin,duration,caldb,irf,emin,emax\n') + f.write('id,ra,dec,tmin,duration,caldb,irf,emin,emax\n') # Initialise identifier - id = idstart + obsid = idstart # Loop over pointings for obs in obsdef: @@ -591,10 +591,10 @@ def write_obsdef(filename, obsdef, idstart): if 'lon' in obs and 'lat' in obs: lon = obs['lon'] lat = obs['lat'] - dir = gammalib.GSkyDir() - dir.lb_deg(lon,lat) - ra = dir.ra_deg() - dec = dir.dec_deg() + pnt = gammalib.GSkyDir() + pnt.lb_deg(lon,lat) + ra = pnt.ra_deg() + dec = pnt.dec_deg() else: ra = obs['ra'] dec = obs['dec'] @@ -608,15 +608,15 @@ def write_obsdef(filename, obsdef, idstart): emax = 50.0 # Write information - file.write('%6.6d,%8.4f,%8.4f,%.4f,%.4f,%s,%s,%.3f,%.1f\n' % - (id, ra, dec, obs['tmin'], obs['duration'], obs['caldb'], \ - obs['irf'], emin, emax)) + f.write('%6.6d,%8.4f,%8.4f,%.4f,%.4f,%s,%s,%.3f,%.1f\n' % + (obsid, ra, dec, obs['tmin'], obs['duration'], obs['caldb'], \ + obs['irf'], emin, emax)) # Increment identifier - id += 1 + obsid += 1 # Close file - file.close() + f.close() # Return return diff --git a/examples/pipeline_binned_disk.py b/examples/pipeline_binned_disk.py index 6cb2b43..8834f0e 100755 --- a/examples/pipeline_binned_disk.py +++ b/examples/pipeline_binned_disk.py @@ -80,27 +80,27 @@ def run_pipeline(obs, emin=0.1, emax=100.0, cubefile = 'cube_'+eventfile # Bin events for that observation - bin = ctools.ctbin() - bin['inobs'] = eventfile - bin['outcube'] = cubefile - bin['ebinalg'] = 'LOG' - bin['emin'] = emin - bin['emax'] = emax - bin['enumbins'] = enumbins - bin['nxpix'] = nxpix - bin['nypix'] = nypix - bin['binsz'] = binsz - bin['coordsys'] = coordsys - bin['usepnt'] = True - bin['proj'] = proj - bin.execute() + binning = ctools.ctbin() + binning['inobs'] = eventfile + binning['outcube'] = cubefile + binning['ebinalg'] = 'LOG' + binning['emin'] = emin + binning['emax'] = emax + binning['enumbins'] = enumbins + binning['nxpix'] = nxpix + binning['nypix'] = nypix + binning['binsz'] = binsz + binning['coordsys'] = coordsys + binning['usepnt'] = True + binning['proj'] = proj + binning.execute() # Set observation ID - bin.obs()[0].id(cubefile) - bin.obs()[0].eventfile(cubefile) + binning.obs()[0].id(cubefile) + binning.obs()[0].eventfile(cubefile) # Append result to observations - obs.extend(bin.obs()) + obs.extend(binning.obs()) # Save XML file xml = gammalib.GXml() diff --git a/examples/pipeline_binned_mem.py b/examples/pipeline_binned_mem.py index 4d356f1..88097d4 100755 --- a/examples/pipeline_binned_mem.py +++ b/examples/pipeline_binned_mem.py @@ -70,21 +70,21 @@ def run_pipeline(obs, emin=0.1, emax=100.0, container.append(run) # Bin events for that observation - bin = ctools.ctbin(container) - bin['ebinalg'] = 'LOG' - bin['emin'] = emin - bin['emax'] = emax - bin['enumbins'] = enumbins - bin['nxpix'] = nxpix - bin['nypix'] = nypix - bin['binsz'] = binsz - bin['coordsys'] = coordsys - bin['usepnt'] = True - bin['proj'] = proj - bin.run() + binning = ctools.ctbin(container) + binning['ebinalg'] = 'LOG' + binning['emin'] = emin + binning['emax'] = emax + binning['enumbins'] = enumbins + binning['nxpix'] = nxpix + binning['nypix'] = nypix + binning['binsz'] = binsz + binning['coordsys'] = coordsys + binning['usepnt'] = True + binning['proj'] = proj + binning.run() # Append result to observations - obs.extend(bin.obs()) + obs.extend(binning.obs()) # Perform maximum likelihood fitting like = ctools.ctlike(obs) diff --git a/examples/pipeline_stacked_disk.py b/examples/pipeline_stacked_disk.py index bbd5f5a..85513e4 100755 --- a/examples/pipeline_stacked_disk.py +++ b/examples/pipeline_stacked_disk.py @@ -75,22 +75,22 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, sim.execute() # Bin events into counts map - bin = ctools.ctbin() - bin['inobs'] = 'obs.xml' - bin['outcube'] = 'cntcube.fits' - bin['ebinalg'] = 'LOG' - bin['emin'] = emin - bin['emax'] = emax - bin['enumbins'] = enumbins - bin['nxpix'] = nxpix - bin['nypix'] = nypix - bin['binsz'] = binsz - bin['coordsys'] = coordsys - bin['proj'] = proj - bin['xref'] = ra - bin['yref'] = dec - bin['debug'] = debug - bin.execute() + binning = ctools.ctbin() + binning['inobs'] = 'obs.xml' + binning['outcube'] = 'cntcube.fits' + binning['ebinalg'] = 'LOG' + binning['emin'] = emin + binning['emax'] = emax + binning['enumbins'] = enumbins + binning['nxpix'] = nxpix + binning['nypix'] = nypix + binning['binsz'] = binsz + binning['coordsys'] = coordsys + binning['proj'] = proj + binning['xref'] = ra + binning['yref'] = dec + binning['debug'] = debug + binning.execute() # Create exposure cube expcube = ctools.ctexpcube() diff --git a/examples/pipeline_stacked_mem.py b/examples/pipeline_stacked_mem.py index 73e6b6b..f0d26cc 100755 --- a/examples/pipeline_stacked_mem.py +++ b/examples/pipeline_stacked_mem.py @@ -65,20 +65,20 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, sim.run() # Bin events into counts map - bin = ctools.ctbin(sim.obs()) - bin['ebinalg'] = 'LOG' - bin['emin'] = emin - bin['emax'] = emax - bin['enumbins'] = enumbins - bin['nxpix'] = nxpix - bin['nypix'] = nypix - bin['binsz'] = binsz - bin['coordsys'] = coordsys - bin['proj'] = proj - bin['xref'] = ra - bin['yref'] = dec - bin['debug'] = debug - bin.run() + binning = ctools.ctbin(sim.obs()) + binning['ebinalg'] = 'LOG' + binning['emin'] = emin + binning['emax'] = emax + binning['enumbins'] = enumbins + binning['nxpix'] = nxpix + binning['nypix'] = nypix + binning['binsz'] = binsz + binning['coordsys'] = coordsys + binning['proj'] = proj + binning['xref'] = ra + binning['yref'] = dec + binning['debug'] = debug + binning.run() # Create exposure cube expcube = ctools.ctexpcube(sim.obs()) @@ -132,14 +132,14 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, bkgcube.run() # Attach background model to observation container - bin.obs().models(bkgcube.models()) + binning.obs().models(bkgcube.models()) # Set Exposure and Psf cube for first CTA observation # (ctbin will create an observation with a single container) - bin.obs()[0].response(expcube.expcube(), psfcube.psfcube(), bkgcube.bkgcube()) + binning.obs()[0].response(expcube.expcube(), psfcube.psfcube(), bkgcube.bkgcube()) # Perform maximum likelihood fitting - like = ctools.ctlike(bin.obs()) + like = ctools.ctlike(binning.obs()) like['debug'] = True # Switch this always on for results in console like.run() diff --git a/pyext/setup.py.in b/pyext/setup.py.in index 4ff8900..f8b40ee 100644 --- a/pyext/setup.py.in +++ b/pyext/setup.py.in @@ -1,7 +1,7 @@ ############################################################################# # Disutils setup file for ctools Python extension module # # ------------------------------------------------------------------------- # -# Copyright (C) 2011-2016 Juergen Knoedlseder # +# Copyright (C) 2011-2017 Juergen Knoedlseder # # ------------------------------------------------------------------------- # # # # This program is free software: you can redistribute it and/or modify # @@ -84,9 +84,9 @@ if os.path.exists(prefix+'/lib'): # in the src directory. Once we added the ctools script we had to # add an explicit filter to avoid appending those. dirs = glob.glob('@top_srcdir@/src/ct*') -for dir in dirs: - if len(dir) > 0 and 'ctools' not in dir: - path = os.path.abspath(dir) +for d in dirs: + if len(d) > 0 and 'ctools' not in d: + path = os.path.abspath(d) include_dirs.append(path) include_dirs.append(os.path.abspath('@top_srcdir@/src/support')) @@ -100,18 +100,18 @@ for extra_lib in extra_libs: extra_lib_paths = ('@LDFLAGS@').split(' ') for extra_lib_path in extra_lib_paths: if extra_lib_path.lstrip().find('-L') == 0: - dir = extra_lib_path.lstrip().lstrip('-L') - if len(dir) > 0: - library_dirs.append(dir) - runtime_library_dirs.append(dir) + d = extra_lib_path.lstrip().lstrip('-L') + if len(d) > 0: + library_dirs.append(d) + runtime_library_dirs.append(d) # Get extra include directories extra_include_dirs = ('@CPPFLAGS@').split(' ') for extra_include_dir in extra_include_dirs: if extra_include_dir.lstrip().find('-I') == 0: - dir = extra_include_dir.lstrip().lstrip('-I') - if len(dir) > 0: - include_dirs.append(dir) + d = extra_include_dir.lstrip().lstrip('-I') + if len(d) > 0: + include_dirs.append(d) # Set data files to install. data_files=[(prefix+'/share/ctools/swig', install_files)] diff --git a/test/test_ctbin.py b/test/test_ctbin.py index aaf5ca3..5d0a65c 100755 --- a/test/test_ctbin.py +++ b/test/test_ctbin.py @@ -129,56 +129,56 @@ class Test(test): Test ctbin from Python """ # Allocate ctbin - bin = ctools.ctbin() + binning = ctools.ctbin() # Check that empty ctbin has an empty observation container and counts # cube - self.test_value(bin.obs().size(), 0, + self.test_value(binning.obs().size(), 0, 'Check that empty ctbin has an empty observation container') - self.test_value(bin.cube().size(), 0, + self.test_value(binning.cube().size(), 0, 'Check that empty ctbin has an empty counts cube') # Check that saving does not nothing - bin['logfile'] = 'ctbin_py0.log' - bin['outcube'] = 'ctbin_py0.fits' - bin.logFileOpen() - bin.save() + binning['logfile'] = 'ctbin_py0.log' + binning['outcube'] = 'ctbin_py0.fits' + binning.logFileOpen() + binning.save() self.test_assert(not os.path.isfile('ctbin_py0.fits'), 'Check that no counts cube has been created') # Check that publishing does not lead to an exception or segfault - bin.publish() + binning.publish() # Check that clearing does not lead to an exception or segfault - bin.clear() + binning.clear() # Now set ctbin parameters - bin['inobs'] = self._events - bin['outcube'] = 'ctbin_py1.fits' - bin['ebinalg'] = 'LOG' - bin['emin'] = 0.1 - bin['emax'] = 100.0 - bin['enumbins'] = 10 - bin['nxpix'] = 40 - bin['nypix'] = 40 - bin['binsz'] = 0.1 - bin['coordsys'] = 'CEL' - bin['proj'] = 'CAR' - bin['xref'] = 83.63 - bin['yref'] = 22.01 - bin['logfile'] = 'ctbin_py1.log' - bin['chatter'] = 2 + binning['inobs'] = self._events + binning['outcube'] = 'ctbin_py1.fits' + binning['ebinalg'] = 'LOG' + binning['emin'] = 0.1 + binning['emax'] = 100.0 + binning['enumbins'] = 10 + binning['nxpix'] = 40 + binning['nypix'] = 40 + binning['binsz'] = 0.1 + binning['coordsys'] = 'CEL' + binning['proj'] = 'CAR' + binning['xref'] = 83.63 + binning['yref'] = 22.01 + binning['logfile'] = 'ctbin_py1.log' + binning['chatter'] = 2 # Run ctbin tool - bin.logFileOpen() - bin.run() + binning.logFileOpen() + binning.run() # Check content of observation container and counts cube - self._check_observation(bin, 5542) - self._check_cube(bin.cube(), 5542) + self._check_observation(binning, 5542) + self._check_cube(binning.cube(), 5542) # Copy ctbin tool - cpy_bin = bin.copy() + cpy_bin = binning.copy() # Check content of observation container and counts cube self._check_observation(cpy_bin, 5542) @@ -197,20 +197,20 @@ class Test(test): self._check_cube(cpy_bin.cube(), 0) # Save counts cube - bin.save() + binning.save() # Load counts cube and check content evt = gammalib.GCTAEventCube('ctbin_py1.fits') self._check_cube(evt, 5542) # Now clear ctbin tool - bin.clear() + binning.clear() # Check that cleared ctbin has an empty observation container and # counts cube - self.test_value(bin.obs().size(), 0, + self.test_value(binning.obs().size(), 0, 'Check that empty ctbin has an empty observation container') - self.test_value(bin.cube().size(), 0, + self.test_value(binning.cube().size(), 0, 'Check that empty ctbin has an empty counts cube') # Prepare observation container for stacking of events into a @@ -218,31 +218,31 @@ class Test(test): obs = self._obs_events() # Set-up ctbin using an observation container - bin = ctools.ctbin(obs) - bin['outcube'] = 'ctbin_py3.fits' - bin['ebinalg'] = 'LOG' - bin['emin'] = 0.1 - bin['emax'] = 100.0 - bin['enumbins'] = 10 - bin['nxpix'] = 40 - bin['nypix'] = 40 - bin['binsz'] = 0.1 - bin['coordsys'] = 'CEL' - bin['proj'] = 'CAR' - bin['xref'] = 83.63 - bin['yref'] = 22.01 - bin['publish'] = True - bin['logfile'] = 'ctbin_py3.log' - bin['chatter'] = 3 + binning = ctools.ctbin(obs) + binning['outcube'] = 'ctbin_py3.fits' + binning['ebinalg'] = 'LOG' + binning['emin'] = 0.1 + binning['emax'] = 100.0 + binning['enumbins'] = 10 + binning['nxpix'] = 40 + binning['nypix'] = 40 + binning['binsz'] = 0.1 + binning['coordsys'] = 'CEL' + binning['proj'] = 'CAR' + binning['xref'] = 83.63 + binning['yref'] = 22.01 + binning['publish'] = True + binning['logfile'] = 'ctbin_py3.log' + binning['chatter'] = 3 # Execute ctbin tool - bin.logFileOpen() - bin.execute() + binning.logFileOpen() + binning.execute() # Check content of observation and cube (need multiplier=3 since # three identical observations have been appended) - self._check_observation(bin, 5542, multiplier=3) - self._check_cube(bin.cube(), 5542, multiplier=3) + self._check_observation(binning, 5542, multiplier=3) + self._check_cube(binning.cube(), 5542, multiplier=3) # Load counts cube and check content. evt = gammalib.GCTAEventCube('ctbin_py3.fits') @@ -255,10 +255,10 @@ class Test(test): 'binsz': 0.1, 'coordsys': 'CEL', 'proj': 'CAR', 'xref': 83.63, 'yref': 22.01, 'outcube': 'ctbin_py4.fits', 'logfile': 'ctbin_py4.log', 'chatter': 2} - bin = ctools.ctbin() - bin.pardict(pars) - bin.logFileOpen() - bin.execute() + binning = ctools.ctbin() + binning.pardict(pars) + binning.logFileOpen() + binning.execute() # Load counts cube and check content evt = gammalib.GCTAEventCube('ctbin_py4.fits') diff --git a/test/test_ctobssim.py b/test/test_ctobssim.py index c4ac25a..a21d35a 100755 --- a/test/test_ctobssim.py +++ b/test/test_ctobssim.py @@ -274,20 +274,20 @@ class Test(test): return # Check event list - def _test_list(self, list, nevents): + def _test_list(self, eventlist, nevents): """ Test content of event list Parameters ---------- - list : `~gammalib.GCTAEventList` + eventlist : `~gammalib.GCTAEventList` Event list nevents : int Expected number of events """ # Test event list - self.test_value(list.size(), nevents, str(nevents)+' elements') - self.test_value(list.number(), nevents, str(nevents)+' events') + self.test_value(eventlist.size(), nevents, str(nevents)+' elements') + self.test_value(eventlist.number(), nevents, str(nevents)+' events') # Return return diff --git a/test/test_obsutils.py b/test/test_obsutils.py index 0bddbf7..07aedd9 100755 --- a/test/test_obsutils.py +++ b/test/test_obsutils.py @@ -84,10 +84,10 @@ class Test(test): Setup method for sim() function test """ # Set-up observation container - dir = gammalib.GSkyDir() - dir.radec_deg(83.6331, 22.0145) + pnt = gammalib.GSkyDir() + pnt.radec_deg(83.6331, 22.0145) obs = gammalib.GObservations() - run = obsutils.set_obs(dir, duration=100.0, emin=1.0, emax=10.0) + run = obsutils.set_obs(pnt, duration=100.0, emin=1.0, emax=10.0) run.id('0') obs.append(run) if two: -- libgit2 0.21.4