Skip to content

Commit b02c14c

Browse files
committed
Feat: montage now supports .pos information file
1 parent 1a89099 commit b02c14c

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

mne/channels/montage.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,48 @@ def _read_isotrak_elp_points(fname):
13831383
}
13841384

13851385

1386+
def _read_isotrak_pos_points(fname):
1387+
"""Read Polhemus Isotrak digitizer data from a ``.pos`` file.
1388+
1389+
Parameters
1390+
----------
1391+
fname : path-like
1392+
The filepath of .pos Polhemus Isotrak file.
1393+
1394+
Returns
1395+
-------
1396+
out : dict of arrays
1397+
The dictionary containing locations for 'nasion', 'lpa', 'rpa'
1398+
and 'points'.
1399+
"""
1400+
with open(fname) as fid:
1401+
file_str = fid.read()
1402+
1403+
# Get all lines which are points
1404+
int_pat = r"[+-]?\d+"
1405+
float_pat = r"[+-]?(?:\d+\.\d*|\d*\.\d+)(?:[eE][+-]?\d+)?"
1406+
pattern_points = re.compile(
1407+
rf"^\s*({int_pat})\s+({float_pat})\s+({float_pat})\s+({float_pat})",
1408+
re.MULTILINE,
1409+
)
1410+
points = pattern_points.findall(file_str)
1411+
1412+
# Get nasion, left and right
1413+
label_pat = r"[A-Za-z]+"
1414+
pattern_labels = re.compile(
1415+
rf"^\s*({label_pat})\s+({float_pat})\s+({float_pat})\s+({float_pat})",
1416+
re.MULTILINE,
1417+
)
1418+
labels = pattern_labels.findall(file_str)
1419+
1420+
return {
1421+
"nasion": [x[1:] for x in labels if x[0] == "nasion"][0],
1422+
"lpa": [x[1:] for x in labels if x[0] == "left"][0],
1423+
"rpa": [x[1:] for x in labels if x[0] == "right"][0],
1424+
"points": [x[1:] for x in points],
1425+
}
1426+
1427+
13861428
def _read_isotrak_hsp_points(fname):
13871429
"""Read Polhemus Isotrak digitizer data from a ``.hsp`` file.
13881430
@@ -1459,7 +1501,7 @@ def read_dig_polhemus_isotrak(fname, ch_names=None, unit="m"):
14591501
read_dig_fif
14601502
read_dig_localite
14611503
"""
1462-
VALID_FILE_EXT = (".hsp", ".elp", ".eeg")
1504+
VALID_FILE_EXT = (".hsp", ".elp", ".eeg", ".pos")
14631505
fname = str(_check_fname(fname, overwrite="read", must_exist=True))
14641506
_scale = _check_unit_and_get_scaling(unit)
14651507

@@ -1468,6 +1510,8 @@ def read_dig_polhemus_isotrak(fname, ch_names=None, unit="m"):
14681510

14691511
if ext == ".elp":
14701512
data = _read_isotrak_elp_points(fname)
1513+
elif ext == ".pos":
1514+
data = _read_isotrak_pos_points(fname)
14711515
else:
14721516
# Default case we read points as hsp since is the most likely scenario
14731517
data = _read_isotrak_hsp_points(fname)

0 commit comments

Comments
 (0)