Update notebooks
parent
1bad6f6dd7
commit
5850871c14
@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
*.ipynb filter=nbstripout
|
*.ipynb filter=nbstripout
|
||||||
|
|
||||||
*.ipynb diff=ipynb
|
*.ipynb diff=ipynb
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,242 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Profile picker"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"heading_collapsed": true
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Setup notebook"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"hidden": true
|
||||||
|
},
|
||||||
|
"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",
|
||||||
|
"%matplotlib inline\n",
|
||||||
|
"%reload_ext autoreload\n",
|
||||||
|
"%autoreload"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"hidden": 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",
|
||||||
|
"import decimal\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",
|
||||||
|
"from plotly import tools\n",
|
||||||
|
"import plotly.io as pio\n",
|
||||||
|
"from scipy import stats\n",
|
||||||
|
"import math\n",
|
||||||
|
"import matplotlib\n",
|
||||||
|
"from matplotlib import cm\n",
|
||||||
|
"import colorlover as cl\n",
|
||||||
|
"import numpy.ma as ma\n",
|
||||||
|
"\n",
|
||||||
|
"from ipywidgets import widgets, Output\n",
|
||||||
|
"from IPython.display import display, clear_output, Image, HTML\n",
|
||||||
|
"\n",
|
||||||
|
"from sklearn.metrics import confusion_matrix\n",
|
||||||
|
"\n",
|
||||||
|
"import numpy as np\n",
|
||||||
|
"from matplotlib import pyplot as plt\n",
|
||||||
|
"\n",
|
||||||
|
"from sklearn import linear_model, datasets\n",
|
||||||
|
"\n",
|
||||||
|
"from scipy.interpolate import UnivariateSpline\n",
|
||||||
|
"from scipy.interpolate import interp1d\n",
|
||||||
|
"from scipy.interpolate import splrep, splev\n",
|
||||||
|
"from scipy.integrate import simps\n",
|
||||||
|
"from scipy.stats import linregress\n",
|
||||||
|
"from scipy.signal import find_peaks\n",
|
||||||
|
"import json"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"hidden": true
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Matplot lib default settings\n",
|
||||||
|
"plt.rcParams[\"figure.figsize\"] = (10,6)\n",
|
||||||
|
"plt.rcParams['axes.grid']=True\n",
|
||||||
|
"plt.rcParams['grid.alpha'] = 0.5\n",
|
||||||
|
"plt.rcParams['grid.color'] = \"grey\"\n",
|
||||||
|
"plt.rcParams['grid.linestyle'] = \"--\"\n",
|
||||||
|
"plt.rcParams['axes.grid']=True\n",
|
||||||
|
"\n",
|
||||||
|
"# https://stackoverflow.com/a/20709149\n",
|
||||||
|
"matplotlib.rcParams['text.usetex'] = True\n",
|
||||||
|
"\n",
|
||||||
|
"matplotlib.rcParams['text.latex.preamble'] = [\n",
|
||||||
|
" r'\\usepackage{siunitx}', # i need upright \\micro symbols, but you need...\n",
|
||||||
|
" r'\\sisetup{detect-all}', # ...this to force siunitx to actually use your fonts\n",
|
||||||
|
" r'\\usepackage{helvet}', # set the normal font here\n",
|
||||||
|
" r'\\usepackage{amsmath}',\n",
|
||||||
|
" r'\\usepackage{sansmath}', # load up the sansmath so that math -> helvet\n",
|
||||||
|
" r'\\sansmath', # <- tricky! -- gotta actually tell tex to use!\n",
|
||||||
|
"] "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Import data\n",
|
||||||
|
"Let's first import data from our pre-processed interim data folder."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"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_crest_toes = df_from_csv('profile_features_crest_toes.csv', index_col=[0,1])\n",
|
||||||
|
"\n",
|
||||||
|
"print('Done!')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Manually pick features"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"%matplotlib notebook\n",
|
||||||
|
"\n",
|
||||||
|
"sites = df_profiles.index.get_level_values('site_id').unique()\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"fig =plt.figure(figsize=(10, 3))\n",
|
||||||
|
"\n",
|
||||||
|
"df_prestorm = df_profiles.xs((sites[0],'prestorm'),level=('site_id','profile_type'))\n",
|
||||||
|
"df_poststorm = df_profiles.xs((sites[0],'poststorm'),level=('site_id','profile_type'))\n",
|
||||||
|
"line_prestorm, = plt.plot(df_prestorm.index, df_prestorm.z, label='prestorm')\n",
|
||||||
|
"line_poststorm, = plt.plot(df_prestorm.index, df_prestorm.z, label='poststorm')\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# df_profiles.xs((sites[0],'prestorm'),level=('site_id','profile_type'))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"hide_input": false,
|
||||||
|
"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.6"
|
||||||
|
},
|
||||||
|
"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
|
||||||
|
}
|
@ -0,0 +1,348 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Longshore plots of each beach\n",
|
||||||
|
"- Need to create a longshore plot of each beach to see how the variables change alongshore."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Setup notebook"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"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",
|
||||||
|
"%matplotlib inline\n",
|
||||||
|
"%reload_ext autoreload\n",
|
||||||
|
"%autoreload"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from IPython.core.debugger import set_trace\n",
|
||||||
|
"\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"import numpy as np\n",
|
||||||
|
"import os\n",
|
||||||
|
"import decimal\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",
|
||||||
|
"from plotly import tools\n",
|
||||||
|
"import plotly.io as pio\n",
|
||||||
|
"from scipy import stats\n",
|
||||||
|
"import math\n",
|
||||||
|
"import matplotlib\n",
|
||||||
|
"from matplotlib import cm\n",
|
||||||
|
"import colorlover as cl\n",
|
||||||
|
"from tqdm import tqdm_notebook\n",
|
||||||
|
"from ipywidgets import widgets, Output\n",
|
||||||
|
"from IPython.display import display, clear_output, Image, HTML\n",
|
||||||
|
"from scipy import stats\n",
|
||||||
|
"from sklearn.metrics import confusion_matrix\n",
|
||||||
|
"import matplotlib.pyplot as plt\n",
|
||||||
|
"from scipy.interpolate import interp1d\n",
|
||||||
|
"from pandas.api.types import CategoricalDtype"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Matplot lib default settings\n",
|
||||||
|
"plt.rcParams[\"figure.figsize\"] = (10,6)\n",
|
||||||
|
"plt.rcParams['axes.grid']=True\n",
|
||||||
|
"plt.rcParams['grid.alpha'] = 0.5\n",
|
||||||
|
"plt.rcParams['grid.color'] = \"grey\"\n",
|
||||||
|
"plt.rcParams['grid.linestyle'] = \"--\"\n",
|
||||||
|
"plt.rcParams['axes.grid']=True\n",
|
||||||
|
"\n",
|
||||||
|
"# https://stackoverflow.com/a/20709149\n",
|
||||||
|
"matplotlib.rcParams['text.usetex'] = True\n",
|
||||||
|
"\n",
|
||||||
|
"matplotlib.rcParams['text.latex.preamble'] = [\n",
|
||||||
|
" r'\\usepackage{siunitx}', # i need upright \\micro symbols, but you need...\n",
|
||||||
|
" r'\\sisetup{detect-all}', # ...this to force siunitx to actually use your fonts\n",
|
||||||
|
" r'\\usepackage{helvet}', # set the normal font here\n",
|
||||||
|
" r'\\usepackage{amsmath}',\n",
|
||||||
|
" r'\\usepackage{sansmath}', # load up the sansmath so that math -> helvet\n",
|
||||||
|
" r'\\sansmath', # <- tricky! -- gotta actually tell tex to use!\n",
|
||||||
|
"] "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Import data"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"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_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_crest_toes = df_from_csv('profile_features_crest_toes.csv', index_col=[0,1])\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",
|
||||||
|
"}\n",
|
||||||
|
"print('Done!')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Generate plot for each beach"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"beach = 'NARRA'\n",
|
||||||
|
"\n",
|
||||||
|
"# Get the dataframe\n",
|
||||||
|
"df = impacts['forecasted']['mean_slope_sto06']\n",
|
||||||
|
"df = df.rename(columns={'storm_regime': 'forecasted_regime'})\n",
|
||||||
|
"\n",
|
||||||
|
"df_beach = df.loc[df.index.str.contains(beach)]\n",
|
||||||
|
"\n",
|
||||||
|
"# Add information about hydrodynamics at max(R_high) time\n",
|
||||||
|
"df_beach = df_beach.merge(\n",
|
||||||
|
" twls['forecasted']['mean_slope_sto06'].drop(columns=['R_high', 'R_low']),\n",
|
||||||
|
" left_on=['site_id', 'datetime'],\n",
|
||||||
|
" right_on=['site_id', 'datetime'])\n",
|
||||||
|
"\n",
|
||||||
|
"# Add information about observed impacts\n",
|
||||||
|
"obs_impacts = impacts['observed'].rename(columns={\n",
|
||||||
|
" 'storm_regime': 'observed_regime'\n",
|
||||||
|
"}).observed_regime.to_frame()\n",
|
||||||
|
"df_beach = df_beach.merge(obs_impacts, left_on='site_id', right_on='site_id')\n",
|
||||||
|
"\n",
|
||||||
|
"# Convert storm regimes to categorical datatype\n",
|
||||||
|
"cat_type = CategoricalDtype(\n",
|
||||||
|
" categories=['swash', 'collision', 'overwash', 'inundation'], ordered=True)\n",
|
||||||
|
"df_beach.forecasted_regime = df_beach.forecasted_regime.astype(cat_type)\n",
|
||||||
|
"df_beach.observed_regime = df_beach.observed_regime.astype(cat_type)\n",
|
||||||
|
"\n",
|
||||||
|
"# Get index\n",
|
||||||
|
"n = [x for x in range(len(df_beach))][::-1]\n",
|
||||||
|
"n_sites = [x for x in df_beach.index][::-1]\n",
|
||||||
|
"\n",
|
||||||
|
"f, (ax1, ax2, ax3, ax4, ax5, ax6, ax7, ax8) = plt.subplots(\n",
|
||||||
|
" 1,\n",
|
||||||
|
" 8,\n",
|
||||||
|
" sharey=True,\n",
|
||||||
|
" figsize=(14, 8),\n",
|
||||||
|
" gridspec_kw={'width_ratios': [4, 4, 2, 2, 2, 2,2,2]})\n",
|
||||||
|
"\n",
|
||||||
|
"# Specify colors for storm regimes\n",
|
||||||
|
"cmap = {\n",
|
||||||
|
" 'swash': '#1a9850',\n",
|
||||||
|
" 'collision': '#fee08b',\n",
|
||||||
|
" 'overwash': '#d73027'\n",
|
||||||
|
"}\n",
|
||||||
|
"\n",
|
||||||
|
"colors = [cmap.get(x) for x in df_beach.observed_regime]\n",
|
||||||
|
"colors = ['#d73027' if c is None else c for c in colors]\n",
|
||||||
|
"\n",
|
||||||
|
"# Plot forecasted and observed storm regime\n",
|
||||||
|
"ax1.scatter(\n",
|
||||||
|
" df_beach.observed_regime.cat.codes.replace(-1,np.NaN),\n",
|
||||||
|
" n,\n",
|
||||||
|
" color=colors,\n",
|
||||||
|
" marker='o',\n",
|
||||||
|
" label='Observed regime')\n",
|
||||||
|
"\n",
|
||||||
|
"ax1.scatter(\n",
|
||||||
|
" df_beach.forecasted_regime.cat.codes.replace(-1,np.NaN),\n",
|
||||||
|
" n,\n",
|
||||||
|
" color='b',\n",
|
||||||
|
" marker='o',\n",
|
||||||
|
" edgecolors='black',\n",
|
||||||
|
" facecolors='none',\n",
|
||||||
|
" label='Forecasted regime')\n",
|
||||||
|
"\n",
|
||||||
|
"ax1.set_title('Storm\\nregime')\n",
|
||||||
|
"ax1.set_xticks([0,1,2,3])\n",
|
||||||
|
"ax1.set_xticklabels(['swash','collision','overwash','inundation'])\n",
|
||||||
|
"ax1.tick_params(axis='x', rotation=45)\n",
|
||||||
|
"ax1.legend(loc='center', bbox_to_anchor=(0.5, -0.15))\n",
|
||||||
|
"\n",
|
||||||
|
"# Replace yticks with site_ids\n",
|
||||||
|
"yticks = ax1.get_yticks().tolist()\n",
|
||||||
|
"yticks = [n_sites[int(y)] if 0 <= y <= len(n_sites) else y for y in yticks ]\n",
|
||||||
|
"ax1.set_yticklabels(yticks)\n",
|
||||||
|
"\n",
|
||||||
|
"# Water levels\n",
|
||||||
|
"ax2.plot(df_beach.R_high, n, color='#2c7bb6')\n",
|
||||||
|
"ax2.plot(df_beach.R_low, n, color='#2c7bb6')\n",
|
||||||
|
"ax2.fill_betweenx(\n",
|
||||||
|
" n, df_beach.R_low, df_beach.R_high, alpha=0.2, color='#2c7bb6', label='$R_{low}$ to $R_{high}$')\n",
|
||||||
|
"\n",
|
||||||
|
"# Dune elevations\n",
|
||||||
|
"ax2.plot(df_beach.dune_crest_z, n, color='#fdae61')\n",
|
||||||
|
"ax2.plot(df_beach.dune_toe_z, n, color='#fdae61')\n",
|
||||||
|
"ax2.fill_betweenx(\n",
|
||||||
|
" n, df_beach.dune_toe_z, df_beach.dune_crest_z, alpha=0.2, color='#fdae61', label='$D_{low}$ to $D_{high}$')\n",
|
||||||
|
"\n",
|
||||||
|
"ax2.set_title('TWL \\& Dune\\nElevations')\n",
|
||||||
|
"ax2.legend(loc='center',bbox_to_anchor=(0.5,-0.15))\n",
|
||||||
|
"ax2.set_xlabel('Elevation (m AHD)')\n",
|
||||||
|
"\n",
|
||||||
|
"# Plot R_high - D_low\n",
|
||||||
|
"ax3.plot(df_beach.R_high - df_beach.dune_toe_z,n,color='#999999')\n",
|
||||||
|
"ax3.axvline(x=0,color='black',linestyle=':')\n",
|
||||||
|
"ax3.set_title('$R_{high}$ - $D_{low}$')\n",
|
||||||
|
"ax3.set_xlabel('Height (m)')\n",
|
||||||
|
"ax3.set_xlim([-2,2])\n",
|
||||||
|
"\n",
|
||||||
|
"# Wave height, wave period, beach slope\n",
|
||||||
|
"ax4.plot(df_beach.Hs0, n,color='#377eb8')\n",
|
||||||
|
"ax4.set_title('$H_{s0}$')\n",
|
||||||
|
"ax4.set_xlabel('Sig. wave height (m)')\n",
|
||||||
|
"ax4.set_xlim([3,5])\n",
|
||||||
|
"\n",
|
||||||
|
"ax5.plot(df_beach.Tp, n,color='#e41a1c')\n",
|
||||||
|
"ax5.set_title('$T_{p}$')\n",
|
||||||
|
"ax5.set_xlabel('Peak wave period (s)')\n",
|
||||||
|
"ax5.set_xlim([8,14])\n",
|
||||||
|
"\n",
|
||||||
|
"ax6.plot(df_beach.tide, n,color='#a6cee3')\n",
|
||||||
|
"ax6.set_title('Tide')\n",
|
||||||
|
"ax6.set_xlabel('Elevation (m AHD)')\n",
|
||||||
|
"ax6.set_xlim([0,2])\n",
|
||||||
|
"\n",
|
||||||
|
"ax7.plot(df_beach.beta, n,color='#4daf4a')\n",
|
||||||
|
"ax7.set_title(r'$\\beta$')\n",
|
||||||
|
"ax7.set_xlabel('Mean prestorm\\nbeach slope')\n",
|
||||||
|
"ax7.set_xlim([0,0.15])\n",
|
||||||
|
"\n",
|
||||||
|
"ax8.plot(df_beach.R2, n,color='#6a3d9a')\n",
|
||||||
|
"ax8.set_title(r'$R_{2\\%}$')\n",
|
||||||
|
"ax8.set_xlabel('Height (m)')\n",
|
||||||
|
"\n",
|
||||||
|
"plt.tight_layout()\n",
|
||||||
|
"f.subplots_adjust(top=0.88)\n",
|
||||||
|
"f.suptitle(beach)\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"# Print to figure\n",
|
||||||
|
"plt.savefig('07-{}.png'.format(beach), dpi=600, bbox_inches='tight') \n",
|
||||||
|
"\n",
|
||||||
|
"plt.show()\n",
|
||||||
|
"plt.close()"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"hide_input": false,
|
||||||
|
"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.6"
|
||||||
|
},
|
||||||
|
"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
|
||||||
|
}
|
@ -0,0 +1,767 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Narrabeen Slope Test\n",
|
||||||
|
"With full topo and bathy combined"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Setup notebook"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"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",
|
||||||
|
"%matplotlib inline\n",
|
||||||
|
"%reload_ext autoreload\n",
|
||||||
|
"%autoreload"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from IPython.core.debugger import set_trace\n",
|
||||||
|
"\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"import numpy as np\n",
|
||||||
|
"import os\n",
|
||||||
|
"import decimal\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",
|
||||||
|
"from plotly import tools\n",
|
||||||
|
"import plotly.io as pio\n",
|
||||||
|
"from scipy import stats\n",
|
||||||
|
"import math\n",
|
||||||
|
"import matplotlib\n",
|
||||||
|
"from matplotlib import cm\n",
|
||||||
|
"import colorlover as cl\n",
|
||||||
|
"from tqdm import tqdm_notebook\n",
|
||||||
|
"from ipywidgets import widgets, Output\n",
|
||||||
|
"from IPython.display import display, clear_output, Image, HTML\n",
|
||||||
|
"from scipy import stats\n",
|
||||||
|
"from sklearn.metrics import confusion_matrix\n",
|
||||||
|
"import matplotlib.pyplot as plt\n",
|
||||||
|
"from scipy.interpolate import interp1d\n",
|
||||||
|
"from pandas.api.types import CategoricalDtype\n",
|
||||||
|
"from scipy.interpolate import UnivariateSpline\n",
|
||||||
|
"from shapely.geometry import Point, LineString"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Matplot lib default settings\n",
|
||||||
|
"plt.rcParams[\"figure.figsize\"] = (10,6)\n",
|
||||||
|
"plt.rcParams['axes.grid']=True\n",
|
||||||
|
"plt.rcParams['grid.alpha'] = 0.5\n",
|
||||||
|
"plt.rcParams['grid.color'] = \"grey\"\n",
|
||||||
|
"plt.rcParams['grid.linestyle'] = \"--\"\n",
|
||||||
|
"plt.rcParams['axes.grid']=True\n",
|
||||||
|
"\n",
|
||||||
|
"# https://stackoverflow.com/a/20709149\n",
|
||||||
|
"matplotlib.rcParams['text.usetex'] = True\n",
|
||||||
|
"\n",
|
||||||
|
"matplotlib.rcParams['text.latex.preamble'] = [\n",
|
||||||
|
" r'\\usepackage{siunitx}', # i need upright \\micro symbols, but you need...\n",
|
||||||
|
" r'\\sisetup{detect-all}', # ...this to force siunitx to actually use your fonts\n",
|
||||||
|
" r'\\usepackage{helvet}', # set the normal font here\n",
|
||||||
|
" r'\\usepackage{amsmath}',\n",
|
||||||
|
" r'\\usepackage{sansmath}', # load up the sansmath so that math -> helvet\n",
|
||||||
|
" r'\\sansmath', # <- tricky! -- gotta actually tell tex to use!\n",
|
||||||
|
"] "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Import .csv data"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"data_filename = '08-narr-topo-bathy-slope-test-full-profiles.csv'\n",
|
||||||
|
"\n",
|
||||||
|
"df_profiles = pd.read_csv(data_filename).set_index(['site_id','x'])\n",
|
||||||
|
"df_profiles = df_profiles[~df_profiles.index.duplicated(keep='first')]\n",
|
||||||
|
"print('df_profiles:')\n",
|
||||||
|
"df_profiles.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Manually cut off the prestorm topo \n",
|
||||||
|
"cuts = {'NARRA0004': {'prestorm_topo_max_x': 330,\n",
|
||||||
|
" 'poststorm_topo_max_x': 250},\n",
|
||||||
|
" 'NARRA0008': {'prestorm_topo_max_x': 290,\n",
|
||||||
|
" 'poststorm_topo_max_x': 250},\n",
|
||||||
|
" 'NARRA0012': {'prestorm_topo_max_x': 300,\n",
|
||||||
|
" 'poststorm_topo_max_x': 250},\n",
|
||||||
|
" 'NARRA0016': {'prestorm_topo_max_x': 300,\n",
|
||||||
|
" 'poststorm_topo_max_x': 225},\n",
|
||||||
|
" 'NARRA0021': {'prestorm_topo_max_x': 280,\n",
|
||||||
|
" 'poststorm_topo_max_x': 225},\n",
|
||||||
|
" 'NARRA0023': {'prestorm_topo_max_x': 275,\n",
|
||||||
|
" 'poststorm_topo_max_x': 215},\n",
|
||||||
|
" 'NARRA0027': {'prestorm_topo_max_x': 260,\n",
|
||||||
|
" 'poststorm_topo_max_x': 225},\n",
|
||||||
|
" 'NARRA0031': {'prestorm_topo_max_x': 260,\n",
|
||||||
|
" 'poststorm_topo_max_x': 225},\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
"for site_id in cuts:\n",
|
||||||
|
" mask1 = df_profiles.index.get_level_values('site_id') == site_id\n",
|
||||||
|
" mask2 = df_profiles.index.get_level_values('x') > cuts[site_id]['prestorm_topo_max_x']\n",
|
||||||
|
" df_profiles.loc[(mask1)&(mask2), 'pre_topo'] = np.nan\n",
|
||||||
|
" \n",
|
||||||
|
" mask3 = df_profiles.index.get_level_values('x') > cuts[site_id]['poststorm_topo_max_x']\n",
|
||||||
|
" df_profiles.loc[(mask1)&(mask3), 'post_topo'] = np.nan\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# for site_id,df_site in df_profiles.groupby('site_id'):\n",
|
||||||
|
"# f, (ax1) = plt.subplots(1,1, figsize=(6, 3))\n",
|
||||||
|
"# ax1.set_title(site_id)\n",
|
||||||
|
" \n",
|
||||||
|
"# ax1.plot(df_site.index.get_level_values('x'),\n",
|
||||||
|
"# df_site.pre_topo,\n",
|
||||||
|
"# label='Pre Topo',\n",
|
||||||
|
"# color='#2c7bb6')\n",
|
||||||
|
"# ax1.plot(df_site.index.get_level_values('x'),\n",
|
||||||
|
"# df_site.pre_bathy,\n",
|
||||||
|
"# label='Pre Bathy',\n",
|
||||||
|
"# color='#abd9e9')\n",
|
||||||
|
"\n",
|
||||||
|
"# ax1.plot(df_site.index.get_level_values('x'),\n",
|
||||||
|
"# df_site.post_topo,\n",
|
||||||
|
"# label='Post Topo',\n",
|
||||||
|
"# color='#d7191c')\n",
|
||||||
|
"# ax1.plot(df_site.index.get_level_values('x'),\n",
|
||||||
|
"# df_site.post_bathy,\n",
|
||||||
|
"# label='Post Bathy',\n",
|
||||||
|
"# color='#fdae61')\n",
|
||||||
|
"\n",
|
||||||
|
"# ax1.legend()\n",
|
||||||
|
"# plt.show()\n",
|
||||||
|
"# plt.close()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"df_profiles = df_profiles.dropna(\n",
|
||||||
|
" subset=['post_topo', 'post_bathy', 'pre_bathy', 'pre_topo'], how='all')\n",
|
||||||
|
"\n",
|
||||||
|
"df_profiles = df_profiles.reset_index()\n",
|
||||||
|
"df_profiles = df_profiles.melt(id_vars=['site_id','x','lat','lon'],\n",
|
||||||
|
" value_vars=['post_topo','post_bathy','pre_bathy','pre_topo']).rename(columns={'variable':'profile_type', 'value':'z'})\n",
|
||||||
|
"\n",
|
||||||
|
"df_profiles = df_profiles.dropna(subset=['z'])\n",
|
||||||
|
"\n",
|
||||||
|
"df_profiles.loc[df_profiles.profile_type=='post_topo','profile_type']='poststorm'\n",
|
||||||
|
"df_profiles.loc[df_profiles.profile_type=='post_bathy','profile_type']='poststorm'\n",
|
||||||
|
"df_profiles.loc[df_profiles.profile_type=='pre_topo','profile_type']='prestorm'\n",
|
||||||
|
"df_profiles.loc[df_profiles.profile_type=='pre_bathy','profile_type']='prestorm'\n",
|
||||||
|
"\n",
|
||||||
|
"df_profiles = df_profiles.set_index(['site_id', 'profile_type', 'x'])\n",
|
||||||
|
"df_profiles = df_profiles[~df_profiles.index.duplicated(keep='first')]\n",
|
||||||
|
"\n",
|
||||||
|
"df_profiles = df_profiles.sort_index()\n",
|
||||||
|
"\n",
|
||||||
|
"print('df_profiles:')\n",
|
||||||
|
"df_profiles.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Just plots each site's x and z values\n",
|
||||||
|
"for site_id,df_site in df_profiles.groupby('site_id'):\n",
|
||||||
|
" f, (ax1) = plt.subplots(1,1, figsize=(6, 3))\n",
|
||||||
|
" ax1.set_title(site_id)\n",
|
||||||
|
" \n",
|
||||||
|
" prestorm=df_site.index.get_level_values('profile_type') == 'prestorm'\n",
|
||||||
|
" ax1.plot(df_site[prestorm].index.get_level_values('x'),\n",
|
||||||
|
" df_site[prestorm].z,\n",
|
||||||
|
" label='Pre Topo',\n",
|
||||||
|
" color='#2c7bb6')\n",
|
||||||
|
"\n",
|
||||||
|
" \n",
|
||||||
|
" poststorm=df_site.index.get_level_values('profile_type') == 'poststorm'\n",
|
||||||
|
" ax1.plot(df_site[poststorm].index.get_level_values('x'),\n",
|
||||||
|
" df_site[poststorm].z,\n",
|
||||||
|
" label='Post Topo',\n",
|
||||||
|
" color='#d7191c')\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" ax1.legend()\n",
|
||||||
|
" plt.show()\n",
|
||||||
|
" plt.close()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Get dune faces"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"code_folding": []
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Manually define dune x coordinates and work out slope\n",
|
||||||
|
"\n",
|
||||||
|
"dune_data = [\n",
|
||||||
|
" {\n",
|
||||||
|
" 'site_id': 'NARRA0004',\n",
|
||||||
|
" 'dune_crest_x': 180,\n",
|
||||||
|
" 'dune_toe_x': 205\n",
|
||||||
|
" },\n",
|
||||||
|
" {\n",
|
||||||
|
" 'site_id': 'NARRA0008',\n",
|
||||||
|
" 'dune_crest_x': 180,\n",
|
||||||
|
" 'dune_toe_x': 205\n",
|
||||||
|
" },\n",
|
||||||
|
" {\n",
|
||||||
|
" 'site_id': 'NARRA0012',\n",
|
||||||
|
" 'dune_crest_x': 195,\n",
|
||||||
|
" 'dune_toe_x': 205\n",
|
||||||
|
" },\n",
|
||||||
|
" {\n",
|
||||||
|
" 'site_id': 'NARRA0016',\n",
|
||||||
|
" 'dune_crest_x': 190,\n",
|
||||||
|
" 'dune_toe_x': 200\n",
|
||||||
|
" },\n",
|
||||||
|
" {\n",
|
||||||
|
" 'site_id': 'NARRA0021',\n",
|
||||||
|
" 'dune_crest_x': 205,\n",
|
||||||
|
" 'dune_toe_x': 210\n",
|
||||||
|
" },\n",
|
||||||
|
" {\n",
|
||||||
|
" 'site_id': 'NARRA0023',\n",
|
||||||
|
" 'dune_crest_x': 205,\n",
|
||||||
|
" 'dune_toe_x': 215\n",
|
||||||
|
" },\n",
|
||||||
|
" {\n",
|
||||||
|
" 'site_id': 'NARRA0027',\n",
|
||||||
|
" 'dune_crest_x': 210,\n",
|
||||||
|
" 'dune_toe_x': 219\n",
|
||||||
|
" },\n",
|
||||||
|
" {\n",
|
||||||
|
" 'site_id': 'NARRA0031',\n",
|
||||||
|
" 'dune_crest_x': 210,\n",
|
||||||
|
" 'dune_toe_x': 218\n",
|
||||||
|
" },\n",
|
||||||
|
"]\n",
|
||||||
|
"\n",
|
||||||
|
"for site_dune in dune_data:\n",
|
||||||
|
" df_site = df_profiles.xs(site_dune['site_id'], level='site_id').xs('prestorm',level='profile_type')\n",
|
||||||
|
" \n",
|
||||||
|
" dune_crest_x = site_dune['dune_crest_x']\n",
|
||||||
|
" dune_toe_x = site_dune['dune_toe_x']\n",
|
||||||
|
" dune_crest_z = df_site.iloc[df_site.index.get_loc(site_dune['dune_crest_x'],method='nearest')].z\n",
|
||||||
|
" dune_toe_z = df_site.iloc[df_site.index.get_loc(site_dune['dune_toe_x'],method='nearest')].z\n",
|
||||||
|
"\n",
|
||||||
|
" dune_slope = (dune_crest_z - dune_toe_z)/(dune_crest_x - dune_toe_x)\n",
|
||||||
|
" \n",
|
||||||
|
" site_dune['dune_crest_z'] = dune_crest_z\n",
|
||||||
|
" site_dune['dune_toe_z'] = dune_toe_z\n",
|
||||||
|
" site_dune['dune_slope'] = dune_slope\n",
|
||||||
|
" \n",
|
||||||
|
" \n",
|
||||||
|
"# Join back into main data\n",
|
||||||
|
"df_dunes = pd.DataFrame(dune_data).set_index('site_id')\n",
|
||||||
|
"print('df_dunes:')\n",
|
||||||
|
"df_dunes.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# # Just plots each site's x and z values\n",
|
||||||
|
"# for site_id,df_site in df_profiles.xs('prestorm',level='profile_type').groupby('site_id'):\n",
|
||||||
|
"# f, (ax1) = plt.subplots(1,1, figsize=(6, 3))\n",
|
||||||
|
"# ax1.set_title(site_id)\n",
|
||||||
|
"# ax1.plot(df_site.index.get_level_values('x'),\n",
|
||||||
|
"# df_site.z)\n",
|
||||||
|
"# ax1.plot([df_dunes.loc[site_id].dune_crest_x, df_dunes.loc[site_id].dune_toe_x],\n",
|
||||||
|
"# [df_dunes.loc[site_id].dune_crest_z, df_dunes.loc[site_id].dune_toe_z],\n",
|
||||||
|
"# 'r.-')\n",
|
||||||
|
"# ax1.set_xlim([150,250])\n",
|
||||||
|
"# ax1.set_ylim([0,15])\n",
|
||||||
|
"# plt.show()\n",
|
||||||
|
"# plt.close()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Get prestorm slope"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"z_ele = 0.7\n",
|
||||||
|
"debug=False\n",
|
||||||
|
"\n",
|
||||||
|
"def find_nearest_idx(array, value):\n",
|
||||||
|
" array = np.asarray(array)\n",
|
||||||
|
" idx = (np.abs(array - value)).argmin()\n",
|
||||||
|
" return idx\n",
|
||||||
|
"\n",
|
||||||
|
"prestorm_slope_data =[]\n",
|
||||||
|
"for site_id, df_site in df_profiles.xs('prestorm',level='profile_type').groupby('site_id'):\n",
|
||||||
|
" \n",
|
||||||
|
" # Find index of our z_ele\n",
|
||||||
|
" idx = np.where(df_site.z.values>=z_ele)[0][-1]\n",
|
||||||
|
" \n",
|
||||||
|
" prestorm_end_x = df_site.iloc[idx].name[1]\n",
|
||||||
|
" prestorm_end_z = df_site.iloc[idx].z\n",
|
||||||
|
" \n",
|
||||||
|
" prestorm_start_x = df_dunes.loc[site_id].dune_toe_x\n",
|
||||||
|
" prestorm_start_z = df_dunes.loc[site_id].dune_toe_z\n",
|
||||||
|
" \n",
|
||||||
|
" prestorm_slope = (prestorm_end_z-prestorm_start_z)/(prestorm_end_x-prestorm_start_x)\n",
|
||||||
|
" \n",
|
||||||
|
" prestorm_slope_data.append({\n",
|
||||||
|
" 'site_id': site_id,\n",
|
||||||
|
" 'prestorm_end_x': prestorm_end_x,\n",
|
||||||
|
" 'prestorm_end_z': prestorm_end_z,\n",
|
||||||
|
" 'prestorm_start_x': prestorm_start_x,\n",
|
||||||
|
" 'prestorm_start_z': prestorm_start_z,\n",
|
||||||
|
" 'prestorm_slope': prestorm_slope\n",
|
||||||
|
" })\n",
|
||||||
|
" \n",
|
||||||
|
"df_prestorm_slope = pd.DataFrame(prestorm_slope_data).set_index(['site_id'])\n",
|
||||||
|
"print('df_prestorm_slope:')\n",
|
||||||
|
"df_prestorm_slope.head()\n",
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Get shelf slope\n",
|
||||||
|
"At 10 m contour"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"code_folding": []
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Elevation to take shelf slope at\n",
|
||||||
|
"z_ele = -9\n",
|
||||||
|
"debug=False\n",
|
||||||
|
"\n",
|
||||||
|
"def find_nearest_idx(array, value):\n",
|
||||||
|
" array = np.asarray(array)\n",
|
||||||
|
" idx = (np.abs(array - value)).argmin()\n",
|
||||||
|
" return idx\n",
|
||||||
|
"\n",
|
||||||
|
"def slope_at_point(x, z, z_ele,debug=False):\n",
|
||||||
|
" # Smooth profile a bit\n",
|
||||||
|
" # TODO the smoothing factor will change based on the number of data points\n",
|
||||||
|
" # Need to fix\n",
|
||||||
|
" s = UnivariateSpline(x, z, s=50)\n",
|
||||||
|
" xs = np.linspace(min(x),max(x),1000)\n",
|
||||||
|
" zs = s(xs)\n",
|
||||||
|
"\n",
|
||||||
|
" # Calculate derivates of spline\n",
|
||||||
|
" dzdx = np.diff(zs)/np.diff(xs)\n",
|
||||||
|
"\n",
|
||||||
|
" # Find index of z_ele\n",
|
||||||
|
" idx = find_nearest_idx(zs, z_ele)\n",
|
||||||
|
" slope = dzdx[idx]\n",
|
||||||
|
" shelf_x = xs[idx]\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" \n",
|
||||||
|
" # For checking how much smoothing is going on\n",
|
||||||
|
" if debug:\n",
|
||||||
|
" f, (ax1) = plt.subplots(1,1, figsize=(6, 3))\n",
|
||||||
|
" ax1.plot(x,z)\n",
|
||||||
|
" ax1.plot(xs,zs)\n",
|
||||||
|
" plt.show()\n",
|
||||||
|
" plt.close()\n",
|
||||||
|
" \n",
|
||||||
|
" return slope, shelf_x, z_ele\n",
|
||||||
|
" \n",
|
||||||
|
"shelf_data = []\n",
|
||||||
|
"for site_id, df_site in df_profiles.xs('prestorm',level='profile_type').groupby('site_id'):\n",
|
||||||
|
" shelf_slope, shelf_x, shelf_z = slope_at_point(df_site.index.get_level_values('x').values,\n",
|
||||||
|
" df_site.z, \n",
|
||||||
|
" z_ele, debug=debug)\n",
|
||||||
|
" shelf_data.append({\n",
|
||||||
|
" 'site_id': site_id,\n",
|
||||||
|
" 'shelf_slope': shelf_slope,\n",
|
||||||
|
" 'shelf_x': shelf_x,\n",
|
||||||
|
" 'shelf_z': shelf_z\n",
|
||||||
|
" })\n",
|
||||||
|
" \n",
|
||||||
|
"df_shelf = pd.DataFrame(shelf_data).set_index(['site_id'])\n",
|
||||||
|
"\n",
|
||||||
|
"df_shelf.loc['NARRA0004','shelf_slope'] = -0.02\n",
|
||||||
|
"\n",
|
||||||
|
"print('df_shelf:')\n",
|
||||||
|
"df_shelf.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Do geometry\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"df_site"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"for site_id, df_site in df_profiles.groupby('site_id'):\n",
|
||||||
|
"\n",
|
||||||
|
" # Project the dune face outwards\n",
|
||||||
|
" dune_face_toe = Point(df_dunes.loc[site_id].dune_toe_x,\n",
|
||||||
|
" df_dunes.loc[site_id].dune_toe_z)\n",
|
||||||
|
" dune_face_sea = Point(\n",
|
||||||
|
" df_dunes.loc[site_id].dune_toe_x + 1000,\n",
|
||||||
|
" # df_dunes.loc[site_id].dune_toe_z +1000 * -1\n",
|
||||||
|
" df_dunes.loc[site_id].dune_toe_z +\n",
|
||||||
|
" 1000 * df_dunes.loc[site_id].dune_slope)\n",
|
||||||
|
" dune_line = LineString([dune_face_toe, dune_face_sea])\n",
|
||||||
|
"\n",
|
||||||
|
" # Project the shelf slope landwards\n",
|
||||||
|
" shelf_point = Point(df_shelf.loc[site_id].shelf_x,\n",
|
||||||
|
" df_shelf.loc[site_id].shelf_z)\n",
|
||||||
|
" shelf_land = Point(\n",
|
||||||
|
" df_shelf.loc[site_id].shelf_x - 1000, df_shelf.loc[site_id].shelf_z -\n",
|
||||||
|
" 1000 * df_shelf.loc[site_id].shelf_slope)\n",
|
||||||
|
" shelf_sea = Point(\n",
|
||||||
|
" df_shelf.loc[site_id].shelf_x + 1000, df_shelf.loc[site_id].shelf_z +\n",
|
||||||
|
" 1000 * df_shelf.loc[site_id].shelf_slope)\n",
|
||||||
|
" shelf_line = LineString([shelf_land, shelf_point, shelf_sea])\n",
|
||||||
|
"\n",
|
||||||
|
" # Find intersection between to lines\n",
|
||||||
|
" dune_shelf_int = dune_line.intersection(shelf_line)\n",
|
||||||
|
" dist_toe_to_int = dune_face_toe.distance(dune_shelf_int)\n",
|
||||||
|
"\n",
|
||||||
|
" # Plots\n",
|
||||||
|
" f, (ax1) = plt.subplots(1, 1, figsize=(12, 4))\n",
|
||||||
|
"\n",
|
||||||
|
" # Raw profile prestorm\n",
|
||||||
|
" ax1.plot(\n",
|
||||||
|
" df_site.xs('prestorm',\n",
|
||||||
|
" level='profile_type').index.get_level_values('x'),\n",
|
||||||
|
" df_site.xs('prestorm', level='profile_type').z,\n",
|
||||||
|
" label='Prestorm profile')\n",
|
||||||
|
"\n",
|
||||||
|
" # Raw profile poststorm\n",
|
||||||
|
" ax1.plot(\n",
|
||||||
|
" df_site.xs('poststorm',\n",
|
||||||
|
" level='profile_type').index.get_level_values('x'),\n",
|
||||||
|
" df_site.xs('poststorm', level='profile_type').z,\n",
|
||||||
|
" label='Poststorm profile')\n",
|
||||||
|
"\n",
|
||||||
|
" # Dune face\n",
|
||||||
|
" ax1.plot(\n",
|
||||||
|
" [df_dunes.loc[site_id].dune_crest_x, df_dunes.loc[site_id].dune_toe_x],\n",
|
||||||
|
" [df_dunes.loc[site_id].dune_crest_z, df_dunes.loc[site_id].dune_toe_z],\n",
|
||||||
|
" linestyle=':',\n",
|
||||||
|
" color='#999999',\n",
|
||||||
|
" label='Dune face ({:.2f})'.format(-df_dunes.loc[site_id].dune_slope))\n",
|
||||||
|
"\n",
|
||||||
|
" # Projected dune face\n",
|
||||||
|
" ax1.plot(\n",
|
||||||
|
" dune_line.xy[0],\n",
|
||||||
|
" dune_line.xy[1],\n",
|
||||||
|
" linestyle='--',\n",
|
||||||
|
" color='#999999',\n",
|
||||||
|
" label='Dune face (projected)')\n",
|
||||||
|
"\n",
|
||||||
|
" # Projected shelf slope\n",
|
||||||
|
" ax1.plot(\n",
|
||||||
|
" shelf_line.xy[0],\n",
|
||||||
|
" shelf_line.xy[1],\n",
|
||||||
|
" linestyle='--',\n",
|
||||||
|
" color='#999999',\n",
|
||||||
|
" label='Shelf slope (projected)')\n",
|
||||||
|
"\n",
|
||||||
|
" # Intersection\n",
|
||||||
|
" ax1.scatter(\n",
|
||||||
|
" dune_shelf_int.xy[0],\n",
|
||||||
|
" dune_shelf_int.xy[1],\n",
|
||||||
|
" marker='x',\n",
|
||||||
|
" color='#999999',\n",
|
||||||
|
" label='Dune/shelf projected intersection')\n",
|
||||||
|
"\n",
|
||||||
|
" # Prestorm slope\n",
|
||||||
|
" ax1.plot([\n",
|
||||||
|
" df_prestorm_slope.loc[site_id].prestorm_start_x,\n",
|
||||||
|
" df_prestorm_slope.loc[site_id].prestorm_end_x\n",
|
||||||
|
" ], [\n",
|
||||||
|
" df_prestorm_slope.loc[site_id].prestorm_start_z,\n",
|
||||||
|
" df_prestorm_slope.loc[site_id].prestorm_end_z\n",
|
||||||
|
" ],\n",
|
||||||
|
" color='violet',\n",
|
||||||
|
" label='Prestorm slope ({:.2f})'.format(\n",
|
||||||
|
" -df_prestorm_slope.loc[site_id].prestorm_slope))\n",
|
||||||
|
"\n",
|
||||||
|
" # # Find best slope based on distance form toe to intersection?\n",
|
||||||
|
" # best_slope_toe = shelf_line.interpolate(\n",
|
||||||
|
" # shelf_line.project(intersection) - 4 * dist_toe_to_int)\n",
|
||||||
|
" # best_slope = (dune_face_toe.xy[1][0] - best_slope_toe.xy[1][0]) / (\n",
|
||||||
|
" # dune_face_toe.xy[0][0] - best_slope_toe.xy[0][0])\n",
|
||||||
|
"\n",
|
||||||
|
" # # Best slope toe\n",
|
||||||
|
" # ax1.scatter(\n",
|
||||||
|
" # best_slope_toe.xy[0], best_slope_toe.xy[1], marker='o', color='g')\n",
|
||||||
|
"\n",
|
||||||
|
" # # Best slope\n",
|
||||||
|
" # ax1.plot([dune_face_toe.xy[0], best_slope_toe.xy[0]],\n",
|
||||||
|
" # [dune_face_toe.xy[1], best_slope_toe.xy[1]],\n",
|
||||||
|
" # color='g',\n",
|
||||||
|
" # label='Best slope ({:.3f})'.format(-best_slope))\n",
|
||||||
|
"\n",
|
||||||
|
" # Find best slope based on intersection of prestorm slope and surf zone slope\n",
|
||||||
|
" prestorm_slope_line = LineString([\n",
|
||||||
|
" Point(\n",
|
||||||
|
" df_prestorm_slope.loc[site_id].prestorm_start_x,\n",
|
||||||
|
" df_prestorm_slope.loc[site_id].prestorm_start_z,\n",
|
||||||
|
" ),\n",
|
||||||
|
" Point(\n",
|
||||||
|
" df_prestorm_slope.loc[site_id].prestorm_start_x + 10000,\n",
|
||||||
|
" df_prestorm_slope.loc[site_id].prestorm_start_z +\n",
|
||||||
|
" 10000 * df_prestorm_slope.loc[site_id].prestorm_slope)\n",
|
||||||
|
" ])\n",
|
||||||
|
"\n",
|
||||||
|
" # Where prestorm slope projection intersects shelf line\n",
|
||||||
|
" prestorm_slope_shelf_int = prestorm_slope_line.intersection(shelf_line)\n",
|
||||||
|
"\n",
|
||||||
|
" # Distance between dune/shelf intersection and prestorm/shelf intersection\n",
|
||||||
|
" dist_shelf_prestorm_ints = prestorm_slope_shelf_int.distance(\n",
|
||||||
|
" dune_shelf_int)\n",
|
||||||
|
"\n",
|
||||||
|
" best_slope_pt = shelf_line.interpolate(\n",
|
||||||
|
" shelf_line.project(dune_shelf_int) + 0.3 * (shelf_line.project(prestorm_slope_shelf_int) -\n",
|
||||||
|
" shelf_line.project(dune_shelf_int)))\n",
|
||||||
|
" \n",
|
||||||
|
" best_slope =(df_prestorm_slope.loc[site_id].prestorm_start_z-best_slope_pt.xy[1][0])/(df_prestorm_slope.loc[site_id].prestorm_start_x-best_slope_pt.xy[0][0])\n",
|
||||||
|
" \n",
|
||||||
|
" if not prestorm_slope_shelf_int.is_empty:\n",
|
||||||
|
" ax1.plot(\n",
|
||||||
|
" prestorm_slope_shelf_int.xy[0],\n",
|
||||||
|
" prestorm_slope_shelf_int.xy[1],\n",
|
||||||
|
" marker='x',\n",
|
||||||
|
" color='#999999',\n",
|
||||||
|
" label='Prestorm slope/shelf\\nprojected intersection')\n",
|
||||||
|
" ax1.plot(\n",
|
||||||
|
" prestorm_slope_line.xy[0],\n",
|
||||||
|
" prestorm_slope_line.xy[1],\n",
|
||||||
|
" color='#999999',\n",
|
||||||
|
" linestyle='--',\n",
|
||||||
|
" label='Prestorm slope projected line')\n",
|
||||||
|
" ax1.plot(\n",
|
||||||
|
" [df_prestorm_slope.loc[site_id].prestorm_start_x,\n",
|
||||||
|
" best_slope_pt.xy[0][0]],\n",
|
||||||
|
" [df_prestorm_slope.loc[site_id].prestorm_start_z,\n",
|
||||||
|
" best_slope_pt.xy[1][0]],\n",
|
||||||
|
" color='red',\n",
|
||||||
|
" linestyle='--',\n",
|
||||||
|
" label='Best slope ({:.3f})'.format(-best_slope))\n",
|
||||||
|
" \n",
|
||||||
|
" # TEMP Target slopes\n",
|
||||||
|
" target_slopes = {\n",
|
||||||
|
" 'NARRA0004': 0.076,\n",
|
||||||
|
" 'NARRA0008': 0.093,\n",
|
||||||
|
" 'NARRA0012': 0.060,\n",
|
||||||
|
" 'NARRA0016': 0.11,\n",
|
||||||
|
" 'NARRA0021': 0.063,\n",
|
||||||
|
" 'NARRA0023': 0.061,\n",
|
||||||
|
" 'NARRA0027': 0.060,\n",
|
||||||
|
" 'NARRA0031': 0.057,\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" target_direction = {\n",
|
||||||
|
" 'NARRA0004': \"flatter\",\n",
|
||||||
|
" 'NARRA0008': \"steeper\",\n",
|
||||||
|
" 'NARRA0012': \"flatter\",\n",
|
||||||
|
" 'NARRA0016': \"flatter\",\n",
|
||||||
|
" 'NARRA0021': \"steeper\",\n",
|
||||||
|
" 'NARRA0023': \"steeper\",\n",
|
||||||
|
" 'NARRA0027': \"steeper\",\n",
|
||||||
|
" 'NARRA0031': \"steeper\",\n",
|
||||||
|
" }\n",
|
||||||
|
" ax1.plot([dune_face_toe.xy[0][0], dune_face_toe.xy[0][0] + 1000], [\n",
|
||||||
|
" dune_face_toe.xy[1][0],\n",
|
||||||
|
" dune_face_toe.xy[1][0] - 1000 * target_slopes[site_id]\n",
|
||||||
|
" ],\n",
|
||||||
|
" color='red',\n",
|
||||||
|
" label='Target slope\\n({} than {:.3f})'.format(\n",
|
||||||
|
" target_direction[site_id], target_slopes[site_id]))\n",
|
||||||
|
"\n",
|
||||||
|
" ax1.set_xlim([100, 800])\n",
|
||||||
|
" ax1.set_ylim([-15, 12])\n",
|
||||||
|
"# ax1.set_xlim([100, 600])\n",
|
||||||
|
"# ax1.set_ylim([-10, 12])\n",
|
||||||
|
"\n",
|
||||||
|
" # ax1.set_xlim([df_dunes.loc[site_id].dune_crest_x - 50,\n",
|
||||||
|
" # intersection.xy[0][0] + 50])\n",
|
||||||
|
" # ax1.set_ylim([intersection.xy[1][0] -3,\n",
|
||||||
|
" # df_dunes.loc[site_id].dune_crest_z + 3])\n",
|
||||||
|
"\n",
|
||||||
|
" ax1.set_title(site_id)\n",
|
||||||
|
" ax1.legend(loc='upper right', prop={'size': 10})\n",
|
||||||
|
" f.savefig('08-{}.png'.format(site_id), dpi=600)\n",
|
||||||
|
" plt.show()\n",
|
||||||
|
" plt.close()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"dune_shelf_int"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"hide_input": false,
|
||||||
|
"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.6"
|
||||||
|
},
|
||||||
|
"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
|
||||||
|
}
|
Loading…
Reference in New Issue