#EDIT BOUNDS FOR AMO (AMOmid in O'Reilly 2016 is defined between 40 N and 60 N, Gulev. et al. 2013 defined between 30 N and 50 N)
for latbounds in latboundar:
    
    fieldlagcorrs = np.zeros((len(lags), nlat, nlon))
    fieldlagcorrs_lt = np.zeros((len(lags), nlat, nlon))
    fieldlagcorrs_st = np.zeros((len(lags), nlat, nlon))
    
    sstcorrs = MV.zeros((nlat,nlon))
    sstpvals = MV.zeros((nlat,nlon))
    fieldcorrs = MV.zeros((nlat, nlon))
    fieldcorrs_lt = MV.zeros((nlat,nlon))
    fieldcorrs_st = MV.zeros((nlat,nlon))

    
    AMO, sstanom_globe_an, sstanom_na_an = calc_NA_globeanom(sst_an, latbounds, lats, lons, baseti, basetf)
    NAfield2, fieldanom_globe_an, fieldanom_na_an = calc_NA_globeanom(field_an, latbounds, lats, lons, baseti, basetf)
    
    AMO_lt = running_mean(AMO, N_map)
    AMO_st = AMO[ci:-ci] - AMO_lt
    
    scaler = StandardScaler()
    AMOstd = scaler.fit_transform(AMO.reshape(-1,1))
    AMOstd_lt = scaler.fit_transform(AMO_lt.reshape(-1,1))
    AMOstd_st = scaler.fit_transform(AMO_st.reshape(-1,1))
    
    #need to normalize in this manner in order to get pearson correlation coefficient from np.correlate
    AMOstd2 = (AMO - np.mean(AMO)) / (np.std(AMO) * len(AMO))
    AMOstd_lt2 = (AMO_lt - np.mean(AMO_lt)) / (np.std(AMO_lt) * len(AMO_lt))
    AMOstd_st2 = (AMO_st - np.mean(AMO_st)) / (np.std(AMO_st) * len(AMO_st))
    
Пример #2
0
lags = np.arange(-lagmax, lagmax + 1)

field_lt = running_mean(fieldprime, N_map)
field_st = fieldprime[ci:-ci, :] - field_lt

nt_lt = field_lt.shape[0]

#EDIT BOUNDS FOR AMO (AMOmid in O'Reilly 2016 is defined between 40 N and 60 N, Gulev. et al. 2013 defined between 30 N and 50 N)
#latitude bounds for SST averaging
latboundar = np.array([[0, 60], [0, 20], [20, 45], [45, 60]])
#latboundar = np.array([[0,20],[20,45],[45,60]])
#latboundar = np.array([[0,60]])

for latbounds in latboundar:

    AMO, sstanom_globe_an, sstanom_na_an = calc_NA_globeanom(
        sst, latbounds, lats, lons, baseti, basetf)
    NAfield2, fieldanom_globe_an, fieldanom_na_an = calc_NA_globeanom3D(
        field, latbounds, lats, lons, baseti, basetf)

    sstcorrs = MV.zeros((nlat, nlon))
    fieldcorrs = MV.zeros((nplev, nlat * nlon))
    fieldcorrs_lt = MV.zeros((nplev, nlat * nlon))
    fieldcorrs_st = MV.zeros((nplev, nlat * nlon))

    fieldlagcorrs = np.zeros((len(lags), nplev, nlat * nlon))
    fieldlagcorrs_lt = np.zeros((len(lags), nplev, nlat * nlon))
    fieldlagcorrs_st = np.zeros((len(lags), nplev, nlat * nlon))

    AMO_lt = running_mean(AMO, N_map)
    AMO_st = AMO[ci:-ci] - AMO_lt
#initial/final indices for base period
baseti = 0
basetf = 10

sst_an = an_ave(sst)
thf_an = an_ave(thf)
ps_an = an_ave(ps)

#detrend annual fields instead of monthly? prevents thf from blowing up for some reason...
if detr:
    sst_an, params = detrend_separate(sst_an)
    ps_an, params = detrend_separate(ps_an)
    thf_an, params = detrend_separate(thf_an)

AMO, sstanom_globe_an, sstanom_na_an = calc_NA_globeanom(
    sst_an, latbounds, lats, lons, baseti, basetf)
NAthf2, thfanom_globe_an, thfanom_na_an = calc_NA_globeanom(
    thf_an, latbounds, lats, lons, baseti, basetf)

#thf blows up after detrending, need to mask values. Why doesn't this work for plotting later?
#thf = np.ma.array(thf, mask=np.bitwise_or(thf_mask, np.abs(thf) > 1e2))

#this seems to work for plotting, but have to mask nan values later
#thf[np.abs(thf) > 1e3] = np.nan

#sstanom_globe_an = signal.detrend(sstanom_globe_an)
#sstanom_na_an = signal.detrend(sstanom_na_an)
#AMO = signal.detrend(AMO)

#NAthf2 = signal.detrend(NAthf2)
#thfanom_globe_an = signal.detrend(thfanom_globe_an)