-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add setup file, and tests infrasturcture
- Loading branch information
Showing
8 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[report] | ||
include = */covmatTest/* | ||
omit = | ||
*/python?.?/* | ||
*/site-packages/pytest/* | ||
*/setup.py | ||
*/tests/* | ||
*/examples/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.pyc | ||
.DS_Store | ||
.coverage | ||
.coveralls.yml | ||
/dist | ||
/*.egg-info/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .get_covmat import get_covmat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from pyriemann.estimation import Covariances | ||
from alphawaves.dataset import AlphaWaves | ||
import numpy as np | ||
import mne | ||
import random | ||
|
||
""" | ||
============================= | ||
Get a covariance matrice sample from alphawaves dataset | ||
============================= | ||
TODO | ||
""" | ||
# Authors: Gregoire Cattan <[email protected]> | ||
# | ||
# License: Apache 2.0 | ||
|
||
import warnings | ||
warnings.filterwarnings("ignore") | ||
|
||
trials = [] | ||
|
||
|
||
def _get_trials(raw): | ||
events = mne.find_events(raw=raw, shortest_event=1, verbose=False) | ||
event_id = {'closed': 1, 'open': 2} | ||
epochs = mne.Epochs(raw, events, event_id, tmin=2.0, tmax=8.0, baseline=None, | ||
verbose=False, preload=True) | ||
epochs.pick_types(eeg=True) | ||
return epochs.get_data() | ||
|
||
def _init(): | ||
dataset = AlphaWaves(useMontagePosition = False) | ||
|
||
subjects = dataset.subject_list | ||
n_subjects = len(subjects) | ||
subject = random.randint(0, n_subjects - 1) | ||
|
||
raw = dataset._get_single_subject_data(subject) | ||
|
||
global trials | ||
trials = _get_trials(raw) | ||
return len(trials) | ||
|
||
def _get_covmat(n_channels): | ||
global trials | ||
n_trials = len(trials) | ||
if n_trials == 0: | ||
n_trials = _init() | ||
index = random.randint(0, n_trials - 1) | ||
trial = np.array([trials[index][:n_channels,:]]) | ||
return Covariances(estimator='lwf').fit_transform(trial) | ||
|
||
def get_covmat(n_matrices, n_channels): | ||
covset = np.zeros((n_matrices, n_channels, n_channels)) | ||
for i in range(0, n_matrices): | ||
covset[i] = _get_covmat(n_channels) | ||
return covset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
"""A setuptools based setup module. | ||
See: | ||
https://packaging.python.org/en/latest/distributing.html | ||
https://github.com/pypa/sampleproject | ||
""" | ||
|
||
from setuptools import setup, find_packages | ||
from os import path | ||
from io import open | ||
|
||
here = path.abspath(path.dirname(__file__)) | ||
|
||
with open(path.join(here, 'README.md'), encoding='utf-8') as f: | ||
long_description = f.read() | ||
|
||
setup( | ||
|
||
name='covmatTest', | ||
|
||
version='0.1', | ||
|
||
license='Apache 2.0', | ||
|
||
description='Alpha Waves Dataset', | ||
|
||
long_description=long_description, | ||
|
||
long_description_content_type='text/markdown', | ||
|
||
url='https://github.com/gcattan/covmatTest', | ||
|
||
author='Gregoire Cattan', | ||
|
||
author_email='[email protected]', # Optional | ||
|
||
# For a list of valid classifiers, see https://pypi.org/classifiers/ | ||
classifiers=[ | ||
# How mature is this project? Common values are | ||
# 3 - Alpha | ||
# 4 - Beta | ||
# 5 - Production/Stable | ||
'Development Status :: 3 - Alpha', | ||
|
||
# Indicate who your project is intended for | ||
'Intended Audience :: Science/Research', | ||
'Topic :: Scientific/Engineering', | ||
|
||
# Pick your license as you wish | ||
'License :: OSI Approved', | ||
|
||
# Specify the Python versions you support here. In particular, ensure | ||
# that you indicate whether you support Python 2, Python 3 or both. | ||
'Programming Language :: Python :: 3.7', | ||
], | ||
|
||
# Note that this is a string of words separated by whitespace, not a list. | ||
keywords='EEG neuroscience test covariance matrices', # Optional | ||
|
||
packages=find_packages(exclude=['contrib', 'docs', 'tests']), # Required | ||
|
||
# For an analysis of "install_requires" vs pip's requirements files see: | ||
# https://packaging.python.org/en/latest/requirements.html | ||
install_requires=["alphawaves"], | ||
|
||
# List additional groups of dependencies here (e.g. development | ||
# dependencies). Users will be able to install these using the "extras" | ||
# syntax, for example: | ||
# | ||
# $ pip install sampleproject[dev] | ||
# | ||
# Similar to `install_requires` above, these must be valid existing | ||
# projects. | ||
# extras_require={ # Optional | ||
# 'dev': ['check-manifest'], | ||
# 'test': ['coverage'], | ||
# }, | ||
|
||
# If there are data files included in your packages that need to be | ||
# installed, specify them here. | ||
# | ||
# If using Python 2.6 or earlier, then these have to be included in | ||
# MANIFEST.in as well. | ||
# package_data={ # Optional | ||
# 'sample': ['package_data.dat'], | ||
# }, | ||
|
||
# Although 'package_data' is the preferred approach, in some case you may | ||
# need to place data files outside of your packages. See: | ||
# http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files | ||
# | ||
# In this case, 'data_file' will be installed into '<sys.prefix>/my_data' | ||
# data_files=[('my_data', ['data/data_file'])], # Optional | ||
|
||
# To provide executable scripts, use entry points in preference to the | ||
# "scripts" keyword. Entry points provide cross-platform support and allow | ||
# `pip` to create the appropriate form of executable for the target | ||
# platform. | ||
# | ||
# For example, the following would provide a command called `sample` which | ||
# executes the function `main` from this package when invoked: | ||
# entry_points={ # Optional | ||
# 'console_scripts': [ | ||
# 'sample=sample:main', | ||
# ], | ||
# }, | ||
|
||
# List additional URLs that are relevant to your project as a dict. | ||
# | ||
# This field corresponds to the "Project-URL" metadata fields: | ||
# https://packaging.python.org/specifications/core-metadata/#project-url-multiple-use | ||
# | ||
# Examples listed include a pattern for specifying where the package tracks | ||
# issues, where the source is hosted, where to say thanks to the package | ||
# maintainers, and where to support the project financially. The key is | ||
# what's used to render the link text on PyPI. | ||
# project_urls={ # Optional | ||
# 'Bug Reports': 'https://github.com/pypa/sampleproject/issues', | ||
# 'Funding': 'https://donate.pypi.org', | ||
# 'Say Thanks!': 'http://saythanks.io/to/example', | ||
# 'Source': 'https://github.com/pypa/sampleproject/', | ||
# }, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
from pytest import approx | ||
import numpy as np | ||
|
||
|
||
def is_positive_semi_definite(X): | ||
cs = X.shape[-1] | ||
return np.all(np.linalg.eigvals(X.reshape((-1, cs, cs))) >= 0.0) | ||
|
||
|
||
def is_positive_definite(X): | ||
cs = X.shape[-1] | ||
return np.all(np.linalg.eigvals(X.reshape((-1, cs, cs))) > 0.0) | ||
|
||
|
||
def is_symmetric(X): | ||
return X == approx(np.swapaxes(X, -2, -1)) | ||
|
||
|
||
@pytest.fixture | ||
def is_spd(): | ||
def _is_spd(X): | ||
return is_symmetric(X) and is_positive_definite(X) | ||
|
||
return _is_spd | ||
|
||
|
||
@pytest.fixture | ||
def is_spsd(): | ||
def _is_spsd(X): | ||
return is_symmetric(X) and is_positive_semi_definite(X) | ||
|
||
return _is_spsd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from covmatTest import get_covmat | ||
|
||
|
||
def test_canary(is_spd, is_spds): | ||
get_covmat(1, 1) |