Skip to content
Snippets Groups Projects

Multi-thread TPS plot

Merged Kien Le requested to merge featured-threading_TPS_plot into master
1 unresolved thread
1 file
+ 48
37
Compare changes
  • Side-by-side
  • Inline
from typing import Dict, Optional
from typing import Dict, Optional, List
import numpy as np
from PySide2 import QtCore
@@ -7,59 +7,70 @@ from sohstationviewer.conf import constants as const
class TimePowerSquaredProcessor(QtCore.QRunnable):
def __init__(self, chan_data, start_time, end_time, each_day_5_mins_list):
def __init__(self, channel_data, start_time, end_time, each_day_5_mins_list):
super().__init__()
self.chan_data = chan_data
self.channel_data = channel_data
self.start_time = start_time
self.end_time = end_time
self.each_day_5_mins_list = each_day_5_mins_list
def trim_waveform_data(self) -> List[Dict]:
"""
Trim off waveform traces whose times do not intersect the closed
interval [self.start_time, self.end_time]. Store the traces that are
not removed in self.trimmed_trace_list.
"""
data_start_time = self.channel_data['tracesInfo'][0]['startTmEpoch']
data_end_time = self.channel_data['tracesInfo'][-1]['endTmEpoch']
if (self.start_time > data_end_time
or self.end_time < data_start_time):
return []
good_start_indices = [index
for index, tr
in enumerate(self.channel_data['tracesInfo'])
if tr['startTmEpoch'] > self.start_time]
if good_start_indices:
start_idx = good_start_indices[0]
if start_idx > 0:
start_idx -= 1 # start_time in middle of trace
else:
start_idx = 0
good_end_indices = [idx
for idx, tr
in enumerate(self.channel_data['tracesInfo'])
if tr['endTmEpoch'] <= self.end_time]
if good_end_indices:
end_idx = good_end_indices[-1]
if end_idx < len(self.channel_data['tracesInfo']) - 1:
end_idx += 1 # end_time in middle of trace
else:
end_idx = 0
end_idx += 1 # a[x:y+1] = [a[x], ...a[y]]
good_indices = slice(start_idx, end_idx)
return self.channel_data['tracesInfo'][good_indices]
def run(self) -> Optional[bool]:
"""
Different from soh_data where times and data are each in one np.array,
in waveform_data, times and data are each kept in a list of np.memmap
files along with startTmEpoch and endTmEpoch.
self.chan_data['startIdx'] and self.chan_data['endIdx'] will be used to
self.channel_data['startIdx'] and self.channel_data['endIdx'] will be used to
exclude np.memmap files that aren't in the zoom time range
(startTm, endTm). Data in np.memmap will be trimmed according to times
then time-power-square value for each 5 minutes will be calculated and
saved in chan_data['tps-data']: np.mean(np.square(5m data))
saved in channel_data['tps-data']: np.mean(np.square(5m data))
"""
z_traces_info = self.trim_waveform_data()
# preset all 0 for all 5 minutes for each day
tps_data = np.zeros((len(self.each_day_5_mins_list), const.NO_5M_DAY))
# zoom in to the given range
self.chan_data['startIdx'] = 0
self.chan_data['endIdx'] = len(self.chan_data['tracesInfo'])
if ((self.start_time > self.chan_data['tracesInfo'][-1]['endTmEpoch']) or
(self.end_time < self.chan_data['tracesInfo'][0]['startTmEpoch'])):
return False
indexes = [index for index, tr in enumerate(self.chan_data['tracesInfo'])
if tr['startTmEpoch'] > self.start_time]
if indexes != []:
self.chan_data['startIdx'] = indexes[0]
if self.chan_data['startIdx'] > 0:
self.chan_data['startIdx'] -= 1 # startTm in middle of trace
else:
self.chan_data['startIdx'] = 0
indexes = [idx for (idx, tr) in enumerate(self.chan_data['tracesInfo'])
if tr['endTmEpoch'] <= self.end_time]
if indexes != []:
self.chan_data['endIdx'] = indexes[-1]
if self.chan_data['endIdx'] < len(self.chan_data['tracesInfo']) - 1:
self.chan_data['endIdx'] += 1 # endTm in middle of trace
else:
self.chan_data['endIdx'] = 0
self.chan_data['endIdx'] += 1 # a[x:y+1] = [a[x], ...a[y]
z_traces_info = self.chan_data['tracesInfo'][self.chan_data['startIdx']:self.chan_data['endIdx']]
spr = self.chan_data['samplerate']
self.chan_data['tps_data'] = []
spr = self.channel_data['samplerate']
self.channel_data['tps_data'] = []
start_tps_tm = 0
acc_data_list = []
@@ -105,4 +116,4 @@ class TimePowerSquaredProcessor(QtCore.QRunnable):
curr_col = 0
curr_row += 1
next_tps_tm += const.SEC_5M
self.chan_data['tps_data'] = tps_data
self.channel_data['tps_data'] = tps_data
Loading