Skip to content

Commit

Permalink
Merge pull request #6 from otavioon/visualization_tools
Browse files Browse the repository at this point in the history
Added visualization tools
  • Loading branch information
otavioon authored Feb 1, 2023
2 parents a2654ad + ab14c7c commit 3daeae3
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ librep.egg-info/
.*
!.gitignore
!.gitmodules
data
1 change: 0 additions & 1 deletion src/librep/utils/visualization/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .graphs import visualize_sample, visualize_sample_windowed
35 changes: 0 additions & 35 deletions src/librep/utils/visualization/graphs.py

This file was deleted.

140 changes: 140 additions & 0 deletions src/librep/utils/visualization/multimodal_har.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import numpy as np
import plotly.graph_objs as go
from typing import List
from librep.datasets.multimodal.multimodal import MultiModalDataset


def plot_windows_sample(
dataset: MultiModalDataset,
windows: List[str] = None,
sample_idx: int = 0,
the_slice: slice = slice(None, None, None),
title: str = "",
mode: str = "lines",
showlegend: bool = True,
xaxis: str = "x",
yaxis: str = "y",
return_traces_layout: bool = False
):
if windows is None:
windows = dataset.window_names

traces = [
go.Scatter(y=dataset.windows(window)[sample_idx][0][the_slice], name=window, mode=mode)
for window in windows
]
layout = go.Layout(
title=title,
showlegend=showlegend,
xaxis=dict(title=xaxis),
yaxis=dict(title=yaxis),
)

if return_traces_layout:
return traces, layout
else:
return go.Figure(data=traces, layout=layout)


def plot_twin_windows_sample(
dataset: MultiModalDataset,
sample_idx: int = 0,
y1_windows: List[str] = ("accel-x", "accel-y", "accel-z"),
y2_windows: List[str] = ("gyro-x", "gyro-y", "gyro-z"),
title: str = "",
mode: str = "lines",
showlegend: bool = True,
xaxis: str = "x",
y1_axis: str = "y1",
y2_axis: str = "y2",
the_slice: slice = slice(None, None, None),
return_traces_layout: bool = False
):
start = 0
traces = []
for window in y1_windows:
window_val = dataset.windows(window)[sample_idx][0][the_slice]
traces.append(
go.Scatter(
x=np.arange(start, start + window_val.shape[0]),
y=window_val,
name=window,
mode=mode,
yaxis="y1"
)
)
start += window_val.shape[0]

start = 0
for window in y2_windows:
window_val = dataset.windows(window)[sample_idx][0][the_slice]
traces.append(
go.Scatter(
x=np.arange(start, start + window_val.shape[0]),
y=window_val,
name=window,
mode=mode,
yaxis="y2"
)
)
start += window_val.shape[0]

layout = go.Layout(
title=title,
showlegend=showlegend,
xaxis=dict(title=xaxis),
yaxis=dict(
title=y1_axis,
side='left',
),
yaxis2=dict(
title=y2_axis,
side='right',
overlaying='y'
)
)

if return_traces_layout:
return traces, layout
else:
return go.Figure(data=traces, layout=layout)

def plot_windows_single_line(
dataset: MultiModalDataset,
windows: List[str],
sample_idx: int = 0,
the_slice: slice = slice(None, None, None),
title: str = "",
mode: str = "lines",
showlegend: bool = True,
xaxis: str = "x",
yaxis: str = "y",
return_traces_layout: bool = False
):
if windows is None:
windows = dataset.window_names
traces = []
start = 0
for window in windows:
window_val = dataset.windows(window)[sample_idx][0][the_slice]
traces.append(
go.Scatter(
x=np.arange(start, start + window_val.shape[0]),
y=window_val,
name=window,
mode=mode,
)
)
start += window_val.shape[0]

layout = go.Layout(
title=title,
showlegend=showlegend,
xaxis=dict(title=xaxis),
yaxis=dict(title=yaxis),
)

if return_traces_layout:
return traces, layout
else:
return go.Figure(data=traces, layout=layout)
Loading

0 comments on commit 3daeae3

Please sign in to comment.