Skip to content

Commit

Permalink
WIP: Add GSN-HydroCel-129
Browse files Browse the repository at this point in the history
  • Loading branch information
massich committed Sep 10, 2019
1 parent 2a873ec commit 6d14613
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
34 changes: 32 additions & 2 deletions mne/channels/_standard_montage_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,36 @@ def get_hydrocel_128():
)


def get_hydrocel_129():
fname = op.join(MONTAGE_PATH, 'GSN-HydroCel-129.sfp')

LPA_CH_NAME = 'FidT9'
NASION_CH_NAME = 'FidNz'
RPA_CH_NAME = 'FidT10'
with open(fname, 'r') as f:
lines = f.read().replace('\t', ' ').splitlines()

ch_names_, pos = [], []
for ii, line in enumerate(lines):
line = line.strip().split()
if len(line) > 0: # skip empty lines
if len(line) != 4: # name, x, y, z
raise ValueError("Malformed .sfp file in line " + str(ii))
this_name, x, y, z = line
ch_names_.append(this_name)
pos.append([float(cord) for cord in (x, y, z)])
pos = np.asarray(pos)

ch_pos = dict(zip(ch_names_, pos))
nasion = ch_pos.pop(NASION_CH_NAME).reshape(3, )
lpa = ch_pos.pop(LPA_CH_NAME).reshape(3, )
rpa = ch_pos.pop(RPA_CH_NAME).reshape(3, )

return make_dig_montage(
ch_pos=ch_pos, nasion=nasion, lpa=lpa, rpa=rpa, coord_frame='unknown',
)


def read_standard_montage(kind):
if kind == 'EGI_256':
dig_montage_A = get_egi_256()
Expand All @@ -142,6 +172,8 @@ def read_standard_montage(kind):
dig_montage_A = get_easycap_M10()
elif kind == 'GSN-HydroCel-128':
dig_montage_A = get_hydrocel_128()
elif kind == 'GSN-HydroCel-129':
dig_montage_A = get_hydrocel_129()

else:
montage = read_montage(kind) # XXX: reader needs to go out!
Expand All @@ -154,5 +186,3 @@ def read_standard_montage(kind):
# dig_montage_B is to create RawArray(.., montage=montage)

return dig_montage_A


18 changes: 15 additions & 3 deletions mne/channels/tests/test_standard_montage.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def test_read_standard_montage_egi_256():
# 'EGI_256',
# 'easycap-M1',
# 'easycap-M10'
'GSN-HydroCel-128',
# 'GSN-HydroCel-129',
# 'GSN-HydroCel-128',
'GSN-HydroCel-129',
# 'GSN-HydroCel-256',
# 'GSN-HydroCel-257',
# 'GSN-HydroCel-32',
Expand All @@ -219,7 +219,7 @@ def test_read_standard_montage_egi_256():
])
def test_foo(kind):
"""Test difference between old and new standard montages."""
# import pdb; pdb.set_trace()
import pdb; pdb.set_trace()
mont = read_montage(kind)
digm = read_standard_montage(kind)
eeg_loc = np.array([ch['r'] for ch in _get_dig_eeg(digm.dig)])
Expand Down Expand Up @@ -247,6 +247,18 @@ def test_hydrocell_128():
assert_array_equal(actual[kk], expected[kk])


def test_hydrocell_129():
"""Test difference between old and new standard montages."""
mont = read_montage('GSN-HydroCel-128')
digm = read_standard_montage('GSN-HydroCel-128')
eeg_loc = np.array([ch['r'] for ch in _get_dig_eeg(digm.dig)])

# Assert we are reading the same thing. (notice dig reorders chnames)
actual = dict(zip(digm.ch_names, eeg_loc))
expected = dict(zip(mont.ch_names, mont.pos))
for kk in actual:
assert_array_equal(actual[kk], expected[kk])

def test_easycaps_are_indeed_different():
"""Test something fishy with easycaps."""
m1 = read_montage('easycap-M1')
Expand Down

0 comments on commit 6d14613

Please sign in to comment.