Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion examples/BESSY2_example/bessy2-chroma.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "jlp-py312",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"name": "python",
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down
487 changes: 80 additions & 407 deletions examples/BESSY2_example/bessy2-orbit.ipynb

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions examples/BESSY2_example/bessy2-orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
# SR = sr.live

# if the ORM is not present measure it
if sr.design.orbit.response_matrix is None:
if SR.orbit.response_matrix is None:
SR.orm.measure(sleep_between_step=0.0 if SR == sr.design else 2.0)
SR.orm.save("orm.json")
# Load it on live
sr.live.orbit.load("orm.json")
# Load it on orbit correction tool
SR.orbit.load("orm.json")

# ----- Correct the orbit -----
# ----- Correct the orbit on live -----

# Get the devices
hcorr = sr.live.get_magnets("HCorr")
vcorr = sr.live.get_magnets("VCorr")
orbit = sr.live.get_bpms("BPM").positions
hcorr = SR.get_magnets("HCorr")
vcorr = SR.get_magnets("VCorr")
orbit = SR.get_bpms("BPM").positions

# Create an initial orbit with errors
std_kick = 10e-6
Expand All @@ -57,9 +57,11 @@
# If you are using the ORM measured on design to correct on live you need to set the
# gain since the unit for the BPMs are not the same for both modes yet.

sr.live.orbit.correct(gain=1e-9)
# sr.design.orbit.correct()
# sr.live.orbit.correct()
if SR == sr.design:
SR.orbit.correct()
else:
# BPM are in nm, work around with a 1e-9 weight
SR.orbit.correct(gain=1e-9)

time.sleep(3)
orbit_after = orbit.get()
Expand Down
41 changes: 14 additions & 27 deletions examples/BESSY2_example/bessy2-tune.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"import numpy as np\n",
"\n",
"from pyaml.accelerator import Accelerator\n",
"from pyaml.common.constants import ACTION_MEASURE\n",
"from pyaml.magnet.magnet import Magnet"
"from pyaml.common.constants import Action"
]
},
{
Expand Down Expand Up @@ -52,10 +51,10 @@
"# This callback is used to print output during the tune response measurement.\n",
"\n",
"\n",
"def tune_callback(step: int, action: int, m: Magnet, dtune: np.array):\n",
" if action == ACTION_MEASURE:\n",
"def tune_callback(action: int, cb_data: dict):\n",
" if action == Action.MEASURE:\n",
" # On action measure, the measured dq / dk is passed as argument\n",
" print(f\"Tune response: #{step} {m.get_name()} {dtune}\")\n",
" print(f\"Tune response: #{cb_data['step']} {cb_data['magnet']} {cb_data['tune']}\")\n",
" return True"
]
},
Expand All @@ -73,26 +72,14 @@
"\n",
"# Choose which backend to use.\n",
"SR = sr.design\n",
"# SR = sr.live\n",
"\n",
"tune_adjust = sr.design.tune\n",
"tune_adjust.response.measure(\n",
" callback=tune_callback, set_wait_time=0.0 if SR == sr.design else 2.0\n",
")\n",
"tune_adjust.response.save_json(\"tune-response.json\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7777a47",
"metadata": {},
"outputs": [],
"source": [
"# ----- Load the response matrix -----\n",
"# The example does the correction for the live mode\n",
"# but it can also be done on the design mode.\n",
"\n",
"sr.live.tune.response.load_json(\"tune-response.json\")"
"# if the TRM is not present measure it\n",
"if SR.tune.response_matrix is None:\n",
" SR.trm.measure(sleep_between_step=0.0 if SR == sr.design else 2.0, callback=tune_callback)\n",
" SR.trm.save(\"trm.json\")\n",
" # Load it on tune tuning tool\n",
" SR.tune.load(\"trm.json\")"
]
},
{
Expand All @@ -106,13 +93,13 @@
"\n",
"print(\"\\nRun tune correction:\")\n",
"\n",
"initial_tunes = np.array2string(sr.live.tune.readback(), precision=6, floatmode=\"fixed\")\n",
"initial_tunes = np.array2string(SR.tune.readback(), precision=6, floatmode=\"fixed\")\n",
"print(f\"Initial tunes: {initial_tunes}\")\n",
"\n",
"sr.live.tune.set([0.83, 0.84], iter=2, wait_time=3)\n",
"SR.tune.set([0.83, 0.84], iter=2, wait_time=3)\n",
"time.sleep(3)\n",
"\n",
"final_tunes = np.array2string(sr.live.tune.readback(), precision=6, floatmode=\"fixed\")\n",
"final_tunes = np.array2string(SR.tune.readback(), precision=6, floatmode=\"fixed\")\n",
"print(f\"Final tunes: {final_tunes}\")"
]
}
Expand Down
11 changes: 6 additions & 5 deletions examples/BESSY2_example/bessy2-tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,24 @@ def tune_callback(action: int, cb_data: dict):

# Choose which backend to use.
SR = sr.design
# SR = sr.live

# if the TRM is not present measure it
if sr.design.tune.response_matrix is None:
SR.trm.measure(sleep_between_step=0.0 if SR == sr.design else 2.0, callback=tune_callback)
SR.trm.save("trm.json")
# Load it on live
sr.live.tune.load("trm.json")
# Load it on tune tuning tool
SR.tune.load("trm.json")

# ----- Correct the tune -----

print("\nRun tune correction:")

initial_tunes = np.array2string(sr.live.tune.readback(), precision=6, floatmode="fixed")
initial_tunes = np.array2string(SR.tune.readback(), precision=6, floatmode="fixed")
print(f"Initial tunes: {initial_tunes}")

sr.live.tune.set([0.83, 0.84], iter=2, wait_time=3)
SR.tune.set([0.83, 0.84], iter=2, wait_time=3)
time.sleep(3)

final_tunes = np.array2string(sr.live.tune.readback(), precision=6, floatmode="fixed")
final_tunes = np.array2string(SR.tune.readback(), precision=6, floatmode="fixed")
print(f"Final tunes: {final_tunes}")
2 changes: 1 addition & 1 deletion pyaml/tuning_tools/chromaticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def response_matrix(self) -> ResponseMatrixData | None:

def load(self, load_path: Path):
"""
Dyanmically loads a response matrix.
Dynamically loads a response matrix.
Parameters
----------
Expand Down
Loading