neuroglancer_scripts.precomputed_io module

High-level access to Neuroglancer pre-computed datasets.

The central component here is the PrecomputedIO base class. Use get_IO_for_existing_dataset() or get_IO_for_new_dataset() for instantiating a concrete accessor object.

class neuroglancer_scripts.precomputed_io.PrecomputedIO(info, accessor, encoder_options={})[source]

Bases: object

Object for high-level access to a Neuroglancer precomputed dataset.

An object of this class provides access to chunk data in terms of NumPy arrays. It handles the reading/writing of files through the provided accessor, as well as the encoding/decoding of chunks.

The structure of the dataset (info) is stored in the PrecomputedIO instance and must not change during its lifetime. If you need to change the info of a dataset, use get_IO_for_new_dataset() to store the new info and create a new PrecomputedIO object.

Parameters:
property info

The precomputed dataset’s info dictionary.

read_chunk(scale_key, chunk_coords)[source]

Read a chunk from the dataset.

The chunk coordinates must be compatible with the dataset’s info. This can be checked with validate_chunk_coords().

Parameters:
  • scale_key (str) – the key attribute of the scale

  • chunk_coords (tuple) – the chunk coordinates (xmin, xmax, ymin, ymax, zmin, zmax)

Returns:

chunk data contained in a 4-D NumPy array (C, Z, Y, X)

Return type:

numpy.ndarray

Raises:
scale_info(scale_key)[source]

The info for a given scale.

Parameters:

scale_key (str) – the key property of the chosen scale.

Returns:

info["scales"][i] where info["scales"][i]["key"] == scale_key

Return type:

dict

scale_is_lossy(scale_key)[source]

Test if the scale is using a lossy encoding.

Parameters:

scale_key (str) – the key attribute of the scale

Returns:

True if the scale is using a lossy encoding

Rtype bool:

Raises:

KeyError – if the scale_key is not a valid scale of this dataset

validate_chunk_coords(scale_key, chunk_coords)[source]

Validate the coordinates of a chunk.

Returns:

True if the chunk coordinates are valid according to the dataset’s info

Rtype bool:

write_chunk(chunk, scale_key, chunk_coords)[source]

Write a chunk into the dataset.

The chunk coordinates must be compatible with the dataset’s info. This can be checked with validate_chunk_coords().

Parameters:
  • chunk (numpy.ndarray) – chunk data contained in a 4-D NumPy array (C, Z, Y, X)

  • scale_key (str) – the key attribute of the scale

  • chunk_coords (tuple) – the chunk coordinates (xmin, xmax, ymin, ymax, zmin, zmax)

Raises:
  • DataAccessError – if the chunk’s file cannot be accessed

  • AssertionError – if the chunk coordinates are incompatible with the dataset’s info

neuroglancer_scripts.precomputed_io.get_IO_for_existing_dataset(accessor, encoder_options={})[source]

Create an object for accessing a pyramid with an existing info.

Parameters:
  • accessor (Accessor) – a low-level accessor

  • encoder_options (dict) – extrinsic encoder options

Return type:

PrecomputedIO

Raises:
neuroglancer_scripts.precomputed_io.get_IO_for_new_dataset(info, accessor, overwrite_info=False, encoder_options={})[source]

Create a new pyramid and store the provided info.

Parameters:
  • info (dict) – the info of the new pyramid

  • accessor (Accessor) – a low-level accessor

  • encoder_options (dict) – extrinsic encoder options

Raises: