import numpy as np
import matplotlib.pyplot as plt
import arrow
import datetime
import xarray as xr
import os
import cmocean.cm as cm
import matplotlib.cm as cma
import scipy.interpolate as interp
from matplotlib.collections import PatchCollection
import matplotlib.dates as mpl_dates
from matplotlib.ticker import ScalarFormatter
from matplotlib.ticker import FormatStrFormatter
import datetime as dt
import pandas as pd
import matplotlib.dates as mpl_dates
import scipy.stats as stats
from matplotlib.ticker import StrMethodFormatter
#Function to extract data from 1 section
def get_secdata(datafile,sectionnum):
variables = ['final_salt','final_transp','final_lon','final_lat','final_depth','final_section','final_z','final_temp','init_lon','init_z','init_salt','init_temp','init_transp','final_age']
dict_var = {}
idx = np.where(datafile['final_section']==sectionnum)
for var in variables:
if var == 'final_age':
agetd = datafile[var].values
agehr = agetd.astype('float64')/(10**9*3600)
age = agehr[idx]
dict_var[var] = age
else:
data_sec = datafile[var]
dict_var[var] = data_sec[idx]
return dict_var
def plotCS(axv,lonsec,zsec,transpsec,lonW,lonE,latgridi,depi,vmax,time,title,cblabel,ylabel):
latgridf = latgridi-1
fmask = mesh.fmask[0, :, latgridf]
tmask = mesh.tmask[0]
lons = data.init_lon[(data.final_section != 0)]
f_lons = mesh.glamf[0, latgridf]
u_lons = mesh.glamv[0, latgridf]
w_depths = mesh.gdepw_1d
m2lon = ((u_lons[lonE]-u_lons[lonW])/(mesh.e2f[0, latgridi, lonW:lonE].sum())).values #degrees/m
cmap = cm.deep
arr,xe,ye,im = axv.hist2d(lonsec/m2lon,df(zsec)[0],weights=transpsec,cmap=cmap,bins=[np.array(f_lons[lonW:lonE:1]/m2lon),w_depths[0,0:depi]],
density=True,vmax=vmax
)
X,Y = np.meshgrid(xe,ye)
im = axv.pcolormesh(X,Y,arr.T*np.sum(transpsec/time).values,cmap=cmap,vmax=vmax)
axv.invert_yaxis()
axv.set_title(title)
axv.set_xlabel('Longitude (°E)')
axv.set_xticks(np.linspace(f_lons[lonW+2]/m2lon,f_lons[lonE-2]/m2lon,2))
axv.xaxis.set_major_formatter(FormatStrFormatter(f"%.{2}f"))
axv.set_xticklabels(['{:.2f}'.format(label) for label in np.linspace(f_lons[lonW+2],f_lons[lonE-2],2)])
axv.set_xticklabels(np.round(np.linspace(f_lons[lonW+2],f_lons[lonE-2],2),2))
pc = draw_patches(fmask, lonW, lonE, np.array(u_lons), np.array(w_depths[0]),m2lon)
axv.add_collection(pc)
if cblabel == True:
cb = fig.colorbar(im,ax=axv)
cb.set_label('Transport (m/s)')
if ylabel == True:
axv.set_ylabel('Depth (m)')
else:
axv.set_yticklabels([])
def plotTS(axn,var,lonsec,zsec,varsec,lonW,lonE,latgridi,depi,time,title,cblabel,ylabel,vmin=None,vmax=None):
latgridf = latgridi-1
fmask = mesh.fmask[0, :, latgridf]
tmask = mesh.tmask[0]
lons = data.init_lon[(data.final_section != 0)]
f_lons = mesh.glamf[0, latgridf]
u_lons = mesh.glamv[0, latgridf]
w_depths = mesh.gdepw_1d
m2lon = ((u_lons[lonE]-u_lons[lonW])/(mesh.e2f[0, latgridi, lonW:lonE].sum())).values #degrees/m
cmap = cm.deep
m2lon = ((u_lons[lonE]-u_lons[lonW])/(mesh.e2f[0, latgridi, lonW:lonE].sum())).values #degrees/m
arrw,xe,ye,im = axn.hist2d(lonsec/m2lon,df(zsec)[0],weights=varsec,cmap=cmap,bins=[np.array(f_lons[lonW:lonE:1]/m2lon),w_depths[0,0:depi]])
arrnw,xe2,ye2,im2 = axn.hist2d(lonsec/m2lon,df(zsec)[0],cmap=cmap,bins=[np.array(f_lons[lonW:lonE:1]/m2lon),w_depths[0,0:depi]])
arr3 = arrw/arrnw
X,Y = np.meshgrid(xe,ye)
im = axn.pcolormesh(X,Y,arr3.T,vmin=vmin,vmax=vmax)
axn.set_xlabel('Longitude (°E)')
axn.set_title(title)
axn.invert_yaxis()
axn.set_xticks(np.linspace(f_lons[lonW]/m2lon,f_lons[lonE-1]/m2lon,2))
axn.set_xticklabels(['{:.2f}'.format(label) for label in np.linspace(f_lons[lonW],f_lons[lonE-1],2)])
if cblabel == True:
cb = fig.colorbar(im,ax=axn)
if var == 'temp':
cb.set_label('Temperature (°C)')
if var == 'sal':
cb.set_label('Salinity (g/kg)')
if ylabel == True:
axn.set_ylabel('Depth (m)')
else:
axn.set_yticks([])
def get_datat(datafile,section, starttime, endtime):
final_section = datafile.final_section
final_transport = datafile.final_transp
transports = np.sum(np.where(final_section == section, final_transport, 0))
return transports/(endtime-starttime+1)
def running_mean(data, window_size):
cumsum = np.cumsum(data)
cumsum[window_size:] = cumsum[window_size:] - cumsum[:-window_size]
return cumsum[window_size - 1:] / window_size
def draw_patches(fmask, ll, ul, u_lons, w_depths,m2lon):
topo = []
for i in range(ll, ul):
for j in range(39):
if fmask[j, i] == 0:
try:
rect = Rectangle((u_lons[i]/m2lon, w_depths[j+1]), u_lons[i+1]/m2lon-u_lons[i]/m2lon, w_depths[j+2]-w_depths[j+1])
topo.append(rect)
except:
pass
pc = PatchCollection(topo, facecolors='lightgray', edgecolors='none')
return(pc)
def plotCSNS(axv,lonsec,zsec,transpsec,lonW,lonE,latgridi,depi,vmax,time,title,cblabel,ylabel):
latgridf = latgridi-1 #actually lon
fmask = mesh.fmask[0,:,:,latgridf] # Giving mask of longitudes
tmask = mesh.tmask[0]
lons = data.init_lat[(data.final_section != 0)]
f_lons = mesh.gphif[0,:, latgridf]
u_lons = mesh.gphiv[0,:, latgridf]
w_depths = mesh.gdepw_1d
m2lon = ((u_lons[lonE]-u_lons[lonW])/(mesh.e2f[0, latgridi, lonW:lonE].sum())).values #degrees/m
cmap = cm.deep
arr,xe,ye,im = axv.hist2d(lonsec/m2lon,df(zsec)[0],weights=transpsec,cmap=cmap,bins=[np.array(f_lons[lonW:lonE:1]/m2lon),w_depths[0,0:depi]],
density=True,vmax=vmax
)
X,Y = np.meshgrid(xe,ye)
im = axv.pcolormesh(X,Y,arr.T*np.sum(transpsec/time).values,cmap=cmap,vmax=vmax)
axv.invert_yaxis()
axv.set_title(title)
axv.set_xlabel('Latitude (°W)')
axv.set_xticks(np.linspace(f_lons[lonW+2]/m2lon,f_lons[lonE-2]/m2lon,2))
axv.xaxis.set_major_formatter(FormatStrFormatter(f"%.{2}f"))
axv.set_xticklabels(['{:.2f}'.format(label) for label in np.linspace(f_lons[lonW+2],f_lons[lonE-2],2)])
axv.set_xticklabels(np.round(np.linspace(f_lons[lonW+2],f_lons[lonE-2],2),2))
pc = draw_patches(fmask, lonW, lonE, np.array(u_lons), np.array(w_depths[0]),m2lon)
axv.add_collection(pc)
if cblabel == True:
cb = fig.colorbar(im,ax=axv)
cb.set_label('Transport (m/s)')
if ylabel == True:
axv.set_ylabel('Depth (m)')
else:
axv.set_yticklabels([])
data = xr.open_dataset('/ocean/cstang/MOAD/analysis-camryn/Ariane/for_jan18/for_straight_01jan18_s7t28/ariane_positions_quantitative.nc')
mesh = xr.open_dataset('/home/sallen/MEOPAR/grid/mesh_mask202108.nc')
lonW = 308
lonE = 327
latgridi = 300
latgridf = latgridi-1
fmask = mesh.fmask[0, :, latgridi]
tmask = mesh.tmask[0]
lons = data.init_lon[(data.final_section != 0)]
f_lons = mesh.glamf[0, latgridi]
u_lons = mesh.glamv[0, latgridi]
w_depths = mesh.gdepw_1d
m2lon = ((u_lons[lonE]-u_lons[lonW])/(mesh.e2f[0, latgridi, lonW:lonE].sum())).values #degrees/m
df = interp.interp1d(mesh.z,mesh.gdepw_1d) # Interpolate to get same binning scheme as SalishSeaCast
#Importing data and calculating section transport
import warnings
warnings.filterwarnings('ignore', category=RuntimeWarning)
files = ['forpr_ros3','backadm_ros3','backvs_ros3']
namen = ['datafvs']
starttime = 1
endtime = 24
sectionnum = [0,1,2,3,4,5,6,7,8]
date = dt.datetime(2016,12,10)
enddate = dt.datetime(2021,12,27)
dates = []
datelist_vs = []
while date <= enddate:
dates.append(date.strftime('%d%b%y').lower())
datelist_vs.append(date)
date+=dt.timedelta(days=1)
dicts = {}
for i,file in enumerate(files):
dict_i = {}
for date in dates:
name = '/ocean/cstang/MOAD/analysis-camryn/Ariane/' + file + '/' + date + '_s1t50/ariane_positions_quantitative.nc'
if os.path.isfile(name):
dict_i[date] = xr.open_dataset(name)
dicts[file] = dict_i
dict_sectiontransp = {}
for file in files:
st_dict = {}
for var in dicts[file].keys():
if var not in st_dict:
st_dict[var] = []
for section in sectionnum:
st_dict[var].append(get_datat(dicts[file][var],section,starttime,endtime))
dict_sectiontransp[file] = st_dict
dict_age = {}
for file in files:
a_dict = {}
for date in dicts[file].keys():
if date not in a_dict:
a_dict[date] = []
for section in sectionnum:
allvar = get_secdata(dicts[file][date],section)
a_dict[date].append(np.mean(allvar['final_age'][allvar['final_age']>=24]))
dict_age[file] = a_dict
age_2018 = {}
for file in files:
if file not in age_2018:
age_2018[file] = {}
for section in sectionnum:
if section not in age_2018[file]:
age_2018[file][section] = []
for date in dicts[file].keys():
age_2018[file][section].append(dict_age[file][date][section])
transp_2018 = {}
for file in files:
transp_2018[file] = []
for date in dates:
try:
transp_2018[file].append(np.sum(dict_sectiontransp[file][date][2:]))
except:
pass
sectransp_2018 = {}
for file in files:
sectransp_2018[file] = {}
for section in sectionnum:
if section not in sectransp_2018[file]:
sectransp_2018[file][section] = []
for date in dates:
try:
sectransp_2018[file][section].append(dict_sectiontransp[file][date][section])
except:
print(date)
pass
dict_secdata = {}
for file in files:
if file not in dict_secdata:
dict_secdata[file] = {}
for section in sectionnum:
if section not in dict_secdata[file]:
dict_secdata[file][section] = {}
for date in dicts[file].keys():
dict_secdata[file][section] = get_secdata(dicts[file][date],section)
def shift_time(dfr,dfr_age,datelist,base,factor):
shifted_time = [date + dt.timedelta(days=base+factor*dfr_age[i]/24) for i,date in enumerate(datelist)]
dfr = pd.DataFrame({'Transport':dfr.values,'Shifted_Time': shifted_time},index=dfr.index)
return dfr
def merge(dfr,dfr2):
"""Aligns shifted dateframes to calculate correlation
Args:
dfr : Forward dataframe
dfr2 (_type_): Backward dataframe
Returns:
_type_: Aligned, shifted dataframes and correlation between the 2.
"""
oidx = dfr.index
ndfr = dfr.set_index('Shifted_Time')
nidx = ndfr.index
step1 = ndfr.reindex(nidx.union(oidx)) # Creates dataframe with row of each old and new index ( no overlap - 128 rows now)
step2 = step1.sort_index() # Sorts into chronological order
step3 = step2.interpolate(axis=0) # Interpolates in between (since dates dont line up)
fdfr = step3
#Same for 2nd dataframe
oidx2 = dfr2.index
ndfr2 = dfr2.set_index('Shifted_Time')
nidx2 = ndfr2.index
step1 = ndfr2.reindex(nidx2.union(oidx2))
step2 = step1.sort_index()
step3 = step2.interpolate(axis=0)
fdfr2 = step3
corr = fdfr.Transport.corr(fdfr2.Transport) #Correlation ignores nan values
avg = 0.5*(fdfr.Transport + fdfr2.Transport)
return fdfr,fdfr2,corr,avg
# Importing density and tidal data
density_ros = pd.read_csv('/ocean/cstang/MOAD/analysis-camryn/notebooks/sigma_2016-22_rosarioNS.csv')
dens_diff_ros = np.array(density_ros.south - density_ros.north)
tides_1d = pd.read_csv('../notebooks/day_avg_tide_BP_16-22.csv')
tides = tides_1d['vozocrtx'].rolling(4, center=True).mean()
# tides_ros = pd.read_csv('low_pass_tide_18-22.csv')
date = dt.datetime(2016,1,1)
enddate = dt.datetime(2022,12,31)
datelist_tides = []
while date <= enddate:
datelist_tides.append(date)
date+=dt.timedelta(days=1)
#Confirm dates are same length
print(len(datelist_tides))
print(tides.shape)
date = dt.datetime(2016,1,1)
enddate = dt.datetime(2022,12,31)
datelist_dens = []
while date <= enddate:
datelist_dens.append(date)
date+=dt.timedelta(days=1)
dens_diff_ros
print(len(datelist_dens),)
2557 (2557,) 2557
wind = pd.read_csv('../notebooks/day_avg_wind_16-22.csv')
x = wind['time']
y = wind['wind']
date = dt.datetime(2016,1,1)
enddate = dt.datetime(2022,12,31)
datelist_winds = []
while date <= enddate:
datelist_winds.append(date)
date+=dt.timedelta(days=1)
y_mean4 = y.rolling(window=4, center=True).mean()
len(datelist_winds),len(y_mean4)
(2557, 2557)
PRtoadm_rosl = sectransp_2018['forpr_ros3'][2]
PRtoadm_rosbl = sectransp_2018['backadm_ros3'][4]
PRtoadm_ros = pd.Series(PRtoadm_rosl,index=datelist_vs)
PRtoadm_rosb = pd.Series(PRtoadm_rosbl,index=datelist_vs)
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtoadm_ros,age_2018['forpr_ros3'][2],datelist_vs,base,factor)
dfr2 = shift_time(PRtoadm_rosb,age_2018['backadm_ros3'][4],datelist_vs,-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.595:
print (base, factor, corr_arr[i, j])
-1.0 0.20000000000000107 0.6134471870019035 -0.95 0.20000000000000107 0.6141062033508613 -0.8999999999999999 0.15000000000000102 0.5965995191035859 -0.8999999999999999 0.20000000000000107 0.616563403904645 -0.8499999999999999 0.15000000000000102 0.5999588917771589 -0.8499999999999999 0.20000000000000107 0.6161236947301135 -0.7999999999999998 0.15000000000000102 0.6019642837149143 -0.7999999999999998 0.20000000000000107 0.6178875089820812 -0.7499999999999998 0.15000000000000102 0.6045028892284918 -0.7499999999999998 0.20000000000000107 0.618635247621217 -0.6999999999999997 0.15000000000000102 0.6019911757426618 -0.6999999999999997 0.20000000000000107 0.6161185260978407 -0.6499999999999997 0.15000000000000102 0.603446973695985 -0.6499999999999997 0.20000000000000107 0.6160302631219547 -0.5999999999999996 0.15000000000000102 0.6019456104774005 -0.5999999999999996 0.20000000000000107 0.6094896528860785 -0.5499999999999996 0.15000000000000102 0.5987353183162476 -0.5499999999999996 0.20000000000000107 0.6076285143990238 -0.49999999999999956 0.15000000000000102 0.6025204148799234 -0.49999999999999956 0.20000000000000107 0.6044594692484322 -0.4499999999999995 0.15000000000000102 0.6021586487062406 -0.4499999999999995 0.20000000000000107 0.6016722798657231 -0.39999999999999947 0.15000000000000102 0.6054568846351679 -0.39999999999999947 0.20000000000000107 0.5987340137739919 -0.3499999999999994 0.15000000000000102 0.6106270625096573 -0.3499999999999994 0.20000000000000107 0.595471205534291 -0.2999999999999994 0.15000000000000102 0.6117048157137647 -0.24999999999999933 0.15000000000000102 0.610844327872914 -0.1999999999999993 0.15000000000000102 0.609047069368267 -0.14999999999999925 0.15000000000000102 0.6128644400697542 -0.0999999999999992 0.15000000000000102 0.61315808965894 -0.049999999999999156 0.15000000000000102 0.6148162035196612 8.881784197001252e-16 0.15000000000000102 0.615402827609878 0.05000000000000093 0.15000000000000102 0.6148789996527163 0.10000000000000098 0.10000000000000098 0.6006771116090173 0.10000000000000098 0.15000000000000102 0.6174544833734916 0.15000000000000102 0.10000000000000098 0.59982324966565 0.15000000000000102 0.15000000000000102 0.617056326377762 0.20000000000000107 0.10000000000000098 0.6000471386096684 0.20000000000000107 0.15000000000000102 0.6155806206416827 0.2500000000000011 0.10000000000000098 0.5992929101109543 0.2500000000000011 0.15000000000000102 0.6109689999584118 0.30000000000000115 0.10000000000000098 0.5958150604250556 0.30000000000000115 0.15000000000000102 0.6042997554506696 0.3500000000000012 0.10000000000000098 0.5962414392018324 0.3500000000000012 0.15000000000000102 0.6025974322791925 0.40000000000000124 0.10000000000000098 0.5965465962438201 0.40000000000000124 0.15000000000000102 0.5961509281026667 0.4500000000000013 0.10000000000000098 0.5999951452516449 0.5000000000000013 0.10000000000000098 0.5984473934183548 0.5500000000000014 0.10000000000000098 0.6000182244793014 0.6000000000000014 0.10000000000000098 0.6011014162258869 0.6500000000000015 0.10000000000000098 0.6043596251473078 0.7000000000000015 0.10000000000000098 0.6035372314219348 0.7500000000000016 0.10000000000000098 0.6078260405219497 0.8000000000000016 0.10000000000000098 0.6111802330624263 0.8500000000000016 0.10000000000000098 0.6115260992326671 0.9000000000000017 0.10000000000000098 0.6101833960607618 0.9500000000000017 0.10000000000000098 0.613322401465926
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
[-0.75] [0.2]
PRtoadm_ros_sh = shift_time(PRtoadm_ros,age_2018['forpr_ros3'][2],datelist_vs,base_adm[0],factor_adm[0])
PRtoadm_rosb_sh = shift_time(PRtoadm_rosb,age_2018['backadm_ros3'][4],datelist_vs,-base_adm[0],-factor_adm[0])
PRtoadm_ros_m,PRtoadm_rosb_m,c,PRtoadm_ros_avg = merge(PRtoadm_ros_sh,PRtoadm_rosb_sh)
print(c)
plt.plot(PRtoadm_ros_m.Transport)
plt.plot(PRtoadm_rosb_m.Transport)
0.618635247621217
[<matplotlib.lines.Line2D at 0x7f87c2f5f6d0>]
PRtoadm2017_rosl = sectransp_2018['forpr_ros3'][2][0:365]
PRtoadm2017_rosbl = sectransp_2018['backadm_ros3'][4][0:365]
PRtoadm2017_ros = pd.Series(PRtoadm2017_rosl,index=datelist_vs[0:365])
PRtoadm2017_rosb = pd.Series(PRtoadm2017_rosbl,index=datelist_vs[0:365])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtoadm2017_ros,age_2018['forpr_ros3'][2][0:365],datelist_vs[0:365],base,factor)
dfr2 = shift_time(PRtoadm2017_rosb,age_2018['backadm_ros3'][4][0:365],datelist_vs[0:365],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.65:
print (base, factor, corr_arr[i, j])
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
PRtoadm2017_ros_sh = shift_time(PRtoadm2017_ros,age_2018['forpr_ros3'][2][0:365],datelist_vs[0:365],base_adm[0],factor_adm[0])
PRtoadm2017_rosb_sh = shift_time(PRtoadm2017_rosb,age_2018['backadm_ros3'][4][0:365],datelist_vs[0:365],-base_adm[0],-factor_adm[0])
PRtoadm2017_ros_m,PRtoadm2017_rosb_m,c,PRtoadm2017_ros_avg = merge(PRtoadm2017_ros_sh,PRtoadm2017_rosb_sh)
print(c)
plt.plot(PRtoadm2017_ros_m.Transport)
plt.plot(PRtoadm2017_rosb_m.Transport)
-1.0 0.15000000000000102 0.6822607053092881 -1.0 0.20000000000000107 0.7024470443652207 -1.0 0.2500000000000011 0.6527367718418796 -0.95 0.15000000000000102 0.6815343528077523 -0.95 0.20000000000000107 0.7021170463876445 -0.95 0.2500000000000011 0.650945497492129 -0.95 0.9500000000000017 0.6510911090813857 -0.8999999999999999 0.15000000000000102 0.6942969499898561 -0.8999999999999999 0.20000000000000107 0.6996713995571741 -0.8999999999999999 0.9500000000000017 0.6543688347800473 -0.8499999999999999 0.15000000000000102 0.6942181648274368 -0.8499999999999999 0.20000000000000107 0.6970079666614348 -0.8499999999999999 0.9500000000000017 0.6504381551130786 -0.7999999999999998 0.15000000000000102 0.6907577733506078 -0.7999999999999998 0.20000000000000107 0.6965526602468409 -0.7499999999999998 0.15000000000000102 0.6890934323506804 -0.7499999999999998 0.20000000000000107 0.6982884658800252 -0.7499999999999998 0.9500000000000017 0.6618792344362406 -0.6999999999999997 0.15000000000000102 0.6875685515573651 -0.6999999999999997 0.20000000000000107 0.6935700703229921 -0.6999999999999997 0.9500000000000017 0.6603040878574578 -0.6499999999999997 0.15000000000000102 0.6943345937185988 -0.6499999999999997 0.20000000000000107 0.6922200693702013 -0.6499999999999997 0.9500000000000017 0.6547876500823443 -0.5999999999999996 0.15000000000000102 0.6862758541887553 -0.5999999999999996 0.20000000000000107 0.68341444549233 -0.5999999999999996 0.9500000000000017 0.6612902763547788 -0.5499999999999996 0.15000000000000102 0.6889960772011853 -0.5499999999999996 0.20000000000000107 0.6857949795085274 -0.5499999999999996 0.9500000000000017 0.6633005181596846 -0.49999999999999956 0.15000000000000102 0.6918909629777626 -0.49999999999999956 0.20000000000000107 0.6790323619067957 -0.49999999999999956 0.9500000000000017 0.6631347998490609 -0.4499999999999995 0.15000000000000102 0.6840386427622973 -0.4499999999999995 0.20000000000000107 0.6701470377465835 -0.4499999999999995 0.9500000000000017 0.6758989681461618 -0.39999999999999947 0.15000000000000102 0.686041037853959 -0.39999999999999947 0.20000000000000107 0.6734815229873333 -0.39999999999999947 0.9500000000000017 0.6604619004511156 -0.3499999999999994 0.15000000000000102 0.6918346968896009 -0.3499999999999994 0.20000000000000107 0.6734949390865768 -0.3499999999999994 0.9500000000000017 0.661191414156077 -0.2999999999999994 0.15000000000000102 0.6914089651776555 -0.2999999999999994 0.20000000000000107 0.6580689153956092 -0.2999999999999994 0.9500000000000017 0.6614622978715714 -0.24999999999999933 0.10000000000000098 0.6511901799287845 -0.24999999999999933 0.15000000000000102 0.687297764916739 -0.24999999999999933 0.20000000000000107 0.6526216776020372 -0.24999999999999933 0.9500000000000017 0.6615604326335219 -0.1999999999999993 0.10000000000000098 0.6588702481834986 -0.1999999999999993 0.15000000000000102 0.6848518433243045 -0.1999999999999993 0.20000000000000107 0.6519424608108428 -0.1999999999999993 0.9500000000000017 0.6635747262282012 -0.14999999999999925 0.10000000000000098 0.6592904444752932 -0.14999999999999925 0.15000000000000102 0.6818793693567285 -0.14999999999999925 0.9500000000000017 0.6622132241372766 -0.0999999999999992 0.10000000000000098 0.661070421141625 -0.0999999999999992 0.15000000000000102 0.6820113051840397 -0.0999999999999992 0.9500000000000017 0.653252262491323 -0.049999999999999156 0.10000000000000098 0.6756752519087845 -0.049999999999999156 0.15000000000000102 0.6878746984772199 -0.049999999999999156 0.9000000000000017 0.6503099544877934 8.881784197001252e-16 0.10000000000000098 0.6780913138706787 8.881784197001252e-16 0.15000000000000102 0.6918251077842904 8.881784197001252e-16 0.9000000000000017 0.6637269480618068 8.881784197001252e-16 0.9500000000000017 0.6529244092053744 0.05000000000000093 0.10000000000000098 0.6845180305445575 0.05000000000000093 0.15000000000000102 0.6899585325374525 0.05000000000000093 0.9000000000000017 0.6636900891954952 0.10000000000000098 0.10000000000000098 0.6899232520315526 0.10000000000000098 0.15000000000000102 0.6975040373770982 0.10000000000000098 0.9000000000000017 0.6610887663743933 0.15000000000000102 0.10000000000000098 0.6846665827263533 0.15000000000000102 0.15000000000000102 0.699289842529472 0.15000000000000102 0.9000000000000017 0.6612401372712366 0.20000000000000107 0.10000000000000098 0.687305393528637 0.20000000000000107 0.15000000000000102 0.6991202902885255 0.20000000000000107 0.9000000000000017 0.6561669488681616 0.2500000000000011 0.10000000000000098 0.6912116373149787 0.2500000000000011 0.15000000000000102 0.6883060864713882 0.2500000000000011 0.9000000000000017 0.6670952072337369 0.30000000000000115 0.10000000000000098 0.6861281833575383 0.30000000000000115 0.15000000000000102 0.6813409721576789 0.30000000000000115 0.9000000000000017 0.6692607285761888 0.3500000000000012 0.10000000000000098 0.6862376222059937 0.3500000000000012 0.15000000000000102 0.6779875734302367 0.3500000000000012 0.9000000000000017 0.6690969167169721 0.40000000000000124 0.10000000000000098 0.6815508233711426 0.40000000000000124 0.15000000000000102 0.6651980323125575 0.40000000000000124 0.9000000000000017 0.6686371613806448 0.40000000000000124 0.9500000000000017 0.6527608072402264 0.4500000000000013 0.10000000000000098 0.6757505742397824 0.4500000000000013 0.15000000000000102 0.6652838900531893 0.4500000000000013 0.9000000000000017 0.6655498928451781 0.5000000000000013 0.10000000000000098 0.671275579070154 0.5000000000000013 0.15000000000000102 0.6627944377334996 0.5000000000000013 0.9000000000000017 0.6616078168354829 0.5500000000000014 0.10000000000000098 0.6667968499498468 0.5500000000000014 0.9000000000000017 0.6544412881960214 0.6000000000000014 0.10000000000000098 0.659403056748561 0.6500000000000015 0.10000000000000098 0.6636300821754338 0.7000000000000015 0.10000000000000098 0.6645164912916616 0.7500000000000016 0.10000000000000098 0.6720636912797863 0.8000000000000016 0.10000000000000098 0.6772959878975802 0.8500000000000016 0.10000000000000098 0.6766560857034589 0.8500000000000016 0.8500000000000016 0.6502200358567785 0.9000000000000017 0.05000000000000093 0.6587509057892883 0.9000000000000017 0.10000000000000098 0.6770785876881324 0.9500000000000017 0.05000000000000093 0.6608917661772469 0.9500000000000017 0.10000000000000098 0.6869455922410117 0.9500000000000017 0.8500000000000016 0.6567410563449035 [-1.] [0.2] 0.7024470443652207
[<matplotlib.lines.Line2D at 0x7f87c336a2f0>]
PRtoadm2018_rosl = sectransp_2018['forpr_ros3'][2][365:750]
PRtoadm2018_rosbl = sectransp_2018['backadm_ros3'][4][365:750]
PRtoadm2018_ros = pd.Series(PRtoadm2018_rosl,index=datelist_vs[365:750])
PRtoadm2018_rosb = pd.Series(PRtoadm2018_rosbl,index=datelist_vs[365:750])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtoadm2018_ros,age_2018['forpr_ros3'][2][365:750],datelist_vs[365:750],base,factor)
dfr2 = shift_time(PRtoadm2018_rosb,age_2018['backadm_ros3'][4][365:750],datelist_vs[365:750],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.8:
print (base, factor, corr_arr[i, j])
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
[-0.8] [0.15]
PRtoadm2018_ros_sh = shift_time(PRtoadm2018_ros,age_2018['forpr_ros3'][2][365:750],datelist_vs[365:750],base_adm[0],factor_adm[0])
PRtoadm2018_rosb_sh = shift_time(PRtoadm2018_rosb,age_2018['backadm_ros3'][4][365:750],datelist_vs[365:750],-base_adm[0],-factor_adm[0])
PRtoadm2018_ros_m,PRtoadm2018_rosb_m,c,PRtoadm2018_ros_avg = merge(PRtoadm2018_ros_sh,PRtoadm2018_rosb_sh)
print(c)
plt.plot(PRtoadm2018_ros_m.Transport)
plt.plot(PRtoadm2018_rosb_m.Transport)
0.6550074656313384
[<matplotlib.lines.Line2D at 0x7f87c36369b0>]
PRtoadm2019_rosl = sectransp_2018['forpr_ros3'][2][750:1110]
PRtoadm2019_rosbl = sectransp_2018['backadm_ros3'][4][750:1110]
PRtoadm2019_ros = pd.Series(PRtoadm2019_rosl,index=datelist_vs[750:1110])
PRtoadm2019_rosb = pd.Series(PRtoadm2019_rosbl,index=datelist_vs[750:1110])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtoadm2019_ros,age_2018['forpr_ros3'][2][750:1110],datelist_vs[750:1110],base,factor)
dfr2 = shift_time(PRtoadm2019_rosb,age_2018['backadm_ros3'][4][750:1110],datelist_vs[750:1110],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.57:
print (base, factor, corr_arr[i, j])
-1.0 0.3500000000000012 0.5762973272730353 -0.95 0.3500000000000012 0.5772148908053214 -0.95 0.40000000000000124 0.5711493272782864 -0.8999999999999999 0.3500000000000012 0.5777127981753594 -0.8499999999999999 0.3500000000000012 0.5717322542979335 -0.7499999999999998 0.3500000000000012 0.5758560027660321 -0.6999999999999997 0.3500000000000012 0.5708110013816076 -0.6499999999999997 0.3500000000000012 0.5768378802871007 -0.5999999999999996 0.3500000000000012 0.570875670845368 -0.49999999999999956 0.3500000000000012 0.5749281616465954 -0.4499999999999995 0.3500000000000012 0.579613943595951 -0.39999999999999947 0.3500000000000012 0.5738270850140776 -0.3499999999999994 0.3500000000000012 0.5778686135893547 -0.2999999999999994 0.3500000000000012 0.5788510131111585 -0.24999999999999933 0.3500000000000012 0.5758464559731834 -0.1999999999999993 0.30000000000000115 0.5704286483682088 -0.1999999999999993 0.3500000000000012 0.5730421755092 -0.14999999999999925 0.30000000000000115 0.5731959205107653 -0.14999999999999925 0.3500000000000012 0.5776964763783452 -0.0999999999999992 0.30000000000000115 0.576753978972669 -0.0999999999999992 0.3500000000000012 0.5730285822333547 -0.049999999999999156 0.30000000000000115 0.5768535672988253 8.881784197001252e-16 0.30000000000000115 0.5776992639698083 0.05000000000000093 0.30000000000000115 0.5713987065200502 0.10000000000000098 0.30000000000000115 0.5770859698349676 0.15000000000000102 0.30000000000000115 0.5705681742544122 0.2500000000000011 0.30000000000000115 0.575431179847962 0.30000000000000115 0.30000000000000115 0.5845297055367664 0.3500000000000012 0.30000000000000115 0.5759539794968648 0.40000000000000124 0.30000000000000115 0.5717484573865378 0.4500000000000013 0.30000000000000115 0.581969577968639 0.5000000000000013 0.30000000000000115 0.5858650199277835 0.5500000000000014 0.30000000000000115 0.585937588817407 0.6000000000000014 0.30000000000000115 0.5833414982945496 0.6500000000000015 0.30000000000000115 0.5808809399617746 0.7000000000000015 0.30000000000000115 0.5779385239618353 0.7500000000000016 0.30000000000000115 0.5776399246420116 0.8000000000000016 0.30000000000000115 0.578570346523993 0.8500000000000016 0.30000000000000115 0.5801150712353219 0.9000000000000017 0.30000000000000115 0.5818931893406027
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
[0.55] [0.3]
PRtoadm2019_ros_sh = shift_time(PRtoadm2019_ros,age_2018['forpr_ros3'][2][750:1110],datelist_vs[750:1110],base_adm[0],factor_adm[0])
PRtoadm2019_rosb_sh = shift_time(PRtoadm2019_rosb,age_2018['backadm_ros3'][4][750:1110],datelist_vs[750:1110],-base_adm[0],-factor_adm[0])
PRtoadm2019_ros_m,PRtoadm2019_rosb_m,c,PRtoadm2019_ros_avg = merge(PRtoadm2019_ros_sh,PRtoadm2019_rosb_sh)
print(c)
plt.plot(PRtoadm2019_ros_m.Transport)
plt.plot(PRtoadm2019_rosb_m.Transport)
0.585937588817407
[<matplotlib.lines.Line2D at 0x7f87c3912710>]
PRtoadm2020_rosl = sectransp_2018['forpr_ros3'][2][1110:1460]
PRtoadm2020_rosbl = sectransp_2018['backadm_ros3'][4][1110:1460]
PRtoadm2020_ros = pd.Series(PRtoadm2020_rosl,index=datelist_vs[1110:1460])
PRtoadm2020_rosb = pd.Series(PRtoadm2020_rosbl,index=datelist_vs[1110:1460])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtoadm2020_ros,age_2018['forpr_ros3'][2][1110:1460],datelist_vs[1110:1460],base,factor)
dfr2 = shift_time(PRtoadm2020_rosb,age_2018['backadm_ros3'][4][1110:1460],datelist_vs[1110:1460],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.57:
print (base, factor, corr_arr[i, j])
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
-1.0 0.20000000000000107 0.6209366878136215 -1.0 0.2500000000000011 0.6603419037308395 -1.0 0.30000000000000115 0.6506753008996614 -1.0 0.3500000000000012 0.5987796774813878 -1.0 0.40000000000000124 0.5706705668893272 -0.95 0.20000000000000107 0.6270608267971052 -0.95 0.2500000000000011 0.6483629464328978 -0.95 0.30000000000000115 0.646469131980799 -0.95 0.3500000000000012 0.5952257255738935 -0.8999999999999999 0.20000000000000107 0.6310598446377154 -0.8999999999999999 0.2500000000000011 0.6498182448550357 -0.8999999999999999 0.30000000000000115 0.6406121296592753 -0.8999999999999999 0.3500000000000012 0.5999334753115627 -0.8499999999999999 0.20000000000000107 0.6268682661903421 -0.8499999999999999 0.2500000000000011 0.643134145167998 -0.8499999999999999 0.30000000000000115 0.6362855282202504 -0.8499999999999999 0.3500000000000012 0.5981421255925088 -0.7999999999999998 0.20000000000000107 0.6383125113374131 -0.7999999999999998 0.2500000000000011 0.6487446449236278 -0.7999999999999998 0.30000000000000115 0.638796302306431 -0.7999999999999998 0.3500000000000012 0.572288270497447 -0.7499999999999998 0.15000000000000102 0.5746032564992278 -0.7499999999999998 0.20000000000000107 0.6450236937566444 -0.7499999999999998 0.2500000000000011 0.6495521864016116 -0.7499999999999998 0.30000000000000115 0.6264524626177032 -0.6999999999999997 0.15000000000000102 0.5774602344308429 -0.6999999999999997 0.20000000000000107 0.6542071107868557 -0.6999999999999997 0.2500000000000011 0.658911975736395 -0.6999999999999997 0.30000000000000115 0.6258489685923662 -0.6499999999999997 0.15000000000000102 0.573093603736793 -0.6499999999999997 0.20000000000000107 0.6586170626873646 -0.6499999999999997 0.2500000000000011 0.6525722654352833 -0.6499999999999997 0.30000000000000115 0.6025660739475568 -0.5999999999999996 0.15000000000000102 0.5789102403329368 -0.5999999999999996 0.20000000000000107 0.6614760183516918 -0.5999999999999996 0.2500000000000011 0.651373758580484 -0.5999999999999996 0.30000000000000115 0.6075015725934022 -0.5499999999999996 0.15000000000000102 0.5795604018705935 -0.5499999999999996 0.20000000000000107 0.6619111621475333 -0.5499999999999996 0.2500000000000011 0.6456573997145908 -0.5499999999999996 0.30000000000000115 0.610164278545215 -0.49999999999999956 0.15000000000000102 0.5844999611632332 -0.49999999999999956 0.20000000000000107 0.6532178385970144 -0.49999999999999956 0.2500000000000011 0.6551318541482445 -0.49999999999999956 0.30000000000000115 0.6118899851391412 -0.4499999999999995 0.15000000000000102 0.6062314770900578 -0.4499999999999995 0.20000000000000107 0.658893160470332 -0.4499999999999995 0.2500000000000011 0.6513097812870688 -0.4499999999999995 0.30000000000000115 0.6101482701909444 -0.39999999999999947 0.15000000000000102 0.6172480160878915 -0.39999999999999947 0.20000000000000107 0.6545064247329283 -0.39999999999999947 0.2500000000000011 0.6467138351286362 -0.39999999999999947 0.30000000000000115 0.6052043899081931 -0.3499999999999994 0.15000000000000102 0.6154992869019132 -0.3499999999999994 0.20000000000000107 0.6455096341077095 -0.3499999999999994 0.2500000000000011 0.6498786526574998 -0.3499999999999994 0.30000000000000115 0.606097033324637 -0.2999999999999994 0.15000000000000102 0.6228235505914316 -0.2999999999999994 0.20000000000000107 0.6378027090681426 -0.2999999999999994 0.2500000000000011 0.650827019671446 -0.2999999999999994 0.30000000000000115 0.6033213388205837 -0.24999999999999933 0.15000000000000102 0.6296468155364582 -0.24999999999999933 0.20000000000000107 0.6505515767660417 -0.24999999999999933 0.2500000000000011 0.6452813912755151 -0.24999999999999933 0.30000000000000115 0.5888850235648398 -0.1999999999999993 0.15000000000000102 0.6344010773824443 -0.1999999999999993 0.20000000000000107 0.6494376307995928 -0.1999999999999993 0.2500000000000011 0.6391757603182476 -0.1999999999999993 0.30000000000000115 0.5886466113771045 -0.14999999999999925 0.15000000000000102 0.6392942265285023 -0.14999999999999925 0.20000000000000107 0.6425157835325924 -0.14999999999999925 0.2500000000000011 0.6299148921563658 -0.14999999999999925 0.30000000000000115 0.591783338857761 -0.0999999999999992 0.15000000000000102 0.6445400106667352 -0.0999999999999992 0.20000000000000107 0.6418361093248031 -0.0999999999999992 0.2500000000000011 0.6333066202973986 -0.0999999999999992 0.30000000000000115 0.5757524244065138 -0.049999999999999156 0.15000000000000102 0.649276905911593 -0.049999999999999156 0.20000000000000107 0.6430837580691724 -0.049999999999999156 0.2500000000000011 0.6242443784640596 -0.049999999999999156 0.30000000000000115 0.5760089057062823 8.881784197001252e-16 0.15000000000000102 0.6561766620437173 8.881784197001252e-16 0.20000000000000107 0.6503732118922431 8.881784197001252e-16 0.2500000000000011 0.6245946567083963 0.05000000000000093 0.15000000000000102 0.6567745883738875 0.05000000000000093 0.20000000000000107 0.6497500195037954 0.05000000000000093 0.2500000000000011 0.6114832904852996 0.10000000000000098 0.15000000000000102 0.6551525784337355 0.10000000000000098 0.20000000000000107 0.6476511611355644 0.10000000000000098 0.2500000000000011 0.614909356751783 0.15000000000000102 0.15000000000000102 0.6580475625119654 0.15000000000000102 0.20000000000000107 0.6437827440567685 0.15000000000000102 0.2500000000000011 0.605349006043457 0.20000000000000107 0.10000000000000098 0.5758566514315098 0.20000000000000107 0.15000000000000102 0.6602813796163117 0.20000000000000107 0.20000000000000107 0.6557320717411308 0.20000000000000107 0.2500000000000011 0.6082303909530083 0.2500000000000011 0.10000000000000098 0.5765452915720264 0.2500000000000011 0.15000000000000102 0.6587888750186432 0.2500000000000011 0.20000000000000107 0.6526739309552197 0.2500000000000011 0.2500000000000011 0.6100019331589304 0.30000000000000115 0.10000000000000098 0.5783719639283104 0.30000000000000115 0.15000000000000102 0.6539530573014741 0.30000000000000115 0.20000000000000107 0.653294957603076 0.30000000000000115 0.2500000000000011 0.606232303822532 0.3500000000000012 0.10000000000000098 0.5844336429025377 0.3500000000000012 0.15000000000000102 0.6476639638849524 0.3500000000000012 0.20000000000000107 0.6557390499698648 0.3500000000000012 0.2500000000000011 0.6017180627381901 0.40000000000000124 0.10000000000000098 0.607757868003395 0.40000000000000124 0.15000000000000102 0.6469349066973884 0.40000000000000124 0.20000000000000107 0.6505184974051474 0.40000000000000124 0.2500000000000011 0.5943255226196095 0.4500000000000013 0.10000000000000098 0.6193339499586508 0.4500000000000013 0.15000000000000102 0.6453044941436409 0.4500000000000013 0.20000000000000107 0.6541087490633555 0.4500000000000013 0.2500000000000011 0.5876255652467532 0.5000000000000013 0.10000000000000098 0.6325586645425377 0.5000000000000013 0.15000000000000102 0.6446976404680539 0.5000000000000013 0.20000000000000107 0.6394585513892608 0.5000000000000013 0.2500000000000011 0.5884625964589358 0.5500000000000014 0.10000000000000098 0.6456370869851665 0.5500000000000014 0.15000000000000102 0.6630744659242892 0.5500000000000014 0.20000000000000107 0.6374336751894645 0.5500000000000014 0.2500000000000011 0.5837296647571921 0.6000000000000014 0.10000000000000098 0.655059998932338 0.6000000000000014 0.15000000000000102 0.6690411633623314 0.6000000000000014 0.20000000000000107 0.6312345432542148 0.6500000000000015 0.10000000000000098 0.6704442170197593 0.6500000000000015 0.15000000000000102 0.658401850746278 0.6500000000000015 0.20000000000000107 0.623032853990986 0.7000000000000015 0.10000000000000098 0.6753283325199141 0.7000000000000015 0.15000000000000102 0.6544793663972567 0.7000000000000015 0.20000000000000107 0.6117846350278383 0.7500000000000016 0.10000000000000098 0.6766759758445638 0.7500000000000016 0.15000000000000102 0.6539800112764788 0.7500000000000016 0.20000000000000107 0.6098899915468676 0.8000000000000016 0.10000000000000098 0.6808523830688374 0.8000000000000016 0.15000000000000102 0.65585274689531 0.8000000000000016 0.20000000000000107 0.6139039767590512 0.8500000000000016 0.10000000000000098 0.6722637200791803 0.8500000000000016 0.15000000000000102 0.6551273837782818 0.8500000000000016 0.20000000000000107 0.6030171874275839 0.9000000000000017 0.10000000000000098 0.668266455962702 0.9000000000000017 0.15000000000000102 0.6610083086577857 0.9000000000000017 0.20000000000000107 0.5925448753765921 0.9500000000000017 0.10000000000000098 0.6655829230683471 0.9500000000000017 0.15000000000000102 0.6551660270770615 0.9500000000000017 0.20000000000000107 0.602821321525448 [0.8] [0.1]
PRtoadm2020_ros_sh = shift_time(PRtoadm2020_ros,age_2018['forpr_ros3'][2][1110:1460],datelist_vs[1110:1460],base_adm[0],factor_adm[0])
PRtoadm2020_rosb_sh = shift_time(PRtoadm2020_rosb,age_2018['backadm_ros3'][4][1110:1460],datelist_vs[1110:1460],-base_adm[0],-factor_adm[0])
PRtoadm2020_ros_m,PRtoadm2020_rosb_m,c,PRtoadm2020_ros_avg = merge(PRtoadm2020_ros_sh,PRtoadm2020_rosb_sh)
print(c)
plt.plot(PRtoadm2020_ros_m.Transport)
plt.plot(PRtoadm2020_rosb_m.Transport)
0.6808523830688374
[<matplotlib.lines.Line2D at 0x7f87c3bd2e30>]
PRtoadm2021_rosl = sectransp_2018['forpr_ros3'][2][1460:]
PRtoadm2021_rosbl = sectransp_2018['backadm_ros3'][4][1460:]
PRtoadm2021_ros = pd.Series(PRtoadm2021_rosl,index=datelist_vs[1460:])
PRtoadm2021_rosb = pd.Series(PRtoadm2021_rosbl,index=datelist_vs[1460:])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtoadm2021_ros,age_2018['forpr_ros3'][2][1460:],datelist_vs[1460:],base,factor)
dfr2 = shift_time(PRtoadm2021_rosb,age_2018['backadm_ros3'][4][1460:],datelist_vs[1460:],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.57:
print (base, factor, corr_arr[i, j])
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
-1.0 0.20000000000000107 0.5729763819284602 -0.95 0.20000000000000107 0.5799883611944041 -0.8999999999999999 0.15000000000000102 0.5709275022174856 -0.8999999999999999 0.20000000000000107 0.5838827625420333 -0.8499999999999999 0.15000000000000102 0.5760436113006984 -0.8499999999999999 0.20000000000000107 0.5926740794875357 -0.7999999999999998 0.15000000000000102 0.5721840263938961 -0.7999999999999998 0.20000000000000107 0.5940202998606867 -0.7499999999999998 0.20000000000000107 0.5825203536847657 -0.6999999999999997 0.20000000000000107 0.5793864448343177 -0.6499999999999997 0.15000000000000102 0.571783048061966 -0.6499999999999997 0.20000000000000107 0.5786549080110281 -0.5999999999999996 0.15000000000000102 0.5708992650753353 -0.5999999999999996 0.20000000000000107 0.5709602073570669 -0.3499999999999994 0.15000000000000102 0.5736169583149043 -0.2999999999999994 0.15000000000000102 0.5790558315472552 -0.24999999999999933 0.15000000000000102 0.5820032352776671 -0.1999999999999993 0.15000000000000102 0.5951439991322349 -0.14999999999999925 0.15000000000000102 0.5983610391386281 -0.0999999999999992 0.15000000000000102 0.5906995846120602 -0.049999999999999156 0.15000000000000102 0.5863897242329847 8.881784197001252e-16 0.15000000000000102 0.5776507593830092 0.10000000000000098 0.10000000000000098 0.5729828509486387 0.10000000000000098 0.15000000000000102 0.5773079062974903 0.15000000000000102 0.15000000000000102 0.5729998537977001 0.6000000000000014 0.10000000000000098 0.5703873789624044 0.8500000000000016 0.10000000000000098 0.5730906980157032 0.9000000000000017 0.10000000000000098 0.5757355722620058 0.9500000000000017 0.10000000000000098 0.5764754881596109 [-0.15] [0.15]
PRtoadm2021_ros_sh = shift_time(PRtoadm2021_ros,age_2018['forpr_ros3'][2][1460:],datelist_vs[1460:],base_adm[0],factor_adm[0])
PRtoadm2021_rosb_sh = shift_time(PRtoadm2021_rosb,age_2018['backadm_ros3'][4][1460:],datelist_vs[1460:],-base_adm[0],-factor_adm[0])
PRtoadm2021_ros_m,PRtoadm2021_rosb_m,c,PRtoadm2021_ros_avg = merge(PRtoadm2021_ros_sh,PRtoadm2021_rosb_sh)
print(c)
plt.plot(PRtoadm2021_ros_m.Transport)
plt.plot(PRtoadm2021_rosb_m.Transport)
0.5983610391386281
[<matplotlib.lines.Line2D at 0x7f87c40beb90>]
PRtovs_rosl = sectransp_2018['forpr_ros3'][4]
PRtovs_rosbl = sectransp_2018['backvs_ros3'][4]
PRtovs_ros = pd.Series(PRtovs_rosl,index=datelist_vs)
PRtovs_rosb = pd.Series(PRtovs_rosbl,index=datelist_vs)
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtovs_ros,age_2018['forpr_ros3'][4],datelist_vs,base,factor)
dfr2 = shift_time(PRtovs_rosb,age_2018['backvs_ros3'][4],datelist_vs,-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.68:
print (base, factor, corr_arr[i, j])
-1.0 0.2500000000000011 0.7325336247425104 -1.0 0.30000000000000115 0.7179785434184929 -0.95 0.2500000000000011 0.7310162412347257 -0.95 0.30000000000000115 0.7103502039954206 -0.8999999999999999 0.20000000000000107 0.6838486549566245 -0.8999999999999999 0.2500000000000011 0.7310166769936179 -0.8999999999999999 0.30000000000000115 0.7061260427139905 -0.8499999999999999 0.20000000000000107 0.6893627421980109 -0.8499999999999999 0.2500000000000011 0.7291223295972036 -0.8499999999999999 0.30000000000000115 0.7040888935453391 -0.7999999999999998 0.20000000000000107 0.6936035140457749 -0.7999999999999998 0.2500000000000011 0.7320561670492404 -0.7999999999999998 0.30000000000000115 0.7027620914408726 -0.7499999999999998 0.20000000000000107 0.6972364300202912 -0.7499999999999998 0.2500000000000011 0.7344922554226359 -0.7499999999999998 0.30000000000000115 0.6964307996002491 -0.6999999999999997 0.20000000000000107 0.6979842814440604 -0.6999999999999997 0.2500000000000011 0.7322324237547829 -0.6999999999999997 0.30000000000000115 0.690544522420751 -0.6499999999999997 0.20000000000000107 0.7014203929968549 -0.6499999999999997 0.2500000000000011 0.733748596636165 -0.6499999999999997 0.30000000000000115 0.687238479405159 -0.5999999999999996 0.20000000000000107 0.7043790242497208 -0.5999999999999996 0.2500000000000011 0.7304990749318522 -0.5999999999999996 0.30000000000000115 0.6807628715937897 -0.5499999999999996 0.20000000000000107 0.7066982856358374 -0.5499999999999996 0.2500000000000011 0.7286937091727042 -0.49999999999999956 0.20000000000000107 0.7084580098801286 -0.49999999999999956 0.2500000000000011 0.7288237205950263 -0.4499999999999995 0.20000000000000107 0.7149251389718005 -0.4499999999999995 0.2500000000000011 0.7255055743200186 -0.39999999999999947 0.20000000000000107 0.7167935138542023 -0.39999999999999947 0.2500000000000011 0.7211947346461045 -0.3499999999999994 0.20000000000000107 0.7143936748381661 -0.3499999999999994 0.2500000000000011 0.7217557675336087 -0.2999999999999994 0.20000000000000107 0.7191396494195313 -0.2999999999999994 0.2500000000000011 0.7159983346926986 -0.24999999999999933 0.20000000000000107 0.7221071706116291 -0.24999999999999933 0.2500000000000011 0.7137592610504193 -0.1999999999999993 0.20000000000000107 0.7234063521027351 -0.1999999999999993 0.2500000000000011 0.7131481580703717 -0.14999999999999925 0.20000000000000107 0.7221969866044176 -0.14999999999999925 0.2500000000000011 0.7108181227334015 -0.0999999999999992 0.20000000000000107 0.7254474707378091 -0.0999999999999992 0.2500000000000011 0.7068727595001775 -0.049999999999999156 0.20000000000000107 0.7217565608483292 -0.049999999999999156 0.2500000000000011 0.7011754064001211 8.881784197001252e-16 0.20000000000000107 0.72463670696527 8.881784197001252e-16 0.2500000000000011 0.7013690144812598 0.05000000000000093 0.15000000000000102 0.6823148301925093 0.05000000000000093 0.20000000000000107 0.7263606881722853 0.05000000000000093 0.2500000000000011 0.6911996948768194 0.10000000000000098 0.15000000000000102 0.6850140387343174 0.10000000000000098 0.20000000000000107 0.7270321278088812 0.10000000000000098 0.2500000000000011 0.6877302096284532 0.15000000000000102 0.15000000000000102 0.6913700645721974 0.15000000000000102 0.20000000000000107 0.7269336805539016 0.15000000000000102 0.2500000000000011 0.6802804562792131 0.20000000000000107 0.15000000000000102 0.6981921339456836 0.20000000000000107 0.20000000000000107 0.729037224345361 0.2500000000000011 0.15000000000000102 0.6967765377948619 0.2500000000000011 0.20000000000000107 0.726102741394 0.30000000000000115 0.15000000000000102 0.7032043587788751 0.30000000000000115 0.20000000000000107 0.7235888523023783 0.3500000000000012 0.15000000000000102 0.7067184943848992 0.3500000000000012 0.20000000000000107 0.7216531278667537 0.40000000000000124 0.15000000000000102 0.7066881183449742 0.40000000000000124 0.20000000000000107 0.7192177612703803 0.4500000000000013 0.15000000000000102 0.7104106276304415 0.4500000000000013 0.20000000000000107 0.7179053052335396 0.5000000000000013 0.15000000000000102 0.7117471471329082 0.5000000000000013 0.20000000000000107 0.7151470160387371 0.5500000000000014 0.15000000000000102 0.7140263764042599 0.5500000000000014 0.20000000000000107 0.7087052617204681 0.6000000000000014 0.15000000000000102 0.7152139105812118 0.6000000000000014 0.20000000000000107 0.7061567638316034 0.6500000000000015 0.15000000000000102 0.716255068402869 0.6500000000000015 0.20000000000000107 0.7021538882085243 0.7000000000000015 0.15000000000000102 0.7146966293927175 0.7000000000000015 0.20000000000000107 0.69815315448332 0.7500000000000016 0.15000000000000102 0.7153894748729244 0.7500000000000016 0.20000000000000107 0.6963356410962004 0.8000000000000016 0.15000000000000102 0.7183714639332015 0.8000000000000016 0.20000000000000107 0.6946231937908636 0.8500000000000016 0.15000000000000102 0.718503511153968 0.8500000000000016 0.20000000000000107 0.6863819790159288 0.9000000000000017 0.15000000000000102 0.7192940613349493 0.9000000000000017 0.20000000000000107 0.6848046488243436 0.9500000000000017 0.15000000000000102 0.7170428313733768
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
[-0.75] [0.25]
PRtovs_ros_sh = shift_time(PRtovs_ros,age_2018['forpr_ros3'][4],datelist_vs,base_adm[0],factor_adm[0])
PRtovs_rosb_sh = shift_time(PRtovs_rosb,age_2018['backvs_ros3'][4],datelist_vs,-base_adm[0],-factor_adm[0])
PRtovs_ros_m,PRtovs_rosb_m,c,PRtovs_ros_avg = merge(PRtovs_ros_sh,PRtovs_rosb_sh)
print(c)
plt.plot(PRtovs_ros_m.Transport)
plt.plot(PRtovs_rosb_m.Transport)
0.7344922554226359
[<matplotlib.lines.Line2D at 0x7f87c44a1540>]
PRtovs2017_rosl = sectransp_2018['forpr_ros3'][4][0:365]
PRtovs2017_rosbl = sectransp_2018['backvs_ros3'][4][0:365]
PRtovs2017_ros = pd.Series(PRtovs2017_rosl,index=datelist_vs[0:365])
PRtovs2017_rosb = pd.Series(PRtovs2017_rosbl,index=datelist_vs[0:365])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtovs2017_ros,age_2018['forpr_ros3'][4][0:365],datelist_vs[0:365],base,factor)
dfr2 = shift_time(PRtovs2017_rosb,age_2018['backvs_ros3'][4][0:365],datelist_vs[0:365],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.73:
print (base, factor, corr_arr[i, j])
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
PRtovs2017_ros_sh = shift_time(PRtovs2017_ros,age_2018['forpr_ros3'][4][0:365],datelist_vs[0:365],base_adm[0],factor_adm[0])
PRtovs2017_rosb_sh = shift_time(PRtovs2017_rosb,age_2018['backvs_ros3'][4][0:365],datelist_vs[0:365],-base_adm[0],-factor_adm[0])
PRtovs2017_ros_m,PRtovs2017_rosb_m,c,PRtovs2017_ros_avg = merge(PRtovs2017_ros_sh,PRtovs2017_rosb_sh)
print(c)
plt.plot(PRtovs2017_ros_m.Transport)
plt.plot(PRtovs2017_rosb_m.Transport)
-1.0 0.20000000000000107 0.7610843511718882 -1.0 0.2500000000000011 0.7763198426842873 -0.95 0.20000000000000107 0.7615233814859687 -0.95 0.2500000000000011 0.7630359475334424 -0.8999999999999999 0.20000000000000107 0.7648934420523167 -0.8999999999999999 0.2500000000000011 0.758683328570182 -0.8499999999999999 0.20000000000000107 0.7628555302688944 -0.8499999999999999 0.2500000000000011 0.7541300583776663 -0.7999999999999998 0.20000000000000107 0.7582768697304704 -0.7999999999999998 0.2500000000000011 0.7523415587675286 -0.7499999999999998 0.20000000000000107 0.7555752947107308 -0.7499999999999998 0.2500000000000011 0.7507323016133077 -0.6999999999999997 0.20000000000000107 0.7510759894839689 -0.6999999999999997 0.2500000000000011 0.7443611153684692 -0.6499999999999997 0.20000000000000107 0.7624439880334823 -0.6499999999999997 0.2500000000000011 0.7449211531184489 -0.5999999999999996 0.20000000000000107 0.7717712498882352 -0.5999999999999996 0.2500000000000011 0.741380026546958 -0.5499999999999996 0.20000000000000107 0.7682497240542593 -0.5499999999999996 0.2500000000000011 0.7377610018811687 -0.49999999999999956 0.20000000000000107 0.7739842730708687 -0.49999999999999956 0.2500000000000011 0.7321828489212299 -0.4499999999999995 0.20000000000000107 0.7739980942191206 -0.39999999999999947 0.20000000000000107 0.7759078841752908 -0.3499999999999994 0.20000000000000107 0.774938697405976 -0.2999999999999994 0.20000000000000107 0.7812226916622822 -0.24999999999999933 0.15000000000000102 0.7431601894712391 -0.24999999999999933 0.20000000000000107 0.7797223644039087 -0.1999999999999993 0.15000000000000102 0.7453673181041695 -0.1999999999999993 0.20000000000000107 0.7794033214591324 -0.14999999999999925 0.15000000000000102 0.7511178502147978 -0.14999999999999925 0.20000000000000107 0.7711022713874807 -0.0999999999999992 0.15000000000000102 0.7469361063651985 -0.0999999999999992 0.20000000000000107 0.7696503672614626 -0.049999999999999156 0.15000000000000102 0.7454082991110782 -0.049999999999999156 0.20000000000000107 0.7611487528368115 8.881784197001252e-16 0.15000000000000102 0.7536011919448963 8.881784197001252e-16 0.20000000000000107 0.757206252729834 0.05000000000000093 0.15000000000000102 0.754874329630136 0.05000000000000093 0.20000000000000107 0.7552855409683068 0.10000000000000098 0.15000000000000102 0.7555980588710765 0.10000000000000098 0.20000000000000107 0.7575324654038729 0.15000000000000102 0.15000000000000102 0.7516208003603199 0.15000000000000102 0.20000000000000107 0.7428010130696078 0.20000000000000107 0.15000000000000102 0.7504950668288501 0.20000000000000107 0.20000000000000107 0.7386980074346546 0.2500000000000011 0.15000000000000102 0.7459921603630827 0.30000000000000115 0.15000000000000102 0.7565940786353018 0.3500000000000012 0.15000000000000102 0.7590791230280717 0.40000000000000124 0.15000000000000102 0.7592478636773391 0.4500000000000013 0.15000000000000102 0.7633422605536261 0.5000000000000013 0.15000000000000102 0.7678794107846661 0.5500000000000014 0.10000000000000098 0.7317844965264909 0.5500000000000014 0.15000000000000102 0.7708238206628453 0.6000000000000014 0.15000000000000102 0.7698405628066535 0.6500000000000015 0.15000000000000102 0.7652302283347914 0.7000000000000015 0.10000000000000098 0.7303645242673386 0.7000000000000015 0.15000000000000102 0.7579628580490599 0.7500000000000016 0.15000000000000102 0.7582475405202487 0.8000000000000016 0.15000000000000102 0.7602248612154017 0.8500000000000016 0.15000000000000102 0.7577374004118355 0.9000000000000017 0.10000000000000098 0.7303694964128754 0.9000000000000017 0.15000000000000102 0.749947009001578 0.9500000000000017 0.10000000000000098 0.7323044863315087 0.9500000000000017 0.15000000000000102 0.7404459075520212 [-0.3] [0.2] 0.7812226916622822
[<matplotlib.lines.Line2D at 0x7f87c43c8ac0>]
PRtovs2018_rosl = sectransp_2018['forpr_ros3'][4][365:750]
PRtovs2018_rosbl = sectransp_2018['backvs_ros3'][4][365:750]
PRtovs2018_ros = pd.Series(PRtovs2018_rosl,index=datelist_vs[365:750])
PRtovs2018_rosb = pd.Series(PRtovs2018_rosbl,index=datelist_vs[365:750])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtovs2018_ros,age_2018['forpr_ros3'][4][365:750],datelist_vs[365:750],base,factor)
dfr2 = shift_time(PRtovs2018_rosb,age_2018['backvs_ros3'][4][365:750],datelist_vs[365:750],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.73:
print (base, factor, corr_arr[i, j])
-1.0 0.30000000000000115 0.7383132790320881 -0.7499999999999998 0.2500000000000011 0.7303184671278201 -0.6499999999999997 0.2500000000000011 0.7314656453815972 -0.5999999999999996 0.2500000000000011 0.7307758320789479 -0.39999999999999947 0.2500000000000011 0.730445030017987 -0.3499999999999994 0.2500000000000011 0.7342245171321492 0.15000000000000102 0.20000000000000107 0.7317687809152374 0.20000000000000107 0.20000000000000107 0.7339911066854953
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
[-1.] [0.3]
PRtovs2018_ros_sh = shift_time(PRtovs2018_ros,age_2018['forpr_ros3'][4][365:750],datelist_vs[365:750],base_adm[0],factor_adm[0])
PRtovs2018_rosb_sh = shift_time(PRtovs2018_rosb,age_2018['backvs_ros3'][4][365:750],datelist_vs[365:750],-base_adm[0],-factor_adm[0])
PRtovs2018_ros_m,PRtovs2018_rosb_m,c,PRtovs2018_ros_avg = merge(PRtovs2018_ros_sh,PRtovs2018_rosb_sh)
print(c)
plt.plot(PRtovs2018_ros_m.Transport)
plt.plot(PRtovs2018_rosb_m.Transport)
0.7383132790320881
[<matplotlib.lines.Line2D at 0x7f87c5194940>]
PRtovs2019_rosl = sectransp_2018['forpr_ros3'][4][750:1110]
PRtovs2019_rosbl = sectransp_2018['backvs_ros3'][4][750:1110]
PRtovs2019_ros = pd.Series(PRtovs2019_rosl,index=datelist_vs[750:1110])
PRtovs2019_rosb = pd.Series(PRtovs2019_rosbl,index=datelist_vs[750:1110])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtovs2019_ros,age_2018['forpr_ros3'][4][750:1110],datelist_vs[750:1110],base,factor)
dfr2 = shift_time(PRtovs2019_rosb,age_2018['backvs_ros3'][4][750:1110],datelist_vs[750:1110],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.57:
print (base, factor, corr_arr[i, j])
-1.0 0.30000000000000115 0.6075211384337889 -0.95 0.30000000000000115 0.5934285748119174 -0.8999999999999999 0.30000000000000115 0.5876971535653234 -0.8499999999999999 0.2500000000000011 0.5715248251737987 -0.8499999999999999 0.30000000000000115 0.5889254336422473 -0.7999999999999998 0.2500000000000011 0.5838706505899163 -0.7999999999999998 0.30000000000000115 0.5860876576449532 -0.7499999999999998 0.2500000000000011 0.5881843768809776 -0.7499999999999998 0.30000000000000115 0.5763112030109387 -0.6999999999999997 0.2500000000000011 0.5905018505811089 -0.6999999999999997 0.30000000000000115 0.5745533726522075 -0.6499999999999997 0.2500000000000011 0.5917824028232308 -0.6499999999999997 0.30000000000000115 0.5776125998124596 -0.5999999999999996 0.2500000000000011 0.5925020515621047 -0.5999999999999996 0.30000000000000115 0.5803866724311335 -0.5499999999999996 0.2500000000000011 0.5914653219695614 -0.49999999999999956 0.2500000000000011 0.60028901117714 -0.4499999999999995 0.2500000000000011 0.5990790703408619 -0.39999999999999947 0.2500000000000011 0.5957072814943288 -0.3499999999999994 0.2500000000000011 0.5944241947219709 -0.2999999999999994 0.2500000000000011 0.5852784737496278 -0.24999999999999933 0.2500000000000011 0.5798813486129121 -0.1999999999999993 0.2500000000000011 0.5866234463937334 -0.14999999999999925 0.2500000000000011 0.5924223152852254 -0.0999999999999992 0.2500000000000011 0.5935991111290394 -0.049999999999999156 0.2500000000000011 0.5875645505722309 8.881784197001252e-16 0.2500000000000011 0.5921108649312974 0.05000000000000093 0.20000000000000107 0.5784524146183654 0.05000000000000093 0.2500000000000011 0.5821941575051804 0.10000000000000098 0.20000000000000107 0.5821196605874457 0.10000000000000098 0.2500000000000011 0.5842801930114659 0.15000000000000102 0.20000000000000107 0.5873609301628936 0.15000000000000102 0.2500000000000011 0.581806457891098 0.20000000000000107 0.20000000000000107 0.5885574213155912 0.20000000000000107 0.2500000000000011 0.5770000239613042 0.2500000000000011 0.20000000000000107 0.5974010350850825 0.2500000000000011 0.2500000000000011 0.5723859692536498 0.30000000000000115 0.20000000000000107 0.5919862953398796 0.3500000000000012 0.20000000000000107 0.5825184193435442 0.40000000000000124 0.20000000000000107 0.5867242168168006 0.4500000000000013 0.20000000000000107 0.585334837706524 0.5000000000000013 0.20000000000000107 0.5797377539226234 0.5500000000000014 0.20000000000000107 0.5859858748089308 0.6000000000000014 0.20000000000000107 0.58435190924537 0.6500000000000015 0.20000000000000107 0.5899513379549092 0.7000000000000015 0.20000000000000107 0.5843487665655233 0.7500000000000016 0.20000000000000107 0.5822855968245153 0.8000000000000016 0.20000000000000107 0.5760773890916607 0.9000000000000017 0.20000000000000107 0.5779651174866303 0.9500000000000017 0.20000000000000107 0.5742452146786886
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
[-1.] [0.3]
PRtovs2019_ros_sh = shift_time(PRtovs2019_ros,age_2018['forpr_ros3'][4][750:1110],datelist_vs[750:1110],base_adm[0],factor_adm[0])
PRtovs2019_rosb_sh = shift_time(PRtovs2019_rosb,age_2018['backvs_ros3'][4][750:1110],datelist_vs[750:1110],-base_adm[0],-factor_adm[0])
PRtovs2019_ros_m,PRtovs2019_rosb_m,c,PRtovs2019_ros_avg = merge(PRtovs2019_ros_sh,PRtovs2019_rosb_sh)
print(c)
plt.plot(PRtovs2019_ros_m.Transport)
plt.plot(PRtovs2019_rosb_m.Transport)
0.6075211384337889
[<matplotlib.lines.Line2D at 0x7f87c45df970>]
PRtovs2020_rosl = sectransp_2018['forpr_ros3'][4][1110:1460]
PRtovs2020_rosbl = sectransp_2018['backvs_ros3'][4][1110:1460]
PRtovs2020_ros = pd.Series(PRtovs2020_rosl,index=datelist_vs[1110:1460])
PRtovs2020_rosb = pd.Series(PRtovs2020_rosbl,index=datelist_vs[1110:1460])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtovs2020_ros,age_2018['forpr_ros3'][4][1110:1460],datelist_vs[1110:1460],base,factor)
dfr2 = shift_time(PRtovs2020_rosb,age_2018['backvs_ros3'][4][1110:1460],datelist_vs[1110:1460],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.57:
print (base, factor, corr_arr[i, j])
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
-1.0 0.15000000000000102 0.5777372008991812 -1.0 0.20000000000000107 0.7235128021885254 -1.0 0.2500000000000011 0.8179089506000462 -1.0 0.30000000000000115 0.7909405145146315 -1.0 0.3500000000000012 0.6719771739841168 -0.95 0.15000000000000102 0.5777823554010787 -0.95 0.20000000000000107 0.7375340915786697 -0.95 0.2500000000000011 0.8184372337250301 -0.95 0.30000000000000115 0.786491465703274 -0.95 0.3500000000000012 0.6734633970430354 -0.8999999999999999 0.15000000000000102 0.5787356048095568 -0.8999999999999999 0.20000000000000107 0.7451338022394541 -0.8999999999999999 0.2500000000000011 0.8202240288090273 -0.8999999999999999 0.30000000000000115 0.7826189888483195 -0.8999999999999999 0.3500000000000012 0.6681729009386236 -0.8499999999999999 0.15000000000000102 0.5942466286999506 -0.8499999999999999 0.20000000000000107 0.7522822875244594 -0.8499999999999999 0.2500000000000011 0.819421588915242 -0.8499999999999999 0.30000000000000115 0.7776565147506596 -0.8499999999999999 0.3500000000000012 0.659141858296467 -0.7999999999999998 0.15000000000000102 0.6216202232038099 -0.7999999999999998 0.20000000000000107 0.7601304104017305 -0.7999999999999998 0.2500000000000011 0.8199640205557011 -0.7999999999999998 0.30000000000000115 0.7728940939531389 -0.7999999999999998 0.3500000000000012 0.638701289324003 -0.7499999999999998 -0.3499999999999994 0.570908366845876 -0.7499999999999998 0.15000000000000102 0.6215623268510893 -0.7499999999999998 0.20000000000000107 0.7681165096163465 -0.7499999999999998 0.2500000000000011 0.8240852710771298 -0.7499999999999998 0.30000000000000115 0.7613713794496071 -0.7499999999999998 0.3500000000000012 0.6265437821224827 -0.6999999999999997 0.15000000000000102 0.6300881977113866 -0.6999999999999997 0.20000000000000107 0.7780602955557813 -0.6999999999999997 0.2500000000000011 0.8207444021345284 -0.6999999999999997 0.30000000000000115 0.7452186544450031 -0.6999999999999997 0.3500000000000012 0.6067853198273051 -0.6499999999999997 0.15000000000000102 0.6373847180686955 -0.6499999999999997 0.20000000000000107 0.7824314757720724 -0.6499999999999997 0.2500000000000011 0.8212644820798304 -0.6499999999999997 0.30000000000000115 0.7374561101627982 -0.6499999999999997 0.3500000000000012 0.5932718415301743 -0.5999999999999996 0.15000000000000102 0.6444550197217422 -0.5999999999999996 0.20000000000000107 0.7816831979561507 -0.5999999999999996 0.2500000000000011 0.8187637440398374 -0.5999999999999996 0.30000000000000115 0.7339100026622871 -0.5999999999999996 0.3500000000000012 0.5832684200388145 -0.5499999999999996 0.15000000000000102 0.6519196500437531 -0.5499999999999996 0.20000000000000107 0.7848877057006155 -0.5499999999999996 0.2500000000000011 0.8133952215250028 -0.5499999999999996 0.30000000000000115 0.7306619507199096 -0.5499999999999996 0.3500000000000012 0.576788309977161 -0.49999999999999956 0.15000000000000102 0.65433099569594 -0.49999999999999956 0.20000000000000107 0.78642112035647 -0.49999999999999956 0.2500000000000011 0.8107057127285079 -0.49999999999999956 0.30000000000000115 0.7185997289870756 -0.49999999999999956 0.3500000000000012 0.5754386000071879 -0.4499999999999995 0.15000000000000102 0.6679268354271855 -0.4499999999999995 0.20000000000000107 0.8086132597541069 -0.4499999999999995 0.2500000000000011 0.804933289891274 -0.4499999999999995 0.30000000000000115 0.7055308611242582 -0.39999999999999947 0.15000000000000102 0.674341876076847 -0.39999999999999947 0.20000000000000107 0.808968852354506 -0.39999999999999947 0.2500000000000011 0.7996914706279108 -0.39999999999999947 0.30000000000000115 0.6923235563555776 -0.3499999999999994 0.15000000000000102 0.6864419604246504 -0.3499999999999994 0.20000000000000107 0.7983175599291089 -0.3499999999999994 0.2500000000000011 0.8052605072883592 -0.3499999999999994 0.30000000000000115 0.6861008462625694 -0.2999999999999994 0.15000000000000102 0.6926426022382695 -0.2999999999999994 0.20000000000000107 0.8010631740226432 -0.2999999999999994 0.2500000000000011 0.8018354270095339 -0.2999999999999994 0.30000000000000115 0.6768528134238355 -0.24999999999999933 0.15000000000000102 0.7031181762510491 -0.24999999999999933 0.20000000000000107 0.8045673071355894 -0.24999999999999933 0.2500000000000011 0.8018819453228749 -0.24999999999999933 0.30000000000000115 0.6654970087163613 -0.1999999999999993 0.10000000000000098 0.591645055104446 -0.1999999999999993 0.15000000000000102 0.725829461756346 -0.1999999999999993 0.20000000000000107 0.8076139593486831 -0.1999999999999993 0.2500000000000011 0.7918170148967505 -0.1999999999999993 0.30000000000000115 0.6587538144142703 -0.14999999999999925 -0.39999999999999947 0.5735745348751139 -0.14999999999999925 0.10000000000000098 0.591105148543494 -0.14999999999999925 0.15000000000000102 0.7282491972833269 -0.14999999999999925 0.20000000000000107 0.8055411796880446 -0.14999999999999925 0.2500000000000011 0.7831514302556528 -0.14999999999999925 0.30000000000000115 0.6485116475469579 -0.0999999999999992 -0.39999999999999947 0.5756266557956645 -0.0999999999999992 0.10000000000000098 0.5894913638792783 -0.0999999999999992 0.15000000000000102 0.7398133632806309 -0.0999999999999992 0.20000000000000107 0.8111405921713873 -0.0999999999999992 0.2500000000000011 0.7746319229922422 -0.0999999999999992 0.30000000000000115 0.6444437222236927 -0.049999999999999156 0.10000000000000098 0.5983726732407278 -0.049999999999999156 0.15000000000000102 0.7468048371743271 -0.049999999999999156 0.20000000000000107 0.8020723133068833 -0.049999999999999156 0.2500000000000011 0.7549760940668219 -0.049999999999999156 0.30000000000000115 0.628457869779906 8.881784197001252e-16 0.10000000000000098 0.6053184815200247 8.881784197001252e-16 0.15000000000000102 0.7563886754891407 8.881784197001252e-16 0.20000000000000107 0.8080740676035549 8.881784197001252e-16 0.2500000000000011 0.7539669874157555 8.881784197001252e-16 0.30000000000000115 0.6222422789803093 0.05000000000000093 -0.39999999999999947 0.5714556905463638 0.05000000000000093 0.10000000000000098 0.6088680494757486 0.05000000000000093 0.15000000000000102 0.7569321480428061 0.05000000000000093 0.20000000000000107 0.8122796343680986 0.05000000000000093 0.2500000000000011 0.74756669089466 0.05000000000000093 0.30000000000000115 0.6142446283144923 0.10000000000000098 0.10000000000000098 0.6140958161973835 0.10000000000000098 0.15000000000000102 0.7604925555149843 0.10000000000000098 0.20000000000000107 0.808196568591403 0.10000000000000098 0.2500000000000011 0.7343824303422047 0.10000000000000098 0.30000000000000115 0.6063749974341494 0.15000000000000102 0.10000000000000098 0.631035914289728 0.15000000000000102 0.15000000000000102 0.7724122917084286 0.15000000000000102 0.20000000000000107 0.8064457876607205 0.15000000000000102 0.2500000000000011 0.7254916933205809 0.15000000000000102 0.30000000000000115 0.5982235127975121 0.20000000000000107 0.10000000000000098 0.6314075948982443 0.20000000000000107 0.15000000000000102 0.7898185139619895 0.20000000000000107 0.20000000000000107 0.807351144051545 0.20000000000000107 0.2500000000000011 0.723831151301175 0.20000000000000107 0.30000000000000115 0.5803190764160131 0.2500000000000011 0.10000000000000098 0.638298955179422 0.2500000000000011 0.15000000000000102 0.7920240387431574 0.2500000000000011 0.20000000000000107 0.8045919785911426 0.2500000000000011 0.2500000000000011 0.7150813973535728 0.30000000000000115 0.10000000000000098 0.6450134392507815 0.30000000000000115 0.15000000000000102 0.7960478828888429 0.30000000000000115 0.20000000000000107 0.8088695070382586 0.30000000000000115 0.2500000000000011 0.7008211282039047 0.3500000000000012 0.10000000000000098 0.644040485947423 0.3500000000000012 0.15000000000000102 0.7959183245173372 0.3500000000000012 0.20000000000000107 0.8052332096682512 0.3500000000000012 0.2500000000000011 0.6955330535451092 0.40000000000000124 -0.4499999999999995 0.5726809698921349 0.40000000000000124 0.05000000000000093 0.5821710259996924 0.40000000000000124 0.10000000000000098 0.6656167347296676 0.40000000000000124 0.15000000000000102 0.7930719067158271 0.40000000000000124 0.20000000000000107 0.8032025282781504 0.40000000000000124 0.2500000000000011 0.683416814878713 0.4500000000000013 0.05000000000000093 0.5817090446604026 0.4500000000000013 0.10000000000000098 0.6803301323842478 0.4500000000000013 0.15000000000000102 0.7925082689026284 0.4500000000000013 0.20000000000000107 0.7969618272503233 0.4500000000000013 0.2500000000000011 0.6769922513749063 0.5000000000000013 0.05000000000000093 0.5881626157462602 0.5000000000000013 0.10000000000000098 0.6915679362655152 0.5000000000000013 0.15000000000000102 0.781579864383167 0.5000000000000013 0.20000000000000107 0.7948549875178091 0.5000000000000013 0.2500000000000011 0.6644405889978353 0.5500000000000014 0.05000000000000093 0.5881938874125648 0.5500000000000014 0.10000000000000098 0.7112658669249527 0.5500000000000014 0.15000000000000102 0.7800614302972239 0.5500000000000014 0.20000000000000107 0.7782710404806151 0.5500000000000014 0.2500000000000011 0.6556671774459711 0.6000000000000014 0.05000000000000093 0.5880792445859488 0.6000000000000014 0.10000000000000098 0.720473884243535 0.6000000000000014 0.15000000000000102 0.7830858240294418 0.6000000000000014 0.20000000000000107 0.773201767461297 0.6000000000000014 0.2500000000000011 0.6503286780204868 0.6500000000000015 0.05000000000000093 0.5877200322841888 0.6500000000000015 0.10000000000000098 0.7296841095706974 0.6500000000000015 0.15000000000000102 0.7901161459470074 0.6500000000000015 0.20000000000000107 0.764065718886815 0.6500000000000015 0.2500000000000011 0.6474390543362951 0.7000000000000015 0.05000000000000093 0.5876658979104578 0.7000000000000015 0.10000000000000098 0.7313766757917227 0.7000000000000015 0.15000000000000102 0.7907053921957422 0.7000000000000015 0.20000000000000107 0.7510646878794107 0.7000000000000015 0.2500000000000011 0.6319007151080076 0.7500000000000016 0.05000000000000093 0.5909407639799381 0.7500000000000016 0.10000000000000098 0.7339970480308671 0.7500000000000016 0.15000000000000102 0.7943149282566074 0.7500000000000016 0.20000000000000107 0.7454591042446869 0.7500000000000016 0.2500000000000011 0.6315091064914369 0.8000000000000016 0.05000000000000093 0.5948949622053877 0.8000000000000016 0.10000000000000098 0.7567283702000037 0.8000000000000016 0.15000000000000102 0.8018340149084169 0.8000000000000016 0.20000000000000107 0.744236294917964 0.8000000000000016 0.2500000000000011 0.6151954826024234 0.8500000000000016 0.05000000000000093 0.5959046999276375 0.8500000000000016 0.10000000000000098 0.7560254669770804 0.8500000000000016 0.15000000000000102 0.7998574946788642 0.8500000000000016 0.20000000000000107 0.7250620340579427 0.8500000000000016 0.2500000000000011 0.6114483335594927 0.9000000000000017 0.05000000000000093 0.5985871764035643 0.9000000000000017 0.10000000000000098 0.7567892750806688 0.9000000000000017 0.15000000000000102 0.8016468894286215 0.9000000000000017 0.20000000000000107 0.7160864949447079 0.9000000000000017 0.2500000000000011 0.5997437282685627 0.9500000000000017 -0.4499999999999995 0.5733939116125794 0.9500000000000017 0.05000000000000093 0.5966214560854918 0.9500000000000017 0.10000000000000098 0.759851928283673 0.9500000000000017 0.15000000000000102 0.7955260669688491 0.9500000000000017 0.20000000000000107 0.7078981920563516 [-0.75] [0.25]
PRtovs2020_ros_sh = shift_time(PRtovs2020_ros,age_2018['forpr_ros3'][4][1110:1460],datelist_vs[1110:1460],base_adm[0],factor_adm[0])
PRtovs2020_rosb_sh = shift_time(PRtovs2020_rosb,age_2018['backvs_ros3'][4][1110:1460],datelist_vs[1110:1460],-base_adm[0],-factor_adm[0])
PRtovs2020_ros_m,PRtovs2020_rosb_m,c,PRtovs2020_ros_avg = merge(PRtovs2020_ros_sh,PRtovs2020_rosb_sh)
print(c)
plt.plot(PRtovs2020_ros_m.Transport)
0.8240852710771298
[<matplotlib.lines.Line2D at 0x7f87c426e800>]
PRtovs2021_rosl = sectransp_2018['forpr_ros3'][4][1460:]
PRtovs2021_rosbl = sectransp_2018['backvs_ros3'][4][1460:]
PRtovs2021_ros = pd.Series(PRtovs2021_rosl,index=datelist_vs[1460:])
PRtovs2021_rosb = pd.Series(PRtovs2021_rosbl,index=datelist_vs[1460:])
# Loop through different base and factors to find which combination maximizes the correlation
factor_arr = np.arange(-1,1,0.05)
base_arr = np.arange(-1,1,0.05)
corr_arr = np.zeros([len(base_arr),len(factor_arr)])
for i,base in enumerate(base_arr):
for j,factor in enumerate(factor_arr):
dfr1 = shift_time(PRtovs2021_ros,age_2018['forpr_ros3'][4][1460:],datelist_vs[1460:],base,factor)
dfr2 = shift_time(PRtovs2021_rosb,age_2018['backvs_ros3'][4][1460:],datelist_vs[1460:],-base,-factor)
dfr1_sh,dfr2_sh,corr_arr[i,j],a = merge(dfr1,dfr2)
if corr_arr[i,j] > 0.57:
print (base, factor, corr_arr[i, j])
i_base_adm,i_factor_adm = np.where(corr_arr==np.max(corr_arr))
base_adm = base_arr[i_base_adm]
factor_adm = factor_arr[i_factor_adm]
print(base_adm,factor_adm)
-1.0 0.15000000000000102 0.5746431334328468 -1.0 0.20000000000000107 0.6588634608325544 -1.0 0.2500000000000011 0.6987159890164342 -1.0 0.30000000000000115 0.6927351707953536 -1.0 0.3500000000000012 0.6280027152299006 -0.95 0.15000000000000102 0.580675311420146 -0.95 0.20000000000000107 0.6561114586429424 -0.95 0.2500000000000011 0.7013669316289 -0.95 0.30000000000000115 0.6877956954337254 -0.95 0.3500000000000012 0.6318229646626421 -0.8999999999999999 0.15000000000000102 0.5966212787720768 -0.8999999999999999 0.20000000000000107 0.6537619611705109 -0.8999999999999999 0.2500000000000011 0.7041142268384987 -0.8999999999999999 0.30000000000000115 0.6802387962689193 -0.8999999999999999 0.3500000000000012 0.6402407795152583 -0.8499999999999999 0.15000000000000102 0.6068629793317425 -0.8499999999999999 0.20000000000000107 0.6660516386117893 -0.8499999999999999 0.2500000000000011 0.6952073340280771 -0.8499999999999999 0.30000000000000115 0.6829702559701336 -0.8499999999999999 0.3500000000000012 0.6382070794822371 -0.7999999999999998 0.15000000000000102 0.6076476373197611 -0.7999999999999998 0.20000000000000107 0.6738869336542167 -0.7999999999999998 0.2500000000000011 0.6973606244657699 -0.7999999999999998 0.30000000000000115 0.6934130959523588 -0.7999999999999998 0.3500000000000012 0.630887446518367 -0.7499999999999998 0.15000000000000102 0.6091484986435988 -0.7499999999999998 0.20000000000000107 0.6807022966386135 -0.7499999999999998 0.2500000000000011 0.7011464620006091 -0.7499999999999998 0.30000000000000115 0.6893190406488369 -0.7499999999999998 0.3500000000000012 0.6252540330494809 -0.6999999999999997 0.15000000000000102 0.609375775197882 -0.6999999999999997 0.20000000000000107 0.6780602045991506 -0.6999999999999997 0.2500000000000011 0.6996170272955619 -0.6999999999999997 0.30000000000000115 0.6794340510275734 -0.6999999999999997 0.3500000000000012 0.6245256561631686 -0.6499999999999997 0.15000000000000102 0.6170390925353494 -0.6499999999999997 0.20000000000000107 0.6798116666281603 -0.6499999999999997 0.2500000000000011 0.7052011978717878 -0.6499999999999997 0.30000000000000115 0.6756440747150291 -0.6499999999999997 0.3500000000000012 0.6162273477347983 -0.5999999999999996 0.15000000000000102 0.6185138280277013 -0.5999999999999996 0.20000000000000107 0.6762058275920603 -0.5999999999999996 0.2500000000000011 0.6945410323195683 -0.5999999999999996 0.30000000000000115 0.6676497568621905 -0.5999999999999996 0.3500000000000012 0.6124414604445901 -0.5499999999999996 0.15000000000000102 0.6186456238813358 -0.5499999999999996 0.20000000000000107 0.6858766237311263 -0.5499999999999996 0.2500000000000011 0.7008791232646375 -0.5499999999999996 0.30000000000000115 0.6576649508334445 -0.5499999999999996 0.3500000000000012 0.6058675059635613 -0.49999999999999956 0.15000000000000102 0.6315045612732555 -0.49999999999999956 0.20000000000000107 0.6805763248891963 -0.49999999999999956 0.2500000000000011 0.7053563457996531 -0.49999999999999956 0.30000000000000115 0.6534057525940445 -0.49999999999999956 0.3500000000000012 0.6048592033210156 -0.4499999999999995 0.15000000000000102 0.6443121696011623 -0.4499999999999995 0.20000000000000107 0.679628012618052 -0.4499999999999995 0.2500000000000011 0.7058044509073802 -0.4499999999999995 0.30000000000000115 0.6474659737144787 -0.4499999999999995 0.3500000000000012 0.59515325222253 -0.39999999999999947 0.15000000000000102 0.6476495130947834 -0.39999999999999947 0.20000000000000107 0.6779958719442025 -0.39999999999999947 0.2500000000000011 0.69029554151439 -0.39999999999999947 0.30000000000000115 0.6447467672708941 -0.39999999999999947 0.3500000000000012 0.5945894960861137 -0.3499999999999994 0.15000000000000102 0.6567874451804783 -0.3499999999999994 0.20000000000000107 0.6822879828519923 -0.3499999999999994 0.2500000000000011 0.6897211398498903 -0.3499999999999994 0.30000000000000115 0.6428793476787388 -0.3499999999999994 0.3500000000000012 0.5849332169631631 -0.2999999999999994 0.15000000000000102 0.6524494468702459 -0.2999999999999994 0.20000000000000107 0.6888076139811472 -0.2999999999999994 0.2500000000000011 0.6802885025806908 -0.2999999999999994 0.30000000000000115 0.6445188285907381 -0.2999999999999994 0.3500000000000012 0.5792059166931712 -0.24999999999999933 0.15000000000000102 0.6510751605688434 -0.24999999999999933 0.20000000000000107 0.69486523579636 -0.24999999999999933 0.2500000000000011 0.677747159082253 -0.24999999999999933 0.30000000000000115 0.6349918653412536 -0.24999999999999933 0.3500000000000012 0.5790251395056629 -0.1999999999999993 0.15000000000000102 0.6494356390610775 -0.1999999999999993 0.20000000000000107 0.6947931159462223 -0.1999999999999993 0.2500000000000011 0.6880135824539141 -0.1999999999999993 0.30000000000000115 0.6317785955220978 -0.1999999999999993 0.3500000000000012 0.5840433517074775 -0.14999999999999925 0.15000000000000102 0.6450260821816861 -0.14999999999999925 0.20000000000000107 0.6958908967036207 -0.14999999999999925 0.2500000000000011 0.6888362634707461 -0.14999999999999925 0.30000000000000115 0.6283733636645932 -0.14999999999999925 0.3500000000000012 0.5736251355953219 -0.0999999999999992 0.15000000000000102 0.6510777172383055 -0.0999999999999992 0.20000000000000107 0.6968562342547278 -0.0999999999999992 0.2500000000000011 0.6819790510221327 -0.0999999999999992 0.30000000000000115 0.6318902470394469 -0.0999999999999992 0.3500000000000012 0.5718721201055353 -0.049999999999999156 0.10000000000000098 0.5720718871898058 -0.049999999999999156 0.15000000000000102 0.6483349593416294 -0.049999999999999156 0.20000000000000107 0.6927421374693853 -0.049999999999999156 0.2500000000000011 0.6783642724238226 -0.049999999999999156 0.30000000000000115 0.640633122034579 -0.049999999999999156 0.3500000000000012 0.5738510851363382 8.881784197001252e-16 0.10000000000000098 0.5834090669123285 8.881784197001252e-16 0.15000000000000102 0.6516886376027368 8.881784197001252e-16 0.20000000000000107 0.6879244492235337 8.881784197001252e-16 0.2500000000000011 0.6764075700348793 8.881784197001252e-16 0.30000000000000115 0.6351664858183316 0.05000000000000093 0.10000000000000098 0.5945735344836789 0.05000000000000093 0.15000000000000102 0.6511755858386993 0.05000000000000093 0.20000000000000107 0.6848287979365241 0.05000000000000093 0.2500000000000011 0.6689798179876835 0.05000000000000093 0.30000000000000115 0.6240598534308857 0.10000000000000098 0.10000000000000098 0.6096536743223183 0.10000000000000098 0.15000000000000102 0.6621999357327505 0.10000000000000098 0.20000000000000107 0.6793006891580732 0.10000000000000098 0.2500000000000011 0.6685533491110831 0.10000000000000098 0.30000000000000115 0.6146327017704825 0.15000000000000102 0.10000000000000098 0.6070296129471354 0.15000000000000102 0.15000000000000102 0.6708951394169315 0.15000000000000102 0.20000000000000107 0.6958399461996682 0.15000000000000102 0.2500000000000011 0.6578160444841601 0.15000000000000102 0.30000000000000115 0.6134578719881943 0.20000000000000107 0.10000000000000098 0.6106364790063694 0.20000000000000107 0.15000000000000102 0.6785808573179549 0.20000000000000107 0.20000000000000107 0.7065767732632187 0.20000000000000107 0.2500000000000011 0.6576605415057643 0.20000000000000107 0.30000000000000115 0.6173038829760572 0.2500000000000011 0.10000000000000098 0.6090034742854272 0.2500000000000011 0.15000000000000102 0.6819903898650468 0.2500000000000011 0.20000000000000107 0.7089597479508083 0.2500000000000011 0.2500000000000011 0.6537588784753154 0.2500000000000011 0.30000000000000115 0.6091416254875065 0.30000000000000115 0.10000000000000098 0.6170964872322735 0.30000000000000115 0.15000000000000102 0.6814676976369431 0.30000000000000115 0.20000000000000107 0.7086483096371325 0.30000000000000115 0.2500000000000011 0.650700413994098 0.30000000000000115 0.30000000000000115 0.5902832442955451 0.3500000000000012 0.10000000000000098 0.6323093641596793 0.3500000000000012 0.15000000000000102 0.6895957603891004 0.3500000000000012 0.20000000000000107 0.702784856614501 0.3500000000000012 0.2500000000000011 0.6504307995158688 0.3500000000000012 0.30000000000000115 0.5905820523973383 0.40000000000000124 0.10000000000000098 0.6408707418923941 0.40000000000000124 0.15000000000000102 0.6814557783918817 0.40000000000000124 0.20000000000000107 0.7018008474498134 0.40000000000000124 0.2500000000000011 0.6459925090643499 0.40000000000000124 0.30000000000000115 0.5909548826824474 0.4500000000000013 0.10000000000000098 0.6501419316998039 0.4500000000000013 0.15000000000000102 0.6789905337301425 0.4500000000000013 0.20000000000000107 0.7039298459615985 0.4500000000000013 0.2500000000000011 0.6455848592245568 0.4500000000000013 0.30000000000000115 0.5828929670100068 0.5000000000000013 0.10000000000000098 0.6428527427500883 0.5000000000000013 0.15000000000000102 0.6839382341764553 0.5000000000000013 0.20000000000000107 0.6907750820778102 0.5000000000000013 0.2500000000000011 0.6444110165082346 0.5000000000000013 0.30000000000000115 0.5879810714708021 0.5500000000000014 0.10000000000000098 0.6315562207374235 0.5500000000000014 0.15000000000000102 0.692184225603883 0.5500000000000014 0.20000000000000107 0.6724248692947428 0.5500000000000014 0.2500000000000011 0.6437420203264126 0.5500000000000014 0.30000000000000115 0.5864342907269161 0.6000000000000014 0.10000000000000098 0.6386553132622599 0.6000000000000014 0.15000000000000102 0.6939272507176569 0.6000000000000014 0.20000000000000107 0.6681891821797241 0.6000000000000014 0.2500000000000011 0.6300769365513839 0.6000000000000014 0.30000000000000115 0.5820597781247476 0.6500000000000015 0.10000000000000098 0.6404004128248793 0.6500000000000015 0.15000000000000102 0.6957818503831377 0.6500000000000015 0.20000000000000107 0.6727156573451153 0.6500000000000015 0.2500000000000011 0.6281588425835909 0.6500000000000015 0.30000000000000115 0.5805239917150272 0.7000000000000015 0.10000000000000098 0.6406739821088304 0.7000000000000015 0.15000000000000102 0.6885194371441601 0.7000000000000015 0.20000000000000107 0.6694671491271358 0.7000000000000015 0.2500000000000011 0.6218435174014676 0.7000000000000015 0.30000000000000115 0.5798499473788032 0.7500000000000016 0.10000000000000098 0.6451761759444723 0.7500000000000016 0.15000000000000102 0.6805414423942326 0.7500000000000016 0.20000000000000107 0.6653419654577312 0.7500000000000016 0.2500000000000011 0.6220906761050579 0.7500000000000016 0.30000000000000115 0.5745889157785614 0.8000000000000016 0.10000000000000098 0.6466840445913872 0.8000000000000016 0.15000000000000102 0.6809636971444405 0.8000000000000016 0.20000000000000107 0.6658641742676806 0.8000000000000016 0.2500000000000011 0.6337227169382634 0.8000000000000016 0.30000000000000115 0.5817839261063984 0.8500000000000016 0.10000000000000098 0.6449206093247162 0.8500000000000016 0.15000000000000102 0.6799393071604419 0.8500000000000016 0.20000000000000107 0.6576118603205854 0.8500000000000016 0.2500000000000011 0.6298366090444464 0.8500000000000016 0.30000000000000115 0.5793072027697962 0.9000000000000017 0.10000000000000098 0.6456443490355925 0.9000000000000017 0.15000000000000102 0.6861679815866233 0.9000000000000017 0.20000000000000107 0.6561727742611129 0.9000000000000017 0.2500000000000011 0.6156507285560062 0.9000000000000017 0.30000000000000115 0.5788394662754348 0.9500000000000017 0.05000000000000093 0.5714859201386515 0.9500000000000017 0.10000000000000098 0.6492192406075703 0.9500000000000017 0.15000000000000102 0.6852773955306292 0.9500000000000017 0.20000000000000107 0.6450636439478757 0.9500000000000017 0.2500000000000011 0.6154632625210867 0.9500000000000017 0.30000000000000115 0.5751162612118781 [0.25] [0.2]
PRtovs2021_ros_sh = shift_time(PRtovs2021_ros,age_2018['forpr_ros3'][4][1460:],datelist_vs[1460:],base_adm[0],factor_adm[0])
PRtovs2021_rosb_sh = shift_time(PRtovs2021_rosb,age_2018['backvs_ros3'][4][1460:],datelist_vs[1460:],-base_adm[0],-factor_adm[0])
PRtovs2021_ros_m,PRtovs2021_rosb_m,c,PRtovs2021_ros_avg = merge(PRtovs2021_ros_sh,PRtovs2021_rosb_sh)
print(c)
plt.plot(PRtovs2021_ros_m.Transport)
0.7089597479508083
[<matplotlib.lines.Line2D at 0x7f87c4cc0760>]
#Separate for each year
## 2017
rostosouth_2017 = PRtovs2017_ros_avg + PRtoadm2017_ros_avg
date2017_rossh = list(rostosouth_2017.dropna().index)
mask = np.isin(datelist_dens,date2017_rossh)
densdiff_ros2017 = dens_diff_ros[mask]
date_dens_2017sh = np.array(datelist_dens)[mask]
corr_rostosouth2017,p = stats.spearmanr(densdiff_ros2017,rostosouth_2017.dropna())
print('2017:',corr_rostosouth2017)
## 2018
rostosouth_2018 = PRtovs2018_ros_avg + PRtoadm2018_ros_avg
date2018_rossh = list(rostosouth_2018.dropna().index)
mask = np.isin(datelist_dens,date2018_rossh)
densdiff_ros2018 = dens_diff_ros[mask]
date_dens_2018sh = np.array(datelist_dens)[mask]
corr_rostosouth2018,p = stats.spearmanr(densdiff_ros2018,rostosouth_2018.dropna())
print('2018:',corr_rostosouth2018)
##2019
rostosouth_2019 = PRtovs2019_ros_avg.dropna() + PRtoadm2019_ros_avg.dropna()
date2019_rossh = list(rostosouth_2019.dropna().index)
mask = np.isin(datelist_dens,date2019_rossh)
densdiff_ros2019 = dens_diff_ros[mask]
date_dens_2019sh = np.array(datelist_dens)[mask]
corr_rostosouth2019,p = stats.spearmanr(densdiff_ros2019,rostosouth_2019.dropna())
print('2019:',corr_rostosouth2019)
##2020
rostosouth_2020 = PRtovs2020_ros_avg.dropna() + PRtoadm2020_ros_avg.dropna()
date2020_rossh = list(rostosouth_2020.dropna().index)
mask = np.isin(datelist_dens,date2020_rossh)
densdiff_ros2020 = dens_diff_ros[mask]
date_dens_2020sh = np.array(datelist_dens)[mask]
corr_rostosouth2020,p = stats.spearmanr(densdiff_ros2020,rostosouth_2020.dropna())
print('2020:',corr_rostosouth2020)
##2021
rostosouth_2021 = PRtovs2021_ros_avg.dropna() + PRtoadm2021_ros_avg.dropna()
date2021_rossh = list(rostosouth_2021.dropna().index)
mask = np.isin(datelist_dens,date2021_rossh)
densdiff_ros2021 = dens_diff_ros[mask]
date_dens_2021sh = np.array(datelist_dens)[mask]
corr_rostosouth2021,p = stats.spearmanr(densdiff_ros2021,rostosouth_2021.dropna())
print('2021:',corr_rostosouth2021)
2017: 0.8026360800109054 2018: 0.8292558573214036 2019: 0.6999855275351025 2020: 0.7782638846760945 2021: 0.7886338537636968
rostosouth = PRtovs_ros_avg + PRtoadm_ros_avg
date_rossh = list(rostosouth.dropna().index)
mask = np.isin(datelist_dens,date_rossh)
densdiff_ros = dens_diff_ros[mask]
# densdiff_ros2 = dens_diff_rosVS[mask]
date_dens_sh = np.array(datelist_dens)[mask]
corr_rostosouth,p = stats.spearmanr(densdiff_ros,rostosouth.dropna())
# PRtoadm2018_ros_avg.dropna().to_csv('combined2timeseries/PRtoadm2018_ros_avg.csv',index_label='Date')
# rostosouth_2017.dropna().to_csv('combined2timeseries/rostosouth_2017.csv',index_label='Date')
# rostosouth_2018.dropna().to_csv('combined2timeseries/rostosouth_2018.csv',index_label='Date')
# rostosouth_2019.dropna().to_csv('combined2timeseries/rostosouth_2019.csv',index_label='Date')
# rostosouth_2020.dropna().to_csv('combined2timeseries/rostosouth_2020.csv',index_label='Date')
# rostosouth_2021.dropna().to_csv('combined2timeseries/rostosouth_2021.csv',index_label='Date')
# rostosouth.dropna().to_csv('combined2timeseries/rostosouth17-21.csv',index_label='Date')
# PRtovs2017_ros_avg.dropna().to_csv('combined2timeseries/PRtovs2017_ros_avg.csv',index_label='Date')
# PRtovs2018_ros_avg.dropna().to_csv('combined2timeseries/PRtovs2018_ros_avg.csv',index_label='Date')
# PRtovs2019_ros_avg.dropna().to_csv('combined2timeseries/PRtovs2019_ros_avg.csv',index_label='Date')
# PRtovs2020_ros_avg.dropna().to_csv('combined2timeseries/PRtovs2020_ros_avg.csv',index_label='Date')
# PRtovs2021_ros_avg.dropna().to_csv('combined2timeseries/PRtovs2021_ros_avg.csv',index_label='Date')
# PRtovs_ros_avg.dropna().to_csv('combined2timeseries/PRtovs_ros_avg.csv',index_label='Date')
# PRtoadm2017_ros_avg.dropna().to_csv('combined2timeseries/PRtoadm2017_ros_avg.csv',index_label='Date')
# PRtoadm2018_ros_avg.dropna().to_csv('combined2timeseries/PRtoadm2018_ros_avg.csv',index_label='Date')
# PRtoadm2019_ros_avg.dropna().to_csv('combined2timeseries/PRtoadm2019_ros_avg.csv',index_label='Date')
# PRtoadm2020_ros_avg.dropna().to_csv('combined2timeseries/PRtoadm2020_ros_avg.csv',index_label='Date')
# PRtoadm2021_ros_avg.dropna().to_csv('combined2timeseries/PRtoadm2021_ros_avg.csv',index_label='Date')
# PRtoadm_ros_avg.dropna().to_csv('combined2timeseries/PRtoadm_ros_avg.csv',index_label='Date')
# harotosouth.dropna().to_csv('combined2timeseries/harotosouth18-21.csv')