heg
pleat.io.heg ¶
File I/O for the .heg half-edge graph format (YAML-based).
graph_to_dict ¶
graph_to_dict(
G: HalfEdgeGraph,
attributes_to_save: tuple[str, ...] = (
"pos",
"length",
"in_angle",
"color_key",
),
) -> dict
Serialise a half-edge graph to a JSON/YAML-friendly nested dict.
Vertices, half-edges, and faces are each given an opaque string label
(v0, h0, f0, ...). Cross-references are stored by label.
Numpy arrays in attributes are converted to plain Python lists, and numpy
scalars to float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
HalfEdgeGraph
|
The graph to serialise. |
required |
attributes_to_save
|
tuple[str, ...]
|
Attribute keys to copy onto each element. Other attributes are dropped. |
('pos', 'length', 'in_angle', 'color_key')
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
func: |
Source code in pleat/io/heg.py
dict_to_graph ¶
Inverse of :func:graph_to_dict: reconstruct a graph from its serialised dict.
The returned graph is always an :class:EuclideanPositionHEG regardless of
the source graph's class (TODO: persist the class).
Source code in pleat/io/heg.py
save_graph ¶
save_graph(
filename: str,
graph: HalfEdgeGraph,
overwrite: bool = False,
extra_attributes_to_save: (
str | tuple[str, ...] | None
) = None,
attributes_to_save: tuple[str, ...] = (
"pos",
"length",
"in_angle",
"color_key",
),
) -> None
Save graph to a .heg (YAML) file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Output path; |
required |
graph
|
HalfEdgeGraph
|
The graph to save. |
required |
overwrite
|
bool
|
If False and the file already exists, raise instead of overwriting. |
False
|
extra_attributes_to_save
|
str | tuple[str, ...] | None
|
Convenience: attribute key(s) to save in addition to attributes_to_save. |
None
|
attributes_to_save
|
tuple[str, ...]
|
Attribute keys to persist (see :func: |
('pos', 'length', 'in_angle', 'color_key')
|
Source code in pleat/io/heg.py
load_graph ¶
Load a graph previously saved by :func:save_graph.