This commit is contained in:
1 parent
f0ea2153f1
commit
66105af285
3 files changed
+109
-95
No files matched your search
+5
-2
@@ -134,8 +134,7 @@ class AareDaq:
|
||||
continue
|
||||
if not resp.ok:
|
||||
raise AareDaqError(
|
||||
f"AareDAQ {method} {endpoint} failed with {resp.status_code}: "
|
||||
f"{resp.text[:500]}"
|
||||
f"AareDAQ {method} {endpoint} failed with {resp.status_code}: {resp.text[:500]}"
|
||||
)
|
||||
return resp.json()
|
||||
raise AssertionError("unreachable") # pragma: no cover
|
||||
@@ -202,6 +201,10 @@ class AareDaq:
|
||||
"/sample/mount", params={"dbid": dbid, "reference": reference}, timeout_s=timeout_s
|
||||
)
|
||||
|
||||
def auto_loop_center(self):
|
||||
self.ensure_baton()
|
||||
self._post("/alc/center_loop")
|
||||
|
||||
def raster_scan(
|
||||
self,
|
||||
request: RasterGridRequest,
|
||||
|
||||
@@ -26,26 +26,26 @@ logger = bec_logger.logger
|
||||
# Hard-coded forms: task name -> [(argument, default value)]; the widget type follows the default.
|
||||
TASK_FORMS: dict[str, list[tuple[str, int | float | str]]] = {
|
||||
"run_optical_centering": [("sample_id", 0)],
|
||||
"run_grid_scan": [
|
||||
("n_x", 4),
|
||||
("n_y", 3),
|
||||
("step_x_um", 50.0),
|
||||
("step_y_um", 50.0),
|
||||
("exp_time_s", 0.1),
|
||||
("file_prefix", "grid"),
|
||||
("detector_distance_mm", 150.0),
|
||||
("transmission", 0.1),
|
||||
("energy_keV", 12.4),
|
||||
("beam_center_x_pxl", 0.0),
|
||||
("beam_center_y_pxl", 0.0),
|
||||
("beam_size_x_mm", 0.02),
|
||||
("beam_size_y_mm", 0.01),
|
||||
("ring_current_mA", 400.0),
|
||||
("flux_ph_s", 1e12),
|
||||
("sample_temperature_K", 100.0),
|
||||
("pgroup", "p16371"),
|
||||
("sample_name", "unknown_sample"),
|
||||
],
|
||||
# "run_grid_scan": [
|
||||
# ("n_x", 4),
|
||||
# ("n_y", 3),
|
||||
# ("step_x_um", 50.0),
|
||||
# ("step_y_um", 50.0),
|
||||
# ("exp_time_s", 0.1),
|
||||
# ("file_prefix", "grid"),
|
||||
# ("detector_distance_mm", 150.0),
|
||||
# ("transmission", 0.1),
|
||||
# ("energy_keV", 12.4),
|
||||
# ("beam_center_x_pxl", 0.0),
|
||||
# ("beam_center_y_pxl", 0.0),
|
||||
# ("beam_size_x_mm", 0.02),
|
||||
# ("beam_size_y_mm", 0.01),
|
||||
# ("ring_current_mA", 400.0),
|
||||
# ("flux_ph_s", 1e12),
|
||||
# ("sample_temperature_K", 100.0),
|
||||
# ("pgroup", "p16371"),
|
||||
# ("sample_name", "unknown_sample"),
|
||||
# ],
|
||||
# the AareDAQ-driven tasks; their bool/optional arguments keep their defaults here
|
||||
"aaredaq_mount_sample": [("dbid", 0)],
|
||||
"aaredaq_raster_scan": [
|
||||
|
||||
+84
-73
@@ -34,8 +34,11 @@ MxSequenceUpdate = tuple[EndpointInfo, MXMeasurementSequenceMessage] | None
|
||||
|
||||
|
||||
class MxTasks:
|
||||
"""Holder for operations on mx beamlines. Probably needs to be reconsidered
|
||||
or at least moved to its own module"""
|
||||
"""Holder for operations on mx beamlines. Probably needs to be reconsidered.
|
||||
TODO:
|
||||
- categorise tasks, allow nesting with one lock
|
||||
- add doc info to decorator, including placeholder for args, to show to GUI
|
||||
"""
|
||||
|
||||
def __init__(self, client: AareBec):
|
||||
self._client = client
|
||||
@@ -79,7 +82,7 @@ class MxTasks:
|
||||
if state_update:
|
||||
self._client.connector.set_and_publish(*state_update)
|
||||
|
||||
setattr(wrapper, "is_mx_task", True)
|
||||
wrapper.is_mx_task = True
|
||||
return wrapper
|
||||
|
||||
def _pause_queue_after_failure(self, task_name: str, e: Exception) -> None:
|
||||
@@ -93,7 +96,7 @@ class MxTasks:
|
||||
logger.exception("Failed to pause the task queue")
|
||||
|
||||
@task
|
||||
def run_optical_centering(self, sample_id: int):
|
||||
def run_optical_centering_bec(self, sample_id: int):
|
||||
"""Rotate the Aerotech to each angle from the config, update the optical centering
|
||||
prediction and tell the Smargon to move there. Publishes the `optical_centering_done`
|
||||
milestone, as failed if no target can be obtained or a move fails."""
|
||||
@@ -117,6 +120,11 @@ class MxTasks:
|
||||
self._client.optical_prediction.update_latest()
|
||||
return self._optical_centering_done_update(sample_id, success=True)
|
||||
|
||||
@task
|
||||
def run_optical_centering(self, sample_id):
|
||||
self._client.aaredaq.auto_loop_center()
|
||||
return self._optical_centering_done_update(sample_id, success=True)
|
||||
|
||||
def _optical_centering_done_update(self, sample_id: int, *, success: bool):
|
||||
return (
|
||||
StateEndpoints.optical_centering_done(),
|
||||
@@ -173,7 +181,9 @@ class MxTasks:
|
||||
dtz=dtz,
|
||||
transmission=transmission,
|
||||
smargon_top_left=SmargonCoordinate(
|
||||
sh_mm=Coordinate(x=smargon.x.get(), y=smargon.x.get(), z=smargon.x.get())
|
||||
sh_mm=Coordinate(x=smargon.x.get(), y=smargon.x.get(), z=smargon.x.get()),
|
||||
chi_deg=smargon.chi.get(),
|
||||
phi_deg=smargon.phi.get(),
|
||||
),
|
||||
)
|
||||
result = self._client.aaredaq.raster_scan(request, auto_center=auto_center)
|
||||
@@ -216,75 +226,76 @@ class MxTasks:
|
||||
result = self._client.aaredaq.rotation_scan(request)
|
||||
logger.info(f"AareDAQ rotation scan done: {len(result.result.images)} images")
|
||||
|
||||
@task
|
||||
def run_grid_scan(
|
||||
self,
|
||||
n_x: int,
|
||||
n_y: int,
|
||||
step_x_um: float,
|
||||
step_y_um: float,
|
||||
exp_time_s: float,
|
||||
file_prefix: str,
|
||||
detector_distance_mm: float,
|
||||
transmission: float,
|
||||
energy_keV: float,
|
||||
beam_center_x_pxl: float,
|
||||
beam_center_y_pxl: float,
|
||||
beam_size_x_mm: float,
|
||||
beam_size_y_mm: float,
|
||||
ring_current_mA: float,
|
||||
flux_ph_s: float,
|
||||
sample_temperature_K: float,
|
||||
pgroup: str = "p16371",
|
||||
sample_name: str = "unknown_sample",
|
||||
) -> None:
|
||||
"""Collect an n_x by n_y grid scan at the current position and omega: configure the
|
||||
Aerotech grid scan and check that AareScan accepts it, arm JFJoch, then trigger the
|
||||
Aerotech and wait for both to finish."""
|
||||
expected_s = exp_time_s * n_x * n_y + n_y * 0.3
|
||||
if expected_s > MAX_GRID_SCAN_S:
|
||||
raise ValueError(f"Grid scan is too long: {expected_s:.0f} s > {MAX_GRID_SCAN_S} s")
|
||||
|
||||
aerotech = self._client.devices.aerotech
|
||||
config = aerotech.gridscan_config
|
||||
for signal, value in (
|
||||
(config.grid_elem_count_x, n_x),
|
||||
(config.grid_elem_count_y, n_y),
|
||||
(config.grid_elem_size_x_um, step_x_um),
|
||||
(config.grid_elem_size_y_um, step_y_um),
|
||||
(config.time_per_element_sec, exp_time_s),
|
||||
):
|
||||
signal.set(value).wait()
|
||||
if not config.valid.get():
|
||||
raise ValueError(f"AareScan rejected the grid scan parameters: {config.message.get()}")
|
||||
|
||||
jfjoch = self._client.jfjoch
|
||||
jfjoch.measure_raster(
|
||||
RasterScan(
|
||||
n_x=n_x,
|
||||
n_y=n_y,
|
||||
step_x_mm=step_x_um / 1000.0,
|
||||
step_y_mm=step_y_um / 1000.0,
|
||||
omega_deg=aerotech.u.get(),
|
||||
exp_time_s=exp_time_s,
|
||||
detector_distance_mm=detector_distance_mm,
|
||||
transmission=transmission,
|
||||
file_prefix=file_prefix,
|
||||
pgroup=pgroup,
|
||||
sample_name=sample_name,
|
||||
energy_keV=energy_keV,
|
||||
beam_center_pxl=(beam_center_x_pxl, beam_center_y_pxl),
|
||||
beam_size_mm=(beam_size_x_mm, beam_size_y_mm),
|
||||
ring_current_mA=ring_current_mA,
|
||||
flux_ph_s=flux_ph_s,
|
||||
sample_temperature_K=sample_temperature_K,
|
||||
)
|
||||
)
|
||||
jfjoch.wait_till_running(timeout_s=60)
|
||||
logger.info(f"Starting {n_x}x{n_y} grid scan, {exp_time_s} s per element")
|
||||
aerotech.trigger().wait()
|
||||
result = jfjoch.wait_till_done(timeout_s=60)
|
||||
logger.info(f"Grid scan finished: {result.file_prefix} with {len(result.images)} images")
|
||||
# @task
|
||||
# def run_grid_scan(
|
||||
# self,
|
||||
# n_x: int,
|
||||
# n_y: int,
|
||||
# step_x_um: float,
|
||||
# step_y_um: float,
|
||||
# exp_time_s: float,
|
||||
# file_prefix: str,
|
||||
# detector_distance_mm: float,
|
||||
# transmission: float,
|
||||
# energy_keV: float,
|
||||
# beam_center_x_pxl: float,
|
||||
# beam_center_y_pxl: float,
|
||||
# beam_size_x_mm: float,
|
||||
# beam_size_y_mm: float,
|
||||
# ring_current_mA: float,
|
||||
# flux_ph_s: float,
|
||||
# sample_temperature_K: float,
|
||||
# pgroup: str = "p16371",
|
||||
# sample_name: str = "unknown_sample",
|
||||
# ) -> None:
|
||||
# """Collect an n_x by n_y grid scan at the current position and omega: configure the
|
||||
# Aerotech grid scan and check that AareScan accepts it, arm JFJoch, then trigger the
|
||||
# Aerotech and wait for both to finish."""
|
||||
# expected_s = exp_time_s * n_x * n_y + n_y * 0.3
|
||||
# if expected_s > MAX_GRID_SCAN_S:
|
||||
# raise ValueError(f"Grid scan is too long: {expected_s:.0f} s > {MAX_GRID_SCAN_S} s")
|
||||
#
|
||||
# aerotech = self._client.devices.aerotech
|
||||
# config = aerotech.gridscan_config
|
||||
# for signal, value in (
|
||||
# (config.grid_elem_count_x, n_x),
|
||||
# (config.grid_elem_count_y, n_y),
|
||||
# (config.grid_elem_size_x_um, step_x_um),
|
||||
# (config.grid_elem_size_y_um, step_y_um),
|
||||
# (config.time_per_element_sec, exp_time_s),
|
||||
# ):
|
||||
# signal.set(value).wait()
|
||||
# if not config.valid.get():
|
||||
# raise ValueError(f"AareScan rejected the grid scan parameters: {config.message.get()}")
|
||||
#
|
||||
# jfjoch = self._client.jfjoch
|
||||
# jfjoch.measure_raster(
|
||||
# RasterScan(
|
||||
# n_x=n_x,
|
||||
# n_y=n_y,
|
||||
# step_x_mm=step_x_um / 1000.0,
|
||||
# step_y_mm=step_y_um / 1000.0,
|
||||
# omega_deg=aerotech.u.get(),
|
||||
# exp_time_s=exp_time_s,
|
||||
# detector_distance_mm=detector_distance_mm,
|
||||
# transmission=transmission,
|
||||
# file_prefix=file_prefix,
|
||||
# pgroup=pgroup,
|
||||
# sample_name=sample_name,
|
||||
# energy_keV=energy_keV,
|
||||
# beam_center_pxl=(beam_center_x_pxl, beam_center_y_pxl),
|
||||
# beam_size_mm=(beam_size_x_mm, beam_size_y_mm),
|
||||
# ring_current_mA=ring_current_mA,
|
||||
# flux_ph_s=flux_ph_s,
|
||||
# sample_temperature_K=sample_temperature_K,
|
||||
# )
|
||||
# )
|
||||
# jfjoch.wait_till_running(timeout_s=60)
|
||||
# logger.info(f"Starting {n_x}x{n_y} grid scan, {exp_time_s} s per element")
|
||||
# aerotech.trigger().wait()
|
||||
# result = jfjoch.wait_till_done(timeout_s=60)
|
||||
# logger.info(f"Grid scan finished: {result.file_prefix} with {len(result.images)} images")
|
||||
|
||||
|
||||
class MxTaskQueue:
|
||||
|
||||
Reference in new issue
Block a user