def test_phase_amplitude_coupling_simulation(): both, lo_none, hi_none = simulate_pac_signal(time, f_phase, f_amp, mag_ph, mag_am, frac_pac=1., **kws_sim) # Shapes are correct assert both.shape == lo_none.shape == hi_none.shape assert time.shape[-1] == both.shape[-1] # Fracs outside of 0 to 1 pytest.raises(ValueError, simulate_pac_signal, time, f_phase, f_amp, mag_ph, mag_am, frac_pac=-.5, **kws_sim) pytest.raises(ValueError, simulate_pac_signal, time, f_phase, f_amp, mag_ph, mag_am, frac_pac=1.5, **kws_sim) # Giving a band for frequencies pytest.raises(ValueError, simulate_pac_signal, time, [1, 2], f_amp, mag_ph, mag_am, frac_pac=-.5, **kws_sim)
def test_phase_amplitude_coupling_simulation(): both, lo_none, hi_none = simulate_pac_signal(time, f_phase, f_amp, mag_ph, mag_am, frac_pac=1., **kws_sim) # Shapes are correct assert_equal(both.shape, lo_none.shape, hi_none.shape) assert_equal(time.shape[-1], both.shape[-1]) # Fracs outside of 0 to 1 assert_raises(ValueError, simulate_pac_signal, time, f_phase, f_amp, mag_ph, mag_am, frac_pac=-.5, **kws_sim) assert_raises(ValueError, simulate_pac_signal, time, f_phase, f_amp, mag_ph, mag_am, frac_pac=1.5, **kws_sim) # Giving a band for frequencies assert_raises(ValueError, simulate_pac_signal, time, [1, 2], f_amp, mag_ph, mag_am, frac_pac=-.5, **kws_sim)
mag_am = 1 # These are the times where PAC is active in our simulated signal n_secs = 20. time = np.arange(0, n_secs, 1. / sfreq) event_times = np.arange(1, 18, 4) events = (event_times * sfreq).astype(int) event_dur = 2. # Create a time mask that defines when PAC is active msk_pac_times = np.zeros_like(time).astype(bool) for i_time in event_times: msk_pac_times += mne.utils._time_mask(time, i_time, i_time + event_dur) kws_sim = dict(mask_pac_times=msk_pac_times, snr_lo=10, snr_hi=10) _, lo_pac, hi_pac = simulate_pac_signal(time, f_phase, f_amp, mag_ph, mag_am, frac_pac=frac_pac, **kws_sim) _, lo_none, hi_none = simulate_pac_signal(time, f_phase, f_amp, mag_ph, mag_am, frac_pac=0, **kws_sim) signal_a = lo_pac + hi_none signal_b = lo_none + hi_pac info = mne.create_info(['pac_hi', 'pac_lo'], sfreq, 'eeg') raw = mne.io.RawArray([signal_a, signal_b], info) events = np.vstack([events, np.zeros_like(events), np.ones_like(events)]).T epochs = mne.Epochs(raw, events, tmin=eptmin, tmax=eptmax, baseline=None) def test_phase_amplitude_coupling(): """ Test phase amplitude coupling."""
# These are the times where PAC is active in our simulated signal n_secs = 20. time = np.arange(0, n_secs, 1. / sfreq) event_times = np.arange(1, 18, 4) event_dur = 2. # Create a time mask that defines when PAC is active msk_pac_times = np.zeros_like(time).astype(bool) for i_time in event_times: msk_pac_times += mne.utils._time_mask(time, i_time, i_time + event_dur) # Now simulate two signals. First, a low-frequency phase # that modulates high-frequency amplitude _, lo_pac, hi_pac = simulate_pac_signal(time, f_phase, f_amp, mag_ph, mag_am, frac_pac=frac_pac, mask_pac_times=msk_pac_times) # Now two signals with no relationship between them _, lo_none, hi_none = simulate_pac_signal(time, f_phase, f_amp, mag_ph, mag_am, frac_pac=0, mask_pac_times=msk_pac_times) # Finally we'll mix them up. # The low-frequency phase of signal A... signal_a = lo_pac + hi_none # Modulates the high-frequency amplitude of signal B. But not the reverse. signal_b = lo_none + hi_pac # To standardize the scales of each PAC metric