ahds package

class ahds.AmiraFile(fn, *args, **kwargs)[source]

Bases: object

Convenience class to handle Amira (R) files

This class aggregates user-level classes from the ahds.header and ahds.data_stream modules into a single class with a simple interface AmiraFile.header() for the header and AmiraFile.data_streams data 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._MockObject

Class 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:
  • fn (str) – file name
  • format_bytes (int) – number of bytes in which to search for the format [default: 50]
  • verbose (bool) – verbose (default) or not
Return str file_format:
 

either AmiraMesh or HyperSurface

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:
  • fn (str) – file name
  • file_format (str) – either AmiraMesh or HyperSurface
  • header_bytes (int) – number of bytes in which to search for the header [default: 20000]
Return str data:
 

the header as per the file_format

ahds.grammar.get_parsed_data(fn, *args, **kwargs)[source]

All above functions as a single function

Parameters:fn (str) – file name
Return list parsed_data:
 structured metadata
ahds.grammar.parse_header(data, verbose=False, *args, **kwargs)[source]

Parse the data using the grammar specified in this module

Parameters:data (str) – delimited data to be parsed for metadata
Return list parsed_data:
 structured metadata

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

Class 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. AmiraMesh or HyperSurface
  • dimensions e.g. 3D
  • format e.g. BINARY-LITTLE-ENDIAN
  • version e.g. 2.1
  • extra format e.g. <hxsurface>
classmethod from_file(fn, *args, **kwargs)[source]

Constructor to build an ahds.header.AmiraHeader object from a file

Parameters:fn (str) – Amira (R) file
Return ah:object of class ahds.header.AmiraHeader containing header metadata
Return 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

class ahds.header.Block(name)[source]

Bases: object

Generic block to be loaded with attributes

add_attr(name, value)[source]

Add an attribute to an ahds.header.Block object

ids

Convenience method to get the IDs for Materials present

ahds.data_stream module

data_stream

The following image shows the class hierarchy for data streams.

_images/ahds_classes.png
class ahds.data_stream.AmiraDataStream(amira_header, data_pointer, stream_data)[source]

Bases: object

Base 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.AmiraHeader object

stream_data

All the raw data from the file

class ahds.data_stream.AmiraHxSurfaceDataStream(*args, **kwargs)[source]

Bases: ahds.data_stream.AmiraDataStream

Base 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.AmiraHeader object

stream_data

All the raw data from the file

class ahds.data_stream.AmiraMeshDataStream(*args, **kwargs)[source]

Bases: ahds.data_stream.AmiraDataStream

Class 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.AmiraHeader object

stream_data

All the raw data from the file

to_volume()[source]

Return a 3D volume of the data

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.AmiraHeader object

stream_data

All the raw data from the file

class ahds.data_stream.Contour(z, array)[source]

Bases: object

Encapsulates the array representing a contour

class ahds.data_stream.ContourSet(initlist=None)[source]

Bases: UserList.UserList

Encapsulation for a set of ahds.data_stream.Contour objects

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

Class to encapsulate all the above functionality

class ahds.data_stream.Image(z, array)[source]

Bases: object

Encapsulates individual images

array

Accessor to underlying array data

as_contours

A dictionary of lists of contours keyed by byte_value

equalise()[source]

Increase the dynamic range of the image

show()[source]

Display the image

class ahds.data_stream.ImageSet(initlist=None)[source]

Bases: UserList.UserList

Encapsulation for set of ahds.data_stream.Image objects

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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.AmiraHeader object

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:
  • output_size (int) – the number of items when data is uncompressed
  • data (str) – a raw stream of data to be unpacked
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:
  • output_size (int) – the number of items when data is uncompressed
  • data (str) – a raw stream of data to be unpacked
Return numpy.array output:
 

an array of numpy.uint8

ahds.data_stream.hxzip_decode(data_size, data)[source]

Decode HxZip data stream

Parameters:
  • data_size (int) – the number of items when data is uncompressed
  • data (str) – a raw stream of data to be unpacked
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 the data_pointer attribute 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

ahds.data_stream.unpack_binary(data_pointer, definitions, data)[source]

Unpack binary data using struct.unpack

Parameters:
  • data_pointer (ahds.header.Block) – metadata for the data_pointer attribute 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