obspy.core.stream.Stream._cleanup

Stream._cleanup(misalignment_threshold=0.01)[source]

Merge consistent trace objects but leave everything else alone.

This can mean traces with matching header that are directly adjacent or are contained/equal/overlapping traces with exactly the same waveform data in the overlapping part. If option misalignment_threshold is non-zero then contained/overlapping/directly adjacent traces with the sampling points misaligned by less than misalignment_threshold times the sampling interval are aligned on the same sampling points (see example below).

Notes

Traces with overlapping data parts that do not match are not merged:

before:
Trace 1: AAAAAAAA
Trace 2:     BBBBBBBB

after:
Trace 1: AAAAAAAA
Trace 2:     BBBBBBBB

Traces with overlapping data parts that do match are merged:

before:
Trace 1: AAAAAAAA
Trace 2:     AAAABBBB

after:
Trace 1: AAAAAAAABBBB

Contained traces are handled the same way. If common data does not match, nothing is done:

before:
Trace 1: AAAAAAAAAAAA
Trace 2:     BBBB

after:
Trace 1: AAAAAAAAAAAA
Trace 2:     BBBB

If the common data part matches they are merged:

before:
Trace 1: AAAAAAAAAAAA
Trace 2:     AAAA

after:
Trace 1: AAAAAAAAAAAA

Directly adjacent traces are merged:

before:
Trace 1: AAAAAAA
Trace 2:        BBBBB

after:
Trace 1: AAAAAAABBBBB

Misaligned traces are aligned, depending on set parameters, e.g. for a directly adjacent trace with slight misalignment (with two common samples at start of Trace 2 for better visualization):

before:
Trace 1: A---------A---------A
Trace 2:            A---------A---------B---------B

after:
Trace 1: A---------A---------A---------B---------B
Parameters:misalignment_threshold (float) Threshold value for sub-sample misalignments of sampling points of two traces that should be merged together (fraction of sampling interval, from 0 to 0.5). 0 means traces with even just the slightest misalignment will not be merged together, 0.5 means traces will be merged together disregarding of any sub-sample shifts of sampling points.