Skip to content

Commit

Permalink
Merge pull request #907 from tov101/groups_fixes
Browse files Browse the repository at this point in the history
Channel Groups fixes and tests
  • Loading branch information
danielhrisca authored Sep 11, 2023
2 parents 127d28d + 9f30d47 commit ded96ae
Show file tree
Hide file tree
Showing 87 changed files with 4,210 additions and 7,729 deletions.
184 changes: 46 additions & 138 deletions benchmarks/bench.py

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions benchmarks/gen_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,9 @@ def generate_graphs(result, topic, aspect, for_doc=False):
ax.invert_yaxis()
ax.set_xlabel("Time [ms]" if aspect == "time" else "RAM [MB]")
if topic == "Get":
ax.set_title(
"Get all channels (36424 calls) - {}".format(
"time" if aspect == "time" else "ram usage"
)
)
ax.set_title("Get all channels (36424 calls) - {}".format("time" if aspect == "time" else "ram usage"))
else:
ax.set_title(
"{} test file - {}".format(
topic, "time" if aspect == "time" else "ram usage"
)
)
ax.set_title("{} test file - {}".format(topic, "time" if aspect == "time" else "ram usage"))
ax.xaxis.grid()

fig.subplots_adjust(
Expand Down
3 changes: 1 addition & 2 deletions ci/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def __str__(self):
verdict_details = ""
for data in datas:
verdict_table_entry = (
f"|{data.classname}|[{data.name}](#user-content-{data.name.lower()})|"
f"{data.time}|\n"
f"|{data.classname}|[{data.name}](#user-content-{data.name.lower()})|" f"{data.time}|\n"
)
verdict_data_entry = (
f"<details><summary>\n"
Expand Down
4 changes: 1 addition & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "asammdf.tex", "asammdf Documentation", "Daniel Hrisca", "manual")
]
latex_documents = [(master_doc, "asammdf.tex", "asammdf Documentation", "Daniel Hrisca", "manual")]


# -- Options for manual page output ---------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions examples/mf4_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@
# value to text
vals = 20
conversion = {"val_{}".format(i): i for i in range(vals)}
conversion.update(
{"text_{}".format(i): "key_{}".format(i).encode("ascii") for i in range(vals)}
)
conversion.update({"text_{}".format(i): "key_{}".format(i).encode("ascii") for i in range(vals)})
conversion["default"] = b"default key"
sig = Signal(
np.arange(cycles, dtype=np.uint32) % 30,
Expand Down
4 changes: 1 addition & 3 deletions examples/working with Signal class.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@

timestamps = np.arange(0, 2, 0.02)

s_map = Signal(
samples=samples, timestamps=timestamps, name="Variable Map Signal", unit="dB"
)
s_map = Signal(samples=samples, timestamps=timestamps, name="Variable Map Signal", unit="dB")
s_map.plot()


Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requires = ["numpy", "setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 120
target-version = ['py38']
extend-exclude = '''
^/src/asammdf/gui/ui
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ def _get_ext_modules():
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
entry_points={
"console_scripts": ["asammdf = asammdf.gui.asammdfgui:main [gui,export,decode]"]
},
entry_points={"console_scripts": ["asammdf = asammdf.gui.asammdfgui:main [gui,export,decode]"]},
ext_modules=_get_ext_modules(),
)
25 changes: 6 additions & 19 deletions src/asammdf/blocks/bus_logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def defined_j1939_bit_count(signal):
return size


def apply_conversion(
vals: NDArray[Any], signal: Signal, ignore_value2text_conversion: bool
) -> NDArray[Any]:
def apply_conversion(vals: NDArray[Any], signal: Signal, ignore_value2text_conversion: bool) -> NDArray[Any]:
a, b = float(signal.factor), float(signal.offset)

if signal.values:
Expand Down Expand Up @@ -99,13 +97,9 @@ def extract_signal(

if is_float:
if bit_offset:
raise MdfException(
f"Cannot extract float signal '{signal}' because it is not byte aligned"
)
raise MdfException(f"Cannot extract float signal '{signal}' because it is not byte aligned")
if bit_count not in (16, 32, 64):
raise MdfException(
f"Cannot extract float signal '{signal}' because it does not have a standard byte size"
)
raise MdfException(f"Cannot extract float signal '{signal}' because it does not have a standard byte size")

if big_endian:
byte_pos = start_byte + 1
Expand Down Expand Up @@ -329,10 +323,7 @@ def extract_mux(
multiplexor_name = sig.name
break
for sig in message:
if (
sig.multiplex not in (None, "Multiplexor")
and sig.muxer_for_signal is None
):
if sig.multiplex not in (None, "Multiplexor") and sig.muxer_for_signal is None:
sig.muxer_for_signal = multiplexor_name
sig.mux_val_min = sig.mux_val_max = int(sig.multiplex)
sig.mux_val_grp.insert(0, (int(sig.multiplex), int(sig.multiplex)))
Expand Down Expand Up @@ -386,17 +377,13 @@ def extract_mux(
"name": sig_name,
"comment": sig.comment or "",
"unit": sig.unit or "",
"samples": samples
if raw
else apply_conversion(samples, sig, ignore_value2text_conversion),
"samples": samples if raw else apply_conversion(samples, sig, ignore_value2text_conversion),
"t": t_,
"invalidation_bits": None,
}

if is_j1939:
signals[sig_name]["invalidation_bits"] = (
samples > MAX_VALID_J1939[defined_j1939_bit_count(sig)]
)
signals[sig_name]["invalidation_bits"] = samples > MAX_VALID_J1939[defined_j1939_bit_count(sig)]

except:
print(format_exc())
Expand Down
68 changes: 17 additions & 51 deletions src/asammdf/blocks/conversion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def conversion_transfer(
unit = conversion.unit.strip(" \r\n\t\0").encode("latin-1")

if conversion_type == v4c.CONVERSION_TYPE_NON:
conversion = v3b.ChannelConversion(
unit=unit, conversion_type=v3c.CONVERSION_TYPE_NONE
)
conversion = v3b.ChannelConversion(unit=unit, conversion_type=v3c.CONVERSION_TYPE_NONE)

elif conversion_type == v4c.CONVERSION_TYPE_LIN:
conversion = v3b.ChannelConversion(
Expand Down Expand Up @@ -141,22 +139,16 @@ def conversion_transfer(
conversion.referenced_blocks[f"text_{i}"],
v4b.ChannelConversion,
):
kargs[f"text_{i}"] = conversion.referenced_blocks[
f"text_{i}"
].name.encode("latin-1")
kargs[f"text_{i}"] = conversion.referenced_blocks[f"text_{i}"].name.encode("latin-1")
else:
kargs[f"text_{i}"] = conversion.referenced_blocks[
f"text_{i}"
]
kargs[f"text_{i}"] = conversion.referenced_blocks[f"text_{i}"]

new_conversion = v3b.ChannelConversion(**kargs)
if isinstance(
conversion.referenced_blocks["default_addr"],
v4b.ChannelConversion,
):
default_addr = conversion.referenced_blocks[
f"default_addr"
].name.encode("latin-1")
default_addr = conversion.referenced_blocks[f"default_addr"].name.encode("latin-1")
else:
default_addr = conversion.referenced_blocks["default_addr"]
new_conversion.referenced_blocks["default_addr"] = default_addr
Expand All @@ -177,22 +169,16 @@ def conversion_transfer(
conversion.referenced_blocks[f"text_{i}"],
v4b.ChannelConversion,
):
kargs[f"text_{i}"] = conversion.referenced_blocks[
f"text_{i}"
].name.encode("latin-1")
kargs[f"text_{i}"] = conversion.referenced_blocks[f"text_{i}"].name.encode("latin-1")
else:
kargs[f"text_{i}"] = conversion.referenced_blocks[
f"text_{i}"
]
kargs[f"text_{i}"] = conversion.referenced_blocks[f"text_{i}"]

new_conversion = v3b.ChannelConversion(**kargs)
if isinstance(
conversion.referenced_blocks["default_addr"],
v4b.ChannelConversion,
):
default_addr = conversion.referenced_blocks[
f"default_addr"
].name.encode("latin-1")
default_addr = conversion.referenced_blocks[f"default_addr"].name.encode("latin-1")
else:
default_addr = conversion.referenced_blocks["default_addr"]
new_conversion.referenced_blocks["default_addr"] = default_addr
Expand All @@ -208,9 +194,7 @@ def conversion_transfer(
unit = conversion.unit_field.decode("latin-1").strip(" \r\n\t\0")

if conversion_type == v3c.CONVERSION_TYPE_NONE:
conversion = v4b.ChannelConversion(
conversion_type=v4c.CONVERSION_TYPE_NON
)
conversion = v4b.ChannelConversion(conversion_type=v4c.CONVERSION_TYPE_NON)

elif conversion_type == v3c.CONVERSION_TYPE_LINEAR:
conversion = v4b.ChannelConversion(
Expand All @@ -232,9 +216,7 @@ def conversion_transfer(

elif conversion_type == v3c.CONVERSION_TYPE_FORMULA:
formula = conversion.formula
conversion = v4b.ChannelConversion(
conversion_type=v4c.CONVERSION_TYPE_ALG, formula=formula
)
conversion = v4b.ChannelConversion(conversion_type=v4c.CONVERSION_TYPE_ALG, formula=formula)

elif conversion_type == v3c.CONVERSION_TYPE_TAB:
conversion_ = {}
Expand All @@ -243,9 +225,7 @@ def conversion_transfer(
conversion_[f"raw_{i}"] = conversion[f"raw_{i}"]
conversion_[f"phys_{i}"] = conversion[f"phys_{i}"]

conversion = v4b.ChannelConversion(
conversion_type=v4c.CONVERSION_TYPE_TAB, **conversion_
)
conversion = v4b.ChannelConversion(conversion_type=v4c.CONVERSION_TYPE_TAB, **conversion_)

elif conversion_type == v3c.CONVERSION_TYPE_TABI:
conversion_ = {}
Expand All @@ -254,9 +234,7 @@ def conversion_transfer(
conversion_[f"raw_{i}"] = conversion[f"raw_{i}"]
conversion_[f"phys_{i}"] = conversion[f"phys_{i}"]

conversion = v4b.ChannelConversion(
conversion_type=v4c.CONVERSION_TYPE_TABI, **conversion_
)
conversion = v4b.ChannelConversion(conversion_type=v4c.CONVERSION_TYPE_TABI, **conversion_)

elif conversion_type == v3c.CONVERSION_TYPE_TABX:
nr = conversion["ref_param_nr"]
Expand Down Expand Up @@ -426,32 +404,20 @@ def to_dict(conversion: ChannelConversionType) -> Union[dict, None]:
conversion_dict["conversion_type"] = conversion_type

elif conversion_type == v4c.CONVERSION_TYPE_RAT:
conversion_dict.update(
{key: conversion[key] for key in [f"P{i}" for i in range(1, 7)]}
)
conversion_dict.update({key: conversion[key] for key in [f"P{i}" for i in range(1, 7)]})
conversion_dict["conversion_type"] = conversion_type

elif conversion_type in (v4c.CONVERSION_TYPE_TAB, v4c.CONVERSION_TYPE_TABI):
params = conversion["val_param_nr"] // 2
conversion_dict.update(
{key: conversion[key] for key in [f"phys_{nr}" for nr in range(params)]}
)
conversion_dict.update(
{key: conversion[key] for key in [f"raw_{nr}" for nr in range(params)]}
)
conversion_dict.update({key: conversion[key] for key in [f"phys_{nr}" for nr in range(params)]})
conversion_dict.update({key: conversion[key] for key in [f"raw_{nr}" for nr in range(params)]})
conversion_dict["conversion_type"] = conversion_type

elif conversion_type == v4c.CONVERSION_TYPE_RTAB:
params = (conversion["val_param_nr"] - 1) // 3
conversion_dict.update(
{key: conversion[key] for key in [f"lower_{nr}" for nr in range(params)]}
)
conversion_dict.update(
{key: conversion[key] for key in [f"upper_{nr}" for nr in range(params)]}
)
conversion_dict.update(
{key: conversion[key] for key in [f"phys_{nr}" for nr in range(params)]}
)
conversion_dict.update({key: conversion[key] for key in [f"lower_{nr}" for nr in range(params)]})
conversion_dict.update({key: conversion[key] for key in [f"upper_{nr}" for nr in range(params)]})
conversion_dict.update({key: conversion[key] for key in [f"phys_{nr}" for nr in range(params)]})
conversion_dict["conversion_type"] = conversion_type
conversion_dict["default"] = conversion.default

Expand Down
15 changes: 3 additions & 12 deletions src/asammdf/blocks/mdf_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ def _validate_channel_selection(

if name is None:
if group is None or index is None:
message = (
"Invalid arguments for channel selection: "
'must give "name" or, "group" and "index"'
)
message = "Invalid arguments for channel selection: " 'must give "name" or, "group" and "index"'
raise MdfException(message)
else:
gp_nr, ch_nr = group, index
Expand All @@ -79,9 +76,7 @@ def _validate_channel_selection(
try:
grp.channels[ch_nr]
except IndexError:
raise MdfException(
f"Channel index out of range: {(name, group, index)}"
)
raise MdfException(f"Channel index out of range: {(name, group, index)}")
else:
if name not in self.channels_db:
raise MdfException(f'Channel "{name}" not found')
Expand Down Expand Up @@ -114,11 +109,7 @@ def _validate_channel_selection(
ch_nr = index
else:
if index is None:
entries = tuple(
(gp_nr, ch_nr)
for gp_nr, ch_nr in self.channels_db[name]
if gp_nr == group
)
entries = tuple((gp_nr, ch_nr) for gp_nr, ch_nr in self.channels_db[name] if gp_nr == group)
count = len(entries)

if count == 1:
Expand Down
4 changes: 1 addition & 3 deletions src/asammdf/blocks/mdf_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ def __init__(
version = validate_version_argument(version, hint=2)

if not kwargs.get("__internal__", False):
raise MdfException(
"Always use the MDF class; do not use the class MDF2 directly"
)
raise MdfException("Always use the MDF class; do not use the class MDF2 directly")

super().__init__(name, version, **kwargs)

Expand Down
Loading

0 comments on commit ded96ae

Please sign in to comment.