本文整理汇总了Python中obspy.core.Stream.slice方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.slice方法的具体用法?Python Stream.slice怎么用?Python Stream.slice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.core.Stream
的用法示例。
在下文中一共展示了Stream.slice方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coincidenceTrigger
# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import slice [as 别名]
#st.simulate(paz_remove="self", paz_simulate=cornFreq2Paz(1.0), remove_sensitivity=False)
st.sort()
st.filter("bandpass", freqmin=PAR.LOW, freqmax=PAR.HIGH, corners=1, zerophase=True)
st.trim(T1, T2)
st_trigger = st.copy()
st.normalize(global_max=False)
# do the triggering
trig = coincidenceTrigger("recstalta", PAR.ON, PAR.OFF, st_trigger,
thr_coincidence_sum=PAR.MIN_STATIONS,
max_trigger_length=PAR.MAXLEN, trigger_off_extension=PAR.ALLOWANCE,
details=True, sta=PAR.STA, lta=PAR.LTA)
for t in trig:
info = "%s %ss %s %s" % (t['time'].strftime("%Y-%m-%dT%H:%M:%S"), ("%.1f" % t['duration']).rjust(4), ("%i" % t['cft_peak_wmean']).rjust(3), "-".join(t['stations']))
summary.append(info)
tmp = st.slice(t['time'] - 1, t['time'] + t['duration'])
outfilename = "%s/%s_%.1f_%i_%s-%s_%s.png" % (PLOTDIR, t['time'].strftime("%Y-%m-%dT%H:%M:%S"), t['duration'], t['cft_peak_wmean'], len(t['stations']), num_stations, "-".join(t['stations']))
tmp.plot(outfile=outfilename)
mutt += ("-a", outfilename)
summary.append("#" * 79)
summary = "\n".join(summary)
summary += "\n" + "\n".join(("%s=%s" % (k, v) for k, v in PAR.items()))
#print summary
open(SUMMARY, "at").write(summary + "\n")
# send emails
if MAILTO:
alert_lvl = 0
if len(trig) > 0:
alert_lvl = 1
for t in trig:
示例2: stations
# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import slice [as 别名]
if tmp_on < off + PAR.ALLOWANCE:
stations.add(tmp_sta)
# allow sets of triggers that overlap only on subsets of all
# stations (e.g. A overlaps with B and B overlaps with C => ABC)
off = max(off, tmp_off)
else:
break
# process event if enough stations reported it.
# a minimum of PAR.MIN_STATIONS must have triggered together.
# if PAR.ALLOW_LESS_STATIONS is set, then an event also is issued if
# ALL stations have triggered but the number of available stations
# falls short of PAR.MIN_STATIONS.
if len(stations) >= (PAR.ALLOW_LESS_STATIONS and min(num_stations, PAR.MIN_STATIONS) or PAR.MIN_STATIONS):
event = (UTCDateTime(on), off - on, tuple(stations))
summary.append("%s %04.1f %s" % event)
tmp = st.slice(UTCDateTime(on), UTCDateTime(off))
outfilename = "%s/%s_%s-%s_%s.png" % (PLOTDIR, UTCDateTime(on), len(stations), num_stations, "-".join(stations))
tmp.plot(outfile=outfilename)
mutt += ("-a", outfilename)
# shorten trigger_list and go on
# index i marks the index of the next non-matching pick
trigger_list = trigger_list[i:]
summary = "\n".join(summary)
summary += "\n" + "\n".join(("%s=%s" % (k, v) for k, v in PAR.items()))
#print summary
open(SUMMARY, "at").write(summary + "\n")
# send emails
if MAILTO:
mutt += MAILTO
subprocess.Popen(mutt, stdin=subprocess.PIPE).communicate(summary)
示例3: Seedlink_plotter
# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import slice [as 别名]
#.........这里部分代码省略.........
fig=self.figure, type='dayplot', interval=self.interval,
number_of_ticks=13, tick_format='%d/%m %Hh',
size=(args.x_size * upscale_factor, args.y_size * upscale_factor),
x_labels_size=8,
y_labels_size=8, title=self.title, title_size=14, linewidth=0.5, right_vertical_labels=False,
vertical_scaling_range=self.scale,
subplots_adjust_left=0.03, subplots_adjust_right=0.99,
subplots_adjust_top=0.95, subplots_adjust_bottom=0.1,
one_tick_per_line=True,
# noir Rouge bleu vert
color = self.color,
show_y_UTC_label=False)
def packetHandler(self, count, slpack):
"""
Processes each packet received from the SeedLinkConnection.
:type count: int
:param count: Packet counter.
:type slpack: :class:`~obspy.seedlink.SLPacket`
:param slpack: packet to process.
:return: Boolean true if connection to SeedLink server should be
closed and session terminated, false otherwise.
"""
# check if not a complete packet
if slpack is None or (slpack == SLPacket.SLNOPACKET) or \
(slpack == SLPacket.SLERROR):
return False
# get basic packet info
type = slpack.getType()
# process INFO packets here
if (type == SLPacket.TYPE_SLINF):
return False
if (type == SLPacket.TYPE_SLINFT):
# print "Complete INFO:\n" + self.slconn.getInfoString()
if self.infolevel is not None:
return True
else:
return False
# process packet data
trace = slpack.getTrace()
if trace is None:
print self.__class__.__name__ + ": blockette contains no trace"
return False
# new samples add to the main stream
self.stream += trace
self.stream.merge()
now = UTCDateTime()
# Stop time will be the next round date
stop_time = UTCDateTime(
now.year, now.month, now.day, now.hour, 0, 0)+3600
start_time = stop_time-self.backtrace
# Limit the stream size
self.stream = self.stream.slice(start_time, stop_time)
self.stream.trim(start_time, stop_time)
self.title = self.stream.traces[0].stats.station+" "+self.stream.traces[0].stats.network+" "+self.stream.traces[
0].stats.location+" "+self.stream.traces[0].stats.channel+' scale: '+str(self.scale) + " - non filtre"
stream_time_length = self.stream.traces[
0].stats.endtime - self.stream.traces[0].stats.starttime
### Before we reach print_percentage of the time data to plot, we plot each initial_update_rate we received
# if (stream_time_length < (self.backtrace*self.print_percentage)):
# if ((stream_time_length))<(self.backtrace-60.0*self.interval):
# print str(stream_time_length)+"/"+str(self.print_max)
if stream_time_length <= self.print_max:
self.flip += 1
# if ((stream_time_length))<(self.backtrace-60.0*self.interval):
self.pbar.update(stream_time_length+1)
# print str(stream_time_length)+"/"+str(self.print_max)
if (self.flip > self.initial_update_rate):
self.flip = 0
self.figure.clear()
self.plot_graph()
# self.pbar.finish()
# Real time plotting
# We plot each update_rate packet we received
# if (stream_time_length >= (self.backtrace*self.print_percentage)):
if ((stream_time_length)) > (self.print_max):
# print str(stream_time_length)+"/"+str(self.print_max)
self.flip += 1
if (self.flip > self.update_rate):
self.figure.clear()
self.plot_graph()
self.flip = 0
return False
示例4: WaveformPlotting
# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import slice [as 别名]
class WaveformPlotting(object):
"""
Class that provides several solutions for plotting large and small waveform
data sets.
.. warning::
This class should NOT be used directly, instead use the
:meth:`~obspy.core.stream.Stream.plot` method of the
ObsPy :class:`~obspy.core.stream.Stream` or
:class:`~obspy.core.trace.Trace` objects.
It uses matplotlib to plot the waveforms.
"""
def __init__(self, **kwargs):
"""
Checks some variables and maps the kwargs to class variables.
"""
self.stream = kwargs.get('stream')
# Check if it is a Stream or a Trace object.
if isinstance(self.stream, Trace):
self.stream = Stream([self.stream])
elif not isinstance(self.stream, Stream):
msg = 'Plotting is only supported for Stream or Trace objects.'
raise TypeError(msg)
# Stream object should contain at least one Trace
if len(self.stream) < 1:
msg = "Empty object"
raise IndexError(msg)
# Type of the plot.
self.type = kwargs.get('type', 'normal')
# Start- and endtimes of the plots.
self.starttime = kwargs.get('starttime', None)
self.endtime = kwargs.get('endtime', None)
self.fig_obj = kwargs.get('fig', None)
# If no times are given take the min/max values from the stream object.
if not self.starttime:
self.starttime = min([trace.stats.starttime for \
trace in self.stream])
if not self.endtime:
self.endtime = max([trace.stats.endtime for \
trace in self.stream])
# Map stream object and slice just in case.
self.stream = self.stream.slice(self.starttime, self.endtime)
# normalize times
if self.type == 'relative':
dt = self.starttime
# fix plotting boundaries
self.endtime = UTCDateTime(self.endtime - self.starttime)
self.starttime = UTCDateTime(0)
# fix stream times
for tr in self.stream:
tr.stats.starttime = UTCDateTime(tr.stats.starttime - dt)
# Whether to use straight plotting or the fast minmax method.
self.plotting_method = kwargs.get('method', 'fast')
# Below that value the data points will be plotted normally. Above it
# the data will be plotted using a different approach (details see
# below). Can be overwritten by the above self.plotting_method kwarg.
self.max_npts = 400000
# If automerge is enabled. Merge traces with the same id for the plot.
self.automerge = kwargs.get('automerge', True)
# Set default values.
# The default value for the size is determined dynamically because
# there might be more than one channel to plot.
self.size = kwargs.get('size', None)
# Values that will be used to calculate the size of the plot.
self.default_width = 800
self.default_height_per_channel = 250
if not self.size:
self.width = 800
# Check the kind of plot.
if self.type == 'dayplot':
self.height = 600
else:
# One plot for each trace.
if self.automerge:
count = []
for tr in self.stream:
if hasattr(tr.stats, 'preview') and tr.stats.preview:
tr_id = tr.id + 'preview'
else:
tr_id = tr.id
if not tr_id in count:
count.append(tr_id)
count = len(count)
else:
count = len(self.stream)
self.height = count * 250
else:
self.width, self.height = self.size
# Interval length in minutes for dayplot.
self.interval = 60 * kwargs.get('interval', 15)
# Scaling.
self.vertical_scaling_range = kwargs.get('vertical_scaling_range',
None)
# Dots per inch of the plot. Might be useful for printing plots.
self.dpi = kwargs.get('dpi', 100)
# Color of the graph.
if self.type == 'dayplot':
self.color = kwargs.get('color', ('#000000','#B2000F', '#004C12',
#.........这里部分代码省略.........