From d529bed240326f99cd4e0711eb071dee9be9559f Mon Sep 17 00:00:00 2001 From: JesseMckinzie Date: Wed, 17 Jul 2024 08:38:53 -0600 Subject: [PATCH] Update dimensions and add test for 3D image --- tests/test_write.py | 68 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/tests/test_write.py b/tests/test_write.py index 1c1630d..4833369 100644 --- a/tests/test_write.py +++ b/tests/test_write.py @@ -52,8 +52,8 @@ def tearDownModule(): class TestZarrWrite(unittest.TestCase): - def test_write_zarr_2d(self): - """test_write_zarr_2d - Write zarr using TSWriter""" + def test_write_zarr_5d(self): + """test_write_zarr_5d - Write zarr using TSWriter""" br = TSReader( str(TEST_DIR.joinpath("5025551.zarr/0")), @@ -84,7 +84,7 @@ def test_write_zarr_2d(self): channels = Seq(0, 0, 1) tsteps = Seq(0, 0, 1) - bw = TSWriter(test_file_path, tmp.shape, tmp.shape, str(tmp.dtype), "ZCTYX") + bw = TSWriter(test_file_path, tmp.shape, tmp.shape, str(tmp.dtype), "TCZYX") bw.write_image_data(tmp, rows, cols, layers, channels, tsteps) bw.close() @@ -100,8 +100,56 @@ def test_write_zarr_2d(self): assert tmp.sum() == 183750394 assert tmp.shape == (1, 1, 1, 2700, 2702) - def test_write_zarr_chunk_2d(self): - """test_write_zarr_2d - Write zarr using TsWriter""" + def test_write_zarr_3d(self): + """test_write_zarr_5d - Write zarr using TSWriter""" + + br = TSReader( + str(TEST_DIR.joinpath("5025551.zarr/0")), + FileType.OmeZarr, + "", + ) + + assert br._X == 2702 + assert br._Y == 2700 + assert br._Z == 1 + assert br._C == 27 + assert br._T == 1 + + rows = Seq(0, br._Y - 1, 1) + cols = Seq(0, br._X - 1, 1) + layers = Seq(0, 0, 1) + channels = Seq(0, 0, 1) + tsteps = Seq(0, 0, 1) + tmp = br.data(rows, cols, layers, channels, tsteps) + + with tempfile.TemporaryDirectory() as dir: + # Use the temporary directory + test_file_path = os.path.join(dir, 'out/test.ome.zarr') + + rows = Seq(0, br._Y - 1, 1) + cols = Seq(0, br._X - 1, 1) + layers = Seq(0, 0, 1) + + tmp = np.expand_dims(np.squeeze(tmp), axis=0) # modify image to be 3D instead of 5D + + bw = TSWriter(test_file_path, tmp.shape, tmp.shape, str(tmp.dtype), "ZYX") + bw.write_image_data(tmp, rows, cols, layers) + bw.close() + + br = TSReader( + str(test_file_path), + FileType.OmeZarr, + "", + ) + + tmp = br.data(rows, cols, layers) + + assert tmp.dtype == np.uint8 + assert tmp.sum() == 183750394 + assert tmp.shape == (1, 1, 1, 2700, 2702) + + def test_write_zarr_chunk_5d(self): + """test_write_zarr_5d - Write zarr using TsWriter""" br = TSReader( str(TEST_DIR.joinpath("5025551.zarr/0")), @@ -130,7 +178,7 @@ def test_write_zarr_chunk_2d(self): chunk_shape = [1, 1, 1, 1350, 1351] #chunk_shape = tmp.shape print("dtype: " + str(tmp.dtype)) - bw = TSWriter(test_file_path, tmp.shape, chunk_shape, str(tmp.dtype), "ZCTYX") + bw = TSWriter(test_file_path, tmp.shape, chunk_shape, str(tmp.dtype), "TCZYX") rows = Seq(0, br._Y//2, 1) cols = Seq(0, br._X - 1, 1) @@ -171,7 +219,7 @@ def test_write_zarr_chunk_2d(self): assert tmp.sum() == 183750394 def test_write_zarr_3d(self): - """test_write_zarr_2d - Write zarr using TsWriter""" + """test_write_zarr_5d - Write zarr using TsWriter""" br = TSReader( str(TEST_DIR.joinpath("5025551.zarr/0")), @@ -204,7 +252,7 @@ def test_write_zarr_3d(self): channels = Seq(0, 2, 1) tsteps = Seq(0, 0, 1) - bw = TSWriter(test_file_path, tmp.shape, tmp.shape, str(tmp.dtype), "ZCTYX") + bw = TSWriter(test_file_path, tmp.shape, tmp.shape, str(tmp.dtype), "TCZYX") bw.write_image_data(tmp, rows, cols, layers, channels, tsteps) bw.close() @@ -222,7 +270,7 @@ def test_write_zarr_3d(self): def test_write_zarr_chunk_3d(self): - """test_write_zarr_2d - Write zarr using TsWriter""" + """test_write_zarr_5d - Write zarr using TsWriter""" br = TSReader( str(TEST_DIR.joinpath("5025551.zarr/0")), @@ -251,7 +299,7 @@ def test_write_zarr_chunk_3d(self): chunk_size = (1,1,1,2700,2702) - bw = TSWriter(test_file_path, tmp.shape, chunk_size, str(tmp.dtype), "ZCTYX") + bw = TSWriter(test_file_path, tmp.shape, chunk_size, str(tmp.dtype), "TCZYX") # write first channel rows = Seq(0, br._Y - 1, 1)