From 75436aca03e5b9209f0f5f7190b106b894b28c6c Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Tue, 20 Aug 2024 15:09:40 +0200 Subject: [PATCH] close #578 --- src/fabio/edfimage.py | 7 ++++++- src/fabio/fabioimage.py | 3 ++- src/fabio/test/codecs/test_edfimage.py | 23 +++++++++++++++++++++ src/fabio/test/codecs/test_edfimage_expg.py | 1 - 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/fabio/edfimage.py b/src/fabio/edfimage.py index cac617cc7..200138e7c 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 343d19e67..8420e19c6 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 47535b572..8099674b9 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()