Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated .zattrs file #18

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 39 additions & 43 deletions linc_convert/modalities/df/multi_slice.py
Original file line number Diff line number Diff line change
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, ...]

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,
]
print("")

# Write OME-Zarr multiscale metadata
print("Write metadata")
Expand All @@ -231,8 +229,6 @@ 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:]
multiscales[0]["datasets"].append({})
level = multiscales[0]["datasets"][-1]
level["path"] = str(n)
Expand All @@ -247,17 +243,17 @@ def convert(
"scale": [1.0] * has_channel
+ [
1.0,
(shape0[0] / shape[0]) * vxh,
(shape0[1] / shape[1]) * vxw,
float(2**n) * vxh,
float(2**n) * vxw,
],
},
{
"type": "translation",
"translation": [0.0] * has_channel
+ [
0.0,
(shape0[0] / shape[0] - 1) * vxh * 0.5,
(shape0[1] / shape[1] - 1) * vxw * 0.5,
float(2**n - 1) * vxh * 0.5,
float(2**n - 1) * vxw * 0.5,
],
},
]
Expand Down
Loading