from __future__ import division from cStringIO import StringIO import datetime import glob import os import arrow from dateutil import tz import matplotlib from matplotlib.backends import backend_agg as backend import matplotlib.cm as cm import matplotlib.dates as mdates import matplotlib.gridspec as gridspec import matplotlib.pyplot as plt import netCDF4 as nc import numpy as np import pandas as pd import requests from scipy import interpolate as interp from salishsea_tools import ( nc_tools, viz_tools, stormtools, tidetools, ) from __future__ import division import datetime from glob import glob import os from IPython.core.display import HTML import netCDF4 as nc from salishsea_tools.nowcast import figures %matplotlib inline def results_dataset(period, grid, results_dir): """Return the results dataset for period (e.g. 1h or 1d) and grid (e.g. grid_T, grid_U) from results_dir. """ filename_pattern = 'SalishSea_{period}_*_{grid}.nc' filepaths = glob(os.path.join(results_dir, filename_pattern.format(period=period, grid=grid))) return nc.Dataset(filepaths[0]) def winds_dataset(run_date, model_path): """Return the winds dataset for the current date from model_path.""" year, month, day = run_date.strftime('%G'), run_date.strftime('%m'), run_date.strftime('%d') filename_pattern = 'ops_y{yyyy}m{mm}d{dd}.nc' filepaths = glob(os.path.join(model_path, filename_pattern.format(yyyy=year,mm=month,dd=day))) return nc.Dataset(filepaths[0]) #run_date = datetime.datetime(2015,1,8) run_date = datetime.date.today() # Results dataset location results_home = '/data/dlatorne/MEOPAR/SalishSea/nowcast/' results_dir = os.path.join(results_home, run_date.strftime('%d%b%y').lower()) # model winds model_path = '/ocean/sallen/allen/research/MEOPAR/Operational/' grid_T_hr = results_dataset('1h', 'grid_T', results_dir) bathy = nc.Dataset('/data/nsoontie/MEOPAR/NEMO-forcing/grid/bathy_meter_SalishSea2.nc') model_c = 'MediumBlue' observations_c = 'DarkGreen' predictions_c = 'MediumVioletRed' stations_c = cm.rainbow(np.linspace(0, 1, 7)) time_shift = datetime.timedelta(hours=-8) hfmt = mdates.DateFormatter('%m/%d %H:%M') MSL_DATUMS = { 'Point Atkinson': 3.10, 'Victoria': 1.90, 'Campbell River': 2.89, 'Patricia Bay': 2.30} reload(figures) fig = figures.plot_threshold_website(bathy, grid_T_hr, model_path, 0.1) import scipy.io as sio coastline = sio.loadmat('/ocean/rich/more/mmapbase/bcgeo/PNW.mat') fig = figures.website_thumbnail(bathy, grid_T_hr, model_path, coastline, 0.1)