Skip to content

Commit d55e3fc

Browse files
authored
Merge pull request #109 from python-accelerator-middle-layer/bugfix/orbit_correction
Bugfix/orbit correction
2 parents ef03b22 + 886cc8f commit d55e3fc

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pyaml/tuning_tools/orbit.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,18 @@ def correct(
9898
trims = trims_v
9999
corr_array = self._vcorr
100100

101-
corrector_was_used = {key: False for key in trims.keys()}
102101
corrector_names = corr_array.names()
102+
corrector_to_index = {name: idx for idx, name in enumerate(corrector_names)}
103103
data_to_send = corr_array.strengths.get()
104-
for idx, name in enumerate(corrector_names):
105-
data_to_send[idx] += trims[name] * gain
106-
corrector_was_used[name] = True
107-
108-
# check that all corrector trims will be sent
109-
for key in trims.keys():
110-
if not corrector_was_used[key]:
104+
for name in trims.keys():
105+
idx = corrector_to_index.get(name, None)
106+
if idx is None:
111107
raise PyAMLException(
112-
f"Corrector {key} was not used in the orbit correction. "
113-
"There is an inconcistency between corrector arrays and "
108+
f"Corrector {name} not found in the magnet array for orbit corr. "
109+
"Possible inconcistency between corrector arrays and "
114110
"response matrix."
115111
)
112+
data_to_send[idx] += trims[name] * gain
116113

117114
corr_array.strengths.set(data_to_send)
118115
return

tests/test_tuning_orbit_correction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def test_tuning_orm():
2424
vcorr = element_holder.get_magnets("VCorr")
2525
bpms = element_holder.get_bpms("BPM")
2626

27+
x, y = bpms.positions.get().T # get reference orbit
28+
reference = np.concat((x, y))
29+
# there should be nothing to correct, but still work
30+
element_holder.orbit.correct(reference=reference)
31+
2732
# mangle orbit
2833
hcorr.strengths.set(
2934
hcorr.strengths.get() + std_kick * np.random.normal(size=len(hcorr))

0 commit comments

Comments
 (0)