Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access for vtkToTensorMesh function #140

Merged
merged 3 commits into from
Mar 8, 2019
Merged

Add access for vtkToTensorMesh function #140

merged 3 commits into from
Mar 8, 2019

Conversation

banesullivan
Copy link
Member

@banesullivan banesullivan commented Mar 6, 2019

The code was already in discretize, these changes just make the function accessible to users to convert vtkRectilinearGrid objects to TensorMesh objects.

Needed this recently for a project - it was easiest to create my mesh in vtki and repeatedly visualize it while tweaking its size. Then I could convert it to discretize to use in an inversion.

Example

For example (needs to be done in IPython)

import vtki
from vtki import examples
import discretize
import numpy as np

# Create a plotting window
p = vtki.BackgroundPlotter()
p.show_grid()
# Get a sample topo surface from vtki
# Note: this requires vtki>=0.17.1
topo = examples.download_st_helens().warp_by_scalar()

p.add_mesh(topo, name='topo')
# Create the mesh interactively
# tweak these parameters and rerun this cell until satisfied

b = topo.bounds
xcoords = np.linspace(b[0], b[1], 50)
ycoords = np.linspace(b[2], b[3], 50)
zcoords = np.linspace(b[4]-5000, b[5], 50)

mesh = vtki.RectilinearGrid(xcoords, ycoords, zcoords)

p.add_mesh(mesh, name='mesh', opacity=0.5, show_edges=True)
# output the mesh
mesh
RectilinearGridInformation
N Cells117649
N Points125000
X Bounds5.579e+05, 5.677e+05
Y Bounds5.108e+06, 5.122e+06
Z Bounds-3.636e+03, 3.225e+03
Volume9.381e+11
N Scalars0
# Once satisfied, convert to discretize:
dmesh, _ = discretize.TensorMesh.vtkToTensorMesh(mesh)
dmesh

<discretize.TensorMesh.TensorMesh at 0xb2a555588>

And a GIF to demo

ezgif com-video-to-gif

@codecov
Copy link

codecov bot commented Mar 6, 2019

Codecov Report

Merging #140 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #140      +/-   ##
==========================================
+ Coverage   72.75%   72.76%   +0.01%     
==========================================
  Files          20       20              
  Lines        4525     4527       +2     
==========================================
+ Hits         3292     3294       +2     
  Misses       1233     1233
Impacted Files Coverage Δ
discretize/mixins/vtkModule.py 81.9% <100%> (+0.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f6d483...915b524. Read the comment docs.

@banesullivan banesullivan added the viz Anything about visualization label Mar 6, 2019
Copy link
Member

@lheagy lheagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Nice work @banesullivan - many thanks for the GIF :)

@lheagy lheagy merged commit d4f35d9 into master Mar 8, 2019
@lheagy lheagy deleted the feat/vtk branch March 8, 2019 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
viz Anything about visualization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants