Store both timeseries and energy spectrum in json_storage div

master
Dan Howe 5 years ago
parent b62464d152
commit 36cd0a68cc

@ -76,7 +76,40 @@ def parse_contents(contents, filename):
# Round dataframe to save disk space # Round dataframe to save disk space
df = df.round(1) df = df.round(1)
return df.to_json(orient='table') # Create dataframe for statistics
stats = pd.DataFrame(columns=range(15))
# Create datafrae for energy spectrum
f = np.arange(0, 2.5, step=0.01)
dfs = pd.DataFrame(index=f)
for col in df.columns:
t = df.index.values[:, np.newaxis]
x = df[[col]].values
# Get spectral statistics
xx = wo.mat2timeseries(np.hstack([t, x]))
S = xx.tospecdata()
values, _, keys = S.characteristic(range(15))
S.freqtype = 'f'
# Interpolate
dfs[col] = np.interp(f, S.args, S.data)
# Update column names
if stats.columns[0] == 0:
stats.columns = keys
# Add spectral values to dataframe
stats.loc[col, keys] = values
json_data = {}
json_data['timeseries'] = df.to_json(orient='table')
json_data['spectrum'] = dfs.to_json(orient='table')
json_data['statistics'] = stats.to_json(orient='table')
return json.dumps(json_data)
@app.callback(Output('json-storage', 'children'), [ @app.callback(Output('json-storage', 'children'), [
@ -94,7 +127,7 @@ def read_json_data(json_data):
if json_data is None: if json_data is None:
return html.Div([]) return html.Div([])
df = pd.read_json(json_data, orient='table') df = pd.read_json(json.loads(json_data)['timeseries'], orient='table')
ts = [] ts = []
for col in df.columns: for col in df.columns:
trace = go.Scatter(x=df.index, y=df[col], name=col, opacity=0.8) trace = go.Scatter(x=df.index, y=df[col], name=col, opacity=0.8)
@ -107,29 +140,12 @@ def read_json_data(json_data):
'layout': layout 'layout': layout
}) })
# Create spectral dataframe dfs = pd.read_json(json.loads(json_data)['spectrum'],
dfs = pd.DataFrame(columns=range(15)) orient='table')
spec = [] spec = []
for col in df.columns: for col in dfs.columns:
t = df.index.values[:, np.newaxis]
x = df[[col]].values
# Get spectral statistics
xx = wo.mat2timeseries(np.hstack([t, x]))
S = xx.tospecdata()
values, _, keys = S.characteristic(range(15))
S.freqtype = 'f'
# 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=dfs.index, y=dfs[col], name=col, opacity=0.8)
spec.append(trace) spec.append(trace)
graph_energy = dcc.Graph(id='energy-spectrum', graph_energy = dcc.Graph(id='energy-spectrum',
@ -145,6 +161,9 @@ def read_json_data(json_data):
# Add location column # Add location column
dfs['location'] = dfs.index dfs['location'] = dfs.index
# Round spectral values
dfs = dfs.round(1)
variables = { variables = {
'location': '', 'location': '',
'Hm0': '', 'Hm0': '',

Loading…
Cancel
Save