py-neuromodulation 0.0.6__py3-none-any.whl → 0.0.7__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.
@@ -193,6 +193,7 @@ coherence_settings:
193
193
  method:
194
194
  coh: true
195
195
  icoh: true
196
+ nperseg: 128
196
197
 
197
198
  fooof_settings:
198
199
  aperiodic:
@@ -96,11 +96,8 @@ class Bispectra(NMFeature):
96
96
  def calc_feature(self, data: np.ndarray) -> dict:
97
97
  from pybispectra import compute_fft, WaveShape
98
98
 
99
- # PyBispectra's compute_fft uses PQDM to parallelize the calculation per channel
100
- # Is this necessary? Maybe the overhead of parallelization is not worth it
101
- # considering that we incur in it once per batch of data
102
99
  fft_coeffs, freqs = compute_fft(
103
- data=np.expand_dims(data, axis=(0)),
100
+ data=np.expand_dims(data, axis=0),
104
101
  sampling_freq=self.sfreq,
105
102
  n_points=data.shape[1],
106
103
  verbose=False,
@@ -127,12 +124,11 @@ class Bispectra(NMFeature):
127
124
  f1s=tuple(self.settings.f1s), # type: ignore
128
125
  f2s=tuple(self.settings.f2s), # type: ignore
129
126
  )
127
+ waveshape = waveshape.results.get_results(copy=False) # can overwrite obj with array
130
128
 
131
129
  feature_results = {}
132
130
  for ch_idx, ch_name in enumerate(self.ch_names):
133
- bispectrum = waveshape._bicoherence[
134
- ch_idx
135
- ] # Same as waveshape.results._data, skips a copy
131
+ bispectrum = waveshape[ch_idx]
136
132
 
137
133
  for component in self.settings.components.get_enabled():
138
134
  spectrum_ch = COMPONENT_DICT[component](bispectrum)
@@ -26,7 +26,7 @@ class CoherenceFeatures(BoolSelector):
26
26
  mean_fband: bool = True
27
27
  max_fband: bool = True
28
28
  max_allfbands: bool = True
29
-
29
+
30
30
 
31
31
  ListOfTwoStr = Annotated[list[str], Field(min_length=2, max_length=2)]
32
32
 
@@ -35,6 +35,7 @@ class CoherenceSettings(NMBaseModel):
35
35
  features: CoherenceFeatures = CoherenceFeatures()
36
36
  method: CoherenceMethods = CoherenceMethods()
37
37
  channels: list[ListOfTwoStr] = []
38
+ nperseg: int = Field(default=128, ge=0)
38
39
  frequency_bands: list[str] = Field(default=["high_beta"], min_length=1)
39
40
 
40
41
  @field_validator("frequency_bands")
@@ -49,6 +50,7 @@ class CoherenceObject:
49
50
  window: str,
50
51
  fbands: list[FrequencyRange],
51
52
  fband_names: list[str],
53
+ nperseg: int,
52
54
  ch_1_name: str,
53
55
  ch_2_name: str,
54
56
  ch_1_idx: int,
@@ -65,6 +67,7 @@ class CoherenceObject:
65
67
  self.ch_2 = ch_2_name
66
68
  self.ch_1_idx = ch_1_idx
67
69
  self.ch_2_idx = ch_2_idx
70
+ self.nperseg = nperseg
68
71
  self.coh = coh
69
72
  self.icoh = icoh
70
73
  self.features_coh = features_coh
@@ -79,14 +82,15 @@ class CoherenceObject:
79
82
  def get_coh(self, feature_results, x, y):
80
83
  from scipy.signal import welch, csd
81
84
 
82
- self.f, self.Pxx = welch(x, self.sfreq, self.window, nperseg=128)
83
- self.Pyy = welch(y, self.sfreq, self.window, nperseg=128)[1]
84
- self.Pxy = csd(x, y, self.sfreq, self.window, nperseg=128)[1]
85
+ self.f, self.Pxx = welch(x, self.sfreq, self.window, nperseg=self.nperseg)
86
+ self.Pyy = welch(y, self.sfreq, self.window, nperseg=self.nperseg)[1]
87
+ self.Pxy = csd(x, y, self.sfreq, self.window, nperseg=self.nperseg)[1]
85
88
 
86
89
  if self.coh:
87
- self.coh_val = np.abs(self.Pxy**2) / (self.Pxx * self.Pyy)
90
+ # XXX: gives different output to abs(Sxy) / sqrt(Sxx * Syy)
91
+ self.coh_val = np.abs(self.Pxy) ** 2 / (self.Pxx * self.Pyy)
88
92
  if self.icoh:
89
- self.icoh_val = np.array(self.Pxy / (self.Pxx * self.Pyy)).imag
93
+ self.icoh_val = self.Pxy.imag / np.sqrt(self.Pxx * self.Pyy)
90
94
 
91
95
  for coh_idx, coh_type in enumerate([self.coh, self.icoh]):
92
96
  if coh_type:
@@ -180,6 +184,7 @@ class Coherence(NMFeature):
180
184
  "hann",
181
185
  fband_specs,
182
186
  fband_names,
187
+ self.settings.nperseg,
183
188
  ch_1_name,
184
189
  ch_2_name,
185
190
  ch_1_idx,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: py_neuromodulation
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: Real-time analysis of intracranial neurophysiology recordings.
5
5
  Project-URL: bugtracker, https://github.com/neuromodulation/py_neuromodulation/issues
6
6
  Project-URL: repository, https://github.com/neuromodulation/py_neuromodulation
@@ -36,20 +36,21 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
36
36
  Requires-Python: >=3.11
37
37
  Requires-Dist: fooof
38
38
  Requires-Dist: joblib>=1.3.2
39
+ Requires-Dist: llvmlite>=0.43.0
39
40
  Requires-Dist: matplotlib>=3.9.0
40
41
  Requires-Dist: mne
41
42
  Requires-Dist: mne-bids>=0.8
42
43
  Requires-Dist: mne-connectivity
43
44
  Requires-Dist: mne-lsl>=1.2.0
44
45
  Requires-Dist: mrmr-selection
45
- Requires-Dist: nolds
46
+ Requires-Dist: nolds>=0.6.1
47
+ Requires-Dist: numba>=0.60.0
46
48
  Requires-Dist: numpy>=1.21.2
47
49
  Requires-Dist: pandas>=2.0.0
48
50
  Requires-Dist: pyarrow>=14.0.2
49
51
  Requires-Dist: pybispectra>=1.2.0
50
52
  Requires-Dist: pydantic>=2.7.3
51
53
  Requires-Dist: pyparrm
52
- Requires-Dist: pyqt5
53
54
  Requires-Dist: scikit-learn>=0.24.2
54
55
  Requires-Dist: scikit-optimize
55
56
  Requires-Dist: scipy>=1.7.1
@@ -108,7 +109,7 @@ The original intention for writing this toolbox was movement decoding from invas
108
109
  The application however could be any neural decoding problem.
109
110
  *py_neuromodulation* offers wrappers around common practice machine learning methods for efficient analysis.
110
111
 
111
- Find the documentation here http://py-neuromodulation.readthedocs.io for example usage and parametrization.
112
+ Find the documentation here neuromodulation.github.io/py_neuromodulation/ for example usage and parametrization.
112
113
 
113
114
  Installation
114
115
  ============
@@ -119,25 +120,15 @@ py_neuromodulation requires at least python 3.10. For installation you can use p
119
120
 
120
121
  pip install py-neuromodulation
121
122
 
122
- Alternatively you can also install the package in a conda environment:
123
+ Alternatively you can also clone the pacakge and install it using `uv <https://docs.astral.sh/uv/>`_:
123
124
 
124
125
  .. code-block::
125
126
 
126
- conda create -n pynm-test python=3.11
127
- conda activate pynm-test
127
+ uv python install 3.10
128
+ uv venv
129
+ . .venv/bin/activate
130
+ uv sync
128
131
 
129
- Then install the packages listed in the `pyproject.toml`:
130
-
131
- .. code-block::
132
-
133
- pip install .
134
-
135
-
136
- Optionally the ipython kernel can be specified for the installed pynm-test conda environment:
137
-
138
- .. code-block::
139
-
140
- ipython kernel install --user --name=pynm-test
141
132
 
142
133
  Then *py_neuromodulation* can be imported via:
143
134
 
@@ -1,5 +1,5 @@
1
1
  py_neuromodulation/__init__.py,sha256=MaOF7mCNRjR9MgcCnk9b7dYJICVJthiWlZVf365lXOo,2831
2
- py_neuromodulation/default_settings.yaml,sha256=g7UcCxmcQtg7YySj3WAhQ-hdqJlOYrvZYZtMcJuWzpQ,5552
2
+ py_neuromodulation/default_settings.yaml,sha256=06KzRz8eLAa5--gmrYsr_bn9UOzSMIpuktrPKNaSc4A,5568
3
3
  py_neuromodulation/grid_cortex.tsv,sha256=k2QOkHY1ej3lJ33LD6DOPVlTynzB3s4BYaoQaoUCyYc,643
4
4
  py_neuromodulation/grid_subcortex.tsv,sha256=oCQDYLDdYSa1DAI9ybwECfuzWulFzXqKHyf7oZ1oDBM,25842
5
5
  py_neuromodulation/ConnectivityDecoding/Automated Anatomical Labeling 3 (Rolls 2020).nii,sha256=Sp-cjF_AuT0Tlilb5s8lB14hVgkXJiR2uKMS9nOQOeg,902981
@@ -30,9 +30,9 @@ py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMe
30
30
  py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vmrk,sha256=BD-VmcKe7dR0vGzzkv4c09QnSwc3zYeAWDGJIzWEOI0,540
31
31
  py_neuromodulation/features/__init__.py,sha256=zpulQ3IaKh6yNSnCBIRa5IC3SZ7FlKNQxHLF50yTdQU,1567
32
32
  py_neuromodulation/features/bandpower.py,sha256=rpkY2dNayXYng1BmZxyKTxgrJFnrslPaKVUpoNXE6EA,6152
33
- py_neuromodulation/features/bispectra.py,sha256=FvXzvkhoKaOZNjYckJgMSscAA4ShN-g8ufwe6-2zNGw,5509
33
+ py_neuromodulation/features/bispectra.py,sha256=BzI0UsMnBWal6qtqmTmLOR20IA_Wly7EIy0wCK0QgVQ,5272
34
34
  py_neuromodulation/features/bursts.py,sha256=7-I81RYSZEm5pbIKc6wXmfxmJ4Q6V41CfJXebqkGGDw,11467
35
- py_neuromodulation/features/coherence.py,sha256=I6w7bUwIh9rte9mYXEB1XX7HYwFJw0OG0IeMpJtR2LU,8798
35
+ py_neuromodulation/features/coherence.py,sha256=j1J7GHTElVuAl7x2NsGVpoQLQ9npxyznJ6HM7Nzb49k,9040
36
36
  py_neuromodulation/features/feature_processor.py,sha256=CT05jNks681LOcyr2yHe1KaUryJXm52_53hNmEhuWnM,3972
37
37
  py_neuromodulation/features/fooof.py,sha256=RouqFikiKf_JSiEel569lfjzfYRE7CEvBlgvuj53Xj4,5016
38
38
  py_neuromodulation/features/hjorth_raw.py,sha256=mRPioPHJdN73AGErRbJ5S1Vz__qEQ89jAKaeN5k8eXo,1845
@@ -83,7 +83,7 @@ py_neuromodulation/utils/io.py,sha256=-qAwtFSsumfzY6dkYSKGySE8_RH1c2M1NDxC_ZQrUV
83
83
  py_neuromodulation/utils/keyboard.py,sha256=swoxYhf4Q3pj50EKALUFt6hREfXnoXq2Z2q01IahPe8,1505
84
84
  py_neuromodulation/utils/logging.py,sha256=eIBFBRaAMb3KJnoxNFiCkMrTGzWwgfeDs8m5iq6FxN8,2178
85
85
  py_neuromodulation/utils/types.py,sha256=QVq3wAgMcw5zKPa_Kj2QQ2Gt2CYavO_PAka3RAZdfwo,7310
86
- py_neuromodulation-0.0.6.dist-info/METADATA,sha256=UcYGczR0VlQ_98AKZe6J-x8Ml-wiie9d7Th7paCeziY,7216
87
- py_neuromodulation-0.0.6.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
88
- py_neuromodulation-0.0.6.dist-info/licenses/LICENSE,sha256=EMBwuBRPBo-WkHSjqxZ55E6j95gKNBZ8x30pt-VGfrM,1118
89
- py_neuromodulation-0.0.6.dist-info/RECORD,,
86
+ py_neuromodulation-0.0.7.dist-info/METADATA,sha256=GnkK958mbJYayCTmPLr9c1lYj3s0cXg4LCqL0SHSQdw,7045
87
+ py_neuromodulation-0.0.7.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
88
+ py_neuromodulation-0.0.7.dist-info/licenses/LICENSE,sha256=EMBwuBRPBo-WkHSjqxZ55E6j95gKNBZ8x30pt-VGfrM,1118
89
+ py_neuromodulation-0.0.7.dist-info/RECORD,,