Skip to content
Snippets Groups Projects
Commit 9378662c authored by Lan Dam's avatar Lan Dam
Browse files

processing.py: modify load_data() to load more than one dir; modify...

processing.py: modify load_data() to load more than one dir; modify detect_data_type due to bug when more than one data_types are detected
parent 0a7dbdc5
No related branches found
No related tags found
1 merge request!122allow to select multi folder to load
......@@ -4,8 +4,6 @@ channels, datatype
"""
import os
import json
import re
import traceback
from pathlib import Path
from typing import List, Set, Optional, Dict, Tuple
......@@ -28,8 +26,8 @@ from sohstationviewer.controller.util import (
from sohstationviewer.view.util.enums import LogType
def load_data(data_type: str, tracking_box: QTextBrowser, dir_list: List[str],
list_of_rt130_paths: List[Path],
def load_data(data_type: str, tracking_box: QTextBrowser,
list_of_dir: List[str], list_of_rt130_paths: List[Path],
req_wf_chans: List[str] = [], req_soh_chans: List[str] = [],
read_start: Optional[float] = None,
read_end: Optional[float] = None) -> DataTypeModel:
......@@ -43,7 +41,7 @@ def load_data(data_type: str, tracking_box: QTextBrowser, dir_list: List[str],
:param data_type: type of data read
:param tracking_box: widget to display tracking info
:param dir_list: list of directories selected by users
:param list_of_dir: list of directories selected by users
:param list_of_rt130_paths: list of rt130 directories selected by users
:param req_wf_chans: requested waveform channel list
:param req_soh_chans: requested soh channel list
......@@ -54,25 +52,15 @@ def load_data(data_type: str, tracking_box: QTextBrowser, dir_list: List[str],
"""
data_object = None
if list_of_rt130_paths == []:
for d in dir_list:
if data_object is None:
try:
data_object = DataTypeModel.create_data_object(
data_type, tracking_box, d, [],
req_wf_chans=req_wf_chans, req_soh_chans=req_soh_chans,
read_start=read_start, read_end=read_end)
except Exception:
fmt = traceback.format_exc()
msg = f"Dir {d} can't be read due to error: {str(fmt)}"
display_tracking_info(tracking_box, msg, LogType.WARNING)
# if data_object.has_data():
# continue
# If no data can be read from the first dir, throw exception
# raise Exception("No data can be read from ", d)
# TODO: will work with select more than one dir later
# else:
# data_object.readDir(d)
try:
data_object = DataTypeModel.create_data_object(
data_type, tracking_box, list_of_dir, [],
req_wf_chans=req_wf_chans, req_soh_chans=req_soh_chans,
read_start=read_start, read_end=read_end)
except Exception:
fmt = traceback.format_exc()
msg = f"Data can't be read due to error: {str(fmt)}"
display_tracking_info(tracking_box, msg, LogType.WARNING)
else:
try:
......@@ -175,14 +163,13 @@ def detect_data_type(list_of_dir: List[str]) -> Optional[str]:
dir_data_type_dict[d] = ("Unknown", '_')
else:
dir_data_type_dict[d] = (data_type, chan)
data_type_list = {d[0] for d in dir_data_type_dict.values()}
if len(data_type_list) > 1:
dir_data_type_str = json.dumps(dir_data_type_dict)
dir_data_type_str = re.sub(r'\{|\}|"', '', dir_data_type_str)
dir_data_type_str = re.sub(r'], ', ']\n', dir_data_type_str)
dir_data_type_str = ', '. join(list(data_type_list))
msg = (f"There are more than one types of data detected:\n"
f"{dir_data_type_str}\n\n"
f"Please have only data that related to each other.")
f"Please have only one data type for each loading.")
raise Exception(msg)
elif data_type_list == {'Unknown'}:
......
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