forked from dschwoerer/xemc3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data.py
42 lines (35 loc) · 1.25 KB
/
get_data.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
import os
import xarray as xr
def download_file():
os.system(
"git clone https://oauth2:[email protected]/dave/xemc3-data/ ../../example-data/ --depth 1"
)
def load_example_data(get_path=False):
# Check whether we have a local copy
for path in "./", "../", "../../":
for path in [path, path + "example-data/"]:
try:
fn = path + "emc3_example.nc"
if get_path:
xr.open_dataset(fn)
return fn[:-3]
return xr.open_dataset(fn)
except FileNotFoundError:
pass
except ValueError:
print("Skipping non-readable file", fn)
# try file from AFS
try:
ds = xr.open_dataset(
"/afs/ipp-garching.mpg.de/u/dave/public/xemc3/emc3_example.nc"
)
print("Accessing example file via AFS, which might be slow ...")
return ds
except: # noqa: E722
# Might fail for a number of reasons ...
pass
# Last resort, download and use that
print("Trying to download an example file to ../../example-data/ ...")
download_file()
print("done")
return xr.open_dataset("../../example-data/emc3_example.nc")