{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from __future__ import division, print_function\n", "\n", "import matplotlib.pyplot as plt\n", "import netCDF4 as nc\n", "import numpy as np\n", "\n", "from salishsea_tools import (\n", " nc_tools,\n", " viz_tools,\n", " tidetools,\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "grid = nc.Dataset('/data/dlatorne/MEOPAR/NEMO-forcing/grid/bathy_meter_SalishSea2.nc')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "bathy = grid.variables['Bathymetry'][:]\n", "lats = grid.variables['nav_lat'][:]\n", "lons = grid.variables['nav_lon'][:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Clover Point 48°24'09.8\"N 123°20'55.6\"W," ] }, { "cell_type": "code", "execution_count": 58, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "48.4027222222\n" ] } ], "source": [ "print (48+24/60.+09.8/60./60.)\n", "dep = 65" ] }, { "cell_type": "code", "execution_count": 59, "metadata": { "collapsed": true }, "outputs": [], "source": [ "yind, xind = tidetools.find_closest_model_point(-123.348778, 48.402722,lons,lats,bathy, lon_tol = 0.082, lat_tol = 0.003) \n", "level = tidetools.find_model_level(dep, zlevels, fractional=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "returns the y-index, yind (latitude) and x-index, xind (longitude) of the grid from specified lon/lat" ] }, { "cell_type": "code", "execution_count": 62, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "289 210 24\n", "70.0\n" ] } ], "source": [ "print (yind, xind, level)\n", "print(bathy[yind-1,xind])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "y-index and x-index " ] }, { "cell_type": "code", "execution_count": 63, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "48.3971595764 48.4011230469 48.3931999207\n", "-123.265525818 -123.260314941 -123.270736694\n" ] } ], "source": [ "yind = yind - 1\n", "# Look at cell and variation\n", "print (lats[yind,xind], lats[yind+1,xind], lats[yind-1,xind])\n", "print (lons[yind, xind], lons[yind, xind+1], lons[yind, xind-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###McCaulay 48°25'05.2\"N 123°24'22.5\"W 60m" ] }, { "cell_type": "code", "execution_count": 91, "metadata": { "collapsed": true }, "outputs": [], "source": [ "lon = -(123+24/60.+22.5/60./60.)\n", "lat = 48+25/60.+05.2/60./60.\n", "dep = 60." ] }, { "cell_type": "code", "execution_count": 92, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "302 192 24\n", "56.0\n" ] } ], "source": [ "yind, xind = tidetools.find_closest_model_point(lon, lat, lons,lats,bathy) \n", "level = tidetools.find_model_level(60, zlevels, fractional=False)\n", "print (yind, xind, level)\n", "print (bathy[yind-3,xind-2])" ] }, { "cell_type": "code", "execution_count": 93, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "48.4022827148 48.4062423706 48.3983192444\n", "-123.406349182 -123.401138306 -123.411552429\n" ] } ], "source": [ "yind = yind - 3; xind = xind-2\n", "# Look at cell and variation\n", "print (lats[yind,xind], lats[yind+1,xind], lats[yind-1,xind])\n", "print (lons[yind, xind], lons[yind, xind+1], lons[yind, xind-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Iona 49°12'20.6\"N 123°15'42.8\"W, 7.5 km offshore; depth of 90 m" ] }, { "cell_type": "code", "execution_count": 89, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "444 311 26\n", "103.0\n" ] } ], "source": [ "lon = -(123+15/60.+42.8/60./60.)\n", "lat = 49+12/60.+20.6/60./60.\n", "dep = 90.\n", "yind, xind = tidetools.find_closest_model_point(lon, lat, lons,lats,bathy) \n", "level = tidetools.find_model_level(dep, zlevels, fractional=False)\n", "print (yind, xind, level)\n", "print (bathy[yind,xind-9])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Need to move 3 m up in depth and 9 grid points out from coast to get out of the topography" ] }, { "cell_type": "code", "execution_count": 90, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "49.1873512268 49.1912727356 49.1834335327\n", "-123.308982849 -123.303787231 -123.314178467\n" ] } ], "source": [ "xind = xind-9\n", "# Look at cell and variation\n", "print (lats[yind,xind], lats[yind+1,xind], lats[yind-1,xind])\n", "print (lons[yind, xind], lons[yind, xind+1], lons[yind, xind-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Nanaimo 49°13'50.0\"N 123°58'04.5\"W, 2.5 km offshore; 70m below sea level" ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "500 211 25\n", "83.8125\n" ] } ], "source": [ "lon = -(123+58/60.+04.5/60./60.)\n", "lat = 49+13/60.+50.0/60./60.\n", "dep = 70.\n", "yind, xind = tidetools.find_closest_model_point(lon, lat, lons,lats,bathy) \n", "level = tidetools.find_model_level(dep, zlevels, fractional=False)\n", "print (yind, xind, level)\n", "print (bathy[yind,xind+2])" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "49.2388648987 49.2427902222 49.2349433899\n", "-123.958374023 -123.953186035 -123.963562012\n" ] } ], "source": [ "xind = xind+2\n", "# Look at cell and variation\n", "print (lats[yind,xind], lats[yind+1,xind], lats[yind-1,xind])\n", "print (lons[yind, xind], lons[yind, xind+1], lons[yind, xind-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Campbell River 50°03'25.6\"N 125°15'48.3\"W, 540m offshore; minimum depth 35m" ] }, { "cell_type": "code", "execution_count": 51, "metadata": { "collapsed": true }, "outputs": [], "source": [ "yind, xind = tidetools.find_closest_model_point(-125.263417, 50.057111, lons,lats,bathy) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "returns the y-index, yind (latitude) and x-index, xind (longitude) of the grid from specified lon/lat" ] }, { "cell_type": "code", "execution_count": 54, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "751 124\n", "42.0\n" ] } ], "source": [ "print (yind, xind)\n", "print (bathy[yind,xind+1])" ] }, { "cell_type": "code", "execution_count": 55, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "22" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tidetools.find_model_level(35, zlevels, fractional=False)" ] }, { "cell_type": "code", "execution_count": 56, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "50.055103302 50.059009552 50.051197052\n", "-125.250205994 -125.244987488 -125.2554245\n" ] } ], "source": [ "xind=xind+1\n", "# Look at cell and variation\n", "print (lats[yind,xind], lats[yind+1,xind], lats[yind-1,xind])\n", "print (lons[yind, xind], lons[yind, xind+1], lons[yind, xind-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Index of the model closest to the specified depth" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [], "source": [ "v_vel = nc.Dataset('/ocean/dlatorne/MEOPAR/SalishSea/results/spin-up/17dec26dec/SalishSea_1d_20031217_20031226_grid_V.nc')\n", "zlevels = v_vel.variables['depthv'][:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }