py-neuromodulation 0.0.5__py3-none-any.whl → 0.0.6__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/__init__.py +16 -10
- py_neuromodulation/{nm_RMAP.py → analysis/RMAP.py} +2 -2
- py_neuromodulation/analysis/__init__.py +4 -0
- py_neuromodulation/{nm_decode.py → analysis/decode.py} +4 -4
- py_neuromodulation/{nm_analysis.py → analysis/feature_reader.py} +21 -20
- py_neuromodulation/{nm_plots.py → analysis/plots.py} +54 -12
- py_neuromodulation/{nm_stats.py → analysis/stats.py} +2 -8
- py_neuromodulation/{nm_settings.yaml → default_settings.yaml} +6 -9
- py_neuromodulation/features/__init__.py +31 -0
- py_neuromodulation/features/bandpower.py +165 -0
- py_neuromodulation/{nm_bispectra.py → features/bispectra.py} +8 -5
- py_neuromodulation/{nm_bursts.py → features/bursts.py} +14 -9
- py_neuromodulation/{nm_coherence.py → features/coherence.py} +17 -13
- py_neuromodulation/{nm_features.py → features/feature_processor.py} +30 -53
- py_neuromodulation/{nm_fooof.py → features/fooof.py} +11 -8
- py_neuromodulation/{nm_hjorth_raw.py → features/hjorth_raw.py} +10 -5
- py_neuromodulation/{nm_linelength.py → features/linelength.py} +1 -1
- py_neuromodulation/{nm_mne_connectivity.py → features/mne_connectivity.py} +5 -6
- py_neuromodulation/{nm_nolds.py → features/nolds.py} +5 -7
- py_neuromodulation/{nm_oscillatory.py → features/oscillatory.py} +7 -181
- py_neuromodulation/{nm_sharpwaves.py → features/sharpwaves.py} +13 -4
- py_neuromodulation/filter/__init__.py +3 -0
- py_neuromodulation/{nm_kalmanfilter.py → filter/kalman_filter.py} +67 -71
- py_neuromodulation/filter/kalman_filter_external.py +1890 -0
- py_neuromodulation/{nm_filter.py → filter/mne_filter.py} +128 -219
- py_neuromodulation/filter/notch_filter.py +93 -0
- py_neuromodulation/processing/__init__.py +10 -0
- py_neuromodulation/{nm_artifacts.py → processing/artifacts.py} +2 -3
- py_neuromodulation/{nm_preprocessing.py → processing/data_preprocessor.py} +19 -25
- py_neuromodulation/{nm_filter_preprocessing.py → processing/filter_preprocessing.py} +3 -4
- py_neuromodulation/{nm_normalization.py → processing/normalization.py} +9 -7
- py_neuromodulation/{nm_projection.py → processing/projection.py} +14 -14
- py_neuromodulation/{nm_rereference.py → processing/rereference.py} +13 -13
- py_neuromodulation/{nm_resample.py → processing/resample.py} +1 -4
- py_neuromodulation/stream/__init__.py +3 -0
- py_neuromodulation/{nm_run_analysis.py → stream/data_processor.py} +42 -42
- py_neuromodulation/stream/generator.py +53 -0
- py_neuromodulation/{nm_mnelsl_generator.py → stream/mnelsl_player.py} +10 -6
- py_neuromodulation/{nm_mnelsl_stream.py → stream/mnelsl_stream.py} +13 -9
- py_neuromodulation/{nm_settings.py → stream/settings.py} +27 -24
- py_neuromodulation/{nm_stream.py → stream/stream.py} +217 -188
- py_neuromodulation/utils/__init__.py +2 -0
- py_neuromodulation/{nm_define_nmchannels.py → utils/channels.py} +14 -9
- py_neuromodulation/{nm_database.py → utils/database.py} +2 -2
- py_neuromodulation/{nm_IO.py → utils/io.py} +42 -77
- py_neuromodulation/utils/keyboard.py +52 -0
- py_neuromodulation/{nm_logger.py → utils/logging.py} +3 -3
- py_neuromodulation/{nm_types.py → utils/types.py} +72 -14
- {py_neuromodulation-0.0.5.dist-info → py_neuromodulation-0.0.6.dist-info}/METADATA +3 -11
- py_neuromodulation-0.0.6.dist-info/RECORD +89 -0
- py_neuromodulation/FieldTrip.py +0 -589
- py_neuromodulation/_write_example_dataset_helper.py +0 -83
- py_neuromodulation/nm_generator.py +0 -45
- py_neuromodulation/nm_stream_abc.py +0 -166
- py_neuromodulation-0.0.5.dist-info/RECORD +0 -83
- {py_neuromodulation-0.0.5.dist-info → py_neuromodulation-0.0.6.dist-info}/WHEEL +0 -0
- {py_neuromodulation-0.0.5.dist-info → py_neuromodulation-0.0.6.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,7 +2,6 @@ from collections.abc import Sequence
|
|
|
2
2
|
from collections import defaultdict
|
|
3
3
|
from itertools import product
|
|
4
4
|
|
|
5
|
-
from py_neuromodulation.nm_types import NMBaseModel
|
|
6
5
|
from pydantic import model_validator
|
|
7
6
|
from typing import TYPE_CHECKING, Any, Callable
|
|
8
7
|
|
|
@@ -13,11 +12,15 @@ if np.__version__ >= "2.0.0":
|
|
|
13
12
|
else:
|
|
14
13
|
from numpy.core._methods import _mean as np_mean
|
|
15
14
|
|
|
16
|
-
from py_neuromodulation.
|
|
17
|
-
|
|
15
|
+
from py_neuromodulation.utils.types import (
|
|
16
|
+
NMFeature,
|
|
17
|
+
NMBaseModel,
|
|
18
|
+
BoolSelector,
|
|
19
|
+
FrequencyRange,
|
|
20
|
+
)
|
|
18
21
|
|
|
19
22
|
if TYPE_CHECKING:
|
|
20
|
-
from py_neuromodulation
|
|
23
|
+
from py_neuromodulation import NMSettings
|
|
21
24
|
|
|
22
25
|
# Using low-level numpy mean function for performance, could do the same for the other estimators
|
|
23
26
|
ESTIMATOR_DICT = {
|
|
@@ -38,6 +41,7 @@ class PeakDetectionSettings(NMBaseModel):
|
|
|
38
41
|
class SharpwaveFeatures(BoolSelector):
|
|
39
42
|
peak_left: bool = False
|
|
40
43
|
peak_right: bool = False
|
|
44
|
+
num_peaks: bool = False
|
|
41
45
|
trough: bool = False
|
|
42
46
|
width: bool = False
|
|
43
47
|
prominence: bool = True
|
|
@@ -368,6 +372,11 @@ class SharpwaveAnalyzer(NMFeature):
|
|
|
368
372
|
# results["sharpness"] = ((trough_height - left_height) + (trough_height - right_height)) / 2
|
|
369
373
|
results["sharpness"] = trough_height - 0.5 * (left_height + right_height)
|
|
370
374
|
|
|
375
|
+
if self.sw_settings.sharpwave_features.num_peaks:
|
|
376
|
+
results["num_peaks"] = [
|
|
377
|
+
trough_idx.shape[0]
|
|
378
|
+
] # keep list to the estimator can be applied
|
|
379
|
+
|
|
371
380
|
if self.need_steepness:
|
|
372
381
|
# steepness is calculated as the first derivative
|
|
373
382
|
steepness: np.ndarray = np.concatenate((np.zeros(1), np.diff(data)))
|
|
@@ -1,71 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if TYPE_CHECKING:
|
|
8
|
-
from py_neuromodulation.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class KalmanSettings(NMBaseModel):
|
|
12
|
-
Tp: float = 0.1
|
|
13
|
-
sigma_w: float = 0.7
|
|
14
|
-
sigma_v: float = 1.0
|
|
15
|
-
frequency_bands: list[str] = [
|
|
16
|
-
"theta",
|
|
17
|
-
"alpha",
|
|
18
|
-
"low_beta",
|
|
19
|
-
"high_beta",
|
|
20
|
-
"low_gamma",
|
|
21
|
-
"high_gamma",
|
|
22
|
-
"HFA",
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
f =
|
|
60
|
-
f.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
]
|
|
69
|
-
)
|
|
70
|
-
f.P = cov([[1, 0], [0, 1]])
|
|
71
|
-
return f
|
|
1
|
+
import numpy as np
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from py_neuromodulation.utils.types import NMBaseModel
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from py_neuromodulation.stream.settings import NMSettings
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class KalmanSettings(NMBaseModel):
|
|
12
|
+
Tp: float = 0.1
|
|
13
|
+
sigma_w: float = 0.7
|
|
14
|
+
sigma_v: float = 1.0
|
|
15
|
+
frequency_bands: list[str] = [
|
|
16
|
+
"theta",
|
|
17
|
+
"alpha",
|
|
18
|
+
"low_beta",
|
|
19
|
+
"high_beta",
|
|
20
|
+
"low_gamma",
|
|
21
|
+
"high_gamma",
|
|
22
|
+
"HFA",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
def validate_fbands(self, settings: "NMSettings") -> None:
|
|
26
|
+
assert all(
|
|
27
|
+
(item in settings.frequency_ranges_hz for item in self.frequency_bands)
|
|
28
|
+
), (
|
|
29
|
+
"Frequency bands for Kalman filter must also be specified in "
|
|
30
|
+
"bandpass_filter_settings."
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def define_KF(Tp, sigma_w, sigma_v):
|
|
35
|
+
"""Define Kalman filter according to white noise acceleration model.
|
|
36
|
+
See DOI: 10.1109/TBME.2009.2038990 for explanation
|
|
37
|
+
See https://filterpy.readthedocs.io/en/latest/kalman/KalmanFilter.html#r64ca38088676-2 for implementation details
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
Tp : float
|
|
42
|
+
prediction interval
|
|
43
|
+
sigma_w : float
|
|
44
|
+
process noise
|
|
45
|
+
sigma_v : float
|
|
46
|
+
measurement noise
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
filterpy.KalmanFilter
|
|
51
|
+
initialized KalmanFilter object
|
|
52
|
+
"""
|
|
53
|
+
from .kalman_filter_external import KalmanFilter
|
|
54
|
+
|
|
55
|
+
f = KalmanFilter(dim_x=2, dim_z=1)
|
|
56
|
+
f.x = np.array([0, 1]) # x here sensor signal and it's first derivative
|
|
57
|
+
f.F = np.array([[1, Tp], [0, 1]])
|
|
58
|
+
f.H = np.array([[1, 0]])
|
|
59
|
+
f.R = sigma_v
|
|
60
|
+
f.Q = np.array(
|
|
61
|
+
[
|
|
62
|
+
[(sigma_w**2) * (Tp**3) / 3, (sigma_w**2) * (Tp**2) / 2],
|
|
63
|
+
[(sigma_w**2) * (Tp**2) / 2, (sigma_w**2) * Tp],
|
|
64
|
+
]
|
|
65
|
+
)
|
|
66
|
+
f.P = np.cov([[1, 0], [0, 1]])
|
|
67
|
+
return f
|