Skip to content
Snippets Groups Projects
Commit 23fbceff authored by Kien Le's avatar Kien Le
Browse files

Read ASCII files

parent 770b191b
No related branches found
No related tags found
1 merge request!132Fast MSEED read
Pipeline #2582 passed with stage
in 2 minutes and 53 seconds
......@@ -250,25 +250,38 @@ class RecordReader:
encoding_format = self.header_unpacker.unpack('b', encoding_format)[0]
encoding_format = EncodingFormat(encoding_format)
# Currently, we are extracting only the first data point in each
# record. The smallest possible amount of bytes we can extract while
# guaranteeing that we get the first data point in the record is 8,
# with Steim encodings and IEEE double precision float needing to use
# the whole buffer.
buffer = self.file.read(8)
encoding_to_decoder = {
EncodingFormat.ASCII: (lambda a1, a2: int(1)),
EncodingFormat.INT_16_BIT: decode_int16,
EncodingFormat.INT_24_BIT: decode_int24,
EncodingFormat.INT_32_BIT: decode_int32,
EncodingFormat.IEEE_FLOAT_32_BIT: decode_ieee_float,
EncodingFormat.IEEE_FLOAT_64_BIT: decode_ieee_double,
EncodingFormat.STEIM_1: decode_steim,
EncodingFormat.STEIM_2: decode_steim,
}
first_data_point = encoding_to_decoder[encoding_format](
buffer, self.data_unpacker
)
if encoding_format == EncodingFormat.ASCII:
# We want to read everything in the record if the encoding is
# ASCII.
record_length_exp = self.header_unpacker.unpack(
'B', self.blockette_1000.record_length
)[0]
record_size = 2 ** record_length_exp
# This name does not make much sense with what we are doing here,
# but it will have to do for now.
# The size of the record includes the header, so we have to account
# for that when grabbing the data.
first_data_point = self.file.read(record_size - data_start)
else:
# Currently, we are extracting only the first data point in each
# record. The smallest possible amount of bytes we can extract
# while guaranteeing that we get the first data point in the
# record is 8, with Steim encodings and IEEE double precision
# float needing to use the whole buffer.
buffer = self.file.read(8)
encoding_to_decoder = {
EncodingFormat.INT_16_BIT: decode_int16,
EncodingFormat.INT_24_BIT: decode_int24,
EncodingFormat.INT_32_BIT: decode_int32,
EncodingFormat.IEEE_FLOAT_32_BIT: decode_ieee_float,
EncodingFormat.IEEE_FLOAT_64_BIT: decode_ieee_double,
EncodingFormat.STEIM_1: decode_steim,
EncodingFormat.STEIM_2: decode_steim,
}
first_data_point = encoding_to_decoder[encoding_format](
buffer, self.data_unpacker
)
# Seek back to the start of the record so we can call this method again
# if needed.
self.file.seek(record_start)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment