tested and corrected sam_data function
This commit is contained in:
parent
c7436ad6b6
commit
c995ed7a3b
89
code/test.py
89
code/test.py
@ -5,6 +5,7 @@ import matplotlib.pyplot as plt
|
|||||||
import rlxnix as rlx
|
import rlxnix as rlx
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
from scipy.signal import welch
|
from scipy.signal import welch
|
||||||
|
import useful_functions as f
|
||||||
|
|
||||||
def binary_spikes(spike_times, duration, dt):
|
def binary_spikes(spike_times, duration, dt):
|
||||||
"""
|
"""
|
||||||
@ -68,10 +69,10 @@ def extract_stim_data(stimulus):
|
|||||||
'''
|
'''
|
||||||
# extract metadata
|
# extract metadata
|
||||||
# the stim.name adjusts the first key as it changes with every stimulus
|
# the stim.name adjusts the first key as it changes with every stimulus
|
||||||
amplitude = stim.metadata[stim.name]['Contrast'][0][0]
|
amplitude = stimulus.metadata[stimulus.name]['Contrast'][0][0]
|
||||||
df = stim.metadata[stim.name]['DeltaF'][0][0]
|
df = stimulus.metadata[stimulus.name]['DeltaF'][0][0]
|
||||||
eodf = round(stim.metadata[stim.name]['EODf'][0][0])
|
eodf = round(stimulus.metadata[stimulus.name]['EODf'][0][0])
|
||||||
stim_freq = round(stim.metadata[stim.name]['Frequency'][0][0])
|
stim_freq = round(stimulus.metadata[stimulus.name]['Frequency'][0][0])
|
||||||
# calculates the amplitude modulation
|
# calculates the amplitude modulation
|
||||||
amp_mod, ny_freq = AM(eodf, stim_freq)
|
amp_mod, ny_freq = AM(eodf, stim_freq)
|
||||||
return amplitude, df, eodf, stim_freq, amp_mod, ny_freq
|
return amplitude, df, eodf, stim_freq, amp_mod, ny_freq
|
||||||
@ -187,7 +188,7 @@ def sam_data(sam):
|
|||||||
#find example data
|
#find example data
|
||||||
datafolder = "../../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")
|
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
|
np.ones_like(spike_times[spike_times < 0.1]) * np.max(potential)) #plot teh spike times on top
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close()
|
plt.close()
|
||||||
# get all the stimuli
|
|
||||||
stims = sam.stimuli
|
sam_amp, sam_am,sam_df, sam_eodf, sam_nyquist, sam_stim = f.sam_data(sam)
|
||||||
# empty list for the spike times
|
# # get all the stimuli
|
||||||
spikes = []
|
# stims = sam.stimuli
|
||||||
#spikes2 = np.array(range(len(stims)))
|
# # empty list for the spike times
|
||||||
# loop over the stimuli
|
# spikes = []
|
||||||
for stim in stims:
|
# #spikes2 = np.array(range(len(stims)))
|
||||||
# get the spike times
|
# # loop over the stimuli
|
||||||
spike, _ = stim.trace_data('Spikes-1')
|
# for stim in stims:
|
||||||
# append the first 100ms to spikes
|
# # get the spike times
|
||||||
spikes.append(spike[spike < 0.1])
|
# spike, _ = stim.trace_data('Spikes-1')
|
||||||
# get stimulus duration
|
# # append the first 100ms to spikes
|
||||||
duration = stim.duration
|
# spikes.append(spike[spike < 0.1])
|
||||||
ti = stim.trace_info("V-1")
|
# # get stimulus duration
|
||||||
dt = ti.sampling_interval # get the stimulus interval
|
# duration = stim.duration
|
||||||
bin_spikes = binary_spikes(spike, duration, dt) #binarize the spike_times
|
# ti = stim.trace_info("V-1")
|
||||||
print(len(bin_spikes))
|
# dt = ti.sampling_interval # get the stimulus interval
|
||||||
pot,tim= stim.trace_data("V-1") #membrane potential
|
# bin_spikes = binary_spikes(spike, duration, dt) #binarize the spike_times
|
||||||
rate = firing_rate(bin_spikes, dt = dt)
|
# print(len(bin_spikes))
|
||||||
print(np.mean(rate))
|
# pot,tim= stim.trace_data("V-1") #membrane potential
|
||||||
fig, [ax1, ax2] = plt.subplots(1, 2,layout = 'constrained')
|
# rate = firing_rate(bin_spikes, dt = dt)
|
||||||
ax1.plot(tim,rate)
|
# print(np.mean(rate))
|
||||||
ax1.set_ylim(0,600)
|
# fig, [ax1, ax2] = plt.subplots(1, 2,layout = 'constrained')
|
||||||
ax1.set_xlim(0, 0.04)
|
# ax1.plot(tim,rate)
|
||||||
freq, power = power_spectrum(rate, dt)
|
# ax1.set_ylim(0,600)
|
||||||
ax2.plot(freq,power)
|
# ax1.set_xlim(0, 0.04)
|
||||||
ax2.set_xlim(0,1000)
|
# freq, power = power_spectrum(rate, dt)
|
||||||
plt.close()
|
# ax2.plot(freq,power)
|
||||||
if stim == stims[-1]:
|
# ax2.set_xlim(0,1000)
|
||||||
amplitude, df, eodf, stim_freq = extract_stim_data(stim)
|
# plt.close()
|
||||||
print(amplitude, df, eodf, stim_freq)
|
# if stim == stims[-1]:
|
||||||
|
# amplitude, df, eodf, stim_freq = extract_stim_data(stim)
|
||||||
# make an eventplot
|
# print(amplitude, df, eodf, stim_freq)
|
||||||
fig = plt.figure(figsize = (5, 3), layout = 'constrained')
|
|
||||||
ax = fig.add_subplot()
|
# # make an eventplot
|
||||||
ax.eventplot(spikes, linelength = 0.8)
|
# fig = plt.figure(figsize = (5, 3), layout = 'constrained')
|
||||||
ax.set_xlabel('time [ms]')
|
# ax = fig.add_subplot()
|
||||||
ax.set_ylabel('loop no.')
|
# ax.eventplot(spikes, linelength = 0.8)
|
||||||
|
# ax.set_xlabel('time [ms]')
|
||||||
|
# ax.set_ylabel('loop no.')
|
||||||
|
Loading…
Reference in New Issue
Block a user