-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathextract_events.py
94 lines (74 loc) · 2.82 KB
/
extract_events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
from pyrocko import util, io
from pyrocko.gui.snuffling import Snuffling, load_markers, Param, NoViewerSet
default_output_filename = '%(eventname)s_%(network)s.%(station)s.%(location)s.%(channel)s.mseed'
class ExtractEvents(Snuffling):
'''
<html>
<head>
<style type="text/css">
body { margin-left:10px };
</style>
</head>
<body>
<h2 align="center">Extract Waveforms of Events</h2>
<p>
Select all event markers for which you want to extract waveforms. Set the
<b>Start time rel. to event</b> and <b>End time rel. to event</b> and hit
<b>Run</b>. You can modify the filename template to store
chopped trace segments in the opening file dialog. Click <b>Save</b>.
</p>
</body>
</html>
'''
def setup(self):
self.set_name('Extract Events')
self.add_parameter(Param('Start time rel. to event [s]', 'tbeg', 0., -3600., 0.))
self.add_parameter(Param('End time rel. to event [s]', 'tend', 1200., 0., 3*3600.))
self.set_live_update(False)
def call(self):
p = self.get_pile()
try:
markers = self.get_selected_event_markers()
except NoViewerSet:
markers = load_markers(self.markers_filename)
try:
out_filename = self.output_filename('Template for output files',
default_output_filename)
except NoViewerSet:
out_filename = self.out_filename
for m in markers:
event = m.get_event()
eventname = event.name
if not eventname:
eventname = util.time_to_str(event.time, format='%Y-%m-%d_%H-%M-%S')
traces = p.all(tmin=event.time + self.tbeg,
tmax=event.time + self.tend)
io.save(traces, out_filename, additional=dict(
eventname=eventname))
def configure_cli_parser(self, parser):
parser.add_option(
'--markers',
dest='markers_filename',
metavar='FILENAME',
help='Read markers from FILENAME')
parser.add_option(
'--output',
dest='out_filename',
default=default_output_filename,
metavar='FILENAME',
help='set output filename template (default="%s")' % default_output_filename)
def __snufflings__():
return [ExtractEvents()]
if __name__ == '__main__':
import logging
logger = logging.getLogger()
util.setup_logging('extract_events.py', 'info')
s = ExtractEvents()
options, args, parser = s.setup_cli()
s.markers_filename = options.markers_filename
s.out_filename = options.out_filename
if not options.markers_filename:
logger.critical('no markers file given; use the --markers=FILENAME option')
sys.exit(1)
s.call()