RtTrace.trim(starttime=None, endtime=None, pad=False, nearest_sample=True, fill_value=None)

Cut current trace to given start and end time.

  • starttime (UTCDateTime, optional) Specify the start time.
  • endtime (UTCDateTime, optional) Specify the end time.
  • pad (bool, optional) Gives the possibility to trim at time points outside the time frame of the original trace, filling the trace with the given fill_value. Defaults to False.
  • nearest_sample (bool, optional)

    If set to True, the closest sample is selected, if set to False, the inner (next sample for a start time border, previous sample for an end time border) sample containing the time is selected. Defaults to True.

    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.

  • fill_value (int, float or None, optional) Fill value for gaps. Defaults to None. Traces will be converted to NumPy masked arrays if no value is given and gaps are present.


This operation is performed in place on the actual data arrays. The raw data is not accessible anymore afterwards. To keep your original data, use copy() to create a copy of your trace object.


>>> tr = Trace(data=np.arange(0, 10))
>>> tr.stats.delta = 1.0
>>> t = tr.stats.starttime
>>> tr.trim(t + 2.000001, t + 7.999999)  
<...Trace object at 0x...>
>>> tr.data
array([2, 3, 4, 5, 6, 7, 8])