Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add glitch_plot_3d() for 3D plots (Issue: #475) #476

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 91 additions & 9 deletions software/chipwhisperer/common/results/glitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,14 @@ def add(self, group, parameters=None, strdesc=None, metadata=None, plot=True):
self.results.add(group, parameters, strdesc, metadata)

i = self.get_group_index(group)
#Basic count
# Basic count
self.group_counts[i] += 1
if not self.widget_list_groups is None:
self.widget_list_groups[i].value = self.group_counts[i]
if self.widget_list_groups is not None:
self.widget_list_groups[i].value = self.group_counts[i]

if plot and self._buffers:
self.update_plot(parameters[self._x_index], parameters[self._y_index], group)
z = parameters[self._z_index] if self.plot_type == "3d" else 0
self.update_plot(parameters[self._x_index], parameters[self._y_index], z, group)

def glitch_plot(self, plotdots, x_index=0, y_index=1, x_bound=None, y_bound=None, bufferlen=100000):
"""Create a plot that can be updated in real-time with gc.add()
Expand Down Expand Up @@ -214,6 +215,7 @@ def glitch_plot(self, plotdots, x_index=0, y_index=1, x_bound=None, y_bound=None
self._dmaps = {}
self._x_index = x_index
self._y_index = y_index
self.plot_type = "2d"

x_label = self.parameters[x_index]
y_label = self.parameters[y_index]
Expand All @@ -222,7 +224,7 @@ def glitch_plot(self, plotdots, x_index=0, y_index=1, x_bound=None, y_bound=None
if plotdots[k] is None:
continue
self._buffers[k] = Buffer(DataFrame({'x': [], 'y': []}, columns=['x', 'y']), length=bufferlen, index=False)
self._dmaps[k] = hv.DynamicMap(hv.Points, streams=[self._buffers[k]]).opts(height=600, width=800,
self._dmaps[k] = hv.DynamicMap(hv.Points, streams=[self._buffers[k]]).opts(height=600, width=800,
framewise=True, size=10, marker=plotdots[k][0], color=plotdots[k][1], tools=['hover'])


Expand All @@ -242,14 +244,94 @@ def glitch_plot(self, plotdots, x_index=0, y_index=1, x_bound=None, y_bound=None
else:
y_bound = {"range": y_bound}
return plot.redim(x=hv.Dimension(x_label, **x_bound), y=hv.Dimension(y_label, **y_bound))

def update_plot(self, x, y, label):

def glitch_plot_3d(self, plotdots, x_index=0, y_index=1, z_index=2, x_bound=None, y_bound=None, z_bound=None,
bufferlen=100000):
import holoviews as hv
from holoviews import opts
from holoviews.streams import Buffer
from pandas import DataFrame
hv.extension('plotly', logo=False) # don't display logo, otherwise it pops up everytime this func is called.

if type(x_index) is str:
x_index = self.parameters.index(x_index)
if type(y_index) is str:
y_index = self.parameters.index(y_index)
if type(z_index) is str:
z_index = self.parameters.index(z_index)

self._glitch_plotdots = plotdots
self._buffers = {}
self._dmaps = {}
self._x_index = x_index
self._y_index = y_index
self._z_index = z_index
self.plot_type = "3d"

x_label = self.parameters[x_index]
y_label = self.parameters[y_index]
z_label = self.parameters[z_index]

marker_map = {
'+': 'cross',
'^': 'diamond',
'x': 'x'
}
color_map = {
'r': 'red',
'g': 'green',
'b': 'blue',
'y': 'yellow',
'k': 'black',
}

for k, v in plotdots.items():
if v is None:
continue

self._buffers[k] = Buffer(DataFrame({'x': [], 'y': [], 'z': []}, columns=['x', 'y', 'z']), length=bufferlen,
index=False)

dy_scatter = (hv.DynamicMap(hv.Scatter3D, streams=[self._buffers[k]]))
dy_scatter.opts(opts.Scatter3D(height=800, width=800, size=5, alpha=0.5, marker=marker_map[v[0]],
color=color_map[v[1]]))
self._dmaps[k] = dy_scatter

plot_iter = iter(self._dmaps)
plot = self._dmaps[next(plot_iter)]

for tmp in plot_iter:
plot *= self._dmaps[tmp]

if not x_bound:
x_bound = {}
else:
x_bound = {"range": x_bound}

if not y_bound:
y_bound = {}
else:
y_bound = {"range": y_bound}

if not z_bound:
z_bound = {}
else:
z_bound = {"range": z_bound}

return plot.redim(x=hv.Dimension(x_label + " (x)", **x_bound),
y=hv.Dimension(y_label + " (y)", **y_bound),
z=hv.Dimension(z_label + " (z)", **z_bound))

def update_plot(self, x, y, z, label):
from pandas import DataFrame # type: ignore
if label not in self._buffers:
#raise ValueError("Invalid label {}. Valid labels are {}".format(label, self._buffers.keys()))
return #probably a label not used
self._buffers[label].send(DataFrame([(x, y)], columns=['x', 'y']))

if self.plot_type == "3d":
self._buffers[label].send(DataFrame([(x, y, z)], columns=['x', 'y', 'z']))
else:
self._buffers[label].send(DataFrame([(x, y)], columns=['x', 'y']))

def display_stats(self):
if widgets is None:
raise ModuleNotFoundError("Could not load ipywidgets, display not available")
Expand Down