[med-svn] [python-mne] 77/376: ENH : better handling of sample dataset

Yaroslav Halchenko debian at onerussian.com
Fri Nov 27 17:22:11 UTC 2015


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

yoh pushed a commit to annotated tag v0.1
in repository python-mne.

commit 81a34e9fb1a25e702936496e518675e68d7ca098
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date:   Tue Feb 15 16:34:36 2011 -0500

    ENH : better handling of sample dataset
---
 examples/plot_compute_mne_inverse.py           |  8 +++---
 examples/plot_estimate_covariance_matrix.py    |  5 ++--
 examples/plot_read_epochs.py                   | 10 +++----
 examples/plot_read_evoked.py                   |  5 ++--
 examples/plot_read_forward.py                  |  5 ++--
 examples/plot_read_noise_covariance_matrix.py  |  5 ++--
 examples/plot_read_raw_data.py                 |  5 ++--
 examples/plot_read_stc.py                      |  5 ++--
 examples/plot_topography.py                    |  5 ++--
 examples/plot_whiten_forward_solution.py       | 11 ++++---
 examples/plot_whitened_evoked_data.py          |  8 +++---
 examples/read_bem_surfaces.py                  |  6 ++--
 examples/read_events.py                        |  5 ++--
 examples/read_inverse.py                       |  5 +++-
 examples/read_write_raw.py                     |  4 ++-
 examples/stats/plot_sensor_permutation_test.py |  8 +++---
 examples/time_frequency/plot_time_frequency.py |  8 +++---
 mne/datasets/__init__.py                       |  0
 mne/datasets/sample/__init__.py                | 40 ++++++++++++++++++++++++++
 mne/layouts/layout.py                          |  3 ++
 mne/tests/test_bem_surfaces.py                 |  8 +++---
 mne/tests/test_forward.py                      |  7 +++--
 mne/tests/test_inverse.py                      |  8 ++++--
 mne/tests/test_stc.py                          |  7 +++--
 24 files changed, 119 insertions(+), 62 deletions(-)

diff --git a/examples/plot_compute_mne_inverse.py b/examples/plot_compute_mne_inverse.py
index 45500ed..0fe1320 100644
--- a/examples/plot_compute_mne_inverse.py
+++ b/examples/plot_compute_mne_inverse.py
@@ -18,11 +18,11 @@ import os
 import numpy as np
 import pylab as pl
 import mne
+from mne.datasets import sample
 
-fname_inv = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname_inv += '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'
-fname_data = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname_data += '/MEG/sample/sample_audvis-ave.fif'
+data_path = sample.data_path('.')
+fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'
+fname_data = data_path + '/MEG/sample/sample_audvis-ave.fif'
 
 setno = 0
 snr = 3.0
diff --git a/examples/plot_estimate_covariance_matrix.py b/examples/plot_estimate_covariance_matrix.py
index 06b247c..128db46 100644
--- a/examples/plot_estimate_covariance_matrix.py
+++ b/examples/plot_estimate_covariance_matrix.py
@@ -13,9 +13,10 @@ print __doc__
 import os
 import mne
 from mne import fiff
+from mne.datasets import sample
 
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/MEG/sample/sample_audvis_raw.fif'
+data_path = sample.data_path('.')
+fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
 
 raw = fiff.setup_read_raw(fname)
 
diff --git a/examples/plot_read_epochs.py b/examples/plot_read_epochs.py
index 98cfcbb..239ec95 100644
--- a/examples/plot_read_epochs.py
+++ b/examples/plot_read_epochs.py
@@ -20,15 +20,13 @@ import numpy as np
 
 import mne
 from mne import fiff
+from mne.datasets import sample
+data_path = sample.data_path('.')
 
 ###############################################################################
 # Set parameters
-raw_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-# raw_fname += '/MEG/sample/sample_audvis_raw.fif'
-raw_fname += '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
-event_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-# event_fname += '/MEG/sample/sample_audvis_raw-eve.fif'
-event_fname += '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
+raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
+event_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
 event_id = 1
 tmin = -0.2
 tmax = 0.5
diff --git a/examples/plot_read_evoked.py b/examples/plot_read_evoked.py
index f48e5e5..3e8634a 100644
--- a/examples/plot_read_evoked.py
+++ b/examples/plot_read_evoked.py
@@ -12,9 +12,10 @@ print __doc__
 
 import os
 from mne import fiff
+from mne.datasets import sample
+data_path = sample.data_path('.')
 
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/MEG/sample/sample_audvis-ave.fif'
+fname = data_path + '/MEG/sample/sample_audvis-ave.fif'
 
 # Reading
 data = fiff.read_evoked(fname, setno=0, baseline=(None, 0))
diff --git a/examples/plot_read_forward.py b/examples/plot_read_forward.py
index caa8338..797f8a9 100644
--- a/examples/plot_read_forward.py
+++ b/examples/plot_read_forward.py
@@ -11,9 +11,10 @@ print __doc__
 
 import os
 import mne
+from mne.datasets import sample
+data_path = sample.data_path('.')
 
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/MEG/sample/sample_audvis-meg-oct-6-fwd.fif'
+fname = data_path + '/MEG/sample/sample_audvis-meg-oct-6-fwd.fif'
 
 fwd = mne.read_forward_solution(fname)
 leadfield = fwd['sol']['data']
diff --git a/examples/plot_read_noise_covariance_matrix.py b/examples/plot_read_noise_covariance_matrix.py
index 3547017..2be0830 100644
--- a/examples/plot_read_noise_covariance_matrix.py
+++ b/examples/plot_read_noise_covariance_matrix.py
@@ -11,9 +11,10 @@ print __doc__
 
 import os
 import mne
+from mne.datasets import sample
 
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/MEG/sample/sample_audvis-cov.fif'
+data_path = sample.data_path('.')
+fname = data_path + '/MEG/sample/sample_audvis-cov.fif'
 
 cov = mne.Covariance(kind='full')
 cov.load(fname)
diff --git a/examples/plot_read_raw_data.py b/examples/plot_read_raw_data.py
index 9e585bd..fee5580 100644
--- a/examples/plot_read_raw_data.py
+++ b/examples/plot_read_raw_data.py
@@ -11,9 +11,10 @@ print __doc__
 
 import os
 from mne import fiff
+from mne.datasets import sample
+data_path = sample.data_path('.')
 
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/MEG/sample/sample_audvis_raw.fif'
+fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
 
 raw = fiff.setup_read_raw(fname)
 
diff --git a/examples/plot_read_stc.py b/examples/plot_read_stc.py
index f35f06e..d8b7778 100644
--- a/examples/plot_read_stc.py
+++ b/examples/plot_read_stc.py
@@ -15,9 +15,10 @@ print __doc__
 import os
 import numpy as np
 import mne
+from mne.datasets import sample
 
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/MEG/sample/sample_audvis-meg-lh.stc'
+data_path = sample.data_path('.')
+fname = data_path + '/MEG/sample/sample_audvis-meg-lh.stc'
 
 stc = mne.read_stc(fname)
 
diff --git a/examples/plot_topography.py b/examples/plot_topography.py
index 2c736af..939ec8e 100644
--- a/examples/plot_topography.py
+++ b/examples/plot_topography.py
@@ -17,9 +17,10 @@ import pylab as pl
 from mne import fiff
 from mne.layouts import Layout
 from mne.viz import plot_topo
+from mne.datasets import sample
+data_path = sample.data_path('.')
 
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/MEG/sample/sample_audvis-ave.fif'
+fname = data_path + '/MEG/sample/sample_audvis-ave.fif'
 
 # Reading
 data = fiff.read_evoked(fname, setno=0, baseline=(None, 0))
diff --git a/examples/plot_whiten_forward_solution.py b/examples/plot_whiten_forward_solution.py
index 0faa4a4..4899da8 100644
--- a/examples/plot_whiten_forward_solution.py
+++ b/examples/plot_whiten_forward_solution.py
@@ -12,13 +12,12 @@ print __doc__
 import os
 import mne
 from mne import fiff
+from mne.datasets import sample
 
-fwd_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fwd_fname += '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif'
-ave_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-ave_fname += '/MEG/sample/sample_audvis-ave.fif'
-cov_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-cov_fname += '/MEG/sample/sample_audvis-cov.fif'
+data_path = sample.data_path('.')
+fwd_fname = data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif'
+ave_fname = data_path + '/MEG/sample/sample_audvis-ave.fif'
+cov_fname = data_path + '/MEG/sample/sample_audvis-cov.fif'
 
 # Reading
 ave = fiff.read_evoked(ave_fname, setno=0, baseline=(None, 0))
diff --git a/examples/plot_whitened_evoked_data.py b/examples/plot_whitened_evoked_data.py
index 58e677a..1228f77 100644
--- a/examples/plot_whitened_evoked_data.py
+++ b/examples/plot_whitened_evoked_data.py
@@ -13,11 +13,11 @@ print __doc__
 import os
 import mne
 from mne import fiff
+from mne.datasets import sample
 
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/MEG/sample/sample_audvis-ave.fif'
-cov_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-cov_fname += '/MEG/sample/sample_audvis-cov.fif'
+data_path = sample.data_path('.')
+fname = data_path + '/MEG/sample/sample_audvis-ave.fif'
+cov_fname = data_path + '/MEG/sample/sample_audvis-cov.fif'
 
 # Reading
 ave = fiff.read_evoked(fname, setno=0, baseline=(None, 0))
diff --git a/examples/read_bem_surfaces.py b/examples/read_bem_surfaces.py
index ad9dcf4..dcd3b28 100644
--- a/examples/read_bem_surfaces.py
+++ b/examples/read_bem_surfaces.py
@@ -10,10 +10,10 @@ Reading BEM surfaces from a forward solution
 print __doc__
 
 import mne
+from mne.datasets import sample
 
-
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/subjects/sample/bem/sample-5120-5120-5120-bem-sol.fif'
+data_path = sample.data_path('.')
+fname = data_path + '/subjects/sample/bem/sample-5120-5120-5120-bem-sol.fif'
 
 surfaces = mne.read_bem_surfaces(fname)
 
diff --git a/examples/read_events.py b/examples/read_events.py
index 0c5b1bf..cc3fc1f 100644
--- a/examples/read_events.py
+++ b/examples/read_events.py
@@ -11,9 +11,10 @@ print __doc__
 
 import os
 import mne
+from mne.datasets import sample
 
-fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-fname += '/MEG/sample/sample_audvis_raw-eve.fif'
+data_path = sample.data_path('.')
+fname = data_path + '/MEG/sample/sample_audvis_raw-eve.fif'
 
 # Reading events
 events = mne.read_events(fname)
diff --git a/examples/read_inverse.py b/examples/read_inverse.py
index 9515503..5663155 100644
--- a/examples/read_inverse.py
+++ b/examples/read_inverse.py
@@ -10,8 +10,11 @@ Reading an inverse operator
 print __doc__
 
 import mne
+from mne.datasets import sample
 
-fname = 'MNE-sample-data/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'
+data_path = sample.data_path('.')
+fname = data_path
+fname += 'MNE-sample-data/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'
 
 inv = mne.read_inverse_operator(fname)
 
diff --git a/examples/read_write_raw.py b/examples/read_write_raw.py
index 09293ee..6d23be4 100644
--- a/examples/read_write_raw.py
+++ b/examples/read_write_raw.py
@@ -14,8 +14,10 @@ print __doc__
 import os
 from math import ceil
 from mne import fiff
+from mne.datasets import sample
 
-infile = os.environ['MNE_SAMPLE_DATASET_PATH']
+data_path = sample.data_path('.')
+infile = data_path
 infile += '/MEG/sample/sample_audvis_raw.fif'
 outfile = 'sample_audvis_small_raw.fif'
 
diff --git a/examples/stats/plot_sensor_permutation_test.py b/examples/stats/plot_sensor_permutation_test.py
index dcc2484..557b50d 100644
--- a/examples/stats/plot_sensor_permutation_test.py
+++ b/examples/stats/plot_sensor_permutation_test.py
@@ -21,13 +21,13 @@ import numpy as np
 import mne
 from mne import fiff
 from mne.stats import permutation_t_test
+from mne.datasets import sample
 
 ###############################################################################
 # Set parameters
-raw_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-raw_fname += '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
-event_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-event_fname += '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
+data_path = sample.data_path('..')
+raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
+event_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
 event_id = 1
 tmin = -0.2
 tmax = 0.5
diff --git a/examples/time_frequency/plot_time_frequency.py b/examples/time_frequency/plot_time_frequency.py
index bb03ae2..f5209c3 100644
--- a/examples/time_frequency/plot_time_frequency.py
+++ b/examples/time_frequency/plot_time_frequency.py
@@ -20,13 +20,13 @@ import numpy as np
 import mne
 from mne import fiff
 from mne import time_frequency
+from mne.datasets import sample
 
 ###############################################################################
 # Set parameters
-raw_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-raw_fname += '/MEG/sample/sample_audvis_raw.fif'
-event_fname = os.environ['MNE_SAMPLE_DATASET_PATH']
-event_fname += '/MEG/sample/sample_audvis_raw-eve.fif'
+data_path = sample.data_path('..')
+raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
+event_fname = data_path + '/MEG/sample/sample_audvis_raw-eve.fif'
 event_id = 1
 tmin = -0.2
 tmax = 0.5
diff --git a/mne/datasets/__init__.py b/mne/datasets/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/mne/datasets/sample/__init__.py b/mne/datasets/sample/__init__.py
new file mode 100644
index 0000000..9aa2703
--- /dev/null
+++ b/mne/datasets/sample/__init__.py
@@ -0,0 +1,40 @@
+# Author: Alexandre Gramfort <gramfort at nmr.mgh.harvard.edu>
+# License: BSD Style.
+
+import os
+import os.path as op
+
+def data_path(path='.'):
+    """Get path to local copy of Sample dataset
+
+    Parameters
+    ----------
+    dir : string
+        Location of where to look for the sample dataset.
+        If not set. The data will be automatically downloaded in
+        the local folder.
+    """
+    archive_name = "MNE-sample-data-processed.tar.gz"
+    url = "ftp://surfer.nmr.mgh.harvard.edu/pub/data/" + archive_name
+    folder_name = "MNE-sample-data-processed"
+
+    martinos_path = '/homes/6/gramfort/cluster/work/data/MNE-sample-data-processed.tar.gz'
+
+    if not os.path.exists(op.join(path, folder_name)):
+        if os.path.exists(martinos_path):
+            archive_name = martinos_path
+        elif not os.path.exists(archive_name):
+            import urllib
+            print "Downloading data, please Wait (600 MB)..."
+            print url
+            opener = urllib.urlopen(url)
+            open(archive_name, 'wb').write(opener.read())
+            print
+
+        import tarfile
+        print "Decompressiong the archive: " + archive_name
+        tarfile.open(archive_name, "r:gz").extractall(path=path)
+        print
+
+    path = op.join(path, folder_name)
+    return path
diff --git a/mne/layouts/layout.py b/mne/layouts/layout.py
index e73bba4..8eac6b4 100644
--- a/mne/layouts/layout.py
+++ b/mne/layouts/layout.py
@@ -8,7 +8,10 @@ class Layout(object):
     """Sensor layouts"""
     def __init__(self, kind='Vectorview-all'):
         """
+        Parameters
+        ----------
         kind : 'Vectorview-all' | 'CTF-275' | 'Vectorview-grad' | 'Vectorview-mag'
+            Type of layout
         """
         lout_fname = op.join(op.dirname(__file__), kind + '.lout')
 
diff --git a/mne/tests/test_bem_surfaces.py b/mne/tests/test_bem_surfaces.py
index 1703fc9..59e3c26 100644
--- a/mne/tests/test_bem_surfaces.py
+++ b/mne/tests/test_bem_surfaces.py
@@ -1,13 +1,13 @@
-import os
 import os.path as op
 
-import numpy as np
 from numpy.testing import assert_array_almost_equal
 
 import mne
+from mne.datasets import sample
 
-MNE_SAMPLE_DATASET_PATH = os.getenv('MNE_SAMPLE_DATASET_PATH')
-fname = op.join(MNE_SAMPLE_DATASET_PATH, 'subjects', 'sample', 'bem',
+examples_folder = op.join(op.dirname(__file__), '..', '..', 'examples')
+data_path = sample.data_path(examples_folder)
+fname = op.join(data_path, 'subjects', 'sample', 'bem',
                                         'sample-5120-5120-5120-bem-sol.fif')
 
 def test_io_bem_surfaces():
diff --git a/mne/tests/test_forward.py b/mne/tests/test_forward.py
index 5f2f85c..5bf55ba 100644
--- a/mne/tests/test_forward.py
+++ b/mne/tests/test_forward.py
@@ -4,10 +4,11 @@ import os.path as op
 from numpy.testing import assert_array_almost_equal, assert_equal
 
 import mne
+from mne.datasets import sample
 
-MNE_SAMPLE_DATASET_PATH = os.getenv('MNE_SAMPLE_DATASET_PATH')
-fname = op.join(MNE_SAMPLE_DATASET_PATH, 'MEG', 'sample',
-                                            'sample_audvis-meg-oct-6-fwd.fif')
+examples_folder = op.join(op.dirname(__file__), '..', '..', 'examples')
+data_path = sample.data_path(examples_folder)
+fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis-meg-oct-6-fwd.fif')
 
 def test_io_forward():
     """Test IO for forward solutions
diff --git a/mne/tests/test_inverse.py b/mne/tests/test_inverse.py
index a41d0c3..840e02c 100644
--- a/mne/tests/test_inverse.py
+++ b/mne/tests/test_inverse.py
@@ -5,11 +5,13 @@ import numpy as np
 from numpy.testing import assert_array_almost_equal, assert_equal
 
 import mne
+from mne.datasets import sample
 
-MNE_SAMPLE_DATASET_PATH = os.getenv('MNE_SAMPLE_DATASET_PATH')
-fname_inv = op.join(MNE_SAMPLE_DATASET_PATH, 'MEG', 'sample',
+examples_folder = op.join(op.dirname(__file__), '..', '..', 'examples')
+data_path = sample.data_path(examples_folder)
+fname_inv = op.join(data_path, 'MEG', 'sample',
                                         'sample_audvis-meg-oct-6-meg-inv.fif')
-fname_data = op.join(MNE_SAMPLE_DATASET_PATH, 'MEG', 'sample',
+fname_data = op.join(data_path, 'MEG', 'sample',
                                         'sample_audvis-ave.fif')
 
 def test_io_inverse():
diff --git a/mne/tests/test_stc.py b/mne/tests/test_stc.py
index 634d4d6..8eece25 100644
--- a/mne/tests/test_stc.py
+++ b/mne/tests/test_stc.py
@@ -4,10 +4,11 @@ import os.path as op
 from numpy.testing import assert_array_almost_equal
 
 import mne
+from mne.datasets import sample
 
-MNE_SAMPLE_DATASET_PATH = os.getenv('MNE_SAMPLE_DATASET_PATH')
-fname = op.join(MNE_SAMPLE_DATASET_PATH, 'MEG', 'sample',
-                                            'sample_audvis-meg-lh.stc')
+examples_folder = op.join(op.dirname(__file__), '..', '..', 'examples')
+data_path = sample.data_path(examples_folder)
+fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis-meg-lh.stc')
 
 
 def test_io_stc():

-- 
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