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.
Files changed (80) hide show
  1. py_neuromodulation/ConnectivityDecoding/_get_grid_hull.m +34 -34
  2. py_neuromodulation/ConnectivityDecoding/_get_grid_whole_brain.py +95 -106
  3. py_neuromodulation/ConnectivityDecoding/_helper_write_connectome.py +107 -119
  4. py_neuromodulation/FieldTrip.py +589 -589
  5. py_neuromodulation/__init__.py +74 -13
  6. py_neuromodulation/_write_example_dataset_helper.py +83 -65
  7. py_neuromodulation/data/README +6 -6
  8. py_neuromodulation/data/dataset_description.json +8 -8
  9. py_neuromodulation/data/participants.json +32 -32
  10. py_neuromodulation/data/participants.tsv +2 -2
  11. py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_space-mni_coordsystem.json +5 -5
  12. py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_space-mni_electrodes.tsv +11 -11
  13. py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_channels.tsv +11 -11
  14. py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.json +18 -18
  15. py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vhdr +35 -35
  16. py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vmrk +13 -13
  17. py_neuromodulation/data/sub-testsub/ses-EphysMedOff/sub-testsub_ses-EphysMedOff_scans.tsv +2 -2
  18. py_neuromodulation/grid_cortex.tsv +40 -40
  19. py_neuromodulation/liblsl/libpugixml.so.1.12 +0 -0
  20. py_neuromodulation/liblsl/linux/bionic_amd64/liblsl.1.16.2.so +0 -0
  21. py_neuromodulation/liblsl/linux/bookworm_amd64/liblsl.1.16.2.so +0 -0
  22. py_neuromodulation/liblsl/linux/focal_amd46/liblsl.1.16.2.so +0 -0
  23. py_neuromodulation/liblsl/linux/jammy_amd64/liblsl.1.16.2.so +0 -0
  24. py_neuromodulation/liblsl/linux/jammy_x86/liblsl.1.16.2.so +0 -0
  25. py_neuromodulation/liblsl/linux/noble_amd64/liblsl.1.16.2.so +0 -0
  26. py_neuromodulation/liblsl/macos/amd64/liblsl.1.16.2.dylib +0 -0
  27. py_neuromodulation/liblsl/macos/arm64/liblsl.1.16.0.dylib +0 -0
  28. py_neuromodulation/liblsl/windows/amd64/liblsl.1.16.2.dll +0 -0
  29. py_neuromodulation/liblsl/windows/x86/liblsl.1.16.2.dll +0 -0
  30. py_neuromodulation/nm_IO.py +413 -417
  31. py_neuromodulation/nm_RMAP.py +496 -531
  32. py_neuromodulation/nm_analysis.py +993 -1074
  33. py_neuromodulation/nm_artifacts.py +30 -25
  34. py_neuromodulation/nm_bispectra.py +154 -168
  35. py_neuromodulation/nm_bursts.py +292 -198
  36. py_neuromodulation/nm_coherence.py +251 -205
  37. py_neuromodulation/nm_database.py +149 -0
  38. py_neuromodulation/nm_decode.py +918 -992
  39. py_neuromodulation/nm_define_nmchannels.py +300 -302
  40. py_neuromodulation/nm_features.py +144 -116
  41. py_neuromodulation/nm_filter.py +219 -219
  42. py_neuromodulation/nm_filter_preprocessing.py +79 -91
  43. py_neuromodulation/nm_fooof.py +139 -159
  44. py_neuromodulation/nm_generator.py +45 -37
  45. py_neuromodulation/nm_hjorth_raw.py +52 -73
  46. py_neuromodulation/nm_kalmanfilter.py +71 -58
  47. py_neuromodulation/nm_linelength.py +21 -33
  48. py_neuromodulation/nm_logger.py +66 -0
  49. py_neuromodulation/nm_mne_connectivity.py +149 -112
  50. py_neuromodulation/nm_mnelsl_generator.py +90 -0
  51. py_neuromodulation/nm_mnelsl_stream.py +116 -0
  52. py_neuromodulation/nm_nolds.py +96 -93
  53. py_neuromodulation/nm_normalization.py +173 -214
  54. py_neuromodulation/nm_oscillatory.py +423 -448
  55. py_neuromodulation/nm_plots.py +585 -612
  56. py_neuromodulation/nm_preprocessing.py +83 -0
  57. py_neuromodulation/nm_projection.py +370 -394
  58. py_neuromodulation/nm_rereference.py +97 -95
  59. py_neuromodulation/nm_resample.py +59 -50
  60. py_neuromodulation/nm_run_analysis.py +325 -435
  61. py_neuromodulation/nm_settings.py +289 -68
  62. py_neuromodulation/nm_settings.yaml +244 -0
  63. py_neuromodulation/nm_sharpwaves.py +423 -401
  64. py_neuromodulation/nm_stats.py +464 -480
  65. py_neuromodulation/nm_stream.py +398 -0
  66. py_neuromodulation/nm_stream_abc.py +166 -218
  67. py_neuromodulation/nm_types.py +193 -0
  68. {py_neuromodulation-0.0.4.dist-info → py_neuromodulation-0.0.5.dist-info}/METADATA +29 -26
  69. py_neuromodulation-0.0.5.dist-info/RECORD +83 -0
  70. {py_neuromodulation-0.0.4.dist-info → py_neuromodulation-0.0.5.dist-info}/WHEEL +1 -1
  71. {py_neuromodulation-0.0.4.dist-info → py_neuromodulation-0.0.5.dist-info}/licenses/LICENSE +21 -21
  72. py_neuromodulation/nm_EpochStream.py +0 -92
  73. py_neuromodulation/nm_across_patient_decoding.py +0 -927
  74. py_neuromodulation/nm_cohortwrapper.py +0 -435
  75. py_neuromodulation/nm_eval_timing.py +0 -239
  76. py_neuromodulation/nm_features_abc.py +0 -39
  77. py_neuromodulation/nm_settings.json +0 -338
  78. py_neuromodulation/nm_stream_offline.py +0 -359
  79. py_neuromodulation/utils/_logging.py +0 -24
  80. py_neuromodulation-0.0.4.dist-info/RECORD +0 -72
@@ -1,95 +1,97 @@
1
- """Re-referencing Module."""
2
- import numpy as np
3
- import pandas as pd
4
-
5
-
6
- class ReReferencer:
7
- ref_matrix: np.ndarray
8
-
9
- def __init__(
10
- self,
11
- sfreq: int | float,
12
- nm_channels: pd.DataFrame,
13
- ) -> None:
14
- """Initialize real-time rereference information.
15
-
16
- Parameters
17
- ----------
18
- sfreq : int | float
19
- Sampling frequency. Is not used, only kept for compatibility.
20
- nm_channels : Pandas DataFrame
21
- Dataframe containing information about rereferencing, as
22
- specified in nm_channels.csv.
23
-
24
-
25
- Raises:
26
- ValueError: rereferencing using undefined channel
27
- ValueError: rereferencing to same channel
28
- """
29
- nm_channels = nm_channels[nm_channels["used"] == 1].reset_index(
30
- drop=True
31
- )
32
- # (channels_used,) = np.where((nm_channels.used == 1))
33
-
34
- ch_names = nm_channels["name"].tolist()
35
-
36
- # no re-referencing is being performed when there is a single channel present only
37
- if nm_channels.shape[0] in (0, 1):
38
- self.ref_matrix = None
39
- return
40
-
41
- ch_types = nm_channels["type"]
42
- refs = nm_channels["rereference"]
43
-
44
- type_map = {}
45
- for ch_type in ch_types.unique():
46
- type_map[ch_type] = np.where(
47
- (ch_types == ch_type) & (nm_channels["status"] == "good")
48
- )[0]
49
-
50
- ref_matrix = np.zeros((len(nm_channels), len(nm_channels)))
51
- for ind in range(len(nm_channels)):
52
- ref_matrix[ind, ind] = 1
53
- # if ind not in channels_used:
54
- # continue
55
- ref = refs[ind]
56
- if ref.lower() == "none" or pd.isnull(ref):
57
- ref_idx = None
58
- continue
59
- if ref.lower() == "average":
60
- ch_type = ch_types[ind]
61
- ref_idx = type_map[ch_type][type_map[ch_type] != ind]
62
- else:
63
- ref_idx = []
64
- ref_channels = ref.split("&")
65
- for ref_chan in ref_channels:
66
- if ref_chan not in ch_names:
67
- raise ValueError(
68
- "One or more of the reference channels are not"
69
- " part of the recording channels. First missing"
70
- f" channel: {ref_chan}."
71
- )
72
- if ref_chan == ch_names[ind]:
73
- raise ValueError(
74
- "You cannot rereference to the same channel."
75
- f" Channel: {ref_chan}."
76
- )
77
- ref_idx.append(ch_names.index(ref_chan))
78
- ref_matrix[ind, ref_idx] = -1 / len(ref_idx)
79
- self.ref_matrix = ref_matrix
80
-
81
- def process(self, data: np.ndarray) -> np.ndarray:
82
- """Rereference data according to the initialized ReReferencer class.
83
-
84
- Args:
85
- data (numpy ndarray) :
86
- shape(n_channels, n_samples) - data to be rereferenced.
87
-
88
- Returns:
89
- reref_data (numpy ndarray):
90
- shape(n_channels, n_samples) - rereferenced data
91
- """
92
- if self.ref_matrix is not None:
93
- return self.ref_matrix @ data
94
- else:
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
- import mne
3
- import numpy as np
4
-
5
-
6
- class Resampler:
7
- """Resample data.
8
-
9
- Parameters
10
- ----------
11
- sfreq : int | float
12
- Original sampling frequency.
13
-
14
- Attributes
15
- ----------
16
- up: float
17
- Factor to upsample by.
18
- """
19
-
20
- def __init__(
21
- self,
22
- sfreq: int | float,
23
- resample_freq_hz: int | float,
24
- ) -> None:
25
-
26
- assert isinstance(resample_freq_hz, (float, int))
27
-
28
- self.sfreq_new: int | float = resample_freq_hz
29
- ratio = float(self.sfreq_new / sfreq)
30
- if ratio == 1.0:
31
- self.up = 0.0
32
- else:
33
- self.up = ratio
34
-
35
- def process(self, data: np.ndarray) -> np.ndarray:
36
- """Resample raw data using mne.filter.resample.
37
-
38
- Parameters
39
- ----------
40
- data : np.ndarray
41
- Data to resample
42
-
43
- Returns
44
- -------
45
- np.ndarray
46
- Resampled data
47
- """
48
- if not self.up:
49
- return data
50
- return mne.filter.resample(data.astype(np.float64), up=self.up, down=1.0)
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)