diff --git a/src/fabio/edfimage.py b/src/fabio/edfimage.py index cac617cc..200138e7 100644 --- a/src/fabio/edfimage.py +++ b/src/fabio/edfimage.py @@ -49,7 +49,7 @@ __contact__ = "jerome.kieffer@esrf.fr" __license__ = "MIT" __copyright__ = "ESRF" -__date__ = "01/06/2022" +__date__ = "20/08/2024" import os import re @@ -1339,6 +1339,8 @@ def fast_read_roi(self, filename, coords=None): Method reading Region of Interest of another file based on metadata available in current EdfImage. The aim is performances, ... but only supports uncompressed files. + :param filename: name of another file with the same structure. + :paran coords: 2 tuple of slices (RECOMMANDED) or a 4 tuple (NOT RECOMMANDED, cryptic fabian convention) :return: ROI-data from another file using positions from current EdfImage :rtype: numpy 2darray """ @@ -1365,6 +1367,9 @@ def fast_read_roi(self, filename, coords=None): with open(filename, "rb")as f: f.seek(start) raw = f.read(size) + if len(raw) coords[2]: diff --git a/src/fabio/test/codecs/test_edfimage.py b/src/fabio/test/codecs/test_edfimage.py index 343d19e6..8420e19c 100755 --- a/src/fabio/test/codecs/test_edfimage.py +++ b/src/fabio/test/codecs/test_edfimage.py @@ -305,6 +305,29 @@ def test_fastread(self): obt = ref.fast_read_data(self.fastFilename) self.assertEqual(abs(obt - refdata).max(), 0, "testedffastread: Same data") + def test_578(self): + "Non regression for issue 578: EDFImage.fast_read_data: cannot read a line" + + file_name = os.path.join(UtilsTest.tempdir, "test_578.edf") + # create some dummy data + edf_writer = fabio.edfimage.EdfImage( + data=numpy.arange(0, 99).reshape(9, 11), + ) + edf_writer.write(file_name) + + edf_reader = fabio.open(file_name) + + # if I want to read it line by line + line_index_to_read = 4 + line_data = edf_reader.fast_read_roi( + file_name,coords=( + slice(3, 9), + slice(line_index_to_read, line_index_to_read+1), + ), + ) + self.assertTrue(numpy.allclose(edf_writer.data[3:9,line_index_to_read:line_index_to_read+1], + line_data)) + class TestEdfWrite(unittest.TestCase): """ diff --git a/src/fabio/test/codecs/test_edfimage_expg.py b/src/fabio/test/codecs/test_edfimage_expg.py index 47535b57..8099674b 100644 --- a/src/fabio/test/codecs/test_edfimage_expg.py +++ b/src/fabio/test/codecs/test_edfimage_expg.py @@ -433,7 +433,6 @@ def test_special(self): # test files 10 and 11 for testing with to be copied and added later - def suite(): loadTests = unittest.defaultTestLoader.loadTestsFromTestCase testsuite = unittest.TestSuite()