Add table for spectral values

master
Dan Howe 5 years ago
parent ba1a53a9a3
commit 47056f7861

@ -7,6 +7,7 @@ import pandas as pd
import webbrowser as wb import webbrowser as wb
import dash import dash
import dash_table
import dash_core_components as dcc import dash_core_components as dcc
import dash_html_components as html import dash_html_components as html
from dash.dependencies import Input, Output from dash.dependencies import Input, Output
@ -83,22 +84,26 @@ def parse_contents(contents, filename, date):
layout = dict(title=basename, xaxis=dict(rangeslider=dict())) layout = dict(title=basename, xaxis=dict(rangeslider=dict()))
timeseries = dict(data=ts, layout=layout) timeseries = dict(data=ts, layout=layout)
# Specify wave statistics # Create spectral dataframe
var = [ dfs = pd.DataFrame(columns=range(15))
'Hm0', 'Tm01', 'Tm02', 'Tm24', 'Tp', 'Ss', 'Sp', 'Ka', 'Tp1', 'alpha',
'eps2', 'eps4'
]
spec = [] spec = []
for col in df.columns: for col in df.columns:
t = df.index.values[:, np.newaxis] t = df.index.values[:, np.newaxis]
x = df[[col]].values x = df[[col]].values
# Get wave statistics # Get spectral statistics
xx = wo.mat2timeseries(np.hstack([t, x])) xx = wo.mat2timeseries(np.hstack([t, x]))
S = xx.tospecdata() S = xx.tospecdata()
S.freqtype = 'f' 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 # Plot energy spectrum
trace = go.Scatter(x=S.args, y=S.data, name=col, opacity=0.8) 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) 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([ elements = html.Div([
dcc.Graph(id='time-series', figure=timeseries), 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 return elements
@ -131,7 +169,7 @@ def update_output(list_of_contents, list_of_names, list_of_dates):
def main(): def main():
port = 8050 port = 8050
wb.open('http://localhost:{}'.format(port)) wb.open('http://localhost:{}'.format(port))
app.run_server(port=port, debug=True) app.run_server(port=port, debug=False)
if __name__ == '__main__': if __name__ == '__main__':

@ -30,10 +30,6 @@ variables = {
df = df[variables.keys()] 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['id'] = df['location']
df = df.set_index('id', drop=False) df = df.set_index('id', drop=False)

Loading…
Cancel
Save