# read\_dig\_dat() does not work

**URL:** <https://mne.discourse.group/t/read-dig-dat-does-not-work/3477>\
**Category:** Support & Discussions\
**Tags:** preprocessing, eeg, montage\
**Created:** [July 31, 2021, 2:33pm UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477 "2021-07-31T14:33:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![leosunpsy](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@leosunpsy](https://mne.discourse.group/u/leosunpsy)\
**Post date:** [July 31, 2021, 2:33pm UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477/1 "2021-07-31T14:33:06Z")

</div>

- MNE-Python version: 0.23.0
- operating system: Windows 10

`montage = mne.channels.read_dig_dat(os.path.join(dataDir,'SynAmps2_Quik_Cap64.DAT'))`

When i used the read\_dig\_dat() to read the SynAmps2\_Quik\_Cap64.DAT, this function did not work. I looked over the source code and found that the code handles five columns of data, but Compumedics only provides four columns for Cap64. Could anyone give me some advice on how to solve this problem?

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [July 31, 2021, 3:02pm UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477/2 "2021-07-31T15:02:34Z")

</div>

Hello @leosunpsy and welcome to the forum!

Could you share the problematic file so the developers can have a look? Thanks!

---

<div class="post-metadata">

**Author:** ![leosunpsy](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@leosunpsy](https://mne.discourse.group/u/leosunpsy)\
**Post date:** [July 31, 2021, 3:42pm UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477/3 "2021-07-31T15:42:21Z")

</div>

Hi, @richard. The SynAmps2\_Quik\_Cap64.DAT file can be download at [here](https://compumedicsneuroscan.com/scan-acquire-configuration-files/). I do not know how to directly upload files in the forum, please forgive me!  
Thanks for your reply.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [July 31, 2021, 4:15pm UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477/4 "2021-07-31T16:15:31Z")

</div>

Thank you! The format of this file is currently not supported by MNE-Python. It would be possible (and not too difficult) to add support for it, but somebody would have to do it. I’d be willing to give it a shot personally, but I’ll be busy for the next couple of days. If you can wait that long, I’d be glad to help.

In the meantime, perhaps you could simply use our built-in 10-20 standard montage? It won’t give you the **precise** locations, but it might be good enough to move on with your sensor-level analysis? To do that, you can call

```python
raw.set_montage(montage='standard_1020')

```

Best wishes,

Richard

---

<div class="post-metadata">

**Author:** ![leosunpsy](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@leosunpsy](https://mne.discourse.group/u/leosunpsy)\
**Post date:** [August 1, 2021, 1:37am UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477/5 "2021-08-01T01:37:32Z")

</div>

@richard OK Thanks for your advice.

---

<div class="post-metadata">

**Author:** ![leosunpsy](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@leosunpsy](https://mne.discourse.group/u/leosunpsy)\
**Post date:** [August 1, 2021, 2:49am UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477/6 "2021-08-01T02:49:12Z")

</div>

Hi @richard, I have solved the problem. The modified code of the read\_dig\_dat function is as follows:

```python
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)

```

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [August 1, 2021, 6:28am UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477/7 "2021-08-01T06:28:56Z")

</div>

Nice! Would you like to try and make a pull request so your improvement can be officially included in the next release of MNE-Python?

---

<div class="post-metadata">

**Author:** ![leosunpsy](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@leosunpsy](https://mne.discourse.group/u/leosunpsy)\
**Post date:** [August 1, 2021, 7:16am UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477/8 "2021-08-01T07:16:34Z")

</div>

@richard I have made a pull request. ✌

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [August 1, 2021, 8:43am UTC](https://mne.discourse.group/t/read-dig-dat-does-not-work/3477/9 "2021-08-01T08:43:48Z")

</div>

Thank you! We will review the PR soon. It may take a few small adjustments until it can be merged.

For reference, the PR can be found here:

> <https://github.com/mne-tools/mne-python/pull/9631>
>
> 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)
