Stream.stack(group_by='all', stack_type='linear', npts_tol=0, time_tol=0)[source]

Stack traces by the same selected metadata.

The metadata of each trace (including starttime) corresponds to the metadata of the original traces if those are the same. Additionaly, the entry stack is written to the stats object(s). It contains the fields group (result of the format operation on the group_by parameter), count (number of stacked traces) and type (stack_type argument).

  • group_by (str) – Stack waveforms together which have the same metadata given by this parameter. The parameter should name the corresponding keys of the stats object, e.g. '{network}.{station}' for stacking all locations and channels of the stations and returning a stream consisting of one stacked trace for each station. This parameter can take two special values, 'id' which stacks the waveforms by SEED id and 'all' (default) which stacks together all traces in the stream.

  • stack_type (str or tuple) – Type of stack, one of the following: 'linear': average stack (default), ('pw', order): phase weighted stack of given order (see [Schimmel1997], order 0 corresponds to linear stack), ('root', order): root stack of given order (order 1 corresponds to linear stack).

  • npts_tol (int) – Tolerate traces with different number of points with a difference up to this value. Surplus samples are discarded.

  • time_tol (float) – Tolerate difference, in seconds, in startime when setting the new starttime of the stack. If starttimes differs more than this value it will be set to timestamp 0.

>>> from obspy import read
>>> st = read()
>>> stack = st.stack()
>>> print(stack)  
1 Trace(s) in Stream:
BW.RJOB.. | 2009-08-24T00:20:03.000000Z - ... | 100.0 Hz, 3000 samples


This operation is performed in place on the actual data arrays. The raw data will no longer be accessible afterwards. To keep your original data, use copy() to create a copy of your stream object.