Skip to content

Commit

Permalink
Avoid creating full mask
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley committed Mar 7, 2024
1 parent 0a832fd commit cd0c715
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sources/zarr/large_image_source_zarr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,10 @@ def addTile(self, tile, x=0, y=0, mask=None, axes=None, **kwargs):

if not mask:
mask = np.full(tile.shape, True)
full_mask = np.full(tuple(new_dims.values()), False)
mask_placement_slices = tuple([
slice(placement.get(a, 0), placement.get(a, 0) + mask.shape[i], 1)
for i, a in enumerate(axes)
])
full_mask[mask_placement_slices] = mask

current_arrays = dict(self._zarr.arrays())
with self._addLock:
Expand All @@ -580,9 +578,13 @@ def addTile(self, tile, x=0, y=0, mask=None, axes=None, **kwargs):
else:
root = current_arrays['root']
root.resize(*tuple(new_dims.values()))
data = root[:]
data = root[mask_placement_slices]
if mask is not None:
np.place(data, mask, tile)
else:
data = tile
np.place(data, full_mask, tile)
root[:] = data
root[mask_placement_slices] = data

# Edit OME metadata
self._zarr.attrs.update({
Expand Down

0 comments on commit cd0c715

Please sign in to comment.