Average TS profiles over my tidal analysis period.
import pandas as pd
import netCDF4 as nc
import numpy as np
import matplotlib.pyplot as plt
from nowcast import analyze
from salishsea_tools import places
import datetime
%matplotlib inline
grid = nc.Dataset('/data/nsoontie/MEOPAR/NEMO-forcing/grid/bathy_meter_SalishSea2.nc')
mesh_mask = nc.Dataset('/data/nsoontie/MEOPAR/NEMO-forcing/grid/mesh_mask_SalishSea2.nc')
tmask = mesh_mask.variables['tmask'][:]
gdept = mesh_mask.variables['gdept'][:]
PLACES = places.PLACES
d1=datetime.datetime(2014,11,26)
d2=datetime.datetime(2015,4,26)
files = analyze.get_filenames(d1,d2,'1d','grid_T','/results/SalishSea/nowcast/')
sals ={}
temps = {}
depths={}
masks={}
for name in ['Central node', 'East node']:
j = PLACES[name]['NEMO grid ji'][0]
i = PLACES[name]['NEMO grid ji'][1]
sals[name], time = analyze.combine_files(files, 'vosaline', np.arange(40), j, i)
temps[name], time = analyze.combine_files(files, 'votemper', np.arange(40), j, i)
depths[name] = gdept[0,:,j,i]
masks[name] = tmask[0,:,j,i]
sals[name] = np.mean(sals[name], axis=0)
temps[name] = np.mean(temps[name], axis=0)
inds = np.where(masks[name]==1)
sals[name] = sals[name][inds]
temps[name] = temps[name][inds]
depths[name] = depths[name][inds]
/data/nsoontie/MEOPAR/tools/SalishSeaNowcast/nowcast/analyze.py:171: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison if kss == 'None':
fig, axs = plt.subplots(1,2,figsize=(10,5))
for name in ['Central node', 'East node']:
ax=axs[0]
ax.plot(sals[name],depths[name],'o-', label=name)
ax.set_ylim([300,0])
ax.set_xlabel('Practical Salinity [psu]')
ax.set_ylabel('Depth [m]')
ax=axs[1]
ax.plot(temps[name],depths[name],'o-', label=name)
ax.set_ylim([300,0])
ax.set_xlabel('Temperature [deg C]')
ax.set_ylabel('Depth [m]')
for ax in axs:
ax.grid()
ax.legend(loc=0)
Save using pandas
for name in ['Central node', 'East node']:
data = pd.DataFrame({'Depth [m]': depths[name],
'Practical Salinity [psu]': sals[name],
'Temperature [deg C]': temps[name]})
fname = '{}_meanTS_{}_{}.csv'.format(name[:-5], d1.strftime('%Y%m%d'), d2.strftime('%Y%m%d'))
data.to_csv(fname)
!ls *.csv
Central_meanTS_20141126_20150426.csv East_meanTS_20141126_20150426.csv
data
Depth [m] | Practical Salinity [psu] | Temperature [deg C] | |
---|---|---|---|
0 | 0.500000 | 19.681507 | 7.649859 |
1 | 1.500003 | 21.742039 | 7.993243 |
2 | 2.500011 | 23.447821 | 8.262228 |
3 | 3.500031 | 24.506578 | 8.452448 |
4 | 4.500071 | 25.250780 | 8.612563 |
5 | 5.500151 | 25.851595 | 8.760666 |
6 | 6.500310 | 26.347780 | 8.891456 |
7 | 7.500623 | 26.754166 | 9.002347 |
8 | 8.501236 | 27.090258 | 9.097125 |
9 | 9.502433 | 27.373615 | 9.179514 |
10 | 10.504766 | 27.609207 | 9.251032 |
11 | 11.509312 | 27.807636 | 9.312590 |
12 | 12.518167 | 27.976418 | 9.365047 |
13 | 13.535412 | 28.123075 | 9.410112 |
14 | 14.568982 | 28.252239 | 9.448424 |
15 | 15.634288 | 28.367905 | 9.480542 |
16 | 16.761173 | 28.473934 | 9.507227 |
17 | 18.007135 | 28.574501 | 9.529068 |
18 | 19.481785 | 28.675165 | 9.545954 |
19 | 21.389978 | 28.781658 | 9.555981 |
20 | 24.100256 | 28.900185 | 9.552986 |
21 | 28.229916 | 29.031275 | 9.525632 |
22 | 34.685757 | 29.166651 | 9.460915 |
23 | 44.517723 | 29.289066 | 9.372986 |
24 | 58.484333 | 29.398809 | 9.314327 |
25 | 76.585587 | 29.524263 | 9.334321 |
26 | 98.062958 | 29.738846 | 9.455692 |
27 | 121.866516 | 29.990423 | 9.615647 |
28 | 147.089462 | 30.195532 | 9.720541 |
29 | 164.994690 | 30.296865 | 9.763904 |