-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathonoffplotter.py
116 lines (97 loc) · 3.38 KB
/
onoffplotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 6 15:27:42 2017
@author: ycan
"""
import os
import numpy as np
import matplotlib.pyplot as plt
main_dir = '/Users/ycan/Documents/official/gottingen/lab rotations/\
LR3 Gollisch/data/Experiments/Salamander/2014_02_25/analyzed/'
exp_name = main_dir.split('/')[-4]+'_'+main_dir.split('/')[-3]
allfiles = os.listdir(main_dir)
files_f = [] # Full field flicker
files_c = [] # Checkerflicker
for i in allfiles:
if i[-4:] == '.npz':
if i[0] == str(2):
files_f.append(i)
elif i[0] == str(3):
files_c.append(i)
onoffindices_f = np.array([])
onoffindices_c = np.array([])
spikenr_f = np.array([])
spikenr_c = np.array([])
filenames_f = []
filenames_c = []
exclude_spike_limit = 200
excluded_f = 0
excluded_c = 0
for i in files_f:
f = np.load(main_dir+i)
spikenr_f = np.append(spikenr_f, f['total_spikes'])
if spikenr_f[-1] < exclude_spike_limit:
spikenr_f = spikenr_f[:-1]
excluded_f += 1
continue
onoffindices_f = np.append(onoffindices_f, f['onoffindex'])
filenames_f.append(str(f['filename']))
for i in files_c:
f = np.load(main_dir+i)
spikenr_c = np.append(spikenr_c, f['total_spikes'])
if spikenr_c[-1] < exclude_spike_limit:
spikenr_c = spikenr_c[:-1]
excluded_c += 1
continue
onoffindices_c = np.append(onoffindices_c, f['onoffindex'])
filenames_c.append(str(f['filename']))
# %% Only get cells that are in both sets
filenamesc_f = []
spikenrc_f = np.array([])
onoffindicesc_f = np.array([])
filenamesc_c = []
spikenrc_c = np.array([])
onoffindicesc_c = np.array([])
for i in range(len(filenames_f)):
if filenames_f[i] in filenames_c:
filenamesc_f.append(filenames_f[i])
spikenrc_f = np.append(spikenrc_f, spikenr_f[i])
onoffindicesc_f = np.append(onoffindicesc_f, onoffindices_f[i])
for i in range(len(filenames_c)):
if filenames_c[i] in filenames_f:
filenamesc_c.append(filenames_c[i])
spikenrc_c = np.append(spikenrc_c, spikenr_c[i])
onoffindicesc_c = np.append(onoffindicesc_c, onoffindices_c[i])
spikenr_f = spikenrc_f
onoffindices_f = onoffindicesc_f
spikenr_c = spikenrc_c
onoffindices_c = onoffindicesc_c
outliers = np.where(np.abs(onoffindices_c - onoffindices_f) > .6)[0]
# %%
plt.figure(figsize=(8, 16), dpi=200)
plt.subplot(2, 1, 2)
plt.hist(onoffindices_f, bins=np.linspace(-1, 1, num=40), alpha=.6)
plt.hist(onoffindices_c, bins=np.linspace(-1, 1, num=40), alpha=.6)
plt.legend(['Full field', 'Checkerflicker'])
plt.title('Histogram of On Off indices \n{}'.format(exp_name))
plt.xlabel('On-off index')
plt.ylabel('Frequency')
plt.subplot(2, 1, 1)
plt.scatter(onoffindices_f, onoffindices_c)
plt.plot(onoffindices_f[outliers], onoffindices_c[outliers], 'r.')
plt.plot(np.linspace(-1, 1), np.linspace(-1, 1), '--')
for i in outliers:
plt.text(onoffindices_f[i], onoffindices_c[i], filenamesc_c[i])
plt.title('On-Off indices obtained from Full field vs Checkerflicker\n{}'
.format(exp_name))
plt.ylabel('Checkerflicker')
plt.xlabel('Full field flicker')
plt.axis('square')
plt.tight_layout()
plt.savefig('/Users/ycan/Documents/official/gottingen/lab rotations/\
LR3 Gollisch/figures/{}'.format(exp_name), dpi=200)
plt.show()
for i in outliers:
print('{:5s} change {:>5.2f} to {:>5.2f}'
.format(filenamesc_c[i], onoffindices_f[i], onoffindices_c[i]))