Skip to content

Commit

Permalink
add pre-variance
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianWhitneyAI committed Sep 29, 2023
1 parent 5e5a388 commit c1d2372
Showing 1 changed file with 133 additions and 133 deletions.
266 changes: 133 additions & 133 deletions bioio_bioformats/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,43 +291,43 @@ def test_bioformats_reader(
],
(0.29, 0.10833333333333334, 0.10833333333333334),
),
pytest.param(
"variance-cfe.ome.tiff",
"3500003034_100X_20190520_1-Scene-18-P108-G03.czi #1",
("3500003034_100X_20190520_1-Scene-18-P108-G03.czi #1",),
(1, 9, 65, 600, 900),
np.uint16,
dimensions.DEFAULT_DIMENSION_ORDER,
[
"CMDRP",
"EGFP",
"H3342",
"Bright_2",
"SEG_STRUCT",
"SEG_Memb",
"SEG_DNA",
"CON_Memb",
"CON_DNA",
],
(0.29, 0.10833333333333332, 0.10833333333333332),
),
(
"actk.ome.tiff",
"IMAGE0",
("IMAGE0",),
(1, 6, 65, 233, 345),
np.float64,
dimensions.DEFAULT_DIMENSION_ORDER,
[
"nucleus_segmentation",
"membrane_segmentation",
"dna",
"membrane",
"structure",
"brightfield",
],
(0.29, 0.29, 0.29),
),
# pytest.param(
# "variance-cfe.ome.tiff",
# "3500003034_100X_20190520_1-Scene-18-P108-G03.czi #1",
# ("3500003034_100X_20190520_1-Scene-18-P108-G03.czi #1",),
# (1, 9, 65, 600, 900),
# np.uint16,
# dimensions.DEFAULT_DIMENSION_ORDER,
# [
# "CMDRP",
# "EGFP",
# "H3342",
# "Bright_2",
# "SEG_STRUCT",
# "SEG_Memb",
# "SEG_DNA",
# "CON_Memb",
# "CON_DNA",
# ],
# (0.29, 0.10833333333333332, 0.10833333333333332),
# ),
# (
# "actk.ome.tiff",
# "IMAGE0",
# ("IMAGE0",),
# (1, 6, 65, 233, 345),
# np.float64,
# dimensions.DEFAULT_DIMENSION_ORDER,
# [
# "nucleus_segmentation",
# "membrane_segmentation",
# "dna",
# "membrane",
# "structure",
# "brightfield",
# ],
# (0.29, 0.29, 0.29),
# ),
],
)
def test_bioformats_reader_large_files(
Expand Down Expand Up @@ -359,111 +359,111 @@ def test_bioformats_reader_large_files(
)


@pytest.mark.parametrize(
"filename, "
"first_scene_id, "
"first_scene_shape, "
"second_scene_id, "
"second_scene_shape",
[
(
"s_3_t_1_c_3_z_5.ome.tiff",
"s_3_t_10_c_3_z_5.czi #1",
(1, 3, 5, 325, 475),
"s_3_t_10_c_3_z_5.czi #2",
(1, 3, 5, 325, 475),
),
(
"s_3_t_1_c_3_z_5.ome.tiff",
"s_3_t_10_c_3_z_5.czi #2",
(1, 3, 5, 325, 475),
"s_3_t_10_c_3_z_5.czi #3",
(1, 3, 5, 325, 475),
),
(
"S=2_4x2_T=2=Z=3_CH=2.czi",
"S=2_4x2_T=2=Z=3_CH=2.czi #1",
(2, 2, 3, 487, 947),
"S=2_4x2_T=2=Z=3_CH=2.czi #2",
(2, 2, 3, 243, 473),
),
],
)
def test_multi_scene_bioformats_reader(
filename: str,
first_scene_id: str,
first_scene_shape: Tuple[int, ...],
second_scene_id: str,
second_scene_shape: Tuple[int, ...],
) -> None:
# Construct full filepath
uri = LOCAL_RESOURCES_DIR / filename
# @pytest.mark.parametrize(
# "filename, "
# "first_scene_id, "
# "first_scene_shape, "
# "second_scene_id, "
# "second_scene_shape",
# [
# (
# "s_3_t_1_c_3_z_5.ome.tiff",
# "s_3_t_10_c_3_z_5.czi #1",
# (1, 3, 5, 325, 475),
# "s_3_t_10_c_3_z_5.czi #2",
# (1, 3, 5, 325, 475),
# ),
# (
# "s_3_t_1_c_3_z_5.ome.tiff",
# "s_3_t_10_c_3_z_5.czi #2",
# (1, 3, 5, 325, 475),
# "s_3_t_10_c_3_z_5.czi #3",
# (1, 3, 5, 325, 475),
# ),
# (
# "S=2_4x2_T=2=Z=3_CH=2.czi",
# "S=2_4x2_T=2=Z=3_CH=2.czi #1",
# (2, 2, 3, 487, 947),
# "S=2_4x2_T=2=Z=3_CH=2.czi #2",
# (2, 2, 3, 243, 473),
# ),
# ],
# )
# def test_multi_scene_bioformats_reader(
# filename: str,
# first_scene_id: str,
# first_scene_shape: Tuple[int, ...],
# second_scene_id: str,
# second_scene_shape: Tuple[int, ...],
# ) -> None:
# # Construct full filepath
# uri = LOCAL_RESOURCES_DIR / filename

# Run checks
test_utilities.run_multi_scene_image_read_checks(
ImageContainer=Reader,
image=uri,
first_scene_id=first_scene_id,
first_scene_shape=first_scene_shape,
first_scene_dtype=np.dtype(np.uint16),
second_scene_id=second_scene_id,
second_scene_shape=second_scene_shape,
second_scene_dtype=np.dtype(np.uint16),
allow_same_scene_data=False, # checks that data is diff between scenes
)
# # Run checks
# test_utilities.run_multi_scene_image_read_checks(
# ImageContainer=Reader,
# image=uri,
# first_scene_id=first_scene_id,
# first_scene_shape=first_scene_shape,
# first_scene_dtype=np.dtype(np.uint16),
# second_scene_id=second_scene_id,
# second_scene_shape=second_scene_shape,
# second_scene_dtype=np.dtype(np.uint16),
# allow_same_scene_data=False, # checks that data is diff between scenes
# )


def test_biofile_scene_change() -> None:
"""Make sure that ResourceBackedDaskArray doesn't close an opened file."""
uri = LOCAL_RESOURCES_DIR / "ND2_dims_p4z5t3c2y32x32.nd2"
f = BioFile(uri)
assert isinstance(f.to_dask().compute(), np.ndarray)
f.set_series(1)
assert isinstance(f.to_dask().compute(), np.ndarray)
f.close()
# def test_biofile_scene_change() -> None:
# """Make sure that ResourceBackedDaskArray doesn't close an opened file."""
# uri = LOCAL_RESOURCES_DIR / "ND2_dims_p4z5t3c2y32x32.nd2"
# f = BioFile(uri)
# assert isinstance(f.to_dask().compute(), np.ndarray)
# f.set_series(1)
# assert isinstance(f.to_dask().compute(), np.ndarray)
# f.close()


@pytest.mark.parametrize("filename, ", [("CMU-1-Small-Region.svs")])
def test_bioformats_dask_tiling_shapes(filename: str) -> None:
# Construct full filepath
uri = LOCAL_RESOURCES_DIR / filename
# @pytest.mark.parametrize("filename, ", [("CMU-1-Small-Region.svs")])
# def test_bioformats_dask_tiling_shapes(filename: str) -> None:
# # Construct full filepath
# uri = LOCAL_RESOURCES_DIR / filename

# Run checks
bf_tiled = Reader(uri, dask_tiles=True)
bf_fullplane = Reader(uri, dask_tiles=False)
bf_tiled_set = Reader(uri, dask_tiles=True, tile_size=(1024, 1024))
# # Run checks
# bf_tiled = Reader(uri, dask_tiles=True)
# bf_fullplane = Reader(uri, dask_tiles=False)
# bf_tiled_set = Reader(uri, dask_tiles=True, tile_size=(1024, 1024))

np.testing.assert_array_equal(
bf_tiled.dask_data.shape, bf_fullplane.dask_data.shape
)
np.testing.assert_array_equal(
bf_tiled_set.dask_data.shape, bf_fullplane.dask_data.shape
)
np.testing.assert_array_equal(
bf_tiled.dask_data.shape, bf_fullplane.dask_data.shape
)
np.testing.assert_array_equal(bf_tiled.dask_data.chunksize, (1, 1, 1, 240, 240, 3))
np.testing.assert_array_equal(
bf_tiled_set.dask_data.chunksize, (1, 1, 1, 1024, 1024, 3)
)
# np.testing.assert_array_equal(
# bf_tiled.dask_data.shape, bf_fullplane.dask_data.shape
# )
# np.testing.assert_array_equal(
# bf_tiled_set.dask_data.shape, bf_fullplane.dask_data.shape
# )
# np.testing.assert_array_equal(
# bf_tiled.dask_data.shape, bf_fullplane.dask_data.shape
# )
# np.testing.assert_array_equal(bf_tiled.dask_data.chunksize, (1, 1, 1, 240, 240, 3))
# np.testing.assert_array_equal(
# bf_tiled_set.dask_data.chunksize, (1, 1, 1, 1024, 1024, 3)
# )


@pytest.mark.parametrize(
"filename, ",
[("s_1_t_1_c_10_z_1.ome.tiff"), ("CMU-1-Small-Region.svs")],
)
def test_bioformats_dask_tiling_read(filename: str) -> None:
# Construct full filepath
uri = LOCAL_RESOURCES_DIR / filename
# @pytest.mark.parametrize(
# "filename, ",
# [("s_1_t_1_c_10_z_1.ome.tiff"), ("CMU-1-Small-Region.svs")],
# )
# def test_bioformats_dask_tiling_read(filename: str) -> None:
# # Construct full filepath
# uri = LOCAL_RESOURCES_DIR / filename

# Run checks
bf_tiled = Reader(uri, dask_tiles=True)
bf_tiled_set = Reader(uri, dask_tiles=True, tile_size=(128, 128))
bf_fullplane = Reader(uri, dask_tiles=False)
# # Run checks
# bf_tiled = Reader(uri, dask_tiles=True)
# bf_tiled_set = Reader(uri, dask_tiles=True, tile_size=(128, 128))
# bf_fullplane = Reader(uri, dask_tiles=False)

arr_tiled = bf_tiled.dask_data.compute()
arr_fullplane = bf_fullplane.dask_data.compute()
arr_tiled_set = bf_tiled_set.dask_data.compute()
# arr_tiled = bf_tiled.dask_data.compute()
# arr_fullplane = bf_fullplane.dask_data.compute()
# arr_tiled_set = bf_tiled_set.dask_data.compute()

np.testing.assert_array_equal(arr_tiled, arr_fullplane)
np.testing.assert_array_equal(arr_tiled_set, arr_fullplane)
# np.testing.assert_array_equal(arr_tiled, arr_fullplane)
# np.testing.assert_array_equal(arr_tiled_set, arr_fullplane)

0 comments on commit c1d2372

Please sign in to comment.