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]) m.drawmeridians([120, 140, 160, 180, 200, 220, 240, 260]) cb = plt.colorbar(orientation='horizontal') cb.set_label('correlation coefficient', fontsize=12) plt.title('EOF1 expressed as correlation', fontsize=16) # Plot the leading PC time series.
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]) m.drawmeridians([120, 140, 160, 180, 200, 220, 240, 260]) cb = plt.colorbar(orientation='horizontal') cb.set_label('correlation coefficient', fontsize=12)