code: def trophic_incoherence_parameter(
      G, weight="weight", cannibalism=False
  ):
      r"""Compute the trophic incoherence parameter of a graph.
  
      Trophic coherence is defined as the homogeneity of the distribution of
      trophic distances: the more similar, the more coherent. This is measured by
      the standard deviation of the trophic differences and referred to as the
      trophic incoherence parameter $q$ by [1].
  
      Parameters
      ----------
      G : DiGraph
          A directed networkx graph
  
      cannibalism: Boolean
          If set to False, self edges are not considered in the calculation
  
      Returns
      -------
      trophic_incoherence_parameter : float
          The trophic coherence of a graph
  
      References
      ----------
      .. [1] Samuel Johnson, Virginia Dominguez-Garcia, Luca Donetti, Miguel A.
          Munoz (2014) PNAS "Trophic coherence determines food-web stability"
      """
      import numpy as np
  
      if cannibalism:
          diffs = trophic_differences(G, weight=weight)
      else:
          # If no cannibalism, remove self-edges
          self_loops = list(nx.selfloop_edges(G))
          if self_loops:
              # Make a copy so we do not change G's edges in memory
              G_2 = G.copy()
              G_2.remove_edges_from(self_loops)
          else:
              # Avoid copy otherwise
              G_2 = G
          diffs = trophic_differences(G_2, weight=weight)
      return np.std(list(diffs.values()))
  
imports: import networkx
  from networkx.utils import not_implemented_for
label_desc: Use image node_id 3 for calling a global function with example usage: trophic_incoherence_parameter(G, weight, cannibalism) and returns: np