Skip to content

Commit

Permalink
Update .zattrs file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jingjing Wu committed Nov 20, 2024
1 parent 919a83f commit 5c67764
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions linc_convert/modalities/df/multi_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -248,7 +246,7 @@ def convert(
+ [
1.0,
(shape0[0] / shape[0]) * vxh,
(shape0[1] / shape[1]) * vxw,
(shape0[0] / shape[0]) * vxw,
],
},
{
Expand All @@ -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,
],
},
]
Expand Down

0 comments on commit 5c67764

Please sign in to comment.