obspy.realtime.rttrace.RtTrace.times

RtTrace.times(type='relative', reftime=None)

For convenient plotting compute a NumPy array with timing information of all samples in the Trace.

Time can be either:

  • seconds relative to trace.stats.starttime (type="relative") or to reftime

  • absolute time as UTCDateTime objects (type="utcdatetime")

  • absolute time as POSIX timestamps ( UTCDateTime.timestamp type="timestamp")

  • absolute time as matplotlib numeric datetime (for matplotlib plotting with absolute time on axes, see matplotlib.dates and matplotlib.dates.date2num(), type="matplotlib")

Note

The option type="utcdatetime" shouldn’t be used for Traces with a large sample size as it will generate an array of thousands of UTCDateTime.timestamp objects.

>>> from obspy import read, UTCDateTime
>>> tr = read()[0]
>>> tr.times()  
array([  0.00000000e+00,   1.00000000e-02,   2.00000000e-02, ...,
         2.99700000e+01,   2.99800000e+01,   2.99900000e+01])
>>> tr.times(reftime=UTCDateTime("2009-01-01T00"))
array([ 20305203.  ,  20305203.01,  20305203.02, ...,  20305232.97,
        20305232.98,  20305232.99])
>>> tr.times("utcdatetime")  
array([UTCDateTime(2009, 8, 24, 0, 20, 3),
       UTCDateTime(2009, 8, 24, 0, 20, 3, 10000),
       UTCDateTime(2009, 8, 24, 0, 20, 3, 20000), ...,
       UTCDateTime(2009, 8, 24, 0, 20, 32, 970000),
       UTCDateTime(2009, 8, 24, 0, 20, 32, 980000),
       UTCDateTime(2009, 8, 24, 0, 20, 32, 990000)], dtype=object)
>>> tr.times("timestamp")
array([  1.25107320e+09,   1.25107320e+09,   1.25107320e+09, ...,
         1.25107323e+09,   1.25107323e+09,   1.25107323e+09])
>>> tr.times("matplotlib")  
array([ 14480.01392361,  14480.01392373,  14480.01392384, ...,
        14480.01427049,  14480.0142706 ,  14480.01427072])
Parameters:
  • type (str) – Determines type of returned time array, see above for valid values.

  • reftime (obspy.core.utcdatetime.UTCDateTime) – When using a relative timing, the time used as the reference for the zero point, i.e., the first sample will be at trace.stats.starttime - reftime (in seconds).

Return type:

ndarray or MaskedArray

Returns:

An array of time samples in an ndarray if the trace doesn’t have any gaps or a MaskedArray otherwise (dtype of array is either float or UTCDateTime).