Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
conversion = v3b.ChannelConversion(unit=unit, **kargs)
elif conversion_type == v4c.CONVERSION_TYPE_TABX:
nr = conversion.val_param_nr
kargs = {
"ref_param_nr": nr,
"unit": unit,
"conversion_type": v3c.CONVERSION_TYPE_TABX,
}
for i in range(nr):
kargs[f"param_val_{i}"] = conversion[f"val_{i}"]
kargs[f"text_{i}"] = conversion.referenced_blocks[
f"text_{i}"
].text
conversion = v3b.ChannelConversion(**kargs)
elif conversion_type == v4c.CONVERSION_TYPE_RTABX:
nr = conversion.val_param_nr // 2
kargs = {
"ref_param_nr": nr + 1,
"unit": unit,
"conversion_type": v3c.CONVERSION_TYPE_RTABX,
}
for i in range(nr):
kargs[f"lower_{i}"] = conversion[f"lower_{i}"]
kargs[f"upper_{i}"] = conversion[f"upper_{i}"]
kargs[f"text_{i}"] = conversion.referenced_blocks[
f"text_{i}"
].text
new_conversion = v3b.ChannelConversion(**kargs)
nr = (conversion.val_param_nr - 1) // 3
kargs = {
"ref_param_nr": nr,
"conversion_type": v3c.CONVERSION_TYPE_TABI,
}
for i in range(nr):
l_ = conversion[f"lower_{i}"]
u_ = conversion[f"upper_{i}"]
p_ = conversion[f"phys_{i}"]
kargs[f"raw_{i}"] = l_
kargs[f"raw_{i}"] = u_ - 0.000_001
kargs[f"phys_{i}"] = p_
kargs[f"phys_{i}"] = p_
conversion = v3b.ChannelConversion(unit=unit, **kargs)
elif conversion_type == v4c.CONVERSION_TYPE_TABX:
nr = conversion.val_param_nr
kargs = {
"ref_param_nr": nr,
"unit": unit,
"conversion_type": v3c.CONVERSION_TYPE_TABX,
}
for i in range(nr):
kargs[f"param_val_{i}"] = conversion[f"val_{i}"]
kargs[f"text_{i}"] = conversion.referenced_blocks[
f"text_{i}"
].text
conversion = v3b.ChannelConversion(**kargs)
elif conversion_type == v4c.CONVERSION_TYPE_TABI:
conversion_ = {}
conversion_["ref_param_nr"] = conversion.val_param_nr // 2
for i in range(conversion.val_param_nr // 2):
conversion_[f"raw_{i}"] = conversion[f"raw_{i}"]
conversion_[f"phys_{i}"] = conversion[f"phys_{i}"]
conversion = v3b.ChannelConversion(
unit=unit,
conversion_type=v3c.CONVERSION_TYPE_TABI,
**conversion_,
)
elif conversion_type == v4c.CONVERSION_TYPE_ALG:
formula = conversion.formula.replace("X", "X1")
conversion = v3b.ChannelConversion(
formula=formula,
unit=unit,
conversion_type=v3c.CONVERSION_TYPE_FORMULA,
)
elif conversion_type == v4c.CONVERSION_TYPE_RTAB:
nr = (conversion.val_param_nr - 1) // 3
kargs = {
"ref_param_nr": nr,
"conversion_type": v3c.CONVERSION_TYPE_TABI,
}
for i in range(nr):
l_ = conversion[f"lower_{i}"]
u_ = conversion[f"upper_{i}"]
p_ = conversion[f"phys_{i}"]
def generate_test_files(version="4.10"):
cycles = 3000
channels_count = 2000
mdf = MDF(version=version)
if version <= "3.30":
filename = r"test.mdf"
else:
filename = r"test.mf4"
if os.path.exists(filename):
return filename
t = np.arange(cycles, dtype=np.float64)
cls = v4b.ChannelConversion if version >= "4.00" else v3b.ChannelConversion
# no conversion
sigs = []
for i in range(channels_count):
sig = Signal(
np.ones(cycles, dtype=np.uint64) * i,
t,
name="Channel_{}".format(i),
unit="unit_{}".format(i),
conversion=None,
comment="Unsigned int 16bit channel {}".format(i),
raw=True,
)
sigs.append(sig)
mdf.append(sigs, common_timebase=True)
channel conversion for specified version
"""
if version <= 3:
if conversion is None:
conversion = v3b.ChannelConversion(conversion_type=v3c.CONVERSION_TYPE_NONE)
else:
conversion_type = conversion["conversion_type"]
if conversion["id"] == b"CC":
pass
else:
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
)
elif conversion_type == v4c.CONVERSION_TYPE_LIN:
conversion = v3b.ChannelConversion(
unit=unit,
conversion_type=v3c.CONVERSION_TYPE_LINEAR,
a=conversion.a,
b=conversion.b,
)
elif conversion_type == v4c.CONVERSION_TYPE_RAT:
conversion = v3b.ChannelConversion(
unit=unit,
conversion_type=v3c.CONVERSION_TYPE_RAT,
P1=conversion.P1,
for i in range(nr):
(self[f"param_val_{i}"], self[f"text_{i}"]) = (
values[i * 2],
values[2 * i + 1],
)
elif conv_type == v23c.CONVERSION_TYPE_RTABX:
nr = self.ref_param_nr - 1
size = v23c.CC_COMMON_BLOCK_SIZE + (nr + 1) * 20
if block_size == v23c.MAX_UINT16:
stream.seek(address)
raw_bytes = stream.read(size)
conversion = ChannelConversion(
raw_bytes=raw_bytes, stream=stream, address=address
)
conversion.block_len = size
for attr in get_fields(conversion):
setattr(self, attr, getattr(conversion, attr))
self.referenced_blocks = conversion.referenced_blocks
else:
(
self.default_lower,
self.default_upper,
self.default_addr,
) = unpack_from("<2dI", block, v23c.CC_COMMON_SHORT_SIZE)
fields = []
types = []
parents = {}
ch_cntr = 0
offset = 0
field_names = UniqueDB()
if df.shape[0]:
# conversion for time channel
kargs = {
"conversion_type": v23c.CONVERSION_TYPE_NONE,
"unit": b"s",
"min_phy_value": timestamps[0] if cycles_nr else 0,
"max_phy_value": timestamps[-1] if cycles_nr else 0,
}
conversion = ChannelConversion(**kargs)
conversion.unit = "s"
source = ce_block
# time channel
t_type, t_size = fmt_to_datatype_v3(timestamps.dtype, timestamps.shape)
kargs = {
"short_name": time_name.encode("latin-1"),
"channel_type": v23c.CHANNEL_TYPE_MASTER,
"data_type": t_type,
"start_offset": 0,
"min_raw_value": timestamps[0] if cycles_nr else 0,
"max_raw_value": timestamps[-1] if cycles_nr else 0,
"bit_count": t_size,
"block_len": channel_size,
"version": version,
}
if source:
if not isinstance(source, SignalSource):
source = source.to_common_source()
self.source = source
if bit_count is None:
self.bit_count = samples.dtype.itemsize * 8
else:
self.bit_count = bit_count
self.stream_sync = stream_sync
self.invalidation_bits = invalidation_bits
if conversion:
if not isinstance(
conversion, (v4b.ChannelConversion, v3b.ChannelConversion)
):
conversion = from_dict(conversion)
self.conversion = conversion
----------
conversion : block
channel conversion
version : int
target mdf version
Returns
-------
conversion : block
channel conversion for specified version
"""
if version <= 3:
if conversion is None:
conversion = v3b.ChannelConversion(conversion_type=v3c.CONVERSION_TYPE_NONE)
else:
conversion_type = conversion["conversion_type"]
if conversion["id"] == b"CC":
pass
else:
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
)
elif conversion_type == v4c.CONVERSION_TYPE_LIN:
conversion = v3b.ChannelConversion(
unit=unit,
conversion_type=v3c.CONVERSION_TYPE_LINEAR,