Skip to content

Commit

Permalink
use log10 for zero padding tiffs (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrofelder authored Nov 1, 2024
1 parent 3a909b4 commit cee4a44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit cee4a44

Please sign in to comment.