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 to False, the outer (previous sample for a start time border, next sample for an end time border) sample containing the time is selected. Defaults to True.
Given the following trace containing 4 samples, “|” are the sample points, “A” is the requested starttime:
| A| | |
nearest_sample=True will select the second sample point, nearest_sample=False will select the first sample point.
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])