ahds package¶
-
class
ahds.AmiraFile(fn, *args, **kwargs)[source]¶ Bases:
objectConvenience class to handle Amira (R) files
This class aggregates user-level classes from the
ahds.headerandahds.data_streammodules into a single class with a simple interfaceAmiraFile.header()for the header andAmiraFile.data_streamsdata streams attribute.
ahds.grammar module¶
Grammar to parse headers in Amira (R) files
-
class
ahds.grammar.AmiraDispatchProcessor(*args, **kwargs)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObjectClass defining methods to handle each token specified in the grammar
-
ahds.grammar.detect_format(fn, format_bytes=50, verbose=False, *args, **kwargs)[source]¶ Detect Amira (R) file format (AmiraMesh or HyperSurface)
Parameters: Return str file_format: either
AmiraMeshorHyperSurface
-
ahds.grammar.get_header(fn, file_format, header_bytes=20000, verbose=False, *args, **kwargs)[source]¶ Apply rules for detecting the boundary of the header
Parameters: Return str data: the header as per the
file_format
ahds.header module¶
Module to convert parsed data from an Amira (R) header into a set of nested objects. The key class is ahds.header.AmiraHeader.
Usage:
>>> from ahds.header import AmiraHeader
>>> ah = AmiraHeader.from_file('file.am')
>>> print ah
Each nested object is constructed from the ahds.header.Block class defined.
There are four top-level attributes that every ahds.header.AmiraHeader will have:
- designation
- definitions
- parameters
- data_pointers
Each attribute can be queried using the attrs attribute.
>>> print ah.data_pointers.attrs
['data_pointer_1', 'data_pointer_2', 'data_pointer_3', 'data_pointer_4', 'data_pointer_5', 'data_pointer_6']
>>> print ah.data_pointers.data_pointer_1
data_pointer_1
pointer_name: VERTEX
data_format: None
data_dimension: 3
data_type: float
data_name: VertexCoordinates
data_index: 1
data_length: None
Data pointers are identified by the name data_pointer_<n>.
-
class
ahds.header.AmiraHeader(parsed_data)[source]¶ Bases:
objectClass to encapsulate Amira (R) metadata
-
data_pointers¶ The list of data pointers together with a name, data type, dimension, index, format and length
-
definitions¶ Definitions consist of a key-value pair specified just after the designation preceded by the key-word ‘define’
-
designation¶ Designation of the Amira (R) file defined in the first row
Designations consist of some or all of the following data:
- filetype e.g.
AmiraMeshorHyperSurface - dimensions e.g.
3D - format e.g.
BINARY-LITTLE-ENDIAN - version e.g.
2.1 - extra format e.g.
<hxsurface>
- filetype e.g.
-
classmethod
from_file(fn, *args, **kwargs)[source]¶ Constructor to build an
ahds.header.AmiraHeaderobject from a fileParameters: fn (str) – Amira (R) file Return ah: object of class ahds.header.AmiraHeadercontaining header metadataReturn type: ah: ahds.header.AmiraHeader
-
parameters¶ The set of parameters for each of the segments specified e.g. colour, data pointer etc.
-
raw_header¶ Show the raw header data
-
ahds.data_stream module¶
data_stream
The following image shows the class hierarchy for data streams.
-
class
ahds.data_stream.AmiraDataStream(amira_header, data_pointer, stream_data)[source]¶ Bases:
objectBase class for all Amira DataStreams
-
data_pointer¶ The data pointer for this data stream
-
decoded_data¶ Decoded data for this stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
encoded_data¶ Encoded raw data in this stream
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.AmiraHxSurfaceDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.AmiraDataStreamBase class for all HyperSurface data streams that inherits from
ahds.data_stream.AmiraDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_data¶ Decoded data for this stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
encoded_data¶ Encoded raw data in this stream
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.AmiraMeshDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.AmiraDataStreamClass encapsulating an AmiraMesh data stream
-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.BoundaryCurvesDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.ValuedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.Contour(z, array)[source]¶ Bases:
objectEncapsulates the array representing a contour
-
class
ahds.data_stream.ContourSet(initlist=None)[source]¶ Bases:
UserList.UserListEncapsulation for a set of
ahds.data_stream.Contourobjects-
append(item)¶ S.append(object) – append object to the end of the sequence
-
count(value) → integer -- return number of occurrences of value¶
-
extend(other)¶ S.extend(iterable) – extend sequence by appending elements from the iterable
-
index(value) → integer -- return first index of value.¶ Raises ValueError if the value is not present.
-
insert(i, item)¶ S.insert(index, object) – insert object before index
-
pop([index]) → item -- remove and return item at index (default last).¶ Raise IndexError if list is empty or index is out of range.
-
remove(item)¶ S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
-
reverse()¶ S.reverse() – reverse IN PLACE
-
-
class
ahds.data_stream.DataStreams(fn, *args, **kwargs)[source]¶ Bases:
objectClass to encapsulate all the above functionality
-
class
ahds.data_stream.Image(z, array)[source]¶ Bases:
objectEncapsulates individual images
-
array¶ Accessor to underlying array data
-
as_contours¶ A dictionary of lists of contours keyed by byte_value
-
-
class
ahds.data_stream.ImageSet(initlist=None)[source]¶ Bases:
UserList.UserListEncapsulation for set of
ahds.data_stream.Imageobjects-
append(item)¶ S.append(object) – append object to the end of the sequence
-
count(value) → integer -- return number of occurrences of value¶
-
extend(other)¶ S.extend(iterable) – extend sequence by appending elements from the iterable
-
index(value) → integer -- return first index of value.¶ Raises ValueError if the value is not present.
-
insert(i, item)¶ S.insert(index, object) – insert object before index
-
pop([index]) → item -- remove and return item at index (default last).¶ Raise IndexError if list is empty or index is out of range.
-
remove(item)¶ S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
-
reverse()¶ S.reverse() – reverse IN PLACE
-
segments¶ A dictionary of lists of contours keyed by z-index
-
-
class
ahds.data_stream.LoadedDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.AmiraHxSurfaceDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.NBranchingPointsDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.ValuedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.NVerticesOnCurvesDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.ValuedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.NamedDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.VoidDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.PatchesBoundaryIDDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.ValuedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.PatchesBranchingPointsDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.ValuedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.PatchesDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.LoadedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.PatchesInnerRegionDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.NamedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.PatchesOuterRegionDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.NamedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.PatchesTrianglesDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.LoadedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.ValuedDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.VoidDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.VerticesDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.LoadedDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
class
ahds.data_stream.VoidDataStream(*args, **kwargs)[source]¶ Bases:
ahds.data_stream.AmiraHxSurfaceDataStream-
data_pointer¶ The data pointer for this data stream
-
decoded_length¶ The length of the decoded stream data in relevant units e.g. tuples, integers (not bytes)
-
header¶ An
ahds.header.AmiraHeaderobject
-
stream_data¶ All the raw data from the file
-
-
ahds.data_stream.byterle_decoder(data, output_size)[source]¶ Python drop-in replacement for compiled equivalent
Parameters: Return numpy.array output: an array of
numpy.uint8
-
ahds.data_stream.hxbyterle_decode(output_size, data)[source]¶ Decode HxRLE data stream
If C-extension is not compiled it will use a (slower) Python equivalent
Parameters: Return numpy.array output: an array of
numpy.uint8
-
ahds.data_stream.hxzip_decode(data_size, data)[source]¶ Decode HxZip data stream
Parameters: Return numpy.array output: an array of
numpy.uint8
-
ahds.data_stream.unpack_ascii(data)[source]¶ Unpack ASCII data using string methods``
Parameters: - data_pointer (
ahds.header.Block) – metadata for thedata_pointerattribute for this data stream - definitions (
ahds.header.Block) – definitions specified in the header - data (bytes) – raw binary data to be unpacked
Return list output: unpacked data
- data_pointer (
-
ahds.data_stream.unpack_binary(data_pointer, definitions, data)[source]¶ Unpack binary data using
struct.unpackParameters: - data_pointer (
ahds.header.Block) – metadata for thedata_pointerattribute for this data stream - definitions (
ahds.header.Block) – definitions specified in the header - data (bytes) – raw binary data to be unpacked
Return tuple output: unpacked data
- data_pointer (