Skip to content

Commit 2bb56bc

Browse files
committed
New option --freq_band for trace plotting commands
1 parent b0a71f8 commit 2bb56bc

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ to the latest version.
2020
scale
2121
- New option `--force` for commands that write files, to overwrite existing
2222
files without asking
23+
- New option `--freq_band` for trace plotting commands, to override the
24+
frequency band specified in the config file
2325
- Config option `waveform_data_path` renamed to `sds_data_path`
2426
- New config option `event_data_path` to specify the path to a local directory
2527
with waveform files organized per event

requake/config/parse_arguments.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def parse_arguments(progname='requake'):
183183
type=float, default=None,
184184
help='maximum cross-correlation coefficient (default: %(default)s)'
185185
)
186+
# ---
186187
# --- traceid
187188
# a parent parser for the "traceid" option,
188189
# used by several subparsers
@@ -192,10 +193,21 @@ def parse_arguments(progname='requake'):
192193
help='use this traceid instead of the one set in the config file'
193194
)
194195
# ---
196+
# --- freq_band
197+
# a parent parser for the "freq_band" option,
198+
# used by several subparsers
199+
freq_band = argparse.ArgumentParser(add_help=False)
200+
freq_band.add_argument(
201+
'-F', '--freq_band', nargs=2, type=float, default=None,
202+
metavar=('FREQ_MIN', 'FREQ_MAX'),
203+
help='use this frequency band instead of the one set in the '
204+
'config file. Specify FREQ_MIN and FREQ_MAX in Hz.'
205+
)
206+
# ---
195207
# --- plot_pair
196208
plot_pair = subparser.add_parser(
197209
'plot_pair',
198-
parents=[traceid],
210+
parents=[traceid, freq_band],
199211
help='plot traces for a given event pair'
200212
)
201213
plot_pair.add_argument('evid1')
@@ -308,7 +320,10 @@ def parse_arguments(progname='requake'):
308320
# --- plot_families
309321
plotfamilies = subparser.add_parser(
310322
'plot_families',
311-
parents=[longerthan, shorterthan, minevents, family_numbers, traceid],
323+
parents=[
324+
longerthan, shorterthan, minevents, family_numbers,
325+
traceid, freq_band
326+
],
312327
help='plot traces for one ore more event families'
313328
)
314329
plotfamilies.add_argument(

requake/plot/plot_pair.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def plot_pair():
7474
fig.canvas.manager.set_window_title(title)
7575
title = f'{tr1.stats.evid}-{tr2.stats.evid} CC: {cc_max:.2f}'
7676
ax[0].set_title(title, loc='left')
77-
title = f'{tr1.id} | {config.cc_freq_min:.1f}-{config.cc_freq_max:.1f} Hz'
77+
title = f'{tr1.id} | {tr1.stats.freq_min:.1f}-{tr1.stats.freq_max:.1f} Hz'
7878
ax[0].set_title(title, loc='right')
7979
stats1 = tr1.stats
8080
stats2 = tr2.stats

requake/waveforms/waveforms.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,39 @@ def get_event_waveform(ev):
302302
return tr
303303

304304

305-
def process_waveforms(st):
306-
"""Demean and filter a waveform trace or stream."""
307-
st = st.copy()
308-
st.detrend(type='demean')
309-
st.taper(max_percentage=0.05, type='cosine')
310-
st.filter(
305+
def process_waveforms(tr_or_st):
306+
"""
307+
Demean and filter a waveform trace or stream.
308+
309+
:param tr_or_st: waveform stream or trace
310+
:type tr_or_st: obspy.Stream or obspy.Trace
311+
312+
:return: processed waveform stream or trace
313+
:rtype: obspy.Stream or obspy.Trace
314+
"""
315+
tr_or_st = tr_or_st.copy()
316+
tr_or_st.detrend(type='demean')
317+
tr_or_st.taper(max_percentage=0.05, type='cosine')
318+
freq_min = (
319+
config.args.freq_band[0] if config.args.freq_band else
320+
config.cc_freq_min
321+
)
322+
freq_max = (
323+
config.args.freq_band[1] if config.args.freq_band else
324+
config.cc_freq_max
325+
)
326+
tr_or_st.filter(
311327
type='bandpass',
312-
freqmin=config.cc_freq_min,
313-
freqmax=config.cc_freq_max)
314-
return st
328+
freqmin=freq_min,
329+
freqmax=freq_max)
330+
if isinstance(tr_or_st, Stream):
331+
for tr in tr_or_st:
332+
tr.stats.freq_min = freq_min
333+
tr.stats.freq_max = freq_max
334+
else:
335+
tr_or_st.stats.freq_min = freq_min
336+
tr_or_st.stats.freq_max = freq_max
337+
return tr_or_st
315338

316339

317340
skipped_evids = []

0 commit comments

Comments
 (0)