-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot_options.py
84 lines (70 loc) · 2.46 KB
/
plot_options.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
This module provides a named tuple plot_options to represent the options as
selected in the UI. Also loads default values from config.yml and makes them available.
TODO: This module should also do a reasonable amount of validation
of config variables.
"""
import os
from collections import namedtuple
import yaml
import numpy as np
plot_options = namedtuple("plot_options", (
# Data
"xindex", # Index of x axis data
"yindex", # Index of y axis data
"zindex", # Index of z axis data
"logx", # Apply log scale to xdata
"logy", # Apply log scale to ydata
"logz", # Apply log scale to zdata
# Limits, bins, ticks
"plot_limits", # Plot limits [xmin, xmax, ymin, ymax]
"bin_limits", # Bin limits [[xmin, xmax], [ymin, ymax]]
"nbins", # Number of bins
"xticks", # Number of x ticks
"yticks", # Number of y ticks
"alpha", # Values of alpha in asc. order [float, float]
"tau", # Theoretical error width on delta chi-squared plots.
# Labels
"xlabel", # Label for x axis
"ylabel", # Label for y axis
"zlabel", # Label for z axis
"plot_title", # Title of plot
"leg_title", # Plot legend
"leg_position", # Location of plot legend
# Whether to show optional plot elements (all True / False)
"show_best_fit",
"show_posterior_mean",
"show_conf_intervals",
"show_credible_regions",
"show_posterior_pdf",
"show_prof_like"
))
# Store a dictionary of default options from config.yml
config_path = os.path.join(
os.path.split(os.path.abspath(__file__))[0],
"config.yml"
)
with open(config_path) as cfile:
_defaults = yaml.load(cfile)["plot_options"]
# Fix the types of a few options. It would also be
# possible to directly specify the types in the YAML file,
# but that might confuse users / be messy.
if _defaults["alpha"] is not None:
_defaults["alpha"] = np.array(_defaults["alpha"])
_defaults["alpha"].sort()
if _defaults["plot_limits"] is not None:
_defaults["plot_limits"] = np.array(_defaults["plot_limits"])
def default(option):
"""
Retrieve the default value of a plot option.
If no default is available, prints an error message and raises
a KeyError.
:param option: Name of the option
:type option: string
:returns: Default value of specified option.
"""
try:
return _defaults[option]
except KeyError:
print "plot_options: No default specified for option: {}".format(option)
raise