Commit cd044cf1 authored by Laura LINDEPERG's avatar Laura LINDEPERG
Browse files

Code for plots

parent 426efa49
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 7 16:17:38 2021
@author: laura.lindeperg
"""
import geopandas as gpd
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# **************************** Data *****************************
# Load hydrological signatures df
df_hydro_sig_path = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/613_stations_hydrosig_df.csv'
# df_hydro_sig_path = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/613_stations_hydrosig_dim_df.csv'
df_hydro_sig = pd.read_csv(df_hydro_sig_path)
## Older files
# df_hydro_sig = df_stations.drop(columns = ['age', 'fc', 'ks', 'maingeol_age', 'maingeol_age_proportion', 'maingeol_description', 'maingeol_id', 'maingeol_proportion', 'name'])
# df_hydro_sig_main = df_hydro_sig.loc[:, ['aridity_ratio', 'code', 'q_mean', 'runoff_ratio']]
# df_hydro_sig_main_long = df_hydro_sig_main.melt(id_vars = ['code'], var_name = 'hydro_sig')
# df_hydro_sig = df_hydro_sig.loc[df_hydro_sig.loc[:,'code'].isin(['K6492510', 'V2814020', 'P7041510', 'A9001050', 'H8043310', 'H4033010']) == False]
# Watersheds
shp_watersheds_path = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/complete_df_wrong_geometries.shp'
shp_foldername = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/GEOMETRY/'
shp_watersheds = gpd.read_file(shp_watersheds_path)
# Geol
df_geol_path = '613_stations_geol_df.csv'
df_geol = pd.read_csv(df_geol_path)
# Transform in long-form data structure
df_hydro_sig = df_hydro_sig.drop(columns = ['name'])
df_hydro_sig_long = df_hydro_sig.melt(id_vars = ['code'], var_name = 'hydro_sig')
my_df = pd.merge(df_hydro_sig_long, df_geol, on = 'code', how = 'outer')
# Merge hydrological signatures with geometry file
shp_watersheds = shp_watersheds.rename(columns = {'Code':'code'})
my_df = pd.merge(my_df, shp_watersheds, on = 'code', how = 'outer')
# Filter border catchments
border_catchments = ['A3792010', 'A3902010', 'B4224310', 'B4601010', 'B4631010', 'D0156510', 'O1900010', 'O2620010', 'O6140010', 'U2512010', 'U2542010', 'U2722010','V1000010', 'V1020010']
my_df = my_df.loc[my_df.loc[:, 'code'].isin(border_catchments)==False]
# Filter catchments based on their size...
my_df = my_df.loc[my_df.loc[:, 'S_km2'] < 5000]
# ...and their main geol proportion
my_geol = df_geol.loc[df_geol.loc[:, 'maingeol_proportion'] > 0.70]
my_df = my_df.loc[my_df.loc[:, 'code'].isin(my_geol.loc[:,'code'])==True]
# Exclude catchments which disturb scales
my_df = my_df.loc[my_df.loc[:,'code'].isin(['K6492510', 'V2814020', 'P7041510', 'A9001050', 'H8043310', 'H4033010']) == False]
# **************************** Plots *****************************
## Boxplot of the hydrological signatures
figure, axes = plt.subplots(4, 4, figsize = (17, 17))
figure.suptitle('Hydrological signatures')
axes[0, 0].set_title('Qmean')
axes[0, 1].set_title('Aridity ratio')
axes[0, 2].set_title('Runoff ratio')
axes[0, 3].set_title('BFI 5')
axes[1, 0].set_title('BF magni')
axes[1, 1].set_title('a_q')
axes[1, 2].set_title('b_q')
axes[1, 3].set_title('FDC q10')
axes[2, 0].set_title('FDC q90')
axes[2, 1].set_title('FDC slope')
axes[2, 2].set_title('tau 1')
axes[2, 3].set_title('tau 2')
axes[3, 0].set_title('tau Roques')
axes[3, 1].set_title('BFI 90')
sns.boxplot(ax=axes[0, 0], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'q_mean']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[0, 1], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'aridity_ratio']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[0, 2], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'runoff_ratio']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[0, 3], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_5']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[1, 0], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bf_magni']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[1, 1], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'a_q']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[1, 2], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'b_q']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[1, 3], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_quantile10']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[2, 0], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_quantile90']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[2, 1], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_slope']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[2, 2], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_1']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[2, 3], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_2']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[3, 0], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_roques']).set(xlabel = None, xticks=[])
sns.boxplot(ax=axes[3, 1], x='hydro_sig', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_90']).set(xlabel = None, xticks=[])
axes[3, 2].axis("off")
axes[3, 3].axis("off")
## Boxplot of the hydrological signatures from their main hydrogeologic type perspective
figure, axes = plt.subplots(4, 4, figsize = (17, 17))
figure.suptitle('Hydrological signatures')
axes[0, 0].set_title('Qmean')
axes[0, 1].set_title('Aridity ratio')
axes[0, 2].set_title('Runoff ratio')
axes[0, 3].set_title('BFI 5')
axes[1, 0].set_title('BF magni')
axes[1, 1].set_title('a_q')
axes[1, 2].set_title('b_q')
axes[1, 3].set_title('FDC q10')
axes[2, 0].set_title('FDC q90')
axes[2, 1].set_title('FDC slope')
axes[2, 2].set_title('tau 1')
axes[2, 3].set_title('tau 2')
axes[3, 0].set_title('tau Roques')
axes[3, 1].set_title('BFI 90')
sns.boxplot(ax=axes[0, 0], x='hydro_sig', y='value', hue = 'maingeol_description', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'q_mean'])
sns.boxplot(ax=axes[0, 1], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'aridity_ratio'])
sns.boxplot(ax=axes[0, 2], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'runoff_ratio'])
sns.boxplot(ax=axes[0, 3], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_5'])
sns.boxplot(ax=axes[1, 0], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bf_magni'])
sns.boxplot(ax=axes[1, 1], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'a_q'])
sns.boxplot(ax=axes[1, 2], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'b_q'])
sns.boxplot(ax=axes[1, 3], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_quantile10'])
sns.boxplot(ax=axes[2, 0], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_quantile90'])
sns.boxplot(ax=axes[2, 1], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_slope'])
sns.boxplot(ax=axes[2, 2], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_1'])
sns.boxplot(ax=axes[2, 3], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_2'])
sns.boxplot(ax=axes[3, 0], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_roques'])
sns.boxplot(ax=axes[3, 1], x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_90'])
axes[3, 2].axis("off")
axes[3, 3].axis("off")
sns.boxplot(x='maingeol_description', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'q_mean']).tick_params(axis='x', labelrotation=45)
## Scatterplot - geographic repartition
figure, axes = plt.subplots(4, 4, figsize = (17, 17))
figure.suptitle('Hydrological signatures')
axes[0, 0].set_title('Qmean')
axes[0, 1].set_title('Aridity ratio')
axes[0, 2].set_title('Runoff ratio')
axes[0, 3].set_title('BFI 5')
axes[1, 0].set_title('BF magni')
axes[1, 1].set_title('a_q')
axes[1, 2].set_title('b_q')
axes[1, 3].set_title('FDC q10')
axes[2, 0].set_title('FDC q90')
axes[2, 1].set_title('FDC slope')
axes[2, 2].set_title('tau 1')
axes[2, 3].set_title('tau 2')
axes[3, 0].set_title('tau Roques')
axes[3, 1].set_title('BFI 90')
sns.scatterplot(ax=axes[0, 0], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'q_mean']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[0, 1], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'aridity_ratio']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[0, 2], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'runoff_ratio']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[0, 3], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_5']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[1, 0], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bf_magni']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[1, 1], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'a_q']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[1, 2], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'b_q']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[1, 3], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_quantile10']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[2, 0], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_quantile90']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[2, 1], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_slope']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[2, 2], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_1']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[2, 3], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_2']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[3, 0], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_roques']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
sns.scatterplot(ax=axes[3, 1], x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_90']).set(xlabel = None, ylabel = None, xticks=[], yticks = [])
axes[3, 2].axis("off")
axes[3, 3].axis("off")
sns.relplot(x='value', y='value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'a_q'])
watershed_code = shp_watersheds.loc[:,'code']
sns.relplot(x='XL93', y='YL93', hue = 'value', data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'q_mean'])
for i in watershed_code:
watershed_i = shp_watersheds.loc[shp_watersheds.loc[:,'code']==i]
plt.text(watershed_i.XL93, watershed_i.YL93, i, horizontalalignment='left', size='medium', color='black')
plt.show()
sns.relplot(x="XL93", y="YL93", hue="S_km2", data=my_df);
g = sns.FacetGrid(my_df, col="hydro_sig", col_wrap=2)
g.map(sns.scatterplot(x="XL93", y="YL93", hue="value", data = my_df), "XL93", "YL93")
def hydro_sig_plot(hydro_sig):
df = my_df.loc[my_df.loc[:, 'hydro_sig'] == hydro_sig]
sns.relplot(x="XL93", y="YL93", hue="value", data = df);
hydro_sig_name = ['q_mean', 'aridity_ratio', 'runoff_ratio']
g = sns.FacetGrid(my_df, col="hydro_sig", col_wrap=2)
for i in hydro_sig_name:
print(i)
g.map(hydro_sig_plot(i), "XL93", "YL93")
sns.relplot(x="XL93", y="YL93", hue="value",
col="hydro_sig", col_wrap=2,
kind="scatter", data= my_df);
# ## Few plots for test
# # bf indices
# sns.relplot(x="q_mean", y="bfi", hue="maingeol_description", data=df_some_stations)
# sns.relplot(x="bfi", y="bf_magni", hue="maingeol_description", data=df_some_stations)
# # recession indices
# sns.relplot(x="q_mean", y="tau_1", hue="maingeol_description", data=df_some_stations)
# sns.relplot(x="q_mean", y="tau_2", hue="maingeol_description", data=df_some_stations)
# sns.relplot(x="tau_1", y="tau_2", hue="maingeol_description", data=df_some_stations)
# all_watershed = shp_contour.plot(color='white', edgecolor='#f4a460')
# problematic_watershed = shp_contour[shp_contour.Code=="A7821010"]
# problematic_watershed.plot(ax=all_watershed, color='blue');
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment