From 38c21ac799a007c3e59d2e756649e29fbadc9f58 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Wed, 5 Jun 2024 17:31:17 +0100 Subject: [PATCH] Remove nrrd IO --- brainglobe_utils/IO/image/load.py | 27 +-------------------------- brainglobe_utils/IO/image/save.py | 24 +----------------------- pyproject.toml | 20 -------------------- tests/tests/test_IO/test_image_io.py | 17 ----------------- 4 files changed, 2 insertions(+), 86 deletions(-) diff --git a/brainglobe_utils/IO/image/load.py b/brainglobe_utils/IO/image/load.py index 99ecbee..318b743 100644 --- a/brainglobe_utils/IO/image/load.py +++ b/brainglobe_utils/IO/image/load.py @@ -7,7 +7,6 @@ from pathlib import Path from typing import Tuple -import nrrd import numpy as np import tifffile from dask import array as da @@ -50,7 +49,7 @@ def load_any( Parameters ---------- src_path : str or pathlib.Path - Can be the path of a nifty file, nrrd file, tiff file, tiff files + Can be the path of a nifty file, tiff file, tiff files folder, or text file containing a list of paths. x_scaling_factor : float, optional @@ -136,9 +135,6 @@ def load_any( z_scaling_factor, anti_aliasing=anti_aliasing, ) - elif src_path.suffix == ".nrrd": - logging.debug("Data type is: nrrd") - img = load_nrrd(src_path) elif src_path.suffix in [".nii", ".nii.gz"]: logging.debug("Data type is: NifTI") img = load_nii(src_path, as_array=True, as_numpy=as_numpy) @@ -150,27 +146,6 @@ def load_any( return img -def load_nrrd(src_path): - """ - Load an .nrrd file as a numpy array. - - Parameters - ---------- - src_path : str or pathlib.Path - The path of the image to be loaded. - - Returns - ------- - np.ndarray - The loaded brain array. - """ - if isinstance(src_path, Path): - src_path = str(src_path.resolve()) - - stack, _ = nrrd.read(src_path) - return stack - - def load_img_stack( stack_path, x_scaling_factor, diff --git a/brainglobe_utils/IO/image/save.py b/brainglobe_utils/IO/image/save.py index 2115f07..9dafea6 100644 --- a/brainglobe_utils/IO/image/save.py +++ b/brainglobe_utils/IO/image/save.py @@ -1,7 +1,6 @@ import warnings from pathlib import Path -import nrrd import numpy as np import tifffile @@ -99,24 +98,6 @@ def to_tiffs(img_volume, path_prefix, path_suffix="", extension=".tif"): tifffile.imwrite(dest_path, img) -def to_nrrd(img_volume, dest_path): - """ - Save the image volume (numpy array) as nrrd. - - Parameters - ---------- - img_volume : np.ndarray - The image to be saved. - - dest_path : str or pathlib.Path - The file path where to save the nrrd image. - """ - if isinstance(dest_path, Path): - dest_path = str(dest_path.resolve()) - - nrrd.write(dest_path, img_volume) - - def save_any(img_volume, dest_path): """ Save the image volume (numpy array) to the given file path, using the save @@ -130,7 +111,7 @@ def save_any(img_volume, dest_path): dest_path : str or pathlib.Path The file path to save the image to. Supports directories (will save a sequence of tiffs), .tif, .tiff, - .nrrd and .nii. + and .nii. """ dest_path = Path(dest_path) @@ -140,9 +121,6 @@ def save_any(img_volume, dest_path): elif dest_path.suffix in [".tif", ".tiff"]: to_tiff(img_volume, dest_path) - elif dest_path.suffix == ".nrrd": - to_nrrd(img_volume, dest_path) - elif dest_path.suffix == ".nii": to_nii(img_volume, dest_path) diff --git a/pyproject.toml b/pyproject.toml index abfeb36..170eae8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,6 @@ dependencies = [ "pandas", "psutil", "pyarrow", - "pynrrd", "PyYAML", "scikit-image", "scipy", @@ -82,20 +81,6 @@ exclude = ["tests", "docs*"] [tool.pytest.ini_options] addopts = "--cov=brainglobe_utils" -filterwarnings = [ - "error", - # Emitted by scikit-image on import, see https://github.com/scikit-image/scikit-image/issues/6663 - # This filter should be removed when scikit-image 0.20 is released - "ignore:`np.bool8` is a deprecated alias for `np.bool_`", - # Emitted by nptyping, see https://github.com/ramonhagenaars/nptyping/issues/102 - # for upstream issue - "ignore:`np.object0` is a deprecated alias for ``np.object0`", - "ignore:`np.int0` is a deprecated alias for `np.intp`", - "ignore:`np.uint0` is a deprecated alias for `np.uintp`", - "ignore:`np.void0` is a deprecated alias for `np.void`", - "ignore:`np.bytes0` is a deprecated alias for `np.bytes_`", - "ignore:`np.str0` is a deprecated alias for `np.str_`", -] [tool.black] target-version = ['py39', 'py310', 'py311'] @@ -115,11 +100,6 @@ select = ["I", "E", "F"] [tool.mypy] ignore_errors = true -# [[tool.mypy.overrides]] -# module = ["imlib.cells.*"] -# ignore_errors = false -# strict = true - [tool.tox] legacy_tox_ini = """ [tox] diff --git a/tests/tests/test_IO/test_image_io.py b/tests/tests/test_IO/test_image_io.py index 6e67f04..55fe6e2 100644 --- a/tests/tests/test_IO/test_image_io.py +++ b/tests/tests/test_IO/test_image_io.py @@ -276,29 +276,12 @@ def test_nii_read_to_numpy(tmp_path, array_3d): np.testing.assert_array_equal(reloaded_array, array_3d) -@pytest.mark.parametrize("use_path", [True, False], ids=["Path", "String"]) -def test_nrrd_io(tmp_path, array_3d, use_path): - """ - Test that a 3D image can be written and read correctly as nrrd, using both - str and pathlib.Path input. - """ - filename = "test_array.nrrd" - if use_path: - nrrd_path = tmp_path / filename - else: - nrrd_path = str(tmp_path / filename) - - save.to_nrrd(array_3d, nrrd_path) - assert (load.load_nrrd(nrrd_path) == array_3d).all() - - @pytest.mark.parametrize("use_path", [True, False], ids=["Path", "String"]) @pytest.mark.parametrize( "file_name", [ "test_array.tiff", "test_array.tif", - "test_array.nrrd", "test_array.nii", pytest.param("", id="dir of tiffs"), ],