Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Leguark committed Dec 14, 2023
1 parent dcf5d0d commit 63b1fc9
Show file tree
Hide file tree
Showing 116 changed files with 16,420 additions and 246 deletions.
407 changes: 407 additions & 0 deletions _downloads/15667dfd325a23fa166b9479624ac830/02_model_1_bayesian.ipynb

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions _downloads/182d45f17a36be0fd850895c86d70e9a/01_read_OMF_sites.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Reading OMF Project Into Python
===============================
This tutorial demonstrates how to read an OMF (Open Mining Format) project file in Python, visualize it using PyVista, and convert it to a format suitable for further analysis with Subsurface.
"""

# %%
# Required Libraries
# ------------------
# First, we import the necessary libraries for handling and visualizing OMF files.

import omfvista
import pyvista
import subsurface
from subsurface import TriSurf
from subsurface.visualization import to_pyvista_mesh, pv_plot
from subsurface.writer import base_structs_to_binary_file
from dotenv import dotenv_values

# %%
# Load OMF Project
# ----------------
# Here, we define a function to load an OMF project using a path specified in a .env file.

def load_omf():
config = dotenv_values()
path = config.get('PATH_TO_MODEL_2')
omf_project = omfvista.load_project(path)
return omf_project

omf_project = load_omf()

# %%
# Visualize OMF with PyVista
# --------------------------
# Utilize PyVista for an interactive visualization of the OMF project.

omf_project.plot(multi_colors=True, show_edges=True, notebook=False)

# %%
# Convert OMF to Unstructured Single Block
# ----------------------------------------
# Convert the loaded OMF project into an unstructured single block for further processing.

block_name = omf_project.get_block_name(4)
polydata_obj: pyvista.PolyData = omf_project[block_name]
unstruct_pyvista: pyvista.UnstructuredGrid = polydata_obj.cast_to_unstructured_grid()
cells_pyvista = unstruct_pyvista.cells.reshape(-1, 4)[:, 1:]

unstruct: subsurface.UnstructuredData = subsurface.UnstructuredData.from_array(
vertex=unstruct_pyvista.points,
cells=cells_pyvista,
)

# Optional: Export to Liquid Earth if required
TO_LIQUID_EARTH = False # Replace with actual condition
if TO_LIQUID_EARTH:
base_structs_to_binary_file("leapfrog1", unstruct)

# %%
# Visualize Unstructured Data
# ---------------------------
# Finally, visualize the converted unstructured data using Subsurface and PyVista.

ts = TriSurf(mesh=unstruct)
subsurface_mesh = to_pyvista_mesh(ts)
pv_plot([subsurface_mesh], image_2d=False)
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline\nfrom pyvista import set_plot_theme\nset_plot_theme('document')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Reading Model 1 OMF Project into Subsurface\n\nThis tutorial demonstrates how to read an OMF (Open Mining Format) project file and convert it into a Subsurface format for enhanced analysis and visualization.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Importing Required Libraries\nBegin by importing the necessary libraries for this tutorial.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import pandas as pd\nimport pyvista\nimport xarray\n\nimport subsurface\nfrom subsurface import TriSurf, LineSet\nfrom subsurface.visualization import to_pyvista_mesh, to_pyvista_line, init_plotter\nfrom vector_geology.utils import load_omf"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Loading the OMF Project\nLoad the OMF project file using a custom function.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"omf = load_omf(\"PATH_TO_MODEL_1\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualizing the OMF Project with PyVista\nNext, we use PyVista for an initial visualization of the OMF project.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Replace `False` with a condition or toggle to enable plotting.\nif False:\n omf.plot(multi_colors=True, show_edges=True, notebook=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualizing Unstructured Data with Subsurface and PyVista\nUse Subsurface and PyVista to visualize the unstructured data.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"meshes_far = []\n\nmeshes = []\nlines_1 = []\nlines_far = []\n\ndataset: xarray.Dataset = None\n\nfor e in range(omf.n_blocks):\n block_name = omf.get_block_name(e)\n print(block_name)\n polydata_obj: pyvista.PolyData = omf[block_name]\n # Check if the polydata is a mesh and if is not continue\n print(polydata_obj.get_cell(0).type)\n unstruct_pyvista: pyvista.UnstructuredGrid = polydata_obj.cast_to_unstructured_grid()\n\n grid = unstruct_pyvista\n cell_data = {name: grid.cell_data[name] for name in grid.cell_data}\n match polydata_obj.get_cell(0).type:\n case pyvista.CellType.TRIANGLE:\n cells_pyvista = unstruct_pyvista.cells.reshape(-1, 4)[:, 1:]\n new_cell_data = {\n **{\n \"Formation_Major_\": e,\n },\n **cell_data\n }\n unstruct: subsurface.UnstructuredData = subsurface.UnstructuredData.from_array(\n vertex=unstruct_pyvista.points,\n cells=cells_pyvista,\n cells_attr=pd.DataFrame(new_cell_data)\n )\n\n ts = TriSurf(mesh=unstruct)\n s = to_pyvista_mesh(ts)\n if e == 5:\n meshes_far.append(s) # * This mesh is far from the rest. I am still unsure what is meant to represent.\n else:\n if False:\n to_netcdf(\n base_data=unstruct,\n path=f\"./{block_name}.nc\",\n )\n meshes.append(s)\n \n\n case pyvista.CellType.LINE:\n if e > 11: continue\n continue # To ignore wells for now\n cells_pyvista = unstruct_pyvista.cells.reshape(-1, 3)[:, 1:]\n unstruct: subsurface.UnstructuredData = subsurface.UnstructuredData.from_array(\n vertex=unstruct_pyvista.points,\n cells=cells_pyvista,\n cells_attr=pd.DataFrame(cell_data)\n )\n line = LineSet(data=unstruct)\n s = to_pyvista_line(line, radius=100, as_tube=True, spline=False)\n if e <= 10:\n lines_1.append(s)\n elif e <= 11:\n lines_far.append(s)\n\nif False: # Replace with condition for exporting to Liquid Earth\n base_structs_to_binary_file(\"leapfrog1\", unstruct)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualize Unstructured Data:\nUse Subsurface and PyVista to visualize the unstructured data.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plotter = init_plotter()\nif plot_model_area := True:\n for mesh in meshes[:1]:\n plotter.add_mesh(mesh, cmap=\"magma\", opacity=1)\n\n for line in lines_far:\n plotter.add_mesh(line, cmap=\"viridis\", opacity=1)\nelse:\n # * This seems to go together\n for mesh in meshes_far:\n plotter.add_mesh(mesh, cmap=\"magma\", opacity=0.7)\n\n for line in lines_1:\n plotter.add_mesh(line, cmap=\"viridis\", opacity=1)\n\nplotter.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conclusions\nIt seems that there are two areas in the OMF but the second one does not match the Legacy report.\nOn the second area, wells do not have lithological data so there is not much we can do with it.\nFor now we will use the interpreted meshes to reconstruct the gempy model\nLithology data and gravity seems to be confidential so how much we can share in this documentation will be limited.\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading

0 comments on commit 63b1fc9

Please sign in to comment.