Skip to content

Commit

Permalink
Merge pull request #1687 from girder/zarr-sink-subprocess
Browse files Browse the repository at this point in the history
Zarr Sink Subprocess
  • Loading branch information
annehaley authored Oct 16, 2024
2 parents ec8935e + b83d013 commit c893b6c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
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

0 comments on commit c893b6c

Please sign in to comment.