Skip to content

Commit 0ab37fb

Browse files
authored
Merge pull request #93 from DiamondLightSource/fix-misc-issues
- Fix broken offset plot - Fix enabling of FOFB - Improve "run topup?" question text - Save offsets plot after each bba run as intended - Fix GUI buttons to enable/disable saving of plots/rawdata/results - Fix the ability to change the save location from the GUI - Tidying of various bits of relevant code
2 parents 107212f + 8e0cf5f commit 0ab37fb

8 files changed

Lines changed: 46 additions & 36 deletions

File tree

src/dls_bba/algorithm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ def use_bba_offsets(
193193
question_callback: The question function for the console or gui.
194194
"""
195195
offsets_dict = self.reformat_and_save_offsets(results_list, save_location)
196-
bba_offsets_plot(self._machine, offsets_dict, save_location)
196+
bba_offsets_plot(
197+
self._machine,
198+
offsets_dict,
199+
save_location,
200+
self._machine.config["SAVE_PLOTS"],
201+
)
197202
if question_callback("Apply these BBA offsets? (y / n) :"):
198203
self.apply_bba_offsets(offsets_dict)
199204
self._machine.apply_feedbacks()

src/dls_bba/beam_current.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def topup_beam(self, minimum_topup: float) -> None:
7676
while True:
7777
log.error(f"Please topup current to > {minimum_topup}mA.")
7878
response = self.question_callback(
79-
"Input y to continue after topup, or n to cancel:"
79+
"Beam current dropped, please topup. Input y to continue after topup, "
80+
"or n to cancel:"
8081
)
8182

8283
if response:

src/dls_bba/defaults.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"CRITICAL_CURRENT_DROP": 100,
99
"SOFB_RUN_TIME": 10,
1010
"FEEDBACK_WAIT_TIME": 3,
11-
"FEEDBACK_RUN_TIME": 3,
11+
"FOFB_RUN_TIME": 3,
1212
"MAX_ORBIT_CORRECTION_MICRONS": 7.5,
1313
"MIN_SLOPE_FRACTION": 0.25,
1414
"MIN_CURRENT": 295,

src/dls_bba/fbba_gui.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@
891891
<string>Feedbacks Wait time [s]</string>
892892
</property>
893893
</widget>
894-
<widget class="QDoubleSpinBox" name="config_run_time">
894+
<widget class="QDoubleSpinBox" name="config_fofb_run_time">
895895
<property name="geometry">
896896
<rect>
897897
<x>10</x>

src/dls_bba/gui.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class MainWindow(QMainWindow):
226226
config_quad_step: QDoubleSpinBox
227227
config_warning_current: QDoubleSpinBox
228228
config_sofb_run_time: QDoubleSpinBox
229-
config_run_time: QDoubleSpinBox
229+
config_fofb_run_time: QDoubleSpinBox
230230
config_wait_time: QDoubleSpinBox
231231
config_sbba_min_frac: QDoubleSpinBox
232232
config_sbba_stdev: QDoubleSpinBox
@@ -288,7 +288,6 @@ def __init__(self, *args, **kwargs) -> None:
288288
self.selection_strings: list[str] | None = None
289289
self.selected: list[str] | str | None = None
290290
self.loadfolder: str | None = None
291-
self.savepath: str | None = None
292291
self.loadfile: str | None = None
293292
self.selected_toggle: int = 0
294293
self.tmp_single_filepath: str | None = None
@@ -476,14 +475,17 @@ def create_worker(self) -> Worker:
476475
if isinstance(self.selected, str):
477476
self.selected = [self.selected]
478477
assert isinstance(self.selected, list) and isinstance(self.selected[0], str)
478+
479+
latest_config = self.get_config_from_gui()
480+
479481
return Worker(
480482
method,
481483
self.selected,
482484
self.create_question_box,
483485
machine=self.machine,
484-
folder_path=self.machine.config["SAVE_LOCATION"],
486+
folder_path=latest_config["SAVE_LOCATION"],
485487
logger=self.logger,
486-
additional_options=self.get_config_from_gui(),
488+
additional_options=latest_config,
487489
)
488490

489491
def reset_iocs(self) -> None:
@@ -551,8 +553,6 @@ def load_config_file(self) -> None:
551553
list_file = [file[0]]
552554
self.machine.update_config(extra_config_files=list_file)
553555
self.show_config()
554-
# Allow for lattice reload.
555-
cothread.Yield() # TODO: Why does this need to yield?
556556
self.display_config_load.setText(f"Config File Applied at {get_isotime()}")
557557

558558
def get_ringmode_options(self) -> list[str]:
@@ -574,36 +574,41 @@ def get_config_from_gui(self) -> dict[str, Any]:
574574
A dictionary of the new config.
575575
"""
576576
config_dict = {
577-
"SAVE_LOCATION": self.display_save_loc.toPlainText(),
577+
# Main Page
578578
"USE_FEEDBACKS": self.config_use_feedbacks.isChecked(),
579579
"FOFB_FEEDBACKS": self.config_use_fofb.isChecked(),
580580
"MAX_ORBIT_CORRECTION_MICRONS": self.config_max_orbit.value(),
581581
"MIN_CURRENT": self.config_current_limit.value(),
582+
## Additional Options and Plotting#
583+
# General Options
582584
"CORRECTOR_KICK_RADIANS": self.config_corr_kick.value() / RAD_TO_URAD_CONV,
583585
"QUADRUPOLE_STEP_PERCENT": self.config_quad_step.value(),
584586
"WARNING_CURRENT_DROP": self.config_warning_current.value(),
585-
"FEEDBACK_WAIT_TIME": self.config_wait_time.value(),
586-
"FEEDBACK_RUN_TIME": self.config_run_time.value(),
587587
"SOFB_RUN_TIME": self.config_sofb_run_time.value(),
588-
"MIN_SLOPE_FRACTION": self.config_sbba_min_frac.value(),
589-
"CENTER_OUTLIER_FACTOR": self.config_sbba_stdev.value(),
590-
"OUTLIER_FACTOR": self.config_sbba_fit_diff.value(),
588+
"FOFB_RUN_TIME": self.config_fofb_run_time.value(),
589+
"FEEDBACK_WAIT_TIME": self.config_wait_time.value(),
591590
"DECIMATED": self.config_use_decimation.isChecked(),
592591
"X_CYCLES": self.config_x_cycles.value(),
593592
"X_FREQUENCY": self.config_x_freq.value(),
594593
"Y_CYCLES": self.config_y_cycles.value(),
595594
"Y_FREQUENCY": self.config_y_freq.value(),
595+
"RESELECTION_LIMIT": self.config_reselection.value(),
596596
"SAVE_RAWDATA": self.save_rawdata.isChecked(),
597597
"SAVE_RESULTS": self.save_results.isChecked(),
598598
"SAVE_PLOTS": self.save_plots.isChecked(),
599-
"RESELECTION_LIMIT": self.config_reselection.value(),
599+
# Advanced Options
600600
"RINGMODE": self.config_ringmode.currentText(),
601601
"COTHREAD_CONTROL_SYSTEM_TIMEOUT": self.config_ccs_timeout.value(),
602602
"COTHREAD_CONTROL_SYSTEM_WAIT_FLAG": self.config_ccs_wait.isChecked(),
603-
"FOFB_EXECUTABLE_PATH": self.config_fofb_executable_path.toPlainText(),
603+
"MIN_SLOPE_FRACTION": self.config_sbba_min_frac.value(),
604+
"OUTLIER_FACTOR": self.config_sbba_fit_diff.value(),
605+
"CENTER_OUTLIER_FACTOR": self.config_sbba_stdev.value(),
604606
"FOFB_MAX_ORBIT_MICRONS": self.config_fofb_max_orbit.value(),
605607
"ORBIT_RESPONSE_MATRIX_PATH": self.config_orm_path.toPlainText(),
606608
"CORRECTORS_TXT_PATH": self.config_corrector_txt_path.toPlainText(),
609+
"FOFB_EXECUTABLE_PATH": self.config_fofb_executable_path.toPlainText(),
610+
# Save Location and Config
611+
"SAVE_LOCATION": self.display_save_loc.toPlainText(),
607612
}
608613
return config_dict
609614

@@ -629,7 +634,7 @@ def show_config(self) -> None:
629634
self.config_quad_step.setValue(config["QUADRUPOLE_STEP_PERCENT"])
630635
self.config_warning_current.setValue(config["WARNING_CURRENT_DROP"])
631636
self.config_wait_time.setValue(config["FEEDBACK_WAIT_TIME"])
632-
self.config_run_time.setValue(config["FEEDBACK_RUN_TIME"])
637+
self.config_fofb_run_time.setValue(config["FOFB_RUN_TIME"])
633638
self.config_sofb_run_time.setValue(config["SOFB_RUN_TIME"])
634639
self.config_sbba_min_frac.setValue(config["MIN_SLOPE_FRACTION"])
635640
self.config_sbba_stdev.setValue(config["CENTER_OUTLIER_FACTOR"])
@@ -703,11 +708,9 @@ def select_save_location_folder(self) -> None:
703708
self, "Select Folder to Save to", self.machine.config["SAVE_LOCATION"]
704709
)
705710
if folderpath == "":
706-
self.display_save_loc.clear()
707-
self.display_save_loc.setPlainText(self.machine.config["SAVE_LOCATION"])
708-
else:
709-
self.display_save_loc.setPlainText(folderpath)
710-
self.savepath = folderpath
711+
folderpath = self.machine.config["SAVE_LOCATION"]
712+
713+
self.display_save_loc.setPlainText(folderpath)
711714

712715
def select_bba_folder(self) -> None:
713716
"""Select a folder of old data to load."""

src/dls_bba/machine.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ def max_orbit_too_big_for_fofb(self) -> None:
503503
"""Check if the maximum orbit is too large for FOFB and run SOFB if so."""
504504
fofb_max_orbit = self.config["FOFB_MAX_ORBIT_MICRONS"]
505505
max_value = self.get_largest_orbit()
506-
while max_value >= fofb_max_orbit:
507-
log.error("Orbit is too large for FOFB. Running SOFB.")
506+
while max_value > fofb_max_orbit:
507+
log.warning("Orbit is too large for FOFB. Running SOFB.")
508508
self.run_sofb()
509509
max_value = self.get_largest_orbit()
510510

@@ -524,9 +524,9 @@ def run_sofb(self) -> None:
524524
def run_fofb(self) -> None:
525525
"""Run FOFB and Tune feedbacks."""
526526
tune_trigger = self.config["FEEDBACK_PVS"]["Tune_Feedback"]
527-
fofb_trigger = self.config["FOFB_NOGUI_PATH"]
527+
fofb_trigger = self.config["FOFB_EXECUTABLE_PATH"]
528528
wait_time = self.config["FEEDBACK_WAIT_TIME"]
529-
run_time = self.config["FEEDBACK_RUN_TIME"]
529+
run_time = self.config["FOFB_RUN_TIME"]
530530
run(f"{fofb_trigger} start", check=True, shell=True)
531531
caput(tune_trigger, 1, wait=True)
532532

src/dls_bba/plotting.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ def bba_offsets_plot(
5858
Returns:
5959
The figure object.
6060
"""
61-
x = np.arange(1, len(machine.bba_x_pvs) + 1)
61+
x = np.arange(1, len(machine.bpms_names) + 1)
6262
change_in_x = []
6363
change_in_dx = []
64-
for bpm_name in machine.bba_x_pvs:
65-
if bpm_name.replace("-", "_").replace(":", "__") in offsets_dict.keys():
66-
calc_offsets = offsets_dict[bpm_name.replace("-", "_").replace(":", "__")].x
64+
for bpm_name in machine.bpms_names:
65+
if bpm_name in offsets_dict.keys():
66+
calc_offsets = offsets_dict[bpm_name].x
6767
change_in_x.append(calc_offsets.diff_value * MM_TO_UM_UNIT_CONV) # type: ignore
6868
change_in_dx.append(abs(calc_offsets.diff_value * MM_TO_UM_UNIT_CONV)) # type: ignore
6969
else:
@@ -72,14 +72,15 @@ def bba_offsets_plot(
7272

7373
change_in_y = []
7474
change_in_dy = []
75-
for bpm_name in machine.bba_y_pvs:
76-
if bpm_name.replace("-", "_").replace(":", "__") in offsets_dict.keys():
77-
calc_offsets = offsets_dict[bpm_name.replace("-", "_").replace(":", "__")].y
75+
for bpm_name in machine.bpms_names:
76+
if bpm_name in offsets_dict.keys():
77+
calc_offsets = offsets_dict[bpm_name].y
7878
change_in_y.append(calc_offsets.diff_value * MM_TO_UM_UNIT_CONV) # type: ignore
7979
change_in_dy.append(abs(calc_offsets.diff_value * MM_TO_UM_UNIT_CONV)) # type: ignore
8080
else:
8181
change_in_y.append(0)
8282
change_in_dy.append(0)
83+
8384
fig, (ax1, ax2) = plt.subplots(2, sharex=True, tight_layout=True)
8485
fig.suptitle("Change in BBA values")
8586
ax1.set_xlim(0, 174)

src/dls_bba/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def work(self) -> float:
9595
break
9696

9797
if rawdata is not None:
98-
if self.save_rawdata is not None:
98+
if self.save_rawdata:
9999
rawdata.save(self.save_location)
100100

101101
results = self.algorithm.analyse(rawdata)

0 commit comments

Comments
 (0)