#!/usr/bin/env python # coding: utf-8 # # Test `time_series_plots` Module # # Render figure object produced by the `nowcast.figures.research.time_series_plots` 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](https://salishsea-nowcast.readthedocs.io/en/latest/figures/fig_dev_env.html) # 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. # In[1]: # reload lets us pull in changes from modules that we edit from importlib import reload # In[2]: # imports from the top of the make_plots worker from pathlib import Path from types import SimpleNamespace import netCDF4 as nc import xarray as xr import arrow from salishsea_tools import places import nowcast.figures.website_theme from nowcast.figures.research import time_series_plots # In[3]: # some extra imports that we need to simulate how the nowcast system works import io import yaml # In[4]: # render figure objects in the notebook get_ipython().run_line_magic('matplotlib', 'inline') # ## Simulate Dataset Loading in `_prep_nowcast_green_research_fig_functions()` # In[5]: place = 'S3' left_variable = 'nitrate' right_variable = 'diatoms' xr_dataset = xr.open_dataset('https://salishsea.eos.ubc.ca/erddap/griddap/ubcSSg3DBiologyFields1hV18-06') # ## Render the Figure # # 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. # In[6]: get_ipython().run_cell_magic('timeit', '-n1 -r1', '\nreload(nowcast.figures.website_theme)\nreload(time_series_plots)\n\nfig = time_series_plots.make_figure(\n xr_dataset, left_variable, right_variable, place\n)\n') # In[ ]: