Skip to content

Commit

Permalink
Merge pull request #526 from mantidproject/525-export-to-external-app
Browse files Browse the repository at this point in the history
Fix indexing error into dict.keys generator
  • Loading branch information
martyngigg authored Mar 3, 2020
2 parents ee207f1 + 845655c commit 5505b82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions mslice/tests/histogram_workspace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from mantid.simpleapi import CreateMDHistoWorkspace

from mslice.tests.workspace_test import BaseWorkspaceTest
from mslice.models.workspacemanager.workspace_provider import add_workspace, remove_workspace
from mslice.workspace.histogram_workspace import HistogramWorkspace


Expand All @@ -22,6 +23,18 @@ def setUpClass(cls):
def test_invalid_workspace(self):
self.assertRaises(TypeError, lambda: HistogramWorkspace(4, 'name'))

def test_convert_to_matrix(self):
# workspace needs to be registered with mslice for conversion
try:
add_workspace(self.workspace, self.workspace.name)
matrix_ws = self.workspace.convert_to_matrix()

self.assertEqual(10, matrix_ws.raw_ws.getNumberHistograms())
self.assertEqual(10, matrix_ws.raw_ws.getNumberBins())
finally:
# remove mslice tracking
remove_workspace(self.workspace)

def test_get_coordinates(self):
expected = np.linspace(0, 100, 10)
self.assertTrue((self.workspace.get_coordinates()['Dim1'] == expected).all())
Expand Down
4 changes: 2 additions & 2 deletions mslice/workspace/histogram_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def rewrap(self, ws):
new_ws.axes = self.axes
return new_ws


def convert_to_matrix(self):
from mslice.util.mantid.mantid_algorithms import ConvertMDHistoToMatrixWorkspace, Scale, ConvertToDistribution
ws_conv = ConvertMDHistoToMatrixWorkspace(self.name, Normalization='NumEventsNormalization',
FindXAxis=False, OutputWorkspace='__mat'+self.name)
coord = self.get_coordinates()
bin_size = coord[coord.keys()[0]][1] - coord[coord.keys()[0]][0]
first_dim = coord[self.raw_ws.getDimension(0).getName()]
bin_size = first_dim[1] - first_dim[0]
ws_conv = Scale(ws_conv, bin_size, OutputWorkspace='__mat'+self.name)
ConvertToDistribution(ws_conv)
return ws_conv
Expand Down

0 comments on commit 5505b82

Please sign in to comment.