Skip to content

Kriging

Kriging module

This module provides kriging functions from variogram estimation to kriging interpolation.

empirical_variogram(arr_coords, arr_values, bin_size, max_dist=None, normalize=True)

Calculate an empirical variogram function of spatial data.

Parameters:

Name Type Description Default
arr_coords ndarray

2D array (m, 2) array with first column corresponding to 'Longitude' and the second one to 'Latitude' and with one location per row.

required
arr_values ndarray

2D array (t, m) containing values with one row per timestep and one column per location.

required
bin_size int

size of each bin in kilometers.

required
max_dist int

maximum distance between two locations to consider this pair as valid.

None
normalize bool

boolean indicating whether to normalize the variogram by global variability values.

True

Returns:

Name Type Description
emp_vario Empirical_Variogram

empirical variogram with one value per bin. Array of size n_bins.

count Empirical_Variogram

number of data points used to compute each bin. Array of size n_bins.

fit_variogram(emp_vario, fit_model, weight=True, kwargs_fit_model=None)

Fit an empirical variogram with a covariance model.

Parameters:

Name Type Description Default
emp_vario Empirical_Variogram

Empirical_Variogram object with one value of variability per bin.

required
fit_model CovModel

covariance model used to fit the variogram (see gstools.covmodel.CovModel documentation).

required
weight bool

if True, weights are applied to each point in the estimation. Weights are positively correlated to the count per bin and negatively correlated to the distance.

True
kwargs_fit_model dict

kwargs to pass in other parameters to the gstools.covmodel.CovModel. For example '{nu: 0.3}' for a Matern kernel.

None

Returns:

Name Type Description
coef

fitted covariance model's main coefficients (full sill, range, nugget).

fit_model

covariance model fitted to the variogram (see gstools.covmodel.CovModel documentation).

r2_score

r2 score of the curve fitting results.

krige_field_timestep(vario_model, field, station_coords, lon_grid, lat_grid, sigma=None, kwargs_krige_class=None, kwargs_krige_call=None)

Compute the kriged field over space using the gstools.krig.Krige class.

Parameters:

Name Type Description Default
vario_model CovModel

variogram covariance kernel to be used in the kriging interpolation

required
field DataFrame

field to interpolate as a pd.DataFrame with with dates as index and the different locations as columns

required
station_coords DataFrame

pd.DataFrame object with location names as index, and columns 'Longitude' and 'Latitude'

required
lon_grid ndarray

1D array of longitude coordinates of the interpolation grid

required
lat_grid ndarray

1D array of latitude coordinates of the interpolation grid

required
sigma int

standard deviation for Gaussian kernel filter used for the kriged field smoothing

None
kwargs_krige_class dict

dict with arguments to pass in the gs.krige.Krige class creation

None
kwargs_krige_call dict

dict with arguments to pass in the gs.krige.Krige() object call

None

Returns:

Name Type Description
kriged_field

field kriged by Gaussian process regression

variogram(df_coords, df_values, fit_model, bin_size, weight, max_dist=None, normalize=True, month_filter=None, kwargs_fit_model=None)

Calculate and fit the empirical variogram using gstools

Parameters:

Name Type Description Default
df_coords DataFrame

pd.DataFrame object with location names as index, and columns 'Longitude' and 'Latitude'

required
df_values DataFrame

pd.DataFrame object containing values to study with dates as index and the different locations as columns

required
fit_model CovModel

covariance model used to fit the variogram (see gstools.covmodel.CovModel documentation)

required
bin_size int

size of bins grouping pairs of locations with similar distances from one another

required
weight bool

if True, weights are applied to each point in the estimation

required
max_dist int

maximum distance between points paired together (if None, maximum distance between all locations considered)

None
normalize bool

boolean indicating whether to normalize the variogram by global variability values.

True
month_filter int | list

month or list of months to filter the dataset on for variogram computation

None
kwargs_fit_model dict

kwargs to pass in other parameters to the gstools.covmodel.CovModel. For example '{"nu": 0.3}' for a Matern kernel.

None

Returns:

Name Type Description
Variogram_Outputs (coef, model, r2)
  • coef: model's main coefficients (full sill, range, nugget)
  • model: gstools model object
  • r2_score: r2 score of the curve fitting results
  • emp_vario: empirical variogram with one value of variance per bin. Array of size n_bins.
  • count: number of data points used to compute each bin. Array of size n_bins.