obspy.core.stream.Stream.normalize

Stream.normalize(global_max=False)[source]

Normalize all Traces in the Stream.

By default all traces are normalized separately to their respective absolute maximum. By setting global_max=True all traces get normalized to the global maximum of all traces.

Parameters:global_max If set to True, all traces are normalized with respect to the global maximum of all traces in the stream instead of normalizing every trace separately.

Note

If data.dtype of a trace was integer it is changing to float.

Note

This operation is performed in place on the actual data arrays. The raw data is not accessible anymore afterwards. To keep your original data, use copy() to create a copy of your stream object. This also makes an entry with information on the applied processing in stats.processing of every trace.

Example

Make a Stream with two Traces:

>>> from obspy import Trace, Stream
>>> tr1 = Trace(data=np.array([0, -3, 9, 6, 4]))
>>> tr2 = Trace(data=np.array([0.3, -0.5, -0.8, 0.4, 0.3]))
>>> st = Stream(traces=[tr1, tr2])

All traces are normalized to their absolute maximum and processing information is added:

>>> st.normalize()  
<...Stream object at 0x...>
>>> st[0].data  
array([ 0.        , -0.33333333,  1.        ,  0.66666667,  ...])
>>> print(st[0].stats.processing[0])  
ObsPy ... normalize(norm=None)
>>> st[1].data
array([ 0.375, -0.625, -1.   ,  0.5  ,  0.375])
>>> print(st[1].stats.processing[0])  
ObsPy ...: normalize(norm=None)

Now let’s do it again normalize all traces to the stream’s global maximum:

>>> tr1 = Trace(data=np.array([0, -3, 9, 6, 4]))
>>> tr2 = Trace(data=np.array([0.3, -0.5, -0.8, 0.4, 0.3]))
>>> st = Stream(traces=[tr1, tr2])
>>> st.normalize(global_max=True)  
<...Stream object at 0x...>
>>> st[0].data  
array([ 0.        , -0.33333333,  1.        ,  0.66666667,  ...])
>>> print(st[0].stats.processing[0])  
ObsPy ...: normalize(norm=9)
>>> st[1].data  
array([ 0.03333333, -0.05555556, -0.08888889,  0.04444444,  ...])
>>> print(st[1].stats.processing[0])  
ObsPy ...: normalize(norm=9)