Tree IO
Tree IO allows de/serialization of a tree and associated attributes in a custom simple format.
|
Print a partition tree in ASCII format. |
|
Read a tree stored in mixed ascii/binary format. |
|
Save a tree and scalar attributes to mixed ascii/binary format. |
- print_partition_tree(tree, *, altitudes=None, attribute=None, float_size=4, ordering='area', scale='linear', return_string=False)[source]
Print a partition tree in ASCII format.
The tree is represented as a dendrogram oriented horizontally with the leaves on the left and the root on the right. Node positions are proportional to their altitudes.
This function can be used for debugging and illustrations: it is not meant to handle large trees.
- Parameters:
tree – Input tree
altitudes – Tree node altitudes (will default to
attribute_regular_altitudes(tree)()
ifNone
)attribute – Optional tree node attributes. If provided, the node attribute value will be printed instead of its altitude.
float_size – Number of characters reserved for number printing.
ordering – determine how the children of a node are ordered. Possible values are ‘altitudes’, ‘area’, ‘none’, ‘leaves’
scale – scale of the x axis: ‘linear’ (default) or ‘log’
return_string – if
True
, the string is returned instead of being printed (defaultFalse
)
- Returns:
A string if
return_string
isTrue
,None
otherwise
- read_tree(filename)[source]
Read a tree stored in mixed ascii/binary format.
Attributes are also registered as tree object attributes.
- Parameters:
filename – path to the tree file
- Returns:
a pair (tree, attribute_map)
- save_tree(filename: str, tree: higra.higram.Tree, attributes: dict[str, numpy.ndarray[numpy.float64]] = {}) None
Save a tree and scalar attributes to mixed ascii/binary format. Attributes must be numpy 1d arrays stored in a dictionary with string keys (attribute names).