Skip to content
Draft
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
2 changes: 1 addition & 1 deletion examples/other_examples/ControlSystem/tango/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sr = Accelerator.load("config.yaml")

# print the BPM position
bpm = sr.live.bpm.get("BPM_C01-01") # bpm is a BPM
bpm = sr.live.diagnostic.bpm.get("BPM_C01-01") # bpm is a BPM
print(bpm.positions.get())

# Direct access to control system
Expand Down
4 changes: 2 additions & 2 deletions examples/other_examples/ORM_Tango_server/ORM.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def orbit_callback(self, action: int, cdata):

def orm_run(self):
# On design sleep 10ms to allow thread schedule
self.SR.design.orm.measure(callback=orbit_callback, sleep_between_meas=0.01)
self.orm_data = self.SR.design.orm.get()
self.SR.design.tool.orm.measure(callback=orbit_callback, sleep_between_meas=0.01)
self.orm_data = self.SR.design.tool.orm.get()
self.set_status(f"Ready to scan: {self.ConfigFileName}")
self.set_state(DevState.ON)

Expand Down
207 changes: 11 additions & 196 deletions examples/use_cases/01-tune_correction.ipynb

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions examples/use_cases/01-tune_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@

# ### Standard tune correction tool
#
# `SR.tune` is the `DEFAULT_TUNE_CORRECTION` tool. `SR.trm` is the `DEFAULT_TUNE_RESPONSE_MATRIX` tool.
# `SR.tool.tune` is the `DEFAULT_TUNE_CORRECTION` tool. `SR.tool.trm` is the `DEFAULT_TUNE_RESPONSE_MATRIX` tool.
#
# Before correcting the tune you need a response matrix. It can be measured (below) or loaded from a previously saved file.

# In[7]:


print(SR.tune) # string representation
print(SR.tool.tune) # string representation


# #### Measuring the tune response matrix
Expand All @@ -145,36 +145,36 @@ def tune_callback(action: int, cb_data: dict):
# In[9]:


if SR.tune.response_matrix is None:
SR.trm.measure(sleep_between_step=wait_time, callback=tune_callback)
SR.trm.save(CONFIG_DIR / "trm.json")
if SR.tool.tune.response_matrix is None:
SR.tool.trm.measure(sleep_between_step=wait_time, callback=tune_callback)
SR.tool.trm.save(CONFIG_DIR / "trm.json")

SR.tune.load(CONFIG_DIR / "trm.json")
SR.tool.tune.load(CONFIG_DIR / "trm.json")
print("Response matrix loaded.")
print(SR.trm) # string representation
print(SR.tool.trm) # string representation


# #### Correcting the tune
#
# `SR.tune.set([qx, qy])` runs the correction iteratively. The `iter` parameter controls
# `SR.tool.tune.set([qx, qy])` runs the correction iteratively. The `iter` parameter controls
# the number of iterations and `wait_time` the settling time between each iteration.

# In[10]:


print(f"Tune before correction: {SR.tune.readback()}")
print(f"Tune before correction: {SR.tool.tune.readback()}")

qx, qy = 0.19, 0.28
print(f"\nSetting tune to [{qx}, {qy}]")
SR.tune.set([qx, qy], iter=10, wait_time=wait_time)
print(f"Tune after correction: {SR.tune.readback()}")
SR.tool.tune.set([qx, qy], iter=10, wait_time=wait_time)
print(f"Tune after correction: {SR.tool.tune.readback()}")

qx, qy = 0.21, 0.30
print(f"\nSetting tune to [{qx}, {qy}]")
SR.tune.set([qx, qy], iter=10, wait_time=wait_time)
print(f"Tune after correction: {SR.tune.readback()}")
SR.tool.tune.set([qx, qy], iter=10, wait_time=wait_time)
print(f"Tune after correction: {SR.tool.tune.readback()}")

print(SR.tune) # string representation
print(SR.tool.tune) # string representation


# In[ ]:
209 changes: 13 additions & 196 deletions examples/use_cases/03-orbit_correction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -185,163 +185,33 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "6adb7436",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"BPMs: 320, H correctors: 288, V correctors: 288\n"
]
}
],
"source": [
"bpms = SR.bpms.get(\"BPM\")\n",
"hcorr = SR.magnets.get(\"HCorr\")\n",
"vcorr = SR.magnets.get(\"VCorr\")\n",
"print(f\"BPMs: {len(bpms)}, H correctors: {len(hcorr)}, V correctors: {len(vcorr)}\")"
]
"outputs": [],
"source": "bpms = SR.diagnostic.bpms.get(\"BPM\")\nhcorr = SR.magnets.get(\"HCorr\")\nvcorr = SR.magnets.get(\"VCorr\")\nprint(f\"BPMs: {len(bpms)}, H correctors: {len(hcorr)}, V correctors: {len(vcorr)}\")"
},
{
"cell_type": "markdown",
"id": "808334df",
"metadata": {},
"source": [
"### Orbit response matrix\n",
"\n",
"The ORM can be saved in multiple formats. Load it into `SR.orbit` before correcting."
]
"source": "### Orbit response matrix\n\nThe ORM can be saved in multiple formats. Load it into `SR.tool.orbit` before correcting."
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "33636af2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrbitResponseMatrix(bpm_array_name='BPM', hcorr_array_name='HCorr', vcorr_array_name='VCorr', corrector_delta=1e-06, n_step=1, sleep_between_step=0.0, n_avg_meas=1, sleep_between_meas=0.0, name='DEFAULT_ORBIT_RESPONSE_MATRIX')"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"SR.orm # string representation"
]
"outputs": [],
"source": "SR.tool.orm # string representation"
},
{
"cell_type": "code",
"execution_count": null,
"id": "3f9dcb18",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"14 Sep 2026, 15:10:12 | INFO | Measuring correctors from the default arrays: HCorr and VCorr.\n",
"14 Sep 2026, 15:10:14 | INFO | Measured response of SH1A-C04-H.\n",
"14 Sep 2026, 15:10:16 | INFO | Measured response of SJ1A-C04-H.\n",
"14 Sep 2026, 15:10:17 | INFO | Measured response of SJ2A-C04-H.\n",
"14 Sep 2026, 15:10:18 | INFO | Measured response of SJ1B-C04-H.\n",
"14 Sep 2026, 15:10:19 | INFO | Measured response of SH2B-C04-H.\n",
"14 Sep 2026, 15:10:21 | INFO | Measured response of SJ1D-C04-H.\n",
"14 Sep 2026, 15:10:22 | INFO | Measured response of SJ2E-C04-H.\n",
"14 Sep 2026, 15:10:23 | INFO | Measured response of SJ1E-C04-H.\n",
"14 Sep 2026, 15:10:24 | INFO | Measured response of SH3E-C04-H.\n",
"14 Sep 2026, 15:10:26 | INFO | Measured response of SH1A-C05-H.\n",
"14 Sep 2026, 15:10:27 | INFO | Measured response of SD1A-C05-H.\n",
"14 Sep 2026, 15:10:28 | INFO | Measured response of SF2A-C05-H.\n",
"14 Sep 2026, 15:10:29 | INFO | Measured response of SD1B-C05-H.\n",
"14 Sep 2026, 15:10:31 | INFO | Measured response of SH2B-C05-H.\n",
"14 Sep 2026, 15:10:32 | INFO | Measured response of SD1D-C05-H.\n",
"14 Sep 2026, 15:10:33 | INFO | Measured response of SF2E-C05-H.\n",
"14 Sep 2026, 15:10:34 | INFO | Measured response of SD1E-C05-H.\n",
"14 Sep 2026, 15:10:36 | INFO | Measured response of SH3E-C05-H.\n",
"14 Sep 2026, 15:10:37 | INFO | Measured response of SH1A-C06-H.\n",
"14 Sep 2026, 15:10:38 | INFO | Measured response of SD1A-C06-H.\n",
"14 Sep 2026, 15:10:39 | INFO | Measured response of SF2A-C06-H.\n",
"14 Sep 2026, 15:10:41 | INFO | Measured response of SD1B-C06-H.\n",
"14 Sep 2026, 15:10:42 | INFO | Measured response of SH2B-C06-H.\n",
"14 Sep 2026, 15:10:43 | INFO | Measured response of SD1D-C06-H.\n",
"14 Sep 2026, 15:10:44 | INFO | Measured response of SF2E-C06-H.\n",
"14 Sep 2026, 15:10:45 | INFO | Measured response of SD1E-C06-H.\n",
"14 Sep 2026, 15:10:47 | INFO | Measured response of SH3E-C06-H.\n",
"14 Sep 2026, 15:10:48 | INFO | Measured response of SH1A-C07-H.\n",
"14 Sep 2026, 15:10:49 | INFO | Measured response of SD1A-C07-H.\n",
"14 Sep 2026, 15:10:50 | INFO | Measured response of SF2A-C07-H.\n",
"14 Sep 2026, 15:10:52 | INFO | Measured response of SD1B-C07-H.\n",
"14 Sep 2026, 15:10:53 | INFO | Measured response of SH2B-C07-H.\n",
"14 Sep 2026, 15:10:54 | INFO | Measured response of SD1D-C07-H.\n",
"14 Sep 2026, 15:10:55 | INFO | Measured response of SF2E-C07-H.\n",
"14 Sep 2026, 15:10:56 | INFO | Measured response of SD1E-C07-H.\n",
"14 Sep 2026, 15:10:57 | INFO | Measured response of SH3E-C07-H.\n",
"14 Sep 2026, 15:10:59 | INFO | Measured response of SH1A-C08-H.\n",
"14 Sep 2026, 15:11:00 | INFO | Measured response of SD1A-C08-H.\n",
"14 Sep 2026, 15:11:01 | INFO | Measured response of SF2A-C08-H.\n",
"14 Sep 2026, 15:11:02 | INFO | Measured response of SD1B-C08-H.\n",
"14 Sep 2026, 15:11:04 | INFO | Measured response of SH2B-C08-H.\n",
"14 Sep 2026, 15:11:05 | INFO | Measured response of SD1D-C08-H.\n",
"14 Sep 2026, 15:11:06 | INFO | Measured response of SF2E-C08-H.\n",
"14 Sep 2026, 15:11:07 | INFO | Measured response of SD1E-C08-H.\n",
"14 Sep 2026, 15:11:08 | INFO | Measured response of SH3E-C08-H.\n",
"14 Sep 2026, 15:11:10 | INFO | Measured response of SH1A-C09-H.\n",
"14 Sep 2026, 15:11:11 | INFO | Measured response of SD1A-C09-H.\n",
"14 Sep 2026, 15:11:12 | INFO | Measured response of SF2A-C09-H.\n",
"14 Sep 2026, 15:11:13 | INFO | Measured response of SD1B-C09-H.\n",
"14 Sep 2026, 15:11:14 | INFO | Measured response of SH2B-C09-H.\n",
"14 Sep 2026, 15:11:16 | INFO | Measured response of SD1D-C09-H.\n",
"14 Sep 2026, 15:11:17 | INFO | Measured response of SF2E-C09-H.\n",
"14 Sep 2026, 15:11:18 | INFO | Measured response of SD1E-C09-H.\n",
"14 Sep 2026, 15:11:19 | INFO | Measured response of SH3E-C09-H.\n",
"14 Sep 2026, 15:11:21 | INFO | Measured response of SH1A-C10-H.\n",
"14 Sep 2026, 15:11:22 | INFO | Measured response of SD1A-C10-H.\n",
"14 Sep 2026, 15:11:23 | INFO | Measured response of SF2A-C10-H.\n",
"14 Sep 2026, 15:11:24 | INFO | Measured response of SD1B-C10-H.\n",
"14 Sep 2026, 15:11:26 | INFO | Measured response of SH2B-C10-H.\n",
"14 Sep 2026, 15:11:27 | INFO | Measured response of SD1D-C10-H.\n",
"14 Sep 2026, 15:11:28 | INFO | Measured response of SF2E-C10-H.\n",
"14 Sep 2026, 15:11:29 | INFO | Measured response of SD1E-C10-H.\n",
"14 Sep 2026, 15:11:31 | INFO | Measured response of SH3E-C10-H.\n",
"14 Sep 2026, 15:11:32 | INFO | Measured response of SH1A-C11-H.\n",
"14 Sep 2026, 15:11:33 | INFO | Measured response of SD1A-C11-H.\n",
"14 Sep 2026, 15:11:34 | INFO | Measured response of SF2A-C11-H.\n",
"14 Sep 2026, 15:11:35 | INFO | Measured response of SD1B-C11-H.\n",
"14 Sep 2026, 15:11:37 | INFO | Measured response of SH2B-C11-H.\n",
"14 Sep 2026, 15:11:38 | INFO | Measured response of SD1D-C11-H.\n",
"14 Sep 2026, 15:11:39 | INFO | Measured response of SF2E-C11-H.\n",
"14 Sep 2026, 15:11:40 | INFO | Measured response of SD1E-C11-H.\n",
"14 Sep 2026, 15:11:41 | INFO | Measured response of SH3E-C11-H.\n",
"14 Sep 2026, 15:11:43 | INFO | Measured response of SH1A-C12-H.\n",
"14 Sep 2026, 15:11:44 | INFO | Measured response of SD1A-C12-H.\n",
"14 Sep 2026, 15:11:45 | INFO | Measured response of SF2A-C12-H.\n",
"14 Sep 2026, 15:11:46 | INFO | Measured response of SD1B-C12-H.\n",
"14 Sep 2026, 15:11:47 | INFO | Measured response of SH2B-C12-H.\n",
"14 Sep 2026, 15:11:49 | INFO | Measured response of SD1D-C12-H.\n",
"14 Sep 2026, 15:11:50 | INFO | Measured response of SF2E-C12-H.\n",
"14 Sep 2026, 15:11:51 | INFO | Measured response of SD1E-C12-H.\n",
"14 Sep 2026, 15:11:52 | INFO | Measured response of SH3E-C12-H.\n",
"14 Sep 2026, 15:11:54 | INFO | Measured response of SH1A-C13-H.\n",
"14 Sep 2026, 15:11:55 | INFO | Measured response of SD1A-C13-H.\n",
"14 Sep 2026, 15:11:56 | INFO | Measured response of SF2A-C13-H.\n"
]
}
],
"source": [
"SR.orm.measure(sleep_between_step=wait_time)\n",
"SR.orm.save(CONFIG_DIR / \"orm.json\")\n",
"SR.orm.save(CONFIG_DIR / \"orm.yaml\", with_type=\"yaml\")\n",
"SR.orm.save(CONFIG_DIR / \"orm.npz\", with_type=\"npz\")\n",
"\n",
"SR.orbit.load(CONFIG_DIR / \"orm.json\")\n",
"print(\"ORM measured, saved and loaded.\")"
]
"outputs": [],
"source": "SR.tool.orm.measure(sleep_between_step=wait_time)\nSR.tool.orm.save(CONFIG_DIR / \"orm.json\")\nSR.tool.orm.save(CONFIG_DIR / \"orm.yaml\", with_type=\"yaml\")\nSR.tool.orm.save(CONFIG_DIR / \"orm.npz\", with_type=\"npz\")\n\nSR.tool.orbit.load(CONFIG_DIR / \"orm.json\")\nprint(\"ORM measured, saved and loaded.\")"
},
{
"cell_type": "markdown",
Expand All @@ -357,15 +227,7 @@
"id": "942f8f3b",
"metadata": {},
"outputs": [],
"source": [
"orm_data = SR.orm.get()\n",
"plt.imshow(np.array(orm_data[\"matrix\"]))\n",
"plt.colorbar()\n",
"plt.title(\"Orbit response matrix\")\n",
"plt.xlabel(\"Corrector index\")\n",
"plt.ylabel(\"BPM index\")\n",
"plt.show()"
]
"source": "orm_data = SR.tool.orm.get()\nplt.imshow(np.array(orm_data[\"matrix\"]))\nplt.colorbar()\nplt.title(\"Orbit response matrix\")\nplt.xlabel(\"Corrector index\")\nplt.ylabel(\"BPM index\")\nplt.show()"
},
{
"cell_type": "markdown",
Expand All @@ -383,28 +245,7 @@
"id": "693fc409",
"metadata": {},
"outputs": [],
"source": [
"# Uncomment to measure and visualise dispersion\n",
"\n",
"# def disp_callback(action: int, cb_data) -> bool:\n",
"# from pyaml.common.constants import Action\n",
"# if action == Action.APPLY:\n",
"# print(\"Changing RF frequency\")\n",
"# elif action == Action.MEASURE:\n",
"# print(\"Reading orbit\")\n",
"# elif action == Action.RESTORE:\n",
"# print(\"Restoring RF frequency\")\n",
"# return True\n",
"\n",
"# SR.dispersion.measure(callback=disp_callback)\n",
"# disp_data = SR.dispersion.get()\n",
"# plt.plot(disp_data[\"frequency_response_x\"], label=\"H dispersion\")\n",
"# plt.plot(disp_data[\"frequency_response_y\"], label=\"V dispersion\")\n",
"# plt.xlabel(\"BPM index\")\n",
"# plt.ylabel(\"Orbit / Δf [m/Hz]\")\n",
"# plt.legend()\n",
"# plt.show()"
]
"source": "# Uncomment to measure and visualise dispersion\n\n# def disp_callback(action: int, cb_data) -> bool:\n# from pyaml.common.constants import Action\n# if action == Action.APPLY:\n# print(\"Changing RF frequency\")\n# elif action == Action.MEASURE:\n# print(\"Reading orbit\")\n# elif action == Action.RESTORE:\n# print(\"Restoring RF frequency\")\n# return True\n\n# SR.tool.dispersion.measure(callback=disp_callback)\n# disp_data = SR.tool.dispersion.get()\n# plt.plot(disp_data[\"frequency_response_x\"], label=\"H dispersion\")\n# plt.plot(disp_data[\"frequency_response_y\"], label=\"V dispersion\")\n# plt.xlabel(\"BPM index\")\n# plt.ylabel(\"Orbit / Δf [m/Hz]\")\n# plt.legend()\n# plt.show()"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -477,39 +318,15 @@
"cell_type": "markdown",
"id": "cf49c543",
"metadata": {},
"source": [
"### Correct the orbit\n",
"\n",
"Standard correction: `SR.orbit.correct(reference=reference)`.\n",
"\n",
"Optional variants (uncomment to use):\n",
"- **Virtual corrector weight**: down-weights correctors that are already at large strengths.\n",
"- **RF correction**: also adjusts the RF frequency to minimise dispersion-driven orbit.\n",
"- **Live unit mismatch**: if BESSY2 BPMs read in nm, pass `gain=1e-9`."
]
"source": "### Correct the orbit\n\nStandard correction: `SR.tool.orbit.correct(reference=reference)`.\n\nOptional variants (uncomment to use):\n- **Virtual corrector weight**: down-weights correctors that are already at large strengths.\n- **RF correction**: also adjusts the RF frequency to minimise dispersion-driven orbit.\n- **Live unit mismatch**: if BESSY2 BPMs read in nm, pass `gain=1e-9`."
},
{
"cell_type": "code",
"execution_count": null,
"id": "93135a4c",
"metadata": {},
"outputs": [],
"source": [
"# Standard correction\n",
"SR.orbit.correct(reference=reference)\n",
"\n",
"# With virtual corrector weight (ESRF style):\n",
"# SR.orbit.set_virtual_weight(1000)\n",
"# SR.orbit.correct(reference=reference)\n",
"\n",
"# With RF orbit correction (ESRF style, requires dispersion in ORM):\n",
"# SR.orbit.correct(reference=reference, rf=True)\n",
"\n",
"# BESSY2 live mode — BPMs in nm, use gain to compensate unit mismatch:\n",
"# SR.orbit.correct(reference=reference, gain=1e-9)\n",
"\n",
"sleep(wait_time)"
]
"source": "# Standard correction\nSR.tool.orbit.correct(reference=reference)\n\n# With virtual corrector weight (ESRF style):\n# SR.tool.orbit.set_virtual_weight(1000)\n# SR.tool.orbit.correct(reference=reference)\n\n# With RF orbit correction (ESRF style, requires dispersion in ORM):\n# SR.tool.orbit.correct(reference=reference, rf=True)\n\n# BESSY2 live mode — BPMs in nm, use gain to compensate unit mismatch:\n# SR.tool.orbit.correct(reference=reference, gain=1e-9)\n\nsleep(wait_time)"
},
{
"cell_type": "code",
Expand Down
Loading
Loading