Kriging-based processes#

BlockFilter

alias of BlockPK


class BlockPK(semivariogram_model, blocks, point_support, kriging_type='ata')[source]

Class is an object that can be used for Area-to-Area, Area-to-Point, Centroid-based Poisson Kriging regularization.

Parameters:
semivariogram_modelTheoreticalVariogram

The fitted variogram model.

blocksUnion[Blocks, gpd.GeoDataFrame, pd.DataFrame, np.ndarray]
Blocks with aggregated data.
  • Blocks: Blocks() class object.

  • GeoDataFrame and DataFrame must have columns: centroid.x, centroid.y, ds, index. Geometry column with polygons is not used.

  • numpy array: [[block index, centroid x, centroid y, value]].

point_supportUnion[Dict, np.ndarray, gpd.GeoDataFrame, pd.DataFrame, PointSupport]
The point support of polygons.
  • Dict: {block id: [[point x, point y, value]]},

  • numpy array: [[block id, x, y, value]],

  • DataFrame and GeoDataFrame: columns={x, y, ds, index},

  • PointSupport.

kriging_typestr, default=’ata’
A type of Poisson Kriging operation. Available methods:
  • 'ata': Area-to-Area Poisson Kriging.

  • 'atp': Area-to-Point Poisson Kriging.

  • 'cb': Centroid-based Poisson Kriging.

Attributes:
semivariogram_modelTheoreticalVariogram

See the semivariogram_model parameter.

blocksUnion[Blocks, gpd.GeoDataFrame, pd.DataFrame, np.ndarray]

See the blocks parameter.

point_supportUnion[Dict, np.ndarray, gpd.GeoDataFrame, pd.DataFrame, PointSupport]

See the point_support parameter.

kriging_typestr, default=’ata’

See the kriging_type parameter.

geo_dsgeopandas GeoDataFrame

A regularized set of blocks: ['id', 'geometry', 'reg.est', 'reg.err', 'rmse']

statisticsDict
A dictionary with two keys:
  • 'RMSE': root mean squared error of regularization,

  • 'time': time (in seconds) of the regularization process.

raise_when_negative_predictionbool, default=True

Raise error when prediction is negative.

raise_when_negative_errorbool, default=True

Raise error when prediction error is negative.

Methods

regularize()

Regularize blocks (you should use it for a data deconvolution - with ATP PK, or for a data filtering - with ATA, C-B PK).

regularize(number_of_neighbors, data_crs=None, raise_when_negative_prediction=True, raise_when_negative_error=True)[source]

Function regularizes whole dataset and creates new values and error maps based on the kriging type. Function does not predict unknown and missing values, areas with NaN values are skipped.

Parameters:
number_of_neighborsint

The minimum number of neighbours that potentially affect block.

data_crsstr, default=None

Data crs, look into: https://geopandas.org/projections.html. If None given then returned GeoDataFrame doesn’t have a crs.

raise_when_negative_predictionbool, default=True

Raise error when prediction is negative.

raise_when_negative_errorbool, default=True

Raise error when prediction error is negative.

Returns:
regularizedgpd.GeoDataFrame

Regularized set of blocks: ['id', 'geometry', 'reg.est', 'reg.err', 'rmse']


class BlockToBlockKrigingComparison(variogram, blocks, point_support, no_of_neighbors=16, neighbors_range=None, simple_kriging_mean=None, raise_when_negative_prediction=True, raise_when_negative_error=True, training_set_frac=0.8, allow_approx_solutions=False, iters=20)[source]

Class compares different block kriging models and techniques.

Parameters:
blocksUnion[Blocks, gpd.GeoDataFrame, pd.DataFrame, np.ndarray]
Blocks with aggregated data.
  • Blocks: Blocks() class object.

  • GeoDataFrame and DataFrame must have columns: centroid.x, centroid.y, ds, index. Geometry column with polygons is not used.

  • numpy array: [[block index, centroid x, centroid y, value]].

point_supportUnion[Dict, np.ndarray, gpd.GeoDataFrame, pd.DataFrame, PointSupport]
The point support of polygons.
  • Dict: {block id: [[point x, point y, value]]},

  • numpy array: [[block id, x, y, value]],

  • DataFrame and GeoDataFrame: columns={x, y, ds, index},

  • PointSupport.

no_of_neighborsint, default = 16

The maximum number of n-closest neighbors used for interpolation.

neighbors_rangefloat, default = None

Maximum distance where we search for point neighbors. If None given then range is selected from the theoretical_model rang attribute. If algorithms picks less neighbors than no_of_neighbors within the range then additional points are selected outside the neighbors_range.

simple_kriging_meanfloat, default = None

The mean value of a process over a study area. Should be known before processing. If not provided then Simple Kriging estimator is skipped.

raise_when_negative_predictionbool, default = True

Raise error when prediction is negative.

raise_when_negative_errorbool, default=True

Raise error when prediction error is negative.

training_set_fracfloat, default = 0.8

How many values sampled as a known points set in each iteration. Could be any fraction within (0:1) range.

allow_approx_solutionsbool, default = False

Allows the approximation of kriging weights based on the OLS algorithm. Not recommended to set to True if you don’t know what you are doing!

itersint, default = 20

How many tests to perform over random samples of a data.

Attributes:
variogramTheoreticalVariogram

See variogram parameter.

blocksUnion[Blocks, gpd.GeoDataFrame, pd.DataFrame, np.ndarray]

See blocks parameter.

point_supportUnion[Dict, np.ndarray, gpd.GeoDataFrame, pd.DataFrame, PointSupport]

See point_support parameter.

no_of_neighborsint

See no_of_neighbors parameter.

neighbors_rangefloat

See neighbors_range parameter.

simple_kriging_meanfloat

See simple_kriging_mean parameter.

raise_when_negative_predictionbool, default = True

See raise_when_negative_prediction parameter.

raise_when_negative_errorbool, default=True

See raise_when_negative_error parameter.

training_set_fracfloat

See training_set_frac parameter.

itersint

See iters parameter.

common_indexesSet

Indexes that are common for blocks and point support.

training_set_indexesList[List]

List of lists with indexes used in a random sampling for a training set.

resultsDict

Results for each type of Block Kriging method.

Methods

run_tests()

Compares different types of Kriging, returns Dict with the mean root mean squared error of each iteration.

run_tests()[source]

Method compares ordinary, simple, area-to-area and centroid-based block Poisson Kriging.


smooth_blocks(semivariogram_model, blocks, point_support, number_of_neighbors, max_range=None, crs=None, raise_when_negative_prediction=True, raise_when_negative_error=True, err_to_nan=True)

Function smooths blocks data into their point support values.

Parameters:
semivariogram_modelTheoreticalVariogram

The regularized variogram.

blocksUnion[Blocks, gpd.GeoDataFrame, pd.DataFrame, np.ndarray]
Blocks with aggregated data.
  • Blocks: Blocks() class object.

  • GeoDataFrame and DataFrame must have columns: centroid.x, centroid.y, ds, index. Geometry column with polygons is not used.

  • numpy array: [[block index, centroid x, centroid y, value]].

point_supportUnion[Dict, np.ndarray, gpd.GeoDataFrame, pd.DataFrame, PointSupport]
The point support of polygons.
  • Dict: {block id: [[point x, point y, value]]},

  • numpy array: [[block id, x, y, value]],

  • DataFrame and GeoDataFrame: columns={x, y, ds, index},

  • PointSupport.

number_of_neighborsint

The minimum number of neighbours that potentially affect block.

max_rangefloat, default=None

The maximum distance to search for neighbors.

crsAny, default=None

CRS of data.

raise_when_negative_predictionbool, default=True

Raise error when prediction is negative.

raise_when_negative_errorbool, default=True

Raise error when prediction error is negative.

err_to_nanbool, default=True

ValueError to NaN.

Returns:
resultsgpd.GeoDataFrame

Columns = [area_id, geometry (Point), prediction, error].