Skip to content

multifunkim/best-python

Repository files navigation

best-python

The goal of this project is to provide a way to use the best-brainstorm Matlab solvers in Python, compatible with MNE-Python.

For now, the project is using matlab.engine to call the best-brainstorm functions from Python, so you need to have Matlab installed on the computer.

Installation

Matlab and matlabengine package installation

You need to have Matlab installed on your computer. Then, you can install the matlabengine package matching the Matlab version you have installed.

You can run the get_matlab_version.py script to get the version of Matlab installed on your computer.

python get_matlab_version.py

It should return something like:

Getting MATLAB version... Please wait.
MATLAB version found: 24.1.0.123456
Run the following command in the terminal to install the required version:
pip install matlabengine>=24.1.0,<25.0.0

Then, you can install the matlabengine package with the version found:

pip install matlabengine>=24.1.0,<25.0.0

After that, you can install the best-python package:

pip install best-python

Best-brainstorm installation

As the best-python package is using the best-brainstorm functions, you need to have the best-brainstorm toolbox downloaded on your computer.

You can download the best-brainstorm toolbox from the best-brainstorm github.

Usage

You can use the functions from the best-python package like this:

import bestpython

# Create a new instance of the wrapper
# You need to provide the path to the best-brainstorm root folder
matlab_wrapper = bestpython.MatlabWrapper("C:/PATH/OF/BEST-BRAINSTORM/ROOT/FOLDER")

# Define the mandatory options
mem_options = bestpython.MEMOptions(
    data_modality="MEG",
    time_segment = [0.04, 0.18],
    baseline_time = [0.04, 0.1]
)

# Call the solver
stc = matlab_wrapper.mem_solver(evoked, forward, noise_cov, MEMOptions=mem_options)

All options

Extracted from https://github.com/multifunkim/best-python/blob/main/bestpython/mem_options.py

    data_modality : str
        Modality of the data, e.g., 'MEG' or 'EEG'. Default is None.
    pipeline : str, optional
        Selected pipeline, one of 'cMEM', 'wMEM', or 'rMEM'. Default is 'cMEM'.
    noise_cov : float matrix, optional
        Noise covariance matrix. Default is an empty list.
    noise_cov_recompute : bool, optional
        If True, noise covariance is recomputed. If False, a noise covariance matrix must be given. Default is True.
    active_mean_method : int, optional
        Method for computing the active mean. Default is 2.
    alpha_method : int, optional
        Method for computing alpha. Default is 3.
    alpha_threshold : float, optional
        Threshold for alpha. Default is 0.
    initial_lambda : float, optional
        Initial value of lambda. Default is 1.
    depth_weigth_MNE : float, optional
        Depth weight for MNE. Default is 0.
    depth_weigth_MEM : float, optional
        Depth weight for MEM. Default is 0.
    baseline_time : [float, float]
        Slot time used to define the baseline, baseline_time[0] < baseline_time[1]
    time_segment : [float, float]
        Slot time within the algorithm will run, time_segment[0] < time_segment[1]

Full example

You can find a full example in the tests/test.py file link.

License

BEst is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. BEst is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should receive a copy of the GNU General Public License along with BEst. If not, get it here.

minFunc. Schmidt M. see license

References

The references to be acknowledged for each method are:

Additional technical references:

Validation and applications:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published