import helperFunctions as hf from CellData import icelldata_of_dir import functions as fu import numpy as np import time import matplotlib.pyplot as plt import os from scipy.signal import argrelmax from thunderfish.eventdetection import detect_peaks from stimuli.SinusAmplitudeModulation import SinusAmplitudeModulationStimulus from models.LIFACnoise import LifacNoiseModel def time_test_function(): for n in [1000]: # number of calls print("calls:", n) start = time.time() for i in range(n): data = np.random.normal(size=10000) y = [fu.rectify(x) for x in data] end = time.time() print("time:", end - start) def test_cell_data(): for cell_data in icelldata_of_dir("./data/"): #if "2012-12-20-ad" not in cell_data.get_data_path(): # continue print() print(cell_data.get_data_path()) if len(cell_data.get_base_traces(cell_data.TIME)) != 0: # print("works!") #print("VS:", cell_data.get_vector_strength()) #print("SC:", cell_data.get_serial_correlation(5)) print("Eod freq:", cell_data.get_eod_frequency()) else: pass #print("NNNOOOOOOOOOO!") #print("spiketimes:", len(cell_data.get_base_spikes())) #print("Times:", len(cell_data.get_base_traces(cell_data.TIME))) #print("EOD:", len(cell_data.get_base_traces(cell_data.EOD))) def test_peak_detection(): for cell_data in icelldata_of_dir("./data/"): print() print(cell_data.get_data_path()) times = cell_data.get_base_traces(cell_data.TIME) eod = cell_data.get_base_traces(cell_data.EOD) v1 = cell_data.get_base_traces(cell_data.V1) for i in range(len(v1)): pieces = 20 v1_trace = v1[i] total = len(v1_trace) all_peaks = [] plt.plot(times[i], v1[i]) for n in range(pieces): length = int(total/pieces) first_index = n*length last_index = (n+1)*length std = np.std(v1_trace[first_index:last_index]) peaks, _ = detect_peaks(v1_trace[first_index:last_index], std * 3) peaks = peaks + first_index all_peaks.extend(peaks) plt.plot(times[i][first_index], v1_trace[first_index], 'o', color="green") all_peaks = np.array(all_peaks) plt.plot(times[i][all_peaks], v1[i][all_peaks], 'o', color='red') plt.show() def test_simulation_speed(): parameters = {'mem_tau': 21.348990483539083, 'delta_a': 20.41809814660199, 'input_scaling': 3.0391541280864196, 'v_offset': 26.25, 'threshold': 1, 'v_base': 0, 'step_size': 0.00005, 'tau_a': 158.0404259501454, 'a_zero': 0, 'v_zero': 0, 'noise_strength': 2.87718460648148} model = LifacNoiseModel(parameters) repetitions = 1 seconds = 10 stimulus = SinusAmplitudeModulationStimulus(750, 1, 10, 1, 8) time_start = 0 t_start = time.time() for i in range(repetitions): v, spikes = model.simulate_fast(stimulus, seconds, time_start) print(len(v)) print(len(spikes)) #time_v = np.arange(time_start, seconds, model.get_sampling_interval()) #plt.plot(time_v, v, '.') #plt.show() #freq = hf.mean_freq_of_spiketimes_after_time_x(spikes, parameters["step_size"], 0) #print(freq) t_end = time.time() #print("baseline markers:", model.calculate_baseline_markers(750, 3)) print("took:", round((t_end-t_start)/repetitions, 5), "seconds for " + str(seconds) + "s simulation", "step size:", parameters["step_size"]*1000, "ms") if __name__ == '__main__': # time_test_function() # test_cell_data() # test_peak_detection() test_simulation_speed() pass