yr_sst = sst.aggregated_by('year', iris.analysis.MEAN) clim_sst = yr_sst.collapsed('time', iris.analysis.MEAN) # yr_sst_detrend = detrend(yr_sst) # clim_sst_detrend = yr_sst_detrend.collapsed('time', iris.analysis.MEAN) anom_sst = yr_sst - clim_sst anom_sst_detrend = detrend(anom_sst) # Create an EOF solver to do the EOF analysis. Square-root of cosine of # latitude weights are applied before the computation of EOFs. # sovler = Eof(anom_sst_detrend) #--> NO FUNCIONA PQ yr_sst_detrend SEMBLA QUE JA ESTÀ FETA LA ANOMALIA. BUENO CLAR PUTO,, SI LI TREUS LA REGRESSIÓ LINEAL ET CARREGUES TOT. solver = Eof(anom_sst, weights='coslat') # 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. n = 3 # eofs = solver.eofsAsCorrelation(neofs=n) eofs = solver.eofsAsCorrelation(neofs=n) pcs = solver.pcs(npcs=n) variance_fractions = solver.varianceFraction(neigs=n) print(variance_fractions.data) for i in range(n): plotter(eofs[i],pcs[:,i],variance_fractions.data[i]*100,i+1) # plt.show()
from eofs.examples import example_data_path # Read SST anomalies using the iris 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 = iris.load_cube(filename) # Create an EOF solver to do the EOF analysis. Square-root of cosine of # latitude weights are applied before the computation of EOFs. solver = Eof(sst, weights='coslat') # 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. clevs = np.linspace(-1, 1, 11) ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=190)) fill = iplt.contourf(eof1[0], clevs, cmap=plt.cm.RdBu_r) ax.add_feature(cartopy.feature.LAND, facecolor='w', edgecolor='k') cb = plt.colorbar(fill, orientation='horizontal') cb.set_label('correlation coefficient', fontsize=12) ax.set_title('EOF1 expressed as correlation', fontsize=16) # Plot the leading PC time series. plt.figure() iplt.plot(pc1[:, 0], color='b', linewidth=2) ax = plt.gca()