2.3.8.7. vacumm.misc.grid.kriging – Kriging

2.3.8.9. Content

Kriging utilities inspired from the AMBHAS library (http://www.ambhas.com/).

class CloudKriger(x, y, z, krigtype, mtype=None, vgf=None, npmax=1000, nproc=None, exact=False, distfunc='simple', errfunc=None, mean=None, farvalue=None, **kwargs)[source]

Bases: object

Ordinary kriger using mutliclouds of points

Big input cloud of points (size > npmax) are split into smaller clouds using cluster analysis of distance with function cloud_split().

The problem is solved in this way:

  1. Input points are split in clouds if necessary.
  2. The input variogram matrix is inverted for each cloud, possibly using multiprocessing if nproc>1.
  3. Value are computed at output positions using each the inverted matrix of cloud.
  4. Final value is a weighted average of the values estimated using each cloud. Weights are inversely proportional to the inverse of the squared error.
Params:
  • x/y/z: Input positions and data (masked array).
  • mtype, optional: Variogram model type (defaults to ‘exp’). See variogram_model_type() and variogram_model_type().
  • vgf, optional: Variogram function. If not set, it is estimated using variogram_fit().
  • npmax, optional: Maxima size of cloud.
  • nproc, optional: Number of processes to use to invert matrices. Set it to a number <2 to switch off parallelisation.
  • exact, optional: If True, variogram is exactly zero when distance is zero.
  • distfunc: Function to compute distances, or a mode argument to get_distances().
  • errfunc, optional: Callable function to compute “errors” like square root difference between to z values. It take two arguments and defaults to \sqrt(z1^2-z0^2)/2.
  • Extra keywords are parameters to the variogram_model() that must not be optimized by variogram_model(). For instance n=0 fix the
  • Extra keywords are the parameters to the variogram_model() that must not be optimized by variogram_model(). For instance n=0 fixes the nugget to zero. This is used only if vfg is not passed as an argument.
Attributes:

x, y, z, np, xc, yc, zc, npc, variogram_function, Ainv, npmax, nproc.

x

List of all input x positions.

y

List of all input y positions.

z

List of all input data.

xc

List of input x positions of each cloud.

yc

List input of y positions of each cloud.

zc

List of input data of each cloud.

Ainv

Invert of A

del_Ainv()[source]

Delete the invert of A

del_variogram_func()[source]

Delete the variogram function

get_Ainv()[source]

Get the inverse of A

get_sill()[source]
get_variogram_func()[source]

Get the variogram function

interp(xo, yo, geterr=False, blockr=None)[source]

Interpolate to positions xo,yo

Params:
  • xo/yo: Output positions.
  • geterr, optional: Also return errors.
Return:

zo or zo,eo

plot_clouds(marker='o', **kwargs)[source]

Quickly Plot inputs points splitted in clouds

set_Ainv(Ainv)[source]

Set the invert of A

set_variogram_func(vgf)[source]

Set the variogram function

sill

Sill

variogram_fit(x=None, y=None, z=None, **kwargs)[source]

Estimate the variogram function by using variogram_fit()

variogram_func

Variogram function

DEFAULT_VARIOGRAM_MODEL_TYPE = 'exponential'

Default variogram model type

exception KrigingError[source]

Bases: exceptions.Exception

class OrdinaryCloudKriger(x, y, z, mtype=None, vgf=None, npmax=1000, nproc=None, exact=False, distfunc='simple', errfunc=None, **kwargs)[source]

Bases: vacumm.misc.grid.kriging.CloudKriger

Ordinary kriger using cloud splitting

OrdinaryKriger

alias of vacumm.misc.grid.kriging.OrdinaryCloudKriger

class SimpleCloudKriger(x, y, z, mtype=None, vgf=None, npmax=1000, nproc=None, exact=False, distfunc='simple', errfunc=None, mean=None, farvalue=None, **kwargs)[source]

Bases: vacumm.misc.grid.kriging.CloudKriger

Simple kriger using cloud splitting

VARIOGRAM_MODEL_TYPES = ['linear', 'exponential', 'spherical', 'gaussian']

Variogram model types

class VariogramModel(mtype, **kwargs)[source]

Bases: object

Class used when fitting a variogram model to data to better control params

get_all_kwargs(pp)[source]

Get arguments list to variogram_model() by merging variable params p and fixed_params

get_var_args(**kwargs)[source]

Get variable arguments list from specified params

Note

Result cannot contain None

get_variogram_model(pp)[source]

Get the variogram model function using pp variable arguments

param_names = ['n', 's', 'r']
exception VariogramModelError[source]

Bases: vacumm.misc.grid.kriging.KrigingError

cloud_split(x, y, npmax=1000, getdist=True, getcent=True)[source]

Split data intot cloud of points of max size npmax:

Returns:

None if len(x)<=npmax

Else indices or (indices, global_distorsion, distortions).

dgemv(a, x)[source]
gauss3(x, y, x0=-1, y0=0.5, dx0=1, dy0=1, f0=1.0, x1=1, y1=1, dx1=2, dy1=0.5, f1=-1, x2=0, y2=-1.5, dx2=0.5, dy2=0.5, f2=-0.3, **kwargs)[source]

Create data sample as function position and 3-gaussian function

get_blas_func(name)[source]
gridded_gauss3(nx=100, ny=100, xmin=-3, xmax=3, ymin=-3, ymax=3, mesh=False, **kwargs)[source]

Create a data sample on a grid using gauss3()

krig(xi, yi, zi, xo, yo, vgf=None, geterr=False, **kwargs)[source]

Quickly krig data

random_gauss3(**kwargs)[source]

Create a data sample of random points using gauss3()

random_points(np=200, xmin=-3, xmax=3, ymin=-3, ymax=3, **kwargs)[source]

Generate random coordinates of points

syminv(A)[source]

Invert a symetric matrix

Params:
  • A: (np+1,np+1) for variogram matrix
Return:

Ainv(np+1,np+1)

Raise:

KrigingError

symm(a, b)[source]
variogram(x, y, z, binned=None, nmax=1500, nbindef=30, nbin0=None, nbmin=10, distmax=None, distfunc='simple', errfunc=None)[source]

Estimate variogram from data

Params:
  • x/y/z: 1D arrays of positions and data.
  • nmax, optional: Above this number, size of the sampe is reduced using undersampling.
  • binned, optional: If set to a number, data are arranged in bins to estimate variogram. If set to None, data are arranged in bins if the number of pairs of points is greater than nbindef*nbmin.
  • nbindef, optional: Default number of bins (not used if binned is a number).
  • nbin0, optional: If set to a number > 1, the first bin is split into nbin0 sub-bins. If set to None, it is evaluated with min(bins[1]/nbmin, nbin).
  • nbmin, optional: Minimal number of points in a bin.
  • distmax, optional: Max distance to consider.
  • distfunc: Function to compute distances, or a mode argument to get_distances().
  • errfunc, optional: Callable function to compute “errors” like square root difference between to z values. It take two arguments and defaults to (z1-z0)^2/2.
variogram_fit(x, y, z, mtype=None, getall=False, getp=False, geterr=False, distfunc='simple', errfunc=None, **kwargs)[source]

Fit a variogram model to data and return the function

Example:
>>> vm, errs = variogram_fit(x, y, z, 'linear', n=0, distmax=30e3, geterr=True)
Params:
  • x/y/z: Position and data.

  • mtype: Variogram model type (see ::variogram_model_type).

  • getall: Get verything in a dictionary whose keys are

    • "func": model function,
    • "err": fitting error,
    • "params": all parameters has a dictionary,
    • "popt": parameters than where optimised,
    • vm": VariogramModel instance,
    • "mtype": variogram model type.
  • getp, optional: Only return model parameters. Return them as a class:`dict if equal to 2.

  • variogram_<param>, optional: param is passed to variogram().

  • distfunc: Function to compute distances, or a mode argument to get_distances().

  • errfunc, optional: Callable function to compute “errors” like square root difference between to z values. It take two arguments and defaults to \sqrt(z1^2-z0^2)/2.

    Warning

    use “haversine” if input coordinates are in degrees.

  • Extra keywords are those of variogram_model(). They can be used to freeze some of the parameters.

    >>> variogram_fit(x, y, z, mtype, n=0) # fix the nugget
    
variogram_model(mtype, n, s, r, nrelmax=0.2)[source]

Get the variogram model function from its name

variogram_model_type(mtype=None)[source]

Check the the variogram model type

Params:
variogram_multifit(xx, yy, zz, mtype=None, getall=False, getp=False, **kwargs)[source]

Same as variogram_fit() but with several samples