Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/gui/drum/main.py: 0%

106 statements  

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

5 

6from __future__ import absolute_import, print_function, division 

7 

8import sys 

9import tempfile 

10import os 

11import signal 

12import gc 

13 

14from pyrocko.gui.qt_compat import qw 

15from pyrocko import pile, orthodrome, cake 

16from pyrocko.client import catalog 

17from pyrocko.gui.util import EventMarker, PhaseMarker 

18 

19from pyrocko.gui.drum import view, state 

20 

21pjoin = os.path.join 

22 

23 

24def event_markers(tmin, tmax, magmin=6.): 

25 cat = catalog.Geofon() 

26 event_names = cat.get_event_names( 

27 time_range=(tmin, tmax), 

28 magmin=magmin) 

29 

30 markers = [] 

31 for event_name in event_names: 

32 event = cat.get_event(event_name) 

33 markers.append(EventMarker(event)) 

34 

35 return markers 

36 

37 

38def phase_markers( 

39 events, stations, phase_names='Pg,P,PKP,PKIKP,S,PP,SS'.split(',')): 

40 

41 mod = cake.load_model() 

42 phases = [] 

43 for name in phase_names: 

44 for phase in cake.PhaseDef.classic(name): 

45 phase.name = name 

46 phases.append(phase) 

47 

48 markers = [] 

49 for event in events: 

50 for station in stations: 

51 dist = orthodrome.distance_accurate50m(event, station) 

52 depth = event.depth 

53 if depth is None: 

54 depth = 0.0 

55 

56 rays = mod.arrivals( 

57 phases=phases, 

58 distances=[dist*cake.m2d], 

59 zstart=depth) 

60 

61 for ray in rays: 

62 time = ray.t 

63 name = ray.given_phase().name 

64 incidence_angle = ray.incidence_angle() 

65 takeoff_angle = ray.takeoff_angle() 

66 

67 time += event.time 

68 m = PhaseMarker( 

69 [(station.network, station.station, '*', '*')], 

70 time, 

71 time, 

72 2, 

73 phasename=name, 

74 event=event, 

75 incidence_angle=incidence_angle, 

76 takeoff_angle=takeoff_angle) 

77 

78 markers.append(m) 

79 

80 return markers 

81 

82 

83class App(qw.QApplication): 

84 def __init__(self): 

85 qw.QApplication.__init__(self, sys.argv) 

86 self.lastWindowClosed.connect(self.myQuit) 

87 self._main_window = None 

88 

89 def install_sigint_handler(self): 

90 self._old_signal_handler = signal.signal( 

91 signal.SIGINT, self.myCloseAllWindows) 

92 

93 def uninstall_sigint_handler(self): 

94 signal.signal(signal.SIGINT, self._old_signal_handler) 

95 

96 def myQuit(self, *args): 

97 self.quit() 

98 

99 def myCloseAllWindows(self, *args): 

100 self.closeAllWindows() 

101 

102 def set_main_window(self, win): 

103 self._main_window = win 

104 

105 def get_main_window(self): 

106 return self._main_window 

107 

108 

109app = None 

110 

111 

112def main(*args, **kwargs): 

113 

114 from pyrocko import util 

115 from pyrocko.gui.snuffler.snuffler_app import PollInjector, \ 

116 setup_acquisition_sources 

117 

118 util.setup_logging('drumplot', 'info') 

119 

120 global app 

121 global win 

122 

123 p = pile.Pile() 

124 

125 paths = ['school:///dev/ttyACM0?rate=40&gain=4&station=LEGO'] 

126 store_path = 'recording' 

127 if not os.path.exists(store_path): 

128 os.mkdir(store_path) 

129 

130 store_interval = 600. 

131 

132 paths.append(store_path) 

133 

134 sources = setup_acquisition_sources(paths) 

135 if store_path is None: 

136 tempdir = tempfile.mkdtemp('', 'drumplot-tmp-') 

137 store_path = pjoin( 

138 tempdir, 

139 '%(network)s.%(station)s.%(location)s.%(channel)s.%(tmin)s.mseed') 

140 

141 elif os.path.isdir(store_path): 

142 store_path = pjoin( 

143 store_path, 

144 '%(network)s.%(station)s.%(location)s.%(channel)s.%(tmin)s.mseed') 

145 

146 if app is None: 

147 app = App() 

148 

149 win = view.DrumViewMain(p) 

150 

151 pollinjector = PollInjector( 

152 p, 

153 fixation_length=store_interval, 

154 path=store_path) 

155 

156 for source in sources: 

157 source.start() 

158 pollinjector.add_source(source) 

159 

160 fns = util.select_files( 

161 paths, 

162 selector=None, 

163 regex=None, 

164 show_progress=False) 

165 

166 p.load_files(fns, show_progress=False) 

167 

168 win.state.style.antialiasing = True 

169 win.state.tline = 600. 

170 # win.state.style.background_color = state.Color(r=0.2,g=0.27,b=0.36) 

171 # win.state.style.trace_color = state.Color(r=0.9,g=0.9,b=0.9) 

172 # win.state.style.title_textstyle.color = state.Color(r=1.0,g=1.0,b=1.0) 

173 # win.state.style.label_textstyle.color = state.Color(r=1.0,g=1.0,b=1.0) 

174 win.state.filters = [state.Demean()] 

175 win.state.scaling.min = -100. 

176 win.state.scaling.max = 100. 

177 win.state.scaling.mode = 'fixed' 

178 

179 win.state.follow = True 

180 

181 # pile_nsl = set(x[:3] for x in p.nslc_ids.keys()) 

182 # stations = [ 

183 # s for s in model.load_stations(stations_fn) if s.nsl() in pile_nsl] 

184 

185 # emarks = event_markers(p.tmin, p.tmax) 

186 # pmarks = phase_markers( 

187 # events=[m.get_event() for m in emarks], 

188 # stations=stations) 

189 # 

190 # win.markers.insert_many(emarks) 

191 # win.markers.insert_many(pmarks) 

192 

193 win.show() 

194 

195 app.set_main_window(win) 

196 

197 app.install_sigint_handler() 

198 app.exec_() 

199 app.uninstall_sigint_handler() 

200 

201 for source in sources: 

202 source.stop() 

203 

204 if pollinjector: 

205 pollinjector.fixate_all() 

206 

207 del win 

208 

209 gc.collect()