{ "cells": [ { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "Template for daily nowcast figure generation." ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "# SalishSeaCast NEMO Model Daily Nowcast Figures" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "# Set-up" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "import datetime\n", "from glob import glob\n", "from importlib import reload\n", "import os\n", "\n", "from IPython.core.display import HTML\n", "import netCDF4 as nc\n", "\n", "#from nowcast.figures import figures\n", "from nowcast.figures.publish import pt_atkinson_tide\n", "from nowcast.figures.publish import storm_surge_alerts\n", "from nowcast.figures.publish import compare_tide_prediction_max_ssh\n", "\n", "import scipy.io as sio\n", "\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "def results_dataset(period, grid, results_dir):\n", " \"\"\"Return the results dataset for period (e.g. 1h or 1d)\n", " and grid (e.g. grid_T, grid_U) from results_dir.\n", " \"\"\"\n", " filename_pattern = 'SalishSea_{period}_*_{grid}.nc'\n", " filepaths = glob(os.path.join(results_dir, filename_pattern.format(period=period, grid=grid)))\n", " return nc.Dataset(filepaths[0])" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "run_date = datetime.date.today()\n", "run_date = datetime.datetime(2017, 12, 13)\n", "# Results dataset location\n", "results_home = '/results/SalishSea/forecast/'\n", "results_dir = os.path.join(results_home, run_date.strftime('%d%b%y').lower())" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "Load the results datasets:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "grid_T_hr = results_dataset('1h', 'grid_T', results_dir)\n", "grid_T_dy = results_dataset('1d', 'grid_T', results_dir)\n", "grid_U_dy = results_dataset('1d', 'grid_U', results_dir)\n", "grid_V_dy = results_dataset('1d', 'grid_V', results_dir)" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "Set lots of paths etc" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "bathy = nc.Dataset('/ocean/sallen/allen/research/MEOPAR/grid/bathymetry_201702.nc')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "tidal_predictions = '/SalishSeaCast/tidal-predictions/'\n", "timezone = 'Canada/Pacific'\n", "names = [\n", " 'Point Atkinson', 'Victoria', 'Campbell River', 'Cherry Point',\n", " 'Friday Harbor', 'Neah Bay', 'Nanaimo', 'Sand Heads', 'Boundary Bay',\n", " 'Port Renfrew', 'Halfmoon Bay', 'Friday Harbor', 'Patricia Bay',\n", " 'Squamish'\n", " ]\n", "filepath_tmpl = os.path.join(results_dir, '{}.nc')\n", "grids_15m = {\n", " name: nc.Dataset(filepath_tmpl.format(name.replace(' ', '')))\n", " for name in names\n", " }\n", "weather_path = '/results/forcing/atmospheric/GEM2.5/operational'\n", "coastline = sio.loadmat('/ocean/rich/more/mmapbase/bcgeo/PNW.mat')" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "Display the figures:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "