Matplotlib overview

Lunch bytes (LB21) - October 12th 2018

  • Presentation is available on Google Slide.
  • Datasets needed to run this notebook are on Dropbox.

I got very little requests for this talk so I use my limited creativity.

  • Contour plot
  • Profile plot
  • axis, tiks, legends, labels, fonts (maybe)
  • Bathymetry with user data
  • Cartopy
    • different projections
  • Collections (Patch and Line)

In [1]:
import matplotlib.cm as cm
import matplotlib.pyplot as plt

import numpy as np
import pandas as pd
import cmocean # colormaps for oceanography
import cartopy.crs as ccrs # cartopy projection
from netCDF4 import Dataset

%matplotlib inline

1. Basic plots

argo profiles

I selected a Argo float 1901295 because it's has a nice path (http://www.argodatamgt.org/Access-to-data/Description-of-all-floats2)

The data for this float was here and I put in dataset/argo_1901295 (ftp://usgodae.org/pub/outgoing/argo/dac/bodc/1901294/)


In [2]:
# get the trajectories
datafile = 'dataset/argo_1901294/1901294_prof.nc'
file = Dataset(datafile, 'r')
lon = file.variables['LONGITUDE'][:]
lat = file.variables['LATITUDE'][:]
time = file.variables['JULD'][:]
file.close()

print('The floats drifted for %d days. (is this possible !?)' % (time[-1] - time[0]))


The floats drifted for 2690 days. (is this possible !?)

In [3]:
fig = plt.figure(figsize=(10,6), dpi=200)
ax = fig.add_subplot(1,1,1)
ax.plot(lon, lat, 'black', zorder=0)
ax.scatter(lon, lat, s=2, color='red', zorder=1)


Out[3]:
<matplotlib.collections.PathCollection at 0x1177ee240>

In [4]:
# plot one profile
profile_file = 'dataset/argo_1901294/profiles/R1901294_001.nc'
file = Dataset(profile_file, 'r')
temp = file.variables['TEMP'][:].squeeze()
psal = file.variables['PSAL'][:].squeeze()
pres = file.variables['PRES'][:].squeeze()
file.close()

In [5]:
fig = plt.figure(figsize=(10,6), dpi=200)
ax = fig.add_subplot(1,1,1)
ax.plot(temp, -pres, 'black', zorder=0) # -press in dbar to get ~depth in meters


Out[5]:
[<matplotlib.lines.Line2D at 0x118816dd8>]

In [6]:
# plot all profiles of this float
fig = plt.figure(figsize=(11,8), dpi=200)
ax1 = fig.add_subplot(2,2,3)
ax2 = fig.add_subplot(2,2,4)

for i in range(1, 271):
    if i not in [150, 174, 213, 214]: # 150 has a wrong salinity point, the others are missing
        profile_file = 'dataset/argo_1901294/profiles/R1901294_%03d.nc' % i
        file = Dataset(profile_file, 'r')
        temp = file.variables['TEMP'][:].squeeze()
        psal = file.variables['PSAL'][:].squeeze()
        pres = file.variables['PRES'][:].squeeze()
        ax1.plot(temp, -pres, linewidth=0.5) # -press in dbar to get ~depth in meters
        ax2.plot(psal, -pres, linewidth=0.5) # -press in dbar to get ~depth in meters

        
ax1.set_xlabel('Temperature [°C]')
ax1.set_ylabel('Depth [m]')
ax2.set_xlabel('Salinity [psu]')
ax2.set_ylabel('Depth [m]')


# third axis for the trajectories with cartopy
import cartopy.crs as ccrs
ax3 = fig.add_subplot(2,1,1, projection=ccrs.NearsidePerspective(central_longitude=-40, central_latitude=55, satellite_height=10000000))
ax3.coastlines(linewidths=0.5)

datafile = 'dataset/argo_1901294/1901294_prof.nc'
file = Dataset(datafile, 'r')
lon = file.variables['LONGITUDE'][:]
lat = file.variables['LATITUDE'][:]
time = file.variables['JULD'][:]
ax3.plot(lon, lat, transform=ccrs.PlateCarree())
ax3.set_global()
fig.tight_layout()



In [7]:
fig = plt.figure(figsize=(8,4), dpi=100)
ax = fig.add_subplot(1,1,1)

# generate fake data
mu, sigma = 12, 0.5
x = mu + sigma*np.random.randn(5000)

# the histogram of the data
n, bins, patches = plt.hist(x, 100, facecolor='orange', edgecolor='black', alpha=0.75)
ax.legend([r'Population ($\mu =%d, \sigma = %d$)' % (mu, sigma)])
ax.set_xlabel('Length [cm]')
ax.set_ylabel('Count [-]')
ax.set_title('Size of Panulirus interruptus at the Rickenbacker Causeway bridge')


Out[7]:
Text(0.5,1,'Size of Panulirus interruptus at the Rickenbacker Causeway bridge')

Bathymetry from external dataset

ETOPO1 is a 1 arc-minute global relief model of Earth's surface that integrates land topography and ocean bathymetry.

This function is to format the axis to °W-°E and °S-°N and only keep a multiple of nx,ny values on each axis.


In [8]:
from matplotlib.ticker import MultipleLocator, FuncFormatter

# add degree °W and °E and remove negative sign
def label_lon(x, pos):
    """The two args are the value and tick position"""
    if x > 0:
        return '%d°E' % x
    else:
        return '%d°W' % -x

# add °N and °S and remove negative sign
def label_lat(x, pos):
    """The two args are the value and tick position"""
    if x > 0:
        return '%d°N' % x
    else:
        return '%d°S' % -x


def format_axis(ax, nx=None, ny=None):
    """Function to clean up the axis of a figure
        nx,ny are the multiple in x,y axis"""
    if nx is None and ny is None:
        # keep the border but hide ticks and labels
        # ax.set_axis_off() remove border, ticks, labels
        ax.xaxis.set_ticks([])
        ax.yaxis.set_ticks([])
        ax.xaxis.set_ticklabels([])
        ax.yaxis.set_ticklabels([])
    else:
        ax.xaxis.set_major_locator(MultipleLocator(nx))
        ax.xaxis.set_major_formatter(FuncFormatter(label_lon))
        ax.yaxis.set_major_locator(MultipleLocator(ny))
        ax.yaxis.set_major_formatter(FuncFormatter(label_lat))

Function to load the bathymetry from the ETOPO1 dataset and keep values inside the box define by the two list lon = [lonmin, lonmax] and lat = [latmin, latmax] given in parameters.


In [9]:
def bathymetry_etopo(lon, lat):
    """
    Return the bathymetry for the regions specified by the input parameters
    lon: list containing min/max values of the longitude
    lat: list containing min/max values of the latitude
    """
    folder = 'dataset/etopo1/'
    nc = Dataset(folder + 'ETOPO1_Ice_c_gmt4.grd', 'r')
    elon = nc.variables['x'][...]
    elat = nc.variables['y'][...]
    
    # get bathymetry inside the region
    i0 = np.argmin((min(lon) - elon) ** 2)
    i1 = np.argmin((max(lon) - elon) ** 2)
    j0 = np.argmin((min(lat) - elat) ** 2)
    j1 = np.argmin((max(lat) - elat) ** 2)
    
    elon = elon[i0:i1]
    elat = elat[j0:j1]
    ez = nc.variables['z'][j0:j1, i0:i1]
    nc.close()
    
    
    return elon, elat, ez

In [10]:
contour = False # plot using contour or pcolormesh

# GoM boundaries 
lon = [-98, -79]
lat = [18, 32]
elon, elat, ez = bathymetry_etopo(lon, lat) # define in the cell above

# figure parameters
ratio = (lat[1] - lat[0]) / (lon[1] - lon[0])
height = 4
width = height * ratio

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(height, width), dpi=300)

if contour:
    # filled contour of the depth of the GoM
    depth_c = ax.contourf(elon, elat, ez, np.arange(-7000, 100, 100), cmap=cmocean.cm.deep_r)

    # plot land in grey, thanks Milan for this trick
    eland = np.copy(ez)
    eland[eland > 0] = 30 # percent of black
    ax.contourf(elon, elat, eland, np.arange(0, 101, 1), cmap=cm.binary)
    
else:
    # pcolormesh: - values are at the center of the cell
    #             - supports NaN (transparent)
    depth_c = ax.pcolormesh(elon, elat, ez[:-1, :-1], cmap=cmocean.cm.deep_r)

# contour plot 3000m and coastlines
ax.contour(elon, elat, ez, [-3000], colors='white', linewidths=0.2)
ax.contour(elon, elat, ez, [0], colors='black', linewidths=0.2)

ax.set_title('Bathymetry of the Gulf of Mexico')
format_axis(ax, 5, 5) # axis cleanup using function define 2 cells above
cb = plt.colorbar(depth_c)
cb.set_label('Depth [m]', size=10, labelpad=5)


2. Subplots


In [11]:
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(8, 4))

# plot on the first axis
x = np.arange(-10,10,0.25)
lx3 = ax1.scatter(x, x**3, marker='x', c='r', edgecolor='black')
lx2 = ax1.scatter(x, x**2, marker='o', c='r', edgecolor='blue')

# by default the legend elements are added in order
# ax.legend(['x^2', 'x^3'], loc='upper left') # this would be wrong

# use the handle to plot elements (lx3, lx2)
ax1.legend([lx2, lx3], ['x**2', 'x**3'], loc='upper left')

ax1.set_title('Title 1')
ax1.set_xlabel('$x$')
ax1.set_ylabel('$y$')

# plot on the second axis
x = np.arange(0,20)
ax2.plot(x, np.sqrt(x))
ax2.set_title('Title 2')
ax2.set_xlabel('$x2$')
ax2.set_ylabel('$y2$')
ax2.yaxis.tick_right()



In [12]:
# data
x = [1, 2, 3, 4, 5]
y1 = np.random.randint(low=1, high=11, size=5)
y2 = np.random.randint(low=1, high=6, size=5)
y3 = np.random.randint(low=1, high=20, size=5)

labels = ["A ", "B", "C"]

fig = plt.figure(figsize=(8, 8))
ax1 = fig.add_subplot(2,2,1)
ax1.stackplot(x, y1, y2, y3, labels=labels)
ax1.set_title('Title left')
ax1.legend(loc='upper left')

# the data can be also join together with numpy
ax2 = fig.add_subplot(2,2,2)
ax2.stackplot(x, np.vstack([y3, y2, y1]), labels=labels) 
ax2.set_title('Title right')
ax2.legend(loc='lower right')

# bottom plot takes all width
ax3 = fig.add_subplot(2,1,2)
ax3.plot(x, y1, x, y2, x, y3)
ax3.set_title('Title on the bottom plot')
ax3.legend(labels)


Out[12]:
<matplotlib.legend.Legend at 0xb217bbe48>

Importances of colormap

cmocean

https://matplotlib.org/cmocean/


In [13]:
# from https://jakevdp.github.io/blog/2014/10/16/how-bad-is-your-colormap/
def grayify_cmap(cmap):
    """Return a grayscale version of the colormap"""
    cmap = plt.cm.get_cmap(cmap)
    colors = cmap(np.arange(cmap.N))
    
    # convert RGBA to perceived greyscale luminance
    # cf. http://alienryderflex.com/hsp.html
    RGB_weight = [0.299, 0.587, 0.114]
    luminance = np.sqrt(np.dot(colors[:, :3] ** 2, RGB_weight))
    colors[:, :3] = luminance[:, np.newaxis]
    return cmap.from_list(cmap.name + "_grayscale", colors, cmap.N)

In [14]:
x = np.linspace(0, 6)
y = np.linspace(0, 3)[:, np.newaxis]
z = 10 * np.cos(x ** 2) * np.exp(-y)

cmaps = [plt.cm.jet, grayify_cmap('jet'), plt.cm.gray]
fig, axes = plt.subplots(1, 3, figsize=(8, 3), dpi=200)
fig.subplots_adjust(wspace=0)

for cmap, ax in zip(cmaps, axes):
    im = ax.imshow(z, cmap=cmap)
    ax.set_title(cmap.name)
    fig.colorbar(im, ax=ax, shrink=0.62)
fig.tight_layout()


Collections

Mapping with Cartopy

Trying the different projections


In [15]:
fig = plt.figure(figsize=(4, 4), dpi=200)
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines(linewidths=0.5)

x = np.array([-75, 32])
y = np.array([45, 45])
ax.plot(x,y,transform=ccrs.Geodetic())

# by default once you plot, the map will be zoom to the data
ax.set_global()



In [16]:
fig = plt.figure(figsize=(4, 4), dpi=200)
ax = fig.add_subplot(1,1,1,projection=ccrs.Mollweide())
ax.stock_img() # add an image on top of the current projections
ax.coastlines(linewidths=0.5)


Out[16]:
<cartopy.mpl.feature_artist.FeatureArtist at 0x1195f5fd0>

In [17]:
## Geostationary
fig = plt.figure(figsize=(3, 3), dpi=200)
ax = plt.axes(projection=ccrs.Geostationary(central_longitude = -80))
ax.coastlines(linewidths=0.5)


Out[17]:
<cartopy.mpl.feature_artist.FeatureArtist at 0xb2197a5c0>

NorthPolarStereo and SouthPolarStereo


In [18]:
# from cartopy.feature we can add all kinds of map element
from cartopy.feature import OCEAN, LAND, COASTLINE

fig = plt.figure(figsize=(5, 4), dpi=200)

# looping two opposite projections
projections = [ccrs.NorthPolarStereo(), ccrs.SouthPolarStereo()]
for i, proj in enumerate(projections):
    ax = fig.add_subplot(1, 2, i+1, projection=proj)
    ax.add_feature(OCEAN)
    ax.add_feature(COASTLINE)
    ax.add_feature(LAND)



In [19]:
from cartopy.feature import NaturalEarthFeature, COLORS, OCEAN, LAND, COASTLINE
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER

# see features interface for more details about the parameters and different data available
# https://scitools.org.uk/cartopy/docs/v0.14/matplotlib/feature_interface.html

fig = plt.figure(figsize=(8, 6), dpi=200)
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([-150, -50, 40, 85])

# color land and ocean
ax.add_feature(OCEAN)
ax.add_feature(COASTLINE)
# ax.add_feature(LAND) like OCEAN and COASTLINES are shortcuts
land_50m = NaturalEarthFeature('physical', 'land', '50m', facecolor=COLORS['land_alt1'])
ax.add_feature(land_50m)

# add provinces again from NaturalEarthFeature
# this time it's in the 'cultural' category
states = NaturalEarthFeature(category='cultural', scale='50m', facecolor='none',
                         name='admin_1_states_provinces_shp')
ax.add_feature(states, edgecolor='red', linewidths=0.2)

# modify the labels
gl = ax.gridlines(draw_labels=True, linestyle='--', color='white')
gl.xlabels_top = False
gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER



In [20]:
fig = plt.figure(figsize=(8, 6), dpi=200)
ax = fig.add_subplot(1, 1, 1, projection=ccrs.InterruptedGoodeHomolosine())
ax.coastlines(linewidths=0.5)
plt.title('Who uses this projection ?')


Out[20]:
Text(0.5,1,'Who uses this projection ?')

Retriving data from THREED server - GOES 17


In [21]:
from datetime import datetime
from siphon.catalog import TDSCatalog # https://unidata.github.io/siphon/
import metpy
import xarray as xr

# get the latest SeaSurfaceTemperature from GOES 16
nowdate = datetime.utcnow()
catalog = TDSCatalog('http://thredds-jumbo.unidata.ucar.edu/thredds/catalog/satellite/goes16/GOES16/' 
                     + 'Products/SeaSurfaceTemperature/FullDisk/' + 
                     str(nowdate.year) + str("%02d"%nowdate.month) + str("%02d"%nowdate.day) + '/catalog.xml')

info = """
Catalog information
-------------------

Base THREDDS URL: {}
Catalog name: {}
Catalog URL: {}
Metadata: {}
""".format(catalog.base_tds_url,
           catalog.catalog_name,
           catalog.catalog_url,
           catalog.metadata)

print(info)


Catalog information
-------------------

Base THREDDS URL: https://thredds-jumbo.unidata.ucar.edu
Catalog name: No name found
Catalog URL: https://thredds-jumbo.unidata.ucar.edu/thredds/catalog/satellite/goes16/GOES16/Products/SeaSurfaceTemperature/FullDisk/20181012/catalog.xml
Metadata: {'inherited': True, 'serviceName': 'GridServices', 'dataType': 'GRID', 'documentation': {'generic': ["NOAA's GOES-17 satellite has not been declared operational and its data are preliminary and undergoing testing. Users receiving these data through any dissemination means (including, but not limited to, PDA and GRB) assume all risk related to their use of GOES-17 data and NOAA disclaims any and all warranties, whether express or implied, including (without limitation) any implied warranties of merchantability or fitness for a particular purpose."]}}


In [22]:
# different services available
# not sure what this means ? I'm still learning!
for service in catalog.services:
    print(service.name)


latest
fullServices
GridServices

In [23]:
# we retrieved all the datasets of today
print('\n'.join(catalog.datasets.keys()))


OR_ABI-L2-SSTF-M3_G16_s20182842300379_e20182842356146_c20182850000217.nc
OR_ABI-L2-SSTF-M3_G16_s20182850000379_e20182850056146_c20182850100252.nc
OR_ABI-L2-SSTF-M3_G16_s20182850100379_e20182850156145_c20182850200158.nc
OR_ABI-L2-SSTF-M3_G16_s20182850200379_e20182850256146_c20182850300259.nc

In [24]:
# sort and get the latest (last) datasets
latest_dataset = sorted(catalog.datasets.keys())[-1]
dataset = catalog.datasets[latest_dataset]

# we now create an xarray from the data on the netCDF on the server
ds = dataset.remote_access(service='OPENDAP', use_xarray=True)

In [25]:
# parse the results to be able to plot it on any cartopy projections later
dqf = ds.metpy.parse_cf('DQF')  # [0,1,2,3] quality of values
sst = ds.metpy.parse_cf('SST')  # SST

In [26]:
# the data now have a projection associated with them
print(sst.metpy.cartopy_crs)


<cartopy.crs.Geostationary object at 0xb1c347b48>

In [27]:
# keep sst where the data quality is good (no clouds!) and between realistic values
sst_corrected = sst.where(dqf == 0) # keep only values where quality is good
sst_corrected = sst_corrected.where(sst_corrected.variable > 273.15) # over 0°C
sst_corrected = sst_corrected.where(sst_corrected.variable < 318.15) # under 45°C
sst_corrected = sst_corrected - 273.15 # transform to Celsius

In [28]:
# this thing is surprisingly slow to plot
# I'm sorry from the bottom of my heart
fig = plt.figure(figsize=[12, 12], dpi=100)
ax = fig.add_subplot(1,1,1, projection=sst_corrected.metpy.cartopy_crs) # metpy projection from the data no need to transform because same projection !

im = ax.pcolormesh(sst_corrected['x'], sst_corrected['y'], sst_corrected, cmap=cmocean.cm.thermal, vmin=sst_corrected.min(), vmax=sst_corrected.max())
#im = ax.pcolormesh(sst['x'], sst['y'], sst, cmap=cmocean.cm.thermal, vmin=sst.min(), vmax=sst.max())

ax.coastlines(linewidths=0.5, zorder=2)

plt.colorbar(im, shrink=0.5)


Out[28]:
<matplotlib.colorbar.Colorbar at 0xb1c3f65f8>

In [29]:
# zoom gulf of mexico
fig = plt.figure(figsize=[12, 12], dpi=100)

ax = fig.add_subplot(1,1,1, projection=sst.metpy.cartopy_crs) # metpy projection from the data
ax.set_extent([-98,-75, 18, 32])

im = ax.pcolormesh(sst['x'], sst['y'], sst, cmap=cmocean.cm.thermal, vmin=sst.min(), vmax=sst.max())

ax.coastlines(linewidths=0.5, zorder=2)

plt.colorbar(im, shrink=0.5)


Out[29]:
<matplotlib.colorbar.Colorbar at 0xb1c4c8c18>

Retrieve GFS Forecast


In [30]:
from datetime import datetime
from siphon.catalog import TDSCatalog # https://unidata.github.io/siphon/
import metpy
import xarray as xr

# get the latest GFS forecast
nowdate = datetime(2018,10,11) # datetime.utcnow()
time = '0000'
catalog = TDSCatalog('http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p25deg/GFS_Global_0p25deg_' +
                     str(nowdate.year) + str("%02d"%nowdate.month) + str("%02d"%nowdate.day) + '_' + time+ '.grib2/catalog.html')


info = """
Catalog information
-------------------

Base THREDDS URL: {}
Catalog name: {}
Catalog URL: {}
Metadata: {}
""".format(catalog.base_tds_url,
           catalog.catalog_name,
           catalog.catalog_url,
           catalog.metadata)

print(info)


Catalog information
-------------------

Base THREDDS URL: http://thredds.ucar.edu
Catalog name: GFS_Global_0p25deg_20181011_0000.grib2
Catalog URL: http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p25deg/GFS_Global_0p25deg_20181011_0000.grib2/catalog.xml
Metadata: {'inherited': True, 'serviceName': 'fullServices', 'authority': ['edu.ucar.unidata'], 'dataType': 'GRID', 'dataFormat': 'GRIB-2', 'documentation': {'summary': ['Forecasts grids starting from the 0 hour forecast every 3 hours out to 10 days, then 12 hour forecasts for days 10-16.', 'NCEP GFS Model : AWIPS 230 (G) Grid. Global Lat/Lon grid. Model runs at 0, 6, 12, and 18Z. Horizontal= 721 by 14400 points, resolution 0.25 degree, Lat/Lon projection. Vertical= 1000 to 100 hPa mandatory pressure levels (26 levels); surface, height above ground, pressure layers.', 'NCEP Global Forecast System Model, previously called AVN/MRF (Medium Range Forecast)'], 'xlink': [{'title': 'COMET MetEd (Meteorology Education and Training) documentation', 'href': 'http://meted.ucar.edu/nwp/pcu2/avintro.htm'}, {'title': 'NCEP Model Notes', 'href': 'http://www.nco.ncep.noaa.gov/pmb/products/gfs/'}, {'title': 'NCEP Model documentation', 'href': 'http://www.emc.ncep.noaa.gov/modelinfo/index.html'}, {'title': 'NCEP/NWS Model Analyses and Forecasts page', 'href': 'http://www.nco.ncep.noaa.gov/pmb/nwprod/analysis/'}, {'title': 'Unidata IDD Model Data page', 'href': 'http://www.unidata.ucar.edu/data/index.html#model'}], 'rights': ['Freely available'], 'processing_level': ['Transmitted through Unidata Internet Data Distribution.', 'Read by CDM Grib Collection.'], 'Reference Time': ['2018-10-11T00:00:00Z']}, 'creator': [{}, {}], 'property': {'Originating_or_generating_Center': 'US National Weather Service, National Centres for Environmental Prediction (NCEP)', 'Originating_or_generating_Subcenter': '0', 'GRIB_table_version': '2,1', 'Type_of_generating_process': 'Forecast', 'Analysis_or_forecast_generating_process_identifier_defined_by_originating_centre': 'Analysis from GFS (Global Forecast System)', 'file_format': 'GRIB-2', 'Conventions': 'CF-1.6', 'history': 'Read using CDM IOSP GribCollection v3', 'featureType': 'GRID'}, 'publisher': [{}, {}], 'geospatialCoverage': [{}], 'timeCoverage': [{}], 'variableMap': [{'{http://www.w3.org/1999/xlink}href': '/thredds/metadata/grib/NCEP/GFS/Global_0p25deg/GFS_Global_0p25deg_20181011_0000.grib2?metadata=variableMap', '{http://www.w3.org/1999/xlink}title': 'variables'}]}

/Users/phil/miniconda3/lib/python3.6/site-packages/siphon/catalog.py:268: UserWarning: URL http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p25deg/GFS_Global_0p25deg_20181011_0000.grib2/catalog.html returned HTML. Changing to: http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p25deg/GFS_Global_0p25deg_20181011_0000.grib2/catalog.xml
  new_url))

In [31]:
# transform the forecast into xarray
dataset = catalog.datasets[0]
ds = dataset.remote_access(service='OPENDAP', use_xarray=True)

In [32]:
# look at the content of the datasets
ds


Out[32]:
<xarray.Dataset>
Dimensions:                                                                     (altitude_above_msl: 3, depth_below_surface_layer: 4, depth_below_surface_layer_bounds_1: 2, height_above_ground: 1, height_above_ground1: 2, height_above_ground2: 1, height_above_ground3: 3, height_above_ground4: 3, height_above_ground_layer: 1, height_above_ground_layer1: 1, height_above_ground_layer1_bounds_1: 2, height_above_ground_layer_bounds_1: 2, isobaric: 31, isobaric1: 19, isobaric2: 1, isobaric3: 21, isobaric4: 26, isobaric5: 17, lat: 721, lon: 1440, potential_vorticity_surface: 2, pressure_difference_layer: 1, pressure_difference_layer1: 1, pressure_difference_layer1_bounds_1: 2, pressure_difference_layer2: 2, pressure_difference_layer2_bounds_1: 2, pressure_difference_layer_bounds_1: 2, sigma: 1, sigma_layer: 4, sigma_layer_bounds_1: 2, time: 62, time1: 69, time10: 69, time100: 78, time101: 65, time102: 64, time11: 66, time11_bounds_1: 2, time12: 63, time13: 69, time14: 62, time15: 67, time15_bounds_1: 2, time16: 63, time17: 68, time18: 66, time19: 65, time2: 69, time20: 67, time21: 77, time22: 64, time22_bounds_1: 2, time23: 67, time24: 65, time25: 74, time26: 68, time26_bounds_1: 2, time27: 69, time28: 68, time28_bounds_1: 2, time29: 70, time3: 64, time30: 73, time31: 62, time31_bounds_1: 2, time32: 62, time32_bounds_1: 2, time33: 67, time34: 67, time34_bounds_1: 2, time35: 66, time36: 61, time36_bounds_1: 2, time37: 67, time38: 67, time39: 63, time4: 69, time40: 65, time41: 64, time41_bounds_1: 2, time42: 64, time43: 73, time44: 64, time44_bounds_1: 2, time45: 66, time46: 69, time47: 66, time48: 75, time49: 65, time5: 63, time50: 68, time51: 63, time51_bounds_1: 2, time52: 63, time53: 73, time54: 69, time54_bounds_1: 2, time55: 73, time56: 68, time56_bounds_1: 2, time57: 65, time57_bounds_1: 2, time58: 67, time58_bounds_1: 2, time59: 68, time5_bounds_1: 2, time6: 66, time60: 64, time60_bounds_1: 2, time61: 70, time62: 62, time62_bounds_1: 2, time63: 63, time64: 65, time65: 66, time66: 69, time67: 67, time67_bounds_1: 2, time68: 64, time69: 76, time7: 64, time70: 68, time71: 67, time71_bounds_1: 2, time72: 65, time73: 73, time74: 67, time75: 68, time75_bounds_1: 2, time76: 65, time77: 64, time78: 66, time79: 62, time7_bounds_1: 2, time8: 69, time80: 64, time80_bounds_1: 2, time81: 75, time82: 66, time83: 69, time84: 67, time85: 69, time86: 65, time86_bounds_1: 2, time87: 71, time88: 82, time89: 72, time9: 64, time90: 63, time91: 63, time92: 80, time93: 83, time94: 75, time95: 67, time96: 67, time97: 69, time98: 66, time99: 70, time9_bounds_1: 2, time_bounds_1: 2)
Coordinates:
  * lat                                                                         (lat) float32 90.0 ...
  * lon                                                                         (lon) float32 0.0 ...
    reftime                                                                     datetime64[ns] ...
  * time                                                                        (time) datetime64[ns] 2018-10-11T03:00:00 ...
  * time1                                                                       (time1) datetime64[ns] 2018-10-11 ...
  * time2                                                                       (time2) datetime64[ns] 2018-10-11 ...
  * time3                                                                       (time3) datetime64[ns] 2018-10-11 ...
  * time4                                                                       (time4) datetime64[ns] 2018-10-11 ...
  * time5                                                                       (time5) datetime64[ns] 2018-10-11T03:00:00 ...
  * time6                                                                       (time6) datetime64[ns] 2018-10-11 ...
  * time7                                                                       (time7) datetime64[ns] 2018-10-11T03:00:00 ...
  * time8                                                                       (time8) datetime64[ns] 2018-10-11 ...
  * time9                                                                       (time9) datetime64[ns] 2018-10-11T03:00:00 ...
  * time10                                                                      (time10) datetime64[ns] 2018-10-11 ...
  * time11                                                                      (time11) datetime64[ns] 2018-10-11T03:00:00 ...
  * time12                                                                      (time12) datetime64[ns] 2018-10-11 ...
  * time13                                                                      (time13) datetime64[ns] 2018-10-11 ...
  * time14                                                                      (time14) datetime64[ns] 2018-10-11 ...
  * time15                                                                      (time15) datetime64[ns] 2018-10-11T03:00:00 ...
  * time16                                                                      (time16) datetime64[ns] 2018-10-11 ...
  * time17                                                                      (time17) datetime64[ns] 2018-10-11 ...
  * time18                                                                      (time18) datetime64[ns] 2018-10-11 ...
  * time19                                                                      (time19) datetime64[ns] 2018-10-11 ...
  * time20                                                                      (time20) datetime64[ns] 2018-10-11 ...
  * time21                                                                      (time21) datetime64[ns] 2018-10-11 ...
  * time22                                                                      (time22) datetime64[ns] 2018-10-11T03:00:00 ...
  * time23                                                                      (time23) datetime64[ns] 2018-10-11 ...
  * time24                                                                      (time24) datetime64[ns] 2018-10-11 ...
  * time25                                                                      (time25) datetime64[ns] 2018-10-11 ...
  * time26                                                                      (time26) datetime64[ns] 2018-10-11T03:00:00 ...
  * time27                                                                      (time27) datetime64[ns] 2018-10-11 ...
  * time28                                                                      (time28) datetime64[ns] 2018-10-11T03:00:00 ...
  * time29                                                                      (time29) datetime64[ns] 2018-10-11 ...
  * time30                                                                      (time30) datetime64[ns] 2018-10-11 ...
  * time31                                                                      (time31) datetime64[ns] 2018-10-11T03:00:00 ...
  * time32                                                                      (time32) datetime64[ns] 2018-10-11T03:00:00 ...
  * time33                                                                      (time33) datetime64[ns] 2018-10-11 ...
  * time34                                                                      (time34) datetime64[ns] 2018-10-11T03:00:00 ...
  * time35                                                                      (time35) datetime64[ns] 2018-10-11 ...
  * time36                                                                      (time36) datetime64[ns] 2018-10-11T03:00:00 ...
  * time37                                                                      (time37) datetime64[ns] 2018-10-11 ...
  * time38                                                                      (time38) datetime64[ns] 2018-10-11 ...
  * time39                                                                      (time39) datetime64[ns] 2018-10-11 ...
  * time40                                                                      (time40) datetime64[ns] 2018-10-11 ...
  * time41                                                                      (time41) datetime64[ns] 2018-10-11T03:00:00 ...
  * time42                                                                      (time42) datetime64[ns] 2018-10-11 ...
  * time43                                                                      (time43) datetime64[ns] 2018-10-11 ...
  * time44                                                                      (time44) datetime64[ns] 2018-10-11T03:00:00 ...
  * time45                                                                      (time45) datetime64[ns] 2018-10-11 ...
  * time46                                                                      (time46) datetime64[ns] 2018-10-11 ...
  * time47                                                                      (time47) datetime64[ns] 2018-10-11 ...
  * time48                                                                      (time48) datetime64[ns] 2018-10-11 ...
  * time49                                                                      (time49) datetime64[ns] 2018-10-11 ...
  * time50                                                                      (time50) datetime64[ns] 2018-10-11T03:00:00 ...
  * time51                                                                      (time51) datetime64[ns] 2018-10-11T03:00:00 ...
  * time52                                                                      (time52) datetime64[ns] 2018-10-11 ...
  * time53                                                                      (time53) datetime64[ns] 2018-10-11 ...
  * time54                                                                      (time54) datetime64[ns] 2018-10-11T03:00:00 ...
  * time55                                                                      (time55) datetime64[ns] 2018-10-11 ...
  * time56                                                                      (time56) datetime64[ns] 2018-10-11T03:00:00 ...
  * time57                                                                      (time57) datetime64[ns] 2018-10-11T03:00:00 ...
  * time58                                                                      (time58) datetime64[ns] 2018-10-11T03:00:00 ...
  * time59                                                                      (time59) datetime64[ns] 2018-10-11 ...
  * time60                                                                      (time60) datetime64[ns] 2018-10-11T03:00:00 ...
  * time61                                                                      (time61) datetime64[ns] 2018-10-11 ...
  * time62                                                                      (time62) datetime64[ns] 2018-10-11T03:00:00 ...
  * time63                                                                      (time63) datetime64[ns] 2018-10-11 ...
  * time64                                                                      (time64) datetime64[ns] 2018-10-11 ...
  * time65                                                                      (time65) datetime64[ns] 2018-10-11 ...
  * time66                                                                      (time66) datetime64[ns] 2018-10-11 ...
  * time67                                                                      (time67) datetime64[ns] 2018-10-11T03:00:00 ...
  * time68                                                                      (time68) datetime64[ns] 2018-10-11 ...
  * time69                                                                      (time69) datetime64[ns] 2018-10-11 ...
  * time70                                                                      (time70) datetime64[ns] 2018-10-11 ...
  * time71                                                                      (time71) datetime64[ns] 2018-10-11T03:00:00 ...
  * time72                                                                      (time72) datetime64[ns] 2018-10-11 ...
  * time73                                                                      (time73) datetime64[ns] 2018-10-11 ...
  * time74                                                                      (time74) datetime64[ns] 2018-10-11 ...
  * time75                                                                      (time75) datetime64[ns] 2018-10-11T03:00:00 ...
  * time76                                                                      (time76) datetime64[ns] 2018-10-11 ...
  * time77                                                                      (time77) datetime64[ns] 2018-10-11 ...
  * time78                                                                      (time78) datetime64[ns] 2018-10-11 ...
  * time79                                                                      (time79) datetime64[ns] 2018-10-11T03:00:00 ...
  * time80                                                                      (time80) datetime64[ns] 2018-10-11T03:00:00 ...
  * time81                                                                      (time81) datetime64[ns] 2018-10-11 ...
  * time82                                                                      (time82) datetime64[ns] 2018-10-11 ...
  * time83                                                                      (time83) datetime64[ns] 2018-10-11T03:00:00 ...
  * time84                                                                      (time84) datetime64[ns] 2018-10-11 ...
  * time85                                                                      (time85) datetime64[ns] 2018-10-11 ...
  * time86                                                                      (time86) datetime64[ns] 2018-10-11T03:00:00 ...
  * time87                                                                      (time87) datetime64[ns] 2018-10-11 ...
  * time88                                                                      (time88) datetime64[ns] 2018-10-11T03:00:00 ...
  * time89                                                                      (time89) datetime64[ns] 2018-10-11 ...
  * time90                                                                      (time90) datetime64[ns] 2018-10-11 ...
  * time91                                                                      (time91) datetime64[ns] 2018-10-11 ...
  * time92                                                                      (time92) datetime64[ns] 2018-10-11 ...
  * time93                                                                      (time93) datetime64[ns] 2018-10-11 ...
  * time94                                                                      (time94) datetime64[ns] 2018-10-11 ...
  * time95                                                                      (time95) datetime64[ns] 2018-10-11 ...
  * time96                                                                      (time96) datetime64[ns] 2018-10-11 ...
  * time97                                                                      (time97) datetime64[ns] 2018-10-11 ...
  * time98                                                                      (time98) datetime64[ns] 2018-10-11 ...
  * time99                                                                      (time99) datetime64[ns] 2018-10-11 ...
  * time100                                                                     (time100) datetime64[ns] 2018-10-11 ...
  * time101                                                                     (time101) datetime64[ns] 2018-10-11 ...
  * time102                                                                     (time102) datetime64[ns] 2018-10-11T03:00:00 ...
  * isobaric                                                                    (isobaric) float32 100.0 ...
  * height_above_ground_layer                                                   (height_above_ground_layer) float32 1500.0 ...
  * height_above_ground                                                         (height_above_ground) float32 2.0 ...
  * sigma                                                                       (sigma) float32 0.995 ...
  * depth_below_surface_layer                                                   (depth_below_surface_layer) float32 0.05 ...
  * pressure_difference_layer                                                   (pressure_difference_layer) float32 1500.0 ...
  * isobaric1                                                                   (isobaric1) float32 10000.0 ...
  * isobaric2                                                                   (isobaric2) float32 50000.0 ...
  * height_above_ground1                                                        (height_above_ground1) float32 2.0 ...
  * height_above_ground2                                                        (height_above_ground2) float32 80.0 ...
  * isobaric3                                                                   (isobaric3) float32 10000.0 ...
  * altitude_above_msl                                                          (altitude_above_msl) float32 1829.0 ...
  * height_above_ground3                                                        (height_above_ground3) float32 10.0 ...
  * height_above_ground_layer1                                                  (height_above_ground_layer1) float32 3000.0 ...
  * pressure_difference_layer1                                                  (pressure_difference_layer1) float32 12750.0 ...
  * isobaric4                                                                   (isobaric4) float32 1000.0 ...
  * pressure_difference_layer2                                                  (pressure_difference_layer2) float32 9000.0 ...
  * sigma_layer                                                                 (sigma_layer) float32 0.58000004 ...
  * height_above_ground4                                                        (height_above_ground4) float32 2.0 ...
  * isobaric5                                                                   (isobaric5) float32 100.0 ...
  * potential_vorticity_surface                                                 (potential_vorticity_surface) float32 -2e-06 ...
Dimensions without coordinates: depth_below_surface_layer_bounds_1, height_above_ground_layer1_bounds_1, height_above_ground_layer_bounds_1, pressure_difference_layer1_bounds_1, pressure_difference_layer2_bounds_1, pressure_difference_layer_bounds_1, sigma_layer_bounds_1, time11_bounds_1, time15_bounds_1, time22_bounds_1, time26_bounds_1, time28_bounds_1, time31_bounds_1, time32_bounds_1, time34_bounds_1, time36_bounds_1, time41_bounds_1, time44_bounds_1, time51_bounds_1, time54_bounds_1, time56_bounds_1, time57_bounds_1, time58_bounds_1, time5_bounds_1, time60_bounds_1, time62_bounds_1, time67_bounds_1, time71_bounds_1, time75_bounds_1, time7_bounds_1, time80_bounds_1, time86_bounds_1, time9_bounds_1, time_bounds_1
Data variables:
    LatLon_Projection                                                           int32 ...
    time_bounds                                                                 (time, time_bounds_1) datetime64[ns] ...
    time5_bounds                                                                (time5, time5_bounds_1) datetime64[ns] ...
    time7_bounds                                                                (time7, time7_bounds_1) datetime64[ns] ...
    time9_bounds                                                                (time9, time9_bounds_1) datetime64[ns] ...
    time11_bounds                                                               (time11, time11_bounds_1) datetime64[ns] ...
    time15_bounds                                                               (time15, time15_bounds_1) datetime64[ns] ...
    time22_bounds                                                               (time22, time22_bounds_1) datetime64[ns] ...
    time26_bounds                                                               (time26, time26_bounds_1) datetime64[ns] ...
    time28_bounds                                                               (time28, time28_bounds_1) datetime64[ns] ...
    time31_bounds                                                               (time31, time31_bounds_1) datetime64[ns] ...
    time32_bounds                                                               (time32, time32_bounds_1) datetime64[ns] ...
    time34_bounds                                                               (time34, time34_bounds_1) datetime64[ns] ...
    time36_bounds                                                               (time36, time36_bounds_1) datetime64[ns] ...
    time41_bounds                                                               (time41, time41_bounds_1) datetime64[ns] ...
    time44_bounds                                                               (time44, time44_bounds_1) datetime64[ns] ...
    time51_bounds                                                               (time51, time51_bounds_1) datetime64[ns] ...
    time54_bounds                                                               (time54, time54_bounds_1) datetime64[ns] ...
    time56_bounds                                                               (time56, time56_bounds_1) datetime64[ns] ...
    time57_bounds                                                               (time57, time57_bounds_1) datetime64[ns] ...
    time58_bounds                                                               (time58, time58_bounds_1) datetime64[ns] ...
    time60_bounds                                                               (time60, time60_bounds_1) datetime64[ns] ...
    time62_bounds                                                               (time62, time62_bounds_1) datetime64[ns] ...
    time67_bounds                                                               (time67, time67_bounds_1) datetime64[ns] ...
    time71_bounds                                                               (time71, time71_bounds_1) datetime64[ns] ...
    time75_bounds                                                               (time75, time75_bounds_1) datetime64[ns] ...
    time80_bounds                                                               (time80, time80_bounds_1) datetime64[ns] ...
    time86_bounds                                                               (time86, time86_bounds_1) datetime64[ns] ...
    height_above_ground_layer_bounds                                            (height_above_ground_layer, height_above_ground_layer_bounds_1) float32 ...
    depth_below_surface_layer_bounds                                            (depth_below_surface_layer, depth_below_surface_layer_bounds_1) float32 ...
    pressure_difference_layer_bounds                                            (pressure_difference_layer, pressure_difference_layer_bounds_1) float32 ...
    height_above_ground_layer1_bounds                                           (height_above_ground_layer1, height_above_ground_layer1_bounds_1) float32 ...
    pressure_difference_layer1_bounds                                           (pressure_difference_layer1, pressure_difference_layer1_bounds_1) float32 ...
    pressure_difference_layer2_bounds                                           (pressure_difference_layer2, pressure_difference_layer2_bounds_1) float32 ...
    sigma_layer_bounds                                                          (sigma_layer, sigma_layer_bounds_1) float32 ...
    Absolute_vorticity_isobaric                                                 (time93, isobaric4, lat, lon) float32 ...
    Albedo_surface_Mixed_intervals_Average                                      (time58, lat, lon) float32 ...
    Apparent_temperature_height_above_ground                                    (time37, height_above_ground, lat, lon) float32 ...
    Cloud_mixing_ratio_isobaric                                                 (time93, isobaric3, lat, lon) float32 ...
    Cloud_water_entire_atmosphere_single_layer                                  (time77, lat, lon) float32 ...
    Convective_available_potential_energy_surface                               (time99, lat, lon) float32 ...
    Convective_available_potential_energy_pressure_difference_layer             (time43, pressure_difference_layer2, lat, lon) float32 ...
    Convective_inhibition_pressure_difference_layer                             (time27, pressure_difference_layer2, lat, lon) float32 ...
    Convective_inhibition_surface                                               (time85, lat, lon) float32 ...
    Convective_precipitation_surface_Mixed_intervals_Accumulation               (time31, lat, lon) float32 ...
    Dewpoint_temperature_height_above_ground                                    (time101, height_above_ground, lat, lon) float32 ...
    Geopotential_height_potential_vorticity_surface                             (time89, potential_vorticity_surface, lat, lon) float32 ...
    Geopotential_height_surface                                                 (time84, lat, lon) float32 ...
    Geopotential_height_highest_tropospheric_freezing                           (time59, lat, lon) float32 ...
    Geopotential_height_isobaric                                                (time93, isobaric, lat, lon) float32 ...
    Geopotential_height_zeroDegC_isotherm                                       (time45, lat, lon) float32 ...
    Geopotential_height_maximum_wind                                            (time90, lat, lon) float32 ...
    Geopotential_height_tropopause                                              (time59, lat, lon) float32 ...
    Haines_index_surface                                                        (time4, lat, lon) float32 ...
    ICAO_Standard_Atmosphere_Reference_Height_maximum_wind                      (time85, lat, lon) float32 ...
    ICAO_Standard_Atmosphere_Reference_Height_tropopause                        (time24, lat, lon) float32 ...
    Ice_cover_surface                                                           (time97, lat, lon) float32 ...
    Land_cover_0__sea_1__land_surface                                           (time14, lat, lon) float32 ...
    Latent_heat_net_flux_surface_Mixed_intervals_Average                        (time36, lat, lon) float32 ...
    Maximum_temperature_height_above_ground_Mixed_intervals_Maximum             (time28, height_above_ground, lat, lon) float32 ...
    Minimum_temperature_height_above_ground_Mixed_intervals_Minimum             (time9, height_above_ground, lat, lon) float32 ...
    Momentum_flux_u-component_surface_Mixed_intervals_Average                   (time32, lat, lon) float32 ...
    Momentum_flux_v-component_surface_Mixed_intervals_Average                   (time31, lat, lon) float32 ...
    Per_cent_frozen_precipitation_surface                                       (time12, lat, lon) float32 ...
    Potential_temperature_sigma                                                 (time8, sigma, lat, lon) float32 ...
    Precipitable_water_entire_atmosphere_single_layer                           (time19, lat, lon) float32 ...
    Precipitation_rate_surface_Mixed_intervals_Average                          (time67, lat, lon) float32 ...
    Pressure_potential_vorticity_surface                                        (time55, potential_vorticity_surface, lat, lon) float32 ...
    Pressure_surface                                                            (time72, lat, lon) float32 ...
    Pressure_maximum_wind                                                       (time2, lat, lon) float32 ...
    Pressure_high_cloud_bottom_Mixed_intervals_Average                          (time80, lat, lon) float32 ...
    Pressure_high_cloud_top_Mixed_intervals_Average                             (time34, lat, lon) float32 ...
    Pressure_middle_cloud_top_Mixed_intervals_Average                           (time41, lat, lon) float32 ...
    Pressure_middle_cloud_bottom_Mixed_intervals_Average                        (time62, lat, lon) float32 ...
    Pressure_height_above_ground                                                (time74, height_above_ground2, lat, lon) float32 ...
    Pressure_low_cloud_top_Mixed_intervals_Average                              (time75, lat, lon) float32 ...
    Pressure_low_cloud_bottom_Mixed_intervals_Average                           (time26, lat, lon) float32 ...
    Pressure_tropopause                                                         (time45, lat, lon) float32 ...
    Pressure_convective_cloud_top                                               (time102, lat, lon) float32 ...
    Pressure_convective_cloud_bottom                                            (time83, lat, lon) float32 ...
    Pressure_reduced_to_MSL_msl                                                 (time63, lat, lon) float32 ...
    Relative_humidity_sigma_layer                                               (time21, sigma_layer, lat, lon) float32 ...
    Relative_humidity_pressure_difference_layer                                 (time96, pressure_difference_layer, lat, lon) float32 ...
    Relative_humidity_isobaric                                                  (time93, isobaric, lat, lon) float32 ...
    Relative_humidity_zeroDegC_isotherm                                         (time91, lat, lon) float32 ...
    Relative_humidity_height_above_ground                                       (time52, height_above_ground, lat, lon) float32 ...
    Relative_humidity_sigma                                                     (time40, sigma, lat, lon) float32 ...
    Relative_humidity_highest_tropospheric_freezing                             (time98, lat, lon) float32 ...
    Relative_humidity_entire_atmosphere_single_layer                            (time24, lat, lon) float32 ...
    Sensible_heat_net_flux_surface_Mixed_intervals_Average                      (time56, lat, lon) float32 ...
    Snow_depth_surface                                                          (time33, lat, lon) float32 ...
    Soil_temperature_depth_below_surface_layer                                  (time69, depth_below_surface_layer, lat, lon) float32 ...
    Specific_humidity_pressure_difference_layer                                 (time16, pressure_difference_layer, lat, lon) float32 ...
    Specific_humidity_height_above_ground                                       (time53, height_above_ground1, lat, lon) float32 ...
    Storm_relative_helicity_height_above_ground_layer                           (time2, height_above_ground_layer, lat, lon) float32 ...
    Temperature_potential_vorticity_surface                                     (time87, potential_vorticity_surface, lat, lon) float32 ...
    Temperature_surface                                                         (time35, lat, lon) float32 ...
    Temperature_pressure_difference_layer                                       (time10, pressure_difference_layer, lat, lon) float32 ...
    Temperature_isobaric                                                        (time93, isobaric, lat, lon) float32 ...
    Temperature_altitude_above_msl                                              (time81, altitude_above_msl, lat, lon) float32 ...
    Temperature_maximum_wind                                                    (time59, lat, lon) float32 ...
    Temperature_tropopause                                                      (time76, lat, lon) float32 ...
    Temperature_height_above_ground                                             (time94, height_above_ground4, lat, lon) float32 ...
    Temperature_middle_cloud_top_Mixed_intervals_Average                        (time, lat, lon) float32 ...
    Temperature_high_cloud_top_Mixed_intervals_Average                          (time54, lat, lon) float32 ...
    Temperature_low_cloud_top_Mixed_intervals_Average                           (time11, lat, lon) float32 ...
    Temperature_sigma                                                           (time29, sigma, lat, lon) float32 ...
    Total_cloud_cover_entire_atmosphere_Mixed_intervals_Average                 (time, lat, lon) float32 ...
    Total_cloud_cover_low_cloud_Mixed_intervals_Average                         (time41, lat, lon) float32 ...
    Total_cloud_cover_high_cloud_Mixed_intervals_Average                        (time11, lat, lon) float32 ...
    Total_cloud_cover_middle_cloud_Mixed_intervals_Average                      (time34, lat, lon) float32 ...
    Total_cloud_cover_convective_cloud                                          (time50, lat, lon) float32 ...
    Total_cloud_cover_boundary_layer_cloud_Mixed_intervals_Average              (time62, lat, lon) float32 ...
    Total_ozone_entire_atmosphere_single_layer                                  (time46, lat, lon) float32 ...
    Total_precipitation_surface_Mixed_intervals_Accumulation                    (time7, lat, lon) float32 ...
    Categorical_Rain_surface_Mixed_intervals_Average                            (time22, lat, lon) float32 ...
    Categorical_Freezing_Rain_surface_Mixed_intervals_Average                   (time86, lat, lon) float32 ...
    Categorical_Ice_Pellets_surface_Mixed_intervals_Average                     (time51, lat, lon) float32 ...
    Categorical_Snow_surface_Mixed_intervals_Average                            (time28, lat, lon) float32 ...
    Convective_Precipitation_Rate_surface_Mixed_intervals_Average               (time15, lat, lon) float32 ...
    Potential_Evaporation_Rate_surface                                          (time79, lat, lon) float32 ...
    Ozone_Mixing_Ratio_isobaric                                                 (time92, isobaric5, lat, lon) float32 ...
    Icing_severity_isobaric                                                     (time88, isobaric1, lat, lon) float32 ...
    Vertical_Speed_Shear_tropopause                                             (time3, lat, lon) float32 ...
    Vertical_Speed_Shear_potential_vorticity_surface                            (time30, potential_vorticity_surface, lat, lon) float32 ...
    U-Component_Storm_Motion_height_above_ground_layer                          (time85, height_above_ground_layer1, lat, lon) float32 ...
    V-Component_Storm_Motion_height_above_ground_layer                          (time90, height_above_ground_layer1, lat, lon) float32 ...
    Ventilation_Rate_planetary_boundary                                         (time18, lat, lon) float32 ...
    MSLP_Eta_model_reduction_msl                                                (time6, lat, lon) float32 ...
    5-Wave_Geopotential_Height_isobaric                                         (time78, isobaric2, lat, lon) float32 ...
    Zonal_Flux_of_Gravity_Wave_Stress_surface_Mixed_intervals_Average           (time60, lat, lon) float32 ...
    Meridional_Flux_of_Gravity_Wave_Stress_surface_Mixed_intervals_Average      (time71, lat, lon) float32 ...
    Planetary_Boundary_Layer_Height_surface                                     (time20, lat, lon) float32 ...
    Pressure_of_level_from_which_parcel_was_lifted_pressure_difference_layer    (time23, pressure_difference_layer1, lat, lon) float32 ...
    Downward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average          (time44, lat, lon) float32 ...
    Upward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average            (time41, lat, lon) float32 ...
    Upward_Short-Wave_Radiation_Flux_atmosphere_top_Mixed_intervals_Average     (time11, lat, lon) float32 ...
    Downward_Long-Wave_Radp_Flux_surface_Mixed_intervals_Average                (time75, lat, lon) float32 ...
    Upward_Long-Wave_Radp_Flux_atmosphere_top_Mixed_intervals_Average           (time5, lat, lon) float32 ...
    Upward_Long-Wave_Radp_Flux_surface_Mixed_intervals_Average                  (time34, lat, lon) float32 ...
    Cloud_Work_Function_entire_atmosphere_single_layer_Mixed_intervals_Average  (time80, lat, lon) float32 ...
    Sunshine_Duration_surface                                                   (time64, lat, lon) float32 ...
    Surface_Lifted_Index_surface                                                (time68, lat, lon) float32 ...
    Best_4_layer_Lifted_Index_surface                                           (time82, lat, lon) float32 ...
    Volumetric_Soil_Moisture_Content_depth_below_surface_layer                  (time100, depth_below_surface_layer, lat, lon) float32 ...
    Ground_Heat_Flux_surface_Mixed_intervals_Average                            (time67, lat, lon) float32 ...
    Wilting_Point_surface                                                       (time49, lat, lon) float32 ...
    Land-sea_coverage_nearest_neighbor_land1sea0_surface                        (time17, lat, lon) float32 ...
    Field_Capacity_surface                                                      (time38, lat, lon) float32 ...
    Vertical_velocity_pressure_isobaric                                         (time93, isobaric3, lat, lon) float32 ...
    Vertical_velocity_pressure_sigma                                            (time20, sigma, lat, lon) float32 ...
    Visibility_surface                                                          (time70, lat, lon) float32 ...
    Water_equivalent_of_accumulated_snow_depth_surface                          (time84, lat, lon) float32 ...
    Water_runoff_surface_Mixed_intervals_Accumulation                           (time57, lat, lon) float32 ...
    Wind_speed_gust_surface                                                     (time39, lat, lon) float32 ...
    u-component_of_wind_potential_vorticity_surface                             (time13, potential_vorticity_surface, lat, lon) float32 ...
    u-component_of_wind_pressure_difference_layer                               (time29, pressure_difference_layer, lat, lon) float32 ...
    u-component_of_wind_planetary_boundary                                      (time47, lat, lon) float32 ...
    u-component_of_wind_isobaric                                                (time93, isobaric, lat, lon) float32 ...
    u-component_of_wind_altitude_above_msl                                      (time48, altitude_above_msl, lat, lon) float32 ...
    u-component_of_wind_maximum_wind                                            (time45, lat, lon) float32 ...
    u-component_of_wind_height_above_ground                                     (time73, height_above_ground3, lat, lon) float32 ...
    u-component_of_wind_tropopause                                              (time95, lat, lon) float32 ...
    u-component_of_wind_sigma                                                   (time65, sigma, lat, lon) float32 ...
    v-component_of_wind_potential_vorticity_surface                             (time66, potential_vorticity_surface, lat, lon) float32 ...
    v-component_of_wind_pressure_difference_layer                               (time8, pressure_difference_layer, lat, lon) float32 ...
    v-component_of_wind_isobaric                                                (time93, isobaric, lat, lon) float32 ...
    v-component_of_wind_planetary_boundary                                      (time61, lat, lon) float32 ...
    v-component_of_wind_maximum_wind                                            (time24, lat, lon) float32 ...
    v-component_of_wind_altitude_above_msl                                      (time1, altitude_above_msl, lat, lon) float32 ...
    v-component_of_wind_height_above_ground                                     (time25, height_above_ground3, lat, lon) float32 ...
    v-component_of_wind_tropopause                                              (time74, lat, lon) float32 ...
    v-component_of_wind_sigma                                                   (time42, sigma, lat, lon) float32 ...
Attributes:
    Originating_or_generating_Center:                                        ...
    Originating_or_generating_Subcenter:                                     ...
    GRIB_table_version:                                                      ...
    Type_of_generating_process:                                              ...
    Analysis_or_forecast_generating_process_identifier_defined_by_originating...
    file_format:                                                             ...
    Conventions:                                                             ...
    history:                                                                 ...
    featureType:                                                             ...
    _CoordSysBuilder:                                                        ...

In [33]:
# now it's only a matter of finding what variable we watn to plot... for example let's try
# 'Temperature_surface'

# this could also retrieve the variable
#sst = ds['Temperature_surface'] 
 
# but this also prepare it to plot with cartopy! <3
sst = ds.metpy.parse_cf('Temperature_surface')  
print(sst.metpy.cartopy_crs) # gives us the coordinates of the data automatically


<cartopy.crs.PlateCarree object at 0xb1c639728>

In [34]:
# 93 timesteps in the forecast (global grid is 721x1440)
# there is different 'time' variable associated with each of the variable...
sst


Out[34]:
<xarray.DataArray 'Temperature_surface' (time35: 66, lat: 721, lon: 1440)>
[68523840 values with dtype=float32]
Coordinates:
  * lat      (lat) float32 90.0 89.75 89.5 89.25 89.0 88.75 88.5 88.25 88.0 ...
  * lon      (lon) float32 0.0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 2.25 2.5 ...
    reftime  datetime64[ns] ...
  * time35   (time35) datetime64[ns] 2018-10-11 2018-10-11T03:00:00 ...
    crs      object Projection: latitude_longitude
Attributes:
    long_name:                      Temperature @ Ground or water surface
    units:                          K
    abbreviation:                   TMP
    Grib_Variable_Id:               VAR_0-0-0_L1
    Grib2_Parameter:                [0 0 0]
    Grib2_Parameter_Discipline:     Meteorological products
    Grib2_Parameter_Category:       Temperature
    Grib2_Parameter_Name:           Temperature
    Grib2_Level_Type:               1
    Grib2_Level_Desc:               Ground or water surface
    Grib2_Generating_Process_Type:  Forecast

In [35]:
sst.shape


Out[35]:
(66, 721, 1440)

In [36]:
# let's plot a global map for the first time 2018-10-11T00:00:00.000000000
# When you plot the data: at this point it will download it from the server
timestep = 0
sst_plot = sst[timestep] - 273.15 # °K to °C

fig = plt.figure(figsize=[12, 12], dpi=100)
ax = fig.add_subplot(1,1,1, projection=ccrs.Mollweide()) # nice global projection
ax.set_global()


# the data are on a regular 2d grid so we have to use the transform keyword to use a projection different then PlateCarre()
im = ax.pcolormesh(sst['lon'], sst['lat'], sst_plot, cmap=cmocean.cm.thermal, transform=sst.metpy.cartopy_crs)
ax.coastlines(linewidths=0.25, zorder=2)

ax.gridlines(xlocs=np.arange(-180,210,30), ylocs=np.arange(-90,120,30),linestyle='--')
cb = plt.colorbar(im, shrink=0.3)
cb.set_label('Temperature [°C]')