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-23 12:34 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-23 12:34 +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 sys
9import tempfile
10import os
11import signal
12import gc
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
19from pyrocko.gui.drum import view, state
21pjoin = os.path.join
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)
30 markers = []
31 for event_name in event_names:
32 event = cat.get_event(event_name)
33 markers.append(EventMarker(event))
35 return markers
38def phase_markers(
39 events, stations, phase_names='Pg,P,PKP,PKIKP,S,PP,SS'.split(',')):
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)
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
56 rays = mod.arrivals(
57 phases=phases,
58 distances=[dist*cake.m2d],
59 zstart=depth)
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()
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)
78 markers.append(m)
80 return markers
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
89 def install_sigint_handler(self):
90 self._old_signal_handler = signal.signal(
91 signal.SIGINT, self.myCloseAllWindows)
93 def uninstall_sigint_handler(self):
94 signal.signal(signal.SIGINT, self._old_signal_handler)
96 def myQuit(self, *args):
97 self.quit()
99 def myCloseAllWindows(self, *args):
100 self.closeAllWindows()
102 def set_main_window(self, win):
103 self._main_window = win
105 def get_main_window(self):
106 return self._main_window
109app = None
112def main(*args, **kwargs):
114 from pyrocko import util
115 from pyrocko.gui.snuffler.snuffler_app import PollInjector, \
116 setup_acquisition_sources
118 util.setup_logging('drumplot', 'info')
120 global app
121 global win
123 p = pile.Pile()
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)
130 store_interval = 600.
132 paths.append(store_path)
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')
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')
146 if app is None:
147 app = App()
149 win = view.DrumViewMain(p)
151 pollinjector = PollInjector(
152 p,
153 fixation_length=store_interval,
154 path=store_path)
156 for source in sources:
157 source.start()
158 pollinjector.add_source(source)
160 fns = util.select_files(
161 paths,
162 selector=None,
163 regex=None,
164 show_progress=False)
166 p.load_files(fns, show_progress=False)
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'
179 win.state.follow = True
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]
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)
193 win.show()
195 app.set_main_window(win)
197 app.install_sigint_handler()
198 app.exec_()
199 app.uninstall_sigint_handler()
201 for source in sources:
202 source.stop()
204 if pollinjector:
205 pollinjector.fixate_all()
207 del win
209 gc.collect()