Skip to content

Commit 7d7dcc0

Browse files
authored
Merge pull request #37926 from cailafinn/37225_helium_analyser_systest
Add System Test for HeliumAnalyserEfficiency
2 parents 53ebf69 + ca89bd9 commit 7d7dcc0

12 files changed

+130
-43
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a7f5d18984e8e55756b4bcbb70d71bdb
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11ca7e54cf2a4426db8537d332e9554b

Testing/SystemTests/tests/framework/PolarizationCorrections/DepolarizedAnalyserTransmissionTest.py

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,26 @@
55
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
66
# SPDX - License - Identifier: GPL - 3.0 +
77

8-
import systemtesting
8+
from mantid.simpleapi import DepolarizedAnalyserTransmission
9+
from SANSPolarizationCorrectionsBase import SANSPolarizationCorrectionsBase
910

10-
from mantid.api import AnalysisDataService
11-
from mantid.simpleapi import *
1211

12+
class DepolarizedAnalyzerTransmissionTest(SANSPolarizationCorrectionsBase):
13+
def __init__(self):
14+
SANSPolarizationCorrectionsBase.__init__(self)
1315

14-
class DepolarizedAnalyzerTransmissionTest(systemtesting.MantidSystemTest):
15-
def runTest(self):
16-
Load("ZOOM00038238.nxs", OutputWorkspace="mt_run")
17-
Load("ZOOM00038335.nxs", OutputWorkspace="dep_run")
18-
19-
mt_group = self._prepare_workspace("mt_run")
20-
dep_group = self._prepare_workspace("dep_run")
16+
def _run_test(self):
17+
mt_group = self._prepare_workspace("ZOOM00038238.nxs")
18+
dep_group = self._prepare_workspace("ZOOM00038335.nxs")
2119
mt = self._average_workspaces_in_group(list(mt_group))
2220
dep = self._average_workspaces_in_group(list(dep_group))
2321

2422
DepolarizedAnalyserTransmission(dep, mt, OutputWorkspace="params" "", OutputFitCurves="curves")
2523

26-
def _prepare_workspace(self, input_ws_name):
27-
converted = ConvertUnits(input_ws_name, "Wavelength", AlignBins=True, StoreInADS=False)
28-
monitor_3 = CropWorkspace(converted, StartWorkspaceIndex=2, EndWorkspaceIndex=2, StoreInADS=False)
29-
monitor_4 = CropWorkspace(converted, StartWorkspaceIndex=3, EndWorkspaceIndex=3, StoreInADS=False)
30-
return monitor_4 / monitor_3
31-
32-
def _average_workspaces_in_group(self, ws_list):
33-
return sum(ws_list) / 4
34-
35-
def validate(self):
36-
self.tolerance = 1e-5
24+
def _validate(self):
3725
result_curves = "curves"
3826
reference_curves = "DepolCurvesReference.nxs"
3927
result_params = "params"
4028
reference_params = "DepolParamsReference.nxs"
4129

42-
def validate_group(result, reference):
43-
Load(Filename=reference, OutputWorkspace=reference)
44-
compare_alg = AlgorithmManager.create("CompareWorkspaces")
45-
compare_alg.setPropertyValue("Workspace1", result)
46-
compare_alg.setPropertyValue("Workspace2", reference)
47-
compare_alg.setPropertyValue("Tolerance", str(self.tolerance))
48-
compare_alg.setChild(True)
49-
50-
compare_alg.execute()
51-
if compare_alg.getPropertyValue("Result") != "1":
52-
print("Workspaces do not match.")
53-
print(self.__class__.__name__)
54-
SaveNexus(InputWorkspace=result, Filename=f"{self.__class__.__name__}-{result}-mismatch.nxs")
55-
return False
56-
return True
57-
58-
is_curves_match = validate_group(result_curves, reference_curves)
59-
is_params_match = validate_group(result_params, reference_params)
60-
return is_curves_match and is_params_match
61-
62-
def cleanup(self):
63-
AnalysisDataService.clear()
30+
return result_curves, reference_curves, result_params, reference_params
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Mantid Repository : https://github.com/mantidproject/mantid
2+
#
3+
# Copyright © 2024 ISIS Rutherford Appleton Laboratory UKRI,
4+
# NScD Oak Ridge National Laboratory, European Spallation Source,
5+
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6+
# SPDX - License - Identifier: GPL - 3.0 +
7+
8+
from abc import ABCMeta, abstractmethod
9+
from mantid.simpleapi import HeliumAnalyserEfficiency
10+
from SANSPolarizationCorrectionsBase import SANSPolarizationCorrectionsBase
11+
12+
13+
class HeliumAnalyserEfficiencyTestBase(SANSPolarizationCorrectionsBase, metaclass=ABCMeta):
14+
def __init__(self):
15+
SANSPolarizationCorrectionsBase.__init__(self)
16+
17+
@property
18+
@abstractmethod
19+
def reference_basename(self):
20+
"""
21+
The algorithm outputs 3 workspaces. This value is the string that precedes the specific workspace's reference
22+
file.
23+
:return: The prefix all the reference files are preceded by for the given test.
24+
"""
25+
pass
26+
27+
@property
28+
@abstractmethod
29+
def input_filename(self):
30+
"""
31+
The filename to use as the input to the algorithm in this test.
32+
:return: The input workspace's filename.
33+
"""
34+
pass
35+
36+
def _run_test(self):
37+
pre_processed = self._prepare_workspace(self.input_filename)
38+
39+
HeliumAnalyserEfficiency(
40+
pre_processed, "00,10,11,01", OutputWorkspace="efficiency", OutputFitCurves="curves", OutputFitParameters="params"
41+
)
42+
43+
def _validate(self):
44+
result_eff = "efficiency"
45+
reference_eff = f"{self.reference_basename}EfficiencyReference.nxs"
46+
result_curves = "curves"
47+
reference_curves = f"{self.reference_basename}CurvesReference.nxs"
48+
result_params = "params"
49+
reference_params = f"{self.reference_basename}ParamsReference.nxs"
50+
51+
return result_eff, reference_eff, result_curves, reference_curves, result_params, reference_params
52+
53+
54+
class HeliumAnalyserEfficiencyPolarisedTest(HeliumAnalyserEfficiencyTestBase):
55+
reference_basename = "HeliumAnalyser"
56+
input_filename = "ZOOM00038249.nxs"
57+
58+
def __init__(self):
59+
HeliumAnalyserEfficiencyTestBase.__init__(self)
60+
61+
62+
class HeliumAnalyserEfficiencyUnpolarisedTest(HeliumAnalyserEfficiencyTestBase):
63+
reference_basename = "UnpolHeliumAnalyser"
64+
input_filename = "ZOOM00038253.nxs"
65+
66+
def __init__(self):
67+
HeliumAnalyserEfficiencyTestBase.__init__(self)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Mantid Repository : https://github.com/mantidproject/mantid
2+
#
3+
# Copyright © 2024 ISIS Rutherford Appleton Laboratory UKRI,
4+
# NScD Oak Ridge National Laboratory, European Spallation Source,
5+
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6+
# SPDX - License - Identifier: GPL - 3.0 +
7+
8+
from abc import ABCMeta, abstractmethod
9+
from systemtesting import MantidSystemTest
10+
from mantid.api import AnalysisDataService
11+
from mantid.simpleapi import Load, ConvertUnits, CropWorkspace
12+
13+
14+
class SANSPolarizationCorrectionsBase(MantidSystemTest, metaclass=ABCMeta):
15+
_tolerance = 1e-7
16+
17+
def runTest(self):
18+
self._run_test()
19+
20+
@abstractmethod
21+
def _run_test(self):
22+
raise NotImplementedError("_run_test() method must be implemented.")
23+
24+
@staticmethod
25+
def _prepare_workspace(input_filename):
26+
run = Load(input_filename)
27+
converted = ConvertUnits(run, "Wavelength", AlignBins=True, StoreInADS=False)
28+
monitor_3 = CropWorkspace(converted, StartWorkspaceIndex=2, EndWorkspaceIndex=2, StoreInADS=False)
29+
monitor_4 = CropWorkspace(converted, StartWorkspaceIndex=3, EndWorkspaceIndex=3, StoreInADS=False)
30+
return monitor_4 / monitor_3
31+
32+
@staticmethod
33+
def _average_workspaces_in_group(ws_list):
34+
return sum(ws_list) / len(ws_list)
35+
36+
def validate(self):
37+
return self._validate()
38+
39+
@abstractmethod
40+
def _validate(self):
41+
raise NotImplementedError("validate() method must be implemented.")
42+
43+
@staticmethod
44+
def cleanup():
45+
AnalysisDataService.clear()

Testing/SystemTests/tests/framework/PolarizationCorrections/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e4e8f8a34da3503ca94abdd7f2d4a43c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
53250098034066a9058e27bcb445958b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a3f1b65884315dd469152a2bbadf6062
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b861a0b89e71014098b482336c0c5018

0 commit comments

Comments
 (0)