Skip to content

Views and selections

anet.view(...) gives a GraphView: a live, read-only part of the graph. anet.N and anet.E are the node and edge sequences (NodeSequence, EdgeSequence), and their select method makes a selection. A write through a view raises ReadOnlyViewError.

view = anet.view(nodes=None, edges=None, layers=None, slices=None, *, predicate=None, boundary='closed')

nodes takes IDs, placements, a NodeSequence, a RowSelection of nodes or node_layers, a mask or a function. edges takes IDs, an EdgeSequence, a RowSelection of edges, a mask or a function. layers takes coordinates or anet.layers.where(...), and slices takes slice names or a slice selection.

Which nodes and edges a view keeps

boundary result
'closed' (default) An edge stays only if all its endpoints are selected. A hyperedge stays whole, or not at all. A selected node without edges stays. A filter on edges only keeps those edges and their endpoints.
'open' The edges that touch a selected node stay, with all their endpoints: one step out. The edge and slice filters still apply. view.summary()['expanded'] lists the added endpoints.
  • Edges that end on an edge: such an edge needs the edge that it ends on. A filter on edges brings that edge with it.
  • A view of a view only removes more. Its filters add to the filters of the first view.
  • A slice is a set of members. A view of a slice does not add the edges between its nodes.

Live and read-only

  • A view is live: it follows all changes of the graph. If a filter is a function, the view calls it again at each read.
  • view.N, view.E and view.attrs work as on the graph, but only for the nodes and edges in the view.
  • A write through a view raises ReadOnlyViewError, a subclass of TypeError. The message tells you to use materialize().
  • view.materialize() gives a new, independent AnnNet with the selected nodes and edges, their slices, layers and attributes.

Selections

anet.N.select(...) and anet.E.select(...) give a selection of the same type. Selections combine with &, | and -, and the result is in the order of the graph. A selection from conditions is live, like a view. A selection from IDs or a mask is fixed. Selections from two graphs raise ValueError when you combine them, and a node selection with an edge selection raises TypeError.

annnet.core._Views.GraphView

A live, read-only, composable selection of a graph.

Built by anet.view(...) and narrowed by V.view(...). The membership rules are documented in :mod:annnet.core._resolve; the reading vocabulary is the graph's: N, E, attrs, uns, slices, layers, the named matrices, shape/supra_shape, the traversal reads, view(), materialize() and summary().

Attributes

graph property
graph

The root graph.

parent property
parent

The graph or view this one narrows.

Functions

entity_kinds
entity_kinds()

The kind of every selected entity, by id ('node' or 'edge').

degree
degree(entity_id)

The number of selected edges touching one selected entity.

neighbors
neighbors(entity_id)

The neighbours of one selected entity along selected edges.

view
view(
    nodes=None,
    edges=None,
    layers=None,
    slices=None,
    *,
    predicate=None,
    boundary="closed"
)

Narrow this view. Every argument intersects with what this view holds.

materialize
materialize(copy_attributes=True)

Build an independent, editable graph holding exactly this selection.

Parameters:

Name Type Description Default
copy_attributes bool

Carry the attributes of every address over. False keeps the structure, the slice memberships and the aspects alone.

True

Returns:

Type Description
AnnNet

A new graph; editing it changes nothing here, and editing the parent changes nothing there. uns['selection'] records what was selected.

annnet.core._select.NodeSequence

The nodes of a graph or a view, in the order the graph holds them.

Functions

at
at(node_id)

Return the record of one node by its id.

A string-shaped record equal to the id, carrying kind, layers and a detached attrs dict. In a view, layers are the placements the view holds.

annnet.core._select.EdgeSequence

The edges of a graph or a view, in the order the graph holds them.

Four structural fields read like columns because a filter over them is as common as one over an attribute: kind (binary, hyper or node_edge), directed, weight and ml_kind.

Functions

at
at(edge_id)

Return the record of one edge by its id.

A tuple-shaped record: (source, target) unpacks; edge_id, kind, members, weight and directed are attributes.

effective_weight
effective_weight(edge_id, slice=None)

Return the weight of one edge in one slice: the override, or the stored weight.

Parameters:

Name Type Description Default
edge_id str
required
slice str

Defaults to the graph's active slice.

None

annnet.core._select.ReadOnlyViewError

Raised by every write route of a view, its selections and its attributes.