%matplotlib inline
import matplotlib.pyplot as plt
import netCDF4 as nc
import numpy as np
import matplotlib.patches as patches
from salishsea_tools import viz_tools, geo_tools, tidetools
from bathy_helpers import *
import matplotlib.path as mpltPath
from fast_ll2ij_SalishSea201702 import *
grid = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/bathy_meter_SalishSea2.nc')
fig, ax = plt.subplots(1,1, figsize=(16,12))
ax.pcolormesh(grid.variables['Bathymetry'][:])
ax.set_ylim(590,670)
ax.set_xlim(115,135)
viz_tools.set_aspect(ax)
ax.add_patch(patches.Rectangle((118,598), 15, 59, fill=False, linewidth=3))
<matplotlib.patches.Rectangle at 0x7f90401e80b8>
Oct = nc.Dataset('/ocean/vdo/MEOPAR/ariane-runs/Oct16/ariane_trajectories_qualitative.nc')
latt = Oct.variables['traj_lat']
lont = Oct.variables['traj_lon']
bathy, lons, lats = tidetools.get_bathy_data(grid)
mask = lont[:].mask
def still_inside(time, number):
number_of_particles = np.zeros(time)
for n in range(time):
for m in range(number):
if (mask[n,m]) == False:
y,x = fast_ll2ij_SalishSea201702(lont[n,m],latt[n,m],lons, lats)
if (598<y<658) and (118<x<134):
number_of_particles[n] = number_of_particles[n] + 1
return number_of_particles
op = still_inside(744, 2694)
fig,ax=plt.subplots(1,1,figsize=(8,6))
time = range(744)
ax.plot(time, op)
ax.grid('on')
ax.set_title('Number of Particles in Domain', fontsize=16)
ax.set_ylabel('Number of Particles', fontsize=14)
ax.set_xlabel('Time (h)', fontsize=14)
ax.tick_params(labelsize=12)
index_deep_particles=[]
d = Oct.variables['init_z']
for n in range(2694):
if d[n] > 6:
index_deep_particles.append(n)
mask = lont[:].mask
def deep_particles(time, index):
number_of_deep_particles = np.zeros(time)
for n in range(time):
for m in index:
if (mask[n,m]) == False:
y,x = fast_ll2ij_SalishSea201702(lont[n,m],latt[n,m],lons, lats)
if (598<y<658) and (118<x<134):
number_of_deep_particles[n] = number_of_deep_particles[n] + 1
return number_of_deep_particles
sa = deep_particles(744,index_deep_particles)
fig,ax=plt.subplots(1,1,figsize=(8,6))
time = range(744)
ax.plot(time, sa)
ax.grid('on')
ax.set_title('Number of Particles (init depth > 6) in Domain at time = x')
ax.set_ylabel('Number of Particles')
ax.set_xlabel('Time')
<matplotlib.text.Text at 0x7f903fb566d8>
index_shallow_particles=[]
for n in range(2694):
if Oct.variables['init_z'][n] < 6:
index_shallow_particles.append(n)
mask=lont[:].mask
def shallow_particles(time, index):
number_of_shallow_particles = np.zeros(time)
for n in range(time):
for m in index:
if (mask[n,m]) == False:
y,x = fast_ll2ij_SalishSea201702(lont[n,m],latt[n,m],lons, lats)
if (598<y<658) and (118<x<134):
number_of_shallow_particles[n] = number_of_shallow_particles[n] + 1
return number_of_shallow_particles
sb = shallow_particles(744, index_shallow_particles)
fig,ax=plt.subplots(1,1,figsize=(8,6))
time = range(744)
ax.plot(time, sb)
ax.grid('on')
ax.set_title('Number of Particles (init depth < 6) in Domain at time = x')
ax.set_ylabel('Number of Particles')
ax.set_xlabel('Time')
<matplotlib.text.Text at 0x7f903fa9a668>