internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: mne-tools/mne-bids

Issue:
prune dependencies that we do not really depend on
As became apparent in a discussion with @agramfort and @jasmainak, we probably do not need the `environment.yml` and instead should rely on minimal dependencies such as numpy, scipy, and matplotlib.

if we decide to keep the `environment.yml` for convenience during installation, we should at least prune it.






Discussion:
+1, we certainly don't need `environment.yml` for `Travis` and maybe not even for `Circle`. Do you want to take a stab at it?
Also, the `pandas` dependency could eventually go away. We use it only for converting dictionary to `tsv`. I think it can be achieved also with the `csv` module + plain numpy
yes, PR is about to come. For the pandas dependency I suggest a separate PR that will introduce two or three new private functions in utils.py to replace the functionality

Resolving patch:
diff --git a/mne_bids/datasets.py b/mne_bids/datasets.py
--- a/mne_bids/datasets.py
+++ b/mne_bids/datasets.py
@@ -10,7 +10,7 @@
 import os.path as op
 import shutil
 import tarfile
-import requests
+from six.moves import urllib
 
 from mne.utils import _fetch_file
 
@@ -85,10 +85,10 @@ def fetch_brainvision_testing_data(data_path=None):
 
     for f_ending in file_endings:
         url = base_url + f_ending
-        response = requests.get(url)
+        response = urllib.request.urlopen(url)
 
         fname = os.path.join(data_path, 'test' + f_ending)
         with open(fname, 'wb') as fout:
-            fout.write(response.content)
+            fout.write(response.read())
 
     return data_path


Test patch:
Repository: mne-tools/mne-bids

Issue:
[MAINT] Avoid using reserved keywords/funcs as variable names
I noticed this: https://github.com/mne-tools/mne-bids/blob/master/mne_bids/utils.py#L29

where the `dir` clashes with a built-in function called `dir`.

Fix coming from me with some more ENHs


Discussion:

Resolving patch:
diff --git a/mne_bids/utils.py b/mne_bids/utils.py
--- a/mne_bids/utils.py
+++ b/mne_bids/utils.py
@@ -25,12 +25,12 @@
 from .io import _parse_ext
 
 
-def print_dir_tree(dir):
-    """Recursively print a directory tree starting from `dir`."""
-    if not op.exists(dir):
-        raise ValueError('Directory does not exist: {}'.format(dir))
+def print_dir_tree(folder):
+    """Recursively print a directory tree starting from `folder`."""
+    if not op.exists(folder):
+        raise ValueError('Directory does not exist: {}'.format(folder))
 
-    for root, dirs, files in os.walk(dir):
+    for root, dirs, files in os.walk(folder):
         path = root.split(os.sep)
         print('|%s %s' % ((len(path) - 1) * '---', op.basename(root)))
         for file in files:


Test patch:
Repository: mne-tools/mne-bids

Issue:
[BUG] part-01 is written for fif file even if there is one part
This one is for @teonbrooks :-)


Discussion:

Resolving patch:
diff --git a/mne_bids/mne_bids.py b/mne_bids/mne_bids.py
--- a/mne_bids/mne_bids.py
+++ b/mne_bids/mne_bids.py
@@ -726,7 +726,8 @@ def write_raw_bids(raw, bids_basename, output_path, events_data=None,
             split_naming = 'bids'
             raw.save(bids_fname, split_naming=split_naming, overwrite=True)
         else:
-            raw.save(bids_fname, overwrite=True, split_naming='bids')
+            # This ensures that single FIF files do not have the part param
+            raw.save(bids_fname, overwrite=True, split_naming='neuromag')
 
     # CTF data is saved in a directory
     elif ext == '.ds':


Test patch:
diff --git a/mne_bids/tests/test_mne_bids.py b/mne_bids/tests/test_mne_bids.py
--- a/mne_bids/tests/test_mne_bids.py
+++ b/mne_bids/tests/test_mne_bids.py
@@ -14,6 +14,7 @@
 import os
 import os.path as op
 import pytest
+from glob import glob
 
 import pandas as pd
 
@@ -72,8 +73,11 @@ def test_fif():
     raw.save(raw_fname2)
 
     bids_basename2 = bids_basename.replace(subject_id, subject_id2)
-    write_raw_bids(raw, bids_basename2, output_path, events_data=events_fname,
-                   event_id=event_id, overwrite=False)
+    raw = mne.io.read_raw_fif(raw_fname2)
+    bids_output_path = write_raw_bids(raw, bids_basename2, output_path,
+                                      events_data=events_fname,
+                                      event_id=event_id, overwrite=False)
+
     # check that the overwrite parameters work correctly for the participant
     # data
     # change the gender but don't force overwrite.
@@ -107,6 +111,29 @@ def test_fif():
 
     assert op.exists(op.join(output_path, 'participants.tsv'))
 
+    # asserting that single fif files do not include the part key
+    files = glob(op.join(bids_output_path, 'sub-' + subject_id2,
+                         'ses-' + subject_id2, 'meg', '*.fif'))
+    for ii, FILE in enumerate(files):
+        assert 'part' not in FILE
+    assert ii < 1
+
+    # check that split files have part key
+    raw = mne.io.read_raw_fif(raw_fname)
+    data_path3 = _TempDir()
+    raw_fname3 = op.join(data_path3, 'sample_audvis_raw.fif')
+    raw.save(raw_fname3, buffer_size_sec=1.0, split_size='10MB',
+             split_naming='neuromag', overwrite=True)
+    raw = mne.io.read_raw_fif(raw_fname3)
+    subject_id3 = '03'
+    bids_basename3 = bids_basename.replace(subject_id, subject_id3)
+    bids_output_path = write_raw_bids(raw, bids_basename3, output_path,
+                                      overwrite=False)
+    files = glob(op.join(bids_output_path, 'sub-' + subject_id3,
+                         'ses-' + subject_id3, 'meg', '*.fif'))
+    for FILE in files:
+        assert 'part' in FILE
+
 
 def test_kit():
     """Test functionality of the write_raw_bids conversion for KIT data."""
Repository: mne-tools/mne-bids

Issue:
wrong CTF files names with write_raw_bids
Hi, 
`write_raw_bids` does not copy the new BIDS name of the CTF folder (i.e. sub-01_ses-01_task-01.ds) for each of the files inside the folder (like .res4 or .meg4)
However, when reading raw CTF file with `mne.read_raw_ctf`, the name of the .ds folder need to be the same that the files that are in this .ds folder.
Is it possible to make `write_raw_bids` not only copy the files in the .ds folder but also change the name of these files to reflect the new name of the .ds folder?
I can try to make a PR.
Thank you, 
Romain



Discussion:
@romquentin yes I found this issue too in [my PR](https://github.com/mne-tools/mne-bids/pull/135/files#r243751864). Help in fixing this would be more than welcome!

Resolving patch:
diff --git a/mne_bids/mne_bids.py b/mne_bids/mne_bids.py
--- a/mne_bids/mne_bids.py
+++ b/mne_bids/mne_bids.py
@@ -31,7 +31,7 @@
 from .utils import (make_bids_basename, make_bids_folders,
                     make_dataset_description, _write_json, _write_tsv,
                     _read_events, _mkdir_p, _age_on_date,
-                    copyfile_brainvision, copyfile_eeglab,
+                    copyfile_brainvision, copyfile_eeglab, copyfile_ctf,
                     _infer_eeg_placement_scheme, _parse_bids_filename,
                     _handle_kind)
 from .io import _parse_ext, ALLOWED_EXTENSIONS, reader
@@ -742,9 +742,9 @@ def write_raw_bids(raw, bids_basename, output_path, events_data=None,
             # This ensures that single FIF files do not have the part param
             raw.save(bids_fname, overwrite=True, split_naming='neuromag')
 
-    # CTF data is saved in a directory
+    # CTF data is saved and renamed in a directory
     elif ext == '.ds':
-        sh.copytree(raw_fname, bids_fname)
+        copyfile_ctf(raw_fname, bids_fname)
     # BrainVision is multifile, copy over all of them and fix pointers
     elif ext == '.vhdr':
         copyfile_brainvision(raw_fname, bids_fname)
diff --git a/mne_bids/utils.py b/mne_bids/utils.py
--- a/mne_bids/utils.py
+++ b/mne_bids/utils.py
@@ -503,6 +503,29 @@ def _get_brainvision_paths(vhdr_path):
     return (eeg_file_path, vmrk_file_path)
 
 
+def copyfile_ctf(src, dest):
+    """Copy and rename CTF files to a new location.
+
+    Parameters
+    ----------
+    src : str
+        path to the source raw .ds folder
+    dest : str
+        path to the destination of the new bids folder.
+    """
+    sh.copytree(src, dest)
+    # list of file types to rename
+    file_types = ('.acq', '.eeg', '.hc', '.hist', '.infods', '.bak',
+                  '.meg4', '.newds', '.res4')
+    # Rename files in dest with the name of the dest directory
+    fnames = [f for f in os.listdir(dest) if f.endswith(file_types)]
+    bids_folder_name = op.splitext(op.split(dest)[-1])[0]
+    for fname in fnames:
+        ext = op.splitext(fname)[-1]
+        os.rename(op.join(dest, fname),
+                  op.join(dest, bids_folder_name + ext))
+
+
 def copyfile_brainvision(vhdr_src, vhdr_dest):
     """Copy a BrainVision file triplet to a new location and repair links.
 


Test patch:
Repository: mne-tools/mne-bids

Issue:
handle_kind not considering seeg
Hi, I've seen that the function _handle_kind (line 82) in utils.py does not consider the case of _seeg_ data:

```python
def _handle_kind(raw):
    """Get kind."""
    if 'eeg' in raw and 'ecog' in raw:
        raise ValueError('Both EEG and iEEG channels found in data.'
                         'There is currently no specification on how'
                         'to handle this data. Please proceed manually.')
    elif 'meg' in raw:
        kind = 'meg'
    elif 'ecog' in raw:
        kind = 'ieeg'
    elif 'eeg' in raw:
        kind = 'eeg'
    else:
        raise ValueError('Neither MEG/EEG/iEEG channels found in data.'
                         'Please use raw.set_channel_types to set the '
                         'channel types in the data.')
    return kind
```

It only considers _ecog_. I solved it by changing it to:
```python
def _handle_kind(raw):
    """Get kind."""
    if 'eeg' in raw and ('ecog' in raw or 'seeg' in raw):
        raise ValueError('Both EEG and iEEG channels found in data.'
                         'There is currently no specification on how'
                         'to handle this data. Please proceed manually.')
    elif 'meg' in raw:
        kind = 'meg'
    elif 'ecog' in raw or 'seeg' in raw:
        kind = 'ieeg'
    elif 'eeg' in raw:
        kind = 'eeg'
    else:
        raise ValueError('Neither MEG/EEG/iEEG channels found in data.'
                         'Please use raw.set_channel_types to set the '
                         'channel types in the data.')
    return kind
```

It seems to work correctly, but I'm not sure if it is compatible with the rest of the library.

If you confirm that this is a correct solution I'll be happy to do a PR.

Cheers,





Discussion:
indeed, a PR would be welcome :+1:

Resolving patch:
diff --git a/mne_bids/utils.py b/mne_bids/utils.py
--- a/mne_bids/utils.py
+++ b/mne_bids/utils.py
@@ -81,13 +81,13 @@ def _parse_bids_filename(fname, verbose):
 
 def _handle_kind(raw):
     """Get kind."""
-    if 'eeg' in raw and 'ecog' in raw:
+    if 'eeg' in raw and ('ecog' in raw or 'seeg' in raw):
         raise ValueError('Both EEG and iEEG channels found in data.'
                          'There is currently no specification on how'
                          'to handle this data. Please proceed manually.')
     elif 'meg' in raw:
         kind = 'meg'
-    elif 'ecog' in raw:
+    elif 'ecog' in raw or 'seeg' in raw:
         kind = 'ieeg'
     elif 'eeg' in raw:
         kind = 'eeg'


Test patch:
Repository: mne-tools/mne-bids

Issue:
*events.tsv columns should be "value" and "sample" instead of "event_value" and "event_sample"
According to the [specification](https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/05-task-events.html) the column "event_value" should be named "value" and "event_sample" should be named "sample".

I'll submit a PR to fix it.


Discussion:

Resolving patch:
diff --git a/mne_bids/mne_bids.py b/mne_bids/mne_bids.py
--- a/mne_bids/mne_bids.py
+++ b/mne_bids/mne_bids.py
@@ -157,7 +157,7 @@ def _events_tsv(events, raw, fname, trial_type, overwrite=False,
     """Create an events.tsv file and save it.
 
     This function will write the mandatory 'onset', and 'duration' columns as
-    well as the optional 'event_value' and 'event_sample'. The 'event_value'
+    well as the optional 'value' and 'sample'. The 'value'
     corresponds to the marker value as found in the TRIG channel of the
     recording. In addition, the 'trial_type' field can be written.
 
@@ -195,8 +195,8 @@ def _events_tsv(events, raw, fname, trial_type, overwrite=False,
     data = OrderedDict([('onset', events[:, 0] / sfreq),
                         ('duration', np.zeros(events.shape[0])),
                         ('trial_type', None),
-                        ('event_value', events[:, 2]),
-                        ('event_sample', events[:, 0])])
+                        ('value', events[:, 2]),
+                        ('sample', events[:, 0])])
 
     # Now check if trial_type is specified or should be removed
     if trial_type:


Test patch:
Repository: mne-tools/mne-bids

Issue:
align readme.md and readme.rst
our README and the landing page of our homepage are very dissimilar: This is not good.

We should align them somewhat.


Discussion:

Resolving patch:
diff --git a/doc/conf.py b/doc/conf.py
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -114,6 +114,7 @@
     'navbar_links': [
         ("Gallery", "auto_examples/index"),
         ("API", "api"),
+        ("What's new", "whats_new"),
         ("Github", "https://github.com/mne-tools/mne-bids", True),
     ]}
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -21,8 +21,8 @@
           url=URL,
           version=VERSION,
           download_url=DOWNLOAD_URL,
-          long_description=open('README.md').read(),
-          long_description_content_type='text/markdown',
+          long_description=open('README.rst').read(),
+          long_description_content_type='text/x-rst',
           classifiers=[
               'Intended Audience :: Science/Research',
               'Intended Audience :: Developers',


Test patch:
Repository: mne-tools/mne-bids

Issue:
new release for mne-bids
We should make a new release for mne-bids

refs:

https://github.com/mne-tools/mne-bids/commit/c43822ef754b58b28ccc8d90af565d1681ac5851

and

https://github.com/mne-tools/mne-bids/commit/eec284cbff44425c0c6fbdad1e32809c247cec05

and

https://github.com/mne-tools/mne-python/wiki/How-to-make-a-release



Discussion:

Resolving patch:
diff --git a/doc/conf.py b/doc/conf.py
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -24,6 +24,8 @@
 import sphinx_gallery  # noqa
 import sphinx_bootstrap_theme
 
+import mne_bids
+
 # -- General configuration ------------------------------------------------
 
 # If your documentation needs a minimal Sphinx version, state it here.
@@ -64,16 +66,16 @@
 copyright = u'%s, MNE Developers. Last updated on %s' % (td.year,
                                                          td.isoformat())
 
-author = u'Mainak Jas'
+author = u'MNE Developers'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
 # built documents.
 #
 # The short X.Y version.
-version = u'0.2.dev0'
+version = mne_bids.__version__
 # The full version, including alpha/beta/rc tags.
-release = u'0.2.dev0'
+release = version
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/mne_bids/__init__.py b/mne_bids/__init__.py
--- a/mne_bids/__init__.py
+++ b/mne_bids/__init__.py
@@ -1,6 +1,6 @@
 """MNE software for easily interacting with BIDS compatible datasets."""
 
-__version__ = '0.2.dev0'
+__version__ = '0.2'
 
 
 from .write import (write_raw_bids, make_bids_folders, make_bids_basename,  # noqa: E501 F401
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,19 @@
 #! /usr/bin/env python
+"""Setup MNE-BIDS."""
+import os
 from setuptools import setup, find_packages
 
+# get the version
+version = None
+with open(os.path.join('mne_bids', '__init__.py'), 'r') as fid:
+    for line in (line.strip() for line in fid):
+        if line.startswith('__version__'):
+            version = line.split('=')[1].strip().strip('\'')
+            break
+if version is None:
+    raise RuntimeError('Could not determine version')
+
+
 descr = """Experimental code for BIDS using MNE."""
 
 DISTNAME = 'mne-bids'
@@ -10,7 +23,7 @@
 URL = 'https://mne-tools.github.io/mne-bids/'
 LICENSE = 'BSD (3-clause)'
 DOWNLOAD_URL = 'http://github.com/mne-tools/mne-bids'
-VERSION = '0.2.dev0'
+VERSION = version
 
 if __name__ == "__main__":
     setup(name=DISTNAME,


Test patch:
Repository: mne-tools/mne-bids

Issue:
Events are misaligned
In sidecar `*_events.tsv` files, the onsets of the events are defined (excerpt from the BIDS doc):

> Onset (in seconds) of the event measured from the beginning of the acquisition of the first volume in the corresponding task imaging data file.

In other words, the first sample is always T=0. MNE-bids currently creates the annotations relative to `raw.info['meas_date']`, causing the events to be misaligned. This is not caught by the unit tests, as the test with events was done after the data was anonymized, causing `raw.info['meas_date']` to be `None`.

See the pull request for a unit test that will fail on current master but shouldn't. And the fix of course.


Discussion:

Resolving patch:
diff --git a/mne_bids/read.py b/mne_bids/read.py
--- a/mne_bids/read.py
+++ b/mne_bids/read.py
@@ -101,7 +101,7 @@ def _handle_events_reading(events_fname, raw):
     annot_from_events = mne.Annotations(onset=onsets,
                                         duration=durations,
                                         description=descriptions,
-                                        orig_time=raw.info['meas_date'])
+                                        orig_time=None)
     raw.set_annotations(annot_from_events)
 
     return raw


Test patch:
diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py
--- a/mne_bids/tests/test_write.py
+++ b/mne_bids/tests/test_write.py
@@ -81,6 +81,15 @@ def test_fif():
     write_raw_bids(raw, bids_basename, output_path, events_data=events_fname,
                    event_id=event_id, overwrite=False)
 
+    # Read the file back in to check that the data has come through cleanly.
+    # Events and bad channel information was read through JSON sidecar files.
+    raw2 = read_raw_bids(bids_basename + '_meg.fif', output_path)
+    assert set(raw.info['bads']) == set(raw2.info['bads'])
+    events, _ = mne.events_from_annotations(raw2)
+    events2 = mne.read_events(events_fname)
+    events2 = events2[events2[:, 2] != 0]
+    assert_array_equal(events2[:, 0], events[:, 0])
+
     # check if write_raw_bids works when there is no stim channel
     raw.set_channel_types({raw.ch_names[i]: 'misc'
                            for i in
@@ -149,11 +158,6 @@ def test_fif():
     # now force the overwrite
     write_raw_bids(raw, bids_basename2, output_path, events_data=events_fname,
                    event_id=event_id, overwrite=True)
-    raw = read_raw_bids(bids_basename2 + '_meg.fif', output_path)
-    events, _ = mne.events_from_annotations(raw)
-    events2 = mne.read_events(events_fname)
-    events2 = events2[events2[:, 2] != 0]
-    assert_array_equal(events2[:, 0], events[:, 0])
 
     with pytest.raises(ValueError, match='raw_file must be'):
         write_raw_bids('blah', bids_basename, output_path)
Repository: mne-tools/mne-bids

Issue:
plot_anat should use BIDS subjects_dir
I'm a bit confused by the example of convert_mri_and_trans.py. I think here:

https://github.com/mne-tools/mne-bids/blob/master/examples/convert_mri_and_trans.py#L139-L150

It should actually read in the nifti file that is written instead of the old mgz file. What do you think @sappelhoff ?


Discussion:
You are right, fix is coming!

Resolving patch:
diff --git a/examples/convert_mri_and_trans.py b/examples/convert_mri_and_trans.py
--- a/examples/convert_mri_and_trans.py
+++ b/examples/convert_mri_and_trans.py
@@ -95,14 +95,14 @@
 # retrieve our transformation matrix :code:`trans`.
 
 # We use the write_anat function
-write_anat(bids_root=output_path,  # point to the BIDS dir we wrote earlier
-           subject=sub,
-           t1w=t1_mgh_fname,  # path to the MRI scan
-           session=ses,
-           raw=raw,  # the raw MEG data file connected to the MRI
-           trans=trans,  # our transformation matrix
-           verbose=True  # this will print out the sidecar file
-           )
+anat_dir = write_anat(bids_root=output_path,  # the BIDS dir we wrote earlier
+                      subject=sub,
+                      t1w=t1_mgh_fname,  # path to the MRI scan
+                      session=ses,
+                      raw=raw,  # the raw MEG data file connected to the MRI
+                      trans=trans,  # our transformation matrix
+                      verbose=True  # this will print out the sidecar file
+                      )
 
 # Let's have another look at our BIDS directory
 print_dir_tree(output_path)
@@ -142,10 +142,13 @@
                       subjects_dir=op.join(data_path, 'subjects')
                       )
 
+# Our MRI written to BIDS, we got `anat_dir` from our `write_anat` function
+t1_nii_fname = op.join(anat_dir, 'sub-01_ses-01_T1w.nii.gz')
+
 # Plot it
 fig, axs = plt.subplots(3, 1)
 for point_idx, label in enumerate(('LPA', 'NAS', 'RPA')):
-    plot_anat(t1_mgh_fname, axes=axs[point_idx],
+    plot_anat(t1_nii_fname, axes=axs[point_idx],
               cut_coords=mri_pos[point_idx, :],
               title=label)
 


Test patch:
Repository: mne-tools/mne-bids

Issue:
Update text before release
The setup.py still states that this is experimental. I think it's grown up a fair bit :) this is the text that ends up on pypi. we should update it to reflect the package's aim

https://github.com/mne-tools/mne-bids/blob/f8f267b45ac36e1600ea9ceb5540299e1bf3ab21/setup.py#L17


Discussion:
Thanks for the reminder @teonbrooks! Any suggestions to how we should describe it?
here is the description for MNE-Python:
```
MNE python project for MEG and EEG data analysis.
```

For this project, we could say,
```
An MNE project for organizing and formatting MEG and EEG data according to the BIDS specification
```

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,8 @@
     raise RuntimeError('Could not determine version')
 
 
-descr = """Experimental code for BIDS using MNE."""
+descr = ('An MNE project for organizing and formatting MEG and EEG data '
+         'according to the BIDS specification.')
 
 DISTNAME = 'mne-bids'
 DESCRIPTION = descr


Test patch: