diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/QLRun.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/QLRun.py index a058e40059b69a329f6046d6640f9d9797f0722f..7da1d0e8651e08198beafcfa987b8eaa07169b7b 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/QLRun.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/QLRun.py @@ -97,13 +97,13 @@ class QLRun(PythonAlgorithm): self.declareProperty(WorkspaceGroupProperty('OutputWorkspaceFit', '', direction=Direction.Output), doc='The name of the fit output workspaces') + self.declareProperty(MatrixWorkspaceProperty('OutputWorkspaceResult', '', direction=Direction.Output), + doc='The name of the result output workspaces') + self.declareProperty(MatrixWorkspaceProperty('OutputWorkspaceProb', '', optional=PropertyMode.Optional, direction=Direction.Output), doc='The name of the probability output workspaces') - self.declareProperty(MatrixWorkspaceProperty('OutputWorkspaceResult', '', direction=Direction.Output), - doc='The name of the result output workspaces') - def validateInputs(self): self._get_properties() @@ -349,8 +349,9 @@ class QLRun(PythonAlgorithm): logger.information('Output fit file created : ' + fit_path) logger.information('Output paramter file created : ' + out_path) - self.setProperty('OutputworkspaceFit', fitWS) + self.setProperty('OutputWorkspaceFit', fitWS) self.setProperty('OutputWorkspaceResult', outWS) + if self._program == 'QL': self.setProperty('OutputWorkspaceProb', probWS) diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/QLRunTest.py b/Framework/PythonInterface/test/python/plugins/algorithms/QLRunTest.py index 5f4f76a679f0937bf69ae52ef7f443e384622ff2..06bbd4d8f5d8c3edc4afcdad3211b277857386e1 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/QLRunTest.py +++ b/Framework/PythonInterface/test/python/plugins/algorithms/QLRunTest.py @@ -18,9 +18,9 @@ class QLRunTest(unittest.TestCase): self._num_hists = self._sample_ws.getNumberHistograms() - def _validate_QLr_result(self, result, probability, group): + def _validate_QLr_shape(self, result, probability, group): """ - Validates that the result workspace is of the correct type, units and shape. + Validates that the output workspaces are of the correct type, units and shape. @param result Result workspace from QLRun @param prob Probability workspace from QLRun @@ -52,20 +52,53 @@ class QLRunTest(unittest.TestCase): self.assertEquals(sub_ws.getAxis(0).getUnit().unitID(), 'DeltaE') - def _validate_QSe_result(self, result, group): + def _validate_Qlr_value(self, result, probability, group): """ - Validates that the result workspace is of the correct type, units and shape. + Validates that the output workspaces have expected values + with values from the last known correct version @param result Result workspace from QLRun + @param prob Probability workspace from QLRun @param group Group workspace of fitted spectra from QLRun """ + # Test values of result + result_y = result.dataY(0) + self.assertEquals(round(result.dataY(0)[0], 5), 6.06105) + self.assertEquals(round(result.dataY(1)[0], 4), 68.5744) + self.assertEquals(round(result.dataY(2)[0], 7), 0.0589315) + self.assertEquals(round(result.dataY(3)[0], 7), 0.0812087) + + # Test values of probability + prob_y = probability.dataY(0) + self.assertEquals(round(probability.dataY(0)[0], 1), -74176.1) + self.assertEquals(round(probability.dataY(1)[0], 3), -404.884) + self.assertEquals(round(probability.dataY(2)[0], 6), -0.222565) + + # Test values of group + sub_ws = group.getItem(0) + sub_y = sub_ws.dataY(0) + self.assertEquals(round(sub_ws.dataY(0)[0], 5), 0.02540) + self.assertEquals(round(sub_ws.dataY(1)[0], 5), 0.01903) + self.assertEquals(round(sub_ws.dataY(2)[0], 5), -0.00638) + self.assertEquals(round(sub_ws.dataY(3)[0], 5), 0.01614) + self.assertEquals(round(sub_ws.dataY(4)[0], 5), -0.00926) + + + def _validate_QSe_shape(self, result, group): + """ + Validates that the output workspaces are of the correct type, units and shape. + with values from the last known correct version + + @param result Result workspace from QLRun + @param group Group workspace of fitted spectra from QLRun + """ # Test size/shape of result self.assertTrue(isinstance(result, MatrixWorkspace)) - self.assertEquals(result.getNumberHistograms(), 21) - self.assertEquals(result.blocksize(), self._num_bins) - self.assertEquals(result.getAxis(0).getUnit().unitID(), 'q') + self.assertEquals(result.getNumberHistograms(), 3) + self.assertEquals(result.blocksize(), self._num_hists) + self.assertEquals(result.getAxis(0).getUnit().unitID(), 'MomentumTransfer') # Test size/shape of group fitting workspaces self.assertTrue(isinstance(group, WorkspaceGroup)) @@ -76,29 +109,80 @@ class QLRunTest(unittest.TestCase): sub_ws = group.getItem(i) self.assertTrue(isinstance(sub_ws, MatrixWorkspace)) self.assertEqual(sub_ws.getNumberHistograms(), 3) - self.assertEqual(sub_ws.blocksize(), self._num_bins) - self.assertEquals(sub_ws.getAxis(0).getUnit().unitID(), 'MomentumTransfer') - + self.assertEquals(sub_ws.getAxis(0).getUnit().unitID(), 'DeltaE') + + + + def _validate_QSe_value(self, result, group): + """ + Validates that the output workspaces have expected values + + @param result Result workspace from QLRun + @param prob Probability workspace from QLRun + @param group Group workspace of fitted spectra from QLRun + """ + + # Test values of result + result_y = result.dataY(0) + self.assertEquals(round(result.dataY(0)[0], 5), 81.12644) + self.assertEquals(round(result.dataY(1)[0], 7), 0.0319747) + self.assertEquals(round(result.dataY(2)[0], 5), 0.77168) + + # Test values of group + sub_ws = group.getItem(0) + sub_y = sub_ws.dataY(0) + self.assertEquals(round(sub_ws.dataY(0)[0], 5), 0.02540) + self.assertEquals(round(sub_ws.dataY(1)[0], 5), 0.01632) + self.assertEquals(round(sub_ws.dataY(2)[0], 5), -0.00908) + + + + + def test_QLr_Run(self): """ Test Lorentzian fit for QLRun """ - fit_group, prob, result = QLRun(Program='QL', - SampleWorkspace=self._sample_ws, - ResolutionWorkspace=self._res_ws, - MinRange=-0.547607, - MaxRange=0.543216, - SampleBins=1, - ResolutionBins=1, - Elastic=False, - Background='Sloping', - FixedWidth=False, - UseResNorm=False, - WidthFile='', - Loop=True, - Save=False, - Plot='None') - self._validate_QLr_result(result, prob, fit_group) + fit_group, result, prob= QLRun(Program='QL', + SampleWorkspace=self._sample_ws, + ResolutionWorkspace=self._res_ws, + MinRange=-0.547607, + MaxRange=0.543216, + SampleBins=1, + ResolutionBins=1, + Elastic=False, + Background='Sloping', + FixedWidth=False, + UseResNorm=False, + WidthFile='', + Loop=True, + Save=False, + Plot='None') + self._validate_QLr_shape(result, prob, fit_group) + self._validate_Qlr_value(result, prob, fit_group) + + + def test_QSe_Run(self): + """ + Test Stretched Exponential fit for QLRun + """ + fit_group, result = QLRun(Program='QSe', + SampleWorkspace=self._sample_ws, + ResolutionWorkspace=self._res_ws, + MinRange=-0.547607, + MaxRange=0.543216, + SampleBins=1, + ResolutionBins=1, + Elastic=False, + Background='Sloping', + FixedWidth=False, + UseResNorm=False, + WidthFile='', + Loop=True, + Save=False, + Plot='None') + self._validate_QSe_shape(result, fit_group) + self._validate_QSe_value(result, fit_group) if __name__=="__main__": unittest.main() \ No newline at end of file