2024-10-04 01:51:34 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import Callable, Tuple, Union
|
2024-02-03 06:45:50 +00:00
|
|
|
|
2024-04-23 02:31:56 +00:00
|
|
|
import numpy as np
|
2024-02-03 06:45:50 +00:00
|
|
|
import pytest
|
2024-04-30 02:49:38 +00:00
|
|
|
import zarr
|
2024-04-23 02:31:56 +00:00
|
|
|
|
|
|
|
from numpydantic.interface.hdf5 import H5ArrayPath
|
2024-04-30 02:49:38 +00:00
|
|
|
from numpydantic.interface.zarr import ZarrArrayPath
|
2024-10-04 07:46:49 +00:00
|
|
|
from numpydantic.testing import ValidationCase
|
|
|
|
from numpydantic.testing.interfaces import HDF5Case, HDF5CompoundCase, VideoCase
|
2024-05-15 03:18:04 +00:00
|
|
|
|
|
|
|
|
2024-04-23 02:31:56 +00:00
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def hdf5_array(
|
2024-09-27 02:58:27 +00:00
|
|
|
request, tmp_output_dir_func
|
2024-04-23 02:31:56 +00:00
|
|
|
) -> Callable[[Tuple[int, ...], Union[np.dtype, type]], H5ArrayPath]:
|
|
|
|
|
|
|
|
def _hdf5_array(
|
2024-09-02 23:45:56 +00:00
|
|
|
shape: Tuple[int, ...] = (10, 10),
|
|
|
|
dtype: Union[np.dtype, type] = float,
|
|
|
|
compound: bool = False,
|
2024-04-23 02:31:56 +00:00
|
|
|
) -> H5ArrayPath:
|
2024-10-04 07:46:49 +00:00
|
|
|
if compound:
|
|
|
|
array: H5ArrayPath = HDF5CompoundCase.make_array(
|
|
|
|
shape, dtype, tmp_output_dir_func
|
|
|
|
)
|
|
|
|
return array
|
2024-09-02 23:45:56 +00:00
|
|
|
else:
|
2024-10-04 07:46:49 +00:00
|
|
|
return HDF5Case.make_array(shape, dtype, tmp_output_dir_func)
|
2024-04-23 02:31:56 +00:00
|
|
|
|
|
|
|
return _hdf5_array
|
2024-04-30 02:49:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def zarr_nested_array(tmp_output_dir_func) -> ZarrArrayPath:
|
|
|
|
"""Zarr array within a nested array"""
|
|
|
|
file = tmp_output_dir_func / "nested.zarr"
|
|
|
|
path = "a/b/c"
|
|
|
|
root = zarr.open(str(file), mode="w")
|
2024-10-04 02:57:54 +00:00
|
|
|
_ = root.zeros(path, shape=(100, 100), chunks=(10, 10))
|
2024-04-30 02:49:38 +00:00
|
|
|
return ZarrArrayPath(file=file, path=path)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def zarr_array(tmp_output_dir_func) -> Path:
|
|
|
|
file = tmp_output_dir_func / "array.zarr"
|
|
|
|
array = zarr.open(str(file), mode="w", shape=(100, 100), chunks=(10, 10))
|
|
|
|
array[:] = 0
|
|
|
|
return file
|
2024-09-03 01:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
2024-09-26 01:15:27 +00:00
|
|
|
def avi_video(tmp_output_dir_func) -> Callable[[Tuple[int, int], int, bool], Path]:
|
2024-09-03 01:13:28 +00:00
|
|
|
|
|
|
|
def _make_video(shape=(100, 50), frames=10, is_color=True) -> Path:
|
2024-10-04 07:46:49 +00:00
|
|
|
shape = (frames, *shape)
|
2024-09-03 01:13:28 +00:00
|
|
|
if is_color:
|
|
|
|
shape = (*shape, 3)
|
2024-10-04 07:46:49 +00:00
|
|
|
return VideoCase.array_from_case(
|
|
|
|
ValidationCase(shape=shape, dtype=np.uint8), tmp_output_dir_func
|
|
|
|
)
|
2024-09-03 01:13:28 +00:00
|
|
|
|
2024-09-03 01:20:55 +00:00
|
|
|
return _make_video
|