#subtract global annual mean to isolate local processes #sstprime = sst.T - sst_globe #sstprime = sstprime.T sstprime = sst #fieldprime = field.T - field_globe #fieldprime = fieldprime.T fieldprime = field uprime = u vprime = v psprime = ps field_lt = running_mean(fieldprime, N_map) field_st = fieldprime[ci:-ci, :] - field_lt sst_lt = running_mean(sstprime, N_map) sst_st = sstprime[ci:-ci, :] - sst_lt u_lt = running_mean(uprime, N_map) u_st = uprime[ci:-ci, :] - u_lt v_lt = running_mean(vprime, N_map) v_st = vprime[ci:-ci, :] - v_lt ps_lt = running_mean(psprime, N_map) ps_st = psprime[ci:-ci, :] - ps_lt field_lt = np.ma.masked_array(field_lt, mask=np.abs(field_lt > 1e4))
sstprime = sst.T - sst_globe_an sstprime = sstprime.T fieldprime = field.T - np.tile(field_globe_an.T, (nlon, nlat, 1, 1)) fieldprime = fieldprime.T #CHANGE THIS TO MODIFY RM WINDOW LENGTH N_map = 5 ci = (N_map - 1) / 2 ltlag = 5 stlag = 1 lagmax = 11 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(
#sst_globe = spatial_ave(sst, lats) field_globe = spatial_ave(field, lats) #subtract global annual mean to isolate local processes #sstprime = sst.T - sst_globe #sstprime = sstprime.T sstprime = sst #fieldprime = field.T - field_globe #fieldprime = fieldprime.T fieldprime = field field_lt = running_mean(fieldprime, N_map) field_st = fieldprime[ci:-ci,:] - field_lt sst_lt = running_mean(sstprime, N_map) sst_st = sstprime[ci:-ci,:] - sst_lt field_lt = np.ma.masked_array(field_lt, mask=np.abs(field_lt>1e3)) field_st = np.ma.masked_array(field_st, mask=np.abs(field_st>1e3)) sst_lt = np.ma.masked_array(sst_lt, mask=np.abs(sst_lt>1e3)) sst_st = np.ma.masked_array(sst_st, mask=np.abs(sst_st>1e3)) MM_lt = running_mean(MM, N_map) MM_st = MM[ci:-ci] - MM_lt
ci = (N_map-1)/2 lagmax=11 lags = np.arange(-lagmax,lagmax+1) sst_globe_an = spatial_ave(sst_an, lats) field_globe_an = spatial_ave(field_an, lats) #subtract global annual mean to isolate processes in NA sstprime = sst_an.T - sst_globe_an sstprime = sstprime.T fieldprime = field_an.T - field_globe_an fieldprime = fieldprime.T field_lt = running_mean(fieldprime, N_map) field_st = fieldprime[ci:-ci,:] - field_lt nt = sst.shape[0] nt_lt = field_lt.shape[0] fieldlagcorrs_merge = np.zeros((len(lags), nlat, nlon)) fieldlagcorrs_merge_lt = np.zeros((len(lags), nlat, nlon)) fieldlagcorrs_merge_st = np.zeros((len(lags), nlat, nlon)) #latboundar = np.array([[0,20],[20,45],[45,60]]) #latboundar = np.array([[0,60]]) latboundar = np.array([[0,20]]) #latboundar = np.array([[45,60]]) #latboundar = np.array([[20,45]])
N_map = 5 ci = (N_map - 1) / 2 ltlag = 5 stlag = 1 lagmax = 11 lags = np.arange(-lagmax, lagmax + 1) thflagcorrs = np.zeros((len(lags), nlat, nlon)) thflagcorrs_lt = np.zeros((len(lags), nlat, nlon)) thflagcorrs_st = np.zeros((len(lags), nlat, nlon)) pslagcorrs = np.zeros((len(lags), nlat, nlon)) pslagcorrs_lt = np.zeros((len(lags), nlat, nlon)) pslagcorrs_st = np.zeros((len(lags), nlat, nlon)) 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)) #thf_lt = running_mean(thf_an, N_map) #thf_st = thf_an[ci:-ci,:] - thf_lt thf_lt = running_mean(thfprime, N_map)
ti = 31 tf = 100 latbounds = [0, 60] times = sst.getTime()[:] tyears = np.arange(1870, 2010) tplot = tyears AMO, sstanom_anave, nasstanom_anave = calc_AMO(sst, latbounds, ti, tf) N = 11 ci = (N - 1) / 2 AMO_smooth = running_mean(AMO, N) AMO_std = (AMO - np.ma.mean(AMO)) / np.ma.std(AMO) AMO_test_std = (AMO_WARM_REMOVED - np.ma.mean(AMO_WARM_REMOVED) / np.ma.std(AMO_WARM_REMOVED)) sst_na = sst.subRegion(latitude=(latbounds[0], latbounds[1]), longitude=(280, 360)) nalats = sst_na.getLatitude()[:] #sst_na_ave = cdutil.averager(sst_na, axis='xy', weights='weighted') sst_na_an = an_ave(sst_na) #sst_na_an_detr = signal.detrend(sst_na_an, axis=0) #sst_globe = sst.subRegion(latitude=(-60,60)) sst_an = an_ave(sst)