import xarray as xr
import netCDF4 as nc
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import cmocean.cm as cm
import copy
from salishsea_tools import viz_tools, places, visualisations
import datetime as dt
import arrow
import copy
import math
import matplotlib.dates as mdates
from salishsea_tools import viz_tools
from mpl_toolkits.axes_grid1 import make_axes_locatable
thalweg = np.loadtxt('/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt', delimiter=' ', dtype=int)
grid = nc.Dataset('/home/sallen/MEOPAR/grid/bathymetry_202108.nc')
grid2 = nc.Dataset('/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/bathymetry_202310b.nc')
bathy = grid.variables['Bathymetry'][:,:]
bathy2 = grid2.variables['Bathymetry'][:,:]
lats = grid.variables['nav_lat'][:,:]
lons = grid.variables['nav_lon'][:,:]
lone = lons[thalweg[:,0],thalweg[:,1]];
late = lats[thalweg[:,0],thalweg[:,1]];
fig, ax = plt.subplots(1, 2, figsize=(14, 6))
mycmap = cm.deep
mycmap.set_bad('grey')
im = ax[0].pcolormesh(bathy, cmap=mycmap, vmin=50, vmax=220)
ax[0].plot(thalweg[:,1],thalweg[:,0],marker='.',color='r')
im2 = ax[1].pcolormesh(bathy2, cmap=mycmap, vmin=50, vmax=220)
ax[1].plot(thalweg[:,1],thalweg[:,0],marker='.',color='r')
viz_tools.set_aspect(ax[0]);
viz_tools.set_aspect(ax[1]);
ax[0].set_xlim([180, 260])
ax[0].set_ylim([328, 380])
ax[1].set_xlim([180, 260])
ax[1].set_ylim([328, 380])
divider = make_axes_locatable(ax[0])
divider2 = make_axes_locatable(ax[1])
cax = divider.append_axes('right', size='5%', pad=0.05)
cax2 = divider2.append_axes('right', size='5%', pad=0.05)
fig.colorbar(im, cax=cax, orientation='vertical')
fig.colorbar(im2, cax=cax2, orientation='vertical')
<matplotlib.colorbar.Colorbar at 0x7f266cb65610>
#open bathy file and meshmask
oldgridT = nc.Dataset('/results2/SalishSea/nowcast-green.202111/12aug19/SalishSea_1h_20190812_20190812_grid_T.nc')
oldgridU = nc.Dataset('/results2/SalishSea/nowcast-green.202111/12aug19/SalishSea_1h_20190812_20190812_grid_U.nc')
oldgridV = nc.Dataset('/results2/SalishSea/nowcast-green.202111/12aug19/SalishSea_1h_20190812_20190812_grid_V.nc')
oldchem = nc.Dataset('/results2/SalishSea/nowcast-green.202111/12aug19/SalishSea_1h_20190812_20190812_chem_T.nc')
oldfbathy = nc.Dataset('/ocean/atall/MOAD/grid/bathymetry_202108.nc')
oldfmesh = nc.Dataset('/ocean/atall/MOAD/grid/mesh_mask202108.nc')
newgridT = nc.Dataset('/ocean/atall/MOAD/Model/runs/12aug19/12aug19_bathy202310b/SalishSea_1h_20190812_20190812_grid_T.nc')
newgridU = nc.Dataset('/ocean/atall/MOAD/Model/runs/12aug19/12aug19_bathy202310b/SalishSea_1h_20190812_20190812_grid_U.nc')
newgridV = nc.Dataset('/ocean/atall/MOAD/Model/runs/12aug19/12aug19_bathy202310b/SalishSea_1h_20190812_20190812_grid_V.nc')
newchem = nc.Dataset('/ocean/atall/MOAD/Model/runs/12aug19/12aug19_bathy202310b/SalishSea_1h_20190812_20190812_chem_T.nc')
newfbathy = nc.Dataset('/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/bathymetry_202310b.nc')
newfmesh = nc.Dataset('/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/mesh_mask_202310b.nc')
fig, ax = plt.subplots(1, 2, figsize = (14, 4))
modvar='vosaline'
level = np.linspace(27,34,20)
oldcb=visualisations.contour_thalweg(ax[0],oldgridT.variables[modvar][0,:,:,:],oldfbathy,oldfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0].set_ylim([250, 0])
ax[0].set_title('oldbathy (v202108)')
newcb=visualisations.contour_thalweg(ax[1],newgridT.variables[modvar][0,...],newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1].set_ylim([250, 0])
ax[1].set_title('newbathy (v202310)')
fig.suptitle('Salinity - 2019-08-12T00:30');
fig, ax = plt.subplots(1, 2, figsize = (14, 4))
modvar='votemper'
level = np.linspace(8,20,30)
oldcb=visualisations.contour_thalweg(ax[0],oldgridT.variables[modvar][0,...],oldfbathy,oldfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0].set_ylim([250, 0])
ax[0].set_title('oldbathy (v202108)')
newcb=visualisations.contour_thalweg(ax[1],newgridT.variables[modvar][0,...],newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1].set_ylim([250, 0])
ax[1].set_title('newbathy (v202310)')
fig.suptitle('Temperature - 2019-08-12T00:30');
fig, ax = plt.subplots(1, 2, figsize = (14, 4))
modvar='vozocrtx'
level = np.linspace(-0.4,0.4,50)
oldcb=visualisations.contour_thalweg(ax[0],oldgridU.variables[modvar][0,...],oldfbathy,oldfmesh,clevels=level,cmap=cm.balance,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0].set_ylim([250, 0])
ax[0].set_title('oldbathy (v202108)')
newcb=visualisations.contour_thalweg(ax[1],newgridU.variables[modvar][0,...],newfbathy,newfmesh,clevels=level,cmap=cm.balance,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1].set_ylim([250, 0])
ax[1].set_title('newbathy (v202310)')
fig.suptitle('U velocity - 2019-08-12T00:30');
fig, ax = plt.subplots(1, 2, figsize = (14, 4))
modvar='vomecrty'
level = np.linspace(-0.4,0.4,50)
oldcb=visualisations.contour_thalweg(ax[0],oldgridV.variables[modvar][0,...],oldfbathy,oldfmesh,clevels=level,cmap=cm.balance,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0].set_ylim([250, 0])
ax[0].set_title('oldbathy (v202108)')
newcb=visualisations.contour_thalweg(ax[1],newgridV.variables[modvar][0,...],newfbathy,newfmesh,clevels=level,cmap=cm.balance,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1].set_ylim([250, 0])
ax[1].set_title('newbathy (v202310)')
fig.suptitle('V velocity - 2019-08-12T00:30');
fig, ax = plt.subplots(1, 2, figsize = (14, 4))
modvar='dissolved_oxygen'
level = np.linspace(80,300,30)
oldcb=visualisations.contour_thalweg(ax[0],oldchem.variables[modvar][0,...],oldfbathy,oldfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0].set_ylim([250, 0])
ax[0].set_title('oldbathy (v202108)')
newcb=visualisations.contour_thalweg(ax[1],newchem.variables[modvar][0,...],newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1].set_ylim([250, 0])
ax[1].set_title('newbathy (v202310)')
fig.suptitle('Oxygen - 2019-08-12T00:30');
gridT01 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201801_grid_T.nc')
gridT02 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201802_grid_T.nc')
gridT03 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201803_grid_T.nc')
gridT04 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201804_grid_T.nc')
gridT05 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201805_grid_T.nc')
gridT06 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201806_grid_T.nc')
gridT07 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201807_grid_T.nc')
gridT08 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201808_grid_T.nc')
gridT09 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201809_grid_T.nc')
chemT01 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201801_chem_T.nc')
chemT02 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201802_chem_T.nc')
chemT03 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201803_chem_T.nc')
chemT04 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201804_chem_T.nc')
chemT05 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201805_chem_T.nc')
chemT06 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201806_chem_T.nc')
chemT07 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201807_chem_T.nc')
chemT08 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201808_chem_T.nc')
chemT09 = nc.Dataset('/data/atall/MEOPAR/SalishSeaCast/results/daily18/SalishSea_1d_201809_chem_T.nc')
fig, ax = plt.subplots(3, 4, figsize = (16, 8))
modvar='vosaline'
level = np.linspace(27.5,31.5,30)
jan=visualisations.contour_thalweg(ax[0,0],np.mean(gridT01[modvar], axis=0),newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0,0].set_ylim([250, 0])
ax[0,0].set_title('Jan')
ax[0,0].set_xlabel('')
feb=visualisations.contour_thalweg(ax[0,1],np.mean(gridT02[modvar], axis=0),newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0,1].set_ylim([250, 0])
ax[0,1].set_title('Feb')
ax[0,1].set_xlabel('')
mar=visualisations.contour_thalweg(ax[0,2],np.mean(gridT03[modvar], axis=0),newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0,2].set_ylim([250, 0])
ax[0,2].set_title('Mar')
ax[0,2].set_xlabel('')
apr=visualisations.contour_thalweg(ax[0,3],np.mean(gridT04[modvar], axis=0),newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0,3].set_ylim([250, 0])
ax[0,3].set_title('Apr')
ax[0,3].set_xlabel('')
may=visualisations.contour_thalweg(ax[1,0],np.mean(gridT05[modvar], axis=0),newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1,0].set_ylim([250, 0])
ax[1,0].set_title('May')
ax[1,0].set_xlabel('')
jun=visualisations.contour_thalweg(ax[1,1],np.mean(gridT06[modvar], axis=0),newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1,1].set_ylim([250, 0])
ax[1,1].set_title('Jun')
jul=visualisations.contour_thalweg(ax[1,2],np.mean(gridT07[modvar], axis=0),newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1,2].set_ylim([250, 0])
ax[1,2].set_title('Jul')
aug=visualisations.contour_thalweg(ax[1,3],np.mean(gridT08[modvar], axis=0),newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1,3].set_ylim([250, 0])
ax[1,3].set_title('Aug')
aug=visualisations.contour_thalweg(ax[2,0],np.mean(gridT09[modvar], axis=0),newfbathy,newfmesh,clevels=level,cmap=cm.amp,thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[2,0].set_ylim([250, 0])
ax[2,0].set_title('Sep')
fig.suptitle('2018- monthly Salinity');
#################
fig, ax = plt.subplots(3, 4, figsize = (16, 8))
modvar='dissolved_oxygen'
level = np.linspace(27.5,31.5,30)
jan=visualisations.contour_thalweg(ax[0,0],np.mean(chemT01[modvar], axis=0),newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0,0].set_ylim([250, 0])
ax[0,0].set_title('Jan')
ax[0,0].set_xlabel('')
feb=visualisations.contour_thalweg(ax[0,1],np.mean(chemT02[modvar], axis=0),newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0,1].set_ylim([250, 0])
ax[0,1].set_title('Feb')
ax[0,1].set_xlabel('')
mar=visualisations.contour_thalweg(ax[0,2],np.mean(chemT03[modvar], axis=0),newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0,2].set_ylim([250, 0])
ax[0,2].set_title('Mar')
ax[0,2].set_xlabel('')
apr=visualisations.contour_thalweg(ax[0,3],np.mean(chemT04[modvar], axis=0),newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[0,3].set_ylim([250, 0])
ax[0,3].set_title('Apr')
ax[0,3].set_xlabel('')
may=visualisations.contour_thalweg(ax[1,0],np.mean(chemT05[modvar], axis=0),newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1,0].set_ylim([250, 0])
ax[1,0].set_title('May')
ax[1,0].set_xlabel('')
jun=visualisations.contour_thalweg(ax[1,1],np.mean(chemT06[modvar], axis=0),newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1,1].set_ylim([250, 0])
ax[1,1].set_title('Jun')
jul=visualisations.contour_thalweg(ax[1,2],np.mean(chemT07[modvar], axis=0),newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1,2].set_ylim([250, 0])
ax[1,2].set_title('Jul')
aug=visualisations.contour_thalweg(ax[1,3],np.mean(chemT08[modvar], axis=0),newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[1,3].set_ylim([250, 0])
ax[1,3].set_title('Aug')
aug=visualisations.contour_thalweg(ax[2,0],np.mean(chemT09[modvar], axis=0),newfbathy,newfmesh,clevels='oxygen',cmap='gist_rainbow_r',thalweg_file='/ocean/atall/MOAD/analysis-abdoul/notebooks/bathy/SaanichInlet_VictoriaSill_thalweg.txt',
cbar_args={'label':modvar})
ax[2,0].set_ylim([250, 0])
ax[2,0].set_title('Sep')
fig.suptitle('2018 monthly Dissolved Oxygen');