-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[draft] new reader for curry files, using curry-python-reader code #13176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6de026b
e640023
d533a5f
63c4da3
a8286d8
0a5a82a
4cd41d6
d338280
e3b91d8
7e8f1cc
8ec4a17
7eea5aa
5afa604
07d4256
e4ae650
b005c57
c75a8e4
99e968d
0364225
e0c7eee
ec4a25c
1e01667
3ffd6aa
3cca0d3
5de6062
2495cd9
feb7def
e850201
e452a1a
7260675
a43d363
fd15e6e
051da8b
168eb8b
0ce2f77
e8016ad
2768f82
966cc6a
20c76a8
0b87c82
c3677b9
3b57bd4
a3caad0
2c5f1a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
New reader for Neuroscan Curry files, using the curry-python-reader module, by `Dominik Welke`_. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Read impedances and montage from Neuroscan Curry files, by `Dominik Welke`_. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -94,3 +94,49 @@ def _parse_brainvision_dig_montage(fname, scale): | |||||
ch_pos=dig_ch_pos, | ||||||
coord_frame="unknown", | ||||||
) | ||||||
|
||||||
|
||||||
def _read_dig_montage_curry(ch_names, ch_types, ch_pos, landmarks, landmarkslabels): | ||||||
import re | ||||||
|
||||||
# scale ch_pos to m?! | ||||||
ch_pos /= 1000.0 | ||||||
landmarks /= 1000.0 | ||||||
# channel locations | ||||||
# what about misc without pos? can they mess things up if unordered? | ||||||
assert len(ch_pos) >= (ch_types.count("mag") + ch_types.count("eeg")) | ||||||
assert len(ch_pos) == (ch_types.count("mag") + ch_types.count("eeg")) | ||||||
ch_pos_eeg = { | ||||||
ch_names[i]: ch_pos[i, :3] for i, t in enumerate(ch_types) if t == "eeg" | ||||||
} | ||||||
# landmarks and headshape | ||||||
landmark_dict = dict(zip(landmarkslabels, landmarks)) | ||||||
for k in ["Nas", "RPA", "LPA"]: | ||||||
if k not in landmark_dict.keys(): | ||||||
landmark_dict[k] = None | ||||||
if len(landmarkslabels) > 0: | ||||||
hpi_pos = landmarks[ | ||||||
[i for i, n in enumerate(landmarkslabels) if re.match("HPI[1-99]", n)], : | ||||||
] | ||||||
else: | ||||||
hpi_pos = None | ||||||
if len(landmarkslabels) > 0: | ||||||
hsp_pos = landmarks[ | ||||||
[i for i, n in enumerate(landmarkslabels) if re.match("H[1-99]", n)], : | ||||||
] | ||||||
else: | ||||||
hsp_pos = None | ||||||
# compile dig montage positions for eeg | ||||||
if len(ch_pos_eeg) > 0: | ||||||
return dict( | ||||||
ch_pos=ch_pos_eeg, | ||||||
nasion=landmark_dict["Nas"], | ||||||
lpa=landmark_dict["LPA"], | ||||||
rpa=landmark_dict["RPA"], | ||||||
hsp=hsp_pos, | ||||||
hpi=hpi_pos, | ||||||
coord_frame="head", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless you've transformed this to the head coord frame already (and it doesn't look like you have?) this should probalby be
Suggested change
that way it'll transform everything to head coords using lpa/nasion/rpa |
||||||
) | ||||||
else: # not recorded? | ||||||
warn("No eeg sensor locations found in file.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should be an error if you try to read dig and can't |
||||||
return None |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -773,6 +773,7 @@ def read_dig_dat(fname): | |
See Also | ||
-------- | ||
read_dig_captrak | ||
read_dig_curry | ||
read_dig_dat | ||
read_dig_egi | ||
read_dig_fif | ||
|
@@ -842,6 +843,7 @@ def read_dig_fif(fname, *, verbose=None): | |
read_dig_dat | ||
read_dig_egi | ||
read_dig_captrak | ||
read_dig_curry | ||
read_dig_polhemus_isotrak | ||
read_dig_hpts | ||
read_dig_localite | ||
|
@@ -892,6 +894,7 @@ def read_dig_hpts(fname, unit="mm"): | |
-------- | ||
DigMontage | ||
read_dig_captrak | ||
read_dig_curry | ||
read_dig_dat | ||
read_dig_egi | ||
read_dig_fif | ||
|
@@ -985,6 +988,7 @@ def read_dig_egi(fname): | |
-------- | ||
DigMontage | ||
read_dig_captrak | ||
read_dig_curry | ||
read_dig_dat | ||
read_dig_fif | ||
read_dig_hpts | ||
|
@@ -1017,6 +1021,7 @@ def read_dig_captrak(fname): | |
See Also | ||
-------- | ||
DigMontage | ||
read_dig_curry | ||
read_dig_dat | ||
read_dig_egi | ||
read_dig_fif | ||
|
@@ -1031,6 +1036,50 @@ def read_dig_captrak(fname): | |
return make_dig_montage(**data) | ||
|
||
|
||
def read_dig_curry(fname): | ||
"""Read electrode locations from Neuroscan Curry files. | ||
|
||
Parameters | ||
---------- | ||
fname : path-like | ||
A valid Curry file. | ||
|
||
Returns | ||
------- | ||
montage : instance of DigMontage | None | ||
The montage. | ||
|
||
See Also | ||
-------- | ||
DigMontage | ||
read_dig_captrak | ||
read_dig_dat | ||
read_dig_egi | ||
read_dig_fif | ||
read_dig_hpts | ||
read_dig_localite | ||
read_dig_polhemus_isotrak | ||
make_dig_montage | ||
""" | ||
from ..io.curry.curry import ( | ||
_check_curry_filename, | ||
_extract_curry_info, | ||
) | ||
from ._dig_montage_utils import _read_dig_montage_curry | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to nest this one |
||
|
||
# TODO - REVIEW NEEDED | ||
# API? do i need to add this in the docs somewhere? | ||
fname = _check_curry_filename(fname) | ||
(_, _, ch_names, ch_types, ch_pos, landmarks, landmarkslabels, _, _, _, _, _, _) = ( | ||
_extract_curry_info(fname) | ||
) | ||
data = _read_dig_montage_curry( | ||
ch_names, ch_types, ch_pos, landmarks, landmarkslabels | ||
) | ||
mont = make_dig_montage(**data) if data else None | ||
return mont | ||
|
||
|
||
def read_dig_localite(fname, nasion=None, lpa=None, rpa=None): | ||
"""Read Localite .csv file. | ||
|
||
|
@@ -1054,6 +1103,7 @@ def read_dig_localite(fname, nasion=None, lpa=None, rpa=None): | |
-------- | ||
DigMontage | ||
read_dig_captrak | ||
read_dig_curry | ||
read_dig_dat | ||
read_dig_egi | ||
read_dig_fif | ||
|
@@ -1455,6 +1505,7 @@ def read_dig_polhemus_isotrak(fname, ch_names=None, unit="m"): | |
make_dig_montage | ||
read_polhemus_fastscan | ||
read_dig_captrak | ||
read_dig_curry | ||
read_dig_dat | ||
read_dig_egi | ||
read_dig_fif | ||
|
@@ -1815,8 +1866,8 @@ def make_standard_montage(kind, head_size="auto"): | |
Notes | ||
----- | ||
Individualized (digitized) electrode positions should be read in using | ||
:func:`read_dig_captrak`, :func:`read_dig_dat`, :func:`read_dig_egi`, | ||
:func:`read_dig_fif`, :func:`read_dig_polhemus_isotrak`, | ||
:func:`read_dig_captrak`, :func:`read_dig_curry`, :func:`read_dig_dat`, | ||
:func:`read_dig_egi`, :func:`read_dig_fif`, :func:`read_dig_polhemus_isotrak`, | ||
:func:`read_dig_hpts`, or manually made with :func:`make_dig_montage`. | ||
|
||
.. versionadded:: 0.19.0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to nest this, should go at the top