-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschemes.py
76 lines (65 loc) · 2.32 KB
/
schemes.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
"""
This module contains the Scheme class, which is used to hold information
about how individual elements should appear in a plot.
Schemes are defined in config.yml. On import, this module loads each Scheme
and attaches it as a module attribute with the defined name.
"""
# External modules.
import os
import sys
from pylab import get_cmap
import yaml
class Scheme:
r"""
Holds information for how a piece of data should be plotted.
All parameters are optional - Schemes can specify any subset of the
available attributes.
:param colour: Colour for a line / point.
:type colour: string
:param symbol: Indicates point style e.g. cirlce 'o' or line style e.g '--'.
:type symbol: string
:param label: Label for legend.
:type label: string
:param level_names: List of contour level names, i.e. for confidence regions.
:type level_names: list
:param colour_map: Colour map for 2D plots. Must be the name of a matplotlib colour map.
:type colour_map: string
:param colour_bar_title: Title for colour bar.
:type colour_bar_title: string
:param size: Size of points.
:type size: integer
:param colours: List of colours to be iterated, for, e.g., filled contours.
:type colours: list
"""
def __init__(
self,
colour=None,
symbol=None,
label=None,
level_names=None,
colour_map=None,
colour_bar_title=None,
size=5,
colours=None):
self.colour = colour
self.symbol = symbol
self.label = label
self.level_names = level_names
self.colour_map = get_cmap(colour_map)
self.colour_bar_title = colour_bar_title
self.size = size
self.colours = colours
# Load config.yml and store contents as private dictionary
config_path = os.path.join(
os.path.split(os.path.abspath(__file__))[0],
"config.yml"
)
with open(config_path) as cfile:
_config = yaml.load(cfile)
# For each scheme in the config file, create a Scheme
# class and add it as a module attribute.
for scheme_name, params in _config["schemes"].iteritems():
scheme = Scheme(**params)
setattr(sys.modules[__name__], scheme_name, scheme)
credible_regions = [credible_region_s2, credible_region_s1]
conf_intervals = [conf_interval_s2, conf_interval_s1]