diff --git a/CHANGELOG.md b/CHANGELOG.md index 157957909f..cc918a8569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* 23.0.1 + - Fix bug with NikonReader requiring ROI to be set in constructor. + * 23.0.0 - Partitioner is now able to create batches even if angle is not the outer dimension - Renamed `max_iteration_stop_cryterion` method in the Algorithm class to `max_iteration_stop_criterion` diff --git a/Wrappers/Python/cil/io/NikonDataReader.py b/Wrappers/Python/cil/io/NikonDataReader.py index 458c411b4a..94b8aaa371 100644 --- a/Wrappers/Python/cil/io/NikonDataReader.py +++ b/Wrappers/Python/cil/io/NikonDataReader.py @@ -102,22 +102,22 @@ def set_up(self, self.fliplr = fliplr if self.file_name is None: - raise Exception('Path to xtekct file is required.') + raise ValueError('Path to xtekct file is required.') # check if xtekct file exists if not(os.path.isfile(self.file_name)): - raise Exception('File\n {}\n does not exist.'.format(self.file_name)) + raise FileNotFoundError('File\n {}\n does not exist.'.format(self.file_name)) if os.path.basename(self.file_name).split('.')[-1].lower() != 'xtekct': raise TypeError('This reader can only process xtekct files. Got {}'.format(os.path.basename(self.file_name))) + + if self.roi is None: + self.roi= {'angle': -1, 'horizontal': -1, 'vertical': -1} # check labels for key in self.roi.keys(): if key not in ['angle', 'horizontal', 'vertical']: - raise Exception("Wrong label. One of the following is expected: angle, horizontal, vertical") - - if self.roi is None: - self.roi= {'angle': -1, 'horizontal': -1, 'vertical': -1} + raise ValueError("Wrong label. One of the following is expected: angle, horizontal, vertical") roi = self.roi.copy() diff --git a/Wrappers/Python/test/test_io.py b/Wrappers/Python/test/test_io.py index b352f6e356..41c89e8c11 100644 --- a/Wrappers/Python/test/test_io.py +++ b/Wrappers/Python/test/test_io.py @@ -24,7 +24,7 @@ import numpy as np import os from cil.framework import ImageGeometry -from cil.io import TXRMDataReader, NEXUSDataReader +from cil.io import TXRMDataReader, NEXUSDataReader, NikonDataReader, ZEISSDataReader from cil.io import TIFFWriter, TIFFStackReader from cil.io.utilities import HDF5_utilities from cil.processors import Slicer @@ -522,3 +522,37 @@ def test_read_to(self): HDF5_utilities.read_to(self.path, self.dset_path, data_partial, source_sel=subset, dest_sel=subset) np.testing.assert_allclose(data_partial_by_hand,data_partial) + + +class TestNikonReader(unittest.TestCase): + + def test_setup(self): + + reader = NikonDataReader() + self.assertEqual(reader.file_name, None) + self.assertEqual(reader.roi, None) + self.assertTrue(reader.normalise) + self.assertEqual(reader.mode, 'bin') + self.assertFalse(reader.fliplr) + + roi = {'vertical':(1,-1),'horizontal':(1,-1),'angle':(1,-1)} + reader = NikonDataReader(file_name=None, roi=roi, normalise=False, mode='slice', fliplr=True) + self.assertEqual(reader.file_name, None) + self.assertEqual(reader.roi, roi) + self.assertFalse(reader.normalise) + self.assertEqual(reader.mode, 'slice') + self.assertTrue(reader.fliplr) + + with self.assertRaises(FileNotFoundError): + reader = NikonDataReader(file_name='no-file') + + +class TestZeissReader(unittest.TestCase): + + def test_setup(self): + + reader = ZEISSDataReader() + self.assertEqual(reader.file_name, None) + + with self.assertRaises(FileNotFoundError): + reader = ZEISSDataReader(file_name='no-file')