#!/usr/bin/env python # coding: utf-8 # # Test New `research_ferries` Module # # Render figure objects returned by `nowcast.research_ferries.salinity_ferry_route()` function. # Provides data for visual testing to confirm that refactoring has not adversely changed figures for web pages. # # Set-up and function call replicates as nearly as possible what is done in the `nowcast.workers.make_plots` worker. # In[1]: from pathlib import Path import arrow import netCDF4 as nc import scipy.io from nowcast.figures import ( figures, research_ferries, ) # In[23]: get_ipython().run_line_magic('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. # In[3]: get_ipython().system('sshfs skookum:/results /results') get_ipython().system('sshfs skookum:/ocean /ocean') # In[19]: # Relevant part of config from nowcast.yaml file config = { 'bathymetry': '/results/nowcast-sys/NEMO-forcing/grid/bathy_meter_SalishSea2.nc', 'coastline': '/ocean/rich/more/mmapbase/bcgeo/PNW.mat', 'observations': { 'ferry data': '/ocean/jieliu/research/meopar/ONC_ferries/', }, 'run': { 'results_archive': { 'nowcast': '/results/SalishSea/nowcast/', }, }, } # In[20]: run_date = arrow.get('2016-03-23') run_type = 'nowcast' dmy = run_date.format('DDMMMYY').lower() results_home = Path(config['run']['results_archive'][run_type]) results_dir = results_home/dmy # In[21]: ferry_data_path = config['observations']['ferry data'] grid_T_hr = nc.Dataset( str(results_dir/'SalishSea_1h_{0}_{0}_grid_T.nc' .format(run_date.format('YYYYMMDD')))) bathy = nc.Dataset(config['bathymetry']) coastline = scipy.io.loadmat(config['coastline']) # In[8]: get_ipython().run_cell_magic('timeit', '-n1 -r1', "\n# Reference rendering of figure\n\nfig = research_ferries.salinity_ferry_route(\n ferry_data_path, grid_T_hr, bathy, 'TW_DP', dmy)\n") # In[35]: get_ipython().run_cell_magic('timeit', '-n1 -r1', "\n# Refactored rendering of figure\n\nfrom importlib import reload\nreload(research_ferries)\n\nfig = research_ferries.salinity_ferry_route(\n ferry_data_path, grid_T_hr, bathy, 'TW_DP', dmy)\n") # In[7]: from importlib import reload reload(research_ferries) fig = research_ferries.salinity_ferry_route( ferry_data_path, grid_T_hr, bathy, 'TW_SB', dmy) # In[8]: from importlib import reload reload(research_ferries) fig = research_ferries.salinity_ferry_route( ferry_data_path, grid_T_hr, bathy, 'HB_DB', dmy)