Skip to content
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

make the mne.channels.read_dig_dat() to support the dat file of neuroscan 64 channels #9631

Closed
wants to merge 2 commits into from

Conversation

leosunpsy
Copy link

Fixes #9631
The mne.channels.read_dig_dat() function does not support the dat file of neuroscan 64 channels. I have solved the problem. The modified code of the read_dig_dat function is as follows:

def read_dig_dat(fname):
    r"""Read electrode positions from a ``*.dat`` file.

    .. Warning::
        This function was implemented based on ``*.dat`` files available from
        `Compumedics <https://compumedicsneuroscan.com/scan-acquire-
        configuration-files/>`__ and might not work as expected with novel
        files. If it does not read your files correctly please contact the
        mne-python developers.

    Parameters
    ----------
    fname : path-like
        File from which to read electrode locations.

    Returns
    -------
    montage : DigMontage
        The montage.

    See Also
    --------
    read_dig_captrak
    read_dig_dat
    read_dig_egi
    read_dig_fif
    read_dig_hpts
    read_dig_polhemus_isotrak
    make_dig_montage

    Notes
    -----
    ``*.dat`` files are plain text files and can be inspected and amended with
    a plain text editor.
    """
    from ._standard_montage_utils import _check_dupes_odict
    fname = _check_fname(fname, overwrite='read', must_exist=True)

    with open(fname, 'r') as fid:
        lines = fid.readlines()

    ch_names, poss = list(), list()
    nasion = lpa = rpa = None
    for i, line in enumerate(lines):
        items = line.split()
        if not items:
            continue
        elif not (len(items) == 4 or len(items) == 5):
            raise ValueError(
                "Error reading %s, line %s has unexpected number of entries:\n"
                "%s" % (fname, i, line.rstrip()))
        
        if len(items) == 5:
            num = items[1]
            if num == '67':
                continue  # centroid
            pos = np.array([float(item) for item in items[2:]])
            if num == '78':
                nasion = pos
            elif num == '76':
                lpa = pos
            elif num == '82':
                rpa = pos
            else:
                ch_names.append(items[0])
                poss.append(pos)
        elif len(items) == 4:
            label = items[0]
            if label == 'Centroid':
                continue  # centroid
            pos = np.array([float(item) for item in items[1:]])
            if label == 'Nasion':
                nasion = pos
            elif label == 'Left':
                lpa = pos
            elif label == 'Right':
                rpa = pos
            else:
                ch_names.append(items[0])
                poss.append(pos)            
    
    electrodes = _check_dupes_odict(ch_names, poss)
    return make_dig_montage(electrodes, nasion, lpa, rpa)

@welcome
Copy link

welcome bot commented Aug 1, 2021

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴🏽‍♂️

@hoechenberger
Copy link
Member

Hello @leosunpsy, thank you very much for contributing to MNE-Python!

It appears something went wrong with the commits included in this PR -- the changes you wanted to contribute aren't here. Could you have a look at your branch again?

@hoechenberger
Copy link
Member

Also you should try to build your changes on top of the "main" branch :) after that, we can try to backport them to 0.23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants