code: def _spatial_extent(resmat, src, function, metric, threshold=0.5):
      """Compute spatial width metrics for resolution matrix.
  
      Parameters
      ----------
      resmat : array, shape (n_orient * n_dipoles, n_dipoles)
          The resolution matrix.
          If not a square matrix and if the number of rows is a multiple of
          number of columns (i.e. n_orient>1), then the Euclidean length per
          source location is computed (e.g. if inverse operator with free
          orientations was applied to forward solution with fixed orientations).
      src : Source Space
          Source space object from forward or inverse operator.
      function : 'psf' | 'ctf'
          Whether to compute metrics for columns (PSFs) or rows (CTFs).
      metric : str
          What type of width metric to compute.
  
          - 'sd_ext': spatial deviation (e.g. Molins et al.), in centimeters.
          - 'maxrad_ext': maximum radius to fraction threshold of max amplitude,
            in centimeters.
  
      threshold : float
          Amplitude fraction threshold for metric 'maxrad'. Defaults to 0.5.
  
      Returns
      -------
      width : array, shape (n_dipoles,)
          Spatial width metric per location.
      """
      locations = _get_src_locations(
          src
      )  # locs used in forw. and inv. operator
      locations = 100.0 * locations  # convert to cm (more common)
  
      # The code below will operate on columns, so transpose if you want CTFs
      if function == "ctf":
          resmat = resmat.T
  
      width = np.empty(resmat.shape[1])  # initialise output array
  
      # spatial deviation as in Molins et al.
      if metric == "sd_ext":
          for ii in range(locations.shape[0]):
              diffloc = (
                  locations - locations[ii, :]
              )  # locs w/r/t true source
              locerr = np.sum(
                  diffloc**2, 1
              )  # squared Eucl dists to true source
              resvec = abs(resmat[:, ii]) ** 2  # pick current row
              # spatial deviation (Molins et al, NI 2008, eq. 12)
              width[ii] = np.sqrt(
                  np.sum(np.multiply(locerr, resvec)) / np.sum(resvec)
              )
  
      # maximum radius to 50% of max amplitude
      elif metric == "maxrad_ext":
          for ii, resvec in enumerate(resmat.T):  # iterate over columns
              resvec = abs(resvec)  # operate on absolute values
              amps = resvec.max()
              # indices of elements with values larger than fraction threshold
              # of peak amplitude
              thresh_idx = np.where(resvec > threshold * amps)
              # get distances for those indices from true source position
              locs_thresh = locations[thresh_idx, :] - locations[ii, :]
              # get maximum distance
              width[ii] = np.sqrt(np.sum(locs_thresh**2, 1).max())
  
      return width
  
file_path: mne-python/mne/minimum_norm/spatial_resolution.py
imports: import numpy
  from ..source_estimate import SourceEstimate
  from ..utils import _check_option, logger, verbose
label_desc: Use image node_id 3 for calling a global function with example usage: _spatial_extent(resmat, src, function, metric, threshold) and returns: width