Skip to content
Snippets Groups Projects
Commit a78deb0c authored by Anton Piccardo-Selg's avatar Anton Piccardo-Selg
Browse files

Refs #12946 Fix unit tests for centre finder

parent 5d99bdac
No related branches found
No related tags found
No related merge requests found
......@@ -1108,15 +1108,14 @@ def FindBeamCentre(rlow, rupp, MaxIter = 10, xstart = None, ystart = None, toler
coord2_step = COORD2STEP,
tolerance = tolerance)
# Produce the initial position
# Produce the initial position
COORD1NEW, COORD2NEW = centre_positioner.produce_initial_position()
centre = CentreFinder(original, find_direction)
# Produce a logger for this the Beam Centre Finder
beam_center_logger = BeamCenterLogger(centre_reduction,
coord1_scale_factor,
coord2_scale_factor,
position_type = find_direction)
coord2_scale_factor)
beam_center_logger.report_init(COORD1NEW, COORD2NEW)
......@@ -1399,6 +1398,7 @@ def is_current_workspace_an_angle_workspace():
@returns true if it is an angle workspace else false
'''
is_angle = False
# pylint: disable=bare-except
try:
is_angle = is_workspace_which_requires_angle(reducer = ReductionSingleton())
except:
......
#pylint: disable=invalid-name
import isis_reducer
from isis_reduction_steps import StripEndNans
from isis_instrument import LARMOR
from mantid.simpleapi import *
......@@ -41,6 +40,7 @@ def get_bench_rotation(reducer):
@returns the bench rotation in degrees
'''
bench_rotation = 0.0
# pylint: disable=bare-except
try:
ws = mtd[str(reducer.get_sample().get_wksp_name())]
bench_rotation = reducer.instrument.getDetValues(ws)[0]
......@@ -730,9 +730,9 @@ class BeamCenterLogger(object):
'''
Logger during the beam centre operation. The logging will
depend partially on the type of the first coordinate, ie [m, m] or [degree, m].
It will also perform a correction for a
It will also perform a correction for potential offsets like bench rotations.
'''
def __init__(self, reducer, coord1_scale_factor, coord2_scale_factor, position_type):
def __init__(self, reducer, coord1_scale_factor, coord2_scale_factor):
super(BeamCenterLogger, self).__init__()
self.logger = Logger("CentreFinder")
self.using_angle = False
......@@ -791,7 +791,7 @@ class BeamCenterLogger(object):
'''
# We need to substract the offset from the coordinate, since we do not want to display the offset
# which is on the data
val1 = (coord1 - self.offset_coord1)* self.coord1_scale_factor
val1 = (coord1 - self.offset_coord1)* self.coord1_scale_factor
val2 = (coord2 - self.offset_coord2)* self.coord2_scale_factor
coord1str = str(val1).ljust(10)[0:9]
coord2str = str(val2).ljust(10)[0:9]
......@@ -814,8 +814,8 @@ class BeamCenterLogger(object):
@param coord2: the second coordinate
'''
# We shouldn't need an offset correction at this point as a possible.
# Also we need to multiply both entries with the same (1000) scaling,
# Because the first coordinate should have been corrected before
# Also we need to multiply both entries with the same (1000) scaling,
# Because the first coordinate should have been corrected before
# being passed into this method. For reporting purposes we revert this
# correction. Also we don't need to remove the offset, since it the input
# already has it removed.
......
......@@ -19,15 +19,12 @@ class SANSBeamCentrePositionUpdater(unittest.TestCase):
# Act
x_new, y_new = position_updater.increment_position(x, y, x_step, y_step)
x_out, y_out = position_updater.produce_final_position(x_new, x, y_new, y)
# Assert
x_expected = 1.1
y_expected = 2.2
self.assertEqual(x_expected, x_new, "The x value should have been incremented.")
self.assertEqual(y_expected, y_new, "The y value should have been incremented.")
self.assertEqual(x_expected, x_out, "The x output should not be the initial value.")
self.assertEqual(y_expected, y_out, "The y output should not be the initial value.")
def test_that_find_LEFTRIGHT_produces_correct_increment(self):
# Arrange
......@@ -40,15 +37,12 @@ class SANSBeamCentrePositionUpdater(unittest.TestCase):
# Act
x_new, y_new = position_updater.increment_position(x, y, x_step, y_step)
x_out, y_out = position_updater.produce_final_position(x_new, x, y_new, y)
# Assert
x_expected = 1.1
y_expected = 2.0
self.assertEqual(x_expected, x_new, "The x value should have been incremented.")
self.assertEqual(y_expected, y_new, "The y value should have been incremented.")
self.assertEqual(x_expected, x_out, "The x output should not be the initial value.")
self.assertEqual(y_expected, y_out, "The y output should not be the initial value.")
def test_that_find_UPPDOWN_produces_correct_increment(self):
# Arrange
......@@ -61,15 +55,12 @@ class SANSBeamCentrePositionUpdater(unittest.TestCase):
# Act
x_new, y_new = position_updater.increment_position(x, y, x_step, y_step)
x_out, y_out = position_updater.produce_final_position(x_new, x, y_new, y)
# Assert
x_expected = 1.0
y_expected = 2.2
self.assertEqual(x_expected, x_new, "The x value should have been incremented.")
self.assertEqual(y_expected, y_new, "The y value should have been incremented.")
self.assertEqual(x_expected, x_out, "The x output should not be the initial value.")
self.assertEqual(y_expected, y_out, "The y output should not be the initial value.")
class TestPositionProvider(unittest.TestCase):
workspace_name = 'dummy_ws'
......@@ -122,8 +113,9 @@ class TestPositionProvider(unittest.TestCase):
reducer = self._provide_reducer(is_larmor)
# Act
factory = cf.PositionProviderFactory(increment_coord1 = increment_coord1,
increment_coord2 = increment_coord2,
tolerance = tolerance)
increment_coord2 = increment_coord2,
tolerance = tolerance,
position_type = cf.FindDirectionEnum.ALL)
provider = factory.create_position_provider(reducer = reducer)
# Asssert
self.assertTrue(isinstance(provider, cf.PositionProviderXY), "Should create a XY increment provider")
......@@ -141,7 +133,8 @@ class TestPositionProvider(unittest.TestCase):
# Act
factory = cf.PositionProviderFactory(increment_coord1 = increment_coord1,
increment_coord2 = increment_coord2,
tolerance = tolerance)
tolerance = tolerance,
position_type = cf.FindDirectionEnum.ALL)
provider = factory.create_position_provider(reducer = reducer)
# Asssert
......@@ -160,7 +153,8 @@ class TestPositionProvider(unittest.TestCase):
# Act
factory = cf.PositionProviderFactory(increment_coord1 = increment_coord1,
increment_coord2 = increment_coord2,
tolerance = tolerance)
tolerance = tolerance,
position_type = cf.FindDirectionEnum.ALL)
provider = factory.create_position_provider(reducer = reducer)
# Asssert
......
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