1 parent
6ad841e5bc
commit
b8f7dabd47
2 files changed
+57
-7
No files matched your search
@@ -53,7 +53,7 @@ def plot_live_data(
|
||||
wf.plot(device_x=motor_name, device_y=signal_name)
|
||||
|
||||
|
||||
def plot_fitted_data(data, fit_result, window_name="Fitting", plot_widget=None):
|
||||
def plot_fitted_data(data, fit_result, window_name="Fitting", plot_widget=None, title=None):
|
||||
"""
|
||||
Plot completed scan data and its fitted curve in BEC.
|
||||
|
||||
@@ -93,3 +93,35 @@ def plot_fitted_data(data, fit_result, window_name="Fitting", plot_widget=None):
|
||||
|
||||
# Display the fitted curve as a line without symbols.
|
||||
wf.get_curve("Fit").set(symbol_size=0)
|
||||
|
||||
def plot_scan_data(
|
||||
data,
|
||||
window_name="Fitting",
|
||||
plot_widget=None,
|
||||
title=None,
|
||||
):
|
||||
"""Plot completed scan data without a fitted curve."""
|
||||
|
||||
if isinstance(plot_widget, str):
|
||||
dock_area = bec.gui.windows[window_name]
|
||||
wf = getattr(dock_area, plot_widget)
|
||||
|
||||
elif plot_widget is not None:
|
||||
wf = plot_widget
|
||||
|
||||
else:
|
||||
wf, text_widget = select_bec_window(window_name)
|
||||
text_widget.set_plain_text("Fit rejected")
|
||||
|
||||
# Clear the live plot/subscription
|
||||
wf.clear_all()
|
||||
|
||||
wf.title = title or f"Scan: {data['scan_number']}"
|
||||
wf.x_label = data["motor_name"]
|
||||
wf.y_label = data["signal_name"]
|
||||
|
||||
wf.plot(
|
||||
x=data["x_data"],
|
||||
y=data["y_data"],
|
||||
label="Data",
|
||||
)
|
||||
@@ -57,7 +57,7 @@ def calculate_step_size(start: float, stop: float, steps: int) -> float:
|
||||
return round((stop - start) / (steps - 1), 5)
|
||||
|
||||
|
||||
def move_to_position(motor_device, motor_name: str, position: float, data: dict):
|
||||
def move_to_scan_position(motor_device, motor_name: str, position: float, data: dict):
|
||||
"""
|
||||
Function to move a specified motor device to a given position.
|
||||
|
||||
@@ -100,6 +100,9 @@ def move_to_position(motor_device, motor_name: str, position: float, data: dict)
|
||||
scans.umv(motor_device, motor_position, relative=False)
|
||||
print(f"\n Moving {motor_name} to position {motor_position: .3f}")
|
||||
|
||||
def restore_position(motor_device, position):
|
||||
"""Return a motor to its position before the scan."""
|
||||
scans.umv(motor_device, position, relative=False)
|
||||
|
||||
def go_to_peak(
|
||||
motor_device,
|
||||
@@ -218,10 +221,25 @@ def go_to_peak(
|
||||
print("Peak fit rejected:")
|
||||
for problem in check["problems"]:
|
||||
print(f" - {problem}")
|
||||
print(f"Returning {motor_name} to starting position " f"{starting_position:.4f}")
|
||||
scans.umv(motor_device, starting_position, relative=False)
|
||||
|
||||
if plot:
|
||||
plot_scan_data(
|
||||
data,
|
||||
window_name=window_name,
|
||||
plot_widget=plot_widget,
|
||||
title=f"{motor_name} scan - FIT REJECTED",
|
||||
)
|
||||
print(f"Returning motor to start position, {starting_position:.5g}")
|
||||
restore_position(
|
||||
motor_device,
|
||||
starting_position,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
# Plot the fitted data if plot = True
|
||||
if plot:
|
||||
plot_fitted_data(data, fit_result, window_name=window_name, plot_widget=plot_widget)
|
||||
@@ -230,18 +248,18 @@ def go_to_peak(
|
||||
if gomax:
|
||||
value = fit_result["x_max"]
|
||||
print(f"Max position is at {value}")
|
||||
move_to_position(data["motor_device"], data["motor_name"], fit_result["x_max"], data)
|
||||
move_scan_to_position(data["motor_device"], data["motor_name"], fit_result["x_max"], data)
|
||||
else:
|
||||
if gap:
|
||||
if fit_result["centre"] < 4.5:
|
||||
umv(dev.id_gap, 4.5)
|
||||
else:
|
||||
move_to_position(
|
||||
move_to_scan_position(
|
||||
data["motor_device"], data["motor_name"], fit_result["centre"], data
|
||||
)
|
||||
else:
|
||||
# Safely move the motor to the peak position
|
||||
move_to_position(data["motor_device"], data["motor_name"], fit_result["centre"], data)
|
||||
move_to_scan_position(data["motor_device"], data["motor_name"], fit_result["centre"], data)
|
||||
|
||||
return {
|
||||
"centre": fit_result["centre"],
|
||||
|
||||
Reference in new issue
Block a user