import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
plt.rcParams['image.cmap'] = 'jet'
%matplotlib inline
result_directory = '/data/jpetrie/MEOPAR/SalishSea/results/remin_param_sweep_new_depth/nampisrem_zz_remin_D_PON_1.4512018923044442e-06/'
tracer_file = 'SS5x5_1h_20150201_20150501_ptrc_T.nc'
mesh_mask_file = 'mesh_mask.nc'
tracer_dataset = xr.open_dataset(result_directory + tracer_file)
mesh_mask = xr.open_dataset(result_directory + mesh_mask_file)
nitrogen_tracers = ['NO3','NH4','DOC','POC','PHY','PHY2','MICZ','MYRI']
tracer_sum = np.zeros(tracer_dataset[nitrogen_tracers[0]].values.shape)
for tracer in nitrogen_tracers:
tracer_sum = tracer_sum + tracer_dataset[tracer].values
# tracer_sum now contains total nitrogen concentration by t,z,y,x
# Sum across x and y coordinates. Gives 2D array with nitrogen concentration by time and depth
x_y_summed = np.sum(np.sum(tracer_sum,axis = 3),axis=2)
# A vector with the height of each grid element
grid_heights = np.array(mesh_mask['e3t_1d'][0])
# 2D array (time,depth) with the total quantity of nitrogen for that time and depth
grid_scaled = np.multiply(grid_heights,x_y_summed)
# Total nitrogen by time only (1D array)
depth_summed = np.sum(grid_scaled,axis = 1)
plt.plot(range(len(depth_summed)),depth_summed)
plt.ylabel("Total Nitrogen")
plt.xlabel("Time Index")
plt.title("5x5 Total Nitrogen vs. Time")
<matplotlib.text.Text at 0x7f6db89c47b8>
z = tracer_dataset.deptht.values
t= np.array([float(x) for x in tracer_dataset.time_centered.values])
tz,zt=np.meshgrid((t[:] - t[0])/10**9/3600/24,z[:])
fig, ax = plt.subplots(1, 1,figsize=(18,8))
mesh=plt.pcolormesh(tz,zt,x_y_summed.T)
fig.colorbar(mesh)
plt.gca().invert_yaxis()
#plt.title("NH4 (DON remineralization Param = " + str(DON_remin_const)+")", size = 20)
plt.xlabel("Days", size =18)
plt.ylabel("Depth", size = 18)
<matplotlib.text.Text at 0x7f6db92a56a0>
plt.plot(tracer_dataset.deptht.values,x_y_summed[2149,:], 'ro')
plt.ylabel("Total Nitrogen")
plt.xlabel("Depth")
<matplotlib.text.Text at 0x7f6db66dacc0>
for n in range(0,40):
#x = np.sum(grid_scaled[:,n],axis = 1)
fig, ax = plt.subplots(1, 1,figsize=(10,4))
plt.plot((t[:] - t[0])/10**9/3600/24,x_y_summed[:,n])
plt.ylabel("Total Nitrogen")
plt.xlabel("Days")
plt.title("Depth = " + str(z[n]))
plt.ylim(0,22)
/home/jpetrie/anaconda3/lib/python3.5/site-packages/matplotlib/pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). max_open_warning, RuntimeWarning)