Skip to content

Commit

Permalink
Merge branch 'master' into log_euclidean_framework
Browse files Browse the repository at this point in the history
  • Loading branch information
gabelstein committed Apr 17, 2024
2 parents d9fbeeb + 6e07fae commit a6cc7f7
Show file tree
Hide file tree
Showing 79 changed files with 2,384 additions and 1,326 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@e53eb8b103ffcb59469888563dc324e3c8ba6f06
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015-2023, authors of pyRiemann
Copyright (c) 2015-2024, authors of pyRiemann
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
18 changes: 11 additions & 7 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ SPD Matrices Estimation
ERPCovariances
XdawnCovariances
BlockCovariances
CospCovariances
CrossSpectra
CoSpectra
Coherences
HankelCovariances
TimeDelayCovariances
Kernels
Shrinkage

Expand Down Expand Up @@ -182,7 +183,6 @@ Datasets

make_gaussian_blobs
make_outliers
make_covariances
make_matrices
make_masks
sample_gaussian_spd
Expand All @@ -192,10 +192,10 @@ Datasets
Utils function
--------------

Utils functions are low level functions that implement most base components of Riemannian Geometry.
Utils functions are low level functions that implement most base components of Riemannian geometry.

Covariance preprocessing
~~~~~~~~~~~~~~~~~~~~~~~~
Covariance processing
~~~~~~~~~~~~~~~~~~~~~
.. _covariance_api:
.. currentmodule:: pyriemann.utils.covariance

Expand Down Expand Up @@ -338,6 +338,7 @@ Aproximate Joint Diagonalization
.. autosummary::
:toctree: generated/

ajd
ajd_pham
rjd
uwedge
Expand Down Expand Up @@ -371,6 +372,9 @@ Visualization
.. autosummary::
:toctree: generated/

plot_embedding
plot_bihist
plot_biscatter
plot_cospectra
plot_cov_ellipse
plot_embedding
plot_waveforms
5 changes: 1 addition & 4 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
curdir = os.path.dirname(__file__)
sys.path.append(os.path.abspath(os.path.join(curdir, 'sphinxext')))


matplotlib.use('Agg')
import shlex
import sphinx_gallery
import sphinx_bootstrap_theme

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -97,7 +94,7 @@

# General information about the project.
project = u'pyRiemann'
copyright = u'2015-2023, pyRiemann Contributors'
copyright = u'2015-2024, pyRiemann Contributors'
author = u'Alexandre Barachant'

# The version info for the project you're documenting, acts as replacement for
Expand Down
31 changes: 30 additions & 1 deletion doc/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ What's new in the package

A catalog of new features, improvements, and bug-fixes in each release.

v0.6.dev
v0.7.dev
--------

- Add kernel option to :class:`pyriemann.embedding.LocallyLinearEmbedding`. :pr:`293` by :user:`gabelstein`

v0.6 (April 2024)
-----------------

- Update pyRiemann from Python 3.7 to 3.8. :pr:`254` by :user:`qbarthelemy`

- Speedup pairwise distance function :func:`pyriemann.utils.distance.pairwise_distance`
Expand All @@ -22,6 +27,30 @@ v0.6.dev

- Correct :func:`pyriemann.utils.distance.distance_wasserstein` and :func:`pyriemann.utils.distance.distance_kullback`, keeping only real part. :pr:`267` by :user:`qbarthelemy`

- Deprecate input ``covmats`` for mean functions, renamed into ``X``. :pr:`252` by :user:`qbarthelemy`

- Add support for complex covariance estimation for 'lwf', 'mcd', 'oas' and 'sch' estimators. :pr:`274` by :user:`gabelstein`

- Deprecate input ``covtest`` for predict of :class:`pyriemann.classification.KNearestNeighbor`, renamed into ``X``. :pr:`259` by :user:`qbarthelemy`

- Correct check for `kernel_fct` param of :class:`pyriemann.classification.SVC`. :pr:`272` by :user:`qbarthelemy`

- Add ``sample_weight`` parameter in TLCenter, TLStretch and TLRotate. :pr:`273` by :user:`apmellot`

- Deprecate ``HankelCovariances``, renamed into :class:`pyriemann.estimation.TimeDelayCovariances`. :pr:`275` by :user:`qbarthelemy`

- Add an example on augmented covariance matrix. :pr:`276` by :user:`carraraig`

- Remove function `make_covariances`. :pr:`280` by :user:`qbarthelemy`

- Speedup :class:`pyriemann.estimation.TimeDelayCovariances`. :pr:`281` by :user:`qbarthelemy`

- Enhance ajd module and add a generic :func:`pyriemann.utils.ajd.ajd` function. :pr:`238` by :user:`qbarthelemy`

- Add :func:`pyriemann.utils.viz.plot_bihist`, :func:`pyriemann.utils.viz.plot_biscatter` and :func:`pyriemann.utils.viz.plot_cov_ellipse` for display. :pr:`287`
by :user:`qbarthelemy` and :user:`gcattan`

- Add :class:`pyriemann.estimation.CrossSpectra` and deprecate `CospCovariances` renamed into :class:`pyriemann.estimation.CoSpectra`. :pr:`288` by :user:`qbarthelemy`

v0.5 (Jun 2023)
---------------
Expand Down
2 changes: 1 addition & 1 deletion examples/ERP/plot_ERP.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
epochs = mne.Epochs(
raw, mne.read_events(event_fname), {'vis_l': 3}, tmin, tmax, proj=False,
baseline=None, preload=True, verbose=False)
X = 5e5 * epochs.get_data()
X = 5e5 * epochs.get_data(copy=False)
print('Number of trials:', X.shape[0])
times = np.linspace(tmin, tmax, num=X.shape[2])

Expand Down
15 changes: 7 additions & 8 deletions examples/ERP/plot_classify_EEG_tangentspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@
# License: BSD (3-clause)

import numpy as np

from pyriemann.estimation import XdawnCovariances
from pyriemann.tangentspace import TangentSpace

from matplotlib import pyplot as plt
import mne
from mne import io
from mne.datasets import sample

from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import KFold
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
from sklearn.pipeline import make_pipeline

from matplotlib import pyplot as plt
from pyriemann.estimation import XdawnCovariances
from pyriemann.tangentspace import TangentSpace

print(__doc__)


###############################################################################
# Set parameters and read data
# ----------------------------

data_path = str(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"
Expand Down Expand Up @@ -65,16 +64,16 @@

labels = epochs.events[:, -1]
evoked = epochs.average()
epochs_data = epochs.get_data(copy=False)

###############################################################################
# Decoding in tangent space with a logistic regression
# ----------------------------------------------------

n_components = 2 # pick some components

# Define a monte-carlo cross-validation generator (reduce variance):
cv = KFold(n_splits=10, shuffle=True, random_state=42)
epochs_data = epochs.get_data()


clf = make_pipeline(
XdawnCovariances(n_components),
Expand Down
7 changes: 3 additions & 4 deletions examples/ERP/plot_classify_MEG_mdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@

import numpy as np
from matplotlib import pyplot as plt
from pyriemann.estimation import XdawnCovariances
from pyriemann.classification import MDM

import mne
from mne import io
from mne.datasets import sample

from sklearn.metrics import (
classification_report,
confusion_matrix,
Expand All @@ -32,6 +28,9 @@
from sklearn.model_selection import KFold
from sklearn.pipeline import make_pipeline

from pyriemann.classification import MDM
from pyriemann.estimation import XdawnCovariances

print(__doc__)


Expand Down
14 changes: 7 additions & 7 deletions examples/ERP/plot_embedding_MEG.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@
# Gabriel Wagner vom Berg <gabriel@bccn-berlin.de>
# License: BSD (3-clause)

from pyriemann.estimation import XdawnCovariances
from pyriemann.utils.viz import plot_embedding

import matplotlib.pyplot as plt
import mne
from mne import io
from mne.datasets import sample

from sklearn.model_selection import train_test_split

import matplotlib.pyplot as plt

from pyriemann.estimation import XdawnCovariances
from pyriemann.utils.viz import plot_embedding

print(__doc__)


###############################################################################
# Set parameters and read data
# ----------------------------

data_path = str(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'
Expand All @@ -56,11 +55,12 @@
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=False,
picks=picks, baseline=None, preload=True, verbose=False)

X = epochs.get_data()
X = epochs.get_data(copy=False)
y = epochs.events[:, -1]

###############################################################################
# Embedding of Xdawn covariance matrices
# --------------------------------------

nfilter = 4
xdwn = XdawnCovariances(estimator='scm', nfilter=nfilter)
Expand Down
14 changes: 8 additions & 6 deletions examples/SSVEP/plot_classify_ssvep_mdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import numpy as np
import matplotlib.pyplot as plt

from mne import find_events, Epochs
from mne.io import Raw
from sklearn.model_selection import cross_val_score, RepeatedKFold
Expand All @@ -36,7 +35,7 @@
# Read data in MNE Raw and numpy format
raw = Raw(destination, preload=True, verbose='ERROR')
events = find_events(raw, shortest_event=0, verbose=False)
raw = raw.pick_types(eeg=True)
raw = raw.pick("eeg")

event_id = {'13 Hz': 2, '17 Hz': 4, '21 Hz': 3, 'resting-state': 1}
sfreq = int(raw.info['sfreq'])
Expand Down Expand Up @@ -100,15 +99,17 @@
###############################################################################
# Building Epochs and plotting 3 s of the signal from electrode Oz for a trial

epochs = Epochs(raw_ext, events, event_id, tmin=2, tmax=5, baseline=None)
epochs = Epochs(
raw_ext, events, event_id, tmin=2, tmax=5, baseline=None
).get_data(copy=False)

n_seconds = 3
time = np.linspace(0, n_seconds, n_seconds * sfreq,
endpoint=False)[np.newaxis, :]
channels = range(0, len(raw_ext.ch_names), len(raw.ch_names))
plt.figure(figsize=(7, 5))
for f, c in zip(frequencies, channels):
plt.plot(epochs.get_data()[5, c, :].T, label=str(int(f))+' Hz')
plt.plot(epochs[5, c, :].T, label=str(int(f))+' Hz')
plt.xlabel("Time (s)")
plt.ylabel(r"Oz after filtering ($\mu$V)")
plt.legend(loc='upper right')
Expand All @@ -125,8 +126,9 @@
# The covariance matrices will be estimated using the Ledoit-Wolf shrinkage
# estimator on the extended signal.

cov_ext_trials = BlockCovariances(estimator='lwf',
block_size=8).transform(epochs.get_data())
cov_ext_trials = BlockCovariances(
estimator='lwf', block_size=8
).transform(epochs)

# This plot shows an example of a covariance matrix observed for each class:
ch_names = raw_ext.info['ch_names']
Expand Down
15 changes: 9 additions & 6 deletions examples/SSVEP/plot_classify_ssvep_pga.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

from mne import find_events, Epochs, make_fixed_length_epochs
from mne.io import Raw
from sklearn.pipeline import make_pipeline
Expand Down Expand Up @@ -64,23 +63,27 @@ def plot_pga(ax, data, labels, centers):
# Training set
raw = Raw(download_data(subject=12, session=1), preload=True, verbose=False)
events = find_events(raw, shortest_event=0, verbose=False)
raw = raw.pick_types(eeg=True)
raw = raw.pick("eeg")
ch_count = len(raw.info['ch_names'])
raw_ext = extend_signal(raw, frequencies, freq_band)
epochs = Epochs(
raw_ext, events, events_id, tmin=2, tmax=5, baseline=None, verbose=False)
raw_ext, events, events_id, tmin=2, tmax=5, baseline=None, verbose=False
).get_data(copy=False)
x_train = BlockCovariances(
estimator='lwf', block_size=ch_count).transform(epochs.get_data())
estimator='lwf', block_size=ch_count
).transform(epochs)
y_train = events[:, 2]

# Testing set
raw = Raw(download_data(subject=12, session=4), preload=True, verbose=False)
raw = raw.pick_types(eeg=True)
raw_ext = extend_signal(raw, frequencies, freq_band)
epochs = make_fixed_length_epochs(
raw_ext, duration=duration, overlap=duration - interval, verbose=False)
raw_ext, duration=duration, overlap=duration - interval, verbose=False
).get_data(copy=False)
x_test = BlockCovariances(
estimator='lwf', block_size=ch_count).transform(epochs.get_data())
estimator='lwf', block_size=ch_count
).transform(epochs)


###############################################################################
Expand Down
3 changes: 1 addition & 2 deletions examples/artifacts/plot_correct_ajdc_EEG.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@

import gzip
import numpy as np
from scipy.signal import welch
from matplotlib import pyplot as plt

from mne import create_info
from mne.io import RawArray
from mne.viz import plot_topomap
from mne.preprocessing import ICA
from scipy.signal import welch

from pyriemann.spatialfilters import AJDC
from pyriemann.utils.viz import plot_cospectra
Expand Down
Loading

0 comments on commit a6cc7f7

Please sign in to comment.