Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_div(self):
s = Signal(
np.arange(1, 5, dtype="
unit='unit_{}'.format(i),
conversion=cls(**conversion),
comment='Channel {} with rational conversion'.format(i),
raw=True,
)
sigs.append(sig)
mdf.append(sigs, common_timebase=True)
# string
sigs = []
for i in range(channels_count):
sig = [
'Channel {} sample {}'.format(i, j).encode('ascii')
for j in range(cycles)
]
sig = Signal(
np.array(sig),
t,
name='Channel_{}'.format(i),
unit='unit_{}'.format(i),
comment='String channel {}'.format(i),
raw=True,
)
sigs.append(sig)
mdf.append(sigs, common_timebase=True)
# byte array
sigs = []
ones = np.ones(cycles, dtype=np.dtype('(8,)u1'))
for i in range(channels_count):
sig = Signal(
ones*i,
if version <= '3.30':
filename = r'tmpdir/big_test_{}.mdf'.format(version)
else:
filename = r'tmpdir/big_test_{}.mf4'.format(version)
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)
# linear
sigs = []
for i in range(channels_count):
conversion = {
'conversion_type': v4c.CONVERSION_TYPE_LIN if version >= '4.00' else v3c.CONVERSION_TYPE_LINEAR,
def test_read_mdf3_10(self):
seed = np.random.randint(0, 2 ** 31)
np.random.seed(seed)
print("Read 3.10 using seed =", seed)
sig_int = Signal(
np.random.randint(-(2 ** 9), 2 ** 7, CHANNEL_LEN),
np.arange(CHANNEL_LEN),
name="Integer Channel",
unit="unit1",
)
sig_float = Signal(
np.random.random(CHANNEL_LEN),
np.arange(CHANNEL_LEN),
name="Float Channel",
unit="unit2",
)
with MDF(version="3.10") as mdf:
mdf.append([sig_int, sig_float], common_timebase=True)
outfile = mdf.save(Path(TestMDF23.tempdir.name) / "tmp", overwrite=True)
with MDF(outfile) as mdf:
ret_sig_int = mdf.get(sig_int.name)
ret_sig_float = mdf.get(sig_float.name)
self.assertTrue(np.array_equal(ret_sig_int.samples, sig_int.samples))
self.assertTrue(np.array_equal(ret_sig_float.samples, sig_float.samples))
unit='unit_{}'.format(i),
conversion=cls(**conversion),
comment='Signed 16bit channel {} with linear conversion'.format(i),
raw=True,
)
sigs.append(sig)
mdf.append(sigs, common_timebase=True)
# algebraic
sigs = []
for i in range(channels_count):
conversion = {
'conversion_type': v4c.CONVERSION_TYPE_ALG if version >= '4.00' else v3c.CONVERSION_TYPE_FORMULA,
'formula': '{} * sin(X)'.format(i),
}
sig = Signal(
np.arange(cycles, dtype=np.int32) / 100.0,
t,
name='Channel_{}'.format(i),
unit='unit_{}'.format(i),
conversion=cls(**conversion),
comment='Sinus channel {} with algebraic conversion'.format(i),
raw=True,
)
sigs.append(sig)
mdf.append(sigs, common_timebase=True)
# rational
sigs = []
for i in range(channels_count):
conversion = {
'conversion_type': v4c.CONVERSION_TYPE_RAT if version >= '4.00' else v3c.CONVERSION_TYPE_RAT,
def etest_read_mdf2_14(self):
seed = np.random.randint(0, 2 ** 31)
np.random.seed(seed)
print("Read 2.14 using seed =", seed)
sig_int = Signal(
np.random.randint(-2 ** 29, 2 ** 29, CHANNEL_LEN),
np.arange(CHANNEL_LEN),
name="Integer Channel",
unit="unit1",
)
sig_float = Signal(
np.random.random(CHANNEL_LEN),
np.arange(CHANNEL_LEN),
name="Float Channel",
unit="unit2",
)
with MDF(version="2.14") as mdf:
mdf.append([sig_int, sig_float], common_timebase=True)
outfile = mdf.save(Path(TestMDF23.tempdir.name) / "tmp", overwrite=True)
def test_read_mdf2_00(self):
seed = np.random.randint(0, 2 ** 31)
np.random.seed(seed)
print("Read 2.00 using seed =", seed)
sig_int = Signal(
np.random.randint(-(2 ** 15), -1, CHANNEL_LEN),
np.arange(CHANNEL_LEN),
name="Integer Channel",
unit="unit1",
)
sig_float = Signal(
np.random.random(CHANNEL_LEN),
np.arange(CHANNEL_LEN),
name="Float Channel",
unit="unit2",
)
with MDF(version="2.00") as mdf:
mdf.append([sig_int, sig_float], common_timebase=True)
outfile = mdf.save(Path(TestMDF23.tempdir.name) / "tmp", overwrite=True)
with MDF(outfile) as mdf:
ret_sig_int = mdf.get(sig_int.name)
ret_sig_float = mdf.get(sig_float.name)
self.assertTrue(np.array_equal(ret_sig_int.samples, sig_int.samples))
self.assertTrue(np.array_equal(ret_sig_float.samples, sig_float.samples))
l2_arr = np.core.records.fromarrays(l2_arr, dtype=types)
l1_arr = [
l2_arr,
]
types = [
("level11", l2_arr.dtype),
]
l1_arr = np.core.records.fromarrays(l1_arr, dtype=types)
sigs.append(Signal(l1_arr, t, name="Nested_structures",))
mdf.append(sigs, "arrays", common_timebase=True)
mdf.save("demo.mf4", overwrite=True)
name="Uint8_Signal",
unit="u1",
)
# int32 with 50ms time raster
timestamps = np.array([0.05 * t for t in range(10)], dtype=np.float32)
s_int32 = Signal(
samples=np.array(list(range(-500, 500, 100)), dtype=np.int32),
timestamps=timestamps,
name="Int32_Signal",
unit="i4",
)
# float64 with 300ms time raster
timestamps = np.array([0.3 * t for t in range(3)], dtype=np.float32)
s_float64 = Signal(
samples=np.array(list(range(2000, -1000, -1000)), dtype=np.int32),
timestamps=timestamps,
name="Float64_Signal",
unit="f8",
)
# map signals
xs = np.linspace(-1, 1, 50)
ys = np.linspace(-1, 1, 50)
X, Y = np.meshgrid(xs, ys)
vals = np.linspace(0, 180.0 / np.pi, 100)
phi = np.ones((len(vals), 50, 50), dtype=np.float64)
for i, val in enumerate(vals):
phi[i] *= val
R = 1 - np.sqrt(X ** 2 + Y ** 2)
samples = np.cos(2 * np.pi * X + phi) * R
name="Channel_{}".format(i),
unit="unit_{}".format(i),
conversion=cls(**conversion),
comment="Channel {} with rational conversion".format(i),
raw=True,
)
sigs.append(sig)
mdf.append(sigs, common_timebase=True)
# string
sigs = []
for i in range(channels_count):
sig = [
"Channel {} sample {}".format(i, j).encode("ascii") for j in range(cycles)
]
sig = Signal(
np.array(sig),
t,
name="Channel_{}".format(i),
unit="unit_{}".format(i),
comment="String channel {}".format(i),
raw=True,
)
sigs.append(sig)
mdf.append(sigs, common_timebase=True)
# byte array
sigs = []
ones = np.ones(cycles, dtype=np.dtype("(8,)u1"))
for i in range(channels_count):
sig = Signal(
ones * (i % 255),