Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ BUG

- Fix field mapping :func:`mne.make_field_map` and MEG bad channel interpolation functions (e.g., :meth:`mne.Evoked.interpolate_bads`) to choose a better number of components during pseudoinversion when few channels are available, by `Eric Larson`_

- Fix bug in :func:`mne.io.read_raw_brainvision`, changed default to read coordinate information if available and added test, by `Jesper Duemose Nielsen`_

API
~~~
- Add ``skip_by_annotation`` to :meth:`mne.io.Raw.filter` to process data concatenated with e.g. :func:`mne.concatenate_raws` separately. This parameter will default to the old behavior (treating all data as a single block) in 0.15 but will change to ``skip_by_annotation='edge'``, which will separately filter the concatenated chunks separately, in 0.16. This should help prevent potential problems with filter-induced ringing in concatenated files, by `Eric Larson`_
Expand Down
35 changes: 24 additions & 11 deletions mne/io/brainvision/brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ class RawBrainVision(BaseRaw):
vhdr_fname : str
Path to the EEG header file.
montage : str | None | instance of Montage
Path or instance of montage containing electrode positions.
If None, sensor locations are (0,0,0). See the documentation of
:func:`mne.channels.read_montage` for more information.
Path or instance of montage containing electrode positions. If None,
read sensor locations from header file if present, otherwise (0, 0, 0).
See the documentation of :func:`mne.channels.read_montage` for more
information.
eog : list or tuple
Names of channels or list of indices that should be designated
EOG channels. Values should correspond to the vhdr file.
Expand Down Expand Up @@ -354,10 +355,11 @@ def _get_vhdr_info(vhdr_fname, eog, misc, scale, montage):
scale : float
The scaling factor for EEG data. Unless specified otherwise by
header file, units are in microvolts. Default scale factor is 1.
montage : str | True | None | instance of Montage
Path or instance of montage containing electrode positions.
If None, sensor locations are (0,0,0). See the documentation of
:func:`mne.channels.read_montage` for more information.
montage : str | None | instance of Montage
Path or instance of montage containing electrode positions. If None,
read sensor locations from header file if present, otherwise (0, 0, 0).
See the documentation of :func:`mne.channels.read_montage` for more
information.

Returns
-------
Expand Down Expand Up @@ -488,20 +490,31 @@ def _get_vhdr_info(vhdr_fname, eog, misc, scale, montage):
misc = list(misc_chs.keys()) if misc == 'auto' else misc

# create montage
if montage is True:
from ...transforms import _sphere_to_cartesian
if cfg.has_section('Coordinates') and montage is None:
from ...transforms import _sph_to_cart
from ...channels.montage import Montage
montage_pos = list()
montage_names = list()
to_misc = list()
for ch in cfg.items('Coordinates'):
montage_names.append(ch_dict[ch[0]])
ch_name = ch_dict[ch[0]]
montage_names.append(ch_name)
radius, theta, phi = map(float, ch[1].split(','))
# 1: radius, 2: theta, 3: phi
pos = _sphere_to_cartesian(r=radius, theta=theta, phi=phi)
pol = np.deg2rad(theta)
az = np.deg2rad(phi)
pos = _sph_to_cart(np.array([[radius * 85., az, pol]]))[0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is the radius multiplied by 0.85 here?
And what makes us sure that theta and phi are given in radians and not degrees?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

multiplier is 85.0, not 0.85. But that doesn't answer your question.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

for the second question: the code assumes theta and phi are in degrees, and they get transformed to radians on the lines above (when they're converted to pol and az).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

most likely a hack that works. See: #4493 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hehe, apparently I am not the first one to misread the 85 as a 0.85, see Alex's comment: #4493 (comment) and yes, thanks for the correction @drammock --> but do you know why?

Thanks for linking to that comment Mainak ... although this leads to a further comment #4493 (comment) saying that this Hack was taken from

elif ext == '.bvef':
# 'BrainVision Electrodes File' format
root = ElementTree.parse(fname).getroot()
ch_names_ = [s.text for s in root.findall("./Electrode/Name")]
theta = [float(s.text) for s in root.findall("./Electrode/Theta")]
pol = np.deg2rad(np.array(theta))
phi = [float(s.text) for s in root.findall("./Electrode/Phi")]
az = np.deg2rad(np.array(phi))
pos = _sph_to_cart(np.array([np.ones(len(az)) * 85., az, pol]).T)

So my question remains unanswered. I'll continue the discussion in #4109

if (pos == 0).all() and ch_name not in list(eog) + misc:
to_misc.append(ch_name)
montage_pos.append(pos)
montage_sel = np.arange(len(montage_pos))
montage = Montage(montage_pos, montage_names, 'Brainvision',
montage_sel)
if len(to_misc) > 0:
misc += to_misc
warn('No coordinate information found for channels {}. '
'Setting channel types to misc. To avoid this warning, set '
'channel types explicitly.'.format(to_misc))

ch_names[-1] = 'STI 014'
cals[-1] = 1.
Expand Down
15 changes: 15 additions & 0 deletions mne/io/brainvision/tests/test_brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,19 @@ def test_events():
assert_equal(raw.info['chs'][-1]['ch_name'], 'STI 014')


def test_brainvision_with_montage():
"""Test reading embedded montage information"""
raw = read_raw_brainvision(vhdr_v2_path, eog=eog, misc=['ReRef'])
for i, d in enumerate(raw.info['dig'], 1):
assert_equal(d['coord_frame'], FIFF.FIFFV_COORD_HEAD)
assert_equal(d['ident'], i)
assert_equal(d['kind'], FIFF.FIFFV_POINT_EEG)
assert_equal(len(d['r']), 3)

raw_none = read_raw_brainvision(vhdr_v2_path)
for r, n in zip(raw.info['chs'], raw_none.info['chs']):
if r['kind'] != n['kind']:
assert_array_equal(r['loc'], n['loc'])


run_tests_if_main()