跳转到主要内容

GSTools: 地统计学工具箱。

项目描述

欢迎使用GSTools

GMD DOI PyPI version Conda Version Build Status Coverage Status Documentation Status Code style: black

GSTools-LOGO

联系方式!

GH-Discussions Slack-Swung Gitter-GSTools Email Twitter Follow

关于GSTools的YouTube教程

GSTools Transform 22 tutorial

目的

GeoStatTools提供各种目的的地统计学工具

  • 随机场生成,包括周期性边界
  • 简单、普通、通用和外部漂移克里金
  • 条件场生成
  • 不可压缩随机矢量场生成
  • (自动化)变异函数估计和拟合
  • 方向变异函数估计和建模
  • 数据归一化和转换
  • 提供多种现成的甚至用户自定义的协方差模型
  • 度量时空建模
  • 绘图和导出例程

安装

conda

GSTools可以通过在Linux、Mac和Windows上使用conda进行安装。在命令终端中输入以下命令来安装包

conda install gstools

如果您尚未为您的系统设置conda forge,请参阅conda forge上易于遵循的说明。使用conda,应安装并行化的GSTools版本。

pip

GSTools可以通过Linux、Mac和Windows上的pip进行安装。在Windows上,您可以通过安装WinPython来获取Python和pip运行。在命令终端中输入以下命令来安装包

pip install gstools

要使用pip安装最新开发版本,请参阅文档。需要指出的是,这种方式安装的是GSTools的非并行版本。如果您需要并行版本,请遵循这些简单的步骤

引用

如果您在出版物中使用GSTools,请引用我们的论文

Müller, S.,Schüler, L.,Zech, A.,和Heße, F.:GSTools v1.3:Python中地质统计学建模的工具箱,Geosci. Model Dev.,15,3161–3182,https://doi.org/10.5194/gmd-15-3161-2022,2022。

您可以通过以下方式引用GSTools的Zenodo代码出版物

Sebastian Müller & Lennart Schüler. GeoStat-Framework/GSTools. Zenodo. https://doi.org/10.5281/zenodo.1313628

如果您想引用特定版本,请查看Zenodo网站

关于GSTools的文档

您可以在geostat-framework.readthedocs.io下找到文档。

教程和示例

文档还包括一些教程,展示了GSTools最重要的用例,包括

相关的python脚本在examples文件夹中提供。

空间随机场生成

这个库的核心是空间随机场的生成。这些场是通过随机化方法生成的,该方法由Heße等人2014年描述

示例

高斯协方差模型

这是一个使用高斯协方差模型生成二维空间随机场的示例。

import gstools as gs
# structured field with a size 100x100 and a grid-size of 1x1
x = y = range(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model)
srf((x, y), mesh_type='structured')
srf.plot()

Random field

GSTools还支持地理坐标。这可以与cartopy完美配合。

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import gstools as gs
# define a structured field by latitude and longitude
lat = lon = range(-80, 81)
model = gs.Gaussian(latlon=True, len_scale=777, geo_scale=gs.KM_SCALE)
srf = gs.SRF(model, seed=12345)
field = srf.structured((lat, lon))
# Orthographic plotting with cartopy
ax = plt.subplot(projection=ccrs.Orthographic(-45, 45))
cont = ax.contourf(lon, lat, field, transform=ccrs.PlateCarree())
ax.coastlines()
ax.set_global()
plt.colorbar(cont)

lat-lon random field

将一个类似的三维场导出到VTK文件中,可以用Python中的ParaViewPyVista进行可视化

import gstools as gs
# structured field with a size 100x100x100 and a grid-size of 1x1x1
x = y = z = range(100)
model = gs.Gaussian(dim=3, len_scale=[16, 8, 4], angles=(0.8, 0.4, 0.2))
srf = gs.SRF(model)
srf((x, y, z), mesh_type='structured')
srf.vtk_export('3d_field') # Save to a VTK file for ParaView

mesh = srf.to_pyvista() # Create a PyVista mesh for plotting in Python
mesh.contour(isosurfaces=8).plot()

3d Random field

估计和拟合变异函数

可以通过变异函数分析场的空间结构,该变异函数包含与协方差函数相同的信息。

所有协方差模型都可以通过简单界面拟合给定的变异函数数据。

示例

这是一个估计二维无结构场变异函数并再次估计协方差模型参数的示例。

import numpy as np
import gstools as gs
# generate a synthetic field with an exponential model
x = np.random.RandomState(19970221).rand(1000) * 100.
y = np.random.RandomState(20011012).rand(1000) * 100.
model = gs.Exponential(dim=2, var=2, len_scale=8)
srf = gs.SRF(model, mean=0, seed=19970221)
field = srf((x, y))
# estimate the variogram of the field
bin_center, gamma = gs.vario_estimate((x, y), field)
# fit the variogram with a stable model. (no nugget fitted)
fit_model = gs.Stable(dim=2)
fit_model.fit_variogram(bin_center, gamma, nugget=False)
# output
ax = fit_model.plot(x_max=max(bin_center))
ax.scatter(bin_center, gamma)
print(fit_model)

它给出了

Stable(dim=2, var=1.85, len_scale=7.42, nugget=0.0, anis=[1.0], angles=[0.0], alpha=1.09)

Variogram

克里金与条件随机场

地统计学的一个重要部分是将克里金与条件空间随机场进行条件化以测量。通过条件随机场,可以生成一系列场实现,其变异性取决于测量的邻近性。

示例

为了更好的可视化,我们将一个一维场条件化到几个“测量”,生成100个实现并绘制它们

import numpy as np
import matplotlib.pyplot as plt
import gstools as gs

# conditions
cond_pos = [0.3, 1.9, 1.1, 3.3, 4.7]
cond_val = [0.47, 0.56, 0.74, 1.47, 1.74]

# conditioned spatial random field class
model = gs.Gaussian(dim=1, var=0.5, len_scale=2)
krige = gs.krige.Ordinary(model, cond_pos, cond_val)
cond_srf = gs.CondSRF(krige)
# same output positions for all ensemble members
grid_pos = np.linspace(0.0, 15.0, 151)
cond_srf.set_pos(grid_pos)

# seeded ensemble generation
seed = gs.random.MasterRNG(20170519)
for i in range(100):
    field = cond_srf(seed=seed(), store=f"field_{i}")
    plt.plot(grid_pos, field, color="k", alpha=0.1)
plt.scatter(cond_pos, cond_val, color="k")
plt.show()

Conditioned

用户定义的协方差模型

gstools的核心特性之一是强大的CovModel类,它允许用户轻松定义协方差模型。

示例

在这里,我们通过定义一个相关函数来重新实现高斯协方差模型,该函数接受一个无量纲距离h = r/l

import numpy as np
import gstools as gs
# use CovModel as the base-class
class Gau(gs.CovModel):
    def cor(self, h):
        return np.exp(-h**2)

这就完成了!现在您有了完整的协方差模型Gau,您可以使用它来生成场或如上所示进行变异函数拟合。

请参阅文档获取有关集成可选参数和优化的更多信息。

不可压缩矢量场生成

使用原始的Kraichnan方法,可以生成不可压缩的随机空间矢量场。

示例

import numpy as np
import gstools as gs
x = np.arange(100)
y = np.arange(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model, generator='VectorField', seed=19841203)
srf((x, y), mesh_type='structured')
srf.plot()

产生

vector field

VTK/PyVista导出

在创建了一个场之后,您可能希望将其保存到文件中,因此我们提供了一个方便的VTK导出例程,使用.vtk_export(),或者您可以使用.to_pyvista()方法创建一个VTK/PyVista数据集以供Python使用。

import gstools as gs
x = y = range(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model)
srf((x, y), mesh_type='structured')
srf.vtk_export("field") # Saves to a VTK file
mesh = srf.to_pyvista() # Create a VTK/PyVista dataset in memory
mesh.plot()

这将生成一个RectilinearGrid VTK文件field.vtr或创建一个PyVista网格在内存中,以便在Python中立即进行3D绘图。

pyvista export

要求

可选

联系

您可以通过info@geostat-framework.org联系我们。

许可证

LGPLv3 © 2018-2024

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

gstools-1.6.0.tar.gz (121.1 kB 查看哈希值)

上传时间 源码

构建版本

gstools-1.6.0-cp312-cp312-win_amd64.whl (360.6 kB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

gstools-1.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

gstools-1.6.0-cp312-cp312-macosx_11_0_arm64.whl (372.5 kB 查看哈希值)

上传时间 CPython 3.12 macOS 11.0+ ARM64

gstools-1.6.0-cp312-cp312-macosx_10_9_x86_64.whl (389.5 kB 查看哈希值)

上传时间 CPython 3.12 macOS 10.9+ x86-64

gstools-1.6.0-cp311-cp311-win_amd64.whl (360.3 kB 查看哈希值)

上传时间 CPython 3.11 Windows x86-64

gstools-1.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB 查看哈希值)

上传时间 CPython 3.11 manylinux: glibc 2.17+ x86-64

gstools-1.6.0-cp311-cp311-macosx_11_0_arm64.whl (369.3 kB 查看哈希值)

上传时间 CPython 3.11 macOS 11.0+ ARM64

gstools-1.6.0-cp311-cp311-macosx_10_9_x86_64.whl (386.4 kB 查看哈希值)

上传时间 CPython 3.11 macOS 10.9+ x86-64

gstools-1.6.0-cp310-cp310-win_amd64.whl (360.3 kB 查看哈希值)

上传时间 CPython 3.10 Windows x86-64

gstools-1.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB 查看哈希值)

上传时间 CPython 3.10 manylinux: glibc 2.17+ x86-64

gstools-1.6.0-cp310-cp310-macosx_11_0_arm64.whl (369.2 kB 查看哈希值)

上传于 CPython 3.10 macOS 11.0+ ARM64

gstools-1.6.0-cp310-cp310-macosx_10_9_x86_64.whl (386.2 kB 查看哈希值)

上传于 CPython 3.10 macOS 10.9+ x86-64

gstools-1.6.0-cp39-cp39-win_amd64.whl (361.9 kB 查看哈希值)

上传于 CPython 3.9 Windows x86-64

gstools-1.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ x86-64

gstools-1.6.0-cp39-cp39-macosx_11_0_arm64.whl (370.9 kB 查看哈希值)

上传于 CPython 3.9 macOS 11.0+ ARM64

gstools-1.6.0-cp39-cp39-macosx_10_9_x86_64.whl (388.3 kB 查看哈希值)

上传于 CPython 3.9 macOS 10.9+ x86-64

gstools-1.6.0-cp38-cp38-win_amd64.whl (361.6 kB 查看哈希值)

上传于 CPython 3.8 Windows x86-64

gstools-1.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ x86-64

gstools-1.6.0-cp38-cp38-macosx_11_0_arm64.whl (370.0 kB 查看哈希值)

上传于 CPython 3.8 macOS 11.0+ ARM64

gstools-1.6.0-cp38-cp38-macosx_10_9_x86_64.whl (387.3 kB 查看哈希值)

上传于 CPython 3.8 macOS 10.9+ x86-64

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面