Function for T-S plot with improved high and low tides markers.
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import glob
from salishsea_tools import (nc_tools, geo_tools, tidetools)
import netCDF4 as nc
Jan = sorted(glob.glob('/results/SalishSea/hindcast/*jan16/*1h*grid_T*'))
Feb = sorted(glob.glob('/results/SalishSea/hindcast/*feb16/*1h*grid_T*'))
Mar = sorted(glob.glob('/results/SalishSea/hindcast/*mar16/*1h*grid_T*'))
Apr = sorted(glob.glob('/results/SalishSea/hindcast/*apr16/*1h*grid_T*'))
May = sorted(glob.glob('/results/SalishSea/hindcast/*may16/*1h*grid_T*'))
Jun = sorted(glob.glob('/results/SalishSea/hindcast/*jun16/*1h*grid_T*'))
Jul = sorted(glob.glob('/results/SalishSea/hindcast/*jul16/*1h*grid_T*'))
Aug = sorted(glob.glob('/results/SalishSea/hindcast/*aug16/*1h*grid_T*'))
Sep = sorted(glob.glob('/results/SalishSea/hindcast/*sep16/*1h*grid_T*'))
Oct = sorted(glob.glob('/results/SalishSea/hindcast/*oct16/*1h*grid_T*'))
Nov = sorted(glob.glob('/results/SalishSea/hindcast/*nov16/*1h*grid_T*'))
Dec = sorted(glob.glob('/results/SalishSea/hindcast/*dec16/*1h*grid_T*'))
with nc_tools.scDataset(Jan) as f:
t = f.variables['votemper'][:57,:7,558,155]
s = f.variables['vosaline'][:57,:7,558,155]
ssh = f.variables['sossheig'][:57,558,155]
lows = []
highs = []
start_point = 0
interval = 9
target = 'low'
while start_point + interval < 56:
if target == 'low':
low = np.argmin(ssh[start_point:start_point + interval])
lows.append(low + start_point)
start_point = low + start_point
target = 'high'
elif target == 'high':
high = np.argmax(ssh[start_point:start_point + interval])
highs.append(high + start_point)
start_point = high + start_point
target = 'low'
list_of_differences = []
for n in range(4):
difference = ssh[highs[n]] - ssh[lows[n+1]]
list_of_differences.append(difference)
list_of_differences
fig,ax = plt.subplots(1,1,figsize=(8,8))
k = 0
for m in highs:
ax.plot(s[m,5], t[m,5], 'ro', markersize = 6*(list_of_differences[k]+1), alpha=0.7)
k = k+1
for n in lows:
ax.plot(s[n,5], t[n,5], 'go')
ax.plot(s[0,5],t[0,5],'y*', markersize = 20)
ax.plot(s[:,5],t[:,5])
ax.grid('on')
plt.title('T-S plot for January over 4 days')
<matplotlib.text.Text at 0x7f564acaba58>
fig, ax = plt.subplots(1,1,figsize=(8,8))
k = 0
for m in highs:
ax.plot(m, ssh[m], 'ro', markersize = 6*list_of_differences[k], alpha=0.7)
k = k+1
for n in lows:
ax.plot(n, ssh[n], 'go')
ax.plot(0,ssh[0],'y*')
ax.plot(range(57),ssh)
ax.grid('on')
ax.set_title('SSH - January 1-4')
<matplotlib.text.Text at 0x7f564ad724e0>
lon=599
lat=125
with nc_tools.scDataset(Jul) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Jan) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Feb) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Mar) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Apr) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(May) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Jun) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Aug) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Sep) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Oct) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Nov) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
with nc_tools.scDataset(Dec) as f:
t = f.variables['votemper'][:,6,lon,lat]
s = f.variables['vosaline'][:,6,lon,lat]
plt.plot(s,t)
plt.grid('on')
def make_TS_with_scaled_markers(files,lon,lat, depth,end_time):
with nc_tools.scDataset(files) as f:
t = f.variables['votemper'][:end_time,depth,lon,lat]
s = f.variables['vosaline'][:end_time,depth,lon,lat]
ssh = f.variables['sossheig'][:end_time,lon,lat]
lows = []
highs = []
start_point = 0
interval = 9
target = 'low'
while (start_point + interval) < (end_time - 1):
if target == 'low':
low = np.argmin(ssh[start_point:start_point + interval])
lows.append(low + start_point)
start_point = low + start_point
target = 'high'
elif target == 'high':
high = np.argmax(ssh[start_point:start_point + interval])
highs.append(high + start_point)
start_point = high + start_point
target = 'low'
list_of_differences = []
if len(lows) > len(highs):
for n in range(len(highs)):
difference = ssh[highs[n]] - ssh[lows[n+1]]
list_of_differences.append(np.abs(difference))
else:
for n in range(len(highs)-1):
difference = ssh[highs[n]] - ssh[lows[n+1]]
list_of_differences.append(np.abs(difference))
fig,ax = plt.subplots(1,1,figsize=(8,8))
k = 0
if len(lows) > len(highs):
for m in highs:
ax.plot(s[m], t[m], 'ro', markersize = 6*(list_of_differences[k]+1), alpha=0.7)
k = k+1
else:
for m in highs[:-1]:
ax.plot(s[m], t[m], 'ro',markersize = 6*(list_of_differences[k]+1), alpha=0.7)
k = k + 1
ax.plot(s[highs[-1]],t[highs[-1]],'r^',markersize=20,alpha=0.7)
for n in lows:
ax.plot(s[n], t[n], 'go')
ax.plot(s[0],t[0],'y*', markersize = 20)
ax.plot(s[:],t[:])
ax.grid('on')
ax.set_title('TS plot at depth=' + str(depth)+", at lon=" + str(lon) + ", lat=" + str(lat))
make_TS_with_scaled_markers(Jan,599,125,6,96)
make_TS_with_scaled_markers(Feb,599,125,6,96)
make_TS_with_scaled_markers(Mar,599,125,6,96)
make_TS_with_scaled_markers(Apr,599,125,6,96)
make_TS_with_scaled_markers(May,599,125,6,96)
make_TS_with_scaled_markers(Jun,599,125,6,96)
make_TS_with_scaled_markers(Jul,599,125,6,96)
make_TS_with_scaled_markers(Aug,599,125,6,96)
make_TS_with_scaled_markers(Sep,599,125,6,96)
make_TS_with_scaled_markers(Oct,599,125,6,96)
make_TS_with_scaled_markers(Nov,599,125,6,96)
make_TS_with_scaled_markers(Dec,599,125,5,96)
def make_TS(files,lon,lat, depth,):
with nc_tools.scDataset(files) as f:
t = f.variables['votemper'][:168,depth,lon,lat]
s = f.variables['vosaline'][:168,depth,lon,lat]
ssh = f.variables['sossheig'][:168,lon,lat]
lows = []
highs = []
start_point = 0
interval = 9
target = 'low'
while start_point + interval < 167:
if target == 'low':
low = np.argmin(ssh[start_point:start_point + interval])
lows.append(low + start_point)
start_point = low + start_point
target = 'high'
elif target == 'high':
high = np.argmax(ssh[start_point:start_point + interval])
highs.append(high + start_point)
start_point = high + start_point
target = 'low'
fig,ax = plt.subplots(1,1,figsize=(8,8))
for m in highs:
ax.plot(s[m], t[m], 'ro')
for n in lows:
ax.plot(s[n], t[n], 'go')
ax.plot(s[0],t[0],'y*', markersize = 20)
ax.plot(s[:],t[:])
ax.grid('on')
ax.set_title('TS plot at depth=' + str(depth)+", at lon=" + str(lon) + ", lat=" + str(lat))
import matplotlib.lines as mlines
depth = 6
lon = 599
lat = 125
with nc_tools.scDataset(Jun) as f:
t = f.variables['votemper'][:168,depth,lon,lat]
s = f.variables['vosaline'][:168,depth,lon,lat]
ssh = f.variables['sossheig'][:168,lon,lat]
lows = []
highs = []
start_point = 0
interval = 9
target = 'low'
while start_point + interval < 167:
if target == 'low':
low = np.argmin(ssh[start_point:start_point + interval])
lows.append(low + start_point)
start_point = low + start_point
target = 'high'
elif target == 'high':
high = np.argmax(ssh[start_point:start_point + interval])
highs.append(high + start_point)
start_point = high + start_point
target = 'low'
fig,ax = plt.subplots(1,1,figsize=(8,8))
for m in highs:
ax.plot(s[m], t[m], 'ro')
for n in lows:
ax.plot(s[n], t[n], 'go')
ax.plot(s[0],t[0],'y*', markersize = 20)
ax.plot(s[:],t[:])
ax.grid('on')
ax.set_title('TS plot at depth=' + str(depth)+", at lon=" + str(lon) + ", lat=" + str(lat), fontsize=16)
ax.set_ylabel('Temperature (C)', fontsize=15)
ax.set_xlabel('Salinity (g/kg)', fontsize=15)
ax.tick_params(labelsize=13)
start = mlines.Line2D([], [], color='yellow', marker='*',
markersize=15, label='Start')
high_point = mlines.Line2D([], [], color='red', marker='o',
markersize=15, label='High Tide')
low_point = mlines.Line2D([], [], color='green', marker='o',
markersize=15, label = 'Low Tide')
plt.legend(handles=[start, high_point, low_point])
#plt.savefig('Jun-TS-DeepBay.png', bbox_inches='tight')
make_TS(Jan,558,155,6)
make_TS(Feb, 558,155,5)