from IPython.core.display import HTML
with open('creative_commons.txt', 'r') as f:
html = f.read()
name = '2013-09-02-WOA09_horizontal'
html = """
<small>
<p> This post was written as an IPython notebook. It is available for
<a href="https://ocefpaf.github.com/python4oceanographers/downloads/
notebooks/%s.ipynb">download</a> or as a static
<a href="https://nbviewer.ipython.org/url/ocefpaf.github.com/
python4oceanographers/downloads/notebooks/%s.ipynb">html</a>.</p>
<p></p>
%s """ % (name, name, html)
%matplotlib inline
from matplotlib import style
style.use('ggplot')
This post is a quick example on how to use the World Ocean Atlas database.
Continuing the plots from the previous post we will produce a figure to show the surface salinity. We will use the same annual climatology from before.
(BTW: Check the images produced by the Aquarius satellite.)
import os
import numpy as np
import numpy.ma as ma
import matplotlib.pyplot as plt
from pandas import read_hdf
from mpl_toolkits.basemap import Basemap
from oceans.colormaps import cm
from oceans.datasets import woa_subset, map_limits
Basemap's robison
projection is probably our best option for global plots.
def make_map(projection='robin', resolution='c'):
fig, ax = plt.subplots(figsize=(10, 6))
m = Basemap(projection=projection, resolution=resolution,
lon_0=0, ax=ax)
m.drawcoastlines()
m.fillcontinents(color='0.85')
parallels = np.arange(-60, 90, 30.)
meridians = np.arange(-360, 360, 60.)
m.drawparallels(parallels, labels=[1, 0, 0, 0])
m.drawmeridians(meridians, labels=[0, 0, 1, 0])
return fig, m
Voilà! Note how [saltier](http://eesc.columbia.edu/courses/ees/climate/lectures/ saltyatlantic.html) the Atlantic is when compared to the Pacific.
fig, m = make_map()
boundary = map_limits(m)
fname = './data/surface_salinity.h5'
if os.path.isfile(fname):
dataset = read_hdf(fname, 'salinity')
else:
dataset = woa_subset(var='salinity', clim_type='annual',
resolution='1deg', levels=slice(0, 1),
**boundary)
dataset = dataset['OA Climatology']['annual'].ix[0]
dataset.to_hdf(fname, 'salinity')
lon = dataset.columns.values.astype(float)
lat = dataset.index.values.astype(float)
lon, lat = np.meshgrid(lon, lat)
surface = ma.masked_invalid(dataset.values)
cs = m.pcolormesh(lon, lat, surface, latlon=True, cmap=cm.odv)
cs.set_clim(27.5, 37.5)
cbar = dict(extend='both', shrink=0.5, pad=0.02,
orientation='horizontal', fraction=0.1)
_ = fig.colorbar(cs, **cbar)
HTML(html)
This post was written as an IPython notebook. It is available for download or as a static html.