#!/usr/bin/env python # coding: utf-8 # # Test `compare_tide_prediction_max_ssh` Module # # Render figure object produced by the `nowcast.figures.publish.compare_tide_prediction_max_ssh` 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](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]: import io import os from pathlib import Path import arrow import netCDF4 as nc import requests import yaml from salishsea_tools import nc_tools from nowcast.figures.publish import compare_tide_prediction_max_ssh # In[2]: get_ipython().run_line_magic('matplotlib', 'inline') # The bits of `config/nowcast.yaml` that are required: # In[3]: config = ''' run types: forecast: bathymetry: bathymetry_201702.nc duration: 1.5 # days forecast2: bathymetry: bathymetry_201702.nc duration: 1.25 # days figures: dataset URLs: HRDPS fields: https://salishsea.eos.ubc.ca/erddap/griddap/ubcSSaSurfaceAtmosphereFieldsV1 tide stn ssh time series: # **Must be quoted to project {} characters** 'https://salishsea.eos.ubc.ca/erddap/griddap/ubcSSf{place}SSH10m' grid dir: /SalishSeaCast/grid/ ssh: tidal_predictions: /SalishSeaCast/tidal-predictions/ weather: ops_dir: /results/forcing/atmospheric/continental2.5/nemo_forcing/ run: results_archive: forecast: /results/SalishSea/forecast.201905/ forecast2: /results/SalishSea/forecast2.201905/ ''' config = yaml.safe_load(io.StringIO(config)) # In[4]: run_date = arrow.get('2021-04-08') run_type = 'forecast' dmy = run_date.format('DDMMMYY').lower() start_day = { 'forecast': run_date.shift(days=+1).format('YYYYMMDD'), 'forecast2': run_date.shift(days=+2).format('YYYYMMDD'), } end_day = { 'forecast': run_date.shift(days=+2).format('YYYYMMDD'), 'forecast2': run_date.shift(days=+3).format('YYYYMMDD'), } ymd = run_date.format('YYYYMMDD') results_home = Path(config['run']['results_archive'][run_type]) results_dir = results_home/dmy # In[5]: ssh_fcst_dataset_url_tmpl = config['figures']['dataset URLs']['tide stn ssh time series'] tidal_predictions = Path(config['ssh']['tidal_predictions']) forecast_hrs = int(config['run types'][run_type]['duration'] * 24) weather_path = Path(config['weather']['ops_dir'], 'fcst') grid_dir = Path(config['figures']['grid dir']) bathy = nc.Dataset(grid_dir / config['run types'][run_type]['bathymetry']) grid_T_hr_path = results_dir/f'SalishSea_1h_{start_day[run_type]}_{end_day[run_type]}_grid_T.nc' # In[6]: get_ipython().run_cell_magic('timeit', '-n1 -r1', "\nfrom importlib import reload\nfrom nowcast.figures import website_theme, shared\nfrom salishsea_tools import places\nreload(compare_tide_prediction_max_ssh)\nreload(website_theme)\nreload(shared)\nreload(places)\n\nfig = compare_tide_prediction_max_ssh.make_figure(\n 'Sandy Cove', ssh_fcst_dataset_url_tmpl, tidal_predictions, forecast_hrs,\n weather_path, bathy, grid_T_hr_path, theme=website_theme\n)\n") # In[7]: get_ipython().run_cell_magic('timeit', '-n1 -r1', '\nfrom importlib import reload\nfrom nowcast.figures import website_theme, shared\nfrom salishsea_tools import places\nreload(compare_tide_prediction_max_ssh)\nreload(website_theme)\nreload(shared)\nreload(places)\n\nnames = {\n "Boundary Bay": "BB_maxSSH",\n "Campbell River": "CR_maxSSH",\n "Cherry Point": "CP_maxSSH",\n "Friday Harbor": "FH_maxSSH",\n "Halfmoon Bay": "HB_maxSSH",\n "Nanaimo": "Nan_maxSSH",\n "Neah Bay": "NB_maxSSH",\n "New Westminster": "NW_maxSSH",\n "Patricia Bay": "PB_maxSSH",\n "Point Atkinson": "PA_maxSSH",\n "Port Renfrew": "PR_maxSSH",\n "Sand Heads": "SH_maxSSH",\n "Sandy Cove": "SC_maxSSH",\n "Squamish": "Sqam_maxSSH",\n "Victoria": "Vic_maxSSH",\n "Woodwards Landing": "WL_maxSSH",\n}\n\nfor name in names:\n fig = compare_tide_prediction_max_ssh.make_figure(\n name, ssh_fcst_dataset_url_tmpl, tidal_predictions, forecast_hrs,\n weather_path, bathy, grid_T_hr_path, theme=website_theme\n )\n') # In[ ]: