diff --git a/rsciio/tests/data/tiff/tiff_hamamatsu.zip b/rsciio/tests/data/tiff/tiff_hamamatsu.zip index a86986f56..3e9590a8a 100644 Binary files a/rsciio/tests/data/tiff/tiff_hamamatsu.zip and b/rsciio/tests/data/tiff/tiff_hamamatsu.zip differ diff --git a/rsciio/tests/registry.txt b/rsciio/tests/registry.txt index 884e0138b..0b4ce5778 100644 --- a/rsciio/tests/registry.txt +++ b/rsciio/tests/registry.txt @@ -487,7 +487,7 @@ 'tiff/test_rgba16.zip' 2a261b2618e7556ea733cd82d2f9954d414391ff46b4099ea24dc6b8c5930b4f 'tiff/tiff_FEI_Helios.zip' eb9e82342152ffd55024356cefdfeffc6c37159172e99e320132e9228f8c5e82 'tiff/tiff_Zeiss_SEM.zip' a4b4532fef22e9222682429dbe4723fff62e82bcaf17ad5142122c9999217950 -'tiff/tiff_hamamatsu.zip' e977af339eeeff7158c6268a7e90da1f7a03a575031f70c0549297279df8ef89 +'tiff/tiff_hamamatsu.zip' 7a01042e6b9c3b8f48822dfc543b1dde663d38de2259c53f8a80574c32908d37 'trivista/linescan.tvf' ff6b9d648901e11bd79b5964c49f7e0e6f6bff38dba061dc347baddcaa0a1f6f 'trivista/map.tvf' 1c734dcb6548236d68b8d90ea4d930c0ff2c0dd13bd58506df0a6bfd94790ab6 'trivista/spec_1s_1acc_1frame_average.tvf' b1b1ae0de7acbe53376ccdfde20159a687b18e663cc5127c569ebe0bebae5dd6 diff --git a/rsciio/tests/test_tiff.py b/rsciio/tests/test_tiff.py index f82c5c1ca..8f002e36b 100644 --- a/rsciio/tests/test_tiff.py +++ b/rsciio/tests/test_tiff.py @@ -1077,6 +1077,23 @@ def test_hamamatsu_streak_focusfile(self): np.testing.assert_allclose(s.axes_manager[0].scale, 0.01714, rtol=1e-3) np.testing.assert_allclose(s.axes_manager[0].offset, 231.0909, rtol=1e-3) + def test_hamamatsu_streak_otherfile(self): + # Test case where ScalingXScalingFile="Other" + file = "test_hamamatsu_streak_OTHER.tif" + fname = os.path.join(self.path, file) + + with pytest.warns(UserWarning): + s = hs.load(fname) + + assert s.axes_manager.signal_shape == (672, 508) + assert s.axes_manager.navigation_shape == () + assert s.data.shape == (508, 672) + assert s.axes_manager[1].units == "" + np.testing.assert_allclose(s.axes_manager[1].scale, 1.0, rtol=1e-3) + np.testing.assert_allclose(s.axes_manager[1].offset, 0.0, rtol=1e-3, atol=1e-5) + np.testing.assert_allclose(s.axes_manager[0].scale, 1.0, rtol=1e-3) + np.testing.assert_allclose(s.axes_manager[0].offset, 0.0, rtol=1e-3, atol=1e-5) + def test_hamamatsu_streak_non_uniform_load(self): file = "test_hamamatsu_streak_SCAN.tif" fname = os.path.join(self.path, file) diff --git a/rsciio/tiff/_api.py b/rsciio/tiff/_api.py index d429a801b..bf019a9bd 100644 --- a/rsciio/tiff/_api.py +++ b/rsciio/tiff/_api.py @@ -696,7 +696,11 @@ def _get_hamamatsu_streak_description(tiff, op): scaling = dict_meta["Scaling"] # Address in file where the X axis is saved - x_scale_address = int(re.findall(r"\d+", scaling["ScalingXScalingFile"])[0]) + # If x axis is "Other" it just loads the axis as pixels + if scaling["ScalingXScalingFile"].startswith("Other"): + x_scale_address = None + else: + x_scale_address = int(re.findall(r"\d+", scaling["ScalingXScalingFile"])[0]) xlen = op["ImageWidth"] # If focus mode is used there is no Y axis @@ -709,8 +713,11 @@ def _get_hamamatsu_streak_description(tiff, op): # Accessing the file as a binary fh = tiff.filehandle # Reading the x axis - fh.seek(x_scale_address, 0) - xax = np.fromfile(fh, dtype="f", count=xlen) + if x_scale_address is None: + xax = np.arange(xlen) + else: + fh.seek(x_scale_address, 0) + xax = np.fromfile(fh, dtype="f", count=xlen) if y_scale_address is None: yax = np.arange(ylen) else: diff --git a/upcoming_changes/347.bugfix.rst b/upcoming_changes/347.bugfix.rst new file mode 100644 index 000000000..d7093d14c --- /dev/null +++ b/upcoming_changes/347.bugfix.rst @@ -0,0 +1 @@ +Allow reading of Hamamatsu tiff file with ``ScalingXScalingFile="Other"``.