# elon=225
# nlat = 52
# slat = 40

sst_index = st2.spatial_ave_xr(sst.sel(lon=slice(wlon,elon)), lats=lats.sel(lat=slice(slat,nlat)))
Q_s_index =  st2.spatial_ave_xr(Q_s.sel(lon=slice(wlon,elon)), lats=lats.sel(lat=slice(slat,nlat)))
Qr_index =  st2.spatial_ave_xr(Qr.sel(lon=slice(wlon,elon)), lats=lats.sel(lat=slice(slat,nlat)))
ps_index = st2.spatial_ave_xr(ps.sel(lon=slice(wlon,elon)), lats=lats.sel(lat=slice(slat,nlat)))
#sst_index = (sst_index - sst_index.mean(dim='time'))/sst_index.std(dim='time')

ps_index = (ps_index - ps_index.mean(dim='time'))/ps_index.std(dim='time')
#sst_index = (sst_index - sst_index.mean(dim='time'))/sst_index.std(dim='time')

lagx = 0

reg_sstsst, b = st2.reg(sst_index, sst, lagx=lagx)
reg_sstQs, b = st2.reg(Q_s_index, sst, lagx=lagx)
reg_sstQr, b = st2.reg(Qr_index, sst,lagx=lagx)
reg_psQs, b = st2.reg(Q_s_index, ps, lagx=lagx)
reg_psQr, b = st2.reg(Qr_index, ps, lagx=lagx)

reg_pssst, b = st2.reg(sst_index, ps, lagx=lagx)

reg_psps, b = st2.reg(ps_index, ps, lagx=lagx)

#reg_Qssst, b = st2.reg(sst_index, Q_s, lagx=lagx)
#reg_Qrsst, b = st2.reg(sst_index, Qr, lagx=lagx)



# reg_psQs_tend = (st2.reg(Q_s_index, ps, lagx=-1)[0] - st2.reg(Q_s_index, ps, lagx=1)[0])/2.
Example #2
0
#ENP
#lonbounds = [200,220]
#latbounds = [38,53]

#Subtropical NA
#latbounds = [15,25]
#lonbounds = [300,330]

x1 = lonbounds[0]
x2 = lonbounds[1]
y1 = latbounds[0]
y2 = latbounds[1]

#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(
Example #3
0
#    else:
#       # Standardize SST
#       sst = (sst - sst.mean(dim='time'))/sst.std(dim='time')
#       lagcorrs[ll,:], intercept = st2.reg(sst,field,lagx=-lag)



lagi=1
lagf=-1

#SLPregQos = np.zeros(len(lags))
#SLPregQss = np.zeros(len(lags))
#SSTregQos = np.zeros(len(lags))
#SSTregQss = np.zeros(len(lags))

SLPregQoi, intercept = st2.reg(Qo_sa,ps,lagx=lagi)
SLPregQsi, intercept = st2.reg(Qs_sa,ps,lagx=lagi)
SSTregQoi, intercept = st2.reg(Qo_sa, sst,lagx=lagi)
SSTregQsi, intercept = st2.reg(Qs_sa, sst,lagx=lagi)


SLPregQof, intercept = st2.reg(Qo_sa,ps,lagx=lagf)
SLPregQsf, intercept = st2.reg(Qs_sa,ps,lagx=lagf)
SSTregQof, intercept = st2.reg(Qo_sa, sst,lagx=lagf)
SSTregQsf, intercept = st2.reg(Qs_sa, sst,lagx=lagf)
#SSTregSST, intercept = st2.reg(sst_sa,sst)
#QsregQo, intercept = st2.reg(Qo_sa, Q_s)
#SSTregtendSST, intercept = st2.reg(tendsst_sa,sst)

SLPregQo = SLPregQof - SLPregQoi
SLPregQs = SLPregQsf - SLPregQsi
Example #4
0
lowmaxi=1
f = f[lowmaxi:]
Tpower = Tpower[lowmaxi:]
Qtotpower = Qtotpower[lowmaxi:]
Qtotstarpower = Qtotstarpower[lowmaxi:]
Qsstarpower = Qsstarpower[lowmaxi:]
Qrstarpower = Qrstarpower[lowmaxi:]
Qspower = Qspower[lowmaxi:]
Qrpower = Qrpower[lowmaxi:]


eps_a = 0.76
sig_b = 5.67*10**(-8)

lmbda, slope = st2.reg(sst-ta, -Q_s)
lambda_odyn = -lambdaQ_r

lambda_sa = lmbda + 4*eps_a*sig_b*np.power(sstbar,3)  
lambda_so = lmbda + 4*eps_a*sig_b*np.power(tabar,3)
lambda_a = 4*eps_a*sig_b*(2*np.power(tabar,3) - np.power(sstbar,3))
lambda_o = 4*sig_b*(np.power(sstbar,3) - eps_a*np.power(tabar,3)) + lambda_odyn


F_o = Q_rstar
F_a = Q_sstar

T_var = sst.var(dim='time')

F_o_var = F_o.var(dim='time')
F_a_var = F_a.var(dim='time')
Example #5
0
    units = ''
else:
    units = r'W/m$^2$'

for ll, lag in enumerate(lags):
    
    print('lag',lag)
    
    print 
    
    if corr:
       lagcorrs[ll,:] = st2.cor(field,sst,lagx=lag)
    else:
       # Standardize SST
       sst = (sst - sst.mean(dim='time'))/sst.std(dim='time')
       lagcorrs[ll,:], intercept = st2.reg(field,sst,lagx=lag)
    

# Plotting
bnds = [np.round(lonbounds[0]-359), np.round(lonbounds[1]-361), latbounds[0], latbounds[1]]

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

pardiff = 30.
merdiff = 60.
if lonbounds[1] - lonbounds[0] <= 180:
    merdiff = 15.
if lonbounds[1] - lonbounds[0] <= 60:
    merdiff = 5.
if np.abs(latbounds[1]-latbounds[0]) <= 30:
Example #6
0
        units = ''
    else:
        units = r'W/m$^2$'
    
    for ll, lag in enumerate(lags):
        
        #print('lag',lag)
        
        print 
        
        if corr:
           lagcorrs[ll,:] = st2.cor(sst,field,lagx=-lag)
        else:
           # Standardize SST
           sst = (sst - sst.mean(dim='time'))/sst.std(dim='time')
           lagcorrs[ll,:], intercept = st2.reg(sst,field,lagx=-lag)
        
    avelagcorrs[jj,:] = st2.spatial_ave(np.ma.array(lagcorrs, mask = np.isnan(lagcorrs)), lats)
        

# Plotting
    
vmin=-0.6
vmax=0.6
cbstep=0.2
if not(corr):
   vmin=-15.0
   vmax=15.0
   cbstep=5.0
   
lagoffset = np.diff(lags)[0]/2.
# Qo_eof_projQo = solver.projectField(Qr, neofs=3)

# Qo_eof_projsst_pcs = Qo_eof_projsst[:,0]
# Qo_eof_projQo_pcs = Qo_eof_projQo[:,0]

#standardize the pseudo-PCS
# Qo_eof_projsst_pcs = (Qo_eof_projsst_pcs - Qo_eof_projsst_pcs.mean())/Qo_eof_projsst_pcs.std()
# Qo_eof_projQo_pcs = (Qo_eof_projQo_pcs - Qo_eof_projQo_pcs.mean())/Qo_eof_projQo_pcs.std()

Qo_pc = (Qo_pc - Qo_pc.mean(dim='time')) / Qo_pc.std(dim='time')

#get spatial patterns associated with projections
# Qo_eof_projsst_map, b = st2.reg(Qo_eof_projsst_pcs, sst)
# Qo_eof_projQo_map, b = st2.reg(Qo_eof_projQo_pcs, Qr)

sst_reg_Qo_pc, b = st2.reg(Qo_pc[:, 0], sst)
Qo_reg_Qo_pc, b = st2.reg(Qo_pc[:, 0], Qr)

solver = Eof(Q_s, weights=weights)
Qs_eof = solver.eofs(neofs=3, eofscaling=2)
Qs_pc = solver.pcs(npcs=3, pcscaling=2)

Qs_pc = (Qs_pc - Qs_pc.mean(dim='time')) / Qs_pc.std(dim='time')

sst_reg_Qs_pc, b = st2.reg(Qs_pc[:, 0], sst)
Qs_reg_Qs_pc, b = st2.reg(Qs_pc[:, 0], Q_s)

Qs_eof_varfracs = solver.varianceFraction()

# Save Q_o anomaly
if fsave: