obspy.core.trace.Trace.slide
- Trace.slide(window_length, step, offset=0, include_partial_windows=False, nearest_sample=True)[source]
Generator yielding equal length sliding windows of the Trace.
Please keep in mind that it only returns a new view of the original data. Any modifications are applied to the original data as well. If you don’t want this you have to create a copy of the yielded windows. Also be aware that if you modify the original data and you have overlapping windows, all following windows are affected as well.
Example
>>> import obspy >>> tr = obspy.read()[0] >>> for windowed_tr in tr.slide(window_length=10.0, step=10.0): ... print("---") ... print(windowed_tr) --- ... | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:13.000000Z | ... --- ... | 2009-08-24T00:20:13.000000Z - 2009-08-24T00:20:23.000000Z | ...
- Parameters:
window_length (float) – The length of each window in seconds.
step (float) – The step between the start times of two successive windows in seconds. Can be negative if an offset is given.
offset (float) – The offset of the first window in seconds relative to the start time of the whole interval.
include_partial_windows (bool) – Determines if windows that are shorter then 99.9 % of the desired length are returned.
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.