-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualization_functions.py
121 lines (102 loc) · 3.29 KB
/
visualization_functions.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
117
118
119
120
####################################################
# Visualization functions
###############################################
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def visualize_distr(V):
"""
Shows the distribuition of voltages
"""
Vdist = V.reshape(len(V)*len(V))
plt.plot(Vdist,'*')
plt.show()
def visualize_network_V(voltage):
"""
Shows a color map of the neuron voltages
"""
plt.imshow(voltage)
cbar = plt.colorbar()
cbar.ax.set_ylabel('Voltage (mV)')
plt.xlabel('Neuron\'s x coordinate')
plt.ylabel('Neuron\'s y coordinate')
plt.title('Voltage')
#plt.clim(-50,10)
plt.show()
def visualize_network_rate(rate):
"""
Shows a color map of the neuron rates
"""
ims = plt.imshow(rate)
cbar = plt.colorbar()
cbar.ax.set_ylabel('Firing Rate (Hz)')
plt.xlabel('Neuron\'s x coordinate')
plt.ylabel('Neuron\'s y coordinate')
plt.title('Firing rate in a 20 ms window')
plt.clim(0,70)
plt.show()
def visualize_network_both(voltage, rate):
"""
Combines visualize_network_rate and visualize_network_v
As subplots
"""
plt.subplot(1,2,1)
plt.imshow(rate)
cbar = plt.colorbar()
cbar.ax.set_ylabel('Firing Rate (Hz)')
plt.xlabel('Neuron\'s x coordinate')
plt.ylabel('Neuron\'s y coordinate')
plt.title('Firing rate in a 20 ms window')
plt.clim(0,70)
plt.subplot(1,2,2)
plt.imshow(voltage)
cbar = plt.colorbar()
cbar.ax.set_ylabel('Voltage (mV)')
plt.xlabel('Neuron\'s x coordinate')
plt.ylabel('Neuron\'s y coordinate')
plt.title('Voltage')
#plt.clim(-50,10)
plt.show()
def create_animation_voltage(voltage, frames=100, interval=1, fps=10, dpi=90, filename='default', format ='.mp4'):
"""
Documentation needed
"""
filename = filename + '-voltage_animation' + format
#Initiate figure
fig = plt.figure()
ims = plt.imshow(voltage[:,:,0])
plt.xlabel('Neuron\'s x coordinate')
plt.ylabel('Neuron\'s y coordinate')
cbar = plt.colorbar()
cbar.ax.set_ylabel('Voltage (mV)')
plt.clim(-50,0)
# Define how to update frames
def updatefig(i):
ims.set_array( voltage[:,:,i] )
return ims,
# run and save the animation
image_animation = animation.FuncAnimation(fig,updatefig, frames=frames, interval=interval, blit = True)
image_animation.save(filename, fps=fps, dpi=dpi)
plt.show()
def create_animation_rate(rate, frames=100, interval=1, fps=10, dpi=90, filename='default.mp4', format='.mp4'):
"""
Documentation needed
"""
filename = filename + '-rate_animation' + format
# Initiate figure
fig = plt.figure()
ims = plt.imshow(rate[::,::,1])
plt.xlabel('Neuron\'s x coordinate')
plt.ylabel('Neuron\'s y coordinate')
plt.title('Firing rate in a 20 ms window')
cbar = plt.colorbar()
cbar.ax.set_ylabel('Firing Rate (Hz)')
plt.clim(0,70)
# Define how to update frames
def updatefig(i):
ims.set_array( rate[:,:,i] )
return ims,
# run and save the animation
image_animation = animation.FuncAnimation(fig,updatefig, frames=frames, interval=interval, blit = True)
image_animation.save(filename, fps=fps, dpi=dpi)
plt.show()