-
Notifications
You must be signed in to change notification settings - Fork 65
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 function for converting MPAS meshes to viz triangles #319
Conversation
@bradyrx, I haven't played around with using this approach ( I think the |
99ef287
to
3ac0f37
Compare
I was able to make a little headway with #!/usr/bin/env python
import holoviews as hv
import xarray
import numpy
import pandas as pd
import datashader
import datashader.transfer_functions as tf
from datashader.utils import export_image
from mpas_tools.viz import mesh_to_triangles
hv.extension('matplotlib')
hv.output(dpi=300, fig='png')
hv.output(backend='matplotlib')
dsMesh = xarray.open_dataset('mpaso.rst.0501-01-01_00000.nc')
dsTris = mesh_to_triangles(dsMesh, periodicCopy=True)
sst = dsMesh.temperature.isel(Time=0, nVertLevels=0).values
sstTri = sst[dsTris.triCellIndices]
sstNode = (sst[dsTris.nodeCellIndices]*dsTris.nodeCellWeights).sum('nInterp')
nTriangles = dsTris.sizes['nTriangles']
tris = numpy.arange(3*nTriangles).reshape(nTriangles, 3)
lonNode = numpy.rad2deg(dsTris.lonNode.values).ravel()
latNode = numpy.rad2deg(dsTris.latNode.values).ravel()
sstNode = sstNode.values.ravel()
verts = pd.DataFrame({'x': lonNode, 'y': latNode, 'z': sstNode})
tris = pd.DataFrame({'v0': tris[:, 0], 'v1': tris[:, 1], 'v2': tris[:, 2]})
cvs = datashader.Canvas(plot_height=800, plot_width=1600,
x_range=(0., 360.), y_range=(-90., 90.))
img = tf.shade(cvs.trimesh(verts, tris), cmap=['lightblue', 'darkblue'],
name='EC60to30')
export_image(img, filename='EC60to30_datashader') |
That looks wonderful! What's the runtime on doing something like this as of now? I.e., is it something that can really be done interactively? |
@bradyrx, For an EC30to60 mesh, definitely could be interactive. For higher res, it depends on how much of the lag I saw is one-time start-up cost of creating the geometry vs. per-render cost. I think it will be slow but might be feasible. Worth a try. Either way, this can also serve as the starting point for a holoviews or geoviews approach that might be more efficient if you have any luck figuring out how it works. Documentation and examples are pretty sparse.... |
Each pair of adjacent vertices on an MPAS cell is joined to the cell center to create a triangle. Interpolation weights and cell indices are computed so that MPAS fields at cell centers can either be plotted as "flat" to show the individual cell polygons or "gouraud" to smoothly interpolate between values from the closest cell centers.
3ac0f37
to
0cd8d60
Compare
Add modules for computing transect geometry This work builds on the triangle mesh produced for MPAS meshes in #319. 1. For a general MPAS mesh, the intersections of a transect defined by a series of lon/lat points with the edges of triangles making up an MPAS cell can be computed. 2. For the ocean, a vertical coordinate is computed for intersection points and cells below the bathymetry are culled. quadrilaterals are then divided into triangles, allowing for visualization with `tripcolor` or `tricontourf`.
Each pair of adjacent vertices on an MPAS cell is joined to the cell center to create a triangle. Interpolation weights and cell
indices are computed so that MPAS fields at cell centers can either be plotted as "flat" to show the individual cell polygons or
"gouraud" to smoothly interpolate between values from the closest cell centers.
Partially addresses #281