from __future__ import division import os import matplotlib.pyplot as plt import netCDF4 as nc from salishsea_tools import nc_tools %matplotlib inline #%%writefile -a figures.py def ssh_PtAtkinson(grid_T, bathy=None, figsize=(12, 4)): """Return a figure containing a plot of hourly sea surface height at Pt. Atkinson. :arg grid_T: Hourly tracer results dataset from NEMO. :type grid_T: :class:`netCDF4.Dataset` :arg bathy: Bathymetry dataset for the SalishSeaCast NEMO model. :type bathy: :class:`netCDF4.Dataset` :arg figsize: Figure size (width, height) in inches. :type figsize: 2-tuple :returns: Matplotlib figure object """ fig, ax = plt.subplots(1, 1, figsize=figsize) ssh = grid_T.variables['sossheig'] results_date = nc_tools.timestamp(grid_T, 0).format('YYYY-MM-DD') ax.plot(ssh[:, 468, 328], 'o') ax.set_xlim(0, 23) ax.set_xlabel('UTC Hour on {}'.format(results_date)) ax.set_ylabel('{label} [{units}]'.format(label=ssh.long_name.title(), units=ssh.units)) ax.grid() ax.set_title('Pt. Atkinson Hourly Sea Surface Height on {}'.format(results_date)) return fig grid_T = nc.Dataset( os.path.expanduser('~/MEOPAR/downloaded_results/SalishSea/nowcast/30oct14/SalishSea_1h_20141030_20141030_grid_T.nc')) fig = ssh_PtAtkinson(grid_T) ax = fig.axes[0] ax.set_axis_bgcolor('#2b3e50') fig.set_facecolor('#2b3e50') fig