-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add streamlit app for DWD climate stations
- Loading branch information
Showing
7 changed files
with
693 additions
and
339 deletions.
There are no files selected for viewing
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2018-2023, earthobservations developers. | ||
# Distributed under the MIT License. See LICENSE for more info. | ||
import plotly.express as px | ||
import polars as pl | ||
import streamlit | ||
import streamlit as st | ||
|
||
from wetterdienst.provider.dwd.observation import DwdObservationRequest | ||
|
||
request = DwdObservationRequest("climate_summary", "daily") | ||
|
||
|
||
@streamlit.cache_data | ||
def get_dwd_observation_stations(): | ||
return request.all().df | ||
|
||
|
||
@streamlit.cache_data | ||
def get_dwd_observation_station(station_id): | ||
return request.filter_by_station_id(station_id) | ||
|
||
|
||
@streamlit.cache_data | ||
def get_dwd_observation_station_values(station_id): | ||
return get_dwd_observation_station(station_id).values.all() | ||
|
||
|
||
def main(): | ||
"""Small streamlit app for accessing German climate stations by DWD""" | ||
st.title("Wetterdienst - Data Tool") | ||
|
||
st.subheader("Introduction") | ||
st.markdown( | ||
""" | ||
This is a streamlit app based on the [wetterdienst](https://github.com/earthobservations/wetterdienst) | ||
library that allows analysis of German climate stations (internally phrased "climate summary") by | ||
the [German Weather Service (DWD)](https://www.dwd.de/). There are over 1_500 climate stations in Germany and | ||
all of the data can be accessed freely thanks to the open data initiative. The app enables you to select any | ||
of the stations (by station id or name), download its data (as CSV) and get visualizations of it. | ||
""" | ||
) | ||
st.markdown("Here's a map of all stations:") | ||
st.map(get_dwd_observation_stations(), latitude="latitude", longitude="longitude") | ||
|
||
st.subheader("Select") | ||
station = st.selectbox( | ||
"Select climate station", | ||
options=get_dwd_observation_stations().sort("name").rows(named=True), | ||
format_func=lambda s: f"{s['name']} [{s['station_id']}]", | ||
) | ||
if station: | ||
st.map(get_dwd_observation_station(station["station_id"]).df) | ||
|
||
st.subheader("DataFrame") | ||
df = pl.DataFrame() | ||
if station: | ||
df = get_dwd_observation_station_values(station["station_id"]).df | ||
st.dataframe(df, hide_index=True, use_container_width=True) | ||
st.download_button("Download CSV", df.write_csv(), "data.csv", "text/csv") | ||
|
||
st.subheader("Plot") | ||
parameters = st.multiselect("Select parameters", options=df.get_column("parameter").unique().sort().to_list()) | ||
if parameters: | ||
fig = px.scatter( | ||
df.filter(pl.col("parameter").is_in(parameters)), | ||
x="date", | ||
y="value", | ||
color="parameter", | ||
facet_row="parameter", | ||
) | ||
fig.update_layout( | ||
showlegend=False, # Hide the legend | ||
height=400 * len(parameters), # plot height times parameters | ||
) | ||
fig.update_yaxes(matches=None) | ||
# Update y-axis titles to use facet labels and remove subplot titles | ||
for i, annotation in enumerate(fig.layout.annotations): | ||
axis_name = f"yaxis{i + 1}" | ||
if axis_name in fig.layout: | ||
fig.layout[axis_name].title.text = annotation.text | ||
annotation.text = "" | ||
st.plotly_chart(fig) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
wetterdienst | ||
plotly |