diff --git a/notebooks/02_collision_protection_volume.ipynb b/notebooks/02_collision_protection_volume.ipynb new file mode 100644 index 0000000..617b435 --- /dev/null +++ b/notebooks/02_collision_protection_volume.ipynb @@ -0,0 +1,1051 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Investigate \"collision protection volume\" concept" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T00:37:28.874517Z", + "start_time": "2018-12-03T00:37:28.528594Z" + } + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "%reload_ext autoreload\n", + "%autoreload" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T00:37:30.229243Z", + "start_time": "2018-12-03T00:37:28.875519Z" + } + }, + "outputs": [], + "source": [ + "from IPython.core.debugger import set_trace\n", + "\n", + "import pandas as pd\n", + "import numpy as np\n", + "import os\n", + "\n", + "import plotly\n", + "import plotly.graph_objs as go\n", + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "import plotly.figure_factory as ff\n", + "import plotly.io as pio" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Load data\n", + "Load data from the `./data/interim/` folder and parse into `pandas` dataframes." + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T02:20:29.132099Z", + "start_time": "2018-12-03T02:20:22.217681Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Importing profiles.csv\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\z5189959\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\numpy\\lib\\arraysetops.py:472: FutureWarning:\n", + "\n", + "elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Importing profile_features.csv\n", + "Importing impacts_forecasted_foreshore_slope_sto06.csv\n", + "Importing impacts_forecasted_mean_slope_sto06.csv\n", + "Importing impacts_observed.csv\n", + "Importing twl_foreshore_slope_sto06.csv\n", + "Importing twl_mean_slope_sto06.csv\n", + "Done!\n" + ] + } + ], + "source": [ + "def df_from_csv(csv, index_col, data_folder='../data/interim'):\n", + " print('Importing {}'.format(csv))\n", + " return pd.read_csv(os.path.join(data_folder,csv), index_col=index_col)\n", + "\n", + "df_profiles = df_from_csv('profiles.csv', index_col=[0, 1, 2])\n", + "df_profile_features = df_from_csv('profile_features.csv', index_col=[0])\n", + "\n", + "impacts = {\n", + " 'forecasted': {\n", + " 'foreshore_slope_sto06': df_from_csv('impacts_forecasted_foreshore_slope_sto06.csv', index_col=[0]),\n", + " 'mean_slope_sto06': df_from_csv('impacts_forecasted_mean_slope_sto06.csv', index_col=[0]),\n", + " },\n", + " 'observed': df_from_csv('impacts_observed.csv', index_col=[0])\n", + " }\n", + "\n", + "twls = {\n", + " 'forecasted': {\n", + " 'foreshore_slope_sto06': df_from_csv('twl_foreshore_slope_sto06.csv', index_col=[0, 1]),\n", + " 'mean_slope_sto06':df_from_csv('twl_mean_slope_sto06.csv', index_col=[0, 1]),\n", + " }\n", + "}\n", + "\n", + "print('Done!')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Lets define a function to calculate the \"collision protection volume\" based on prestorm profiles." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T00:37:37.244970Z", + "start_time": "2018-12-03T00:37:36.924017Z" + }, + "code_folding": [] + }, + "outputs": [], + "source": [ + "from shapely.geometry import Point, LineString, Polygon\n", + "\n", + "def collision_protection_vol(x,z, d_low_x, d_low_z, lower_z, angle):\n", + " # First, get the bounding line strings of our protection volume\n", + " lower_line = LineString([Point(min(x), lower_z), Point(max(x), lower_z)])\n", + " profile_line = LineString([Point(x_coord, z_coord) for x_coord, z_coord in zip(x,z) \n", + " if all([not np.isnan(x_coord), not np.isnan(z_coord)])])\n", + " slope_line = LineString([Point(d_low_x, d_low_z), \n", + " Point(max(x), d_low_z - max(x) * np.sin(np.deg2rad(angle)))])\n", + "\n", + " # Work out where our lower line and slope line intersect\n", + " lower_profile_intersection = lower_line.intersection(profile_line)\n", + " d_protected_intersection = lower_line.intersection(slope_line)\n", + " \n", + " # Define the perimeter of the protection area\n", + " profile_protected = LineString([Point(x_coord, z_coord) for x_coord, z_coord \n", + " in zip(profile_line.xy[0],profile_line.xy[1]) \n", + " if d_low_x < x_coord < lower_profile_intersection.xy[0][0]] \n", + " + [lower_profile_intersection]\n", + " + [d_protected_intersection]\n", + " + [Point(d_low_x, d_low_z)])\n", + " \n", + " # Convert to polygon and return the area (m3/m)\n", + " protection_area_poly = Polygon(profile_protected)\n", + " protection_area_vol = protection_area_poly.area\n", + " return protection_area_vol\n", + "\n", + "site_id = 'NARRA0018'\n", + "profile_type = 'prestorm'\n", + "query = \"site_id == '{}' and profile_type == '{}'\".format(site_id, profile_type)\n", + "prestorm_profile = df_profiles.query(query)\n", + "profile_features = df_profile_features.query(query)\n", + "\n", + "x = prestorm_profile.index.get_level_values('x')\n", + "z = prestorm_profile.z\n", + "d_low_x = profile_features.dune_toe_x.tolist()[0]\n", + "d_low_z = profile_features.dune_toe_z.tolist()[0]\n", + "angle = 60 # degrees from the horizontal\n", + "lower_z = 0.5 # from mhw\n", + "\n", + "vol = collision_protection_vol(x,z, d_low_x, d_low_z, lower_z, angle)" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T01:24:18.270476Z", + "start_time": "2018-12-03T01:24:18.119986Z" + } + }, + "outputs": [], + "source": [ + "from datetime import timedelta\n", + "\n", + "def wl_time(t, wl, z_lower, z_upper):\n", + " \"\"\"\n", + " Returns the amount of time the water level is between two elevations.\n", + " \"\"\"\n", + " df_wl = pd.DataFrame.from_records([(t_val, R2_val) for t_val, R2_val in zip(t,R2)], columns=['datetime','wl'])\n", + " df_wl.set_index(pd.DatetimeIndex(df_wl['datetime']),inplace=True)\n", + " df_wl.drop(columns=['datetime'], inplace=True)\n", + " \n", + " # Assumes that each record is one hour... probably need to check this\n", + " hours = len(df_wl.query('{} < wl < {}'.format(z_lower, z_upper)))\n", + " return timedelta(hours=hours)\n", + "\n", + "def wave_power(t, wl, z_lower, z_upper, Hs0, Tp):\n", + " \"\"\"\n", + " Returns the cumulative wave power when the water level is between two elevations.\n", + " \"\"\"\n", + " df_wl = pd.DataFrame.from_records([(t_val, R2_val,Hs0_val,Tp_val) for t_val, R2_val,Hs0_val,Tp_val in zip(t,R2,Hs0,Tp)], columns=['datetime','wl', 'Hs0','Tp'])\n", + " df_wl.set_index(pd.DatetimeIndex(df_wl['datetime']),inplace=True)\n", + " df_wl.drop(columns=['datetime'], inplace=True)\n", + " \n", + " # Assumes that each record is one hour... probably need to check this\n", + " rho = 1025 # kg/m3\n", + " g = 9.8 # m/s2\n", + " df_wl_times = df_wl.query('{} < wl < {}'.format(z_lower, z_upper))\n", + " power = rho * g ** 2 / 64 / np.pi * df_wl_times.Hs0 ** 2 * df_wl_times.Tp\n", + " return power.sum()\n", + "\n", + "df_twl = twls['forecasted']['mean_slope_sto06']\n", + "df_twl_site = df_twl.query(\"site_id == '{}'\".format(site_id))\n", + "\n", + "R2 = df_twl_site.R2.tolist()\n", + "t = df_twl_site.index.get_level_values('datetime')\n", + "z_lower = 0.5\n", + "z_upper = d_low_z\n", + "\n", + "exposed_time = wl_time(t, R2, z_lower,z_upper)\n", + "\n", + "Hs0 = df_twl.Hs0.tolist()\n", + "Tp = df_twl.Tp.tolist()\n", + "wave_p = wave_power(t, R2, z_lower,z_upper,Hs0, Tp)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T01:24:24.215223Z", + "start_time": "2018-12-03T01:24:24.210209Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "8554715.596323118" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "wave_p" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T00:54:57.439956Z", + "start_time": "2018-12-03T00:54:57.425899Z" + } + }, + "outputs": [], + "source": [ + "def dune_toe_elevation_change(site_id, df_profile_features):\n", + " query = \"site_id == '{}'\".format(site_id)\n", + " profile_features = df_profile_features.query(query)\n", + " prestorm_dune_toe_z = profile_features.query(\"profile_type=='prestorm'\").dune_toe_z.tolist()[0]\n", + " poststorm_dune_toe_z = profile_features.query(\"profile_type=='poststorm'\").dune_toe_z.tolist()[0]\n", + " return prestorm_dune_toe_z - poststorm_dune_toe_z\n", + "\n", + "toe_ele_change = dune_toe_elevation_change(\"NARRA0018\", df_profile_features)" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T03:07:48.328428Z", + "start_time": "2018-12-03T03:06:54.182343Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 of 204\n", + "20 of 204\n", + "40 of 204\n", + "60 of 204\n", + "80 of 204\n", + "100 of 204\n", + "120 of 204\n", + "140 of 204\n", + "160 of 204\n", + "180 of 204\n", + "200 of 204\n" + ] + } + ], + "source": [ + "vols = []\n", + "exposed_times = []\n", + "toe_ele_changes = []\n", + "wave_powers = []\n", + "\n", + "# Get site ids where we observed collision\n", + "observed_site_ids = impacts['observed'].query(\"storm_regime=='collision'\").index.get_level_values('site_id').unique()\n", + "\n", + "# Get site ids where we forecast swash\n", + "forecasted_site_ids = impacts['forecasted']['mean_slope_sto06'].query(\"storm_regime=='swash'\").index.get_level_values('site_id').unique()\n", + "\n", + "site_ids = set(observed_site_ids).intersection(set(forecasted_site_ids))\n", + "\n", + "# Calculate for each site\n", + "\n", + "for n, site_id in enumerate(site_ids):\n", + " \n", + " if n%20 ==0:\n", + " print('{} of {}'.format(n, len(site_ids)))\n", + " \n", + " try:\n", + " query = \"site_id == '{}' and profile_type == '{}'\".format(site_id, 'prestorm')\n", + " prestorm_profile = df_profiles.query(query)\n", + " profile_features = df_profile_features.query(query)\n", + "\n", + " vol = collision_protection_vol(x = prestorm_profile.index.get_level_values('x'),\n", + " z = prestorm_profile.z,\n", + " d_low_x = profile_features.dune_toe_x.tolist()[0],\n", + " d_low_z = profile_features.dune_toe_z.tolist()[0],\n", + " lower_z = profile_features.dune_toe_z.tolist()[0] - 2, # from mhw\n", + " angle = 60, # degrees from the horizontal\n", + " )\n", + "\n", + " df_twl = twls['forecasted']['mean_slope_sto06']\n", + " df_twl_site = df_twl.query(\"site_id == '{}'\".format(site_id))\n", + "\n", + " exposed_time = wl_time(t = df_twl_site.index.get_level_values('datetime'),\n", + " wl = df_twl_site.R2.tolist(),\n", + " z_lower = profile_features.dune_toe_z.tolist()[0] -2,\n", + " z_upper = profile_features.dune_toe_z.tolist()[0],\n", + " )\n", + "\n", + " \n", + " power = wave_power(t = df_twl_site.index.get_level_values('datetime'),\n", + " wl = df_twl_site.R2.tolist(),\n", + " z_lower = profile_features.dune_toe_z.tolist()[0] -2,\n", + " z_upper = profile_features.dune_toe_z.tolist()[0],\n", + " Hs0=df_twl_site.Hs0.tolist(),\n", + " Tp=df_twl_site.Tp.tolist())\n", + " \n", + " toe_ele_change = dune_toe_elevation_change(site_id, df_profile_features)\n", + " except:\n", + " continue\n", + "\n", + " vols.append(vol)\n", + " exposed_times.append(exposed_time)\n", + " toe_ele_changes.append(toe_ele_change)\n", + " wave_powers.append(power)\n", + "# if n>100:\n", + "# break\n", + "\n", + " \n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T03:12:11.598150Z", + "start_time": "2018-12-03T03:12:11.590128Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[0.0,\n", + " 62.0,\n", + " 35.0,\n", + " 53.0,\n", + " 4.0,\n", + " 41.0,\n", + " 31.0,\n", + " 98.0,\n", + " 17.0,\n", + " 103.0,\n", + " 81.0,\n", + " 1.0,\n", + " 31.0,\n", + " 0.0,\n", + " 24.0,\n", + " 35.0,\n", + " 67.0,\n", + " 53.0,\n", + " 77.0,\n", + " 130.0,\n", + " 66.0,\n", + " 89.0,\n", + " 31.0,\n", + " 13.0,\n", + " 41.0,\n", + " 118.0,\n", + " 0.0,\n", + " 29.0,\n", + " 82.0,\n", + " 52.0,\n", + " 84.0,\n", + " 31.0,\n", + " 2.0,\n", + " 43.0,\n", + " 84.0,\n", + " 421.0,\n", + " 29.0,\n", + " 22.0,\n", + " 54.0,\n", + " 150.0,\n", + " 115.0,\n", + " 46.0,\n", + " 29.0,\n", + " 86.0,\n", + " 103.0,\n", + " 82.0,\n", + " 77.0,\n", + " 50.0,\n", + " 104.0,\n", + " 81.0,\n", + " 67.0,\n", + " 81.0,\n", + " 141.0,\n", + " 64.0,\n", + " 17.0,\n", + " 95.0,\n", + " 46.0,\n", + " 80.0,\n", + " 77.0,\n", + " 4.0,\n", + " 159.0,\n", + " 115.0,\n", + " 33.0,\n", + " 13.0,\n", + " 46.0,\n", + " 110.0,\n", + " 162.0,\n", + " 16.0,\n", + " 77.0,\n", + " 77.0,\n", + " 86.0,\n", + " 46.0,\n", + " 6.0,\n", + " 42.0,\n", + " 77.0,\n", + " 89.0,\n", + " 29.0,\n", + " 172.0,\n", + " 68.0,\n", + " 204.0,\n", + " 8.0,\n", + " 13.0,\n", + " 78.0,\n", + " 0.0,\n", + " 81.0,\n", + " 156.0,\n", + " 57.0,\n", + " 0.0,\n", + " 62.0,\n", + " 46.0,\n", + " 37.0,\n", + " 52.0,\n", + " 310.0,\n", + " 287.0,\n", + " 4.0,\n", + " 89.0,\n", + " 2.0,\n", + " 22.0,\n", + " 31.0,\n", + " 20.0,\n", + " 45.0,\n", + " 54.0,\n", + " 46.0,\n", + " 43.0,\n", + " 0.0,\n", + " 89.0,\n", + " 122.0,\n", + " 5.0,\n", + " 46.0,\n", + " 24.0,\n", + " 0.0,\n", + " 77.0,\n", + " 51.0,\n", + " 0.0,\n", + " 43.0,\n", + " 53.0,\n", + " 151.0,\n", + " 52.0,\n", + " 29.0,\n", + " 103.0,\n", + " 35.0,\n", + " 68.0,\n", + " 17.0,\n", + " 29.0,\n", + " 34.0,\n", + " 211.0,\n", + " 55.0,\n", + " 85.0,\n", + " 21.0,\n", + " 14.0,\n", + " 103.0,\n", + " 227.0,\n", + " 208.0,\n", + " 78.0,\n", + " 43.0,\n", + " 17.0,\n", + " 104.0,\n", + " 50.0,\n", + " 37.0,\n", + " 54.0,\n", + " 78.0,\n", + " 349.0,\n", + " 80.0,\n", + " 49.0,\n", + " 29.0,\n", + " 17.0,\n", + " 82.0,\n", + " 91.0,\n", + " 1.0,\n", + " 75.0,\n", + " 46.0,\n", + " 210.0,\n", + " 205.0,\n", + " 16.0,\n", + " 35.0,\n", + " 82.0,\n", + " 49.0,\n", + " 0.0,\n", + " 29.0,\n", + " 58.0,\n", + " 57.0,\n", + " 103.0,\n", + " 29.0,\n", + " 0.0,\n", + " 46.0,\n", + " 48.0,\n", + " 1.0,\n", + " 17.0,\n", + " 48.0,\n", + " 29.0,\n", + " 17.0,\n", + " 165.0,\n", + " 45.0,\n", + " 17.0,\n", + " 426.0,\n", + " 30.0]" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T03:31:19.534072Z", + "start_time": "2018-12-03T03:31:19.439822Z" + } + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "01b5e4786fd44414a38db9266df25a12", + "version_major": 2, + "version_minor": 0 + }, + "text/html": [ + "

Failed to display Jupyter Widget of type FigureWidget.

\n", + "

\n", + " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", + " that the widgets JavaScript is still loading. If this message persists, it\n", + " likely means that the widgets JavaScript library is either not installed or\n", + " not enabled. See the Jupyter\n", + " Widgets Documentation for setup instructions.\n", + "

\n", + "

\n", + " If you're reading this message in another frontend (for example, a static\n", + " rendering on GitHub or NBViewer),\n", + " it may mean that your frontend doesn't currently support widgets.\n", + "

\n" + ], + "text/plain": [ + "FigureWidget({\n", + " 'data': [{'marker': {'color': [0.6740000000000004, -0.262, 0.5449999999999999,\n", + " 0.35399999999999965, 0.3929999999999998,\n", + " 0.35399999999999965, 0.6699999999999999,\n", + " -0.22799999999999976, 1.0739999999999998,\n", + " -0.125, 0.35199999999999987, 0.5299999999999998,\n", + " 0.4109999999999996, -0.1120000000000001,\n", + " 0.9180000000000001, 0.621, -0.3579999999999992,\n", + " -0.20699999999999985, -0.48400000000000043,\n", + " 0.5430000000000001, -0.09600000000000053,\n", + " -0.41700000000000026, 0.4340000000000006,\n", + " 0.7559999999999998, 0.8720000000000003,\n", + " -0.5759999999999996, 0.5119999999999996,\n", + " 0.6440000000000001, 0.395, 0.09300000000000042,\n", + " 0.923, 0.4339999999999997, 0.5429999999999993,\n", + " -0.09699999999999998, -0.20899999999999963,\n", + " -0.8130000000000002, 0.706, 0.36399999999999944,\n", + " 0.34099999999999975, -0.08499999999999996,\n", + " 0.21799999999999953, 0.6240000000000006,\n", + " -0.16700000000000026, -0.278,\n", + " -0.5110000000000001, 0.726,\n", + " -0.35199999999999987, 0.13100000000000023,\n", + " -0.3440000000000003, 0.6760000000000002,\n", + " -0.5719999999999996, -0.4980000000000002,\n", + " -0.2020000000000004, 0.34199999999999964,\n", + " 0.41999999999999993, 0.5800000000000001,\n", + " 0.7200000000000002, 0.6230000000000002,\n", + " -0.49100000000000055, 0.11499999999999977,\n", + " -0.242, -0.6240000000000006, 0.9500000000000002,\n", + " 1.2479999999999998, 1.2889999999999997,\n", + " 0.021999999999999797, -0.3200000000000003,\n", + " 0.7829999999999999, -0.32899999999999974,\n", + " 0.3389999999999995, -0.01599999999999957,\n", + " 0.38399999999999945, -0.04599999999999982,\n", + " 0.4849999999999999, 0.02499999999999991,\n", + " -0.7749999999999999, 0.617,\n", + " -0.06500000000000039, 0.5589999999999997,\n", + " -0.1299999999999999, -0.0040000000000000036,\n", + " 1.298, 0.05500000000000016, 0.9689999999999999,\n", + " -0.28800000000000026, -0.09700000000000042,\n", + " -0.03100000000000014, 0.7960000000000003,\n", + " 0.33599999999999985, 0.28900000000000015, 0.798,\n", + " -0.05900000000000016, -0.0029999999999996696,\n", + " -0.15399999999999991, 0.31999999999999984,\n", + " -0.613, 0.2650000000000001, 0.258, 1.513,\n", + " 0.36199999999999966, 0.7849999999999997,\n", + " -0.28900000000000015, 1.0290000000000004,\n", + " 0.8260000000000005, -0.03799999999999981,\n", + " -0.21300000000000008, -0.492,\n", + " 1.6029999999999998, 0.5699999999999998,\n", + " 0.9300000000000002, 0.0389999999999997,\n", + " -0.3110000000000004, 1.0070000000000001,\n", + " 0.11500000000000021, 0.7269999999999999,\n", + " 0.30100000000000016, -0.5180000000000002,\n", + " 0.40600000000000014, 0.1389999999999998,\n", + " -0.08299999999999974, 1.174,\n", + " -0.29300000000000015, 0.036000000000000476,\n", + " 0.702, 0.49099999999999966, 0.27400000000000047,\n", + " 0.6890000000000005, 0.46199999999999974,\n", + " 0.7839999999999998, 0.2939999999999996,\n", + " 0.013000000000000345, -0.09400000000000075,\n", + " 0.022999999999999687, -0.6230000000000002,\n", + " 0.9040000000000004, 0.027000000000000135,\n", + " -0.1280000000000001, 0.25, 0.488,\n", + " -0.1200000000000001, 0.43599999999999994,\n", + " 0.04999999999999982, 0.11599999999999966,\n", + " 1.5290000000000001, 1.0189999999999997,\n", + " 0.5780000000000003, -0.4969999999999999,\n", + " -0.39800000000000013, 0.6430000000000002,\n", + " -0.04500000000000037, -0.40700000000000003,\n", + " 0.07000000000000028, -0.18599999999999994,\n", + " 1.4900000000000002, 0.2889999999999997,\n", + " -0.3719999999999999, 0.1519999999999997,\n", + " 0.10899999999999999, -0.3700000000000001,\n", + " 0.7320000000000002, -0.238,\n", + " -0.08900000000000041, 0.20699999999999985,\n", + " 0.9870000000000001, 1.9829999999999997,\n", + " 0.6460000000000004, 0.06100000000000039,\n", + " 0.06300000000000017, -0.03500000000000014,\n", + " 0.5730000000000004, 0.7640000000000002,\n", + " -0.7690000000000006, 0.5750000000000002,\n", + " 1.4529999999999998, 0.07500000000000018, 0.649],\n", + " 'colorscale': 'Viridis',\n", + " 'showscale': True,\n", + " 'size': 4},\n", + " 'mode': 'markers',\n", + " 'text': [0.6740000000000004
STOCS0025, -0.262
NINEMn0049,\n", + " 0.5449999999999999
NINEMn0043,\n", + " 0.35399999999999965
LHOUSEn0056,\n", + " 0.3929999999999998
CRESn0120,\n", + " 0.35399999999999965
BOOM0008,\n", + " 0.6699999999999999
NINEMn0028,\n", + " -0.22799999999999976
DIAMONDn0028,\n", + " 1.0739999999999998
NINEMs0019, -0.125
DUNBn0032,\n", + " 0.35199999999999987
DUNBn0048,\n", + " 0.5299999999999998
MANNING0076,\n", + " 0.4109999999999996
DIAMONDn0014,\n", + " -0.1120000000000001
NARRA0008,\n", + " 0.9180000000000001
NINEMn0036, 0.621
BILG0005,\n", + " -0.3579999999999992
CRESn0085,\n", + " -0.20699999999999985
SWRO0009,\n", + " -0.48400000000000043
NINEMs0027,\n", + " 0.5430000000000001
NINEMs0012,\n", + " -0.09600000000000053
ONEMILE0006,\n", + " -0.41700000000000026
CRESn0066,\n", + " 0.4340000000000006
NINEMn0018,\n", + " 0.7559999999999998
DUNBn0033,\n", + " 0.8720000000000003
NINEMs0036,\n", + " -0.5759999999999996
ENTRA0074,\n", + " 0.5119999999999996
NINEMn0037,\n", + " 0.6440000000000001
DUNBn0035, 0.395
CRESn0103,\n", + " 0.09300000000000042
NINEMs0038, 0.923
MONA0011,\n", + " 0.4339999999999997
STUART0041,\n", + " 0.5429999999999993
NAMB0070,\n", + " -0.09699999999999998
NINEMs0013,\n", + " -0.20899999999999963
NINEMs0047,\n", + " -0.8130000000000002
NINEMs0057, 0.706
NINEMn0053,\n", + " 0.36399999999999944
NINEMn0052,\n", + " 0.34099999999999975
ENTRA0067,\n", + " -0.08499999999999996
NINEMs0014,\n", + " 0.21799999999999953
STOCNn0047,\n", + " 0.6240000000000006
ENTRA0073,\n", + " -0.16700000000000026
NINEMs0001, -0.278
NINEMn0042,\n", + " -0.5110000000000001
ONEMILE0003, 0.726
GRANTSs0002,\n", + " -0.35199999999999987
NSHORE_n0021,\n", + " 0.13100000000000023
AVOCAn0008,\n", + " -0.3440000000000003
ENTRA0069,\n", + " 0.6760000000000002
NINEMs0032,\n", + " -0.5719999999999996
NINEMs0048,\n", + " -0.4980000000000002
CRESn0105,\n", + " -0.2020000000000004
NINEMs0031,\n", + " 0.34199999999999964
DUNBn0047,\n", + " 0.41999999999999993
STUART0050,\n", + " 0.5800000000000001
BLUEYS0004,\n", + " 0.7200000000000002
SWRO0006,\n", + " 0.6230000000000002
NINEMs0044,\n", + " -0.49100000000000055
NINEMs0020,\n", + " 0.11499999999999977
NINEMs0039, -0.242
SWRO0010,\n", + " -0.6240000000000006
NINEMn0047,\n", + " 0.9500000000000002
NAMB0068,\n", + " 1.2479999999999998
OLDBAR0025,\n", + " 1.2889999999999997
MANNING0094,\n", + " 0.021999999999999797
NINEMs0005,\n", + " -0.3200000000000003
ONEMILE0010,\n", + " 0.7829999999999999
GRANTSn0018,\n", + " -0.32899999999999974
NINEMs0028,\n", + " 0.3389999999999995
NSHORE_n0031,\n", + " -0.01599999999999957
WAMBE0012,\n", + " 0.38399999999999945
NARRA0024,\n", + " -0.04599999999999982
ONEMILE0002,\n", + " 0.4849999999999999
LHOUSE0006,\n", + " 0.02499999999999991
WAMBE0014,\n", + " -0.7749999999999999
DIAMONDn0013, 0.617
DIAMONDn0034,\n", + " -0.06500000000000039
ELIZA0005,\n", + " 0.5589999999999997
OLDBAR0023,\n", + " -0.1299999999999999
ENTRA0046,\n", + " -0.0040000000000000036
DIAMONDn0039, 1.298
NINEMs0040,\n", + " 0.05500000000000016
NINEMs0017,\n", + " 0.9689999999999999
NINEMn0051,\n", + " -0.28800000000000026
CATHIE0012,\n", + " -0.09700000000000042
NAMB0059,\n", + " -0.03100000000000014
CRESn0112,\n", + " 0.7960000000000003
STOCS0015,\n", + " 0.33599999999999985
LHOUSEn0028,\n", + " 0.28900000000000015
NINEMs0003, 0.798
STUART0045,\n", + " -0.05900000000000016
WAMBE0013,\n", + " -0.0029999999999996696
NINEMs0018,\n", + " -0.15399999999999991
BLUEYS0002,\n", + " 0.31999999999999984
NINEMs0011, -0.613
STUART0036,\n", + " 0.2650000000000001
ELIZA0003, 0.258
NARRA0020,\n", + " 1.513
NSHORE_n0028, 0.36199999999999966
ELIZA0007,\n", + " 0.7849999999999997
STOCNn0010,\n", + " -0.28900000000000015
STUART0058,\n", + " 1.0290000000000004
STOCNn0008,\n", + " 0.8260000000000005
STOCS0002,\n", + " -0.03799999999999981
NINEMs0026,\n", + " -0.21300000000000008
WAMBE0009, -0.492
MONA0009,\n", + " 1.6029999999999998
NARRA0022,\n", + " 0.5699999999999998
OLDBAR0021,\n", + " 0.9300000000000002
NSHORE_n0029,\n", + " 0.0389999999999997
ONEMILE0008,\n", + " -0.3110000000000004
LHOUSEn0042,\n", + " 1.0070000000000001
NARRA0021,\n", + " 0.11500000000000021
STOCS0029,\n", + " 0.7269999999999999
BLUEYS0001,\n", + " 0.30100000000000016
BOOM0009,\n", + " -0.5180000000000002
MANNING0042,\n", + " 0.40600000000000014
NINEMn0046,\n", + " 0.1389999999999998
LHOUSEn0069,\n", + " -0.08299999999999974
STOCNs0192, 1.174
ENTRA0065,\n", + " -0.29300000000000015
LHOUSEn0025,\n", + " 0.036000000000000476
NINEMs0007, 0.702
GRANTSn0013,\n", + " 0.49099999999999966
MANNING0095,\n", + " 0.27400000000000047
NINEMs0043,\n", + " 0.6890000000000005
ENTRA0070,\n", + " 0.46199999999999974
LHOUSEn0059,\n", + " 0.7839999999999998
LHOUSEn0057,\n", + " 0.2939999999999996
NINEMs0029,\n", + " 0.013000000000000345
LHOUSEn0030,\n", + " -0.09400000000000075
NINEMs0008,\n", + " 0.022999999999999687
MANNING0092,\n", + " -0.6230000000000002
MONA0012,\n", + " 0.9040000000000004
NSHORE_n0026,\n", + " 0.027000000000000135
DIAMONDn0030,\n", + " -0.1280000000000001
MANNING0091, 0.25
STUART0043,\n", + " 0.488
NSHORE_n0020, -0.1200000000000001
ELIZA0004,\n", + " 0.43599999999999994
SWRO0005,\n", + " 0.04999999999999982
HARR0050,\n", + " 0.11599999999999966
FOST0001,\n", + " 1.5290000000000001
STOCS0008,\n", + " 1.0189999999999997
NARRA0009,\n", + " 0.5780000000000003
STUART0037,\n", + " -0.4969999999999999
STUART0033,\n", + " -0.39800000000000013
STUART0046,\n", + " 0.6430000000000002
FOST0004,\n", + " -0.04500000000000037
SWRO0001,\n", + " -0.40700000000000003
NINEMn0054,\n", + " 0.07000000000000028
STOCNs0069,\n", + " -0.18599999999999994
STOCNn0004,\n", + " 1.4900000000000002
MANNING0084,\n", + " 0.2889999999999997
STUART0040,\n", + " -0.3719999999999999
NAMB0048,\n", + " 0.1519999999999997
BOOM0007,\n", + " 0.10899999999999999
NINEMn0034,\n", + " -0.3700000000000001
ONEMILE0001,\n", + " 0.7320000000000002
ENTRA0075, -0.238
STOCNn0011,\n", + " -0.08900000000000041
DIAMONDn0021,\n", + " 0.20699999999999985
LHOUSEn0060,\n", + " 0.9870000000000001
CRESn0064,\n", + " 1.9829999999999997
NARRA0007,\n", + " 0.6460000000000004
MANNING0073,\n", + " 0.06100000000000039
ONEMILE0005,\n", + " 0.06300000000000017
NINEMs0037,\n", + " -0.03500000000000014
LHOUSEn0061,\n", + " 0.5730000000000004
NINEMn0040,\n", + " 0.7640000000000002
AVOCAn0005,\n", + " -0.7690000000000006
STOCNn0041,\n", + " 0.5750000000000002
ELIZA0006,\n", + " 1.4529999999999998
ENTRA0072,\n", + " 0.07500000000000018
MANNING0082, 0.649
LHOUSEn0029],\n", + " 'type': 'scatter',\n", + " 'uid': 'bdcb15ca-50ce-42b2-8441-134aec09d1a6',\n", + " 'x': [0.0, 62.0, 35.0, 53.0, 4.0, 41.0, 31.0, 98.0, 17.0, 103.0,\n", + " 81.0, 1.0, 31.0, 0.0, 24.0, 35.0, 67.0, 53.0, 77.0, 130.0,\n", + " 66.0, 89.0, 31.0, 13.0, 41.0, 118.0, 0.0, 29.0, 82.0, 52.0,\n", + " 84.0, 31.0, 2.0, 43.0, 84.0, 421.0, 29.0, 22.0, 54.0, 150.0,\n", + " 115.0, 46.0, 29.0, 86.0, 103.0, 82.0, 77.0, 50.0, 104.0, 81.0,\n", + " 67.0, 81.0, 141.0, 64.0, 17.0, 95.0, 46.0, 80.0, 77.0, 4.0,\n", + " 159.0, 115.0, 33.0, 13.0, 46.0, 110.0, 162.0, 16.0, 77.0, 77.0,\n", + " 86.0, 46.0, 6.0, 42.0, 77.0, 89.0, 29.0, 172.0, 68.0, 204.0,\n", + " 8.0, 13.0, 78.0, 0.0, 81.0, 156.0, 57.0, 0.0, 62.0, 46.0, 37.0,\n", + " 52.0, 310.0, 287.0, 4.0, 89.0, 2.0, 22.0, 31.0, 20.0, 45.0,\n", + " 54.0, 46.0, 43.0, 0.0, 89.0, 122.0, 5.0, 46.0, 24.0, 0.0, 77.0,\n", + " 51.0, 0.0, 43.0, 53.0, 151.0, 52.0, 29.0, 103.0, 35.0, 68.0,\n", + " 17.0, 29.0, 34.0, 211.0, 55.0, 85.0, 21.0, 14.0, 103.0, 227.0,\n", + " 208.0, 78.0, 43.0, 17.0, 104.0, 50.0, 37.0, 54.0, 78.0, 349.0,\n", + " 80.0, 49.0, 29.0, 17.0, 82.0, 91.0, 1.0, 75.0, 46.0, 210.0,\n", + " 205.0, 16.0, 35.0, 82.0, 49.0, 0.0, 29.0, 58.0, 57.0, 103.0,\n", + " 29.0, 0.0, 46.0, 48.0, 1.0, 17.0, 48.0, 29.0, 17.0, 165.0,\n", + " 45.0, 17.0, 426.0, 30.0],\n", + " 'y': [15.057260981886461, 50.48600703337221, 52.22661963845738,\n", + " 49.87527193413516, 60.378091629296, 44.69467666268621,\n", + " 33.08824662372501, 69.24966143957133, 46.3983426493909,\n", + " 55.66269386408765, 50.5038685904488, 38.24722379458162,\n", + " 48.77392309821484, 34.42678889134076, 32.339772440128606,\n", + " 28.13518326624829, 54.01652317900755, 51.57523510716254,\n", + " 59.03553546603745, 52.45400614301138, 62.599820358965985,\n", + " 70.4542638944535, 24.852993645288876, 38.001197477131235,\n", + " 31.316631841848864, 64.57753852853112, 17.65164087230827,\n", + " 27.89358334754175, 61.85947610858759, 63.58558665629535,\n", + " 52.707965993289484, 54.59027355785616, 53.4369169941986,\n", + " 36.53074365372308, 60.662690901453374, 93.01545825805395,\n", + " 21.321395510574977, 47.03420447676251, 44.784472634287866,\n", + " 67.77932649819007, 77.67132854981324, 49.702151674694086,\n", + " 57.01843446390366, 57.55836238002917, 60.0758110522641,\n", + " 32.33715180121005, 57.2927341040066, 53.685587497734865,\n", + " 77.02236536546766, 46.43886428194846, 74.93504091748079,\n", + " 60.06724901876906, 77.03905086279573, 30.912726190943072,\n", + " 54.53170249189508, 53.70339057156003, 22.441638077872113,\n", + " 54.791537795661974, 62.13997820476877, 29.40727911432272,\n", + " 82.18692443832771, 61.97015902384305, 42.77787059874549,\n", + " 47.91815920377601, 52.11069344547651, 49.79396221773086,\n", + " 73.9414412498821, 37.876215036107936, 57.13461030091145,\n", + " 37.3514512031067, 59.923715953669195, 25.866493800185477,\n", + " 45.53280065268179, 27.02215306756141, 81.15248906718988,\n", + " 71.51536479781095, 45.97756678228884, 69.86050918469093,\n", + " 49.48043946500161, 57.899970620410635, 37.74710860574265,\n", + " 34.57820959659622, 55.62901703497036, 31.875858999358044,\n", + " 62.34650424255848, 73.60708709493487, 50.53187039062722,\n", + " 19.918164614381215, 41.9039188222106, 74.10573605782186,\n", + " 42.98820404001569, 70.89929008060581, 91.11150252345915,\n", + " 103.92435818263927, 25.781875086423824, 65.08855861060485,\n", + " 32.16685072172824, 26.3774436608266, 49.37115355443433,\n", + " 19.700396999896146, 45.0105834352614, 46.43117556836857,\n", + " 25.19648137654068, 58.46871157481417, 16.8505048443866,\n", + " 75.37390874203606, 68.1773833511795, 14.320950372734673,\n", + " 46.84538149567382, 51.48000161377281, 53.437015226686775,\n", + " 45.40805859249032, 40.76201971776089, 50.89636554048608,\n", + " 57.403293218019435, 54.46366012058966, 64.73300675848911,\n", + " 55.16180585094216, 41.57191993591717, 63.75449963841763,\n", + " 35.469027712428435, 56.59236212355033, 31.326546007774674,\n", + " 37.03650824212717, 31.520950268291358, 58.44841826927378,\n", + " 46.28021033720412, 54.90788208817708, 29.509983621209795,\n", + " 34.0063988459262, 64.86742099649922, 59.221944976590606,\n", + " 74.9874011223268, 55.207330372211956, 26.000385560413722,\n", + " 39.945013530743594, 37.27891136273222, 59.478825901465555,\n", + " 57.3560107484194, 57.08482809741879, 24.933290176259288,\n", + " 88.35412756202288, 42.25595601431678, 56.81861249472931,\n", + " 32.63000580753741, 36.79710517558988, 58.3621888814069,\n", + " 70.12310930216574, 34.01482594371291, 58.839577879424155,\n", + " 55.252330933788805, 78.22085308306589, 59.782634298874065,\n", + " 28.36317684006946, 43.8967970926609, 47.27816880026671,\n", + " 21.722947051488013, 19.58764895174499, 38.591489138007844,\n", + " 50.57685864743641, 63.74425935533099, 82.20046361640517,\n", + " 44.20822435998208, 26.438775903302503, 50.05321159752885,\n", + " 54.12827133882625, 24.70991457046442, 60.9358370882951,\n", + " 54.14071472699229, 27.848684395204568, 52.36273443570386,\n", + " 71.01829280596758, 46.862832006518445, 15.790885970513834,\n", + " 89.42388399872287, 53.47096959758166]}],\n", + " 'layout': {'title': 'Dune Collision Protection',\n", + " 'xaxis': {'autorange': True, 'showgrid': True, 'showline': True, 'title': 'Exposed time', 'zeroline': True},\n", + " 'yaxis': {'autorange': True,\n", + " 'showgrid': True,\n", + " 'showline': True,\n", + " 'title': 'Collision protection volume',\n", + " 'zeroline': True}}\n", + "})" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "trace1 = go.Scatter(\n", + " x=[x.total_seconds() / 60 / 60 for x in exposed_times],\n", + " y=vols,\n", + " text = ['{}
{}'.format(ele, site_id) for ele,site_id in zip(toe_ele_changes,site_ids)],\n", + " mode='markers',\n", + " marker=dict(\n", + " size=4,\n", + "# color = [-1 if x<0 else 1 for x in toe_ele_changes],\n", + " color = toe_ele_changes,\n", + "# color = wave_powers,\n", + "# color = [x.total_seconds() / 60 / 60 for x in exposed_times],\n", + " colorscale='Viridis',\n", + " showscale=True\n", + " ))\n", + "\n", + "layout = go.Layout(\n", + " title='Dune Collision Protection',\n", + "# height=300,\n", + "# legend=dict(font={'size': 10}),\n", + "# margin=dict(t=50, b=50, l=50, r=20),\n", + " xaxis=dict(\n", + " title='Exposed time',\n", + " autorange=True,\n", + " showgrid=True,\n", + " zeroline=True,\n", + " showline=True,\n", + " ),\n", + " yaxis=dict(\n", + " title='Collision protection volume',\n", + " autorange=True,\n", + " showgrid=True,\n", + " zeroline=True,\n", + " showline=True,\n", + " ))\n", + "\n", + "g_plot = go.FigureWidget(data=[trace1], layout=layout)\n", + "g_plot" + ] + } + ], + "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 + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/03_dune_to_vs_runup.ipynb b/notebooks/03_dune_to_vs_runup.ipynb new file mode 100644 index 0000000..9673fcb --- /dev/null +++ b/notebooks/03_dune_to_vs_runup.ipynb @@ -0,0 +1,554 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Investigate how dune toe compares to R_high" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T03:38:44.538853Z", + "start_time": "2018-12-03T03:38:44.189514Z" + } + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "%reload_ext autoreload\n", + "%autoreload" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T03:38:46.213387Z", + "start_time": "2018-12-03T03:38:44.781382Z" + } + }, + "outputs": [], + "source": [ + "from IPython.core.debugger import set_trace\n", + "\n", + "import pandas as pd\n", + "import numpy as np\n", + "import os\n", + "\n", + "import plotly\n", + "import plotly.graph_objs as go\n", + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "import plotly.figure_factory as ff\n", + "import plotly.io as pio" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Load data\n", + "Load data from the `./data/interim/` folder and parse into `pandas` dataframes." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T03:38:53.297184Z", + "start_time": "2018-12-03T03:38:46.365829Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Importing profiles.csv\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\z5189959\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\numpy\\lib\\arraysetops.py:472: FutureWarning:\n", + "\n", + "elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Importing profile_features.csv\n", + "Importing impacts_forecasted_foreshore_slope_sto06.csv\n", + "Importing impacts_forecasted_mean_slope_sto06.csv\n", + "Importing impacts_observed.csv\n", + "Importing twl_foreshore_slope_sto06.csv\n", + "Importing twl_mean_slope_sto06.csv\n", + "Done!\n" + ] + } + ], + "source": [ + "def df_from_csv(csv, index_col, data_folder='../data/interim'):\n", + " print('Importing {}'.format(csv))\n", + " return pd.read_csv(os.path.join(data_folder,csv), index_col=index_col)\n", + "\n", + "df_profiles = df_from_csv('profiles.csv', index_col=[0, 1, 2])\n", + "df_profile_features = df_from_csv('profile_features.csv', index_col=[0])\n", + "\n", + "impacts = {\n", + " 'forecasted': {\n", + " 'foreshore_slope_sto06': df_from_csv('impacts_forecasted_foreshore_slope_sto06.csv', index_col=[0]),\n", + " 'mean_slope_sto06': df_from_csv('impacts_forecasted_mean_slope_sto06.csv', index_col=[0]),\n", + " },\n", + " 'observed': df_from_csv('impacts_observed.csv', index_col=[0])\n", + " }\n", + "\n", + "twls = {\n", + " 'forecasted': {\n", + " 'foreshore_slope_sto06': df_from_csv('twl_foreshore_slope_sto06.csv', index_col=[0, 1]),\n", + " 'mean_slope_sto06':df_from_csv('twl_mean_slope_sto06.csv', index_col=[0, 1]),\n", + " }\n", + "}\n", + "\n", + "print('Done!')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Compare underpredicted cases" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T04:05:30.984007Z", + "start_time": "2018-12-03T04:05:30.805508Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
dune_toe_zR_highdiff
AVOCAn00053.3063.260440-0.045560
AVOCAn00083.5073.220084-0.286916
BILG00054.8073.293445-1.513555
BLUEYS00013.0642.800144-0.263856
BLUEYS00022.9292.470641-0.458359
\n", + "
" + ], + "text/plain": [ + " dune_toe_z R_high diff\n", + "AVOCAn0005 3.306 3.260440 -0.045560\n", + "AVOCAn0008 3.507 3.220084 -0.286916\n", + "BILG0005 4.807 3.293445 -1.513555\n", + "BLUEYS0001 3.064 2.800144 -0.263856\n", + "BLUEYS0002 2.929 2.470641 -0.458359" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Find site_ids where the forecast has been underpredicted\n", + "set1 = set(impacts['forecasted']['mean_slope_sto06'].query(\"storm_regime == 'swash'\").index.get_level_values('site_id'))\n", + "set2 = set(impacts['observed'].query(\"storm_regime == 'collision'\").index.get_level_values('site_id'))\n", + "site_ids = list(set1.intersection(set2))\n", + "\n", + "# Get dune toes at these sites and predicted max R_high\n", + "df_toes = df_profile_features.loc[site_ids].query('profile_type==\"prestorm\"').dune_toe_z\n", + "df_R_highs = twls['forecasted']['mean_slope_sto06'].loc[site_ids].groupby('site_id')['R_high'].max()\n", + "\n", + "# Join into one dataframe\n", + "df_twl_toes = pd.concat([df_toes, df_R_highs],axis=1,sort=True)\n", + "df_twl_toes['diff'] = df_twl_toes['R_high'] - df_twl_toes['dune_toe_z']\n", + "df_twl_toes.head()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now let's plot the comparison between our R_high TWL values and the dune toes to see how far off they were." + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T04:08:15.732169Z", + "start_time": "2018-12-03T04:08:15.656966Z" + } + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "35b9331242af473dba2f91761c307022", + "version_major": 2, + "version_minor": 0 + }, + "text/html": [ + "

Failed to display Jupyter Widget of type FigureWidget.

\n", + "

\n", + " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", + " that the widgets JavaScript is still loading. If this message persists, it\n", + " likely means that the widgets JavaScript library is either not installed or\n", + " not enabled. See the Jupyter\n", + " Widgets Documentation for setup instructions.\n", + "

\n", + "

\n", + " If you're reading this message in another frontend (for example, a static\n", + " rendering on GitHub or NBViewer),\n", + " it may mean that your frontend doesn't currently support widgets.\n", + "

\n" + ], + "text/plain": [ + "FigureWidget({\n", + " 'data': [{'type': 'histogram',\n", + " 'uid': '75f0d11f-9242-4fc7-b433-1f04e1e37ba6',\n", + " 'y': [-0.045560088746212646, -0.28691603912686325,\n", + " -1.5135547360075963, ..., -0.4613631587476821,\n", + " -0.5212332930925054, -0.3948507473332721]}],\n", + " 'layout': {'bargap': 0.2,\n", + " 'bargroupgap': 0.1,\n", + " 'title': 'D_low - R_high
Observed Collision, Forecasted Swash',\n", + " 'xaxis': {'title': 'Count'},\n", + " 'yaxis': {'title': 'z (m AHD)'}}\n", + "})" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "trace1 = go.Histogram(y=df_twl_toes['diff'].tolist())\n", + "\n", + "layout = go.Layout(\n", + " title='D_low - R_high
Observed Collision, Forecasted Swash',\n", + " yaxis=dict(\n", + " title='z (m AHD)'\n", + " ),\n", + " xaxis=dict(\n", + " title='Count'\n", + " ),\n", + " bargap=0.2,\n", + " bargroupgap=0.1\n", + ")\n", + "\n", + "g_plot = go.FigureWidget(data=[trace1], layout=layout)\n", + "g_plot" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The above plot shows that the R_high value for most of the incorrectly forecasted collision regimes, was typically underpredicted by less than 0.5 m." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Compare overpredicted cases" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T04:08:56.128806Z", + "start_time": "2018-12-03T04:08:55.894182Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
dune_toe_zR_highdiff
AVOCAn00043.1783.4169880.238988
BOOM00043.0653.0749800.009980
BOOM00112.7716.4918243.720824
BOOM00122.7963.1480870.352087
CATHIE00012.7803.5227920.742792
\n", + "
" + ], + "text/plain": [ + " dune_toe_z R_high diff\n", + "AVOCAn0004 3.178 3.416988 0.238988\n", + "BOOM0004 3.065 3.074980 0.009980\n", + "BOOM0011 2.771 6.491824 3.720824\n", + "BOOM0012 2.796 3.148087 0.352087\n", + "CATHIE0001 2.780 3.522792 0.742792" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Find site_ids where the forecast has been overpredicted\n", + "set1 = set(impacts['forecasted']['mean_slope_sto06'].query(\"storm_regime == 'collision'\").index.get_level_values('site_id'))\n", + "set2 = set(impacts['observed'].query(\"storm_regime == 'swash'\").index.get_level_values('site_id'))\n", + "site_ids = list(set1.intersection(set2))\n", + "\n", + "# Get dune toes at these sites and predicted max R_high\n", + "df_toes = df_profile_features.loc[site_ids].query('profile_type==\"prestorm\"').dune_toe_z\n", + "df_R_highs = twls['forecasted']['mean_slope_sto06'].loc[site_ids].groupby('site_id')['R_high'].max()\n", + "\n", + "# Join into one dataframe\n", + "df_twl_toes = pd.concat([df_toes, df_R_highs],axis=1,sort=True)\n", + "df_twl_toes['diff'] = df_twl_toes['R_high'] - df_twl_toes['dune_toe_z']\n", + "df_twl_toes.head()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": { + "ExecuteTime": { + "end_time": "2018-12-03T04:14:46.601092Z", + "start_time": "2018-12-03T04:14:46.522883Z" + } + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "3ea49a4ac07c4ea19bbb4532326ff94c", + "version_major": 2, + "version_minor": 0 + }, + "text/html": [ + "

Failed to display Jupyter Widget of type FigureWidget.

\n", + "

\n", + " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", + " that the widgets JavaScript is still loading. If this message persists, it\n", + " likely means that the widgets JavaScript library is either not installed or\n", + " not enabled. See the Jupyter\n", + " Widgets Documentation for setup instructions.\n", + "

\n", + "

\n", + " If you're reading this message in another frontend (for example, a static\n", + " rendering on GitHub or NBViewer),\n", + " it may mean that your frontend doesn't currently support widgets.\n", + "

\n" + ], + "text/plain": [ + "FigureWidget({\n", + " 'data': [{'type': 'histogram',\n", + " 'uid': '4a284474-2be1-4fd7-87d5-25364cc78df4',\n", + " 'y': [0.23898814460475037, 0.009980312001434566, 3.720823710344608,\n", + " ..., 1.5720238663972683, 0.912998680585452, 1.1419977620500927]}],\n", + " 'layout': {'bargap': 0.2,\n", + " 'bargroupgap': 0.1,\n", + " 'title': 'D_low - R_high
Observed Swash, Forecasted Collision',\n", + " 'xaxis': {'title': 'Count'},\n", + " 'yaxis': {'title': 'z (m AHD)'}}\n", + "})" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "trace1 = go.Histogram(y=df_twl_toes['diff'].tolist())\n", + "\n", + "layout = go.Layout(\n", + " title='D_low - R_high
Observed Swash, Forecasted Collision',\n", + " yaxis=dict(\n", + " title='z (m AHD)'\n", + " ),\n", + " xaxis=dict(\n", + " title='Count'\n", + " ),\n", + " bargap=0.2,\n", + " bargroupgap=0.1\n", + ")\n", + "\n", + "g_plot = go.FigureWidget(data=[trace1], layout=layout)\n", + "g_plot" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The errors when we forecast collision but observe swash are much greater than we we forecast swash and observe collision. For this case, errors in excess of 1.0 m common. Why is this?" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "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 + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}