py-neuromodulation 0.0.4__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/_get_grid_hull.m +34 -34
- py_neuromodulation/ConnectivityDecoding/_get_grid_whole_brain.py +95 -106
- py_neuromodulation/ConnectivityDecoding/_helper_write_connectome.py +107 -119
- 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 -6
- py_neuromodulation/data/dataset_description.json +8 -8
- py_neuromodulation/data/participants.json +32 -32
- py_neuromodulation/data/participants.tsv +2 -2
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_space-mni_coordsystem.json +5 -5
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_space-mni_electrodes.tsv +11 -11
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_channels.tsv +11 -11
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.json +18 -18
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vhdr +35 -35
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vmrk +13 -13
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/sub-testsub_ses-EphysMedOff_scans.tsv +2 -2
- py_neuromodulation/grid_cortex.tsv +40 -40
- 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-0.0.4.dist-info → py_neuromodulation-0.0.5.dist-info}/METADATA +29 -26
- py_neuromodulation-0.0.5.dist-info/RECORD +83 -0
- {py_neuromodulation-0.0.4.dist-info → py_neuromodulation-0.0.5.dist-info}/WHEEL +1 -1
- {py_neuromodulation-0.0.4.dist-info → py_neuromodulation-0.0.5.dist-info}/licenses/LICENSE +21 -21
- 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_settings.json +0 -338
- py_neuromodulation/nm_stream_offline.py +0 -359
- py_neuromodulation/utils/_logging.py +0 -24
- py_neuromodulation-0.0.4.dist-info/RECORD +0 -72
|
@@ -1,95 +1,97 @@
|
|
|
1
|
-
"""Re-referencing Module."""
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ValueError: rereferencing
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
ref_idx = []
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return data
|
|
1
|
+
"""Re-referencing Module."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
from py_neuromodulation.nm_preprocessing import NMPreprocessor
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ReReferencer(NMPreprocessor):
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
sfreq: float,
|
|
13
|
+
nm_channels: pd.DataFrame,
|
|
14
|
+
) -> None:
|
|
15
|
+
"""Initialize real-time rereference information.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
sfreq : float
|
|
20
|
+
Sampling frequency. Is not used, only kept for compatibility.
|
|
21
|
+
nm_channels : Pandas DataFrame
|
|
22
|
+
Dataframe containing information about rereferencing, as
|
|
23
|
+
specified in nm_channels.csv.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Raises:
|
|
27
|
+
ValueError: rereferencing using undefined channel
|
|
28
|
+
ValueError: rereferencing to same channel
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
self.ref_matrix: np.ndarray | None
|
|
32
|
+
|
|
33
|
+
nm_channels = nm_channels[nm_channels["used"] == 1].reset_index(drop=True)
|
|
34
|
+
# (channels_used,) = np.where((nm_channels.used == 1))
|
|
35
|
+
|
|
36
|
+
ch_names = nm_channels["name"].tolist()
|
|
37
|
+
|
|
38
|
+
# no re-referencing is being performed when there is a single channel present only
|
|
39
|
+
if nm_channels.shape[0] in (0, 1):
|
|
40
|
+
self.ref_matrix = None
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
ch_types = nm_channels["type"]
|
|
44
|
+
refs = nm_channels["rereference"]
|
|
45
|
+
|
|
46
|
+
type_map = {}
|
|
47
|
+
for ch_type in ch_types.unique():
|
|
48
|
+
type_map[ch_type] = np.where(
|
|
49
|
+
(ch_types == ch_type) & (nm_channels["status"] == "good")
|
|
50
|
+
)[0]
|
|
51
|
+
|
|
52
|
+
ref_matrix = np.zeros((len(nm_channels), len(nm_channels)))
|
|
53
|
+
for ind in range(len(nm_channels)):
|
|
54
|
+
ref_matrix[ind, ind] = 1
|
|
55
|
+
# if ind not in channels_used:
|
|
56
|
+
# continue
|
|
57
|
+
ref = refs[ind]
|
|
58
|
+
if ref.lower() == "none" or pd.isnull(ref):
|
|
59
|
+
ref_idx = None
|
|
60
|
+
continue
|
|
61
|
+
if ref.lower() == "average":
|
|
62
|
+
ch_type = ch_types[ind]
|
|
63
|
+
ref_idx = type_map[ch_type][type_map[ch_type] != ind]
|
|
64
|
+
else:
|
|
65
|
+
ref_idx = []
|
|
66
|
+
ref_channels = ref.split("&")
|
|
67
|
+
for ref_chan in ref_channels:
|
|
68
|
+
if ref_chan not in ch_names:
|
|
69
|
+
raise ValueError(
|
|
70
|
+
"One or more of the reference channels are not"
|
|
71
|
+
" part of the recording channels. First missing"
|
|
72
|
+
f" channel: {ref_chan}."
|
|
73
|
+
)
|
|
74
|
+
if ref_chan == ch_names[ind]:
|
|
75
|
+
raise ValueError(
|
|
76
|
+
"You cannot rereference to the same channel."
|
|
77
|
+
f" Channel: {ref_chan}."
|
|
78
|
+
)
|
|
79
|
+
ref_idx.append(ch_names.index(ref_chan))
|
|
80
|
+
ref_matrix[ind, ref_idx] = -1 / len(ref_idx)
|
|
81
|
+
self.ref_matrix = ref_matrix
|
|
82
|
+
|
|
83
|
+
def process(self, data: np.ndarray) -> np.ndarray:
|
|
84
|
+
"""Rereference data according to the initialized ReReferencer class.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
data (numpy ndarray) :
|
|
88
|
+
shape(n_channels, n_samples) - data to be rereferenced.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
reref_data (numpy ndarray):
|
|
92
|
+
shape(n_channels, n_samples) - rereferenced data
|
|
93
|
+
"""
|
|
94
|
+
if self.ref_matrix is not None:
|
|
95
|
+
return self.ref_matrix @ data
|
|
96
|
+
else:
|
|
97
|
+
return data
|
|
@@ -1,50 +1,59 @@
|
|
|
1
|
-
"""Module for resampling."""
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
1
|
+
"""Module for resampling."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from py_neuromodulation.nm_types import NMBaseModel, Field
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from py_neuromodulation.nm_preprocessing import NMPreprocessor
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ResamplerSettings(NMBaseModel):
|
|
11
|
+
resample_freq_hz: float = Field(default=1000, gt=0)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Resampler(NMPreprocessor):
|
|
15
|
+
"""Resample data.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
sfreq : float
|
|
20
|
+
Original sampling frequency.
|
|
21
|
+
|
|
22
|
+
Attributes
|
|
23
|
+
----------
|
|
24
|
+
up: float
|
|
25
|
+
Factor to upsample by.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
sfreq: float,
|
|
31
|
+
resample_freq_hz: float,
|
|
32
|
+
) -> None:
|
|
33
|
+
self.settings = ResamplerSettings(resample_freq_hz=resample_freq_hz)
|
|
34
|
+
|
|
35
|
+
ratio = float(resample_freq_hz / sfreq)
|
|
36
|
+
if ratio == 1.0:
|
|
37
|
+
self.up = 0.0
|
|
38
|
+
else:
|
|
39
|
+
self.up = ratio
|
|
40
|
+
|
|
41
|
+
def process(self, data: np.ndarray) -> np.ndarray:
|
|
42
|
+
"""Resample raw data using mne.filter.resample.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
data : np.ndarray
|
|
47
|
+
Data to resample
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
np.ndarray
|
|
52
|
+
Resampled data
|
|
53
|
+
"""
|
|
54
|
+
if not self.up:
|
|
55
|
+
return data
|
|
56
|
+
|
|
57
|
+
from mne.filter import resample
|
|
58
|
+
|
|
59
|
+
return resample(data.astype(np.float64), up=self.up, down=1.0)
|