Skip to content

Commit 541ff9c

Browse files
authored
Refactor to use ImageIOLoadException from brainglobe_utils (#186)
* refactor to use ImageIOLoadException from brainglobe_utils * update brainglobe-utils version
1 parent 31e2111 commit 541ff9c

File tree

4 files changed

+17
-93
lines changed

4 files changed

+17
-93
lines changed

brainreg/core/exceptions.py

-66
This file was deleted.

brainreg/core/main.py

+9-19
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
from brainglobe_utils.image_io import load_any
77

88
from brainreg.core.backend.niftyreg.run import run_niftyreg
9-
from brainreg.core.exceptions import (
10-
LoadFileException,
11-
path_is_folder_with_one_tiff,
12-
)
139
from brainreg.core.utils.boundaries import boundaries
1410
from brainreg.core.utils.volume import calculate_volumes
1511

@@ -31,9 +27,6 @@ def main(
3127
save_original_orientation=False,
3228
brain_geometry="full",
3329
):
34-
if path_is_folder_with_one_tiff(target_brain_path):
35-
raise LoadFileException("single_tiff")
36-
3730
atlas = BrainGlobeAtlas(atlas)
3831
source_space = bg.AnatomicalSpace(data_orientation)
3932

@@ -54,18 +47,15 @@ def main(
5447

5548
logging.info("Loading raw image data")
5649

57-
try:
58-
target_brain = load_any(
59-
target_brain_path,
60-
scaling[1],
61-
scaling[2],
62-
scaling[0],
63-
load_parallel=load_parallel,
64-
sort_input_file=sort_input_file,
65-
n_free_cpus=n_free_cpus,
66-
)
67-
except ValueError as error:
68-
raise LoadFileException(None, error) from None
50+
target_brain = load_any(
51+
target_brain_path,
52+
scaling[1],
53+
scaling[2],
54+
scaling[0],
55+
load_parallel=load_parallel,
56+
sort_input_file=sort_input_file,
57+
n_free_cpus=n_free_cpus,
58+
)
6959

7060
target_brain = bg.map_stack_to(
7161
data_orientation, atlas.metadata["orientation"], target_brain

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ requires-python = ">=3.9"
2121
dependencies = [
2222
"brainglobe-atlasapi>=2.0.1",
2323
"brainglobe-space>=1.0.0",
24-
"brainglobe-utils>=0.4.0",
24+
"brainglobe-utils>=0.4.2",
2525
"fancylog",
2626
"numpy",
2727
"scikit-image",

tests/tests/test_unit/test_exceptions.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from pathlib import Path
33

44
import pytest
5+
from brainglobe_utils.image_io.utils import ImageIOLoadException
56

67
from brainreg.core.cli import main as brainreg_run
7-
from brainreg.core.exceptions import LoadFileException
88

99
test_data_dir = Path(__file__).parent.parent.parent / "data"
1010
one_tiff_data_dir = test_data_dir / "input" / "exceptions" / "one_tiff"
@@ -45,13 +45,13 @@ def test_mismatched_dims_error(test_output_dir):
4545
)
4646
sys.argv = brainreg_args
4747

48-
with pytest.raises(LoadFileException) as e:
48+
with pytest.raises(ImageIOLoadException) as e:
4949
brainreg_run()
5050

5151
assert (
52-
"File failed to load with brainglobe_utils.image_io. "
53-
"Ensure all image files contain the "
54-
"same number of pixels. Full traceback above." in e.value.message
52+
"Attempted to load an image sequence where individual 2D "
53+
"images did not have the same shape. Please ensure all image "
54+
"files contain the same number of pixels." in e.value.message
5555
)
5656

5757

@@ -60,7 +60,7 @@ def test_one_tiff_data_dir(test_output_dir):
6060
Test case in which a single 2D image is in the folder,
6161
which is not supported.
6262
63-
Some tiffs load as a zero-size array, wheras others
63+
Some tiffs load as a zero-size array, whereas others
6464
load as a 2D array (well, 3D array with a singleton).
6565
Test both cases here.
6666
"""
@@ -70,7 +70,7 @@ def test_one_tiff_data_dir(test_output_dir):
7070

7171
sys.argv = brainreg_args
7272

73-
with pytest.raises(LoadFileException) as e:
73+
with pytest.raises(ImageIOLoadException) as e:
7474
brainreg_run()
7575

7676
assert (

0 commit comments

Comments
 (0)