From 523117096d89921f3a6c778af0de62bb1ad6f9bf Mon Sep 17 00:00:00 2001 From: JeanBilheux Date: Fri, 30 Jun 2023 09:19:40 -0400 Subject: [PATCH] index of tof regions collected. this refs #70 --- src/hyperctui/__init__.py | 2 ++ .../event_handler.py | 7 ++++ .../select_tof_regions.py | 17 +++++++-- src/hyperctui/ui/main_application.ui | 36 ------------------- src/hyperctui/utilities/array.py | 6 ++++ 5 files changed, 29 insertions(+), 39 deletions(-) create mode 100644 src/hyperctui/utilities/array.py diff --git a/src/hyperctui/__init__.py b/src/hyperctui/__init__.py index d121e5d..74dc509 100644 --- a/src/hyperctui/__init__.py +++ b/src/hyperctui/__init__.py @@ -81,6 +81,8 @@ class EvaluationRegionKeys: id = "id of the pg horizontal line" name = 'name of the region' label_id = "id of the label naming the region" + from_index = "from file index" + to_index = "to file index" def load_ui(ui_filename, baseinstance): diff --git a/src/hyperctui/autonomous_reconstruction/event_handler.py b/src/hyperctui/autonomous_reconstruction/event_handler.py index ea72683..57bed4d 100644 --- a/src/hyperctui/autonomous_reconstruction/event_handler.py +++ b/src/hyperctui/autonomous_reconstruction/event_handler.py @@ -145,14 +145,21 @@ def init_autonomous_table(self): tof_regions = self.parent.tof_regions list_tof_region_collected = [] + list_tof_region_index = [] for _index in tof_regions.keys(): if tof_regions[_index][EvaluationRegionKeys.state]: _from = str(tof_regions[_index][EvaluationRegionKeys.from_value]).replace(".", "_") _to = str(tof_regions[_index][EvaluationRegionKeys.to_value]).replace(".", "_") + + _from_index = tof_regions[_index][EvaluationRegionKeys.from_index] + _to_index = tof_regions[_index][EvaluationRegionKeys.to_index] + list_tof_region_collected.append(f"from_{_from}Ang_to_{_to}Ang") + list_tof_region_index.append(f"from index: {_from_index} to index: {_to_index}") print(f"{formatted2_list_golden_ratio =}") print(f"{list_tof_region_collected =}") + print(f"{list_tof_region_index =}") def refresh_table_clicked(self): """refresh button next to the table has been clicked""" diff --git a/src/hyperctui/autonomous_reconstruction/select_tof_regions.py b/src/hyperctui/autonomous_reconstruction/select_tof_regions.py index 59e0e80..9b47bb0 100644 --- a/src/hyperctui/autonomous_reconstruction/select_tof_regions.py +++ b/src/hyperctui/autonomous_reconstruction/select_tof_regions.py @@ -12,6 +12,7 @@ from neutronbraggedge.experiment_handler.experiment import Experiment from hyperctui.utilities.table import TableHandler +from hyperctui.utilities.array import get_nearest_index from hyperctui import load_ui, EvaluationRegionKeys from hyperctui.session import SessionKeys from hyperctui.utilities.check import is_float, is_int @@ -190,18 +191,28 @@ def save_table(self): _name = o_table.get_item_str_from_cell(row=_row, column=ColumnIndex.name) _from = float(o_table.get_item_str_from_cell(row=_row, - column=ColumnIndex.from_value)) + column=ColumnIndex.from_value)) _to = float(o_table.get_item_str_from_cell(row=_row, - column=ColumnIndex.to_value)) + column=ColumnIndex.to_value)) _from, _to = self.sort(_from, _to) + _from_index = self.get_corresponding_index(lambda_value=_from, + lambda_array=self.lambda_array) + _to_index = self.get_corresponding_index(lambda_value=_to, + lambda_array=self.lambda_array) + tof_regions[_row] = {EvaluationRegionKeys.state: _state, EvaluationRegionKeys.name: _name, EvaluationRegionKeys.from_value: float(_from), EvaluationRegionKeys.to_value: float(_to), - EvaluationRegionKeys.id: None} + EvaluationRegionKeys.id: None, + EvaluationRegionKeys.from_index: _from_index, + EvaluationRegionKeys.to_index: _to_index} self.parent.tof_regions = tof_regions + def get_corresponding_index(self, lambda_value=None, lambda_array=None): + return get_nearest_index(lambda_array, lambda_value) + def check_table_content(self): """ make sure 'from' and 'to' values are int diff --git a/src/hyperctui/ui/main_application.ui b/src/hyperctui/ui/main_application.ui index 5d17b8e..4e25e10 100644 --- a/src/hyperctui/ui/main_application.ui +++ b/src/hyperctui/ui/main_application.ui @@ -1378,25 +1378,6 @@ - - - - - 50 - 0 - - - - - 100 - 16777215 - - - - Kill process - - - @@ -2572,22 +2553,6 @@ - - pushButton - clicked() - MainWindow - autonomous_reconstruction_stop_process_button_clicked() - - - 1026 - 444 - - - 1128 - 581 - - - step1_instrument_changed() @@ -2636,6 +2601,5 @@ action_step5_clicked() action_settings_clicked() refresh_list_of_obs_button_clicked() - autonomous_reconstruction_stop_process_button_clicked() diff --git a/src/hyperctui/utilities/array.py b/src/hyperctui/utilities/array.py new file mode 100644 index 0000000..8468a46 --- /dev/null +++ b/src/hyperctui/utilities/array.py @@ -0,0 +1,6 @@ +import numpy as np + + +def get_nearest_index(array, value): + idx = int((np.abs(np.array(array) - value)).argmin()) + return idx