python4oceanographers

Turning ripples into waves

Downloading and plotting World Ocean Atlas 2009 - Part 02

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.)

In [2]:
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.

In [3]:
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 the Atlantic is when compared to the Pacific.

In [4]:
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)
In [5]:
HTML(html)
Out[5]:

This post was written as an IPython notebook. It is available for download or as a static html.

Creative Commons License
python4oceanographers by Filipe Fernandes is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Based on a work at https://ocefpaf.github.io/.

Comments