x0_BW = range(0,8000,50)
y0_BW = range(0,8000,50)
z0_BW = range(0,52,2)

xp_B = len(x0_B)
yp_B = len(y0_B)
zp_B = len(z0_B)
pt_B = xp_B*yp_B*zp_B

xp_BW = len(x0_BW)
yp_BW = len(y0_BW)
zp_BW = len(z0_BW)
pt_BW = xp_BW*yp_BW*zp_BW

time_B, par_B = advect_functions.read_particles_csv(filename_B,pt_B,tt_B)
#par_B = lagrangian_stats.periodicCoords(par_B,2000,2000)
time_B = time_B[:-1]*1440 + 86400*2

time_BW, par_BW = advect_functions.read_particles_csv(filename_BW,pt_BW,tt_BW)
#par_BW = lagrangian_stats.periodicCoords(par_BW,10000,4000)
time_BW = time_BW[:-1]*1440 + 86400*2
    
xm = 2.5 
xM = 7.5
ym = 2
yM = 7

depths = [5] 
depthid_B = [1] 
depthid_BW = [1] 
x0 = range(0,5010,10)
y0 = range(0,5010,10)
#y0 = range(0,4010,10)
z0 = [0,5,10,15]

#BW
#x0 = range(0,9010,10)
#y0 = range(0,3010,10)
#z0 = [0,5,10,15]

xp = len(x0)
yp = len(y0)
zp = len(z0)
pt = xp*yp*zp

time2D, par2D = advect_functions.read_particles_csv(filename2D,pt,tt)
par2D = lagrangian_stats.periodicCoords(par2D,8000,8000)

#
time2D = (time2D)*1440
#    
time = time2D[:-1]

depths = [5, 10, 15] 
depthid = [1, 2, 3] 

nl = len(depths)

RD_2D = np.zeros((tt,nl))
CD_2D = np.zeros((tt,nl))
ED_2D = np.zeros((tt,nl))
     yt.append(y+dy)
     zt.append(z)

xt = np.asarray(xt)
yt = np.asarray(yt)
zt = np.asarray(zt)

#x0 = range(3000,4000,50)
#y0 = range(2000,3000,50)
#z0 = range(0,30,1)
xp = len(xt)
yp = len(yt)
zp = len(zt)

pt = xp
timet, par0 = advect_functions.read_particles_csv(filename0,pt,tt)
par0p = lagrangian_stats.periodicCoords(par0,2000,2000)
time0 = (timet)*360 + 48*3600 - 360
time0 = np.asarray(range(len(timet)))*360 + 48*3600 - 360

par = np.reshape(par0p,(pt,3,tt))

# FSLE
di = 5
time = time0 - time0[0]

rad = [5,10,20]

depths = [0, -10, -20] # z0

def dist(x0,x1,y0,y1,z0,z1):
tt_BW = 600 # IC + 24-48 included
tt_B = 600 # IC + 24-48 included

Xlist_BW = np.linspace(0,10000,801)
Ylist_BW = np.linspace(0,4000,321)
Xlist_B = np.linspace(0,8000,641)
Ylist_B = np.linspace(0,8000,641)
dl = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]
Zlist = 1.*np.cumsum(dl)

xp = 101
yp = 101
zp = 4
pt = xp*yp*zp
          
time2D_B, par2D_B = advect_functions.read_particles_csv(filename2D_B,pt,tt_B)
par2D_B = lagrangian_stats.periodicCoords(par2D_B,8000,8000)
time3D_B, par3D_B = advect_functions.read_particles_csv(filename3D_B,pt,tt_B)
par3D_B = lagrangian_stats.periodicCoords(par3D_B,8000,8000)

time2D_B = (time2D_B)*1440
time3D_B = (time3D_B)*1440 

time2D_BW, par2D_BW = advect_functions.read_particles_csv(filename2D_BW,pt,tt_BW)
par2D_BW = lagrangian_stats.periodicCoords(par2D_BW,10000,4000)
time3D_BW, par3D_BW = advect_functions.read_particles_csv(filename3D_BW,pt,tt_BW)
par3D_BW = lagrangian_stats.periodicCoords(par3D_BW,10000,4000)

time2D_BW = (time2D_BW)*1440
time3D_BW = (time3D_BW)*1440