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

Zarr Sink Subprocess #1687

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 10 additions & 8 deletions sources/zarr/large_image_source_zarr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,16 @@ def addTile(self, tile, x=0, y=0, mask=None, axes=None, **kwargs):
])
else:
arr = current_arrays[store_path]
arr.resize(*tuple(new_dims.values()))
if arr.chunks[-1] != new_dims.get('s'):
# rechunk if length of samples axis changes
chunking = tuple([
self._tileSize if a in ['x', 'y'] else
new_dims.get('s') if a == 's' else 1
for a in axes
])
new_shape = tuple(max(v, arr.shape[i]) for i, v in enumerate(new_dims.values()))
if new_shape != arr.shape:
arr.resize(*new_shape)
if arr.chunks[-1] != new_dims.get('s'):
# rechunk if length of samples axis changes
chunking = tuple([
self._tileSize if a in ['x', 'y'] else
new_dims.get('s') if a == 's' else 1
for a in axes
])

if mask is not None:
arr[placement_slices] = np.where(mask, tile, arr[placement_slices])
Expand Down
26 changes: 26 additions & 0 deletions test/test_sink.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import math
import subprocess
from multiprocessing.pool import Pool, ThreadPool
from os import sys

import large_image_source_test
import large_image_source_zarr
Expand Down Expand Up @@ -535,3 +537,27 @@ def testConcurrency(tmp_path):
assert data is not None
assert data.shape == seed_data.shape
assert np.allclose(data, seed_data)


def testSubprocess(tmp_path):
sink = large_image_source_zarr.new()
path = sink.largeImagePath
subprocess.run([sys.executable, '-c', """import large_image_source_zarr
import numpy as np
sink = large_image_source_zarr.open('%s')
sink.addTile(np.ones((1, 1, 1)), x=2047, y=2047, t=5, z=2)
""" % path], capture_output=True, text=True, check=True)
sink.addTile(np.ones((1, 1, 1)), x=5000, y=4095, t=0, z=4)

assert sink.metadata['IndexRange']['IndexZ'] == 5
assert sink.getRegion(
region=dict(left=2047, top=2047, width=1, height=1),
format='numpy',
frame=27,
)[0] == 1
assert sink.getRegion(
region=dict(left=5000, top=4095, width=1, height=1),
format='numpy',
frame=4,
)[0] == 1
assert sink.sizeX == 5001