PyVista is leveraged to quickly visualize 3D models of Damavand Volcano, Alborz, Iran.
Find this notebook on GitHub.
Creator of this notebook: Bane Sullivan
This is an adaption of Alexey Pechnikov and A.V.Durandin's ParaView-MoshaFault
See LinkedIn posts for more details:
Simply install PyVista (see installation for tips):
pip install -U pyvista panel
or
conda install -c conda-forge pyvista panel
The panel
installation is optional. panel
enables embeddable renderings within the notebook (it is an experimental feature).
import pyvista as pv
import numpy as np
gebco = pv.read("data/GEBCO_2019.subset.32639.0.5km_b_gamma15.0km,20.0km.anomaly.vtk")
gebco_a = pv.read("data/gebco7510_49cl.stl")
gebco_b = pv.read("data/gebco7510_55cl.stl")
aoi = pv.read("data/AOI.Damavand.32639.vtp")
def extract_subset(volume, voi):
"""Helper for filter not yet in PyVista.
Coming in https://github.com/pyvista/pyvista/pull/569
"""
import vtk
alg = vtk.vtkExtractVOI()
alg.SetVOI(voi)
alg.SetInputDataObject(volume)
alg.Update()
return pv.wrap(alg.GetOutput())
gebco_clipped = extract_subset(gebco, [175, 200, 105, 132, 98, 170])
contours = gebco_clipped.contour(np.arange(5,55,5))
contours
Header | Data Arrays | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
contours.plot(cmap="nipy_spectral", opacity=0.15, use_panel=True)
roi = [*gebco_clipped.bounds[0:4],
*aoi.bounds[4:6]]
aoi_clipped = aoi.clip_box(roi, invert=False)
pv.plot([aoi, pv.Box(roi).outline()], cpos="xy", use_panel=True)
p = pv.Plotter(window_size=np.array([1024, 768])*2)
# Add all the data we want to see
p.add_mesh(contours, cmap="nipy_spectral", opacity=0.15)
p.add_mesh(gebco_a, color="#ff0000")
p.add_mesh(gebco_b, color="#ff0000")
p.add_mesh(aoi_clipped, cmap="coolwarm", opacity=0.7)
# Add a title
p.add_text("Vent and Magma Chambers\nDamavand Volcano, Alborz")
# A nice perspective
p.camera_position = [(544065.5831913119, 3924518.576093113, 24324.3096344195),
(597885.1732914157, 3982998.0900773173, -12587.537450058662),
(0.33162714740718435, 0.26609487244915314, 0.9051060456978746)]
p.show(use_panel=True, screenshot="volcano.png")