From 1cb06ae408e413890f21e0776bed785a1111377b Mon Sep 17 00:00:00 2001 From: Gemma Fardell <47746591+gfardell@users.noreply.github.com> Date: Wed, 20 Nov 2019 09:34:58 +0000 Subject: added default input to CentreOfRotationFinder set_slice. Added check on value input. (#419) --- .../ccpi/processors/CenterOfRotationFinder.py | 24 +++++++++++----------- Wrappers/Python/test/test_DataProcessor.py | 5 ++++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Wrappers/Python/ccpi/processors/CenterOfRotationFinder.py b/Wrappers/Python/ccpi/processors/CenterOfRotationFinder.py index 11b640f..f9ed19d 100755 --- a/Wrappers/Python/ccpi/processors/CenterOfRotationFinder.py +++ b/Wrappers/Python/ccpi/processors/CenterOfRotationFinder.py @@ -43,9 +43,9 @@ class CenterOfRotationFinder(DataProcessor): #DataProcessor.__init__(self, **kwargs) super(CenterOfRotationFinder, self).__init__(**kwargs) - def set_slice(self, slice): + def set_slice(self, slice_index='centre'): """ - Set the slice to run over in a 3D data set. + Set the slice to run over in a 3D data set. The default will use the centre slice. Input is any valid slice index or 'centre' """ @@ -53,21 +53,21 @@ class CenterOfRotationFinder(DataProcessor): if dataset is None: raise ValueError('Please set input data before slice selection') + + if dataset.number_of_dimensions == 2: + print('Slice number not a valid parameter of a 2D data set') #check slice number is valid - if dataset.number_of_dimensions == 3: - if slice == 'centre': - slice = dataset.get_dimension_size('vertical')//2 - - elif slice >= dataset.get_dimension_size('vertical'): + elif dataset.number_of_dimensions == 3: + if slice_index == 'centre': + slice_index = dataset.get_dimension_size('vertical')//2 + elif not isinstance(slice_index, (int)): + raise TypeError("Invalid input. Expect integer slice index.") + elif slice_index >= dataset.get_dimension_size('vertical'): raise ValueError("Slice out of range must be less than {0}"\ .format(dataset.get_dimension_size('vertical'))) - elif dataset.number_of_dimensions == 2: - if slice is not None: - raise ValueError('Slice number not a valid parameter of a 2D data set') - - self.slice_number = slice + self.slice_number = slice_index def check_input(self, dataset): #check dataset diff --git a/Wrappers/Python/test/test_DataProcessor.py b/Wrappers/Python/test/test_DataProcessor.py index 55f38d3..1666ea8 100755 --- a/Wrappers/Python/test/test_DataProcessor.py +++ b/Wrappers/Python/test/test_DataProcessor.py @@ -64,7 +64,7 @@ class TestDataProcessor(unittest.TestCase): print ("Center of rotation", cf.get_output()) self.assertAlmostEqual(86.25, cf.get_output()) - #def test_CenterOfRotation_slice(self): + #def test_CenterOfRotation_singleslice(self): #reader = NexusReader(self.filename) #data = reader.get_acquisition_data_whole() @@ -87,6 +87,9 @@ class TestDataProcessor(unittest.TestCase): cf.set_slice(80) print ("Center of rotation", cf.get_output()) self.assertAlmostEqual(86.25, cf.get_output()) + cf.set_slice() + print ("Center of rotation", cf.get_output()) + self.assertAlmostEqual(86.25, cf.get_output()) cf.set_slice('centre') print ("Center of rotation", cf.get_output()) self.assertAlmostEqual(86.25, cf.get_output()) -- cgit v1.2.3