neuroglancer_scripts.file_accessor module

Access to a Neuroglancer pre-computed dataset on the local filesystem.

See the accessor module for a description of the API.

class neuroglancer_scripts.file_accessor.FileAccessor(base_dir, flat=False, gzip=True, compresslevel=9)[source]

Bases: Accessor

Access a Neuroglancer pre-computed pyramid on the local file system.

Parameters:
  • base_dir (str) – path to the directory containing the pyramid

  • flat (bool) – use a flat file layout (see On-disk file layout)

  • gzip (bool) – compress chunks losslessly with gzip

can_read = True

This accessor is able to read data.

can_write = True

This accessor is able to write data.

fetch_chunk(key, chunk_coords)[source]

Fetch a chunk from the pyramid as a bytes buffer.

Parameters:
  • key (str) – the scale’s key

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

Returns:

the data for the chunk (uncompressed for gzip)

Return type:

bytes

Raises:
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:

bytes

Raises:
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:

bool

Raises:
store_chunk(buf, key, chunk_coords, mime_type='application/octet-stream', overwrite=True)[source]

Store a chunk in the pyramid from a bytes buffer.

Parameters:
  • key (str) – the scale’s key

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

  • mime_type (str) – MIME type of the chunk data

Raises:
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:
  • relative_path (str) – path to the file relative to the base directory of the pyramid

  • buf (bytes) – the contents of the file to be stored

  • mime_type (str) – MIME type of the file

  • overwrite (bool) – whether to allow overwriting an existing file

Raises: