bmtool 0.6.9.27__tar.gz → 0.6.9.28__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 (34) hide show
  1. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/PKG-INFO +1 -1
  2. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/analysis/entrainment.py +109 -0
  3. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool.egg-info/PKG-INFO +1 -1
  4. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/setup.py +1 -1
  5. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/LICENSE +0 -0
  6. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/README.md +0 -0
  7. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/SLURM.py +0 -0
  8. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/__init__.py +0 -0
  9. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/__main__.py +0 -0
  10. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/analysis/__init__.py +0 -0
  11. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/analysis/lfp.py +0 -0
  12. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/analysis/netcon_reports.py +0 -0
  13. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/analysis/spikes.py +0 -0
  14. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/bmplot.py +0 -0
  15. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/connectors.py +0 -0
  16. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/debug/__init__.py +0 -0
  17. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/debug/commands.py +0 -0
  18. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/debug/debug.py +0 -0
  19. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/graphs.py +0 -0
  20. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/manage.py +0 -0
  21. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/plot_commands.py +0 -0
  22. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/singlecell.py +0 -0
  23. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/synapses.py +0 -0
  24. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/util/__init__.py +0 -0
  25. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/util/commands.py +0 -0
  26. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/util/neuron/__init__.py +0 -0
  27. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/util/neuron/celltuner.py +0 -0
  28. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool/util/util.py +0 -0
  29. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool.egg-info/SOURCES.txt +0 -0
  30. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool.egg-info/dependency_links.txt +0 -0
  31. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool.egg-info/entry_points.txt +0 -0
  32. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool.egg-info/requires.txt +0 -0
  33. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/bmtool.egg-info/top_level.txt +0 -0
  34. {bmtool-0.6.9.27 → bmtool-0.6.9.28}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bmtool
3
- Version: 0.6.9.27
3
+ Version: 0.6.9.28
4
4
  Summary: BMTool
5
5
  Home-page: https://github.com/cyneuro/bmtool
6
6
  Download-URL:
@@ -11,6 +11,7 @@ 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
14
15
 
15
16
 
16
17
  def calculate_signal_signal_plv(x1: np.ndarray, x2: np.ndarray, fs: float, freq_of_interest: float = None,
@@ -426,4 +427,112 @@ def calculate_ppc_per_cell(spike_df: pd.DataFrame, lfp_signal: np.ndarray,
426
427
  return ppc_dict
427
428
 
428
429
 
430
+ def calculate_spike_rate_power_correlation(spike_rate, lfp, fs, pop_names, freq_range=(10, 100), freq_step=5):
431
+ """
432
+ Calculate correlation between population spike rates and LFP power across frequencies
433
+ using wavelet filtering. This function assumes the fs of the spike_rate and lfp are the same.
434
+
435
+ Parameters:
436
+ -----------
437
+ spike_rate : DataFrame
438
+ Pre-calculated population spike rates at the same fs as lfp
439
+ lfp : np.array
440
+ LFP data
441
+ fs : float
442
+ Sampling frequency
443
+ pop_names : list
444
+ List of population names to analyze
445
+ freq_range : tuple
446
+ Min and max frequency to analyze
447
+ freq_step : float
448
+ Step size for frequency analysis
449
+
450
+ Returns:
451
+ --------
452
+ correlation_results : dict
453
+ Dictionary with correlation results for each population and frequency
454
+ frequencies : array
455
+ Array of frequencies analyzed
456
+ """
457
+
458
+ # Define frequency bands to analyze
459
+ frequencies = np.arange(freq_range[0], freq_range[1] + 1, freq_step)
460
+
461
+ # Dictionary to store results
462
+ correlation_results = {pop: {} for pop in pop_names}
463
+
464
+ # Calculate power at each frequency band using wavelet filter
465
+ power_by_freq = {}
466
+ for freq in frequencies:
467
+ # Use the wavelet_filter function from bmlfp
468
+ filtered_signal = wavelet_filter(lfp, freq, fs)
469
+ # Calculate power (magnitude squared of complex wavelet transform)
470
+ power = np.abs(filtered_signal)**2
471
+ power_by_freq[freq] = power
472
+
473
+ # Calculate correlation for each population
474
+ for pop in pop_names:
475
+ # Extract spike rate for this population
476
+ pop_rate = spike_rate[pop]
477
+
478
+ # Calculate correlation with power at each frequency
479
+ for freq in frequencies:
480
+ # Make sure the lengths match
481
+ if len(pop_rate) != len(power_by_freq[freq]):
482
+ 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])}")
483
+ # use spearman for non-parametric correlation
484
+ corr, p_val = stats.spearmanr(pop_rate, power_by_freq[freq])
485
+ correlation_results[pop][freq] = {'correlation': corr, 'p_value': p_val}
486
+
487
+ return correlation_results, frequencies
488
+
489
+
490
+ def plot_spike_power_correlation(correlation_results, frequencies, pop_names):
491
+ """
492
+ Plot the correlation between population spike rates and LFP power.
493
+
494
+ Parameters:
495
+ -----------
496
+ correlation_results : dict
497
+ Dictionary with correlation results for calculate_spike_rate_power_correlation
498
+ frequencies : array
499
+ Array of frequencies analyzed
500
+ pop_names : list
501
+ List of population names
502
+ """
503
+ sns.set_style("whitegrid")
504
+ plt.figure(figsize=(10, 6))
505
+
506
+ for pop in pop_names:
507
+ # Extract correlation values for each frequency
508
+ corr_values = []
509
+ valid_freqs = []
510
+
511
+ for freq in frequencies:
512
+ if freq in correlation_results[pop]:
513
+ corr_values.append(correlation_results[pop][freq]['correlation'])
514
+ valid_freqs.append(freq)
515
+
516
+ # Plot correlation line
517
+ plt.plot(valid_freqs, corr_values, marker='o', label=pop,
518
+ linewidth=2, markersize=6)
519
+
520
+ plt.xlabel('Frequency (Hz)', fontsize=12)
521
+ plt.ylabel('Spike Rate-Power Correlation', fontsize=12)
522
+ plt.title('Spike rate LFP power correlation during stimulus', fontsize=14)
523
+ plt.grid(True, alpha=0.3)
524
+ plt.legend(fontsize=12)
525
+ plt.xticks(frequencies[::2]) # Display every other frequency on x-axis
526
+
527
+ # Add horizontal line at zero for reference
528
+ plt.axhline(y=0, color='gray', linestyle='-', alpha=0.5)
529
+
530
+ # Set y-axis limits to make zero visible
531
+ y_min, y_max = plt.ylim()
532
+ plt.ylim(min(y_min, -0.1), max(y_max, 0.1))
533
+
534
+ plt.tight_layout()
535
+
536
+ plt.show()
537
+
429
538
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bmtool
3
- Version: 0.6.9.27
3
+ Version: 0.6.9.28
4
4
  Summary: BMTool
5
5
  Home-page: https://github.com/cyneuro/bmtool
6
6
  Download-URL:
@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
6
6
 
7
7
  setup(
8
8
  name="bmtool",
9
- version='0.6.9.27',
9
+ version='0.6.9.28',
10
10
  author="Neural Engineering Laboratory at the University of Missouri",
11
11
  author_email="gregglickert@mail.missouri.edu",
12
12
  description="BMTool",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes