From e9cab20449847ca1284258c8300e4c6395e588b3 Mon Sep 17 00:00:00 2001 From: timonmerk Date: Mon, 2 Oct 2023 18:22:42 +0200 Subject: [PATCH] add test for bispectra feature and add dependency --- pyproject.toml | 3 +- tests/test_bispectra.py | 67 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/test_bispectra.py diff --git a/pyproject.toml b/pyproject.toml index ce14d282..24a1eba6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,8 @@ dependencies = [ "scipy >= 1.7.1", "seaborn >= 0.11", "notebook", - "ipython" + "ipython", + "pybispectra" ] [project.optional-dependencies] diff --git a/tests/test_bispectra.py b/tests/test_bispectra.py new file mode 100644 index 00000000..19ea73be --- /dev/null +++ b/tests/test_bispectra.py @@ -0,0 +1,67 @@ +import pytest +import mne +import numpy as np + +from py_neuromodulation import ( + nm_analysis, + nm_decode, + nm_define_nmchannels, + nm_IO, + nm_plots, + nm_settings, + nm_stream_offline +) + +def test_bispectrum(): + + ( + RUN_NAME, + PATH_RUN, + PATH_BIDS, + PATH_OUT, + datatype, + ) = nm_IO.get_paths_example_data() + + ( + raw, + data, + sfreq, + line_noise, + coord_list, + coord_names, + ) = nm_IO.read_BIDS_data( + PATH_RUN=PATH_RUN, BIDS_PATH=PATH_BIDS, datatype=datatype + ) + + ch_names = raw.ch_names[4] + ch_types = raw.get_channel_types()[4] + + nm_channels = nm_define_nmchannels.set_channels( + ch_names=[ch_names], + ch_types=[ch_types], + reference="default", + bads=None, + new_names="default", + used_types=("ecog", "dbs", "seeg"), + target_keywords=("MOV_RIGHT_CLEAN",), + ) + + settings = nm_settings.get_default_settings() + settings = nm_settings.reset_settings(settings) + + settings["features"]["bispectrum"] = True + + stream = nm_stream_offline.Stream( + settings=settings, + nm_channels=nm_channels, + path_grids=None, + verbose=True, + sfreq=sfreq, + line_noise=line_noise, + coord_list=coord_list, + coord_names=coord_names, + ) + + features = stream.run(np.expand_dims(data[3, :], axis=0)) + + assert features["ECOG_RIGHT_1_Bispectrum_phase_mean_whole_fband_range"].sum() != 0 \ No newline at end of file