Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Conversion of somato data to BIDS #6414

Merged
merged 16 commits into from
Jul 29, 2019
1 change: 1 addition & 0 deletions doc/manual/datasets_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ The recordings were made using the BCI2000 system. To load a subject, do::

* :ref:`ex-decoding-csp-eeg`

.. _somato-dataset:

Somatosensory
=============
Expand Down
21 changes: 14 additions & 7 deletions examples/inverse/plot_dics_source_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
Compute a Dynamic Imaging of Coherent Sources (DICS) [1]_ filter from
single-trial activity to estimate source power across a frequency band. This
example demonstrates how to source localize the event-related synchronization
(ERS) of beta band activity in the "somato" dataset.

(ERS) of beta band activity in this dataset: :ref:`somato-dataset`

References
----------
Expand All @@ -19,8 +18,11 @@
# Author: Marijn van Vliet <w.m.vanvliet@gmail.com>
# Roman Goj <roman.goj@gmail.com>
# Denis Engemann <denis.engemann@gmail.com>
# Stefan Appelhoff <stefan.appelhoff@mailbox.org>
#
# License: BSD (3-clause)
import os.path as op

import numpy as np
import mne
from mne.datasets import somato
Expand All @@ -32,9 +34,10 @@
###############################################################################
# Reading the raw data and creating epochs:
data_path = somato.data_path()
raw_fname = data_path + '/MEG/somato/sef_raw_sss.fif'
fname_fwd = data_path + '/MEG/somato/somato-meg-oct-6-fwd.fif'
subjects_dir = data_path + '/subjects'
subject = '01'
task = 'somato'
raw_fname = op.join(data_path, 'sub-{}'.format(subject), 'meg',
'sub-{}_task-{}_meg.fif'.format(subject, task))
Copy link
Contributor

@massich massich Aug 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I'm late on the review cycle and this is merged, but do you guys find worth to create a helper function that allows composing the name?

def fname_helper(subject, task='somato', data_type_prefix=''):
    return op.join(
        'sub-{0:02d}'.format(subject),
        data_type_prefix,
        'sub-{0:02d}_task-{}_meg.fif'.format(subject, task)
    )
from mne.datasets.somato import data_path, fname_helper

raw_fname = op.join(data_path(), fname_helper(subject=1, data_type_prefix='meg'))
fname_fwd = op.join(data_path, 'derivatives', fname_helper(subject=1))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ups !! the file names are not the same.

one is _meg.fif the other one is _fwd.fif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The derivatives is not set in stone, so I would not make a new function. There is already one in mne-bids for the existing BIDS spec: https://mne.tools/mne-bids/generated/mne_bids.make_bids_basename.html#mne_bids.make_bids_basename.


raw = mne.io.read_raw_fif(raw_fname)

Expand All @@ -46,7 +49,11 @@
epochs = mne.Epochs(raw, events, event_id=1, tmin=-1.5, tmax=2, picks=picks,
preload=True)

# Read forward operator
# Read forward operator and point to freesurfer subject directory
fname_fwd = op.join(data_path, 'derivatives', 'sub-{}'.format(subject),
'sub-{}_task-{}-fwd.fif'.format(subject, task))
subjects_dir = op.join(data_path, 'derivatives', 'freesurfer', 'subjects')

fwd = mne.read_forward_solution(fname_fwd)

###############################################################################
Expand Down Expand Up @@ -79,4 +86,4 @@
stc = beta_source_power / baseline_source_power
message = 'DICS source power in the 12-30 Hz frequency band'
brain = stc.plot(hemi='both', views='par', subjects_dir=subjects_dir,
time_label=message)
subject=subject, time_label=message)
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
importantly, the clear-cut comparability of the spectral decomposition (the
same type of filter is used across all bands).

We will use this dataset: :ref:`somato-dataset`

References
----------

Expand All @@ -38,10 +40,12 @@
vol. 108, 328-342, NeuroImage.
.. [3] Efron B. and Hastie T. Computer Age Statistical Inference (2016).
Cambrdige University Press, Chapter 11.2.
"""
""" # noqa: E501
# Authors: Denis A. Engemann <denis.engemann@gmail.com>
# Stefan Appelhoff <stefan.appelhoff@mailbox.org>
#
# License: BSD (3-clause)
import os.path as op

import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -54,7 +58,10 @@
###############################################################################
# Set parameters
data_path = somato.data_path()
raw_fname = data_path + '/MEG/somato/sef_raw_sss.fif'
subject = '01'
task = 'somato'
raw_fname = op.join(data_path, 'sub-{}'.format(subject), 'meg',
'sub-{}_task-{}_meg.fif'.format(subject, task))

# let's explore some frequency bands
iter_freqs = [
Expand Down
17 changes: 9 additions & 8 deletions mne/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Martin Luessi <mluessi@nmr.mgh.harvard.edu>
# Eric Larson <larson.eric.d@gmail.com>
# Denis Egnemann <denis.engemann@gmail.com>
# Stefan Appelhoff <stefan.appelhoff@mailbox.org>
# License: BSD Style.

from collections import OrderedDict
Expand Down Expand Up @@ -237,10 +238,10 @@ def _data_path(path=None, force_update=False, update_path=True, download=True,
# To update the testing or misc dataset, push commits, then make a new
# release on GitHub. Then update the "releases" variable:
releases = dict(testing='0.67', misc='0.3')
# And also update the "hashes['testing']" variable below.
# And also update the "md5_hashes['testing']" variable below.

# To update any other dataset, update the data archive itself (upload
# an updated version) and update the hash.
# an updated version) and update the md5 hash.

# try to match url->archive_name->folder_name
urls = dict( # the URLs to use
Expand All @@ -254,8 +255,8 @@ def _data_path(path=None, force_update=False, update_path=True, download=True,
'datasets/foo.tgz',
misc='https://codeload.github.com/mne-tools/mne-misc-data/'
'tar.gz/%s' % releases['misc'],
sample="https://osf.io/86qa2/download?version=4",
somato='https://osf.io/tp4sg/download?version=2',
sample='https://osf.io/86qa2/download?version=4',
somato='https://osf.io/tp4sg/download?version=5',
spm='https://osf.io/je4s8/download?version=2',
testing='https://codeload.github.com/mne-tools/mne-testing-data/'
'tar.gz/%s' % releases['testing'],
Expand Down Expand Up @@ -306,7 +307,7 @@ def _data_path(path=None, force_update=False, update_path=True, download=True,
fieldtrip_cmc='MNE-fieldtrip_cmc-data',
phantom_4dbti='MNE-phantom-4DBTi',
)
hashes = dict(
md5_hashes = dict(
brainstorm=dict(
bst_auditory='fa371a889a5688258896bfa29dd1700b',
bst_phantom_ctf='80819cb7f5b92d1a5289db3fb6acb33c',
Expand All @@ -316,7 +317,7 @@ def _data_path(path=None, force_update=False, update_path=True, download=True,
fake='3194e9f7b46039bb050a74f3e1ae9908',
misc='d822a720ef94302467cb6ad1d320b669',
sample='fc2d5b9eb0a144b1d6ba84dc3b983602',
somato='77a7601948c9e38d2da52446e2eab10f',
somato='f08f17924e23c57a751b3bed4a05fe02',
spm='9f43f67150e3b694b523a21eb929ea75',
testing='9bc5543854737f32d426629b31ea85d7',
multimodal='26ec847ae9ab80f58f204d09e2c08367',
Expand All @@ -328,9 +329,9 @@ def _data_path(path=None, force_update=False, update_path=True, download=True,
fieldtrip_cmc='6f9fd6520f9a66e20994423808d2528c',
phantom_4dbti='f1d96f81d46480d0cc52a7ba4f125367'
)
assert set(hashes.keys()) == set(urls.keys())
assert set(md5_hashes.keys()) == set(urls.keys())
url = urls[name]
hash_ = hashes[name]
hash_ = md5_hashes[name]
folder_orig = folder_origs.get(name, None)
if name == 'brainstorm':
assert archive_name is not None
Expand Down
17 changes: 12 additions & 5 deletions tutorials/time-freq/plot_sensors_time_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
The objective is to show you how to explore the spectral content
of your data (frequency and time-frequency). Here we'll work on Epochs.

We will use the somatosensory dataset that contains so-called
event related synchronizations (ERS) / desynchronizations (ERD) in
the beta band.
"""
We will use this dataset: :ref:`somato-dataset`. It contains so-called event
related synchronizations (ERS) / desynchronizations (ERD) in the beta band.
""" # noqa: E501
# Authors: Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr>
# Stefan Appelhoff <stefan.appelhoff@mailbox.org>
#
# License: BSD (3-clause)
import os.path as op

import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -23,7 +27,10 @@
###############################################################################
# Set parameters
data_path = somato.data_path()
raw_fname = data_path + '/MEG/somato/sef_raw_sss.fif'
subject = '01'
task = 'somato'
raw_fname = op.join(data_path, 'sub-{}'.format(subject), 'meg',
'sub-{}_task-{}_meg.fif'.format(subject, task))

# Setup for reading the raw data
raw = mne.io.read_raw_fif(raw_fname)
Expand Down