Commit 04806e7b authored by Javier Quinteros's avatar Javier Quinteros

Decimate and save the whole channel

parent 5ea4ded3
......@@ -537,14 +537,36 @@ def main():
chstart=args.chstart, chstop=args.chstop, chstep=args.chstep,
starttime=dtstart, endtime=dtend)
openedfiles = dict()
with td:
curstream = None
for data in td:
if args.metadata:
logs.info(data)
else:
tr0 = Trace(data=data[0], header=data[1])
if curstream != '%s.%s.%s.%s' % (data[1]['network'], data[1]['station'], data[1]['location'], data[1]['channel']):
# Save the previous Stream completely
if curstream is not None:
with open('%s.mseed' % (curstream), 'wb') as fout:
# Do not call the decimate method if it is not needed
# 1: no decimation
if args.decimate > 1:
tr0.decimate(args.decimate)
# Use the headers from the decimated Trace
tr1 = Trace(data=tr0.data.astype(td.datatype), header=tr0.stats)
st = Stream([tr1])
logs.info('Storing channel %s' % curstream)
st.write(fout, format='MSEED')
# Update which stream is being processed
curstream = '%s.%s.%s.%s' % (data[1]['network'], data[1]['station'], data[1]['location'], data[1]['channel'])
# Create the Trace
tr0 = Trace(data=data[0], header=data[1])
else:
tr0 += Trace(data=data[0], header=data[1])
else:
with open('%s.mseed' % (curstream), 'wb') as fout:
# Do not call the decimate method if it is not needed
# 1: no decimation
if args.decimate > 1:
......@@ -553,24 +575,10 @@ def main():
# Use the headers from the decimated Trace
tr1 = Trace(data=tr0.data.astype(td.datatype), header=tr0.stats)
# and create a Stream to be saved in a MiniSEED file
st = Stream([tr1])
try:
fout = openedfiles[(data[1]['network'], data[1]['station'],
data[1]['location'], data[1]['channel'])]
except KeyError:
fout = open('%s.%s.%s.%s.mseed' % (data[1]['network'], data[1]['station'],
data[1]['location'], data[1]['channel']), 'wb')
openedfiles[(data[1]['network'], data[1]['station'],
data[1]['location'], data[1]['channel'])] = fout
logs.info('Storing channel %s' % curstream)
st.write(fout, format='MSEED')
# Close all opened files
for fout in openedfiles.values():
fout.close()
if __name__ == '__main__':
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment