python的kriging工具包

PyKrige的Python项目详细描述


python的kriging工具包

https://img.shields.io/pypi/v/pykrige.svghttps://anaconda.org/conda-forge/pykrige/badges/version.svgDocumentation Statushttps://travis-ci.org/bsmurphy/PyKrige.svg?branch=masterhttps://ci.appveyor.com/api/projects/status/github/bsmurphy/PyKrige?branch=master&svg=true

该代码支持二维和三维普通克里格和通用克里格。标准变异函数模型 (线性、幂、球面、高斯、指数)是内置的,但也可以使用自定义变差函数模型。 二维通用克里格码目前支持区域线性、点对数和外部漂移项, 而3d通用kriging程序在所有三维空间中都支持区域线性漂移项。 这两个通用克里格类还支持通用的“指定”和“函数”漂移功能。 使用“指定”漂移功能,用户可以手动指定每个数据的漂移值 点和所有网格点。有了“功能”漂移能力,用户可以提供可调用的功能 定义漂移的空间坐标。该包包含一个包含函数的模块 这在使用ascii网格文件(*.asc)时应该很有用。

有关详细信息,请参阅http://pykrige.readthedocs.io/上的文档。

安装

pykrige需要python 2.7或3.5+以及numpy、scipy和matplotlib。它可以通过pypi安装,

pip install pykrige

scikit learn是参数调整和回归kriging所需的可选依赖项。

如果您使用conda,则可以使用,

从conda forge频道安装pykrige
conda install -c conda-forge pykrige

普通克里格示例

首先,我们将创建一个二维数据集以及相关的x,y网格,

importnumpyasnpimportpykrige.kriging_toolsasktfrompykrige.okimportOrdinaryKrigingdata=np.array([[0.3,1.2,0.47],[1.9,0.6,0.56],[1.1,3.2,0.74],[3.3,4.4,1.47],[4.7,3.8,1.74]])gridx=np.arange(0.0,5.5,0.5)gridy=np.arange(0.0,5.5,0.5)# Create the ordinary kriging object. Required inputs are the X-coordinates of# the data points, the Y-coordinates of the data points, and the Z-values of the# data points. If no variogram model is specified, defaults to a linear variogram# model. If no variogram model parameters are specified, then the code automatically# calculates the parameters by fitting the variogram model to the binned# experimental semivariogram. The verbose kwarg controls code talk-back, and# the enable_plotting kwarg controls the display of the semivariogram.OK=OrdinaryKriging(data[:,0],data[:,1],data[:,2],variogram_model='linear',verbose=False,enable_plotting=False)# Creates the kriged grid and the variance grid. Allows for kriging on a rectangular# grid of points, on a masked rectangular grid of points, or with arbitrary points.# (See OrdinaryKriging.__doc__ for more information.)z,ss=OK.execute('grid',gridx,gridy)# Writes the kriged grid to an ASCII grid file.kt.write_asc_grid(gridx,gridy,z,filename="output.asc")

通用克里格示例

frompykrige.ukimportUniversalKrigingimportnumpyasnpdata=np.array([[0.3,1.2,0.47],[1.9,0.6,0.56],[1.1,3.2,0.74],[3.3,4.4,1.47],[4.7,3.8,1.74]])gridx=np.arange(0.0,5.5,0.5)gridy=np.arange(0.0,5.5,0.5)# Create the ordinary kriging object. Required inputs are the X-coordinates of# the data points, the Y-coordinates of the data points, and the Z-values of the# data points. Variogram is handled as in the ordinary kriging case.# drift_terms is a list of the drift terms to include; currently supported terms# are 'regional_linear', 'point_log', and 'external_Z'. Refer to# UniversalKriging.__doc__ for more information.UK=UniversalKriging(data[:,0],data[:,1],data[:,2],variogram_model='linear',drift_terms=['regional_linear'])# Creates the kriged grid and the variance grid. Allows for kriging on a rectangular# grid of points, on a masked rectangular grid of points, or with arbitrary points.# (See UniversalKriging.__doc__ for more information.)z,ss=UK.execute('grid',gridx,gridy)

三维kriging示例

frompykrige.ok3dimportOrdinaryKriging3Dfrompykrige.uk3dimportUniversalKriging3Dimportnumpyasnpdata=np.array([[0.1,0.1,0.3,0.9],[0.2,0.1,0.4,0.8],[0.1,0.3,0.1,0.9],[0.5,0.4,0.4,0.5],[0.3,0.3,0.2,0.7]])gridx=np.arange(0.0,0.6,0.05)gridy=np.arange(0.0,0.6,0.01)gridz=np.arange(0.0,0.6,0.1)# Create the 3D ordinary kriging object and solves for the three-dimension kriged# volume and variance. Refer to OrdinaryKriging3D.__doc__ for more information.ok3d=OrdinaryKriging3D(data[:,0],data[:,1],data[:,2],data[:,3],variogram_model='linear')k3d,ss3d=ok3d.execute('grid',gridx,gridy,gridz)# Create the 3D universal kriging object and solves for the three-dimension kriged# volume and variance. Refer to UniversalKriging3D.__doc__ for more information.uk3d=UniversalKriging3D(data[:,0],data[:,1],data[:,2],data[:,3],variogram_model='linear',drift_terms=['regional_linear'])k3d,ss3d=uk3d.execute('grid',gridx,gridy,gridz)# To use the generic 'specified' drift term, the user must provide the drift values# at each data point and at every grid point. The following example is equivalent to# using a linear drift in all three spatial dimensions. Refer to# UniversalKriging3D.__doc__ for more information.zg,yg,xg=np.meshgrid(gridz,gridy,gridx,indexing='ij')uk3d=UniversalKriging3D(data[:,0],data[:,1],data[:,2],data[:,3],variogram_model='linear',drift_terms=['specified'],specified_drift=[data[:,0],data[:,1]])k3d,ss3d=uk3d.execute('grid',gridx,gridy,gridz,specified_drift_arrays=[xg,yg,zg])# To use the generic 'functional' drift term, the user must provide a callable# function that takes only the spatial dimensions as arguments. The following example# is equivalent to using a linear drift only in the x-direction. Refer to# UniversalKriging3D.__doc__ for more information.func=lambdax,y,z:xuk3d=UniversalKriging3D(data[:,0],data[:,1],data[:,2],data[:,3],variogram_model='linear',drift_terms=['functional'],functional_drift=[func])k3d,ss3d=uk3d.execute('grid',gridx,gridy,gridz)# Note that the use of the 'specified' and 'functional' generic drift capabilities is# essentially identical in the two-dimensional universal kriging class (except for a# difference in the number of spatial coordinates for the passed drift functions).# See UniversalKriging.__doc__ for more information.

kriging参数调整

sklearn.model_selection.GridSearchCV。 见Krige CV 一个更实际的例子。

回归克立格

Regression kriging可以执行 用pykrige.rk.RegressionKriging。 这个类将scikit学习回归模型作为参数,并详细说明 OrdinaryKrigingUniversalKriging类,并对ml回归预测执行更正步骤。

回归克立格的一个证明在 corresponding example

许可证

Pykrige使用BSD 3条款许可证。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用Spring的AnnotationMethodHandlerAdapter实现redirectafterpost表单?   使用“$”处理ANTLR异常,Java   从Oracle触发器启动Java Web应用程序中的进程   java如何从GWTUpload SingleUploader将照片保存到MySQL?   snappydata无法使用Java智能连接器从现有Spark安装访问snappydata存储   java将值设置/放入Springboot的Spring环境中供以后使用   java jsonsimple,从文件中读取   JavaSpring异步请求和每个线程的设置值   java如何从数组对象中删除符号并保存?   安卓如何从Java中的asynctask访问外部类中的公共变量?   java如何获取以下错误的崩溃点。它没有告诉我线路没有   曲线1D数组下的数学区域(Java)   java如何在第一个错误时停止验证?   java使用本机查询更新数据库中数据的最佳方法是什么   java事务如何真正工作简单用例(SpingBoot)?