forked from pyrocko/contrib-snufflings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_waveforms.py
108 lines (89 loc) · 3.58 KB
/
export_waveforms.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from pyrocko import io
from pyrocko import model
from pyrocko.gui.snuffling import Snuffling, Choice, Switch, Param
class ExportWaveforms(Snuffling):
'''
<html>
<head>
<style type="text/css">
body { margin-left:10px };
</style>
</head>
<h1 align="center">Export selected or visible traces</h1>
<body>
<p>
Choose the desired format from the <b>Format</b> menu and press
<b>Run</b>.
If no traces have been selected using extended markers all traces visible
in the viewer will be exported.
</p>
<p>
Note that exporting to miniseed requires the network, station, location and
channel codes to be of length 2, 5, 2 and 3, respectively. Codes exceeding
these lenghts will be silently truncated.<br />
In order to have more control on code replacements it is recommended to use
the command line tool <b>jackseis</b> which is shipped with pyrocko.<br />
When exporting to miniseed it is possible to combine all traces into
one file by giving a filename without template placeholders.
</p>
</body>
</html>
'''
def setup(self):
self.set_name('Export Waveforms')
self.add_parameter(
Choice(
'Format', 'format', 'mseed', ['mseed', 'text', 'sac', 'yaff']))
self.add_parameter(
Param(
'Time length limit for output files', 'tinc', None,
0.1, 86400., low_is_none=True))
self.add_parameter(Switch('Save Station Meta', 'save_stations', False))
self.add_parameter(Switch('Apply Filters', 'apply_filter', False))
self.set_live_update(False)
def call(self):
self.cleanup()
if self.tinc is not None:
template = \
'trace_%n.%s.%l.%c_%(tmin_us)s'
else:
template = 'trace_%n.%s.%l.%c'
if self.format == 'text':
default_output_filename = template + '.dat'
else:
default_output_filename = template + '.' + self.format
out_filename = self.output_filename('Template for output files',
default_output_filename)
viewer = self.get_viewer()
for trs in self.chopper_selected_traces(fallback=True, tinc=self.tinc):
trs2save = []
for tr in trs:
if self.format == 'mseed':
if len(tr.network) > 2:
tr.set_network(tr.network[:2])
if len(tr.station) > 5:
tr.set_station(tr.station[:5])
if len(tr.location) > 2:
tr.set_location(tr.location[:2])
if len(tr.channel) > 3:
tr.set_channel(tr.channel[:3])
if viewer.lowpass:
if viewer.lowpass < 0.5/tr.deltat:
tr.lowpass(4, viewer.lowpass, demean=False)
if viewer.highpass:
if viewer.highpass < 0.5/tr.deltat:
tr.highpass(4, viewer.highpass, demean=False)
trs2save.append(tr)
try:
io.save(
trs2save, out_filename,
format=self.format,
overwrite=True)
except io.io_common.FileSaveError as e:
self.fail(str(e))
if self.save_stations:
stations = viewer.stations.values()
fn = self.output_filename('Save Stations', 'stations.pf')
model.dump_stations(list(stations), fn)
def __snufflings__():
return [ExportWaveforms()]