From 7becb43a0740492c9ee8cadbba32e9ff03487666 Mon Sep 17 00:00:00 2001 From: kienle <kienle@passcal.nmt.edu> Date: Thu, 3 Aug 2023 15:18:55 -0600 Subject: [PATCH] Refactor the various RT130 classes --- .../model/reftek/from_rt2ms/core.py | 19 +++++++++++++++++++ sohstationviewer/model/reftek/reftek.py | 2 +- .../model/reftek/rt130_experiment/reftek.py | 19 ++----------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/sohstationviewer/model/reftek/from_rt2ms/core.py b/sohstationviewer/model/reftek/from_rt2ms/core.py index bdcab7c58..525522a9d 100644 --- a/sohstationviewer/model/reftek/from_rt2ms/core.py +++ b/sohstationviewer/model/reftek/from_rt2ms/core.py @@ -18,10 +18,16 @@ import numpy as np from obspy import Trace, Stream, UTCDateTime from obspy.core.util.obspy_types import ObsPyException +from obspy.io.reftek.packet import PACKET_FINAL_DTYPE from obspy.io.reftek.util import _decode_ascii, _parse_long_time +from sohstationviewer.model.mseed_data.record_reader_helper import Unpacker from sohstationviewer.model.reftek.from_rt2ms import packet from sohstationviewer.model.reftek.from_rt2ms.soh_packet import Packet +from sohstationviewer.model.reftek.rt130_experiment.reftek import \ + ( + read_rt130_file, convert_packet_to_obspy_format, +) class DiscontinuousTrace(Trace): @@ -107,6 +113,19 @@ class Reftek130Exception(ObsPyException): class Reftek130(obspy_rt130_core.Reftek130): + @staticmethod + def from_file(filename: str): + rt130_unpacker = Unpacker('>') + rt = Reftek130() + rt._filename = filename + packets_in_file = read_rt130_file(filename, rt130_unpacker) + converted_packets = [] + for packet in packets_in_file: + converted_packets.append( + convert_packet_to_obspy_format(packet, rt130_unpacker)) + rt._data = np.array(converted_packets, dtype=PACKET_FINAL_DTYPE) + return rt + def to_stream(self, network="", location="", component_codes=None, include_mp123=False, include_mp456=False, headonly=False, verbose=False, diff --git a/sohstationviewer/model/reftek/reftek.py b/sohstationviewer/model/reftek/reftek.py index 3dfe5be2b..df995d7ec 100755 --- a/sohstationviewer/model/reftek/reftek.py +++ b/sohstationviewer/model/reftek/reftek.py @@ -147,7 +147,7 @@ class RT130(DataTypeModel): :param path2file: absolute path to file """ try: - rt130 = Reftek130.from_file(path2file) + rt130 = core.Reftek130.from_file(path2file) except Exception: fmt = traceback.format_exc() self.track_info(f"Skip file {path2file} can't be read " diff --git a/sohstationviewer/model/reftek/rt130_experiment/reftek.py b/sohstationviewer/model/reftek/rt130_experiment/reftek.py index 63dc41cb2..34b3785e5 100644 --- a/sohstationviewer/model/reftek/rt130_experiment/reftek.py +++ b/sohstationviewer/model/reftek/rt130_experiment/reftek.py @@ -1,14 +1,10 @@ import os -import warnings from typing import Callable, Dict, Union import numpy import numpy as np -from matplotlib import pyplot as plt from obspy import UTCDateTime -from obspy.io.reftek.packet import PACKET_FINAL_DTYPE -from sohstationviewer.controller.util import validate_file from sohstationviewer.model.mseed_data.record_reader_helper import \ Unpacker from sohstationviewer.model.reftek.rt130_experiment.dt_packet import \ @@ -189,23 +185,12 @@ def convert_packet_to_obspy_format(packet: Union[EHETPacket, DTPacket], class Reftek130(core.Reftek130): - @staticmethod - def from_file(filename: str): - rt130_unpacker = Unpacker('>') - rt = Reftek130() - rt._filename = filename - packets_in_file = read_rt130_file(filename, rt130_unpacker) - converted_packets = [] - for packet in packets_in_file: - converted_packets.append( - convert_packet_to_obspy_format(packet, rt130_unpacker)) - rt._data = numpy.array(converted_packets, dtype=PACKET_FINAL_DTYPE) - return rt + pass waveform_file = '/Users/kle/PycharmProjects/sohstationviewer/tests/test_data/RT130-sample/2017149.92EB/2017150/92EB/1/000000015_0036EE80' soh_file = '/Users/kle/PycharmProjects/sohstationviewer/tests/test_data/RT130-sample/2017149.92EB/2017150/92EB/0/000000000_00000000' import time start = time.perf_counter() -(repr(Reftek130.from_file(waveform_file)._data)) +(Reftek130.from_file(waveform_file).to_stream()) # print('Time taken:', time.perf_counter() - start) -- GitLab