Skip to content

Commit 3e208ce

Browse files
committed
axisdef
1 parent 2d43388 commit 3e208ce

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

pyat/at/lattice/axisdef.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Helper functions for axis and plane descriptions"""
2+
23
from __future__ import annotations
34
from typing import Optional, Union
5+
46
# For sys.version_info.minor < 9:
57
from typing import Tuple
68

@@ -16,31 +18,31 @@
1618
ct=dict(index=5, label=r"$\beta c \tau$", unit=" [m]"),
1719
)
1820
for xk, xv in [it for it in _axis_def.items()]:
19-
xv['code'] = xk
20-
_axis_def[xv['index']] = xv
21+
xv["code"] = xk
22+
_axis_def[xv["index"]] = xv
2123
_axis_def[xk.upper()] = xv
22-
_axis_def['delta'] = _axis_def['dp']
23-
_axis_def['xp'] = _axis_def['px'] # For backward compatibility
24-
_axis_def['yp'] = _axis_def['py'] # For backward compatibility
25-
_axis_def['s'] = _axis_def['ct']
26-
_axis_def['S'] = _axis_def['ct']
27-
_axis_def[None] = dict(index=slice(None), label="", unit="", code=":")
24+
_axis_def["delta"] = _axis_def["dp"]
25+
_axis_def["xp"] = _axis_def["px"] # For backward compatibility
26+
_axis_def["yp"] = _axis_def["py"] # For backward compatibility
27+
_axis_def["s"] = _axis_def["ct"]
28+
_axis_def["S"] = _axis_def["ct"]
29+
_axis_def[None] = dict(index=None, label="", unit="", code=":")
2830
_axis_def[Ellipsis] = dict(index=Ellipsis, label="", unit="", code="...")
2931

3032
_plane_def = dict(
3133
x=dict(index=0, label="x", unit=" [m]"),
3234
y=dict(index=1, label="y", unit=" [m]"),
33-
z=dict(index=2, label="z", unit="")
35+
z=dict(index=2, label="z", unit=""),
3436
)
3537
for xk, xv in [it for it in _plane_def.items()]:
36-
xv['code'] = xk
37-
_plane_def[xv['index']] = xv
38+
xv["code"] = xk
39+
_plane_def[xv["index"]] = xv
3840
_plane_def[xk.upper()] = xv
39-
_plane_def['h'] = _plane_def['x']
40-
_plane_def['v'] = _plane_def['y']
41-
_plane_def['H'] = _plane_def['x']
42-
_plane_def['V'] = _plane_def['y']
43-
_plane_def[None] = dict(index=slice(None), label="", unit="", code=":")
41+
_plane_def["h"] = _plane_def["x"]
42+
_plane_def["v"] = _plane_def["y"]
43+
_plane_def["H"] = _plane_def["x"]
44+
_plane_def["V"] = _plane_def["y"]
45+
_plane_def[None] = dict(index=None, label="", unit="", code=":")
4446
_plane_def[Ellipsis] = dict(index=Ellipsis, label="", unit="", code="...")
4547

4648

pyat/at/lattice/elements.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,9 @@ def is_compatible(self, other) -> bool:
930930
def invrho(dip: Dipole):
931931
return dip.BendingAngle / dip.Length
932932

933-
return (super().is_compatible(other) and
934-
self.ExitAngle == -other.EntranceAngle and
935-
abs(invrho(self) - invrho(other)) <= 1.e-6)
933+
return (super().is_compatible(other)
934+
and self.ExitAngle == -other.EntranceAngle
935+
and abs(invrho(self) - invrho(other)) <= 1.e-6)
936936

937937
def merge(self, other) -> None:
938938
super().merge(other)

pyat/at/lattice/lattice_object.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,13 @@ def insert(self, idx: SupportsIndex, elem: Element, copy_elements=False):
319319
If :py:obj:`True` a deep copy of elem
320320
is used.
321321
"""
322-
# noinspection PyUnusedLocal
323322
# scan the new element to update it
324-
elist = list(self._addition_filter([elem],
323+
elist = list(self._addition_filter([elem], # noqa: F841
325324
copy_elements=copy_elements))
326325
super().insert(idx, elem)
327326

328327
def extend(self, elems: Iterable[Element], copy_elements=False):
328+
# noinspection PyUnresolvedReferences
329329
r"""This method adds all the elements of `elems` to the end of the
330330
lattice. The behavior is the same as for a :py:obj:`list`
331331
@@ -347,24 +347,25 @@ def extend(self, elems: Iterable[Element], copy_elements=False):
347347
super().extend(elems)
348348

349349
def append(self, elem: Element, copy_elements=False):
350-
r"""This method overwrites the inherited method
351-
:py:meth:`list.append()`,
352-
it behavior is changed, it accepts only AT lattice elements
353-
:py:obj:`Element` as input argument.
354-
355-
Equivalents syntaxes:
356-
>>> ring.append(elem)
357-
>>> ring += [elem]
358-
359-
Parameters:
360-
elem (Element): AT element to be appended to the lattice
361-
copy_elements(bool): Default :py:obj:`True`.
362-
If :py:obj:`True` a deep copy of elem
363-
is used
350+
# noinspection PyUnresolvedReferences
351+
r"""This method overwrites the inherited method :py:meth:`list.append()`,
352+
its behavior is changed, it accepts only AT lattice elements
353+
:py:obj:`Element` as input argument.
354+
355+
Equivalents syntaxes:
356+
>>> ring.append(elem)
357+
>>> ring += [elem]
358+
359+
Parameters:
360+
elem (Element): AT element to be appended to the lattice
361+
copy_elements(bool): Default :py:obj:`True`.
362+
If :py:obj:`True` a deep copy of elem
363+
is used
364364
"""
365365
self.extend([elem], copy_elements=copy_elements)
366366

367367
def repeat(self, n: int, copy_elements=True):
368+
# noinspection SpellCheckingInspection,PyUnresolvedReferences,PyRedeclaration
368369
r"""This method allows to repeat the lattice `n` times.
369370
If `n` does not divide `ring.periodicity`, the new ring
370371
periodicity is set to 1, otherwise it is et to
@@ -409,6 +410,7 @@ def copy_fun(elem, copy):
409410

410411
def concatenate(self, *lattices: Iterable[Element],
411412
copy_elements=False, copy=False):
413+
# noinspection PyUnresolvedReferences,SpellCheckingInspection,PyRedeclaration
412414
"""Concatenate several `Iterable[Element]` with the lattice
413415
414416
Equivalents syntaxes:
@@ -442,6 +444,7 @@ def concatenate(self, *lattices: Iterable[Element],
442444
return lattice if copy else None
443445

444446
def reverse(self, copy=False):
447+
# noinspection PyUnresolvedReferences
445448
r"""Reverse the order of the lattice and swapt the faces
446449
of elements. Alignment errors are not swapped
447450
@@ -520,7 +523,7 @@ def copy(self) -> Lattice:
520523
def deepcopy(self) -> Lattice:
521524
"""Returns a deep copy of the lattice"""
522525
return copy.deepcopy(self)
523-
526+
524527
def slice_elements(self, refpts: Refpts, slices: int = 1) -> Lattice:
525528
"""Create a new lattice by slicing the elements at refpts
526529
@@ -542,7 +545,7 @@ def slice_generator(_):
542545
else:
543546
yield el
544547

545-
return Lattice(slice_generator, iterator=self.attrs_filter)
548+
return Lattice(slice_generator, iterator=self.attrs_filter)
546549

547550
def slice(self, size: Optional[float] = None, slices: Optional[int] = 1) \
548551
-> Lattice:
@@ -639,8 +642,8 @@ def energy(self) -> float:
639642
def energy(self, energy: float):
640643
# Set the Energy attribute of radiating elements
641644
for elem in self:
642-
if (isinstance(elem, (elt.RFCavity, elt.Wiggler)) or
643-
elem.PassMethod.endswith('RadPass')):
645+
if (isinstance(elem, (elt.RFCavity, elt.Wiggler))
646+
or elem.PassMethod.endswith('RadPass')):
644647
elem.Energy = energy
645648
# Set the energy attribute of the Lattice
646649
# Use a numpy scalar to allow division by zero

0 commit comments

Comments
 (0)