Exemplo n.º 1
0
 def setup_class(cls):
     # Generate a scalar field and a corresponding EOF solution for the
     # standard numpy array interface.
     cls.sf, cls.eofs, cls.pcs = reference_solution('numpy')
     cls.neofs = cls.eofs.shape[0]
     # Create an EofSolver instance with the scalar field.
     cls.eofobj = EofSolver(cls.sf)
Exemplo n.º 2
0
 def setup_class(cls):
     # Generate a scalar field and a corresponding EOF solution for the
     # standard numpy array interface.
     cls.sf, cls.eofs, cls.pcs = reference_solution('numpy')
     # Create an EofSolver instance with the scalar field.
     cls.eofobj = EofSolver(cls.sf)
     cls.tools = {
         'covmap': eof2.nptools.covariance_map,
         'cormap': eof2.nptools.correlation_map
     }
Exemplo n.º 3
0
# European/Atlantic domain (80W-40E, 20-90N).
ncin = Dataset('../../example_data/hgt_djf.nc', '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 = EofSolver(z_djf, weights=wgts)

# Retrieve the leading EOF, expressed as the covariance between the leading PC
# time series and the input SLP anomalies at each grid point.
eof1 = solver.eofsAsCovariance(neofs=1)

# Plot the leading EOF expressed as covariance in the European/Atlantic domain.
m = Basemap(projection='ortho', lat_0=60., lon_0=-20.)
x, y = m(*np.meshgrid(lons, lats))
m.contourf(x, y, eof1.squeeze(), cmap=plt.cm.RdBu_r)
m.drawcoastlines()
m.drawparallels(np.arange(-80, 90, 20))
m.drawmeridians(np.arange(0, 360, 20))
plt.title('EOF1 expressed as covariance', fontsize=16)

plt.show()
Exemplo n.º 4
0
from eof2 import EofSolver


# Read SST anomalies using the netCDF4 module. The file contains
# November-March averages of SST anomaly in the central and northern Pacific.
ncin = Dataset('../../example_data/sst_ndjfm_anom.nc', 'r')
sst = ncin.variables['sst'][:]
lons = ncin.variables['longitude'][:]
lats = ncin.variables['latitude'][:]
ncin.close()

# 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))
wgts = np.sqrt(coslat)[..., np.newaxis]
solver = EofSolver(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.
m = Basemap(projection='cyl', llcrnrlon=120, llcrnrlat=-20,
        urcrnrlon=260, urcrnrlat=60)
x, y = m(*np.meshgrid(lons, lats))
clevs = np.linspace(-1, 1, 11)
m.contourf(x, y, eof1.squeeze(), clevs, cmap=plt.cm.RdBu_r)
m.drawcoastlines()
m.drawparallels([-20, 0, 20, 40, 60])
Exemplo n.º 5
0
# European/Atlantic domain (80W-40E, 20-90N).
ncin = Dataset('../../example_data/hgt_djf.nc', '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 = EofSolver(z_djf, weights=wgts)

# Retrieve the leading EOF, expressed as the covariance between the leading PC
# time series and the input SLP anomalies at each grid point.
eof1 = solver.eofsAsCovariance(neofs=1)

# Plot the leading EOF expressed as covariance in the European/Atlantic domain.
m = Basemap(projection='ortho', lat_0=60., lon_0=-20.)
x, y = m(*np.meshgrid(lons, lats))
m.contourf(x, y, eof1.squeeze(), cmap=plt.cm.RdBu_r)
m.drawcoastlines()
m.drawparallels(np.arange(-80, 90, 20))
m.drawmeridians(np.arange(0, 360, 20))
plt.title('EOF1 expressed as covariance', fontsize=16)

plt.show()
Exemplo n.º 6
0
from eof2 import EofSolver

# Read SST anomalies using the netCDF4 module. The file contains
# November-March averages of SST anomaly in the central and northern Pacific.
ncin = Dataset('../../example_data/sst_ndjfm_anom.nc', 'r')
sst = ncin.variables['sst'][:]
lons = ncin.variables['longitude'][:]
lats = ncin.variables['latitude'][:]
ncin.close()

# 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))
wgts = np.sqrt(coslat)[..., np.newaxis]
solver = EofSolver(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.
m = Basemap(projection='cyl',
            llcrnrlon=120,
            llcrnrlat=-20,
            urcrnrlon=260,
            urcrnrlat=60)
x, y = m(*np.meshgrid(lons, lats))
clevs = np.linspace(-1, 1, 11)