{ "cells": [ { "cell_type": "markdown", "id": "306afddf-230e-42d5-82a6-954ab48739d1", "metadata": {}, "source": [ "# 4. Advanced - grouping models" ] }, { "cell_type": "markdown", "id": "08cf26ca-dfdc-42ae-9b9d-e7fbe8883e98", "metadata": {}, "source": [ "> [!WARNING]\n", "> This tutorial and the associated functions are still under construction, only use these functions for development puprose \n", "\n", "\n", "For this tutorial we will simulate data for two participants, one with noise and one without. We make the simulation deterministic by providing the exact times at which we want the events to occur for two trials.\n", "Importantly we will use the same source names and parameters for both participants, but we will swap the first two sources between the two participants. This will allow us to test the grouping model's ability to handle different event configuration across conditions or participants." ] }, { "cell_type": "code", "execution_count": 1, "id": "e73e3a79-c328-46bd-9f1f-bb4ed1c7ec28", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Simulating /home/gabriel/ownCloud/projects/RUGUU/hmp/docs/source/notebooks/sample_data/simulated/dataset_a_raw_raw.fif\n", "/home/gabriel/ownCloud/projects/RUGUU/hmp/docs/source/notebooks/sample_data/simulated/dataset_a_raw_raw.fif simulated\n", "Simulating /home/gabriel/ownCloud/projects/RUGUU/hmp/docs/source/notebooks/sample_data/simulated/dataset_b_raw_raw.fif\n", "/home/gabriel/ownCloud/projects/RUGUU/hmp/docs/source/notebooks/sample_data/simulated/dataset_b_raw_raw.fif simulated\n" ] } ], "source": [ "import os.path as op\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "import hmp\n", "from hmp import simulations\n", "\n", "sfreq = 100\n", "n_events = 3\n", "# Data creation/reading\n", "## Simulation parameters\n", "n_trials = 2\n", "# Times (in milliseconds) for participant A: 3 events per trial, 2 trials with the following time structure:\n", "# On trial 1 the events will occur at 100ms, 300ms, and 400ms after the simulated trial onset\n", "# On trial 2 all inter-event duration were doubled and thus occur at 200ms, 600ms, and 800ms after the simulated trial onset\n", "times = np.array([[100, 200, 100, 100],\n", " [200, 400, 200, 200]], dtype='float64')\n", "# Thus, on average, the events appear at 150, 450 and 600ms after trial onset\n", "avg_times = np.cumsum(times.mean(axis=0))[:-1]\n", "\n", "# Define source names and parameters, the same for both participants\n", "names_a = ['bankssts-rh', 'bankssts-lh', 'caudalanteriorcingulate-rh', 'bankssts-lh']\n", "# same but the two first sources are swapped\n", "names_b = ['bankssts-lh', 'bankssts-rh','caudalanteriorcingulate-rh', 'bankssts-lh']\n", "sources_a, sources_b = [], []\n", "for name_a_i, name_b_i in zip(names_a, names_b):\n", " sources_a.append([name_a_i, 10., 4e-8])\n", " sources_b.append([name_b_i, 10., 4e-8])\n", "\n", "## Now we simulated two datasets with the exact same structure except one is noise, one isn't\n", "# Participant A is noisy\n", "files_a = simulations.simulate(sources_a, n_trials, 1, 'dataset_a_raw', overwrite=True,\n", " sfreq=sfreq, times=times, noise=True, seed=1, path=op.join('sample_data', 'simulated'))\n", "# Participant B has no noise\n", "files_b = simulations.simulate(sources_b, n_trials, 1, 'dataset_b_raw', overwrite=True,\n", " sfreq=sfreq, times=times, noise=False, seed=1, path=op.join('sample_data', 'simulated'))\n" ] }, { "cell_type": "markdown", "id": "a5ffa862-b7e8-4a5a-9573-e9f7ac1e82e2", "metadata": {}, "source": [ "Next we read the data as we do for simulations (Tutorial 1)" ] }, { "cell_type": "code", "execution_count": 2, "id": "8da824ce-3039-4227-95f5-946f673c0580", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Processing participant /home/gabriel/ownCloud/projects/RUGUU/hmp/docs/source/notebooks/sample_data/simulated/dataset_a_raw_raw.fif's raw eeg\n", "Processing participant /home/gabriel/ownCloud/projects/RUGUU/hmp/docs/source/notebooks/sample_data/simulated/dataset_b_raw_raw.fif's raw eeg\n" ] }, { "data": { "text/html": [ "
<xarray.Dataset> Size: 498kB\n",
"Dimensions: (participant: 2, epoch: 2, channel: 59, sample: 521)\n",
"Coordinates:\n",
" * epoch (epoch) int64 16B 0 1\n",
" * channel (channel) <U7 2kB 'EEG 001' 'EEG 002' ... 'EEG 059' 'EEG 060'\n",
" * sample (sample) int64 4kB -20 -19 -18 -17 -16 ... 496 497 498 499 500\n",
" event_name (epoch) object 16B 'stimulus' 'stimulus'\n",
" rt (epoch) float64 16B 0.5 1.0\n",
" * participant (participant) <U1 8B 'a' 'b'\n",
"Data variables:\n",
" data (participant, epoch, channel, sample) float32 492kB 7.267e-0...\n",
"Attributes:\n",
" sfreq: 100.0\n",
" lowpass: 40.0\n",
" highpass: 0.10000000149011612\n",
" reference: None\n",
" n_trials: 4\n",
" tmin: -0.2\n",
" tmax: 5