Skip to content

Commit eaa9d59

Browse files
authored
Move download script to root directory (#9)
1 parent 5cb352a commit eaa9d59

File tree

6 files changed

+13
-19
lines changed

6 files changed

+13
-19
lines changed
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
1010
2) A configuration file called datasets.yml in esmvaltool_sample_data that
1111
defines the datasets to download.
12-
1312
"""
1413
import datetime
15-
import os
1614
import warnings
1715
from pathlib import Path
1816

@@ -34,7 +32,6 @@ def get_time(filename):
3432
-------
3533
(datetetime.datetime, datetime.datetime)
3634
A tuple containing the start and end date of the file.
37-
3835
"""
3936
times = Path(filename).stem.split('_')[-1].split('-')
4037
fmt = {
@@ -57,7 +54,6 @@ def select_by_time(filename, from_timestamp, to_timestamp):
5754
The required start date, formatted as "2000-01-01T00:00:00Z".
5855
to_timestamp : str or None
5956
The required end date, formatted as "2000-01-01T00:00:00Z".
60-
6157
"""
6258
if from_timestamp is None and to_timestamp is None:
6359
return True
@@ -99,7 +95,6 @@ def select_host(hosts, preferred_hosts, ignore_hosts):
9995
-----
10096
Not sure if this is reliable: sometimes no files are found on the
10197
selected host.
102-
10398
"""
10499
hosts = [h for h in hosts if h not in ignore_hosts]
105100
if not hosts:
@@ -205,7 +200,6 @@ def save_sample(in_file, out_file):
205200
Path to the input file.
206201
out_file : str
207202
Path to the output file.
208-
209203
"""
210204
print("Saving sample of", in_file, "to", out_file)
211205
with warnings.catch_warnings():
@@ -262,13 +256,14 @@ def sample_files(plot_type, dataset_name, files):
262256
Name of the dataset to sample.
263257
files : :obj:`list` of :obj:`str`
264258
A list of filenames that comprise the dataset.
265-
266259
"""
260+
project_dir = Path(__file__).parent
261+
data_dir = project_dir / 'esmvaltool_sample_data' / 'data' / plot_type
262+
data_path = data_dir.joinpath(*dataset_name.split('.'))
263+
data_path.mkdir(parents=True, exist_ok=True)
264+
267265
for filename in files:
268-
dirpath = (Path(__file__).parent / 'data' / plot_type /
269-
dataset_name.replace('.', os.sep))
270-
dirpath.mkdir(parents=True, exist_ok=True)
271-
out_file = dirpath / Path(filename).name
266+
out_file = data_path / Path(filename).name
272267
if out_file.exists():
273268
print("File exists, skipping:", out_file)
274269
else:
@@ -283,13 +278,13 @@ def main():
283278
284279
The resulting list of files is then sampled and stored locally in the
285280
directory 'data' using a commonly used directory structure.
286-
287281
"""
288-
cfg_file = Path(__file__).parent.parent / "config.yml"
282+
project_dir = Path(__file__).parent
283+
cfg_file = project_dir / "config.yml"
289284
with cfg_file.open() as file:
290285
cfg = yaml.safe_load(file)
291286

292-
facets_file = Path(__file__).parent / "datasets.yml"
287+
facets_file = project_dir / "datasets.yml"
293288
with facets_file.open() as file:
294289
cfg_data = yaml.safe_load(file)
295290

esmvaltool_sample_data/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
import cf_units
44
import iris
5-
import yaml
65

76
base_dir = Path(__file__).parent
87

98
VERBOSE = False
109

11-
with open(base_dir / 'datasets.yml', 'r') as f:
12-
config = yaml.safe_load(f)
13-
14-
ignore_list = [fn.replace('.', '/') for fn in config['ignore']]
10+
# This ignore list is used to help with debugging
11+
ignore_list = [
12+
# 'CMIP6/CMIP/AWI/AWI-ESM-1-1-LR/historical/r1i1p1f1/Amon/ta/gn/v20200212',
13+
]
1514

1615

1716
def strip_attributes(cube: 'iris.Cube') -> None:

0 commit comments

Comments
 (0)