Skip to content
Snippets Groups Projects

Read log files generated by users

Merged Kien Le requested to merge feature-#94-read_log_files into master
1 unresolved thread
2 files
+ 37
13
Compare changes
  • Side-by-side
  • Inline
Files
2
from pathlib import Path
from typing import List, Literal, Optional, Dict, Callable, Tuple
import numpy as np
from obspy import UTCDateTime
LogFileFormat = Literal['rt2ms', 'logpeek', 'sohstationviewer']
# These packets can be found in section 4 of the RT130 record documentation.
RT130_PACKETS = ['SH', 'SC', 'OM', 'DS', 'AD', 'CD', 'FD', 'EH', 'ET']
@@ -256,3 +259,31 @@ class LogFileReader:
# separate the SOH lines blocks during processing.
self.soh_lines.append('\n')
self.masspos_lines.extend(masspos_lines)
def process_mass_poss_line(masspos_lines: List[str]
) -> List[Tuple[np.ndarray, np.ndarray]]:
"""
Process a list of mass-position lines into a list of mass-position data,
sorted by the channel suffix
:param masspos_lines: a list of mass-position log lines
:return: a list of mass-position data, sorted by the channel suffix
"""
# There can be 6 mass-position channels.
mass_pos_data = []
for masspos_num in range(6):
current_lines = [line.split()
for line
in masspos_lines
if int(line.split()[2]) == masspos_num]
data = np.asarray([line[3] for line in current_lines], dtype=float)
time_format = '%Y:%j:%H:%M:%S.%f'
times = np.array(
# strptime requires the microsecond component to have 6 digits, but
# a mass-position log lines only have 3 digits for microsecond. So,
# we have to pad the time with 0s.
[UTCDateTime.strptime(line[1] + '000', time_format).timestamp
for line in current_lines]
)
mass_pos_data.append((times, data))
return mass_pos_data
Loading