surface_currents
Module¶Render figure object produced by the nowcast.figures.fvcom.surface_currents
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.
Notebooks like this should be developed in a
Nowcast Figures Development Environment
so that all of the necessary dependency packages are installed.
The development has to be done on a workstation that has the Vancouver Harbour & Fraser River FVCOM model results /opp/
parition mounted.
import io
from pathlib import Path
import arrow
import netCDF4
import yaml
from nowcast.figures.fvcom.research import surface_currents
%matplotlib inline
The bits of config/nowcast.yaml
that are required:
config = '''
vhfr fvcom runs:
results archive:
nowcast x2: /opp/fvcom/nowcast-x2/
forecast x2: /opp/fvcom/forecast-x2/
nowcast r12: /opp/fvcom/nowcast-r12/
'''
config = yaml.safe_load(io.StringIO(config))
The bits that the make_plots
worker must provide:
run_date = arrow.get('2019-05-16')
model_config = 'x2'
run_type = 'nowcast'
ddmmmyy = run_date.format('DDMMMYY').lower()
results_dir = Path(
config["vhfr fvcom runs"]["results archive"][f"{run_type} {model_config}"], ddmmmyy
)
fvcom_results_dataset = netCDF4.Dataset(results_dir/f"vh_{model_config}_0001.nc")
One time step, and one section for quickest testing:
%%timeit -n1 -r1
from importlib import reload
reload(surface_currents)
names = {
"English Bay": "EnglishBay_surface_currents",
"Vancouver Harbour": "VancouverHarbour_surface_currents",
"Indian Arm": "IndianArm_surface_currents",
}
time_index = 0
fig = surface_currents.make_figure(
"Vancouver Harbour", time_index, fvcom_results_dataset
)
2.47 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
All sections:
%%timeit -n1 -r1
from importlib import reload
reload(surface_currents)
names = {
"English Bay": "EnglishBay_surface_currents",
"Vancouver Harbour": "VancouverHarbour_surface_currents",
"Indian Arm": "IndianArm_surface_currents",
}
time_index = 0
for place in names:
fig = surface_currents.make_figure(
place, time_index, fvcom_results_dataset
)
6.29 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
run_date = arrow.get('2019-05-11')
model_config = 'r12'
run_type = 'nowcast'
ddmmmyy = run_date.format('DDMMMYY').lower()
results_dir = Path(
config["vhfr fvcom runs"]["results archive"][f"{run_type} {model_config}"], ddmmmyy
)
fvcom_results_dataset = netCDF4.Dataset(results_dir/f"vh_{model_config}_0001.nc")
One time step, and one section for quickest testing:
%%timeit -n1 -r1
from importlib import reload
reload(surface_currents)
names = {
"English Bay": "EnglishBay_surface_currents",
"Vancouver Harbour": "VancouverHarbour_surface_currents",
"Indian Arm": "IndianArm_surface_currents",
}
time_index = 0
fig = surface_currents.make_figure(
"Vancouver Harbour", time_index, fvcom_results_dataset
)
3.91 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
All sections:
%%timeit -n1 -r1
from importlib import reload
reload(surface_currents)
names = {
"English Bay": "EnglishBay_surface_currents",
"Vancouver Harbour": "VancouverHarbour_surface_currents",
"Indian Arm": "IndianArm_surface_currents",
}
time_index = 0
for place in names:
fig = surface_currents.make_figure(
place, time_index, fvcom_results_dataset
)
10.3 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
run_date = arrow.get('2019-05-16')
model_config = 'x2'
run_type = 'forecast'
ddmmmyy = run_date.format('DDMMMYY').lower()
results_dir = Path(
config["vhfr fvcom runs"]["results archive"][f"{run_type} {model_config}"], ddmmmyy
)
fvcom_results_dataset = netCDF4.Dataset(results_dir/f"vh_{model_config}_0001.nc")
One time step, and one section for quickest testing:
%%timeit -n1 -r1
from importlib import reload
reload(surface_currents)
names = {
"English Bay": "EnglishBay_surface_currents",
"Vancouver Harbour": "VancouverHarbour_surface_currents",
"Indian Arm": "IndianArm_surface_currents",
}
time_index = -1
fig = surface_currents.make_figure(
"Vancouver Harbour", time_index, fvcom_results_dataset
)
2.41 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
All sections:
%%timeit -n1 -r1
from importlib import reload
reload(surface_currents)
names = {
"English Bay": "EnglishBay_surface_currents",
"Vancouver Harbour": "VancouverHarbour_surface_currents",
"Indian Arm": "IndianArm_surface_currents",
}
time_index = -1
for place in names:
fig = surface_currents.make_figure(
place, time_index, fvcom_results_dataset
)
6.13 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)