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

use log10 for zero padding tiffs #104

Merged
merged 2 commits into from
Nov 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion brainglobe_utils/IO/image/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def to_tiffs(img_volume, path_prefix, path_suffix="", extension=".tif"):
path_prefix = str(path_prefix.resolve())

z_size = img_volume.shape[0]
pad_width = int(round(z_size / 10)) + 1
pad_width = int(np.floor(np.log10(z_size)) + 1)
for i in range(z_size):
img = img_volume[i, :, :]
dest_path = (
Expand Down
15 changes: 14 additions & 1 deletion tests/tests/test_IO/test_image_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
import tifffile

from brainglobe_utils.IO.image import load, save, utils
from brainglobe_utils.IO.image import load, save, to_tiffs, utils


@pytest.fixture()
Expand Down Expand Up @@ -435,3 +435,16 @@ def test_read_with_dask_raises(tmp_path):
with pytest.raises(ValueError) as e:
load.read_with_dask(tmp_path)
assert e.match("not contain any .tif or .tiff files")


@pytest.mark.parametrize(
"z_size, expected_length",
[(10000, 5), (9999, 4), (1, 1)],
)
def test_to_tiffs_padwidth(tmp_path, z_size, expected_length):
volume = np.ones((z_size, 1, 1))
prefix = "test"
to_tiffs(volume, tmp_path / prefix)
image_path = list(tmp_path.glob("*.tif"))[0]
assert str(image_path.stem).split("_")[0] == prefix
assert len(str(image_path.stem).split("_")[1]) == expected_length
Loading