Skip to content

Commit

Permalink
Merge pull request #241 from spc-group/gridscan_fix
Browse files Browse the repository at this point in the history
Gridscan fix
  • Loading branch information
Cathyhjj authored Jul 16, 2024
2 parents e3ba767 + c179e3b commit 0e51cec
Show file tree
Hide file tree
Showing 16 changed files with 451 additions and 387 deletions.
22 changes: 16 additions & 6 deletions src/firefly/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,44 +217,49 @@ def setup_window_actions(self):
text="&Count",
display_file=plans_dir / "count.py",
shortcut="Ctrl+Shift+C",
icon=qta.icon("mdi.counter"),
icon=qta.icon("mdi.numeric"),
WindowClass=PlanMainWindow,
),
"move_motor": WindowAction(
name="move_motor",
text="&Move motor",
display_file=plans_dir / "move_motor_window.py",
shortcut="Ctrl+Shift+M",
icon=qta.icon("mdi.rotate-right-variant"),
WindowClass=PlanMainWindow,
),
"line_scan": WindowAction(
name="line_scan",
text="&Line scan",
display_file=plans_dir / "line_scan.py",
shortcut="Ctrl+Shift+L",
icon=qta.icon("mdi.chart-bell-curve"),
WindowClass=PlanMainWindow,
),
"grid_scan": WindowAction(
name="grid_scan",
text="&Grid scan",
shortcut="Ctrl+Shift+G",
display_file=plans_dir / "grid_scan.py",
icon=qta.icon("mdi.grid"),
WindowClass=PlanMainWindow,
),
"xafs_scan": WindowAction(
name="xafs_scan",
text="&XAFS scan",
display_file=plans_dir / "xafs_scan.py",
shortcut="Ctrl+Shift+X",
icon=qta.icon("mdi.chart-bell-curve-cumulative"),
WindowClass=PlanMainWindow,
),
}
# Disabled the grid scan window until this issue is fixed
# https://github.com/spc-group/haven/issues/231
self.actions.plans["grid_scan"].setEnabled(False)

# Action for showing the run browser window
self.actions.run_browser = WindowAction(
name="show_run_browser_action",
text="Browse Runs",
display_file=ui_dir / "run_browser.py",
icon=qta.icon("mdi.book-open-variant"),
WindowClass=FireflyMainWindow,
)
# Action for showing the beamline scheduling window
Expand Down Expand Up @@ -300,6 +305,9 @@ def setup_window_actions(self):
icon=qta.icon("mdi.sine-wave"),
)

def update_queue_controls(self, status):
print(status)

@asyncSlot(QAction)
async def finalize_new_window(self, action):
"""Slot for providing new windows for after a new window is created."""
Expand Down Expand Up @@ -379,6 +387,7 @@ def setup_queue_actions(self):
text="Success",
icon=qta.icon("fa5s.check"),
tooltip="End the current plan, marking as successful.",
checkable=True,
),
"abort": Action(
name="abort_runengine_action",
Expand Down Expand Up @@ -521,7 +530,7 @@ def prepare_queue_client(self, client=None, api=None):
partial(client.request_pause, defer=True)
)
self.actions.queue_controls["pause_now"].triggered.connect(
partial(client.request_pause, defer=True)
partial(client.request_pause, defer=False)
)
self.actions.queue_controls["start"].triggered.connect(client.start_queue)
self.actions.queue_controls["resume"].triggered.connect(client.resume_runengine)
Expand Down Expand Up @@ -589,14 +598,15 @@ def enable_queue_controls(self, re_state):
queue_actions["resume"],
queue_actions["halt"],
queue_actions["abort"],
queue_actions["stop_queue"],
]
elif re_state == "running":
enabled_signals = [
queue_actions["pause"],
queue_actions["pause_now"],
queue_actions["stop_queue"],
]
elif re_state == "stopping":
enabled_signals = []
else:
raise ValueError(f"Unknown run engine state: {re_state}")
# Enable/disable the relevant signals
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def update_queue_status(self, status):
self.ui.environment_label.setText(status["worker_environment_state"])
new_length = status["items_in_queue"]
self.ui.queue_length_label.setText(f"({new_length})")
self.ui.re_label.setText(status["manager_state"])
self.ui.re_label.setText(status["re_state"])
# Notify the display of the new status
display = self.display_widget()
display.update_queue_status(status)
Expand Down
65 changes: 52 additions & 13 deletions src/firefly/plans/grid_scan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

import numpy as np
from bluesky_queueserver_api import BPlan
from qasync import asyncSlot
from qtpy import QtWidgets
Expand All @@ -17,7 +18,15 @@ def __init__(self):

def setup_ui(self):
self.layout = QtWidgets.QGridLayout()
labels = ["Priority axis", "Motor", "Start", "Stop", "Snake", "Fly"]
labels = [
"Priority axis",
"Motor",
"Start",
"Stop",
"Scan points",
"Snake",
"Fly",
]
Qlabels_all = {}

# add labels in the first row
Expand All @@ -29,6 +38,7 @@ def setup_ui(self):
# fix widths so the labels are aligned with GridScanRegions
Qlabels_all["Priority axis"].setFixedWidth(70)
Qlabels_all["Motor"].setFixedWidth(100)
Qlabels_all["Scan points"].setFixedWidth(68)
Qlabels_all["Snake"].setFixedWidth(53)
Qlabels_all["Fly"].setFixedWidth(43)

Expand Down Expand Up @@ -66,13 +76,19 @@ def setup_ui(self):
self.stop_line_edit.setPlaceholderText("Stop…")
self.layout.addWidget(self.stop_line_edit)

# Fifth item, snake checkbox
# Fifth item, number of scan point
self.scan_pts_spin_box = QtWidgets.QSpinBox()
self.scan_pts_spin_box.setMinimum(1)
self.scan_pts_spin_box.setMaximum(99999)
self.layout.addWidget(self.scan_pts_spin_box)

# Sixth item, snake checkbox
self.snake_checkbox = QtWidgets.QCheckBox()
self.snake_checkbox.setText("Snake")
self.snake_checkbox.setEnabled(True)
self.layout.addWidget(self.snake_checkbox)

# Sixth item, fly checkbox # not available right now
# Seventh item, fly checkbox # not available right now
self.fly_checkbox = QtWidgets.QCheckBox()
self.fly_checkbox.setText("Fly")
self.fly_checkbox.setEnabled(False)
Expand All @@ -97,12 +113,15 @@ def customize_ui(self):
self.update_total_time
)
self.ui.spinBox_repeat_scan_num.valueChanged.connect(self.update_total_time)
self.ui.scan_pts_spin_box.valueChanged.connect(self.update_total_time)
# Connect scan points change to update total time
for region in self.regions:
region.scan_pts_spin_box.valueChanged.connect(self.update_total_time)

def time_calculate_method(self, detector_time):
num_points = self.ui.scan_pts_spin_box.value()
num_regions = len(self.regions)
total_time_per_scan = num_regions * detector_time * num_points
def time_per_scan(self, detector_time):
total_num_pnts = np.prod(
[region_i.scan_pts_spin_box.value() for region_i in self.regions]
)
total_time_per_scan = total_num_pnts * detector_time
return total_time_per_scan

@asyncSlot(object)
Expand All @@ -119,19 +138,40 @@ def update_snakes(self):
"""Update the snake checkboxes.
The last region is not snakable, so that checkbox gets
disabled. The rest get enabled.
disabled and unchecked. The rest get enabled.
"""
if len(self.regions) > 0:
self.regions[-1].snake_checkbox.setEnabled(False)
self.regions[-1].snake_checkbox.setChecked(False)
for region_i in self.regions[:-1]:
region_i.snake_checkbox.setEnabled(True)

def get_scan_parameters(self):
# Get scan parameters from widgets
detectors = self.ui.detectors_list.selected_detectors()
repeat_scan_num = int(self.ui.spinBox_repeat_scan_num.value())

# Get paramters from each rows of line regions:
motor_lst, start_lst, stop_lst, num_points_lst = [], [], [], []
for region_i in reversed(self.regions):
motor_lst.append(region_i.motor_box.current_component().name)
start_lst.append(float(region_i.start_line_edit.text()))
stop_lst.append(float(region_i.stop_line_edit.text()))
num_points_lst.append(int(region_i.scan_pts_spin_box.value()))

motor_args = [
values
for motor_i in zip(motor_lst, start_lst, stop_lst, num_points_lst)
for values in motor_i
]

return detectors, motor_args, repeat_scan_num

def queue_plan(self, *args, **kwargs):
"""Execute this plan on the queueserver."""
detectors, num_points, motor_args, repeat_scan_num, md = (
self.get_scan_parameters()
)
detectors, motor_args, repeat_scan_num = self.get_scan_parameters()
md = self.get_meta_data()

# get snake axes, if all unchecked, set it None
snake_axes = [
Expand All @@ -153,7 +193,6 @@ def queue_plan(self, *args, **kwargs):
scan_type,
detectors,
*motor_args,
num=num_points,
snake_axes=snake_axes,
md=md,
)
Expand Down
Loading

0 comments on commit 0e51cec

Please sign in to comment.