Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/gui/drum/state.py: 0%
100 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-06 06:59 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-06 06:59 +0000
1# https://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from __future__ import absolute_import, print_function, division
8import math
10import numpy as num
12from pyrocko.guts import Object, Float, StringChoice, Int, String, Bool, \
13 Tuple, List
15from pyrocko.gui import talkie
18class Color(Object):
19 r = Float.T(default=0.0)
20 g = Float.T(default=0.0)
21 b = Float.T(default=0.0)
22 a = Float.T(default=1.0)
24 @property
25 def qt_color(self):
26 from pyrocko.gui.qt_compat import qg
27 color = qg.QColor(*(int(round(x*255)) for x in (
28 self.r, self.g, self.b, self.a)))
29 return color
32class ScalingMode(StringChoice):
33 choices = ['same', 'individual', 'fixed']
36class ScalingBase(StringChoice):
37 choices = [
38 'min-max', 'mean-plusminus-1-sigma',
39 'mean-plusminus-2-sigma', 'mean-plusminus-4-sigma']
42class Filter(Object):
44 def apply(self, tr):
45 pass
47 def tpad(self):
48 return 0.0
51class Demean(Filter):
52 def apply(self, tr):
53 tr.ydata = tr.ydata - num.mean(tr.ydata)
56class ButterLowpass(Filter):
57 order = Int.T(default=4)
58 corner = Float.T()
59 pad_factor = Float.T(default=1.0, optional=True)
61 def apply(self, tr):
62 tr.lowpass(self.order, self.corner)
64 def tpad(self):
65 return self.pad_factor/self.corner
68class ButterHighpass(Filter):
69 order = Int.T(default=4)
70 corner = Float.T()
71 pad_factor = Float.T(default=1.0, optional=True)
73 def apply(self, tr):
74 tr.highpass(self.order, self.corner)
76 def tpad(self):
77 return self.pad_factor/self.corner
80class Downsample(Filter):
81 deltat = Float.T()
83 def apply(self, tr):
84 tr.downsample_to(self.deltat)
87class TextStyle(talkie.Talkie):
88 family = String.T(default='default', optional=True)
89 size = Float.T(default=9.0, optional=True)
90 bold = Bool.T(default=False, optional=True)
91 italic = Bool.T(default=False, optional=True)
92 color = Color.T(default=Color.D())
93 outline = Bool.T(default=False)
94 background_color = Color.T(optional=True)
96 @property
97 def qt_font(self):
98 from pyrocko.gui.qt_compat import qg
99 font = qg.QFont(self.family)
100 font.setPointSizeF(self.size)
101 font.setBold(self.bold)
102 font.setItalic(self.italic)
103 return font
106class Style(talkie.Talkie):
107 antialiasing = Bool.T(default=False, optional=True)
108 label_textstyle = TextStyle.T(default=TextStyle.D(
109 bold=True,
110 background_color=Color(r=1.0, g=1.0, b=1.0, a=0.5),
111 ))
112 title_textstyle = TextStyle.T(default=TextStyle.D(bold=True, size=12.0))
113 marker_textstyle = TextStyle.T(default=TextStyle.D(
114 bold=False,
115 size=9.0,
116 italic=True,
117 background_color=Color(r=1.0, g=1.0, b=0.7),
118 outline=True,
119 ))
120 marker_color = Color.T(default=Color.D())
121 trace_resolution = Float.T(default=2.0, optional=True)
122 trace_color = Color.T(default=Color.D())
123 background_color = Color.T(default=Color.D(r=1.0, g=1.0, b=1.0))
126class Scaling(talkie.Talkie):
127 mode = ScalingMode.T(default='same')
128 base = ScalingBase.T(default='min-max')
129 min = Float.T(default=-1.0, optional=True)
130 max = Float.T(default=1.0, optional=True)
131 gain = Float.T(default=1.0, optional=True)
134class State(talkie.TalkieRoot):
135 nslc = Tuple.T(4, String.T(default=''))
136 tline = Float.T(default=60.*60.)
137 nlines = Int.T(default=24)
138 iline = Int.T(default=0)
140 follow = Bool.T(default=False)
142 style = Style.T(default=Style.D())
143 filters = List.T(Filter.T())
144 scaling = Scaling.T(default=Scaling.D())
146 npages_cache = Int.T(default=10, optional=True)
148 @property
149 def tmin(self):
150 return self.iline*self.tline
152 @tmin.setter
153 def tmin(self, tmin):
154 self.iline = int(math.floor(tmin / self.tline))
156 @property
157 def tmax(self):
158 return (self.iline+self.nlines)*self.tline
160 @tmax.setter
161 def tmax(self, tmax):
162 self.iline = int(math.ceil(tmax / self.tline))-self.nlines