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: ...@@ -250,25 +250,38 @@ class RecordReader:
encoding_format = self.header_unpacker.unpack('b', encoding_format)[0] encoding_format = self.header_unpacker.unpack('b', encoding_format)[0]
encoding_format = EncodingFormat(encoding_format) encoding_format = EncodingFormat(encoding_format)
# Currently, we are extracting only the first data point in each if encoding_format == EncodingFormat.ASCII:
# record. The smallest possible amount of bytes we can extract while # We want to read everything in the record if the encoding is
# guaranteeing that we get the first data point in the record is 8, # ASCII.
# with Steim encodings and IEEE double precision float needing to use record_length_exp = self.header_unpacker.unpack(
# the whole buffer. 'B', self.blockette_1000.record_length
buffer = self.file.read(8) )[0]
encoding_to_decoder = { record_size = 2 ** record_length_exp
EncodingFormat.ASCII: (lambda a1, a2: int(1)), # This name does not make much sense with what we are doing here,
EncodingFormat.INT_16_BIT: decode_int16, # but it will have to do for now.
EncodingFormat.INT_24_BIT: decode_int24, # The size of the record includes the header, so we have to account
EncodingFormat.INT_32_BIT: decode_int32, # for that when grabbing the data.
EncodingFormat.IEEE_FLOAT_32_BIT: decode_ieee_float, first_data_point = self.file.read(record_size - data_start)
EncodingFormat.IEEE_FLOAT_64_BIT: decode_ieee_double, else:
EncodingFormat.STEIM_1: decode_steim,
EncodingFormat.STEIM_2: decode_steim, # Currently, we are extracting only the first data point in each
} # record. The smallest possible amount of bytes we can extract
first_data_point = encoding_to_decoder[encoding_format]( # while guaranteeing that we get the first data point in the
buffer, self.data_unpacker # 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 # Seek back to the start of the record so we can call this method again
# if needed. # if needed.
self.file.seek(record_start) 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