Commit f9d0e707 authored by Antoine Laudrain's avatar Antoine Laudrain
Browse files

Merge branch 'reduce_data_size' into 'master'

MSO: Reduce data size

See merge request !26
parents 8690b5da d5c2a589
Pipeline #140126 passed with stages
in 3 minutes and 41 seconds
......@@ -108,7 +108,7 @@ def get_time_points(npoints, xinc, xorigin):
@param[in] yinc: float, gain of scope (mV/ADC).
@param[in] yorigin: float, offset of y axis.
"""
return np.arange(npoints) * xinc + xorigin
return np.arange(npoints, dtype=np.float32) * xinc + xorigin
def process_waveform(waveform, yinc, yorigin, bytes_per_point):
......@@ -126,7 +126,12 @@ def process_waveform(waveform, yinc, yorigin, bytes_per_point):
# Switch dtype to read based on byteness ('h' or 'b'). SIGNED!!!
dtype = np.int16 if bytes_per_point == 2 else np.int8
logger.debug("bytes per point: %d => dtype: %s", bytes_per_point, dtype)
return np.frombuffer(waveform, dtype=dtype) * yinc + yorigin
# The oscilloscope precision is 10 bits, so it doesn't make sense to use
# float64 (52-bit mantissa): a float32 is enough (23-bit mantissa).
# /!\ Do not use float16: mantissa is only 8 bits. /!\
# Casting the multiplicand to float32 forces the computation (and result)
# to happen with float32 (otherwise float64 is used).
return np.frombuffer(waveform, dtype=dtype) * np.float32(yinc) + yorigin
def process_sequence(sequence, points_per_wf, yinc, yorigin, bytes_per_point=2):
......
......@@ -57,6 +57,13 @@ class TestGetTimePoints(ut.TestCase):
expected = np.array([-45, -35, -25, -15, -5, 5, 15, 25, 35, 45])
np.testing.assert_equal(get_time_points(10, xinc=10, xorigin=-45), expected)
def test_dtype(self):
"""Time points array should be float32."""
result = get_time_points(10,
xinc=float("2.00000000E-10"),
xorigin=float("-4.00192886930E-07"))
self.assertIs(result.dtype, np.dtype(np.float32))
class TestProcessWaveform(ut.TestCase):
"""Test cases for process_waveform."""
......@@ -86,16 +93,26 @@ class TestProcessWaveform(ut.TestCase):
"""Scaling and shifting correct."""
waveform = b'H\xd1T\xd1\\\xd1d\xd1l\xd1x\xd1\x80\xd1\x84\xd1\x8c\xd1\x94\xd1'
expected = np.array([
-1.9829920e-03, -1.6666696e-03, -1.4557880e-03, -1.2449064e-03, -1.0340248e-03,
-7.1770240e-04, -5.0682080e-04, -4.0138000e-04, -1.9049840e-04, 2.0383200e-05])
-1.9829869e-03, -1.6666651e-03, -1.4557838e-03, -1.2449026e-03, -1.0340214e-03,
-7.1769953e-04, -5.0681829e-04, -4.0137768e-04, -1.9049644e-04, 2.0384789e-05])
np.testing.assert_allclose(
process_waveform(waveform,
yinc=2.63602e-05,
yorigin=0.313285,
yinc=float("2.63602e-05"),
yorigin=float("0.313285"),
bytes_per_point=2),
expected
expected,
rtol=1e-6
)
def test_dtype(self):
"""dtype should be float32."""
waveform = b'H\xd1T\xd1\\\xd1d\xd1l\xd1x\xd1\x80\xd1\x84\xd1\x8c\xd1\x94\xd1'
result = process_waveform(waveform,
yinc=float("2.63602e-05"),
yorigin=float("0.313285"),
bytes_per_point=2)
self.assertIs(result.dtype, np.dtype(np.float32))
class TestProcessSequence(ut.TestCase):
"""Test cases for process_sequence."""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment