[med-svn] [python-mne] 230/353: ENH: warning if sample dataset old

Yaroslav Halchenko debian at onerussian.com
Fri Nov 27 17:25:03 UTC 2015


This is an automated email from the git hooks/post-receive script.

yoh pushed a commit to tag 0.4
in repository python-mne.

commit 80d2dad437f5d5230e0c79b44ffd6fda9cf36ec6
Author: mluessi at nmr.mgh.harvard.edu <mluessi at nmr.mgh.harvard.edu>
Date:   Tue Jun 26 07:26:23 2012 -0400

    ENH: warning if sample dataset old
---
 mne/datasets/sample/__init__.py | 49 +++++++++++++++++++++++++++++++++--------
 1 file changed, 40 insertions(+), 9 deletions(-)

diff --git a/mne/datasets/sample/__init__.py b/mne/datasets/sample/__init__.py
index 4e2c93c..79233db 100644
--- a/mne/datasets/sample/__init__.py
+++ b/mne/datasets/sample/__init__.py
@@ -1,10 +1,23 @@
 # Author: Alexandre Gramfort <gramfort at nmr.mgh.harvard.edu>
 # License: BSD Style.
 
-import os
-import os.path as op
 
-def data_path(path='.'):
+def _sample_version(path):
+    """Get the version of the Sample dataset"""
+    import os.path as op
+    ver_fname = op.join(path, 'version.txt')
+    if op.exists(ver_fname):
+        fid = open(ver_fname, 'r')
+        version = fid.readline().strip()  # version is on first line
+        fid.close()
+    else:
+        # Sample dataset versioning was introduced after 0.3
+        version = '0.3'
+
+    return version
+
+
+def data_path(path='.', force_update=False):
     """Get path to local copy of Sample dataset
 
     Parameters
@@ -13,20 +26,28 @@ def data_path(path='.'):
         Location of where to look for the sample dataset.
         If not set. The data will be automatically downloaded in
         the local folder.
+    force_update : bool
+        Force update of the sample dataset even if a local copy exists.
     """
+    import os.path as op
+    from warnings import warn
+    from distutils.version import LooseVersion
+
+    from ... import __version__ as mne_version
+
     archive_name = "MNE-sample-data-processed.tar.gz"
     url = "ftp://surfer.nmr.mgh.harvard.edu/pub/data/" + archive_name
     folder_name = "MNE-sample-data"
 
-    martinos_path = '/homes/6/gramfort/cluster/work/data/MNE-sample-data-processed.tar.gz'
-    neurospin_path = '/neurospin/tmp/gramfort/MNE-sample-data-processed.tar.gz'
+    martinos_path = '/homes/6/gramfort/cluster/work/data/' + archive_name
+    neurospin_path = '/neurospin/tmp/gramfort/' + archive_name
 
-    if not os.path.exists(op.join(path, folder_name)):
-        if os.path.exists(martinos_path):
+    if not op.exists(op.join(path, folder_name)) or force_update:
+        if op.exists(martinos_path):
             archive_name = martinos_path
-        elif os.path.exists(neurospin_path):
+        elif op.exists(neurospin_path):
             archive_name = neurospin_path
-        elif not os.path.exists(archive_name):
+        elif not op.exists(archive_name):
             import urllib
             print "Downloading data, please Wait (600 MB)..."
             print url
@@ -40,4 +61,14 @@ def data_path(path='.'):
         print
 
     path = op.join(path, folder_name)
+
+    # compare the version of the Sample dataset and mne
+    sample_version = _sample_version(path)
+    if LooseVersion(sample_version) < LooseVersion(mne_version):
+        warn('Sample dataset (version %s) is older than mne-python '
+             '(version %s). If the examples fail, you may need to update '
+             'the sample dataset by using force_update=True' % (sample_version,
+             mne_version))
+
     return path
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git



More information about the debian-med-commit mailing list