Exemplo n.º 1
0
def eofs_as(dat):
    A = climatologia_xarray(dat['curl']).values
    global land
    EC, WC, land = get_coasts(dat.lat, dat.lon)

    msk = np.empty(np.shape(A))
    for i in range(0, len(A[:,0,0])):
        msk[i,:,:] = land
        B = np.ma.array(A, mask=msk)
    from get_eddof import get_eddof
    edof = np.empty([len(dat.lat), len(dat.lon)])
    for i in range(0, len(dat.lat)):
        for j in range(0, len(dat.lon)):
            if msk[0,i,j] == False:
                edof[i,j] = get_eddof(B[:,i,j])
            else:
                edof[i,j] = np.nan

    dof = int(np.nanmean(edof))
    coslat = np.cos(np.deg2rad(dat.lat.values)).clip(0., 1.)
    wgts = np.sqrt(coslat)[..., np.newaxis]
    solver = Eof(B, center=True, weights=wgts, ddof=dof)

    eof = solver.eofs(neofs=10, eofscaling=2)
    pc = solver.pcs(npcs=10, pcscaling=1)
    varfrac = solver.varianceFraction()
    eigvals = solver.eigenvalues()

    x, y = np.meshgrid(dat.lon, dat.lat)

    return eof, pc, varfrac, x, y, edof
Exemplo n.º 2
0
def zonal_integration(x, lat, lon):
    import numpy as np
    from functions import get_coasts
    from scipy import integrate

    EC, WC, land = get_coasts(lat, lon); del land
    if np.ndim(x) == 2:
        x_int = np.empty(len(lat))
        for i in range(1, len(lat)):
            n = len(lon[int(WC[i]):int(EC[i])])
            h = np.abs(lon[1]-lon[0])*60*1.852*1000*np.cos(lat[i]*np.pi/180)
            xx = np.empty(n); xx[0] = 0
            for j in range(0, n-1):
                xx[j+1] = xx[j] + h
            x_int[i] = integrate.simps(x[i, int(WC[i]):int(EC[i])], xx)
    else:
        x_int = np.empty([len(x[:,0,0]), len(lat)])
        for i in range(1, len(lat)):
            n = len(lon[int(WC[i]):int(EC[i])])
            h = np.abs(lon[1]-lon[0])*60*1.852*1000*np.cos(lat[i]*np.pi/180)
            xx = np.empty(n); xx[0] = 0
            for j in range(0, n-1):
                xx[j+1] = xx[j] + h
            x_int[:, i] = integrate.simps(x[:, i, int(WC[i]):int(EC[i])], xx)
    return x_int
def latmax_clim(dat):
    A = dat['curl'].resample('1MS', dim='time', how='mean')
    B = np.empty([len(A.lat), len(A.time)])
    EC, WC, land = get_coasts(A.lat, A.lon)
    del land

    for i in range(0, len(A.lat)):
        B[i, :] = A[:, i, int(WC[i]):int(EC[i])].mean(dim='lon')

    C = B.argmax(axis=0)
    LM = np.empty(np.shape(C))
    for i in range(0, len(C)):
        LM[i] = A.lat[C[i]].item()
    return LM, A.time
Exemplo n.º 4
0
def mysv_clim(dat):
    A = climatologia_xarray(dat['curl'])
    B = A.sel(lat=-40, method='nearest')

    EC, WC = get_coasts(A.lat, A.lon)
    C = np.empty(len(A[:, 0, 0]))
    kk = np.where(A.lat == B.lat)[0][0]
    n = len(B.lon[int(WC[kk]):int(EC[kk])])
    h = np.abs(B.lon[1] - B.lon[0]) * 60 * 1.852 * 1000 * np.cos(
        B.lat * np.pi / 180)
    xx = np.empty(n)
    xx[0] = 0
    for j in range(0, n - 1):
        xx[j + 1] = xx[j] + h
    C = integrate.simps(B[:, int(WC[kk]):int(EC[kk])], xx)
    D = B.lat.item()
    CC = C / (1027 * 2 * 7.29e-5 * np.cos(np.deg2rad(D)) / 6371000)
    return CC, D
import numpy as np
import xarray
from functions import get_coasts
from functions import climatologia_xarray
from matplotlib import pyplot as plt

dat = xarray.open_dataset(
    '/home/bock/Documents/tesis/vientos/era_int/ERA_curl_daily_2009-2015.nc'
).squeeze()
A = climatologia_xarray(dat['curl'])
B = np.empty([len(dat.lat), 12])
EC, WC = get_coasts(dat.lat, dat.lon)
for i in range(0, len(dat.lat)):
    B[i, :] = np.mean(A[:, i, int(WC[i]):int(EC[i])], axis=1)

t = np.arange(1, 13, 1)
x, y = np.meshgrid(t, dat.lat)

fig = plt.figure(figsize=(7, 9))
ax = fig.add_subplot(111)
pc = plt.pcolormesh(x, y, B * 1e7, cmap='jet', vmin=-1.5, vmax=1.5)
cbar = fig.colorbar(pc, ax=ax, shrink=0.9)
cbar.ax.set_ylabel('10$^{-7}$ Pa/m')
plt.xlabel('Mes')
plt.ylabel('Latitud')
plt.title('Rotor promediado en la cuenca ERA')
plt.savefig('figuras/curl_promediado_climatologia_eraint.png',
            bbox_inches='tight')
plt.close()
import numpy as np
import xarray
from functions import get_coasts
from matplotlib import pyplot as plt

dat = xarray.open_dataset(
    '/home/bock/Documents/tesis/vientos/ncep_v1/NCEP1_curl_daily_2009-2015.nc')
NC1 = dat['curl'].mean(dim='time')
NC1_lat = dat.lat
EC, WC = get_coasts(NC1_lat, dat.lon)
NC1_za = np.empty(len(NC1_lat))
for i in range(0, len(NC1_lat)):
    NC1_za[i] = np.mean(NC1[i, int(WC[i]):int(EC[i])])
del EC, WC, NC1, dat

dat = xarray.open_dataset(
    '/home/bock/Documents/tesis/vientos/ncep_v2/NCEP2_curl_daily_2009-2015.nc')
NC2 = dat['curl'].mean(dim='time')
NC2_lat = dat.lat
EC, WC = get_coasts(NC2_lat, dat.lon)
NC2_za = np.empty(len(NC2_lat))
for i in range(0, len(NC2_lat)):
    NC2_za[i] = np.mean(NC2[i, int(WC[i]):int(EC[i])])
del EC, WC, NC2, dat

dat = xarray.open_dataset(
    '/home/bock/Documents/tesis/vientos/ccmp/CCMP_curl_daily_2009-2015.nc')
NC2 = dat['curl'].mean(dim='time')
CCM_lat = dat.lat
EC, WC = get_coasts(CCM_lat, dat.lon)
CCM_za = np.empty(len(CCM_lat))