gstlal  1.4.1
plotutil.py
Go to the documentation of this file.
1 # Copyright (C) 2013-2016 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 
31 
32 
33 import math
34 import numpy
35 import re
36 
37 
38 golden_ratio = (1. + math.sqrt(5.)) / 2.
39 
40 
41 def colour_from_instruments(instruments, colours = {
42  "G1": numpy.array((0.0, 1.0, 1.0)),
43  "H1": numpy.array((1.0, 0.0, 0.0)),
44  "H2": numpy.array((0.0, 0.0, 1.0)),
45  "L1": numpy.array((0.0, 0.7, 0.0)),
46  "E1": numpy.array((1.0, 0.0, 0.0)),
47  "E2": numpy.array((0.0, 0.8, 0.0)),
48  "E3": numpy.array((1.0, 0.0, 1.0)),
49  "V1": numpy.array((1.0, 0.0, 1.0)),
50  "K1": numpy.array((0.0, 0.0, 1.0)),
51 }):
52  # mix colours additively
53  colour = sum(map(colours.__getitem__, instruments))
54  # use single-instrument colours as-given
55  if len(instruments) > 1:
56  # desaturate
57  colour += len(instruments) - 1
58  # normalize
59  colour /= colour.max()
60  return colour
61 
62 
63 #
64 # =============================================================================
65 #
66 # TeX Helpers
67 #
68 # =============================================================================
69 #
70 
71 
72 floatpattern = re.compile("([+-]?[.0-9]+)[Ee]([+-]?[0-9]+)")
73 
74 def latexnumber(s):
75  """
76  Convert a string of the form "d.dddde-dd" to "d.dddd \\times
77  10^{-dd}". Strings that contain neither an "e" nor an "E" are
78  returned unchanged.
79  """
80  if "e" not in s and "E" not in s:
81  return s
82  m, e = floatpattern.match(s).groups()
83  return r"%s \times 10^{%d}" % (m, int(e))
84 
85 
87  """
88  Escapes "\\" and "_" characters, and replaces " " with "~"
89  (non-breaking space).
90  """
91  return s.replace("\\", "\\\\").replace("_", "\\_").replace(" ", "~")
def latexnumber(s)
Definition: plotutil.py:74
def latexfilename(s)
Definition: plotutil.py:86