-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.py
62 lines (52 loc) · 1.96 KB
/
configure.py
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
"""
This script download and unzips the zmap files of DGM5 and VELMOD3.1, such that
the `convert.py`script can pick them up and convert them into xarray format.
The file URL's are supplied in the `config.json` file included in the distribution.
"""
import json5
import wget
import zipfile
from pathlib import Path
def configure(verbose=False):
module_path = Path(__file__).parent.parent
config_path = module_path / "config/config.json"
with open(config_path, "r") as f:
config = json5.load(f)
downloads = Path(config["download_directory"])
if not downloads.is_absolute():
downloads = module_path / downloads
if verbose:
print("download model files")
filelist = []
for ds, files in config["downloads"].items():
folder = downloads / ds
folder.mkdir(parents=True, exist_ok=True)
assert folder.is_dir()
for url in files:
filename = folder / wget.detect_filename(url)
if filename.exists():
if verbose:
print(f" file {filename} exists .. skipped")
else:
if verbose:
print(f" downloading {filename}")
wget.download(url, str(folder))
filelist.append(filename)
if verbose:
print("extract ZMAP files")
for zipf in filelist:
folder = zipf.parent
with zipfile.ZipFile(zipf) as z:
files = z.namelist()
for f in files:
if f.endswith(("on_offshore_merge_DGM50_ED50_UTM31.zmap", ".dat")):
target = folder / f
if target.exists():
if verbose:
print(f" file {target} exists .. skipped")
else:
if verbose:
print(f" extracting {target}")
z.extract(f, path=folder)
if __name__ == "__main__":
configure(verbose=True)