Skip to content

Commit

Permalink
feat: ✨ Allow write to array with scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
rhoadesScholar committed Oct 30, 2024
1 parent bbce0cc commit bd0ce55
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/cellmap_data/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,17 @@ def array(self) -> xarray.DataArray:
array = array_future.result()
data = xt._TensorStoreAdapter(array)
self._array = xarray.DataArray(data=data, coords=self.full_coords)

# Set the metadata for the Zarr array
ds = zarr.open_array(self.path)
for key, value in self.metadata.items():
ds.attrs[key] = value
ds.attrs["_ARRAY_DIMENSIONS"] = self.metadata["axes"]
ds.attrs["dimension_units"] = [
f"{s} {u}"
for s, u in zip(self.metadata["voxel_size"], self.metadata["units"])
]

return self._array

@property
Expand Down Expand Up @@ -899,9 +910,10 @@ def __setitem__(
raise NotImplementedError(
"Writing to specific coordinates is not yet implemented."
)
# if isinstance(data, torch.Tensor):
# data = data.cpu().numpy()
self.array.loc[coords] = data.cpu().squeeze().numpy().astype(self.dtype)
if isinstance(data, torch.Tensor):
data = data.cpu()

self.array.loc[coords] = np.array(data).squeeze().astype(self.dtype)

def __repr__(self) -> str:
"""Returns a string representation of the ImageWriter object."""
Expand Down

0 comments on commit bd0ce55

Please sign in to comment.