compare_venus_ctd
Module¶Render figure object produced by the nowcast.figures.publish.compare_venus_ctd
module.
Provides data for visual testing to confirm that refactoring has not adversely changed figure for web page.
Set-up and function call replicates as nearly as possible what is done in the nowcast.workers.make_plots
worker.
import io
import os
from pathlib import Path
import arrow
import netCDF4 as nc
import yaml
from salishsea_tools import nc_tools
from nowcast.figures import research_VENUS
from nowcast.figures.comparison import compare_venus_ctd
%matplotlib inline
NOTE
The next cell mounts the /results
filesystem on skookum
and the /ocean
filesystem locally.
It is intended for use if when this notebook is run on a laptop or other
non-Waterhole machine that has sshfs
installed
and mount points for /results
and /ocean
available in its root filesystem.
Don't execute the cell if that doesn't describe your situation.
!sshfs skookum:/results /results
!sshfs skookum:/ocean /ocean
config = '''
timezone: Canada/Pacific
run_types:
nowcast:
config name: SalishSea
bathymetry: /results/nowcast-sys/NEMO-forcing/grid/bathy_meter_SalishSea2.nc
mesh_mask: /results/nowcast-sys/NEMO-forcing/grid/mesh_mask_SalishSea2.nc
nowcast-green:
config name: SOG
bathymetry: /results/nowcast-sys/NEMO-forcing/grid/bathy_downonegrid2.nc
mesh_mask: /results/nowcast-sys/NEMO-forcing/grid/mesh_mask_downbyone2.nc
run:
results_archive:
nowcast: /results/SalishSea/nowcast/
nowcast-green: /results/SalishSea/nowcast-green/
forecast: /results/SalishSea/forecast/
'''
config = yaml.load(io.StringIO(config))
run_date = arrow.get('2016-07-03')
run_type = 'nowcast'
dmy = run_date.format('DDMMMYY').lower()
start_day = {
'nowcast': run_date.format('YYYYMMDD'),
'forecast': run_date.replace(days=+1).format('YYYYMMDD'),
}
end_day = {
'nowcast': run_date.format('YYYYMMDD'),
'forecast': run_date.replace(days=+2).format('YYYYMMDD'),
}
ymd = run_date.format('YYYYMMDD')
results_home = Path(config['run']['results_archive'][run_type])
results_dir = results_home/dmy
dev_results_home = Path(config['run']['results_archive']['nowcast-green'])
dev_results_dir = dev_results_home/dmy
bathy = nc.Dataset(config['run_types'][run_type]['bathymetry'])
mesh_mask = nc.Dataset(config['run_types'][run_type]['mesh_mask'])
dev_mesh_mask = nc.Dataset(config['run_types']['nowcast-green']['mesh_mask'])
grid_T_hr = nc.Dataset(
str(results_dir/'SalishSea_1h_{0}_{1}_grid_T.nc'
.format(start_day[run_type], end_day[run_type])))
dev_grid_T_hr = nc.Dataset(
str(dev_results_dir/'SalishSea_1h_{0}_{1}_grid_T.nc'
.format(start_day[run_type], end_day[run_type])))
%%timeit -n1 -r1
# Reference rendering of figure
fig = research_VENUS.compare_VENUS(
'East', grid_T_hr, bathy)
1 loop, best of 1: 9.24 s per loop
%%timeit -n1 -r1
# Refactored rendering of figure
from importlib import reload
from nowcast.figures import website_theme, shared
from salishsea_tools import places, data_tools
reload(compare_venus_ctd)
reload(website_theme)
reload(shared)
reload(places)
reload(data_tools)
fig = compare_venus_ctd.compare_venus_ctd(
'East node', grid_T_hr, dev_grid_T_hr,
config['timezone'], mesh_mask, dev_mesh_mask,
theme=website_theme)
1 loop, best of 1: 24.5 s per loop
%%timeit -n1 -r1
# Refactored rendering of figure
from importlib import reload
from nowcast.figures import website_theme, shared
from salishsea_tools import places, data_tools
reload(compare_venus_ctd)
reload(website_theme)
reload(shared)
reload(places)
reload(data_tools)
fig = compare_venus_ctd.compare_venus_ctd(
'Central node', grid_T_hr, dev_grid_T_hr,
config['timezone'], mesh_mask, dev_mesh_mask,
theme=website_theme)
1 loop, best of 1: 24 s per loop
%%timeit -n1 -r1
# Refactored rendering of figure
from importlib import reload
from nowcast.figures import website_theme, shared
from salishsea_tools import places, data_tools
reload(compare_venus_ctd)
reload(website_theme)
reload(shared)
reload(places)
reload(data_tools)
fig = compare_venus_ctd.compare_venus_ctd(
'Delta BBL node', grid_T_hr, dev_grid_T_hr,
config['timezone'], mesh_mask, dev_mesh_mask,
theme=website_theme, figsize=(8, 10))
1 loop, best of 1: 24.2 s per loop
%%timeit -n1 -r1
# Refactored rendering of figure
from importlib import reload
from nowcast.figures import website_theme, shared
from salishsea_tools import places, data_tools
reload(compare_venus_ctd)
reload(website_theme)
reload(shared)
reload(places)
reload(data_tools)
fig = compare_venus_ctd.compare_venus_ctd(
'Delta DDL node', grid_T_hr, dev_grid_T_hr,
config['timezone'], mesh_mask, dev_mesh_mask,
theme=website_theme, figsize=(8, 10))
True 1 loop, best of 1: 24.1 s per loop