def test_sw_detect_multi(self): """Test sw_detect_multi""" data_full = file_full.get('data') sw = sw_detect_multi(data_full, sf_full, chan_full) sw_no_out = sw_detect_multi(data_full, sf_full, chan_full, remove_outliers=True) assert sw_no_out.shape[0] < sw.shape[0] bv = get_bool_vector(data_full, sf_full, sw) assert bv.shape[0] == len(chan_full) # Test with hypnogram sw_detect_multi(data_full, sf_full, chan_full, hypno=hypno_full, include=3) # Now we replace one channel with no slow-wave / bad data data_full[1, :] = np.random.random(data_full.shape[1]) # Test where data.shape[0] != len(chan) with pytest.raises(AssertionError): sw_detect_multi(data_full, sf_full, chan_full[:-1]) # Test with only bad channels data_full[0, :] = np.random.random(data_full.shape[1]) data_full[2, :] = np.random.random(data_full.shape[1]) with self.assertLogs('yasa', level='WARNING'): sp = sw_detect_multi(data_full, sf_full, chan_full) assert sp is None
def test_spindles_detect_multi(self): """Test spindles_detect_multi""" sp = spindles_detect_multi(data_full, sf_full, chan_full) sp_no_out = spindles_detect_multi(data_full, sf_full, chan_full, remove_outliers=True) sp_multi = spindles_detect_multi(data_full, sf_full, chan_full, multi_only=True) assert sp_multi.shape[0] < sp.shape[0] assert sp_no_out.shape[0] < sp.shape[0] bv = get_bool_vector(data_full, sf_full, sp) assert bv.shape[0] == len(chan_full) # Test with hypnogram spindles_detect_multi(data_full, sf_full, chan_full, hypno=hypno_full, include=2) # Now we replace one channel with no spindle / bad data data_full[1, :] = np.random.random(data_full.shape[1]) # Test where data.shape[0] != len(chan) with pytest.raises(AssertionError): spindles_detect_multi(data_full, sf_full, chan_full[:-1]) # Test with only bad channels data_full[0, :] = np.random.random(data_full.shape[1]) data_full[2, :] = np.random.random(data_full.shape[1]) with self.assertLogs('yasa', level='WARNING'): sp = spindles_detect_multi(data_full, sf_full, chan_full) assert sp is None
def test_rem_detect(self): """Test function REM detect """ file_rem = np.load('notebooks/data_EOGs_REM_256Hz.npz') data_rem = file_rem['data'] loc, roc = data_rem[0, :], data_rem[1, :] sf_rem = file_rem['sf'] # chan_rem = file_rem['chan'] hypno_rem = 4 * np.ones_like(loc) # Parameters product testing freq_rem = [(0.5, 5), (0.3, 8)] duration = [(0.3, 1.5), [0.5, 1]] amplitude = [(50, 200), [60, 300]] downsample = [True, False] hypno = [hypno_rem, None] prod_args = product(freq_rem, duration, amplitude, downsample, hypno) for i, (f, dr, am, ds, h) in enumerate(prod_args): rem_detect(loc, roc, sf_rem, hypno=h, freq_rem=f, duration=dr, amplitude=am, downsample=ds) # With isolation forest df_rem = rem_detect(loc, roc, sf) df_rem2 = rem_detect(loc, roc, sf, remove_outliers=True) assert df_rem.shape[0] > df_rem2.shape[0] assert get_bool_vector(loc, sf, df_rem).size == loc.size # With REM hypnogram hypno_rem = 4 * np.ones_like(loc) df_rem = rem_detect(loc, roc, sf_full, hypno=hypno_rem) hypno_rem = np.r_[np.ones(int(loc.size / 2)), 4 * np.ones(int(loc.size / 2))] df_rem2 = rem_detect(loc, roc, sf_full, hypno=hypno_rem) assert df_rem.shape[0] > df_rem2.shape[0] # Test with wrong data amplitude on ROC with self.assertLogs('yasa', level='ERROR'): rd = rem_detect(loc * 1e-8, roc, sf) assert rd is None # Test with wrong data amplitude on LOC with self.assertLogs('yasa', level='ERROR'): rd = rem_detect(loc, roc * 1e8, sf) assert rd is None # Hypnogram with sf = 150 with self.assertLogs('yasa', level='WARNING'): rem_detect(loc, roc * 1e8, sf=150) # Fake sampling frequency # No values in hypno intersect with include with self.assertLogs('yasa', level='ERROR'): sp = rem_detect(loc, roc, sf_full, hypno=hypno_rem, include=5) assert sp is None
def test_get_bool_vector(self): """Test functions get_bool_vector""" # Numpy sp_params = spindles_detect(data, sf) out = get_bool_vector(data, sf, sp_params) assert out.size == data.size assert np.unique(out).size == 2 # MNE # Single channel sp_params = spindles_detect_multi(data_mne_single) out = get_bool_vector(data_mne_single, detection=sp_params) assert out.size == max(data_mne_single.get_data().shape) assert np.unique(out).size == 2 # Multi-channels sp_params = spindles_detect_multi(data_mne) out = get_bool_vector(data_mne, detection=sp_params) assert out.size == data_mne.get_data().size assert np.unique(out).size == 2
def test_get_bool_vector(self): """Test functions get_bool_vector""" sp_params = spindles_detect(data, sf) out = get_bool_vector(data, sf, sp_params) assert out.size == data.size assert np.unique(out).size == 2