geometry_utils¶
Graph-based geometry helpers. The package uses networkx directed
graphs to represent the vascular tree. Each edge stores attributes such as
length, radius, resistance, edge_id and strahler.
Main responsibilities¶
- Building the initial directed graph from node and element lists
(
create_geometry()).
- Adding a venous mesh based on arterial topology
(
create_venous_mesh()).
- Computing Strahler ordering for radii assignment
(
update_strahlers()).
- Utility helpers to compute lengths, branching angles and to add
anastomoses (
calcLength(),calculate_branching_angles(),create_anastomosis()).
- create_geometry(nodes, elements, inlet_radius, strahler_ratio_arteries, …)
Construct a
networkx.DiGraphfrom raw node and element data, set per-edge defaults, compute Strahler ordering and assign radii.- nodesdict
Mapping
node_id -> [x, y, z](0-based indices). Produced byfile_parsing_utils.read_nodes().- elementslist of tuple
Connectivity list
[(node_from, node_to), ...](0-based indices).- inlet_radiusfloat
Radius (m) used for the root/inlet arterial vessels.
- strahler_ratio_arteriesfloat
Scaling factor between Strahler orders used to set vessel radii.
- arteries_onlybool, optional
When True do not create a venous mesh; only arterial graph is returned. Default is False.
- outlet_vein_radiusfloat, optional
Outlet vein radius (m) used when building the venous mesh. Required if
arteries_onlyis False.- strahler_ratio_veinsfloat, optional
Strahler scaling factor used for veins. Required when building venous mesh.
- fieldsdict, optional
Optional per-edge fields (for example radius or resistance) as produced by
file_parsing_utils.define_fields_from_files().- default_mufloat, optional
Default dynamic viscosity (Pa.s) assigned to edges.
- default_hematocritfloat, optional
Default hematocrit value assigned to edges.
- networkx.DiGraph
Directed graph with nodes and edges annotated with attributes such as
length,radius,edge_id,strahlerandvessel_type.
create_venous_mesh(),update_strahlers(),create_anastomosis()>>> from FetoFlow.file_parsing_utils import read_nodes, read_elements >>> nodes = read_nodes('placenta.ipnode') >>> elements = read_elements('placenta.ipelem') >>> G = create_geometry(nodes, elements, inlet_radius=0.002, strahler_ratio_arteries=0.79)
- create_venous_mesh(…)
Build a venous graph by copying and relabelling the arterial graph, applying vein radii and reversing edge directions.
- update_strahlers(G, node_in, node_out)
Recursive Strahler calculation used during geometry construction.
- create_anastomosis(G, node_from, node_to, radius=None, mu=…)
Add a connecting edge (anastomosis) between two nodes and compute an approximate resistance for it. Input indices are in the external (1-based) IPNODE indexing and converted to internal 0-based indices.
Examples¶
G = create_geometry(nodes, elements, inlet_radius=0.002, strahler_ratio_arteries=0.79)
G = create_anastomosis(G, node_from=12, node_to=34, radius=0.1)
API reference¶
Function arguments¶
- create_geometry
- nodesdict
Mapping
node_id -> [x, y, z](0-based indices). Produced byfile_parsing_utils.read_nodes().- elementslist of tuple
Connectivity list
[(node_from, node_to), ...](0-based indices).- inlet_radiusfloat
Radius (m) used for the root/inlet arterial vessels.
- strahler_ratio_arteriesfloat
Scaling factor between Strahler orders used to set vessel radii.
- arteries_onlybool, optional
When True do not create a venous mesh; only arterial graph is returned. Default is False.
- outlet_vein_radiusfloat, optional
Outlet vein radius (m) used when building the venous mesh. Required if
arteries_onlyis False.- strahler_ratio_veinsfloat, optional
Strahler scaling factor used for veins. Required when building venous mesh.
- fieldsdict, optional
Optional per-edge fields (for example radius or resistance) as produced by
file_parsing_utils.define_fields_from_files().- default_mufloat, optional
Default dynamic viscosity (Pa.s) assigned to edges.
- default_hematocritfloat, optional
Default hematocrit value assigned to edges.
- networkx.DiGraph
Directed graph with nodes and edges annotated with attributes such as
length,radius,edge_id,strahlerandvessel_type.The function will compute Strahler numbers for each edge and assign radii by scaling from the inlet radius. If a
fieldsdict is provided and contains aradiusfield that value is used where specified and Strahler scaling applied elsewhere.Use
FetoFlow.file_parsing_utils.read_nodes()andFetoFlow.file_parsing_utils.read_elements()to produce thenodesandelementsinputs to this function.
- create_venous_mesh
- Gnetworkx.DiGraph
The arterial graph to copy and relabel into a venous mesh.
- networkx.DiGraph
Venous mesh graph with relabelled nodes and vein attributes.
The venous mesh is generated by copying the arterial topology, relabelling node ids (offset by
num_artery_nodes) and reversing edges. The function is usually called internally bycreate_geometry()whenarteries_only=False.- update_strahlers
- Gnetworkx.DiGraph
Graph to update in-place.
- node_in, node_outint
Edge endpoints describing the arc for which Strahler ordering should be computed. This function is recursive and intended to be used during geometry building.
- networkx.DiGraph
The graph with updated
strahlerattributes.
- create_anastomosis
- Gnetworkx.DiGraph
Graph to modify.
- node_fromint
1-based ipnode index identifying the anastomosis start node.
- node_toint
1-based ipnode index identifying the anastomosis end node.
- radiusfloat, optional
Radius of the anastomosis (mm in calling code; will be converted to m).
- mufloat, optional
Viscosity used to compute an approximate resistance for the new edge.
- networkx.DiGraph
The modified graph with the new anastomosis edge and attributes set.
# build graph first from parsed files G = create_geometry(nodes, elements, inlet_radius=0.002, strahler_ratio_arteries=0.79) # add a small anastomosis between ipnode indices 12 and 34 G = create_anastomosis(G, node_from=12, node_to=34, radius=0.05)
- create_venous_mesh
- Gnetworkx.DiGraph
The arterial graph to copy and relabel into a venous mesh.
- num_artery_nodesint
Number of arterial nodes (used for relabelling offsets).
- num_artery_edgesint
Number of arterial edges (used to offset edge ids for veins).
- num_terminal_arterial_nodesint
Number of terminal arterial nodes (used when connecting capillary equivalents).
- outlet_vein_radiusfloat
Vein outlet radius (m) used for radius assignment.
- strahler_ratio_veinsfloat
Strahler ratio used to scale vein radii.
- max_strahlerint
Maximum Strahler order in the arterial tree.
- networkx.DiGraph
Venous mesh graph with relabelled nodes and vein attributes.
- create_anastomosis
- Gnetworkx.DiGraph
Graph to modify.
- node_fromint
1-based ipnode index identifying the anastomosis start node.
- node_toint
1-based ipnode index identifying the anastomosis end node.
- radiusfloat, optional
Radius of the anastomosis (mm in calling code; will be converted to m).
- mufloat, optional
Viscosity used to compute an approximate resistance for the new edge.
- networkx.DiGraph
The modified graph with the new anastomosis edge and attributes set.