From 5c677643117088e0044d85d432e0eb478253dd0b Mon Sep 17 00:00:00 2001 From: Jingjing Wu Date: Wed, 20 Nov 2024 09:43:57 -0500 Subject: [PATCH 1/4] Update .zattrs file --- linc_convert/modalities/df/multi_slice.py | 84 +++++++++++------------ 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/linc_convert/modalities/df/multi_slice.py b/linc_convert/modalities/df/multi_slice.py index d66136fd..20af1ec6 100644 --- a/linc_convert/modalities/df/multi_slice.py +++ b/linc_convert/modalities/df/multi_slice.py @@ -40,7 +40,7 @@ def convert( inp: list[str], out: str | None = None, *, - chunk: int = 4096, + chunk: int = 1024, compressor: str = "blosc", compressor_opt: str = "{}", max_load: int = 16384, @@ -131,7 +131,7 @@ def convert( new_width = jp2.shape[1] new_size = (new_height, new_width) if has_channel: - new_size += (3.0,) + new_size += (3,) print(len(inp), new_size, nblevel, has_channel) # Prepare chunking options @@ -174,43 +174,41 @@ def convert( x = floordiv(shape[-2] - subdat_size[-2], 2) y = floordiv(shape[-1] - subdat_size[-1], 2) - if max_load is None or (shape[-2] < max_load and shape[-1] < max_load): - array[..., idx, x : x + subdat_size[1], y : y + subdat_size[2]] = ( - subdat[...] - ) - - else: - ni = ceildiv(shape[-2], max_load) - nj = ceildiv(shape[-1], max_load) - - for i in range(ni): - for j in range(nj): - print(f"\r{i+1}/{ni}, {j+1}/{nj}", end=" ") - start_x, end_x = ( - i * max_load, - min((i + 1) * max_load, shape[-2]), - ) - start_y, end_y = ( - j * max_load, - min((j + 1) * max_load, shape[-1]), - ) - if end_x <= x or end_y <= y: - continue - - if start_x >= subdat_size[-2] or start_y >= subdat_size[-1]: - continue - - array[ - ..., - idx, - x + start_x : x + min(end_x, subdat_size[-2]), - y + start_y : y + min(end_y, subdat_size[-1]), - ] = subdat[ - ..., - start_x : min((i + 1) * max_load, subdat_size[-2]), - start_y : min((j + 1) * max_load, subdat_size[-1]), - ] - print("") + for channel in range(3): + if max_load is None or ( + subdat_size[-2] < max_load and subdat_size[-1] < max_load + ): + array[ + channel, idx, x : x + subdat_size[-2], y : y + subdat_size[-1] + ] = subdat[channel : channel + 1, ...][0] + else: + ni = ceildiv(subdat_size[-2], max_load) + nj = ceildiv(subdat_size[-1], max_load) + + for i in range(ni): + for j in range(nj): + print(f"\r{i+1}/{ni}, {j+1}/{nj}", end=" ") + start_x, end_x = ( + i * max_load, + min((i + 1) * max_load, subdat_size[-2]), + ) + start_y, end_y = ( + j * max_load, + min((j + 1) * max_load, subdat_size[-1]), + ) + + array[ + channel, + idx, + x + start_x : x + end_x, + y + start_y : y + end_y, + ] = subdat[ + channel : channel + 1, + start_x:end_x, + start_y:end_y, + ][0] + + print("") # Write OME-Zarr multiscale metadata print("Write metadata") @@ -231,8 +229,8 @@ def convert( multiscales[0]["axes"].insert(0, {"name": "c", "type": "channel"}) for n in range(nblevel): - shape0 = omz["0"].shape[-2:] - shape = omz[str(n)].shape[-2:] + shape0 = omz['0'].shape[2:] + shape = omz[str(n)].shape[2:] multiscales[0]["datasets"].append({}) level = multiscales[0]["datasets"][-1] level["path"] = str(n) @@ -248,7 +246,7 @@ def convert( + [ 1.0, (shape0[0] / shape[0]) * vxh, - (shape0[1] / shape[1]) * vxw, + (shape0[0] / shape[0]) * vxw, ], }, { @@ -257,7 +255,7 @@ def convert( + [ 0.0, (shape0[0] / shape[0] - 1) * vxh * 0.5, - (shape0[1] / shape[1] - 1) * vxw * 0.5, + (shape0[0] / shape[0] - 1) * vxw * 0.5, ], }, ] From af4853bd9e196e100e4a2a94d5bb370d35519dbf Mon Sep 17 00:00:00 2001 From: Jingjing Wu Date: Wed, 20 Nov 2024 09:52:06 -0500 Subject: [PATCH 2/4] Updated .zattrs scale calculation process --- linc_convert/modalities/df/multi_slice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linc_convert/modalities/df/multi_slice.py b/linc_convert/modalities/df/multi_slice.py index 20af1ec6..be4d0729 100644 --- a/linc_convert/modalities/df/multi_slice.py +++ b/linc_convert/modalities/df/multi_slice.py @@ -229,7 +229,7 @@ def convert( multiscales[0]["axes"].insert(0, {"name": "c", "type": "channel"}) for n in range(nblevel): - shape0 = omz['0'].shape[2:] + shape0 = omz['0'].shape[2:] shape = omz[str(n)].shape[2:] multiscales[0]["datasets"].append({}) level = multiscales[0]["datasets"][-1] From 3b7b4de527565045323c0a5e48cb1354714b6a68 Mon Sep 17 00:00:00 2001 From: jingjingwu1225 Date: Wed, 20 Nov 2024 14:52:53 +0000 Subject: [PATCH 3/4] style fixes by ruff --- linc_convert/modalities/df/multi_slice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linc_convert/modalities/df/multi_slice.py b/linc_convert/modalities/df/multi_slice.py index be4d0729..c9dcaa2a 100644 --- a/linc_convert/modalities/df/multi_slice.py +++ b/linc_convert/modalities/df/multi_slice.py @@ -229,7 +229,7 @@ def convert( multiscales[0]["axes"].insert(0, {"name": "c", "type": "channel"}) for n in range(nblevel): - shape0 = omz['0'].shape[2:] + shape0 = omz["0"].shape[2:] shape = omz[str(n)].shape[2:] multiscales[0]["datasets"].append({}) level = multiscales[0]["datasets"][-1] From a7f4d03f681e9193ca0b96d8d33e657a3042ee68 Mon Sep 17 00:00:00 2001 From: Jingjing Wu <49615883+jingjingwu1225@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:18:07 -0500 Subject: [PATCH 4/4] Update multi_slice.py --- linc_convert/modalities/df/multi_slice.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/linc_convert/modalities/df/multi_slice.py b/linc_convert/modalities/df/multi_slice.py index c9dcaa2a..e9380f3b 100644 --- a/linc_convert/modalities/df/multi_slice.py +++ b/linc_convert/modalities/df/multi_slice.py @@ -229,8 +229,8 @@ def convert( multiscales[0]["axes"].insert(0, {"name": "c", "type": "channel"}) for n in range(nblevel): - shape0 = omz["0"].shape[2:] - shape = omz[str(n)].shape[2:] + shape0 = omz["0"].shape[-2:] + shape = omz[str(n)].shape[-2:] multiscales[0]["datasets"].append({}) level = multiscales[0]["datasets"][-1] level["path"] = str(n) @@ -246,7 +246,7 @@ def convert( + [ 1.0, (shape0[0] / shape[0]) * vxh, - (shape0[0] / shape[0]) * vxw, + (shape0[1] / shape[1]) * vxw, ], }, { @@ -255,7 +255,7 @@ def convert( + [ 0.0, (shape0[0] / shape[0] - 1) * vxh * 0.5, - (shape0[0] / shape[0] - 1) * vxw * 0.5, + (shape0[1] / shape[1] - 1) * vxw * 0.5, ], }, ]