Graph metrics and functions
Basic metrics
Using the baboons graph from the Introduction, we can probe it for some basic metrics such as how many nodes and edges it contains, its layers and node types, and the time range over which it exists.
In the code below, count_edges() and count_temporal_edges() return different results. This is because count_edges() returns the number of unique edges while count_temporal_edges() returns the total edge updates which have occurred.
Using count_temporal_edges() is useful if you want to imagine each edge update as a separate connection between the two nodes. The edges can be accessed in this manner via edge.explode(), as is discussed in edge metrics and functions.
You can also inspect the graph's layers with unique_layers and its node types with get_all_node_types(). To check if a specific layer exists, use has_layer().
Time functions like earliest_time and latest_time return an EventTime object. You can access the datetime via .dt or the raw Unix epoch (milliseconds) via .t. These time bounds are essential for understanding when your data starts and ends, and for constructing temporal views.
The property APIs are the same for the graph, nodes and edges, these are discussed together in Property queries.
Accessing nodes and edges
Three types of functions are provided for accessing the nodes and edges within a graph:
- Existence check: using
has_node()andhas_edge()you can check if an entity is present within the graph. - Direct access:
node()andedge()will return aNodeorEdgeobject if the entity is present andNoneif it is not. - Iterable access:
nodesandedgeswill return iterables for all nodes/edges which can be used within a for loop or as part of a function chain.
All of these functions are shown in the code below and will appear in several other examples throughout this tutorial.
Selecting subsets with []
You can also use [] indexing with filter expressions to select a subset of nodes or edges. Unlike creating a filtered graph view, the filter does not persist on the returned entities — it simply selects which ones to return.
This non-persistent behaviour is particularly powerful for graph traversal — for example, finding all baboons active on one day, then exploring their neighbours on the next. We cover these patterns in depth in Chaining Queries.
For more details on filter expressions and combining filters with logical operators, see Filtering.