Commit cc3eb783 authored by Florent Jaillet's avatar Florent Jaillet

Force boolean masking for Waveform in pyteuf

parent 9a12c5b4
Pipeline #602 passed with stage
in 20 seconds
......@@ -45,8 +45,6 @@
.. moduleauthor:: Valentin Emiya
.. moduleauthor:: Florent Jaillet
"""
import warnings
import numpy as np
......
......@@ -217,6 +217,22 @@ class TestWaveform:
w = Waveform(self.x_mono, mask=self.m_mono, fs=self.fs)
w2 = Waveform(w)
assert w2.fs == self.fs
np.testing.assert_array_equal(w._mask, w2._mask)
def test_init_from_madarray(self):
w = MadArray(self.x_mono, mask=self.m_mono)
w2 = Waveform(w)
np.testing.assert_array_equal(w2._mask, w._mask)
w = MadArray(self.x_mono, mask_magnitude=self.m_mono)
match = ('Construction of a Waveform from a MadArray with '
'complex masking: the original masking data are '
'discarded and a boolean mask set to False is used.')
with pytest.warns(UserWarning, match=match):
w2 = Waveform(w)
np.testing.assert_array_equal(
w2._mask, np.zeros_like(w2, dtype=np.bool))
def test_resample(self):
......
......@@ -153,6 +153,15 @@ class Waveform(MadArray):
# create the MadArray
data = data.squeeze()
if isinstance(data, MadArray) and data._complex_masking \
and mask is None :
warnmsg = ('Construction of a Waveform from a MadArray with '
'complex masking: the original masking data are '
'discarded and a boolean mask set to False is used.')
warnings.warn(warnmsg)
# Create mask to force boolean masking
mask = np.zeros_like(data, dtype=np.bool)
obj = MadArray.__new__(cls=cls, data=data, mask=mask,
masked_indexing=masked_indexing)
......@@ -310,7 +319,7 @@ class Waveform(MadArray):
self._fs = fs
self._mask = np.zeros_like(self, dtype=np.bool)
def plot(self, x_axis_label='Time (s)', y_axis_label='s(t)',
def plot(self, x_axis_label='Time (s)', y_axis_label='',
cpx_mode='real', fill_value=0, **kwargs):
"""Plot the signal.
......@@ -366,7 +375,7 @@ class Waveform(MadArray):
def plot_mask(self,
x_axis_label='Time (s)',
y_axis_label='Missing',
y_axis_label='',
**kwargs):
"""Plot the mask.
......
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