Source code for csaxs_bec.bec_ipython_client.plugins.cSAXS.slits
from __future__ import annotations
import builtins
from typing import Optional
# ------------------------------------------------------------
# Make dev visible if running inside BEC
# ------------------------------------------------------------
if builtins.__dict__.get("dev") is not None:
dev = builtins.__dict__.get("dev")
# ============================================================
# Slits root (user-facing object)
# ============================================================
[docs]
class cSAXSSlits:
"""
User-visible slits namespace.
"""
def __init__(self, client):
self.client = client
self.device_manager = client.device_manager
# --------------------------------------------------------
# internal helpers
# --------------------------------------------------------
def _sl_get_position(self, device_name: str) -> Optional[float]:
"""
Safely return the position of a device or None.
"""
try:
device = self.device_manager.devices[device_name]
except Exception:
return None
try:
if hasattr(device, "readback"):
return device.readback.get()
except Exception:
pass
try:
if hasattr(device, "get"):
return device.get()
except Exception:
pass
return None
@staticmethod
def _sl_fmt(value: Optional[float]) -> str:
if value is None:
return " --- "
return f"{value:7.4f}"
# --------------------------------------------------------
# public API
# --------------------------------------------------------
[docs]
def slits_show_all(self):
"""
Show all slits with center and width.
"""
print("")
print("========== cSAXS Slits Overview ==========")
print("")
# Slit 1
print("Slit 1 (frontend):")
ch = self._sl_get_position("sl1xc")
wh = self._sl_get_position("sl1xs")
cv = self._sl_get_position("sl1yc")
wv = self._sl_get_position("sl1ys")
print(
f" center horizontal = {self._sl_fmt(ch)} "
f"width horizontal = {self._sl_fmt(wh)}"
)
print(
f" center vertical = {self._sl_fmt(cv)} "
f"width vertical = {self._sl_fmt(wv)}"
)
print("")
# Slits 3–5
slit_map = {
3: "exposure box 2 entrance",
4: "exposure box 2 exit",
5: "exposure box 3",
}
for slit, label in slit_map.items():
print(f"Slit {slit} ({label}):")
ch = self._sl_get_position(f"sl{slit}ch")
wh = self._sl_get_position(f"sl{slit}wh")
cv = self._sl_get_position(f"sl{slit}cv")
wv = self._sl_get_position(f"sl{slit}wv")
print(
f" center horizontal = {self._sl_fmt(ch)} "
f"width horizontal = {self._sl_fmt(wh)}"
)
print(
f" center vertical = {self._sl_fmt(cv)} "
f"width vertical = {self._sl_fmt(wv)}"
)
print("")
print("==========================================")
print("")