Plotting Data on MPAS Native Grid

This notebook shows how to plot MPAS native grids

© Software was developed by Charles Doutriaux. (April 2018)

Necessary Modules

Back to Top

In [1]:
from __future__ import print_function
import e3sm_nex
import cdms2
import vcs
import requests
import numpy

Download Data

Back to Top

In [2]:
def download(fnm):
    r = requests.get("" % fnm,stream=True)
    with open(fnm,"wb") as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk:  # filter local_filename keep-alive new chunks

for filename in ["", ""]:

data_path = ""
grid_file_path = ""

Grid Info

Back to Top

In [3]:
# Reads in data from grid file
gf =

# needs to send filled data
lats = gf("grid_center_lat").filled()
lons = gf("grid_center_lon").filled()

lat_corners = gf("grid_corner_lat").filled()
lon_corners = gf("grid_corner_lon").filled()

Generate MPAS Grid

Back to Top

In [4]:
# Generate grid
grid = e3sm_nex.generateMPASGrid(lats, lons, lat_corners, lon_corners)

Load Data and Apply Grid

Back to Top

In [5]:
# Load data and apply grid
fd =
data = fd("timeMonthly_avg_activeTracers_temperature")
# Need to clean up missing/bad values
data = cdms2.MV2.masked_greater(numpy.abs(data),1.e20)
data = e3sm_nex.applyGrid(data,grid)


Back to Top

In [6]:
# plot
# create Canvas
x=vcs.init(bg=True, geometry=(1200,800))

# Create graphics method
mesh = vcs.createmeshfill()

# Only show a sub domain
mesh.datawc_x1 = -170
mesh.datawc_x2 = -50
mesh.datawc_y1 = -25
mesh.datawc_y2 = 75

# If you want to show mesh
# mesh.mesh = True

x.plot(data, mesh, ratio="autot")
/home/doutriaux1/anaconda2/envs/cdat_test/lib/python2.7/site-packages/vtk/util/ FutureWarning: Conversion of the second argument of issubdtype from `complex` to `np.complexfloating` is deprecated. In future, it will be treated as `np.complex128 == np.dtype(complex).type`.
  assert not numpy.issubdtype(z.dtype, complex), \