Skip to content

Commit 85cf860

Browse files
committed
Miscellaneous Changes
* Added an option to control when a high-pass filter is applied in bulk_rf_report.py * Added options to filter output in rf_inversion_export.py
1 parent b7aa0fd commit 85cf860

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

seismic/receiver_fn/bulk_rf_report.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,17 @@ def _plot_hk_solution_point(axes, k, h, idx, phase_time_dict=None):
285285
'purposes. Note that this parameter has no effect on the computation of the hk_stack')
286286
@click.option('--hk-hpf-freq', type=float, default=None, show_default=True,
287287
help='If present, cutoff frequency for high pass filter to use prior to generating H-k stacking plot')
288+
@click.option('--hk-hpf-after-dereverberation', is_flag=True, default=False, show_default=True,
289+
help='If present, the high pass filter is applied after dereverberation -- by default, it is '
290+
'applied before dereverberation. This flag has no effect if --hk-hpf-freq is not specified')
288291
@click.option('--disable-semblance-weighting', is_flag=True, default=False, show_default=True,
289292
help='Disables default semblance-weighting applied to H-k stacks')
290293
def main(input_file, output_file, network_list='*', station_list='*', event_mask_folder='',
291294
apply_amplitude_filter=False, apply_similarity_filter=False, min_slope_ratio=-1,
292295
force_dereverberate=None, filter_by_distance=None,
293296
hk_vp=rf_stacking.DEFAULT_Vp, hk_weights=rf_stacking.DEFAULT_WEIGHTS,
294297
hk_solution_labels=DEFAULT_HK_SOLN_LABEL, depth_colour_range=(20, 70),
295-
hk_hpf_freq=None, disable_semblance_weighting=False):
298+
hk_hpf_freq=None, hk_hpf_after_dereverberation=False, disable_semblance_weighting=False):
296299

297300
"""
298301
INPUT_FILE : Input RFs in H5 format\n
@@ -488,13 +491,13 @@ def match_stations(sta, sta_list):
488491
rf_stream = rf_util.filter_crosscorr_coeff(rf_stream)
489492
# end if
490493

491-
if not rf_stream:
492-
continue
494+
if not rf_stream: continue
493495

494496
###############################################################################
495-
# Filter rf_stream if needed
497+
# Filter rf_stream if needed. The default approach is to filter before
498+
# dereverberation is applied
496499
###############################################################################
497-
if(hk_hpf_freq and hk_hpf_freq>0):
500+
if(hk_hpf_freq and hk_hpf_freq>0 and not hk_hpf_after_dereverberation):
498501
rf_stream.filter(type='highpass', freq=hk_hpf_freq,
499502
corners=1, zerophase=True)
500503
# end if
@@ -529,8 +532,15 @@ def match_stations(sta, sta_list):
529532
# end if
530533
# end if
531534

532-
if not rf_stream:
533-
continue
535+
if not rf_stream: continue
536+
537+
###############################################################################
538+
# Filter rf_stream if needed, after dereverberation, as requested
539+
###############################################################################
540+
if(hk_hpf_freq and hk_hpf_freq>0 and hk_hpf_after_dereverberation):
541+
rf_stream.filter(type='highpass', freq=hk_hpf_freq,
542+
corners=1, zerophase=True)
543+
# end if
534544

535545
############################################
536546
# Collate streams to plot

seismic/receiver_fn/rf_inversion_export.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def rf_inversion_export(input_h5_file, output_folder, network_list="*", station_
7070
min_station_weight=-1, apply_amplitude_filter=False, apply_similarity_filter=False,
7171
min_slope_ratio=-1, dereverberate=False, baz_range=(0, 360),
7272
apply_phase_weighting=False, pw_exponent=1.,
73-
resample_freq=None, trim_window=(-5.0, 30.0),
73+
fmin=None, fmax=None, resample_freq=None, trim_window=(-5.0, 30.0),
7474
moveout=True, logger=None):
7575
"""Export receiver function to text format for ingestion into Fortran RF inversion code.
7676
@@ -93,6 +93,8 @@ def rf_inversion_export(input_h5_file, output_folder, network_list="*", station_
9393
:type min_slope_ratio: float
9494
:param dereverberate
9595
type: bool
96+
:param fmin: minimum frequency for bandpass filter
97+
:param fmax: maximum frequency for bandpass filter
9698
:param resample_freq: Sampling rate (Hz) of the output files. The default (None) preserves original sampling rate
9799
:type resample_freq: float, optional
98100
:param trim_window: Time window to export relative to onset, defaults to (-5.0, 30.0). If data needs
@@ -112,8 +114,9 @@ def rf_inversion_export(input_h5_file, output_folder, network_list="*", station_
112114
# 7. Apply back-azimuth filter if specified
113115
# 8. Quality filter to those that meet criteria (Sippl cross-correlation similarity)
114116
# 9. Moveout and stack the RFs
115-
# 10. Resample (lanczos) and trim RF
116-
# 11. Export one file per station in (time, amplitude format)
117+
# 10 Apply lowpass/highpass/bandpass filter based on fmin and fmax
118+
# 11. Resample (lanczos) and trim RF
119+
# 12. Export one file per station in (time, amplitude format)
117120

118121
TRIM_BUFFER = 10
119122
if(logger is None): logger = setup_logger('__func__')
@@ -307,6 +310,18 @@ def rf_inversion_export(input_h5_file, output_folder, network_list="*", station_
307310
# end if
308311
trace = stack[0]
309312

313+
# Apply filter as specified
314+
if(fmin and fmax):
315+
logger.info('{}.{}.{}: Applying a bandpass filter..'.format(network_code, sta, loc))
316+
stack.filter(type='bandpass', freqmin=fmin, freqmax=fmax, corners=1, zerophase=True)
317+
elif(fmin):
318+
logger.info('{}.{}.{}: Applying a highpass filter..'.format(network_code, sta, loc))
319+
stack.filter(type='highpass', freq=fmin, corners=1, zerophase=True)
320+
elif(fmax):
321+
logger.info('{}.{}.{}: Applying a lowpass filter..'.format(network_code, sta, loc))
322+
stack.filter(type='lowpass', freq=fmax, corners=1, zerophase=True)
323+
# end if
324+
310325
if(resample_freq is not None):
311326
exact_start_time = trace.stats.onset + trim_window[0]
312327
stack.interpolate(sampling_rate=resample_freq, method='lanczos', a=10, starttime=exact_start_time)
@@ -449,11 +464,17 @@ def _plot(ax, t, d, i, label):
449464
@click.option('--pw-exponent', type=float, default=1, show_default=True,
450465
help='Exponent used in instantaneous phase-weighting of RF amplitudes. This parameter '
451466
'has no effect when --apply-phase-weighting is absent.')
467+
@click.option('--fmin', type=float, default=None, show_default=True,
468+
help="Lowest frequency for bandpass filter; default is None."
469+
"If only --fmin in provided, a highpass filter is aplied.")
470+
@click.option('--fmax', type=float, default=None, show_default=True,
471+
help="Highest frequency for bandpass filter; default is None."
472+
"If only --fmax is provided, a lowpass filter is applied.")
452473
@click.option('--resample-rate', default=None, type=float, show_default=True,
453474
help='Resampling rate (Hz) for output traces.')
454475
def main(input_file, output_folder, output_plot_file, network_list, station_list, station_weights,
455476
min_station_weight, apply_amplitude_filter, apply_similarity_filter, min_slope_ratio, baz_range,
456-
dereverberate, apply_phase_weighting, pw_exponent, resample_rate):
477+
dereverberate, apply_phase_weighting, pw_exponent, fmin, fmax, resample_rate):
457478
"""
458479
INPUT_FILE : Input RFs in H5 format\n
459480
(output of generate_rf.py or rf_quality_filter.py)\n
@@ -474,6 +495,8 @@ def main(input_file, output_folder, output_plot_file, network_list, station_list
474495
dereverberate=dereverberate,
475496
apply_phase_weighting=apply_phase_weighting,
476497
pw_exponent=pw_exponent,
498+
fmin=fmin,
499+
fmax=fmax,
477500
resample_freq=resample_rate,
478501
trim_window=(-5., 30.),
479502
moveout=True,

0 commit comments

Comments
 (0)