Skip to content

Commit

Permalink
fix some bugs with mdf v3 channels in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed Feb 18, 2019
1 parent 2e20ca0 commit 1ce857d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
10 changes: 5 additions & 5 deletions asammdf/blocks/mdf_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def _prepare_record(self, group):
sortedchannels = sorted(enumerate(grp.channels), key=lambda i: i[1])
for original_index, new_ch in sortedchannels:
# skip channels with channel dependencies from the numpy record
if new_ch.ch_depend_addr:
if new_ch.component_addr:
continue

start_offset = new_ch.start_offset
Expand Down Expand Up @@ -755,9 +755,9 @@ def _read(self, mapped=False):
)

# check if it has channel dependencies
if new_ch.ch_depend_addr:
if new_ch.component_addr:
dep = ChannelDependency(
address=new_ch.ch_depend_addr, stream=stream,
address=new_ch.component_addr, stream=stream,
)
grp.channel_dependencies.append(dep)
else:
Expand Down Expand Up @@ -3230,11 +3230,11 @@ def save(self, dst, overwrite=False, compression=0):

for channel, dep in zip(gp.channels, gp.channel_dependencies):
if dep:
channel.ch_depend_addr = dep.address = address
channel.component_addr = dep.address = address
blocks.append(dep)
address += dep.block_len
else:
channel.ch_depend_addr = 0
channel.component_addr = 0
address = channel.to_blocks(
address, blocks, defined_texts, cc_map, si_map
)
Expand Down
54 changes: 38 additions & 16 deletions asammdf/blocks/v2_v3_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Channel:
* ``next_ch_addr`` - int : next CNBLOCK address
* ``conversion_addr`` - int : address of channel conversion block
* ``source_addr`` - int : address of channel source block
* ``ch_depend_addr`` - int : address of dependency block (CDBLOCK) of this
* ``component_addr`` - int : address of dependency block (CDBLOCK) of this
channel
* ``comment_addr`` - int : address of TXBLOCK that contains the
channel comment
Expand Down Expand Up @@ -143,7 +143,7 @@ class Channel:
"next_ch_addr",
"conversion_addr",
"source_addr",
"ch_depend_addr",
"component_addr",
"comment_addr",
"channel_type",
"short_name",
Expand Down Expand Up @@ -181,7 +181,7 @@ def __init__(self, **kwargs):
self.next_ch_addr,
self.conversion_addr,
self.source_addr,
self.ch_depend_addr,
self.component_addr,
self.comment_addr,
self.channel_type,
self.short_name,
Expand Down Expand Up @@ -215,7 +215,7 @@ def __init__(self, **kwargs):
self.next_ch_addr,
self.conversion_addr,
self.source_addr,
self.ch_depend_addr,
self.component_addr,
self.comment_addr,
self.channel_type,
self.short_name,
Expand Down Expand Up @@ -243,7 +243,7 @@ def __init__(self, **kwargs):
self.next_ch_addr,
self.conversion_addr,
self.source_addr,
self.ch_depend_addr,
self.component_addr,
self.comment_addr,
self.channel_type,
self.short_name,
Expand Down Expand Up @@ -309,7 +309,7 @@ def __init__(self, **kwargs):
self.next_ch_addr,
self.conversion_addr,
self.source_addr,
self.ch_depend_addr,
self.component_addr,
self.comment_addr,
self.channel_type,
self.short_name,
Expand Down Expand Up @@ -343,7 +343,7 @@ def __init__(self, **kwargs):
self.next_ch_addr,
self.conversion_addr,
self.source_addr,
self.ch_depend_addr,
self.component_addr,
self.comment_addr,
self.channel_type,
self.short_name,
Expand Down Expand Up @@ -371,7 +371,7 @@ def __init__(self, **kwargs):
self.next_ch_addr,
self.conversion_addr,
self.source_addr,
self.ch_depend_addr,
self.component_addr,
self.comment_addr,
self.channel_type,
self.short_name,
Expand Down Expand Up @@ -441,7 +441,7 @@ def __init__(self, **kwargs):
self.next_ch_addr = kwargs.get("next_ch_addr", 0)
self.conversion_addr = kwargs.get("conversion_addr", 0)
self.source_addr = kwargs.get("source_addr", 0)
self.ch_depend_addr = kwargs.get("ch_depend_addr", 0)
self.component_addr = kwargs.get("component_addr", 0)
self.comment_addr = kwargs.get("comment_addr", 0)
self.channel_type = kwargs.get("channel_type", 0)
self.short_name = kwargs.get("short_name", (b"\0" * 32))
Expand Down Expand Up @@ -576,7 +576,7 @@ def __bytes__(self):
self.next_ch_addr,
self.conversion_addr,
self.source_addr,
self.ch_depend_addr,
self.component_addr,
self.comment_addr,
self.channel_type,
self.short_name,
Expand All @@ -599,7 +599,7 @@ def __bytes__(self):
self.next_ch_addr,
self.conversion_addr,
self.source_addr,
self.ch_depend_addr,
self.component_addr,
self.comment_addr,
self.channel_type,
self.short_name,
Expand All @@ -620,7 +620,7 @@ def __bytes__(self):
self.next_ch_addr,
self.conversion_addr,
self.source_addr,
self.ch_depend_addr,
self.component_addr,
self.comment_addr,
self.channel_type,
self.short_name,
Expand Down Expand Up @@ -1260,9 +1260,31 @@ def convert(self, values):
phys = [self[f"text_{i}"] for i in range(nr)]
phys = np.array(phys)

indexes = np.searchsorted(raw_vals, values)
x = sorted(zip(raw_vals, phys))
raw_vals = np.array(
[e[0] for e in x], dtype='<i8'
)
phys = np.array(
[e[1] for e in x]
)

default = b'unknown'

idx1 = np.searchsorted(raw_vals, values, side="right") - 1
idx2 = np.searchsorted(raw_vals, values, side="left")

idx = np.argwhere(idx1 != idx2).flatten()

new_values = np.zeros(
len(values), dtype=max(phys.dtype, np.array([default]).dtype)
)

new_values[idx] = default
idx = np.argwhere(idx1 == idx2).flatten()
if len(idx):
new_values[idx] = phys[idx1[idx]]

values = phys[indexes]
values = new_values

elif conversion_type == v23c.CONVERSION_TYPE_RTABX:
nr = self.ref_param_nr - 1
Expand All @@ -1283,6 +1305,7 @@ def convert(self, values):
default = default.text
else:
default = b""
default = default.strip(b'\0\r\n\t') or b'unknown'

if b"{X}" in default:
default = default.decode("latin-1").replace("{X}", "X").split('"')[1]
Expand Down Expand Up @@ -1317,8 +1340,7 @@ def convert(self, values):

idx = np.argwhere(idx1 == idx2).flatten()
if len(idx):
print(values[idx], type(values[idx]))
new_values[idx] = phys[values[idx]]
new_values[idx] = phys[idx1[idx]]
values = new_values
else:
values = phys[idx1]
Expand Down
13 changes: 9 additions & 4 deletions asammdf/gui/widgets/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,19 @@ def __init__(self, signals, with_dots, *args, **kwargs):
sig.color = color

if len(sig.samples):
sig.min = np.amin(sig.samples)
sig.max = np.amax(sig.samples)
if sig.samples.dtype.kind not in 'SV':
sig.min = np.amin(sig.samples)
sig.max = np.amax(sig.samples)
else:
sig.min = 'n.a.'
sig.max = 'n.a.'

sig.empty = False
else:
sig.empty = True

axis = FormatedAxis("right", pen=color)
if sig.conversion and "text_0" in sig.conversion:
if sig.conversion and hasattr(sig.conversion, "text_0"):
axis.text_conversion = sig.conversion

view_box = pg.ViewBox(enableMenu=False)
Expand Down Expand Up @@ -912,7 +917,7 @@ def keyPressEvent(self, event):
sig.empty = True

axis = FormatedAxis("right", pen=color)
if sig.conversion and "text_0" in sig.conversion:
if sig.conversion and hasattr(sig.conversion, "text_0"):
axis.text_conversion = sig.conversion

view_box = pg.ViewBox(enableMenu=False)
Expand Down

0 comments on commit 1ce857d

Please sign in to comment.