code: def _gpdfit(ary):
      """Estimate the parameters for the Generalized Pareto Distribution (GPD).
  
      Empirical Bayes estimate for the parameters of the generalized Pareto
      distribution given the data.
  
      Parameters
      ----------
      ary: array
          sorted 1D data array
  
      Returns
      -------
      k: float
          estimated shape parameter
      sigma: float
          estimated scale parameter
      """
      prior_bs = 3
      prior_k = 10
      n = len(ary)
      m_est = 30 + int(n**0.5)
  
      b_ary = 1 - np.sqrt(
          m_est / (np.arange(1, m_est + 1, dtype=float) - 0.5)
      )
      b_ary /= prior_bs * ary[int(n / 4 + 0.5) - 1]
      b_ary += 1 / ary[-1]
  
      k_ary = np.log1p(-b_ary[:, None] * ary).mean(
          axis=1
      )  # pylint: disable=no-member
      len_scale = n * (np.log(-(b_ary / k_ary)) - k_ary - 1)
      weights = 1 / np.exp(len_scale - len_scale[:, None]).sum(axis=1)
  
      # remove negligible weights
      real_idxs = weights >= 10 * np.finfo(float).eps
      if not np.all(real_idxs):
          weights = weights[real_idxs]
          b_ary = b_ary[real_idxs]
      # normalise weights
      weights /= weights.sum()
  
      # posterior mean for b
      b_post = np.sum(b_ary * weights)
      # estimate for k
      k_post = np.log1p(
          -b_post * ary
      ).mean()  # pylint: disable=invalid-unary-operand-type,no-member
      # add prior for k_post
      sigma = -k_post / b_post
      k_post = (n * k_post + prior_k * 0.5) / (n + prior_k)
  
      return k_post, sigma
  
imports: import itertools
  import warnings
  from copy import deepcopy
  from typing import List, Optional, Tuple, Union, Mapping, cast, Callable
  import numpy
  import pandas
  import scipy.stats
  from xarray_einstats import stats
  import xarray
  from scipy.optimize import minimize
  from typing_extensions import Literal
  from ..None import _log
  from ..data import InferenceData, convert_to_dataset, convert_to_inference_data, extract
  from ..rcparams import rcParams, ScaleKeyword, ICKeyword
  from ..utils import Numba, _numba_var, _var_names, get_coords
  from .density_utils import get_bins
  from .density_utils import histogram
  from .density_utils import kde
  from .diagnostics import _mc_error, _multichain_statistics, ess
  from .stats_utils import ELPDData, _circular_standard_deviation, smooth_data
  from .stats_utils import get_log_likelihood
  from .stats_utils import get_log_prior
  from .stats_utils import logsumexp
  from .stats_utils import make_ufunc
  from .stats_utils import stats_variance_2d
  from .stats_utils import wrap_xarray_ufunc
  from ..sel_utils import xarray_var_iter
  from ..labels import BaseLabeller
label_desc: Use image node_id 10 for calling a global function with example usage: _gpdfit(ary) and returns: k_post,  sigma