Skip to content

Commit

Permalink
remove nxs sofq support for gr tab, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
y8z committed Oct 7, 2024
1 parent 39ede04 commit bf7f74f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
38 changes: 17 additions & 21 deletions addie/addiedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@ def calculate_gr(
sq_pystog = np.insert(sq_pystog, 0, sq_pystog[0])
transformer = Transformer()
r_pystog = np.arange(0, max_r + delta_r, delta_r)
print(q_pystog)
print(sq_pystog)
r_pystog, gr_pystog, _ = transformer.S_to_G(q_pystog, sq_pystog, r_pystog)
print(r_pystog)
print(gr_pystog)

gr_ws_name = '%s(R)_%s_%d' % (prefix, self._currSqWsName, ws_seq_index)
simpleapi.CreateWorkspace(
Expand Down Expand Up @@ -457,6 +453,7 @@ def load_gr(self, gr_file_name):

return True, gr_ws_name


def load_sq(self, file_name):
"""
Load S(Q) to a numpy
Expand All @@ -472,20 +469,22 @@ def load_sq(self, file_name):
# generate S(Q) workspace name
sq_ws_name = os.path.basename(file_name).split('.')[0]

def count_header_lines(file_path):
header_characters = ['#', '%', '!', '-']
header_lines_count = 0

with open(file_path, 'r') as file:
for line in file:
condt1 = line.strip().startswith(tuple(header_characters))
condt2 = len(line.strip().split()) == 1
if condt1 or condt2:
header_lines_count += 1

return header_lines_count

# call mantid LoadAscii
ext = file_name.upper().split('.')[-1]
if ext == 'NXS':
simpleapi.LoadNexusProcessed(
Filename=file_name, OutputWorkspace=sq_ws_name)
simpleapi.ConvertUnits(
InputWorkspace=sq_ws_name,
OutputWorkspace=sq_ws_name,
EMode='Elastic',
Target='MomentumTransfer')
simpleapi.ConvertToPointData(
InputWorkspace=sq_ws_name,
OutputWorkspace=sq_ws_name) # TODO REMOVE THIS LINE
elif ext == 'DAT' or ext == 'TXT':
if ext == 'DAT' or ext == 'TXT':
try:
simpleapi.LoadAscii(
Filename=file_name,
Expand All @@ -494,17 +493,14 @@ def load_sq(self, file_name):
except RuntimeError:
sq_ws_name, q_min, q_max = "InvalidInput", 0, 0
return sq_ws_name, q_min, q_max
# The S(Q) file is in fact S(Q)-1 in sq file. So need to add 1 to
# the workspace
# out_ws = AnalysisDataService.retrieve(sq_ws_name)
# out_ws += 1
elif ext == 'SQ':
num_hl = count_header_lines(file_name)
try:
simpleapi.LoadAscii(
Filename=file_name,
OutputWorkspace=sq_ws_name,
Unit='MomentumTransfer',
SkipNumLines=2)
SkipNumLines=num_hl)
except RuntimeError:
sq_ws_name, q_min, q_max = "InvalidInput", 0, 0
return sq_ws_name, q_min, q_max
Expand Down
6 changes: 1 addition & 5 deletions addie/calculate_gr/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def load_sq(main_window):
default_dir = get_default_dir(main_window, sub_dir='SofQ')

# get the file
ext = 'dat (*.dat);;nxs (*.nxs);;All (*.*)'
ext = 'dat (*.dat);;SofQ (*.sq);;All (*.*)'
sq_file_names = QFileDialog.getOpenFileNames(main_window,
'Choose S(Q) File',
default_dir,
Expand Down Expand Up @@ -408,10 +408,6 @@ def plot_gr(main_window, ws_name, line_color, line_style,
# check whether the workspace is on the figure
graphicsView_gr = main_window.calculategr_ui.graphicsView_gr
has_gr = graphicsView_gr.has_gr(ws_name)
current_grs = graphicsView_gr.get_current_grs()
msg = '[DB...BAT] G(r) graphic has plot {0} is {1}. Keys are {2}'
msg = msg.format(ws_name, has_gr, current_grs)
print(msg)

if graphicsView_gr.has_gr(ws_name):
# update G(r) value of an existing plot
Expand Down
4 changes: 3 additions & 1 deletion addie/calculate_gr/gofrview.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ def plot_gr(self, plot_key, ws_name, plotError=False, color='black', style='.',

line_id = self.add_plot_1d(ws_name, wkspindex=0, marker=marker,
color=color, line_style=style, alpha=alpha,
label=label, x_label=r'r ($\AA$)', plotError=plotError)
label=label, x_label=r'r ($\AA$)',
y_label="PDF, G(r), ...",
plotError=plotError)
self._colorIndex += 1
self._grDict[str(plot_key)] = line_id

Expand Down
6 changes: 3 additions & 3 deletions addie/plot/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, parent):
self.fig.patch.set_facecolor('white')

self.axes = self.fig.add_subplot(111, projection='mantid')
self.fig.subplots_adjust(bottom=0.15)
self.fig.subplots_adjust(bottom=0.2)

# Initialize parent class and set parent
FigureCanvasQTAgg.__init__(self, self.fig)
Expand Down Expand Up @@ -123,9 +123,9 @@ def add_plot_1d(

# set x-axis and y-axis label
if x_label is not None:
self.axes.set_xlabel(x_label, fontsize=20)
self.axes.set_xlabel(x_label, fontsize=14)
if y_label is not None:
self.axes.set_ylabel(y_label, fontsize=20)
self.axes.set_ylabel(y_label, fontsize=14)

# set/update legend
if show_legend:
Expand Down

0 comments on commit bf7f74f

Please sign in to comment.