diff --git a/sohstationviewer/model/mseed/read_mseed_experiment/mseed_reader.py b/sohstationviewer/model/mseed/read_mseed_experiment/mseed_reader.py index 441dad773f046362ba5bc27827b2ac74c47c096d..e15eb14cb5bf9d752a02c435889f7cf29d4f2a6b 100644 --- a/sohstationviewer/model/mseed/read_mseed_experiment/mseed_reader.py +++ b/sohstationviewer/model/mseed/read_mseed_experiment/mseed_reader.py @@ -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)