pymaid.get_entity_graph

pymaid.get_entity_graph(types: Iterable[Literal['neuron', 'annotation', 'volume', 'skeleton']] | None = None, by_name=False, annotated_with: Iterable[Iterable[int | str]] | None = None, not_annotated_with: Iterable[Iterable[int | str]] | None = None, expand_subannotations: Iterable[int | str] | None = None, *, remote_instance=None) DiGraph[source]

Get a networkx DiGraph of semantic objects.

Can be slow for large projects.

Note that CATMAID distinguishes between neurons (semantic objects which can be named and annotated) and skeletons (spatial objects which can model neurons). Most pymaid (and CATMAID) functions use the skeleton ID, rather than the neuron ID, and assume that a neuron is modeled by a single skeleton. To replace neurons in the graph with the skeletons they are modelled by, include "skeleton" in the types argument (this is mutually exclusive with "neuron").

Nodes in the graph have data:

  • id: int

  • name: str

  • type: str, one of “neuron”, “annotation”, “volume”, “skeleton”

Neurons additionally have

  • skeleton_ids: List[int]

Skeletons additionally have

  • neuron_id: int

Edges in the graph have

  • is_meta_annotation (bool): whether it is between two annotations

Parameters:
  • types (optional sequence of str, default None) – Which types of entity to fetch. Choices are “neuron”, “annotation”, “volume”, “skeleton”; “neuron” and “skeleton” are mutually exclusive. None uses CATMAID default (“neuron”, “annotation”).

  • by_name (bool, default False) – If True, use the entity’s name rather than its integer ID. This can be convenient but has a risk of name collisions, which will raise errors. In particular, name collisions will occur if types includes "skeleton" and a neuron is modelled by more than one skeleton.

  • annotated_with (Optional[Iterable[Iterable[Union[int, str]]]], default None) – If not None, only include entities annotated with these annotations. Can be integer IDs or str names (not IDs as strings!). The inner iterables are combined with OR. The outer iterable is combined with AND. e.g. for [["a", "b"], ["c"]], entities must be annotated with "c", and at least one of "a" or "b". Nesting is enforced, i.e. "a" is not a valid argument; it must be [["a"]].

  • not_annotated_with (Optional[Iterable[Iterable[Union[int, str]]]], default None) – If not None, only include entites NOT annotated with these. See annotated_with for more usage details.

  • expand_subannotations (Optional[Iterable[Union[int, str]]], default None) – Which annotations in the annotated_with, not_annotated_with sets to expand into all their sub-annotations (each as an OR group).

  • remote_instance (optional CatmaidInstance) –

Return type:

networkx.DiGraph

Raises:
  • UnknownEntityTypeError – CATMAID returned an entity type pymaid doesn’t know how to interpret.

  • AmbiguousEntityNameError – When by_name=True is used, and there are naming collisions.