Skip to content

Commit

Permalink
make integer array in fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
ziw-liu committed Dec 7, 2024
1 parent 976cc1c commit ac0643b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from pathlib import Path

import numpy as np
from iohub import open_ome_zarr
from pytest import TempPathFactory, fixture

if TYPE_CHECKING:
from numpy.typing import DTypeLike

channel_names = ["Phase", "Retardance", "GFP", "DAPI"]


def _build_hcs(path: Path, channel_names: list[str], zyx_shape: tuple[int, int, int]):
def _build_hcs(
path: Path,
channel_names: list[str],
zyx_shape: tuple[int, int, int],
dtype: DTypeLike,
):
dataset = open_ome_zarr(
path,
layout="hcs",
Expand All @@ -20,17 +30,15 @@ def _build_hcs(path: Path, channel_names: list[str], zyx_shape: tuple[int, int,
pos = dataset.create_position(row, col, fov)
pos.create_image(
"0",
np.random.rand(2, len(channel_names), *zyx_shape).astype(
np.float32
),
np.random.rand(2, len(channel_names), *zyx_shape).astype(dtype),
)


@fixture(scope="session")
def preprocessed_hcs_dataset(tmp_path_factory: TempPathFactory) -> Path:
"""Provides a preprocessed HCS OME-Zarr dataset."""
dataset_path = tmp_path_factory.mktemp("preprocessed.zarr")
_build_hcs(dataset_path, channel_names, (12, 256, 256))
_build_hcs(dataset_path, channel_names, (12, 256, 256), np.float32)
# U[0, 1)
expected = {"mean": 0.5, "std": 1 / np.sqrt(12), "median": 0.5, "iqr": 0.5}
norm_meta = {channel: {"dataset_statistics": expected} for channel in channel_names}
Expand All @@ -45,5 +53,5 @@ def preprocessed_hcs_dataset(tmp_path_factory: TempPathFactory) -> Path:
def small_hcs_dataset(tmp_path_factory: TempPathFactory) -> Path:
"""Provides a small, not preprocessed HCS OME-Zarr dataset."""
dataset_path = tmp_path_factory.mktemp("small.zarr")
_build_hcs(dataset_path, channel_names, (12, 64, 64))
_build_hcs(dataset_path, channel_names, (12, 64, 64), np.uint16)
return dataset_path

0 comments on commit ac0643b

Please sign in to comment.