Skip to content
Snippets Groups Projects
Commit b2490634 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Fix SaveReflections for modulated structures

parent a3090ff5
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# NScD Oak Ridge National Laboratory, European Spallation Source # NScD Oak Ridge National Laboratory, European Spallation Source
# & Institut Laue - Langevin # & Institut Laue - Langevin
# SPDX - License - Identifier: GPL - 3.0 + # SPDX - License - Identifier: GPL - 3.0 +
import re
import numpy as np import numpy as np
from mantid.api import AlgorithmFactory, FileProperty, FileAction, PythonAlgorithm, ITableWorkspaceProperty from mantid.api import AlgorithmFactory, FileProperty, FileAction, PythonAlgorithm, ITableWorkspaceProperty
from mantid.kernel import StringListValidator, Direction from mantid.kernel import StringListValidator, Direction
...@@ -11,7 +12,6 @@ from mantid.simpleapi import SaveHKL ...@@ -11,7 +12,6 @@ from mantid.simpleapi import SaveHKL
# List of file format names supported by this algorithm # List of file format names supported by this algorithm
SUPPORTED_FORMATS = ["Fullprof", "GSAS", "Jana", "SHELX"] SUPPORTED_FORMATS = ["Fullprof", "GSAS", "Jana", "SHELX"]
NUM_PEAKSWS_COLUMNS = 18
def has_modulated_indexing(workspace): def has_modulated_indexing(workspace):
...@@ -20,7 +20,7 @@ def has_modulated_indexing(workspace): ...@@ -20,7 +20,7 @@ def has_modulated_indexing(workspace):
:params: workspace :: the workspace to check :params: workspace :: the workspace to check
:returns: True if the workspace > 3 indicies else False :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): def num_additional_indicies(workspace):
...@@ -29,7 +29,7 @@ def num_additional_indicies(workspace): ...@@ -29,7 +29,7 @@ def num_additional_indicies(workspace):
:params: workspace :: the workspace count indicies in :params: workspace :: the workspace count indicies in
:returns: the number of additional indicies present in the workspace :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): def get_additional_index_names(workspace):
...@@ -38,7 +38,9 @@ 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 :params: workspace :: the workspace to get column names from
:returns: the names of any additional columns in the workspace :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): class SaveReflections(PythonAlgorithm):
...@@ -83,6 +85,7 @@ class SaveReflections(PythonAlgorithm): ...@@ -83,6 +85,7 @@ class SaveReflections(PythonAlgorithm):
:returns: file format to use for saving reflections to an ASCII file. :returns: file format to use for saving reflections to an ASCII file.
""" """
if output_format == "Fullprof": if output_format == "Fullprof":
return FullprofFormat() return FullprofFormat()
elif output_format == "Jana": elif output_format == "Jana":
......
...@@ -55,14 +55,14 @@ class SaveReflectionsTest(unittest.TestCase): ...@@ -55,14 +55,14 @@ class SaveReflectionsTest(unittest.TestCase):
return ws return ws
def _create_modulated_peak_table(self): 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): def _create_indexed_workspace(self, fractional_peaks, ndim, hklm):
# Create table with the number of columns we need # 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() indexed = CreateEmptyTableWorkspace()
names = fractional_peaks.getColumnNames() names = fractional_peaks.getColumnNames()
types = fractional_peaks.columnTypes()
# Insert the extra columns for the addtional indicies # Insert the extra columns for the addtional indicies
for i in range(ndim - 3): for i in range(ndim - 3):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment