From cd44df15318e43740e1893e8960a2bf04253e6dc Mon Sep 17 00:00:00 2001 From: ldam <ldam@passcal.nmt.edu> Date: Thu, 18 May 2023 16:31:39 -0600 Subject: [PATCH] report and skip if can't read a file --- sohstationviewer/model/reftek/reftek.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/sohstationviewer/model/reftek/reftek.py b/sohstationviewer/model/reftek/reftek.py index f7fa193d4..eb1730d4e 100755 --- a/sohstationviewer/model/reftek/reftek.py +++ b/sohstationviewer/model/reftek/reftek.py @@ -4,7 +4,7 @@ RT130 object to hold and process RefTek data import os from pathlib import Path from typing import Tuple, List, Union - +import traceback import numpy as np from sohstationviewer.model.reftek.from_rt2ms import ( @@ -89,8 +89,15 @@ class RT130(DataTypeModel): path2file = Path(path).joinpath(file_name) if not validate_file(path2file, file_name): continue - if not self.read_reftek_130(path2file): - read_text(path2file, file_name, self.log_data['TEXT']) + try: + if not self.read_reftek_130(path2file): + read_text(path2file, self.log_data['TEXT']) + except Exception: + fmt = traceback.format_exc() + self.track_info(f"Skip file {path2file} can't be read " + f"due to error: {str(fmt)}", + LogType.WARNING) + count += 1 if count % 50 == 0: self.track_info( @@ -133,7 +140,13 @@ class RT130(DataTypeModel): :param path2file: absolute path to file """ - rt130 = core.Reftek130.from_file(path2file) + try: + rt130 = core.Reftek130.from_file(path2file) + except Exception: + fmt = traceback.format_exc() + self.track_info(f"Skip file {path2file} can't be read " + f"due to error: {str(fmt)}", LogType.WARNING) + return unique, counts = np.unique(rt130._data["packet_type"], return_counts=True) nbr_packet_type = dict(zip(unique, counts)) -- GitLab