add reference and test for detect spikes

This commit is contained in:
a.ott 2020-05-20 15:23:45 +02:00
parent f7ffdcc66f
commit 15bcc09655

View File

@ -2,9 +2,17 @@ import unittest
import numpy as np
import helperFunctions as hF
import matplotlib.pyplot as plt
from CellData import icelldata_of_dir
from Baseline import BaselineCellData
import os
class HelperFunctionsTester(unittest.TestCase):
reference_base_spikes = {'2012-12-21-an-invivo-1': 39, '2012-07-12-ag-invivo-1': 21, '2012-12-13-ac-invivo-1': 19,
'2012-12-20-ac-invivo-1': 43, '2013-01-08-ad-invivo-1': 29, '2012-06-27-an-invivo-1': 19,
'2012-12-13-ah-invivo-1': 35, '2012-12-13-ag-invivo-1': 26, '2012-12-13-an-invivo-1': 29,
'2012-12-21-ai-invivo-1': 55, '2012-12-20-aa-invivo-1': 24, '2012-12-21-am-invivo-1': 26,
'2012-06-27-ah-invivo-1': 27, '2012-07-12-ap-invivo-1': 35, '2012-12-21-ak-invivo-1': 30}
noise_levels = [0, 0.05, 0.1, 0.2]
frequencies = [0, 1, 5, 30, 100, 500, 750, 1000]
@ -30,18 +38,44 @@ class HelperFunctionsTester(unittest.TestCase):
self.assertEqual(0, round(hF.__vector_strength__(rel_spike_times, eod_durations), 5))
# def test_eods_around_spikes(self):
#
# time = np.arange(0, 3, 0.01)
# eod = np.sin(2*np.pi * 2 * time)
#
# spikes = [0.2, 0.5, 0.6]
# indices = np.searchsorted(time, spikes)
#
# rel_spike_time, eod_duration = hF.eods_around_spikes(time, eod, indices)
#
# print("meep")
def test_detect_spiketimes(self):
count = 0
for cell_data in icelldata_of_dir("./test_data/"):
print(cell_data.get_data_path())
# if "21-ai" not in cell_data.get_data_path() and "20-ac" not in cell_data.get_data_path():
# continue
spikes = np.array(cell_data.get_base_spikes()[0])
time_length = 0.2
time = cell_data.get_base_traces(cell_data.TIME)[0]
length_data_points = int(time_length / cell_data.get_sampling_interval())
start_idx = 0
end_idx = length_data_points + 1
end_idx = end_idx if end_idx <= len(time) else len(time)
bot_lim_spikes = spikes[spikes > time[start_idx]]
top_lim_spikes = bot_lim_spikes[bot_lim_spikes < time[end_idx]]
expected = self.reference_base_spikes[os.path.basename(cell_data.get_data_path())]
if len(top_lim_spikes) == expected:
print("yay")
else:
print("detected: {:}, reference: {:}".format(len(top_lim_spikes), expected))
print("nay")
baseline = BaselineCellData(cell_data)
baseline.plot_baseline(position=0, time_length=0.2)
count += 1
def test_automatic_splitting(self):
for cell_data in icelldata_of_dir("./test_data/"):
print(cell_data.get_data_path())
v1 = cell_data.get_base_traces(cell_data.V1)[0]
hF.detect_spike_indices_automatic_split(v1)
# todo
# search_eod_start_and_end_times ? (not used anymore ?)