Skip to content

Commit

Permalink
release 5.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed May 7, 2020
2 parents 20931b9 + 7dbdda7 commit 4633ea5
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 31 deletions.
12 changes: 8 additions & 4 deletions asammdf/blocks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ def master_using_raster(mdf, raster, endpoint=False):
return master


def extract_can_signal(signal, payload):
def extract_signal(signal, payload):
vals = payload

big_endian = False if signal.is_little_endian else True
Expand Down Expand Up @@ -1369,7 +1369,7 @@ def extract_can_signal(signal, payload):
else:
break

if byte_pos > vals.shape[1] * 8:
if byte_pos > vals.shape[1]:
raise MdfException(
f'Could not extract signal "{signal.name}" with start '
f"bit {start_bit} and bit count {signal.size} "
Expand Down Expand Up @@ -1474,6 +1474,10 @@ def extract_can_signal(signal, payload):
return vals


def extract_can_signal(signal, payload):
return extract_signal(signal, payload)


def extract_mux(payload, message, message_id, bus, t, muxer=None, muxer_values=None):
""" extract multiplexed CAN signals from the raw payload
Expand All @@ -1486,7 +1490,7 @@ def extract_mux(payload, message, message_id, bus, t, muxer=None, muxer_values=N
message_id : int
message id
bus : int
CAN bus channel number
bus channel number
t : np.ndarray
timestamps for the raw payload
muxer (None): str
Expand Down Expand Up @@ -1546,7 +1550,7 @@ def extract_mux(payload, message, message_id, bus, t, muxer=None, muxer_values=N
payload_ = payload

for sig in pair_signals:
samples = extract_can_signal(sig, payload_)
samples = extract_signal(sig, payload_)
if len(samples) == 0 and len(t_):
continue

Expand Down
12 changes: 12 additions & 0 deletions asammdf/gui/widgets/formated_axis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from datetime import timedelta
import numpy as np
import pyqtgraph as pg

Expand All @@ -12,6 +13,7 @@ def __init__(self, *args, **kwargs):
self.format = "phys"
self.mode = "phys"
self.text_conversion = None
self.origin = None

def tickStrings(self, values, scale, spacing):
strns = []
Expand Down Expand Up @@ -64,6 +66,16 @@ def tickStrings(self, values, scale, spacing):
else:
val = ""
strns.append(val)
elif self.format == 'time':
strns = [
str(timedelta(seconds=val))
for val in values
]
elif self.format == 'date':
strns = [
str(self.origin + timedelta(seconds=val))
for val in values
]

return strns

Expand Down
45 changes: 44 additions & 1 deletion asammdf/gui/widgets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(self, files=None, *args, **kwargs):
subplot_action.setChecked(self.ignore_value2text_conversions)
menu.addAction(subplot_action)

# search mode menu
# plot background
plot_background_option = QtWidgets.QActionGroup(self)

for option in ("Black", "White"):
Expand All @@ -178,6 +178,24 @@ def __init__(self, files=None, *args, **kwargs):
submenu.addActions(plot_background_option.actions())
menu.addMenu(submenu)

# plot X axis display mode
plot_xaxis_option = QtWidgets.QActionGroup(self)

for option in ("seconds", "time", "date"):

action = QtWidgets.QAction(option, menu)
action.setCheckable(True)
plot_xaxis_option.addAction(action)
action.triggered.connect(partial(self.set_plot_xaxis, option))

if option == self._settings.value("plot_xaxis", "seconds"):
action.setChecked(True)
action.triggered.emit()

submenu = QtWidgets.QMenu("Plot X axis", self.menubar)
submenu.addActions(plot_xaxis_option.actions())
menu.addMenu(submenu)

# search mode menu
theme_option = QtWidgets.QActionGroup(self)

Expand Down Expand Up @@ -577,6 +595,31 @@ def set_plot_background(self, option):
pg.setConfigOption("background", "w")
pg.setConfigOption("foreground", "k")

def set_plot_xaxis(self, option):
self._settings.setValue("plot_xaxis", option)
if option == "seconds":
fmt = "phys"
elif option == "time":
fmt = "time"
elif option == "date":
fmt = "date"

if self.stackedWidget.currentIndex() == 0:
widget = self.files.currentWidget()
elif self.stackedWidget.currentIndex() == 2:
widget = self
else:
widget = None
if widget:
plot = widget.get_current_plot()
if plot:
widget.get_current_plot().plot.x_axis.format = fmt
widget.get_current_plot().plot.x_axis.updateAutoSIPrefix()
if plot.plot.cursor1 is not None:
plot.cursor_moved()
if plot.plot.region is not None:
plot.range_modified()

def set_theme(self, option):
self._settings.setValue("theme", option)
app = QtWidgets.QApplication.instance()
Expand Down
10 changes: 7 additions & 3 deletions asammdf/gui/widgets/mdi_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def add_new_channels(self, names, widget):

count = len(widget.plot.signals)
for i, sig in enumerate(sigs, count):
sig.color = COLORS[len(COLORS) % i]
sig.color = COLORS[i % len(COLORS)]

widget.add_new_channels(sigs)

Expand Down Expand Up @@ -367,6 +367,7 @@ def set_title(mdi):
elif window_type == "Plot":
if hasattr(self, "mdf"):
events = []
origin = self.mdf.start_time

if self.mdf.version >= "4.00":
mdf_events = list(self.mdf.events)
Expand Down Expand Up @@ -407,8 +408,9 @@ def set_title(mdi):
events.append(event)
else:
events = []
origin = self.files.widget(0).mdf.start_time

plot = Plot([], events=events, with_dots=self.with_dots)
plot = Plot([], events=events, with_dots=self.with_dots, origin=origin)

if not self.subplots:
for mdi in self.mdi_area.subWindowList():
Expand Down Expand Up @@ -753,6 +755,7 @@ def set_title(mdi):

if hasattr(self, "mdf"):
events = []
origin = self.mdf.start_time

if self.mdf.version >= "4.00":
mdf_events = list(self.mdf.events)
Expand Down Expand Up @@ -793,8 +796,9 @@ def set_title(mdi):
events.append(event)
else:
events = []
origin = self.files.widget(0).mdf.start_time

plot = Plot([], self.with_dots, events=events)
plot = Plot([], self.with_dots, events=events, origin=origin)

if not self.subplots:
for mdi in self.mdi_area.subWindowList():
Expand Down
83 changes: 61 additions & 22 deletions asammdf/gui/widgets/plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from datetime import timedelta
from functools import partial, reduce
import logging
import os
Expand Down Expand Up @@ -694,7 +695,7 @@ class Plot(QtWidgets.QWidget):
region_removed_signal = QtCore.pyqtSignal(object)
show_properties = QtCore.pyqtSignal(list)

def __init__(self, signals, with_dots=False, *args, **kwargs):
def __init__(self, signals, with_dots=False, origin=None, *args, **kwargs):
events = kwargs.pop("events", None)
super().__init__(*args, **kwargs)
self.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -730,7 +731,7 @@ def __init__(self, signals, with_dots=False, *args, **kwargs):
self.splitter.addWidget(widget)
self.splitter.setOpaqueResize(False)

self.plot = _Plot(with_dots=with_dots, parent=self, events=events)
self.plot = _Plot(with_dots=with_dots, parent=self, events=events, origin=origin)
self.plot.range_modified.connect(self.range_modified)
self.plot.range_removed.connect(self.range_removed)
self.plot.range_modified_finished.connect(self.range_modified_finished)
Expand Down Expand Up @@ -903,7 +904,16 @@ def cursor_moved(self):
# self.plot.cursor_hint.show()

if not self.plot.region:
self.cursor_info.setText(f"t = {position:.6f}s")
fmt = self.plot.x_axis.format
if fmt == "phys":
cursor_info_text = f"t = {position:.6f}s"
elif fmt == "time":
cursor_info_text = f"t = {timedelta(seconds=position)}"
elif fmt == "date":
position_date = self.plot.x_axis.origin + timedelta(seconds=position)
cursor_info_text = f"t = {position_date}"
self.cursor_info.setText(cursor_info_text)

items = [
self.channel_selection.item(i)
for i in range(self.channel_selection.count())
Expand Down Expand Up @@ -948,12 +958,27 @@ def cursor_removed(self):
def range_modified(self):
start, stop = self.plot.region.getRegion()

fmt = self.plot.x_axis.format
if fmt == "phys":
start_info = f"{start:.6f}s"
stop_info = f"{stop:.6f}s"
delta_info = f"{stop - start:.6f}s"
elif fmt == "time":
start_info = f"{timedelta(seconds=start)}"
stop_info = f"{timedelta(seconds=stop)}"
delta_info = f"{timedelta(seconds=(stop - start))}"
elif fmt == "date":
start_info = self.plot.x_axis.origin + timedelta(seconds=start)
stop_info = self.plot.x_axis.origin + timedelta(seconds=stop)

delta_info = f"{timedelta(seconds=(stop - start))}"

self.cursor_info.setText(
(
"< html > < head / > < body >"
f"< p >t1 = {start:.6f}s< / p > "
f"< p >t2 = {stop:.6f}s< / p > "
f"< p >Δt = {stop - start:.6f}s< / p > "
f"< p >t1 = {start_info}< / p > "
f"< p >t2 = {stop_info}< / p > "
f"< p >Δt = {delta_info}< / p > "
"< / body > < / html >"
)
)
Expand Down Expand Up @@ -1080,9 +1105,9 @@ def keyPressEvent(self, event):
if signal.plot_samples.dtype.kind in "ui":
signal.format = fmt
if self.plot.current_uuid == signal.uuid:
self.plot.axis.format = fmt
self.plot.axis.hide()
self.plot.axis.show()
self.plot.y_axis.format = fmt
self.plot.y_axis.hide()
self.plot.y_axis.show()
if self.plot.cursor1:
self.plot.cursor_moved.emit()

Expand Down Expand Up @@ -1145,9 +1170,9 @@ def keyPressEvent(self, event):
view.setYRange(buttom, top, padding=0, update=True)

if self.plot.current_uuid == signal.uuid:
self.plot.axis.mode = mode
self.plot.axis.hide()
self.plot.axis.show()
self.plot.y_axis.mode = mode
self.plot.y_axis.hide()
self.plot.y_axis.show()

self.plot.update_lines(force=True)

Expand Down Expand Up @@ -1416,7 +1441,7 @@ class _Plot(pg.PlotWidget):

add_channels_request = QtCore.pyqtSignal(list)

def __init__(self, signals=None, with_dots=False, *args, **kwargs):
def __init__(self, signals=None, with_dots=False, origin=None, *args, **kwargs):
events = kwargs.pop("events", [])
super().__init__()

Expand Down Expand Up @@ -1462,6 +1487,7 @@ def __init__(self, signals=None, with_dots=False, *args, **kwargs):

self.plot_item = self.plotItem
self.plot_item.hideAxis("left")
self.plot_item.hideAxis("bottom")
self.layout = self.plot_item.layout
self.scene_ = self.plot_item.scene()
self.scene_.sigMouseClicked.connect(self._clicked)
Expand All @@ -1474,13 +1500,26 @@ def __init__(self, signals=None, with_dots=False, *args, **kwargs):
self.scene_.addItem(self.common_viewbox)
self.common_viewbox.setXLink(self.viewbox)

axis = self.layout.itemAt(3, 1)
axis.setParent(None)
self.x_axis = FormatedAxis("bottom")
self.layout.removeItem(self.x_axis)
self.layout.addItem(self.x_axis, 3, 1)
self.x_axis.linkToView(axis.linkedView())
self.plot_item.axes["bottom"]["item"] = self.x_axis
fmt = self._settings.value("plot_xaxis")
if fmt == "seconds":
fmt = "phys"
self.x_axis.format = fmt
self.x_axis.origin = origin

axis = self.layout.itemAt(2, 0)
axis.setParent(None)
self.axis = FormatedAxis("left")
self.y_axis = FormatedAxis("left")
self.layout.removeItem(axis)
self.layout.addItem(self.axis, 2, 0)
self.axis.linkToView(axis.linkedView())
self.plot_item.axes["left"]["item"] = self.axis
self.layout.addItem(self.y_axis, 2, 0)
self.y_axis.linkToView(axis.linkedView())
self.plot_item.axes["left"]["item"] = self.y_axis

self.cursor_hint = pg.PlotDataItem(
[],
Expand Down Expand Up @@ -1647,8 +1686,8 @@ def set_color(self, uuid, color):
self.curves[index].setSymbolBrush(color)

if uuid == self.current_uuid:
self.axis.setPen(color)
self.axis.setTextPen(color)
self.y_axis.setPen(color)
self.y_axis.setTextPen(color)

def set_common_axis(self, uuid, state):
_, index = self.signal_by_uuid(uuid)
Expand Down Expand Up @@ -2084,7 +2123,7 @@ def trim(self, signals=None):
return
(start, stop), _ = self.viewbox.viewRange()

width = self.width() - self.axis.width()
width = self.width() - self.y_axis.width()

for sig in signals:
sig.trim(start, stop, width)
Expand All @@ -2102,7 +2141,7 @@ def _resizeEvent(self, ev):
super().resizeEvent(ev)

def set_current_uuid(self, uuid, force=False):
axis = self.axis
axis = self.y_axis
viewbox = self.viewbox

sig, index = self.signal_by_uuid(uuid)
Expand Down Expand Up @@ -2202,7 +2241,7 @@ def add_new_channels(self, channels, computed=False):

(start, stop), _ = self.viewbox.viewRange()

width = self.width() - self.axis.width()
width = self.width() - self.y_axis.width()
trim_info = start, stop, width

channels = [
Expand Down
Loading

0 comments on commit 4633ea5

Please sign in to comment.