Skip to content

Commit 217a478

Browse files
committed
plot observables
1 parent 173085a commit 217a478

11 files changed

+108
-1479
lines changed

docs/p/api/at.latticetools.response_matrix.rst

-15
This file was deleted.

docs/p/index.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ Sub-packages
3636
howto/multiprocessing
3737
howto/CavityControl
3838
howto/Collective
39-
Work with MAD-X files <api/at.load.madx>
40-
Use response matrices <notebooks/response_matrices>
39+
Working with MAD-X files <api/at.load.madx>
4140

4241
.. autosummary::
4342
:toctree: api

docs/p/notebooks/observables.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@
936936
"name": "python",
937937
"nbconvert_exporter": "python",
938938
"pygments_lexer": "ipython3",
939-
"version": "3.11.11"
939+
"version": "3.9.20"
940940
}
941941
},
942942
"nbformat": 4,

docs/p/notebooks/response_matrices.ipynb

-446
This file was deleted.

pyat/at/lattice/utils.py

+12-33
Original file line numberDiff line numberDiff line change
@@ -105,32 +105,6 @@ class RefptsCode(Enum):
105105
End = RefptsCode.End
106106

107107

108-
def _chkattr(attrname: str, el):
109-
return hasattr(el, attrname)
110-
111-
112-
def _chkattrval(attrname: str, attrvalue, el):
113-
try:
114-
v = getattr(el, attrname)
115-
except AttributeError:
116-
return False
117-
else:
118-
return v == attrvalue
119-
120-
121-
def _chkpattern(pattern: str, el):
122-
return fnmatch(el.FamName, pattern)
123-
124-
125-
def _chkregex(pattern: str, el):
126-
rgx = re.compile(pattern)
127-
return rgx.fullmatch(el.FamName)
128-
129-
130-
def _chktype(eltype: type, el):
131-
return isinstance(el, eltype)
132-
133-
134108
def _type_error(refpts, types):
135109
if isinstance(refpts, numpy.ndarray):
136110
tp = refpts.dtype.type
@@ -641,10 +615,14 @@ def checkattr(attrname: str, attrvalue: Optional = None) \
641615
Returns an iterator over all elements in ring that have a
642616
:pycode:`K` attribute equal to 0.0
643617
"""
644-
if attrvalue is None:
645-
return functools.partial(_chkattr, attrname)
646-
else:
647-
return functools.partial(_chkattrval, attrname, attrvalue)
618+
def testf(el):
619+
try:
620+
v = getattr(el, attrname)
621+
return (attrvalue is None) or (v == attrvalue)
622+
except AttributeError:
623+
return False
624+
625+
return testf
648626

649627

650628
def checktype(eltype: Union[type, Tuple[type, ...]]) -> ElementFilter:
@@ -668,7 +646,7 @@ def checktype(eltype: Union[type, Tuple[type, ...]]) -> ElementFilter:
668646
669647
Returns an iterator over all quadrupoles in ring
670648
"""
671-
return functools.partial(_chktype, eltype)
649+
return lambda el: isinstance(el, eltype)
672650

673651

674652
def checkname(pattern: str, regex: bool = False) -> ElementFilter:
@@ -696,9 +674,10 @@ def checkname(pattern: str, regex: bool = False) -> ElementFilter:
696674
Returns an iterator over all with name starting with ``QF``.
697675
"""
698676
if regex:
699-
return functools.partial(_chkregex, pattern)
677+
rgx = re.compile(pattern)
678+
return lambda el: rgx.fullmatch(el.FamName)
700679
else:
701-
return functools.partial(_chkpattern, pattern)
680+
return lambda el: fnmatch(el.FamName, pattern)
702681

703682

704683
def refpts_iterator(ring: Sequence[Element], refpts: Refpts,

pyat/at/lattice/variables.py

-12
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,6 @@ class VariableList(list):
403403
appending, insertion or concatenation with the "+" operator.
404404
"""
405405

406-
def __getitem__(self, index):
407-
if isinstance(index, slice):
408-
return VariableList(super().__getitem__(index))
409-
else:
410-
return super().__getitem__(index)
411-
412406
def get(self, ring=None, **kwargs) -> Sequence[float]:
413407
r"""Get the current values of Variables
414408
@@ -462,9 +456,3 @@ def __str__(self) -> str:
462456
def deltas(self) -> Sequence[Number]:
463457
"""delta values of the variables"""
464458
return np.array([var.delta for var in self])
465-
466-
@deltas.setter
467-
def deltas(self, value: Number | Sequence[Number]) -> None:
468-
deltas = np.broadcast_to(value, len(self))
469-
for var, delta in zip(self, deltas):
470-
var.delta = delta

pyat/at/latticetools/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""Defines classes for modifying a lattice and observing its parameters."""
1+
"""Defines classes for modifying a lattice and observing its parameters"""
22

33
from .observables import *
44
from .observablelist import *
5-
# from .matching import *
6-
from .response_matrix import *
5+
from .matching import *

0 commit comments

Comments
 (0)