Commit 3bb139ef authored by Javier Quinteros's avatar Javier Quinteros

Bugfix: Use headers from decimated Trace instead of originals

Use of wrong headers resulted in saturation of values.
Also add the metadata optional parameter.
parent bfb22d3d
......@@ -492,6 +492,8 @@ def main():
parser.add_argument('--decimate', type=int,
help='Factor by which the sampling rate is lowered by decimation.',
default=5)
parser.add_argument('--metadata', action='store_true', default=False,
help='Read and display the metadata from the TDMS files')
parser.add_argument('--version', action='version', version='dasconv v%s' % version)
parser.add_argument('filename',
help='Experiment to read and process. It is usually the first part of the filenames.')
......@@ -509,30 +511,35 @@ def main():
logs.error('End time is smaller than Start time.')
return
td = TDMS(args.filename, directory=args.directory, iterate='D',
td = TDMS(args.filename, directory=args.directory, iterate='M' if args.metadata else 'D',
chstart=args.chstart, chstop=args.chstop, chstep=args.chstep,
starttime=dtstart, endtime=dtend)
openedfiles = dict()
with td:
for data, stats in td:
tr0 = Trace(data=data, header=stats)
tr0.decimate(args.decimate)
tr1 = Trace(data=tr0.data.astype(td.datatype), header=stats)
for data in td:
if args.metadata:
logs.info(data)
else:
tr0 = Trace(data=data[0], header=data[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])
# and create a Stream to be saved in a MiniSEED file
st = Stream([tr1])
try:
fout = openedfiles[(stats['network'], stats['station'],
stats['location'], stats['channel'])]
except KeyError:
fout = open('%s.%s.%s.%s.mseed' % (stats['network'], stats['station'],
stats['location'], stats['channel']), 'wb')
openedfiles[(stats['network'], stats['station'],
stats['location'], stats['channel'])] = fout
st.write(fout, format='MSEED')
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
st.write(fout, format='MSEED')
# Close all opened files
for fout in openedfiles.values():
......
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