-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation_and_plot_CA3_oscilatory.py
85 lines (71 loc) · 3.48 KB
/
simulation_and_plot_CA3_oscilatory.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
import random
import utils
import CA3_oscilatory
def custom_plots(fullPathFile, plot, save, saveName, savePath):
"""
Processing the data from a simulation to get a visual representation of the result
:param fullPathFile: the full path to the file with the data recorded from the simulation
:param plot: if show the plot in running time
:param save: if store the plots
:param saveName: the base name used to store the generated files
:param savePath: the base path used to store the generated files
:return: True if the simulation and/or the creation of the visual representation of the data has been done correctly
or False in other cases
"""
# Open data file of the simulation
data = utils.read_file(fullPathFile)
if not data:
print("Error to open data file")
return False
# Create folder to store all the generated files
savePath = utils.check_folder(savePath + saveName + "/")
if not savePath:
print("Error to create a folder to store generated files")
return False
# Search all variables which are going to be used to create the plots and representations
vPC, spikesPC, spikesDG, wPC_PC, vINH, spikesINH = {}, {}, {}, {}, {}, {}
for variable in data["variables"]:
if variable["type"] == "spikes" and variable["popNameShort"] == "PCL":
spikesPC = variable
elif variable["type"] == "spikes" and variable["popNameShort"] == "DGL":
spikesDG = variable
# Create the stream of time stamp and color to use in representations
colors = ["red", "green", "blue", "orange", "pink", "goldenrod"]
timeStream = utils.generate_time_streams(data["simTime"], data["timeStep"], False)
# Create a spike plot of all activations of DG and PC (CA3) neurons
utils.plot_spike_pc_dg(spikesPC["data"], spikesDG["data"], timeStream, colors, 0.01, "Spikes DG-CA3", True, plot,
save, saveName+ "_spikes_DG_CA3", savePath)
return True
def main(plot, save, savePath, execute, fullPathFile, saveName):
"""
Execute the simulation of the network and/or create a visual representation of the data recorded
:param plot: if show the plot in running time
:param save: if store the plots
:param savePath: the base path used to store the generated files
:param execute: if execute or not the simulation, in case of false, a fullPathFile is needed
:param fullPathFile: the full path to the file with the data recorded from the simulation
:param saveName: the base name used to store the generated files
:return:
"""
# Execute the model if applicable
if execute:
fullPathFile, filename = CA3_oscilatory.main()
saveName = filename
# Processing the data and plot it
custom_plots(fullPathFile, plot, save, saveName, savePath)
if __name__ == "__main__":
# Plot and execution parameters
# + If show the plot in running time
plot = False
# + If store the plots
save = True
# + Base path where store the plot
savePath = "plot/"
# + If execute the network or take already generated data
execute = True
# + If not execute, the full path to the file with the data recorded from the simulation and the base name used to store
# the generated files (txt, png, ...)
fullPathFile = "data/CA3_simple_2021_11_18__12_42_34.txt"
saveName = "CA3_simple_2021_11_18__12_42_34"
# Simulation and/or representation
main(plot, save, savePath, execute, fullPathFile, saveName)