Skip to content
Snippets Groups Projects
Commit 598e8aa8 authored by Michael Wedel's avatar Michael Wedel
Browse files

Refs #11285. Fixing some pylint problems

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