several things changed in mne with montage, we need to changed CreateRawand test_dataaccordingly
tests/test_data.py:15 (test_CreateRaw_invalidmontage)
data = array([[ 0.49671415, -0.1382643 , 0.64768854, 1.52302986, -0.23415337,
-0.23413696, 1.57921282, 0.76743473...8769, 0.27157884, -1.27674858, -1.08105654,
1.05315285, -0.03955515, 0.6815007 , 0.02831838, 0.02975614]])
def test_CreateRaw_invalidmontage(data):
ch_names = ['Fz', 'Pz']
with pytest.raises(ValueError, match="Could not find the montage. Please provide the full path."):
> raw = CreateRaw(data, ch_names, montage="nice")
test_data.py:19:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
data = array([[ 0.49671415, -0.1382643 , 0.64768854, 1.52302986, -0.23415337,
-0.23413696, 1.57921282, 0.76743473...8769, 0.27157884, -1.27674858, -1.08105654,
1.05315285, -0.03955515, 0.6815007 , 0.02831838, 0.02975614]])
ch_names = ['Fz', 'Pz'], montage = 'nice', ch_types = ['eeg', 'eeg']
def CreateRaw(data, ch_names, montage=None, ch_types=None):
"""Generate a mne raw structure based on hardcoded info for bruxisme data"""
if ch_types is None:
ch_types = ['eeg']
ch_types = ch_types * len(ch_names)
sfreq = 200
if montage is None:
montage = 'standard_1020'
> info = mne.create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types, montage=montage, verbose=False)
../tinnsleep/data.py:12:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ch_names = ['Fz', 'Pz'], sfreq = 200, ch_types = ['eeg', 'eeg']
montage = 'nice', verbose = False
> ???
<decorator-gen-27>:20:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ch_names = ['Fz', 'Pz'], sfreq = 200.0
ch_types = array(['eeg', 'eeg'], dtype='<U3'), montage = 'nice', verbose = False
@verbose
def create_info(ch_names, sfreq, ch_types='misc', montage=None, verbose=None):
"""Create a basic Info instance suitable for use with create_raw.
Parameters
----------
ch_names : list of str | int
Channel names. If an int, a list of channel names will be created
from ``range(ch_names)``.
sfreq : float
Sample rate of the data.
ch_types : list of str | str
Channel types, default is ``'misc'`` which is not a
:term:`data channel <data channels>`.
Currently supported fields are 'ecg', 'bio', 'stim', 'eog', 'misc',
'seeg', 'ecog', 'mag', 'eeg', 'ref_meg', 'grad', 'emg', 'hbr' or 'hbo'.
If str, then all channels are assumed to be of the same type.
montage : None
Deprecated. Use :meth:`mne.Info.set_montage` instead.
%(verbose)s
Returns
-------
info : instance of Info
The measurement info.
Notes
-----
The info dictionary will be sparsely populated to enable functionality
within the rest of the package. Advanced functionality such as source
localization can only be obtained through substantial, proper
modifications of the info structure (not recommended).
Note that the MEG device-to-head transform ``info['dev_head_t']`` will
be initialized to the identity transform.
Proper units of measure:
* V: eeg, eog, seeg, emg, ecg, bio, ecog
* T: mag
* T/m: grad
* M: hbo, hbr
* Am: dipole
* AU: misc
"""
from ..channels.montage import (DigMontage, _set_montage)
try:
ch_names = operator.index(ch_names) # int-like
except TypeError:
pass
else:
ch_names = list(np.arange(ch_names).astype(str))
_validate_type(ch_names, (list, tuple), "ch_names",
("list, tuple, or int"))
_validate_type(montage, (None, str, DigMontage), 'montage')
if montage is not None:
warn('Passing montage to create_info is deprecated and will be '
'removed in 0.21, use raw.set_montage (or epochs.set_montage, '
'etc.) instead', DeprecationWarning)
sfreq = float(sfreq)
if sfreq <= 0:
raise ValueError('sfreq must be positive')
nchan = len(ch_names)
if ch_types is None:
warn('Passing ch_types=None is deprecated and will not be supported '
'in 0.21, pass ch_types="misc" instead.', DeprecationWarning)
ch_types = 'misc' # just for backward compat
if isinstance(ch_types, str):
ch_types = [ch_types] * nchan
ch_types = np.atleast_1d(np.array(ch_types, np.str))
if ch_types.ndim != 1 or len(ch_types) != nchan:
raise ValueError('ch_types and ch_names must be the same length '
'(%s != %s) for ch_types=%s'
% (len(ch_types), nchan, ch_types))
info = _empty_info(sfreq)
for ci, (name, kind) in enumerate(zip(ch_names, ch_types)):
_validate_type(name, 'str', "each entry in ch_names")
_validate_type(kind, 'str', "each entry in ch_types")
if kind not in _kind_dict:
raise KeyError('kind must be one of %s, not %s'
% (list(_kind_dict.keys()), kind))
kind = _kind_dict[kind]
# mirror what tag.py does here
coord_frame = _coord_dict.get(kind[0], FIFF.FIFFV_COORD_UNKNOWN)
chan_info = dict(loc=np.full(12, np.nan), unit_mul=0, range=1., cal=1.,
kind=kind[0], coil_type=kind[1],
unit=kind[2], coord_frame=coord_frame,
ch_name=str(name), scanno=ci + 1, logno=ci + 1)
info['chs'].append(chan_info)
info._update_redundant()
> _set_montage(info, montage)
../../../anaconda3/envs/tinnsleep-env/lib/python3.8/site-packages/mne/io/meas_info.py:2000:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
info = <Info | 7 non-empty values
bads: []
ch_names: Fz, Pz
chs: 2 EEG
custom_ref_applied: False
highpass: 0.0 Hz
lowpass: 100.0 Hz
meas_date: unspecified
nchan: 2
projs: []
sfreq: 200.0 Hz
>
montage = 'nice', raise_if_subset = <object object at 0x1216b03f0>
match_case = True
@fill_doc
def _set_montage(info, montage, raise_if_subset=DEPRECATED_PARAM,
match_case=True):
"""Apply montage to data.
With a DigMontage, this function will replace the digitizer info with
the values specified for the particular montage.
Usually, a montage is expected to contain the positions of all EEG
electrodes and a warning is raised when this is not the case.
Parameters
----------
info : instance of Info
The measurement info to update.
%(montage)s
raise_if_subset: bool
If True, ValueError will be raised when montage.ch_names is a
subset of info['ch_names']. This parameter was introduced for
backward compatibility when set to False.
Defaults to False in 0.19, it will change to default to True in
0.20, and will be removed in 0.21.
.. versionadded: 0.19
%(match_case)s
Notes
-----
This function will change the info variable in place.
"""
_validate_type(montage, types=(DigMontage, type(None), str),
item_name='montage')
_set_montage_deprecation_helper(montage, None, None, raise_if_subset)
if isinstance(montage, str): # load builtin montage
> _check_option('montage', montage, _BUILT_IN_MONTAGES)
../../../anaconda3/envs/tinnsleep-env/lib/python3.8/site-packages/mne/channels/montage.py:693:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
parameter = 'montage', value = 'nice'
allowed_values = ['EGI_256', 'GSN-HydroCel-128', 'GSN-HydroCel-129', 'GSN-HydroCel-256', 'GSN-HydroCel-257', 'GSN-HydroCel-32', ...]
extra = ''
def _check_option(parameter, value, allowed_values, extra=''):
"""Check the value of a parameter against a list of valid options.
Raises a ValueError with a readable error message if the value was invalid.
Parameters
----------
parameter : str
The name of the parameter to check. This is used in the error message.
value : any type
The value of the parameter to check.
allowed_values : list
The list of allowed values for the parameter.
extra : str
Extra string to append to the invalid value sentence, e.g.
"when using ico mode".
Raises
------
ValueError
When the value of the parameter was not one of the valid options.
"""
if value in allowed_values:
return True
# Prepare a nice error message for the user
extra = ' ' + extra if extra else extra
msg = ("Invalid value for the '{parameter}' parameter{extra}. "
'{options}, but got {value!r} instead.')
if len(allowed_values) == 1:
options = 'The only allowed value is %r' % allowed_values[0]
else:
options = 'Allowed values are '
options += ', '.join(['%r' % v for v in allowed_values[:-1]])
options += ' and %r' % allowed_values[-1]
> raise ValueError(msg.format(parameter=parameter, options=options,
value=value, extra=extra))
E ValueError: Invalid value for the 'montage' parameter. Allowed values are 'EGI_256', 'GSN-HydroCel-128', 'GSN-HydroCel-129', 'GSN-HydroCel-256', 'GSN-HydroCel-257', 'GSN-HydroCel-32', 'GSN-HydroCel-64_1.0', 'GSN-HydroCel-65_1.0', 'biosemi128', 'biosemi16', 'biosemi160', 'biosemi256', 'biosemi32', 'biosemi64', 'easycap-M1', 'easycap-M10', 'mgh60', 'mgh70', 'standard_1005', 'standard_1020', 'standard_alphabetic', 'standard_postfixed', 'standard_prefixed' and 'standard_primed', but got 'nice' instead.
../../../anaconda3/envs/tinnsleep-env/lib/python3.8/site-packages/mne/utils/check.py:563: ValueError
During handling of the above exception, another exception occurred:
data = array([[ 0.49671415, -0.1382643 , 0.64768854, 1.52302986, -0.23415337,
-0.23413696, 1.57921282, 0.76743473...8769, 0.27157884, -1.27674858, -1.08105654,
1.05315285, -0.03955515, 0.6815007 , 0.02831838, 0.02975614]])
def test_CreateRaw_invalidmontage(data):
ch_names = ['Fz', 'Pz']
with pytest.raises(ValueError, match="Could not find the montage. Please provide the full path."):
> raw = CreateRaw(data, ch_names, montage="nice")
E AssertionError: Pattern 'Could not find the montage. Please provide the full path.' does not match "Invalid value for the 'montage' parameter. Allowed values are 'EGI_256', 'GSN-HydroCel-128', 'GSN-HydroCel-129', 'GSN-HydroCel-256', 'GSN-HydroCel-257', 'GSN-HydroCel-32', 'GSN-HydroCel-64_1.0', 'GSN-HydroCel-65_1.0', 'biosemi128', 'biosemi16', 'biosemi160', 'biosemi256', 'biosemi32', 'biosemi64', 'easycap-M1', 'easycap-M10', 'mgh60', 'mgh70', 'standard_1005', 'standard_1020', 'standard_alphabetic', 'standard_postfixed', 'standard_prefixed' and 'standard_primed', but got 'nice' instead."
test_data.py:19: AssertionError
several things changed in mne with montage, we need to changed
CreateRaw
andtest_data
accordingly