Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions geonet_obspy_utils/clients/aws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from parse import parse
from itertools import product


class Client(object):
"""
AWS Client to access waveform (all available clients) and event
Expand Down Expand Up @@ -112,7 +111,7 @@ def _list_available_files(self, prefix):
except self._s3.exceptions.NoSuchBucket:
print(f"Bucket '{self.waveform_bucket_name}' does not exist.")
except Exception as e:
print(f"Error accessing S3 bucket '{self.bucket_name}': {e}")
print(f"Error accessing S3 bucket '{self.waveform_bucket_name}': {e}")
return file_list

def get_waveforms(self, network, station, location, channel, starttime,
Expand Down Expand Up @@ -535,13 +534,34 @@ def _fix_mseed_timing(mstl_traceids):
"""
stream = Stream()
for traceid in mstl_traceids:
for segment in traceid.segments():
try:
segments = list(traceid.segments())
except ValueError as e:
n, s, l, c = sourceid2nslc(traceid.sourceid)
print(f"Skipping trace {n}.{s}.{l}.{c} due to mseedlib and ctypes error: {e}")
continue
for segment in segments:
data = np.ctypeslib.as_array(segment.datasamples)
# compute actual average sampling interval
dt = (UTCDateTime(segment.endtime_str()) -
UTCDateTime(segment.starttime_str()))/(len(data)-1)
trace = Trace()
n, s, l, c = sourceid2nslc(traceid.sourceid)

if len(data) <= 1:
print(f"Trace {n}.{s}.{l}.{c} has {len(data)} sample(s). "
"Skipping timing correction.")
continue

total_time = (UTCDateTime(segment.endtime_str()) -
UTCDateTime(segment.starttime_str()))

if total_time <= 0 or segment.samprate <= 0:
print(f"Trace {n}.{s}.{l}.{c} has degenerate timing "
f"(total_time={total_time}, samprate={segment.samprate}). "
"Skipping.")
continue

dt = total_time / (len(data) - 1)
trace = Trace()

trace.data = data
trace.stats.network = n
trace.stats.station = s
Expand All @@ -550,8 +570,9 @@ def _fix_mseed_timing(mstl_traceids):
trace.stats.starttime = UTCDateTime(segment.starttime_str())
trace.stats.delta = dt

trace.resample(int(segment.samprate))
trace.stats.sampling_rate = int(segment.samprate)
nominal_rate = round(segment.samprate) if segment.samprate >= 0.5 else segment.samprate
trace.resample(nominal_rate)
trace.stats.sampling_rate = nominal_rate

stream += trace

Expand Down