ajdawson / eofs

EOF analysis in Python
http://ajdawson.github.io/eofs/
GNU General Public License v3.0
199 stars 60 forks source link

Opposite signal in EOF correlation map #120

Closed alinedefreitasocn closed 3 years ago

alinedefreitasocn commented 3 years ago

Hi everyone,

I'm having trouble to calculate the NAO EOF pattern. Using Eofs package example, the resultant covariance map has opposite signal (it was supposed to have negative covariance in the poles and positive in midi latitudes). Does anyone know what's the problem?

The code used:

import cartopy.crs as ccrs 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 geopotential height data using the xarray 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') z_djf = xr.open_dataset(filename)['z']

Compute anomalies by removing the time-mean.

z_djf = z_djf - z_djf.mean(dim='time')

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(z_djf.coords['latitude'].values)).clip(0., 1.) wgts = np.sqrt(coslat)[..., np.newaxis] solver = Eof(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

clevs = np.linspace(-75, 75, 11) proj = ccrs.Orthographic(central_longitude=-20, central_latitude=60) ax = plt.axes(projection=proj) ax.coastlines() ax.set_global() eof1[0, 0].plot.contourf(ax=ax, levels=clevs, cmap=plt.cm.RdBu_r, transform=ccrs.PlateCarree(), add_colorbar=False) ax.set_title('EOF1 expressed as covariance', fontsize=16) plt.show()

test_EOF

=============================================================

Result was supposed to be like this: https://www.cpc.ncep.noaa.gov/products/precip/CWlink/pna/nao_loading.html

new nao loading

Thanks for your time, hope this is not a silly question.

lee1043 commented 3 years ago

Hi @alinedefreitasocn,

The sign of an EOF is arbitrary by the nature of the EOF analysis. Please also refer @ajdawson's comment at https://github.com/ajdawson/eofs/issues/73#issuecomment-227976178.

What I often do is multiplying -1 to the pattern and PC time series to reverse the sign if needed.

funkpreacher commented 3 years ago

There is no preferred sign. As the EOF are eigenvectors (of the covariance matrix), they can be normalized any way you like.

alinedefreitasocn commented 3 years ago

Thanks a lot @lee1043 and @funkpreacher