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

Refactor to use ImageIOLoadException from brainglobe_utils #186

Merged
merged 2 commits into from
Mar 25, 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
66 changes: 0 additions & 66 deletions brainreg/core/exceptions.py

This file was deleted.

28 changes: 9 additions & 19 deletions brainreg/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
from brainglobe_utils.image_io import load_any

from brainreg.core.backend.niftyreg.run import run_niftyreg
from brainreg.core.exceptions import (
LoadFileException,
path_is_folder_with_one_tiff,
)
from brainreg.core.utils.boundaries import boundaries
from brainreg.core.utils.volume import calculate_volumes

Expand All @@ -31,9 +27,6 @@ def main(
save_original_orientation=False,
brain_geometry="full",
):
if path_is_folder_with_one_tiff(target_brain_path):
raise LoadFileException("single_tiff")

atlas = BrainGlobeAtlas(atlas)
source_space = bg.AnatomicalSpace(data_orientation)

Expand All @@ -54,18 +47,15 @@ def main(

logging.info("Loading raw image data")

try:
target_brain = load_any(
target_brain_path,
scaling[1],
scaling[2],
scaling[0],
load_parallel=load_parallel,
sort_input_file=sort_input_file,
n_free_cpus=n_free_cpus,
)
except ValueError as error:
raise LoadFileException(None, error) from None
target_brain = load_any(
target_brain_path,
scaling[1],
scaling[2],
scaling[0],
load_parallel=load_parallel,
sort_input_file=sort_input_file,
n_free_cpus=n_free_cpus,
)

target_brain = bg.map_stack_to(
data_orientation, atlas.metadata["orientation"], target_brain
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ requires-python = ">=3.9"
dependencies = [
"brainglobe-atlasapi>=2.0.1",
"brainglobe-space>=1.0.0",
"brainglobe-utils>=0.4.0",
"brainglobe-utils>=0.4.2",
"fancylog",
"numpy",
"scikit-image",
Expand Down
14 changes: 7 additions & 7 deletions tests/tests/test_unit/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from pathlib import Path

import pytest
from brainglobe_utils.image_io.utils import ImageIOLoadException

from brainreg.core.cli import main as brainreg_run
from brainreg.core.exceptions import LoadFileException

test_data_dir = Path(__file__).parent.parent.parent / "data"
one_tiff_data_dir = test_data_dir / "input" / "exceptions" / "one_tiff"
Expand Down Expand Up @@ -45,13 +45,13 @@ def test_mismatched_dims_error(test_output_dir):
)
sys.argv = brainreg_args

with pytest.raises(LoadFileException) as e:
with pytest.raises(ImageIOLoadException) as e:
brainreg_run()

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


Expand All @@ -60,7 +60,7 @@ def test_one_tiff_data_dir(test_output_dir):
Test case in which a single 2D image is in the folder,
which is not supported.

Some tiffs load as a zero-size array, wheras others
Some tiffs load as a zero-size array, whereas others
load as a 2D array (well, 3D array with a singleton).
Test both cases here.
"""
Expand All @@ -70,7 +70,7 @@ def test_one_tiff_data_dir(test_output_dir):

sys.argv = brainreg_args

with pytest.raises(LoadFileException) as e:
with pytest.raises(ImageIOLoadException) as e:
brainreg_run()

assert (
Expand Down
Loading