gstlal  0.8.1
 All Classes Namespaces Files Functions Variables Pages
plotutil.py
Go to the documentation of this file.
1 # Copyright (C) 2013-2015 Kipp Cannon
2 # Copyright (C) 2015 Chad Hanna
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the
6 # Free Software Foundation; either version 2 of the License, or (at your
7 # option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 # Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 
19 ##
20 # @file
21 #
22 # A file that contains some generic plotting module code
23 #
24 # ### Review Status
25 #
26 ##
27 # @package python.plotutil
28 #
29 # plotting utilities module
30 #
31 import math
32 import matplotlib
33 from matplotlib import figure
34 from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
35 import numpy
36 
37 def colour_from_instruments(instruments, colours = {
38  "G1": numpy.array((0.0, 1.0, 1.0)),
39  "H1": numpy.array((1.0, 0.0, 0.0)),
40  "H2": numpy.array((0.0, 0.0, 1.0)),
41  "L1": numpy.array((0.0, 0.8, 0.0)),
42  "V1": numpy.array((1.0, 0.0, 1.0)),
43  "E1": numpy.array((1.0, 0.0, 0.0)),
44  "E2": numpy.array((0.0, 0.8, 0.0)),
45  "E3": numpy.array((1.0, 0.0, 1.0)),
46 }):
47  # mix colours additively
48  colour = sum(map(colours.__getitem__, instruments))
49  # desaturate
50  colour += len(instruments) - 1
51  # normalize
52  return colour / colour.max()
53 
54 golden_ratio = (1. + math.sqrt(5.)) / 2.
55