Skip to content

Commit

Permalink
Merge pull request #321 from neutrons/addie_several_updates
Browse files Browse the repository at this point in the history
Multiple updates
  • Loading branch information
marshallmcdonnell committed Jan 16, 2021
2 parents a72b548 + 8770cb7 commit 23c827e
Show file tree
Hide file tree
Showing 19 changed files with 448 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
channels: marshallmcdonnell,conda-forge,mantid
channels: marshallmcdonnell,conda-forge,mantid,neutrons

- name: Apt install deps
run: sudo apt-get install xvfb freeglut3-dev libglu1-mesa
Expand Down
2 changes: 2 additions & 0 deletions addie/autoNOM/make_exp_ini_file_and_run_autonom.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, parent=None, folder=None):
# self.parent = parent.ui
self.parent = parent.autonom_ui
self.folder = folder
self.script_to_run = "python " + parent._autonom_script + " -l -P " + parent.idl_script_dir

def create(self):
self.retrieve_metadata()
Expand Down Expand Up @@ -208,6 +209,7 @@ def run_auto_nom_script(self):
_script_to_run = self.script_to_run + self.script_flag
os.chdir(self.folder)

print("[LOG] " + _script_to_run)
# o_gui = Step1GuiHandler(parent=self.parent_no_ui)
o_gui = Step1GuiHandler(main_window=self.parent_no_ui)
o_gui.set_main_window_title()
Expand Down
4 changes: 2 additions & 2 deletions addie/autoNOM/run_step1.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def create_auto_folder(self):

self._make_folder(_full_path)
if self.run_autonom:
self.parent.statusbar.showMessage("Created folder: " + _full_path + " and running autoNOM script !")
self.parent_no_ui.ui.statusbar.showMessage("Created folder: " + _full_path + " and running autoNOM script !")
else:
self.parent.statusbar.showMessage("Created folder: " + _full_path)
self.parent_no_ui.ui.statusbar.showMessage("Created folder: " + _full_path)

def retrieve_last_incremented_index(self, list_folder):
_list_index = []
Expand Down
53 changes: 53 additions & 0 deletions addie/calculate_gr/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import addie.calculate_gr.edit_sq_dialog
from addie.calculate_gr.save_sq_dialog_message import SaveSqDialogMessageDialog
from addie.widgets.filedialog import get_save_file
from mantid.api import AnalysisDataService
import mantid.simpleapi as simpleapi
from pystog import Transformer, FourierFilter


def check_widgets_status(main_window, enable_gr_widgets=False):
Expand Down Expand Up @@ -217,6 +220,56 @@ def generate_gr_step2(main_window, sq_ws_name_list):
max_q,
pdf_filter,
rho0)
if main_window.calculategr_ui.ff_check.checkState() == 2:
if rho0 is None:
print("WARNING: rho0 is not a float. Necessary for applying meaningful Fourier filter.")
return
# Fourier filter
out_ws_temp = AnalysisDataService.retrieve(sq_ws_name)
out_ws_r_temp = AnalysisDataService.retrieve(gr_ws_name)
r_in = out_ws_r_temp.readX(0)
q_in = out_ws_temp.readX(0)
sq_in = out_ws_temp.readY(0)
transformer = Transformer()
import pystog
print("PYSTOG:", pystog.__file__)
r_in, gr_in, dg_in = transformer.S_to_G(q_in, sq_in, r_in)
ff = FourierFilter()
r_cutoff_ff_text = main_window.calculategr_ui.lineEdit_rcutoff.text()
try:
r_cutoff_ff = float(r_cutoff_ff_text)
except ValueError:
print("WARNING: rcutoff is not a float. Necessary for applying Fourier filter.")
return

q_ft, sq_ft, q_out, sq_out, r_out, gr_out, dsq_ft, dsq, dgr = ff.G_using_S(
r_in,
gr_in,
q_in,
sq_in,
r_cutoff_ff,
rho=rho0)

new_sq_wks = sq_ws_name + "_ff_rcutoff_" + r_cutoff_ff_text.replace(".", "p")
simpleapi.CreateWorkspace(
DataX=q_out,
DataY=sq_out,
OutputWorkspace=new_sq_wks,
NSpec=1,
unitX="MomentumTransfer")
main_window.calculategr_ui.treeWidget_grWsList.add_sq(new_sq_wks)
main_window.calculategr_ui.treeWidget_grWsList._workspaceNameList.append(new_sq_wks)
plot_sq(main_window, new_sq_wks, color=None, clear_prev=False)
gr_ws_name = main_window._myController.calculate_gr(
new_sq_wks,
pdf_type,
min_r,
delta_r,
max_r,
min_q,
max_q,
pdf_filter,
rho0)

# check whether G(r) is in GofR plot to either update or add new plot
update = main_window.calculategr_ui.graphicsView_gr.has_gr(gr_ws_name)
Expand Down
4 changes: 2 additions & 2 deletions addie/initialization/events/postprocessing_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def run(main_window=None):
main_window.postprocessing_ui.pushButton.clicked.connect(main_window.reset_q_range)
main_window.postprocessing_ui.plazcek_fit_range_max.editingFinished.connect(main_window.check_plazcek_widgets)
main_window.postprocessing_ui.plazcek_fit_range_min.editingFinished.connect(main_window.check_plazcek_widgets)
main_window.postprocessing_ui.hydrogen_no.clicked.connect(main_window.no_hidrogen_clicked)
main_window.postprocessing_ui.hydrogen_yes.clicked.connect(main_window.hidrogen_clicked)
main_window.postprocessing_ui.hydrogen_no.clicked.connect(main_window.no_hydrogen_clicked)
main_window.postprocessing_ui.hydrogen_yes.clicked.connect(main_window.hydrogen_clicked)
main_window.postprocessing_ui.fourier_filter_from.editingFinished.connect(main_window.check_fourier_filter_widgets)
main_window.postprocessing_ui.fourier_filter_to.editingFinished.connect(main_window.check_fourier_filter_widgets)
main_window.postprocessing_ui.run_ndabs_output_file_name.textChanged['QString'].connect(
Expand Down
23 changes: 18 additions & 5 deletions addie/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ class MainWindow(QMainWindow):
global_key_value = {}
align_and_focus_powder_from_files_blacklist = []

idl_modes = ("idl", "idl_dev")

def __init__(self, parent=None, processing_mode=None):
""" Initialization
Parameters
Expand Down Expand Up @@ -363,6 +365,16 @@ def __init__(self, parent=None, processing_mode=None):
# color management
self._pdfColorManager = PDFPlotManager()

# IDL config scripts
idl_script_dir = "/SNS/NOM/shared/autoNOM/stable/"
if self.post_processing == "idl_dev":
idl_script_dir = "/SNS/NOM/shared/autoNOM/dev/"
self.idl_script_dir = idl_script_dir
self._autonom_script = os.path.join(idl_script_dir, "autoNOM.py")
self._sum_scans_script = os.path.join(idl_script_dir, "sumscans.py")
self._ndabs_script = os.path.join(idl_script_dir, "NDabs.py")
self._is_sum_scans_python_checked = False

# Connecting all the widgets
main_tab_events_handler.run(main_window=self)
autonom_tab_events_handler.run(main_window=self)
Expand Down Expand Up @@ -581,13 +593,13 @@ def check_q_range(self):
_o_gui = Step2GuiHandler(main_window=self)
_o_gui.check_gui()

def hidrogen_clicked(self):
def hydrogen_clicked(self):
o_gui = Step2GuiHandler(main_window=self)
o_gui.hidrogen_clicked()
o_gui.hydrogen_clicked()

def no_hidrogen_clicked(self):
def no_hydrogen_clicked(self):
o_gui = Step2GuiHandler(main_window=self)
o_gui.no_hidrogen_clicked()
o_gui.no_hydrogen_clicked()

def yes_background_clicked(self):
o_gui = Step2GuiHandler(main_window=self)
Expand Down Expand Up @@ -996,7 +1008,8 @@ def main(config=None):
help='Set processing mode (default=%(default)s)',
choices=[
'mantid',
'idl'])
'idl',
'idl_dev'])

try: # set up bash completion as a soft dependency
import argcomplete # noqa
Expand Down
2 changes: 1 addition & 1 deletion addie/menu/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def help_about_clicked(main_window):


def activate_reduction_tabs(main_window):
if main_window.post_processing == 'idl':
if main_window.post_processing in main_window.idl_modes:
tab_0 = True
tab_1 = True
tab_2 = False
Expand Down
82 changes: 79 additions & 3 deletions addie/menu/file/settings/advanced_file_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ def __init__(self, parent=None):
def init_widgets(self):
_idl_status = False
_mantid_status = False
if self.parent.post_processing == 'idl':
if self.parent.post_processing in self.parent.idl_modes:
_idl_status = True
else:
_mantid_status = True

self.ui.idl_groupbox.setVisible(self.parent.advanced_window_idl_groupbox_visible)
self.ui.idl_config_group_box.setVisible(self.parent.advanced_window_idl_groupbox_visible)

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

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

# IDL config
self.ui.autonom_path_line_edit.setText(self.parent._autonom_script)
self.ui.sum_scans_path_line_edit.setText(self.parent._sum_scans_script)
self.ui.ndabs_path_line_edit.setText(self.parent._ndabs_script)
self.ui.idl_config_browse_button_dialog = None

self.ui.centralwidget.setContentsMargins(10, 10, 10, 10)

def is_idl_selected(self):
Expand All @@ -71,7 +81,7 @@ def post_processing_clicked(self):
_post = 'mantid'
_idl_groupbox_visible = False

self.ui.idl_groupbox.setVisible(_idl_groupbox_visible)
self.ui.idl_config_group_box.setVisible(_idl_groupbox_visible)
self.parent.post_processing = _post
self.parent.activate_reduction_tabs() # hide or show right tabs
self.parent.advanced_window_idl_groupbox_visible = _idl_groupbox_visible
Expand All @@ -97,5 +107,71 @@ def output_dir_button_clicked(self):
self.ui.output_dir_label.setText(str(_output_folder))
self.parent.output_folder = str(_output_folder)

# IDL Config - Line Edits
def autonom_path_line_edited(self):
""" update autonom script in top-level after line editing """
_script = str(self.ui.autonom_path_line_edit.text())
self.parent._autonom_script = _script

def sum_scans_path_line_edited(self):
""" update sum scans script in top-level after line editing """
_script = str(self.ui.sum_scans_path_line_edit.text())
self.parent._sum_scans_script = _script

def ndabs_path_line_edited(self):
""" update ndabs script in top-level after line editing """
_script = str(self.ui.ndabs_path_line_edit.text())
self.parent._ndabs_script = _script

# IDL Config - Browse Buttons
def _idl_button_clicked(self, line_edit):
""" Utility function to handle IDL script path browse buttons """

# Initialize with current script in line edit
script = str(line_edit.text())

# Get current working directory to open file dialog in
_current_folder = self.parent.current_folder

# Launch file dialog
self.ui.idl_config_browse_button_dialog = QFileDialog(
parent=self.ui,
directory=_current_folder,
caption="Select File",
filter=("Python (*.py);; All Files (*.*)"))

# Handle if we select a file or cancel
if self.ui.idl_config_browse_button_dialog.exec_():
files = self.ui.idl_config_browse_button_dialog.selectedFiles()

if files[0] != '':
script = str(files[0])
line_edit.setText(script)

# Set the class attribute back to None for monitoring / testing
self.ui.idl_config_browse_button_dialog = None

return script

def autonom_path_browse_button_clicked(self):
""" Handle browse button clicked for autonom script path """
line_edit = self.ui.autonom_path_line_edit
self.parent._autonom_script = self._idl_button_clicked(line_edit)

def sum_scans_path_browse_button_clicked(self):
""" Handle browse button clicked for sum scans script path """
line_edit = self.ui.sum_scans_path_line_edit
self.parent._sum_scans_script = self._idl_button_clicked(line_edit)

def ndabs_path_browse_button_clicked(self):
""" Handle browse button clicked for ndabs script path """
line_edit = self.ui.ndabs_path_line_edit
self.parent._ndabs_script = self._idl_button_clicked(line_edit)

def sum_scans_python_version_checkbox_toggled(self):
""" Handle the sum scans checkbox for using the python version """
_is_checked = self.ui.sum_scans_python_version_checkbox.isChecked()
self.parent._is_sum_scans_python_checked = _is_checked

def closeEvent(self, c):
self.parent.advanced_window_ui = None
21 changes: 14 additions & 7 deletions addie/processing/idl/run_sum_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

class RunSumScans(object):

script = 'python /SNS/NOM/shared/autoNOM/stable/sumscans.py '
output_file = ''

def __init__(self, parent=None):
self.parent = parent.ui.postprocessing_ui
self.parent_no_ui = parent
self.o_gui_handler = Step2GuiHandler(main_window=self.parent_no_ui)
self.folder = os.getcwd()
self.set_sum_scans_script()

def set_sum_scans_script(self):
self.script_path = self.o_gui_handler.get_sum_scans_script()
self.script = 'python ' + self.script_path
print("SumScans: ", self.script)

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

def add_script_flags(self):
self.set_sum_scans_script()
_script = self.script

if not self.parent.interactive_mode_checkbox.isChecked():
_script += "-n True"
if self.parent.pytest.isChecked():
_script += "-u True"
_script += " -n True "
if self.parent_no_ui._is_sum_scans_python_checked:
_script += " -u True "

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

def create_output_file(self):
_output_file_name = "sum_" + self.parent.sum_scans_output_file_name.text() + ".inp"
# print("_output_file_name: {}".format(_output_file_name))
# print("_output_file_name: {}".format(_output_file_name))
_full_output_file_name = os.path.join(self.folder, _output_file_name)
# print("_full_output_file_name: {}".format(_full_output_file_name))
# print("_full_output_file_name: {}".format(_full_output_file_name))
self.full_output_file_name = _full_output_file_name

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

# hydrogen flag
plattype_flag = 0
if o_gui_handler.is_hidrogen_clicked():
if o_gui_handler.is_hydrogen_clicked():
plattype_flag = 2
f.write("platype {}\n".format(plattype_flag))

Expand Down
9 changes: 6 additions & 3 deletions addie/processing/idl/step2_gui_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def move_to_folder(self):
self.main_window.current_folder = _new_folder
self.main_window.setWindowTitle(_new_folder)

def is_hidrogen_clicked(self):
def is_hydrogen_clicked(self):
return self.main_window.postprocessing_ui.hydrogen_yes.isChecked()

def hidrogen_clicked(self):
def hydrogen_clicked(self):
_range = self.hidrogen_range
self.populate_hidrogen_range(_range)

def no_hidrogen_clicked(self):
def no_hydrogen_clicked(self):
_range = self.no_hidrogen_range
self.populate_hidrogen_range(_range)

Expand Down Expand Up @@ -113,6 +113,9 @@ def define_new_output_file_name(self):
_output_file_name = self.default_ndabs_output_file_name
return _output_file_name

def get_sum_scans_script(self):
return self.main_window._sum_scans_script

def check_import_export_buttons(self):
_export_status = False
if self.main_window.postprocessing_ui.table.rowCount() > 0:
Expand Down
3 changes: 2 additions & 1 deletion addie/processing/idl/table_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def right_click(self, position=None):
_refresh_table = -1
_clear_table = -1
# _import = -1
# _export = -1 _check_all = -1
# _export = -1
_check_all = -1
_uncheck_all = -1
_undo = -1
_redo = -1
Expand Down
Loading

0 comments on commit 23c827e

Please sign in to comment.