wolfhece 2.2.41__py3-none-any.whl → 2.2.43__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wolfhece/PyDraw.py +73 -19
- wolfhece/apps/version.py +1 -1
- wolfhece/mesh2d/wolf2dprev.py +45 -17
- wolfhece/models/walous_ocs.pal +49 -0
- wolfhece/pywalous.py +346 -141
- wolfhece/wolf_array.py +148 -78
- {wolfhece-2.2.41.dist-info → wolfhece-2.2.43.dist-info}/METADATA +1 -1
- {wolfhece-2.2.41.dist-info → wolfhece-2.2.43.dist-info}/RECORD +11 -10
- {wolfhece-2.2.41.dist-info → wolfhece-2.2.43.dist-info}/WHEEL +0 -0
- {wolfhece-2.2.41.dist-info → wolfhece-2.2.43.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.2.41.dist-info → wolfhece-2.2.43.dist-info}/top_level.txt +0 -0
wolfhece/pywalous.py
CHANGED
@@ -22,6 +22,125 @@ import wx.grid
|
|
22
22
|
|
23
23
|
from .PyTranslate import _
|
24
24
|
from .PyPalette import wolfpalette
|
25
|
+
from .wolf_array import WolfArray, header_wolf
|
26
|
+
|
27
|
+
|
28
|
+
"""
|
29
|
+
Hydrology classification for Land Use in Wallonia:
|
30
|
+
1 = forêt
|
31
|
+
2 = prairie
|
32
|
+
3 = culture
|
33
|
+
4 = pavés/urbain
|
34
|
+
5 = rivière
|
35
|
+
6 = plan d'eau
|
36
|
+
"""
|
37
|
+
|
38
|
+
HYDROLOGY_LANDUSE_FR = {"forêt" : 1.,
|
39
|
+
"prairie" : 2.,
|
40
|
+
"culture" : 3.,
|
41
|
+
"pavés/urbain" : 4.,
|
42
|
+
"rivière" : 5.,
|
43
|
+
"plan d'eau" : 6.,
|
44
|
+
}
|
45
|
+
|
46
|
+
HYDROLOGY_LANDUSE_EN = {"forest" : 1.,
|
47
|
+
"meadow" : 2.,
|
48
|
+
"crop" : 3.,
|
49
|
+
"paved/urban" : 4.,
|
50
|
+
"river" : 5.,
|
51
|
+
"water body" : 6.,
|
52
|
+
}
|
53
|
+
|
54
|
+
# WALOUS OCS
|
55
|
+
# ----------
|
56
|
+
|
57
|
+
"""
|
58
|
+
Extrait de https://metawal.wallonie.be/geonetwork/srv/api/records/86462606-4a21-49c8-ab9e-564ccba681b7/attachments/DescriptionLegende_WALOUS_OCS.pdf
|
59
|
+
|
60
|
+
1. Revêtement artificiel du sol: cette classe reprend tous les revêtements artificiels du sol
|
61
|
+
de nature peu ou pas perméable (ex béton, le bitume ou les pavés). Ceci comprend le réseau routier, les trottoirs, les terrasses, les parkings (les emplacements de parking semiperméables non végétalisés sont également dans cette catégorie) et les terrains ou pistes de sport en matériaux synthétiques.
|
62
|
+
2. Constructions artificielles hors sol : cette classe reprend tous les bâtiments et autres constructions s'élevant au-dessus du sol.
|
63
|
+
3. Réseau ferroviaire : cette classe reprend les rails et ballasts des chemins de fer encore en activité (les RaVEL entre dans la classe 1). Cette classe se différencie de la classe 1 par sa grande perméabilité.
|
64
|
+
4. Sols nus : cette classe inclut tout type de roche mère n'étant couverte par des végétaux supérieurs à aucun moment de l'année. Ces sols sont soit naturels (roches affleurantes, falaises, berges caillouteuses…), soit générés par l'activité humaine (extraction, sols compactés, coupe à blanc de l'année…)
|
65
|
+
5. Eaux de surface : cette classe comprend toutes les surfaces d'eau libre, naturelles ou artificielles. Ceci inclut donc à la fois les cours d'eau (rivières, fleuves et canaux) et les plans d'eau (mares, étangs, lacs, bassins de décantation, piscines extérieures).
|
66
|
+
6. Couvert herbacé en rotation : cette classe reprend les parcelles combinant un couvert herbacé une partie de l'année et un sol nu temporairement mis à nu. On y retrouve toutes les cultures annuelles, ainsi que les prairies temporaires succédant à une culture annuelle.
|
67
|
+
7. Couvert herbacé continu : cette classe reprend tous les sols recouverts par de la végétation herbacée tout au long de l'année. Cette végétation peut être d'origine naturelle (landes, mégaphorbiaies, tourbières, pelouses naturelles, végétation rudérale recolonisant une friche ou une ancienne coupe à blanc…), agricole (prés et prairies non labourés dans la saison) ou artificielle (jardin, terrains de sport, parcs…)
|
68
|
+
8. Arbres résineux : cette classe comprend tous les arbres de plus de 3 m (isolés, en haie ou en peuplement) du groupe des résineux (gymnosperme).
|
69
|
+
9. Arbres feuillus : cette classe comprend tous les arbres de plus de 3 m (isolés, en haie ou en peuplement) du groupe des feuillus (angiosperme).
|
70
|
+
80. Arbustes résineux : cette classe comprend tous les arbres et arbustes de moins de 3 m (isolés, en haie ou en peuplement) du groupe des résineux (gymnosperme).
|
71
|
+
90. Arbustes feuillus : cette classe comprend tous les arbres et arbuste de moins de 3 m (isolés, en haie ou en peuplement) du groupe des feuillus (angiosperme).
|
72
|
+
|
73
|
+
|
74
|
+
<paletteEntry color="#8a8a8a" value="1" alpha="255" label="Revêtement artificiel au sol"/>
|
75
|
+
<paletteEntry color="#dc0f0f" value="2" alpha="255" label="Constructions artificielles hors sol"/>
|
76
|
+
<paletteEntry color="#4e4e4e" value="3" alpha="255" label="Réseau ferroviaire"/>
|
77
|
+
<paletteEntry color="#d0d0d0" value="4" alpha="255" label="Sols nus"/>
|
78
|
+
<paletteEntry color="#2461f7" value="5" alpha="255" label="Eaux de surface"/>
|
79
|
+
<paletteEntry color="#ffff73" value="6" alpha="255" label="Couvert herbacé en rotation dans l'année (ex: culture annuelle)"/>
|
80
|
+
<paletteEntry color="#e9ffbe" value="7" alpha="255" label="Couvert herbacé toute l'année"/>
|
81
|
+
<paletteEntry color="#003200" value="8" alpha="255" label="Résineux (> 3m)"/>
|
82
|
+
<paletteEntry color="#007800" value="80" alpha="255" label="Résineux (≤ 3m)"/>
|
83
|
+
<paletteEntry color="#28c828" value="9" alpha="255" label="Feuillus (> 3m)"/>
|
84
|
+
<paletteEntry color="#b7e8b0" value="90" alpha="255" label="Feuillus (≤ 3m)"/>
|
85
|
+
<paletteEntry color="#e5ea3f" value="0" alpha="0" label="Pas de données"/>
|
86
|
+
"""
|
87
|
+
|
88
|
+
WALOUS_OCS = { "Revêtement artificiel au sol": 1.,
|
89
|
+
"Constructions artificielles hors sol": 2.,
|
90
|
+
"Réseau ferroviaire": 3.,
|
91
|
+
"Sols nus": 4.,
|
92
|
+
"Eaux de surface": 5.,
|
93
|
+
"Couvert herbacé en rotation dans l'année": 6.,
|
94
|
+
"Couvert herbacé toute l'année": 7.,
|
95
|
+
"Arbres résineux (>= 3m)": 8.,
|
96
|
+
"Arbres feuillus (>= 3m)": 9.,
|
97
|
+
"Arbustes résineux (< 3m)": 80.,
|
98
|
+
"Arbustes feuillus (< 3m)": 90.}
|
99
|
+
|
100
|
+
WALOUS_OCS_COLORMAP = {
|
101
|
+
0.: (229, 234, 63, 0), # #e5ea3f Pas de données
|
102
|
+
1.: (138, 138, 138, 255), # #8a8a8a Revêtement artificiel au sol
|
103
|
+
2.: (220, 15, 15, 255), # #dc0f0f Constructions artificielles hors sol
|
104
|
+
3.: (78, 78, 78, 255), # #4e4e4e Réseau ferroviaire
|
105
|
+
4.: (208, 208, 208, 255), # #d0d0d0 Sols nus
|
106
|
+
5.: (36, 97, 247, 255), # #2461f7 Eaux de surface
|
107
|
+
6.: (255, 255, 115, 255), # #ffff73 Couvert herbacé en rotation
|
108
|
+
7.: (233, 255, 190, 255), # #e9ffbe Couvert herbacé continu
|
109
|
+
8.: (0, 50, 0, 255), # #003200 Arbres résineux (> 3m)
|
110
|
+
9.: (40, 200, 40, 255), # #28c828 Arbres feuillus (> 3m)
|
111
|
+
80.: (0, 120, 0, 255), # #007800 Arbustes résineux (≤ 3m)
|
112
|
+
90.: (183, 232, 176, 255), # #b7e8b0 Arbustes feuillus (≤ 3m)
|
113
|
+
}
|
114
|
+
|
115
|
+
WALOUS_OCS2MANNING = {1.: 0.02, # Revêtement artificiel au sol
|
116
|
+
2.: 0.025, # Constructions artificielles hors sol
|
117
|
+
3.: 0.04, # Réseau ferroviaire
|
118
|
+
4.: 0.04, # Sols nus
|
119
|
+
5.: 0.033, # Eaux de surface
|
120
|
+
6.: 0.04, # Couvert herbacé en rotation dans l'année
|
121
|
+
7.: 0.03, # Couvert herbacé toute l'année
|
122
|
+
8.: 0.04, # Résineux (> 3m)
|
123
|
+
9.: 0.04, # Feuillus (> 3m)
|
124
|
+
80.: 0.03, # Résineux (≤ 3m)
|
125
|
+
90.: 0.03, # Feuillus (≤ 3m)
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
WALOUS_OCS2HYDROLOGY = {1.: 4., # Revêtement artificiel au sol
|
130
|
+
2.: 4., # Constructions artificielles hors sol
|
131
|
+
3.: 4., # Réseau ferroviaire
|
132
|
+
4.: 4., # Sols nus
|
133
|
+
5.: 5., # Eaux de surface
|
134
|
+
6.: 3., # Couvert herbacé en rotation dans l'année
|
135
|
+
7.: 2., # Couvert herbacé toute l'année
|
136
|
+
8.: 1., # Résineux (> 3m)
|
137
|
+
9.: 1., # Feuillus (> 3m)
|
138
|
+
80.: 3., # Arbustes résineux (< 3m)
|
139
|
+
90.: 3. # Arbustes feuillus (< 3m)
|
140
|
+
}
|
141
|
+
|
142
|
+
# WALOUS UTS
|
143
|
+
# ----------
|
25
144
|
|
26
145
|
WALOUS_UTS_MAJ_NIV1 = {'Production primaire': 1.,
|
27
146
|
'Production secondaire': 2.,
|
@@ -85,59 +204,37 @@ WALOUS_UTS_COLORMAP_MAJ_NIV2 = {11.: (153,230,0,255),
|
|
85
204
|
66.: (206,136,102,255),
|
86
205
|
70.: (255,255,190,255)}
|
87
206
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
"Eaux de surface": 8.,
|
96
|
-
"Revêtement artificiels au sol": 9.,
|
97
|
-
"Réseau ferroviaire": 10.,
|
98
|
-
"Constructions artificielles hors sol": 11.}
|
99
|
-
|
100
|
-
WALOUS_OCS_COLORMAP = {1.: (255,254,162,255), # Couvert herbacé en rotation dans l'année
|
101
|
-
2.: (253,254,194,255), # Couvert herbacé toute l'année
|
102
|
-
3.: (3,49,5,255), # Résineux (>3 m)
|
103
|
-
4.: (55,198,61,255), # Feuillus (> 3m)
|
104
|
-
5.: (18,119,23,255), # Résineux (<= 3m)
|
105
|
-
6.: (185,231,179,255), # Feuillus (<= 3m)
|
106
|
-
7.: (208,208,208,255), # Sols nus
|
107
|
-
8.: (45,101,242,255), # Eaux de surface
|
108
|
-
9.: (138,138,138,255), # Revêtement artificiels au sol
|
109
|
-
10.: (78,78,78,255), # Réseau ferroviaire
|
110
|
-
11.: (199,22,19,255), # Constructions artificielles hors sol
|
111
|
-
}
|
112
|
-
|
113
|
-
HYDROLOGY_LANDUSE_FR = {"forêt" : 1.,
|
114
|
-
"prairie" : 2.,
|
115
|
-
"culture" : 3.,
|
116
|
-
"pavés/urbain" : 4.,
|
117
|
-
"rivière" : 5.,
|
118
|
-
"plan d'eau" : 6.,
|
119
|
-
}
|
207
|
+
WALOUS_UTS2MANNING_MAJ_NIV1 = {1.: 0.04, # Production primaire
|
208
|
+
2.: 0.02, # Production secondaire
|
209
|
+
3.: 0.02, # Production tertiaire
|
210
|
+
4.: 0.03, # Réseaux de transport, Logistique et réseaux d'utilité publique
|
211
|
+
5.: 0.025,# Usage résidentiel
|
212
|
+
6.: 0.04, # Autres usages
|
213
|
+
7.: 0.05} # Zones naturelles
|
120
214
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
215
|
+
WALOUS_UTS2MANNING_MAJ_NIV2 = {11.: 0.04, # Agriculture
|
216
|
+
12.: 0.04, # Sylviculture
|
217
|
+
13.: 0.04, # Industries Extractives
|
218
|
+
14.: 0.04, # Aquaculture et pêche
|
219
|
+
20.: 0.03, # Production secondaire non définie
|
220
|
+
21.: 0.03, # Industrie de matières premières
|
221
|
+
22.: 0.03, # Industrie lourde
|
222
|
+
23.: 0.03, # Industrie légère
|
223
|
+
24.: 0.03, # Production d'énergie
|
224
|
+
31.: 0.02, # Service commerciaux
|
225
|
+
32.: 0.02, # Services financiers, spécialisés et d'information
|
226
|
+
33.: 0.02, # Services publics
|
227
|
+
34.: 0.02, # Services culturels, Services de loisirs et Services récréatifs
|
228
|
+
41.: 0.025, # Réseaux de transport
|
229
|
+
42.: 0.02, # Services Logistiques et d'entreposage
|
230
|
+
43.: 0.025, # Réseau d'utilité publique
|
231
|
+
51.: 0.025, # Usage résidentiel permanent
|
232
|
+
52.: 0.025, # Usage résidentiel avec d'autres usages compatibles
|
233
|
+
53.: 0.025, # Autres usages résidentiels
|
234
|
+
62.: 0.04, # Zones abandonnées
|
235
|
+
66.: 0.04, # Usage inconnu
|
236
|
+
70.: 0.05} # Zones naturelles
|
128
237
|
|
129
|
-
MAPPING_WALOUS_TO_HYDROLOGY = {1.: 2., # Couvert herbacé en rotation dans l'année
|
130
|
-
2.: 2., # Couvert herbacé toute l'année
|
131
|
-
3.: 1., # Résineux (>3 m)
|
132
|
-
4.: 1., # Feuillus (> 3m)
|
133
|
-
5.: 3., # Résineux (<= 3m)
|
134
|
-
6.: 3., # Feuillus (<= 3m)
|
135
|
-
7.: 3., # Sols nus
|
136
|
-
8.: 5., # Eaux de surface
|
137
|
-
9.: 4., # Revêtement artificiels au sol
|
138
|
-
10.: 4., # Constructions artificielles hors sol
|
139
|
-
11.: 4., # Réseau ferroviaire
|
140
|
-
}
|
141
238
|
|
142
239
|
def get_palette_walous_uts(which:Literal['MAJ_NIV1', 'MAJ_NIV2']) -> wolfpalette:
|
143
240
|
"""
|
@@ -177,7 +274,7 @@ def get_palette_walous_ocs() -> wolfpalette:
|
|
177
274
|
|
178
275
|
return locpal
|
179
276
|
|
180
|
-
def update_palette_walous_uts(which:Literal['
|
277
|
+
def update_palette_walous_uts(which:Literal['UTS_MAJ_NIV1', 'UTS_MAJ_NIV2'], pal:wolfpalette):
|
181
278
|
"""
|
182
279
|
Update the palette for WALOUS MAJ_NIV1
|
183
280
|
|
@@ -185,13 +282,13 @@ def update_palette_walous_uts(which:Literal['MAJ_NIV1', 'MAJ_NIV2'], pal:wolfpal
|
|
185
282
|
:return : updated palette
|
186
283
|
"""
|
187
284
|
|
188
|
-
if which
|
285
|
+
if which in ['UTS_MAJ_NIV1', 'MAJ_NIV1']:
|
189
286
|
for k, v in WALOUS_UTS_COLORMAP_MAJ_NIV1.items():
|
190
|
-
pal.set_values_colors(values = list(WALOUS_UTS_MAJ_NIV1.values()),
|
287
|
+
pal.set_values_colors(values = [val - 1e-6 for val in list(WALOUS_UTS_MAJ_NIV1.values())],
|
191
288
|
colors = list(WALOUS_UTS_COLORMAP_MAJ_NIV1.values()))
|
192
|
-
elif which
|
289
|
+
elif which in ['UTS_MAJ_NIV2', 'MAJ_NIV2']:
|
193
290
|
for k, v in WALOUS_UTS_COLORMAP_MAJ_NIV2.items():
|
194
|
-
pal.set_values_colors(values = list(WALOUS_UTS_MAJ_NIV2.values()),
|
291
|
+
pal.set_values_colors(values = [val - 1e-6 for val in list(WALOUS_UTS_MAJ_NIV2.values())],
|
195
292
|
colors = list(WALOUS_UTS_COLORMAP_MAJ_NIV2.values()))
|
196
293
|
|
197
294
|
pal.interval_cst = True
|
@@ -208,7 +305,7 @@ def update_palette_walous_ocs(pal:wolfpalette):
|
|
208
305
|
"""
|
209
306
|
|
210
307
|
for k, v in WALOUS_OCS_COLORMAP.items():
|
211
|
-
pal.set_values_colors(values = list(WALOUS_OCS_COLORMAP.keys()),
|
308
|
+
pal.set_values_colors(values = [val - 1e-6 for val in list(WALOUS_OCS_COLORMAP.keys())],
|
212
309
|
colors = list(WALOUS_OCS_COLORMAP.values()))
|
213
310
|
|
214
311
|
pal.interval_cst = True
|
@@ -217,71 +314,6 @@ def update_palette_walous_ocs(pal:wolfpalette):
|
|
217
314
|
return 0
|
218
315
|
|
219
316
|
|
220
|
-
WALOUS2MANNING_MAJ_NIV1 = {1.: 0.04, # Production primaire
|
221
|
-
2.: 0.02, # Production secondaire
|
222
|
-
3.: 0.02, # Production tertiaire
|
223
|
-
4.: 0.03, # Réseaux de transport, Logistique et réseaux d'utilité publique
|
224
|
-
5.: 0.025,# Usage résidentiel
|
225
|
-
6.: 0.04, # Autres usages
|
226
|
-
7.: 0.05} # Zones naturelles
|
227
|
-
|
228
|
-
WALOUS2MANNING_MAJ_NIV2 = {11.: 0.04, # Agriculture
|
229
|
-
12.: 0.04, # Sylviculture
|
230
|
-
13.: 0.04, # Industries Extractives
|
231
|
-
14.: 0.04, # Aquaculture et pêche
|
232
|
-
20.: 0.03, # Production secondaire non définie
|
233
|
-
21.: 0.03, # Industrie de matières premières
|
234
|
-
22.: 0.03, # Industrie lourde
|
235
|
-
23.: 0.03, # Industrie légère
|
236
|
-
24.: 0.03, # Production d'énergie
|
237
|
-
31.: 0.02, # Service commerciaux
|
238
|
-
32.: 0.02, # Services financiers, spécialisés et d'information
|
239
|
-
33.: 0.02, # Services publics
|
240
|
-
34.: 0.02, # Services culturels, Services de loisirs et Services récréatifs
|
241
|
-
41.: 0.025, # Réseaux de transport
|
242
|
-
42.: 0.02, # Services Logistiques et d'entreposage
|
243
|
-
43.: 0.025, # Réseau d'utilité publique
|
244
|
-
51.: 0.025, # Usage résidentiel permanent
|
245
|
-
52.: 0.025, # Usage résidentiel avec d'autres usages compatibles
|
246
|
-
53.: 0.025, # Autres usages résidentiels
|
247
|
-
62.: 0.04, # Zones abandonnées
|
248
|
-
66.: 0.04, # Usage inconnu
|
249
|
-
70.: 0.05} # Zones naturelles
|
250
|
-
|
251
|
-
WALOUSOCS2MANNING = {1.: 0.04, # Couvert herbacé en rotation dans l'année
|
252
|
-
2.: 0.04, # Couvert herbacé toute l'année
|
253
|
-
3.: 0.04, # Résineux (>3 m)
|
254
|
-
4.: 0.04, # Feuillus (> 3m)
|
255
|
-
5.: 0.04, # Résineux (<= 3m)
|
256
|
-
6.: 0.04, # Feuillus (<= 3m)
|
257
|
-
7.: 0.02, # Sols nus
|
258
|
-
8.: 0.033, # Eaux de surface
|
259
|
-
9.: 0.02, # Revêtement artificiels au sol
|
260
|
-
10.: 0.02, # Réseau ferroviaire
|
261
|
-
11.: 0.02} # Constructions artificielles hors sol
|
262
|
-
|
263
|
-
"""
|
264
|
-
Hydrology classification for Land Use in Wallonia:
|
265
|
-
1 = forêt
|
266
|
-
2 = prairie
|
267
|
-
3 = culture
|
268
|
-
4 = pavés/urbain
|
269
|
-
5 = rivière
|
270
|
-
6 = plan d'eau
|
271
|
-
"""
|
272
|
-
WALOUS2HYDROLOGY = {1.: 2, # Couvert herbacé en rotation dans l'année
|
273
|
-
2.: 2, # Couvert herbacé toute l'année
|
274
|
-
3.: 1, # Résineux (>3 m)
|
275
|
-
4.: 1, # Feillus (> 3m)
|
276
|
-
5.: 3, # Résineux (<= 3m)
|
277
|
-
6.: 3, # Feuillus (<= 3m)
|
278
|
-
7.: 4, # Sols nus
|
279
|
-
8.: 5, # Eaux de surface
|
280
|
-
9.: 4, # Revêtement artificiels au sol
|
281
|
-
10.: 4, # Réseau ferroviaire
|
282
|
-
11.: 4, # Constructions artificielles hors sol
|
283
|
-
}
|
284
|
-
|
285
317
|
class Walous_data():
|
286
318
|
"""
|
287
319
|
La donnée Walous est liée à l'utilisation des sols en Wallonie
|
@@ -297,18 +329,21 @@ class Walous_data():
|
|
297
329
|
def __init__(self,
|
298
330
|
dir_data:str = '',
|
299
331
|
fn:str = 'WAL_UTS__2018_L72',
|
332
|
+
extension:str = '.shp',
|
300
333
|
bounds:Union[list[float, float, float, float],list[list[float, float], list[float, float]]] = None) -> None:
|
301
334
|
"""
|
302
335
|
Constructor
|
303
336
|
|
304
337
|
:param dir_data : directory of the data
|
305
|
-
:param fn : filename without extension
|
338
|
+
:param fn : filename without extension
|
339
|
+
:param extension : extension of the file (.shp, .gpkg, ...)
|
306
340
|
:param bounds : Two ways to set spatial bounds -- [xmin, ymin, xmax, ymax] or [[xmin, xmax], [ymin, ymax]]
|
307
341
|
|
308
342
|
"""
|
309
343
|
|
310
|
-
self._dir = dir_data # directory of the data
|
311
|
-
self._fn = fn # filename without extension
|
344
|
+
self._dir = str(dir_data) # directory of the data
|
345
|
+
self._fn = str(fn) # filename without extension
|
346
|
+
self._extension = extension # extension of the file
|
312
347
|
self._gdf = None # geopandas dataframe
|
313
348
|
|
314
349
|
if bounds is not None:
|
@@ -328,7 +363,7 @@ class Walous_data():
|
|
328
363
|
if self._gdf is None or force:
|
329
364
|
assert self._dir!="" and self._fn != ''
|
330
365
|
|
331
|
-
filepath = (Path(self._dir)/ self._fn).with_suffix(
|
366
|
+
filepath = (Path(self._dir)/ self._fn).with_suffix(self._extension)
|
332
367
|
|
333
368
|
if filepath.exists():
|
334
369
|
if bounds is not None:
|
@@ -369,6 +404,8 @@ class Walous_data():
|
|
369
404
|
|
370
405
|
chdir(detsdir)
|
371
406
|
|
407
|
+
fnout = str((Path(fnout)).with_suffix(self._extension))
|
408
|
+
|
372
409
|
self._gdf.to_file(basename(fnout))
|
373
410
|
|
374
411
|
chdir(curdir)
|
@@ -390,15 +427,15 @@ class Walous_data():
|
|
390
427
|
|
391
428
|
def rasterize(self,
|
392
429
|
bounds:Union[list[float, float, float, float],list[list[float, float], list[float, float]]],
|
393
|
-
layer:Literal['
|
430
|
+
layer:Literal['UTS_MAJ_NIV1','UTS_MAJ_NIV2'] = 'UTS_MAJ_NIV1',
|
394
431
|
fn_out:str = 'out.tif',
|
395
432
|
pixel_size:float = 0.5,
|
396
433
|
NoData_value:float = -99999.,
|
397
|
-
num_type = gdal.GDT_Float32
|
434
|
+
num_type = gdal.GDT_Float32,
|
398
435
|
):
|
399
436
|
|
400
437
|
"""
|
401
|
-
Rasterization of polygon data to tif
|
438
|
+
Rasterization of polygon data to tif.
|
402
439
|
|
403
440
|
:param bounds : [xmin, ymin, xmax, ymax] or [[xmin, xmax], [ymin, ymax]]
|
404
441
|
:param layer : layer to rasterize
|
@@ -408,6 +445,8 @@ class Walous_data():
|
|
408
445
|
:param num_type : type of the number
|
409
446
|
"""
|
410
447
|
|
448
|
+
layer = layer.upper().replace('UTS_', '')
|
449
|
+
|
411
450
|
if bounds is None:
|
412
451
|
logging.error('Bounds must be set')
|
413
452
|
return None
|
@@ -438,10 +477,10 @@ class Walous_data():
|
|
438
477
|
try:
|
439
478
|
|
440
479
|
# Add a new column for mapping based on the desired layer
|
441
|
-
self._gdf['Mapping'] = np.float32(self._gdf[layer])
|
442
|
-
|
443
480
|
if layer == 'MAJ_NIV2':
|
444
|
-
self._gdf['Mapping'] = np.float32(self._gdf[
|
481
|
+
self._gdf['Mapping'] = np.float32(self._gdf[layer].replace('_', ''))
|
482
|
+
else:
|
483
|
+
self._gdf['Mapping'] = np.float32(self._gdf[layer])
|
445
484
|
|
446
485
|
source_ds:ogr.DataSource
|
447
486
|
source_layer:ogr.Layer
|
@@ -485,7 +524,7 @@ class Walous_data():
|
|
485
524
|
class DlgMapWalous2Manning(wx.Dialog):
|
486
525
|
""" Modal dialog for mapping WALOUS value to another ones """
|
487
526
|
|
488
|
-
def __init__(self, parent, title:str = _("Mapping WALOUS value to ..."), which:
|
527
|
+
def __init__(self, parent, title:str = _("Mapping WALOUS value to ..."), which:Literal['UTS_MAJ_NIV1', 'UTS_MAJ_NIV2', 'OCS_MANNING', 'OCS_HYDROLOGY'] = 'UTS_MAJ_NIV1'):
|
489
528
|
|
490
529
|
super(DlgMapWalous2Manning, self).__init__(parent, title=title, size=(450, 400))
|
491
530
|
|
@@ -495,7 +534,7 @@ class DlgMapWalous2Manning(wx.Dialog):
|
|
495
534
|
|
496
535
|
self._table = wx.grid.Grid(panel)
|
497
536
|
|
498
|
-
if which == '
|
537
|
+
if which == 'UTS_MAJ_NIV1':
|
499
538
|
self._table.CreateGrid(len(WALOUS_UTS_MAJ_NIV1), 3)
|
500
539
|
self._table.SetColLabelValue(0, _("Name"))
|
501
540
|
self._table.SetColLabelValue(1, _("Value - UTS"))
|
@@ -505,11 +544,11 @@ class DlgMapWalous2Manning(wx.Dialog):
|
|
505
544
|
for i, (k, v) in enumerate(WALOUS_UTS_MAJ_NIV1.items()):
|
506
545
|
self._table.SetCellValue(i, 0, str(k))
|
507
546
|
self._table.SetCellValue(i, 1, str(v))
|
508
|
-
self._table.SetCellValue(i, 2, str(
|
547
|
+
self._table.SetCellValue(i, 2, str(WALOUS_UTS2MANNING_MAJ_NIV1[v]))
|
509
548
|
self._table.SetCellAlignment(i, 1, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
|
510
549
|
self._table.SetCellAlignment(i, 2, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
|
511
550
|
|
512
|
-
elif which == '
|
551
|
+
elif which == 'UTS_MAJ_NIV2':
|
513
552
|
self._table.CreateGrid(len(WALOUS_UTS_MAJ_NIV2), 3)
|
514
553
|
self._table.SetColLabelValue(0, _("Name"))
|
515
554
|
self._table.SetColLabelValue(1, _("Value - UTS"))
|
@@ -519,7 +558,33 @@ class DlgMapWalous2Manning(wx.Dialog):
|
|
519
558
|
for i, (k, v) in enumerate(WALOUS_UTS_MAJ_NIV2.items()):
|
520
559
|
self._table.SetCellValue(i, 0, str(k))
|
521
560
|
self._table.SetCellValue(i, 1, str(v))
|
522
|
-
self._table.SetCellValue(i, 2, str(
|
561
|
+
self._table.SetCellValue(i, 2, str(WALOUS_UTS2MANNING_MAJ_NIV2[v]))
|
562
|
+
self._table.SetCellAlignment(i, 1, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
|
563
|
+
self._table.SetCellAlignment(i, 2, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
|
564
|
+
|
565
|
+
elif which == 'OCS_MANNING':
|
566
|
+
self._table.CreateGrid(len(WALOUS_OCS2MANNING), 3)
|
567
|
+
self._table.SetColLabelValue(0, _("Name"))
|
568
|
+
self._table.SetColLabelValue(1, _("Value - OCS"))
|
569
|
+
self._table.SetColLabelValue(2, _("Manning 'n'"))
|
570
|
+
self._table.HideRowLabels()
|
571
|
+
for i, (k, v) in enumerate(WALOUS_OCS.items()):
|
572
|
+
self._table.SetCellValue(i, 0, str(k))
|
573
|
+
self._table.SetCellValue(i, 1, str(v))
|
574
|
+
self._table.SetCellValue(i, 2, str(WALOUS_OCS2MANNING[v]))
|
575
|
+
self._table.SetCellAlignment(i, 1, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
|
576
|
+
self._table.SetCellAlignment(i, 2, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
|
577
|
+
|
578
|
+
elif which == 'OCS_HYDROLOGY':
|
579
|
+
self._table.CreateGrid(len(WALOUS_OCS2HYDROLOGY), 3)
|
580
|
+
self._table.SetColLabelValue(0, _("Name"))
|
581
|
+
self._table.SetColLabelValue(1, _("Value - OCS"))
|
582
|
+
self._table.SetColLabelValue(2, _("LandUse - Hydrology"))
|
583
|
+
self._table.HideRowLabels()
|
584
|
+
for i, (k, v) in enumerate(WALOUS_OCS2HYDROLOGY.items()):
|
585
|
+
self._table.SetCellValue(i, 0, str(k))
|
586
|
+
self._table.SetCellValue(i, 1, str(v))
|
587
|
+
self._table.SetCellValue(i, 2, str(WALOUS_OCS2HYDROLOGY[v]))
|
523
588
|
self._table.SetCellAlignment(i, 1, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
|
524
589
|
self._table.SetCellAlignment(i, 2, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
|
525
590
|
|
@@ -575,11 +640,11 @@ class DlgMapWalousOCS2Manning(DlgMapWalous2Manning):
|
|
575
640
|
|
576
641
|
def __init__(self, parent, title:str = _("Mapping WALOUS value to ...")):
|
577
642
|
|
578
|
-
super(DlgMapWalousOCS2Manning, self).__init__(parent, title= title)
|
643
|
+
super(DlgMapWalousOCS2Manning, self).__init__(parent, title= title, which='OCS_MANNING')
|
579
644
|
|
580
645
|
self._table.SetColLabelValue(2, _("Land Use - OCS"))
|
581
646
|
|
582
|
-
for i, (k, v) in enumerate(
|
647
|
+
for i, (k, v) in enumerate(WALOUS_OCS2MANNING.items()):
|
583
648
|
self._table.SetColLabelValue(1, _("Value - OCS"))
|
584
649
|
self._table.SetCellValue(i, 2, str(v))
|
585
650
|
|
@@ -593,11 +658,11 @@ class DlgMapWalous2Hydrology(DlgMapWalous2Manning):
|
|
593
658
|
|
594
659
|
def __init__(self, parent, title:str = _("Mapping WALOUS value to ...")):
|
595
660
|
|
596
|
-
super(DlgMapWalous2Hydrology, self).__init__(parent, title= title)
|
661
|
+
super(DlgMapWalous2Hydrology, self).__init__(parent, title= title, which='OCS_HYDROLOGY')
|
597
662
|
|
598
663
|
self._table.SetColLabelValue(2, _("Land Use - OCS"))
|
599
664
|
|
600
|
-
for i, (k, v) in enumerate(
|
665
|
+
for i, (k, v) in enumerate(WALOUS_OCS2HYDROLOGY.items()):
|
601
666
|
self._table.SetColLabelValue(1, _("Value - OCS"))
|
602
667
|
self._table.SetCellValue(i, 2, str(v))
|
603
668
|
|
@@ -692,3 +757,143 @@ class Walous_OCS_Legend(wx.Dialog):
|
|
692
757
|
|
693
758
|
def close(self):
|
694
759
|
self.Destroy()
|
760
|
+
|
761
|
+
|
762
|
+
def get_array_WALOUS_OCS(fname:Path, spatial_res:float, bounds:Union[list[float, float, float, float],list[list[float, float], list[float, float]]]) -> Union[WolfArray, None]:
|
763
|
+
""" Get WALOUS OCS as WolfArray
|
764
|
+
|
765
|
+
:param fname: path to the WALOUS OCS file
|
766
|
+
:param spatial_res: desired spatial resolution (in m)
|
767
|
+
:param bounds: [xmin, ymin, xmax, ymax] or [[xmin, xmax], [ymin, ymax]]
|
768
|
+
:return: WolfArray or None if error
|
769
|
+
"""
|
770
|
+
|
771
|
+
if not fname.exists():
|
772
|
+
logging.error(_('WALOUS OCS file not found: {}').format(fname))
|
773
|
+
return None
|
774
|
+
|
775
|
+
# Convert bounds to [[xmin, xmax], [ymin, ymax]] if needed
|
776
|
+
if len(bounds)==4:
|
777
|
+
bounds = [[bounds[0], bounds[2]], [bounds[1], bounds[3]]]
|
778
|
+
|
779
|
+
# Convert bvounds to list to be able to modify it
|
780
|
+
bounds = [list(bounds[0]), list(bounds[1])]
|
781
|
+
|
782
|
+
bounds_copy = [list(bounds[0]), list(bounds[1])]
|
783
|
+
|
784
|
+
header_OCS = header_wolf.read_header(fname)
|
785
|
+
if header_OCS.dx != spatial_res:
|
786
|
+
# Adapt bounds to ensure that the rebin will be correct.
|
787
|
+
# If spatial_res is a multiple of header_OCS.dx, no need to change bounds.
|
788
|
+
# If not, change the bounds to ensure that the crop will include data in all footprints.
|
789
|
+
|
790
|
+
if (bounds[0][0] - header_OCS.origx) % header_OCS.dx != 0:
|
791
|
+
bounds[0][0] = header_OCS.origx + ((bounds[0][0] - header_OCS.origx) // header_OCS.dx) * header_OCS.dx
|
792
|
+
if (bounds[0][1] - bounds[0][0]) % header_OCS.dx != 0:
|
793
|
+
bounds[0][1] = bounds[0][0] + ((bounds[0][1] - bounds[0][0]) // header_OCS.dx + 1) * header_OCS.dx
|
794
|
+
if (bounds[1][0] - header_OCS.origy) % header_OCS.dy != 0:
|
795
|
+
bounds[1][0] = header_OCS.origy + ((bounds[1][0] - header_OCS.origy) // header_OCS.dy) * header_OCS.dy
|
796
|
+
if (bounds[1][1] - bounds[1][0]) % header_OCS.dy != 0:
|
797
|
+
bounds[1][1] = bounds[1][0] + ((bounds[1][1] - bounds[1][0]) // header_OCS.dy + 1) * header_OCS.dy
|
798
|
+
|
799
|
+
locwalous = WolfArray(fname=fname, crop = [bounds[0][0], bounds[0][1], bounds[1][0], bounds[1][1]])
|
800
|
+
|
801
|
+
if locwalous.dx != spatial_res:
|
802
|
+
locwalous.rebin(spatial_res / locwalous.dx, operation='min')
|
803
|
+
logging.info(_('Rebin to {} m because original data are {} m').format(spatial_res, locwalous.dx))
|
804
|
+
locwalous = WolfArray(mold=locwalous, crop = bounds_copy)
|
805
|
+
|
806
|
+
return locwalous
|
807
|
+
|
808
|
+
def get_array_WALOUS_OCS_2023_10m(spatial_res:float, bounds:Union[list[float, float, float, float],list[list[float, float], list[float, float]]]) -> Union[WolfArray, None]:
|
809
|
+
""" Get WALOUS OCS 2023 as WolfArray
|
810
|
+
|
811
|
+
:param spatial_res: desired spatial resolution (in m)
|
812
|
+
:param bounds: [xmin, ymin, xmax, ymax] or [[xmin, xmax], [ymin, ymax]]
|
813
|
+
:return: WolfArray or None if error
|
814
|
+
"""
|
815
|
+
|
816
|
+
from wolfhece.pydownloader import toys_dataset
|
817
|
+
|
818
|
+
fname = toys_dataset(dir='Walous_OCS', file='WALOUS_2023_lbt72_10m.tif')
|
819
|
+
|
820
|
+
return get_array_WALOUS_OCS(fname, spatial_res, bounds)
|
821
|
+
|
822
|
+
def get_array_WALOUS_OCS_2023_4m(spatial_res:float, bounds:Union[list[float, float, float, float],list[list[float, float], list[float, float]]]) -> Union[WolfArray, None]:
|
823
|
+
""" Get WALOUS OCS 2023 as WolfArray
|
824
|
+
|
825
|
+
:param spatial_res: desired spatial resolution (in m)
|
826
|
+
:param bounds: [xmin, ymin, xmax, ymax] or [[xmin, xmax], [ymin, ymax]]
|
827
|
+
:return: WolfArray or None if error
|
828
|
+
"""
|
829
|
+
|
830
|
+
from wolfhece.pydownloader import toys_dataset
|
831
|
+
|
832
|
+
fname = toys_dataset(dir='Walous_OCS', file='WALOUS_2023_lbt72_4m.tif')
|
833
|
+
|
834
|
+
return get_array_WALOUS_OCS(fname, spatial_res, bounds)
|
835
|
+
|
836
|
+
def get_array_WALOUS_OCS_2020_10m(spatial_res:float, bounds:Union[list[float, float, float, float],list[list[float, float], list[float, float]]]) -> Union[WolfArray, None]:
|
837
|
+
""" Get WALOUS OCS 2020 as WolfArray
|
838
|
+
|
839
|
+
:param spatial_res: desired spatial resolution (in m)
|
840
|
+
:param bounds: [xmin, ymin, xmax, ymax] or [[xmin, xmax], [ymin, ymax]]
|
841
|
+
:return: WolfArray or None if error
|
842
|
+
"""
|
843
|
+
|
844
|
+
from wolfhece.pydownloader import toys_dataset
|
845
|
+
|
846
|
+
fname = toys_dataset(dir='Walous_OCS', file='WALOUS_2020_lbt72_10m.tif')
|
847
|
+
|
848
|
+
return get_array_WALOUS_OCS(fname, spatial_res, bounds)
|
849
|
+
|
850
|
+
def get_array_WALOUS_OCS_2020_4m(spatial_res:float, bounds:Union[list[float, float, float, float],list[list[float, float], list[float, float]]]) -> Union[WolfArray, None]:
|
851
|
+
""" Get WALOUS OCS 2020 as WolfArray
|
852
|
+
|
853
|
+
:param spatial_res: desired spatial resolution (in m)
|
854
|
+
:param bounds: [xmin, ymin, xmax, ymax] or [[xmin, xmax], [ymin, ymax]]
|
855
|
+
:return: WolfArray or None if error
|
856
|
+
"""
|
857
|
+
|
858
|
+
from wolfhece.pydownloader import toys_dataset
|
859
|
+
|
860
|
+
fname = toys_dataset(dir='Walous_OCS', file='WALOUS_2020_lbt72_4m.tif')
|
861
|
+
|
862
|
+
return get_array_WALOUS_OCS(fname, spatial_res, bounds)
|
863
|
+
|
864
|
+
def get_array_WALOUS_UTS(fname:Path, fnout:Path, spatial_res:float, bounds:Union[list[float, float, float, float],list[list[float, float], list[float, float]]], which:Literal['UTS_MAJ_NIV1', 'UTS_MAJ_NIV2'] = 'UTS_MAJ_NIV1') -> Union[WolfArray, None]:
|
865
|
+
""" Get WALOUS UTS as WolfArray
|
866
|
+
|
867
|
+
:param fname: path to the WALOUS UTS file
|
868
|
+
:param spatial_res: desired spatial resolution (in m)
|
869
|
+
:param bounds: [xmin, ymin, xmax, ymax] or [[xmin, xmax], [ymin, ymax]]
|
870
|
+
:param which: which level to use ('UTS_MAJ_NIV1' or 'UTS_MAJ_NIV2')
|
871
|
+
:return: WolfArray or None if error
|
872
|
+
"""
|
873
|
+
|
874
|
+
fname = Path(fname)
|
875
|
+
fnout = Path(fnout)
|
876
|
+
|
877
|
+
if not fname.exists():
|
878
|
+
logging.error(_('WALOUS UTS file not found: {}').format(fname))
|
879
|
+
return None
|
880
|
+
|
881
|
+
# Convert bounds to [[xmin, xmax], [ymin, ymax]] if needed
|
882
|
+
if len(bounds)==4:
|
883
|
+
bounds = [[bounds[0], bounds[2]], [bounds[1], bounds[3]]]
|
884
|
+
|
885
|
+
# Convert bvounds to list to be able to modify it
|
886
|
+
bounds = [list(bounds[0]), list(bounds[1])]
|
887
|
+
|
888
|
+
bounds_copy = [list(bounds[0]), list(bounds[1])]
|
889
|
+
|
890
|
+
locwalous = Walous_data(fname.parent, fname.name, extension=fname.suffix, bounds=bounds)
|
891
|
+
ret = locwalous.rasterize(bounds=bounds, layer= which, fn_out=fnout.with_suffix('.tif'), pixel_size=spatial_res)
|
892
|
+
|
893
|
+
ret = Path(ret)
|
894
|
+
|
895
|
+
if ret.exists():
|
896
|
+
locwalous_array = WolfArray(fname=ret)
|
897
|
+
return locwalous_array
|
898
|
+
else:
|
899
|
+
return None
|