Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hamamatsu tiff reader if x axis not calibrated #347

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified rsciio/tests/data/tiff/tiff_hamamatsu.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion rsciio/tests/registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions rsciio/tests/test_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions rsciio/tiff/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions upcoming_changes/347.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow reading of Hamamatsu tiff file with ``ScalingXScalingFile="Other"``.
Loading