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:
objectObject 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:
info (dict) – description of the dataset’s structure (see The Neuroglancer info file).
accessor (Accessor) – an object providing low-level access to the dataset’s files (see
neuroglancer_scripts.accessor.get_accessor_for_url()).encoder_options (dict) – extrinsic encoder options (see
neuroglancer_scripts.chunk_encoding.get_encoder()).
- 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:
- Returns:
chunk data contained in a 4-D NumPy array (C, Z, Y, X)
- Return type:
- Raises:
DataAccessError – if the chunk’s file cannot be accessed
InvalidFormatError – if the chunk cannot be decoded
AssertionError – if the chunk coordinates are incompatible with the dataset’s info
- 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:
- Return type:
- Raises:
DataAccessError – if the info file cannot be retrieved
InvalidInfoError – if the info file is not valid JSON
NotImplementedError – if the accessor is unable to read files
- 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:
- Raises:
DataAccessError – if the info file cannot be stored
NotImplementedError – if the accessor is unable to write files