Skip to content

Commit

Permalink
Merge pull request #26443 from mantidproject/26440_flatten_muon_ADS_l…
Browse files Browse the repository at this point in the history
…ists

Flattened muon ADS lists
  • Loading branch information
NickDraper authored Jul 22, 2019
2 parents 5c59244 + da61495 commit 4f102e5
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 66 deletions.
5 changes: 5 additions & 0 deletions docs/source/release/v4.1.0/muon.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,10 @@ Bug Fixes
* Elemental Analysis no longer crashes when an ill formatted data file is loaded.
* Changed the y-axis label in Elemental Analysis to `Counts`.

Known Issues
############

* Plotting can be very slow to update if large numbers of workspaces are plotted. This can lead to unresponsive behaviour when large numbers of workspaces are fitted with sequential fits. As a temporary solution closing the plot window before performing large sequential fits can avoid this slowdown.


:ref:`Release 4.1.0 <v4.1.0>`
7 changes: 2 additions & 5 deletions scripts/Muon/GUI/Common/ADSHandler/workspace_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ def get_pair_data_workspace_name(context, pair_name, run, rebin):


def get_base_data_directory(context, run):
if context.data_context.is_multi_period():
return context.data_context.base_directory + "/" + context.data_context._base_run_name(run) + context.workspace_suffix + "/"
else:
return context.data_context.base_directory + "/" + context.data_context._base_run_name(run) + context.workspace_suffix + "/"
return context.data_context._base_run_name(run) + context.workspace_suffix + "/"


def get_raw_data_directory(context, run):
Expand Down Expand Up @@ -114,7 +111,7 @@ def get_pair_data_directory(context, run):

def get_phase_table_workspace_name(raw_workspace, forward_group, backward_group):
workspace_name = raw_workspace.replace('_raw_data', '; PhaseTable')
workspace_name += '; ' + forward_group + ', ' + backward_group
workspace_name += '; ' + forward_group + '; ' + backward_group
return workspace_name


Expand Down
9 changes: 2 additions & 7 deletions scripts/Muon/GUI/Common/contexts/muon_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

from Muon.GUI.Common.ADSHandler.workspace_naming import (get_raw_data_workspace_name, get_group_data_workspace_name,
get_pair_data_workspace_name, get_base_data_directory,
get_raw_data_directory, get_group_data_directory,
get_pair_data_directory, get_group_asymmetry_name,
get_group_asymmetry_name,
get_group_asymmetry_unnorm_name)
from Muon.GUI.Common.calculate_pair_and_group import calculate_group_data, calculate_pair_data, \
estimate_group_asymmetry_data
Expand Down Expand Up @@ -86,7 +85,7 @@ def show_all_groups(self):
for group_name in self._group_pair_context.group_names:
run_as_string = run_list_to_string(run)

directory = get_base_data_directory(self, run_as_string) + get_group_data_directory(self, run_as_string)
directory = get_base_data_directory(self, run_as_string)

name = get_group_data_workspace_name(self, group_name, run_as_string, rebin=False)
asym_name = get_group_asymmetry_name(self, group_name, run_as_string, rebin=False)
Expand Down Expand Up @@ -114,8 +113,6 @@ def show_all_pairs(self):
run_as_string,
rebin=False)
directory = get_base_data_directory(
self,
run_as_string) + get_pair_data_directory(
self,
run_as_string)

Expand Down Expand Up @@ -185,8 +182,6 @@ def show_raw_data(self):
self.data_context._loaded_data.get_data(run=run, instrument=self.data_context.instrument)['workspace'][
'OutputWorkspace']
directory = get_base_data_directory(
self,
run_string) + get_raw_data_directory(
self,
run_string)

Expand Down
16 changes: 6 additions & 10 deletions scripts/Muon/GUI/Common/fitting_tab_widget/fitting_tab_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from Muon.GUI.Common.utilities.algorithm_utils import run_Fit, run_simultaneous_Fit, run_CalculateMuonAsymmetry
import mantid
from Muon.GUI.Common.ADSHandler.muon_workspace_wrapper import MuonWorkspaceWrapper
from Muon.GUI.Common.ADSHandler.workspace_naming import get_fit_workspace_directory
from mantid.simpleapi import RenameWorkspace, ConvertFitFunctionForMuonTFAsymmetry, CopyLogs


Expand Down Expand Up @@ -62,22 +61,19 @@ def add_workspace_to_ADS(self, workspace, name, directory):
return workspace_wrapper

def create_fitted_workspace_name(self, input_workspace_name, function_name, group_name):
directory = get_fit_workspace_directory(group_name, '_workspaces', self.context.data_context.base_directory,
self.context.workspace_suffix)
name = input_workspace_name + '; Fitted; ' + self.function_name
directory = input_workspace_name + '; Fitted; ' + self.function_name + '/'
name = input_workspace_name + '; Fitted; ' + self.function_name + '; Workspace'

return name, directory

def create_multi_domain_fitted_workspace_name(self, input_workspace, function, group_name):
directory = get_fit_workspace_directory(group_name, '_workspaces', self.context.data_context.base_directory,
self.context.workspace_suffix)
directory = input_workspace + '; Fitted; ' + self.function_name + '/'
name = input_workspace + '+ ...; Fitted; ' + self.function_name

return name, directory

def create_parameter_table_name(self, input_workspace_name, function_name, group_name):
directory = get_fit_workspace_directory(group_name, '_parameter_tables', self.context.data_context.base_directory,
self.context.workspace_suffix)
directory = input_workspace_name + '; Fitted; ' + self.function_name + '/'
name = input_workspace_name + '; Fitted Parameters; ' + self.function_name

return name, directory
Expand Down Expand Up @@ -206,12 +202,12 @@ def _handle_simultaneous_fit_results(self, input_workspace_list, fit_function, f
workspace_name, workspace_directory = self.create_multi_domain_fitted_workspace_name(
input_workspace_list[0],
fit_function, fit_group_name)
self.add_workspace_to_ADS(output_workspace, workspace_name, workspace_directory)
self.add_workspace_to_ADS(covariance_matrix, workspace_name + '_CovarianceMatrix', table_directory)
self.add_workspace_to_ADS(output_workspace, workspace_name, '')
workspace_name = self.rename_members_of_fitted_workspace_group(output_workspace,
input_workspace_list,
fit_function,
fit_group_name)
self.add_workspace_to_ADS(covariance_matrix, workspace_name[0] + '_CovarianceMatrix', table_directory)
else:
table_name, table_directory = self.create_parameter_table_name(input_workspace_list[0],
fit_function,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def handle_load_grouping_from_file(self):
file_filter = file_utils.filter_for_extensions(["xml"])
filename = self._view.show_file_browser_and_return_selection(file_filter, [""])

if filename == '':
return

groups, pairs, description, default = xml_utils.load_grouping_from_XML(filename)

self._model.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ def get_parameters_for_phase_quad(self):
def add_phase_quad_to_ADS(self, input_workspace, input_phase_table, phase_quad):
run = re.search('[0-9]+', input_workspace).group()
phasequad_workspace_name = get_phase_quad_workspace_name(input_workspace, input_phase_table)
phase_table_group = get_phase_table_workspace_group_name(phasequad_workspace_name,
self.context.data_context.instrument, self.context.workspace_suffix)
directory = get_base_data_directory(self.context, run) + phase_table_group

directory = get_base_data_directory(self.context, run)

muon_workspace_wrapper = MuonWorkspaceWrapper(phase_quad, directory + phasequad_workspace_name)
muon_workspace_wrapper.show()
Expand Down Expand Up @@ -158,10 +157,7 @@ def calculate_phase_table(self):
def add_phase_table_to_ADS(self, base_name, detector_table):
run = re.search('[0-9]+', base_name).group()

phase_table_group = get_phase_table_workspace_group_name(base_name,
self.context.data_context.instrument,
self.context.workspace_suffix)
directory = get_base_data_directory(self.context, run) + phase_table_group
directory = get_base_data_directory(self.context, run)
muon_workspace_wrapper = MuonWorkspaceWrapper(detector_table, directory + base_name)
muon_workspace_wrapper.show()

Expand Down
25 changes: 14 additions & 11 deletions scripts/Muon/GUI/FrequencyDomainAnalysis/FFT/fft_presenter_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import mantid.simpleapi as mantid

from Muon.GUI.Common import thread_model
from Muon.GUI.Common.utilities.algorithm_utils import run_PaddingAndApodization, run_FFT, convert_to_field, extract_single_spec
from Muon.GUI.Common.utilities.algorithm_utils import run_PaddingAndApodization, run_FFT, convert_to_field, \
extract_single_spec
from Muon.GUI.Common.thread_model_wrapper import ThreadModelWrapper
from Muon.GUI.Common.ADSHandler.workspace_naming import get_fft_workspace_name, get_fft_workspace_group_name, \
get_base_data_directory, get_group_or_pair_from_name
get_group_or_pair_from_name
import re
from Muon.GUI.Common.ADSHandler.muon_workspace_wrapper import MuonWorkspaceWrapper
from Muon.GUI.Common.observer_pattern import GenericObservable
Expand Down Expand Up @@ -169,7 +170,8 @@ def calculate_FFT(self):
if self.view.imaginary_data:
if 'PhaseQuad' in self.view.workspace:
imaginary_workspace_input = real_workspace_input
imaginary_workspace_padding_parameters['InputWorkspace'] = real_workspace_padding_parameters['InputWorkspace']
imaginary_workspace_padding_parameters['InputWorkspace'] = real_workspace_padding_parameters[
'InputWorkspace']
imaginary_workspace_index = 1
else:
imaginary_workspace_input = run_PaddingAndApodization(imaginary_workspace_padding_parameters)
Expand All @@ -187,23 +189,24 @@ def calculate_FFT(self):
def add_fft_workspace_to_ADS(self, input_workspace, imaginary_input_workspace, fft_workspace):
run = re.search('[0-9]+', input_workspace).group()
Im_run = ""
if imaginary_input_workspace is not "":
if imaginary_input_workspace != "":
Im_run = re.search('[0-9]+', imaginary_input_workspace).group()
fft_workspace_name = get_fft_workspace_name(input_workspace, imaginary_input_workspace)
group = get_fft_workspace_group_name(fft_workspace_name, self.load.data_context.instrument, self.load.workspace_suffix)
directory = get_base_data_directory(self.load, run) + group

directory = get_fft_workspace_group_name(fft_workspace_name, self.load.data_context.instrument,
self.load.workspace_suffix)
Re = get_group_or_pair_from_name(input_workspace)
Im = get_group_or_pair_from_name(imaginary_input_workspace)
shift = 3 if fft_workspace.getNumberHistograms() == 6 else 0
spectra = {"_"+FREQUENCY_EXTENSIONS["RE"]:0+shift, "_"+FREQUENCY_EXTENSIONS["IM"]:1+shift, "_"+FREQUENCY_EXTENSIONS["MOD"]:2+shift}
spectra = {"_" + FREQUENCY_EXTENSIONS["RE"]: 0 + shift, "_" + FREQUENCY_EXTENSIONS["IM"]: 1 + shift,
"_" + FREQUENCY_EXTENSIONS["MOD"]: 2 + shift}
for spec_type in list(spectra.keys()):
extracted_ws = extract_single_spec(fft_workspace,spectra[spec_type])
extracted_ws = extract_single_spec(fft_workspace, spectra[spec_type])

if 'PhaseQuad' in self.view.workspace:
self.load._frequency_context.add_FFT(fft_workspace_name + spec_type, run, Re,Im_run, Im, phasequad = True)
self.load._frequency_context.add_FFT(fft_workspace_name + spec_type, run, Re, Im_run, Im,
phasequad=True)
else:
self.load._frequency_context.add_FFT(fft_workspace_name + spec_type, run, Re,Im_run, Im)
self.load._frequency_context.add_FFT(fft_workspace_name + spec_type, run, Re, Im_run, Im)

muon_workspace_wrapper = MuonWorkspaceWrapper(extracted_ws, directory + fft_workspace_name + spec_type)
muon_workspace_wrapper.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

from Muon.GUI.Common import thread_model
from Muon.GUI.Common.ADSHandler.muon_workspace_wrapper import MuonWorkspaceWrapper
from Muon.GUI.Common.ADSHandler.workspace_naming import get_maxent_workspace_group_name, get_maxent_workspace_name, \
get_base_data_directory
from Muon.GUI.Common.ADSHandler.workspace_naming import get_maxent_workspace_group_name, get_maxent_workspace_name
from Muon.GUI.Common.observer_pattern import GenericObserver, GenericObservable
from Muon.GUI.Common.thread_model_wrapper import ThreadModelWrapper
from Muon.GUI.Common.utilities.algorithm_utils import run_MuonMaxent
Expand Down Expand Up @@ -154,8 +153,7 @@ def update_phase_table_options(self):
def add_maxent_workspace_to_ADS(self, input_workspace, maxent_workspace, alg):
run = re.search('[0-9]+', input_workspace).group()
base_name = get_maxent_workspace_name(input_workspace)
group = get_maxent_workspace_group_name(base_name, self.load.data_context.instrument, self.load.workspace_suffix)
directory = get_base_data_directory(self.load, run) + group
directory = get_maxent_workspace_group_name(base_name, self.load.data_context.instrument, self.load.workspace_suffix)

muon_workspace_wrapper = MuonWorkspaceWrapper(maxent_workspace, directory + base_name)
muon_workspace_wrapper.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def test_convert_function_string_into_dict(self):
def test_create_fitted_workspace_name(self):
input_workspace_name = 'MUSR22725; Group; top; Asymmetry; #1'
trial_function = FunctionFactory.createInitialized('name=GausOsc,A=0.2,Sigma=0.2,Frequency=0.1,Phi=0')
expected_directory_name = 'Muon Data/Fitting Output MA/Fitting Output_workspaces MA/'
expected_workspace_name = 'MUSR22725; Group; top; Asymmetry; #1; Fitted; GausOsc'
expected_directory_name = 'MUSR22725; Group; top; Asymmetry; #1; Fitted; GausOsc/'
expected_workspace_name = 'MUSR22725; Group; top; Asymmetry; #1; Fitted; GausOsc; Workspace'
self.model.function_name = 'GausOsc'

name, directory = self.model.create_fitted_workspace_name(input_workspace_name, trial_function,
Expand All @@ -41,7 +41,7 @@ def test_create_fitted_workspace_name(self):
def test_create_parameter_table_name(self):
input_workspace_name = 'MUSR22725; Group; top; Asymmetry; #1'
trial_function = FunctionFactory.createInitialized('name=GausOsc,A=0.2,Sigma=0.2,Frequency=0.1,Phi=0')
expected_directory_name = 'Muon Data/Fitting Output MA/Fitting Output_parameter_tables MA/'
expected_directory_name = 'MUSR22725; Group; top; Asymmetry; #1; Fitted; GausOsc/'
expected_workspace_name = 'MUSR22725; Group; top; Asymmetry; #1; Fitted Parameters; GausOsc'
self.model.function_name = 'GausOsc'

Expand Down Expand Up @@ -86,7 +86,7 @@ def test_create_multi_domain_fitted_workspace_name(self):
' n = 0, A0 = 0,$domains = i;name = Polynomial, n = 0, A0 = 0,'
'$domains = i;name = Polynomial, n = 0, A0 = 0,$domains = i;'
'name = Polynomial, n = 0, A0 = 0,$domains = i')
expected_directory_name = 'Muon Data/Fitting Output MA/Fitting Output_workspaces MA/'
expected_directory_name = 'MUSR22725; Group; top; Asymmetry; #1; Fitted; Polynomial/'
expected_workspace_name = 'MUSR22725; Group; top; Asymmetry; #1+ ...; Fitted; Polynomial'
self.model.function_name = 'Polynomial'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_add_maxent_workspace_to_ADS(self, workspace_wrapper_mock):
self.presenter.add_maxent_workspace_to_ADS('MUSR22725_MaxEnt', maxent_workspace, mock.MagicMock())

workspace_wrapper_mock.assert_called_once_with(maxent_workspace,
'Muon Data/MUSR22725 MA/MUSR22725 Maxent MA/MUSR22725_MaxEnt; MaxEnt')
'MUSR22725 Maxent MA/MUSR22725_MaxEnt; MaxEnt')
workspace_wrapper_mock.return_value.show.assert_called_once_with()

def test_get_output_options_defaults_returns_correctly(self):
Expand Down
Loading

0 comments on commit 4f102e5

Please sign in to comment.