docs: def _variogram_residuals(params, x, y, variogram_function, weight):
      """Function used in variogram model estimation. Returns residuals between
      calculated variogram and actual data (lags/semivariance).
      Called by _calculate_variogram_model.
  
      Parameters
      ----------
      params: list or 1D array
          parameters for calculating the model variogram
      x: ndarray
          lags (distances) at which to evaluate the model variogram
      y: ndarray
          experimental semivariances at the specified lags
      variogram_function: callable
          the actual funtion that evaluates the model variogram
      weight: bool
          flag for implementing the crude weighting routine, used in order to
          fit smaller lags better
  
      Returns
      -------
      resid: 1d array
          residuals, dimension same as y
      """
  
      # this crude weighting routine can be used to better fit the model
      # variogram to the experimental variogram at smaller lags...
      # the weights are calculated from a logistic function, so weights at small
      # lags are ~1 and weights at the longest lags are ~0;
      # the center of the logistic weighting is hard-coded to be at 70% of the
      # distance from the shortest lag to the largest lag
      if weight:
          drange = np.amax(x) - np.amin(x)
          k = 2.1972 / (0.1 * drange)
          x0 = 0.7 * drange + np.amin(x)
          weights = 1. / (1. + np.exp(-k * (x0 - x)))
          weights /= np.sum(weights)
          resid = (variogram_function(params, x) - y) * weights
      else:
          resid = variogram_function(params, x) - y
  
      return resid