Skip to content

Commit

Permalink
Update dimensions and add test for 3D image
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseMckinzie committed Jul 17, 2024
1 parent 15f9aa2 commit d529bed
Showing 1 changed file with 58 additions and 10 deletions.
68 changes: 58 additions & 10 deletions tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -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()

Expand All @@ -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")),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")),
Expand Down Expand Up @@ -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()

Expand All @@ -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")),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d529bed

Please sign in to comment.