Skip to content

API reference

cave_mapper.map_points(points, root_id, client, initial_distance=0, max_distance=4, verbose=False, *, point_offset=None, convention='round', timestamp=None, lru_bytes=int(100000000.0))

Map points in space to voxels and their corresponding supervoxels.

Each point goes to a voxel (see convention). If that voxel is not part of root_id, the search grows one voxel shell at a time, up to max_distance, and keeps the nearest voxel of the root in the first shell that holds one.

The chunkedgraph calls use the client's own retry settings. For long runs, raise them before building the client, for example caveclient.set_session_defaults(max_retries=10, backoff_factor=1, backoff_max=240, status_forcelist=(429, 500, 502, 503, 504)). The segmentation reads are retried by CloudFiles.

Parameters:

Name Type Description Default
points ndarray

Array of points in space to be mapped. Must be of shape (n_points, 3), and are assumed to be in coordinates of nanometers.

required
root_id int

The root id of the object to map to.

required
client CAVEclient

The CAVEclient object to use for mapping.

required
initial_distance int

The initial distance to search for a mapping. Default is 0. Units are in voxels.

0
max_distance int

The maximum distance to search for a mapping. Default is 4. Units are in voxels.

4
verbose

Whether to print progress messages.

False
point_offset

Nanometers added to every point before the voxel conversion. None adds nothing. "mesh" adds mesh_point_offset, for points taken from the object's mesh, which sits half a mesh voxel off the voxel grid.

None
convention str

How a point becomes a voxel. "floor" is the voxel that holds the point, as CloudVolume and the CAVE materialization engine do it. "round" (the default, for backward compatibility) treats i * res as the voxel center.

'round'
timestamp

The time for the get_roots calls. None uses the end of the root's lifetime (or now, for a latest root), so any time the root is valid gives the same answer.

None
lru_bytes int

Size of the CloudVolume chunk cache. Points close together share chunks.

int(100000000.0)

Returns:

Type Description
DataFrame

A DataFrame with one row per point, in the input order. A point with no voxel of the root within max_distance has nulls. Columns:

  • query_pt_x, query_pt_y, query_pt_z: The original points in space.
  • voxel_pt_x, voxel_pt_y, voxel_pt_z: The corresponding voxel coordinates. Units are the same as client.chunkedgraph.base_resolution.
  • anchor_pt_x, anchor_pt_y, anchor_pt_z: The voxel's minimum corner in nanometers, voxel * resolution. A floor lookup of this point, as the materialization engine does it, returns the same voxel at any annotation resolution that divides the segmentation resolution.
  • supervoxel_id: The supervoxel id of the corresponding voxel.
  • root_id: The root id of the object.
  • query_voxel_distance_nm: The distance from the offset point to the center of the chosen voxel (under convention).
  • search_distance: The shell the voxel was found in, in voxels. 0 means the point's own voxel.

cave_mapper.map_points_via_mesh(points, root_id, client, max_distance=4, verbose=False)

Map points in space to a mesh and then to voxels and their corresponding supervoxels.

Parameters:

Name Type Description Default
points ndarray

Array of points in space to be mapped. Must be of shape (n_points, 3), and are assumed to be in coordinates of nanometers.

required
root_id int

The root id of the object to map to.

required
client CAVEclient

The CAVEclient object to use for mapping.

required
max_distance int

The maximum distance to search for a mapping. Default is 4. Units are in voxels.

4
verbose

Whether to print progress messages.

False

Returns:

Type Description
DataFrame

A DataFrame containing the mapping information. The DataFrame will have the following columns:

  • query_pt_x, query_pt_y, query_pt_z: The original points in space.
  • mesh_pt_x, mesh_pt_y, mesh_pt_z: The closest points on the mesh.
  • voxel_pt_x, voxel_pt_y, voxel_pt_z: The corresponding voxel coordinates. Units are the same as client.chunkedgraph.base_resolution.
  • supervoxel_id: The supervoxel id of the corresponding voxel.
  • root_id: The root id of the object.
  • query_mesh_distance_nm: The distance from the original point to the closest point on the mesh.
  • mesh_voxel_distance_nm: The distance from the closest point on the mesh to the corresponding voxel.

cave_mapper.mesh_point_offset(cv)

The offset, in nanometers, to add to a point taken from a mesh before looking up the voxel that holds it.

Meshes are built from a downsampled segmentation (the mesh "mip") and sit half a voxel of that mip off the voxel grid. This returns that half voxel, resolution(mesh_mip) / 2.

Measured on MICrONS (minnie65_phase3_v1, mesh mip 2): the shift is about (15, 8, 19) nm, against (16, 16, 20) from this rule. With the rule and convention="floor", deep points inside spine meshes landed on the root 100% and 99.8% of the time on three cells, against 96% to 98% for medoids with round. On H01 (h01_c3_flat, mesh mip 2) the measured shift is about (3, 6, 15) nm, against (16, 16, 16.5). The rule still gave 99.58% there, against 99.68% for the measured offset and 99.34% for none.

Parameters:

Name Type Description Default
cv CloudVolume

The segmentation CloudVolume. Its mesh info must name the mesh mip.

required

Returns:

Type Description
ndarray

Array of shape (3,), in nanometers.

cave_mapper.points_to_voxels(points, resolution, convention='round')

Convert points in nanometers to mip-0 voxel indices.

convention="floor" is the voxel that holds the point: voxel i covers [i * res, (i + 1) * res). CloudVolume, Neuroglancer and the CAVE materialization engine all use it. convention="round" is the older behavior of this package, which treats i * res as the voxel center.