changed for multiple repros
This commit is contained in:
parent
3bcc6b72ad
commit
ccd7623421
@ -10,7 +10,7 @@ import matplotlib.pyplot as plt
|
|||||||
from IPython import embed
|
from IPython import embed
|
||||||
import sys
|
import sys
|
||||||
from icr_analysis import *
|
from icr_analysis import *
|
||||||
from open_nixio import *
|
from open_nixio_new import *
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
sampling_rate = 20000
|
sampling_rate = 20000
|
||||||
@ -19,7 +19,7 @@ delay = 1.5 # delay in seconds after comb reaches one end, before commencing mo
|
|||||||
cell_name = sys.argv[1].split('/')[-2]
|
cell_name = sys.argv[1].split('/')[-2]
|
||||||
|
|
||||||
# Open Nixio File
|
# Open Nixio File
|
||||||
curr_comb, intervals_dict = open_nixio(sys.argv[1], sys.argv[2])
|
curr_comb, intervals_dict = open_nixio_new(sys.argv[1], sys.argv[2])
|
||||||
|
|
||||||
# Kernel Density estimator: gaussian fit
|
# Kernel Density estimator: gaussian fit
|
||||||
t = np.arange(-sigma*4, sigma*4, 1/sampling_rate)
|
t = np.arange(-sigma*4, sigma*4, 1/sampling_rate)
|
||||||
@ -53,7 +53,7 @@ if sys.argv[2] == 'average':
|
|||||||
plt.close(fig)
|
plt.close(fig)
|
||||||
|
|
||||||
elif sys.argv[2] == 'nonaverage':
|
elif sys.argv[2] == 'nonaverage':
|
||||||
for (speed, direct, pos, comb) in intervals_dict:
|
for (repro, speed, direct, pos, comb) in intervals_dict:
|
||||||
spike_train = intervals_dict[speed, direct, pos, comb]
|
spike_train = intervals_dict[speed, direct, pos, comb]
|
||||||
avg_convolve_spikes = gaussian_convolve(spike_train, fxn, sampling_rate)
|
avg_convolve_spikes = gaussian_convolve(spike_train, fxn, sampling_rate)
|
||||||
p, freq, std_four, mn_four = fourier_psd(avg_convolve_spikes, sampling_rate)
|
p, freq, std_four, mn_four = fourier_psd(avg_convolve_spikes, sampling_rate)
|
||||||
@ -73,7 +73,7 @@ elif sys.argv[2] == 'nonaverage':
|
|||||||
ax2.axhline(y=(mn_four+std_four), xmin=0, xmax=1, linestyle='--', color='red')
|
ax2.axhline(y=(mn_four+std_four), xmin=0, xmax=1, linestyle='--', color='red')
|
||||||
# ax2.axvline(x=max_four,linestyle='--', color='green')
|
# ax2.axvline(x=max_four,linestyle='--', color='green')
|
||||||
|
|
||||||
plt.savefig(('nonavg_' + '_' + str(cell_name) + '_' + str(speed) + '_' + str(pos)
|
plt.savefig(('nonavg_' + str(repro) +'_' + str(cell_name) + '_' + str(speed) + '_' + str(pos)
|
||||||
+ '_' + str(comb) + '_' + str(direct) + '.png'))
|
+ '_' + str(comb) + '_' + str(direct) + '.png'))
|
||||||
plt.close(fig)
|
plt.close(fig)
|
||||||
|
|
||||||
|
53
analysis_graphs_new.py
Normal file
53
analysis_graphs_new.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
# Name: Firing Rate and Fourier Script (moving comb repro)
|
||||||
|
# Purpose: Takes nixio spike data from moving comb repro and plots firing rate and power spectrum density graph
|
||||||
|
# Usage: python3 analysis_graphs.py average
|
||||||
|
# Author: Carolin Sachgau, University of Tuebingen
|
||||||
|
# Created: 20/09/2018
|
||||||
|
# ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from IPython import embed
|
||||||
|
import sys
|
||||||
|
from icr_analysis import *
|
||||||
|
from open_nixio_new import *
|
||||||
|
|
||||||
|
# Parameters
|
||||||
|
sampling_rate = 20000
|
||||||
|
sigma = 0.01 # for Gaussian
|
||||||
|
delay = 1.5 # delay in seconds after comb reaches one end, before commencing movement again
|
||||||
|
cell_name = sys.argv[1].split('/')[-2]
|
||||||
|
|
||||||
|
# Open Nixio File
|
||||||
|
intervals_dict = open_nixio_new(sys.argv[1])
|
||||||
|
|
||||||
|
# Kernel Density estimator: gaussian fit
|
||||||
|
t = np.arange(-sigma*4, sigma*4, 1/sampling_rate)
|
||||||
|
fxn = np.exp(-0.5*(t/sigma)**2) / np.sqrt(2*np.pi) / sigma # gaussian function
|
||||||
|
|
||||||
|
|
||||||
|
for (repro, speed, direct, pos, comb) in intervals_dict:
|
||||||
|
spike_train = intervals_dict[speed, direct, pos, comb]
|
||||||
|
avg_convolve_spikes = gaussian_convolve(spike_train, fxn, sampling_rate)
|
||||||
|
p, freq, std_four, mn_four = fourier_psd(avg_convolve_spikes, sampling_rate)
|
||||||
|
|
||||||
|
# Graphing
|
||||||
|
fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1)
|
||||||
|
|
||||||
|
# Firing Rate Graph
|
||||||
|
firing_times = np.arange(0, len(avg_convolve_spikes))
|
||||||
|
ax1.plot((firing_times / sampling_rate), avg_convolve_spikes)
|
||||||
|
ax1.set_title('Firing Rate of trial ' + str((speed, pos)) + ' comb = ' + str(comb) + '\n')
|
||||||
|
ax1.set_xlabel('Time (s)')
|
||||||
|
ax1.set_ylabel('Firing rate (Hz)')
|
||||||
|
|
||||||
|
# Fourier Graph
|
||||||
|
ax2.semilogy(freq[freq < 200], p[freq < 200])
|
||||||
|
ax2.axhline(y=(mn_four+std_four), xmin=0, xmax=1, linestyle='--', color='red')
|
||||||
|
# ax2.axvline(x=max_four,linestyle='--', color='green')
|
||||||
|
|
||||||
|
plt.savefig(('nonavg_' + str(repro) +'_' + str(cell_name) + '_' + str(speed) + '_' + str(pos)
|
||||||
|
+ '_' + str(comb) + '_' + str(direct) + '.png'))
|
||||||
|
plt.close(fig)
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------------------------------------------------
|
@ -39,6 +39,5 @@ def open_nixio(nix_file, avg_opt):
|
|||||||
|
|
||||||
# Spike data at baseline
|
# Spike data at baseline
|
||||||
# comb_baseline = spikes[(spikes < comb_pos[0])]
|
# comb_baseline = spikes[(spikes < comb_pos[0])]
|
||||||
embed()
|
|
||||||
quit()
|
|
||||||
return curr_comb, intervals_dict
|
return curr_comb, intervals_dict
|
||||||
|
@ -3,24 +3,24 @@ from IPython import embed
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
nix_file = '/home/sachgau/Documents/combproject/comb_data/2018-11-16-ag/2018-11-16-ag.nix'
|
|
||||||
|
|
||||||
|
def open_nixio_new(nix_file):
|
||||||
|
|
||||||
f = nix.File.open(nix_file, nix.FileMode.ReadOnly)
|
f = nix.File.open(nix_file, nix.FileMode.ReadOnly)
|
||||||
b = f.blocks[0] # first block
|
b = f.blocks[0] # first block
|
||||||
mt = b.multi_tags['moving object-1']
|
mt = b.multi_tags['moving object-1']
|
||||||
comb_pos = mt.positions[:]
|
comb_pos = mt.positions[:]
|
||||||
comb_ext = np.array(mt.extents[:])
|
comb_ext = np.array(mt.extents[:])
|
||||||
spikes = b.data_arrays["Spikes-1"][:]
|
spikes = b.data_arrays["Spikes-1"][:]
|
||||||
|
|
||||||
feature_dict = {}
|
feature_dict = {}
|
||||||
for feat in mt.features:
|
for feat in mt.features:
|
||||||
feature_dict.update({feat.data.name[16:]: mt.features[feat.data.name].data[:]})
|
feature_dict.update({feat.data.name[16:]: mt.features[feat.data.name].data[:]})
|
||||||
|
|
||||||
tags = b.tags
|
tags = b.tags
|
||||||
intervals_dict = defaultdict(list)
|
intervals_dict = defaultdict(list)
|
||||||
|
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
if tag.name.startswith('Baseline'):
|
if tag.name.startswith('Baseline'):
|
||||||
continue
|
continue
|
||||||
curr_comb = tag.metadata["RePro-Info"]["settings"]["object"]
|
curr_comb = tag.metadata["RePro-Info"]["settings"]["object"]
|
||||||
@ -38,5 +38,5 @@ for tag in tags:
|
|||||||
curr_dir = feature_dict['direction'][idx]
|
curr_dir = feature_dict['direction'][idx]
|
||||||
curr_spikes = spikes[(spikes < comb_pos[idx + 1]) & (spikes > comb_pos[idx])]
|
curr_spikes = spikes[(spikes < comb_pos[idx + 1]) & (spikes > comb_pos[idx])]
|
||||||
intervals_dict.update({(tag.name, curr_speed, curr_dir, curr_pos, curr_comb): curr_spikes})
|
intervals_dict.update({(tag.name, curr_speed, curr_dir, curr_pos, curr_comb): curr_spikes})
|
||||||
embed()
|
|
||||||
quit()
|
return intervals_dict
|
Loading…
Reference in New Issue
Block a user