本文整理匯總了Python中obspy.Stream方法的典型用法代碼示例。如果您正苦於以下問題:Python obspy.Stream方法的具體用法?Python obspy.Stream怎麽用?Python obspy.Stream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類obspy
的用法示例。
在下文中一共展示了obspy.Stream方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: interpolate_stream
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def interpolate_stream(stream, sampling_rate, starttime=None, npts=None):
"""
For a fairly large stream, use stream.interpolate() is not a wise
choice since if there is one trace fails, then the whole interpolation
will stop. So it is better to operate interpolation on the trace
level
"""
st_new = Stream()
if not isinstance(stream, Stream):
raise TypeError("Input stream must be type of obspy.Stream")
for tr in stream:
try:
tr.interpolate(sampling_rate, starttime=starttime, npts=npts)
st_new.append(tr)
except ValueError as err:
print("Error in interpolation on '%s':%s" % (tr.id, err))
return st_new
示例2: test_sort_stream_by_station
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def test_sort_stream_by_station():
st = read(small_mseed)
st += testobs.copy()
st += testsyn.copy()
sorted = rotate.sort_stream_by_station(st)
assert len(sorted) == 3
st = read(small_mseed)
st2 = st.copy()
tr1 = st2.select(component="N")[0]
tr1.stats.channel = "EH1"
tr2 = st2.select(component="E")[0]
tr2.stats.channel = "EH2"
st += Stream([tr1, tr2])
sorted = rotate.sort_stream_by_station(st)
assert len(sorted) == 1
示例3: test_zero_padding_stream
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def test_zero_padding_stream():
tr = obspy.Trace()
array = np.array([1., 2., 3.])
tr.data = np.array(array)
st = obspy.Stream([tr])
starttime = tr.stats.starttime - 10 * tr.stats.delta
endtime = tr.stats.endtime + 5 * tr.stats.delta
st_new = deepcopy(st)
pa.zero_padding_stream(st_new, starttime, endtime)
assert len(st_new) == 1
tr_new = st_new[0]
assert tr_new.stats.starttime == (starttime - 1.0)
assert tr_new.stats.endtime == (endtime + 1.0)
assert len(tr_new) == 20
npt.assert_allclose(tr_new.data[0:11], np.zeros(11))
npt.assert_allclose(tr_new.data[11:14], array)
npt.assert_allclose(tr_new.data[14:20], np.zeros(6))
示例4: sum_adjoint_with_weighting
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def sum_adjoint_with_weighting(adj_stream, meta_info, weight_dict):
new_stream = Stream()
new_meta = {}
done_comps = []
# sum using components weight
for comp, comp_weights in weight_dict.iteritems():
for chan_id, chan_weight in comp_weights.iteritems():
if comp not in done_comps:
done_comps.append(comp)
adj_tr = adj_stream.select(id=chan_id)[0]
comp_tr = adj_tr.copy()
comp_tr.data *= chan_weight
comp_tr.stats.location = ""
comp_tr.stats.channel = comp
new_stream.append(comp_tr)
new_meta[comp_tr.id] = meta_info[adj_tr.id].copy()
new_meta[comp_tr.id]["misfit"] = \
chan_weight * meta_info[adj_tr.id]["misfit"]
else:
adj_tr = adj_stream.select(id=chan_id)[0]
comp_tr = new_stream.select(channel="*%s" % comp)[0]
comp_tr.data += chan_weight * adj_tr.data
new_meta[comp_tr.id]["misfit"] += \
chan_weight * meta_info[adj_tr.id]["misfit"]
return new_stream, new_meta
示例5: get_waveforms
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def get_waveforms():
events = get_events()
client = ArcClient(**client_kwargs)
wforms = Stream()
for i, event in enumerate(events):
print('Fetch data for event no. %d' % (i + 1))
t = event.preferred_origin().time
for sta in stations:
args = (net, sta, loc, cha, t - 10, t + 220)
try:
stream = client.getWaveform(*args)
except Exception:
print('no data for %s' % (args,))
continue
sr = stream[0].stats.sampling_rate
stream.decimate(int(sr) // 20, no_filter=True)
for tr in stream:
del tr.stats.mseed
stream.merge()
wforms.extend(stream)
wforms.write(wavname, wavformat)
return wforms
示例6: read_sds
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def read_sds(window):
config = get_config()
station = window['station']
starttime = window['starttime']
endtime = window['endtime'] + 0.1
client = sds.Client(sds_root=config['SDS_ROOT'])
stream = client.get_waveforms(network="*", station=station, location="*", channel="*",
starttime=starttime, endtime=endtime)
stream.sort(keys=['channel'], reverse=True)
stream_list = {}
for trace in stream:
geophone_type = trace.stats.channel[0:2]
if not stream_list.get(geophone_type):
stream_list[geophone_type] = Stream(trace)
else:
stream_list[geophone_type].append(trace)
return stream_list
示例7: process
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def process(self, window, *args, **kwargs):
station = window['station']
starttime = window['starttime']
endtime = window['endtime']
client = Client(sds_root=self.sds_root)
stream = client.get_waveforms(network="*", station=station, location="*", channel="*",
starttime=starttime, endtime=endtime)
stream.sort(keys=['channel'], reverse=True)
seismometer_list = {}
for trace in stream:
current_type = trace.stats.channel[0:2]
if not seismometer_list.get(current_type):
seismometer_list[current_type] = Stream(trace)
else:
seismometer_list[current_type].append(trace)
for key, value in seismometer_list.items():
yield value
示例8: check_sample
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def check_sample(stream):
"""
Returns sampling rate of traces in stream.
:type stream:`~obspy.core.stream.Stream` object.
:param stream: Stream containing one or more day-long trace
:return: List of sampling rates in stream
"""
if type(stream) == obspy.core.trace.Trace:
return stream
else:
freqs = []
for tr in stream:
freqs.append(tr.stats.sampling_rate)
freq = max(set(freqs),key=freqs.count)
for tr in stream:
if tr.stats.sampling_rate != freq:
stream.remove(tr)
return stream
示例9: check_length
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def check_length(stream):
"""
Forces all traces to have same number of samples.
Traces must be one day long.
:type stream:`~obspy.core.stream.Stream` object.
:param stream: Stream containing one or more day-long trace
:return: Stream of similar length traces
"""
pts = 24*3600*stream[0].stats.sampling_rate
npts = []
for trace in stream:
npts.append(trace.stats.npts)
npts = np.array(npts)
if len(npts) == 0:
return stream
index = np.where(npts != pts)
index = list(index[0])[::-1]
# remove short traces
for trace in index:
stream.pop(trace)
return stream
示例10: check_sample
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def check_sample(stream):
"""
Returns sampling rate of traces in stream.
:type stream:`~obspy.core.stream.Stream` object.
:param stream: Stream containing one or more day-long trace
:return: List of sampling rates in stream
"""
if len(stream)==0:
return stream
else:
freqs = []
for tr in stream:
freqs.append(tr.stats.sampling_rate)
freq = max(freqs)
for tr in stream:
if tr.stats.sampling_rate != freq:
stream.remove(tr)
return stream
示例11: clean_daily_segments
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def clean_daily_segments(tr,date_info):
'''
subfunction to clean the tr recordings. only the traces with at least 0.5-day long
sequence (respect to 00:00:00.0 of the day) is kept. note that the trace here could
be of several days recordings, so this function helps to break continuous chunck
into a day-long segment from 00:00:00.0 to 24:00:00.0.
tr: obspy stream object
return ntr: obspy stream object
'''
# duration of data
starttime = date_info['starttime']
endtime = date_info['endtime']
# make a new stream
ntr = obspy.Stream()
# trim a continous segment into user-defined sequences
tr[0].trim(starttime=starttime,endtime=endtime,pad=True,fill_value=0)
ntr.append(tr[0])
return ntr
示例12: get_data_for_tag
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def get_data_for_tag(self, station_name, tag):
"""
Returns the waveform and station data for the requested station and
path.
:param station_name: A string with network id and station id,
e.g. ``"IU.ANMO"``
:type station_name: str
:param tag: The path of the waveform.
:type tag: str
:return: tuple of the waveform and the inventory.
:rtype: (:class:`~obspy.core.stream.Stream`,
:class:`~obspy.core.inventory.inventory.Inventory`)
"""
station_name = station_name.replace(".", "_")
station = getattr(self.waveforms, station_name)
st = getattr(station, tag)
inv = (
getattr(station, "StationXML") if "StationXML" in station else None
)
return st, inv
示例13: write_coastream
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def write_coastream(self, st, write_start=None, write_end=None):
"""
Write a new .scanmseed file from an obspy Stream object containing the
data output from detect(). Note: values have been multiplied by a
power of ten, rounded and converted to an int32 array so the data can
be saved as mSEED with STEIM2 compression. This multiplication factor
is removed when the data is read back in with read_coastream().
Files are labelled by year and julian day, and split by julian day
(this behaviour is determined in signal/scan.py).
Parameters
----------
st : obspy Stream object
Output of detect() stored in obspy Stream object with
channels: ["COA", "COA_N", "X", "Y", "Z"]
write_start : UTCDateTime object, optional
Time from which to write the coastream stream to a file
write_end : UTCDateTime object, optional
Time upto which to write the coastream stream to a file
"""
if write_start or write_end:
st = st.slice(starttime=write_start, endtime=write_end)
file_str = "{}_{}_{}".format(self.name,
str(st[0].stats.starttime.year),
str(st[0].stats.starttime.julday).zfill(3))
fname = (self.run / file_str).with_suffix(".scanmseed")
st.write(str(fname), format="MSEED", encoding="STEIM2")
示例14: flex_cut_stream
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def flex_cut_stream(st, cut_start, cut_end, dynamic_npts=0):
"""
Flexible cut stream. But checks for the time.
:param st: input stream
:param cut_start: cut starttime
:param cut_end: cut endtime
:param dynamic_npts: the dynamic number of points before cut_start
and after
cut_end
:return: the cutted stream
"""
if not isinstance(st, Stream):
raise TypeError("flex_cut_stream method only accepts obspy.Stream "
"the first Argument")
new_st = Stream()
count = 0
for tr in st:
flex_cut_trace(tr, cut_start, cut_end, dynamic_npts=dynamic_npts)
# throw out small piece of data at this step
if tr.stats.starttime <= cut_start and tr.stats.endtime >= cut_end:
new_st.append(tr)
count += 1
if count == 0:
raise ValueError("None of traces in Stream satisfy the "
"cut time length")
return new_st
示例15: filter_stream
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import Stream [as 別名]
def filter_stream(st, pre_filt):
"""
Filter a stream
:param st:
:param per_filt:
:return:
"""
if not isinstance(st, Stream):
raise TypeError("Input st should be type of Stream")
for tr in st:
filter_trace(tr, pre_filt)