Skip to content

Commit c24bf3b

Browse files
committed
Python 3 migration of PyHEADTAIL v1.13.5
1 parent e05caf2 commit c24bf3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+217
-235
lines changed

PyHEADTAIL/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from ._version import __version__
2323
dirty = False
2424

25-
print ('PyHEADTAIL v' + __version__)
25+
print(('PyHEADTAIL v' + __version__))
2626
if dirty:
2727
print ('(dirty git work tree)')
2828
print ('\n')

PyHEADTAIL/aperture/aperture.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Michael Schenk
1111
'''
1212

13-
from __future__ import division
13+
1414

1515
import numpy as np
1616
from abc import ABCMeta, abstractmethod
@@ -23,15 +23,13 @@ def make_int32(array):
2323
return array.astype(np.int32)
2424

2525

26-
class Aperture(Element):
26+
class Aperture(Element, metaclass=ABCMeta):
2727
'''Abstract base class for Aperture elements. An aperture is
2828
generally defined as a condition on the phase space coordinates.
2929
Particles not fulfilling this condition are tagged as lost and
3030
are removed from the beam directly after.
3131
'''
3232

33-
__metaclass__ = ABCMeta
34-
3533
@clean_slices
3634
def track(self, beam):
3735
'''Tag particles not passing through the aperture as lost. If

PyHEADTAIL/cobra_functions/curve_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import division
1+
22

33
import numpy as np
44
from scipy.optimize import brentq
@@ -20,4 +20,4 @@ def extrema(x, y=None):
2020
zix = np.where(np.abs(np.diff(np.sign(np.diff(x)))) == 2)[0]
2121
return zix
2222
if not y:
23-
print zix
23+
print(zix)

PyHEADTAIL/feedback/transverse_damper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@copyright CERN
55
'''
66

7-
from __future__ import division
7+
88

99
import numpy as np
1010
from scipy.special import k0

PyHEADTAIL/feedback/widebandfeedback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@copyright CERN
55
'''
66

7-
from __future__ import division
7+
88

99
import numpy as np
1010
from scipy.special import k0

PyHEADTAIL/field_maps/Transverse_Efield_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def track(self, beam):
3636

3737
slices = beam.get_slices(self.slicer)
3838

39-
for sid in xrange(slices.n_slices-1, -1, -1):
39+
for sid in range(slices.n_slices-1, -1, -1):
4040

4141
# select particles in the slice
4242
pid = slices.particle_indices_of_slice(sid)

PyHEADTAIL/field_maps/field_map.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@date: 13.06.2017
1616
'''
1717

18-
from __future__ import division, print_function
18+
1919

2020
from scipy.constants import c
2121

@@ -82,7 +82,7 @@ def __init__(self, length, mesh, fields, wrt_beam_centroid=False,
8282
poissonsolver=None,
8383
gradient=lambda *args, **kwargs: None,
8484
mesh=mesh)
85-
self.fields = map(pm.ensure_same_device, fields)
85+
self.fields = list(map(pm.ensure_same_device, fields))
8686
self.wrt_beam_centroid = wrt_beam_centroid
8787

8888
def track(self, beam):
@@ -94,7 +94,7 @@ def track(self, beam):
9494
beam.y - my,
9595
beam.z - mz] # zip will cut to #fields
9696

97-
mesh_fields_and_mp_coords = zip(self.fields, mp_coords)
97+
mesh_fields_and_mp_coords = list(zip(self.fields, mp_coords))
9898

9999
# electric fields at each particle position in lab frame [V/m]
100100
part_fields = self.pypic.field_to_particles(*mesh_fields_and_mp_coords)
@@ -149,7 +149,7 @@ def __init__(self, slicer, *args, **kwargs):
149149
# require 2D!
150150
assert self.pypic.mesh.dimension == 2, \
151151
'mesh needs to be two-dimensional!'
152-
assert all(map(lambda f: f.ndim == 2, self.fields)), \
152+
assert all([f.ndim == 2 for f in self.fields]), \
153153
'transverse field components need to be two-dimensional arrays!'
154154
#
155155

@@ -167,7 +167,7 @@ def track(self, beam):
167167
mp_coords = [beam.x - mx,
168168
beam.y - my,
169169
beam.z] # zip will cut to #fields
170-
mesh_fields_and_mp_coords = zip(self.fields, mp_coords)
170+
mesh_fields_and_mp_coords = list(zip(self.fields, mp_coords))
171171

172172
# electric fields at each particle position in lab frame [V/m]
173173
part_fields = self.pypic.field_to_particles(*mesh_fields_and_mp_coords)

PyHEADTAIL/general/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def deprecated_wrapper(*args, **kwargs):
2626
'PyHEADTAIL release!'.format(name),
2727
category=DeprecationWarning, stacklevel=2)
2828
warnings.simplefilter('default', DeprecationWarning)
29-
print message
29+
print(message)
3030
return func(*args, **kwargs)
3131
return deprecated_wrapper
3232
return deprecated_decorator
@@ -41,7 +41,7 @@ def memoize(function):
4141
@wraps(function)
4242
def evaluate(*args):
4343
signature = (args)
44-
if not store.has_key(signature):
44+
if signature not in store:
4545
store[signature] = function(*args)
4646
return store[signature]
4747
return evaluate

PyHEADTAIL/general/element.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ def warns(self, output):
7171
self._warningprinter.prints("*** PyHEADTAIL WARNING! " + output)
7272

7373

74-
class Element(Printing):
74+
class Element(Printing, metaclass=ABCMeta):
7575
'''
7676
Abstract element as part of the tracking layout. Guarantees
7777
to fulfil its tracking contract via the method track(beam).
7878
'''
79-
__metaclass__ = ABCMeta
8079

8180
@abstractmethod
8281
def track(self, beam):

PyHEADTAIL/general/pmath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ def update_active_dict(new_dict):
331331
if not hasattr(update_active_dict, 'active_dict'):
332332
update_active_dict.active_dict = new_dict
333333
# delete all old implementations/references from globals()
334-
for key in globals().keys():
335-
if key in update_active_dict.active_dict.keys():
334+
for key in list(globals().keys()):
335+
if key in list(update_active_dict.active_dict.keys()):
336336
del globals()[key]
337337
# add the new active dict to the globals()
338338
globals().update(new_dict)

0 commit comments

Comments
 (0)