stuart-cls / python-agilent-file-formats

Python library for reading FT-IR imaging datasets created by Resolutions Pro on Agilent Cary instruments with FPA area detectors.
MIT License
3 stars 2 forks source link

Testsuite fails on s390x (endianness problem?) #5

Open rolandmas opened 3 hours ago

rolandmas commented 3 hours ago

Hi, your friendly Debian package maintainer here. python-agilent-file-formats's testsuite fails to run on the s390x architecture. I've started to debug that, starting with test_image.py, and I believe this is due to endianness problems. By comparing data between s390x and amd64, I ended up determining that the _readint and _readdouble methods in agilent.py assume local endianness in the files even though they might not come from the same architecture.

The following patch fixes the results of these two methods, but errors remain:

index dbc1b59..0f5a93f 100644
--- a/agilent_format/agilent.py
+++ b/agilent_format/agilent.py
@@ -62,10 +62,10 @@ def dmt_path(path: Path) -> Path:
     return path.parent.joinpath(path.with_suffix(".dmt").name.lower())

 def _readint(f):
-    return struct.unpack("i", f.read(4))[0]
+    return struct.unpack("<i", f.read(4))[0]

 def _readdouble(f):
-    return struct.unpack("d", f.read(8))[0]
+    return struct.unpack("<d", f.read(8))[0]

 def _get_wavenumbers(f):
     """

Just adding the < in the other instances of struct.unpack of the same file doesn't seem to fix the tests, so I'll leave that part to you, hoping that this already helps a bit :-)

rolandmas commented 3 hours ago

If it helps:


self = <agilent_format.tests.test_image.TestImage testMethod=test_load_image>

    def test_load_image(self):
        ai = agilentImage(DAT, MAT=False)
        # Check parameters
        Npts = ai.info['Npts']
        self.assertEqual(Npts, 9)
        self.assertEqual(Npts, len(ai.wavenumbers))
        self.assertEqual(ai.wavenumbers[0], ai.info['StartPt'] * ai.info['PtSep'])
        self.assertEqual(ai.wavenumbers[-1],
                         (ai.info['StartPt'] + Npts - 1) * ai.info['PtSep'])
        self.assertEqual(ai.data.shape, (8, 8, Npts))
        self.assertEqual(ai.info['FPA Pixel Size'], 5.5)
        self.assertEqual(ai.info['PixelAggregationSize'], 16)
        self.assertEqual(ai.width, ai.data.shape[0])
        self.assertEqual(ai.height, ai.data.shape[1])
        f_bsp = str(DAT.with_suffix(".bsp"))
        self.assertEqual(ai.filename, f_bsp)
        self.assertEqual(ai.acqdate, "Tuesday, January 02, 2018 14:01:52")
        # Confirm image orientation
>       self.assertAlmostEqual(ai.data[0, 1, 1], 1.27181053)
E       AssertionError: -1.4743547e-09 != 1.27181053 within 7 places (1.2718105314743546 difference)

agilent_format/tests/test_image.py:28: AssertionError