In [2]:
import netCDF4 as nc
import numpy as np 
import matplotlib.pyplot as plt
import datetime as dt
import cmocean
import datetime
from salishsea_tools import nc_tools, viz_tools
%matplotlib inline
In [3]:
import matplotlib as mpl
mpl.rcParams['font.size'] = 18
mpl.rcParams['axes.titlesize'] = 18
In [43]:
from IPython.display import HTML

HTML('''<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 } else {
 $('div.input').show();
 }
 code_show = !code_show
} 
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
Out[43]:
In [4]:
f2015top = nc.Dataset('/data/vdo/MEOPAR/test/seasonal-30_2015.nc')
f2016top = nc.Dataset('/data/vdo/MEOPAR/test/seasonal-30_2016.nc')
f2017top = nc.Dataset('/data/vdo/MEOPAR/test/seasonal-30_2017.nc')
In [5]:
t_averages = (f2015top.variables['sum_pp'][:] 
              + f2016top.variables['sum_pp'][:]
              + f2017top.variables['sum_pp'][:])/3
In [6]:
mesh = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/mesh_mask201702.nc')
In [7]:
for n in range(4):
    i = np.ma.masked_array(t_averages[n,...],
                           mask = 1 - mesh.variables['tmask'][0,22,...])
    print(i.min(), i.max())
6.2210294e-14 1.9626452e-06
1.3756005e-13 1.5440315e-05
1.8499491e-13 2.6186326e-05
1.0207395e-13 7.768977e-06

PPDIAT + PPPHY + PPMRUB

In [8]:
fig, axs = plt.subplots(1,4,figsize = (30,10))
s = axs[0].pcolormesh(np.ma.masked_array(t_averages[0,...],
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.dense, vmin = 0, vmax = 0.00003)
fig.colorbar(s, ax=axs[0])
viz_tools.set_aspect(axs[0])
axs[0].set_title('Winter Averaged')

s = axs[1].pcolormesh(np.ma.masked_array(t_averages[1,...],
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.dense, vmin = 0, vmax = 0.00003)
fig.colorbar(s, ax=axs[1])
viz_tools.set_aspect(axs[1])
axs[1].set_title('Spring Averaged')

s = axs[2].pcolormesh(np.ma.masked_array(t_averages[2,...],
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.dense, vmin = 0, vmax = 0.00003)
fig.colorbar(s, ax=axs[2])
viz_tools.set_aspect(axs[2])
axs[2].set_title('Summer Averaged')

s = axs[3].pcolormesh(np.ma.masked_array(t_averages[3,...],
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.dense, vmin = 0, vmax = 0.00003)
fig.colorbar(s, ax=axs[3])
viz_tools.set_aspect(axs[3])
axs[3].set_title('Fall Averaged');
/home/vdo/anaconda3/lib/python3.6/site-packages/matplotlib/colors.py:861: RuntimeWarning: overflow encountered in true_divide
  resdat /= (vmax - vmin)
In [9]:
fig, axs = plt.subplots(1,4,figsize = (30,10))

s = axs[0].pcolormesh(np.ma.masked_array(f2015top.variables['sum_pp'][0,...] 
                                           - t_averages[0,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.000005, vmax = 0.000005)
fig.colorbar(s, ax=axs[0])
viz_tools.set_aspect(axs[0])
axs[0].set_title('Winter, 2015 - averaged')

s = axs[1].pcolormesh(np.ma.masked_array(f2015top.variables['sum_pp'][1,...] 
                                           - t_averages[1,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.000005, vmax = 0.000005)
fig.colorbar(s, ax=axs[1])
viz_tools.set_aspect(axs[1])
axs[1].set_title('Spring, 2015 - averaged')

s = axs[2].pcolormesh(np.ma.masked_array(f2015top.variables['sum_pp'][2,...] 
                                           - t_averages[2,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.000005, vmax = 0.000005)
fig.colorbar(s, ax=axs[2])
viz_tools.set_aspect(axs[2])
axs[2].set_title('Summer, 2015 - averaged')

s = axs[3].pcolormesh(np.ma.masked_array(f2015top.variables['sum_pp'][3,...] 
                                           - t_averages[3,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.000005, vmax = 0.000005)
fig.colorbar(s, ax=axs[3])
viz_tools.set_aspect(axs[3])
axs[3].set_title('Fall, 2015 - averaged');
/home/vdo/anaconda3/lib/python3.6/site-packages/matplotlib/colors.py:861: RuntimeWarning: overflow encountered in true_divide
  resdat /= (vmax - vmin)
In [10]:
fig, axs = plt.subplots(1,4,figsize = (30,10))

s = axs[0].pcolormesh(np.ma.masked_array(f2016top.variables['sum_pp'][0,...] 
                                           - t_averages[0,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.00001, vmax = 0.00001)
fig.colorbar(s, ax=axs[0])
viz_tools.set_aspect(axs[0])
axs[0].set_title('Winter, 2016 - averaged')

s = axs[1].pcolormesh(np.ma.masked_array(f2016top.variables['sum_pp'][1,...] 
                                           - t_averages[1,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.00001, vmax = 0.00001)
fig.colorbar(s, ax=axs[1])
viz_tools.set_aspect(axs[1])
axs[1].set_title('Spring, 2016 - averaged')

s = axs[2].pcolormesh(np.ma.masked_array(f2016top.variables['sum_pp'][2,...] 
                                           - t_averages[2,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.00001, vmax = 0.00001)
fig.colorbar(s, ax=axs[2])
viz_tools.set_aspect(axs[2])
axs[2].set_title('Summer, 2016 - averaged')

s = axs[3].pcolormesh(np.ma.masked_array(f2016top.variables['sum_pp'][3,...] 
                                           - t_averages[3,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.00001, vmax = 0.00001)
fig.colorbar(s, ax=axs[3])
viz_tools.set_aspect(axs[3])
axs[3].set_title('Fall, 2016 - averaged');
/home/vdo/anaconda3/lib/python3.6/site-packages/matplotlib/colors.py:861: RuntimeWarning: overflow encountered in true_divide
  resdat /= (vmax - vmin)
In [11]:
fig, axs = plt.subplots(1,4,figsize = (30,10))

s = axs[0].pcolormesh(np.ma.masked_array(f2017top.variables['sum_pp'][0,...] 
                                           - t_averages[0,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.00001, vmax = 0.00001)
fig.colorbar(s, ax=axs[0])
viz_tools.set_aspect(axs[0])
axs[0].set_title('Winter, 2017 - averaged')

s = axs[1].pcolormesh(np.ma.masked_array(f2017top.variables['sum_pp'][1,...] 
                                           - t_averages[1,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.00001, vmax = 0.00001)
fig.colorbar(s, ax=axs[1])
viz_tools.set_aspect(axs[1])
axs[1].set_title('Spring, 2017 - averaged')

s = axs[2].pcolormesh(np.ma.masked_array(f2017top.variables['sum_pp'][2,...] 
                                           - t_averages[2,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.00001, vmax = 0.00001)
fig.colorbar(s, ax=axs[2])
viz_tools.set_aspect(axs[2])
axs[2].set_title('Summer, 2017 - averaged')

s = axs[3].pcolormesh(np.ma.masked_array(f2017top.variables['sum_pp'][3,...] 
                                           - t_averages[3,...], 
                                           mask = 1 - mesh.variables['tmask'][0,22,...]), 
                        cmap = cmocean.cm.balance, vmin = -0.00001, vmax = 0.00001)
fig.colorbar(s, ax=axs[3])
viz_tools.set_aspect(axs[3])
axs[3].set_title('Fall, 2017 - averaged');
/home/vdo/anaconda3/lib/python3.6/site-packages/matplotlib/colors.py:861: RuntimeWarning: overflow encountered in true_divide
  resdat /= (vmax - vmin)
In [12]:
n = nc.Dataset('/data/vdo/MEOPAR/test/all_years_averages.nc', 'w')
In [13]:
time = n.createDimension("time_counter", None)
y = n.createDimension("y", 898)
x = n.createDimension("x", 398)
In [14]:
times = n.createVariable("time","f8",("time_counter",))
top_T = n.createVariable("sum_pp","f4",("time_counter","y", "x"))
In [15]:
dates = [datetime.datetime(2016, 1, 15, 12, 0), datetime.datetime(2016, 4, 16, 0, 0),
         datetime.datetime(2016, 7, 17, 0, 0), datetime.datetime(2016, 10, 16, 12, 0)]
In [16]:
f2015top.variables['time_counter'].units
Out[16]:
'seconds since 1900-01-01 00:00:00'
In [17]:
times[:] = nc.date2num(dates,'seconds since 1900-01-01 00:00:00')
In [18]:
top_T[:] = t_averages
In [19]:
n.close()
In [ ]: