Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b84425c3f9 | |||
| 01ce021a77 | |||
| 153c46659d | |||
| 26e5627fcf | |||
| 923a139846 | |||
| c1454d0b6d | |||
| d9e737faef | |||
| bda1409c51 | |||
| 945f8fb54e | |||
| 44f903bd1f | |||
| e277f96900 | |||
| 3cc58dc817 | |||
| 36387e992c | |||
| ea4766eb2c | |||
| d52aafca46 | |||
| 3045656fa8 | |||
| 3a6b50b131 | |||
| f734d3c47a | |||
| c523818cdb | |||
| 9a9bbdac12 | |||
| de54db82bf | |||
| 289a4dcdff |
@@ -4,6 +4,7 @@ include mne/__init__.py
|
||||
recursive-include examples *.py
|
||||
recursive-include examples *.txt
|
||||
recursive-include mne *.py
|
||||
recursive-include mne/data *.dat
|
||||
recursive-include mne/data *.sel
|
||||
recursive-include mne/data *.fif.gz
|
||||
recursive-include mne/layouts *.lout
|
||||
|
||||
@@ -34,7 +34,7 @@ $(CURDIR)/examples/MNE-sample-data/MEG/sample/sample_audvis_raw.fif:
|
||||
wget ftp://surfer.nmr.mgh.harvard.edu/pub/data/MNE-sample-data-processed.tar.gz
|
||||
tar xvzf MNE-sample-data-processed.tar.gz
|
||||
mv MNE-sample-data examples/
|
||||
ln -s ${PWD}/examples/MNE-sample-data ${PWD}/MNE-sample-data -f
|
||||
ln -sf ${PWD}/examples/MNE-sample-data ${PWD}/MNE-sample-data
|
||||
|
||||
test: in sample_data
|
||||
rm -f .coverage
|
||||
|
||||
@@ -33,4 +33,4 @@ elif sys.argv[1] not in valid_commands:
|
||||
else:
|
||||
cmd = sys.argv[1]
|
||||
cmd_path = op.join(mne_bin_dir, 'commands', 'mne_%s.py' % cmd)
|
||||
sys.exit(subprocess.call([cmd_path] + sys.argv[2:]))
|
||||
sys.exit(subprocess.call([sys.executable, cmd_path] + sys.argv[2:]))
|
||||
|
||||
+12
-1
@@ -15,7 +15,8 @@ ALLSPHINXOPTS = -d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " html to make standalone HTML files (stable version)"
|
||||
@echo " dev_html to make standalone HTML files (dev version)"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@@ -39,11 +40,21 @@ html:
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in build/html."
|
||||
|
||||
html_dev:
|
||||
BUILD_DEV_HTML=1 $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in build/html."
|
||||
|
||||
html-noplot:
|
||||
$(SPHINXBUILD) -D plot_gallery=False -b html $(ALLSPHINXOPTS) build/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in build/html/stable."
|
||||
|
||||
html_dev-noplot:
|
||||
BUILD_DEV_HTML=1 $(SPHINXBUILD) -D plot_gallery=False -b html $(ALLSPHINXOPTS) build/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in build/html/stable."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) build/dirhtml
|
||||
@echo
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 172 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
@@ -45,16 +45,27 @@
|
||||
<!-- <li><a href="{{ pathto('search') }}">Search</a></li> -->
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block relbar1 %}
|
||||
<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px">
|
||||
{% if build_dev_html|tobool %}
|
||||
<div style="background-color: red; color: white; font-weight:bold; text-align: center; padding: 10px; min-width: 910px">
|
||||
This documentation is for the development version ({{ release }}) - <a href="http://martinos.org/mne/stable">Stable version</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div style="background-color: white; text-align: left; padding: 10px 7px 15px 15px; min-width: 910px">
|
||||
<div style="float: left">
|
||||
<a href="{{ pathto('index') }}"><img src="{{
|
||||
pathto("_static/logo.png", 1) }}" border="0" alt="py4sci"/></a>
|
||||
pathto("_static/mne_logo.png", 1) }}" border="0" alt="py4sci"/></a>
|
||||
</div>
|
||||
|
||||
<div style="float: right">
|
||||
<a href="{{ pathto('index') }}"><img src="{{
|
||||
pathto("_static/institutions.png", 1) }}" border="0" alt="py4sci"/></a>
|
||||
</div>
|
||||
<br style="clear:both"/>
|
||||
</div>
|
||||
{{ super() }}
|
||||
{% endblock %}
|
||||
|
||||
{# put the sidebar before the body #}
|
||||
{% block sidebar1 %}{{ sidebar() }}{% endblock %}
|
||||
{% block sidebar2 %}{% endblock %}
|
||||
|
||||
{% block sidebar2 %}{% endblock %}
|
||||
@@ -0,0 +1,5 @@
|
||||
<h3>Versions</h3>
|
||||
<ul class="current">
|
||||
<li class="toctree-l1"><a href=http://martinos.org/mne/stable>Stable</a></li>
|
||||
<li class="toctree-l1"><a href=http://martinos.org/mne/dev>Development</a></li>
|
||||
</ul>
|
||||
+5
-2
@@ -160,7 +160,8 @@ html_last_updated_fmt = '%b %d, %Y'
|
||||
#html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#html_sidebars = {}
|
||||
html_sidebars = {'**': ['globaltoc.html', 'sourcelink.html', 'searchbox.html',
|
||||
'sidebar.html']}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
@@ -179,8 +180,10 @@ html_use_index = False
|
||||
html_show_sourcelink = False
|
||||
|
||||
# variables to pass to HTML templating engine
|
||||
build_dev_html = bool(int(os.environ.get('BUILD_DEV_HTML', False)))
|
||||
|
||||
html_context = {'use_google_analytics':True, 'use_twitter':True,
|
||||
'use_media_buttons':True}
|
||||
'use_media_buttons':True, 'build_dev_html':build_dev_html}
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
|
||||
@@ -29,9 +29,16 @@ component of MNE is presently evolving quickly and thanks to the
|
||||
adopted open development environment user contributions can be easily
|
||||
incorporated.
|
||||
|
||||
The MNE development is supported by National Institute of Biomedical Imaging and Bioengineering
|
||||
grants 5R01EB009048 and P41EB015896 (Center for Functional Neuroimaging Technologies) as well as
|
||||
NSF awards 0958669 and 1042134.
|
||||
|
||||
The Matlab and Python components of MNE are provided under the
|
||||
simplified BSD license.
|
||||
|
||||
|
||||
|
||||
|
||||
* `Download <http://www.nmr.mgh.harvard.edu/martinos/userInfo/data/MNE_register/index.php>`_ MNE
|
||||
* Read the :ref:`manual`.
|
||||
* Get started with :ref:`mne_python`
|
||||
|
||||
@@ -393,9 +393,9 @@ MRI Processing
|
||||
Step by step instructions for using :func:`gui.coregistration`:
|
||||
|
||||
- `Coregistration for subjects with structural MRI
|
||||
<http://www.slideshare.net/slideshow/embed_code/28598463>`_
|
||||
<http://www.slideshare.net/mne-python/mnepython-coregistration>`_
|
||||
- `Scaling a template MRI for subjects for which no MRI is available
|
||||
<http://www.slideshare.net/slideshow/embed_code/28598561>`_
|
||||
<http://www.slideshare.net/mne-python/mnepython-scale-mri>`_
|
||||
|
||||
.. autosummary::
|
||||
:toctree: generated/
|
||||
|
||||
+14
-10
@@ -61,16 +61,20 @@ class Tee(object):
|
||||
def get_data(url):
|
||||
"""Helper function to get data over http or from a local file"""
|
||||
if url.startswith('http://'):
|
||||
resp = urllib2.urlopen(url)
|
||||
encoding = resp.headers.dict.get('content-encoding', 'plain')
|
||||
data = resp.read()
|
||||
if encoding == 'plain':
|
||||
pass
|
||||
elif encoding == 'gzip':
|
||||
data = StringIO(data)
|
||||
data = gzip.GzipFile(fileobj=data).read()
|
||||
else:
|
||||
raise RuntimeError('unknown encoding')
|
||||
try:
|
||||
resp = urllib2.urlopen(url)
|
||||
encoding = resp.headers.dict.get('content-encoding', 'plain')
|
||||
data = resp.read()
|
||||
if encoding == 'plain':
|
||||
pass
|
||||
elif encoding == 'gzip':
|
||||
data = StringIO(data)
|
||||
data = gzip.GzipFile(fileobj=data).read()
|
||||
else:
|
||||
raise RuntimeError('unknown encoding')
|
||||
except urllib2.HTTPError as err:
|
||||
print 'Error downloading %s: %s' % (url, str(err))
|
||||
return ''
|
||||
else:
|
||||
with open(url, 'r') as fid:
|
||||
data = fid.read()
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#scp -r build/html/* martinos-data:/web/html/mne/
|
||||
rsync -rltvz --delete --perms --chmod=g+w build/html/ martinos-data:/web/html/mne/ -essh
|
||||
ssh martinos-data "chgrp -R megweb /web/html/mne"
|
||||
rsync -rltvz --delete --perms --chmod=g+w build/html/ martinos-data:/web/html/ext/mne/stable -essh
|
||||
ssh martinos-data "chgrp -R megweb /web/html/ext/mne/stable"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
"""MNE for MEG and EEG data analysis
|
||||
"""
|
||||
|
||||
__version__ = '0.7'
|
||||
__version__ = '0.7.1'
|
||||
|
||||
# have to import verbose first since it's needed by many things
|
||||
from .utils import (set_log_level, set_log_file, verbose, set_config,
|
||||
|
||||
+3
-3
@@ -715,13 +715,13 @@ def _is_mri_subject(subject, subjects_dir=None):
|
||||
Whether ``subject`` is an mri subject.
|
||||
"""
|
||||
subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
|
||||
sdir = os.path.join(subjects_dir, subject)
|
||||
|
||||
fname = os.path.join(sdir, 'bem', '%s-head.fif' % subject)
|
||||
fname = head_bem_fname.format(subjects_dir=subjects_dir, subject=subject)
|
||||
if not os.path.exists(fname):
|
||||
return False
|
||||
|
||||
fname = os.path.join(sdir, 'bem', '%s-*-bem.fif' % subject)
|
||||
fname = bem_fname.format(subjects_dir=subjects_dir, subject=subject,
|
||||
name='*')
|
||||
if len(glob(fname)) == 0:
|
||||
return False
|
||||
|
||||
|
||||
@@ -205,16 +205,27 @@ def _read_vmrk(vmrk_fname):
|
||||
stim_channel : array
|
||||
An array containing the whole recording's event marking
|
||||
"""
|
||||
# read vmrk file
|
||||
with open(vmrk_fname) as fid:
|
||||
txt = fid.read()
|
||||
|
||||
with open(vmrk_fname) as f:
|
||||
# setup config reader
|
||||
assert (f.readline().strip() ==
|
||||
'Brain Vision Data Exchange Marker File, Version 1.0')
|
||||
start_tag = 'Brain Vision Data Exchange Marker File, Version 1.0'
|
||||
if not txt.startswith(start_tag):
|
||||
raise ValueError("vmrk file should start with %r" % start_tag)
|
||||
|
||||
cfg = SafeConfigParser()
|
||||
cfg.readfp(f)
|
||||
# extract Marker Infos block
|
||||
m = re.search("\[Marker Infos\]", txt)
|
||||
if not m:
|
||||
return np.zeros(0)
|
||||
mk_txt = txt[m.end():]
|
||||
m = re.search("\[.*\]", mk_txt)
|
||||
if m:
|
||||
mk_txt = mk_txt[:m.start()]
|
||||
|
||||
# extract event information
|
||||
items = re.findall("^Mk\d+=(.*)", mk_txt, re.MULTILINE)
|
||||
events = []
|
||||
for _, info in cfg.items('Marker Infos'):
|
||||
for info in items:
|
||||
mtype, mdesc, offset, duration = info.split(',')[:4]
|
||||
if mtype == 'Stimulus':
|
||||
trigger = int(re.findall('S\s?(\d+)', mdesc)[0])
|
||||
|
||||
+5
-4
@@ -417,11 +417,12 @@ def _get_edf_info(fname, n_eeg, stim_channel, annot, annotmap, hpts, preload):
|
||||
if hpts and os.path.lexists(hpts):
|
||||
fid = open(hpts, 'rb').read()
|
||||
locs = {}
|
||||
temp = re.findall('eeg\s(\w+)\s(-?\d+)\s(-?\d+)\s(-?\d+)', fid)
|
||||
temp = temp + re.findall('cardinal\s(\d+)\s(-?\d+)\s(-?\d+)\s(-?\d+)',
|
||||
fid)
|
||||
temp = re.findall('eeg\s(\w+)\s(-?[\d,.]+)\s(-?[\d,.]+)\s(-?[\d,.]+)',
|
||||
fid)
|
||||
temp += re.findall('cardinal\s([\d,.]+)\s(-?[\d,.]+)\s(-?[\d,.]+)\s(-?'
|
||||
'[\d,.]+)', fid)
|
||||
for loc in temp:
|
||||
coord = np.array(map(int, loc[1:]))
|
||||
coord = np.array(map(float, loc[1:]))
|
||||
coord = apply_trans(als_ras_trans_mm, coord)
|
||||
locs[loc[0].lower()] = coord
|
||||
trans = get_ras_to_neuromag_trans(nasion=locs['2'], lpa=locs['1'],
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#
|
||||
# 64 eeg channels
|
||||
# ---------------
|
||||
eeg Fp1 -95 -31 -3
|
||||
eeg Fp1 -95.0 -31.0 -3.0
|
||||
eeg AF7 -81 -59 -3
|
||||
eeg AF3 -87 -41 28
|
||||
eeg F1 -71 -29 64
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import os.path as op
|
||||
import inspect
|
||||
|
||||
from nose.tools import assert_equal
|
||||
from nose.tools import assert_equal, assert_true
|
||||
from numpy.testing import assert_array_almost_equal, assert_array_equal
|
||||
from scipy import io
|
||||
|
||||
@@ -43,6 +43,11 @@ def test_bdf_data():
|
||||
|
||||
assert_array_almost_equal(data_py, data_eeglab)
|
||||
|
||||
# Manually checking that float coordinates are imported
|
||||
assert_true((raw_py.info['chs'][0]['eeg_loc']).any())
|
||||
assert_true((raw_py.info['chs'][25]['eeg_loc']).any())
|
||||
assert_true((raw_py.info['chs'][63]['eeg_loc']).any())
|
||||
|
||||
|
||||
def test_edf_data():
|
||||
"""Test reading raw edf files
|
||||
|
||||
+6
-3
@@ -94,11 +94,14 @@ def read_big(fid, size=None):
|
||||
>>> with open(fname, 'wb') as fid: x.tofile(fid)
|
||||
>>> with open(fname, 'rb') as fid: y = np.fromstring(read_big(fid))
|
||||
>>> assert np.all(x == y)
|
||||
>>> with gzip.open(fname_gz, 'wb') as fid: fid.write(x.tostring())
|
||||
24000000
|
||||
>>> with gzip.open(fname_gz, 'rb') as fid: y = np.fromstring(read_big(fid))
|
||||
>>> fid_gz = gzip.open(fname_gz, 'wb')
|
||||
>>> _ = fid_gz.write(x.tostring())
|
||||
>>> fid_gz.close()
|
||||
>>> fid_gz = gzip.open(fname_gz, 'rb')
|
||||
>>> y = np.fromstring(read_big(fid_gz))
|
||||
>>> assert np.all(x == y)
|
||||
>>> shutil.rmtree(os.path.dirname(fname))
|
||||
>>> fid_gz.close()
|
||||
|
||||
"""
|
||||
# buf_size is chosen as a largest working power of 2 (16 MB):
|
||||
|
||||
@@ -1500,8 +1500,8 @@ def do_forward_solution(subject, meas, fname=None, src=None, spacing=None,
|
||||
logger.info('Running forward solution generation command with '
|
||||
'subjects_dir %s' % subjects_dir)
|
||||
run_subprocess(cmd, env=env)
|
||||
except Exception as exception:
|
||||
raise exception
|
||||
except:
|
||||
raise
|
||||
else:
|
||||
fwd = read_forward_solution(op.join(path, fname), verbose=False)
|
||||
finally:
|
||||
|
||||
+2
-2
@@ -45,9 +45,9 @@ def coregistration(tabbed=False, split=True, scene_width=01, raw=None,
|
||||
All parameters are optional, since they can be set through the GUI.
|
||||
Step by step instructions for the coregistrations can be accessed as
|
||||
slides, `for subjects with structural MRI
|
||||
<http://www.slideshare.net/slideshow/embed_code/28598463>`_ and `for
|
||||
<http://www.slideshare.net/mne-python/mnepython-coregistration>`_ and `for
|
||||
subjects for which no MRI is available
|
||||
<http://www.slideshare.net/slideshow/embed_code/28598561>`_.
|
||||
<http://www.slideshare.net/mne-python/mnepython-scale-mri>`_.
|
||||
"""
|
||||
from ._coreg_gui import CoregFrame, _make_view
|
||||
view = _make_view(tabbed, split, scene_width)
|
||||
|
||||
@@ -73,8 +73,7 @@ from ..utils import get_subjects_dir, logger
|
||||
from ._fiducials_gui import MRIHeadWithFiducialsModel, FiducialsPanel
|
||||
from ._file_traits import (assert_env_set, trans_wildcard, RawSource,
|
||||
SubjectSelectorPanel)
|
||||
from ._viewer import (defaults, HeadViewController, PointObject, SurfaceObject,
|
||||
headview_borders)
|
||||
from ._viewer import defaults, HeadViewController, PointObject, SurfaceObject
|
||||
|
||||
|
||||
laggy_float_editor = TextEditor(auto_set=False, enter_set=True, evaluate=float)
|
||||
@@ -523,6 +522,12 @@ class CoregModel(HasPrivateTraits):
|
||||
head_mri_trans = info['trans']
|
||||
self.set_trans(head_mri_trans)
|
||||
|
||||
def reset(self):
|
||||
"""Reset all the parameters affecting the coregistration"""
|
||||
self.reset_traits(('n_scaling_params', 'scale_x', 'scale_y', 'scale_z',
|
||||
'rot_x', 'rot_y', 'rot_z', 'trans_x', 'trans_y',
|
||||
'trans_z'))
|
||||
|
||||
def set_trans(self, head_mri_trans):
|
||||
"""Set rotation and translation parameters from a transformation matrix
|
||||
|
||||
@@ -885,9 +890,7 @@ class CoregPanel(HasPrivateTraits):
|
||||
warning(None, err, "MNE_ROOT Not Set")
|
||||
|
||||
def _reset_params_fired(self):
|
||||
self.reset_traits(('n_scaling_params', 'scale_x', 'scale_y', 'scale_z',
|
||||
'rot_x', 'rot_y', 'rot_z', 'trans_x', 'trans_y',
|
||||
'trans_z'))
|
||||
self.model.reset()
|
||||
|
||||
def _rot_x_dec_fired(self):
|
||||
self.rot_x -= self.rot_step
|
||||
|
||||
@@ -297,7 +297,7 @@ class RawSource(HasPrivateTraits):
|
||||
def _get_fid_points(self):
|
||||
if not self.raw:
|
||||
return {}
|
||||
digs = {d['ident']: d for d in self.fid_dig}
|
||||
digs = dict((d['ident'], d) for d in self.fid_dig)
|
||||
return digs
|
||||
|
||||
@cached_property
|
||||
@@ -321,6 +321,9 @@ class RawSource(HasPrivateTraits):
|
||||
else:
|
||||
return np.zeros((1, 3))
|
||||
|
||||
def _file_changed(self):
|
||||
self.reset_traits(('points_filter',))
|
||||
|
||||
|
||||
class MRISubjectSource(HasPrivateTraits):
|
||||
"""Find subjects in SUBJECTS_DIR and select one
|
||||
|
||||
@@ -4,24 +4,25 @@
|
||||
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
import numpy as np
|
||||
from numpy.testing import assert_allclose
|
||||
from nose.tools import (assert_equal, assert_almost_equal, assert_false,
|
||||
assert_is_instance, assert_less, assert_raises,
|
||||
assert_true)
|
||||
assert_raises, assert_true)
|
||||
|
||||
import mne
|
||||
from mne.datasets import sample
|
||||
from mne.fiff.kit.tests import data_dir as kit_data_dir
|
||||
from mne.utils import _TempDir, requires_traits, requires_mne_fs_in_env
|
||||
|
||||
|
||||
data_path = sample.data_path(download=False)
|
||||
raw_path = os.path.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif')
|
||||
kit_raw_path = os.path.join(kit_data_dir, 'test_bin.fif')
|
||||
subjects_dir = os.path.join(data_path, 'subjects')
|
||||
|
||||
tempdir = _TempDir()
|
||||
|
||||
trans_dst = os.path.join(tempdir, 'test-trans.fif')
|
||||
|
||||
trans_dst = os.path.join(tempdir, 'test-trans.fif')
|
||||
|
||||
|
||||
@sample.requires_sample_data
|
||||
@@ -35,40 +36,40 @@ def test_coreg_model():
|
||||
|
||||
model.mri.subjects_dir = subjects_dir
|
||||
model.mri.subject = 'sample'
|
||||
|
||||
assert_false(model.mri.fid_ok)
|
||||
model.mri.lpa = [[-0.06, 0, 0]]
|
||||
model.mri.nasion = [[0, 0.05, 0]]
|
||||
model.mri.rpa = [[0.08, 0, 0]]
|
||||
assert_true(model.mri.fid_ok)
|
||||
|
||||
model.hsp.file = raw_path
|
||||
assert_allclose(model.hsp.lpa, [[-7.137e-2, 0, 5.122e-9]], 1e-4)
|
||||
assert_allclose(model.hsp.rpa, [[ 7.527e-2, 0, 5.588e-9]], 1e-4)
|
||||
assert_allclose(model.hsp.nasion, [[ 3.725e-9, 1.026e-1, 4.191e-9]], 1e-4)
|
||||
assert_true(model.has_fid_data)
|
||||
|
||||
assert_false(model.mri.fid_ok)
|
||||
model.mri.lpa = [[-0.06, 0, 0]]
|
||||
model.mri.nasion = [[0, 0.05, 0]]
|
||||
model.mri.rpa = [[0.08, 0, 0]]
|
||||
assert_true(model.mri.fid_ok)
|
||||
|
||||
model.hsp.file = raw_path
|
||||
assert_allclose(model.hsp.lpa, [[-7.137e-2, 0, 5.122e-9]], 1e-4)
|
||||
assert_allclose(model.hsp.rpa, [[+7.527e-2, 0, 5.588e-9]], 1e-4)
|
||||
assert_allclose(model.hsp.nasion, [[+3.725e-9, 1.026e-1, 4.191e-9]], 1e-4)
|
||||
assert_true(model.has_fid_data)
|
||||
|
||||
lpa_distance = model.lpa_distance
|
||||
nasion_distance = model.nasion_distance
|
||||
rpa_distance = model.rpa_distance
|
||||
avg_point_distance = np.mean(model.point_distance)
|
||||
|
||||
model.fit_auricular_points()
|
||||
old_x = lpa_distance ** 2 + rpa_distance ** 2
|
||||
model.fit_auricular_points()
|
||||
old_x = lpa_distance ** 2 + rpa_distance ** 2
|
||||
new_x = model.lpa_distance ** 2 + model.rpa_distance ** 2
|
||||
assert_less(new_x, old_x)
|
||||
|
||||
model.fit_fiducials()
|
||||
old_x = lpa_distance ** 2 + rpa_distance ** 2 + nasion_distance ** 2
|
||||
assert_true(new_x < old_x)
|
||||
|
||||
model.fit_fiducials()
|
||||
old_x = lpa_distance ** 2 + rpa_distance ** 2 + nasion_distance ** 2
|
||||
new_x = (model.lpa_distance ** 2 + model.rpa_distance ** 2
|
||||
+ model.nasion_distance ** 2)
|
||||
assert_less(new_x, old_x)
|
||||
|
||||
model.fit_hsp_points()
|
||||
assert_less(np.mean(model.point_distance), avg_point_distance)
|
||||
|
||||
model.save_trans(trans_dst)
|
||||
trans = mne.read_trans(trans_dst)
|
||||
+ model.nasion_distance ** 2)
|
||||
assert_true(new_x < old_x)
|
||||
|
||||
model.fit_hsp_points()
|
||||
assert_true(np.mean(model.point_distance) < avg_point_distance)
|
||||
|
||||
model.save_trans(trans_dst)
|
||||
trans = mne.read_trans(trans_dst)
|
||||
assert_allclose(trans['trans'], model.head_mri_trans)
|
||||
|
||||
# test restoring trans
|
||||
@@ -92,9 +93,9 @@ def test_coreg_model():
|
||||
assert_almost_equal(model.rot_z, rot_z)
|
||||
|
||||
# info
|
||||
assert_is_instance(model.fid_eval_str, basestring)
|
||||
assert_is_instance(model.points_eval_str, basestring)
|
||||
|
||||
assert_true(isinstance(model.fid_eval_str, basestring))
|
||||
assert_true(isinstance(model.points_eval_str, basestring))
|
||||
|
||||
|
||||
@sample.requires_sample_data
|
||||
@requires_traits
|
||||
@@ -127,22 +128,22 @@ def test_coreg_model_with_fsaverage():
|
||||
assert_equal(model.hsp.n_omitted, 1)
|
||||
|
||||
# scale with 1 parameter
|
||||
model.n_scale_params = 1
|
||||
|
||||
model.fit_scale_auricular_points()
|
||||
model.n_scale_params = 1
|
||||
|
||||
model.fit_scale_auricular_points()
|
||||
old_x = lpa_distance ** 2 + rpa_distance ** 2
|
||||
new_x = model.lpa_distance ** 2 + model.rpa_distance ** 2
|
||||
assert_less(new_x, old_x)
|
||||
assert_true(new_x < old_x)
|
||||
|
||||
model.fit_scale_fiducials()
|
||||
old_x = lpa_distance ** 2 + rpa_distance ** 2 + nasion_distance ** 2
|
||||
new_x = (model.lpa_distance ** 2 + model.rpa_distance ** 2
|
||||
+ model.nasion_distance ** 2)
|
||||
assert_less(new_x, old_x)
|
||||
assert_true(new_x < old_x)
|
||||
|
||||
model.fit_scale_hsp_points()
|
||||
avg_point_distance_1param = np.mean(model.point_distance)
|
||||
assert_less(avg_point_distance_1param, avg_point_distance)
|
||||
assert_true(avg_point_distance_1param < avg_point_distance)
|
||||
|
||||
desc, func, args, kwargs = model.get_scaling_job('test')
|
||||
assert_true(isinstance(desc, basestring))
|
||||
@@ -154,4 +155,9 @@ def test_coreg_model_with_fsaverage():
|
||||
# scale with 3 parameters
|
||||
model.n_scale_params = 3
|
||||
model.fit_scale_hsp_points()
|
||||
assert_less(np.mean(model.point_distance), avg_point_distance_1param)
|
||||
assert_true(np.mean(model.point_distance) < avg_point_distance_1param)
|
||||
|
||||
# test switching raw disables point omission
|
||||
assert_equal(model.hsp.n_omitted, 1)
|
||||
model.hsp.file = kit_raw_path
|
||||
assert_equal(model.hsp.n_omitted, 0)
|
||||
|
||||
@@ -664,7 +664,7 @@ def test_epoch_eq():
|
||||
epochs[key]
|
||||
except KeyError:
|
||||
caught += 1
|
||||
assert_raises(caught == 2)
|
||||
assert_raises(Exception, caught == 2)
|
||||
assert_true(not np.any(epochs.events[:, 2] == 1))
|
||||
assert_true(not np.any(epochs.events[:, 2] == 2))
|
||||
epochs = combine_event_ids(epochs, ['c', 'd'], {'cd': 34})
|
||||
|
||||
@@ -122,14 +122,14 @@ def test_config():
|
||||
del os.environ[key]
|
||||
# catch the warning about it being a non-standard config key
|
||||
with warnings.catch_warnings(True) as w:
|
||||
set_config(key, None)
|
||||
set_config(key, None, home_dir=tempdir)
|
||||
assert_true(len(w) == 1)
|
||||
assert_true(get_config(key) is None)
|
||||
assert_true(get_config(key, home_dir=tempdir) is None)
|
||||
assert_raises(KeyError, get_config, key, raise_error=True)
|
||||
with warnings.catch_warnings(True):
|
||||
set_config(key, value)
|
||||
assert_true(get_config(key) == value)
|
||||
set_config(key, None)
|
||||
set_config(key, value, home_dir=tempdir)
|
||||
assert_true(get_config(key, home_dir=tempdir) == value)
|
||||
set_config(key, None, home_dir=tempdir)
|
||||
if old_val is not None:
|
||||
os.environ[key] = old_val
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import numpy as np
|
||||
from nose.tools import assert_raises, assert_equal, assert_almost_equal
|
||||
from nose.tools import (assert_raises, assert_equal, assert_almost_equal,
|
||||
assert_true)
|
||||
from numpy.testing import assert_array_equal
|
||||
from os import path as op
|
||||
|
||||
@@ -124,8 +125,8 @@ def test_compute_epochs_csd_on_artificial_data():
|
||||
data_csd_mt = compute_epochs_csd(epochs_sin, mode='multitaper')
|
||||
fourier_power = np.abs(data_csd_fourier.data[0, 0]) * sfreq
|
||||
mt_power = np.abs(data_csd_mt.data[0, 0]) * sfreq
|
||||
assert_almost_equal(fourier_power, signal_power, delta=0.5)
|
||||
assert_almost_equal(mt_power, signal_power, delta=1)
|
||||
assert_true(abs(fourier_power - signal_power) <= 0.5)
|
||||
assert_true(abs(mt_power - signal_power) <= 1)
|
||||
|
||||
# Power per sample should not depend on time window length
|
||||
for tmax in [0.2, 0.4, 0.6, 0.8]:
|
||||
@@ -139,9 +140,8 @@ def test_compute_epochs_csd_on_artificial_data():
|
||||
fmax=np.inf, n_fft=n_fft)
|
||||
fourier_power_per_sample = np.abs(data_csd_fourier.data[0, 0]) *\
|
||||
sfreq / data_csd_fourier.n_fft
|
||||
assert_almost_equal(signal_power_per_sample,
|
||||
fourier_power_per_sample, delta=0.003)
|
||||
|
||||
assert_true(abs(signal_power_per_sample -
|
||||
fourier_power_per_sample) < 0.003)
|
||||
# Power per sample should not depend on number of tapers
|
||||
for n_tapers in [1, 2, 3, 5]:
|
||||
for add_n_fft in [30, 0, 30]:
|
||||
@@ -159,5 +159,5 @@ def test_compute_epochs_csd_on_artificial_data():
|
||||
delta = 0.05
|
||||
else:
|
||||
delta = 0.004
|
||||
assert_almost_equal(signal_power_per_sample,
|
||||
mt_power_per_sample, delta=delta)
|
||||
assert_true(abs(signal_power_per_sample - mt_power_per_sample)
|
||||
< delta)
|
||||
|
||||
+31
-15
@@ -215,8 +215,12 @@ def run_subprocess(command, *args, **kwargs):
|
||||
|
||||
output = (stdout_, stderr)
|
||||
if p.returncode:
|
||||
print output
|
||||
raise subprocess.CalledProcessError(p.returncode, command, output)
|
||||
print(output)
|
||||
err_fun = subprocess.CalledProcessError.__init__
|
||||
if 'output' in inspect.getargspec(err_fun).args:
|
||||
raise subprocess.CalledProcessError(p.returncode, command, output)
|
||||
else:
|
||||
raise subprocess.CalledProcessError(p.returncode, command)
|
||||
|
||||
return output
|
||||
|
||||
@@ -704,9 +708,15 @@ def get_subjects_dir(subjects_dir=None, raise_error=False):
|
||||
return subjects_dir
|
||||
|
||||
|
||||
def get_config_path():
|
||||
def get_config_path(home_dir=None):
|
||||
"""Get path to standard mne-python config file
|
||||
|
||||
Parameters
|
||||
----------
|
||||
home_dir : str | None
|
||||
The folder that contains the .mne config folder.
|
||||
If None, it is found automatically.
|
||||
|
||||
Returns
|
||||
-------
|
||||
config_path : str
|
||||
@@ -714,16 +724,17 @@ def get_config_path():
|
||||
will be '%APPDATA%\.mne\mne-python.json'. On every other
|
||||
system, this will be $HOME/.mne/mne-python.json.
|
||||
"""
|
||||
if home_dir is None:
|
||||
# this has been checked on OSX64, Linux64, and Win32
|
||||
home_dir = os.getenv('APPDATA' if 'nt' == os.name.lower() else 'HOME',
|
||||
None)
|
||||
|
||||
# this has been checked on OSX64, Linux64, and Win32
|
||||
val = os.getenv('APPDATA' if 'nt' == os.name.lower() else 'HOME', None)
|
||||
if val is None:
|
||||
if home_dir is None:
|
||||
raise ValueError('mne-python config file path could '
|
||||
'not be determined, please report this '
|
||||
'error to mne-python developers')
|
||||
|
||||
val = op.join(val, '.mne', 'mne-python.json')
|
||||
return val
|
||||
return op.join(home_dir, '.mne', 'mne-python.json')
|
||||
|
||||
|
||||
def set_cache_dir(cache_dir):
|
||||
@@ -787,7 +798,7 @@ known_config_wildcards = [
|
||||
]
|
||||
|
||||
|
||||
def get_config(key, default=None, raise_error=False):
|
||||
def get_config(key, default=None, raise_error=False, home_dir=None):
|
||||
"""Read mne(-python) preference from env, then mne-python config
|
||||
|
||||
Parameters
|
||||
@@ -800,6 +811,9 @@ def get_config(key, default=None, raise_error=False):
|
||||
raise_error : bool
|
||||
If True, raise an error if the key is not found (instead of returning
|
||||
default).
|
||||
home_dir : str | None
|
||||
The folder that contains the .mne config folder.
|
||||
If None, it is found automatically.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -815,7 +829,7 @@ def get_config(key, default=None, raise_error=False):
|
||||
return os.environ[key]
|
||||
|
||||
# second, look for it in mne-python config file
|
||||
config_path = get_config_path()
|
||||
config_path = get_config_path(home_dir=home_dir)
|
||||
if not op.isfile(config_path):
|
||||
key_found = False
|
||||
val = default
|
||||
@@ -838,7 +852,7 @@ def get_config(key, default=None, raise_error=False):
|
||||
return val
|
||||
|
||||
|
||||
def set_config(key, value):
|
||||
def set_config(key, value, home_dir=None):
|
||||
"""Set mne-python preference in config
|
||||
|
||||
Parameters
|
||||
@@ -848,8 +862,10 @@ def set_config(key, value):
|
||||
value : str | None
|
||||
The value to assign to the preference key. If None, the key is
|
||||
deleted.
|
||||
home_dir : str | None
|
||||
The folder that contains the .mne config folder.
|
||||
If None, it is found automatically.
|
||||
"""
|
||||
|
||||
if not isinstance(key, basestring):
|
||||
raise ValueError('key must be a string')
|
||||
# While JSON allow non-string types, we allow users to override config
|
||||
@@ -861,7 +877,7 @@ def set_config(key, value):
|
||||
warnings.warn('Setting non-standard config type: "%s"' % key)
|
||||
|
||||
# Read all previous values
|
||||
config_path = get_config_path()
|
||||
config_path = get_config_path(home_dir=home_dir)
|
||||
if op.isfile(config_path):
|
||||
with open(config_path, 'r') as fid:
|
||||
config = json.load(fid)
|
||||
@@ -921,7 +937,7 @@ class ProgressBar(object):
|
||||
"""
|
||||
|
||||
spinner_symbols = ['|', '/', '-', '\\']
|
||||
template = '\r[{}{}] {:.05f} {} {} '
|
||||
template = '\r[{0}{1}] {2:.05f} {3} {4} '
|
||||
|
||||
def __init__(self, max_value, initial_value=0, mesg='', max_chars=40,
|
||||
progress_character='.', spinner=False):
|
||||
@@ -1162,7 +1178,7 @@ def sizeof_fmt(num):
|
||||
exponent = min(int(log(num, 1024)), len(unit_list) - 1)
|
||||
quotient = float(num) / 1024 ** exponent
|
||||
unit, num_decimals = unit_list[exponent]
|
||||
format_string = '{:.%sf} {}' % (num_decimals)
|
||||
format_string = '{0:.%sf} {1}' % (num_decimals)
|
||||
return format_string.format(quotient, unit)
|
||||
if num == 0:
|
||||
return '0 bytes'
|
||||
|
||||
Reference in New Issue
Block a user