Add new notebook for examining variables
Want to find relationships between explanatory variables.develop
parent
7069c3b627
commit
7e09b9a084
@ -0,0 +1,261 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Investigate "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Setup notebook\n",
|
||||||
|
"Import our required packages and set default plotting options."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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 matplotlib.ticker import MultipleLocator\n",
|
||||||
|
"from matplotlib.lines import Line2D\n",
|
||||||
|
"from cycler import cycler\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\n",
|
||||||
|
"Import our data from the `./data/interim/` folder and load it into pandas dataframes. "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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_sites_waves = df_from_csv('sites_waves.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",
|
||||||
|
" 'postintertidal_slope_sto06': df_from_csv('impacts_forecasted_postintertidal_slope_sto06.csv', index_col=[0]),\n",
|
||||||
|
" 'postmean_slope_sto06': df_from_csv('impacts_forecasted_postmean_slope_sto06.csv', index_col=[0]),\n",
|
||||||
|
" 'preintertidal_slope_sto06': df_from_csv('impacts_forecasted_preintertidal_slope_sto06.csv', index_col=[0]),\n",
|
||||||
|
" 'premean_slope_sto06': df_from_csv('impacts_forecasted_premean_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",
|
||||||
|
" 'postintertidal_slope_sto06': df_from_csv('twl_postintertidal_slope_sto06.csv', index_col=[0,1]),\n",
|
||||||
|
" 'postmean_slope_sto06': df_from_csv('twl_postmean_slope_sto06.csv', index_col=[0,1]),\n",
|
||||||
|
" 'preintertidal_slope_sto06': df_from_csv('twl_preintertidal_slope_sto06.csv', index_col=[0,1]),\n",
|
||||||
|
" 'premean_slope_sto06': df_from_csv('twl_premean_slope_sto06.csv', index_col=[0,1]),\n",
|
||||||
|
" }\n",
|
||||||
|
"}\n",
|
||||||
|
"print('Done!')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Sec1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Create df with all our data\n",
|
||||||
|
"df = impacts['observed'].merge(df_sites_waves,left_index=True,right_index=True)\n",
|
||||||
|
"df.columns"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import seaborn as sns\n",
|
||||||
|
"sns.set(style=\"white\")\n",
|
||||||
|
"g = sns.pairplot(\n",
|
||||||
|
" data=df,\n",
|
||||||
|
" hue='storm_regime',\n",
|
||||||
|
" dropna=True,\n",
|
||||||
|
" palette={\n",
|
||||||
|
" 'swash': 'blue',\n",
|
||||||
|
" 'collision': 'orange',\n",
|
||||||
|
" 'overwash': 'red'\n",
|
||||||
|
" },\n",
|
||||||
|
" vars=['beta_prestorm_mean',\n",
|
||||||
|
" 'beta_poststorm_mean',\n",
|
||||||
|
" 'beta_diff_mean',\n",
|
||||||
|
" 'swash_pct_change',\n",
|
||||||
|
" 'df_width_msl_change_m',\n",
|
||||||
|
" 'df_width_msl_change_pct',\n",
|
||||||
|
" 'Exscum'])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"g.savefig('11_pairplot.png')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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