[obspy-users] obspy.core.trace.Trace.slice

Tobias Megies megies at geophysik.uni-muenchen.de
Mon Nov 4 16:40:02 CET 2019


See also
http://docs.obspy.org/packages/autogen/obspy.core.trace.Trace.slide.html

I don't use it much, so not sure about the endpoint with that one, though.
We're always happy to accept pull requests with improvements to docs.

cheers,
T

On 04/11/2019 16:30, Peter Schmidt wrote:
> On 2019-11-03 23:08, Peter Schmidt wrote:
> 
> Forgott to add, it would at least be nice if the documentation of the
> method points out that the data point at endtime will be included in the
> slice, similar to numpy.arange pointing out that the data point at the
> time given by argument stop is not included in the interval.
> 
>> Hi
>>
>>
>> Using obspy to read data and cut the returned Traces into smaller
>> segments I note that the slice method on the obspy.core.trace.Trace
>> includes the data point at obspy.core.trace.Trace.stats.endtime, e.g:
>>
>> >>> from obspy import Trace
>> >>> import numpy
>> >>> tr = Trace(data=numpy.arange(0, 10))
>> >>> tr.stats.delta = 1.0
>> >>> t = tr.stats.starttime
>> >>> print tr.data
>> [0 1 2 3 4 5 6 7 8 9]
>> >>> tr2 = tr.slice(t, t+5)
>> >>> print tr2.data,tr2.stats.endtime
>> [0 1 2 3 4 5] 1970-01-01T00:00:05.000000Z
>> >>> tr3 = tr.slice(t+5, t+10)
>> >>> print tr3.data,tr3.stats.endtime
>> [5 6 7 8 9] 1970-01-01T00:00:09.000000Z
>>
>> Now, the question here is if this is the standard way to handle
>> slicing of a uniformly spaced datavector. My point being is that if
>> you have time series data, a conservative way to look at the data
>> inbetween your known measurements is that is constant from the one
>> measurment until the next. I.e. if you at time 0 measure the value 10
>> of a given system, you do not know the value of the system until you
>> make your next measurement, hence the conservative thing to do is to
>> assume it to be the last measured value (in this case 10). Adopting
>> this approach each data point can be considered to have a duration of
>> validity equal to the time separation between your measurements. Thus
>> following this logic I would expect the above to have yielded the
>> output: 
>>
>> >>> from obspy import Trace
>> >>> import numpy
>> >>> tr = Trace(data=numpy.arange(0, 10))
>> >>> tr.stats.delta = 1.0
>> >>> t = tr.stats.starttime
>> >>> print tr.data
>> [0 1 2 3 4 5 6 7 8 9]
>> >>> tr2 = tr.slice(t, t+5)
>> >>> print tr2.data,tr2.stats.endtime
>> [0 1 2 3 4] 1970-01-01T00:00:05.000000Z
>> >>> tr3 = tr.slice(t+5, t+10)
>> >>> print tr3.data,tr3.stats.endtime
>> [5 6 7 8 9] 1970-01-01T00:00:10.000000Z
>>
>> From a practical point of view the current way the slice method works
>> prevents slicing a trace into shorter (non-overlapping) traces using
>> an algorithm on the form:
>>
>> traces = []
>> t = tr.stats.starttime
>> stop = tr.stats.endtime
>> trace_lenght = 5
>> while t < stop:
>>    traces.append(tr.slice(t,t+trace_length))
>>    t += trace_length
>>
>> so question is how to best slice a Trace into smaller non-overlapping
>> traces? Would it perhaps be possible to add an argument to the slice
>> method to not include the data point at argument endtime?
>>
>>
>> regards Peter
>>
>> -- 
>> ********************************************************************************
>> Peter Schmidt                                      Tel: +46-18-4717104
>> Swedish National Seismological Network (SNSN)   Mobile: +46-73-3190975
>> Dept. of Earth Sciences:geophysics              e-mail: peter.schmidt at geo.uu.se  
>> Uppsala University
>> Villavagen 16
>> SE-75236 Uppsala
>> ******************************************************************************** 
>> Page Title
>>
>>
>>
>>
>>
>>
>>
>> När du har kontakt med oss på Uppsala universitet med e-post så
>> innebär det att vi behandlar dina personuppgifter. För att läsa mer om
>> hur vi gör det kan du läsa här:
>> http://www.uu.se/om-uu/dataskydd-personuppgifter/
>>
>> E-mailing Uppsala University means that we will process your personal
>> data. For more information on how this is performed, please read here:
>> http://www.uu.se/en/about-uu/data-protection-policy
>>
>> _______________________________________________
>> obspy-users mailing list
>> obspy-users at lists.swapbytes.de
>> https://lists.swapbytes.de/mailman/listinfo/obspy-users
> 
> 
> -- 
> ********************************************************************************
> Peter Schmidt                                      Tel: +46-18-4717104
> Swedish National Seismological Network (SNSN)   Mobile: +46-73-3190975
> Dept. of Earth Sciences:geophysics              e-mail: peter.schmidt at geo.uu.se  
> Uppsala University
> Villavagen 16
> SE-75236 Uppsala
> ******************************************************************************** 
> 
> 
> _______________________________________________
> obspy-users mailing list
> obspy-users at lists.swapbytes.de
> https://lists.swapbytes.de/mailman/listinfo/obspy-users
> 

-- 
EMail: tobias.megies at lmu.de
WWW: https://www.geophysik.uni-muenchen.de

Geophysikalisches Observatorium
Ludwigshöhe 8
82256 Fürstenfeldbruck

Tel: +49 (0) 89 2180-73981
Fax: +49 (0) 89 2180-73970

Ludwig-Maximilians-Universität
Department für Geo- und Umweltwissenschaften
Sektion Geophysik
Theresienstrasse 41/IV
80333 München

Tel: +49 (0) 89 2180-4326
Fax: +49 (0) 89 2180-4205


More information about the obspy-users mailing list