Extracting \(\mu\)-wave from the somato-sensory dataset#

This example illustrates how to learn rank-1 atoms [1] on the multivariate somato-sensorymotor dataset from mne. The displayed results highlight the presence of \(\mu\)-waves located in the SI cortex.

# Authors: Thomas Moreau <thomas.moreau@inria.fr>
#          Mainak Jas <mainak.jas@telecom-paristech.fr>
#          Tom Dupre La Tour <tom.duprelatour@telecom-paristech.fr>
#          Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr>
#
# License: BSD (3-clause)

Let us first define the parameters of our model.

sfreq = 150.

# Define the shape of the dictionary
n_atoms = 25
n_times_atom = int(round(sfreq * 1.0))  # 1000. ms

Next, we define the parameters for multivariate CSC

from alphacsc import BatchCDL
cdl = BatchCDL(
    # Shape of the dictionary
    n_atoms=n_atoms,
    n_times_atom=n_times_atom,
    # Request a rank1 dictionary with unit norm temporal and spatial maps
    rank1=True, uv_constraint='separate',
    # Initialize the dictionary with random chunk from the data
    D_init='chunk',
    # rescale the regularization parameter to be 20% of lambda_max
    lmbd_max="scaled", reg=.2,
    # Number of iteration for the alternate minimization and cvg threshold
    n_iter=100, eps=1e-4,
    # solver for the z-step
    solver_z="lgcd", solver_z_kwargs={'tol': 1e-2, 'max_iter': 1000},
    # solver for the d-step
    solver_d='alternate_adaptive', solver_d_kwargs={'max_iter': 300},
    # Technical parameters
    verbose=1, random_state=0, n_jobs=6)

Here, we load the data from the somato-sensory dataset and preprocess them in epochs. The epochs are selected around the stim, starting 2 seconds before and finishing 4 seconds after.

from alphacsc.datasets.mne_data import load_data
t_lim = (-2, 4)
X, info = load_data(dataset='somato', epoch=t_lim, sfreq=sfreq)
Using default location ~/mne_data for somato...

  0%|                                               | 0.00/611M [00:00<?, ?B/s]
  0%|                                       | 546k/611M [00:00<02:04, 4.89MB/s]
  0%|                                      | 1.32M/611M [00:00<01:44, 5.81MB/s]
  0%|▏                                     | 2.22M/611M [00:00<01:25, 7.14MB/s]
  1%|▏                                     | 3.93M/611M [00:00<00:55, 10.9MB/s]
  1%|▎                                     | 6.02M/611M [00:00<00:42, 14.3MB/s]
  2%|▌                                     | 9.34M/611M [00:00<00:29, 20.2MB/s]
  2%|▊                                     | 12.2M/611M [00:00<00:26, 22.8MB/s]
  2%|▉                                     | 15.0M/611M [00:00<00:24, 24.5MB/s]
  3%|█                                     | 17.9M/611M [00:00<00:23, 25.7MB/s]
  3%|█▎                                    | 20.7M/611M [00:01<00:22, 26.5MB/s]
  4%|█▍                                    | 23.5M/611M [00:01<00:21, 27.0MB/s]
  4%|█▋                                    | 26.4M/611M [00:01<00:21, 27.5MB/s]
  5%|█▊                                    | 29.2M/611M [00:01<00:20, 27.7MB/s]
  5%|█▉                                    | 32.1M/611M [00:01<00:20, 27.9MB/s]
  6%|██▏                                   | 34.9M/611M [00:01<00:20, 28.0MB/s]
  6%|██▎                                   | 37.8M/611M [00:01<00:20, 28.1MB/s]
  7%|██▌                                   | 40.6M/611M [00:01<00:20, 28.2MB/s]
  7%|██▋                                   | 43.4M/611M [00:01<00:20, 28.2MB/s]
  8%|██▉                                   | 46.3M/611M [00:01<00:19, 28.2MB/s]
  8%|███                                   | 49.1M/611M [00:02<00:19, 28.3MB/s]
  9%|███▏                                  | 52.0M/611M [00:02<00:19, 28.3MB/s]
  9%|███▍                                  | 54.8M/611M [00:02<00:19, 28.3MB/s]
  9%|███▌                                  | 57.6M/611M [00:02<00:19, 28.3MB/s]
 10%|███▊                                  | 60.5M/611M [00:02<00:19, 28.3MB/s]
 10%|███▉                                  | 63.3M/611M [00:02<00:19, 28.3MB/s]
 11%|████                                  | 66.2M/611M [00:02<00:19, 28.3MB/s]
 11%|████▎                                 | 69.0M/611M [00:02<00:19, 28.3MB/s]
 12%|████▍                                 | 71.9M/611M [00:02<00:18, 28.4MB/s]
 12%|████▋                                 | 74.7M/611M [00:02<00:18, 28.3MB/s]
 13%|████▊                                 | 77.6M/611M [00:03<00:18, 28.4MB/s]
 13%|█████                                 | 80.4M/611M [00:03<00:18, 28.3MB/s]
 14%|█████▏                                | 83.2M/611M [00:03<00:18, 28.3MB/s]
 14%|█████▎                                | 86.1M/611M [00:03<00:18, 28.3MB/s]
 15%|█████▌                                | 88.9M/611M [00:03<00:18, 28.3MB/s]
 15%|█████▋                                | 91.8M/611M [00:03<00:18, 28.3MB/s]
 15%|█████▉                                | 94.6M/611M [00:03<00:18, 28.3MB/s]
 16%|██████                                | 97.4M/611M [00:03<00:18, 28.3MB/s]
 16%|██████▍                                | 100M/611M [00:03<00:18, 28.3MB/s]
 17%|██████▌                                | 103M/611M [00:03<00:17, 28.3MB/s]
 17%|██████▊                                | 106M/611M [00:04<00:17, 28.3MB/s]
 18%|██████▉                                | 109M/611M [00:04<00:17, 28.3MB/s]
 18%|███████▏                               | 112M/611M [00:04<00:17, 28.3MB/s]
 19%|███████▎                               | 114M/611M [00:04<00:17, 28.3MB/s]
 19%|███████▍                               | 117M/611M [00:04<00:17, 28.3MB/s]
 20%|███████▋                               | 120M/611M [00:04<00:17, 28.3MB/s]
 20%|███████▊                               | 123M/611M [00:04<00:17, 28.3MB/s]
 21%|████████                               | 126M/611M [00:04<00:17, 28.3MB/s]
 21%|████████▏                              | 129M/611M [00:04<00:17, 28.3MB/s]
 22%|████████▍                              | 132M/611M [00:04<00:16, 28.3MB/s]
 22%|████████▌                              | 134M/611M [00:05<00:16, 28.3MB/s]
 22%|████████▊                              | 137M/611M [00:05<00:16, 28.3MB/s]
 23%|████████▉                              | 140M/611M [00:05<00:16, 28.3MB/s]
 23%|█████████▏                             | 143M/611M [00:05<00:16, 28.3MB/s]
 24%|█████████▎                             | 146M/611M [00:05<00:16, 28.3MB/s]
 24%|█████████▍                             | 149M/611M [00:05<00:16, 28.3MB/s]
 25%|█████████▋                             | 151M/611M [00:05<00:16, 28.4MB/s]
 25%|█████████▊                             | 154M/611M [00:05<00:16, 28.3MB/s]
 26%|██████████                             | 157M/611M [00:05<00:15, 28.4MB/s]
 26%|██████████▏                            | 160M/611M [00:05<00:15, 28.3MB/s]
 27%|██████████▍                            | 163M/611M [00:06<00:15, 28.3MB/s]
 27%|██████████▌                            | 166M/611M [00:06<00:15, 28.3MB/s]
 28%|██████████▊                            | 169M/611M [00:06<00:15, 28.4MB/s]
 28%|██████████▉                            | 171M/611M [00:06<00:15, 28.3MB/s]
 29%|███████████▏                           | 174M/611M [00:06<00:15, 28.4MB/s]
 29%|███████████▎                           | 177M/611M [00:06<00:15, 28.4MB/s]
 29%|███████████▍                           | 180M/611M [00:06<00:15, 28.4MB/s]
 30%|███████████▋                           | 183M/611M [00:06<00:15, 28.3MB/s]
 30%|███████████▊                           | 186M/611M [00:06<00:15, 28.3MB/s]
 31%|████████████                           | 188M/611M [00:06<00:14, 28.3MB/s]
 31%|████████████▏                          | 191M/611M [00:07<00:14, 28.3MB/s]
 32%|████████████▍                          | 194M/611M [00:07<00:14, 28.3MB/s]
 32%|████████████▌                          | 197M/611M [00:07<00:14, 28.3MB/s]
 33%|████████████▊                          | 200M/611M [00:07<00:14, 28.3MB/s]
 33%|████████████▉                          | 203M/611M [00:07<00:14, 28.3MB/s]
 34%|█████████████▏                         | 205M/611M [00:07<00:14, 28.3MB/s]
 34%|█████████████▎                         | 208M/611M [00:07<00:14, 28.3MB/s]
 35%|█████████████▍                         | 211M/611M [00:07<00:14, 28.3MB/s]
 35%|█████████████▋                         | 214M/611M [00:07<00:14, 28.3MB/s]
 36%|█████████████▊                         | 217M/611M [00:07<00:13, 28.4MB/s]
 36%|██████████████                         | 220M/611M [00:08<00:13, 28.3MB/s]
 36%|██████████████▏                        | 223M/611M [00:08<00:13, 28.4MB/s]
 37%|██████████████▍                        | 225M/611M [00:08<00:13, 28.3MB/s]
 37%|██████████████▌                        | 228M/611M [00:08<00:13, 28.4MB/s]
 38%|██████████████▊                        | 231M/611M [00:08<00:13, 28.3MB/s]
 38%|██████████████▉                        | 234M/611M [00:08<00:13, 28.3MB/s]
 39%|███████████████                        | 237M/611M [00:08<00:13, 28.3MB/s]
 39%|███████████████▎                       | 240M/611M [00:08<00:13, 28.3MB/s]
 40%|███████████████▍                       | 242M/611M [00:08<00:12, 28.4MB/s]
 40%|███████████████▋                       | 245M/611M [00:08<00:12, 28.3MB/s]
 41%|███████████████▊                       | 248M/611M [00:09<00:12, 28.3MB/s]
 41%|████████████████                       | 251M/611M [00:09<00:12, 28.3MB/s]
 42%|████████████████▏                      | 254M/611M [00:09<00:12, 28.3MB/s]
 42%|████████████████▍                      | 257M/611M [00:09<00:12, 28.3MB/s]
 43%|████████████████▌                      | 259M/611M [00:09<00:12, 28.0MB/s]
 43%|████████████████▊                      | 262M/611M [00:09<00:12, 27.1MB/s]
 43%|████████████████▉                      | 265M/611M [00:09<00:13, 26.4MB/s]
 44%|█████████████████                      | 268M/611M [00:09<00:12, 27.0MB/s]
 44%|█████████████████▎                     | 271M/611M [00:09<00:12, 27.2MB/s]
 45%|█████████████████▍                     | 273M/611M [00:09<00:12, 27.6MB/s]
 45%|█████████████████▋                     | 276M/611M [00:10<00:12, 27.7MB/s]
 46%|█████████████████▊                     | 279M/611M [00:10<00:11, 27.9MB/s]
 46%|██████████████████                     | 282M/611M [00:10<00:11, 28.1MB/s]
 47%|██████████████████▏                    | 285M/611M [00:10<00:11, 28.1MB/s]
 47%|██████████████████▎                    | 288M/611M [00:10<00:11, 28.1MB/s]
 48%|██████████████████▌                    | 290M/611M [00:10<00:11, 28.1MB/s]
 48%|██████████████████▋                    | 293M/611M [00:10<00:11, 28.1MB/s]
 48%|██████████████████▉                    | 296M/611M [00:10<00:11, 28.1MB/s]
 49%|███████████████████                    | 299M/611M [00:10<00:10, 28.4MB/s]
 49%|███████████████████▎                   | 302M/611M [00:10<00:10, 28.3MB/s]
 50%|███████████████████▍                   | 305M/611M [00:11<00:10, 28.3MB/s]
 50%|███████████████████▋                   | 307M/611M [00:11<00:10, 28.3MB/s]
 51%|███████████████████▊                   | 310M/611M [00:11<00:10, 28.2MB/s]
 51%|████████████████████                   | 313M/611M [00:11<00:10, 28.2MB/s]
 52%|████████████████████▏                  | 316M/611M [00:11<00:10, 28.2MB/s]
 52%|████████████████████▎                  | 319M/611M [00:11<00:10, 28.2MB/s]
 53%|████████████████████▌                  | 322M/611M [00:11<00:10, 28.3MB/s]
 53%|████████████████████▋                  | 324M/611M [00:11<00:10, 28.3MB/s]
 54%|████████████████████▉                  | 327M/611M [00:11<00:10, 28.2MB/s]
 54%|█████████████████████                  | 330M/611M [00:12<00:09, 28.4MB/s]
 55%|█████████████████████▎                 | 333M/611M [00:12<00:09, 28.4MB/s]
 55%|█████████████████████▍                 | 336M/611M [00:12<00:09, 28.3MB/s]
 55%|█████████████████████▋                 | 339M/611M [00:12<00:09, 28.4MB/s]
 56%|█████████████████████▊                 | 342M/611M [00:12<00:09, 28.3MB/s]
 56%|█████████████████████▉                 | 344M/611M [00:12<00:09, 28.3MB/s]
 57%|██████████████████████▏                | 347M/611M [00:12<00:09, 28.3MB/s]
 57%|██████████████████████▎                | 350M/611M [00:12<00:09, 28.3MB/s]
 58%|██████████████████████▌                | 353M/611M [00:12<00:09, 28.3MB/s]
 58%|██████████████████████▋                | 356M/611M [00:12<00:09, 28.3MB/s]
 59%|██████████████████████▉                | 359M/611M [00:13<00:08, 28.4MB/s]
 59%|███████████████████████                | 361M/611M [00:13<00:08, 28.3MB/s]
 60%|███████████████████████▎               | 364M/611M [00:13<00:08, 28.2MB/s]
 60%|███████████████████████▍               | 367M/611M [00:13<00:08, 28.6MB/s]
 61%|███████████████████████▋               | 370M/611M [00:13<00:08, 28.4MB/s]
 61%|███████████████████████▊               | 373M/611M [00:13<00:08, 28.0MB/s]
 62%|████████████████████████               | 376M/611M [00:13<00:07, 29.3MB/s]
 62%|████████████████████████▏              | 379M/611M [00:13<00:08, 26.6MB/s]
 63%|████████████████████████▍              | 382M/611M [00:13<00:08, 27.1MB/s]
 63%|████████████████████████▌              | 385M/611M [00:13<00:08, 27.4MB/s]
 63%|████████████████████████▊              | 388M/611M [00:14<00:08, 27.7MB/s]
 64%|████████████████████████▉              | 390M/611M [00:14<00:07, 27.9MB/s]
 64%|█████████████████████████              | 393M/611M [00:14<00:07, 28.0MB/s]
 65%|█████████████████████████▎             | 396M/611M [00:14<00:07, 28.1MB/s]
 65%|█████████████████████████▍             | 399M/611M [00:14<00:07, 28.2MB/s]
 66%|█████████████████████████▋             | 402M/611M [00:14<00:07, 28.2MB/s]
 66%|█████████████████████████▊             | 405M/611M [00:14<00:07, 28.3MB/s]
 67%|██████████████████████████             | 407M/611M [00:14<00:07, 28.2MB/s]
 67%|██████████████████████████▏            | 410M/611M [00:14<00:07, 28.3MB/s]
 68%|██████████████████████████▍            | 413M/611M [00:14<00:06, 28.3MB/s]
 68%|██████████████████████████▌            | 416M/611M [00:15<00:06, 28.3MB/s]
 69%|██████████████████████████▊            | 419M/611M [00:15<00:06, 28.3MB/s]
 69%|██████████████████████████▉            | 422M/611M [00:15<00:06, 28.3MB/s]
 70%|███████████████████████████            | 425M/611M [00:15<00:06, 28.3MB/s]
 70%|███████████████████████████▎           | 427M/611M [00:15<00:06, 28.3MB/s]
 70%|███████████████████████████▍           | 430M/611M [00:15<00:06, 28.3MB/s]
 71%|███████████████████████████▋           | 433M/611M [00:15<00:06, 28.3MB/s]
 71%|███████████████████████████▊           | 436M/611M [00:15<00:06, 28.3MB/s]
 72%|████████████████████████████           | 439M/611M [00:15<00:06, 28.3MB/s]
 72%|████████████████████████████▏          | 442M/611M [00:15<00:05, 28.3MB/s]
 73%|████████████████████████████▍          | 444M/611M [00:16<00:05, 28.3MB/s]
 73%|████████████████████████████▌          | 447M/611M [00:16<00:05, 28.3MB/s]
 74%|████████████████████████████▊          | 450M/611M [00:16<00:05, 28.3MB/s]
 74%|████████████████████████████▉          | 453M/611M [00:16<00:05, 28.3MB/s]
 75%|█████████████████████████████          | 456M/611M [00:16<00:05, 28.3MB/s]
 75%|█████████████████████████████▎         | 459M/611M [00:16<00:05, 28.3MB/s]
 76%|█████████████████████████████▍         | 461M/611M [00:16<00:05, 28.3MB/s]
 76%|█████████████████████████████▋         | 464M/611M [00:16<00:05, 28.3MB/s]
 77%|█████████████████████████████▊         | 467M/611M [00:16<00:05, 28.3MB/s]
 77%|██████████████████████████████         | 470M/611M [00:16<00:04, 28.3MB/s]
 77%|██████████████████████████████▏        | 473M/611M [00:17<00:04, 28.3MB/s]
 78%|██████████████████████████████▍        | 476M/611M [00:17<00:04, 28.3MB/s]
 78%|██████████████████████████████▌        | 478M/611M [00:17<00:04, 28.3MB/s]
 79%|██████████████████████████████▋        | 481M/611M [00:17<00:04, 28.3MB/s]
 79%|██████████████████████████████▉        | 484M/611M [00:17<00:04, 28.3MB/s]
 80%|███████████████████████████████        | 487M/611M [00:17<00:04, 28.3MB/s]
 80%|███████████████████████████████▎       | 490M/611M [00:17<00:04, 28.3MB/s]
 81%|███████████████████████████████▍       | 493M/611M [00:17<00:04, 28.3MB/s]
 81%|███████████████████████████████▋       | 495M/611M [00:17<00:04, 28.3MB/s]
 82%|███████████████████████████████▊       | 498M/611M [00:17<00:03, 28.3MB/s]
 82%|████████████████████████████████       | 501M/611M [00:18<00:03, 28.3MB/s]
 83%|████████████████████████████████▏      | 504M/611M [00:18<00:03, 28.3MB/s]
 83%|████████████████████████████████▍      | 507M/611M [00:18<00:03, 28.3MB/s]
 83%|████████████████████████████████▌      | 510M/611M [00:18<00:03, 28.3MB/s]
 84%|████████████████████████████████▋      | 513M/611M [00:18<00:03, 28.3MB/s]
 84%|████████████████████████████████▉      | 515M/611M [00:18<00:03, 28.3MB/s]
 85%|█████████████████████████████████      | 518M/611M [00:18<00:03, 28.3MB/s]
 85%|█████████████████████████████████▎     | 521M/611M [00:18<00:03, 28.3MB/s]
 86%|█████████████████████████████████▍     | 524M/611M [00:18<00:03, 28.3MB/s]
 86%|█████████████████████████████████▋     | 527M/611M [00:18<00:02, 28.3MB/s]
 87%|█████████████████████████████████▊     | 530M/611M [00:19<00:02, 28.3MB/s]
 87%|██████████████████████████████████     | 532M/611M [00:19<00:02, 28.3MB/s]
 88%|██████████████████████████████████▏    | 535M/611M [00:19<00:02, 28.3MB/s]
 88%|██████████████████████████████████▍    | 538M/611M [00:19<00:02, 28.3MB/s]
 89%|██████████████████████████████████▌    | 541M/611M [00:19<00:02, 28.3MB/s]
 89%|██████████████████████████████████▋    | 544M/611M [00:19<00:02, 28.3MB/s]
 90%|██████████████████████████████████▉    | 547M/611M [00:19<00:02, 28.3MB/s]
 90%|███████████████████████████████████    | 549M/611M [00:19<00:02, 28.3MB/s]
 90%|███████████████████████████████████▎   | 552M/611M [00:19<00:02, 28.3MB/s]
 91%|███████████████████████████████████▍   | 555M/611M [00:19<00:02, 27.4MB/s]
 91%|███████████████████████████████████▋   | 558M/611M [00:20<00:02, 24.1MB/s]
 92%|███████████████████████████████████▊   | 561M/611M [00:20<00:01, 25.8MB/s]
 92%|████████████████████████████████████   | 564M/611M [00:20<00:01, 26.6MB/s]
 93%|████████████████████████████████████▏  | 567M/611M [00:20<00:01, 27.0MB/s]
 93%|████████████████████████████████████▍  | 569M/611M [00:20<00:01, 27.4MB/s]
 94%|████████████████████████████████████▌  | 572M/611M [00:20<00:01, 27.7MB/s]
 94%|████████████████████████████████████▋  | 575M/611M [00:20<00:01, 27.9MB/s]
 95%|████████████████████████████████████▉  | 578M/611M [00:20<00:01, 28.0MB/s]
 95%|█████████████████████████████████████  | 581M/611M [00:20<00:01, 28.2MB/s]
 96%|█████████████████████████████████████▎ | 584M/611M [00:21<00:00, 28.2MB/s]
 96%|█████████████████████████████████████▍ | 587M/611M [00:21<00:00, 28.2MB/s]
 97%|█████████████████████████████████████▋ | 589M/611M [00:21<00:00, 28.3MB/s]
 97%|█████████████████████████████████████▊ | 592M/611M [00:21<00:00, 28.3MB/s]
 97%|██████████████████████████████████████ | 595M/611M [00:21<00:00, 28.3MB/s]
 98%|██████████████████████████████████████▏| 598M/611M [00:21<00:00, 28.3MB/s]
 98%|██████████████████████████████████████▍| 601M/611M [00:21<00:00, 28.3MB/s]
 99%|██████████████████████████████████████▌| 604M/611M [00:21<00:00, 28.3MB/s]
 99%|██████████████████████████████████████▋| 606M/611M [00:21<00:00, 28.3MB/s]
100%|██████████████████████████████████████▉| 609M/611M [00:21<00:00, 28.3MB/s]
  0%|                                               | 0.00/611M [00:00<?, ?B/s]
100%|███████████████████████████████████████| 611M/611M [00:00<00:00, 2.72TB/s]
Attempting to create new mne-python configuration file:
/github/home/.mne/mne-python.json
Download complete in 35s (582.2 MB)
Opening raw data file /github/home/mne_data/MNE-somato-data/sub-01/meg/sub-01_task-somato_meg.fif...
    Range : 237600 ... 506999 =    791.189 ...  1688.266 secs
Ready.
Reading 0 ... 269399  =      0.000 ...   897.077 secs...
Filtering raw data in 1 contiguous segment
Setting up band-stop filter

FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal bandstop filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower transition bandwidth: 0.50 Hz
- Upper transition bandwidth: 0.50 Hz
- Filter length: 1983 samples (6.603 s)

Filtering raw data in 1 contiguous segment
Setting up high-pass filter at 2 Hz

FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal highpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower passband edge: 2.00
- Lower transition bandwidth: 2.00 Hz (-6 dB cutoff frequency: 1.00 Hz)
- Filter length: 497 samples (1.655 s)

111 events found on stim channel STI 014
Event IDs: [1]
Not setting metadata
111 matching events found
Setting baseline interval to [-3.9992341833870637, 0.0] s
Applying baseline correction (mode: mean)
0 projection items activated
Using data from preloaded Raw for 111 events and 1202 original time points ...
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
5 bad epochs dropped
NOTE: pick_types() is a legacy function. New code should use inst.pick(...).
/github/workspace/alphacsc/datasets/mne_data.py:98: RuntimeWarning: Something went wrong in the data-driven estimation of the data rank as it exceeds the theoretical rank from the info (204 > 64). Consider setting rank to "auto" or setting it explicitly as an integer.
  cov = mne.compute_covariance(epochs_cov)
Reducing data rank from 204 -> 204
Estimating covariance using EMPIRICAL
Done.
Number of samples used : 127412
[done]
Not setting metadata
111 matching events found
Setting baseline interval to [-2.001282051803185, 0.0] s
Applying baseline correction (mode: mean)
0 projection items activated
Using data from preloaded Raw for 111 events and 1803 original time points ...
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
8 bad epochs dropped
NOTE: pick_types() is a legacy function. New code should use inst.pick(...).

Fit the model and learn rank1 atoms

cdl.fit(X)
..............
[BatchCDL] Converged after 14 iteration, (dz, du) = 8.765e-05, 8.726e-05
[BatchCDL] Fit in 270.8s

<alphacsc.convolutional_dictionary_learning.BatchCDL object at 0x7f05b1f4d730>

Display the 4-th atom, which displays a \(\mu\)-waveform in its temporal pattern.

import mne
import numpy as np
import matplotlib.pyplot as plt

i_atom = 4
n_plots = 3
figsize = (n_plots * 5, 5.5)
fig, axes = plt.subplots(1, n_plots, figsize=figsize, squeeze=False)

# Plot the spatial map of the learn atom using mne topomap
ax = axes[0, 0]
u_hat = cdl.u_hat_[i_atom]
mne.viz.plot_topomap(u_hat, info, axes=ax, show=False)
ax.set(title='Learned spatial pattern')

# Plot the temporal pattern of the learn atom
ax = axes[0, 1]
v_hat = cdl.v_hat_[i_atom]
t = np.arange(v_hat.size) / sfreq
ax.plot(t, v_hat)
ax.set(xlabel='Time (sec)', title='Learned temporal waveform')
ax.grid(True)

# Plot the psd of the time atom
ax = axes[0, 2]
psd = np.abs(np.fft.rfft(v_hat)) ** 2
frequencies = np.linspace(0, sfreq / 2.0, len(psd))
ax.semilogy(frequencies, psd)
ax.set(xlabel='Frequencies (Hz)', title='Power Spectral Density')
ax.grid(True)
ax.set_xlim(0, 30)

plt.tight_layout()
plt.show()
Learned spatial pattern, Learned temporal waveform, Power Spectral Density

Total running time of the script: (5 minutes 15.516 seconds)

Gallery generated by Sphinx-Gallery