simen
commited on
Commit
·
f59ae9e
1
Parent(s):
a0e4229
make clickable and update thermal position
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ import os
|
|
13 |
from utils import latlon_to_xy
|
14 |
import plotly.graph_objects as go
|
15 |
from matplotlib.colors import to_hex, LinearSegmentedColormap
|
16 |
-
from
|
17 |
|
18 |
|
19 |
@st.cache_data(ttl=7200)
|
@@ -342,31 +342,6 @@ def build_map(_subset, date=None, hour=None):
|
|
342 |
return fig
|
343 |
|
344 |
|
345 |
-
from plotly.subplots import make_subplots
|
346 |
-
|
347 |
-
import numpy as np
|
348 |
-
import pandas as pd
|
349 |
-
import plotly.graph_objects as go
|
350 |
-
from plotly.subplots import make_subplots
|
351 |
-
import numpy as np
|
352 |
-
import pandas as pd
|
353 |
-
import plotly.graph_objects as go
|
354 |
-
from plotly.subplots import make_subplots
|
355 |
-
|
356 |
-
import pandas as pd
|
357 |
-
import numpy as np
|
358 |
-
import plotly.graph_objects as go
|
359 |
-
from plotly.subplots import make_subplots
|
360 |
-
from plotly.subplots import make_subplots
|
361 |
-
import numpy as np
|
362 |
-
import pandas as pd
|
363 |
-
import plotly.graph_objects as go
|
364 |
-
from plotly.subplots import make_subplots
|
365 |
-
import numpy as np
|
366 |
-
import pandas as pd
|
367 |
-
import plotly.graph_objects as go
|
368 |
-
|
369 |
-
|
370 |
def interpolate_color(
|
371 |
wind_speed, thresholds=[2, 8, 14], colors=["white", "green", "red", "black"]
|
372 |
):
|
@@ -552,7 +527,7 @@ def create_daily_thermal_and_wind_airgram(subset, x_target, y_target, date):
|
|
552 |
fig.update_layout(
|
553 |
height=800,
|
554 |
width=950,
|
555 |
-
title=f"
|
556 |
xaxis=dict(title="Time"),
|
557 |
yaxis=dict(title="Altitude (m)"),
|
558 |
xaxis2=dict(title="Time", tickangle=-45),
|
@@ -637,31 +612,6 @@ def create_daily_airgram(subset, x_target, y_target, date):
|
|
637 |
textfont={"size": 12},
|
638 |
)
|
639 |
)
|
640 |
-
|
641 |
-
# Add wind speed information (if needed)
|
642 |
-
speed = (
|
643 |
-
np.sqrt(location_data["x_wind_ml"] ** 2 + location_data["y_wind_ml"] ** 2)
|
644 |
-
.interp(time=new_timestamps, altitude=altitudes)
|
645 |
-
.T.values
|
646 |
-
)
|
647 |
-
# fig.add_trace(
|
648 |
-
# go.Scatter(
|
649 |
-
# x=times,
|
650 |
-
# y=altitudes,
|
651 |
-
# mode="markers",
|
652 |
-
# marker=dict(
|
653 |
-
# size=8,
|
654 |
-
# color=speed,
|
655 |
-
# colorscale="Viridis",
|
656 |
-
# colorbar=dict(title="Wind Speed (m/s)"),
|
657 |
-
# cmin=0,
|
658 |
-
# cmax=20, # Adjusted for expected data range
|
659 |
-
# ),
|
660 |
-
# hoverinfo="text",
|
661 |
-
# text=[f"Speed: {s:.2f} m/s" for s in speed.flatten()],
|
662 |
-
# )
|
663 |
-
# )
|
664 |
-
|
665 |
# Update layout
|
666 |
fig.update_layout(
|
667 |
title=f"Thermal Profiles for {start_date.strftime('%Y-%m-%d')}",
|
@@ -669,7 +619,6 @@ def create_daily_airgram(subset, x_target, y_target, date):
|
|
669 |
yaxis=dict(title="Altitude (m)"),
|
670 |
xaxis_tickangle=-45,
|
671 |
)
|
672 |
-
|
673 |
return fig
|
674 |
|
675 |
|
@@ -692,8 +641,19 @@ def show_forecast():
|
|
692 |
date=st.session_state.forecast_date,
|
693 |
hour=st.session_state.forecast_time,
|
694 |
)
|
695 |
-
st.plotly_chart(
|
696 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
697 |
x_target, y_target = latlon_to_xy(
|
698 |
st.session_state.target_latitude, st.session_state.target_longitude
|
699 |
)
|
|
|
13 |
from utils import latlon_to_xy
|
14 |
import plotly.graph_objects as go
|
15 |
from matplotlib.colors import to_hex, LinearSegmentedColormap
|
16 |
+
from plotly.subplots import make_subplots
|
17 |
|
18 |
|
19 |
@st.cache_data(ttl=7200)
|
|
|
342 |
return fig
|
343 |
|
344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
def interpolate_color(
|
346 |
wind_speed, thresholds=[2, 8, 14], colors=["white", "green", "red", "black"]
|
347 |
):
|
|
|
527 |
fig.update_layout(
|
528 |
height=800,
|
529 |
width=950,
|
530 |
+
title=f"Airgram for {start_date.strftime('%Y-%m-%d')}, lat/lon: {st.session_state.target_latitude:.2f}, {st.session_state.target_longitude:.2f}",
|
531 |
xaxis=dict(title="Time"),
|
532 |
yaxis=dict(title="Altitude (m)"),
|
533 |
xaxis2=dict(title="Time", tickangle=-45),
|
|
|
612 |
textfont={"size": 12},
|
613 |
)
|
614 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
615 |
# Update layout
|
616 |
fig.update_layout(
|
617 |
title=f"Thermal Profiles for {start_date.strftime('%Y-%m-%d')}",
|
|
|
619 |
yaxis=dict(title="Altitude (m)"),
|
620 |
xaxis_tickangle=-45,
|
621 |
)
|
|
|
622 |
return fig
|
623 |
|
624 |
|
|
|
641 |
date=st.session_state.forecast_date,
|
642 |
hour=st.session_state.forecast_time,
|
643 |
)
|
644 |
+
map_selection = st.plotly_chart(
|
645 |
+
map_fig,
|
646 |
+
use_container_width=True,
|
647 |
+
config={"scrollZoom": True, "displayModeBar": False},
|
648 |
+
on_select="rerun",
|
649 |
+
)
|
650 |
+
# Update lat lon if selection is made
|
651 |
+
selected_points = map_selection.get("selection").get("points")
|
652 |
+
if len(selected_points) > 0:
|
653 |
+
point = selected_points[0]
|
654 |
+
st.session_state.target_latitude = point["lat"]
|
655 |
+
st.session_state.target_longitude = point["lon"]
|
656 |
+
print("Updated lat lon")
|
657 |
x_target, y_target = latlon_to_xy(
|
658 |
st.session_state.target_latitude, st.session_state.target_longitude
|
659 |
)
|