Layered graphs

Prerequisites

Before reading this topic, please ensure you are familiar with:

Creating layers views

An edge object by default will contain information on all layers between its source and destination nodes. Often there are only a subset of these relationships that you are interested in. To handle this the Graph, Node and Edge provide the layers() function which takes a list of layer names and returns a view with only the edge updates that occurred on these layers.

Layer views can also be used in combination with any other view function. In the example below, we look at the total edge weight over the full graph, then restrict this to the Grooming and Resting layers and then reduce this further by applying a window between the 13th and 20th of June.

Filtering to specific layers

Valid layers

When working with layers, you may encounter situations where you're not sure which layers exist in your current view. Raphtory provides several functions to handle this gracefully:

  • layers() — Throws an error if you specify a layer that doesn't exist in the graph
  • valid_layers() — Silently ignores invalid layer names and only uses the valid ones

This makes valid_layers() useful when you have a list of layers from external input and aren't sure which ones exist:

Excluding layers

Sometimes it's easier to specify which layers you don't want rather than listing all the ones you do. The exclude_layers() function lets you remove specific layers from a view. Like the include functions, there's also an exclude_valid_layers() variant that silently ignores invalid layer names.

The default layer

When you add an edge without specifying a layer, it goes to the default layer. You can access this layer using default_layer(), or by using the string "_default" with the layers() function.

Traversing the graph with layers

Building on the Multi-layer Temporal Traversal pattern, you can use layer filters with the [] syntax to traverse across different relationship types. In this example, we find LOME's grooming partners, then discover who those baboons have rested with.