-
Notifications
You must be signed in to change notification settings - Fork 122
/
POLDITruncateDataTest.py
82 lines (59 loc) · 2.92 KB
/
POLDITruncateDataTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pylint: disable=no-init,invalid-name
import stresstesting
from mantid.simpleapi import *
# This test checks that the results of PoldiAutoCorrelation match the expected outcome.
class POLDITruncateDataTest(stresstesting.MantidStressTest):
def runTest(self):
self.dataFileName = "poldi2013n006903"
self.loadDataFiles()
self.workingAnalysis()
self.workspaceAlreadyCorrect()
self.workspaceTooSmall()
def loadDataFiles(self,):
LoadSINQFile(Instrument='POLDI',Filename=self.dataFileName + ".hdf",OutputWorkspace=self.dataFileName)
LoadInstrument(Workspace=self.dataFileName, InstrumentName="POLDI")
def workingAnalysis(self):
# In this method the "normal behavior" is tested, if everything is
# running as expected.
currentWs = mtd[self.dataFileName]
# Input data has 10 extra bins
self.assertEqual(len(currentWs.readX(0)), 510)
# First without keeping the additional data
truncated = PoldiTruncateData(currentWs)
self.assertEqual(truncated.getNumberHistograms(), currentWs.getNumberHistograms())
self.assertEqual(len(truncated.readX(0)), 500)
# now keeping the additional data
truncated = PoldiTruncateData(currentWs, ExtraCountsWorkspaceName="extra")
self.assertTrue(mtd.doesExist("extra"))
extraWs = mtd['extra']
self.assertEqual(extraWs.getNumberHistograms(), 1)
extraCounts = extraWs.readY(0)
self.assertEqual(len(extraCounts), 10)
# there are 13 counts in the first bin
self.assertEqual(extraCounts[0], 13.0)
# and none in the others
for y in extraCounts[1:]:
self.assertEqual(y, 0.0)
def workspaceAlreadyCorrect(self):
# This method tests expected behavior if the workspace
# already has the correct size
currentWs = mtd[self.dataFileName]
cropped = CropWorkspace(currentWs, XMax=1497.0)
self.assertEqual(len(cropped.readX(0)), 500)
truncated = PoldiTruncateData(cropped)
self.assertEqual(len(truncated.readX(0)), len(cropped.readX(0)))
# Now there are no extra bins.
truncated = PoldiTruncateData(cropped, ExtraCountsWorkspaceName="moreCounts")
# "extraCounts" should not be in the analysis data service
self.assertTrue(not mtd.doesExist("moreCounts"))
def workspaceTooSmall(self):
# When the workspace is too small, the whole analysis fails.
# This is reasonable since the timing information is then
# very likely to be incorrect, so that the data file is not usable
currentWs = mtd[self.dataFileName]
cropped = CropWorkspace(currentWs, XMax=1197.0)
self.assertEqual(len(cropped.readX(0)), 400)
truncated = PoldiTruncateData(cropped)
self.assertTrue(truncated is None)
PoldiTruncateData(InputWorkspace=cropped, OutputWorkspace="NamedWorkspaceTest")
self.assertTrue(not mtd.doesExist("NamedWorkspaceTest"))