In [1]:
%matplotlib inline
import os
from pycmbs.data import Data
from pycmbs.mapping import map_plot
# we download some NCEP data
if not os.path.exists('air.mon.mean.nc'):
!wget --ftp-user=anonymous --ftp-password=nothing ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis.derived/surface/air.mon.mean.nc
ncep = Data('air.mon.mean.nc', 'air', read=True, label='NCEP air')
In [2]:
from pycmbs.diagnostic import EOF
E = EOF(ncep, anomalies=True)
We now plot the resulting patterns for the first 4 EOF's and also their temporal evolution.
In [8]:
E.plot_EOF([0,1,2,3],use_basemap=True,show_coef=True)
Out[8]:
In [10]:
from pycmbs.plots import LinePlot
import matplotlib.pyplot as plt
f = plt.figure(figsize=(15,8))
ax1 = f.add_subplot(2,1,1)
#ax2 = f.add_subplot(2,1,2)
ax2 = ax1.twinx()
ax3 = f.add_subplot(2,2,3)
ax4 = f.add_subplot(2,2,4)
L = LinePlot(ax=ax1)
L.plot(ncep, color='grey')
L.ax.grid()
L.legend(loc='lower right')
L1 = LinePlot(ax=ax2)
L1.plot(ncep.get_deseasonalized_anomaly(base='all'), color='red') # calculate anomalies on the fly
L1.ax.grid()
L1.legend(loc='lower left')
# calculate longterm trend
R, S, I, P = ncep.temporal_trend(return_object=True) #, pthres=0.05)
f = map_plot(S, cmap_data = 'RdBu_r', vmin=-0.0001, vmax=0.0001, use_basemap=True, ax=ax3)
# we plot EOF in addition
E.plot_EOF([0], use_basemap=True, ax=ax4)
In [10]:
f.savefig('../temperature_trend.pdf', bbox_inches='tight')