braindynamics-starprotocol 1.0.2__tar.gz → 1.0.3__tar.gz
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.
- braindynamics_starprotocol-1.0.3/MANIFEST.in +7 -0
- {braindynamics_starprotocol-1.0.2/src/braindynamics_starprotocol.egg-info → braindynamics_starprotocol-1.0.3}/PKG-INFO +1 -1
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/pyproject.toml +1 -1
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/setup.py +1 -1
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/sca/crosscorrelogram.py +37 -19
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/sca/sca_cy.c +187 -617
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/sca/sca_cy.pyx +0 -9
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3/src/braindynamics_starprotocol.egg-info}/PKG-INFO +1 -1
- braindynamics_starprotocol-1.0.2/MANIFEST.in +0 -6
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/LICENSE +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/README.md +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/setup.cfg +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/__init__.py +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/__init__.py +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/compare.py +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/networkdata.py +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/plot.py +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/sort.py +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/sca/__init__.py +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/trialbraindata.py +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol.egg-info/SOURCES.txt +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol.egg-info/dependency_links.txt +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol.egg-info/requires.txt +0 -0
- {braindynamics_starprotocol-1.0.2 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
include src/braindynamics_starprotocol/sca/sca_cy.pyx
|
|
2
|
+
|
|
3
|
+
exclude src/braindynamics_starprotocol/rawbraindata.py
|
|
4
|
+
exclude src/braindynamics_starprotocol/trialdata.py
|
|
5
|
+
recursive-exclude src/braindynamics_starprotocol/build/ *
|
|
6
|
+
recursive-exclude src/braindynamics_starprotocol/io/ *
|
|
7
|
+
recursive-exclude **/__pycache__ *
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: braindynamics_starprotocol
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Functional brain network analysis protocol developed by Varga et al., 2024
|
|
5
5
|
Author-email: vlewir <levente.varga@ubbcluj.ro>, bpentek <balazs.pentek@ubbcluj.ro>
|
|
6
6
|
Project-URL: Homepage, https://github.com/vlewir/BrainDynamics_STARProtocols
|
|
@@ -2,12 +2,12 @@ import os
|
|
|
2
2
|
import numpy as np
|
|
3
3
|
from scipy.stats import pearsonr
|
|
4
4
|
try:
|
|
5
|
-
from .sca_cy import cross_correlation
|
|
5
|
+
from .sca_cy import cross_correlation
|
|
6
6
|
except ModuleNotFoundError:
|
|
7
|
-
from sca.sca_cy import cross_correlation
|
|
7
|
+
from sca.sca_cy import cross_correlation
|
|
8
8
|
import matplotlib.pyplot as plt
|
|
9
9
|
from scipy.interpolate import Akima1DInterpolator
|
|
10
|
-
from scipy.optimize import
|
|
10
|
+
from scipy.optimize import minimize_scalar
|
|
11
11
|
|
|
12
12
|
def _fisher_transform(r:float, norm_factor:float=1.12)->float:
|
|
13
13
|
return 0.5*log((1 + r/norm_factor)/(1 - r/norm_factor))
|
|
@@ -155,19 +155,21 @@ class CrossCorrelogram():
|
|
|
155
155
|
self._compute_py(x, y, use_fisher=use_fisher)
|
|
156
156
|
else:
|
|
157
157
|
raise ValueError("Only two options are supported for `cc_method` parameter: 'py' for pure python implementation, 'C' for cython (recommended)")
|
|
158
|
-
|
|
158
|
+
|
|
159
159
|
def _find_extremas(self)->np.ndarray:
|
|
160
160
|
"""
|
|
161
|
-
Find extremas of the correlogram
|
|
161
|
+
Find extremas (peaks) of the correlogram.
|
|
162
162
|
|
|
163
163
|
Returns:
|
|
164
|
-
np.ndarray: array of
|
|
164
|
+
np.ndarray: array of booleans representing whether the given point of the correlogram is an extrema or not
|
|
165
165
|
"""
|
|
166
|
-
extremas = np.
|
|
167
|
-
|
|
166
|
+
extremas = np.full(len(self.corr_coeff_arr), False, dtype=bool)
|
|
167
|
+
for i in range(1, len(self.corr_coeff_arr) - 1):
|
|
168
|
+
if (self.corr_coeff_arr[i] - self.corr_coeff_arr[i - 1])*(self.corr_coeff_arr[i + 1] - self.corr_coeff_arr[i]) < 0:
|
|
169
|
+
extremas[i] = True
|
|
168
170
|
return extremas
|
|
169
171
|
|
|
170
|
-
def
|
|
172
|
+
def _set_interpolator(self, shifts:np.ndarray, values:np.ndarray):
|
|
171
173
|
"""
|
|
172
174
|
Wrapper function for the interpolator object.
|
|
173
175
|
|
|
@@ -177,6 +179,11 @@ class CrossCorrelogram():
|
|
|
177
179
|
"""
|
|
178
180
|
self._interpolator = Akima1DInterpolator(shifts, values)
|
|
179
181
|
|
|
182
|
+
def _interpolate(self, shift:float):
|
|
183
|
+
if self._interpolator is None:
|
|
184
|
+
raise ValueError('Akima interpolator object not set')
|
|
185
|
+
return self._interpolator(shift)
|
|
186
|
+
|
|
180
187
|
def get_maxabs(self)->tuple:
|
|
181
188
|
"""
|
|
182
189
|
Function that determines & saves MaxAbs (absolute peak) of the interpolated correlogram.
|
|
@@ -194,7 +201,16 @@ class CrossCorrelogram():
|
|
|
194
201
|
return self.max_shift_size, self.corr_coeff_arr[0]
|
|
195
202
|
|
|
196
203
|
# finding maxabs on correlogram
|
|
197
|
-
is_extrema =
|
|
204
|
+
is_extrema = self._find_extremas()
|
|
205
|
+
|
|
206
|
+
# check if no peaks were detected on correlogram
|
|
207
|
+
if (is_extrema == False).all():
|
|
208
|
+
maxabs_idx = np.argmax(np.abs(self.corr_coeff_arr)) # in that case, maxabs will be its maximal absolute value (either first or last point, because it's monotonic)
|
|
209
|
+
self._maxabs_shift = maxabs_idx - self.max_shift_size
|
|
210
|
+
self._maxabs_value = self.corr_coeff_arr[maxabs_idx]
|
|
211
|
+
print(f'\tNOTE: No peaks found on the correlogram (it is monotonic function). Returning the maximal absolute value of the correlogram ({self._maxabs_value}) located at the maximal shift ({self._maxabs_shift}).')
|
|
212
|
+
return self._maxabs_shift, self._maxabs_value
|
|
213
|
+
|
|
198
214
|
argmax_idx = np.argmax(np.abs(self.corr_coeff_arr[is_extrema]))
|
|
199
215
|
maxabs_idx = np.where(is_extrema == 1)[0][argmax_idx] # index of extrema with max abs in the correlogram
|
|
200
216
|
# preparing data for interpolation
|
|
@@ -203,20 +219,22 @@ class CrossCorrelogram():
|
|
|
203
219
|
# interpolate & find minima
|
|
204
220
|
if self.corr_coeff_arr[maxabs_idx] < self.corr_coeff_arr[maxabs_idx - 1] and self.corr_coeff_arr[maxabs_idx] < self.corr_coeff_arr[maxabs_idx + 1]:
|
|
205
221
|
self._maxabs_is_min = True
|
|
206
|
-
self.
|
|
207
|
-
|
|
208
|
-
|
|
222
|
+
self._set_interpolator(shifts, values)
|
|
223
|
+
res = minimize_scalar(self._interpolate, bounds=(shifts[maxabs_idx - 1], shifts[maxabs_idx + 1]), method='bounded') # find minimum near the detected peak (maxabs)
|
|
224
|
+
maxabs_hires_shift = res.x
|
|
225
|
+
maxabs_hires_value = res.fun
|
|
209
226
|
elif self.corr_coeff_arr[maxabs_idx] > self.corr_coeff_arr[maxabs_idx - 1] and self.corr_coeff_arr[maxabs_idx] > self.corr_coeff_arr[maxabs_idx + 1]:
|
|
210
227
|
self._maxabs_is_min = False
|
|
211
|
-
self.
|
|
212
|
-
|
|
213
|
-
|
|
228
|
+
self._set_interpolator(shifts, -values) # if extrema is maxima, flip the function & find the minimas
|
|
229
|
+
res = minimize_scalar(self._interpolate, bounds=(shifts[maxabs_idx - 1], shifts[maxabs_idx + 1]), method='bounded')
|
|
230
|
+
maxabs_hires_shift = res.x
|
|
231
|
+
maxabs_hires_value = -res.fun # flipping back to get maxima value
|
|
214
232
|
|
|
215
|
-
self._maxabs_shift = maxabs_hires_shift
|
|
216
|
-
self._maxabs_value = maxabs_hires_value
|
|
233
|
+
self._maxabs_shift = maxabs_hires_shift
|
|
234
|
+
self._maxabs_value = maxabs_hires_value
|
|
217
235
|
|
|
218
236
|
return self._maxabs_shift, self._maxabs_value
|
|
219
|
-
|
|
237
|
+
|
|
220
238
|
def plot(self, show_interp:bool=False, show_maxabs:bool=False, interp_shift_res:float=0.1):
|
|
221
239
|
"""
|
|
222
240
|
Plot correlogram.
|