Skip to content

Commit

Permalink
fix multiple bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kvieta1990 committed Dec 19, 2022
1 parent 0787121 commit 6b3363d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6,573 deletions.
49 changes: 37 additions & 12 deletions addie/addiedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,48 @@ def __init__(self):
self._grWsIndex = 0
self._grWsNameDict = dict()

def calculate_sqAlt(self, ws_name, outputType):
def calculate_sqAlt(self, ws_name, initType, outputType):
if initType == "S(Q)":
pass # don't do anything
elif initType == "S(Q)-1":
x_tmp = simpleapi.mtd[ws_name].readX(0)
y_tmp = simpleapi.mtd[ws_name].readY(0) + 1.0
simpleapi.CreateWorkspace(DataX=x_tmp,
DataY=y_tmp,
NSpec=1,
UnitX="MomentumTransfer",
OutputWorkspace=ws_name)
elif initType == "Q[S(Q)-1]":
simpleapi.PDConvertReciprocalSpace(
InputWorkspace=ws_name,
OutputWorkspace=ws_name,
From='F(Q)',
To='S(Q)')

if outputType == 'S(Q)': # don't do anything
return ws_name
elif outputType == 'Q[S(Q)-1]':
outputType = 'F(Q)'
else:
# PDConvertReciprocalSpace doesn't currently know how to convert to
# S(Q)-1
raise ValueError(
'Do not know how to convert to {}'.format(outputType))
outputType = 'S(Q)-1'

outputName = '__{}Alt'.format(ws_name) # should be hidden
simpleapi.PDConvertReciprocalSpace(
InputWorkspace=ws_name,
OutputWorkspace=outputName,
From='S(Q)',
To=outputType)

if outputType != 'S(Q)-1':
simpleapi.PDConvertReciprocalSpace(
InputWorkspace=ws_name,
OutputWorkspace=outputName,
From='S(Q)',
To=outputType)
else:
x_tmp = simpleapi.mtd[ws_name].readX(0)
y_tmp = simpleapi.mtd[ws_name].readY(0) - 1.0
simpleapi.CreateWorkspace(DataX=x_tmp,
DataY=y_tmp,
NSpec=1,
UnitX="MomentumTransfer",
OutputWorkspace=outputName)

return outputName

def calculate_gr(
Expand Down Expand Up @@ -464,7 +489,7 @@ def save_ascii(self, ws_name, file_name, filetype, comment=''):
Args:
ws_name:
file_name:
filetype: xye, csv, rmcprofile, dat
filetype: xye, csv, rmcprofile, dat, gr, gofr
comment: user comment to the file
Returns:
Expand All @@ -473,7 +498,7 @@ def save_ascii(self, ws_name, file_name, filetype, comment=''):
assert isinstance(
filetype, str), 'GofR file type {0} must be a supported string.'.format(filetype)

if filetype == 'xye' or filetype == 'gr':
if filetype == 'xye' or filetype == 'gr' or filetype == 'gofr':
x_val = simpleapi.mtd[ws_name].readX(0)[:-1]
y_val = simpleapi.mtd[ws_name].readY(0)
e_val = simpleapi.mtd[ws_name].readE(0)
Expand Down
45 changes: 16 additions & 29 deletions addie/calculate_gr/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def gr_widgets_status(main_window, gr_status):
list_gr_ui = [main_window.calculategr_ui.pushButton_saveGR,
main_window.calculategr_ui.pushButton_rescaleGr,
main_window.calculategr_ui.pushButton_grColorStyle,
main_window.calculategr_ui.pushButton_generateSQ,
main_window.calculategr_ui.pushButton_clearGrCanvas]

for _ui in list_gr_ui:
Expand Down Expand Up @@ -135,7 +134,8 @@ def plot_sq(main_window, ws_name, color, clear_prev):
# convert to the function to plot
sq_type = str(main_window.calculategr_ui.comboBox_SofQType.currentText())
plottable_name = main_window._myController.calculate_sqAlt(
ws_name, sq_type)
ws_name, main_window.sofq_type_in_mem, sq_type)
main_window.sofq_type_in_mem = sq_type

main_window.calculategr_ui.graphicsView_sq.plot_sq(
plottable_name,
Expand All @@ -152,7 +152,7 @@ def generate_gr_step1(main_window):
# get S(Q) workspace
gr_list = main_window.calculategr_ui.treeWidget_grWsList
sq_name_list = gr_list.get_selected_items_of_level(
2, excluded_parent='GofR', return_item_text=True)
2, excluded_parent='G(R)', return_item_text=True)
if len(sq_name_list) == 0:
comboBox_SofQ = main_window.calculategr_ui.comboBox_SofQ
selected_sq = str(comboBox_SofQ.currentText())
Expand Down Expand Up @@ -507,7 +507,8 @@ def do_save_gr(main_window):
FILE_FILTERS = {'PDFgui (*.gr)': 'gr',
'XYE (*.xye)': 'xye',
'CSV XYE (*.csv)': 'csv',
'RMCProfile (*.dat)': 'dat'}
'RMCProfile (*.dat)': 'dat',
'g(r) (*.gofr)': 'gofr'}

filename, filetype = get_save_file(
parent=main_window,
Expand All @@ -521,7 +522,13 @@ def do_save_gr(main_window):
filetype = 'rmcprofile'

# save!
main_window._myController.save_ascii(gr_ws_name, filename, filetype)
try:
main_window._myController.save_ascii(gr_ws_name, filename, filetype)
except RuntimeError as err:
main_window.ui.statusbar.setStyleSheet("color: red")
main_window.ui.statusbar.showMessage(err,
main_window.statusbar_display_time)

main_window.ui.statusbar.setStyleSheet("color: blue")
main_window.ui.statusbar.showMessage("File successfully saved.",
main_window.statusbar_display_time)
Expand All @@ -536,7 +543,8 @@ def do_save_gr(main_window):
"gr": "gr",
"csv": "csv",
"rmcprofile": "dat",
"dat": "dat"
"dat": "dat",
"gofr": "gofr"
}
if "xye" in out_dir.lower():
filetype = "xye"
Expand All @@ -548,6 +556,8 @@ def do_save_gr(main_window):
filetype = "rmcprofile"
elif "dat" in out_dir.lower():
filetype = "dat"
elif "gofr" in out_dir.lower():
filetype = "gofr"
else:
filetype = "gr"

Expand Down Expand Up @@ -623,29 +633,6 @@ def do_edit_sq(main_window):
main_window._editSqDialog.show()


def do_generate_sq(main_window):
"""
generate S(Q) from G(r) by PDFFourierTransform
"""
# TODO/ISSUE/NOW - Need to implement!
raise NotImplementedError(
'Dialog box for generating S(Q) has not been implemented yet.')
# get setup
min_r = float(main_window.calculategr_ui.doubleSpinBoxRmin.value())
max_r = float(main_window.calculategr_ui.doubleSpinBoxRmax.value())
min_q = main_window.calculategr_ui.doubleSpinBoxQmin.value()
max_q = main_window.calculategr_ui.doubleSpinBoxQmax.value()

# launch the dialog bo
if main_window._generateSofQDialog is None:
main_window._generateSofQDialog = None

main_window._generateSofQDialog.set_r_range(min_r, max_r)
main_window._generateSofQDialog.set_q_range(min_q, max_q)

main_window._generateSofQDialog.show()


def _set_color_marker(main_window, graphicsView):
plot_id_label_list = graphicsView.get_current_plots()

Expand Down
1 change: 0 additions & 1 deletion addie/initialization/events/calculategr_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def run(main_window=None):
main_window.calculategr_ui.pushButton_clearGrCanvas.clicked.connect(main_window.do_clear_gr)
main_window.calculategr_ui.pushButton_saveSQ.clicked.connect(main_window.do_save_sq)
main_window.calculategr_ui.pushButton_editSofQ.clicked.connect(main_window.do_edit_sq)
main_window.calculategr_ui.pushButton_generateSQ.clicked.connect(main_window.do_generate_sq)

main_window.calculategr_ui.doubleSpinBoxQmin.valueChanged.connect(main_window.evt_qmin_changed)
main_window.calculategr_ui.doubleSpinBoxQmax.valueChanged.connect(main_window.evt_qmax_changed)
Expand Down
5 changes: 2 additions & 3 deletions addie/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ class MainWindow(QMainWindow):

idl_modes = ("idl", "idl_dev")

sofq_type_in_mem = "S(Q)"

def __init__(self, parent=None, processing_mode=None):
""" Initialization
Parameters
Expand Down Expand Up @@ -845,9 +847,6 @@ def do_save_sq(self):
def do_edit_sq(self):
calculategr_event_handler.do_edit_sq(self)

def do_generate_sq(self):
calculategr_event_handler.do_generate_sq(self)

def do_set_gofr_color_marker(self):
calculategr_event_handler.do_set_gofr_color_marker(self)

Expand Down
Loading

0 comments on commit 6b3363d

Please sign in to comment.