obspy.core.util.testing.streams_almost_equal

streams_almost_equal(st1, st2, default_stats=True, rtol=1e-05, atol=1e-08, equal_nan=True)[source]

Return True if two streams are almost equal.

Parameters:
  • st1 – The first Stream object.

  • st2 – The second Stream object.

  • default_stats – If True only compare the default stats on the traces, such as seed identification codes, start/end times, sampling_rates, etc. If False also compare extra stats attributes such as processing and format specific information.

  • rtol – The relative tolerance parameter passed to allclose() for comparing time series.

  • atol – The absolute tolerance parameter passed to allclose() for comparing time series.

  • equal_nan – If True NaNs are evaluated equal when comparing the time series.

Returns:

bool

Example

  1. Changes to the non-default parameters of the

    Stats objects of the stream’s contained Trace objects will cause the streams to be considered unequal, but they will be considered almost equal.

    >>> from obspy import read
    >>> st1 = read()
    >>> st2 = read()
    >>> # The traces should, of course, be equal.
    >>> assert st1 == st2
    >>> # Perform detrending on st1 twice so processing stats differ.
    >>> st1 = st1.detrend('linear')
    >>> st1 = st1.detrend('linear')
    >>> st2 = st2.detrend('linear')
    >>> # The traces are no longer equal, but are almost equal.
    >>> assert st1 != st2
    >>> assert streams_almost_equal(st1, st2)
    
  2. Slight differences in each trace’s data will cause the streams

    to be considered unequal, but they will be almost equal if the differences don’t exceed the limits set by the rtol and atol parameters.

    >>> from obspy import read
    >>> st1 = read()
    >>> st2 = read()
    >>> # Perturb the trace data in st2 slightly.
    >>> for tr in st2:
    ...     tr.data *= (1 + 1e-6)
    >>> # The streams are no longer equal.
    >>> assert st1 != st2
    >>> # But they are almost equal.
    >>> assert streams_almost_equal(st1, st2)
    >>> # Unless, of course, there is a large change.
    >>> st1[0].data *= 10
    >>> assert not streams_almost_equal(st1, st2)