Template for daily nowcast figure generation.
import datetime
from glob import glob
from importlib import reload
import os
from IPython.core.display import HTML
import netCDF4 as nc
#from nowcast.figures import figures
from nowcast.figures.publish import pt_atkinson_tide
from nowcast.figures.publish import storm_surge_alerts
from nowcast.figures.publish import compare_tide_prediction_max_ssh
import scipy.io as sio
%matplotlib inline
def results_dataset(period, grid, results_dir):
"""Return the results dataset for period (e.g. 1h or 1d)
and grid (e.g. grid_T, grid_U) from results_dir.
"""
filename_pattern = 'SalishSea_{period}_*_{grid}.nc'
filepaths = glob(os.path.join(results_dir, filename_pattern.format(period=period, grid=grid)))
return nc.Dataset(filepaths[0])
run_date = datetime.date.today()
run_date = datetime.datetime(2017, 12, 13)
# Results dataset location
results_home = '/results/SalishSea/forecast/'
results_dir = os.path.join(results_home, run_date.strftime('%d%b%y').lower())
Load the results datasets:
grid_T_hr = results_dataset('1h', 'grid_T', results_dir)
grid_T_dy = results_dataset('1d', 'grid_T', results_dir)
grid_U_dy = results_dataset('1d', 'grid_U', results_dir)
grid_V_dy = results_dataset('1d', 'grid_V', results_dir)
Set lots of paths etc
bathy = nc.Dataset('/ocean/sallen/allen/research/MEOPAR/grid/bathymetry_201702.nc')
tidal_predictions = '/SalishSeaCast/tidal-predictions/'
timezone = 'Canada/Pacific'
names = [
'Point Atkinson', 'Victoria', 'Campbell River', 'Cherry Point',
'Friday Harbor', 'Neah Bay', 'Nanaimo', 'Sand Heads', 'Boundary Bay',
'Port Renfrew', 'Halfmoon Bay', 'Friday Harbor', 'Patricia Bay',
'Squamish'
]
filepath_tmpl = os.path.join(results_dir, '{}.nc')
grids_15m = {
name: nc.Dataset(filepath_tmpl.format(name.replace(' ', '')))
for name in names
}
weather_path = '/results/forcing/atmospheric/GEM2.5/operational'
coastline = sio.loadmat('/ocean/rich/more/mmapbase/bcgeo/PNW.mat')
Display the figures:
HTML('<h2>{:%d%b%y} Figures</h2>'.format(run_date))
fig = figures.ssh_PtAtkinson(grid_T_hr)
reload(storm_surge_alerts)
<module 'nowcast.figures.publish.storm_surge_alerts' from '/ocean/sallen/allen/research/Meopar/SalishSeaNowcast/nowcast/figures/publish/storm_surge_alerts.py'>
fig = storm_surge_alerts.make_figure(grids_15m, weather_path, coastline, tidal_predictions)
fig = pt_atkinson_tide.make_figure(grid_T_hr, tidal_predictions, timezone)
fig = compare_tide_prediction_max_ssh.make_figure('Victoria', grid_T_hr, grids_15m, bathy, weather_path, tidal_predictions,
timezone)
fig = compare_tide_prediction_max_ssh.make_figure('Point Atkinson', grid_T_hr, grids_15m, bathy, weather_path, tidal_predictions,
timezone)
fig = compare_tide_prediction_max_ssh.make_figure('Campbell River', grid_T_hr, grids_15m, bathy, weather_path, tidal_predictions,
timezone)
fig = compare_tide_prediction_max_ssh.make_figure('Nanaimo', grid_T_hr, grids_15m, bathy, weather_path, tidal_predictions,
timezone)
fig = compare_tide_prediction_max_ssh.make_figure('Cherry Point', grid_T_hr, grids_15m, bathy, weather_path, tidal_predictions,
timezone)
fig = figures.compare_water_levels(grid_T_hr, bathy, grids_15m, coastline)
fig = figures.PA_max_ssh(grid_T_hr,bathy)
fig = figures.Sandheads_winds(grid_T_hr)
reload(figures)
fig = figures.thalweg_salinity(grid_T_dy)
fig = figures.plot_surface(grid_T_dy, grid_U_dy, grid_V_dy, bathy)