Commit 690dfa66 authored by Florent Jaillet's avatar Florent Jaillet

Replace the _complex_entries_only decorator by the use of a simple method

parent b9f0a0fa
{}
\ No newline at end of file
......@@ -91,16 +91,6 @@ def _merge_masks(ma1, ma2):
return {'mask': np.logical_or(ma1.unknown_mask, ma2.unknown_mask)}
def _complex_masking_only(f):
def decorated(self):
if not self._complex_masking:
errmsg = 'Method not defined if masking is not complex.'
raise ValueError(errmsg)
return f(self)
decorated.__doc__ = f.__doc__
return decorated
UFUNC_NOT_RETURNING_MADARRAYS = ['bitwise_and', 'bitwise_or', 'bitwise_xor',
'invert', 'left_shift', 'right_shift',
'greater', 'greater_equal', 'less',
......@@ -429,7 +419,6 @@ class MadArray(np.ndarray):
return np.copy(self._mask)
@property
@_complex_masking_only
def any_unknown_mask(self):
"""Boolean mask for coefficients with unknown magnitude and/or phase.
......@@ -446,10 +435,10 @@ class MadArray(np.ndarray):
ValueError
If `complex_masking` is False.
"""
self._raise_if_not_complex_masking()
return ~(self._mask == 0)
@property
@_complex_masking_only
def all_unknown_mask(self):
"""Boolean mask for coefficients with both unknown magnitude and phase.
......@@ -466,10 +455,10 @@ class MadArray(np.ndarray):
ValueError
If `complex_masking` is False.
"""
self._raise_if_not_complex_masking()
return self._mask == 3
@property
@_complex_masking_only
def known_phase_mask(self):
"""Boolean mask for coefficients with known phase.
......@@ -485,10 +474,10 @@ class MadArray(np.ndarray):
ValueError
If masking is not complex.
"""
self._raise_if_not_complex_masking()
return ~np.logical_or(self._mask == 1, self._mask == 3)
@property
@_complex_masking_only
def unknown_phase_mask(self):
"""Boolean mask for coefficients with unknown phase.
......@@ -504,10 +493,10 @@ class MadArray(np.ndarray):
ValueError
If masking is not complex.
"""
self._raise_if_not_complex_masking()
return np.logical_or(self._mask == 1, self._mask == 3)
@property
@_complex_masking_only
def known_magnitude_mask(self):
"""Boolean mask for coefficients with known magnitude.
......@@ -523,10 +512,10 @@ class MadArray(np.ndarray):
ValueError
If masking is not complex.
"""
self._raise_if_not_complex_masking()
return ~np.logical_or(self._mask == 2, self._mask == 3)
@property
@_complex_masking_only
def unknown_magnitude_mask(self):
"""Boolean mask for coefficients with unknown magnitude
......@@ -542,10 +531,10 @@ class MadArray(np.ndarray):
ValueError
If masking is not complex.
"""
self._raise_if_not_complex_masking()
return np.logical_or(self._mask == 2, self._mask == 3)
@property
@_complex_masking_only
def unknown_phase_only_mask(self):
"""Boolean mask for coefficients with unknown phase and known magnitude.
......@@ -562,10 +551,10 @@ class MadArray(np.ndarray):
ValueError
If masking is not complex.
"""
self._raise_if_not_complex_masking()
return self._mask == 1
@property
@_complex_masking_only
def unknown_magnitude_only_mask(self):
"""Boolean mask for coefficients with unknown magnitude and known phase.
......@@ -582,6 +571,7 @@ class MadArray(np.ndarray):
ValueError
If masking is not complex.
"""
self._raise_if_not_complex_masking()
return self._mask == 2
@property
......@@ -620,6 +610,11 @@ class MadArray(np.ndarray):
else:
return np.average(self.unknown_mask)
def _raise_if_not_complex_masking(self):
if not self._complex_masking:
errmsg = 'Method not defined if masking is not complex.'
raise ValueError(errmsg)
def is_masked(self):
"""Indicate if one or several elements are masked."""
return np.any(self._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