py-neuromodulation 0.0.3__py3-none-any.whl → 0.0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py_neuromodulation/ConnectivityDecoding/Automated Anatomical Labeling 3 (Rolls 2020).nii +0 -0
- py_neuromodulation/ConnectivityDecoding/_get_grid_hull.m +34 -0
- py_neuromodulation/ConnectivityDecoding/_get_grid_whole_brain.py +95 -0
- py_neuromodulation/ConnectivityDecoding/_helper_write_connectome.py +107 -0
- py_neuromodulation/ConnectivityDecoding/mni_coords_cortical_surface.mat +0 -0
- py_neuromodulation/ConnectivityDecoding/mni_coords_whole_brain.mat +0 -0
- py_neuromodulation/ConnectivityDecoding/rmap_func_all.nii +0 -0
- py_neuromodulation/ConnectivityDecoding/rmap_struc.nii +0 -0
- py_neuromodulation/FieldTrip.py +589 -589
- py_neuromodulation/__init__.py +74 -13
- py_neuromodulation/_write_example_dataset_helper.py +83 -65
- py_neuromodulation/data/README +6 -0
- py_neuromodulation/data/dataset_description.json +8 -0
- py_neuromodulation/data/participants.json +32 -0
- py_neuromodulation/data/participants.tsv +2 -0
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_space-mni_coordsystem.json +5 -0
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_space-mni_electrodes.tsv +11 -0
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_channels.tsv +11 -0
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.eeg +0 -0
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.json +18 -0
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vhdr +35 -0
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vmrk +13 -0
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/sub-testsub_ses-EphysMedOff_scans.tsv +2 -0
- py_neuromodulation/grid_cortex.tsv +40 -0
- py_neuromodulation/grid_subcortex.tsv +1429 -0
- py_neuromodulation/liblsl/libpugixml.so.1.12 +0 -0
- py_neuromodulation/liblsl/linux/bionic_amd64/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/bookworm_amd64/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/focal_amd46/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/jammy_amd64/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/jammy_x86/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/noble_amd64/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/macos/amd64/liblsl.1.16.2.dylib +0 -0
- py_neuromodulation/liblsl/macos/arm64/liblsl.1.16.0.dylib +0 -0
- py_neuromodulation/liblsl/windows/amd64/liblsl.1.16.2.dll +0 -0
- py_neuromodulation/liblsl/windows/x86/liblsl.1.16.2.dll +0 -0
- py_neuromodulation/nm_IO.py +413 -417
- py_neuromodulation/nm_RMAP.py +496 -531
- py_neuromodulation/nm_analysis.py +993 -1074
- py_neuromodulation/nm_artifacts.py +30 -25
- py_neuromodulation/nm_bispectra.py +154 -168
- py_neuromodulation/nm_bursts.py +292 -198
- py_neuromodulation/nm_coherence.py +251 -205
- py_neuromodulation/nm_database.py +149 -0
- py_neuromodulation/nm_decode.py +918 -992
- py_neuromodulation/nm_define_nmchannels.py +300 -302
- py_neuromodulation/nm_features.py +144 -116
- py_neuromodulation/nm_filter.py +219 -219
- py_neuromodulation/nm_filter_preprocessing.py +79 -91
- py_neuromodulation/nm_fooof.py +139 -159
- py_neuromodulation/nm_generator.py +45 -37
- py_neuromodulation/nm_hjorth_raw.py +52 -73
- py_neuromodulation/nm_kalmanfilter.py +71 -58
- py_neuromodulation/nm_linelength.py +21 -33
- py_neuromodulation/nm_logger.py +66 -0
- py_neuromodulation/nm_mne_connectivity.py +149 -112
- py_neuromodulation/nm_mnelsl_generator.py +90 -0
- py_neuromodulation/nm_mnelsl_stream.py +116 -0
- py_neuromodulation/nm_nolds.py +96 -93
- py_neuromodulation/nm_normalization.py +173 -214
- py_neuromodulation/nm_oscillatory.py +423 -448
- py_neuromodulation/nm_plots.py +585 -612
- py_neuromodulation/nm_preprocessing.py +83 -0
- py_neuromodulation/nm_projection.py +370 -394
- py_neuromodulation/nm_rereference.py +97 -95
- py_neuromodulation/nm_resample.py +59 -50
- py_neuromodulation/nm_run_analysis.py +325 -435
- py_neuromodulation/nm_settings.py +289 -68
- py_neuromodulation/nm_settings.yaml +244 -0
- py_neuromodulation/nm_sharpwaves.py +423 -401
- py_neuromodulation/nm_stats.py +464 -480
- py_neuromodulation/nm_stream.py +398 -0
- py_neuromodulation/nm_stream_abc.py +166 -218
- py_neuromodulation/nm_types.py +193 -0
- py_neuromodulation/plots/STN_surf.mat +0 -0
- py_neuromodulation/plots/Vertices.mat +0 -0
- py_neuromodulation/plots/faces.mat +0 -0
- py_neuromodulation/plots/grid.mat +0 -0
- {py_neuromodulation-0.0.3.dist-info → py_neuromodulation-0.0.5.dist-info}/METADATA +185 -182
- py_neuromodulation-0.0.5.dist-info/RECORD +83 -0
- {py_neuromodulation-0.0.3.dist-info → py_neuromodulation-0.0.5.dist-info}/WHEEL +1 -2
- {py_neuromodulation-0.0.3.dist-info → py_neuromodulation-0.0.5.dist-info/licenses}/LICENSE +21 -21
- docs/build/_downloads/09df217f95985497f45d69e2d4bdc5b1/plot_2_example_add_feature.py +0 -68
- docs/build/_downloads/3b4900a2b2818ff30362215b76f7d5eb/plot_1_example_BIDS.py +0 -233
- docs/build/_downloads/7e92dd2e6cc86b239d14cafad972ae4f/plot_3_example_sharpwave_analysis.py +0 -219
- docs/build/_downloads/c2db0bf2b334d541b00662b991682256/plot_6_real_time_demo.py +0 -97
- docs/build/_downloads/ce3914826f782cbd1ea8fd024eaf0ac3/plot_5_example_rmap_computing.py +0 -64
- docs/build/_downloads/da36848a41e6a3235d91fb7cfb6d59b4/plot_0_first_demo.py +0 -192
- docs/build/_downloads/eaa4305c75b19a1e2eea941f742a6331/plot_4_example_gridPointProjection.py +0 -210
- docs/build/html/_downloads/09df217f95985497f45d69e2d4bdc5b1/plot_2_example_add_feature.py +0 -68
- docs/build/html/_downloads/3b4900a2b2818ff30362215b76f7d5eb/plot_1_example_BIDS.py +0 -239
- docs/build/html/_downloads/7e92dd2e6cc86b239d14cafad972ae4f/plot_3_example_sharpwave_analysis.py +0 -219
- docs/build/html/_downloads/c2db0bf2b334d541b00662b991682256/plot_6_real_time_demo.py +0 -97
- docs/build/html/_downloads/ce3914826f782cbd1ea8fd024eaf0ac3/plot_5_example_rmap_computing.py +0 -64
- docs/build/html/_downloads/da36848a41e6a3235d91fb7cfb6d59b4/plot_0_first_demo.py +0 -192
- docs/build/html/_downloads/eaa4305c75b19a1e2eea941f742a6331/plot_4_example_gridPointProjection.py +0 -210
- docs/source/_build/html/_downloads/09df217f95985497f45d69e2d4bdc5b1/plot_2_example_add_feature.py +0 -76
- docs/source/_build/html/_downloads/0d0d0a76e8f648d5d3cbc47da6351932/plot_real_time_demo.py +0 -97
- docs/source/_build/html/_downloads/3b4900a2b2818ff30362215b76f7d5eb/plot_1_example_BIDS.py +0 -240
- docs/source/_build/html/_downloads/5d73cadc59a8805c47e3b84063afc157/plot_example_BIDS.py +0 -233
- docs/source/_build/html/_downloads/7660317fa5a6bfbd12fcca9961457fc4/plot_example_rmap_computing.py +0 -63
- docs/source/_build/html/_downloads/7e92dd2e6cc86b239d14cafad972ae4f/plot_3_example_sharpwave_analysis.py +0 -219
- docs/source/_build/html/_downloads/839e5b319379f7fd9e867deb00fd797f/plot_example_gridPointProjection.py +0 -210
- docs/source/_build/html/_downloads/ae8be19afe5e559f011fc9b138968ba0/plot_first_demo.py +0 -192
- docs/source/_build/html/_downloads/b8b06cacc17969d3725a0b6f1d7741c5/plot_example_sharpwave_analysis.py +0 -219
- docs/source/_build/html/_downloads/c2db0bf2b334d541b00662b991682256/plot_6_real_time_demo.py +0 -121
- docs/source/_build/html/_downloads/c31a86c0b68cb4167d968091ace8080d/plot_example_add_feature.py +0 -68
- docs/source/_build/html/_downloads/ce3914826f782cbd1ea8fd024eaf0ac3/plot_5_example_rmap_computing.py +0 -64
- docs/source/_build/html/_downloads/da36848a41e6a3235d91fb7cfb6d59b4/plot_0_first_demo.py +0 -189
- docs/source/_build/html/_downloads/eaa4305c75b19a1e2eea941f742a6331/plot_4_example_gridPointProjection.py +0 -210
- docs/source/auto_examples/plot_0_first_demo.py +0 -189
- docs/source/auto_examples/plot_1_example_BIDS.py +0 -240
- docs/source/auto_examples/plot_2_example_add_feature.py +0 -76
- docs/source/auto_examples/plot_3_example_sharpwave_analysis.py +0 -219
- docs/source/auto_examples/plot_4_example_gridPointProjection.py +0 -210
- docs/source/auto_examples/plot_5_example_rmap_computing.py +0 -64
- docs/source/auto_examples/plot_6_real_time_demo.py +0 -121
- docs/source/conf.py +0 -105
- examples/plot_0_first_demo.py +0 -189
- examples/plot_1_example_BIDS.py +0 -240
- examples/plot_2_example_add_feature.py +0 -76
- examples/plot_3_example_sharpwave_analysis.py +0 -219
- examples/plot_4_example_gridPointProjection.py +0 -210
- examples/plot_5_example_rmap_computing.py +0 -64
- examples/plot_6_real_time_demo.py +0 -121
- packages/realtime_decoding/build/lib/realtime_decoding/__init__.py +0 -4
- packages/realtime_decoding/build/lib/realtime_decoding/decoder.py +0 -104
- packages/realtime_decoding/build/lib/realtime_decoding/features.py +0 -163
- packages/realtime_decoding/build/lib/realtime_decoding/helpers.py +0 -15
- packages/realtime_decoding/build/lib/realtime_decoding/run_decoding.py +0 -345
- packages/realtime_decoding/build/lib/realtime_decoding/trainer.py +0 -54
- packages/tmsi/build/lib/TMSiFileFormats/__init__.py +0 -37
- packages/tmsi/build/lib/TMSiFileFormats/file_formats/__init__.py +0 -36
- packages/tmsi/build/lib/TMSiFileFormats/file_formats/lsl_stream_writer.py +0 -200
- packages/tmsi/build/lib/TMSiFileFormats/file_formats/poly5_file_writer.py +0 -496
- packages/tmsi/build/lib/TMSiFileFormats/file_formats/poly5_to_edf_converter.py +0 -236
- packages/tmsi/build/lib/TMSiFileFormats/file_formats/xdf_file_writer.py +0 -977
- packages/tmsi/build/lib/TMSiFileFormats/file_readers/__init__.py +0 -35
- packages/tmsi/build/lib/TMSiFileFormats/file_readers/edf_reader.py +0 -116
- packages/tmsi/build/lib/TMSiFileFormats/file_readers/poly5reader.py +0 -294
- packages/tmsi/build/lib/TMSiFileFormats/file_readers/xdf_reader.py +0 -229
- packages/tmsi/build/lib/TMSiFileFormats/file_writer.py +0 -102
- packages/tmsi/build/lib/TMSiPlotters/__init__.py +0 -2
- packages/tmsi/build/lib/TMSiPlotters/gui/__init__.py +0 -39
- packages/tmsi/build/lib/TMSiPlotters/gui/_plotter_gui.py +0 -234
- packages/tmsi/build/lib/TMSiPlotters/gui/plotting_gui.py +0 -440
- packages/tmsi/build/lib/TMSiPlotters/plotters/__init__.py +0 -44
- packages/tmsi/build/lib/TMSiPlotters/plotters/hd_emg_plotter.py +0 -446
- packages/tmsi/build/lib/TMSiPlotters/plotters/impedance_plotter.py +0 -589
- packages/tmsi/build/lib/TMSiPlotters/plotters/signal_plotter.py +0 -1326
- packages/tmsi/build/lib/TMSiSDK/__init__.py +0 -54
- packages/tmsi/build/lib/TMSiSDK/device.py +0 -588
- packages/tmsi/build/lib/TMSiSDK/devices/__init__.py +0 -34
- packages/tmsi/build/lib/TMSiSDK/devices/saga/TMSi_Device_API.py +0 -1764
- packages/tmsi/build/lib/TMSiSDK/devices/saga/__init__.py +0 -34
- packages/tmsi/build/lib/TMSiSDK/devices/saga/saga_device.py +0 -1366
- packages/tmsi/build/lib/TMSiSDK/devices/saga/saga_types.py +0 -520
- packages/tmsi/build/lib/TMSiSDK/devices/saga/xml_saga_config.py +0 -165
- packages/tmsi/build/lib/TMSiSDK/error.py +0 -95
- packages/tmsi/build/lib/TMSiSDK/sample_data.py +0 -63
- packages/tmsi/build/lib/TMSiSDK/sample_data_server.py +0 -99
- packages/tmsi/build/lib/TMSiSDK/settings.py +0 -45
- packages/tmsi/build/lib/TMSiSDK/tmsi_device.py +0 -111
- packages/tmsi/build/lib/__init__.py +0 -4
- packages/tmsi/build/lib/apex_sdk/__init__.py +0 -34
- packages/tmsi/build/lib/apex_sdk/device/__init__.py +0 -41
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_API.py +0 -1009
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_API_enums.py +0 -239
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_API_structures.py +0 -668
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_device.py +0 -1611
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_dongle.py +0 -38
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_event_reader.py +0 -57
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_structures/apex_channel.py +0 -44
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_structures/apex_config.py +0 -150
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_structures/apex_const.py +0 -36
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_structures/apex_impedance_channel.py +0 -48
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_structures/apex_info.py +0 -108
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/apex_structures/dongle_info.py +0 -39
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/measurements/download_measurement.py +0 -77
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/measurements/eeg_measurement.py +0 -150
- packages/tmsi/build/lib/apex_sdk/device/devices/apex/measurements/impedance_measurement.py +0 -129
- packages/tmsi/build/lib/apex_sdk/device/threads/conversion_thread.py +0 -59
- packages/tmsi/build/lib/apex_sdk/device/threads/sampling_thread.py +0 -57
- packages/tmsi/build/lib/apex_sdk/device/tmsi_channel.py +0 -83
- packages/tmsi/build/lib/apex_sdk/device/tmsi_device.py +0 -201
- packages/tmsi/build/lib/apex_sdk/device/tmsi_device_enums.py +0 -103
- packages/tmsi/build/lib/apex_sdk/device/tmsi_dongle.py +0 -43
- packages/tmsi/build/lib/apex_sdk/device/tmsi_event_reader.py +0 -50
- packages/tmsi/build/lib/apex_sdk/device/tmsi_measurement.py +0 -118
- packages/tmsi/build/lib/apex_sdk/sample_data_server/__init__.py +0 -33
- packages/tmsi/build/lib/apex_sdk/sample_data_server/event_data.py +0 -44
- packages/tmsi/build/lib/apex_sdk/sample_data_server/sample_data.py +0 -50
- packages/tmsi/build/lib/apex_sdk/sample_data_server/sample_data_server.py +0 -136
- packages/tmsi/build/lib/apex_sdk/tmsi_errors/error.py +0 -126
- packages/tmsi/build/lib/apex_sdk/tmsi_sdk.py +0 -113
- packages/tmsi/build/lib/apex_sdk/tmsi_utilities/apex/apex_structure_generator.py +0 -134
- packages/tmsi/build/lib/apex_sdk/tmsi_utilities/decorators.py +0 -60
- packages/tmsi/build/lib/apex_sdk/tmsi_utilities/logger_filter.py +0 -42
- packages/tmsi/build/lib/apex_sdk/tmsi_utilities/singleton.py +0 -42
- packages/tmsi/build/lib/apex_sdk/tmsi_utilities/support_functions.py +0 -72
- packages/tmsi/build/lib/apex_sdk/tmsi_utilities/tmsi_logger.py +0 -98
- py_neuromodulation/nm_EpochStream.py +0 -92
- py_neuromodulation/nm_across_patient_decoding.py +0 -927
- py_neuromodulation/nm_cohortwrapper.py +0 -435
- py_neuromodulation/nm_eval_timing.py +0 -239
- py_neuromodulation/nm_features_abc.py +0 -39
- py_neuromodulation/nm_stream_offline.py +0 -358
- py_neuromodulation/utils/_logging.py +0 -24
- py_neuromodulation-0.0.3.dist-info/RECORD +0 -188
- py_neuromodulation-0.0.3.dist-info/top_level.txt +0 -5
- tests/__init__.py +0 -0
- tests/conftest.py +0 -117
- tests/test_all_examples.py +0 -10
- tests/test_all_features.py +0 -63
- tests/test_bispectra.py +0 -70
- tests/test_bursts.py +0 -105
- tests/test_feature_sampling_rates.py +0 -143
- tests/test_fooof.py +0 -16
- tests/test_initalization_offline_stream.py +0 -41
- tests/test_multiprocessing.py +0 -58
- tests/test_nan_values.py +0 -29
- tests/test_nm_filter.py +0 -95
- tests/test_nm_resample.py +0 -63
- tests/test_normalization_settings.py +0 -146
- tests/test_notch_filter.py +0 -31
- tests/test_osc_features.py +0 -424
- tests/test_preprocessing_filter.py +0 -151
- tests/test_rereference.py +0 -171
- tests/test_sampling.py +0 -57
- tests/test_settings_change_after_init.py +0 -76
- tests/test_sharpwave.py +0 -165
- tests/test_target_channel_add.py +0 -100
- tests/test_timing.py +0 -80
tests/test_osc_features.py
DELETED
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
import pytest
|
|
3
|
-
|
|
4
|
-
from py_neuromodulation import nm_oscillatory, nm_settings
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def setup_osc_settings(
|
|
8
|
-
osc_feature_name: str,
|
|
9
|
-
osc_feature_setting: str,
|
|
10
|
-
windowlength_ms: int,
|
|
11
|
-
log_transform: bool,
|
|
12
|
-
):
|
|
13
|
-
settings = nm_settings.get_default_settings()
|
|
14
|
-
settings = nm_settings.reset_settings(settings)
|
|
15
|
-
settings[osc_feature_name] = True
|
|
16
|
-
settings[osc_feature_setting]["windowlength_ms"] = windowlength_ms
|
|
17
|
-
settings[osc_feature_setting]["log_transform"] = log_transform
|
|
18
|
-
|
|
19
|
-
return settings
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def test_fft_wrong_logtransform_param_init():
|
|
23
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
24
|
-
sfreq = 1000
|
|
25
|
-
|
|
26
|
-
settings = setup_osc_settings(
|
|
27
|
-
osc_feature_name="fft",
|
|
28
|
-
osc_feature_setting="fft_settings",
|
|
29
|
-
windowlength_ms=1000,
|
|
30
|
-
log_transform="123",
|
|
31
|
-
)
|
|
32
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "beta": [10, 20]}
|
|
33
|
-
|
|
34
|
-
with pytest.raises(Exception) as e_info:
|
|
35
|
-
nm_oscillatory.FFT.test_settings(settings, ch_names, sfreq)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def test_fft_wrong_frequencyband_range_init():
|
|
39
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
40
|
-
sfreq = 1000
|
|
41
|
-
|
|
42
|
-
settings = setup_osc_settings(
|
|
43
|
-
osc_feature_name="fft",
|
|
44
|
-
osc_feature_setting="fft_settings",
|
|
45
|
-
windowlength_ms=1000,
|
|
46
|
-
log_transform="123",
|
|
47
|
-
)
|
|
48
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "broadband": [10, 600]}
|
|
49
|
-
|
|
50
|
-
with pytest.raises(Exception):
|
|
51
|
-
nm_oscillatory.FFT.test_settings(settings, ch_names, sfreq)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def test_fft_zero_data():
|
|
55
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
56
|
-
sfreq = 1000
|
|
57
|
-
|
|
58
|
-
settings = setup_osc_settings(
|
|
59
|
-
osc_feature_name="fft",
|
|
60
|
-
osc_feature_setting="fft_settings",
|
|
61
|
-
windowlength_ms=1000,
|
|
62
|
-
log_transform=False,
|
|
63
|
-
)
|
|
64
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "beta": [10, 20]}
|
|
65
|
-
fft_obj = nm_oscillatory.FFT(settings, ch_names, sfreq)
|
|
66
|
-
fft_obj.test_settings(settings, ch_names, sfreq)
|
|
67
|
-
|
|
68
|
-
data = np.ones([len(ch_names), sfreq])
|
|
69
|
-
features_out = fft_obj.calc_feature(data, {})
|
|
70
|
-
|
|
71
|
-
for f in features_out.keys():
|
|
72
|
-
if "psd_0" not in f:
|
|
73
|
-
assert np.isclose(features_out[f], 0, atol=1e-6)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def test_fft_random_data():
|
|
77
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
78
|
-
sfreq = 1000
|
|
79
|
-
|
|
80
|
-
settings = setup_osc_settings(
|
|
81
|
-
osc_feature_name="fft",
|
|
82
|
-
osc_feature_setting="fft_settings",
|
|
83
|
-
windowlength_ms=1000,
|
|
84
|
-
log_transform=False,
|
|
85
|
-
)
|
|
86
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "beta": [10, 20]}
|
|
87
|
-
fft_obj = nm_oscillatory.FFT(settings, ch_names, sfreq)
|
|
88
|
-
fft_obj.test_settings(settings, ch_names, sfreq)
|
|
89
|
-
|
|
90
|
-
data = np.random.random([len(ch_names), sfreq])
|
|
91
|
-
features_out = fft_obj.calc_feature(data, {})
|
|
92
|
-
|
|
93
|
-
for f in features_out.keys():
|
|
94
|
-
assert features_out[f] != 0
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def test_fft_beta_osc():
|
|
98
|
-
ch_names = [
|
|
99
|
-
"ch1",
|
|
100
|
-
]
|
|
101
|
-
sfreq = 1000
|
|
102
|
-
|
|
103
|
-
settings = setup_osc_settings(
|
|
104
|
-
osc_feature_name="fft",
|
|
105
|
-
osc_feature_setting="fft_settings",
|
|
106
|
-
windowlength_ms=1000,
|
|
107
|
-
log_transform=False,
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
settings["frequency_ranges_hz"] = {
|
|
111
|
-
"theta": [4, 8],
|
|
112
|
-
"beta": [10, 28],
|
|
113
|
-
"gamma": [50, 60],
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
fft_obj = nm_oscillatory.FFT(settings, ch_names, sfreq)
|
|
117
|
-
fft_obj.test_settings(settings, ch_names, sfreq)
|
|
118
|
-
|
|
119
|
-
time_duration = 1
|
|
120
|
-
|
|
121
|
-
time_points = np.arange(0, time_duration, 1 / sfreq)
|
|
122
|
-
beta_freq = 20
|
|
123
|
-
|
|
124
|
-
beta_wave = np.sin(2 * np.pi * beta_freq * time_points)
|
|
125
|
-
|
|
126
|
-
np.random.seed(0)
|
|
127
|
-
data = np.random.random([len(ch_names), sfreq]) + beta_wave
|
|
128
|
-
|
|
129
|
-
features_out = fft_obj.calc_feature(data, {})
|
|
130
|
-
|
|
131
|
-
assert (
|
|
132
|
-
features_out["ch1_fft_beta_mean"] > features_out["ch1_fft_theta_mean"]
|
|
133
|
-
and features_out["ch1_fft_beta_mean"]
|
|
134
|
-
> features_out["ch1_fft_gamma_mean"]
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
def test_stft_wrong_logtransform_param_init():
|
|
139
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
140
|
-
sfreq = 1000
|
|
141
|
-
|
|
142
|
-
settings = setup_osc_settings(
|
|
143
|
-
osc_feature_name="stft",
|
|
144
|
-
osc_feature_setting="stft_settings",
|
|
145
|
-
windowlength_ms=1000,
|
|
146
|
-
log_transform="123",
|
|
147
|
-
)
|
|
148
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "beta": [10, 20]}
|
|
149
|
-
|
|
150
|
-
with pytest.raises(Exception) as e_info:
|
|
151
|
-
nm_oscillatory.STFT.test_settings(settings, ch_names, sfreq)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def test_stft_wrong_frequencyband_range_init():
|
|
155
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
156
|
-
sfreq = 1000
|
|
157
|
-
|
|
158
|
-
settings = setup_osc_settings(
|
|
159
|
-
osc_feature_name="stft",
|
|
160
|
-
osc_feature_setting="stft_settings",
|
|
161
|
-
windowlength_ms=1000,
|
|
162
|
-
log_transform="123",
|
|
163
|
-
)
|
|
164
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "broadband": [10, 600]}
|
|
165
|
-
|
|
166
|
-
with pytest.raises(Exception):
|
|
167
|
-
nm_oscillatory.STFT.test_settings(settings, ch_names, sfreq)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def test_stft_beta_osc():
|
|
171
|
-
ch_names = [
|
|
172
|
-
"ch1",
|
|
173
|
-
]
|
|
174
|
-
sfreq = 1000
|
|
175
|
-
|
|
176
|
-
settings = setup_osc_settings(
|
|
177
|
-
osc_feature_name="stft",
|
|
178
|
-
osc_feature_setting="stft_settings",
|
|
179
|
-
windowlength_ms=1000,
|
|
180
|
-
log_transform=True,
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
settings["frequency_ranges_hz"] = {
|
|
184
|
-
"theta": [4, 8],
|
|
185
|
-
"beta": [10, 28],
|
|
186
|
-
"gamma": [50, 60],
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
stft_obj = nm_oscillatory.STFT(settings, ch_names, sfreq)
|
|
190
|
-
stft_obj.test_settings(settings, ch_names, sfreq)
|
|
191
|
-
|
|
192
|
-
time_duration = 1
|
|
193
|
-
|
|
194
|
-
time_points = np.arange(0, time_duration, 1 / sfreq)
|
|
195
|
-
beta_freq = 20
|
|
196
|
-
|
|
197
|
-
beta_wave = np.sin(2 * np.pi * beta_freq * time_points)
|
|
198
|
-
|
|
199
|
-
np.random.seed(0)
|
|
200
|
-
data = np.random.random([len(ch_names), sfreq]) + beta_wave
|
|
201
|
-
|
|
202
|
-
features_out = stft_obj.calc_feature(data, {})
|
|
203
|
-
|
|
204
|
-
assert (
|
|
205
|
-
features_out["ch1_stft_beta_mean"] > features_out["ch1_stft_theta_mean"]
|
|
206
|
-
and features_out["ch1_stft_beta_mean"]
|
|
207
|
-
> features_out["ch1_stft_gamma_mean"]
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
def test_welch_beta_osc():
|
|
212
|
-
ch_names = [
|
|
213
|
-
"ch1",
|
|
214
|
-
]
|
|
215
|
-
sfreq = 1000
|
|
216
|
-
|
|
217
|
-
settings = setup_osc_settings(
|
|
218
|
-
osc_feature_name="welch",
|
|
219
|
-
osc_feature_setting="welch_settings",
|
|
220
|
-
windowlength_ms=1000,
|
|
221
|
-
log_transform=True,
|
|
222
|
-
)
|
|
223
|
-
|
|
224
|
-
settings["frequency_ranges_hz"] = {
|
|
225
|
-
"theta": [4, 8],
|
|
226
|
-
"beta": [10, 28],
|
|
227
|
-
"gamma": [50, 60],
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
stft_obj = nm_oscillatory.Welch(settings, ch_names, sfreq)
|
|
231
|
-
stft_obj.test_settings(settings, ch_names, sfreq)
|
|
232
|
-
|
|
233
|
-
time_duration = 1
|
|
234
|
-
|
|
235
|
-
time_points = np.arange(0, time_duration, 1 / sfreq)
|
|
236
|
-
beta_freq = 20
|
|
237
|
-
|
|
238
|
-
beta_wave = np.sin(2 * np.pi * beta_freq * time_points)
|
|
239
|
-
|
|
240
|
-
np.random.seed(0)
|
|
241
|
-
data = np.random.random([len(ch_names), sfreq]) + beta_wave
|
|
242
|
-
|
|
243
|
-
features_out = stft_obj.calc_feature(data, {})
|
|
244
|
-
|
|
245
|
-
assert (
|
|
246
|
-
features_out["ch1_welch_beta_mean"]
|
|
247
|
-
> features_out["ch1_welch_theta_mean"]
|
|
248
|
-
and features_out["ch1_welch_beta_mean"]
|
|
249
|
-
> features_out["ch1_welch_gamma_mean"]
|
|
250
|
-
)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def test_bp_wrong_logtransform_param_init():
|
|
254
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
255
|
-
sfreq = 1000
|
|
256
|
-
|
|
257
|
-
settings = setup_osc_settings(
|
|
258
|
-
osc_feature_name="bandpass_filter",
|
|
259
|
-
osc_feature_setting="bandpass_filter_settings",
|
|
260
|
-
windowlength_ms=1000,
|
|
261
|
-
log_transform="123",
|
|
262
|
-
)
|
|
263
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "beta": [10, 20]}
|
|
264
|
-
|
|
265
|
-
with pytest.raises(Exception) as e_info:
|
|
266
|
-
nm_oscillatory.BandPower.test_settings(settings, ch_names, sfreq)
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
def test_bp_wrong_frequencyband_range_init():
|
|
270
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
271
|
-
sfreq = 1000
|
|
272
|
-
|
|
273
|
-
settings = setup_osc_settings(
|
|
274
|
-
osc_feature_name="bandpass_filter",
|
|
275
|
-
osc_feature_setting="bandpass_filter_settings",
|
|
276
|
-
windowlength_ms=1000,
|
|
277
|
-
log_transform="123",
|
|
278
|
-
)
|
|
279
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "broadband": [10, 600]}
|
|
280
|
-
|
|
281
|
-
with pytest.raises(Exception):
|
|
282
|
-
nm_oscillatory.BandPower.test_settings(settings, ch_names, sfreq)
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
def test_bp_non_defined_fband():
|
|
286
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
287
|
-
sfreq = 1000
|
|
288
|
-
|
|
289
|
-
settings = setup_osc_settings(
|
|
290
|
-
osc_feature_name="bandpass_filter",
|
|
291
|
-
osc_feature_setting="bandpass_filter_settings",
|
|
292
|
-
windowlength_ms=1000,
|
|
293
|
-
log_transform=True,
|
|
294
|
-
)
|
|
295
|
-
|
|
296
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "broadband": [10, 600]}
|
|
297
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["theta"] = 1000
|
|
298
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["beta"] = 300
|
|
299
|
-
|
|
300
|
-
with pytest.raises(Exception):
|
|
301
|
-
nm_oscillatory.BandPower.test_settings(settings, ch_names, sfreq)
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
def test_bp_segment_length_fb_exceeds_segment_length_features():
|
|
305
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
306
|
-
sfreq = 1000
|
|
307
|
-
|
|
308
|
-
settings = setup_osc_settings(
|
|
309
|
-
osc_feature_name="bandpass_filter",
|
|
310
|
-
osc_feature_setting="bandpass_filter_settings",
|
|
311
|
-
windowlength_ms=1000,
|
|
312
|
-
log_transform=True,
|
|
313
|
-
)
|
|
314
|
-
|
|
315
|
-
settings["segment_length_features_ms"] = 500
|
|
316
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "broadband": [10, 600]}
|
|
317
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["theta"] = 1000
|
|
318
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["beta"] = 300
|
|
319
|
-
|
|
320
|
-
with pytest.raises(Exception):
|
|
321
|
-
nm_oscillatory.BandPower.test_settings(settings, ch_names, sfreq)
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
def test_bp_zero_data():
|
|
325
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
326
|
-
sfreq = 1000
|
|
327
|
-
|
|
328
|
-
settings = nm_settings.get_default_settings()
|
|
329
|
-
settings = nm_settings.reset_settings(settings)
|
|
330
|
-
settings["features"]["bandpass_filter"] = True
|
|
331
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["theta"] = 1000
|
|
332
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["beta"] = 300
|
|
333
|
-
|
|
334
|
-
settings["bandpass_filter_settings"]["log_transform"] = False
|
|
335
|
-
settings["bandpass_filter_settings"]["kalman_filter"] = False
|
|
336
|
-
settings["bandpass_filter_settings"]["bandpower_features"][
|
|
337
|
-
"activity"
|
|
338
|
-
] = True
|
|
339
|
-
|
|
340
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "beta": [10, 20]}
|
|
341
|
-
stft_obj = nm_oscillatory.BandPower(settings, ch_names, sfreq)
|
|
342
|
-
stft_obj.test_settings(settings, ch_names, sfreq)
|
|
343
|
-
|
|
344
|
-
data = np.zeros([len(ch_names), sfreq])
|
|
345
|
-
features_out = stft_obj.calc_feature(data, {})
|
|
346
|
-
|
|
347
|
-
for f in features_out.keys():
|
|
348
|
-
assert pytest.approx(0, 0.01) == features_out[f]
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
def test_bp_random_data():
|
|
352
|
-
ch_names = ["ch1", "ch2", "ch3", "ch4"]
|
|
353
|
-
sfreq = 1000
|
|
354
|
-
|
|
355
|
-
settings = nm_settings.get_default_settings()
|
|
356
|
-
settings = nm_settings.reset_settings(settings)
|
|
357
|
-
settings["frequency_ranges_hz"] = {"theta": [4, 8], "beta": [10, 30]}
|
|
358
|
-
settings["features"]["bandpass_filter"] = True
|
|
359
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["theta"] = 1000
|
|
360
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["beta"] = 300
|
|
361
|
-
|
|
362
|
-
settings["bandpass_filter_settings"]["log_transform"] = False
|
|
363
|
-
settings["bandpass_filter_settings"]["kalman_filter"] = False
|
|
364
|
-
settings["bandpass_filter_settings"]["bandpower_features"][
|
|
365
|
-
"activity"
|
|
366
|
-
] = True
|
|
367
|
-
|
|
368
|
-
stft_obj = nm_oscillatory.BandPower(settings, ch_names, sfreq)
|
|
369
|
-
stft_obj.test_settings(settings, ch_names, sfreq)
|
|
370
|
-
|
|
371
|
-
np.random.seed(0)
|
|
372
|
-
data = np.random.random([len(ch_names), sfreq])
|
|
373
|
-
features_out = stft_obj.calc_feature(data, {})
|
|
374
|
-
|
|
375
|
-
for f in features_out.keys():
|
|
376
|
-
assert pytest.approx(0, 0.01) != features_out[f]
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
def test_bp_beta_osc():
|
|
380
|
-
ch_names = [
|
|
381
|
-
"ch1",
|
|
382
|
-
]
|
|
383
|
-
sfreq = 1000
|
|
384
|
-
|
|
385
|
-
settings = nm_settings.get_default_settings()
|
|
386
|
-
settings = nm_settings.reset_settings(settings)
|
|
387
|
-
settings["frequency_ranges_hz"] = {
|
|
388
|
-
"theta": [4, 8],
|
|
389
|
-
"beta": [10, 30],
|
|
390
|
-
"gamma": [50, 60],
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
settings["features"]["bandpass_filter"] = True
|
|
394
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["theta"] = 1000
|
|
395
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["beta"] = 300
|
|
396
|
-
settings["bandpass_filter_settings"]["segment_lengths_ms"]["gamma"] = 100
|
|
397
|
-
|
|
398
|
-
settings["bandpass_filter_settings"]["log_transform"] = False
|
|
399
|
-
settings["bandpass_filter_settings"]["kalman_filter"] = False
|
|
400
|
-
settings["bandpass_filter_settings"]["bandpower_features"][
|
|
401
|
-
"activity"
|
|
402
|
-
] = True
|
|
403
|
-
|
|
404
|
-
bp_obj = nm_oscillatory.BandPower(settings, ch_names, sfreq)
|
|
405
|
-
bp_obj.test_settings(settings, ch_names, sfreq)
|
|
406
|
-
|
|
407
|
-
time_duration = 1
|
|
408
|
-
|
|
409
|
-
time_points = np.arange(0, time_duration, 1 / sfreq)
|
|
410
|
-
beta_freq = 20
|
|
411
|
-
|
|
412
|
-
beta_wave = np.sin(2 * np.pi * beta_freq * time_points)
|
|
413
|
-
|
|
414
|
-
np.random.seed(0)
|
|
415
|
-
data = np.random.random([len(ch_names), sfreq]) + beta_wave
|
|
416
|
-
|
|
417
|
-
features_out = bp_obj.calc_feature(data, {})
|
|
418
|
-
|
|
419
|
-
assert (
|
|
420
|
-
features_out["ch1_bandpass_activity_beta"]
|
|
421
|
-
> features_out["ch1_bandpass_activity_theta"]
|
|
422
|
-
and features_out["ch1_bandpass_activity_beta"]
|
|
423
|
-
> features_out["ch1_bandpass_activity_gamma"]
|
|
424
|
-
)
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
from scipy import signal
|
|
3
|
-
|
|
4
|
-
from py_neuromodulation import nm_settings
|
|
5
|
-
from py_neuromodulation.nm_filter_preprocessing import PreprocessingFilter
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def test_preprocessing_within_pipeline(setup_default_stream_fast_compute):
|
|
9
|
-
|
|
10
|
-
data, stream = setup_default_stream_fast_compute
|
|
11
|
-
|
|
12
|
-
stream.settings["preprocessing"].append("preprocessing_filter")
|
|
13
|
-
|
|
14
|
-
stream.settings["preprocessing_filter"]["bandstop_filter"] = True
|
|
15
|
-
stream.settings["preprocessing_filter"]["bandpass_filter"] = True
|
|
16
|
-
stream.settings["preprocessing_filter"]["lowpass_filter"] = True
|
|
17
|
-
stream.settings["preprocessing_filter"]["highpass_filter"] = True
|
|
18
|
-
|
|
19
|
-
stream.sfreq
|
|
20
|
-
|
|
21
|
-
try:
|
|
22
|
-
_ = stream.run(data[:, : int(stream.sfreq * 2)])
|
|
23
|
-
except Exception as e:
|
|
24
|
-
assert False, f"Error in pipeline including preprocess filtering : {e}"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def test_preprocessing_filter_lowpass():
|
|
28
|
-
|
|
29
|
-
data_batch = np.random.random([1, 1000])
|
|
30
|
-
|
|
31
|
-
settings = nm_settings.get_default_settings()
|
|
32
|
-
settings["preprocessing"] = settings["preprocessing"].append(
|
|
33
|
-
"preprocessing_filter"
|
|
34
|
-
)
|
|
35
|
-
settings["preprocessing_filter"]["lowpass_filter"] = True
|
|
36
|
-
settings["preprocessing_filter"]["highpass_filter"] = False
|
|
37
|
-
settings["preprocessing_filter"]["bandpass_filter"] = False
|
|
38
|
-
settings["preprocessing_filter"]["bandstop_filter"] = False
|
|
39
|
-
|
|
40
|
-
settings["preprocessing_filter"]["lowpass_filter_settings"][
|
|
41
|
-
"frequency_cutoff_hz"
|
|
42
|
-
] = 100
|
|
43
|
-
|
|
44
|
-
sfreq = 1000
|
|
45
|
-
|
|
46
|
-
preprocessing_filter = PreprocessingFilter(settings, sfreq)
|
|
47
|
-
data_filtered = preprocessing_filter.process(data_batch)
|
|
48
|
-
|
|
49
|
-
# compute a scipy signal welch to check if the filter worked
|
|
50
|
-
f, Pxx = signal.welch(data_batch, fs=sfreq, nperseg=1000)
|
|
51
|
-
f, Pxx_f = signal.welch(data_filtered, fs=sfreq, nperseg=1000)
|
|
52
|
-
|
|
53
|
-
# check if the power in the frequency range of the lowpass filter is reduced
|
|
54
|
-
assert np.mean(Pxx_f[0, 100:500]) < np.mean(Pxx[0, 100:500])
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def test_preprocessing_filter_highpass():
|
|
58
|
-
|
|
59
|
-
data_batch = np.random.random([1, 1000])
|
|
60
|
-
|
|
61
|
-
settings = nm_settings.get_default_settings()
|
|
62
|
-
settings["preprocessing"] = settings["preprocessing"].append(
|
|
63
|
-
"preprocessing_filter"
|
|
64
|
-
)
|
|
65
|
-
settings["preprocessing_filter"]["highpass_filter"] = True
|
|
66
|
-
settings["preprocessing_filter"]["lowpass_filter"] = False
|
|
67
|
-
settings["preprocessing_filter"]["bandpass_filter"] = False
|
|
68
|
-
settings["preprocessing_filter"]["bandstop_filter"] = False
|
|
69
|
-
|
|
70
|
-
settings["preprocessing_filter"]["highpass_filter_settings"][
|
|
71
|
-
"frequency_cutoff_hz"
|
|
72
|
-
] = 100
|
|
73
|
-
|
|
74
|
-
sfreq = 1000
|
|
75
|
-
|
|
76
|
-
preprocessing_filter = PreprocessingFilter(settings, sfreq)
|
|
77
|
-
data_filtered = preprocessing_filter.process(data_batch)
|
|
78
|
-
|
|
79
|
-
# compute a scipy signal welch to check if the filter worked
|
|
80
|
-
f, Pxx = signal.welch(data_batch, fs=sfreq, nperseg=1000)
|
|
81
|
-
f, Pxx_f = signal.welch(data_filtered, fs=sfreq, nperseg=1000)
|
|
82
|
-
|
|
83
|
-
# check if the power in the frequency range of the highpass filter is reduced
|
|
84
|
-
assert np.mean(Pxx_f[0, 0:100]) < np.mean(Pxx[0, 0:100])
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def test_preprocessing_filter_bandstop():
|
|
88
|
-
|
|
89
|
-
data_batch = np.random.random([1, 1000])
|
|
90
|
-
|
|
91
|
-
settings = nm_settings.get_default_settings()
|
|
92
|
-
settings["preprocessing"] = settings["preprocessing"].append(
|
|
93
|
-
"preprocessing_filter"
|
|
94
|
-
)
|
|
95
|
-
settings["preprocessing_filter"]["bandstop_filter"] = True
|
|
96
|
-
settings["preprocessing_filter"]["bandpass_filter"] = False
|
|
97
|
-
settings["preprocessing_filter"]["lowpass_filter"] = False
|
|
98
|
-
settings["preprocessing_filter"]["highpass_filter"] = False
|
|
99
|
-
|
|
100
|
-
settings["preprocessing_filter"]["bandstop_filter_settings"][
|
|
101
|
-
"frequency_low_hz"
|
|
102
|
-
] = 100
|
|
103
|
-
settings["preprocessing_filter"]["bandstop_filter_settings"][
|
|
104
|
-
"frequency_high_hz"
|
|
105
|
-
] = 160
|
|
106
|
-
|
|
107
|
-
sfreq = 1000
|
|
108
|
-
|
|
109
|
-
preprocessing_filter = PreprocessingFilter(settings, sfreq)
|
|
110
|
-
data_filtered = preprocessing_filter.process(data_batch)
|
|
111
|
-
|
|
112
|
-
# compute a scipy signal welch to check if the filter worked
|
|
113
|
-
f, Pxx = signal.welch(data_batch, fs=sfreq, nperseg=1000)
|
|
114
|
-
f, Pxx_f = signal.welch(data_filtered, fs=sfreq, nperseg=1000)
|
|
115
|
-
|
|
116
|
-
# check if the power in the frequency range of the bandstop filter is reduced
|
|
117
|
-
assert np.mean(Pxx_f[0, 100:160]) < np.mean(Pxx[0, 100:160])
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
def test_preprocessing_filter_bandpass():
|
|
121
|
-
|
|
122
|
-
data_batch = np.random.random([1, 1000])
|
|
123
|
-
|
|
124
|
-
settings = nm_settings.get_default_settings()
|
|
125
|
-
settings["preprocessing"] = settings["preprocessing"].append(
|
|
126
|
-
"preprocessing_filter"
|
|
127
|
-
)
|
|
128
|
-
settings["preprocessing_filter"]["bandstop_filter"] = False
|
|
129
|
-
settings["preprocessing_filter"]["bandpass_filter"] = True
|
|
130
|
-
settings["preprocessing_filter"]["lowpass_filter"] = False
|
|
131
|
-
settings["preprocessing_filter"]["highpass_filter"] = False
|
|
132
|
-
|
|
133
|
-
settings["preprocessing_filter"]["bandpass_filter_settings"][
|
|
134
|
-
"frequency_low_hz"
|
|
135
|
-
] = 100
|
|
136
|
-
settings["preprocessing_filter"]["bandpass_filter_settings"][
|
|
137
|
-
"frequency_high_hz"
|
|
138
|
-
] = 160
|
|
139
|
-
|
|
140
|
-
sfreq = 1000
|
|
141
|
-
|
|
142
|
-
preprocessing_filter = PreprocessingFilter(settings, sfreq)
|
|
143
|
-
data_filtered = preprocessing_filter.process(data_batch)
|
|
144
|
-
|
|
145
|
-
# compute a scipy signal welch to check if the filter worked
|
|
146
|
-
f, Pxx = signal.welch(data_batch, fs=sfreq, nperseg=1000)
|
|
147
|
-
f, Pxx_f = signal.welch(data_filtered, fs=sfreq, nperseg=1000)
|
|
148
|
-
|
|
149
|
-
# check if the power in the frequency range of the bandpass filter is reduced
|
|
150
|
-
assert np.mean(Pxx_f[0, 0:100]) < np.mean(Pxx[0, 0:100])
|
|
151
|
-
assert np.mean(Pxx_f[0, 160:500]) < np.mean(Pxx[0, 160:500])
|