예제 #1
0
nt = sste.shape[0]
#timeslice = slice(0,nt)
#timeslice = slice(int(Tn),nt-int(Tn))

# Q_s = Q_s.isel(time=timeslice)
# Q_r = Q_r.isel(time=timeslice)
# tendsst = tendsst.isel(time=timeslice)
# sst = sst.isel(time=timeslice)


order = 5
fs = 1     # sample rate, (cycles per month)
Tn_enso = 12.*2
cutoff_enso = 1/Tn_enso  # desired cutoff frequency of the filter (cycles per month)
enso = st2.spatial_ave_xr(sst.sel(lon=slice(190,240)), lats=lats.sel(lat=slice(-5,5)))

enso = st.butter_lowpass_filter_xr(enso,cutoff_enso,fs,order) 

sste = st2.regressout_x(enso, sste)
Q_se = st2.regressout_x(enso, Q_se)
Q_re = st2.regressout_x(enso, Q_re)
Q_tote = st2.regressout_x(enso, Q_tote)
    
#lambdaQ_totlag0 = st.cov(sste, Q_tote, lagx=0)/st.cov(sste,sste, lagx=0)
lambdaQ_totlag1 = st.cov(sste, Q_tote, lagx=-1)/st.cov(sste,sste, lagx=-1)
#lambdaQ_totlag2 = st.cov(sste, Q_tote, lagx=-2)/st.cov(sste,sste, lagx=-2)
#lambdaQ_totlag3 = st.cov(sste, Q_tote, lagx=-3)/st.cov(sste,sste, lagx=-3)

#lambdaQ_tot = (lambdaQ_totlag1 + lambdaQ_totlag2 + lambdaQ_totlag3)/3.
예제 #2
0
 # Q_net_surf = Q_net_surf.fillna(0.)    
 # Q_net_surf = xr.DataArray(signal.detrend(Q_net_surf, axis=0), dims=Q_net_surf.dims, coords=Q_net_surf.coords) 
 
# SW_net_surf = SW_net_surf.fillna(0.)    
# SW_net_surf = xr.DataArray(signal.detrend(SW_net_surf, axis=0), dims=SW_net_surf.dims, coords=SW_net_surf.coords) 
 
 # Q_ek = Q_ek.fillna(0.)    
 # Q_ek = xr.DataArray(signal.detrend(Q_ek, axis=0), dims=Q_ek.dims, coords=Q_ek.coords) 
# 
#  
# Q_ek_f = Q_ek_f.fillna(0.)    
# Q_ek_f = xr.DataArray(signal.detrend(Q_ek_f, axis=0), dims=Q_ek_f.dims, coords=Q_ek_f.coords) 
 
Tn = 6.
cutoff = 1/Tn  # desired cutoff frequency of the filter (cycles per month)
enso = st2.spatial_ave_xr(sst.sel(lon=slice(190,240)), lats=lats.sel(lat=slice(-5,5))) 
 
if rENSO:
    sst = st2.regressout_x(enso, sst)
    #thf = st2.regressout_x(enso, thf)
    Qs = st2.regressout_x(enso, Qs)


#eqi = np.where(lats[1:-1]==0)
#Q_ek[:,eqi,:] = 0
#Q_ek_test = Q_ek
 

#adv_hs = -(adv_hDivH['X'] + adv_hDivH['Y'])/vol
 
 # Filter requirements.
예제 #3
0
Tn = 4. * 12.
cutoff = 1 / Tn  # desired cutoff frequency of the filter (cycles per month)

if lowpass:
    sst_lp = st.butter_lowpass_filter_xr(sst, cutoff, fs, order)
    r2corrs = st2.cor(sst_lp, sst_lp, lagx=2)
else:
    r2corrs = st2.cor(sst, sst, lagx=2)

#Niño 3.4 (5N-5S, 170W-120W

order = 5
fs = 1  # sample rate, (cycles per month)
Tn_enso = 6.
cutoff_enso = 1 / Tn  # desired cutoff frequency of the filter (cycles per month)
enso = st2.spatial_ave_xr(sst.sel(lon=slice(190, 240)),
                          lats=lats.sel(lat=slice(-5, 5)))

enso = st.butter_lowpass_filter_xr(enso, cutoff_enso, fs, order)

if not (lowpass):
    Tn = 0.

if rENSO:
    sste = st2.regressout_x(enso, sst)
    Q_se = st2.regressout_x(enso, Q_s)
    Q_re = st2.regressout_x(enso, Q_r)
    Q_tote = st2.regressout_x(enso, Q_tot)

# Scaling factor (to convert from units of W*K/(s*m^2) to K^2)
#G = (2*dt**2/(Cbar**2*(1-r2corrs)))
예제 #4
0
    # Q_net_surf = Q_net_surf.fillna(0.)
    # Q_net_surf = xr.DataArray(signal.detrend(Q_net_surf, axis=0), dims=Q_net_surf.dims, coords=Q_net_surf.coords)

# SW_net_surf = SW_net_surf.fillna(0.)
# SW_net_surf = xr.DataArray(signal.detrend(SW_net_surf, axis=0), dims=SW_net_surf.dims, coords=SW_net_surf.coords)

# Q_ek = Q_ek.fillna(0.)
# Q_ek = xr.DataArray(signal.detrend(Q_ek, axis=0), dims=Q_ek.dims, coords=Q_ek.coords)
#
#
# Q_ek_f = Q_ek_f.fillna(0.)
# Q_ek_f = xr.DataArray(signal.detrend(Q_ek_f, axis=0), dims=Q_ek_f.dims, coords=Q_ek_f.coords)

Tn = 6.
cutoff = 1 / Tn  # desired cutoff frequency of the filter (cycles per month)
enso = st2.spatial_ave_xr(sst.sel(lon=slice(190, 240)),
                          lats=lats.sel(lat=slice(-5, 5)))

if rENSO:
    sst = st2.regressout_x(enso, sst)
    #thf = st2.regressout_x(enso, thf)
    Qs = st2.regressout_x(enso, Qs)

# Filter requirements.
order = 5
fs = 1  # sample rate, (cycles per month)

delTn = 4
Tnmax = 6 * 12
Tns = np.arange(0, Tnmax + delTn, delTn)

Tns = Tns * 1.
예제 #5
0
#Q_s = a1*Q_o + residual
#Q_s = a1*Q_o + Q_{s,r}
a1, b = st2.reg(Qr, Q_s)

Q_s_o = a1 * Qr

Q_s_r = Q_s - Q_s_o

Q_s_o = Q_s_o.transpose('time', 'lat', 'lon')

a1_test = st2.cor(Q_s_o, Q_s_r)

lats_ave = lats.sel(lat=slice(latbounds[0], latbounds[1]))

Qs_sa = st2.spatial_ave_xr(
    Q_s.sel(lat=slice(latbounds[0], latbounds[1]),
            lon=slice(lonbounds[0], lonbounds[1])), lats_ave)
Qo_sa = st2.spatial_ave_xr(
    Qr.sel(lat=slice(latbounds[0], latbounds[1]),
           lon=slice(lonbounds[0], lonbounds[1])), lats_ave)
tendsst_sa = st2.spatial_ave_xr(
    tendsst.sel(lat=slice(latbounds[0], latbounds[1]),
                lon=slice(lonbounds[0], lonbounds[1])), lats_ave)
Cbar_sa = st2.spatial_ave_xr(
    Cbar.sel(lat=slice(latbounds[0], latbounds[1]),
             lon=slice(lonbounds[0], lonbounds[1])), lats_ave)
sst_sa = st2.spatial_ave_xr(
    sst.sel(lat=slice(latbounds[0], latbounds[1]),
            lon=slice(lonbounds[0], lonbounds[1])), lats_ave)

Q_s_o_sa = st2.spatial_ave_xr(
예제 #6
0
Tn = 4. * 12.
cutoff = 1 / Tn  # desired cutoff frequency of the filter (cycles per month)

if lowpass:
    sst_lp = st.butter_lowpass_filter_xr(sst, cutoff, fs, order)
    r2corrs = st2.cor(sst_lp, sst_lp, lagx=2)
else:
    r2corrs = st2.cor(sst, sst, lagx=2)

#Niño 3.4 (5N-5S, 170W-120W

order = 5
fs = 1  # sample rate, (cycles per month)
Tn_enso = 6.
cutoff_enso = 1 / Tn  # desired cutoff frequency of the filter (cycles per month)
enso = st2.spatial_ave_xr(sst.sel(lon=slice(190, 240)),
                          lats=lats.sel(lat=slice(-5, 5)))

enso = st.butter_lowpass_filter_xr(enso, cutoff_enso, fs, order)

if not (lowpass):
    Tn = 0.

if rENSO:
    sste = st2.regressout_x(enso, sst)
    Q_se = st2.regressout_x(enso, Q_s)
    Q_re = st2.regressout_x(enso, Q_r)
    Q_tote = st2.regressout_x(enso, Q_tot)

# Scaling factor (to convert from units of W*K/(s*m^2) to K^2)
#G = (2*dt**2/(Cbar**2*(1-r2corrs)))
T_var = sst.var(dim='time')

#Q_s = -thf + Q_net_surf 

nt = sst.shape[0]
#timeslice = slice(0,nt)
timeslice = slice(int(Tn),nt-int(Tn))

Q_s = Q_s.isel(time=timeslice)
Qr = Qr.isel(time=timeslice)
tendsst = tendsst.isel(time=timeslice)
sst = sst.isel(time=timeslice)

Tn = 6.
cutoff = 1/Tn  # desired cutoff frequency of the filter (cycles per month)
enso = st2.spatial_ave_xr(sst.sel(lon=slice(190,240)), lats=lats.sel(lat=slice(-5,5)))

enso = st.butter_lowpass_filter_xr(enso,cutoff,fs,order) 

if rENSO:
   sst = st2.regressout_x(enso, sst)

#Gulf Stream 37.5–45N, 72–42W
wlon=288
elon=318
nlat = 45
slat = 37.5

#Kuroshio 36–42N, 140–171E
# wlon=142
# elon=180
    # var_Qs_T = (fac/Cbar)*var_Qs
    # cov_QsQo_T = (fac/Cbar)*cov_QsQo

    # Compute observed SST variance
    T_var = np.var(sst, axis=0)

    # Compute contributions to SST variance
    T_var_Qr = fac * cov_Qr
    T_var_Qs = fac * cov_Qs
    #T_var_Qek = fac*cov_Qek
    T_var_Rnet = fac * cov_Rnet
    T_var_thf = fac * cov_thf
    #T_var_sum = T_var_Qr + T_var_Qs + T_var_Qek
    T_var_sum = T_var_Qr + T_var_Qs

    ave_T_var_Qr[jj] = st2.spatial_ave_xr(T_var_Qr, lats)
    ave_T_var_Qs[jj] = st2.spatial_ave_xr(T_var_Qs, lats)
    ave_T_var_thf[jj] = st2.spatial_ave_xr(T_var_thf, lats)
    #ave_T_var_Qek[jj] = st2.spatial_ave_xr(T_var_Qek, lats)
    ave_T_var_Rnet[jj] = st2.spatial_ave_xr(T_var_Rnet, lats)
    ave_T_var_sum[jj] = st2.spatial_ave_xr(T_var_sum, lats)
    ave_T_var[jj] = st2.spatial_ave_xr(T_var, lats)

    print('T_var_sum', ave_T_var_sum[jj])
    print('T_var', ave_T_var[jj])

#plt.figure(figsize=(12,10))

fig, axs = plot.subplots(ncols=1,
                         nrows=2,
                         aspect=1.2,
예제 #9
0
cutoff = 1/Tn  # desired cutoff frequency of the filter (cycles per month)


if lowpass:
    sst_lp = st.butter_lowpass_filter_xr(sst, cutoff, fs, order)
    r2corrs = st2.cor(sst_lp,sst_lp,lagx=2)
else:
    r2corrs = st2.cor(sst,sst,lagx=2)
    
#Niño 3.4 (5N-5S, 170W-120W

order = 5
fs = 1     # sample rate, (cycles per month)
Tn_enso = 6.
cutoff_enso = 1/Tn  # desired cutoff frequency of the filter (cycles per month)
enso = st2.spatial_ave_xr(sst.sel(lon=slice(190,240)), lats=lats.sel(lat=slice(-5,5)))

enso = st.butter_lowpass_filter_xr(enso,cutoff_enso,fs,order) 

if not(lowpass):
     Tn = 0.
    

if rENSO:
   sste = st2.regressout_x(enso, sst)
   Q_se = st2.regressout_x(enso, Q_s)
   Q_re = st2.regressout_x(enso, Q_r)
   Q_tote = st2.regressout_x(enso, Q_tot)
   

예제 #10
0
#T_var_Qek = fac*cov_Qek
#T_var_Qek_f = fac*cov_Qek_f
#T_var_Rnet = fac*cov_Rnet
#T_var_sum = T_var_Qr + T_var_Qs + T_var_Qek

T_var_sum = T_var_Qr + T_var_Qs

#T_var_RnetRnet = G*cov_RnetRnet
#T_var_thfRnet = G*cov_thfRnet
#T_var_QrRnet = G*cov_QrRnet
#
#T_var_thfthf = G*cov_thfthf
#T_var_Qrthf = G*cov_Qrthf
#T_var_QrQr = G*cov_QrQr

T_var_ave = st2.spatial_ave_xr(T_var, lats)
print('T_var_ave', T_var_ave)

# Approximation of SST variance by the covariance of the SST tendency
#T_var_test = (fac*Cbar)*cov_ssttend

# Plotting
bnds = [
    lonbounds_plot[0], lonbounds_plot[1], latbounds_plot[0], latbounds_plot[1]
]

cent = (bnds[0] + bnds[1]) / 2.
prj = cart.crs.PlateCarree(central_longitude=cent)

# bnds[0] = bnds[0] + 1
# bnds[2] = bnds[2] + 2
예제 #11
0
    fac = (2 * dt**2 / (Cbar * (1 - r2corrs)))

    #MERRA-2 sometimes blows up fac...
    fac = fac.where(~(xr.ufuncs.isinf(fac)))

    # Compute observed SST variance
    T_var = np.var(sst, axis=0)

    # Compute contributions to SST variance
    T_var_Qr = fac * cov_Qr
    T_var_Qs = fac * cov_Qs
    T_var_Qek = fac * cov_Qek
    T_var_sum = T_var_Qr + T_var_Qs + T_var_Qek
    #T_var_sum = T_var_Qr + T_var_Qs

    ave_T_var_Qr[jj] = st2.spatial_ave_xr(T_var_Qr, lats)
    ave_T_var_Qs[jj] = st2.spatial_ave_xr(T_var_Qs, lats)
    ave_T_var_Qek[jj] = st2.spatial_ave_xr(T_var_Qek, lats)
    ave_T_var_sum[jj] = st2.spatial_ave_xr(T_var_sum, lats)
    ave_T_var[jj] = st2.spatial_ave_xr(T_var, lats)

    print('T_var_sum', ave_T_var_sum[jj])
    print('T_var', ave_T_var[jj])

plt.figure(figsize=(12, 10))
plt.plot(Tns / 12., ave_T_var_Qs, color='C0', label=r'$Q_s$')
plt.plot(Tns / 12., ave_T_var_Qr, color='C2', label=r'$Q_o$')
plt.plot(Tns / 12., ave_T_var_Qek, color='C1', label=r'$Q_{ek}$')
plt.plot(Tns / 12., ave_T_var_sum, color='k', label=r'sum')
plt.plot(Tns / 12., ave_T_var, color='C5', label=r'$\sigma_T^2$')
plt.axhline(0, color='k', linewidth=1)
예제 #12
0
cutoff = 1/Tn  # desired cutoff frequency of the filter (cycles per month)


if lowpass:
    sst_lp = st.butter_lowpass_filter_xr(sst, cutoff, fs, order)
    r2corrs = st2.cor(sst_lp,sst_lp,lagx=2)
else:
    r2corrs = st2.cor(sst,sst,lagx=2)
    
#Niño 3.4 (5N-5S, 170W-120W

order = 5
fs = 1     # sample rate, (cycles per month)
Tn_enso = 6.
cutoff_enso = 1/Tn  # desired cutoff frequency of the filter (cycles per month)
enso = st2.spatial_ave_xr(sst.sel(lon=slice(190,240)), lats=lats.sel(lat=slice(-5,5)))

enso = st.butter_lowpass_filter_xr(enso,cutoff_enso,fs,order) 

if not(lowpass):
     Tn = 0.
    

if rENSO:
   sste = st2.regressout_x(enso, sst)
   Q_se = st2.regressout_x(enso, Q_s)
   Q_re = st2.regressout_x(enso, Q_r)
   Q_tote = st2.regressout_x(enso, Q_tot)