HTML('<iframe src=http://scitools.org.uk width=700 height=350></iframe>')
They are great for loading, exploring, analyzing and visualizing gridded
data like model outputs. iris
supports netCDF, GRIB, and PP formats so far.
Here is a quick example to load and plot data from a dap
url.
from oceans.colormaps import cm
from iris.fileformats.netcdf import load_cubes
url = 'http://data.nodc.noaa.gov/thredds/dodsC/woa/WOA09/NetCDFdata/silicate_annual_5deg.nc'
cubes = dict()
for cube in load_cubes([url]):
cubes.update({cube.long_name: cube})
print(cubes.keys())
Now let's perform a horizontal slices at the Statistical Mean
variable.
.slices
return an iterator along the depth dimension, so when we use
.next()
we extract the first depth level only.
surface = cubes['Statistical Mean'].slices(['latitude', 'longitude']).next()
iris
provides its own plotting modules. Let's test the iris.quickplot
:
import iris.quickplot as qplt
_ = qplt.contourf(surface, 25, extend='both', cmap=cm.odv)
A nice feature of iris.quickplot
is that it "knows" about the cube's
metadata. Therefore, we automagically
got a title for the figure and a unit
label for the colorbar. Let's try the iris.plot
for more control over the
plot. Here we will plot the data on a cartopy axes.
import numpy as np
import matplotlib.pyplot as plt
import iris.plot as iplt
import cartopy.crs as ccrs
levels = np.arange(0, 15, 1)
fig = plt.figure(figsize=(6, 4))
ax = plt.axes(projection=ccrs.PlateCarree())
cs = iplt.contourf(surface, cmap=cm.odv, levels=levels, extend='both')
ax.stock_img()
ax.coastlines()
gl = ax.gridlines()
dx, dy = 40, 20
_ = ax.set_xticks(range(-180, 180+dx, dx))
_ = ax.set_yticks(range(-90, 90+dy, dy))
cbar = fig.colorbar(cs, extend='both', orientation='horizontal', shrink=0.6)
_ = cbar.ax.set_xlabel(r'$\mu$mol l$^{-1}$')
We went from 2 to 14 lines of code.
In conclusion, iris.quickplot
is definitely the way to go when you want a
quick way to explorer the data. However, when you need more customization you
will probably do better with iris.plot
.
Take a look at the docs, and the following talk (from Scipy 2013) to learn more about these two packages.
from datetime import timedelta
from IPython.display import YouTubeVideo
start=int(timedelta(seconds=34).total_seconds())
YouTubeVideo("MW9wmGsscrs", start=start, autoplay=0, theme="light", color="red")
HTML(html)