Skip to content

Commit

Permalink
refactor: Simplify data shape validation in ImageWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
rhoadesScholar committed Nov 5, 2024
1 parent 59dde48 commit 069fae5
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/cellmap_data/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,11 +916,7 @@ def __setitem__(
data: torch.Tensor | np.typing.ArrayLike | float | int, # type: ignore
) -> None:
"""Writes the given data to the image at the given center (in world units). Supports writing torch.Tensor, numpy.ndarray, and scalar data types, including for batches."""
if not isinstance(data, (int, float)):
if any(data.shape[i] > self.shape[c] for i, c in enumerate(self.axes)):
raise ValueError(
f"Image {self.path} is too small to write data of shape {data.shape}. Image shape is {self.shape}."
)

# Find vectors of coordinates in world space to write data to if necessary
if isinstance(list(coords.values())[0], int | float):
center = coords
Expand Down

0 comments on commit 069fae5

Please sign in to comment.