diff options
author | Gemma Fardell <47746591+gfardell@users.noreply.github.com> | 2019-11-20 09:34:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-20 09:34:58 +0000 |
commit | 1cb06ae408e413890f21e0776bed785a1111377b (patch) | |
tree | 47675e36e3f2dd21085735443a8456cbfbc8f0c5 | |
parent | a1341271589a5bd3dad0def8198c49c37d1c197d (diff) | |
download | framework-1cb06ae408e413890f21e0776bed785a1111377b.tar.gz framework-1cb06ae408e413890f21e0776bed785a1111377b.tar.bz2 framework-1cb06ae408e413890f21e0776bed785a1111377b.tar.xz framework-1cb06ae408e413890f21e0776bed785a1111377b.zip |
added default input to CentreOfRotationFinder set_slice. Added check on value input. (#419)
-rwxr-xr-x | Wrappers/Python/ccpi/processors/CenterOfRotationFinder.py | 24 | ||||
-rwxr-xr-x | 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())
|