Commit 6bf4f258 authored by Florent Jaillet's avatar Florent Jaillet

Remove the complex_masking parameter in the contructor of MadArray

parent 2cde666e
Pipeline #588 passed with stage
in 53 seconds
......@@ -71,7 +71,7 @@
"The masking of data differs according to the type of entries:\n",
"\n",
"* if the data entries are not *complex* (e.g., *int* or *float*), argument `mask` must be exclusively a boolean array with the same shape as the data array, each entry indicating if the corresponding entry in the data array is missing or not;\n",
"* if the data entries are *complex*, the masking can be done as previously, or by setting argument `complex_masking` to `true` and by giving two boolean arrays `mask_magnitude` and `mask_phase` with the same size with the same shape as the data array, each entry indicating respectively if the magnitude and the phase of the corresponding entry is missing or not."
"* if the data entries are *complex*, the masking can be done as previously, or by giving two boolean arrays `mask_magnitude` and `mask_phase` with the same size with the same shape as the data array, each entry indicating respectively if the magnitude and the phase of the corresponding entry is missing or not."
]
},
{
......@@ -181,7 +181,7 @@
"mask_mag = np.random.random(data.shape) < 0.5\n",
"mask_pha = np.random.random(data.shape) < 0.5\n",
"A_cpx1 = MadArray(complex_data, mask)\n",
"A_cpx2 = MadArray(complex_data, mask_magnitude=mask_mag, mask_phase=mask_pha, complex_masking=True)\n",
"A_cpx2 = MadArray(complex_data, mask_magnitude=mask_mag, mask_phase=mask_pha)\n",
"print('{} - {}'.format(str(A_cpx1), repr(A_cpx1)))\n",
"print('{} - {}'.format(str(A_cpx2), repr(A_cpx2)))\n",
"print('Magnitude mask', mask_mag)\n",
......
......@@ -114,10 +114,14 @@ class MadArray(np.ndarray):
**Masking**: the masking of entries has two different modes:
* entries can be either masked or not masked, leading to a boolean mask,
* Entries can be either masked or not masked, leading to a boolean mask,
whose entries are equal to True if the corresponding data entry is
masked, or False otherwise. This is the default mode;
* complex entries can have only the magnitude or phase component masked, or
masked, or False otherwise.
This is the default mode and the mode selected when specifying
:paramref:`mask` during creation.
* Complex entries can have only the magnitude or phase component masked, or
both. The resulting mask has integers entries, equal to:
* *0* if the phase and the magnitude are not masked (known magnitude
......@@ -127,10 +131,13 @@ class MadArray(np.ndarray):
* *3* if the magnitude and the phase are masked (unknown magnitude and
phase).
This mode is selected by setting :paramref:`complex_masking` to `True`.
Entries are converted to a complex type. If entries are complex values
and paramref:`complex_masking` is `False`, both the magnitude and
phase are masked.
This mode is selected when specifying :paramref:`mask_magnitude` and/or
:paramref:`mask_phase` during creation.
Entries are converted to a complex type.
If entries are complex values and :paramref:`mask` is given during
creation, both the magnitude and phase are masked and the boolean mask
mode is used.
.. _indexing_madarray:
......@@ -156,18 +163,15 @@ class MadArray(np.ndarray):
Parameters
----------
data : array_like
One-dimensional array. See :ref:`Type of Entry<type_entry_madarray>`.
Multidimensional array. See :ref:`Type of Entry<type_entry_madarray>`.
mask : boolean array_like, optional
Mask if type of entry is int or float. See
Mask for boolean masking mode. See
:ref:`Masking<masking_madarray>`.
mask_magnitude : boolean array_like or None, optional
Magnitude mask if type of entry is complex. See
Magnitude mask for masking with complex data. See
:ref:`Masking<masking_madarray>`.
mask_phase : boolean or array_like or None, optional
Phase mask if type of entry is complex. See
:ref:`Masking<masking_madarray>`.
complex_masking : bool or None, optional
Indicate how the masking is performed. If None, set to False. See
Phase mask for masking with complex data. See
:ref:`Masking<masking_madarray>`.
masked_indexing : bool or None, optional
Indicate how the indexing is performed. If None, set to False. See
......@@ -192,21 +196,18 @@ class MadArray(np.ndarray):
needed.
"""
def __new__(cls, data, mask=None, mask_magnitude=None, mask_phase=None,
masked_indexing=None, complex_masking=None, **kwargs):
masked_indexing=None, **kwargs):
_data = np.array(data, **kwargs)
if mask is not None and mask_magnitude is not None:
errmsg = ('Parameters mask and mask_magnitude are mutually '
'exclusive')
raise ValueError(errmsg)
if complex_masking is None:
if isinstance(data, MadArray):
complex_masking = data._complex_masking
else:
complex_masking = False
if mask is not None and mask_phase is not None:
errmsg = 'Parameters mask and mask_phase are mutually exclusive'
raise ValueError(errmsg)
if masked_indexing is None:
if isinstance(data, MadArray):
masked_indexing = data._masked_indexing
else:
masked_indexing = False
_data = np.array(data, **kwargs)
if not (np.issubdtype(_data.dtype, np.floating) or
np.issubdtype(_data.dtype, np.integer) or
......@@ -214,15 +215,22 @@ class MadArray(np.ndarray):
errmsg = 'Invalid dtype: {}'
raise TypeError(errmsg.format(data.dtype))
if not complex_masking:
if mask is not None:
complex_masking = False
elif mask_magnitude is not None or mask_phase is not None:
complex_masking = True
elif isinstance(data, MadArray):
complex_masking = data._complex_masking
else:
complex_masking = False
if mask_magnitude is not None:
warnmsg = 'Argument `mask_magnitude` is ignored.'
warnings.warn(warnmsg)
if masked_indexing is None:
if isinstance(data, MadArray):
masked_indexing = data._masked_indexing
else:
masked_indexing = False
if mask_phase is not None:
warnmsg = 'Argument `mask_phase` is ignored.'
warnings.warn(warnmsg)
if not complex_masking:
if mask is None:
if isinstance(data, MadArray):
......@@ -241,12 +249,7 @@ class MadArray(np.ndarray):
if not np.issubdtype(_data.dtype, np.complexfloating):
_data = _data.astype(np.complex)
if mask is not None:
warnmsg = 'Argument `mask` is ignored.'
warnings.warn(warnmsg)
if mask_magnitude is None:
if isinstance(data, MadArray):
if data._complex_masking:
mask_magnitude = data.unknown_magnitude_mask
......@@ -255,6 +258,7 @@ class MadArray(np.ndarray):
else:
mask_magnitude = np.zeros_like(data, dtype=np.bool)
else:
mask_magnitude = np.array(mask_magnitude, dtype=np.bool)
if mask_magnitude.shape != _data.shape:
errmsg = 'Magnitude mask shape {} and data shape {} not '\
'compatible.'
......@@ -262,7 +266,6 @@ class MadArray(np.ndarray):
_data.shape))
if mask_phase is None:
if isinstance(data, MadArray):
if data._complex_masking:
mask_phase = data.unknown_phase_mask
......@@ -270,7 +273,9 @@ class MadArray(np.ndarray):
mask_phase = data.unknown_mask
else:
mask_phase = np.zeros_like(data, dtype=np.bool)
else:
mask_phase = np.array(mask_phase, dtype=np.bool)
if mask_phase.shape != _data.shape:
errmsg = 'Phase mask shape {} and data shape {} not '\
'compatible.'
......@@ -426,7 +431,7 @@ class MadArray(np.ndarray):
Raises
------
ValueError
If `complex_masking` is False.
If masking is not complex.
"""
self._raise_if_not_complex_masking()
return ~(self._mask == 0)
......@@ -444,7 +449,7 @@ class MadArray(np.ndarray):
Raises
------
ValueError
If `complex_masking` is False.
If masking is not complex.
"""
self._raise_if_not_complex_masking()
return self._mask == 3
......
This diff is collapsed.
......@@ -154,8 +154,7 @@ class Waveform(MadArray):
# create the MadArray
data = data.squeeze()
obj = MadArray.__new__(cls=cls, data=data, mask=mask,
masked_indexing=masked_indexing,
complex_masking=False)
masked_indexing=masked_indexing)
if obj.ndim > 2 or obj.ndim == 2 and obj.shape[1] > 2:
raise ValueError('`data` should be either mono or stereo.')
......
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