-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on HBR graph updation on sound change PART-1
- Loading branch information
1 parent
418719a
commit 67082a5
Showing
8 changed files
with
77 additions
and
86 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,49 @@ | ||
import datetime | ||
|
||
import dash | ||
from dash import Dash, dcc, html, Input, Output, callback | ||
import plotly | ||
|
||
# pip install pyorbital | ||
from pyorbital.orbital import Orbital | ||
satellite = Orbital('TERRA') | ||
|
||
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] | ||
|
||
app = Dash(__name__, external_stylesheets=external_stylesheets) | ||
app.layout = html.Div( | ||
html.Div([ | ||
html.H4('TERRA Satellite Live Feed'), | ||
html.Div(id='live-update-text'), | ||
dcc.Graph(id='live-update-graph'), | ||
dcc.Interval( | ||
id='interval-component', | ||
interval=1*1000, # in milliseconds | ||
n_intervals=0 | ||
) | ||
]) | ||
from dash import dcc, html | ||
from dash.dependencies import Input, Output | ||
import plotly.express as px | ||
import pandas as pd | ||
import numpy as np | ||
|
||
# Dummy data generation function | ||
def generate_dummy_data(num_points=100): | ||
np.random.seed(42) | ||
x = np.linspace(0, 1, num_points) | ||
y = np.random.rand(num_points) | ||
df = pd.DataFrame({'X': x, 'Y': y}) | ||
return df | ||
|
||
# Initial dummy data | ||
initial_data = generate_dummy_data() | ||
|
||
# Initialize the Dash app | ||
app = dash.Dash(__name__) | ||
|
||
# App layout | ||
app.layout = html.Div([ | ||
html.H1("Dummy Data Plot"), | ||
|
||
# Graph component for plotting | ||
dcc.Graph(id='scatter-plot'), | ||
|
||
# Button to refresh the plot | ||
html.Button('Refresh Plot', id='refresh-button', n_clicks=0) | ||
]) | ||
|
||
# Callback to update the plot on button click | ||
@app.callback( | ||
Output('scatter-plot', 'figure'), | ||
[Input('refresh-button', 'n_clicks')] | ||
) | ||
|
||
|
||
@callback(Output('live-update-text', 'children'), | ||
Input('interval-component', 'n_intervals')) | ||
def update_metrics(n): | ||
lon, lat, alt = satellite.get_lonlatalt(datetime.datetime.now()) | ||
style = {'padding': '5px', 'fontSize': '16px'} | ||
return [ | ||
html.Span('Longitude: {0:.2f}'.format(lon), style=style), | ||
html.Span('Latitude: {0:.2f}'.format(lat), style=style), | ||
html.Span('Altitude: {0:0.2f}'.format(alt), style=style) | ||
] | ||
|
||
|
||
# Multiple components can update everytime interval gets fired. | ||
@callback(Output('live-update-graph', 'figure'), | ||
Input('interval-component', 'n_intervals')) | ||
def update_graph_live(n): | ||
satellite = Orbital('TERRA') | ||
data = { | ||
'time': [], | ||
'Latitude': [], | ||
'Longitude': [], | ||
'Altitude': [] | ||
} | ||
|
||
# Collect some data | ||
for i in range(180): | ||
time = datetime.datetime.now() - datetime.timedelta(seconds=i*20) | ||
lon, lat, alt = satellite.get_lonlatalt( | ||
time | ||
) | ||
data['Longitude'].append(lon) | ||
data['Latitude'].append(lat) | ||
data['Altitude'].append(alt) | ||
data['time'].append(time) | ||
|
||
# Create the graph with subplots | ||
fig = plotly.tools.make_subplots(rows=2, cols=1, vertical_spacing=0.2) | ||
fig['layout']['margin'] = { | ||
'l': 30, 'r': 10, 'b': 30, 't': 10 | ||
} | ||
fig['layout']['legend'] = {'x': 0, 'y': 1, 'xanchor': 'left'} | ||
|
||
fig.append_trace({ | ||
'x': data['time'], | ||
'y': data['Altitude'], | ||
'name': 'Altitude', | ||
'mode': 'lines+markers', | ||
'type': 'scatter' | ||
}, 1, 1) | ||
fig.append_trace({ | ||
'x': data['Longitude'], | ||
'y': data['Latitude'], | ||
'text': data['time'], | ||
'name': 'Longitude vs Latitude', | ||
'mode': 'lines+markers', | ||
'type': 'scatter' | ||
}, 2, 1) | ||
|
||
def update_plot(n_clicks): | ||
# Generate new dummy data on button click | ||
dummy_data = generate_dummy_data() | ||
|
||
# Create a scatter plot using Plotly Express | ||
fig = px.scatter(dummy_data, x='X', y='Y', title='Dummy Data Plot') | ||
|
||
return fig | ||
|
||
|
||
# Run the app | ||
if __name__ == '__main__': | ||
app.run(debug=True) | ||
app.run_server(debug=True) |