PacIOOS Glider Example

This notebook demonstrates the ability to discover OOI data products, open an erddap session, access the data, and plot the data

Imports


In [1]:
import sys
import os
import numpy as np
import datetime as dt
import matplotlib.pyplot as plt
# Make it so notebook knows how to access ooitk from the notebook dir
sys.path.append(os.path.dirname(os.getcwd()))
from ooitk.data_catalog import DataProductCatalog
from ooitk.display import ListTable
from ooitk.session import ERDDAPSession
from mpl_toolkits.basemap import Basemap, shiftgrid, cm

sys.path.append(os.path.dirname(os.getcwd()))

Get Data Products


In [2]:
dpc = DataProductCatalog('localhost', 3000)
data_product_listing = dpc.list_data_products()

In [3]:
listing = ListTable([['name', 'description', 'id']])
listing.extend([[i['name'], i['description'], i['_id']] for i in data_product_listing[:10]])
listing


Out[3]:
namedescriptionid
PacIOOS Ocean Gliders: SeaGlider 523: Mission 45f2b92a89caa4ff39ede2fb9056d3086

In [4]:
# Open and download the ERDDAP Data
session = ERDDAPSession('http://localhost:9000/erddap/tabledap/data5f2b92a89caa4ff39ede2fb9056d3086.html')

# Download the NetCDF dataset and apply the following constraints on the DAP request
session.open()

List all of the variables available


In [5]:
session.print_vars()


time
density
pressure
temp
salinity
latitude
longitude
conductivity
depth

In [6]:
# Get time
time = session.variables['time'][:]

# Get pressure (dbar ~= meters of depth)
print session.variables['pressure']
pressure = session.variables['pressure'][:]

# Get temperature and salinity
temp = session.variables['temp']
salinity = session.variables['salinity']


<type 'netCDF4.Variable'>
float64 pressure(row)
    actual_range: [  1.71110762e-01   4.04777606e+02]
    data_product_level: unknown
    ioos_category: Pressure
    standard_name: sea_water_pressure
    units: dbar
unlimited dimensions: 
current shape = (1000,)
filling off

Plot profiles


In [7]:
fig, ax1 = plt.subplots(figsize=(7, 9))
ax1.set_xlabel('Temperature (C)')
ax1.set_ylabel('Depth (m)')

ax1.plot(temp, pressure, 'b.')
ax1.invert_yaxis()
for tl in ax1.get_xticklabels():
    tl.set_color('b')
ax1.xaxis.label.set_color('blue')

ax2x = ax1.twinx()
ax2 = ax2x.twiny()
ax2.plot(salinity, pressure, 'r.')
ax2.set_xlabel('Salinity')
ax2.invert_yaxis()
for tl in ax2.get_xticklabels():
    tl.set_color('r')
ax2.xaxis.label.set_color('red')
plt.show()


Plot Glider trajectory


In [8]:
# Get lat lon
lat = session.variables['latitude'][:]
lon = session.variables['longitude'][:]

fig = plt.figure(figsize=[10,10])
fig = Basemap(projection='merc', llcrnrlat = np.min(lat)-0.05, urcrnrlat = np.max(lat)+0.05, llcrnrlon = np.min(lon)-0.05, urcrnrlon = np.max(lon)+0.05, resolution='l')

#draw coasts
fig.drawcoastlines()

# draw boundary, fill background.
fig.drawmapboundary(fill_color='lightblue')
fig.fillcontinents(color='#FFD39B',lake_color='lightblue')

# draw parallels
fig.drawparallels(np.arange(20,22,.1),labels=[1,1,0,1], fontsize=10)

# draw meridians
fig.drawmeridians(np.arange(-158,-157,.1),labels=[1,1,0,1], fontsize=10)

x, y = fig(lon, lat)
fig.plot(x,y,'ko',markersize=1)

plt.show()



In [9]:
# Close the 
session.close()