-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
61 lines (49 loc) · 1.97 KB
/
config.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
"""Module for configuration of the parser"""
import argparse
import yaml
def parser():
"""
Command-line parser
"""
internal_parser = argparse.ArgumentParser(description="Script for data retrieval and processing")
internal_parser.add_argument("-c", "--config", help="Path to the YAML configuration file")
internal_parser.add_argument("-n", "--nprocs", type=int, help="Number of parallel processes")
internal_parser.add_argument("-u", "--update", action="store_true", help="Update existing dataset")
# Parse the command-line arguments
return internal_parser.parse_args()
def load_config(file_path):
"""
Loading configuration YML file
Returning configuration dict
"""
with open(file_path, 'r', encoding='utf8') as file:
try:
config = yaml.safe_load(file)
return config
except yaml.YAMLError as exc:
print(f"Error loading config file: {exc}")
return None
def print_config(conf_dict):
"""
Print the configuration options
"""
print(f"\nDownloading files in {conf_dict['tmpdir']}")
print(f"Storing final files in {conf_dict['storedir']}")
print(f"Downloading {conf_dict['varlist']} from {conf_dict['dataset']}")
print(f"Data range: {conf_dict['year']['begin']}-{conf_dict['year']['end']}")
if conf_dict['year']['update']:
print('Updating existing datasets...')
print(f"Vertical levels: {conf_dict['levelout']}")
print(f"Data frequency: {conf_dict['freq']}")
print(f"Grid selection: {conf_dict['grid']}")
print(f"Area: {conf_dict['area']}")
print(f"Number of parallel processes: {conf_dict['nprocs']}")
print(f"Download {conf_dict['download_request']} chunks")
print('Actions:')
if conf_dict['do_retrieve']:
print('\t - Retrieving data')
if conf_dict['do_postproc']:
print('\t - Postprocess data')
if conf_dict['do_align']:
print('\t - Set a common time axis for monthly data')
print()