99
10102) A configuration file called datasets.yml in esmvaltool_sample_data that
1111 defines the datasets to download.
12-
1312"""
1413import datetime
15- import os
1614import warnings
1715from 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
0 commit comments