Easy access to environmental data for analyzing environmental drivers of the dynamics of small pelagic fish

This notebook demonstrates how easy it is to retrieve data relevant to analysing environmental drivers of small pelagics using ERDDAP servers and Python. In the examples, the code needed to actually get the data, which is short and simple, are separated from code to map or graph the data once the data ar in memory, so that the more complicated plotting code doesn't obscure how simple it is to extract the desired data.

ERDDAP servers provide access to literally petabytes of data, including satellite data, fisheries survey data, glider data, animal tracking data and more.

To start we define some functions that are used throughout.

In [2]:
from mpl_toolkits.basemap import Basemap
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import numpy.ma as ma
import cmocean
import urllib
import pandas as pd
from netCDF4 import Dataset
import datetime
/Users/rmendels/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
In [3]:
def getURL(myURL, outFile):
    response = urllib.urlretrieve(myURL, outFile)
    return(response)
In [4]:
def plot_map(grid, lats, lons, myPalette):
    southlat = lats.min()
    northlat = lats.max()
    westlon = lons.min()
    eastlon = lons.max()
    latdif = abs(northlat - southlat)
    londif = abs(westlon - eastlon)
    westedge = westlon - londif * 0.1
    eastedge = eastlon + londif * 0.1
    edgedif = abs(westedge-eastedge)
    northedge = northlat - latdif * 0.1
    southedge = southlat - latdif * 0.1
    mylons,  mylats = np.meshgrid(lons, lats)
    plt.figure(figsize=(12,8))
    map = Basemap(projection = 'merc', lat_0 = (southlat + northlat)/2, (lon_0) = (westlon + eastlon)/2,
        resolution = 'h', area_thresh = 0.1,
        llcrnrlon = westedge, llcrnrlat = southedge,
        urcrnrlon = eastedge, urcrnrlat = northedge)
    map.drawcoastlines()
    map.drawcountries()
    im1 = map.fillcontinents(color = '0.3')
    im2 = map.drawmapboundary()
    im3 = map.drawmeridians(np.arange((westedge - np.mod(westedge, 5)), (eastedge + np.mod(eastedge, 5)),5),
        labels=[True, False, False, True])
    im4 = map.drawparallels(np.arange((southedge - np.mod(southedge, 5)), (northedge + np.mod(northedge, 5)),5),
        labels=[True, False, False, True])
    im5 = map.pcolormesh(mylons, mylats, grid, shading = 'flat',cmap = myPalette, latlon = True)
    cb = map.colorbar(im5, "right", size = "5%", pad = "2%")
    plt.show()

MUR SST

MUR (Multi-scale Ultra-high Resolution) is an analyzed SST product at 0.01-degree resolution going back to 2002, providing one of the longest satellite based time series at such high resolution (see https://podaac.jpl.nasa.gov/dataset/MUR-JPL-L4-GLOB-v4.1). The latest data available for a region off the west coast can be extracted and downloaded by:

In [7]:
murURL = 'http://coastwatch.pfeg.noaa.gov/erddap/griddap/jplMURSST41.nc?analysed_sst[(last):1:(last)][(22.):1:(51.)][(-140.):1:(-105)]'
result = getURL(murURL, 'murSST.nc')
sstFile = Dataset('murSST.nc')
sst = sstFile.variables['analysed_sst'][:,:,:]
latitude = sstFile.variables['latitude'][:]
longitude = sstFile.variables['longitude'][:]
sstFile.close()
sst = np.squeeze(sst)

and then the downloaded netcdf file read into memory:

In [ ]:
sstFile = Dataset('murSST.nc')
sst = sstFile.variables['analysed_sst'][:,:,:]
latitude = sstFile.variables['latitude'][:]
longitude = sstFile.variables['longitude'][:]
sstFile.close()
sst = np.squeeze(sst)

and then plotted using matplotlib and basemap:

In [10]:
plot_map(sst, latitude, longitude, cmocean.cm.thermal)
<matplotlib.figure.Figure at 0x10d92b990>

VIIRS SST and Chlorophyll

VIIRS (Visible Infrared Imaging Radiometer Suite) is a scanning radiometer, that collects visible and infrared imagery and radiometric measurements of the land, atmosphere, cryosphere, and oceans. VIIRS data is used to measure cloud and aerosol properties, ocean color, sea and land surface temperature, ice motion and temperature, fires, and Earth's albedo. Both NASA and NOAA provide VIIRS-based high resolution SST and chlorophyll products.

We look at the latest 3-day composite SST product at 750 meter resolution developed by ERD from a real-time NOAA product (see http://coastwatch.noaa.gov/cwn/cw_products_sst.html). Download the data from ERDDAP:

In [14]:
viirsSSTUrl = 'http://coastwatch.pfeg.noaa.gov/erddap/griddap/erdVHsstaWS3day.nc?sst[(last):1:(last)][(0.0):1:(0.0)][(41.):1:(31.)][(-128.):1:(-115.)]'
result = getURL(viirsSSTUrl, 'viirsSST.nc')

read in the data from the netcdf file:

In [ ]:
viirssstFile = Dataset('viirsSST.nc')
viirsSST = viirssstFile.variables['sst'][:,:,:,:]
latitude = viirssstFile.variables['latitude'][:]
longitude = viirssstFile.variables['longitude'][:]
viirssstFile.close()
viirsSST = np.squeeze(viirsSST)

and plot the data:

In [15]:
plot_map(viirsSST, latitude, longitude, cmocean.cm.thermal)