Skip to content

Commit

Permalink
add highpass filter
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneweiqiang committed Sep 24, 2021
1 parent eba5272 commit ca9e29f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions phasenet/data_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def __init__(self, format="numpy", config=DataConfig(), **kwargs):
self.label_width = config.label_width
self.config = config
self.format = format
if "highpass_filter" in kwargs:
self.highpass_filter = kwargs["highpass_filter"]
if format in ["numpy", "mseed", "sac"]:
self.data_dir = kwargs["data_dir"]
try:
Expand Down Expand Up @@ -291,6 +293,8 @@ def read_mseed(self, fname):
mseed = obspy.read(fname)
mseed = mseed.detrend("spline", order=2, dspline=5 * mseed[0].stats.sampling_rate)
mseed = mseed.merge(fill_value=0)
if self.highpass_filter > 0:
mseed = mseed.filter("highpass", freq=self.highpass_filter)
starttime = min([st.stats.starttime for st in mseed])
endtime = max([st.stats.endtime for st in mseed])
mseed = mseed.trim(starttime, endtime, pad=True, fill_value=0)
Expand Down Expand Up @@ -326,6 +330,8 @@ def read_sac(self, fname, traces):
mseed += obspy.read(tr, format="sac")
mseed = mseed.detrend("spline", order=2, dspline=5 * mseed[0].stats.sampling_rate)
mseed = mseed.merge(fill_value=0)
if self.highpass_filter > 0:
mseed = mseed.filter("highpass", freq=self.highpass_filter)
starttime = min([st.stats.starttime for st in mseed])
endtime = max([st.stats.endtime for st in mseed])
mseed = mseed.trim(starttime, endtime, pad=True, fill_value=0)
Expand Down
2 changes: 2 additions & 0 deletions phasenet/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def read_args():
parser.add_argument("--hdf5_group", default="data", help="data group name in hdf5 file")
parser.add_argument("--result_dir", default="results", help="Output directory")
parser.add_argument("--result_fname", default="picks", help="Output file")
parser.add_argument("--highpass_filter", default=0.0, type=float, help="Highpass filter")
parser.add_argument("--min_p_prob", default=0.3, type=float, help="Probability threshold for P pick")
parser.add_argument("--min_s_prob", default=0.3, type=float, help="Probability threshold for S pick")
parser.add_argument("--mpd", default=50, type=float, help="Minimum peak distance")
Expand Down Expand Up @@ -170,6 +171,7 @@ def main(args):
hdf5_file=args.hdf5_file,
hdf5_group=args.hdf5_group,
amplitude=args.amplitude,
highpass_filter=args.highpass_filter,
)

pred_fn(args, data_reader, log_dir=args.result_dir)
Expand Down

0 comments on commit ca9e29f

Please sign in to comment.