bmtool 0.6.9.27__py3-none-any.whl → 0.6.9.29__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.
- bmtool/analysis/entrainment.py +111 -0
- {bmtool-0.6.9.27.dist-info → bmtool-0.6.9.29.dist-info}/METADATA +1 -1
- {bmtool-0.6.9.27.dist-info → bmtool-0.6.9.29.dist-info}/RECORD +7 -7
- {bmtool-0.6.9.27.dist-info → bmtool-0.6.9.29.dist-info}/WHEEL +0 -0
- {bmtool-0.6.9.27.dist-info → bmtool-0.6.9.29.dist-info}/entry_points.txt +0 -0
- {bmtool-0.6.9.27.dist-info → bmtool-0.6.9.29.dist-info}/licenses/LICENSE +0 -0
- {bmtool-0.6.9.27.dist-info → bmtool-0.6.9.29.dist-info}/top_level.txt +0 -0
bmtool/analysis/entrainment.py
CHANGED
@@ -11,6 +11,9 @@ import xarray as xr
|
|
11
11
|
from .lfp import wavelet_filter,butter_bandpass_filter
|
12
12
|
from typing import Dict, List
|
13
13
|
from tqdm.notebook import tqdm
|
14
|
+
import scipy.stats as stats
|
15
|
+
import seaborn as sns
|
16
|
+
import matplotlib.pyplot as plt
|
14
17
|
|
15
18
|
|
16
19
|
def calculate_signal_signal_plv(x1: np.ndarray, x2: np.ndarray, fs: float, freq_of_interest: float = None,
|
@@ -426,4 +429,112 @@ def calculate_ppc_per_cell(spike_df: pd.DataFrame, lfp_signal: np.ndarray,
|
|
426
429
|
return ppc_dict
|
427
430
|
|
428
431
|
|
432
|
+
def calculate_spike_rate_power_correlation(spike_rate, lfp, fs, pop_names, freq_range=(10, 100), freq_step=5):
|
433
|
+
"""
|
434
|
+
Calculate correlation between population spike rates and LFP power across frequencies
|
435
|
+
using wavelet filtering. This function assumes the fs of the spike_rate and lfp are the same.
|
436
|
+
|
437
|
+
Parameters:
|
438
|
+
-----------
|
439
|
+
spike_rate : DataFrame
|
440
|
+
Pre-calculated population spike rates at the same fs as lfp
|
441
|
+
lfp : np.array
|
442
|
+
LFP data
|
443
|
+
fs : float
|
444
|
+
Sampling frequency
|
445
|
+
pop_names : list
|
446
|
+
List of population names to analyze
|
447
|
+
freq_range : tuple
|
448
|
+
Min and max frequency to analyze
|
449
|
+
freq_step : float
|
450
|
+
Step size for frequency analysis
|
451
|
+
|
452
|
+
Returns:
|
453
|
+
--------
|
454
|
+
correlation_results : dict
|
455
|
+
Dictionary with correlation results for each population and frequency
|
456
|
+
frequencies : array
|
457
|
+
Array of frequencies analyzed
|
458
|
+
"""
|
459
|
+
|
460
|
+
# Define frequency bands to analyze
|
461
|
+
frequencies = np.arange(freq_range[0], freq_range[1] + 1, freq_step)
|
462
|
+
|
463
|
+
# Dictionary to store results
|
464
|
+
correlation_results = {pop: {} for pop in pop_names}
|
465
|
+
|
466
|
+
# Calculate power at each frequency band using wavelet filter
|
467
|
+
power_by_freq = {}
|
468
|
+
for freq in frequencies:
|
469
|
+
# Use the wavelet_filter function from bmlfp
|
470
|
+
filtered_signal = wavelet_filter(lfp, freq, fs)
|
471
|
+
# Calculate power (magnitude squared of complex wavelet transform)
|
472
|
+
power = np.abs(filtered_signal)**2
|
473
|
+
power_by_freq[freq] = power
|
474
|
+
|
475
|
+
# Calculate correlation for each population
|
476
|
+
for pop in pop_names:
|
477
|
+
# Extract spike rate for this population
|
478
|
+
pop_rate = spike_rate[pop]
|
479
|
+
|
480
|
+
# Calculate correlation with power at each frequency
|
481
|
+
for freq in frequencies:
|
482
|
+
# Make sure the lengths match
|
483
|
+
if len(pop_rate) != len(power_by_freq[freq]):
|
484
|
+
raise Exception(f"Mismatched lengths for {pop} at {freq} Hz len(pop_rate): {len(pop_rate)}, len(power_by_freq): {len(power_by_freq[freq])}")
|
485
|
+
# use spearman for non-parametric correlation
|
486
|
+
corr, p_val = stats.spearmanr(pop_rate, power_by_freq[freq])
|
487
|
+
correlation_results[pop][freq] = {'correlation': corr, 'p_value': p_val}
|
488
|
+
|
489
|
+
return correlation_results, frequencies
|
490
|
+
|
491
|
+
|
492
|
+
def plot_spike_power_correlation(correlation_results, frequencies, pop_names):
|
493
|
+
"""
|
494
|
+
Plot the correlation between population spike rates and LFP power.
|
495
|
+
|
496
|
+
Parameters:
|
497
|
+
-----------
|
498
|
+
correlation_results : dict
|
499
|
+
Dictionary with correlation results for calculate_spike_rate_power_correlation
|
500
|
+
frequencies : array
|
501
|
+
Array of frequencies analyzed
|
502
|
+
pop_names : list
|
503
|
+
List of population names
|
504
|
+
"""
|
505
|
+
sns.set_style("whitegrid")
|
506
|
+
plt.figure(figsize=(10, 6))
|
507
|
+
|
508
|
+
for pop in pop_names:
|
509
|
+
# Extract correlation values for each frequency
|
510
|
+
corr_values = []
|
511
|
+
valid_freqs = []
|
512
|
+
|
513
|
+
for freq in frequencies:
|
514
|
+
if freq in correlation_results[pop]:
|
515
|
+
corr_values.append(correlation_results[pop][freq]['correlation'])
|
516
|
+
valid_freqs.append(freq)
|
517
|
+
|
518
|
+
# Plot correlation line
|
519
|
+
plt.plot(valid_freqs, corr_values, marker='o', label=pop,
|
520
|
+
linewidth=2, markersize=6)
|
521
|
+
|
522
|
+
plt.xlabel('Frequency (Hz)', fontsize=12)
|
523
|
+
plt.ylabel('Spike Rate-Power Correlation', fontsize=12)
|
524
|
+
plt.title('Spike rate LFP power correlation during stimulus', fontsize=14)
|
525
|
+
plt.grid(True, alpha=0.3)
|
526
|
+
plt.legend(fontsize=12)
|
527
|
+
plt.xticks(frequencies[::2]) # Display every other frequency on x-axis
|
528
|
+
|
529
|
+
# Add horizontal line at zero for reference
|
530
|
+
plt.axhline(y=0, color='gray', linestyle='-', alpha=0.5)
|
531
|
+
|
532
|
+
# Set y-axis limits to make zero visible
|
533
|
+
y_min, y_max = plt.ylim()
|
534
|
+
plt.ylim(min(y_min, -0.1), max(y_max, 0.1))
|
535
|
+
|
536
|
+
plt.tight_layout()
|
537
|
+
|
538
|
+
plt.show()
|
539
|
+
|
429
540
|
|
@@ -9,7 +9,7 @@ bmtool/plot_commands.py,sha256=Tqujyf0c0u8olhiHOMwgUSJXIIE1hgjv6otb25G9cA0,12298
|
|
9
9
|
bmtool/singlecell.py,sha256=imcdxIzvYVkaOLSGDxYp8WGGssGwXXBCRhzhlqVp7hA,44267
|
10
10
|
bmtool/synapses.py,sha256=Ow2fZavA_3_5BYCjcgPjW0YsyVOetn1wvLxL7hQvbZo,64556
|
11
11
|
bmtool/analysis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
bmtool/analysis/entrainment.py,sha256=
|
12
|
+
bmtool/analysis/entrainment.py,sha256=gq7xuE4quwwBO4eXBDpfPT32hnNuwMOd2X1DLBU9dmg,21626
|
13
13
|
bmtool/analysis/lfp.py,sha256=pMXhqWO5TB-B1cIkR9ZhPgJZi7zpiqrGdRb-JNjjI2Y,18707
|
14
14
|
bmtool/analysis/netcon_reports.py,sha256=7moyoUC45Cl1_6sGqwZ5aKphK_8i4AimroePXcgUnIo,3057
|
15
15
|
bmtool/analysis/spikes.py,sha256=x24kd0RUhumJkiunfHNEE7mM6JUqdWy1gqabmkMM4cU,14129
|
@@ -21,9 +21,9 @@ bmtool/util/commands.py,sha256=zJF-fiLk0b8LyzHDfvewUyS7iumOxVnj33IkJDzux4M,64396
|
|
21
21
|
bmtool/util/util.py,sha256=XR0qZnv_Q47jMBKQpFzCSkCuKe9u8L3YSGJAOpP2zT0,57630
|
22
22
|
bmtool/util/neuron/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
23
23
|
bmtool/util/neuron/celltuner.py,sha256=xSRpRN6DhPFz4q5buq_W8UmsD7BbUrkzYBEbKVloYss,87194
|
24
|
-
bmtool-0.6.9.
|
25
|
-
bmtool-0.6.9.
|
26
|
-
bmtool-0.6.9.
|
27
|
-
bmtool-0.6.9.
|
28
|
-
bmtool-0.6.9.
|
29
|
-
bmtool-0.6.9.
|
24
|
+
bmtool-0.6.9.29.dist-info/licenses/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
|
25
|
+
bmtool-0.6.9.29.dist-info/METADATA,sha256=g1w2cc1P9-NgBJxpw6JYlqMEVoSaglK7hIYKd082lVc,2769
|
26
|
+
bmtool-0.6.9.29.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
|
27
|
+
bmtool-0.6.9.29.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
|
28
|
+
bmtool-0.6.9.29.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
|
29
|
+
bmtool-0.6.9.29.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|