Skip to content

Commit

Permalink
Merge branch 'main' into auto_shutter
Browse files Browse the repository at this point in the history
  • Loading branch information
canismarko committed Jan 12, 2025
2 parents 997cdd4 + 2645708 commit fcb2653
Show file tree
Hide file tree
Showing 34 changed files with 798 additions and 471 deletions.
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ dependencies:
- bluesky-queueserver-api
- bluesky-widgets
- bluesky-adaptive
- bluesky >=1.8.1
# - bluesky >=1.13.1
- git+https://github.com/bluesky/[email protected] # Replace with pypi version once released
- ophyd >=1.6.3
- ophyd-async >=0.9.0a1
- apstools == 1.6.20 # Leave at 1.6.20 until this is fixed: https://github.com/BCDA-APS/apstools/issues/1022
Expand Down
58 changes: 34 additions & 24 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ophyd import Kind
from ophyd.sim import instantiate_fake_device, make_fake_device
from tiled.adapters.mapping import MapAdapter
from tiled.adapters.xarray import DatasetAdapter
from tiled.adapters.table import TableAdapter
from tiled.client import Context, from_context
from tiled.server.app import build_app

Expand Down Expand Up @@ -246,10 +246,11 @@ async def filters(sim_registry):
run1 = pd.DataFrame(
{
"energy_energy": np.linspace(8300, 8400, num=100),
"energy_id_energy_readback": np.linspace(8.3, 8.4, num=100),
"It_net_counts": np.abs(np.sin(np.linspace(0, 4 * np.pi, num=100))),
"I0_net_counts": np.linspace(1, 2, num=100),
}
).to_xarray()
)

grid_scan = pd.DataFrame(
{
Expand All @@ -258,7 +259,7 @@ async def filters(sim_registry):
"aerotech_horiz": np.linspace(0, 104, num=105),
"aerotech_vert": np.linspace(0, 104, num=105),
}
).to_xarray()
)

hints = {
"energy": {"fields": ["energy_energy", "energy_id_energy_readback"]},
Expand All @@ -269,9 +270,13 @@ async def filters(sim_registry):
{
"primary": MapAdapter(
{
"data": DatasetAdapter.from_dataset(run1),
"internal": MapAdapter(
{
"events": TableAdapter.from_pandas(run1),
}
),
},
metadata={"descriptors": [{"hints": hints}]},
metadata={"hints": hints},
),
},
metadata={
Expand All @@ -287,42 +292,47 @@ async def filters(sim_registry):
{
"primary": MapAdapter(
{
"data": DatasetAdapter.from_dataset(run1),
"internal": MapAdapter(
{
"events": TableAdapter.from_pandas(run1),
}
),
},
metadata={"descriptors": [{"hints": hints}]},
metadata={"hints": hints},
),
},
metadata={
"plan_name": "rel_scan",
"start": {
"plan_name": "rel_scan",
"uid": "9d33bf66-9701-4ee3-90f4-3be730bc226c",
"hints": {"dimensions": [[["pitch2"], "primary"]]},
}
},
},
),
# 2D grid scan map data
"85573831-f4b4-4f64-b613-a6007bf03a8d": MapAdapter(
{
"primary": MapAdapter(
{
"data": DatasetAdapter.from_dataset(grid_scan),
"internal": MapAdapter(
{
"events": TableAdapter.from_pandas(grid_scan),
},
),
},
metadata={
"descriptors": [
{
"hints": {
"Ipreslit": {"fields": ["Ipreslit_net_counts"]},
"CdnIPreKb": {"fields": ["CdnIPreKb_net_counts"]},
"I0": {"fields": ["I0_net_counts"]},
"CdnIt": {"fields": ["CdnIt_net_counts"]},
"aerotech_vert": {"fields": ["aerotech_vert"]},
"aerotech_horiz": {"fields": ["aerotech_horiz"]},
"Ipre_KB": {"fields": ["Ipre_KB_net_counts"]},
"CdnI0": {"fields": ["CdnI0_net_counts"]},
"It": {"fields": ["It_net_counts"]},
}
}
]
"hints": {
"Ipreslit": {"fields": ["Ipreslit_net_counts"]},
"CdnIPreKb": {"fields": ["CdnIPreKb_net_counts"]},
"I0": {"fields": ["I0_net_counts"]},
"CdnIt": {"fields": ["CdnIt_net_counts"]},
"aerotech_vert": {"fields": ["aerotech_vert"]},
"aerotech_horiz": {"fields": ["aerotech_horiz"]},
"Ipre_KB": {"fields": ["Ipre_KB_net_counts"]},
"CdnI0": {"fields": ["CdnI0_net_counts"]},
"It": {"fields": ["It_net_counts"]},
},
},
),
},
Expand Down
59 changes: 46 additions & 13 deletions src/firefly/plans/grid_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def setup_ui(self):
"Motor",
"Start",
"Stop",
"Scan points",
"N. points",
"Size",
"Snake",
"Fly",
]
Expand All @@ -38,7 +39,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["N. points"].setFixedWidth(68)
Qlabels_all["Snake"].setFixedWidth(53)
Qlabels_all["Fly"].setFixedWidth(43)

Expand All @@ -52,48 +53,84 @@ class GridScanRegion(regions_display.RegionBase):
def setup_ui(self):
self.layout = QtWidgets.QHBoxLayout()

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

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

# Third item, start point
# 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
# 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, number of scan point
# 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
# Step size (non-editable)
self.step_size_line_edit = QtWidgets.QLineEdit()
self.step_size_line_edit.setReadOnly(True)
self.step_size_line_edit.setDisabled(True)
self.step_size_line_edit.setPlaceholderText("Step Size…")
self.layout.addWidget(self.step_size_line_edit)

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

# Seventh item, fly checkbox # not available right now
# 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)

# Connect signals
self.start_line_edit.textChanged.connect(self.update_step_size)
self.stop_line_edit.textChanged.connect(self.update_step_size)
self.scan_pts_spin_box.valueChanged.connect(self.update_step_size)

def update_step_size(self):
try:
# Get Start and Stop values
start_text = self.start_line_edit.text().strip()
stop_text = self.stop_line_edit.text().strip()
if not start_text or not stop_text:
self.step_size_line_edit.setText("N/A")
return

start = float(start_text)
stop = float(stop_text)

# Ensure num_points is an integer
num_points = int(self.scan_pts_spin_box.value()) # Corrected method call

# Calculate step size
if num_points > 1:
step_size = (stop - start) / (num_points - 1)
self.step_size_line_edit.setText(f"{step_size}")
else:
self.step_size_line_edit.setText("N/A")
except ValueError:
self.step_size_line_edit.setText("N/A")


class GridScanDisplay(regions_display.RegionsDisplay):
Region = GridScanRegion
Expand All @@ -108,10 +145,6 @@ def customize_ui(self):
# add title layout
self.title_region = TitleRegion()
self.ui.title_layout.addLayout(self.title_region.layout)
# When selections of detectors changed update_total_time
# self.ui.detectors_list.selectionModel().selectionChanged.connect(
# self.update_total_time
# )
self.ui.spinBox_repeat_scan_num.valueChanged.connect(self.update_total_time)
# Connect scan points change to update total time
for region in self.regions:
Expand Down
Loading

0 comments on commit fcb2653

Please sign in to comment.