neuroglancer_scripts.chunk_encoding module¶
Encoding / decoding of Neuroglancer precomputed chunks.
The central component here is the ChunkEncoder base class. Use
get_encoder() for instantiating a concrete encoder object.
- class neuroglancer_scripts.chunk_encoding.ChunkEncoder(data_type, num_channels)[source]¶
Bases:
objectEncode/decode chunks from NumPy arrays to byte buffers.
- Parameters:
- decode(buf, chunk_size)[source]¶
Decode a chunk from bytes into a NumPy array.
- Parameters:
- Returns:
chunk contained in a 4-D NumPy array (C, Z, Y, X)
- Return type:
- Raises:
InvalidFormatError – if there the chunk data cannot be decoded properly
- encode(chunk)[source]¶
Encode a chunk from a NumPy array into bytes.
- Parameters:
chunk (numpy.ndarray) – array with four dimensions (C, Z, Y, X)
- Returns:
encoded chunk
- Return type:
- lossy = False¶
True if this encoder is lossy.
- mime_type = 'application/octet-stream'¶
MIME type of the encoded chunk.
- class neuroglancer_scripts.chunk_encoding.CompressedSegmentationEncoder(data_type, num_channels, block_size)[source]¶
Bases:
ChunkEncoderCodec for to the Neuroglancer precomputed chunk format.
- Parameters:
- Raises:
IncompatibleEncoderError – if data_type or num_channels are unsupported
- decode(buf, chunk_size)[source]¶
Decode a chunk from bytes into a NumPy array.
- Parameters:
- Returns:
chunk contained in a 4-D NumPy array (C, Z, Y, X)
- Return type:
- Raises:
InvalidFormatError – if there the chunk data cannot be decoded properly
- encode(chunk)[source]¶
Encode a chunk from a NumPy array into bytes.
- Parameters:
chunk (numpy.ndarray) – array with four dimensions (C, Z, Y, X)
- Returns:
encoded chunk
- Return type:
- lossy = False¶
True if this encoder is lossy.
- exception neuroglancer_scripts.chunk_encoding.IncompatibleEncoderError[source]¶
Bases:
ExceptionRaised when an Encoder cannot handle the requested data type.
- exception neuroglancer_scripts.chunk_encoding.InvalidFormatError[source]¶
Bases:
ExceptionRaised when chunk data cannot be decoded properly.
- exception neuroglancer_scripts.chunk_encoding.InvalidInfoError[source]¶
Bases:
ExceptionRaised when an info dict is invalid or inconsistent.
- class neuroglancer_scripts.chunk_encoding.JpegChunkEncoder(data_type, num_channels, jpeg_quality=95, jpeg_plane='xy')[source]¶
Bases:
ChunkEncoderCodec for to the Neuroglancer raw chunk format.
- Parameters:
- Raises:
IncompatibleEncoderError – if data_type or num_channels are unsupported
- decode(buf, chunk_size)[source]¶
Decode a chunk from bytes into a NumPy array.
- Parameters:
- Returns:
chunk contained in a 4-D NumPy array (C, Z, Y, X)
- Return type:
- Raises:
InvalidFormatError – if there the chunk data cannot be decoded properly
- encode(chunk)[source]¶
Encode a chunk from a NumPy array into bytes.
- Parameters:
chunk (numpy.ndarray) – array with four dimensions (C, Z, Y, X)
- Returns:
encoded chunk
- Return type:
- lossy = True¶
True if this encoder is lossy.
- mime_type = 'image/jpeg'¶
MIME type of the encoded chunk.
- class neuroglancer_scripts.chunk_encoding.RawChunkEncoder(data_type, num_channels)[source]¶
Bases:
ChunkEncoderCodec for to the Neuroglancer raw chunk format.
- Parameters:
- decode(buf, chunk_size)[source]¶
Decode a chunk from bytes into a NumPy array.
- Parameters:
- Returns:
chunk contained in a 4-D NumPy array (C, Z, Y, X)
- Return type:
- Raises:
InvalidFormatError – if there the chunk data cannot be decoded properly
- encode(chunk)[source]¶
Encode a chunk from a NumPy array into bytes.
- Parameters:
chunk (numpy.ndarray) – array with four dimensions (C, Z, Y, X)
- Returns:
encoded chunk
- Return type:
- lossy = False¶
True if this encoder is lossy.
- neuroglancer_scripts.chunk_encoding.add_argparse_options(parser, allow_lossy=False)[source]¶
Add command-line options for chunk encoding.
- Parameters:
parser – an instance of
argparse.ArgumentParserallow_lossy (bool) – show parameters for lossy encodings (i.e. jpeg)
The extrinsic encoder parameters can be obtained from command-line arguments with
add_argparse_options()and passed toget_encoder():import argparse parser = argparse.ArgumentParser() add_argparse_options(parser) args = parser.parse_args() get_encoder(info, scale_info, vars(args))
- neuroglancer_scripts.chunk_encoding.get_encoder(info, scale_info, encoder_options={})[source]¶
Create an Encoder object for the provided scale.
- Parameters:
info (dict) – a Neuroglancer info dictionary (The Neuroglancer info file) containing general encoding parameters (
data_typeandnum_channels)scale_info (dict) – an element of (
info["scales"]) containing scale-specific encoding parameters (encodingand encoding-specific parameters)encoder_options (dict) – extrinsic encoder parameters
- Returns:
an instance of a chunk encoder
- Return type:
- Raises:
InvalidInfoError – if the provided info dict is invalid