Repository: mne-tools/mne-python

Issue:
[BUG] Issue with EEGLAB filenames
When reading a raw file into an [`mne.io.Raw`](https://martinos.org/mne/stable/generated/mne.io.Raw.html) object, we usually get an attribute "filenames", which points to the datafile.

For formats that have just a single file, such as `.cnt`, the `.filenames` attribute will be a tuple pointing to that single file:
```python
import mne
from mne.datasets import testing

f = op.join(testing.data_path(), 'CNT', 'scan41_short.cnt')
raw = mne.io.read_raw_cnt(f, None)
raw.filenames
>>>('/home/stefanappelhoff/mne_data/MNE-testing-data/CNT/scan41_short.cnt',)
```

For formats that have multiple files, such as BrainVision, `.filenames` will point to the data file.In the case of BrainVision this is to the `.eeg` file. (Actually, this might be considered a bit weird, as one could also expect the accompanying `.vmrk` and `.vhdr` files in the `.filenames` tuple. Is that a bug?)

Now the issue:

EEGLAB's `.set` format is basically a MATLAB structure which contains a field called `data`. This field can either be a string, pointing to a binary data file `.fdt`, or it can contain the data as an array already (no `.fdt` file necessary).

As expected, when we have `.set` and an accompanying `.fdt`, we get the following:
```python
f = op.join(testing.data_path(), 'EEGLAB', 'test_raw.set')
raw = mne.io.read_raw_eeglab(f)
raw.filenames
>>>('/home/stefanappelhoff/mne_data/MNE-testing-data/EEGLAB/test_raw.fdt',)
```

The bug arises when no `.fdt` is present and we thus have a "standalone" `.set` file:
```python
f = op.join(testing.data_path(), 'EEGLAB', 'test_raw_onefile.set')
raw = mne.io.read_raw_eeglab(f)
raw.filenames
>>>(None,)
```

Here, we get `(None,)`, while we would expect `('/home/stefanappelhoff/mne_data/MNE-testing-data/EEGLAB/test_raw_onefile.set',)`

------------
Next to the obvious bug it'd be great to get a comment on why `.filenames` only ever lists a tuple of length 1, even for multifile formats.


Discussion:
> Actually, this might be considered a bit weird, as one could also expect the accompanying .vmrk and .vhdr files in the .filenames tuple. Is that a bug?

We have not been strict about this, but the idea roughly is that doing `raw = read_raw_*` will have `raw.filenames` give the name of *one* file or directory that contains the data. For example in CTF you load a directory with many files, but `filenames` contains the `res4` data filename:
```
>>> raw = mne.io.read_raw_ctf(mne.datasets.testing.data_path() + '/CTF/catch-alp-good-f.ds')
>>> raw.filenames
('/home/larsoner/python/MNE-testing-data/CTF/catch-alp-good-f.ds/catch-alp-good-f.meg4',)
```
Then when you concat:
```
>>> raws = mne.concatenate_raws([raw.copy(), raw.copy()])
>>> raws.filenames
('/home/larsoner/python/MNE-testing-data/CTF/catch-alp-good-f.ds/catch-alp-good-f.meg4',
 '/home/larsoner/python/MNE-testing-data/CTF/catch-alp-good-f.ds/catch-alp-good-f.meg4')
```
So for `EEGLAB` it should probably not be `None` but rather the `.set` filename.

Resolving patch:
diff --git a/mne/io/eeglab/eeglab.py b/mne/io/eeglab/eeglab.py
--- a/mne/io/eeglab/eeglab.py
+++ b/mne/io/eeglab/eeglab.py
@@ -1,5 +1,6 @@
 # Authors: Mainak Jas <mainak.jas@telecom-paristech.fr>
 #          Jona Sassenhagen <jona.sassenhagen@gmail.com>
+#          Stefan Appelhoff <stefan.appelhoff@mailbox.org>
 #
 # License: BSD (3-clause)
 
@@ -385,8 +386,8 @@ def __init__(self, input_fname, montage, eog=(), event_id=None,
             data *= CAL
             data[-1] = self._event_ch
             super(RawEEGLAB, self).__init__(
-                info, data, last_samps=last_samps, orig_format='double',
-                verbose=verbose)
+                info, data, filenames=[input_fname], last_samps=last_samps,
+                orig_format='double', verbose=verbose)
 
     def _create_event_ch(self, events, n_samples=None):
         """Create the event channel."""


Test patch:
diff --git a/mne/io/eeglab/tests/test_eeglab.py b/mne/io/eeglab/tests/test_eeglab.py
--- a/mne/io/eeglab/tests/test_eeglab.py
+++ b/mne/io/eeglab/tests/test_eeglab.py
@@ -1,5 +1,6 @@
 # Author: Mainak Jas <mainak.jas@telecom-paristech.fr>
 #         Mikolaj Magnuski <mmagnuski@swps.edu.pl>
+#         Stefan Appelhoff <stefan.appelhoff@mailbox.org>
 #
 # License: BSD (3-clause)
 
@@ -79,6 +80,8 @@ def test_io_set_raw(fnames, tmpdir):
         raw3 = read_raw_eeglab(input_fname=raw_fname, montage=montage,
                                event_id=event_id)
         raw4 = read_raw_eeglab(input_fname=raw_fname, montage=montage)
+        assert raw0.filenames[0].endswith('.fdt')  # .set with additional .fdt
+        assert raw2.filenames[0].endswith('.set')  # standalone .set
         Epochs(raw0, find_events(raw0), event_id)
         epochs = Epochs(raw1, find_events(raw1), event_id)
         assert_equal(len(find_events(raw4)), 0)  # no events without event_id