Example #1
0
    def test_MEG_03(self):
        '''test LFPy.MEG.calculate_H()'''
        current_dipole_moment = np.zeros((1, 3))
        current_dipole_moment[:, 0] += 1.
        dipole_location = np.zeros(3)
        sensor_locations = np.r_[np.eye(3), -np.eye(3)]

        gt = np.zeros(
            (sensor_locations.shape[0], current_dipole_moment.shape[0], 3))
        gt[1, :, 2] = 1. / 4 / np.pi
        gt[2, :, 1] = -1. / 4 / np.pi
        gt[4, :, 2] = -1. / 4 / np.pi
        gt[5, :, 1] = 1. / 4 / np.pi

        meg = LFPy.MEG(sensor_locations)
        np.testing.assert_equal(
            gt, meg.calculate_H(current_dipole_moment, dipole_location))
Example #2
0
    def test_MEG_03(self):
        '''test eegmegcalc.MEG.calculate_H()'''
        current_dipole_moment = np.zeros((3, 1))
        current_dipole_moment[0, :] += 1.
        dipole_location = np.zeros(3)
        sensor_locations = np.r_[np.eye(3), -np.eye(3)]

        gt = np.zeros(
            (sensor_locations.shape[0], 3, current_dipole_moment.shape[1]))
        gt[1, 2, :] = 1. / 4 / np.pi
        gt[2, 1, :] = -1. / 4 / np.pi
        gt[4, 2, :] = -1. / 4 / np.pi
        gt[5, 1, :] = 1. / 4 / np.pi

        meg = LFPy.MEG(sensor_locations)
        np.testing.assert_equal(
            gt, meg.calculate_H(current_dipole_moment, dipole_location))
Example #3
0
    def test_MEG_06(self):
        '''test eegmegcalc.MEG.get_transformation_matrix()'''
        current_dipole_moment = np.c_[np.eye(3), -np.eye(3)]

        dipole_location = np.zeros(3)
        sensor_locations = np.r_[np.eye(3), -np.eye(3)]

        gt = np.array([[[0., 0., 0., 0., 0., 0.], [0., 0., 1., 0., 0., -1.],
                        [0., -1., 0., 0., 1., 0.]],
                       [[0., 0., -1., 0., 0., 1.], [0., 0., 0., 0., 0., 0.],
                        [1., 0., 0., -1., 0., 0.]],
                       [[0., 1., 0., 0., -1., 0.], [-1., 0., 0., 1., 0., 0.],
                        [0., 0., 0., 0., 0., 0.]],
                       [[0., 0., 0., 0., 0., 0.], [0., 0., -1., 0., 0., 1.],
                        [0., 1., 0., 0., -1., 0.]],
                       [[0., 0., 1., 0., 0., -1.], [0., 0., 0., 0., 0., 0.],
                        [-1., 0., 0., 1., 0., 0.]],
                       [[0., -1., 0., 0., 1., 0.], [1., 0., 0., -1., 0., 0.],
                        [0., 0., 0., 0., 0., 0.]]]) / 4 / np.pi

        meg = LFPy.MEG(sensor_locations)
        M = meg.get_transformation_matrix(dipole_location)

        np.testing.assert_equal(gt, M @ current_dipole_moment)
Example #4
0
# compute the radial unit vector from the center of the sphere to each
# measurement point, then unit vectors along theta and phi
r_hat = (sphere.rxyz.T / sphere.r).T
theta = np.arccos(sphere.rxyz[:, 2] / sphere.r)
phi = np.arctan2(sphere.rxyz[:, 1], sphere.rxyz[:, 0])
theta_hat = np.array(
    [np.cos(theta) * np.cos(phi),
     np.cos(theta) * np.sin(phi), -np.sin(phi)]).T
phi_hat = np.array([-np.sin(phi), np.cos(phi), np.zeros(r_hat.shape[0])]).T

ax5.set_title(
    r"scalp magnetic field $\mathbf{B}_\mathbf{p}(\mathbf{r}) \cdot \hat{\mathbf{\varphi}}$"
)
# radial component of H at squid locations
# create MEG object and compute magnetic field
meg = LFPy.MEG(sensor_locations=foursphereParams['r'])
H = meg.calculate_H(cell.current_dipole_moment, dipole_position)

H_phi = np.zeros(phi_p.shape)
for j, (h, u) in enumerate(zip(H, phi_hat)):
    H_phi[j, ] += np.dot(h, u)

vlimround = draw_lineplot(
    ax=ax5,
    data=H_phi * meg.mu * 1E12,  # mT -> fT unit conversion
    dt=cell.dt,
    unit=r'fT',
    ztransform=False,
    label=r'$\mathbf{B}_\mathbf{p}(\mathbf{r}) \cdot \hat{\mathbf{\varphi}}$',
    T=(0, cell.tstop),
    color='k',
Example #5
0
# compute the radial unit vector from the center of the sphere to each
# measurement point, then unit vectors along theta and phi
r_hat = (sphere.rxyz.T / sphere.r).T
theta = np.arccos(sphere.rxyz[:, 2] / sphere.r)
phi = np.arctan2(sphere.rxyz[:, 1], sphere.rxyz[:, 0])
theta_hat = np.array(
    [np.cos(theta) * np.cos(phi),
     np.cos(theta) * np.sin(phi), -np.sin(phi)]).T
phi_hat = np.array([-np.sin(phi), np.cos(phi), np.zeros(r_hat.shape[0])]).T

ax5.set_title(
    r"scalp magnetic field " +
    r"$\mathbf{B}_\mathbf{p}(\mathbf{r}) \cdot \hat{\mathbf{\varphi}}$")
# radial component of H at squid locations
# create MEG object and compute magnetic field
meg = LFPy.MEG(sensor_locations=foursphereParams['r_electrodes'])
H = meg.calculate_H(current_dipole_moment.data, dipole_position)

H_phi = np.zeros(phi_p.shape)
for j, (h, u) in enumerate(zip(H, phi_hat)):
    H_phi[j, ] += h.T @ u

vlimround = draw_lineplot(
    ax=ax5,
    data=H_phi * meg.mu * 1E12,  # mT -> fT unit conv.
    dt=cell.dt,
    unit=r'fT',
    ztransform=False,
    label=r'$\mathbf{B}_\mathbf{p}(\mathbf{r}) \cdot \hat{\mathbf{\varphi}}$',
    T=(0, cell.tstop),
    color='k',