From 47056f7861712a2106f1a11a8079b32d0ebfa9e6 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Tue, 13 Aug 2019 08:15:59 +1000 Subject: [PATCH] Add table for spectral values --- daqviewer/daqviewer.py | 56 +++++++++++++++++++++++++++++++++++------- daqviewer/tables.py | 4 --- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/daqviewer/daqviewer.py b/daqviewer/daqviewer.py index 69316e9..1dab24d 100644 --- a/daqviewer/daqviewer.py +++ b/daqviewer/daqviewer.py @@ -7,6 +7,7 @@ import pandas as pd import webbrowser as wb import dash +import dash_table import dash_core_components as dcc import dash_html_components as html from dash.dependencies import Input, Output @@ -83,22 +84,26 @@ def parse_contents(contents, filename, date): layout = dict(title=basename, xaxis=dict(rangeslider=dict())) timeseries = dict(data=ts, layout=layout) - # Specify wave statistics - var = [ - 'Hm0', 'Tm01', 'Tm02', 'Tm24', 'Tp', 'Ss', 'Sp', 'Ka', 'Tp1', 'alpha', - 'eps2', 'eps4' - ] + # Create spectral dataframe + dfs = pd.DataFrame(columns=range(15)) spec = [] for col in df.columns: t = df.index.values[:, np.newaxis] x = df[[col]].values - # Get wave statistics + # Get spectral statistics xx = wo.mat2timeseries(np.hstack([t, x])) S = xx.tospecdata() S.freqtype = 'f' - values, _, keys = S.characteristic(var) + values, _, keys = S.characteristic(range(15)) + + # Update column names + if dfs.columns[0] == 0: + dfs.columns = keys + + # Add spectral values to dataframe + dfs.loc[col, keys] = values # Plot energy spectrum trace = go.Scatter(x=S.args, y=S.data, name=col, opacity=0.8) @@ -106,9 +111,42 @@ def parse_contents(contents, filename, date): energy = dict(data=spec) + # Add location column + dfs['location'] = dfs.index + + variables = { + 'location': '', + 'Hm0': '◊', + 'Tp': '□', + 'Tp1': 'o', + } + + # Add table + table = dash_table.DataTable( + id='datatable-row-ids', + columns=[{ + 'name': [val, key], + 'id': key + } for key, val in variables.items()], + data=dfs.to_dict('records'), + editable=False, + sort_action='native', + sort_mode='multi', + row_selectable='multi', + row_deletable=False, + selected_rows=np.arange(dfs.shape[0]), + style_as_list_view=True, + style_cell={ + 'minWidth': '100px', + 'width': '100px', + 'maxWidth': '100px', + }, + ) + elements = html.Div([ dcc.Graph(id='time-series', figure=timeseries), - dcc.Graph(id='energy-spectrum', figure=energy) + dcc.Graph(id='energy-spectrum', figure=energy), table, + html.Div(id='datatable-row-ids-container') ]) return elements @@ -131,7 +169,7 @@ def update_output(list_of_contents, list_of_names, list_of_dates): def main(): port = 8050 wb.open('http://localhost:{}'.format(port)) - app.run_server(port=port, debug=True) + app.run_server(port=port, debug=False) if __name__ == '__main__': diff --git a/daqviewer/tables.py b/daqviewer/tables.py index 2898dbc..daaaa7d 100644 --- a/daqviewer/tables.py +++ b/daqviewer/tables.py @@ -30,10 +30,6 @@ variables = { df = df[variables.keys()] -# add an id column and set it as the index -# in this case the unique ID is just the country name, so we could have just -# renamed 'country' to 'id' (but given it the display name 'country'), but -# here it's duplicated just to show the more general pattern. df['id'] = df['location'] df = df.set_index('id', drop=False)