tracer_thalweg_and_surface_hourly
Module¶Render figure object produced by the nowcast.figures.research.tracer_thalweg_and_surface_hourly
module.
Set-up and function call replicates as nearly as possible what is done in the nowcast.workers.make_plots
worker
to help ensure that the module will work in the nowcast production context.
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 Salish Sea Nowcast system /results/
parition mounted.
# reload lets us pull in changes from modules that we edit
from importlib import reload
# imports from the top of the make_plots worker
import datetime
from glob import glob
import logging
import os
from pathlib import Path
import matplotlib
import arrow
import cmocean
from nemo_nowcast import NowcastWorker
import netCDF4 as nc
import scipy.io as sio
from nowcast import lib
from nowcast.figures.research import tracer_thalweg_and_surface_hourly
# some extra imports that we need to simulate how the nowcast system works
import io
import yaml
# render figure objects in the notebook
%matplotlib inline
The config
multiline string contains the pieces of nowcast/config/nowcast.yaml
that are needed to set up the conditions as nowcast.workers.make_plots
does
before calling the figure module make_figure()
function.
The yaml.load()
call at the bottom of the cell converts the string into a config
dict.
config = '''
run_types:
nowcast-green:
bathymetry: /results/nowcast-sys/grid/bathymetry_201702.nc
mesh_mask: /results/nowcast-sys/grid/mesh_mask201702.nc
run:
results_archive:
nowcast-green: /results/SalishSea/nowcast-green/
'''
config = yaml.load(io.StringIO(config))
make_plots
Command-line Interface¶make_plots
gets run_type
, plot_type
, and run_date
from the command-line.
run_type = 'nowcast-green'
plot_type = 'research'
run_date = arrow.get('2017-09-11')
make_plots.make_plots()
Function¶The make_plots()
function uses paths defined in the nowcast system configuration file
to set up a collection of commonly used variables, paths, and datasets.
These are just the ones that we need for our test.
dmy = run_date.format('DDMMMYY').lower()
results_dir = Path(config['run']['results_archive'][run_type], dmy)
bathy = nc.Dataset(config['run_types'][run_type]['bathymetry'])
mesh_mask = nc.Dataset(config['run_types']['nowcast-green']['mesh_mask'])
_prep_nowcast_green_research_fig_functions()
¶This has the same effect as:
ptrc_T_hr = _results_dataset('1h', 'ptrc_T', results_dir)
yyyymmdd = run_date.format('YYYYMMDD')
ptrc_T_hr = nc.Dataset(os.fspath(results_dir/f'SalishSea_1h_{yyyymmdd}_{yyyymmdd}_ptrc_T.nc'))
The %%timeit
cell magic lets us keep an eye on how log the figure takes to process.
Setting -n1 -r1
prevents it from processing the figure more than once
as it might try to do to generate better statistics.
The reload()
calls reload imported modules so that any edits you have made will take effect here.
The make_figure()
call should be the same as goes in the make_plots
worker module.
%%timeit -n1 -r1
reload(tracer_thalweg_and_surface_hourly)
var = 'diatoms'
clevels_thalweg, clevels_surface = tracer_thalweg_and_surface_hourly.clevels(
ptrc_T_hr.variables[var], mesh_mask, depth_integrated=True)
hr = 0
fig = tracer_thalweg_and_surface_hourly.make_figure(
hr, ptrc_T_hr.variables[var], bathy, mesh_mask,
clevels_thalweg, clevels_surface, cmap=cmocean.cm.algae, depth_integrated=True
)
2.63 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)