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 2024-01-04 09:19 +0000

1# https://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6from __future__ import absolute_import, print_function, division 

7 

8import math 

9 

10import numpy as num 

11 

12from pyrocko.guts import Object, Float, StringChoice, Int, String, Bool, \ 

13 Tuple, List 

14 

15from pyrocko.gui import talkie 

16 

17 

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) 

23 

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 

30 

31 

32class ScalingMode(StringChoice): 

33 choices = ['same', 'individual', 'fixed'] 

34 

35 

36class ScalingBase(StringChoice): 

37 choices = [ 

38 'min-max', 'mean-plusminus-1-sigma', 

39 'mean-plusminus-2-sigma', 'mean-plusminus-4-sigma'] 

40 

41 

42class Filter(Object): 

43 

44 def apply(self, tr): 

45 pass 

46 

47 def tpad(self): 

48 return 0.0 

49 

50 

51class Demean(Filter): 

52 def apply(self, tr): 

53 tr.ydata = tr.ydata - num.mean(tr.ydata) 

54 

55 

56class ButterLowpass(Filter): 

57 order = Int.T(default=4) 

58 corner = Float.T() 

59 pad_factor = Float.T(default=1.0, optional=True) 

60 

61 def apply(self, tr): 

62 tr.lowpass(self.order, self.corner) 

63 

64 def tpad(self): 

65 return self.pad_factor/self.corner 

66 

67 

68class ButterHighpass(Filter): 

69 order = Int.T(default=4) 

70 corner = Float.T() 

71 pad_factor = Float.T(default=1.0, optional=True) 

72 

73 def apply(self, tr): 

74 tr.highpass(self.order, self.corner) 

75 

76 def tpad(self): 

77 return self.pad_factor/self.corner 

78 

79 

80class Downsample(Filter): 

81 deltat = Float.T() 

82 

83 def apply(self, tr): 

84 tr.downsample_to(self.deltat) 

85 

86 

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) 

95 

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 

104 

105 

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)) 

124 

125 

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) 

132 

133 

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) 

139 

140 follow = Bool.T(default=False) 

141 

142 style = Style.T(default=Style.D()) 

143 filters = List.T(Filter.T()) 

144 scaling = Scaling.T(default=Scaling.D()) 

145 

146 npages_cache = Int.T(default=10, optional=True) 

147 

148 @property 

149 def tmin(self): 

150 return self.iline*self.tline 

151 

152 @tmin.setter 

153 def tmin(self, tmin): 

154 self.iline = int(math.floor(tmin / self.tline)) 

155 

156 @property 

157 def tmax(self): 

158 return (self.iline+self.nlines)*self.tline 

159 

160 @tmax.setter 

161 def tmax(self, tmax): 

162 self.iline = int(math.ceil(tmax / self.tline))-self.nlines