diff --git a/Framework/PythonInterface/plugins/algorithms/SaveReflections.py b/Framework/PythonInterface/plugins/algorithms/SaveReflections.py index 1ab8fe3cca743458e80eccc8ffaa0297732954d5..d2b28cb2661b2562400a6c1cc19aabbdbd8735bd 100644 --- a/Framework/PythonInterface/plugins/algorithms/SaveReflections.py +++ b/Framework/PythonInterface/plugins/algorithms/SaveReflections.py @@ -4,6 +4,7 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + +import re import numpy as np from mantid.api import AlgorithmFactory, FileProperty, FileAction, PythonAlgorithm, ITableWorkspaceProperty from mantid.kernel import StringListValidator, Direction @@ -11,7 +12,6 @@ from mantid.simpleapi import SaveHKL # List of file format names supported by this algorithm SUPPORTED_FORMATS = ["Fullprof", "GSAS", "Jana", "SHELX"] -NUM_PEAKSWS_COLUMNS = 18 def has_modulated_indexing(workspace): @@ -20,7 +20,7 @@ def has_modulated_indexing(workspace): :params: workspace :: the workspace to check :returns: True if the workspace > 3 indicies else False """ - return workspace.columnCount() > NUM_PEAKSWS_COLUMNS + return num_additional_indicies(workspace) > 0 def num_additional_indicies(workspace): @@ -29,7 +29,7 @@ def num_additional_indicies(workspace): :params: workspace :: the workspace count indicies in :returns: the number of additional indicies present in the workspace """ - return workspace.columnCount() - NUM_PEAKSWS_COLUMNS + return len(get_additional_index_names(workspace)) def get_additional_index_names(workspace): @@ -38,7 +38,9 @@ def get_additional_index_names(workspace): :params: workspace :: the workspace to get column names from :returns: the names of any additional columns in the workspace """ - return ["m{}".format(i+1) for i in range(num_additional_indicies(workspace))] + pattern = re.compile("m[1-9]+") + names = workspace.getColumnNames() + return list(filter(pattern.match, names)) class SaveReflections(PythonAlgorithm): @@ -83,6 +85,7 @@ class SaveReflections(PythonAlgorithm): :returns: file format to use for saving reflections to an ASCII file. """ + if output_format == "Fullprof": return FullprofFormat() elif output_format == "Jana": diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/SaveReflectionsTest.py b/Framework/PythonInterface/test/python/plugins/algorithms/SaveReflectionsTest.py index b314b28f726332e56c41de962b4b95831e2d51b9..63af0dd771be8b0a6355a4007c892dbcd1a03f70 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/SaveReflectionsTest.py +++ b/Framework/PythonInterface/test/python/plugins/algorithms/SaveReflectionsTest.py @@ -55,14 +55,14 @@ class SaveReflectionsTest(unittest.TestCase): return ws def _create_modulated_peak_table(self): - return self._create_indexed_workspace(self._workspace, 5, np.ones((self._workspace.rowCount(), 2))) + hklm = np.ones((self._workspace.rowCount(), 2)) + return self._create_indexed_workspace(self._workspace, 5, hklm) def _create_indexed_workspace(self, fractional_peaks, ndim, hklm): # Create table with the number of columns we need - types = ['int', 'long64', 'double', 'double', 'double', 'double', 'double', 'double', - 'double', 'double', 'double', 'float', 'str', 'float', 'float', 'V3D', 'V3D', 'int'] indexed = CreateEmptyTableWorkspace() names = fractional_peaks.getColumnNames() + types = fractional_peaks.columnTypes() # Insert the extra columns for the addtional indicies for i in range(ndim - 3):