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

Code to extract and save watershed's properties

parent 4f8dbe5d
No related merge requests found
Showing with 97 additions and 0 deletions
+97 -0
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 15 12:34:40 2021
@author: laura.lindeperg
"""
import geopandas as gpd
import pandas as pd
import seaborn as sns
from Watershed import Watershed
# **************************** Data *****************************
# Banque Hydro
banquehydro_foldername = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/BanqueHydro/Export2020/'
# SAFRAN
safran_foldername = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/SAFRAN/daily/'
# safran_grid_shpfilename = './TestData/SAFRAN/maille_meteo_fr_pr93.shp'
# GEOL
BDLisa_shp = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/BD_Lisa/RegionalHydrogeologyAnalysisMe/BD_Lisa_regionalhydrogeology.shp'
BRGM_geol_map = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/CarteGeolBRGM/FR_vecteur/FR_vecteur/GEO001M_CART_FR_S_FGEOL_2154.shp'
# Watersheds
# shp_stations_filepath = 'E:/DonneesLaura/BanqueHydro/Shapes/StationBHYDRO_L93.shp'
df_stations_filepath = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/BanqueHydro/StationsNonInfluenceesExplore2/Synthèse analyses/Synthèse_meta_selection_624.csv'
shp_contour_filepath = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/BanqueHydro/Shapes/BassinsVersantsMetropole/BV_4207_stations.shp'
df_stations = pd.read_csv(df_stations_filepath, sep = ';', encoding='latin-1')
shp_contour = gpd.read_file(shp_contour_filepath)
# List of the stations'codes
watershed_code = df_stations.loc[:,'Code']
# Get a sample of them for test
code_for_test = watershed_code.loc[1:10]
# *************************** Extract watersheds' properties ************************************
studied_watersheds = pd.DataFrame()
for i in code_for_test:
#for i in watershed_code:
# Get the station's name
watershed_stations_i = df_stations[df_stations.loc[:, 'Code'] == i]
watershed_name_i = watershed_stations_i.loc[:, 'Nom'].values[0]
# Create waterhed object and extract its properties
watershed_i = Watershed(i, watershed_name_i)
watershed_i.extract_watershed_contour_from_filename(shp_contour_filepath, 'Code')
watershed_i.extract_banquehydro_discharge_timeseries(banquehydro_foldername)
# watershed_i.extract_SAFRAN_forcings(safran_foldername, safran_grid_shpfilename)
watershed_i.extract_SAFRAN_forcings(safran_foldername)
watershed_i.extract_hydrological_signatures()
watershed_i.extract_geologic_properties_from_filename(BDLisa_shp)
watershed_i.geologic_properties.extract_average_age_geology(BRGM_geol_map, watershed_i.contour)
# Create a dictionnary and fill the dataframe
watershed_dict = watershed_i.to_dict()
studied_watersheds = studied_watersheds.append(watershed_dict, ignore_index=True)
# And save it
# studied_watersheds.to_csv('few_stations_df.csv', index=False)
# Few plots for test
df_some_stations_path = 'few_stations_df.csv'
df_some_stations = pd.read_csv(df_some_stations_path)
# 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');
Supports Markdown
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