fix slits show all
This commit was merged in pull request #183.
This commit is contained in:
@@ -3,105 +3,114 @@ from __future__ import annotations
|
||||
import builtins
|
||||
from typing import Optional
|
||||
|
||||
# Make dev visible if running inside BEC (same pattern as diagnostics)
|
||||
if builtins.dict.get("dev") is not None:
|
||||
dev = builtins.dict.get("dev")
|
||||
# ------------------------------------------------------------
|
||||
# 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)
|
||||
# ============================================================
|
||||
|
||||
class cSAXSSlits:
|
||||
"""
|
||||
User-visible slits namespace.
|
||||
|
||||
Provides read-only overview and helper methods for all cSAXS slits.
|
||||
"""
|
||||
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
self.device_manager = client.device_manager
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# --------------------------------------------------------
|
||||
# internal helpers
|
||||
# ------------------------------------------------------------------
|
||||
# --------------------------------------------------------
|
||||
|
||||
def _get_position(self, device_name: str) -> Optional[float]:
|
||||
def _sl_get_position(self, device_name: str) -> Optional[float]:
|
||||
"""
|
||||
Safely return the position of a device or None if unavailable.
|
||||
Safely return the position of a device or None.
|
||||
"""
|
||||
try:
|
||||
dev = self.device_manager.devices[device_name]
|
||||
return dev.position
|
||||
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 _fmt(value: Optional[float]) -> str:
|
||||
"""
|
||||
Format numeric values consistently, SPEC-style.
|
||||
"""
|
||||
def _sl_fmt(value: Optional[float]) -> str:
|
||||
if value is None:
|
||||
return " --- "
|
||||
return f"{value:7.4f}"
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# --------------------------------------------------------
|
||||
# public API
|
||||
# ------------------------------------------------------------------
|
||||
# --------------------------------------------------------
|
||||
|
||||
def show_all(self):
|
||||
def slits_show_all(self):
|
||||
"""
|
||||
Show all slits with center and width, ordered along the beamline.
|
||||
Equivalent to the historic SPEC macro slits_show_all.
|
||||
Show all slits with center and width.
|
||||
"""
|
||||
|
||||
print("")
|
||||
print("========== cSAXS Slits Overview ==========")
|
||||
print("")
|
||||
|
||||
# --------------------------------------------------------------
|
||||
# Slit 1 – frontend (white beam)
|
||||
# --------------------------------------------------------------
|
||||
# Slit 1
|
||||
print("Slit 1 (frontend):")
|
||||
|
||||
ch = self._get_position("sl1xc")
|
||||
wh = self._get_position("sl1xs")
|
||||
cv = self._get_position("sl1yc")
|
||||
wv = self._get_position("sl1ys")
|
||||
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._fmt(ch)} "
|
||||
f"width horizontal = {self._fmt(wh)}"
|
||||
f" center horizontal = {self._sl_fmt(ch)} "
|
||||
f"width horizontal = {self._sl_fmt(wh)}"
|
||||
)
|
||||
print(
|
||||
f" center vertical = {self._fmt(cv)} "
|
||||
f"width vertical = {self._fmt(wv)}"
|
||||
f" center vertical = {self._sl_fmt(cv)} "
|
||||
f"width vertical = {self._sl_fmt(wv)}"
|
||||
)
|
||||
print("")
|
||||
|
||||
# --------------------------------------------------------------
|
||||
# Slits 3–5 – exposure boxes
|
||||
# --------------------------------------------------------------
|
||||
# Slits 3–5
|
||||
slit_map = {
|
||||
3: "exposure box 1 entrance",
|
||||
4: "exposure box 1 exit",
|
||||
5: "exposure box 2 exit",
|
||||
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._get_position(f"sl{slit}ch")
|
||||
wh = self._get_position(f"sl{slit}wh")
|
||||
cv = self._get_position(f"sl{slit}cv")
|
||||
wv = self._get_position(f"sl{slit}wv")
|
||||
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._fmt(ch)} "
|
||||
f"width horizontal = {self._fmt(wh)}"
|
||||
f" center horizontal = {self._sl_fmt(ch)} "
|
||||
f"width horizontal = {self._sl_fmt(wh)}"
|
||||
)
|
||||
print(
|
||||
f" center vertical = {self._fmt(cv)} "
|
||||
f"width vertical = {self._fmt(wv)}"
|
||||
f" center vertical = {self._sl_fmt(cv)} "
|
||||
f"width vertical = {self._sl_fmt(wv)}"
|
||||
)
|
||||
print("")
|
||||
|
||||
print("==========================================")
|
||||
print("")
|
||||
print("")
|
||||
Reference in New Issue
Block a user