obspy.realtime.rttrace.RtTrace.slice
- RtTrace.slice(starttime=None, endtime=None, nearest_sample=True)
Return a new Trace object with data going from start to end time.
- Parameters
starttime (
UTCDateTime
) – Specify the start time of slice.endtime (
UTCDateTime
) – Specify the end time of slice.nearest_sample (bool, optional) –
If set to
True
, the closest sample is selected, if set toFalse
, the inner (next sample for a start time border, previous sample for an end time border) sample containing the time is selected. Defaults toTrue
.Given the following trace containing 6 samples, “|” are the sample points, “A” is the requested starttime:
| |A | | B | | 1 2 3 4 5 6
nearest_sample=True
will select samples 2-5,nearest_sample=False
will select samples 3-4 only.
- Returns
New
Trace
object. Does not copy data but just passes a reference to it.
Example
>>> tr = Trace(data=np.arange(0, 10)) >>> tr.stats.delta = 1.0 >>> t = tr.stats.starttime >>> tr2 = tr.slice(t + 2, t + 8) >>> tr2.data array([2, 3, 4, 5, 6, 7, 8])