braindynamics-starprotocol 1.0.1__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.
Files changed (24) hide show
  1. braindynamics_starprotocol-1.0.3/MANIFEST.in +7 -0
  2. {braindynamics_starprotocol-1.0.1/src/braindynamics_starprotocol.egg-info → braindynamics_starprotocol-1.0.3}/PKG-INFO +7 -2
  3. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/README.md +4 -0
  4. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/pyproject.toml +1 -1
  5. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/setup.py +1 -1
  6. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/sca/crosscorrelogram.py +37 -19
  7. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/sca/sca_cy.c +216 -646
  8. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/sca/sca_cy.pyx +0 -9
  9. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/trialbraindata.py +1 -1
  10. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3/src/braindynamics_starprotocol.egg-info}/PKG-INFO +7 -2
  11. braindynamics_starprotocol-1.0.1/MANIFEST.in +0 -6
  12. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/LICENSE +0 -0
  13. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/setup.cfg +0 -0
  14. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/__init__.py +0 -0
  15. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/__init__.py +0 -0
  16. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/compare.py +0 -0
  17. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/networkdata.py +0 -0
  18. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/plot.py +0 -0
  19. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/network/sort.py +0 -0
  20. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol/sca/__init__.py +0 -0
  21. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol.egg-info/SOURCES.txt +0 -0
  22. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol.egg-info/dependency_links.txt +0 -0
  23. {braindynamics_starprotocol-1.0.1 → braindynamics_starprotocol-1.0.3}/src/braindynamics_starprotocol.egg-info/requires.txt +0 -0
  24. {braindynamics_starprotocol-1.0.1 → 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
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: braindynamics_starprotocol
3
- Version: 1.0.1
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
@@ -16,6 +16,7 @@ Requires-Dist: pandas>=2.2.2
16
16
  Requires-Dist: scipy>=1.14.0
17
17
  Requires-Dist: matplotlib>=3.9.2
18
18
  Requires-Dist: cliffs_delta>=1.0.0
19
+ Dynamic: license-file
19
20
 
20
21
  # BrainDynamics protocol
21
22
 
@@ -61,3 +62,7 @@ For an example of the pipeline, check `examples/pipeline_example.ipynb` notebook
61
62
  For more details, you can also refer to the [documentation available on ReadTheDocs](https://braindynamics-starprotocols.readthedocs.io)
62
63
 
63
64
  Link to the PyPi project site for release history: https://pypi.org/project/braindynamics-starprotocol
65
+
66
+ ### 4) Citation
67
+
68
+ Please cite our publication when using our code: **Varga, L.** et al. Protocol to study brain dynamics of mammals through the hierarchy of complex correlation patterns defining a robust functional architecture. _STAR Protocols_, Volume **6**, Issue **2**, 103693 (2025). DOI: https://doi.org/10.1016/j.xpro.2025.103693
@@ -42,3 +42,7 @@ For an example of the pipeline, check `examples/pipeline_example.ipynb` notebook
42
42
  For more details, you can also refer to the [documentation available on ReadTheDocs](https://braindynamics-starprotocols.readthedocs.io)
43
43
 
44
44
  Link to the PyPi project site for release history: https://pypi.org/project/braindynamics-starprotocol
45
+
46
+ ### 4) Citation
47
+
48
+ Please cite our publication when using our code: **Varga, L.** et al. Protocol to study brain dynamics of mammals through the hierarchy of complex correlation patterns defining a robust functional architecture. _STAR Protocols_, Volume **6**, Issue **2**, 103693 (2025). DOI: https://doi.org/10.1016/j.xpro.2025.103693
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "braindynamics_starprotocol"
7
- version = "1.0.1"
7
+ version = "1.0.3"
8
8
  authors = [
9
9
  { name="vlewir", email="levente.varga@ubbcluj.ro"},
10
10
  { name="bpentek", email="balazs.pentek@ubbcluj.ro" },
@@ -8,7 +8,7 @@ extensions = [ Extension( name="sca.sca_cy",
8
8
  include_dirs=[np.get_include()]) ]
9
9
 
10
10
  setup( name="braindynamics_starprotocol",
11
- version="1.0.1",
11
+ version="1.0.3",
12
12
  ext_modules=cythonize(extensions),
13
13
  include_dirs=[np.get_include()],
14
14
  options={
@@ -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, find_extremas
5
+ from .sca_cy import cross_correlation
6
6
  except ModuleNotFoundError:
7
- from sca.sca_cy import cross_correlation, find_extremas
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 fmin
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 1 or 0 representing whether the given point of the correlogram is an extrema or not
164
+ np.ndarray: array of booleans representing whether the given point of the correlogram is an extrema or not
165
165
  """
166
- extremas = np.zeros(len(self.corr_coeff_arr), dtype=np.uint16)
167
- find_extremas(np.abs(self.corr_coeff_arr), extremas)
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 _interpolate(self, shifts:np.ndarray, values:np.ndarray):
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 = (self._find_extremas() == 1)
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._interpolate(shifts, values)
207
- maxabs_hires_shift = fmin(self._interpolator, shifts[maxabs_idx], disp=0)
208
- maxabs_hires_value = self._interpolator(maxabs_hires_shift)
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._interpolate(shifts, -values) # if extrema is maxima, flip the function & find the minimas
212
- maxabs_hires_shift = fmin(self._interpolator, shifts[maxabs_idx], disp=0)
213
- maxabs_hires_value = -self._interpolator(maxabs_hires_shift)
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[0]
216
- self._maxabs_value = maxabs_hires_value[0]
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.