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

MSO helpers_wav: force float32 for amplitude.

parent ee62861e
......@@ -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):
......
......@@ -86,16 +86,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