You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

789 lines
54 KiB
Plaintext

6 years ago
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data exploration\n",
"This notebook provides an example how the data has been loaded and accessed for further analysis."
]
},
{
"cell_type": "code",
"execution_count": 6,
6 years ago
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-21T05:09:17.883914Z",
"start_time": "2018-11-21T05:09:16.981157Z"
6 years ago
}
},
"outputs": [],
"source": [
"# Enable autoreloading of our modules. \n",
"# Most of the code will be located in the /src/ folder, \n",
"# and then called from the notebook.\n",
"\n",
"%reload_ext autoreload\n",
"%autoreload"
]
},
{
"cell_type": "code",
"execution_count": 7,
6 years ago
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-21T05:09:17.891936Z",
"start_time": "2018-11-21T05:09:17.884916Z"
6 years ago
},
"scrolled": true
},
"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",
"\n",
"from ipywidgets import widgets, Output\n",
6 years ago
"from IPython.display import display, clear_output, Image"
]
},
{
"cell_type": "code",
"execution_count": 22,
6 years ago
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-21T05:26:30.254784Z",
"start_time": "2018-11-21T05:26:13.523566Z"
6 years ago
},
"pixiedust": {
"displayParams": {}
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\z5189959\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\numpy\\lib\\arraysetops.py:472: FutureWarning:\n",
6 years ago
"\n",
"elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison\n",
"\n"
]
}
],
"source": [
"def df_from_csv(csv, index_col, data_folder='../data/interim'):\n",
" return pd.read_csv(os.path.join(data_folder,csv), index_col=index_col)\n",
"\n",
"df_waves = df_from_csv('waves.csv', index_col=[0, 1])\n",
"df_tides = df_from_csv('tides.csv', index_col=[0, 1])\n",
"df_profiles = df_from_csv('profiles.csv', index_col=[0, 1, 2])\n",
"df_sites = df_from_csv('sites.csv', index_col=[0])\n",
"df_profile_features = df_from_csv('profile_features.csv', index_col=[0])\n",
"\n",
"# Note that the forecasted data sets should be in the same order for impacts and twls\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",
"\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",
"}"
6 years ago
]
},
{
"cell_type": "code",
"execution_count": null,
6 years ago
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-21T04:02:25.614132Z",
"start_time": "2018-11-21T04:02:25.609119Z"
}
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-21T06:07:17.024328Z",
"start_time": "2018-11-21T06:07:14.488829Z"
},
"code_folding": [],
"scrolled": false
6 years ago
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e4413b11f1694a8fb8da0c001aa18344",
6 years ago
"version_major": 2,
"version_minor": 0
},
"text/html": [
"<p>Failed to display Jupyter Widget of type <code>VBox</code>.</p>\n",
"<p>\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 <a href=\"https://ipywidgets.readthedocs.io/en/stable/user_install.html\">Jupyter\n",
" Widgets Documentation</a> for setup instructions.\n",
"</p>\n",
"<p>\n",
" If you're reading this message in another frontend (for example, a static\n",
" rendering on GitHub or <a href=\"https://nbviewer.jupyter.org/\">NBViewer</a>),\n",
" it may mean that your frontend doesn't currently support widgets.\n",
"</p>\n"
],
"text/plain": [
"VBox(children=(VBox(children=(HTML(value='<b>Filter by observed and predicted impacts:</b>'), HBox(children=(VBox(children=(HTML(value='Observed Impacts'), SelectMultiple(index=(0, 1), options=('swash', 'collision'), value=('swash', 'collision')))), VBox(children=(HTML(value='Forecasted: foreshore_slope_sto06'), SelectMultiple(index=(0, 1, 2), options=('collision', 'swash', 'overwash'), value=('collision', 'swash', 'overwash')))), VBox(children=(HTML(value='Forecasted: mean_slope_sto06'), SelectMultiple(index=(0, 1, 2), options=('collision', 'swash', 'overwash'), value=('collision', 'swash', 'overwash')))))))), VBox(children=(HTML(value='<b>Filter by site_id:</b>'), HBox(children=(Dropdown(description='site_id: ', index=942, options=('AVOCAn0001', 'AVOCAn0002', 'AVOCAn0003', 'AVOCAn0004', 'AVOCAn0005', 'AVOCAn0006', 'AVOCAn0007', 'AVOCAn0008', 'AVOCAn0009', 'AVOCAs0002', 'AVOCAs0003', 'AVOCAs0004', 'AVOCAs0005', 'AVOCAs0006', 'AVOCAs0007', 'AVOCAs0008', 'BILG0001', 'BILG0002', 'BILG0003', 'BILG0004', 'BILG0005', 'BLUEYS0001', 'BLUEYS0002', 'BLUEYS0003', 'BLUEYS0004', 'BLUEYS0005', 'BLUEYS0006', 'BOAT0001', 'BOAT0002', 'BOAT0003', 'BOAT0004', 'BOAT0005', 'BOOM0001', 'BOOM0002', 'BOOM0003', 'BOOM0004', 'BOOM0005', 'BOOM0006', 'BOOM0007', 'BOOM0008', 'BOOM0009', 'BOOM0010', 'BOOM0011', 'BOOM0012', 'BOOM0013', 'BOOM0014', 'CATHIE0001', 'CATHIE0002', 'CATHIE0003', 'CATHIE0004', 'CATHIE0005', 'CATHIE0006', 'CATHIE0007', 'CATHIE0008', 'CATHIE0009', 'CATHIE0010', 'CATHIE0011', 'CATHIE0012', 'CATHIE0013', 'CATHIE0014', 'CATHIE0015', 'CATHIE0016', 'CATHIE0017', 'CATHIE0018', 'CATHIE0019', 'CATHIE0020', 'CATHIE0021', 'CATHIE0022', 'CATHIE0023', 'CATHIE0024', 'CATHIE0025', 'CATHIE0026', 'CATHIE0027', 'CATHIE0028', 'CATHIE0029', 'CRESn0001', 'CRESn0002', 'CRESn0003', 'CRESn0004', 'CRESn0005', 'CRESn0006', 'CRESn0007', 'CRESn0008', 'CRESn0009', 'CRESn0010', 'CRESn0011', 'CRESn0012', 'CRESn0013', 'CRESn0014', 'CRESn0015', 'CRESn0016', 'CRESn0017', 'CRESn0018', 'CRESn0019', 'CRESn0020', 'CRESn0021', 'CRESn0022', 'CRESn0023', 'CRESn0024', 'CRESn0025', 'CRESn0026', 'CRESn0027', 'CRESn0028', 'CRESn0029', 'CRESn0030', 'CRESn0031', 'CRESn0032', 'CRESn0033', 'CRESn0034', 'CRESn0035', 'CRESn0036', 'CRESn0037', 'CRESn0038', 'CRESn0039', 'CRESn0040', 'CRESn0041', 'CRESn0042', 'CRESn0043', 'CRESn0044', 'CRESn0045', 'CRESn0046', 'CRESn0047', 'CRESn0048', 'CRESn0049', 'CRESn0050', 'CRESn0051', 'CRESn0052', 'CRESn0053', 'CRESn0054', 'CRESn0055', 'CRESn0056', 'CRESn0057', 'CRESn0058', 'CRESn0059', 'CRESn0060', 'CRESn0061', 'CRESn0062', 'CRESn0063', 'CRESn0064', 'CRESn0065', 'CRESn0066', 'CRESn0067', 'CRESn0068', 'CRESn0069', 'CRESn0070', 'CRESn0071', 'CRESn0072', 'CRESn0073', 'CRESn0074', 'CRESn0075', 'CRESn0076', 'CRESn0077', 'CRESn0078', 'CRESn0079', 'CRESn0080', 'CRESn0081', 'CRESn0082', 'CRESn0083', 'CRESn0084', 'CRESn0085', 'CRESn0086', 'CRESn0087', 'CRESn0088', 'CRESn0089', 'CRESn0090', 'CRESn0091', 'CRESn0092', 'CRESn0093', 'CRESn0094', 'CRESn0095', 'CRESn0096', 'CRESn0097', 'CRESn0098', 'CRESn0099', 'CRESn0100', 'CRESn0101', 'CRESn0102', 'CRESn0103', 'CRESn0104', 'CRESn0105', 'CRESn0106', 'CRESn0107', 'CRESn0108', 'CRESn0109', 'CRESn0110', 'CRESn0111', 'CRESn0112', 'CRESn0113', 'CRESn0114', 'CRESn0115', 'CRESn0116', 'CRESn0117', 'CRESn0118', 'CRESn0119', 'CRESn0120', 'CRESn0121', 'CRESn0122', 'CRESn0123', 'CRESn0124', 'CRESn0125', 'CRESs0001', 'CRESs0002', 'CRESs0003', 'CRESs0004', 'CRESs0005', 'CRESs0006', 'CRESs0007', 'CRESs0008', 'CRESs0009', 'CRESs0010', 'CRESs0011', 'CRESs0012', 'CRESs0013', 'CRESs0014', 'DEEWHYn0001', 'DEEWHYn0002', 'DEEWHYn0003', 'DEEWHYn0004', 'DEEWHYn0005', 'DEEWHYn0006', 'DEEWHYn0007', 'DEEWHYn0008', 'DEEWHYn0009', 'DEEWHYn0010', 'DEEWHYn0011', 'DEEWHYn0012', 'DEEWHYs0001', 'DEEWHYs0002', 'DEEWHYs0003', 'DEEWHYs0004', 'DEEWHYs0005', 'DEEWHYs0006', 'DEEWHYs0007', 'DEEWHYs0008', 'DIAMONDn0001', 'DIAMONDn0002', 'DIAMONDn0003', 'DIAMONDn0004', 'DIAMONDn0005', 'DIAMONDn0006', 'DIAMONDn0007', 'DIAMONDn0008', 'DIAMONDn0009', 'DIAMONDn0010', 'DIAMONDn0011', 'DIAMONDn0012', 'DIAMONDn0013', 'DIAMONDn0014', 'DIAMOND
6 years ago
" 'data': [{'name': 'Pre Storm Profile',\n",
" 'type': 'scatter',\n",
" 'uid': '391027af-be5a-4413-863d-53385a59391d',\n",
6 years ago
" 'x': [0],\n",
" 'y': [0]},\n",
" {'name': 'Post Storm Profile',\n",
" 'type': 'scatter',\n",
" 'uid': 'a5d7d2e9-d3af-462c-9466-51c2b6f09aa4',\n",
" 'x': [0],\n",
" 'y': [0]},\n",
" {'marker': {'color': 'rgb(17, 157, 255)', 'size': 20},\n",
" 'mode': 'markers',\n",
" 'name': 'Pre-storm dune crest',\n",
" 'type': 'scatter',\n",
" 'uid': '2eba8b17-45a7-4bcd-b988-31bbb487fb1f',\n",
" 'x': [0],\n",
" 'y': [0]},\n",
" {'marker': {'color': 'rgb(231, 99, 250)', 'size': 20},\n",
" 'mode': 'markers',\n",
" 'name': 'Pre-storm dune toe',\n",
" 'type': 'scatter',\n",
" 'uid': '022f5c93-fc10-4d1d-ac97-e30b8efd28d1',\n",
" 'x': [0],\n",
" 'y': [0]},\n",
" {'name': 'Peak R_high: foreshore_slope_sto06',\n",
" 'type': 'scatter',\n",
" 'uid': '0c93ba4e-2213-4db9-9b13-1227d17f5074',\n",
" 'x': [0],\n",
" 'y': [0]},\n",
" {'name': 'Peak R_high: mean_slope_sto06',\n",
" 'type': 'scatter',\n",
" 'uid': 'dceb5ce7-eb4c-4af6-9a79-cf0b2291e801',\n",
6 years ago
" 'x': [0],\n",
" 'y': [0]}],\n",
" 'layout': {'height': 300,\n",
" 'legend': {'font': {'size': 10}},\n",
" 'margin': {'b': 50, 'l': 50, 'r': 20, 't': 50},\n",
6 years ago
" 'title': 'Bed Profiles',\n",
" 'xaxis': {'autorange': True,\n",
" 'range': [0, 200],\n",
" 'showgrid': True,\n",
" 'showline': True,\n",
" 'title': 'x (m)',\n",
" 'zeroline': True},\n",
" 'yaxis': {'autorange': False,\n",
" 'range': [-1, 20],\n",
" 'showgrid': True,\n",
" 'showline': True,\n",
" 'title': 'z (m)',\n",
" 'zeroline': True}}\n",
"}), FigureWidget({\n",
" 'data': [{'lat': array([-33.46381539, -33.46301835, -33.46221051, ..., -33.4279646 ,\n",
" -33.42732743, -33.42671036]),\n",
" 'lon': array([151.43639576, 151.43690633, 151.43738179, ..., 151.4501613 ,\n",
" 151.45092222, 151.45170635]),\n",
" 'marker': {'size': 10},\n",
" 'mode': 'markers',\n",
" 'text': array(['AVOCAn0001', 'AVOCAn0002', 'AVOCAn0003', ..., 'WAMBE0025', 'WAMBE0026',\n",
" 'WAMBE0027'], dtype='<U12'),\n",
" 'type': 'scattermapbox',\n",
" 'uid': 'a3b0c913-a478-4496-a607-3da5b8e48bcf'},\n",
6 years ago
" {'lat': [0],\n",
" 'lon': [0],\n",
" 'marker': {'color': 'rgb(255, 0, 0)', 'opacity': 0.5, 'size': 20},\n",
" 'mode': 'markers',\n",
" 'text': array(['AVOCAn0001', 'AVOCAn0002', 'AVOCAn0003', ..., 'WAMBE0025', 'WAMBE0026',\n",
" 'WAMBE0027'], dtype='<U12'),\n",
" 'type': 'scattermapbox',\n",
" 'uid': '0af9db05-d087-4eea-94f5-973734e364b3'}],\n",
6 years ago
" 'layout': {'autosize': True,\n",
" 'height': 300,\n",
6 years ago
" 'hovermode': 'closest',\n",
" 'mapbox': {'accesstoken': ('pk.eyJ1IjoiY2hyaXNsZWFtYW4iLCJ' ... 'Hp5bCJ9.U2dwFg2c7RFjUNSayERUiw'),\n",
" 'bearing': 0,\n",
" 'center': {'lat': -33.7, 'lon': 151.3},\n",
" 'pitch': 0,\n",
" 'style': 'satellite-streets',\n",
" 'zoom': 12},\n",
" 'margin': {'b': 50, 'l': 20, 'r': 20, 't': 50},\n",
" 'showlegend': False}\n",
"}))), FigureWidget({\n",
" 'data': [{'line': {'color': 'rgb(214, 117, 14)', 'dash': 'dot', 'width': 2},\n",
" 'name': 'Dune Crest',\n",
" 'type': 'scatter',\n",
" 'uid': '8dbd0ac0-321f-42c9-b401-a2bcd5d66867',\n",
" 'x': [0, 3],\n",
" 'y': [0, 3]},\n",
" {'line': {'color': 'rgb(142, 77, 8)', 'dash': 'dash', 'width': 2},\n",
" 'name': 'Dune Toe',\n",
" 'type': 'scatter',\n",
" 'uid': '3938e7cf-2a0c-4c56-b258-459480b42c5c',\n",
" 'x': [0, 3],\n",
" 'y': [0, 3]},\n",
" {'line': {'color': 'rgb(8,51,137)', 'dash': 'dot', 'width': 2},\n",
" 'name': 'Tide+Surge WL',\n",
" 'type': 'scatter',\n",
" 'uid': '15bce5f1-f7b7-4555-b19f-1d9c70041e60',\n",
" 'x': [0, 4],\n",
" 'y': [0, 4]},\n",
" {'name': 'R_high: foreshore_slope_sto06',\n",
" 'type': 'scatter',\n",
" 'uid': 'fedcd3c9-f6b7-4e68-abc9-f65e6f4075fe',\n",
" 'x': [0],\n",
" 'y': [0]},\n",
" {'name': 'R_high: mean_slope_sto06',\n",
" 'type': 'scatter',\n",
" 'uid': '6f7e80b2-a994-4f1a-ade0-08ec5921e54d',\n",
" 'x': [0],\n",
" 'y': [0]}],\n",
" 'layout': {'height': 200,\n",
" 'margin': {'b': 50, 'l': 50, 'r': 50, 't': 50},\n",
" 'title': 'Water Level & Dune Toe/Crest',\n",
" 'xaxis': {'domain': [0.0, 0.95], 'title': 'time', 'zeroline': False},\n",
" 'yaxis': {'title': 'Water Level (m)'}}\n",
"}), FigureWidget({\n",
" 'data': [{'name': 'Hs0', 'type': 'scatter', 'uid': 'ba107c82-0112-4674-a471-c08d69d6f900', 'x': [0, 1], 'y': [0, 1]},\n",
" {'name': 'Tp',\n",
" 'type': 'scatter',\n",
" 'uid': '6e348dfe-5a22-49d6-912b-d6dacacdeb02',\n",
" 'x': [0, 2],\n",
" 'y': [0, 2],\n",
" 'yaxis': 'y2'},\n",
" {'name': 'Beta: foreshore_slope_sto06',\n",
" 'type': 'scatter',\n",
" 'uid': '39364e19-0edc-4243-976d-d7c8e3fbdfb7',\n",
" 'x': [0],\n",
" 'y': [0],\n",
" 'yaxis': 'y3'},\n",
" {'name': 'Beta: mean_slope_sto06',\n",
" 'type': 'scatter',\n",
" 'uid': '83696b2e-a5b6-4682-ab40-7c41ae8b7f73',\n",
" 'x': [0],\n",
" 'y': [0],\n",
" 'yaxis': 'y3'}],\n",
" 'layout': {'height': 200,\n",
" 'margin': {'b': 50, 'l': 50, 'r': 50, 't': 50},\n",
" 'title': 'Hydro/Morpho Parameters',\n",
" 'xaxis': {'domain': [0.0, 0.9], 'title': 'time', 'zeroline': False},\n",
" 'yaxis': {'title': 'Hs0 (m)'},\n",
" 'yaxis2': {'overlaying': 'y', 'side': 'right', 'title': 'Tp (s)'},\n",
" 'yaxis3': {'overlaying': 'y', 'position': 0.97, 'side': 'right', 'title': 'beta (-)'}}\n",
"})))"
6 years ago
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Create widgets for filtering by observed and forecasted impacts\n",
"filter_title = widgets.HTML(\n",
" value=\"<b>Filter by observed and predicted impacts:</b>\",\n",
")\n",
"\n",
"titles = ['Observed Impacts']\n",
"selectboxes = [widgets.SelectMultiple(\n",
" options=impacts['observed'].storm_regime.dropna().unique().tolist(),\n",
" value=impacts['observed'].storm_regime.dropna().unique().tolist(),\n",
" disabled=False)]\n",
"\n",
"# Iterate through each of our forecasted impacts \n",
"for forecast in impacts['forecasted']:\n",
" selectboxes.append(\n",
" widgets.SelectMultiple(\n",
" options=impacts['forecasted'][forecast].storm_regime.dropna().unique().tolist(),\n",
" value=impacts['forecasted'][forecast].storm_regime.dropna().unique().tolist(),\n",
" disabled=False))\n",
" titles.append('Forecasted: {}'.format(forecast))\n",
"\n",
"titles = [widgets.HTML(value=title) for title in titles]\n",
" \n",
"children = widgets.HBox(children=[widgets.VBox(children=[title, box]) for title, box in zip(titles, selectboxes)])\n",
"filter_container = widgets.VBox(children=[filter_title,children])\n",
"\n",
"\n",
"\n",
"# Create widgets for selecting site_id\n",
"site_id_title = widgets.HTML(\n",
" value=\"<b>Filter by site_id:</b>\",\n",
")\n",
"\n",
"site_id_select = widgets.Dropdown(\n",
6 years ago
" description='site_id: ',\n",
" value='NARRA0001',\n",
" options=df_profiles.index.get_level_values('site_id').unique().sort_values().tolist()\n",
")\n",
"site_id_container = widgets.VBox(children=[site_id_title,widgets.HBox(children=[site_id_select])])\n",
"\n",
6 years ago
"\n",
"\n",
"# Add panel for pre/post storm profiles\n",
"trace1 = go.Scatter(\n",
" x = [0],\n",
" y = [0],\n",
" name='Pre Storm Profile'\n",
")\n",
"trace2 = go.Scatter(\n",
" x = [0],\n",
" y = [0],\n",
" name='Post Storm Profile'\n",
")\n",
"trace3 = go.Scatter(\n",
" x = [0],\n",
" y = [0],\n",
" name='Pre-storm dune crest',\n",
" mode = 'markers',\n",
" marker = dict(\n",
" color = 'rgb(17, 157, 255)',\n",
" size = 20,\n",
" ),\n",
")\n",
"trace4 = go.Scatter(\n",
" x = [0],\n",
" y = [0],\n",
" name='Pre-storm dune toe',\n",
" mode = 'markers',\n",
" marker = dict(\n",
" color = 'rgb(231, 99, 250)',\n",
" size = 20,\n",
" ),\n",
")\n",
6 years ago
"\n",
"forecast_traces = []\n",
"for forecast in impacts['forecasted']:\n",
" forecast_traces.append(go.Scatter(\n",
" x = [0],\n",
" y = [0],\n",
" name = 'Peak R_high: {}'.format(forecast)\n",
" ))\n",
" \n",
6 years ago
"layout = go.Layout(\n",
" title = 'Bed Profiles',\n",
" height=300,\n",
" legend=dict(font={'size':10}),\n",
" margin=dict(t=50,b=50,l=50,r=20),\n",
6 years ago
" xaxis=dict(\n",
" title = 'x (m)',\n",
" autorange=True,\n",
" showgrid=True,\n",
" zeroline=True,\n",
" showline=True,\n",
" range=[0, 200]\n",
" ),\n",
" yaxis=dict(\n",
" title = 'z (m)',\n",
" autorange=False,\n",
" showgrid=True,\n",
" zeroline=True,\n",
" showline=True,\n",
" range=[-1, 20]\n",
" )\n",
")\n",
"\n",
"g_profiles = go.FigureWidget(data=[trace1, trace2, trace3, trace4]+forecast_traces,\n",
6 years ago
" layout=layout)\n",
"\n",
"\n",
"# Add panel for google maps\n",
"mapbox_access_token = 'pk.eyJ1IjoiY2hyaXNsZWFtYW4iLCJhIjoiY2pvNTY1MzZpMDc2OTN2bmw5MGsycHp5bCJ9.U2dwFg2c7RFjUNSayERUiw'\n",
"\n",
"data = [\n",
" go.Scattermapbox(\n",
" lat=df_sites['lat'],\n",
" lon=df_sites['lon'],\n",
" mode='markers',\n",
" marker=dict(\n",
" size=10\n",
" ),\n",
" text=df_sites.index.get_level_values('site_id'),\n",
" ),\n",
" go.Scattermapbox(\n",
" lat=[0],\n",
" lon=[0],\n",
" mode='markers',\n",
" marker=dict(\n",
" size=20,\n",
" color='rgb(255, 0, 0)',\n",
" opacity = 0.5,\n",
" ),\n",
" text=df_sites.index.get_level_values('site_id'),\n",
" ),\n",
"]\n",
"\n",
"layout = go.Layout(\n",
" autosize=True,\n",
" height=300,\n",
6 years ago
" hovermode='closest',\n",
" showlegend=False,\n",
" margin=dict(t=50,b=50,l=20,r=20),\n",
" mapbox=dict(\n",
" accesstoken=mapbox_access_token,\n",
" bearing=0,\n",
" center=dict(\n",
" lat=-33.7,\n",
" lon=151.3\n",
" ),\n",
" pitch=0,\n",
" zoom=12,\n",
" style='satellite-streets'\n",
" ),\n",
")\n",
"\n",
"fig = dict(data=data, layout=layout)\n",
"g_map = go.FigureWidget(data=data,layout=layout)\n",
"\n",
"\n",
"# Add panel for time series\n",
"\n",
"trace_Hs0 = go.Scatter(\n",
" x = [0,1],\n",
" y = [0,1],\n",
" name='Hs0'\n",
")\n",
"trace_Tp = go.Scatter(\n",
" x = [0,2],\n",
" y = [0,2],\n",
" name='Tp',\n",
" yaxis='y2'\n",
")\n",
"\n",
"forecast_traces = []\n",
"for forecast in impacts['forecasted']:\n",
" forecast_traces.append(go.Scatter(\n",
" x = [0],\n",
" y = [0],\n",
" name = 'Beta: {}'.format(forecast),\n",
" yaxis='y3'\n",
" ))\n",
"\n",
" \n",
"data=[trace_Hs0, trace_Tp] + forecast_traces\n",
"\n",
"layout = go.Layout(\n",
" title = 'Hydro/Morpho Parameters',\n",
" height=200,\n",
" margin=dict(t=50,b=50,l=50,r=50),\n",
" xaxis=dict(\n",
" title='time',\n",
" domain=[0.0, 0.9],\n",
" zeroline=False,\n",
" ),\n",
" yaxis=dict(\n",
" title = 'Hs0 (m)',\n",
" ),\n",
" yaxis2=dict(\n",
" title='Tp (s)',\n",
" overlaying='y',\n",
" side='right'\n",
" ),\n",
" yaxis3=dict(\n",
" title='beta (-)',\n",
" overlaying='y',\n",
" side='right',\n",
" position=0.97\n",
" )\n",
")\n",
"\n",
"g_params = go.FigureWidget(data=data, layout=layout)\n",
"\n",
"\n",
"# Add panel for water level\n",
"trace_dune_crest = go.Scatter(\n",
" x = [0,3],\n",
" y = [0,3],\n",
" name='Dune Crest',\n",
" line = dict(\n",
" color = ('rgb(214, 117, 14)'),\n",
" width = 2,\n",
" dash = 'dot')\n",
")\n",
"trace_dune_toe = go.Scatter(\n",
" x = [0,3],\n",
" y = [0,3],\n",
" name='Dune Toe',\n",
" line = dict(\n",
" color = ('rgb(142, 77, 8)'),\n",
" width = 2,\n",
" dash = 'dash')\n",
")\n",
"trace_tide = go.Scatter(\n",
" x = [0,4],\n",
" y = [0,4],\n",
" name='Tide+Surge WL',\n",
" line = dict(\n",
" color = ('rgb(8,51,137)'),\n",
" width = 2,\n",
" dash = 'dot')\n",
")\n",
"\n",
"forecast_traces = []\n",
"for forecast in twls['forecasted']:\n",
" forecast_traces.append(go.Scatter(\n",
" x = [0],\n",
" y = [0],\n",
" name = 'R_high: {}'.format(forecast),\n",
" ))\n",
" \n",
"data=[trace_dune_crest, trace_dune_toe,trace_tide] + forecast_traces\n",
"\n",
"layout = go.Layout(\n",
" title = 'Water Level & Dune Toe/Crest',\n",
" height=200,\n",
" margin=dict(t=50,b=50,l=50,r=50),\n",
" xaxis=dict(\n",
" title='time',\n",
" domain=[0.0, 0.95],\n",
" zeroline=False,\n",
" ),\n",
" yaxis=dict(\n",
" title = 'Water Level (m)',\n",
" ),\n",
")\n",
"\n",
"g_twls = go.FigureWidget(data=data, layout=layout)\n",
"\n",
6 years ago
"\n",
"\n",
"def update_profile(change):\n",
6 years ago
" \n",
" site_id = site_id_select.value\n",
" \n",
" if site_id is None:\n",
" return \n",
" \n",
6 years ago
" site_profile = df_profiles.query('site_id == \"{}\"'.format(site_id))\n",
" prestorm_profile = site_profile.query('profile_type == \"prestorm\"')\n",
" poststorm_profile = site_profile.query('profile_type == \"poststorm\"')\n",
"\n",
" poststorm_x = poststorm_profile.index.get_level_values('x').tolist()\n",
" poststorm_z = poststorm_profile.z.tolist()\n",
"\n",
" prestorm_x = prestorm_profile.index.get_level_values('x').tolist()\n",
" prestorm_z = prestorm_profile.z.tolist()\n",
" \n",
" site_features = df_profile_features.query('site_id == \"{}\"'.format(site_id))\n",
" dune_crest_x = site_features.dune_crest_x\n",
" dune_crest_z = site_features.dune_crest_z\n",
" dune_toe_x = site_features.dune_toe_x\n",
" dune_toe_z = site_features.dune_toe_z\n",
6 years ago
" \n",
" # Update beach profile section plots\n",
" with g_profiles.batch_update():\n",
" g_profiles.data[0].x = prestorm_x\n",
" g_profiles.data[0].y = prestorm_z\n",
" g_profiles.data[1].x = poststorm_x\n",
" g_profiles.data[1].y = poststorm_z\n",
" g_profiles.data[2].x = dune_crest_x\n",
" g_profiles.data[2].y = dune_crest_z\n",
" g_profiles.data[3].x = dune_toe_x\n",
" g_profiles.data[3].y = dune_toe_z\n",
" \n",
" for n, forecast in enumerate(impacts['forecasted']):\n",
" R_high = max(impacts['forecasted'][forecast].query(\"site_id=='{}'\".format(site_id)).R_high)\n",
" g_profiles.data[4+n].x=[200,400]\n",
" g_profiles.data[4+n].y=[R_high, R_high]\n",
" \n",
" # Relocate plan of satellite imagery\n",
6 years ago
" site_coords = df_sites.query('site_id == \"{}\"'.format(site_id))\n",
" with g_map.batch_update():\n",
" g_map.layout.mapbox['center'] = {\n",
6 years ago
" 'lat': site_coords['lat'].values[0],\n",
" 'lon': site_coords['lon'].values[0]\n",
" }\n",
" g_map.layout.mapbox['zoom'] = 15\n",
" g_map.data[1].lat = [site_coords['lat'].values[0]]\n",
" g_map.data[1].lon = [site_coords['lon'].values[0]]\n",
" g_map.data[1].text = site_coords['lon'].index.get_level_values('site_id').tolist()\n",
"\n",
" # Update time series plots \n",
" df_waves_site = df_waves.query(\"site_id=='{}'\".format(site_id))\n",
" times = df_waves_site.index.get_level_values('datetime').tolist()\n",
" Hs0s = df_waves_site.Hs0.tolist()\n",
" Tps = df_waves_site.Tp.tolist()\n",
" with g_params.batch_update():\n",
" g_params.data[0].x = times\n",
" g_params.data[0].y = Hs0s\n",
" g_params.data[1].x = times\n",
" g_params.data[1].y = Tps\n",
" \n",
" for n, forecast in enumerate(twls['forecasted']):\n",
" df_twl = twls['forecasted'][forecast].query(\"site_id=='{}'\".format(site_id))\n",
" times = df_twl.index.get_level_values('datetime').tolist()\n",
" beta = df_twl.beta.tolist()\n",
" g_params.data[2+n].x= times\n",
" g_params.data[2+n].y= beta\n",
"\n",
"\n",
" # Update water levels plot\n",
" df_tide_site = df_tides.query(\"site_id=='{}'\".format(site_id))\n",
" mask = (df_tide_site.index.get_level_values('datetime') >= min(times)) & (df_tide_site.index.get_level_values('datetime') <= max(times))\n",
" df_tide_site = df_tide_site.loc[mask]\n",
"\n",
" with g_twls.batch_update():\n",
" g_twls.data[0].x = [min(times), max(times)]\n",
" g_twls.data[1].x = [min(times), max(times)]\n",
" g_twls.data[2].x = df_tide_site.index.get_level_values('datetime')\n",
" g_twls.data[0].y = dune_crest_z.tolist()[0], dune_crest_z.tolist()[0],\n",
" g_twls.data[1].y = dune_toe_z.tolist()[0], dune_toe_z.tolist()[0],\n",
" g_twls.data[2].y = df_tide_site.tide.tolist()\n",
" \n",
" for n, forecast in enumerate(twls['forecasted']):\n",
" df_twl = twls['forecasted'][forecast].query(\"site_id=='{}'\".format(site_id))\n",
" times = df_twl.index.get_level_values('datetime').tolist()\n",
" R_high = df_twl.R_high.tolist()\n",
" g_twls.data[3+n].x= times\n",
" g_twls.data[3+n].y= R_high\n",
" \n",
6 years ago
" \n",
"site_id_select.observe(update_profile, names=\"value\")\n",
" \n",
" \n",
" \n",
"def update_filter(change):\n",
" \n",
" # Iterate through each box, only keeping site_ids which are not filtered out by each box\n",
" valid_site_ids = impacts['observed'].index.tolist()\n",
" dfs = [impacts['observed']] + [impacts['forecasted'][key] for key in impacts['forecasted']]\n",
" \n",
" for box, df in zip(selectboxes, dfs):\n",
" valid_site_ids = list(set(valid_site_ids).intersection(set(df[df.storm_regime.isin(box.value)].index.tolist())))\n",
" site_id_select.options = sorted(valid_site_ids)\n",
"\n",
" # TODO Update options in selectboxes with number of observations?\n",
" \n",
"# Update the filter if any of the boxes changes\n",
"for box in selectboxes:\n",
" box.observe(update_filter, names=\"value\")\n",
" \n",
"# Display our widgets!\n",
"widgets.VBox([filter_container,site_id_container,widgets.HBox([g_profiles,g_map]),g_twls,g_params])\n",
"\n",
6 years ago
"\n",
"\n",
"# For table\n",
"# out = Output()\n",
"# with out:\n",
"# display(df_waves.head(3))\n",
"\n",
"# widgets.VBox([filter_container,site_id_container, out])\n"
6 years ago
]
},
{
"cell_type": "code",
"execution_count": 55,
6 years ago
"metadata": {
"ExecuteTime": {
"end_time": "2018-11-21T06:04:27.672922Z",
"start_time": "2018-11-21T06:04:26.098269Z"
6 years ago
}
},
"outputs": [],
6 years ago
"source": [
"# print(max(impacts['forecasted']['foreshore_slope_sto06'].query(\"site_id=='{}'\".format('NARRA0018')).R_high))\n",
"# print(max(impacts['forecasted']['mean_slope_sto06'].query(\"site_id=='{}'\".format('NARRA0018')).R_high))\n",
"\n",
"# df_twl = twls['forecasted']['foreshore_slope_sto06'].query(\"site_id=='{}'\".format('NARRA0018'))\n",
"\n",
"df_waves_site = df_waves.query(\"site_id=='{}'\".format(\"NARRA0016\"))\n",
"times = df_waves_site.index.get_level_values('datetime').tolist()\n",
"\n",
"\n",
"df_tides_site = df_tides.query(\"{} <= datetime <= {}\".format(min(times), max(times)))\n",
"mask = (df_tides.index.get_level_values('datetime') >= min(times)) & (df_waves_site.index.get_level_values('datetime') <= max(times))"
6 years ago
]
}
],
"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": {
"height": "47px",
"width": "262px"
},
6 years ago
"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
}