code: def spatial_deviation_error(
      stc_true, stc_est, src, threshold="50%", per_sample=True
  ):
      r"""Compute the spatial deviation.
  
      The spatial deviation characterizes the spread of the estimate source
      around the true source.
  
      .. math::
  
          SD = \dfrac{\sum_i|s_i|\|r_{i} - r_{true}\|^2}{\sum_i|s_i|}.
  
      where :math:`r_{true}` is a true dipole position,
      :math:`r_i` and :math:`|s_i|` denote respectively the position
      and amplitude of i-th dipole in source estimate.
  
      Threshold is used on estimated source for focusing the metric to strong
      amplitudes and omitting the low-amplitude values.
  
      Parameters
      ----------
      %(stc_true_metric)s
      %(stc_est_metric)s
      src : instance of SourceSpaces
          The source space on which the source estimates are defined.
      threshold : float | str
          The threshold to apply to source estimates before computing
          the recall. If a string the threshold is
          a percentage and it should end with the percent character.
      %(per_sample_metric)s
  
      Returns
      -------
      %(stc_metric)s
  
      Notes
      -----
      These metrics are documented in :footcite:`StenroosHauk2013` and
      :footcite:`LinEtAl2006a`.
  
      .. versionadded:: 1.2
  
      References
      ----------
      .. footbibliography::
      """
      stc_est, r_true, r_est = _prepare_ppe_sd(
          stc_true, stc_est, src, threshold
      )
      func = partial(_spatial_deviation, r_est=r_est, r_true=r_true)
      metric = _apply(func, stc_true, stc_est, per_sample=per_sample)
      return metric
  
imports: from functools import partial
  import numpy
  from scipy.spatial.distance import cdist
  from ...utils import _check_option, _validate_type, fill_doc
label_desc: Use image node_id 24 for calling a global function with example usage: spatial_deviation_error(stc_true, stc_est, src, threshold, per_sample) and returns: metric