Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed Nov 28, 2018
2 parents 915f583 + 5a90135 commit 9cd3554
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 131 deletions.
16 changes: 11 additions & 5 deletions asammdf/mdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ def export(self, fmt, filename=None, **kargs):
options are *skip* or *zeros*; default is *zeros*
* `format`: only valid for *mat* export; can be '4', '5' or '7.3',
default is '5'
* `oned_as`: only valid for *mat* export; can be 'row' or 'column'
Returns
-------
Expand All @@ -969,6 +970,7 @@ def export(self, fmt, filename=None, **kargs):
use_display_names = kargs.get("use_display_names", True)
empty_channels = kargs.get("empty_channels", "zeros")
format = kargs.get("format", "5")
oned_as = kargs.get("oned_as", "row")

name = filename if filename else self.name

Expand Down Expand Up @@ -1444,9 +1446,15 @@ def export(self, fmt, filename=None, **kargs):
long_field_names=True,
format="7.3",
delete_unused_variables=False,
oned_as=oned_as,
)
else:
savemat(name, mdict, long_field_names=True)
savemat(
name,
mdict,
long_field_names=True,
oned_as=oned_as,
)

elif fmt in ("pandas", "parquet"):
if fmt == "pandas":
Expand Down Expand Up @@ -1832,7 +1840,7 @@ def concatenate(files, version="4.10", memory="full", sync=True, **kwargs):

oldest = header.start_time

offsets = [oldest - oldest for _ in files]
offsets = [0 for _ in files]

sizes = set()
for file in files:
Expand Down Expand Up @@ -1946,7 +1954,6 @@ def concatenate(files, version="4.10", memory="full", sync=True, **kwargs):

if len(signals[0]):
last_timestamp = signals[0].timestamps[-1]
delta = last_timestamp / len(signals[0])

if signals:
merged.append(signals, common_timebase=True)
Expand All @@ -1958,10 +1965,9 @@ def concatenate(files, version="4.10", memory="full", sync=True, **kwargs):
if len(master):
if last_timestamp is None:
last_timestamp = master[-1]
delta = last_timestamp / len(master)
else:
if last_timestamp >= master[0]:
master += last_timestamp + delta - master[0]
master += last_timestamp
last_timestamp = master[-1]

signals = [(master, None)]
Expand Down
10 changes: 6 additions & 4 deletions asammdf/mdf_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2264,16 +2264,18 @@ def close(self):

def extend(self, index, signals):
"""
Extend a group with new samples. The first signal is the master channel's samples, and the
next signals must respect the same order in which they were appended. The samples must have raw
Extend a group with new samples. *signals* contains (values, invalidation_bits)
pairs for each extended signal. Since MDF3 does not support invalidation
bits, the second item of each pair must be None. The first pair is the master channel's pair, and the
next pairs must respect the same order in which the signals were appended. The samples must have raw
or physical values according to the *Signals* used for the initial append.
Parameters
----------
index : int
group index
signals : list
list on numpy.ndarray objects
list of (numpy.ndarray, None) objects
Examples
--------
Expand All @@ -2290,7 +2292,7 @@ def extend(self, index, signals):
>>> mdf = MDF3('new.mdf')
>>> mdf.append([s1, s2, s3], 'created by asammdf v1.1.0')
>>> t = np.array([0.006, 0.007, 0.008, 0.009, 0.010])
>>> mdf2.extend(0, [t, s1, s2, s3])
>>> mdf2.extend(0, [(t, None), (s1.samples, None), (s2.samples, None), (s3.samples, None)])
"""
memory = self.memory
Expand Down
13 changes: 9 additions & 4 deletions asammdf/mdf_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -3667,16 +3667,17 @@ def _append_dataframe(self, df, source_info="", units=None):

def extend(self, index, signals):
"""
Extend a group with new samples. The first signal is the master channel's samples, and the
next signals must respect the same order in which they were appended. The samples must have raw
Extend a group with new samples. *signals* contains (values, invalidation_bits)
pairs for each extended signal. The first pair is the master channel's pair, and the
next pairs must respect the same order in which the signals were appended. The samples must have raw
or physical values according to the *Signals* used for the initial append.
Parameters
----------
index : int
group index
signals : list
list on numpy.ndarray objects
list on (numpy.ndarray, numpy.ndarray) objects
Examples
--------
Expand All @@ -3693,7 +3694,11 @@ def extend(self, index, signals):
>>> mdf = MDF3('new.mdf')
>>> mdf.append([s1, s2, s3], 'created by asammdf v1.1.0')
>>> t = np.array([0.006, 0.007, 0.008, 0.009, 0.010])
>>> mdf2.extend(0, [t, s1, s2, s3])
>>> # extend without invalidation bits
>>> mdf2.extend(0, [(t, None), (s1, None), (s2, None), (s3, None)])
>>> # some invaldiation btis
>>> s1_inv = np.array([0,0,0,1,1], dtype=np.bool)
>>> mdf2.extend(0, [(t, None), (s1.samples, None), (s2.samples, None), (s3.samples, None)])
"""
gp = self.groups[index]
Expand Down
29 changes: 9 additions & 20 deletions asammdf/v2_v3_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,6 @@ def metadata(self, indent=""):
return "\n".join(metadata)

def convert(self, values):
numexpr_favorable_size = 140000
conversion_type = self["conversion_type"]

if conversion_type == v23c.CONVERSION_TYPE_NONE:
Expand All @@ -1086,13 +1085,9 @@ def convert(self, values):
a = self["a"]
b = self["b"]
if (a, b) != (1, 0):
if len(values) >= numexpr_favorable_size:
values = values.astype("float64")
values = evaluate("values * a + b")
else:
values = values * a
if b:
values += b
values = values * a
if b:
values += b

elif conversion_type in (v23c.CONVERSION_TYPE_TABI, v23c.CONVERSION_TYPE_TAB):
nr = self["ref_param_nr"]
Expand Down Expand Up @@ -1219,20 +1214,14 @@ def convert(self, values):
X = values
if (P1, P4, P5, P6) == (0, 0, 0, 1):
if (P2, P3) != (1, 0):
if len(values) >= numexpr_favorable_size:
values = evaluate("values * P2 + P3")
else:
values = values * P2
if P3:
values += P3
values = values * P2
if P3:
values += P3
elif (P3, P4, P5, P6) == (0, 0, 1, 0):
if (P1, P2) != (1, 0):
if len(values) >= numexpr_favorable_size:
values = evaluate("values * P1 + P2")
else:
values = values * P1
if P2:
values += P2
values = values * P1
if P2:
values += P2
else:
values = evaluate(v23c.RAT_CONV_TEXT)

Expand Down
29 changes: 9 additions & 20 deletions asammdf/v4_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"DataList",
"DataGroup",
"FileHistory",
"SignalDataBlock",
"SourceInformation",
"TextBlock",
]
Expand Down Expand Up @@ -2222,20 +2221,16 @@ def to_stream(self, stream, defined_texts, cc_map):
return address

def convert(self, values):
numexpr_favorable_size = 140000
conversion_type = self["conversion_type"]
if conversion_type == v4c.CONVERSION_TYPE_NON:
pass
elif conversion_type == v4c.CONVERSION_TYPE_LIN:
a = self["a"]
b = self["b"]
if (a, b) != (1, 0):
if len(values) >= 140000:
values = evaluate("values * a + b")
else:
values = values * a
if b:
values += b
values = values * a
if b:
values += b
elif conversion_type == v4c.CONVERSION_TYPE_RAT:
P1 = self["P1"]
P2 = self["P2"]
Expand All @@ -2247,20 +2242,14 @@ def convert(self, values):
X = values
if (P1, P4, P5, P6) == (0, 0, 0, 1):
if (P2, P3) != (1, 0):
if len(values) >= numexpr_favorable_size:
values = evaluate("values * P2 + P3")
else:
values = values * P2
if P3:
values += P3
values = values * P2
if P3:
values += P3
elif (P3, P4, P5, P6) == (0, 0, 1, 0):
if (P1, P2) != (1, 0):
if len(values) >= numexpr_favorable_size:
values = evaluate("values * P1 + P2")
else:
values = values * P1
if P2:
values += P2
values = values * P1
if P2:
values += P2
else:
values = evaluate(v4c.CONV_RAT_TEXT)

Expand Down
Loading

0 comments on commit 9cd3554

Please sign in to comment.