* cartopy (http://scitools.org.uk/cartopy/) """ import cartopy.crs as ccrs from netCDF4 import Dataset import matplotlib.pyplot as plt import numpy as np from eofs.standard import Eof from eofs.examples import example_data_path # Read geopotential height data using the netCDF4 module. The file contains # December-February averages of geopotential height at 500 hPa for the # European/Atlantic domain (80W-40E, 20-90N). filename = example_data_path('hgt_djf.nc') ncin = Dataset(filename, 'r') z_djf = ncin.variables['z'][:] lons = ncin.variables['longitude'][:] lats = ncin.variables['latitude'][:] ncin.close() # Compute anomalies by removing the time-mean. z_djf_mean = z_djf.mean(axis=0) z_djf = z_djf - z_djf_mean # Create an EOF solver to do the EOF analysis. Square-root of cosine of # latitude weights are applied before the computation of EOFs. coslat = np.cos(np.deg2rad(lats)).clip(0., 1.) wgts = np.sqrt(coslat)[..., np.newaxis] solver = Eof(z_djf, weights=wgts)
* cartopy (http://scitools.org.uk/cartopy/) """ import cartopy.crs as ccrs import cartopy.feature as cfeature import matplotlib.pyplot as plt import numpy as np import xarray as xr from eofs.xarray import Eof from eofs.examples import example_data_path # Read SST anomalies using the xarray module. The file contains November-March # averages of SST anomaly in the central and northern Pacific. filename = example_data_path('sst_ndjfm_anom.nc') sst = xr.open_dataset(filename)['sst'] # Create an EOF solver to do the EOF analysis. Square-root of cosine of # latitude weights are applied before the computation of EOFs. coslat = np.cos(np.deg2rad(sst.coords['latitude'].values)) wgts = np.sqrt(coslat)[..., np.newaxis] solver = Eof(sst, weights=wgts) # Retrieve the leading EOF, expressed as the correlation between the leading # PC time series and the input SST anomalies at each grid point, and the # leading PC time series itself. eof1 = solver.eofsAsCorrelation(neofs=1) pc1 = solver.pcs(npcs=1, pcscaling=1) # Plot the leading EOF expressed as correlation in the Pacific domain.