Exemple #1
0
def RelativePsie(ye, xm):
    Nx = TrackNormal(xm)
    u = 1j * Nx
    rx = u * ye + xm
    Nr = TrackNormal(rx)

    # psie is sort of backwards: higher angles go to the left
    return np.angle(Nx) - np.angle(Nr)
Exemple #2
0
def RelativePsie(ye, xm):
    Nx = TrackNormal(xm)
    u = 1j * Nx
    rx = u*ye + xm
    Nr = TrackNormal(rx)

    # psie is sort of backwards: higher angles go to the left
    return np.angle(Nx) - np.angle(Nr)
    def calculate_Fi_ci_si(self):
        ''' Calculate simple calculation of Fi, ci, si: does not include any CPV effects, not time dependece '''
        bin_num = self.binning.get_number_of_bins()
        Fi = np.array([])
        ci = np.array([])
        si = np.array([])

        A_mag = abs(self.amplitude.get_A(
            0))  # Just make simple calculation in this class
        A_ph = np.angle(self.amplitude.get_A(0))
        A_mag_inv = np.transpose(A_mag)
        A_ph_inv = np.transpose(A_ph)

        avg_eff_over_phsp = self.efficiency.get_time_averaged_eff()
        for i in range(-bin_num, bin_num + 1):
            if i == 0: continue
            bin_idx = self.binning.get_bin_indices(i)
            inv_bin_idx = self.binning.get_bin_indices(-i)
            avg_eff = avg_eff_over_phsp[bin_idx]
            Fi = np.append(Fi, np.sum(avg_eff * A_mag[bin_idx]**2))
            ci = np.append(
                ci,
                np.sum(avg_eff * A_mag[bin_idx] * A_mag_inv[bin_idx] *
                       np.cos(A_ph[bin_idx] - A_ph_inv[bin_idx])))
            si = np.append(
                si,
                np.sum(avg_eff * A_mag[bin_idx] * A_mag_inv[bin_idx] *
                       np.sin(A_ph[bin_idx] - A_ph_inv[bin_idx])))

        Fi_inv = np.flip(Fi, 0)
        ci = ci / np.sqrt(Fi * np.flip(Fi, 0))
        si = si / np.sqrt(Fi * np.flip(Fi, 0))
        Fi = Fi / sum(Fi)

        return Fi, ci, si
Exemple #4
0
def optimal_rotation_new(Y, p):
    """Choose the correct representative from each equivalence class.

    Parameters
    ----------
    Y : ndarray (d*n)
        Data, with one COLUMN for each of the n data points in
        d-dimensional space.
    w : ndarray (d*d)
        Rotation matrix for p-th root of unity.
    p : int
        Order of cyclic group.

    Returns
    -------
    S : ndarray (n*n)
        Correct power of w to use for each inner product. Satisfies
            S + S.T = 0 (mod p)

    """

    # (I'm not convinced this method is actually better, algorithmically.)
    # Convert Y to complex form:
    Ycplx = Y[0::2] + 1j * Y[1::2]
    cplx_ip = Ycplx.T @ Ycplx.conjugate()
    ip_angles = np.angle(cplx_ip)
    ip_angles[ip_angles < 0] += 2 * np.pi  #np.angles uses range -pi,pi
    root_angles = np.linspace(0, 2 * np.pi, p + 1)
    S = np.zeros(ip_angles.shape)
    for i in range(ip_angles.shape[0]):
        for j in range(ip_angles.shape[1]):
            S[i, j] = np.argmin(np.abs(ip_angles[i, j] - root_angles))
    S[S == p] = 0
    S = S.T  # Want the angle to act on the second component.
    return S
Exemple #5
0
def plotfiltphase(x):
    f = np.arange(1, 256)
    w = 2 * np.pi * f / 670.0
    z = np.exp(1j * w)
    h = FilterResponse(z, x)
    h = h * (h[1] / np.abs(h[1]))**(np.arange(len(h)) - 2)
    phase = np.angle(h[1:] / h[:-1])
    plt.plot(np.log(f[:-1]) / np.log(2), phase)
plt.figure()
for order in [1, 2, 3, 4, 5, 6, 9]:
    b, a = butter_bandpass(8., 12., fs, order=order)
    w, h = signal.freqz(b, a, worN=2000)
    plt.plot((fs * 0.5 / np.pi) * w[:200],
             abs(h[:200]),
             label="order = %d" % order)
plt.xlabel('Frequency (Hz)')
plt.ylabel('Gain')
plt.grid(True)
plt.legend(loc='best')

b, a = butter_bandpass(8., 12., fs=1000., order=3)

csd_fast_filt = signal.filtfilt(b, a, gpcsd_model.csd_pred_list[1], axis=1)
csd_fast_phase = np.angle(signal.hilbert(csd_fast_filt, axis=1), deg=False)
lfp_fast_filt = signal.filtfilt(b, a, gpcsd_model.lfp_pred_list[1], axis=1)
lfp_fast_phase = np.angle(signal.hilbert(lfp_fast_filt, axis=1), deg=False)

# %% compute within-probe PLV matrix over time
plv_csd = np.nan * np.zeros((24, 24, gpcsd_model.t_pred.shape[0]))
plv_lfp = np.nan * np.zeros((24, 24, gpcsd_model.t_pred.shape[0]))
for ci in range(24):
    for cj in range(ci, 24):
        if ci == cj:
            continue
        res_csd = plv(
            np.squeeze(csd_fast_phase[ci, :, :]).T,
            np.squeeze(csd_fast_phase[cj, :, :]).T)
        plv_csd[ci, cj, :] = res_csd
        plv_csd[cj, ci, :] = res_csd
Exemple #7
0
def test_angle_complex():
    fun = lambda x : np.angle(x)
    d_fun = lambda x: grad(fun)(x)
    check_grads(fun)(npr.rand() + 1j*npr.rand())
    check_grads(d_fun)(npr.rand() + 1j*npr.rand())
Exemple #8
0
def test_angle_real():
    fun = lambda x : np.angle(x)
    d_fun = lambda x: grad(fun)(x)
    check_grads(fun)(npr.rand())
    check_grads(d_fun)(npr.rand())
def test_angle_complex():
    fun = lambda x : to_scalar(np.angle(x))
    d_fun = lambda x: to_scalar(grad(fun)(x))
    check_grads(fun, npr.rand() + 1j*npr.rand())
    check_grads(d_fun, npr.rand() + 1j*npr.rand())
Exemple #10
0
def test_angle_complex():
    fun = lambda x: np.angle(x)
    d_fun = lambda x: grad(fun)(x)
    check_grads(fun)(npr.rand() + 1j * npr.rand())
    check_grads(d_fun)(npr.rand() + 1j * npr.rand())
Exemple #11
0
def test_angle_real():
    fun = lambda x: np.angle(x)
    d_fun = lambda x: grad(fun)(x)
    check_grads(fun)(npr.rand())
    check_grads(d_fun)(npr.rand())
Exemple #12
0
def plot303phase(n):
    f = np.arange(1, 300)
    y = np.fft.rfft(-Y[int(n * 670) - 100:int((n + 1) * 670) - 100])
    # y = y * (y[1] / np.abs(y[1]))**(np.arange(len(y)) - 2)
    phase = np.angle(y[1:] / y[:-1])
    plt.plot(np.log(f) / np.log(2), phase[f - 1])
Exemple #13
0
    b, a = signal.butter(order, [low, high], btype='band')
    return b, a


fs = 2500
bands = {'theta': [3., 7.], 'beta': [20., 24.]}
for probe, probe_name in zip(['probeC', 'probeD'], ['V1', 'LM']):
    phases = {}
    for bk in bands.keys():
        ord, wn = signal.buttord([bands[bk][0], bands[bk][1]],
                                 [bands[bk][0] - 2, bands[bk][1] + 2],
                                 10,
                                 20,
                                 fs=fs)
        sos = signal.butter(1, [bands[bk][0], bands[bk][1]],
                            btype='bandpass',
                            fs=fs,
                            output='sos')
        res = signal.sosfiltfilt(sos, csdMatern[probe] + csdSE[probe], axis=1)
        phase_tmp = np.angle(signal.hilbert(res, axis=1), deg=False)
        # TODO get time index of interest
        ti = np.array([
            np.argmin(np.abs(t.squeeze() - 0.0)),
            np.argmin(np.abs(t.squeeze() - 70.0))
        ])
        phases[bk] = phase_tmp[:, ti, :]
    scipy.io.savemat(
        '%s/results/neuropixel_csd_%s_phases.mat' % (root_path, probe_name),
        phases)
# %%
Exemple #14
0
def real_imag_to_mag_phase(realpart, imagpart):

    a = realpart + 1j * imagpart
    return np.abs(a), np.angle(a)
def test_angle_real():
    fun = lambda x: to_scalar(np.angle(x))
    d_fun = lambda x: to_scalar(grad(fun)(x))
    check_grads(fun, npr.rand())
    check_grads(d_fun, npr.rand())
def test_angle_complex():
    fun = lambda x: to_scalar(np.angle(x))
    d_fun = lambda x: to_scalar(grad(fun)(x))
    check_grads(fun, npr.rand() + 1j * npr.rand())
    check_grads(d_fun, npr.rand() + 1j * npr.rand())
def test_angle_real():
    fun = lambda x : to_scalar(np.angle(x))
    d_fun = lambda x: to_scalar(grad(fun)(x))
    check_grads(fun, npr.rand())
    check_grads(d_fun, npr.rand())