Update TensorMesh-OMF interface
- from pr #174
- commits from @banesullivan
- review from @lheagy
Overview
This release adds full support for going back and forth between OMF and discretize.TensorMesh
. The OMF support implemented in a previous release only went one way (disscretize
➡️ OMF) and had a bug that messed up the spatial reference of the OMF mesh. This release makes it seamless to go back and forth (discretize
to_omf(models)
method and load your TensorMesh
s into other software that supports OMF (e.g. Leapfrog)!
Notes
- At the moment, only
TensorMesh
s are supported by OMF - OMFv2 should bring more support for Curvilinear and Tree meshes. When that's released we can fill in the methods that currently raises a
NotImplementedError
- These changes makes updates to the
TensorMesh
-OMF interface to make going to/from OMF/discretize more fluid.
Example
import discretize
import omf
import numpy as np
# Make a TensorMesh
h = np.ones(16)
mesh = discretize.TensorMesh([h, 2*h, 3*h])
vec = np.arange(mesh.nC)
models = {'arange': vec}
# Make an OMF Element
omf_element = mesh.to_omf(models)
# Use OMF to save that element to an OMF project
proj = omf.Project(
name='My project',
description='The most awesome project I have ever worked '\
'on and this is a lengthy description of how '\
'awesome it is.',
)
# Add the volume element
proj.elements = [omf_element,]
# Verify all is good
assert proj.validate()
# Write it out
omf.OMFWriter(proj, 'myproject.omf')
And now you can use the .omf
project file with your tensor mesh or many tensor meshes in your favorite software that supports OMF (e.g. Leapfrog).
Or you could verify this all worked with omfvista
:
import omfvista
foo = omfvista.load_project('myproject.omf')
foo.plot()