def test_freq_mask(): """Test safe frequency masking.""" N = 10 x = np.arange(N).astype(float) assert _freq_mask(x, 1000., fmin=0, fmax=N - 1).sum() == N assert _freq_mask(x - 1e-10, 1000., fmin=0, fmax=N - 1).sum() == N assert _freq_mask(x - 1e-10, 1000., fmin=None, fmax=N - 1).sum() == N assert _freq_mask(x - 1e-10, 1000., fmin=None, fmax=None).sum() == N assert _freq_mask(x - 1e-10, 1000., fmin=-np.inf, fmax=None).sum() == N assert _freq_mask(x - 1e-10, 1000., fmin=None, fmax=np.inf).sum() == N # non-uniformly spaced inputs x = np.array([4, 10]) assert _freq_mask(x[:1], 1, fmin=10, raise_error=False).sum() == 0 assert _freq_mask(x[:1], 1, fmin=11, fmax=12, raise_error=False).sum() == 0 assert _freq_mask(x, sfreq=1, fmin=10).sum() == 1 assert _freq_mask(x, sfreq=1, fmin=6).sum() == 1 assert _freq_mask(x, sfreq=1, fmin=5).sum() == 1 assert _freq_mask(x, sfreq=1, fmin=4.5001).sum() == 1 assert _freq_mask(x, sfreq=1, fmin=4.4999).sum() == 2 assert _freq_mask(x, sfreq=1, fmin=4).sum() == 2 # degenerate cases with pytest.raises(ValueError, match='sfreq can not be None'): _freq_mask(x[:1], sfreq=None, fmin=3, fmax=5) with pytest.raises(ValueError, match='No frequencies remain'): _freq_mask(x[:1], sfreq=1, fmin=11, fmax=12) with pytest.raises(ValueError, match='must be less than or equal to fmax'): _freq_mask(x[:1], sfreq=1, fmin=10)