Skip to content

Commit

Permalink
allow selection of multiple files in peak fitting window
Browse files Browse the repository at this point in the history
  • Loading branch information
fanchercm committed Oct 11, 2024
1 parent e3ef071 commit 95a9b91
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
1 change: 0 additions & 1 deletion pyrs/interface/combine_runs/combine_runs_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def combine_project_files(self, project_files):
_project.close()

for project in project_files[1:]:
print(project)
_project = HidraProjectFile(project)
self._hidra_ws.append_hidra_project(_project)
_project.close()
Expand Down
2 changes: 1 addition & 1 deletion pyrs/interface/combine_runs/combine_runs_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def saveFileDialog(self):
"",
self.fileType,
options=QFileDialog.DontUseNativeDialog)
print(_export_project)

self._parent.controller.export_combined_projectfile(_export_project)

def loadRunNumbers(self):
Expand Down
2 changes: 1 addition & 1 deletion pyrs/interface/peak_fitting/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def load_and_plot(self, hidra_file_name):

self.parent.current_root_statusbar_message = "Working with: {} " \
"\t\t\t\t Project Name: {}" \
"".format(hidra_file_name,
"".format(self.parent._curr_file_name,
self.parent._project_name)
self.parent.ui.statusbar.showMessage(self.parent.current_root_statusbar_message)

Expand Down
60 changes: 38 additions & 22 deletions pyrs/interface/peak_fitting/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,20 @@ def __init__(self, parent=None):
def load(self, project_file=None):
if project_file is None:
return
elif len(project_file) == 1:
project_file = project_file[0]
try:
self.__set_up_project_name(project_file=project_file)
ws = self.parent._core.load_hidra_project(project_file,
project_name=self.parent._project_name,
load_detector_counts=False,
load_diffraction=True)

# Record data key and next
self.parent._curr_file_name = project_file
self.parent.hidra_workspace = ws
self.parent.fit_result = None
self.parent.create_plot_color_range()
except (RuntimeError, TypeError) as run_err:
pop_message(self, 'Unable to load {}'.format(project_file),
detailed_message=str(run_err),
message_type='error')
else:
self.parent._curr_file_name = project_file[0]
self.parent.hidra_workspace = self.__load_multiple_file(project_file)

try:
self.__set_up_project_name(project_file=project_file)
ws = self.__load_multiple_file(project_file)

# Record data key and next
self.parent._curr_file_name = self.__parse_working_files(project_file)
self.parent.hidra_workspace = ws
self.parent.fit_result = None
self.parent.create_plot_color_range()
except (RuntimeError, TypeError) as run_err:
pop_message(self, 'Unable to load {}'.format(project_file),
detailed_message=str(run_err),
message_type='error')

# Get and set the range of sub runs
o_utility = Utilities(parent=self.parent)
Expand All @@ -52,6 +43,19 @@ def load(self, project_file=None):
self.parent.ui.graphicsView_plot2D.reset_viewer()

def __load_multiple_file(self, project_files):
'''
Load project files for peak fitting
Parameters
----------
project_files : Hidraproject file
DESCRIPTION.
Returns
-------
_hidra_ws : HIDRAWORKSPACE
'''
_hidra_ws = self.parent._core.load_hidra_project(project_files[0],
project_name=self.parent._project_name,
load_detector_counts=False,
Expand All @@ -66,4 +70,16 @@ def __load_multiple_file(self, project_files):

def __set_up_project_name(self, project_file=""):
"""Keep the basename and removed the nxs and h5 extenstions"""
self.parent._project_name = os.path.basename(project_file).split('.')[0]
if type(project_file) is list:
self.parent._project_name = 'HB2B' + ''.join(['_{}'.format(run.split('.')[0].split('_')[-1])
for run in project_file])
else:
self.parent._project_name = os.path.basename(project_file).split('.')[0]

def __parse_working_files(self, project_file=""):
"""Keep the filepath and append runs being fitted"""
if type(project_file) is list:
return project_file[0].split('HB2B')[0] + ''.join(['HB2B_{} '.format(run.split('.')[0].split('_')[-1])
for run in project_file])
else:
return project_file

0 comments on commit 95a9b91

Please sign in to comment.