wolfhece 2.2.40__py3-none-any.whl → 2.2.42__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 +373 -102
- wolfhece/apps/version.py +1 -1
- wolfhece/eva/pyseries.py +24 -1
- wolfhece/hydrometry/kiwis.py +5 -3
- wolfhece/hydrometry/kiwis_gui.py +2 -1
- wolfhece/math_parser/calculator.py +1 -1
- wolfhece/mesh2d/wolf2dprev.py +45 -17
- wolfhece/models/walous_ocs.pal +49 -0
- wolfhece/pydownloader.py +140 -13
- wolfhece/pywalous.py +200 -139
- wolfhece/scenario/config_manager.py +9 -1
- wolfhece/wolf_array.py +190 -83
- wolfhece/wolfresults_2D.py +4 -4
- {wolfhece-2.2.40.dist-info → wolfhece-2.2.42.dist-info}/METADATA +1 -1
- {wolfhece-2.2.40.dist-info → wolfhece-2.2.42.dist-info}/RECORD +18 -17
- {wolfhece-2.2.40.dist-info → wolfhece-2.2.42.dist-info}/WHEEL +0 -0
- {wolfhece-2.2.40.dist-info → wolfhece-2.2.42.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.2.40.dist-info → wolfhece-2.2.42.dist-info}/top_level.txt +0 -0
wolfhece/eva/pyseries.py
CHANGED
@@ -1277,8 +1277,31 @@ class EVA_Serie:
|
|
1277
1277
|
k+=1
|
1278
1278
|
|
1279
1279
|
|
1280
|
-
def plot_classified_flowrate_curve(self, fig:Figure=None, ax:Axes=None, label='', textvalues=True, show=False) -> tuple[Figure,Axes]:
|
1280
|
+
def plot_classified_flowrate_curve(self, fig:Figure=None, ax:Axes=None, label='', textvalues=True, show=False) -> tuple[Figure,Axes, dict]:
|
1281
|
+
"""
|
1282
|
+
Plot classified flow rate curve.
|
1283
|
+
|
1284
|
+
Characteristics returned in dict are:
|
1285
|
+
- DCE : Débit journalier dépassé en moyenne 355 jours par an
|
1286
|
+
- DC10 : Débit journalier dépassé en moyenne 10 mois par an
|
1287
|
+
- Q347 : Débit atteint ou dépassé, en moyenne, pendant 347 jours par an
|
1288
|
+
- DM : Débit atteint ou dépassé, en moyenne, pendant 50% du temps - débit médian
|
1289
|
+
- DCC : Débit journalier qui est dépassé 10 jours par an
|
1290
|
+
|
1291
|
+
Previous lines are keys of characteristics dict.
|
1281
1292
|
|
1293
|
+
Each characteristic is a dict with:
|
1294
|
+
- 'help' : explanation of characteristic
|
1295
|
+
- 'x' : number of days with exceedance
|
1296
|
+
- 'value' : discharge value
|
1297
|
+
|
1298
|
+
:param fig: Matplotlib figure
|
1299
|
+
:param ax: Matplotlib axis
|
1300
|
+
:param label: label for the curve
|
1301
|
+
:param textvalues: if True, text of characteristics are added
|
1302
|
+
:param show: if True, plt.show() is called
|
1303
|
+
:return: fig, ax, resdict
|
1304
|
+
"""
|
1282
1305
|
if ax is None:
|
1283
1306
|
fig,ax = plt.subplots(1,1)
|
1284
1307
|
|
wolfhece/hydrometry/kiwis.py
CHANGED
@@ -1114,8 +1114,10 @@ class hydrometry():
|
|
1114
1114
|
while curfrom<todate:
|
1115
1115
|
logging.info('Getting data from {0} to {1}'.format(curfrom, curend))
|
1116
1116
|
tmpts = self.timeseries(stationname, stationcode, dir = dir, fromdate= curfrom, todate= curend, ts_name= ts_name, ts_id= ts_id, timezone=timezone)
|
1117
|
-
|
1118
|
-
|
1117
|
+
|
1118
|
+
if isinstance(tmpts, pd.Series):
|
1119
|
+
if len(tmpts)>0:
|
1120
|
+
locts.append(tmpts)
|
1119
1121
|
|
1120
1122
|
curfrom = curend
|
1121
1123
|
curend = curfrom+timedelta(seconds=200000 * cursec)
|
@@ -1145,7 +1147,7 @@ class hydrometry():
|
|
1145
1147
|
df.index = pd.to_datetime(df.index,format="%Y-%m-%dT%H:%M:%S.%f%z")
|
1146
1148
|
|
1147
1149
|
except Exception as e:
|
1148
|
-
logging.error('Error in timeseries
|
1150
|
+
logging.error('Error in timeseries ! - Check if the server is responding.')
|
1149
1151
|
return pd.DataFrame()
|
1150
1152
|
|
1151
1153
|
return df.squeeze()
|
wolfhece/hydrometry/kiwis_gui.py
CHANGED
@@ -17,6 +17,7 @@ import matplotlib.pyplot as plt
|
|
17
17
|
import pandas as pd
|
18
18
|
from datetime import datetime as dt, timedelta
|
19
19
|
import logging
|
20
|
+
import numpy as np
|
20
21
|
|
21
22
|
#Test de la présence de la fonction de traduction i18n "gettext" et définition le cas échéant pour ne pas créer d'erreur d'exécution
|
22
23
|
import os
|
@@ -472,7 +473,7 @@ class hydrometry_gui(wx.Frame):
|
|
472
473
|
for curdata, curname in zip(data,tsname):
|
473
474
|
if curdata is not None:
|
474
475
|
if len(curdata)>1:
|
475
|
-
if datumsizebv[0]!='':
|
476
|
+
if datumsizebv[0]!='' and not np.isnan(datumsizebv[0]):
|
476
477
|
ax.step(curdata.index, curdata+float(datumsizebv[0]), where='post', label=curname)
|
477
478
|
else:
|
478
479
|
ax.step(curdata.index, curdata, where='post', label=curname)
|
@@ -142,7 +142,7 @@ class Calculator(wx.Frame):
|
|
142
142
|
checked_state=None)
|
143
143
|
|
144
144
|
for id_array in id_arrays:
|
145
|
-
self._memory[id_array] = self._mapviewer.get_obj_from_id(id_array,
|
145
|
+
self._memory[id_array] = self._mapviewer.get_obj_from_id(id_array, drawing_type=draw_type.ARRAYS)
|
146
146
|
|
147
147
|
if len(variables) > 0:
|
148
148
|
for var in variables:
|
wolfhece/mesh2d/wolf2dprev.py
CHANGED
@@ -51,6 +51,8 @@ PREV_INFILTRATION_VAR_SIMPLE = -1 #INFILTRATION VARIABLE (RÉPARTITION UNIFORME
|
|
51
51
|
PREV_INFILTRATION_VAR_MOD_MOMENTUM = -2 #INFILTRATION VARIABLE AVEC MOD QT MVT (RÉPARTITION NON UNIFORME DU DÉBIT INJECTÉ CALCULÉ SUR BASE DE L'ÉTAT HYDRODYNAMIQUE INSTANTANÉ)
|
52
52
|
PREV_INFILTRATION_VAR_LINKED_ZONES = -3 #INFILTRATION/EXFILTRATION "INTERNE" VARIABLE (RÉPARTITION UNIFORME DU DÉBIT SUR BASE DE DEUX ZONES D'INFILTRATION)
|
53
53
|
|
54
|
+
PREV_INFILTRATION_MODES = [PREV_INFILTRATION_NULL, PREV_INFILTRATION_SIMPLE, PREV_INFILTRATION_MOD_MOMENTUM, PREV_INFILTRATION_MOD_MOMENTUM_IMPOSED, PREV_INFILTRATION_VAR_SIMPLE, PREV_INFILTRATION_VAR_MOD_MOMENTUM, PREV_INFILTRATION_VAR_LINKED_ZONES]
|
55
|
+
|
54
56
|
##
|
55
57
|
PREV_READ_TXT = 1
|
56
58
|
PREV_READ_FINE = 2
|
@@ -968,8 +970,8 @@ class prev_parameters_blocks:
|
|
968
970
|
def get_params_sediment(self) -> dict:
|
969
971
|
""" Retourne les paramètres du modèle sédimentaire """
|
970
972
|
|
971
|
-
return {_('Model'): self.
|
972
|
-
_('Drifting model'): self.
|
973
|
+
return {_('Model'): self._get_params_sediment_model(),
|
974
|
+
_('Drifting model'): self._get_params_sediment_drifting_model(),
|
973
975
|
_('Porosity'): self._sed_porosity,
|
974
976
|
_('Mean diameter'): self._sed_d_mean,
|
975
977
|
_('Sediment density'): self._sed_s,
|
@@ -2127,48 +2129,74 @@ class prev_parameters_blocks:
|
|
2127
2129
|
'cd_c': self._infil_dev_c,
|
2128
2130
|
'cd_d': self._infil_dev_d}
|
2129
2131
|
|
2130
|
-
elif self._infiltration_mode ==
|
2131
|
-
return self.
|
2132
|
+
elif self._infiltration_mode == PREV_INFILTRATION_MOD_MOMENTUM_IMPOSED:
|
2133
|
+
return self.get_params_infiltration_momentum_correction()
|
2132
2134
|
|
2133
2135
|
else:
|
2134
2136
|
return {}
|
2135
2137
|
|
2138
|
+
def get_infiltration_mode(self) -> int:
|
2139
|
+
""" Retourne le mode d'infiltration """
|
2140
|
+
return self._infiltration_mode
|
2141
|
+
|
2142
|
+
def set_infiltration_mode(self, mode:int) -> None:
|
2143
|
+
""" Définit le mode d'infiltration
|
2144
|
+
|
2145
|
+
0 : PREV_INFILTRATION_NULL - PAS D'INFILTRATION
|
2146
|
+
1 : PREV_INFILTRATION_SIMPLE - INFILTRATION SIMPLE (RÉPARTITION UNIFORME DU DÉBIT INJECTÉ PAR FICHIER .INF)
|
2147
|
+
2 : PREV_INFILTRATION_MOD_MOMENTUM - INFILTRATION AVEC MODIFICATION DE LA QT DE MVT (RÉPARTITION NON UNIFORME DU DÉBIT INJECTÉ PAR FICHIER .INF)
|
2148
|
+
4 : PREV_INFILTRATION_MOD_MOMENTUM_IMPOSED - INFILTRATION AVEC MODIFICATION IMPOSÉE DE LA QT DE MVT (RÉPARTITION NON UNIFORME DU DÉBIT INJECTÉ PAR FICHIER .INF)
|
2149
|
+
-1 : PREV_INFILTRATION_VAR_SIMPLE - INFILTRATION VARIABLE (RÉPARTITION UNIFORME DU DÉBIT INJECTÉ CALCULÉ SUR BASE DE L'ÉTAT HYDRODYNAMIQUE INSTANTANÉ)
|
2150
|
+
-2 : PREV_INFILTRATION_VAR_MOD_MOMENTUM - INFILTRATION VARIABLE AVEC MOD QT MVT (RÉPARTITION NON UNIFORME DU DÉBIT INJECTÉ CALCULÉ SUR BASE DE L'ÉTAT HYDRODYNAMIQUE INSTANTANÉ)
|
2151
|
+
-3 : PREV_INFILTRATION_VAR_LINKED_ZONES - INFILTRATION/EXFILTRATION "INTERNE" VARIABLE (RÉPARTITION UNIFORME DU DÉBIT SUR BASE DE DEUX ZONES D'INFILTRATION)
|
2152
|
+
|
2153
|
+
:param mode: mode d'infiltration
|
2154
|
+
"""
|
2155
|
+
assert isinstance(mode, int), "mode must be an integer"
|
2156
|
+
assert mode in PREV_INFILTRATION_MODES, f"mode must be in {PREV_INFILTRATION_MODES}"
|
2157
|
+
self._infiltration_mode = mode
|
2158
|
+
|
2159
|
+
def reset_infiltration_mode(self) -> None:
|
2160
|
+
""" Réinitialise le mode d'infiltration """
|
2161
|
+
self._infiltration_mode = PREV_INFILTRATION_NULL
|
2162
|
+
|
2163
|
+
|
2136
2164
|
def check_params_infiltration(self) -> tuple[bool, str]:
|
2137
2165
|
""" Vérifie les paramètres d'infiltration """
|
2138
2166
|
|
2139
2167
|
ret = '\nInfiltration\n************\n'
|
2140
2168
|
valid = True
|
2141
2169
|
|
2142
|
-
if self._infiltration_mode ==
|
2170
|
+
if self._infiltration_mode == PREV_INFILTRATION_NULL:
|
2143
2171
|
ret += _('Info: No infiltration\n')
|
2144
|
-
elif self._infiltration_mode ==
|
2172
|
+
elif self._infiltration_mode == PREV_INFILTRATION_SIMPLE:
|
2145
2173
|
ret += _('Info: Simple infiltration\n')
|
2146
|
-
elif self._infiltration_mode ==
|
2174
|
+
elif self._infiltration_mode == PREV_INFILTRATION_MOD_MOMENTUM:
|
2147
2175
|
ret += _('Info: Infiltration with momentum modification\n')
|
2148
|
-
elif self._infiltration_mode ==
|
2176
|
+
elif self._infiltration_mode == PREV_INFILTRATION_MOD_MOMENTUM_IMPOSED:
|
2149
2177
|
ret += _('Info: Infiltration with imposed momentum modification\n')
|
2150
|
-
elif self._infiltration_mode ==
|
2178
|
+
elif self._infiltration_mode == PREV_INFILTRATION_VAR_SIMPLE:
|
2151
2179
|
ret += _('Info: Variable infiltration\n')
|
2152
|
-
elif self._infiltration_mode ==
|
2180
|
+
elif self._infiltration_mode == PREV_INFILTRATION_VAR_MOD_MOMENTUM:
|
2153
2181
|
ret += _('Info: Variable infiltration with momentum modification\n')
|
2154
|
-
elif self._infiltration_mode ==
|
2182
|
+
elif self._infiltration_mode == PREV_INFILTRATION_VAR_LINKED_ZONES:
|
2155
2183
|
ret += _('Info: Variable infiltration/exfiltration (linked zone)\n')
|
2156
2184
|
|
2157
2185
|
if self._infiltration_mode < 0:
|
2158
2186
|
ret += _('Info: Coefficients a={self._infil_a}, b={self._infil_b}, c={self._infil_c}\n')
|
2159
2187
|
|
2160
|
-
if self._infiltration_mode !=
|
2188
|
+
if self._infiltration_mode != PREV_INFILTRATION_VAR_LINKED_ZONES and self._infil_a == 0. and self._infil_b == 0. and self._infil_c == 0.:
|
2161
2189
|
ret += _('Warning: No polynomial infiltration\n')
|
2162
2190
|
|
2163
|
-
if self._infiltration_mode ==
|
2191
|
+
if self._infiltration_mode == PREV_INFILTRATION_VAR_LINKED_ZONES and self._infil_a == 0.:
|
2164
2192
|
ret += _('Warning: No infiltration/exfiltration under bridge\n')
|
2165
2193
|
|
2166
2194
|
ret += _('Info: Coefficients Cd={self._infil_dev_cd}, width={self._infil_dev_width}\n, zseuil={self._infil_dev_zseuil}')
|
2167
2195
|
|
2168
|
-
if self._infiltration_mode !=
|
2196
|
+
if self._infiltration_mode != PREV_INFILTRATION_VAR_LINKED_ZONES and self._infil_dev_cd == 0. or self._infil_dev_width == 0.:
|
2169
2197
|
ret += _('Warning: No weir exfiltration\n')
|
2170
2198
|
|
2171
|
-
if self._infiltration_mode ==
|
2199
|
+
if self._infiltration_mode == PREV_INFILTRATION_VAR_LINKED_ZONES and (self._infil_dev_cd == 0. or self._infil_dev_width == 0.):
|
2172
2200
|
ret += _('Warning: No weir over bridge\n')
|
2173
2201
|
|
2174
2202
|
ret += _('Info: Coefficients d={self._infil_var_d}, e={self._infil_var_e}\n')
|
@@ -2195,7 +2223,7 @@ class prev_parameters_blocks:
|
|
2195
2223
|
self._infil_correction_ux = ux
|
2196
2224
|
self._infil_correction_vy = vy
|
2197
2225
|
|
2198
|
-
if self._infiltration_mode !=
|
2226
|
+
if self._infiltration_mode != PREV_INFILTRATION_MOD_MOMENTUM_IMPOSED:
|
2199
2227
|
logging.warning("To apply, you must set ninfil to 4")
|
2200
2228
|
else:
|
2201
2229
|
logging.info("Infiltration momentum correction applied")
|
@@ -2203,7 +2231,7 @@ class prev_parameters_blocks:
|
|
2203
2231
|
def get_params_infiltration_momentum_correction(self) -> dict:
|
2204
2232
|
""" Retourne les corrections de moment pour l'infiltration """
|
2205
2233
|
|
2206
|
-
if self._infiltration_mode ==
|
2234
|
+
if self._infiltration_mode == PREV_INFILTRATION_MOD_MOMENTUM_IMPOSED:
|
2207
2235
|
return {'ux': self._infil_correction_ux,
|
2208
2236
|
'vy': self._infil_correction_vy}
|
2209
2237
|
else:
|
@@ -0,0 +1,49 @@
|
|
1
|
+
12
|
2
|
+
0.0
|
3
|
+
229
|
4
|
+
234
|
5
|
+
63
|
6
|
+
1.0
|
7
|
+
138
|
8
|
+
138
|
9
|
+
138
|
10
|
+
2.0
|
11
|
+
220
|
12
|
+
15
|
13
|
+
15
|
14
|
+
3.0
|
15
|
+
78
|
16
|
+
78
|
17
|
+
78
|
18
|
+
4.0
|
19
|
+
208
|
20
|
+
208
|
21
|
+
208
|
22
|
+
5.0
|
23
|
+
36
|
24
|
+
97
|
25
|
+
247
|
26
|
+
6.0
|
27
|
+
255
|
28
|
+
255
|
29
|
+
115
|
30
|
+
7.0
|
31
|
+
233
|
32
|
+
255
|
33
|
+
190
|
34
|
+
8.0
|
35
|
+
0
|
36
|
+
50
|
37
|
+
0
|
38
|
+
9.0
|
39
|
+
40
|
40
|
+
200
|
41
|
+
40
|
42
|
+
80.0
|
43
|
+
0
|
44
|
+
120
|
45
|
+
0
|
46
|
+
90.0
|
47
|
+
183
|
48
|
+
232
|
49
|
+
176
|
wolfhece/pydownloader.py
CHANGED
@@ -19,6 +19,7 @@ from enum import Enum
|
|
19
19
|
from typing import Union, Optional, List
|
20
20
|
from collections import namedtuple
|
21
21
|
import logging
|
22
|
+
import urllib.parse
|
22
23
|
|
23
24
|
class DownloadType(Enum):
|
24
25
|
""" Enum to define the type of download. """
|
@@ -44,7 +45,7 @@ class DownloadFiles(Enum):
|
|
44
45
|
DXFFILES = ('dxf',)
|
45
46
|
ZIPFILES = ('zip',)
|
46
47
|
LAZFILES = ('laz',)
|
47
|
-
|
48
|
+
LISTFILES = ('lst',)
|
48
49
|
LAZBIN = ('bin',)
|
49
50
|
|
50
51
|
class DonwloadDirectories(Enum):
|
@@ -54,6 +55,10 @@ class DonwloadDirectories(Enum):
|
|
54
55
|
|
55
56
|
GITLAB_EXAMPLE = 'https://gitlab.uliege.be/HECE/wolf_examples/-/raw/main'
|
56
57
|
GITLAB_EXAMPLE_GPU = 'https://gitlab.uliege.be/HECE/wolfgpu_examples/-/raw/main'
|
58
|
+
|
59
|
+
GITLAB_MODREC_DATA_VESDRE = 'https://gitlab.uliege.be/api/v4/projects/4933'
|
60
|
+
GITLAB_MODREC_DATA_VESDRE_FILES = 'https://gitlab.uliege.be/api/v4/projects/4933/repository/files/'
|
61
|
+
|
57
62
|
DATADIR = Path(__file__).parent / 'data' / 'downloads'
|
58
63
|
|
59
64
|
def clean_url(url: str) -> str:
|
@@ -83,7 +88,12 @@ def clean_url(url: str) -> str:
|
|
83
88
|
raise ValueError(f"Invalid URL: {url}. Must start with http://, https://, or ftp://")
|
84
89
|
return cleaned_url.strip()
|
85
90
|
|
86
|
-
def download_file(url: str,
|
91
|
+
def download_file(url: str,
|
92
|
+
destination: Union[str, Path] = None,
|
93
|
+
download_type: DownloadType = DownloadType.HTTP,
|
94
|
+
load_from_cache:bool = True,
|
95
|
+
token:str = None,
|
96
|
+
file_type:DownloadType = None) -> Path:
|
87
97
|
""" Download a file from the specified URL to the destination path.
|
88
98
|
|
89
99
|
:param url: The URL of the file to download.
|
@@ -98,11 +108,13 @@ def download_file(url: str, destination: Union[str, Path] = None, download_type:
|
|
98
108
|
|
99
109
|
url = str(url).strip()
|
100
110
|
# Clean the URL
|
101
|
-
|
111
|
+
if file_type is None:
|
112
|
+
url = clean_url(url)
|
102
113
|
|
103
114
|
if destination is None:
|
104
115
|
try:
|
105
|
-
|
116
|
+
url_cleaned = url.replace('/raw?ref=main', '').replace('%2F', '/')
|
117
|
+
destination = DATADIR / Path(url_cleaned).parent.name / Path(url_cleaned).name
|
106
118
|
except:
|
107
119
|
destination = DATADIR / Path(url).name
|
108
120
|
# create the directory if it does not exist
|
@@ -113,16 +125,19 @@ def download_file(url: str, destination: Union[str, Path] = None, download_type:
|
|
113
125
|
if suffix.startswith('.'):
|
114
126
|
suffix = suffix[1:]
|
115
127
|
|
116
|
-
|
117
|
-
|
118
|
-
|
128
|
+
if file_type is None:
|
129
|
+
# Find the download type based on the URL suffix
|
130
|
+
for file_type_enum in DownloadFiles:
|
131
|
+
if suffix in file_type_enum.value:
|
119
132
|
|
120
|
-
|
121
|
-
|
122
|
-
|
133
|
+
if suffix == 'bin' and '_xyz.bin' in url:
|
134
|
+
# special case for LAZ bin files
|
135
|
+
file_type_enum = DownloadFiles.LAZBIN
|
123
136
|
|
124
|
-
|
125
|
-
|
137
|
+
file_type = file_type_enum
|
138
|
+
break
|
139
|
+
else:
|
140
|
+
suffix = file_type.value[0]
|
126
141
|
|
127
142
|
# Create a list of files to download based on the download type
|
128
143
|
# by replacing suffix in the url with the appropriate file extensions
|
@@ -132,6 +147,7 @@ def download_file(url: str, destination: Union[str, Path] = None, download_type:
|
|
132
147
|
if ext.startswith('.'):
|
133
148
|
ext = ext[1:]
|
134
149
|
to_download.append(url.replace(suffix, f'{ext}'))
|
150
|
+
|
135
151
|
to_destination.append(destination.with_suffix(f'.{ext}'))
|
136
152
|
|
137
153
|
|
@@ -139,6 +155,15 @@ def download_file(url: str, destination: Union[str, Path] = None, download_type:
|
|
139
155
|
|
140
156
|
for url, destination in zip(to_download, to_destination):
|
141
157
|
|
158
|
+
if token is not None:
|
159
|
+
# Requête HTTP avec le token
|
160
|
+
headers = {
|
161
|
+
"PRIVATE-TOKEN": token
|
162
|
+
}
|
163
|
+
else:
|
164
|
+
headers = {}
|
165
|
+
|
166
|
+
|
142
167
|
if load_from_cache and destination.exists():
|
143
168
|
logging.info(f"File {destination} already exists. Skipping download.")
|
144
169
|
continue
|
@@ -147,7 +172,7 @@ def download_file(url: str, destination: Union[str, Path] = None, download_type:
|
|
147
172
|
raise ValueError(f"Invalid URL: {url}. Must start with http:// or https://")
|
148
173
|
|
149
174
|
try:
|
150
|
-
response = requests.get(url)
|
175
|
+
response = requests.get(url, headers=headers)
|
151
176
|
response.raise_for_status()
|
152
177
|
with open(destination, 'wb') as file:
|
153
178
|
file.write(response.content)
|
@@ -287,7 +312,109 @@ def toys_laz_grid(dir:str, file:str, load_from_cache:bool = True):
|
|
287
312
|
|
288
313
|
return DATADIR / dir
|
289
314
|
|
315
|
+
def laz_grid_from_url(url:str, dir:str, file:str, load_from_cache:bool = True):
|
316
|
+
""" Download toy LAZ or GRIDWOLF files from an external URL.
|
317
|
+
|
318
|
+
:param url: The base URL where the files are located.
|
319
|
+
:param dir: The directory where the file will be saved.
|
320
|
+
:param file: The name of the file to download.
|
321
|
+
:type url: str
|
322
|
+
:type dir: str
|
323
|
+
:type file: str
|
324
|
+
:return: The path to the downloaded directory.
|
325
|
+
"""
|
326
|
+
url = f"{url}/{dir}/{file}"
|
327
|
+
destination = DATADIR / dir / file
|
328
|
+
lst = download_file(url, destination, load_from_cache=load_from_cache)
|
329
|
+
|
330
|
+
if not Path(lst).exists():
|
331
|
+
raise FileNotFoundError(f"The file {lst} does not exist. -- Check the URL and file name.")
|
332
|
+
|
333
|
+
with open(lst, 'r') as f:
|
334
|
+
lines = f.read().splitlines()
|
335
|
+
|
336
|
+
for line in lines:
|
337
|
+
line = line.strip().replace('\\', '/')
|
338
|
+
if line:
|
339
|
+
url = f"{GITLAB_EXAMPLE}/{dir}/{line}"
|
340
|
+
destination = DATADIR / dir / line
|
341
|
+
download_file(url, destination, load_from_cache=load_from_cache)
|
342
|
+
|
343
|
+
return DATADIR / dir
|
344
|
+
|
345
|
+
def check_status(url:str, token:str = None) -> bool:
|
346
|
+
""" Check the status of a URL.
|
347
|
+
|
348
|
+
:param url: The URL to check.
|
349
|
+
:param token: The private token for authentication (if required).
|
350
|
+
:type url: str
|
351
|
+
:type token: str
|
352
|
+
:return: True if the URL is accessible, False otherwise.
|
353
|
+
:rtype: bool
|
354
|
+
"""
|
355
|
+
url = str(url).strip()
|
356
|
+
url = clean_url(url)
|
357
|
+
|
358
|
+
if not url.startswith(('http://', 'https://')):
|
359
|
+
raise ValueError(f"Invalid URL: {url}. Must start with http:// or https://")
|
360
|
+
|
361
|
+
try:
|
362
|
+
if token is not None:
|
363
|
+
headers = {
|
364
|
+
"PRIVATE-TOKEN": token
|
365
|
+
}
|
366
|
+
else:
|
367
|
+
headers = {}
|
368
|
+
|
369
|
+
response = requests.head(url, headers=headers)
|
370
|
+
return response.status_code == 200
|
371
|
+
except requests.RequestException as e:
|
372
|
+
logging.error(f"Error checking URL {url}: {e}")
|
373
|
+
return False
|
374
|
+
|
375
|
+
def download_modrec_vesdre_file(directory:str, filename:str,
|
376
|
+
token:str = None, load_from_cache:bool = True,
|
377
|
+
file_type:DownloadFiles = None) -> Path:
|
378
|
+
|
379
|
+
""" Download a file from the ModRec Vesdre dataset.
|
380
|
+
|
381
|
+
:param directory: The directory where the file is located (relative to the repository root).
|
382
|
+
:param filename: The name of the file to download.
|
383
|
+
:param token: The private token for authentication (if required).
|
384
|
+
:param load_from_cache: If True, will not download the file if it already exists.
|
385
|
+
:type directory: str
|
386
|
+
:type filename: str
|
387
|
+
:type token: str
|
388
|
+
:type load_from_cache: bool
|
389
|
+
:return: The path to the downloaded file.
|
390
|
+
:rtype: Path
|
391
|
+
"""
|
392
|
+
|
393
|
+
# Find the download type based on the URL suffix
|
394
|
+
if file_type is None:
|
395
|
+
suffix = Path(filename).suffix.lower().replace('.', '')
|
396
|
+
|
397
|
+
for file_type_enum in DownloadFiles:
|
398
|
+
if suffix in file_type_enum.value:
|
399
|
+
|
400
|
+
if suffix == 'bin' and '_xyz.bin' in filename:
|
401
|
+
# special case for LAZ bin files
|
402
|
+
file_type_enum = DownloadFiles.LAZBIN
|
403
|
+
|
404
|
+
file_type = file_type_enum
|
405
|
+
break
|
406
|
+
|
407
|
+
file_path_encoded = urllib.parse.quote_plus(directory + '/' + filename)
|
408
|
+
url = f"{GITLAB_MODREC_DATA_VESDRE_FILES}{file_path_encoded}/raw?ref=main"
|
409
|
+
destination = DATADIR / 'Vesdre' / file_path_encoded.replace('%2F', '/')
|
410
|
+
return download_file(url, destination, token=token, load_from_cache=load_from_cache, file_type=file_type)
|
411
|
+
|
290
412
|
if __name__ == "__main__":
|
413
|
+
token = '' # Add your GitLab private token here if needed
|
414
|
+
dir = 'LAZ_Vesdre/2023/grids_flt32/237500_145500'
|
415
|
+
file_path = "237500_145500_237500_145000_xyz.bin"
|
416
|
+
print(download_modrec_vesdre_file(dir, file_path, token=token, load_from_cache=False))
|
417
|
+
|
291
418
|
# Example usage
|
292
419
|
print(download_file(r'https:\\gitlab.uliege.be\HECE\wolf_examples\-\raw\main\Extract_part_array\extraction.vec'))
|
293
420
|
print(download_file('https://gitlab.uliege.be/HECE/wolf_examples/-/raw/main/Extract_part_array/extraction.vec'))
|