forked from ScreamingPigeon/ms-analysis-23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vis_helpers.py
92 lines (77 loc) · 2.04 KB
/
vis_helpers.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
import os
import pandas as pd
import matplotlib as mp
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
'''
src - directory for source data
return - list of dataframe objects
'''
def read_data(src):
#to-do
csv_file = []
for path, subdirs, files in os.walk(src):
for name in files: #for every file in this directory
file = os.path.join(path, name)
if 'ACC.csv' in file: #if file name contains acc.csv, read data
acc = pd.read_csv(file)
csv_file.append(acc)
return csv_file
'''
df - dataframe of shape NxM
return - dataframe of shape (N+1)(M-1)
method removes the unix time, and sampling rate rows
Method adds column with timestamps using frequency
method renames columns for x, y and z
'''
def clean_col(df):
frequency = df.iloc[0][1]
df = df.drop([0, 1])
df = df.apply(lambda x: 9.81*(x/64), axis=0) #processes to a magnitutde
df.columns = ['x (N)', 'y (N)', 'z (N)']
df['time(s)'] = np.arange(df.shape[0])/frequency
return df
'''
df - dataframe to be visualized
return - plotly.express line object
Method uses Vega-Altair to render simple interactive plot of df
'''
def simple_vis(df):
fig = px.line(df, x = 'time(s)', y = df.columns[0:3])
return fig
'''
dfs - list of dataframes
return plotly graph object
'''
def many_simple(dfs):
lines= []
for df in dfs:
lines.append(
go.line(df, x = 'time(s)', y = df.columns[0:3])
)
updatemenus = [
{
'buttons': [
{
'method': 'restyle',
'label': 'Val 1',
'args': [
{'y': [values_1, values_1b]},
]
},
{
'method': 'restyle',
'label': 'Val 2',
'args': [
{'y': [values_2, values_2b]},
]
}
],
'direction': 'down',
'showactive': True,
}
]
layout = go.Layout(
updatemenus=updatemenus,
)