Como convertir unidades geológicas de Leapfrog (*.msh) a Vtk con Python y GemGIS - Tutorial

Este tutorial muestra el procedimiento completo para convertir una unidad geológica como una malla Leapfrog (*.msh) al formato VTK (Visualization Toolkit) utilizando Python y GemGIS. Sigue estos pasos para transferir de manera eficiente tus datos geológicos para su visualización avanzada, análisis y comparación con resultados de otros modelos.

Tutorial

Datos de ingreso

Puede descargar los datos de ingreso desde este enlace.

Código

#import required packages
import gemgis as gg
import numpy as np
import pyvista as pv
import os
#define mesh and vtk dir
meshDir = '../Mesh'
vtkDir = '../Vtk'
#open all meshs and filter
meshList = os.listdir(meshDir)
meshList = [x for x in meshList if x.endswith('msh')]
meshList
['GM_Breccia.msh',
 'GM_Dyke.msh',
 'GM_Granodiorite.msh',
 'GM_Marble.msh',
 'GM_Sandstone.msh']
#define a funtion to convert
def convertMshtoVtk(file):
    srcPath = os.path.join(meshDir,file)
    outPath = os.path.join(vtkDir,file[:-3]+'vtk')
    tempDict = gg.raster.read_msh(srcPath)
    tempMesh = gg.visualization.create_polydata_from_msh(tempDict)
    tempMesh.save(outPath)
    return tempMesh
#convert all vtks
GM_Breccia = convertMshtoVtk('GM_Breccia.msh')
GM_Dyke = convertMshtoVtk('GM_Dyke.msh')
GM_Granodiorite = convertMshtoVtk('GM_Granodiorite.msh')
GM_Marble = convertMshtoVtk('GM_Marble.msh')
GM_Sandstone = convertMshtoVtk('GM_Sandstone.msh')
#to prevent warnings of pyvista
import warnings
warnings.filterwarnings('ignore')
#plot geological units as vtks

p = pv.Plotter(notebook=True)

p.add_mesh(GM_Breccia, color='crimson')
p.add_mesh(GM_Dyke, color='teal')
p.add_mesh(GM_Granodiorite, color='gold')
p.add_mesh(GM_Marble, color='snow')
p.add_mesh(GM_Sandstone, color='slategrey')

#p.camera_position = [(0, 0, 5), (0, 0, 0), (0, 1, 0)]

p.show_grid(color='black')
p.set_background(color='white')
p.show()

 

Suscríbete a nuestro boletín electrónico

Suscríbase a nuestro boletín gratuito para recibir noticias, datos interesantes y fechas de nuestros cursos en recursos hídricos.

 

Posted on January 12, 2024 .