Spaces:
Running
Running
# -*- coding: utf-8 -*- | |
""" | |
Created on Fri Mar 10 15:10:36 2023 | |
@author: BorowyP | |
""" | |
import os | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
import hvplot.pandas | |
import holoviews as hv | |
from holoviews.operation.timeseries import rolling, rolling_outlier_std | |
import xarray as xr | |
import panel as pn | |
import panel.widgets as pnw | |
import hvplot.xarray | |
cwd = os.getcwd() | |
print(cwd) | |
print(os.listdir(cwd)) | |
os.chdir('hemi_fotos') | |
pic_cwd = os.getcwd() | |
print(pic_cwd) | |
os.listdir(pic_cwd) | |
os.chdir(pic_cwd) | |
#os.listdir() | |
list_pictures_files = os.listdir() | |
rgb_list = [] | |
for i in range(len(list_pictures_files)): | |
im = plt.imread(list_pictures_files[i]) | |
x = np.arange(len(im[0])) | |
y = np.arange(len(im)) | |
channel = np.arange(3) | |
im_xr = xr.DataArray(im,coords={'y': y,'x': x,'channel': channel},dims=["y", "x", "channel"]) | |
rgb_list.append(im_xr) | |
#print(str(list_pictures_files[i]) + ' ' + | |
# 'y-Achse: ' + ' ' + str(len(im)) + ', ' + | |
# 'x-Achse: ' + ' ' + str(len(im[0])) + ', ' + 'channel: ' + ' ' + str(len(im[0][0]))) | |
#print(' ') | |
x = np.arange(len(rgb_list[0][0])) | |
y = np.arange(len(rgb_list[0])) | |
channel = np.arange(3) | |
Stndrt = np.array([ | |
'Krausnick K', | |
'Glienig K', | |
'Glienig nK', | |
'Halbe K', | |
'Halbe nK', | |
'Hangelsberg K', | |
'Hangelsberg nK', | |
'Spreeau K', | |
'Spreeau nK', | |
'Groß Liebitz K', | |
'Groß Liebitz nK' | |
]) | |
xar = xr.DataArray(rgb_list, | |
dims=( | |
'Standort', | |
"y", | |
"x", | |
"channel") | |
, | |
coords={ | |
"x": x, | |
"y": y, | |
"channel": channel, | |
'Standort' : Stndrt, | |
}, | |
name="rgb") | |
fisheye = xar.hvplot.rgb(x='x', y='y', bands='channel', data_aspect=1, flip_yaxis=True, xaxis=False, yaxis=None, width=500) | |
os.chdir(cwd) | |
df = pd.read_csv( | |
'Hemisphere_totals_holzdeko.csv' , | |
encoding_errors='ignore', | |
sep=';', | |
#skiprows=[5,10], | |
header=0, | |
decimal=',' | |
) | |
df['transmission'] = df['transmission'].str.strip('%') # entfernt Character '%' | |
df['transm_gaps'] = df['transm_gaps'].str.strip('%') | |
df['openness'] = df['openness'].str.strip('%') | |
df['openn_gaps'] = df['openn_gaps'].str.strip('%') | |
df['transmission'] = df['transmission'].replace(',', '.', regex=True) # wandelt , in . um | |
df['transm_gaps'] = df['transm_gaps'].replace(',', '.', regex=True) | |
df['openness'] = df['openness'].replace(',', '.', regex=True) | |
df['openn_gaps'] = df['openn_gaps'].replace(',', '.', regex=True) | |
df['transmission'] = df['transmission'].astype('float64', copy=False) | |
df['transm_gaps'] = df['transm_gaps'].astype('float64', copy=False) | |
df['openness'] = df['openness'].astype('float64', copy=False) | |
df['openn_gaps'] = df['openn_gaps'].astype('float64', copy=False) | |
params = pn.widgets.RadioButtonGroup( | |
name='param', | |
options=['white', | |
'black', | |
'transmission', | |
'transm_gaps', | |
'openness', | |
'openn_gaps' | |
], | |
button_type='success') | |
data_inter = df.interactive() | |
mean_param = ( | |
data_inter | |
.groupby(['Standort', 'k_nk']).mean() | |
) | |
mean_param_plot = mean_param[params].hvplot(x='Standort', y=params, by='k_nk', kind='bar', | |
title=params, xlabel='Standort') | |
param_discription = pd.DataFrame({'white': ['white pixels (sky)'], | |
'black' : ['black pixels (canopy)'], | |
'transmission' : ['light transmission in 2D (azimutal equidistant projection of the hemisphere)'], | |
'transm_gaps' : ['large gaps of transmission'], | |
'openness' : ['canopy openness in 3D, also called sky view factor (solid angles of the hemisphere)'], | |
'openn_gaps' : ['large gaps of openness']}) | |
param_discription = param_discription.interactive() | |
param_discription = param_discription[params].values[0] | |
os.chdir(cwd) | |
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='Auswertung Hemisfere', | |
sidebar=[hd_logo, | |
pn.pane.Markdown("## Einstellungen"), | |
#'Standort',Stndrt, | |
#'gekalkt/ungekalkt', yaxis, | |
lfe_logo, | |
fnr_logo | |
#'Boden', | |
#'Gekalkt/ungekalkt', yaxis, | |
], | |
main=[pn.pane.Markdown("## Hemisfere"), | |
fisheye,#.panel(), | |
#params, | |
param_discription, | |
mean_param_plot.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\hemisfer | |
# panel serve 2023_02_10_hemi_dashboard.ipynb --autoreload | |