diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/PoldiLoadRuns.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/PoldiLoadRuns.py index 9c111c7263fe5b30598022c8bbb39672ad8822dc..01bee48608109496344a479e6fdd5bc39a4a31e0 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/PoldiLoadRuns.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/PoldiLoadRuns.py @@ -1,4 +1,4 @@ -# pylint: disable=no-init,invalid-name +# pylint: disable=no-init,invalid-name,bare-except from mantid.kernel import * from mantid.simpleapi import * from mantid.api import * @@ -7,6 +7,9 @@ from datetime import date class PoldiLoadRuns(PythonAlgorithm): + _nameTemplate = "" + _mergeCheckEnabled = True + def category(self): return "SINQ\\Poldi" @@ -70,7 +73,7 @@ class PoldiLoadRuns(PythonAlgorithm): # Construct the names of the workspaces using the output workspace name to avoid ambiguities. outputWorkspaceName = self.getProperty("OutputWorkspace").valueAsStr - nameTemplate = outputWorkspaceName + "_data_" + self._nameTemplate = outputWorkspaceName + "_data_" # If any output was produced, it needs to be checked what to do with it. overwriteWorkspaces = self.getProperty('OverwriteExistingWorkspace').value @@ -80,7 +83,7 @@ class PoldiLoadRuns(PythonAlgorithm): if AnalysisDataService.doesExist(outputWorkspaceName): if not self.isGroupWorkspace(AnalysisDataService.retrieve(outputWorkspaceName)) and not overwriteWorkspaces: self.log().error("Workspace '" + outputWorkspaceName + "' already exists, is not a WorkspaceGroup " - "and is not supposed to be overwritten, aborting.") + "and is not supposed to be overwritten, aborting.") return @@ -88,10 +91,10 @@ class PoldiLoadRuns(PythonAlgorithm): mergeRange = self.getActualMergeRange(firstRun, lastRun, mergeWidth) # PoldiMerge checks that instruments are compatible, but it can be disabled (calibration measurements) - mergeCheckEnabled = self.getProperty('EnableMergeCheck').value + self._mergeCheckEnabled = self.getProperty('EnableMergeCheck').value # Get a list of output workspace names. - outputWorkspaces = self.getLoadedWorkspaceNames(year, mergeRange, mergeWidth, nameTemplate, mergeCheckEnabled) + outputWorkspaces = self.getLoadedWorkspaceNames(year, mergeRange, mergeWidth) # No workspaces, return - the algorithm will fail with an error. Additional log entry. if len(outputWorkspaces) == 0: @@ -137,16 +140,16 @@ class PoldiLoadRuns(PythonAlgorithm): return (firstRun, actualLastRun) # Load workspaces and return a list of workspaces that were actually loaded. - def getLoadedWorkspaceNames(self, year, mergeRange, mergeWidth, nameTemplate, mergeCheckEnabled): + def getLoadedWorkspaceNames(self, year, mergeRange, mergeWidth): outputWorkspaces = [] for i in range(mergeRange[0], mergeRange[1] + 1, mergeWidth): # The name of the possibly merged workspace is this the last name of the merged series. currentNameNumor = i + mergeWidth - 1 - currentTotalWsName = nameTemplate + str(currentNameNumor) + currentTotalWsName = self._nameTemplate + str(currentNameNumor) workspaceNames = [] for j in range(i, i + mergeWidth): - currentWsName = nameTemplate + str(j) + currentWsName = self._nameTemplate + str(j) # Errors are handled by writing a message to the log, so the user can check the files. try: @@ -159,14 +162,15 @@ class PoldiLoadRuns(PythonAlgorithm): if mergeWidth > 1 and len(workspaceNames) > 1: # If workspaces are not compatible, the range is skipped and the workspaces deleted. try: - PoldiMerge(workspaceNames, OutputWorkspace=currentTotalWsName, CheckInstruments=mergeCheckEnabled) + PoldiMerge(workspaceNames, OutputWorkspace=currentTotalWsName, + CheckInstruments=self._mergeCheckEnabled) except: self.log().warning( "Could not merge range [" + str(i) + ", " + str(currentNameNumor) + "], skipping.") # Delete all workspaces that contributed to the merged one. for j in range(i, i + mergeWidth - 1): - DeleteWorkspace(nameTemplate + str(j)) + DeleteWorkspace(self._nameTemplate + str(j)) # If the workspace is still valid (merging could have failed), it's appended to the output. if AnalysisDataService.doesExist(currentTotalWsName): diff --git a/Code/Mantid/Testing/SystemTests/tests/analysis/POLDILoadRunsTest.py b/Code/Mantid/Testing/SystemTests/tests/analysis/POLDILoadRunsTest.py index 3ef83e3ab85da50a1029d832c6c649d0797b63d1..8aa5c1009fe2a85a2391a1f31809e2614da1eb66 100644 --- a/Code/Mantid/Testing/SystemTests/tests/analysis/POLDILoadRunsTest.py +++ b/Code/Mantid/Testing/SystemTests/tests/analysis/POLDILoadRunsTest.py @@ -1,10 +1,10 @@ -# pylint: disable=no-init,invalid-name +# pylint: disable=no-init,invalid-name,bare-except import stresstesting from mantid.simpleapi import * from mantid.api import * import numpy as np -'''This assembly of test cases checks that the behavior of PoldiLoadRuns is correct.''' +#This assembly of test cases checks that the behavior of PoldiLoadRuns is correct. class POLDILoadRunsTest(stresstesting.MantidStressTest): def runTest(self): self.loadSingleWorkspace() @@ -54,7 +54,7 @@ class POLDILoadRunsTest(stresstesting.MantidStressTest): self.assertEquals(len(wsNames), 1) self.assertEquals(wsNames[0], "twoWorkspacesMergedReversed_data_6904") - twoWorkspacesMerged = PoldiLoadRuns(2013, 6903, 6904, 2) + PoldiLoadRuns(2013, 6903, 6904, 2, OutputWorkspace="twoWorkspacesMerged") wsMergedReversed = AnalysisDataService.retrieve("twoWorkspacesMergedReversed_data_6904") wsMerged = AnalysisDataService.retrieve("twoWorkspacesMerged_data_6904") @@ -65,14 +65,14 @@ class POLDILoadRunsTest(stresstesting.MantidStressTest): def loadWorkspacesMergeThreeNotWorking(self): try: - threeWorkspacesFail = PoldiLoadRuns(2013, 6903, 6904, 3) + PoldiLoadRuns(2013, 6903, 6904, 3, OutputWorkspace="threeWorkspacesFail") self.assertTrue(False) except: self.assertTrue(True) def loadWorkspacesNotFound(self): try: - notFound = PoldiLoadRuns(1990, 6903) + PoldiLoadRuns(1990, 6903, OutputWorkspace="notFound") self.assertTrue(False) except: self.assertTrue(True) @@ -132,4 +132,4 @@ class POLDILoadRunsTest(stresstesting.MantidStressTest): self.assertTrue(np.array_equal(left.dataY(i), right.dataY(i))) def clearAnalysisDataService(self): - AnalysisDataService.clear() \ No newline at end of file + AnalysisDataService.clear()