Skip to content
Snippets Groups Projects
Commit 30437627 authored by Kien Le's avatar Kien Le
Browse files

Read all data points based on database

parent 74e96200
No related branches found
No related tags found
No related merge requests found
Pipeline #4297 failed with stage
in 3 minutes and 51 seconds
...@@ -6,6 +6,7 @@ import re ...@@ -6,6 +6,7 @@ import re
from pathlib import Path from pathlib import Path
from typing import Dict, List from typing import Dict, List
from sohstationviewer.database.process_db import execute_db_dict
from sohstationviewer.view.util.enums import LogType from sohstationviewer.view.util.enums import LogType
from sohstationviewer.model.general_data.general_data import GeneralData from sohstationviewer.model.general_data.general_data import GeneralData
...@@ -29,6 +30,20 @@ class MSeed(GeneralData): ...@@ -29,6 +30,20 @@ class MSeed(GeneralData):
self.nets_by_sta: Dict[str, List[str]] = {} self.nets_by_sta: Dict[str, List[str]] = {}
self.invalid_blockettes = False self.invalid_blockettes = False
self.not_mseed_files = [] self.not_mseed_files = []
# Get whether a channel should have all its data points read.
channels_sql = (
f"SELECT channel, readAllPoints "
f"FROM Channels "
f"WHERE dataType='{self.data_type}'"
)
channels_db_info = execute_db_dict(channels_sql)
self.channels_db_info = {
channel_info['channel']: int(channel_info['readAllPoints'])
for channel_info in channels_db_info
}
# We never want to read all data points in waveform channels, so we
# remove it preemptively.
self.channels_db_info.pop('SEISMIC', None)
self.processing_data() self.processing_data()
def finalize_data(self): def finalize_data(self):
...@@ -86,7 +101,10 @@ class MSeed(GeneralData): ...@@ -86,7 +101,10 @@ class MSeed(GeneralData):
mass_pos_data=self.mass_pos_data, mass_pos_data=self.mass_pos_data,
waveform_data=self.waveform_data, waveform_data=self.waveform_data,
log_data=self.log_data, log_data=self.log_data,
gap_minimum=self.gap_minimum) gap_minimum=self.gap_minimum,
channels_db_info=self.channels_db_info,
data_type=self.data_type,
)
try: try:
reader.read() reader.read()
self.invalid_blockettes = (self.invalid_blockettes self.invalid_blockettes = (self.invalid_blockettes
......
...@@ -5,6 +5,8 @@ from pathlib import Path ...@@ -5,6 +5,8 @@ from pathlib import Path
import numpy import numpy
from obspy import UTCDateTime from obspy import UTCDateTime
from sohstationviewer.database.extract_data import \
convert_actual_channel_to_db_channel_w_question_mark
from sohstationviewer.model.mseed_data.record_reader import RecordReader from sohstationviewer.model.mseed_data.record_reader import RecordReader
from sohstationviewer.model.mseed_data.record_reader_helper import \ from sohstationviewer.model.mseed_data.record_reader_helper import \
RecordMetadata RecordMetadata
...@@ -48,7 +50,9 @@ class MSeedReader: ...@@ -48,7 +50,9 @@ class MSeedReader:
mass_pos_data: Dict = {}, mass_pos_data: Dict = {},
waveform_data: Dict = {}, waveform_data: Dict = {},
log_data: LogData = {}, log_data: LogData = {},
gap_minimum: Optional[float] = None gap_minimum: Optional[float] = None,
channels_db_info: Dict = None,
data_type: str = None,
) -> None: ) -> None:
""" """
The object of the class is to read data from given file to add The object of the class is to read data from given file to add
...@@ -74,6 +78,9 @@ class MSeedReader: ...@@ -74,6 +78,9 @@ class MSeedReader:
:param log_data: data dict of log_data :param log_data: data dict of log_data
:param gap_minimum: minimum length of gaps required to detect :param gap_minimum: minimum length of gaps required to detect
from record from record
:param channels_db_info: dict containing the needed information about
each channel. Only includes whether to read all data points from
a channel currently.
""" """
self.read_start = read_start self.read_start = read_start
self.read_end = read_end self.read_end = read_end
...@@ -89,6 +96,8 @@ class MSeedReader: ...@@ -89,6 +96,8 @@ class MSeedReader:
self.log_data = log_data self.log_data = log_data
self.file_path = file_path self.file_path = file_path
self.file: BinaryIO = open(file_path, 'rb') self.file: BinaryIO = open(file_path, 'rb')
self.channels_db_info = channels_db_info
self.data_type = data_type
self.invalid_blockettes = False, self.invalid_blockettes = False,
...@@ -319,18 +328,24 @@ class MSeedReader: ...@@ -319,18 +328,24 @@ class MSeedReader:
continue continue
else: else:
break break
if data_dict is self.waveform_data:
data_points = list(record.get_two_data_points()) # Some channels are represented differently in the database, so we
times = [record.record_metadata.start_time, # need to convert them to that representation. One such example is
record.record_metadata.end_time] # VM1 for Centaur, which is represented by VM? in the database.
else: # Waveform channels also work like this, but because we never want
# to read all the data points in a waveform channel, we ignore them
# in this conversion.
db_channel = convert_actual_channel_to_db_channel_w_question_mark(
record.record_metadata.channel, self.data_type
)
if self.channels_db_info.get(db_channel):
try: try:
data_points = record.get_data_points() data_points = record.get_data_points()
sample_interval = 1 / record.record_metadata.sample_rate sample_interval = 1 / record.record_metadata.sample_rate
times = numpy.arange( times = numpy.arange(
record.record_metadata.start_time, record.record_metadata.start_time,
record.record_metadata.end_time, record.record_metadata.end_time,
sample_interval).tolist() sample_interval).tolist()
# The previous calculation will always miss one time point # The previous calculation will always miss one time point
# at the end. We can adjust the stop argument to capture # at the end. We can adjust the stop argument to capture
# that point in one calculation, but the code for that is a # that point in one calculation, but the code for that is a
...@@ -340,6 +355,10 @@ class MSeedReader: ...@@ -340,6 +355,10 @@ class MSeedReader:
except ZeroDivisionError: except ZeroDivisionError:
data_points = None data_points = None
times = None times = None
else:
data_points = list(record.get_two_data_points())
times = [record.record_metadata.start_time,
record.record_metadata.end_time]
self.append_data(data_dict, record, data_points, times) self.append_data(data_dict, record, data_points, times)
self.append_log(record) self.append_log(record)
......
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