Skip to content
Snippets Groups Projects
Commit 59c27dc7 authored by Jose Borreguero's avatar Jose Borreguero
Browse files

Add FixY property add unit test

parent fa99886e
No related branches found
No related tags found
No related merge requests found
......@@ -136,9 +136,10 @@ class CorelliPowderCalibrationCreate(DataProcessorAlgorithm):
self.setPropertySettings("SourceMaxTranslation",
EnabledWhenProperty("AdjustSource", PropertyCriterion.IsNotDefault))
property_names = ['FixSource', 'SourceToSampleDistance', 'AdjustSource', 'SourceMaxTranslation']
[self.setPropertyGroup(name, 'Source Position') for name in property_names]
[self.setPropertyGroup(name, 'Source Calibration') for name in property_names]
# AlignComponents properties
self.declareProperty(name='FixY', defaultValue=True, doc="Vertical bank position is left unchanged")
self.declareProperty(StringArrayProperty('ComponentList', values=self._banks, direction=Direction.Input),
doc='Comma separated list on banks to refine')
self.declareProperty(name='ComponentMaxTranslation', defaultValue=0.02,
......@@ -146,7 +147,7 @@ class CorelliPowderCalibrationCreate(DataProcessorAlgorithm):
self.declareProperty(name='ComponentMaxRotation', defaultValue=3.0,
doc='Maximum rotation of each component along either of the X, Y, Z axes (deg)')
property_names = ['ComponentList', 'ComponentMaxTranslation', 'ComponentMaxRotation']
[self.setPropertyGroup(name, 'AlignComponents') for name in property_names]
[self.setPropertyGroup(name, 'Banks Calibration') for name in property_names]
def PyExec(self):
temporary_workspaces = []
......@@ -238,6 +239,7 @@ class CorelliPowderCalibrationCreate(DataProcessorAlgorithm):
# The instrument in `input_workspace` is adjusted in-place
dt = self.getProperty('ComponentMaxTranslation').value # maximum translation along either axis
dr = self.getProperty('ComponentMaxRotation').value # maximum rotation along either axis
move_y = False if self.getProperty('FixY').value is True else True
kwargs = dict(InputWorkspace=input_workspace,
OutputWorkspace=input_workspace,
PeakCentersTofTable=peak_centers_in_tof,
......@@ -248,7 +250,7 @@ class CorelliPowderCalibrationCreate(DataProcessorAlgorithm):
FitSamplePosition=False,
ComponentList=self.getProperty('ComponentList').value,
Xposition=True, MinXPosition=-dt, MaxXPosition=dt,
Yposition=True, MinYPosition=-dt, MaxYPosition=dt,
Yposition=move_y, MinYPosition=-dt, MaxYPosition=dt,
Zposition=True, MinZPosition=-dt, MaxZPosition=dt,
AlphaRotation=True, MinAlphaRotation=-dr, MaxAlphaRotation=dr,
BetaRotation=True, MinBetaRotation=-dr, MaxBetaRotation=dr,
......
......@@ -10,12 +10,14 @@ import unittest
from mantid.api import mtd
from mantid.simpleapi import (
CorelliPowderCalibrationCreate, CreateSampleWorkspace, MoveInstrumentComponent, RotateInstrumentComponent)
CorelliPowderCalibrationCreate, CreateSampleWorkspace, DeleteWorkspace, MoveInstrumentComponent,
RotateInstrumentComponent)
class CorelliPowderCalibrationCreateTest(unittest.TestCase):
def test_exec(self):
def setUp(self) -> None:
r"""Fixture runs at the beginning of every test method"""
# Single 10x10 rectangular detector, located 5m downstream the sample
CreateSampleWorkspace(WorkspaceType="Event", Function="Powder Diffraction", XMin=300, XMax=16666.7, BinWidth=1,
NumBanks=1, NumEvents=100000, PixelSpacing=0.02, OutputWorkspace="test_workspace",
......@@ -23,30 +25,41 @@ class CorelliPowderCalibrationCreateTest(unittest.TestCase):
# The detector ID at the center of the detector panel is detector-ID = 155, corresponding to workspace index 55.
# When the detector panel is placed perpendicular to the X axis and five meters away from the sample,
# detector-ID 155 shows nine peaks with the following peak-centers, in d-spacing (Angstroms) units:
spacings_reference = [0.304670, 0.610286, 0.915385, 1.220476, 1.525575, 1.830671, 2.135765, 2.44092, 2.74598]
self.spacings_reference = [0.304670, 0.610286, 0.915385, 1.220476, 1.525575,
1.830671, 2.135765, 2.44092, 2.74598]
# We select these d-spacings as the reference d-spacings
# Place the detector at a position and orientation close, but not equal to, perpendicular to the X axis
# 5 meters from the sample
RotateInstrumentComponent(Workspace='test_workspace', ComponentName='bank1', X=0.1, Y=99, z=0.1, Angle=88,
# and meters from the sample
# First we rotate almost 90 degrees around an axis almost parallel to the vertical direction
RotateInstrumentComponent(Workspace='test_workspace', ComponentName='bank1', X=0.1, Y=0.99, z=0.1, Angle=88,
RelativeRotation=True)
# Second, we move the bank
MoveInstrumentComponent(Workspace='test_workspace', ComponentName='bank1', X=4.98, y=-0.12, z=0.08,
RelativePosition=False)
self.workspace = 'test_workspace'
def tearDown(self) -> None:
r"""Fixture runs at the end of every test method"""
DeleteWorkspace(self.workspace)
def test_exec(self):
# Both FixSource=True, AdjustSource=True can't be True
try:
CorelliPowderCalibrationCreate(
InputWorkspace='test_workspace', OutputWorkspacesPrefix='cal_',
TofBinning=[300, 1.0, 16666.7], PeakPositions=spacings_reference, FixSource=True, AdjustSource=True,
ComponentList='bank1', ComponentMaxTranslation=0.2, ComponentMaxRotation=10)
InputWorkspace=self.workspace, OutputWorkspacesPrefix='cal_',
TofBinning=[300, 1.0, 16666.7], PeakPositions=self.spacings_reference, FixSource=True,
AdjustSource=True, FixY=False, ComponentList='bank1', ComponentMaxTranslation=0.2,
ComponentMaxRotation=10)
except RuntimeError as error:
assert 'Some invalid Properties found' in str(error)
# Both FixSource=True, AdjustSource=True can't be False
try:
CorelliPowderCalibrationCreate(
InputWorkspace='test_workspace', OutputWorkspacesPrefix='cal_',
TofBinning=[300, 1.0, 16666.7], PeakPositions=spacings_reference, FixSource=False, AdjustSource=False,
ComponentList='bank1', ComponentMaxTranslation=0.2, ComponentMaxRotation=10)
InputWorkspace=self.workspace, OutputWorkspacesPrefix='cal_',
TofBinning=[300, 1.0, 16666.7], PeakPositions=self.spacings_reference, FixSource=False,
AdjustSource=False, FixY=False, ComponentList='bank1', ComponentMaxTranslation=0.2,
ComponentMaxRotation=10)
except RuntimeError as error:
assert 'Some invalid Properties found' in str(error)
......@@ -55,9 +68,9 @@ class CorelliPowderCalibrationCreateTest(unittest.TestCase):
# a result, the final position and orientation is not exactly perpendicular to the X-axis and positioned
# five meters away from the sample.
CorelliPowderCalibrationCreate(
InputWorkspace='test_workspace', OutputWorkspacesPrefix='cal_',
TofBinning=[300, 1.0, 16666.7], PeakPositions=spacings_reference, SourceToSampleDistance=10.0,
ComponentList='bank1', ComponentMaxTranslation=0.2, ComponentMaxRotation=10)
InputWorkspace=self.workspace, OutputWorkspacesPrefix='cal_',
TofBinning=[300, 1.0, 16666.7], PeakPositions=self.spacings_reference, SourceToSampleDistance=10.0,
FixY=False, ComponentList='bank1', ComponentMaxTranslation=0.2, ComponentMaxRotation=10)
# Check source position
row = mtd['cal_adjustments'].row(0)
assert_allclose([row[name] for name in ('Xposition', 'Yposition', 'Zposition')], [0., 0., -10.0], atol=0.001)
......@@ -70,6 +83,17 @@ class CorelliPowderCalibrationCreateTest(unittest.TestCase):
target_orientation, atol=0.05)
assert_allclose(row['RotationAngle'], target_rotation, atol=2.0)
def test_fix_y(self) -> None:
r"""Pass option FixY=True"""
CorelliPowderCalibrationCreate(
InputWorkspace=self.workspace, OutputWorkspacesPrefix='cal_',
TofBinning=[300, 1.0, 16666.7], PeakPositions=self.spacings_reference, SourceToSampleDistance=10.0,
FixY=True, ComponentList='bank1', ComponentMaxTranslation=0.2, ComponentMaxRotation=10)
self.assertAlmostEqual()
# Check Y-position of first bank hasn't changed
row = mtd['cal_adjustments'].row(1)
self.assertAlmostEquals(row['Yposition'], -0.12, places=5)
if __name__ == '__main__':
unittest.main()
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