An error occurred while loading the file. Please try again.
-
Stephane ALBERT authoreda4249f5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 24 09:21:44 2021
@author: laura.lindeperg
"""
import geopandas as gpd
import pandas as pd
# **************************** Data *****************************
# 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'
shp_BV_IV_path ='C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/BV_InvalidesValides/BVsInvalidesValides.shp'
df_stations = pd.read_csv(df_stations_filepath, sep = ';', encoding='latin-1')
shp_contour = gpd.read_file(shp_contour_filepath)
shp_BV_IV = gpd.read_file(shp_BV_IV_path)
# shp_BV_VV = gpd.read_file('C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/BV_InvalidesValides/BVsValidesValides.shp')
shp_foldername = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/GEOMETRY/'
# 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_path = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/BD_Lisa/RegionalHydrogeologyAnalysisMe/BD_Lisa_regionalhydrogeology.shp'
BDLisa_shp = gpd.read_file(BDLisa_shp_path)
BRGM_geol_path = 'C:/Users/laura.lindeperg/Documents/DonneesLaura/CarteGeolBRGM/FR_vecteur/FR_vecteur/GEO001M_CART_FR_S_FGEOL_2154.shp'
BRGM_shp = gpd.read_file(BRGM_geol_path)
# extract safran gpd
from HydroClimaticFluxes import HydroClimaticFluxes
HCF = HydroClimaticFluxes(code=-1)
# Ptot_gpd = HCF.extract_safran_variable(safran_foldername, 'Ptot')
ET0_gpd = HCF.extract_safran_variable(safran_foldername, 'ET0')
Tair_gpd = HCF.extract_safran_variable(safran_foldername, 'Tair')
Snow_gpd = HCF.extract_safran_variable(safran_foldername, 'Snow')
Rain_gpd = HCF.extract_safran_variable(safran_foldername, 'Rain')
# **************************** Create my own Data *****************************
my_df_stations = df_stations.loc[:, 'Code':'YL93' ]
duplicated_stations = my_df_stations.duplicated(subset = ['Code'])
index_duplicated = duplicated_stations[duplicated_stations[:,] == True]
stations_duplicated = my_df_stations.iloc[index_duplicated.index[0]]
no_duplicated = my_df_stations.drop(index_duplicated.index[0])
# shp_watersheds = my_df_stations.merge(shp_contour, on = 'Code', how = 'outer')
shp_watersheds = no_duplicated.merge(shp_contour, on = 'Code', how = 'outer')
shp_watersheds = gpd.GeoDataFrame(shp_watersheds)
no_geometry = shp_watersheds[shp_watersheds['geometry'] == None]
studied_watersheds = shp_watersheds.loc[shp_watersheds.loc[:,'Code'].isin(no_duplicated.loc[:,'Code'])]
complete_watersheds = studied_watersheds[studied_watersheds['geometry'] != None]
# complete_watersheds.to_file('C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/complete_df_wrong_geometries.shp')
complete_watersheds_noElle = complete_watersheds.drop(complete_watersheds.loc[complete_watersheds.loc[:, 'Code'] == 'J4742020'].index[0])
## Dealing with BV_IV
df_BV_IV = no_duplicated.loc[no_duplicated.loc[:,'Code'].isin(shp_BV_IV.loc[:,'Code'])]
shp_BV_IV = shp_BV_IV.loc[:, ['Code', 'S_km2', 'dt_pstn', 'geometry']]
bv_IV = df_BV_IV.merge(shp_BV_IV, on = 'Code', how = 'outer')
bv_IV = gpd.GeoDataFrame(bv_IV)
# bv_IV.to_file('C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/BV_IV.shp')
## Replacing problematic watersheds'geometry in final df
index_BV_Inv = complete_watersheds.loc[complete_watersheds.loc[:,'Code'].isin(bv_IV.loc[:,'Code'])].index
new_geometries = bv_IV.loc[:, ['Code', 'geometry']]
# for i in index_BV_Inv:
# print(i)
# geometry = bv_IV.loc[bv_IV.loc[:, 'Code'] == complete_watersheds.loc[i, 'Code']]
# print(geometry)
# # print(geometry.__dict__)
# complete_watersheds = complete_watersheds.loc[i,:].replace(geometry.__dict__)
# print(complete_watersheds.loc[i, 'geometry'])
# *************************** Create watersheds' shapefiles and rasters ************************************
# List of the stations'codes
watershed_code = complete_watersheds.loc[:,'Code']
# watershed_code_SAFRAN = complete_watersheds_noElle.loc[:,'Code']
watershed_code_IV = shp_BV_IV.loc[shp_BV_IV.loc[:,'Code'].isin(watershed_code)].loc[:, 'Code']
# Get a sample of them for test
code_for_test = watershed_code.loc[0:3]
# code_for_test = ['K9341810']
# code_for_test = ['J4742020']
## SHP and GEOL
# for i in code_for_test:
for i in watershed_code:
## Get shp
shpfile_contour_i = gpd.read_file(shp_foldername+i+'.shp')
# shpfile_contour_i = shp_contour[shp_contour.loc[:, 'Code'] == i]
# And save it in a file (identifier = its code)
# shpfile_contour_i.to_file('C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/GEOMETRY/'+i+'.shp')
## Get watershed's geologic properties and save them in file
# BDLisa
try:
shpfile_BDLisa = gpd.clip(BDLisa_shp, shpfile_contour_i)
except:
shpfile_BDLisa = gpd.overlay(BDLisa_shp, shpfile_contour_i)
shpfile_BDLisa.to_file('C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/GEOL/BDLisa/'+i+'_BDLisa.shp')
# BRGM geol
try:
shpfile_BRGM = gpd.clip(BRGM_shp, shpfile_contour_i)
except:
shpfile_BRGM = gpd.overlay(BRGM_shp, shpfile_contour_i)
shpfile_BRGM.to_file('C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/GEOL/BRGM/'+i+'_BRGM.shp')
## SAFRAN csv
# for i in code_for_test:
for i in watershed_code_IV:
## Get shp
shpfile_contour_i = complete_watersheds[complete_watersheds.loc[:, 'Code'] == i]
# shpfile_contour_i = bv_IV[bv_IV.loc[:, 'Code'] == i]
# And save it in a file (identifier = its code)
# shpfile_contour_i.to_file('C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/GEOMETRY/'+i+'.shp')
HCF = HydroClimaticFluxes(code = i)
HCF.intersect_safran_gpd_and_contour(ET0_gpd, shpfile_contour_i, 'ET0')
HCF.intersect_safran_gpd_and_contour(Tair_gpd, shpfile_contour_i, 'Tair')
HCF.intersect_safran_gpd_and_contour(Snow_gpd, shpfile_contour_i, 'Snow')
HCF.intersect_safran_gpd_and_contour(Rain_gpd, shpfile_contour_i, 'Rain')
HCF.safran_timeseries['Ptot'] = HCF.safran_timeseries['Snow'] + HCF.safran_timeseries['Rain']
# HCF.safran_timeseries.to_csv('C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/SAFRAN/'+i+'_safran_timeseries.csv', index=False)
# Test
safran_test = pd.read_csv('C:/Users/laura.lindeperg/Documents/DonneesLaura/Watersheds/SAFRAN/A1072010_safran_timeseries.csv', encoding='latin-1')