{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import xarray as xr\n", "import hvplot.xarray\n", "import cartopy.crs as crs, geoviews as gv\n", "import holoviews as hv\n", "import glob\n", "\n", "gv.extension('bokeh', logo=False)\n", "hv.extension('bokeh', logo=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds = xr.open_dataset('out00000024.nc')\n", "ds.depth.values[ ds.depth.values < 0.01 ] = np.nan" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "outcrs = crs.epsg(6677)\n", "url = 'https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/{Z}/{X}/{Y}.jpg'\n", "geomap = gv.WMTS(url, crs=outcrs) #.options(width=600, height=400)\n", "\n", "out1 = ds.hvplot.quadmesh( 'xc','yc',z='depth'\n", " , crs=outcrs, rasterize=True, dynamic=True, cmap='jet'\n", " ,width=600, height=800,colorbar=True ).redim.range(depth=(0.2,1.5))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x0 = ds.xc.values[0,0]\n", "x1 = ds.xc.values[1,0]\n", "y0 = ds.yc.values[0,0]\n", "y1 = ds.yc.values[1,0]\n", "vc = [x1-x0, y1-y0]\n", "th = np.arccos( vc[0]/np.linalg.norm(vc) ) \n", "\n", "U = ds.u.values[::3,::3]\n", "V = ds.v.values[::3,::3]\n", "X = ds.xc.values[::3,::3]\n", "Y = ds.yc.values[::3,::3]\n", "\n", "mag = np.sqrt(U**2 + V**2) + 0.00000001 \n", "angle = (np.pi/2.) - np.arctan2(U/mag, V/mag) - th\n", "vectorfield = gv.VectorField((X, Y, angle, mag), crs=outcrs).options(magnitude='Magnitude', scale=0.5, color='white')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g = out1.opts(alpha=0.5) * vectorfield * geomap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hv.save(g,'out.html')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }