地质统计学工具箱。
gstools的Python项目详细描述
欢迎使用gstools
目的
基于许多现成的、甚至是用户定义的协方差模型,地震动为随机场的产生和变异函数的估计提供了地统计学工具。
安装
可以通过pip安装包。 在windows上,您可以安装WinPython来获取 python和pip正在运行。
pip install gstools
gstools的文档
您可以在geostat-framework.readthedocs.io下找到文档。
教程和示例
文档还包括一些tutorials,显示了gstools最重要的用例,它们是
示例文件夹中提供了更多示例。
空间随机场生成
该库的核心是空间随机场的生成。这些字段是使用随机方法生成的,由Heße et al. 2014描述。
示例
高斯协方差模型
这是一个如何用高斯协方差模型产生二维空间随机场的例子。
fromgstoolsimportSRF,Gaussianimportmatplotlib.pyplotasplt# structured field with a size 100x100 and a grid-size of 1x1x=y=range(100)model=Gaussian(dim=2,var=1,len_scale=10)srf=SRF(model)field=srf((x,y),mesh_type='structured')plt.imshow(field)plt.show()
类似的例子,但对于三维字段,则导出到VTK文件,该文件可以用ParaView可视化。
fromgstoolsimportSRF,Gaussian,vtk_exportimportmatplotlib.pyplotaspt# structured field with a size 100x100x100 and a grid-size of 1x1x1x=y=z=range(100)model=Gaussian(dim=3,var=0.6,len_scale=20)srf=SRF(model)field=srf((x,y,z),mesh_type='structured')vtk_export('3d_field',(x,y,z),field,mesh_type='structured')
截断幂律模型
gstools还实现了截断幂律变异函数,它可以表示为 标准变差函数形式的尺度相关模式的叠加,其被截断为 较高的长度刻度lu。
此示例显示基于stable model的截断幂律,由
它给出了alpha=2
的高斯模或alpha=1
的指数模
这将导致:
importnumpyasnpimportmatplotlib.pyplotaspltfromgstoolsimportSRF,TPLStablex=y=np.linspace(0,100,100)model=TPLStable(dim=2,# spatial dimensionvar=1,# variance (C is calculated internally, so that the variance is actually 1)len_low=0,# lower truncation of the power lawlen_scale=10,# length scale (a.k.a. range), len_up = len_low + len_scalenugget=0.1,# nuggetanis=0.5,# anisotropy between main direction and transversal onesangles=np.pi/4,# rotation anglesalpha=1.5,# shape parameter from the stable modelhurst=0.7,# hurst coefficient from the power law)srf=SRF(model,mean=1,mode_no=1000,seed=19970221,verbose=True)field=srf((x,y),mesh_type='structured',force_moments=True)# show the field in xy coordinatesplt.imshow(field.T,origin="lower")plt.show()
估计和拟合变异函数
场的空间结构可以用方差函数来分析,它包含与协方差函数相同的信息。
所有的协方差模型都可以通过一个简单的界面来拟合给定的变异函数数据。
示例
这是一个如何估计二维非结构场的变差函数和估计协方差参数的例子。 再做一次模特。
importnumpyasnpfromgstoolsimportSRF,Exponential,Stable,vario_estimate_unstructuredfromgstools.covmodel.plotimportplot_variogramimportmatplotlib.pyplotasplt# generate a synthetic field with an exponential modelx=np.random.RandomState(19970221).rand(1000)*100.y=np.random.RandomState(20011012).rand(1000)*100.model=Exponential(dim=2,var=2,len_scale=8)srf=SRF(model,mean=0,seed=19970221)field=srf((x,y))# estimate the variogram of the field with 40 binsbins=np.arange(40)bin_center,gamma=vario_estimate_unstructured((x,y),field,bins)plt.plot(bin_center,gamma)# fit the variogram with a stable model. (no nugget fitted)fit_model=Stable(dim=2)fit_model.fit_variogram(bin_center,gamma,nugget=False)plot_variogram(fit_model,x_max=40)# outputprint(fit_model)plt.show()
它给出:
Stable(dim=2,var=1.92,len_scale=8.15,nugget=0.0,anis=[1.],angles=[0.],alpha=1.05)
用户定义的协方差模型
gstools的核心特性之一是powerfull CovModel 类,它允许用户轻松定义协方差模型。
示例
在这里,我们通过定义 correlation函数:
fromgstoolsimportCovModelimportnumpyasnp# use CovModel as the base-classclassGau(CovModel):defcorrelation(self,r):returnnp.exp(-(r/self.len_scale)**2)
就这样!有了Gau
你现在有了一个完全工作的协方差模型,
如上图所示,可用于场生成或变差函数拟合。
查看documentation 以获取有关合并的更多信息 可选参数和优化。
VTK导出
创建字段后,可能需要将其保存到文件中,因此我们提供 方便的VTK导出例程:
fromgstoolsimportSRF,Gaussian,vtk_exportx=y=range(100)model=Gaussian(dim=2,var=1,len_scale=10)srf=SRF(model)field=srf((x,y),mesh_type='structured')vtk_export("field",(x,y),field,mesh_type='structured')
它给出了一个矩形网格vtk文件field.vtr
。
要求:
联系人
你可以通过info@geostat-framework.org联系我们。
许可证
GPL©2018-2019年