diff --git a/impy/core.py b/impy/core.py index 2811650..7210780 100644 --- a/impy/core.py +++ b/impy/core.py @@ -834,7 +834,9 @@ def big_imread( ------- BigImgArray """ - out = lazy_imread(path, chunks=chunks, name=name, squeeze=squeeze) + from impy.lazy import imread as lazy_imread_ + + out = lazy_imread_(path, chunks=chunks, name=name, squeeze=squeeze) return BigImgArray(out.value, out.name, out.axes, out.source, out.metadata) def read_meta(path: str) -> dict[str, Any]: diff --git a/impy/lazy/random.py b/impy/lazy/random.py index 1f4e091..1419a19 100644 --- a/impy/lazy/random.py +++ b/impy/lazy/random.py @@ -166,7 +166,7 @@ def standard_exponential( def random( self, size: int | tuple[int, ...] | None = None, - dtype = None, + dtype = np.float32, *, axes: AxesLike | None = None, name: str | None = None, @@ -175,10 +175,10 @@ def random( ) -> LazyImgArray: size, name, axes = _normalize_like(size, name, axes, like) - arr = self._rng.random(size=size, dtype=dtype, chunks=chunks) + arr = self._rng.random(size=size, dtype=np.float64, chunks=chunks) if np.isscalar(arr): return arr - return asarray(arr, axes=axes, name=name) + return asarray(arr.astype(dtype, copy=False), axes=axes, name=name) def normal( self, @@ -196,7 +196,7 @@ def normal( arr = self._rng.normal(loc=loc, scale=scale, size=size, chunks=chunks) if np.isscalar(arr): return arr - return asarray(arr, axes=axes, name=name) + return asarray(arr.astype(np.float32), axes=axes, name=name) def poisson( self, diff --git a/impy/viewer/utils.py b/impy/viewer/utils.py index 69d066c..fa05059 100644 --- a/impy/viewer/utils.py +++ b/impy/viewer/utils.py @@ -5,13 +5,14 @@ import napari import os -from ..arrays import * -from .._const import Const -from ..core import imread, lazy_imread +from impy.arrays import * +from impy._const import Const +from impy.core import imread +from impy.lazy import imread as lazy_imread if TYPE_CHECKING: - from ..frame import TrackFrame, PathFrame, AxesFrame - from ..roi import Roi + from impy.frame import TrackFrame, PathFrame, AxesFrame + from impy.roi import Roi from napari.layers import Shapes diff --git a/impy/viewer/viewer.py b/impy/viewer/viewer.py index 119c57d..0a30331 100644 --- a/impy/viewer/viewer.py +++ b/impy/viewer/viewer.py @@ -19,11 +19,12 @@ make_world_scale, ) -from ..collections import * -from ..arrays import * -from ..core import array as ip_array, aslazy as ip_aslazy -from ..axes import ScaleView, AxisLike, Axes, Axis -from .._const import Const +from impy.collections import * +from impy.arrays import * +from impy.core import array as ip_array +from impy.lazy import asarray as ip_aslazy +from impy.axes import ScaleView, AxisLike, Axes, Axis +from impy._const import Const if TYPE_CHECKING: from napari.components import LayerList @@ -44,6 +45,7 @@ class napariViewers: def __init__(self): self._viewers: WeakValueDictionary[str, "napari.Viewer"] = WeakValueDictionary() self._front_viewer: str = None + self._axes: Axes = None def __repr__(self): w = "".join([f"<{k}>" for k in self._viewers.keys()]) diff --git a/rst/tutorial.rst b/rst/tutorial.rst index 80b5db4..2685b32 100644 --- a/rst/tutorial.rst +++ b/rst/tutorial.rst @@ -251,12 +251,12 @@ memory map of the image file that is split into smaller chunks, and passes it to read" state. The image data is therefore loaded only when it is needed. Many useful functions in ``ImgArray`` are also implemented in ``LazyImgArray`` so that you can easily handle large datasets. -To read large images as ``LazyImgArray``, call ``lazy_imread`` instead. You can specify its chunk size using +To read large images as ``LazyImgArray``, call ``impy.lazy.imread`` instead. You can specify its chunk size using ``chunks`` parameter. .. code-block:: python - img = ip.lazy_imread("path/to/image.tif", chunks=(1, "auto", "auto", "auto")) + img = ip.lazy.imread("path/to/image.tif", chunks=(1, "auto", "auto", "auto")) img .. code-block:: diff --git a/tests/test_lazy.py b/tests/test_lazy.py index 04f372f..e1f426f 100644 --- a/tests/test_lazy.py +++ b/tests/test_lazy.py @@ -12,7 +12,7 @@ def test_functions_and_slicing(resource): with ip.SetConst(RESOURCE=resource): path = Path(__file__).parent / "_test_images" / "image_tzcyx.tif" - img = ip.lazy_imread(path, chunks=(4, 5, 2, 32, 32)) + img = ip.lazy.imread(path, chunks=(4, 5, 2, 32, 32)) sl = "y=20:40;x=30:50;c=0;z=2,4" assert_allclose(img[sl].compute(), img.compute()[sl]) assert_allclose( @@ -27,7 +27,7 @@ def test_filters(fn, resource): return with ip.SetConst(RESOURCE=resource): path = Path(__file__).parent / "_test_images" / "image_tzcyx.tif" - img = ip.lazy_imread(path, chunks=(4, 5, 2, 32, 32)) + img = ip.lazy.imread(path, chunks=(4, 5, 2, 32, 32)) assert_allclose( getattr(img, fn)().compute(), @@ -37,7 +37,8 @@ def test_filters(fn, resource): def test_numpy_function(): from dask.array.core import Array as DaskArray - img = ip.aslazy(ip.random.random_uint16((2, 3, 4))) + rng = ip.lazy.random.default_rng(0) + img = rng.random_uint16((2, 3, 4)) assert img.axes == "tyx" assert isinstance(np.mean(img).compute(), float) proj = np.mean(img, axis="y") @@ -49,9 +50,9 @@ def test_numpy_function(): @pytest.mark.parametrize("opname", ["gt", "lt", "ge", "le", "eq", "ne"]) def test_operator(opname): op = getattr(operator, opname) - rng = ip.random.default_rng(0) - img1 = ip.aslazy(rng.random_uint16((2, 3, 4))) - img2 = ip.aslazy(rng.random_uint16((2, 3, 4))) + rng = ip.lazy.random.default_rng(0) + img1 = rng.random_uint16((2, 3, 4)) + img2 = rng.random_uint16((2, 3, 4)) assert_allclose( op(img1, img2).compute(), op(img1.compute(), img2.compute()), diff --git a/tests/test_methods.py b/tests/test_methods.py index 2cc82c8..61f6ba5 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -110,6 +110,18 @@ def test_tiled(resource): img.tiled(chunks=(40, 50, 50)).dog_filter(low_sigma=1.0, fourier=True) img.tiled(chunks=(40, 50, 50)).log_filter(sigma=1.0) +def test_lazy_tiled(resource): + with ip.SetConst(RESOURCE=resource): + rng = ip.lazy.random.default_rng(1111) + + img = rng.random(size=(120, 120, 120), axes="zyx") + img.tiled(chunks=(40, 50, 50)).lowpass_filter() + img.tiled(chunks=(40, 50, 50)).gaussian_filter(sigma=1.0) + img.tiled(chunks=(40, 50, 50)).gaussian_filter(sigma=1.0, fourier=True) + img.tiled(chunks=(40, 50, 50)).dog_filter(low_sigma=1.0) + img.tiled(chunks=(40, 50, 50)).dog_filter(low_sigma=1.0, fourier=True) + img.tiled(chunks=(40, 50, 50)).log_filter(sigma=1.0) + @pytest.mark.parametrize("order", [1, 3]) def test_drift_correction(order: int): img = ip.random.normal(size=(5, 10, 3, 120, 120), axes="tzcyx")