Replace zeros in a trace with gaps

I have some data in miniseed files that contains zeros where there are gaps in the data. (The data was generated by SEISAN.)

Is there a way to put the gaps back using obspy?

Yes, obspy simply uses numpy masked arrays for representing gappy traces (since usually a Trace is commonly representing a gapless piece of waveform).

from obspy import read
import numpy as np

tr = read()[0]
print(tr)
tr.data[1000:1200] = 0.0

tr.data = np.ma.masked_where(tr.data == 0, tr.data)
print(tr)

st = tr.split()
print(st)
BW.RJOB..EHZ | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples

BW.RJOB..EHZ | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples (masked)

2 Trace(s) in Stream:
BW.RJOB..EHZ | 2009-08-24T00:20:03.010000Z - 2009-08-24T00:20:12.990000Z | 100.0 Hz, 999 samples
BW.RJOB..EHZ | 2009-08-24T00:20:15.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 1800 samples

compare Trace/Stream.split()

1 Like