Skip to content

Commit 6d14613

Browse files
author
Joan Massich
committed
WIP: Add GSN-HydroCel-129
1 parent 2a873ec commit 6d14613

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

mne/channels/_standard_montage_utils.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,36 @@ def get_hydrocel_128():
132132
)
133133

134134

135+
def get_hydrocel_129():
136+
fname = op.join(MONTAGE_PATH, 'GSN-HydroCel-129.sfp')
137+
138+
LPA_CH_NAME = 'FidT9'
139+
NASION_CH_NAME = 'FidNz'
140+
RPA_CH_NAME = 'FidT10'
141+
with open(fname, 'r') as f:
142+
lines = f.read().replace('\t', ' ').splitlines()
143+
144+
ch_names_, pos = [], []
145+
for ii, line in enumerate(lines):
146+
line = line.strip().split()
147+
if len(line) > 0: # skip empty lines
148+
if len(line) != 4: # name, x, y, z
149+
raise ValueError("Malformed .sfp file in line " + str(ii))
150+
this_name, x, y, z = line
151+
ch_names_.append(this_name)
152+
pos.append([float(cord) for cord in (x, y, z)])
153+
pos = np.asarray(pos)
154+
155+
ch_pos = dict(zip(ch_names_, pos))
156+
nasion = ch_pos.pop(NASION_CH_NAME).reshape(3, )
157+
lpa = ch_pos.pop(LPA_CH_NAME).reshape(3, )
158+
rpa = ch_pos.pop(RPA_CH_NAME).reshape(3, )
159+
160+
return make_dig_montage(
161+
ch_pos=ch_pos, nasion=nasion, lpa=lpa, rpa=rpa, coord_frame='unknown',
162+
)
163+
164+
135165
def read_standard_montage(kind):
136166
if kind == 'EGI_256':
137167
dig_montage_A = get_egi_256()
@@ -142,6 +172,8 @@ def read_standard_montage(kind):
142172
dig_montage_A = get_easycap_M10()
143173
elif kind == 'GSN-HydroCel-128':
144174
dig_montage_A = get_hydrocel_128()
175+
elif kind == 'GSN-HydroCel-129':
176+
dig_montage_A = get_hydrocel_129()
145177

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

156188
return dig_montage_A
157-
158-

mne/channels/tests/test_standard_montage.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ def test_read_standard_montage_egi_256():
195195
# 'EGI_256',
196196
# 'easycap-M1',
197197
# 'easycap-M10'
198-
'GSN-HydroCel-128',
199-
# 'GSN-HydroCel-129',
198+
# 'GSN-HydroCel-128',
199+
'GSN-HydroCel-129',
200200
# 'GSN-HydroCel-256',
201201
# 'GSN-HydroCel-257',
202202
# 'GSN-HydroCel-32',
@@ -219,7 +219,7 @@ def test_read_standard_montage_egi_256():
219219
])
220220
def test_foo(kind):
221221
"""Test difference between old and new standard montages."""
222-
# import pdb; pdb.set_trace()
222+
import pdb; pdb.set_trace()
223223
mont = read_montage(kind)
224224
digm = read_standard_montage(kind)
225225
eeg_loc = np.array([ch['r'] for ch in _get_dig_eeg(digm.dig)])
@@ -247,6 +247,18 @@ def test_hydrocell_128():
247247
assert_array_equal(actual[kk], expected[kk])
248248

249249

250+
def test_hydrocell_129():
251+
"""Test difference between old and new standard montages."""
252+
mont = read_montage('GSN-HydroCel-128')
253+
digm = read_standard_montage('GSN-HydroCel-128')
254+
eeg_loc = np.array([ch['r'] for ch in _get_dig_eeg(digm.dig)])
255+
256+
# Assert we are reading the same thing. (notice dig reorders chnames)
257+
actual = dict(zip(digm.ch_names, eeg_loc))
258+
expected = dict(zip(mont.ch_names, mont.pos))
259+
for kk in actual:
260+
assert_array_equal(actual[kk], expected[kk])
261+
250262
def test_easycaps_are_indeed_different():
251263
"""Test something fishy with easycaps."""
252264
m1 = read_montage('easycap-M1')

0 commit comments

Comments
 (0)