Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	asammdf/version.py
  • Loading branch information
danielhrisca committed Feb 2, 2021
2 parents e407afb + 61209be commit 97d1ddd
Show file tree
Hide file tree
Showing 15 changed files with 1,661 additions and 244 deletions.
26 changes: 16 additions & 10 deletions asammdf/blocks/bus_logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
def apply_conversion(vals, signal, ignore_value2text_conversion):
a, b = float(signal.factor), float(signal.offset)

if signal.values and not ignore_value2text_conversion:
if signal.values:
if ignore_value2text_conversion:
if (a, b) != (1, 0):
vals = vals * a
if b:
vals += b
else:

conv = {}
for i, (val, text) in enumerate(signal.values.items()):
conv[f"upper_{i}"] = val
conv[f"lower_{i}"] = val
conv[f"text_{i}"] = text
conv = {}
for i, (val, text) in enumerate(signal.values.items()):
conv[f"upper_{i}"] = val
conv[f"lower_{i}"] = val
conv[f"text_{i}"] = text

conv["default"] = from_dict({"a": a, "b": b})
conv["default"] = from_dict({"a": a, "b": b})

conv = from_dict(conv)
vals = conv.convert(vals)
conv = from_dict(conv)
vals = conv.convert(vals)

else:

Expand Down Expand Up @@ -331,7 +337,7 @@ def extract_mux(
"samples": samples if raw else apply_conversion(samples, sig, ignore_value2text_conversion),
"t": t_,
"invalidation_bits": (
np.isclose(samples, max_val)
np.isclose(apply_conversion(samples, sig, ignore_value2text_conversion=True), max_val)
if len(samples.shape) == 1
else np.zeros(len(samples), dtype=bool)
),
Expand Down
7 changes: 3 additions & 4 deletions asammdf/blocks/cutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,16 @@ static PyObject* sort_data_block(PyObject* self, PyObject* args)
static PyObject* extract(PyObject* self, PyObject* args)
{
int i=0, count, max=0;
bool is_byte_array;
int pos=0;
int size;
PyObject *signal_data;
PyObject *signal_data, *is_byte_array;
unsigned char *buf;
PyArrayObject *vals;
PyArray_Descr *descr;
void *addr;
unsigned char * addr2;

if(!PyArg_ParseTuple(args, "Op", &signal_data, &is_byte_array))
if(!PyArg_ParseTuple(args, "OO", &signal_data, &is_byte_array))
{
snprintf(err_string, 1024, "extract was called with wrong parameters");
PyErr_SetString(PyExc_ValueError, err_string);
Expand All @@ -180,7 +179,7 @@ static PyObject* extract(PyObject* self, PyObject* args)
count++;
}

if (is_byte_array)
if (PyObject_IsTrue(is_byte_array))
{

npy_intp dims[2];
Expand Down
45 changes: 32 additions & 13 deletions asammdf/blocks/mdf_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,22 @@ def _validate_channel_selection(

entries = self.channels_db[name]
if len(entries) > 1:
message = (
f'Multiple occurrences for channel "{name}": {entries}. '
'Provide both "group" and "index" arguments'
" to select another data group"
)
logger.exception(message)
raise MdfException(message)
if self._raise_on_mutiple_occurences:
message = (
f'Multiple occurrences for channel "{name}": {entries}. '
'Provide both "group" and "index" arguments'
" to select another data group"
)
logger.exception(message)
raise MdfException(message)
else:
message = (
f'Multiple occurrences for channel "{name}": {entries}. '
'Returning the first occurence since the MDF obejct was '
'configured to not raise an exception in this case.'
)
logger.warning(message)
gp_nr, ch_nr = entries[0]
else:
gp_nr, ch_nr = entries[0]

Expand All @@ -153,12 +162,22 @@ def _validate_channel_selection(
raise MdfException(message)

else:
message = (
f'Multiple occurrences for channel "{name}" in group {group}. '
'Provide also the "index" argument'
" to select the desired channel"
)
raise MdfException(message)
if self._raise_on_mutiple_occurences:
message = (
f'Multiple occurrences for channel "{name}": {entries}. '
'Provide both "group" and "index" arguments'
" to select another data group"
)
logger.exception(message)
raise MdfException(message)
else:
message = (
f'Multiple occurrences for channel "{name}": {entries}. '
'Returning the first occurence since the MDF obejct was '
'configured to not raise an exception in this case.'
)
logger.warning(message)
gp_nr, ch_nr = entries[0]
else:
if (group, index) in self.channels_db[name]:
ch_nr = index
Expand Down
74 changes: 70 additions & 4 deletions asammdf/blocks/mdf_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ def __init__(self, name=None, version="3.30", channels=(), **kwargs):
self._write_fragment_size = 4 * 2 ** 20
self._single_bit_uint_as_bool = False
self._integer_interpolation = 0
self._float_interpolation = 1
self._raise_on_multiple_occurrences = True
self._use_display_names = False
self.copy_on_get = False
self.raise_on_multiple_occurrences = True

self._si_map = {}
self._cc_map = {}
Expand Down Expand Up @@ -942,15 +947,28 @@ def _read(self, mapped=False):
def configure(
self,
*,
from_other=None,
read_fragment_size=None,
write_fragment_size=None,
use_display_names=None,
single_bit_uint_as_bool=None,
integer_interpolation=None,
copy_on_get=None,
float_interpolation=None,
raise_on_multiple_occurrences=None,
):
"""configure MDF parameters
The default values for the options are the following:
* read_fragment_size = 0
* write_fragment_size = 4MB
* use_display_names = False
* single_bit_uint_as_bool = False
* integer_interpolation = 0 (ffill - use previous sample)
* float_interpolation = 1 (linear interpolation)
* copy_on_get = False
* raise_on_multiple_occurrences = True
Parameters
----------
read_fragment_size : int
Expand Down Expand Up @@ -981,8 +999,37 @@ def configure(
copy_on_get : bool
copy arrays in the get method
float_interpolation : int
interpolation mode for float channels:
* 0 - repeat previous sample
* 1 - use linear interpolation
.. versionadded:: 6.2.0
raise_on_multiple_occurrences : bool
raise exception when there are multiple channel occurrences in the file and
the `get` call is ambiguos; default True
.. versionadded:: 6.2.0
from_other : MDF
copy configuration options from other MDF
.. versionadded:: 6.2.0
"""

if from_other is not None:
self._read_fragment_size = from_other._read_fragment_size
self._write_fragment_size = from_other._write_fragment_size
self._use_display_names = from_other._use_display_names
self._single_bit_uint_as_bool = from_other._single_bit_uint_as_bool
self._integer_interpolation = from_other._integer_interpolation
self.copy_on_get = from_other.copy_on_get
self._float_interpolation = from_other._float_interpolation
self._raise_on_multiple_occurrences = from_other._raise_on_multiple_occurrences

if read_fragment_size is not None:
self._read_fragment_size = int(read_fragment_size)

Expand All @@ -1001,6 +1048,12 @@ def configure(
if copy_on_get is not None:
self.copy_on_get = copy_on_get

if float_interpolation in (0, 1):
self._float_interpolation = int(float_interpolation)

if raise_on_multiple_occurrences is not None:
self._raise_on_multiple_occurrences = bool(raise_on_multiple_occurrences)

def add_trigger(self, group, timestamp, pre_time=0, post_time=0, comment=""):
"""add trigger to data group
Expand Down Expand Up @@ -1147,7 +1200,8 @@ def append(
return

version = self.version
interp_mode = self._integer_interpolation
integer_interp_mode = self._integer_interpolation
float_interp_mode = self._float_interpolation

# check if the signals have a common timebase
# if not interpolate the signals using the union of all timbases
Expand All @@ -1165,7 +1219,11 @@ def append(
times = [s.timestamps for s in signals]
timestamps = unique(concatenate(times)).astype(float64)
signals = [
s.interp(timestamps, interpolation_mode=interp_mode)
s.interp(
timestamps,
integer_interpolation_mode=integer_interp_mode,
float_interpolation_mode=float_interp_mode,
)
for s in signals
]
times = None
Expand Down Expand Up @@ -2829,7 +2887,11 @@ def get(

vals = (
Signal(vals, timestamps, name="_")
.interp(t, interpolation_mode=self._integer_interpolation)
.interp(
t,
integer_interpolation_mode=self._integer_interpolation,
float_interpolation_mode=self._float_interpolation
)
.samples
)

Expand Down Expand Up @@ -2964,7 +3026,11 @@ def get(

vals = (
Signal(vals, timestamps, name="_")
.interp(t, interpolation_mode=self._integer_interpolation)
.interp(
t,
integer_interpolation_mode=self._integer_interpolation,
float_interpolation_mode=self._float_interpolation,
)
.samples
)

Expand Down
Loading

0 comments on commit 97d1ddd

Please sign in to comment.