Skip to content

Commit

Permalink
index of tof regions collected. this refs #70
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBilheux committed Jun 30, 2023
1 parent 8aacdb1 commit 5231170
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 deletions.
2 changes: 2 additions & 0 deletions src/hyperctui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions src/hyperctui/autonomous_reconstruction/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
17 changes: 14 additions & 3 deletions src/hyperctui/autonomous_reconstruction/select_tof_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 0 additions & 36 deletions src/hyperctui/ui/main_application.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1378,25 +1378,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Kill process</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -2572,22 +2553,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>autonomous_reconstruction_stop_process_button_clicked()</slot>
<hints>
<hint type="sourcelabel">
<x>1026</x>
<y>444</y>
</hint>
<hint type="destinationlabel">
<x>1128</x>
<y>581</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>step1_instrument_changed()</slot>
Expand Down Expand Up @@ -2636,6 +2601,5 @@
<slot>action_step5_clicked()</slot>
<slot>action_settings_clicked()</slot>
<slot>refresh_list_of_obs_button_clicked()</slot>
<slot>autonomous_reconstruction_stop_process_button_clicked()</slot>
</slots>
</ui>
6 changes: 6 additions & 0 deletions src/hyperctui/utilities/array.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5231170

Please sign in to comment.