本文整理汇总了Python中obspy.core.stream.Stream.append方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.append方法的具体用法?Python Stream.append怎么用?Python Stream.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.core.stream.Stream
的用法示例。
在下文中一共展示了Stream.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: join_NERT
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def join_NERT(a,b):
new=Stream()
for i in range(len(a)):
if a[i].stats['station'] == b[i].stats['station'] and \
a[i].stats['channel'] == b[i].stats['channel']:
new.append(a[i])
else:
new.append(a[i])
new.append(b[i])
return new
示例2: purgeListStation
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def purgeListStation(st,args,ty):
new=Stream()
ra=args.radius.split()
lii = []
# select for distances
if(ty=='d'):
for i in range(len(st)):
if(st[i].stats.gcarc >= eval(ra[0]) and st[i].stats.gcarc <= eval(ra[1])):
new.append(st[i])
return new
示例3: saveData
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def saveData(self, filename = None):
stream = Stream()
for i in range(0,self.ntraces):
curr_trace = self.data[:,i]
curr_trace = np.require(curr_trace, dtype='float32')
temp = Trace(data=curr_trace)
# Attributes in trace.stats will overwrite everything in
# trace.stats.segy.trace_header
temp.stats.delta = 0.01
# Add trace to stream
stream.append(temp)
print "Stream object before writing..."
print stream
stream.write(filename, format="SEGY", data_encoding=1,
byteorder=sys.byteorder)
示例4: poisson_segmenting
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def poisson_segmenting(poisson_times, noise_trace, samp_rate, delta, st_event_2):
""" Sets out the events at the poisson times (from poisson_interevent), and adds the noise onto the event at that point.
"""
st_events_poisson = Stream()
for i in range(0, len(poisson_times)):
testnoise = np.array(noise_trace)
noise_portion = testnoise[(poisson_times[i]*int(samp_rate)):
(poisson_times[i]*int(samp_rate)) + len(st_event_2)]
noise_plus_event_arr = noise_portion + np.array(st_event_2)
noise_plus_event = Trace(noise_plus_event_arr)
noise_plus_event.stats.sampling_rate = samp_rate
noise_plus_event.stats.delta = delta
noise_plus_event.stats.starttime = noise_trace.stats.starttime + poisson_times[i]
#plt.plot(noise_plus_event)
st_events_poisson.append(noise_plus_event)
st_events_poisson[-1].stats.endtime+100
return st_events_poisson
示例5: stream_stack_distance_intervals
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def stream_stack_distance_intervals(st, interval):
""" Stack average traces in a stream if their distance difference is
smaller than interval.
The stream containing a number of traces with given distance (e.g. from source)
is used to create a number of equally spaced traces by averaging traces that fall
into the same distance bin. If interval is a scalar the bins are equally spaced with
a width of interval. If interval is a sequence its elements define the lower distance
limit of the bins.
:type st: :class:`~obspy.core.stream.Stream`
:param st: Stream fo be used for stacking.
:type interval: scalar os array like
:param interval: width of bins in case of scalar or smaller edge of
bins if interval is a sequence.
:rtype sst: :class:`~obspy.core.stream.Stream`
:return: **sst**: stacked stream
"""
dist = []
npts = []
for tr in st:
dist.append(tr.stats.sac['dist'])
npts.append(tr.stats['npts'])
if not hasattr(interval, "__len__"):
bins = np.arange(min(dist), max(dist),interval)
else:
bins = np.array(interval)
sst = Stream()
for ii in bins:
sst.append(Trace(data=np.zeros(max(npts),dtype=np.float64),header={
'network':'stack','station':str(ii),'location':'',
'channel':st[0].stats['channel'],'starttime':st[0].stats['starttime'],'sampling_rate':st[0].stats['sampling_rate'],
'sac':{'dist':ii,'az':0,'evla':0.,'evlo':0.,'stla':ii/(np.pi*6371000)*180.,'stlo':0.}}))
count = np.zeros_like(bins)
for tr in st:
ind = sum((tr.stats.sac['dist'] - bins)>=0)-1
sst[ind].data[0:tr.stats['npts']] += tr.data
count[ind] += 1
for ind, tr in enumerate(sst):
tr.data /= count[ind]
return sst
示例6: dataclean
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def dataclean(alltrigs, opt, flag=1):
"""
Examine triggers and weed out spikes and calibration pulses using kurtosis and
outlier ratios
alltrigs: triggers output from triggering
opt: opt from config
flag: 1 if defining window to check, 0 if want to check whole waveform for spikes
(note that different threshold values should be used for different window lengths)
Returns good trigs (trigs) and junk (junk)
"""
trigs=Stream()
junk=Stream()
for i in range(len(alltrigs)):
#define data
dat=alltrigs[i].data
if flag==0:
datcut=dat
else:
datcut=alltrigs[i].data[range(int((opt.ptrig-opt.kurtwin/2)*opt.samprate),
int((opt.ptrig+opt.kurtwin/2)*opt.samprate))]
#calculate kurtosis in window
k = stats.kurtosis(datcut)
#compute kurtosis of frequency amplitude spectrum next
datf = np.absolute(fft(dat))
kf = stats.kurtosis(datf)
#calculate outlier ratio using z ((data-median)/mad), outliers have z>4.45
mad = np.median(np.absolute(dat - np.median(dat)))
z=(dat-np.median(dat))/mad
orm = len(z[z>4.45])/len(z)
if k<opt.kurtmax and orm<opt.oratiomax and kf<opt.kurtfmax:
trigs.append(alltrigs[i])
else:
junk.append(alltrigs[i])
return trigs, junk
示例7: corr_trace_to_obspy
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def corr_trace_to_obspy(corr_trace):
""" Convert a correlation trace dictionary to an obspy trace.
Convert a single correlation trace (or a list of) in an
:class:`~obspy.core.trace.Trace` (or :class:`~obspy.core.stream.Stream`)
object.
:type corr_trace: dictionary of type correlation trace or list of these
:param corr_trace: input date to be converted
:rtype: :class:`~obspy.core.trace.Trace` if ``corr_trace`` is a dict
and :class:`~obspy.core.stream.Stream` if ``corr_trace`` is a list of
dicts
:return: **st**: the obspy object containing the data
"""
if isinstance(corr_trace, list):
st = Stream()
for tr in corr_trace:
st.append(_single_corr_trace_to_obspy_trace(tr))
else:
st = _single_corr_trace_to_obspy_trace(corr_trace)
return st
示例8: removeGaps
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def removeGaps(self, min_gap, max_gap, verbose="False"):
"""
Returns the Stream object without trace gaps/overlaps.
:param min_gap: All gaps smaller than this value will be omitted. The
value is assumed to be in seconds. Defaults to None.
:param max_gap: All gaps larger than this value will be omitted. The
value is assumed to be in seconds. Defaults to None.
:param verbose: stdout traces removed. Default verbose=False
"""
new=Stream()
self.sort()
gap_list = []
# since one would be left
if(len(self) != 0):
self.append(self[0])
for _i in xrange(1,len(self.traces) - 0):
# skip traces with different network, station, location or channel
if self.traces[_i - 1].id != self.traces[_i + 0].id:
new.append(self.traces[_i])
continue
# different sampling rates should always result in a gap or overlap
if self.traces[_i - 1].stats.delta == self.traces[_i + 0].stats.delta:
flag = True
else:
flag = False
stats = self.traces[_i - 1].stats
stime = stats['endtime']
etime = self.traces[_i + 0].stats['starttime']
delta = etime.timestamp - stime.timestamp
# Check that any overlap is not larger than the trace coverage
if delta < 0:
temp = self.traces[_i + 0].stats['endtime'].timestamp - \
etime.timestamp
if (delta * -1) > temp:
delta = -1 * temp
# Check gap/overlap criteria
if min_gap and delta < min_gap:
new.append(self.traces[_i - 1])
continue
if max_gap and delta > max_gap:
new.append(self.traces[_i - 1])
continue
# Number of missing samples
nsamples = int(round(fabs(delta) * stats['sampling_rate']))
# skip if is equal to delta (1 / sampling rate)
if flag and nsamples == 1:
new.append(self.traces[_i - 1])
continue
elif delta > 0:
nsamples -= 1
else:
nsamples += 1
gap_list.append([_i,stats['network'], stats['station'],
stats['location'], stats['channel'],
stime, etime, delta, nsamples])
if verbose == "True" or verbose == "TRUE" or verbose == "true":
print "Removed because of gap: ",stats['network'],stats['station'],stats['channel'],stime,etime,delta, nsamples
return new
示例9: get_preview
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def get_preview(self, trace_ids=[], starttime=None, endtime=None,
network=None, station=None, location=None, channel=None,
pad=False):
"""
Returns the preview trace.
"""
# build up query
session = self.session()
query = session.query(WaveformChannel)
# start and end time
try:
starttime = UTCDateTime(starttime)
except:
starttime = UTCDateTime() - 60 * 20
finally:
query = query.filter(WaveformChannel.endtime > starttime.datetime)
try:
endtime = UTCDateTime(endtime)
except:
# 10 minutes
endtime = UTCDateTime()
finally:
query = query.filter(WaveformChannel.starttime < endtime.datetime)
# process arguments
if trace_ids:
# filter over trace id list
trace_filter = or_()
for trace_id in trace_ids:
temp = trace_id.split('.')
if len(temp) != 4:
continue
trace_filter.append(and_(
WaveformChannel.network == temp[0],
WaveformChannel.station == temp[1],
WaveformChannel.location == temp[2],
WaveformChannel.channel == temp[3]))
if trace_filter.clauses:
query = query.filter(trace_filter)
else:
# filter over network/station/location/channel id
kwargs = {'network': network, 'station': station,
'location': location, 'channel': channel}
for key, value in kwargs.items():
if value is None:
continue
col = getattr(WaveformChannel, key)
if '*' in value or '?' in value:
value = value.replace('?', '_')
value = value.replace('*', '%')
query = query.filter(col.like(value))
else:
query = query.filter(col == value)
# execute query
results = query.all()
session.close()
# create Stream
st = Stream()
for result in results:
preview = result.get_preview()
st.append(preview)
# merge and trim
st = merge_previews(st)
st.trim(starttime, endtime, pad=pad)
return st
示例10: mergePreviews
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def mergePreviews(stream):
"""
Merges all preview traces in one Stream object. Does not change the
original stream because the data needs to be copied anyway.
:type stream: :class:`~obspy.core.Stream`
:param stream: Stream object to be merged
:rtype: :class:`~obspy.core.Stream`
:return: Merged Stream object.
"""
copied_traces = copy(stream.traces)
stream.sort()
# Group traces by id.
traces = {}
dtypes = []
for trace in stream:
# Throw away empty traces.
if trace.stats.npts == 0:
continue
if not hasattr(trace.stats, 'preview') or not trace.stats.preview:
msg = 'Trace\n%s\n is no preview file.' % str(trace)
raise Exception(msg)
traces.setdefault(trace.id, [])
traces[trace.id].append(trace)
dtypes.append(trace.data.dtype)
if len(traces) == 0:
return Stream()
# Initialize new Stream object.
new_stream = Stream()
for value in traces.values():
if len(value) == 1:
new_stream.append(value[0])
continue
# All traces need to have the same delta value and also be on the same
# grid spacing. It is enough to only check the sampling rate because
# the algorithm that creates the preview assures that the grid spacing
# is correct.
sampling_rates = set([tr.stats.sampling_rate for tr in value])
if len(sampling_rates) != 1:
msg = 'More than one sampling rate for traces with id %s.' % \
value[0].id
raise Exception(msg)
delta = value[0].stats.delta
# Check dtype.
dtypes = set([str(tr.data.dtype) for tr in value])
if len(dtypes) > 1:
msg = 'Different dtypes for traces with id %s' % value[0].id
raise Exception(msg)
dtype = dtypes.pop()
# Get the minimum start and maximum endtime for all traces.
min_starttime = min([tr.stats.starttime for tr in value])
max_endtime = max([tr.stats.endtime for tr in value])
samples = (max_endtime - min_starttime) / delta + 1
data = np.empty(samples, dtype=dtype)
# Fill with negative one values which corresponds to a gap.
data[:] = -1
# Create trace and give starttime.
new_trace = Trace(data=data, header=value[0].stats)
# Loop over all traces in value and add to data.
for trace in value:
start_index = int((trace.stats.starttime - min_starttime) / delta)
end_index = start_index + len(trace.data)
# Element-by-element comparison.
data[start_index:end_index] = \
np.maximum(data[start_index:end_index], trace.data)
# set npts again, because data is changed in place
new_trace.stats.npts = len(data)
new_stream.append(new_trace)
stream.traces = copied_traces
return new_stream
示例11: dataclean
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def dataclean(alltrigs, opt, flag=1):
"""
Examine triggers and weed out spikes and calibration pulses using kurtosis and
outlier ratios
alltrigs: triggers output from triggering
opt: opt from config
flag: 1 if defining window to check, 0 if want to check whole waveform for spikes
(note that different threshold values should be used for different window lengths)
Returns good trigs (trigs) and junk (junk)
"""
trigs=Stream()
junk=Stream()
for i in range(len(alltrigs)):
njunk = 0
ntele = 0
for n in range(opt.nsta):
dat = alltrigs[i].data[n*opt.wshape:(n+1)*opt.wshape]
if flag == 1:
datcut=dat[range(int((opt.ptrig-opt.kurtwin/2)*opt.samprate),
int((opt.ptrig+opt.kurtwin/2)*opt.samprate))]
else:
datcut=dat
# Calculate kurtosis in window
k = stats.kurtosis(datcut)
# Compute kurtosis of frequency amplitude spectrum next
datf = np.absolute(fft(dat))
kf = stats.kurtosis(datf)
# Calculate outlier ratio using z ((data-median)/mad); outliers have z > 4.45
mad = np.median(np.absolute(dat - np.median(dat)))
z = (dat-np.median(dat))/mad
orm = len(z[z>4.45])/np.array(len(z)).astype(float)
if k >= opt.kurtmax or orm >= opt.oratiomax or kf >= opt.kurtfmax:
njunk+=1
winstart = opt.ptrig*opt.samprate - opt.winlen/10
winend = opt.ptrig*opt.samprate - opt.winlen/10 + opt.winlen
fftwin = np.reshape(fft(dat[winstart:winend]),(opt.winlen,))
if np.median(np.abs(dat[winstart:winend]))!=0:
fi = np.log10(np.mean(np.abs(np.real(
fftwin[int(opt.fiupmin*opt.winlen/opt.samprate):int(
opt.fiupmax*opt.winlen/opt.samprate)])))/np.mean(np.abs(np.real(
fftwin[int(opt.filomin*opt.winlen/opt.samprate):int(
opt.filomax*opt.winlen/opt.samprate)]))))
if fi<opt.telefi:
ntele+=1
# Allow if there are enough good stations to correlate
if njunk <= (opt.nsta-opt.ncor) and ntele <= opt.teleok:
trigs.append(alltrigs[i])
else:
junk.append(alltrigs[i])
return trigs, junk
示例12: trigger
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def trigger(st, stC, rtable, opt):
"""
Run triggering algorithm on a stream of data.
st: OBSPy stream of data
rtable: Repeater table contains reference time of previous trigger in samples
opt: Options object describing station/run parameters
Returns triggered traces as OBSPy trace object updates ptime for next run
"""
tr = st[0]
t = tr.stats.starttime
cft = coincidence_trigger("classicstalta", opt.trigon, opt.trigoff, stC, opt.nstaC,
sta=opt.swin, lta=opt.lwin, details=True)
if len(cft) > 0:
ind = 0
# Slice out the data from st and save the maximum STA/LTA ratio value for
# use in orphan expiration
# Convert ptime from time of last trigger to seconds before start time
if rtable.attrs.ptime:
ptime = (UTCDateTime(rtable.attrs.ptime) - t)
else:
ptime = -opt.mintrig
for n in range(len(cft)):
ttime = cft[n]['time'] # This is a UTCDateTime, not samples
if (ttime >= t + opt.atrig) and (ttime >= t + ptime +
opt.mintrig) and (ttime < t + len(tr.data)/opt.samprate -
2*opt.atrig):
ptime = ttime - t
# Slice and save as first trace
ttmp = st.slice(ttime - opt.ptrig, ttime + opt.atrig)
ttmp[0].data = ttmp[0].data[0:opt.wshape] - np.mean(
ttmp[0].data[0:opt.wshape])
for s in range(1,len(ttmp)):
ttmp[0].data = np.append(ttmp[0].data, ttmp[s].data[
0:opt.wshape] - np.mean(ttmp[s].data[0:opt.wshape]))
ttmp[0].stats.maxratio = np.max(cft[n]['cft_peaks'])
if ind is 0:
trigs = Stream(ttmp[0])
ind = ind+1
else:
trigs = trigs.append(ttmp[0])
if ind is 0:
return []
else:
rtable.attrs.ptime = (t + ptime).isoformat()
return trigs
else:
return []
示例13: getData
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def getData(tstart, tend, opt):
"""
Download data from files in a folder, from IRIS, or a Earthworm waveserver
A note on SAC/miniSEED files: as this makes no assumptions about the naming scheme of
your data files, please ensure that your headers contain the correct SCNL information!
tstart: UTCDateTime of beginning of period of interest
tend: UTCDateTime of end of period of interest
opt: Options object describing station/run parameters
Returns ObsPy stream objects, one for cutting and the other for triggering
"""
nets = opt.network.split(',')
stas = opt.station.split(',')
locs = opt.location.split(',')
chas = opt.channel.split(',')
st = Stream()
if opt.server == 'SAC' or opt.server == 'miniSEED':
# Generate list of files
if opt.server == 'SAC':
flist = list(itertools.chain.from_iterable(glob.iglob(os.path.join(
root,'*.sac')) for root, dirs, files in os.walk(opt.sacdir)))+list(
itertools.chain.from_iterable(glob.iglob(os.path.join(
root,'*.SAC')) for root, dirs, files in os.walk(opt.sacdir)))
elif opt.server == 'miniSEED':
flist = list(itertools.chain.from_iterable(glob.iglob(os.path.join(
root,'*.mseed')) for root, dirs, files in os.walk(opt.mseeddir)))+list(
itertools.chain.from_iterable(glob.iglob(os.path.join(
root,'*.MSEED')) for root, dirs, files in os.walk(opt.mseeddir)))
# Determine which subset of files to load based on start and end times and
# station name; we'll fully deal with stations below
flist_sub = []
for f in flist:
# Load header only
stmp = obspy.read(f, headonly=True)
# Check if station is contained in the stas list
if stmp[0].stats.station in stas:
# Check if contains either start or end time
ststart = stmp[0].stats.starttime
stend = stmp[0].stats.endtime
if (ststart<=tstart and tstart<=stend) or (ststart<=tend and
tend<=stend) or (tstart<=stend and ststart<=tend):
flist_sub.append(f)
# Fully load data from file
stmp = Stream()
for f in flist_sub:
tmp = obspy.read(f, starttime=tstart, endtime=tend+opt.maxdt)
if len(tmp) > 0:
stmp = stmp.extend(tmp)
# Filter and merge
stmp = stmp.filter('bandpass', freqmin=opt.fmin, freqmax=opt.fmax, corners=2,
zerophase=True)
stmp = stmp.taper(0.05,type='hann',max_length=opt.mintrig)
for m in range(len(stmp)):
if stmp[m].stats.sampling_rate != opt.samprate:
stmp[m] = stmp[m].resample(opt.samprate)
stmp = stmp.merge(method=1, fill_value=0)
# Only grab stations/channels that we want and in order
netlist = []
stalist = []
chalist = []
loclist = []
for s in stmp:
stalist.append(s.stats.station)
chalist.append(s.stats.channel)
netlist.append(s.stats.network)
loclist.append(s.stats.location)
# Find match of SCNL in header or fill empty
for n in range(len(stas)):
for m in range(len(stalist)):
if (stas[n] in stalist[m] and chas[n] in chalist[m] and nets[n] in
netlist[m] and locs[n] in loclist[m]):
st = st.append(stmp[m])
if len(st) == n:
print("Couldn't find "+stas[n]+'.'+chas[n]+'.'+nets[n]+'.'+locs[n])
trtmp = Trace()
trtmp.stats.sampling_rate = opt.samprate
trtmp.stats.station = stas[n]
st = st.append(trtmp.copy())
else:
if '.' not in opt.server:
client = Client(opt.server)
else:
client = EWClient(opt.server, opt.port)
for n in range(len(stas)):
try:
#.........这里部分代码省略.........
示例14: stream_stack_distance_intervals
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
def stream_stack_distance_intervals(st, interval, norm_type='no'):
""" Stack average traces in a stream if their distance difference is
smaller than interval.
The stream containing a number of traces with given distance (e.g. from source)
is used to create a number of equally spaced traces by averaging traces that fall
into the same distance bin. If interval is a scalar the bins are equally spaced with
a width of interval. If interval is a sequence its elements define the lower distance
limit of the bins.
:type st: :class:`~obspy.core.stream.Stream`
:param st: Stream fo be used for stacking.
:type interval: scalar os array like
:param interval: width of bins in case of scalar or smaller edge of
bins if interval is a sequence.
:type norm_type: str
:param norm_type: normalization to be applied within bins before stacking
Possibilities are `no` for no normalization, `max` for normalization
to maximum, `rms` for normaliation to root mean square or `abs_mean`
for normalization to the mean of the absolute value.
:rtype sst: :class:`~obspy.core.stream.Stream`
:return: **sst**: stacked stream
"""
dist = []
npts = []
for tr in st:
dist.append(tr.stats.sac['dist'])
npts.append(tr.stats['npts'])
if not hasattr(interval, "__len__"):
bins = np.arange(min(dist), max(dist),interval)
else:
bins = np.array(interval)
sst = Stream()
for ii in bins:
sst.append(Trace(data=np.zeros(max(npts),dtype=np.float64),header={
'network':'stack','station':str(ii),'location':'',
'channel':st[0].stats['channel'],'starttime':st[0].stats['starttime'],'sampling_rate':st[0].stats['sampling_rate'],
'sac':{'dist':ii,'az':0,'evla':0.,'evlo':0.,'stla':ii/(np.pi*6371000)*180.,'stlo':0.}}))
count = np.zeros_like(bins)
weight = np.zeros_like(bins)
for tr in st:
ind = sum((tr.stats.sac['dist'] - bins)>=0)-1
if norm_type == 'no':
norm = 1.
elif norm_type == 'max':
norm = np.max(np.abs(tr.data))
elif norm_type == 'rms':
norm = np.sqrt(np.mean(tr.data**2))
elif norm_type == 'abs_mean':
norm = np.mean(np.abs(tr.data))
else:
raise ValueError('norm_type %s not implemented' % norm_type)
sst[ind].data[0:tr.stats['npts']] += (tr.data/norm)
weight[ind] += norm
count[ind] += 1
for ind, tr in enumerate(sst):
tr.data *= weight[ind]/(count[ind]**2)
return sst
示例15: Stream
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import append [as 别名]
return None, None
# Create the Stream obj and populate it
st = Stream()
for (_, rec) in df.iterrows():
fname = os.path.join(rec['path'], rec['file'])
for tr in _read(fname, fformat, headonly=False, **kwargs).traces:
if (networks_ok) and (tr.stats.network not in networks):
continue
if (stations_ok) and (tr.stats.station not in stations):
continue
if (locations_ok) and (tr.stats.location not in locations):
continue
if (channels_ok) and (tr.stats.channel not in channels):
continue
st.append(tr)
if st.count() > 0:
# If the starttime is given then it trims the resulting traces
if starttime:
st.trim(starttime=starttime, endtime=endtime,
nearest_sample=nearest_sample)
st.merge(method=1, fill_value=0, interpolation_samples=1)
else:
print "Empty stream"
n_trace = st.count()
return st, n_trace