Skip to content

Commit 3f5311f

Browse files
authored
Merge pull request #4 from den-sq/main
Address TIFF file loading.
2 parents d8e6715 + 2af5021 commit 3f5311f

File tree

5 files changed

+40
-17
lines changed

5 files changed

+40
-17
lines changed

.github/workflows/pr-coverage.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ on:
33
pull_request:
44
branches:
55
- main
6+
7+
env:
8+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
9+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
10+
611
jobs:
712
coverage:
813
runs-on: ubuntu-latest

python/ouroboros/helpers/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def get_sorted_tif_files(directory):
9494
files = os.listdir(directory)
9595

9696
# Filter to include only .tif files and sort them numerically
97-
tif_files = sorted((file for file in files if file.endswith(".tif")))
97+
tif_files = sorted((file for file in files if file.endswith((".tif", ".tiff"))))
9898

9999
return tif_files
100100

python/ouroboros/pipeline/backproject_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
9191

9292
# Save the straightened volume to a new tif file
9393
with tifffile.TiffWriter(new_straightened_volume_path) as tif:
94-
if straightened_volume_path.endswith(".tif"):
94+
if straightened_volume_path.endswith((".tif", ".tiff")):
9595
# Read the single tif file
9696
with tifffile.TiffFile(straightened_volume_path) as tif_in:
9797
for i in range(len(tif_in.pages)):

python/test/helpers/test_files.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from pathlib import Path
23
from tifffile import imwrite
34
from ouroboros.helpers.files import (
45
format_backproject_output_file,
@@ -22,9 +23,16 @@ def test_load_and_save_tiff_from_slices(tmp_path):
2223
slices_folder = tmp_path / "slices"
2324
slices_folder.mkdir()
2425

26+
input_names = [slices_folder / f"slice_{i:03d}.tif" for i in range(5)]
27+
28+
# Change some names to .tiff to ensure both .tif and .tiff are read.
29+
from random import randrange
30+
for i in [randrange(5) for j in range(2)]:
31+
input_names[i] = input_names[i].with_suffix('.tiff')
32+
2533
# Create some sample tiff files
26-
for i in range(5):
27-
imwrite(slices_folder / f"slice_{i:03d}.tif", data=[[i]])
34+
for name in input_names:
35+
imwrite(name, data=[[i]])
2836

2937
output_file_path = tmp_path / "output.tif"
3038
load_and_save_tiff_from_slices(
@@ -44,36 +52,46 @@ def test_load_and_save_tiff_from_slices(tmp_path):
4452

4553

4654
def test_get_sorted_tif_files(tmp_path):
55+
import random
56+
4757
# Generate some sample tiff files
48-
filenames = [f"{i:03d}.tif" for i in range(101)]
49-
original_filenames = filenames.copy()
58+
filenames = [Path(tmp_path, f"{i:03d}.tif") for i in range(101)]
5059

51-
# Randomize the order
52-
import random
60+
# Ensure both .tif and .tiff files are handled.
61+
for i in [random.randrange(101) for j in range(35)]:
62+
filenames[i] = filenames[i].with_suffix('.tiff')
63+
64+
original_filenames = [path.name for path in filenames]
5365

66+
# Randomize the order
5467
random.shuffle(filenames)
5568

5669
# Create the files
57-
for filename in filenames:
58-
(tmp_path / filename).touch()
70+
for path in filenames:
71+
path.touch()
5972

6073
sorted_files = get_sorted_tif_files(str(tmp_path))
6174
assert sorted_files == original_filenames
6275

6376

6477
def test_get_sorted_tif_files_prefix(tmp_path):
78+
import random
79+
6580
# Generate some sample tiff files
66-
filenames = [f"slice_{i:03d}.tif" for i in range(101)]
67-
original_filenames = filenames.copy()
81+
filenames = [Path(tmp_path, f"slice_{i:03d}.tif") for i in range(101)]
6882

69-
# Randomize the order
70-
import random
83+
# Ensure both .tif and .tiff files are handled.
84+
for i in [random.randrange(101) for j in range(35)]:
85+
filenames[i] = filenames[i].with_suffix('.tiff')
86+
87+
original_filenames = [path.name for path in filenames]
7188

89+
# Randomize the order
7290
random.shuffle(filenames)
7391

7492
# Create the files
75-
for filename in filenames:
76-
(tmp_path / filename).touch()
93+
for path in filenames:
94+
path.touch()
7795

7896
sorted_files = get_sorted_tif_files(str(tmp_path))
7997
assert sorted_files == original_filenames

src/renderer/src/components/MenuPanel/components/FileExplorer/components/DraggableEntry/DraggableEntry.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function DraggableEntry({
2020
handleChange: (event: InputEvent) => void
2121
}): JSX.Element {
2222
// Determine the type of the entry
23-
const type = node.children ? 'folder' : node.name.endsWith('.tif') ? 'image' : 'file'
23+
const type = node.children ? 'folder' : (node.name.endsWith('.tif') || node.name.endsWith('.tiff')) ? 'image' : 'file'
2424
const isFolder = type === 'folder'
2525
const isEmpty = !node.children || Object.keys(node.children).length === 0
2626

0 commit comments

Comments
 (0)