Conpute SVD#

import matplotlib.pyplot as plt
import numpy as np
import pycartool as cart

#### Import from Cartool files

fname_spi = "MNI152.NlinAsym09c.204.5000.2017.spi"
fname_roi = "MNI152.NlinAsym09c.204.5000.2017.AAL.rois"

spi = cart.spi.read_spi(fname_spi)
roi = cart.rois.read_roi(fname_roi, spi)

#### Constants

sfreq = 512
n_sources = len(spi.names)
snr = 10
n_times = 2048

### Simulate sources time course

Here we simulate the sources time course as random noise generators everywhere in the brain, expect in the first Region of interest where sources time course are simulated are sin waves in the x direction.

#### Create random noise

plt.figure()
plt.plot(simulated_tc[0, 0], color="navy")
plt.title("Time course of a source outside the first Roi")
plt.show()
Time course of a source outside the first Roi

#### Create sin wave in Roi

x = np.arange(0, n_times, 1)
sin = snr * np.sin(x / (2 * np.pi))
plt.figure()
plt.plot(sin, color="red")
plt.title("Time course of sources inside the first Roi  (x direction)")
plt.show()
Time course of sources inside the first Roi  (x direction)

#### Compute the regions of interest time course

plt.figure()
plt.plot(roi_t_simulated.sources_tc[0:4, 0, :].T)
plt.title("Rois time course")
plt.show()
Rois time course

Total running time of the script: ( 0 minutes 7.155 seconds)

Estimated memory usage: 502 MB

Gallery generated by Sphinx-Gallery