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
3 files
+ 39
13
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -61,8 +61,11 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
self.tps_t = 0
self.tps_processors: List[TimePowerSquaredProcessor] = []
# The list of all channels that are processed.
self.channels = []
# The list of channels that have been processed.
self.processed_channels = []
# The post-processing step does not take too much time so there is no
# need to limit the number of threads that can run at once.
self.thread_pool = QtCore.QThreadPool()
@@ -83,10 +86,6 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
:param waveform_data: dict - read waveform data of selected data set,
refer to DataTypeModel.__init__.waveform_data[key]['read_data']
"""
if self.axes:
self.plotting_axes.fig.clear()
self.draw()
self.processed_channels = []
self.channels = []
self.tps_processors = []
@@ -99,6 +98,7 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
if self.axes:
self.plotting_axes.fig.clear()
self.draw()
self.date_mode = self.parent.date_format.upper()
if waveform_data is not None:
self.plotting_data1 = waveform_data
@@ -120,7 +120,6 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
for chan_id in self.plotting_data1:
c_data = self.plotting_data1[chan_id]
if 'tps_data' not in c_data:
# get new minX, maxX according to exact start time of days
self.channels.append(chan_id)
channel_processor = TimePowerSquaredProcessor(
chan_id, c_data, self.min_x, self.max_x,
@@ -140,7 +139,16 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
self.thread_pool.start(processor)
@QtCore.Slot()
def channel_done(self, chan_id):
def channel_done(self, chan_id: str):
"""
Called when a TPS processor finishes processing a channel. Plot the
channel's data if chan_id is not the empty string and add chan_id to
the list of processed channel. If all channels are processed, move to
final step.
:param chan_id: the name of the channel that were processed. Is the
empty string if processing is stopped prematurely.
"""
self.finished_lock.lock()
if chan_id != '':
ax = self.plot_channel(self.plotting_data1[chan_id], chan_id)
@@ -156,6 +164,7 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
self.finished_lock.unlock()
def done(self):
"""Add finishing touches to the plot and display it on the screen."""
self.set_legend()
# Set view size fit with the given data
if self.main_widget.geometry().height() < self.plotting_bot_pixel:
@@ -417,6 +426,7 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
zm2.set_data(x_idx, y_idx)
def request_stop(self):
"""Request all running channel processors to stop."""
for processor in self.tps_processors:
processor.request_stop()
Loading