Commit 6a76a76f authored by Laura LINDEPERG's avatar Laura LINDEPERG
Browse files

Spearman information

parent 3d5c6917
......@@ -6,6 +6,7 @@ Created on Wed Apr 7 16:17:38 2021
"""
import geopandas as gpd
import pandas as pd
import seaborn as sns
......@@ -22,11 +23,12 @@ df_hydro_sig_path = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/616_stations_
# df_hydro_sig_path = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/616_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 = df_hydro_sig.drop(columns = ['name'])
## Cross correlations - hydro signatures
df_hydro_sig_1 = df_hydro_sig.loc[:, ['code', 'aridity_ratio', 'q_mean', 'runoff_ratio']]
df_hydro_sig_2 = df_hydro_sig.loc[:, ['code', 'bfi_5', 'bfi_90', 'bf_magni']]
df_hydro_sig_3 = df_hydro_sig.loc[:, ['code', 'fdc_quantile10', 'fdc_quantile90', 'fdc_slope']]
......@@ -56,6 +58,7 @@ df_hydro_sig_35_long = df_hydro_sig_35.melt(id_vars = ['code'], var_name = 'hydr
df_hydro_sig_45_long = df_hydro_sig_45.melt(id_vars = ['code'], var_name = 'hydro_sig')
# Watersheds
shp_watersheds_path = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/616_Catchments.shp'
shp_foldername = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/GEOMETRY/'
......@@ -68,11 +71,12 @@ rrse_241 = rrse_241.rename(columns = {'levels.RRSE.':'Code'})
rrse_241 = rrse_241.loc[:, 'Code']
r2se_236_path = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/STATIONS/R2SE_stations_et_critique_v01_IgnazioGiuntoli.xls'
r2se_236 = pd.read_excel(r2se_236_path, sheet_name=0)
# # Other lists of stations
# r2se_236_path = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/STATIONS/R2SE_stations_et_critique_v01_IgnazioGiuntoli.xls'
# r2se_236 = pd.read_excel(r2se_236_path, sheet_name=0)
her_662_path = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/STATIONS/Stations662_HER.csv'
her_662 = pd.read_csv(her_662_path)
# her_662_path = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/STATIONS/Stations662_HER.csv'
# her_662 = pd.read_csv(her_662_path)
......@@ -85,11 +89,14 @@ df_geomorpho_path = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/CODE/fhysa/61
df_geomorpho = pd.read_csv(df_geomorpho_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_geomorpho, on = 'code', how = 'outer')
my_df = pd.merge(df_hydro_sig_long, df_geol, on = 'code', how = 'outer')
# my_df = pd.merge(my_df, delta_v, on = 'code', how = 'outer')
......@@ -100,10 +107,17 @@ my_df = pd.merge(my_df, shp_watersheds, on = 'code', how = 'outer')
# Add maingeol_description from geol indicators in the df when using geomorpho indicators
geol = df_geol.loc[:, ['code', 'maingeol_description']]
df_hydro_sig_long = df_hydro_sig.melt(id_vars = ['code'], var_name = 'hydro_sig')
my_df = pd.merge(df_hydro_sig_long, df_geomorpho, on = 'code', how = 'outer')
my_df = pd.merge(my_df, geol, on='code')
# Pick catchments within the rrse list
my_df = my_df.loc[my_df.loc[:, 'code'].isin(rrse_241)==True]
# 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]
......@@ -193,6 +207,7 @@ for i in code_for_test:
# filename_i = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/CODE/fhysa/Object_watershed/watershed_'+i
# filename_i = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/CODE/fhysa/Object_watershed/watershed_allYears_'+i
# filename_i = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/CODE/fhysa/Object_watershed/Adim_new/watershed_adim_'+i
# filename_i = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/CODE/fhysa/Object_watershed/Dim/watershed_dim_J4742020'
filename_i = 'C:/Users/laura.lindeperg/Documents/INRAE_2021/CODE/fhysa/Object_watershed/Dim/watershed_dim_'+i
infile_i = open(filename_i, 'rb')
watershed_i = pickle.load(infile_i)
......@@ -263,38 +278,51 @@ nobs = [str(x) for x in nobs.tolist()]
nobs = [i for i in nobs]
# nobs = ["n: " + i for i in nobs]
my_df=my_df.sort_values(by=['maingeol_description'])
my_df=my_df.sort_values(by=['maingeol_description'])
## Scatterplots of the hydrological signatures with extra dimension -> geol or geomorpho indicator parameter
x_column = 'intermittent_ratio'
x_column = 'median_slope'
y_column = 'value'
define_hue = 'maingeol_description'
hydrosig_list = ['bfi_5', 'bfi_90', 'b_q', 'tau_roques', 'tau_2', 'fdc_slope']
xtitle = 'median slope [%]'
from scipy.stats import spearmanr
#calculate Spearman Rank correlation and corresponding p-value
my_data = pd.merge(df_hydro_sig, df_geomorpho, on = 'code', how = 'outer')
spearman_coeff = pd.DataFrame(columns=['hydro_sig', 'rho', 'p_value'])
for i in hydrosig_list:
rho, p = spearmanr(my_data[x_column], my_data[i], nan_policy='omit')
spearman_coeff = spearman_coeff.append({'hydro_sig':i, 'rho': rho, 'p_value': p}, ignore_index = True)
figure, axes = plt.subplots(2, 3, figsize = (17, 17), sharex = True)
# figure.suptitle('Hydrological signatures')
axes[0, 0].set_title('BFI 5')
axes[0, 1].set_title('BFI 90')
axes[0, 2].set_title('b_l Roques')
axes[1, 0].set_title('tau_l Roques')
axes[1, 1].set_title('tau_l Horner')
axes[1, 2].set_title('FDC slope')
axes[0, 0].set_title('BFI 5 \nrho: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'bfi_5'].rho.values[0]) + ' p: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'bfi_5'].p_value.values[0]))
axes[0, 1].set_title('BFI 90 \nrho: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'bfi_90'].rho.values[0]) + ' p: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'bfi_90'].p_value.values[0]))
axes[0, 2].set_title('b_l Roques \nrho: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'b_q'].rho.values[0]) + ' p: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'b_q'].p_value.values[0]))
axes[1, 0].set_title('tau_l Roques \nrho: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'tau_roques'].rho.values[0]) + ' p: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'tau_roques'].p_value.values[0]))
axes[1, 1].set_title('tau_l Horner \nrho: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'tau_2'].rho.values[0]) + ' p: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'tau_2'].p_value.values[0]))
axes[1, 2].set_title('FDC slope \nrho: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'fdc_slope'].rho.values[0]) + ' p: ' + str("%.4f"%spearman_coeff.loc[spearman_coeff.hydro_sig == 'fdc_slope'].p_value.values[0]))
# axes[1, 2].set_title('FDC q90')
sns.scatterplot(ax=axes[0, 0], x=x_column, y=y_column, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_5']).set(xlabel = None, ylabel = None)
sns.scatterplot(ax=axes[0, 1], x=x_column, y=y_column, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_90']).set(xlabel = None, ylabel = None)
sns.scatterplot(ax=axes[0, 2], x=x_column, y=y_column, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'b_q']).set(xlabel = None, ylabel = None)
sns.scatterplot(ax=axes[1, 0], x=x_column, y=y_column, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_roques']).set(ylabel = None)
sns.scatterplot(ax=axes[1, 1], x=x_column, y=y_column, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_2']).set(ylabel = None)
sns.scatterplot(ax=axes[1, 2], x=x_column, y=y_column, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_slope']).set(ylabel = None)
# sns.scatterplot(ax=axes[1, 2], x=x_column, y=y_column, hue = define_hue, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_quantile90']).set(xlabel = None, ylabel = None)
sns.scatterplot(ax=axes[0, 0], x=x_column, y=y_column, hue = define_hue, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_5']).set(xlabel = None, ylabel = None)
sns.scatterplot(ax=axes[0, 1], x=x_column, y=y_column, hue = define_hue, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'bfi_90']).set(xlabel = None, ylabel = None)
sns.scatterplot(ax=axes[0, 2], x=x_column, y=y_column, hue = define_hue, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'b_q']).set(xlabel = None, ylabel = None)
sns.scatterplot(ax=axes[1, 0], x=x_column, y=y_column, hue = define_hue, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_roques']).set(ylabel = None, xlabel = xtitle)
sns.scatterplot(ax=axes[1, 1], x=x_column, y=y_column, hue = define_hue, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'tau_2']).set(ylabel = None, xlabel = xtitle)
sns.scatterplot(ax=axes[1, 2], x=x_column, y=y_column, hue = define_hue, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_slope']).set(ylabel = None, xlabel = xtitle)
# sns.scatterplot(ax=axes[1, 2], x=x_column, y=y_column, hue = define_hue, data=my_df.loc[my_df.loc[:, 'hydro_sig'] == 'fdc_quantile90']).set(xlabel = None, ylabel = None, xscale = 'log')
# ax31.set(xlabel = None, ylabel = None)
axes[0,0].legend().set_visible(False)
axes[0,1].legend().set_visible(False)
......
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