Skip to content

Commit

Permalink
implement rf length fix (#250)
Browse files Browse the repository at this point in the history
Co-authored-by: Auggie Marignier <augustin.marignier.14@ucl.ac.uk>
  • Loading branch information
auggiemarignier and Auggie Marignier committed May 12, 2023
1 parent 603b1e5 commit 5e18e52
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions seismic/receiver_fn/generate_rf_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,19 @@ def transform_stream_to_rf(ev_id, stream3c, config_filtering,
tr.stats.update(metadata)
# end for

# If traces are just one sample longer or shorter than the expected length
# pad with a zero at the end or remove last sample
# If lengths are wildly differnt than expected, trace will be dropped in rf_quality_filter.py
expected_length = (trim_end_time_sec - trim_start_time_sec) * resample_rate_hz
for tr in stream3c:
if tr.data.size == expected_length - 1:
tr.data = np.concatenate((tr.data, np.zeros(1)))
elif tr.data.size == expected_length + 1:
tr.data = tr.data[:-1]
elif tr.data.size == expected_length:
continue
else:
logger.warning("Unexpected length of trace {}".format(ev_id))

return stream3c
# end func

0 comments on commit 5e18e52

Please sign in to comment.