add rectify, cv, serial correlation
This commit is contained in:
parent
357c09d3dd
commit
2256800e33
@ -3,6 +3,8 @@ import pyrelacs.DataLoader as dl
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from warnings import warn
|
||||
import scipy.stats
|
||||
|
||||
|
||||
def get_subfolder_paths(basepath):
|
||||
subfolders = []
|
||||
@ -212,4 +214,35 @@ def plot_frequency_curve(cell_data, save_path: str = None, indices: list = None)
|
||||
plt.show()
|
||||
else:
|
||||
plt.savefig(save_path + "mean_frequency_curves.png")
|
||||
plt.close()
|
||||
plt.close()
|
||||
|
||||
|
||||
def rectify(x):
|
||||
if x < 0:
|
||||
return 0
|
||||
return x
|
||||
|
||||
|
||||
def calculate_coefficient_of_variation(spiketimes: list) -> float:
|
||||
# CV (stddev of ISI divided by mean ISI (np.diff(spiketimes))
|
||||
isi = np.diff(spiketimes)
|
||||
std = np.std(isi)
|
||||
mean = np.mean(isi)
|
||||
|
||||
return std/mean
|
||||
|
||||
|
||||
def calculate_serial_correlation(spiketimes: list, max_lag: int) -> list:
|
||||
isi = np.diff(spiketimes)
|
||||
if len(spiketimes) < max_lag + 1:
|
||||
raise ValueError("Given list to short, with given max_lag")
|
||||
|
||||
cor = []
|
||||
for lag in range(max_lag):
|
||||
lag = lag + 1
|
||||
first = isi[:-lag]
|
||||
second = isi[lag:]
|
||||
|
||||
cor.append(np.corrcoef(first, second)[0][1])
|
||||
|
||||
return cor
|
||||
|
Loading…
Reference in New Issue
Block a user