diff --git a/code/test.py b/code/test.py index b08d495..dd49edb 100644 --- a/code/test.py +++ b/code/test.py @@ -5,6 +5,7 @@ import matplotlib.pyplot as plt import rlxnix as rlx from IPython import embed from scipy.signal import welch +import useful_functions as f def binary_spikes(spike_times, duration, dt): """ @@ -68,10 +69,10 @@ def extract_stim_data(stimulus): ''' # extract metadata # the stim.name adjusts the first key as it changes with every stimulus - amplitude = stim.metadata[stim.name]['Contrast'][0][0] - df = stim.metadata[stim.name]['DeltaF'][0][0] - eodf = round(stim.metadata[stim.name]['EODf'][0][0]) - stim_freq = round(stim.metadata[stim.name]['Frequency'][0][0]) + amplitude = stimulus.metadata[stimulus.name]['Contrast'][0][0] + df = stimulus.metadata[stimulus.name]['DeltaF'][0][0] + eodf = round(stimulus.metadata[stimulus.name]['EODf'][0][0]) + stim_freq = round(stimulus.metadata[stimulus.name]['Frequency'][0][0]) # calculates the amplitude modulation amp_mod, ny_freq = AM(eodf, stim_freq) return amplitude, df, eodf, stim_freq, amp_mod, ny_freq @@ -187,7 +188,7 @@ def sam_data(sam): #find example data datafolder = "../../data" -example_file = datafolder + "/" + "2024-10-16-ah-invivo-1.nix" +example_file = datafolder + "/" + "2024-10-16-ad-invivo-1.nix" data_files = glob.glob("../../data/*.nix") @@ -209,41 +210,43 @@ ax.scatter(spike_times[spike_times < 0.1], np.ones_like(spike_times[spike_times < 0.1]) * np.max(potential)) #plot teh spike times on top plt.show() plt.close() -# get all the stimuli -stims = sam.stimuli -# empty list for the spike times -spikes = [] -#spikes2 = np.array(range(len(stims))) -# loop over the stimuli -for stim in stims: - # get the spike times - spike, _ = stim.trace_data('Spikes-1') - # append the first 100ms to spikes - spikes.append(spike[spike < 0.1]) - # get stimulus duration - duration = stim.duration - ti = stim.trace_info("V-1") - dt = ti.sampling_interval # get the stimulus interval - bin_spikes = binary_spikes(spike, duration, dt) #binarize the spike_times - print(len(bin_spikes)) - pot,tim= stim.trace_data("V-1") #membrane potential - rate = firing_rate(bin_spikes, dt = dt) - print(np.mean(rate)) - fig, [ax1, ax2] = plt.subplots(1, 2,layout = 'constrained') - ax1.plot(tim,rate) - ax1.set_ylim(0,600) - ax1.set_xlim(0, 0.04) - freq, power = power_spectrum(rate, dt) - ax2.plot(freq,power) - ax2.set_xlim(0,1000) - plt.close() - if stim == stims[-1]: - amplitude, df, eodf, stim_freq = extract_stim_data(stim) - print(amplitude, df, eodf, stim_freq) - -# make an eventplot -fig = plt.figure(figsize = (5, 3), layout = 'constrained') -ax = fig.add_subplot() -ax.eventplot(spikes, linelength = 0.8) -ax.set_xlabel('time [ms]') -ax.set_ylabel('loop no.') + +sam_amp, sam_am,sam_df, sam_eodf, sam_nyquist, sam_stim = f.sam_data(sam) +# # get all the stimuli +# stims = sam.stimuli +# # empty list for the spike times +# spikes = [] +# #spikes2 = np.array(range(len(stims))) +# # loop over the stimuli +# for stim in stims: +# # get the spike times +# spike, _ = stim.trace_data('Spikes-1') +# # append the first 100ms to spikes +# spikes.append(spike[spike < 0.1]) +# # get stimulus duration +# duration = stim.duration +# ti = stim.trace_info("V-1") +# dt = ti.sampling_interval # get the stimulus interval +# bin_spikes = binary_spikes(spike, duration, dt) #binarize the spike_times +# print(len(bin_spikes)) +# pot,tim= stim.trace_data("V-1") #membrane potential +# rate = firing_rate(bin_spikes, dt = dt) +# print(np.mean(rate)) +# fig, [ax1, ax2] = plt.subplots(1, 2,layout = 'constrained') +# ax1.plot(tim,rate) +# ax1.set_ylim(0,600) +# ax1.set_xlim(0, 0.04) +# freq, power = power_spectrum(rate, dt) +# ax2.plot(freq,power) +# ax2.set_xlim(0,1000) +# plt.close() +# if stim == stims[-1]: +# amplitude, df, eodf, stim_freq = extract_stim_data(stim) +# print(amplitude, df, eodf, stim_freq) + +# # make an eventplot +# fig = plt.figure(figsize = (5, 3), layout = 'constrained') +# ax = fig.add_subplot() +# ax.eventplot(spikes, linelength = 0.8) +# ax.set_xlabel('time [ms]') +# ax.set_ylabel('loop no.')