Spaces:
Running
Running
# -*- coding: utf-8 -*- | |
""" | |
Created on Fri Mar 3 12:57:34 2023 | |
@author: BorowyP | |
""" | |
import pandas as pd | |
import hvplot.pandas # Adds .hvplot and .interactive methods to Pandas dataframes | |
from hvplot.plotting import scatter_matrix | |
import panel as pn # Panel is a simple, flexible and enterprise-ready data app framework | |
import holoviews as hv | |
from holoviews.operation.timeseries import rolling, rolling_outlier_std | |
hv.extension('bokeh') | |
#pn.extension('tabulator') | |
pn.extension(sizing_mode="stretch_width") | |
#pd.set_option("precision", 0) | |
PALETTE = ["#ff6f69", "#ffcc5c", "#88d8b0", ] | |
import numpy as np | |
from bokeh.models.formatters import DatetimeTickFormatter | |
formatter = DatetimeTickFormatter(months='%b %Y') # wird in .hvplot benötigt für x-achse! | |
soil_temp = pd.read_csv('df_soil_temp.csv',header=0,sep=',') | |
soil_temp.index = pd.to_datetime(soil_temp['Date'], format='%Y.%m.%d %H:%M:%S') | |
soil_temp.index.names = ['Date'] | |
soil_temp = soil_temp.drop(['Date'], axis=1) | |
soil_temp = soil_temp.drop(['Unnamed: 0'], axis=1) | |
soil_temp[soil_temp.columns[list(range(6))]] = soil_temp[soil_temp.columns[list(range(6))]].round(1) #RUNDEN auf 1 Kommastelle fuer bessere Perfomance!!! | |
soil_temp = soil_temp.rename(columns={'Temp05' : '50', | |
'Temp10' : '100', | |
'Temp20' : '200', | |
'Temp30' : '300', | |
'Temp50' : '500' , | |
'Temp100' : '1000', | |
'Standort' : 'Standort'}) | |
Stndrt = pn.widgets.RadioButtonGroup(name='Standort', options=['Glienig', 'Groß Liebitz', 'Krausnick', 'Halbe', 'Spreeau', 'Hangelsberg'],button_type='success') | |
soiltempbtn = pn.widgets.ToggleGroup( | |
name='soiltemperature', | |
options=['50', '100', '200', '300', '500', '1000'], | |
value=['50'], | |
button_type='success') | |
soil_date_slider = pn.widgets.DateRangeSlider(name='Date', start=soil_temp.index.min(), end=soil_temp.index.max()) | |
soil_temp_i= soil_temp.interactive() | |
soil_temp_i = ( | |
soil_temp_i[ | |
(soil_temp_i.Standort == Stndrt) & | |
(soil_temp_i.index >= soil_date_slider.param.value_start) & | |
(soil_temp_i.index <= soil_date_slider.param.value_end) | |
] | |
) | |
soiltempplot = soil_temp_i.hvplot(x='Date',xlabel='Datum',title=Stndrt, y=soiltempbtn, color=PALETTE, line_width=1, xformatter=formatter, ylabel='Bodentemperatur [°C]') | |
def callback_temp(soil_temp_i): | |
df = soil_temp_i | |
monitor = pd.DataFrame({#'Standort' : [Stndrt.value, Stndrt.value], | |
#'von' : soil_temp_i.index.min(), | |
#'bis' : soil_temp_i.index.max(), | |
'Mittelwert' : [df['50'].mean(), | |
df['100'].mean(), | |
df['200'].mean(), | |
df['300'].mean(), | |
df['500'].mean(), | |
df['1000'].mean(), | |
] , | |
'Median' : [df['50'].median(), | |
df['100'].median(), | |
df['200'].median(), | |
df['300'].median(), | |
df['500'].median(), | |
df['1000'].median(), | |
] , | |
'Maximum' : [df['50'].max(), | |
df['100'].max(), | |
df['200'].max(), | |
df['300'].max(), | |
df['500'].max(), | |
df['1000'].max()], | |
'Minimum' : [df['50'].min(), | |
df['100'].min(), | |
df['200'].min(), | |
df['300'].min(), | |
df['500'].min(), | |
df['1000'].min()], | |
'Anzahl' : [df['50'].count(), | |
df['100'].count(), | |
df['200'].count(), | |
df['300'].count(), | |
df['500'].count(), | |
df['1000'].count()] | |
}, index=['50', | |
'100', | |
'200', | |
'300', | |
'500', | |
'1000', | |
]) | |
monitor.index.name='Profiltiefe' | |
#soiltemp_scatter = scatter_matrix(soil_temp, alpha=0.2) #Scattermatrix zum Vergleich der einzelnen Profiltiefen??? | |
soiltemp_scatter_df = soil_temp[soil_temp['Standort'] == Stndrt.value]#.iloc[df.index.min(): df.index.max()] | |
soiltemp_scatter = scatter_matrix(soiltemp_scatter_df, alpha=0.2) | |
scatter_headline = pn.pane.Markdown(f"## Scattermatrix **{Stndrt.value}**") | |
scatter_discription = pn.pane.Markdown('scatter_matrix shows all the pairwise relationships between the columns of your data. Each non-diagonal entry plots the corresponding columns against another, while the diagonal plot shows the distribution of the data within each individual column.' | |
) | |
monitor_gesamt = pd.DataFrame({'Standort' : [Stndrt.value], | |
'von' : df.index.min(), | |
'bis' : df.index.max(), | |
'Mittelwert' : df.mean(numeric_only=True).mean(), | |
'Median' : df.median(numeric_only=True).median(), | |
'Maximum' : df.max(numeric_only=True).max(), | |
'Minimum' : df.min(numeric_only=True).min() | |
}, index=['Gesamt']) | |
return pn.Column(monitor_gesamt, monitor,scatter_headline, soiltemp_scatter, scatter_discription) | |
callback = soil_temp_i.pipe(callback_temp) | |
callback | |
hd_logo = pn.pane.PNG('HD_Logo.png', width=100) | |
lfe_logo = pn.pane.PNG('LFE_Logo.png', width=100) | |
fnr_logo = pn.pane.PNG('fnr_logo.png', width=100) | |
template = pn.template.FastListTemplate( | |
title='Holzdeko Dashboard', | |
sidebar=[hd_logo, | |
pn.pane.Markdown("## Einstellungen"), | |
'Standort',Stndrt, | |
lfe_logo, | |
fnr_logo | |
], | |
main=[pn.pane.Markdown("## Bodentemperatur"), | |
soiltempbtn, | |
soil_date_slider, | |
soiltempplot.panel(), | |
callback.panel(), | |
#accent_base_color="#88d8b0", | |
#header_background="#88d8b0", | |
]) | |
template.servable(); | |
#print('fertig!') | |
# To launch this dashboard as a web server, we can simply run | |
# cd C:\Users\BorowyP\Desktop\Dashboard-Preasi\soil_air\ | |
# panel serve 20230307_soil_temp_docker.ipynb --autoreload |