def __init__(self, x, sf, f_pha=[2, 4], dcomplex='hilbert', cycle=3, width=7, edges=None, n_jobs=-1): """Init.""" _PacObj.__init__(self, f_pha=f_pha, f_amp=[60, 80], dcomplex=dcomplex, cycle=(cycle, 6), width=width) # check x = np.atleast_2d(x) assert x.ndim <= 2, ("`x` input should be an array of shape " "(n_epochs, n_times)") self._n_trials = x.shape[0] # extract phase and amplitude kw = dict(keepfilt=False, edges=edges, n_jobs=n_jobs) pha = self.filter(sf, x, 'phase', **kw) # compute plv self._plv = np.abs(np.exp(1j * pha).mean(1)).squeeze() self._sf = sf
def __init__(self, x, sf, f_pha=[2, 4], dcomplex='hilbert', cycle=3, width=7, edges=None, n_jobs=-1, verbose=None): """Init.""" set_log_level(verbose) _PacObj.__init__(self, f_pha=f_pha, f_amp=[60, 80], dcomplex=dcomplex, cycle=(cycle, 6), width=width) _PacVisual.__init__(self) # check x = np.atleast_2d(x) assert x.ndim <= 2, ("`x` input should be an array of shape " "(n_epochs, n_times)") self._n_trials = x.shape[0] logger.info("Inter-Trials Coherence (ITC)") logger.info(f" extracting {len(self.xvec)} phases") # extract phase and amplitude kw = dict(keepfilt=False, edges=edges, n_jobs=n_jobs) pha = self.filter(sf, x, 'phase', **kw) # compute itc self._itc = np.abs(np.exp(1j * pha).mean(1)).squeeze() self._sf = sf
def __init__(self, x, sf, f_pha=[2, 4], f_amp=[60, 80], n_bins=18, dcomplex='hilbert', cycle=(3, 6), width=7, edges=None, n_jobs=-1): """Init.""" _PacObj.__init__(self, f_pha=f_pha, f_amp=f_amp, dcomplex=dcomplex, cycle=cycle, width=width) # check x = np.atleast_2d(x) assert x.ndim <= 2, ("`x` input should be an array of shape " "(n_epochs, n_times)") assert isinstance(sf, (int, float)), ("`sf` input should be a integer " "or a float") assert all([isinstance(k, (int, float)) for k in f_pha]), ( "`f_pha` input should be a list of two integers / floats") assert all([isinstance(k, (int, float)) for k in f_amp]), ( "`f_amp` input should be a list of two integers / floats") assert isinstance(n_bins, int), "`n_bins` should be an integer" logger.info(f"Binning {f_amp}Hz amplitude according to {f_pha}Hz " "phase") # extract phase and amplitude kw = dict(keepfilt=False, edges=edges, n_jobs=n_jobs) pha = self.filter(sf, x, 'phase', **kw) amp = self.filter(sf, x, 'amplitude', **kw) # binarize amplitude according to phase self._amplitude = _kl_hr(pha, amp, n_bins, mean_bins=False).squeeze() self.n_bins = n_bins
def __init__(self, x, sf, cue, times=None, f_pha=[5, 7], f_amp='hres', cycle=(3, 6), n_jobs=-1, verbose=None): """Init.""" set_log_level(verbose) # initialize to retrieve filtering methods _PacObj.__init__(self, f_pha=f_pha, f_amp=f_amp, dcomplex='hilbert', cycle=cycle) _PacVisual.__init__(self) logger.info("PeakLockedTF object defined") # inputs checking x = np.atleast_2d(x) assert isinstance(x, np.ndarray) and (x.ndim == 2) assert isinstance(sf, (int, float)) assert isinstance(cue, (int, float)) assert isinstance(f_pha, (list, tuple)) and (len(f_pha) == 2) n_epochs, n_times = x.shape # manage cur conversion if times is None: cue = int(cue) times = np.arange(n_times) logger.info(f" align on sample cue={cue}") else: assert isinstance(times, np.ndarray) and (len(times) == n_times) cue_time = cue cue = np.abs(times - cue).argmin() - 1 logger.info(f" align on time-point={cue_time} (sample={cue})") self.cue, self._times = cue, times # extract phase and amplitudes logger.info(f" extract phase and amplitudes " f"(n_amps={len(self.yvec)})") kw = dict(keepfilt=False, n_jobs=n_jobs) pha = self.filter(sf, x, 'phase', n_jobs=n_jobs, keepfilt=True) amp = self.filter(sf, x, 'amplitude', n_jobs=n_jobs) self._pha, self._amp = pha, amp**2 # peak detection logger.info(f" running peak detection around sample={cue}") self.shifts = self._peak_detection(self._pha.squeeze(), cue) # realign phases and amplitudes logger.info(f" realign the {n_epochs} phases and amplitudes") self.amp_a = self._shift_signals(self._amp, self.shifts, fill_with=0.) self.pha_a = self._shift_signals(self._pha, self.shifts, fill_with=0.)