Skip to content

Commit 23c827e

Browse files
Merge pull request #321 from neutrons/addie_several_updates
Multiple updates
2 parents a72b548 + 8770cb7 commit 23c827e

File tree

19 files changed

+448
-77
lines changed

19 files changed

+448
-77
lines changed

.github/workflows/actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
with:
2929
auto-update-conda: true
3030
python-version: ${{ matrix.python-version }}
31-
channels: marshallmcdonnell,conda-forge,mantid
31+
channels: marshallmcdonnell,conda-forge,mantid,neutrons
3232

3333
- name: Apt install deps
3434
run: sudo apt-get install xvfb freeglut3-dev libglu1-mesa

addie/autoNOM/make_exp_ini_file_and_run_autonom.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self, parent=None, folder=None):
2727
# self.parent = parent.ui
2828
self.parent = parent.autonom_ui
2929
self.folder = folder
30+
self.script_to_run = "python " + parent._autonom_script + " -l -P " + parent.idl_script_dir
3031

3132
def create(self):
3233
self.retrieve_metadata()
@@ -208,6 +209,7 @@ def run_auto_nom_script(self):
208209
_script_to_run = self.script_to_run + self.script_flag
209210
os.chdir(self.folder)
210211

212+
print("[LOG] " + _script_to_run)
211213
# o_gui = Step1GuiHandler(parent=self.parent_no_ui)
212214
o_gui = Step1GuiHandler(main_window=self.parent_no_ui)
213215
o_gui.set_main_window_title()

addie/autoNOM/run_step1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def create_auto_folder(self):
7373

7474
self._make_folder(_full_path)
7575
if self.run_autonom:
76-
self.parent.statusbar.showMessage("Created folder: " + _full_path + " and running autoNOM script !")
76+
self.parent_no_ui.ui.statusbar.showMessage("Created folder: " + _full_path + " and running autoNOM script !")
7777
else:
78-
self.parent.statusbar.showMessage("Created folder: " + _full_path)
78+
self.parent_no_ui.ui.statusbar.showMessage("Created folder: " + _full_path)
7979

8080
def retrieve_last_incremented_index(self, list_folder):
8181
_list_index = []

addie/calculate_gr/event_handler.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import addie.calculate_gr.edit_sq_dialog
88
from addie.calculate_gr.save_sq_dialog_message import SaveSqDialogMessageDialog
99
from addie.widgets.filedialog import get_save_file
10+
from mantid.api import AnalysisDataService
11+
import mantid.simpleapi as simpleapi
12+
from pystog import Transformer, FourierFilter
1013

1114

1215
def check_widgets_status(main_window, enable_gr_widgets=False):
@@ -217,6 +220,56 @@ def generate_gr_step2(main_window, sq_ws_name_list):
217220
max_q,
218221
pdf_filter,
219222
rho0)
223+
if main_window.calculategr_ui.ff_check.checkState() == 2:
224+
if rho0 is None:
225+
print("WARNING: rho0 is not a float. Necessary for applying meaningful Fourier filter.")
226+
return
227+
# Fourier filter
228+
out_ws_temp = AnalysisDataService.retrieve(sq_ws_name)
229+
out_ws_r_temp = AnalysisDataService.retrieve(gr_ws_name)
230+
r_in = out_ws_r_temp.readX(0)
231+
q_in = out_ws_temp.readX(0)
232+
sq_in = out_ws_temp.readY(0)
233+
transformer = Transformer()
234+
import pystog
235+
print("PYSTOG:", pystog.__file__)
236+
r_in, gr_in, dg_in = transformer.S_to_G(q_in, sq_in, r_in)
237+
ff = FourierFilter()
238+
r_cutoff_ff_text = main_window.calculategr_ui.lineEdit_rcutoff.text()
239+
try:
240+
r_cutoff_ff = float(r_cutoff_ff_text)
241+
except ValueError:
242+
print("WARNING: rcutoff is not a float. Necessary for applying Fourier filter.")
243+
return
244+
245+
q_ft, sq_ft, q_out, sq_out, r_out, gr_out, dsq_ft, dsq, dgr = ff.G_using_S(
246+
r_in,
247+
gr_in,
248+
q_in,
249+
sq_in,
250+
r_cutoff_ff,
251+
rho=rho0)
252+
253+
new_sq_wks = sq_ws_name + "_ff_rcutoff_" + r_cutoff_ff_text.replace(".", "p")
254+
simpleapi.CreateWorkspace(
255+
DataX=q_out,
256+
DataY=sq_out,
257+
OutputWorkspace=new_sq_wks,
258+
NSpec=1,
259+
unitX="MomentumTransfer")
260+
main_window.calculategr_ui.treeWidget_grWsList.add_sq(new_sq_wks)
261+
main_window.calculategr_ui.treeWidget_grWsList._workspaceNameList.append(new_sq_wks)
262+
plot_sq(main_window, new_sq_wks, color=None, clear_prev=False)
263+
gr_ws_name = main_window._myController.calculate_gr(
264+
new_sq_wks,
265+
pdf_type,
266+
min_r,
267+
delta_r,
268+
max_r,
269+
min_q,
270+
max_q,
271+
pdf_filter,
272+
rho0)
220273

221274
# check whether G(r) is in GofR plot to either update or add new plot
222275
update = main_window.calculategr_ui.graphicsView_gr.has_gr(gr_ws_name)

addie/initialization/events/postprocessing_tab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def run(main_window=None):
1515
main_window.postprocessing_ui.pushButton.clicked.connect(main_window.reset_q_range)
1616
main_window.postprocessing_ui.plazcek_fit_range_max.editingFinished.connect(main_window.check_plazcek_widgets)
1717
main_window.postprocessing_ui.plazcek_fit_range_min.editingFinished.connect(main_window.check_plazcek_widgets)
18-
main_window.postprocessing_ui.hydrogen_no.clicked.connect(main_window.no_hidrogen_clicked)
19-
main_window.postprocessing_ui.hydrogen_yes.clicked.connect(main_window.hidrogen_clicked)
18+
main_window.postprocessing_ui.hydrogen_no.clicked.connect(main_window.no_hydrogen_clicked)
19+
main_window.postprocessing_ui.hydrogen_yes.clicked.connect(main_window.hydrogen_clicked)
2020
main_window.postprocessing_ui.fourier_filter_from.editingFinished.connect(main_window.check_fourier_filter_widgets)
2121
main_window.postprocessing_ui.fourier_filter_to.editingFinished.connect(main_window.check_fourier_filter_widgets)
2222
main_window.postprocessing_ui.run_ndabs_output_file_name.textChanged['QString'].connect(

addie/main.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ class MainWindow(QMainWindow):
278278
global_key_value = {}
279279
align_and_focus_powder_from_files_blacklist = []
280280

281+
idl_modes = ("idl", "idl_dev")
282+
281283
def __init__(self, parent=None, processing_mode=None):
282284
""" Initialization
283285
Parameters
@@ -363,6 +365,16 @@ def __init__(self, parent=None, processing_mode=None):
363365
# color management
364366
self._pdfColorManager = PDFPlotManager()
365367

368+
# IDL config scripts
369+
idl_script_dir = "/SNS/NOM/shared/autoNOM/stable/"
370+
if self.post_processing == "idl_dev":
371+
idl_script_dir = "/SNS/NOM/shared/autoNOM/dev/"
372+
self.idl_script_dir = idl_script_dir
373+
self._autonom_script = os.path.join(idl_script_dir, "autoNOM.py")
374+
self._sum_scans_script = os.path.join(idl_script_dir, "sumscans.py")
375+
self._ndabs_script = os.path.join(idl_script_dir, "NDabs.py")
376+
self._is_sum_scans_python_checked = False
377+
366378
# Connecting all the widgets
367379
main_tab_events_handler.run(main_window=self)
368380
autonom_tab_events_handler.run(main_window=self)
@@ -581,13 +593,13 @@ def check_q_range(self):
581593
_o_gui = Step2GuiHandler(main_window=self)
582594
_o_gui.check_gui()
583595

584-
def hidrogen_clicked(self):
596+
def hydrogen_clicked(self):
585597
o_gui = Step2GuiHandler(main_window=self)
586-
o_gui.hidrogen_clicked()
598+
o_gui.hydrogen_clicked()
587599

588-
def no_hidrogen_clicked(self):
600+
def no_hydrogen_clicked(self):
589601
o_gui = Step2GuiHandler(main_window=self)
590-
o_gui.no_hidrogen_clicked()
602+
o_gui.no_hydrogen_clicked()
591603

592604
def yes_background_clicked(self):
593605
o_gui = Step2GuiHandler(main_window=self)
@@ -996,7 +1008,8 @@ def main(config=None):
9961008
help='Set processing mode (default=%(default)s)',
9971009
choices=[
9981010
'mantid',
999-
'idl'])
1011+
'idl',
1012+
'idl_dev'])
10001013

10011014
try: # set up bash completion as a soft dependency
10021015
import argcomplete # noqa

addie/menu/event_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def help_about_clicked(main_window):
5454

5555

5656
def activate_reduction_tabs(main_window):
57-
if main_window.post_processing == 'idl':
57+
if main_window.post_processing in main_window.idl_modes:
5858
tab_0 = True
5959
tab_1 = True
6060
tab_2 = False

addie/menu/file/settings/advanced_file_window.py

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ def __init__(self, parent=None):
3333
def init_widgets(self):
3434
_idl_status = False
3535
_mantid_status = False
36-
if self.parent.post_processing == 'idl':
36+
if self.parent.post_processing in self.parent.idl_modes:
3737
_idl_status = True
3838
else:
3939
_mantid_status = True
4040

41-
self.ui.idl_groupbox.setVisible(self.parent.advanced_window_idl_groupbox_visible)
41+
self.ui.idl_config_group_box.setVisible(self.parent.advanced_window_idl_groupbox_visible)
4242

4343
self.ui.idl_post_processing_button.setChecked(_idl_status)
4444
self.ui.mantid_post_processing_button.setChecked(_mantid_status)
45+
# When 'idl' or 'idl_dev' model is enabled from CLI, this should enable
46+
# the setting box, etc. by default without the need for explicitly
47+
# clicking on the 'IDL' radio button.
48+
self.post_processing_clicked()
4549

4650
instrument = self.parent.instrument["full_name"]
4751
list_instrument_full_name = self.parent.list_instrument["full_name"]
@@ -58,6 +62,12 @@ def init_widgets(self):
5862
self.ui.cache_dir_label.setText(self.parent.cache_folder)
5963
self.ui.output_dir_label.setText(self.parent.output_folder)
6064

65+
# IDL config
66+
self.ui.autonom_path_line_edit.setText(self.parent._autonom_script)
67+
self.ui.sum_scans_path_line_edit.setText(self.parent._sum_scans_script)
68+
self.ui.ndabs_path_line_edit.setText(self.parent._ndabs_script)
69+
self.ui.idl_config_browse_button_dialog = None
70+
6171
self.ui.centralwidget.setContentsMargins(10, 10, 10, 10)
6272

6373
def is_idl_selected(self):
@@ -71,7 +81,7 @@ def post_processing_clicked(self):
7181
_post = 'mantid'
7282
_idl_groupbox_visible = False
7383

74-
self.ui.idl_groupbox.setVisible(_idl_groupbox_visible)
84+
self.ui.idl_config_group_box.setVisible(_idl_groupbox_visible)
7585
self.parent.post_processing = _post
7686
self.parent.activate_reduction_tabs() # hide or show right tabs
7787
self.parent.advanced_window_idl_groupbox_visible = _idl_groupbox_visible
@@ -97,5 +107,71 @@ def output_dir_button_clicked(self):
97107
self.ui.output_dir_label.setText(str(_output_folder))
98108
self.parent.output_folder = str(_output_folder)
99109

110+
# IDL Config - Line Edits
111+
def autonom_path_line_edited(self):
112+
""" update autonom script in top-level after line editing """
113+
_script = str(self.ui.autonom_path_line_edit.text())
114+
self.parent._autonom_script = _script
115+
116+
def sum_scans_path_line_edited(self):
117+
""" update sum scans script in top-level after line editing """
118+
_script = str(self.ui.sum_scans_path_line_edit.text())
119+
self.parent._sum_scans_script = _script
120+
121+
def ndabs_path_line_edited(self):
122+
""" update ndabs script in top-level after line editing """
123+
_script = str(self.ui.ndabs_path_line_edit.text())
124+
self.parent._ndabs_script = _script
125+
126+
# IDL Config - Browse Buttons
127+
def _idl_button_clicked(self, line_edit):
128+
""" Utility function to handle IDL script path browse buttons """
129+
130+
# Initialize with current script in line edit
131+
script = str(line_edit.text())
132+
133+
# Get current working directory to open file dialog in
134+
_current_folder = self.parent.current_folder
135+
136+
# Launch file dialog
137+
self.ui.idl_config_browse_button_dialog = QFileDialog(
138+
parent=self.ui,
139+
directory=_current_folder,
140+
caption="Select File",
141+
filter=("Python (*.py);; All Files (*.*)"))
142+
143+
# Handle if we select a file or cancel
144+
if self.ui.idl_config_browse_button_dialog.exec_():
145+
files = self.ui.idl_config_browse_button_dialog.selectedFiles()
146+
147+
if files[0] != '':
148+
script = str(files[0])
149+
line_edit.setText(script)
150+
151+
# Set the class attribute back to None for monitoring / testing
152+
self.ui.idl_config_browse_button_dialog = None
153+
154+
return script
155+
156+
def autonom_path_browse_button_clicked(self):
157+
""" Handle browse button clicked for autonom script path """
158+
line_edit = self.ui.autonom_path_line_edit
159+
self.parent._autonom_script = self._idl_button_clicked(line_edit)
160+
161+
def sum_scans_path_browse_button_clicked(self):
162+
""" Handle browse button clicked for sum scans script path """
163+
line_edit = self.ui.sum_scans_path_line_edit
164+
self.parent._sum_scans_script = self._idl_button_clicked(line_edit)
165+
166+
def ndabs_path_browse_button_clicked(self):
167+
""" Handle browse button clicked for ndabs script path """
168+
line_edit = self.ui.ndabs_path_line_edit
169+
self.parent._ndabs_script = self._idl_button_clicked(line_edit)
170+
171+
def sum_scans_python_version_checkbox_toggled(self):
172+
""" Handle the sum scans checkbox for using the python version """
173+
_is_checked = self.ui.sum_scans_python_version_checkbox.isChecked()
174+
self.parent._is_sum_scans_python_checked = _is_checked
175+
100176
def closeEvent(self, c):
101177
self.parent.advanced_window_ui = None

addie/processing/idl/run_sum_scans.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66

77
class RunSumScans(object):
88

9-
script = 'python /SNS/NOM/shared/autoNOM/stable/sumscans.py '
109
output_file = ''
1110

1211
def __init__(self, parent=None):
1312
self.parent = parent.ui.postprocessing_ui
1413
self.parent_no_ui = parent
14+
self.o_gui_handler = Step2GuiHandler(main_window=self.parent_no_ui)
1515
self.folder = os.getcwd()
16+
self.set_sum_scans_script()
17+
18+
def set_sum_scans_script(self):
19+
self.script_path = self.o_gui_handler.get_sum_scans_script()
20+
self.script = 'python ' + self.script_path
21+
print("SumScans: ", self.script)
1622

1723
def run(self):
1824
self._background = self.collect_background_runs()
@@ -30,12 +36,13 @@ def run_script(self):
3036
print("[LOG] " + _script_to_run)
3137

3238
def add_script_flags(self):
39+
self.set_sum_scans_script()
3340
_script = self.script
3441

3542
if not self.parent.interactive_mode_checkbox.isChecked():
36-
_script += "-n True"
37-
if self.parent.pytest.isChecked():
38-
_script += "-u True"
43+
_script += " -n True "
44+
if self.parent_no_ui._is_sum_scans_python_checked:
45+
_script += " -u True "
3946

4047
qmax_list = str(self.parent.pdf_qmax_line_edit.text()).strip()
4148
if not (qmax_list == ""):
@@ -45,9 +52,9 @@ def add_script_flags(self):
4552

4653
def create_output_file(self):
4754
_output_file_name = "sum_" + self.parent.sum_scans_output_file_name.text() + ".inp"
48-
# print("_output_file_name: {}".format(_output_file_name))
55+
# print("_output_file_name: {}".format(_output_file_name))
4956
_full_output_file_name = os.path.join(self.folder, _output_file_name)
50-
# print("_full_output_file_name: {}".format(_full_output_file_name))
57+
# print("_full_output_file_name: {}".format(_full_output_file_name))
5158
self.full_output_file_name = _full_output_file_name
5259

5360
f = open(_full_output_file_name, 'w')
@@ -61,7 +68,7 @@ def create_output_file(self):
6168

6269
# hydrogen flag
6370
plattype_flag = 0
64-
if o_gui_handler.is_hidrogen_clicked():
71+
if o_gui_handler.is_hydrogen_clicked():
6572
plattype_flag = 2
6673
f.write("platype {}\n".format(plattype_flag))
6774

addie/processing/idl/step2_gui_handler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ def move_to_folder(self):
3434
self.main_window.current_folder = _new_folder
3535
self.main_window.setWindowTitle(_new_folder)
3636

37-
def is_hidrogen_clicked(self):
37+
def is_hydrogen_clicked(self):
3838
return self.main_window.postprocessing_ui.hydrogen_yes.isChecked()
3939

40-
def hidrogen_clicked(self):
40+
def hydrogen_clicked(self):
4141
_range = self.hidrogen_range
4242
self.populate_hidrogen_range(_range)
4343

44-
def no_hidrogen_clicked(self):
44+
def no_hydrogen_clicked(self):
4545
_range = self.no_hidrogen_range
4646
self.populate_hidrogen_range(_range)
4747

@@ -113,6 +113,9 @@ def define_new_output_file_name(self):
113113
_output_file_name = self.default_ndabs_output_file_name
114114
return _output_file_name
115115

116+
def get_sum_scans_script(self):
117+
return self.main_window._sum_scans_script
118+
116119
def check_import_export_buttons(self):
117120
_export_status = False
118121
if self.main_window.postprocessing_ui.table.rowCount() > 0:

0 commit comments

Comments
 (0)