Skip to content

Commit

Permalink
feat: new, safe, documented PrecomputedInfoSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
supersergiy committed Feb 2, 2025
1 parent 31939fa commit b575873
Show file tree
Hide file tree
Showing 31 changed files with 1,882 additions and 809 deletions.
5 changes: 3 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ omit =
zetta_utils/mazepa_layer_processing/**/*.py
zetta_utils/tensor_mapping/*.py
zetta_utils/tensor_mapping/**/*.py
zetta_utils/convnet/architecture/deprecated/*.py
zetta_utils/convnet/architecture/deprecated/**/*.py
zetta_utils/**/deprecated.py
zetta_utils/**/deprecated/*.py
zetta_utils/**/deprecated/**/*.py
zetta_utils/viz/*.py
zetta_utils/viz/**/*.py
zetta_utils/internal/*.py
Expand Down
2 changes: 1 addition & 1 deletion docs/source/subchunkable_apply_flow_quick_start_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Precomputed volumes require an *infofile* that contains information about things

.. collapse:: infofiles in zetta_utils

In ``zetta_utils``, infofiles are handled by ``zetta_utils.layer.volumetric.precomputed`` module, which is used by ``zetta_utils.layer.volumetric.cloudvol`` and ``zetta_utils.layer.volumetric.tensorstore`` (both instances of ``VolumetricBackend``). While changing the contents of the infofiles within Python (rather than passing in arguments into `build_cv_layer`) is outside the scope of this guide and is something that you shouldn't need to do, here is the example code for reading the content (with ``cvl`` as before):
In ``zetta_utils``, infofiles are handled by ``zetta_utils.layer.precomputed`` module, which is used by ``zetta_utils.layer.volumetric.cloudvol`` and ``zetta_utils.layer.volumetric.tensorstore`` (both instances of ``VolumetricBackend``). While changing the contents of the infofiles within Python (rather than passing in arguments into `build_cv_layer`) is outside the scope of this guide and is something that you shouldn't need to do, here is the example code for reading the content (with ``cvl`` as before):

>>> cvl.backend.get_bounds(Vec3D(4, 4, 40)) # get bound at resolution
VolumetricIndex(resolution=Vec3D(4, 4, 40), bbox=BBox3D(bounds=((0, 1048576), (0, 524288), (0, 282560)), unit='nm', pprint_px_resolution=(1, 1, 1)), chunk_id=0, allow_slice_rounding=False)
Expand Down
28 changes: 10 additions & 18 deletions scripts/assign_synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

import zetta_utils.tensor_ops.convert as convert
from zetta_utils.geometry import BBox3D, Vec3D
from zetta_utils.layer.precomputed import PrecomputedInfoSpec, PrecomputedVolumeDType
from zetta_utils.layer.volumetric import VolumetricIndex, VolumetricLayer
from zetta_utils.layer.volumetric.cloudvol import build_cv_layer
from zetta_utils.layer.volumetric.precomputed import PrecomputedInfoSpec

# Configuration
resolution = Vec3D(8, 8, 42) # working resolution
Expand All @@ -56,28 +56,20 @@ def make_layer(
bbox: BBox3D,
resolution: Vec3D,
path: str,
data_type: str = "int32",
data_type: PrecomputedVolumeDType = "int32",
chunk_sizes: Sequence[Sequence[int]] = [[256, 256, 32]],
) -> VolumetricLayer:
return build_cv_layer(
path=path,
on_info_exists="overwrite",
index_resolution=resolution,
info_field_overrides={
"type": "image",
"data_type": data_type,
"num_channels": 1,
"scales": [
{
"encoding": "raw",
"resolution": list(resolution),
"size": list(bbox.shape),
"chunk_sizes": chunk_sizes,
"voxel_offset": list(bbox.start),
"key": "_".join(str(i) for i in resolution),
}
],
},
info_type="image",
info_data_type=data_type,
info_num_channels=1,
info_encoding="raw",
info_scales=[resolution],
info_chunk_size=chunk_sizes[0],
info_bbox=bbox,
cv_kwargs={"non_aligned_writes": True},
)

Expand All @@ -87,7 +79,7 @@ def load_volume(path: str, scale_index: int = 0) -> Tuple[VolumetricLayer, BBox3
Load a CloudVolume given the path, and optionally, which scale (resolution) is desired.
Return the CloudVolume, and a BBox3D describing the data bounds.
"""
spec = PrecomputedInfoSpec(reference_path=path)
spec = PrecomputedInfoSpec(info_path=path)
info = spec.make_info()
assert info is not None
scale = info["scales"][scale_index]
Expand Down
26 changes: 8 additions & 18 deletions scripts/find_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from zetta_utils.geometry import BBox3D, Vec3D
from zetta_utils.layer.volumetric import VolumetricIndex, VolumetricLayer
from zetta_utils.layer.volumetric.cloudvol import build_cv_layer
from zetta_utils.layer.volumetric.precomputed import PrecomputedInfoSpec
from zetta_utils.layer.volumetric.deprecated import PrecomputedInfoSpec

client: CAVEclient

Expand Down Expand Up @@ -290,24 +290,14 @@ def find_contact_clusters(cell_ids, cell1, cell2, n=2):
data_resolution=resolution,
allow_slice_rounding=True,
interpolation_mode="segmentation",
info_voxel_offset=volume_index.start,
info_dataset_size=volume_index.shape,
info_chunk_size=[128, 128, 40],
info_type="segmentation",
info_data_type="int32",
info_num_channels=1,
on_info_exists="overwrite",
info_add_scales_ref={
"chunk_sizes": [128, 128, 40],
"encoding": "raw",
"resolution": resolution,
"size": volume_index.shape,
"voxel_offset": volume_index.start,
},
info_add_scales=[resolution],
# info_add_scales_mode = 'replace',
info_field_overrides={
"type": "segmentation",
"data_type": "int32",
"num_channels": 1,
},
info_scales=[resolution],
info_encoding="raw",
info_chunk_size=[128, 128, 40],
info_bbox=volume_index.bbox,
)
enable_stdout()
shape = (1, *volume_index.shape)
Expand Down
Loading

0 comments on commit b575873

Please sign in to comment.