-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting_autom.py
More file actions
89 lines (69 loc) · 2.83 KB
/
plotting_autom.py
File metadata and controls
89 lines (69 loc) · 2.83 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pickle
import copy
import os
import argparse
import logging
import sys
import yaml
import plotting_functions as plf
def load_yaml(yaml_path):
with open(yaml_path, 'r') as yaml_file:
yaml_data = yaml.safe_load(yaml_file)
return yaml_data
def setup_logger(debug=False):
"""
Configure a logger with specified console and file handlers.
Args:
debug (bool): Whether to enable debug logging.
log_file (str): The name of the log file.
Returns:
logging.Logger: The configured logger.
"""
console_format = '%(asctime)s - %(levelname)s - %(message)s'
logger = logging.getLogger()
logger.setLevel(logging.DEBUG if debug else logging.INFO)
logger.propagate = False
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.DEBUG if debug else logging.INFO)
console_formatter = logging.Formatter(console_format)
console_handler.setFormatter(console_formatter)
logger.addHandler(console_handler)
return logger
def main():
# Parse command line arguments
parser = argparse.ArgumentParser(description="Plot experiments.")
parser.add_argument("--config", type=str, default="plotting_autom.yml", help="Path to the configuration file")
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
args = parser.parse_args()
# Configure logger
logger = setup_logger(debug=args.debug)
# Log the start of the program
logger.info("Starting program.")
try:
logger.info(f"Loading configuration from {args.config}")
# Load the configuration
config = load_yaml(args.config)
experiments = config['experiments']
metrics = config['metrics']
logger.debug("###### Experiments ##########")
logger.debug(experiments)
logger.debug("###### Metrics ##########")
logger.debug(metrics)
logger.debug(config['number_dates'])
assert 'output_plots' in config, f"output_plots path must be specified in {args.config}"
if not os.path.exists(config['output_plots']):
os.mkdir(config['output_plots'])
for metr_idx, metric in enumerate(metrics):
logger.info(f"metric {metric['name']} being plotted")
os.makedirs(os.path.join(config['output_plots'],metric['folder']),exist_ok=True)
plot_func = getattr(plf, f"plot_{metric['name']}")
try:
plot_func(experiments, metric, config)
except FileNotFoundError as e:
logger.info(e)
logger.info(f"Metric {metric['name']} : One of the experiments did not have the file needed. Cannot plot.")
logger.info("Program completed.")
except Exception as e:
logger.exception(f"An error occurred: {str(e)}")
if __name__ == "__main__":
main()