52 Digitizing data from PyVista Meshes#

The topography of an area can be visualized in 3D with PyVista.

[ ]:
#<img src="../images/tutorial52_cover.png">

Set File Paths and download Tutorial Data#

If you downloaded the latest GemGIS version from the Github repository, append the path so that the package can be imported successfully. Otherwise, it is recommended to install GemGIS via pip install gemgis and import GemGIS using import gemgis as gg. In addition, the file path to the folder where the data is being stored is set. The tutorial data is downloaded using Pooch (https://www.fatiando.org/pooch/latest/index.html) and stored in the specified folder. Use pip install pooch if Pooch is not installed on your system yet.

[1]:
import gemgis as gg

file_path ='data/52_digitizing_data_from_pyvista_meshes/'
WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
C:\Users\ale93371\Anaconda3\envs\test_gempy\lib\site-packages\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
  warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
[2]:
gg.download_gemgis_data.download_tutorial_data(filename="52_digitizing_data_from_pyvista_meshes.zip", dirpath=file_path)
Downloading file '52_digitizing_data_from_pyvista_meshes.zip' from 'https://rwth-aachen.sciebo.de/s/AfXRsZywYDbUF34/download?path=%2F52_digitizing_data_from_pyvista_meshes.zip' to 'C:\Users\ale93371\Documents\gemgis\docs\getting_started\tutorial\data\52_digitizing_data_from_pyvista_meshes'.

Loading the data#

A 50 m DEM of the Münsterland Basin is loaded to illustrate the visualizing of topography in PyVista. The data will be used under Datenlizenz Deutschland – Zero – Version 2.0. It was obtained from the WCS Service https://www.wcs.nrw.de/geobasis/wcs_nw_dgm. The data will automatically be converted to a StructuredGrid with Elevation [m] as data array.

[2]:
import pyvista as pv

mesh = gg.visualization.read_raster(path=file_path + 'DEM50.tif',
                                    nodata_val=9999.0,
                                    name='Elevation [m]')

mesh
WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
C:\Users\ale93371\Anaconda3\envs\test_gempy\lib\site-packages\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
  warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
[2]:
HeaderData Arrays
StructuredGridInformation
N Cells5595201
N Points5600000
X Bounds3.236e+07, 3.250e+07
Y Bounds5.700e+06, 5.800e+06
Z Bounds0.000e+00, 0.000e+00
Dimensions2000, 2800, 1
N Arrays1
NameFieldTypeN CompMinMax
Elevation [m]Pointsfloat3210.000e+005.038e+02

Plotting the data in 2D#

[3]:
import rasterio

dem = rasterio.open(file_path + 'DEM50.tif')
dem.read(1)
[3]:
array([[  0.  ,   0.  ,   0.  , ...,  40.1 ,  40.09,  44.58],
       [  0.  ,   0.  ,   0.  , ...,  40.08,  40.07,  44.21],
       [  0.  ,   0.  ,   0.  , ...,  40.14,  44.21,  43.98],
       ...,
       [100.56, 102.14, 102.17, ...,   0.  ,   0.  ,   0.  ],
       [ 99.44,  99.85,  99.77, ...,   0.  ,   0.  ,   0.  ],
       [ 88.32,  91.76,  98.68, ...,   0.  ,   0.  ,   0.  ]],
      dtype=float32)
[4]:
import matplotlib.pyplot as plt

im = plt.imshow(dem.read(1), cmap='gist_earth', vmin=0, vmax=500)
cbar = plt.colorbar(im)
cbar.set_label('m')
../../_images/getting_started_tutorial_52_digitizing_data_from_pyvista_meshes_9_0.png

Wrap Mesh by Scalars#

The dataset’s points are wrapped by a point data scalars array’s values.

[5]:
topo = mesh.warp_by_scalar(scalars="Elevation [m]", factor=1.0)

topo
[5]:
HeaderData Arrays
StructuredGridInformation
N Cells5595201
N Points5600000
X Bounds3.236e+07, 3.250e+07
Y Bounds5.700e+06, 5.800e+06
Z Bounds0.000e+00, 5.038e+02
Dimensions2000, 2800, 1
N Arrays1
NameFieldTypeN CompMinMax
Elevation [m]Pointsfloat3210.000e+005.038e+02

Plotting the Mesh#

The mesh can then easily be plotted with PyVista

[6]:
sargs = dict(fmt="%.0f", color='black')


p = pv.Plotter(notebook=True)
p.add_mesh(mesh=topo, cmap='gist_earth', scalar_bar_args=sargs, clim=[-0, 500])

p.set_background('white')
p.show_grid(color='black')
p.set_scale(1,1,10)
p.show()
../../_images/getting_started_tutorial_52_digitizing_data_from_pyvista_meshes_13_0.png
[7]:
p = pv.Plotter(notebook=True)
p.add_mesh(pv.Sphere(), show_edges=True)
p.enable_geodesic_picking()
p.show()
[7]:
[(1.9410089246532642, 1.9117894925560552, 1.9264378181907793),
 (0.0, 0.0, 0.0),
 (-0.4096375714326179, -0.4068542655596967, 0.8164965809277261)]
[21]:
sargs = dict(fmt="%.0f", color='black')


p = pv.Plotter(notebook=True)
p.add_mesh(mesh=topo, cmap='gist_earth', scalar_bar_args=sargs, clim=[-0, 500])

p.enable_geodesic_picking(show_message=True)

p.set_background('white')
p.show_grid(color='black')
p.set_scale(1,1,10)
p.show()
[21]:
[(32513908.06643164, 5851789.661366982, 30759.992596354175),
 (32430000.0, 5750000.0, 251.9149932861328),
 (-0.732512038854102, -0.5593046377635457, 0.3880778724817944)]
[12]:
p.picked_geodesic
[12]:
PolyDataInformation
N Cells0
N Points0
X Bounds1.000e+00, -1.000e+00
Y Bounds1.000e+00, -1.000e+00
Z Bounds1.000e+00, -1.000e+00
N Arrays0