Skip to content
Snippets Groups Projects
Commit 1e8a2fe8 authored by Hammouda Elbez's avatar Hammouda Elbez :computer:
Browse files

Working on third graph in 2D view

parent f6beb5db
Branches
No related tags found
1 merge request!26Custom 2d view
......@@ -27,6 +27,7 @@ class Global_Var():
updateInterval = 1.0 # 1 second
stepMax = 0
Max = 0
nbrClasses = 0
# General network information ------------------------------------
LayersNeuronsInfo = []
......
......@@ -544,10 +544,10 @@ class callbacks(callbacksOp):
# Callback to handle the 2D view spiking visualization
@app.callback(
Output("cytoscape-compound", "elements"),Output('spikes_info', 'children'),Output({"index": ALL, "type": '2DView-heatmap'},'figure'),
Output("cytoscape-compound", "elements"),Output('spikes_info', 'children'),Output({"index": ALL, "type": '2DView-heatmap'},'figure'),Output({"index": ALL, "type": 'SpikesActivityPerInput'},'figure'),
Input("vis-update", "n_intervals"),Input("v-step", "children"),Input('cytoscape-compound', 'mouseoverNodeData'),
State("interval", "value"),State('cytoscape-compound', 'elements'),State({"index": ALL, "type": '2DView-heatmap'}, "id"),State("2DViewLayerFilter", "value"))
def animation2DView(visUpdateInterval,sliderValue, mouseOverNodeData, updateInterval, elements, selectedItem, Layer2DViewFilter):
State("interval", "value"),State('cytoscape-compound', 'elements'),State("2DViewLayerFilter", "value"))
def animation2DView(visUpdateInterval,sliderValue, mouseOverNodeData, updateInterval, elements, Layer2DViewFilter):
""" Function called each step to update the 2D view
Args:
......@@ -557,7 +557,6 @@ class callbacks(callbacksOp):
mouseOverNodeData : contains data of the hovered node
elements : nodes description
heatmapData : heatmap data
selectedItem (list): selected layer
Layer2DViewFilter : selected layers
Returns:
......@@ -576,8 +575,9 @@ class callbacks(callbacksOp):
spikes = getSpike(int(sliderValue)*float(updateInterval), g.updateInterval,Layer2DViewFilter,True)
for layer in Layer2DViewFilter:
neurons = [[0 for j in range(g.nbrClasses)] for i in range(g.Layer_Neuron[layer])]
if spikes:
maxSpike = max([list(list(s.values())[0].values())[0] for s in spikes])
maxSpike = max([list(list(list(s.values())[0].values())[0].values())[0] for s in spikes if list(s.keys())[0] == layer])
for spike in spikes:
if list(spike.keys())[0] == layer:
# update the spikes neurons
......@@ -593,15 +593,18 @@ class callbacks(callbacksOp):
matrix[layer] = super.toMatrix(super.AccumulatedSpikes2D[layer])
indices[layer] = super.toMatrix([i for i in range(0,len(super.AccumulatedSpikes2D[layer]))])
if len(Layer2DViewFilter) != len(super.AccumulatedSpikes2D):
for layer in super.AccumulatedSpikes2D:
if layer not in matrix:
matrix[layer] = []
indices[layer] = []
heatmaps = [{"data":[go.Heatmap(z = matrix[layer], zsmooth= 'best', colorscale= 'Reds',showscale= False, customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 10, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D]
heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds',showscale= False, customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 10, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D]
return [elements,[],heatmaps]
SpikesActivityPerInput = [{"data":[go.Scatter(data=neurons)]} for layer in super.AccumulatedSpikes2D]
return [elements,[],heatmaps,SpikesActivityPerInput]
else:
try:
......@@ -615,9 +618,10 @@ class callbacks(callbacksOp):
matrix[layer] = []
indices[layer] = []
heatmaps = [{"data":[go.Heatmap(z = matrix[layer], zsmooth= 'best', colorscale= 'Reds',showscale= False, customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 10, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D]
heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds',showscale= False, customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 10, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D]
return [elements,f"Neuron {mouseOverNodeData['label']} : {mouseOverNodeData['spikes']}" if 'spikes' in mouseOverNodeData else "", heatmaps]
SpikesActivityPerInput = [{"data":[]} for layer in super.AccumulatedSpikes2D]
return [elements,f"Neuron {mouseOverNodeData['label']} : {mouseOverNodeData['spikes']}" if 'spikes' in mouseOverNodeData else "", heatmaps,SpikesActivityPerInput]
except Exception:
print("OnHover:"+traceback.format_exc())
return no_update
......@@ -713,13 +717,10 @@ class callbacks(callbacksOp):
for i in labels:
Max = max(Max, i["G"])
L = dict({i["_id"]: 0 for i in labels})
if not labels:
return None
for i in labels:
L[i["_id"]] = L[i["_id"]] + i["C"]
L = dict({i["_id"]: i["C"] for i in labels})
return [L, Max]
......@@ -741,7 +742,7 @@ class callbacks(callbacksOp):
if perNeuron:
spikes = col.aggregate([
{"$match": {"$and": [{"T": {'$gt': timestamp, '$lte': (timestamp+interval)}},{"i.L": {'$in': layer}}]}},
{"$group": {"_id": {"L":"$i.L","N":"$i.N"},"spikes": {"$sum":1}}},{"$sort": {"_id": 1}}
{"$group": {"_id": {"L":"$i.L","N":"$i.N","Input":"$Input"},"spikes": {"$sum":1}}},{"$sort": {"_id": 1}}
])
else:
spikes = col.aggregate([
......@@ -751,10 +752,10 @@ class callbacks(callbacksOp):
# ToJson----------------------
spikes = loads(dumps(spikes))
# ----------------------------
if perNeuron:
spikes = [{s["_id"]["L"]:{s["_id"]["N"]:s["spikes"]}} for s in spikes]
spikes = [{s["_id"]["L"]:{s["_id"]["N"]:{s["_id"]["Input"]:s["spikes"]}}} for s in spikes]
print(spikes)
else:
spikes = {s["_id"]:s for s in spikes}
......
......@@ -273,10 +273,10 @@ class layout(layoutOp):
# 3D destribution
html.Div([
html.Div([html.P("3D Destribution", style={"margin":"0px"})]),
html.Div([html.P("Spikes Activity Per Input", style={"margin":"0px"})]),
dcc.Tabs([dcc.Tab(dbc.Card(dbc.CardBody([
dcc.Graph(id={"type":"30NeuronDestribution","index":i}, config={"displaylogo": False})
])),label=i, value='30Neuron-'+str(x)) for x, i in enumerate(self.g.Layer_Neuron) if i != "Input"],value="30Neuron-1")
dcc.Graph(id={"type":"SpikesActivityPerInput","index":i}, config={"displaylogo": False})
])),label=i, value='SpikesActivityPerInput-'+str(x)) for x, i in enumerate(self.g.Layer_Neuron) if i != "Input"],value="SpikesActivityPerInput-1")
], style={"textAlign": "start", },className="col-lg-3 col-sm-12 col-xs-12")
], className="row")), label="2D view", value="2Dview")], id="tabinfo", value="General information"),
......
......@@ -56,6 +56,8 @@ class spark(sparkOp):
if ('spikes' in self.g.db.list_collection_names()):
M = max(M, pymongo.collection.Collection(
self.g.db, 'spikes').find_one(sort=[("T", -1)])["T"])
self.g.nbrClasses = pymongo.collection.Collection(
self.g.db, 'spikes').find_one(sort=[("Input", -1)])["Input"]
if ('potential' in self.g.db.list_collection_names()):
M = max(M, pymongo.collection.Collection(
self.g.db, 'potential').find_one(sort=[("T", -1)])["T"])
......
......@@ -58,7 +58,6 @@ class callbacks(callbacksOp):
the updated content of 'GraphsAreaSynapse' and 'GlobalHeatMapAreaSynapse'
"""
context = dash.callback_context.triggered
print(context,selectedNeuron)
if "AddComponentSynapse" in context[0]['prop_id']:
if context[0]['value'] == 0:
selectedNeuron = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment