happy weekend
This commit is contained in:
parent
18c6550f2a
commit
7f88f5b226
@ -1,4 +1,3 @@
|
||||
import os
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import nixio as nix
|
||||
@ -6,62 +5,87 @@ import glob
|
||||
import os
|
||||
from IPython import embed
|
||||
|
||||
|
||||
def stimulus_collector(filename):
|
||||
try:
|
||||
stims = []
|
||||
f = nix.File.open(filename, nix.FileMode.ReadOnly)
|
||||
b = f.blocks[0]
|
||||
for g in b.groups:
|
||||
# embed()
|
||||
# exit()
|
||||
stims.append(g.multi_tags[0].name)
|
||||
except KeyError:
|
||||
embed()
|
||||
exit()
|
||||
return stims
|
||||
|
||||
|
||||
def analyze_sams(filename):
|
||||
# print(filename)
|
||||
print(filename)
|
||||
f = nix.File.open(filename, nix.FileMode.ReadOnly)
|
||||
b = f.blocks[0]
|
||||
b.metadata.pprint(max_depth=-1) # max_depth=-1: alles rausschreiben
|
||||
# print(b.groups)
|
||||
for g in b.groups:
|
||||
if 'sam' in g.name.lower(): # go through loop, until 'sam' is found
|
||||
break
|
||||
rtag_data = g.tags[0]
|
||||
rtag_data.metadata.pprint(max_depth=-1)
|
||||
# print(40*'*')
|
||||
stim_tag = g.multi_tags[0]
|
||||
stim_pos = stim_tag.positions[:] # beginnings of stimulations
|
||||
stim_extent = stim_tag.extents[:] # duration of stimulations
|
||||
# embed()
|
||||
# exit()
|
||||
for r in rtag_data.references:
|
||||
print(r.name, r.type)
|
||||
# embed()
|
||||
# exit()
|
||||
voltage_trace = rtag_data.references['V-1']
|
||||
|
||||
spike_data = []
|
||||
embed()
|
||||
exit()
|
||||
for stim in stims:
|
||||
print(stim)
|
||||
if stim in g.name.lower():
|
||||
# embed()
|
||||
# exit()
|
||||
# if 'sam' in g.name.lower(): # go through loop, until 'sam' is found
|
||||
# break
|
||||
rtag_data = g.tags[0]
|
||||
# rtag_data.metadata.pprint(max_depth=-1)
|
||||
#
|
||||
# print(40*'*')
|
||||
|
||||
stim_tag = g.multi_tags[0]
|
||||
stim_type = g.multi_tags[0].name
|
||||
stim_pos = stim_tag.positions[:] # beginnings of stimulations
|
||||
stim_extent = stim_tag.extents[:] # duration of stimulations
|
||||
|
||||
# for r in rtag_data.references:
|
||||
# print(r.name, r.type)
|
||||
|
||||
voltage_trace = rtag_data.references['V-1']
|
||||
|
||||
spike_data = []
|
||||
|
||||
for idx in range(len(stim_pos)):
|
||||
spike_data.append(stim_tag.retrieve_data(idx, 'Spikes-1')[:])
|
||||
for idx in range(len(stim_pos)):
|
||||
spike_data.append(stim_tag.retrieve_data(idx, 'Spikes-1')[:])
|
||||
|
||||
# embed()
|
||||
# exit()
|
||||
dims = voltage_trace.dimensions[0].axis(len(voltage_trace))
|
||||
dims = voltage_trace.dimensions[0].axis(len(voltage_trace))
|
||||
plt.plot(dims[:-1], voltage_trace[:-1])
|
||||
for i in range(len(stim_pos)):
|
||||
stim_y = [np.max(voltage_trace)+10, np.max(voltage_trace)+10]
|
||||
plt.plot([stim_pos[i], stim_pos[i] + stim_extent[i]], stim_y, 'k')
|
||||
|
||||
# # f.close()
|
||||
# embed()
|
||||
# exit()
|
||||
return stim_pos, stim_extent, spike_data, voltage_trace, dims
|
||||
for j in range(len(spike_data)):
|
||||
for k in range(len(spike_data[j])):
|
||||
plt.plot(spike_data[j][k], np.max(voltage_trace)+5, 'o', color='k')
|
||||
plt.xlim([stim_pos[0]-1, stim_extent[-1]+1])
|
||||
plt.title(filename + ': ' + stim_type)
|
||||
# plt.show()
|
||||
print('saving...')
|
||||
os.chdir('/home/lisa/Dropbox/Masterarbeit/')
|
||||
plt.savefig(filename[-22:-19] + ': ' + stim + '.png')
|
||||
plt.close()
|
||||
# f.close()
|
||||
# embed()
|
||||
# exit()
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
data_dir = '/home/lisa/data'
|
||||
data_dir = '/home/lisa/data/'
|
||||
os.chdir(data_dir)
|
||||
data_set = glob.glob('2019-*')
|
||||
stim_pos, stim_extent, spike_data, voltage_trace, dims = analyze_sams(os.path.join(data_dir, data_set,
|
||||
data_set + '.nix'))
|
||||
print(len(spike_data))
|
||||
stims = []
|
||||
for i in range(len(stim_pos)):
|
||||
stim_y = [-38, -38]
|
||||
plt.plot([stim_pos[i], stim_pos[i] + stim_extent[i]], stim_y, 'k')
|
||||
plt.plot(dims[:-1], voltage_trace[:-1])
|
||||
spike_y = np.ones(len(spike_data))*80
|
||||
# data_set = glob.glob('2019-*')
|
||||
# for i in range(len(data_set)):
|
||||
data_set = '2019-08-22-aa-invivo-1'
|
||||
# print(data_dir + data_set[i] + '/' + data_set[i])
|
||||
# stims = stimulus_collector(data_dir + data_set[i] + '/' + data_set[i] + '.nix')
|
||||
analyze_sams(data_dir + data_set + '/' + data_set + '.nix')
|
||||
|
||||
for j in range(len(spike_data)):
|
||||
print('length of current spike train: ', len(spike_data))
|
||||
for k in range(len(spike_data[j])):
|
||||
print('current spike time is: ', spike_data[j][k])
|
||||
plt.plot(spike_data[j][k], -40, 'o', color='k')
|
||||
# plt.ylim([-45, 0])
|
||||
plt.show()
|
@ -1,6 +1,6 @@
|
||||
import glob
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# figures for phase_ and amplitude_sweep should be made with artificial data
|
||||
filenames = glob.glob('*.dat')
|
||||
|
||||
for i in range(len(filenames)):
|
||||
|
Loading…
Reference in New Issue
Block a user