neuroglancer_scripts.accessor module¶
Low-level file access to Neuroglancer pre-computed datasets.
The central component here is the Accessor base class. Use
get_accessor_for_url() for instantiating a concrete accessor object.
- class neuroglancer_scripts.accessor.Accessor[source]¶
Bases:
objectAccess a Neuroglancer pre-computed pyramid.
An accessor encapsulates access to the files that form a Neuroglancer pre-computed dataset. It works with sequences of bytes, without interpreting the file contents.
You can inherit from this class in order to implement a new accessor (see
FileAccessor,HttpAccessor).- can_read = False¶
This accessor is able to read data.
- can_write = False¶
This accessor is able to write data.
- fetch_chunk(key, chunk_coords)[source]¶
Fetch a chunk from the pyramid as a bytes buffer.
- Parameters:
- Returns:
the data for the chunk (uncompressed for gzip)
- Return type:
- Raises:
DataAccessError – if the chunk cannot be retrieved
NotImplementedError – if
can_readis False
- fetch_file(relative_path)[source]¶
Fetch a file relative to the precomputed pyramid’s base directory.
- Parameters:
relative_path (str) – path to the file relative to the base directory of the pyramid
- Returns:
contents of the fetched file
- Return type:
- Raises:
DataAccessError – if the requested file cannot be retrieved
NotImplementedError – if
can_readis False
- file_exists(relative_path)[source]¶
Test existence of a file relative to the base directory.
- Parameters:
relative_path (str) – path to the file relative to the base directory of the pyramid
- Returns:
True if the file exists
- Return type:
- Raises:
DataAccessError – if an error occurs when probing file existence
NotImplementedError – if
can_readis False
- store_chunk(buf, key, chunk_coords, mime_type='application/octet-stream', overwrite=False)[source]¶
Store a chunk in the pyramid from a bytes buffer.
- Parameters:
- Raises:
DataAccessError – if the chunk cannot be stored
NotImplementedError – if
can_writeis False
- store_file(relative_path, buf, mime_type='application/octet-stream', overwrite=False)[source]¶
Store a file relative to the precomputed pyramid’s base directory.
- Parameters:
- Raises:
DataAccessError – if the info file cannot be retrieved
NotImplementedError – if
can_writeis False
- exception neuroglancer_scripts.accessor.DataAccessError[source]¶
Bases:
ExceptionException indicating an error with access to a data resource.
- exception neuroglancer_scripts.accessor.URLError[source]¶
Bases:
ExceptionException indicating an invalid or unsupported URL.
- neuroglancer_scripts.accessor.add_argparse_options(parser, write_chunks=True, write_files=True)[source]¶
Add command-line options for file access.
- Parameters:
parser (argparse.ArgumentParser) – an argument parser
write_chunks (bool) – whether to add options for chunk writing
write_files (bool) – whether to add options for file writing
The accesor options can be obtained from command-line arguments with
add_argparse_options()and passed toget_accessor_for_url():import argparse parser = argparse.ArgumentParser() add_argparse_options(parser) args = parser.parse_args() get_accessor_for_url(url, vars(args))
- neuroglancer_scripts.accessor.convert_file_url_to_pathname(url)[source]¶
Convert a local file:// URL or plain pathname to a pathname.