Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Planwindows #218

Merged
merged 50 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
cf05754
add repeat scan num and sample notes
Cathyhjj May 7, 2024
14a2533
calculate total exposure time real time for xafs_scan
Cathyhjj May 7, 2024
a1781ae
add pop up warning box that is_standard option will make the data public
Cathyhjj May 7, 2024
5d3853c
changed xafs_scan ui to include notes, repeat scans, total exposure time
Cathyhjj May 7, 2024
0abccbf
added notes md in test_xafs_scan
Cathyhjj May 7, 2024
80eeb34
disable weight box when k checkbox is not checked in xafs_scan plan w…
Cathyhjj May 7, 2024
ecbc6aa
changed timeEdit into lables, add total time to include scan_repeat_num
Cathyhjj May 13, 2024
fd6a151
add yes and no option for the in_standard checkbox messagebox in xafs…
Cathyhjj May 13, 2024
fda38c9
refactor line_scan as a parent class for grid_scan
Cathyhjj May 14, 2024
7c16ac5
add grid_scan window plan
Cathyhjj May 14, 2024
a8b91f4
remove weight for Erange
Cathyhjj May 14, 2024
3bf652c
reset repeat_scan_num to 1 when hitting reset button in xafs_scan window
Cathyhjj May 14, 2024
484d721
changed the time calculator in xafs_scan, do merge energies first bef…
Cathyhjj May 22, 2024
8b65c56
add time_calculator test in test_xafs_scan
Cathyhjj May 28, 2024
5a3871c
add notes, repeats, time_calculator into grid and line_scan ui
Cathyhjj May 28, 2024
194f7b0
add time calculator in line_scan
Cathyhjj May 28, 2024
3baf9c4
modified grid_scan and add test_grid_scan
Cathyhjj May 28, 2024
610664b
black, isort and flake8 formatting
Cathyhjj May 28, 2024
ee91ed0
flake8 check
Cathyhjj May 28, 2024
bbd1e2c
change detectorlistview widget to multiple selection in ui files
Cathyhjj May 28, 2024
57504e4
Merge branch 'main' into planwindows
canismarko May 30, 2024
c25ed48
add move_motor_window.ui
Cathyhjj May 31, 2024
f5f49a6
add move_motor_window.py and its test python file
Cathyhjj Jun 3, 2024
050f5a9
modify except statements in xafs_scan
Cathyhjj Jun 3, 2024
78db05a
enhance line_scan and partially fixed line_scan test regarding the ti…
Cathyhjj Jun 4, 2024
94963e7
black, isort flake8 formatting
Cathyhjj Jun 4, 2024
175433d
fixed mistake that move_motor only takes one position value instead o…
Cathyhjj Jun 4, 2024
bd88cc5
add Qvalidators so that line and grid scan only takes floats in the l…
Cathyhjj Jun 4, 2024
dbed34f
removed unused imports and codes
Cathyhjj Jun 4, 2024
b0b6007
black, isort, flake8 formatting
Cathyhjj Jun 4, 2024
ecbe349
add test move motor file
Cathyhjj Jun 4, 2024
f4ae770
add util file in firefly plans, which includes time_converter and che…
Cathyhjj Jun 5, 2024
317e98d
removed time_converter and checked md in a more rebost way
Cathyhjj Jun 5, 2024
145e5f8
removed time_converter and checked md in a more rebost wayin line_scan
Cathyhjj Jun 5, 2024
3690efc
add time_calculator test in a seperate function
Cathyhjj Jun 5, 2024
1913b05
reduce try except block in xafs_scan
Cathyhjj Jun 5, 2024
a60a7ba
set one of the metadata to empty string to check whether it will be r…
Cathyhjj Jun 5, 2024
b824e98
removed redudent lines
Cathyhjj Jun 5, 2024
6e8f54e
black, isort formatting
Cathyhjj Jun 5, 2024
53e6138
add time calculator to grid_scan
Cathyhjj Jun 5, 2024
db31302
add time calcultor to test_grid_scan
Cathyhjj Jun 5, 2024
4dee9b5
fixed import
Cathyhjj Jun 5, 2024
ae23181
isort formatting
Cathyhjj Jun 5, 2024
3bda789
Merge branch 'main' into planwindows
Cathyhjj Jun 5, 2024
9356418
include nan into the total_time_calculator
Cathyhjj Jun 6, 2024
dc1ac21
added float conversion before int conversion for the time label.text(…
Cathyhjj Jun 6, 2024
5677221
modified disclaimer
Cathyhjj Jun 7, 2024
12f26c0
removed finally statement for the try except block in the time_calcul…
Cathyhjj Jun 7, 2024
4a916e7
modified docs strings for is_valid_value
Cathyhjj Jun 7, 2024
fa5327a
black formatting
Cathyhjj Jun 7, 2024
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: 2 additions & 0 deletions src/firefly/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ def setup_window_actions(self):
plans = [
# (plan_name, text, display file)
("count", "&Count", "count.py"),
("move_motor", "&Move motor", "move_motor_window.py"),
("line_scan", "&Line scan", "line_scan.py"),
("grid_scan", "&Grid scan", "grid_scan.py"),
("xafs_scan", "&XAFS Scan", "xafs_scan.py"),
]
self.plan_actions = []
Expand Down
162 changes: 162 additions & 0 deletions src/firefly/plans/grid_scan.py
canismarko marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import logging

from bluesky_queueserver_api import BPlan
from qtpy import QtWidgets
from qtpy.QtGui import QDoubleValidator

from firefly.application import FireflyApplication
from firefly.component_selector import ComponentSelector
from firefly.plans.line_scan import LineScanDisplay

log = logging.getLogger()


class TitleRegion:
def __init__(self):
self.setup_ui()

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

# add labels in the first row
for i, label_i in enumerate(labels):
Qlabel_i = QtWidgets.QLabel(label_i)
self.layout.addWidget(Qlabel_i, 0, i)
Qlabels_all[label_i] = Qlabel_i

# fix widths so the labels are aligned with GridScanRegions
Qlabels_all["Priority axis"].setFixedWidth(70)
Qlabels_all["Motor"].setFixedWidth(100)
Qlabels_all["Snake"].setFixedWidth(53)
Qlabels_all["Fly"].setFixedWidth(43)

# add labels in the second row
label = QtWidgets.QLabel("fast -> slow")
self.layout.addWidget(label, 1, 0)


class GridScanRegion:
def __init__(self):
self.setup_ui()

def setup_ui(self):
self.layout = QtWidgets.QHBoxLayout()

# First item, motor No.
self.motor_label = QtWidgets.QLCDNumber()
self.motor_label.setStyleSheet(
"QLCDNumber { background-color: white; color: red; }"
)
self.layout.addWidget(self.motor_label)

# Second item, ComponentSelector
self.motor_box = ComponentSelector()
self.layout.addWidget(self.motor_box)

# Third item, start point
self.start_line_edit = QtWidgets.QLineEdit()
self.start_line_edit.setValidator(QDoubleValidator()) # only takes floats
self.start_line_edit.setPlaceholderText("Start…")
self.layout.addWidget(self.start_line_edit)

# Forth item, stop point
self.stop_line_edit = QtWidgets.QLineEdit()
self.stop_line_edit.setValidator(QDoubleValidator()) # only takes floats
self.stop_line_edit.setPlaceholderText("Stop…")
self.layout.addWidget(self.stop_line_edit)

# Fifth 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
self.fly_checkbox = QtWidgets.QCheckBox()
self.fly_checkbox.setText("Fly")
self.fly_checkbox.setEnabled(False)
self.layout.addWidget(self.fly_checkbox)


class GridScanDisplay(LineScanDisplay):
default_num_regions = 2

def __init__(self, parent=None, args=None, macros=None, ui_filename=None, **kwargs):
super().__init__(parent, args, macros, ui_filename, **kwargs)

def customize_ui(self):
super().customize_ui()
# add title layout
self.title_region = TitleRegion()
self.ui.title_layout.addLayout(self.title_region.layout)
# reset button
self.ui.reset_pushButton.clicked.connect(self.reset_default_regions)

def add_regions(self, num=1):
for i in range(num):
region = GridScanRegion()
self.ui.regions_layout.addLayout(region.layout)
# Save it to the list
self.regions.append(region)

# the num of motor
num_motor_i = len(self.regions)
# region.motor_label.setText(str(num_motor_i)) # when using label
region.motor_label.display(num_motor_i)

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
return total_time_per_scan

def update_regions(self):
super().update_regions()

# disable snake for the last region and enable the previous regions
self.regions[-1].snake_checkbox.setEnabled(False)
for region_i in self.regions[:-1]:
region_i.snake_checkbox.setEnabled(True)

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()
)

# get snake axes, if all unchecked, set it None
snake_axes = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked that this actually works? According to the documentation:

The elements of the list are motors that are listed in args.

I read that to mean that the arguments should be the motors themselves, not their indices.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be discussed

region_i.motor_box.current_component().name
for i, region_i in enumerate(self.regions)
if region_i.snake_checkbox.isChecked()
]

if snake_axes == []:
snake_axes = False

if self.ui.relative_scan_checkbox.isChecked():
scan_type = "rel_grid_scan"
else:
scan_type = "grid_scan"

# # Build the queue item
item = BPlan(
scan_type,
detectors,
*motor_args,
num=num_points,
snake_axes=snake_axes,
md=md,
)

# Submit the item to the queueserver
app = FireflyApplication.instance()
log.info("Added line scan() plan to queue.")
# repeat scans
for i in range(repeat_scan_num):
app.add_queue_item(item)

def ui_filename(self):
return "plans/grid_scan.ui"
Loading
Loading