PVGeo-Examples 2.0 - PVGeo+Discretize

14 篇文章 2 订阅

PVGeo-Discretize

This notebook demonstrates how to pair PVGeo and discretize for simple processing routines.

This notebook is outlined into four sections:

  1. Introduction to PVGeo
  2. Overview of new VTK interface in discretize
  3. Pairing PVGeo and discretize
  4. Examples of PVGeo in ParaView
%matplotlib notebook
import discretize
import PVGeo
import numpy as np
import pyvista
import vtk

print('NumPy Version: %s' % np.__version__)
print('PVGeo Version: %s' % PVGeo.__version__)
print('vista Version: %s' % pyvista.__version__)
print('vtk Version: %s' % vtk.VTK_VERSION)

pyvista.set_plot_theme('document')
NumPy Version: 1.18.5
PVGeo Version: 2.1.0
vista Version: 0.24.2
vtk Version: 9.0.0

1. Learn about PVGeo

To learn more about PVGeo, please refer to the first notebook: 1.0 - Welcome

2. Discretize VTK Mixin

This section demonstrates the VTK interface in discretize outlined in SimPEG/discretize#114.

Let’s check out how the new VTK interface can be used on simple mesh objects to create a VTK data object ready for VTK and/or PVGeo processing routines.

# Create a simple TensorMesh
h1 = np.linspace(.1, .5, 3)
h2 = np.linspace(.1, .5, 5)
h3 = np.linspace(.1, .5, 3)
mesh = discretize.TensorMesh([h1, h2, h3])
mesh.plotGrid()
<IPython.core.display.Javascript object>

在这里插入图片描述

<matplotlib.axes._subplots.Axes3DSubplot at 0x27f71c1ceb8>

Now that we have a TensorMesh object, we can call the toVTK() method to yield the proper VTK data object.

# Get a VTK data object
grid = mesh.toVTK()
grid
RectilinearGridInformation
N Cells45
N Points96
X Bounds0.000e+00, 9.000e-01
Y Bounds0.000e+00, 1.500e+00
Z Bounds0.000e+00, 9.000e-01
Dimensions4, 6, 4
N Arrays0

An additional feature added in SimPEG/discretize#114 is the ability to specify rotated reference frames for any given mesh object. Let’s rotate our reference frame and then convert the mesh to a VTK data object. Note that we no longer have a vtkRectilinearGrid but a vtkStructuredGrid due to having that TensorMesh rotated off of the traditional reference frame (traditional being <1,0,0>, <0,1,0>, <0,0,1>).

# Defined a rotated reference frame
mesh.axis_u = (1,-1,0)
mesh.axis_v = (-1,-1,0)
mesh.axis_w = (0,0,1)

# Check that the referenc fram is valid
mesh._validate_orientation()

# At this time, the grid code in discretize is not updated to plot the rotated grid
True
# Yield the rotated vtkStructuredGrid
grid_r = mesh.toVTK()
grid_r
StructuredGridInformation
N Cells45
N Points96
X Bounds-1.061e+00, 6.364e-01
Y Bounds-1.697e+00, 0.000e+00
Z Bounds0.000e+00, 9.000e-01
Dimensions4, 6, 4
N Arrays0

Here is a rendering of these two meshes to demonstrate the rotation:

# Note: you could also use vista.BackgroundPlotter() for interactivity
p = pyvista.Plotter(notebook=True)
p.add_mesh(grid, color='green', show_edges=True)
p.add_mesh(grid_r, color='orange', show_edges=True)
p.show_grid()
p.show()

在这里插入图片描述

3. Pairing discretize+PVGeo

In this example, we load a discretize 3D model and a topography surface that generally covers that model in space. We then use PVGeo to provide a boolean array to describe whether any given cell is above/below the topography surface for the mesh.

This is a fairly simple example… we want you to focus less on the specific task of extracting the topography and more on the idea that discretize and PVGeo are able to talk to eachother and share their processing results.

The Data

Here we load in some data we’d like to process: the Laguna del Maule Bouguer Gravity example from the SimPEG docs.

This data scene is was produced from the Laguna del Maule Bouguer Gravity example provided by Craig Miller (Maule volcanic field, Chile. Refer to Miller et al 2016 EPSL for full details.)

Miller, C. A., Williams-Jones, G., Fournier, D., & Witter, J. (2017). 3D gravity inversion and thermodynamic modelling reveal properties of shallow silicic magma reservoir beneath Laguna del Maule, Chile. Earth and Planetary Science Letters, 459, 14–27. https://doi.org/10.1016/j.epsl.2016.11.007

The rendering below shows several data sets and a model integrated together:

  • Point Data: the Bouguer gravity anomalies
  • Topography Surface
  • Inverted Model: The model has been both sliced and thresholded for low values

This rendering was created in ParaView using file I/O methods in PVGeo for UBC fomrats and general VTK filters available in ParaView. A ParaView state file is included in the data directory to recreate this scene.

在这里插入图片描述

#!head data/Craig-Chile/LdM_topo.topo
#!head data/Craig-Chile/craig_chile.msh

Let’s load the data files using a mixture of discretize and PVGeo for now to demo how PVGeo and discretize can talk to eachother.

# Load the TensorMesh and some already processed model data 
mesh = discretize.TensorMesh.readUBC('craig_chile.msh', directory='data/Craig-Chile')
models = {'lpout': mesh.readModelUBC(fileName='Lpout.mod', directory='data/Craig-Chile')}
mesh.plot_3d_slicer(v=models['lpout'], zslice=2350)
<IPython.core.display.Javascript object>

在这里插入图片描述

mesh.nC

Process the Data

Now let’s use the mesh from discretize and the topo surface in PVGeo to create a model array that describes whether or not any given cell in the model space is above/below the topogrpahy surface.

Also, let’s ignore the fact the given model data is already accounts for topography (NaN values). Let’s suppose for a moment that you are designing/inspecting your model space: Simply load the topography into a vtkPolyData object in PVGeo and feed it to the ExtractTopography algorithm.

Since the given topography file is in the 3D GIF Topography format, we can use the PVGeo.ubc.TopoReader file reader to read the file and automatically construct the vtkPolyData

# Load topography data using PVGeo
topo = PVGeo.ubc.TopoReader().apply('data/Craig-Chile/LdM_topo.topo')
topo
HeaderData Arrays
PolyDataInformation
N Cells381924
N Points381924
X Bounds3.550e+05, 3.720e+05
Y Bounds5.999e+06, 6.016e+06
Z Bounds2.050e+03, 3.104e+03
N Arrays1
NameFieldTypeN CompMinMax
ElevationPointsfloat6412.050e+033.104e+03
# Call the ExtractTopography algorithm and have it apply on the 
#    discretize mesh and the topography
extracted = PVGeo.grids.ExtractTopography().apply(mesh.toVTK(models), topo)
extracted
#print(dir(extracted))
HeaderData Arrays
RectilinearGridInformation
N Cells190440
N Points200900
X Bounds3.550e+05, 3.722e+05
Y Bounds5.999e+06, 6.016e+06
Z Bounds-5.250e+03, 3.000e+03
Dimensions70, 70, 41
N Arrays2
NameFieldTypeN CompMinMax
lpoutCellsfloat641-6.000e-013.000e-01
ExtractedCellsint3210.000e+001.000e+00
active = extracted.get_array('Extracted')
models['active'] = active
mesh.plot_3d_slicer(v=models['active'], zslice=2350)
<IPython.core.display.Javascript object>

What about plotting those orthographic slices in 3D and showing the topography and creating a whole integrated scene?

slices = extracted.slice_orthogonal()
# And then we can add more features to the scene
p = pyvista.Plotter()
p.add_mesh(topo, opacity=0.5, 
           cmap='gist_earth', clim=[1.7e+03, 3.104e+03])
p.add_mesh(slices, cmap='coolwarm')
p.show_grid()
p.show()

在这里插入图片描述

What about using a VTK algorthm?

Easy! Simply pass the VTK object to the VTK algorithm and use PVGeo’s top level functions to yield the output in NumPy or Pandas friendly data structures!

# Instantiate your algorithm
alg = vtk.vtkCellSizeFilter()
# Set the inputs
alg.SetInputDataObject(mesh.toVTK(models=models))
# Run the algorithm
alg.Update()
# Yield the output on the 0th port
out = alg.GetOutputDataObject(0)

# Get the Volme array via PVGeo
counts = PVGeo.get_array(out, 'Volume')
# Use that arry to plot up the results!
mesh.plot_3d_slicer(counts)
<IPython.core.display.Javascript object>

Or better yet, utilize vista's streamlined interface to VTK:

cell_sizes = mesh.toVTK(models=models).compute_cell_sizes()
cell_sizes.plot(scalars='Volume')

在这里插入图片描述

4. Now What?

There are tons of awesome algorithms in ParaView/VTK and PVGeo that you could use to integrate datasets and produce meaningful visualizations. At this time, using those algorithms in a standard Python environment doesn’t really make sense… They should be used directly in ParaView or pvpython to create visualizations until we have a stable toolset for interactive VTK visualizations in Jupyter Notebooks.

Note that the new VTK interface in discretize enables PVGeo to build an interface for discretize directly in ParaView.

Use the UBC suite in PVGeo which has I/O functionality for discretize to create compelling 3D visualizations of all your data!

Some algorithms that might be of interest to you:

Reference

PVGeo-Examples

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: cesium-examples-master 是一个 Cesium 的示例项目。Cesium 是一个开源的3D地球可视化引擎,能够在Web上以浏览器为平台展示地球相关的数据和图形。cesium-examples-master 包含了一系列基于 Cesium 引擎的示例代码和样例数据,供开发人员学习和参考。 这个项目提供了丰富的示例,涵盖了各种场景和功能,如地形渲染、卫星图像展示、空中飞行效果、地球热力图、数据可视化等。每个示例都提供了完整的源代码和相关资源,开发人员可以直接运行和修改,快速了解 Cesium 的使用方式和功能特性。 cesium-examples-master 的目的是帮助开发人员加快上手 Cesium,提供具体的示例代码和实现思路,同时也是一个社区贡献的项目,任何人都可以向其中添加自己的示例代码。这对于想要共享自己的 Cesium 开发经验,或者想要通过Cesium实现自己的创意项目的开发者们来说都是很有帮助的。 总之,cesium-examples-master 是一个集合了Cesium引擎的示例代码和样例数据的项目,通过这个项目,开发人员可以学习和参考Cesium的使用方式和功能特性,同时也可以贡献自己的示例代码,为Cesium社区贡献自己的力量。 ### 回答2: cesium-examples-master是一个开源的Cesium.js示例库。Cesium.js是一个基于WebGL的开源JavaScript库,用于创建3D地球和地理信息可视化应用程序。 cesium-examples-master库中包含了大量的示例代码,用于演示如何使用Cesium.js库进行地球和地理数据可视化。这些示例涵盖了各种应用场景,包括地球浏览、地理数据可视化、飞行模拟、地球时间轴等等。 这个示例库非常有用,特别是对于那些想要利用Cesium.js构建自己的3D地球和地理信息应用程序的开发人员来说。通过学习和理解这些示例代码,开发人员可以快速上手并加快应用程序的开发速度。 此外,cesium-examples-master还可以作为一个学习资源,供初学者学习Cesium.js库的使用。通过运行和修改这些示例代码,初学者可以逐步掌握Cesium.js的各种功能和技术知识。 总之,cesium-examples-master是一个非常有用的示例库,可以帮助开发人员和初学者更好地了解和应用Cesium.js库。无论是开发3D地球和地理信息应用程序,还是学习Cesium.js库的使用,这个示例库都是一个很好的资源。如果你对Cesium.js感兴趣,不妨去查看cesium-examples-master库并尝试运行其中的示例代码。 ### 回答3: cesium-examples-master是一个Cesium的示例代码库。Cesium是一个开源的地球可视化库,用于在Web浏览器中创建交互式三维地球和地球数据的应用程序。cesium-examples-master提供了许多不同类型的示例,展示了使用Cesium创建各种地球可视化应用的能力。这些示例包括地球模型的加载、地形数据的展示、地图投影的转换、地球上的点、线和面的创建等等。通过这些示例,开发者可以学习如何使用Cesium的API来构建自己的地球可视化项目,并根据自己的需求进行修改和扩展。cesium-examples-master的代码注释详细,对于刚开始学习Cesium的开发者来说是一个很好的参考工具。在cesium-examples-master中,开发者可以找到各种应用场景的示例代码,例如飞行模拟、地球上的图层切换、轨迹的绘制和动态效果等等。总之,cesium-examples-master对于想要学习和探索Cesium地球可视化库的开发者来说是一个非常有用的资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值