Skip to content

Commit

Permalink
feat: protect against non 3D data
Browse files Browse the repository at this point in the history
  • Loading branch information
seankmartin committed Nov 21, 2023
1 parent 3e141bc commit d223309
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cryo_et_neuroglancer/segmentation_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def create_segmentation_chunk(
) -> Chunk:
"""Convert data in a dask array to a neuroglancer segmentation chunk"""
bz, by, bx = block_size
if len(data.shape) != 3:
raise ValueError("Data must be 3-dimensional")
gz, gy, gx = get_grid_size_from_block_shape(data.shape, block_size)
stored_lookup_tables: dict[bytes, tuple[int, int]] = {}
# big enough to hold the 64-bit starting block headers
Expand Down
2 changes: 2 additions & 0 deletions src/cryo_et_neuroglancer/write_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def main(
for c in create_segmentation(dask_data, block_size):
c.write_to_directory(output_directory / data_directory)

if len(dask_data.chunksize) != 3:
raise ValueError(f"Expected 3 chunk dimensions, got {len(dask_data.chunksize)}")
metadata = _create_metadata(
dask_data.chunksize, block_size, dask_data.shape, data_directory, resolution
)
Expand Down

0 comments on commit d223309

Please sign in to comment.