diff --git a/sources/zarr/large_image_source_zarr/__init__.py b/sources/zarr/large_image_source_zarr/__init__.py index a19b1698a..318760260 100644 --- a/sources/zarr/large_image_source_zarr/__init__.py +++ b/sources/zarr/large_image_source_zarr/__init__.py @@ -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]) diff --git a/test/test_sink.py b/test/test_sink.py index df6e7c6ca..0aae650a2 100644 --- a/test/test_sink.py +++ b/test/test_sink.py @@ -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 @@ -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