Apply the k-means clustering on the NCEP/NCAR reanalysis 500hPa geopotential height (Z500) anomalies to get the North Atlantic winter weather regimes, including:
In [1]:
import numpy as np
import matplotlib.pyplot as plt
import xarray as xr
# personal packages
from xlearn.cluster import KMeans
from pyingrid import Ingrid
import geoxarray
%matplotlib inline
In [2]:
ig = Ingrid('http://iridl.ldeo.columbia.edu',
'SOURCES/.NOAA/.NCEP-NCAR/.CDAS-1/.MONTHLY',
'.Intrinsic/.PressureLevel/.phi')\
.do('P(500)VALUES') \
.do('T(Dec 1979)(Mar 2010)RANGE')\
.do('yearly-anomalies') \
.do('T(Dec)(Jan)(Feb)(Mar)VALUES')\
.do('X -90 2 60 GRID Y 80 -2 20 GRID')
print(ig)
print('\n[Final data URL]:\n', ig.to_url())
In [3]:
ds = ig.to_dataset()
print(ds)
In [4]:
da = ds.sel(P=500).phi.load()
print(da.name, da.dims)
print(da.coords)
In [5]:
m = KMeans(n_clusters=4, random_state=0, n_jobs=-1).fit(da)
print(m)
In [6]:
fig, axes = plt.subplots(2,2, figsize=(8,8))
regimes = ['NAO$^-$', 'NAO$^+$', 'Blocking', 'Atlantic Ridge']
tags = list('abcd')
for i in range(m.n_clusters):
m.plot_cluster_centers(label=i,
proj='ortho',
plot_type='contourf+',
levels=np.arange(-110, 111, 20),
units='m',
ax=axes.flat[i])
title = '{}, {}'.format(regimes[i],
axes.flat[i].title.get_text())
plt.title(title)
plt.text(0, 1, tags[i],
transform=axes.flat[i].transAxes,
va='bottom',
fontsize=plt.rcParams['font.size']*2,
fontweight='bold')