Skip to content

Commit

Permalink
ENH: Improve MATLAB compat (#8515)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Nov 14, 2020
1 parent 3a4d375 commit c0d098e
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 69 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,23 @@ jobs:
python -c "import mne; print(mne.datasets.hf_sef.data_path(update_path=True))";
fi;
if [[ $(cat $FNAME | grep -x ".*brainstorm.*bst_auditory.*" | wc -l) -gt 0 ]]; then
python -c "import mne; print(mne.datasets.brainstorm.bst_auditory.data_path(update_path=True))" --accept-brainstorm-license;
python -c "import mne; print(mne.datasets.brainstorm.bst_auditory.data_path(update_path=True, accept=True))";
fi;
if [[ $(cat $FNAME | grep -x ".*brainstorm.*bst_resting.*" | wc -l) -gt 0 ]]; then
python -c "import mne; print(mne.datasets.brainstorm.bst_resting.data_path(update_path=True))" --accept-brainstorm-license;
python -c "import mne; print(mne.datasets.brainstorm.bst_resting.data_path(update_path=True, accept=True))";
fi;
if [[ $(cat $FNAME | grep -x ".*brainstorm.*bst_raw.*" | wc -l) -gt 0 ]]; then
python -c "import mne; print(mne.datasets.brainstorm.bst_raw.data_path(update_path=True))" --accept-brainstorm-license;
python -c "import mne; print(mne.datasets.brainstorm.bst_raw.data_path(update_path=True, accept=True))";
fi;
if [[ $(cat $FNAME | grep -x ".*brainstorm.*bst_phantom_ctf.*" | wc -l) -gt 0 ]]; then
python -c "import mne; print(mne.datasets.brainstorm.bst_phantom_ctf.data_path(update_path=True))" --accept-brainstorm-license;
python -c "import mne; print(mne.datasets.brainstorm.bst_phantom_ctf.data_path(update_path=True, accept=True))";
fi;
if [[ $(cat $FNAME | grep -x ".*brainstorm.*bst_phantom_elekta.*" | wc -l) -gt 0 ]]; then
python -c "import mne; print(mne.datasets.brainstorm.bst_phantom_elekta.data_path(update_path=True))" --accept-brainstorm-license;
python -c "import mne; print(mne.datasets.brainstorm.bst_phantom_elekta.data_path(update_path=True, accept=True))";
fi;
if [[ $(cat $FNAME | grep -x ".*datasets.*hcp_mmp_parcellation.*" | wc -l) -gt 0 ]]; then
python -c "import mne; print(mne.datasets.sample.data_path(update_path=True))";
python -c "import mne; print(mne.datasets.fetch_hcp_mmp_parcellation(subjects_dir=mne.datasets.sample.data_path() + '/subjects'))" --accept-hcpmmp-license;
python -c "import mne; print(mne.datasets.fetch_hcp_mmp_parcellation(subjects_dir=mne.datasets.sample.data_path() + '/subjects'), accept=True)";
fi;
if [[ $(cat $FNAME | grep -x ".*datasets.*misc.*" | wc -l) -gt 0 ]]; then
python -c "import mne; print(mne.datasets.misc.data_path(update_path=True))";
Expand Down
18 changes: 14 additions & 4 deletions doc/changes/0.21.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@
- "Bugs" for bug fixes
- "API changes" for backward-incompatible changes

.. _changes_0_21_2:

Version 0.21.2
--------------

Bugs
~~~~

- Add option to disable TQDM entirely with ``MNE_TQDM='off'`` (:gh:`8515` by `Eric Larson`_)

- Fix reading GDF files with excluded channels in :func:`mne.io.read_raw_gdf` (:gh:`8520` by `Clemens Brunner`_)


.. _changes_0_21_1:

Version 0.21.1 (unreleased)
---------------------------
Version 0.21.1
--------------

.. |Eduard Ort| replace:: **Eduard Ort**

Expand Down Expand Up @@ -56,8 +68,6 @@ Bugs
- When reading BrainVision raw data, the channel units and types were sometimes not inferred correctly by `Richard Höchenberger`_ (:gh:`8434`)
- Fix reading GDF files with excluded channels in :func:`mne.io.read_raw_gdf` (:gh:`8520` by `Clemens Brunner`_)
.. _changes_0_21:
Version 0.21
Expand Down
12 changes: 6 additions & 6 deletions mne/datasets/brainstorm/bst_auditory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...utils import verbose
from ..utils import (has_dataset, _data_path, _get_version, _version_doc,
_data_path_doc)
_data_path_doc_accept)

has_brainstorm_data = partial(has_dataset, name='brainstorm.bst_auditory')

Expand All @@ -29,15 +29,15 @@

@verbose
def data_path(path=None, force_update=False, update_path=True, download=True,
verbose=None): # noqa: D103
*, accept=False, verbose=None): # noqa: D103
return _data_path(path=path, force_update=force_update,
update_path=update_path, name='brainstorm',
download=download, archive_name='bst_auditory.tar.gz')
download=download, archive_name='bst_auditory.tar.gz',
accept=accept)


_data_path_doc = _data_path_doc.format(name='brainstorm',
conf='MNE_DATASETS_BRAINSTORM_DATA'
'_PATH')
_data_path_doc = _data_path_doc_accept.format(
name='brainstorm', conf='MNE_DATASETS_BRAINSTORM_DATA_PATH')
_data_path_doc = _data_path_doc.replace('brainstorm dataset',
'brainstorm (bst_auditory) dataset')
data_path.__doc__ = _data_path_doc
Expand Down
12 changes: 6 additions & 6 deletions mne/datasets/brainstorm/bst_phantom_ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...utils import verbose
from ..utils import (has_dataset, _data_path, _get_version, _version_doc,
_data_path_doc)
_data_path_doc_accept)

has_brainstorm_data = partial(has_dataset, name='brainstorm.bst_phantom_ctf')

Expand All @@ -18,15 +18,15 @@

@verbose
def data_path(path=None, force_update=False, update_path=True, download=True,
verbose=None): # noqa: D103
*, accept=False, verbose=None): # noqa: D103
return _data_path(path=path, force_update=force_update,
update_path=update_path, name='brainstorm',
download=download, archive_name='bst_phantom_ctf.tar.gz')
download=download, archive_name='bst_phantom_ctf.tar.gz',
accept=accept)


_data_path_doc = _data_path_doc.format(name='brainstorm',
conf='MNE_DATASETS_BRAINSTORM_DATA'
'_PATH')
_data_path_doc = _data_path_doc_accept.format(
name='brainstorm', conf='MNE_DATASETS_BRAINSTORM_DATA_PATH')
_data_path_doc = _data_path_doc.replace('brainstorm dataset',
'brainstorm (bst_phantom_ctf) dataset')
data_path.__doc__ = _data_path_doc
Expand Down
12 changes: 6 additions & 6 deletions mne/datasets/brainstorm/bst_phantom_elekta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...utils import verbose
from ..utils import (has_dataset, _data_path, _get_version, _version_doc,
_data_path_doc)
_data_path_doc_accept)

has_brainstorm_data = partial(has_dataset,
name='brainstorm.bst_phantom_elekta')
Expand All @@ -19,16 +19,16 @@

@verbose
def data_path(path=None, force_update=False, update_path=True, download=True,
verbose=None): # noqa: D103
*, accept=False, verbose=None): # noqa: D103
return _data_path(path=path, force_update=force_update,
update_path=update_path, name='brainstorm',
download=download,
archive_name='bst_phantom_elekta.tar.gz')
archive_name='bst_phantom_elekta.tar.gz',
accept=accept)


_data_path_doc = _data_path_doc.format(name='brainstorm',
conf='MNE_DATASETS_BRAINSTORM_DATA'
'_PATH')
_data_path_doc = _data_path_doc_accept.format(
name='brainstorm', conf='MNE_DATASETS_BRAINSTORM_DATA_PATH')
_data_path_doc = _data_path_doc.replace('brainstorm dataset',
'brainstorm (bst_phantom_elekta) '
'dataset')
Expand Down
12 changes: 6 additions & 6 deletions mne/datasets/brainstorm/bst_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...utils import verbose, get_config
from ..utils import (has_dataset, _data_path, _get_version, _version_doc,
_data_path_doc)
_data_path_doc_accept)

has_brainstorm_data = partial(has_dataset, name='brainstorm.bst_raw')

Expand All @@ -27,15 +27,15 @@

@verbose
def data_path(path=None, force_update=False, update_path=True, download=True,
verbose=None): # noqa: D103
*, accept=False, verbose=None): # noqa: D103
return _data_path(path=path, force_update=force_update,
update_path=update_path, name='brainstorm',
download=download, archive_name='bst_raw.tar.gz')
download=download, archive_name='bst_raw.tar.gz',
accept=accept)


_data_path_doc = _data_path_doc.format(name='brainstorm',
conf='MNE_DATASETS_BRAINSTORM_DATA'
'_PATH')
_data_path_doc = _data_path_doc_accept.format(
name='brainstorm', conf='MNE_DATASETS_BRAINSTORM_DATA_PATH')
_data_path_doc = _data_path_doc.replace('brainstorm dataset',
'brainstorm (bst_raw) dataset')
data_path.__doc__ = _data_path_doc
Expand Down
12 changes: 6 additions & 6 deletions mne/datasets/brainstorm/bst_resting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...utils import verbose
from ..utils import (has_dataset, _data_path, _get_version, _version_doc,
_data_path_doc)
_data_path_doc_accept)

has_brainstorm_data = partial(has_dataset, name='brainstorm.bst_resting')

Expand All @@ -20,15 +20,15 @@

@verbose
def data_path(path=None, force_update=False, update_path=True, download=True,
verbose=None): # noqa: D103
*, accept=False, verbose=None): # noqa: D103
return _data_path(path=path, force_update=force_update,
update_path=update_path, name='brainstorm',
download=download, archive_name='bst_resting.tar.gz')
download=download, archive_name='bst_resting.tar.gz',
accept=accept)


_data_path_doc = _data_path_doc.format(name='brainstorm',
conf='MNE_DATASETS_BRAINSTORM_DATA'
'_PATH')
_data_path_doc = _data_path_doc_accept.format(
name='brainstorm', conf='MNE_DATASETS_BRAINSTORM_DATA_PATH')
_data_path_doc = _data_path_doc.replace('brainstorm dataset',
'brainstorm (bst_resting) dataset')
data_path.__doc__ = _data_path_doc
Expand Down
47 changes: 25 additions & 22 deletions mne/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .. import __version__ as mne_version
from ..label import read_labels_from_annot, Label, write_labels_to_annot
from ..utils import (get_config, set_config, _fetch_file, logger, warn,
verbose, get_subjects_dir, hashfunc, _pl)
verbose, get_subjects_dir, hashfunc, _pl, _safe_input)
from ..utils.docs import docdict
from ..externals.doccer import docformat

Expand Down Expand Up @@ -55,7 +55,12 @@
path : str
Path to {name} dataset directory.
"""
_data_path_doc_accept = _data_path_doc.split('%(verbose)s')
_data_path_doc_accept[-1] = '%(verbose)s' + _data_path_doc_accept[-1]
_data_path_doc_accept.insert(1, ' %(accept)s')
_data_path_doc_accept = ''.join(_data_path_doc_accept)
_data_path_doc = docformat(_data_path_doc, docdict)
_data_path_doc_accept = docformat(_data_path_doc_accept, docdict)

_version_doc = """Get version of the local {name} dataset.
Expand Down Expand Up @@ -204,7 +209,7 @@ def _do_path_update(path, update_path, key, name):
msg = ('Do you want to set the path:\n %s\nas the default '
'%s dataset path in the mne-python config [y]/n? '
% (path, name))
answer = input(msg)
answer = _safe_input(msg, alt='pass update_path=True')
if answer.lower() == 'n':
update_path = False

Expand All @@ -215,7 +220,7 @@ def _do_path_update(path, update_path, key, name):

def _data_path(path=None, force_update=False, update_path=True, download=True,
name=None, check_version=False, return_version=False,
archive_name=None):
archive_name=None, accept=False):
"""Aux function."""
key = {
'fake': 'MNE_DATASETS_FAKE_PATH',
Expand Down Expand Up @@ -381,10 +386,13 @@ def _data_path(path=None, force_update=False, update_path=True, download=True,
for f in folder_path:
logger.debug(' Exists: %s: %s' % (f, op.exists(f)))
if name == 'brainstorm':
if '--accept-brainstorm-license' in sys.argv:
if accept or '--accept-brainstorm-license' in sys.argv:
answer = 'y'
else:
answer = input('%sAgree (y/[n])? ' % _bst_license_text)
# If they don't have stdin, just accept the license
# https://github.com/mne-tools/mne-python/issues/8513#issuecomment-726823724 # noqa: E501
answer = _safe_input(
'%sAgree (y/[n])? ' % _bst_license_text, use='y')
if answer.lower() != 'y':
raise RuntimeError('You must agree to the license to use this '
'dataset')
Expand Down Expand Up @@ -590,15 +598,11 @@ def _download_all_example_data(verbose=True):
kiloword.data_path()
phantom_4dbti.data_path()
refmeg_noise.data_path()
sys.argv += ['--accept-brainstorm-license']
try:
brainstorm.bst_raw.data_path()
brainstorm.bst_auditory.data_path()
brainstorm.bst_resting.data_path()
brainstorm.bst_phantom_elekta.data_path()
brainstorm.bst_phantom_ctf.data_path()
finally:
sys.argv.pop(-1)
brainstorm.bst_raw.data_path(accept=True)
brainstorm.bst_auditory.data_path(accept=True)
brainstorm.bst_resting.data_path(accept=True)
brainstorm.bst_phantom_elekta.data_path(accept=True)
brainstorm.bst_phantom_ctf.data_path(accept=True)
eegbci.load_data(1, [6, 10, 14], update_path=True)
for subj in range(4):
eegbci.load_data(subj + 1, runs=[3], update_path=True)
Expand All @@ -607,11 +611,8 @@ def _download_all_example_data(verbose=True):
# If the user has SUBJECTS_DIR, respect it, if not, set it to the EEG one
# (probably on CircleCI, or otherwise advanced user)
fetch_fsaverage(None)
sys.argv += ['--accept-hcpmmp-license']
try:
fetch_hcp_mmp_parcellation(subjects_dir=sample_path + '/subjects')
finally:
sys.argv.pop(-1)
fetch_hcp_mmp_parcellation(
subjects_dir=sample_path + '/subjects', accept=True)
limo.load_data(subject=1, update_path=True)


Expand Down Expand Up @@ -648,7 +649,8 @@ def fetch_aparc_sub_parcellation(subjects_dir=None, verbose=None):


@verbose
def fetch_hcp_mmp_parcellation(subjects_dir=None, combine=True, verbose=None):
def fetch_hcp_mmp_parcellation(subjects_dir=None, combine=True, *,
accept=False, verbose=None):
"""Fetch the HCP-MMP parcellation.
This will download and install the HCP-MMP parcellation
Expand All @@ -664,6 +666,7 @@ def fetch_hcp_mmp_parcellation(subjects_dir=None, combine=True, verbose=None):
If True, also produce the combined/reduced set of 23 labels per
hemisphere as ``HCPMMP1_combined.annot``
:footcite:`GlasserEtAl2016supp`.
%(accept)s
%(verbose)s
Notes
Expand All @@ -684,10 +687,10 @@ def fetch_hcp_mmp_parcellation(subjects_dir=None, combine=True, verbose=None):
hashes = dict(lh='46a102b59b2fb1bb4bd62d51bf02e975',
rh='75e96b331940227bbcb07c1c791c2463')
if not all(op.isfile(fname) for fname in fnames):
if '--accept-hcpmmp-license' in sys.argv:
if accept or '--accept-hcpmmp-license' in sys.argv:
answer = 'y'
else:
answer = input('%s\nAgree (y/[n])? ' % _hcp_mmp_license_text)
answer = _safe_input('%s\nAgree (y/[n])? ' % _hcp_mmp_license_text)
if answer.lower() != 'y':
raise RuntimeError('You must agree to the license to use this '
'dataset')
Expand Down
4 changes: 2 additions & 2 deletions mne/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .io.pick import _DATA_CH_TYPES_SPLIT
from .source_space import _mri_orientation
from .utils import (logger, verbose, get_subjects_dir, warn,
fill_doc, _check_option, _validate_type)
fill_doc, _check_option, _validate_type, _safe_input)
from .viz import (plot_events, plot_alignment, plot_cov, plot_projs_topomap,
plot_compare_evokeds)
from .viz.misc import _plot_mri_contours, _get_bem_plotting_surfaces
Expand Down Expand Up @@ -1586,7 +1586,7 @@ def save(self, fname=None, open_browser=True, overwrite=False):
msg = ('Report already exists at location %s. '
'Overwrite it (y/[n])? '
% fname)
answer = input(msg)
answer = _safe_input(msg, alt='pass overwrite=True')
if answer.lower() == 'y':
overwrite = True

Expand Down
2 changes: 1 addition & 1 deletion mne/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
_check_path_like, _check_src_normal, _check_stc_units,
_check_pyqt5_version, _check_sphere, _check_time_format,
_check_freesurfer_home, _suggest, _require_version,
_on_missing)
_on_missing, _safe_input)
from .config import (set_config, get_config, get_config_path, set_cache_dir,
set_memmap_min_size, get_subjects_dir, _get_stim_channel,
sys_info, _get_extra_data_path, _get_root_dir,
Expand Down
12 changes: 12 additions & 0 deletions mne/utils/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# License: BSD (3-clause)

from builtins import input # no-op here but facilitates testing
from difflib import get_close_matches
from distutils.version import LooseVersion
import operator
Expand Down Expand Up @@ -730,3 +731,14 @@ def _on_missing(on_missing, msg):
warn(msg)
else: # Ignore
assert on_missing == 'ignore'


def _safe_input(msg, *, alt=None, use=None):
try:
return input(msg)
except EOFError: # MATLAB or other non-stdin
if use is not None:
return use
raise RuntimeError(
f'Could not use input() to get a response to:\n{msg}\n'
f'You can {alt} to avoid this error.')
Loading

0 comments on commit c0d098e

Please sign in to comment.