Commit c5fe4b05 authored by Harbola's avatar Harbola
Browse files

initial commit

parents
Demo help for user!
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 10 18:49:03 2021
@author: Shub
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 31 16:54:15 2020
@author: hp
# -*- coding: utf-8 -*-
Created on Sat Oct 31 16:28:11 2020
@author: Shub
"""
import numpy as np
import streamlit as st
import pandas as pd
#from shapely.geometry import Point,Polygon
#import mplleaflet
#import matplotlib.pyplot as plt
import datetime
import pydeck as pdk
#import plotly.express as px
#from windrose import WindroseAxes
import altair as alt
#import plotly.graph_objects as go
#import copy
#import pandas as pd
#import matplotlib.pyplot
#from matplotlib.widgets import Cursor, MultiCursor
#import altair as alt
from statistics import mean # library for mathematical calulations
#import streamlit as st
#from streamlit_folium import folium_static
#import folium
#from vega_datasets import data
#import numpy
import streamlit_wide_mode
import SessionState
#import naming as n
###@ function method @@@@@####################################################
streamlit_wide_mode._max_width_()
### stacked chart function ####################################
def bar_plot_method(filter_value2,parameter):
#
brush = alt.selection(type='interval', encodings=['x'])
base = alt.Chart(filter_value2).mark_area().encode(
x="monthdate(time)",
y= parameter
).properties(
width=1600,
height=200
)
upper = base.encode(alt.X("monthdate(time)", scale=alt.Scale(domain=brush))
#alt.Y("wind_speed", scale=alt.Scale(domain=brush))
)
lower = base.properties(
height=60
).add_selection(brush)
upper&lower
# end of method
def format_coord(x, y):
# Shree Radhakrishna
# https://stackoverflow.com/questions/46531243/how-to-control-mouseover-text-in-matplotlib
try:
# z = # get value depending on x,y, e.g. via interpolation on grid
# I can't fill this because the kind of data is unknown here
# return "x: {}, y: {}, z: {}".format(x,y,z)
return "x: {}, y: {}".format(x,y) ;
except:
# return "x: {}, y: {}".format(x,y)
return "x: {}, y: {}".format(x,y)
# ax.format_coord = format_coord
###@ reding the data method @@@@@####################################################
## reading the data completed
#def testmethod(selectedsensor):
#pathName_input = 'C:\\Users\\Dell\\Desktop\\didiji survey paper\\visualisation_codes\\more_codes\\updated_Sensordata\\updated_Sensordata\\'
#pathName_input = 'F:/Spatial_interpolation/Sensors_data/updated_Sensordata/'#F:\stuttgart_wind_direction\final_str_Hbf_winddata
pathName_input = 'C:/Users/Shub/streamlite_dashboard/data/updated_Sensordata/'
#pathName_input = 'F:/Spatial_interpolation/Sensors_data/updated_Sensordata/'#F:\stuttgart_wind_direction\final_str_Hbf_winddata
fileName1 = 'sensorA.csv'
fileName2 = 'sensorB.csv'
fileName3 = 'sensorC.csv'
fileName4 = 'sensorD.csv'
fileName5 = 'sensorE.csv'
fileName6 = 'sensorF.csv'
fileName7 = 'sensorG.csv'
fileName8 = 'sensorH.csv'
fileName9 = 'sensorI.csv'
fileName10 = 'sensorJ.csv'
#Stations = pd.concat([df1,df2,df3,df4],ignore_index=True)
#Stations = pd.concat([df1,df2,df3,df4,df5,df6,df7,df8,df9,df10], axis=0).drop_duplicates(subset=['sensor'])
#print('\n concatenated data is \n ' , Stations , '\n');
#Stations['Windspeed'] = pd.to_numeric( Stations['Windspeed'] ) ;
#Stations['PM10'] = pd.to_numeric( Stations['PM10']) ;
#Stations['PM2_5'] = pd.to_numeric( Stations['PM2_5'] ) ;
#Stations['Humd'] = pd.to_numeric( Stations['Humd'] ) ;
@st.cache
def load_data(nrows):
#df = pd.read_csv(( pathName_input +fileName ), sep = ",", nrows=nrows)
#data = pd.read_pickle(( pathName_input +fileName ), nrows=nrows)
#lowercase = lambda x: str(x).lower()
#Drop rows which contains any NaN or missing value
#newdf = df.dropna()
# Drop rows with NaN or missing value in all columns
#df = newdf.dropna(how='all')
#data.rename(lowercase, axis='columns', inplace=True)
#data['YEAR'] = pd.to_datetime(data['YEAR'])
# define eastern timezone
#eastern = timezone('US/Eastern')
# dti = dti.tz_localize('UTC')
#df_temp=copy.deepcopy(df)
sensorA = pd.read_csv(( pathName_input +fileName1 ), sep = ",", nrows=1000)
sensorB = pd.read_csv(( pathName_input +fileName2 ), sep = ",", nrows=1000)
sensorC = pd.read_csv(( pathName_input +fileName3 ), sep = ",", nrows=1000)
sensorD = pd.read_csv(( pathName_input +fileName4 ), sep = ",",nrows=1000)
sensorE = pd.read_csv(( pathName_input +fileName5 ), sep = ",", nrows=1000)
sensorF = pd.read_csv(( pathName_input +fileName6 ), sep = ",",nrows=1000)
sensorG = pd.read_csv(( pathName_input +fileName7 ), sep = ",",nrows=1000)
sensorH = pd.read_csv(( pathName_input +fileName8 ), sep = ",",nrows=1000)
sensorI = pd.read_csv(( pathName_input +fileName9 ), sep = ",",nrows=1000)
sensorJ = pd.read_csv(( pathName_input +fileName10 ), sep = ",",nrows=1000)
Stations = pd.concat([sensorA, sensorB, sensorC, sensorD,
sensorE, sensorF, sensorG, sensorH, sensorI, sensorJ], axis=0)
Stations["time"] = pd.to_datetime(
Stations['YEAR'] + ' ' + Stations['time'])
Stations = Stations.drop(["YEAR"], axis=1)
# Kepler needs time as string, otherwise it will throw an error
#sensor_all["time"] = sensor_all["time"].apply(str)
Stations["time"] = pd.to_datetime(Stations["time"],utc=True, dayfirst=True)
## removing neagtive
#https://stackoverflow.com/questions/27759084/how-to-replace-negative-numbers-in-pandas-data-frame-by-zero
Stations['Windspeed'] [Stations['Windspeed'] < 0]=0
Stations['PM10'] [Stations['PM10'] < 0]=0
Stations['PM2_5'] [Stations['PM2_5'] < 0]=0
Stations['Humd'] [Stations['Humd'] < 0]=0
#df['timestamp'] = pd.to_datetime(df['date'], utc=True, dayfirst=True) #day saving problem recovered b the conversion to local time
#generate the datetime
#df['date'] = df['timestamp'].apply(lambda x: datetime.datetime(x.year,x.month,x.day, x.hour, x.minute, x.second))
#import time
#df['date']=time.strftime("%H:%M", time.strptime(str(df['timestamp']), "%Y-%m-%d %H:%M:%S"))
#df['date'] = df['date'].astype('datetime64[ns]')
#df['date']=df['date'].to_pydatetime()
#df_temp['date']= pd.to_datetime(df['date'], dayfirst=True)
return Stations
Stations = load_data(50) #458384
print('\n concatenated data is \n ' , Stations , '\n');
Stations['Windspeed'] = pd.to_numeric( Stations['Windspeed'] ) ;
#Stations['Windspeed'] .clip_lower(0) ## 1st method removing the negative value with 0 in the normalised dataset
#Stations['Windspeed'] [Stations['Windspeed'] < 0]=0
#df[df < 0] = 0 2 mthod of removing negative vlaues
#print ('wind speed data after removing the negative vlaues', Stations['Windspeed'] )
Stations['PM10'] = pd.to_numeric( Stations['PM10']) ;
#Stations['Windspeed'] .clip_lower(0) ## 1st method removing the negative value with 0 in the normalised dataset
#Stations['PM10'] [Stations['Windspeed'] < 0]=0
#df[df < 0] = 0 2 mthod of removing negative vlaues
#print ('PM10 data after removing the negative vlaues', Stations['Windspeed'] )
Stations['PM2_5'] = pd.to_numeric( Stations['PM2_5'] ) ;
#Stations['Windspeed'] .clip_lower(0) ## 1st method removing the negative value with 0 in the normalised dataset
#Stations['PM2_5'] [Stations['Windspeed'] < 0]=0
#df[df < 0] = 0 2 mthod of removing negative vlaues
#print ('PM2_5 data after removing the negative vlaues', Stations['Windspeed'] )
Stations['Humd'] = pd.to_numeric( Stations['Humd'] ) ;
#Stations['Windspeed'] .clip_lower(0) ## 1st method removing the negative value with 0 in the normalised dataset
#Stations['Humd'] [Stations['Windspeed'] < 0]=0
#df[df < 0] = 0 2 mthod of removing negative vlaues
#print ('Humdiity removing the negative vlaues', Stations['Windspeed'] )
#print('check this block')
##plotting heading
st.title("Environmental Dashboard For Stuttgart")#st.markdown('The dashboard will visualize the Wind and Air Quality Situation in Stuttgart')
#st.markdown('Stuttgart in-depth analysis. The BW state capital Stuttgart started the new fine dust alarm season & calls on its citizens to use public transportation. This visual anlytics tool for interactively anlyse & explore historical+spatial+temporal+future of meterological & air qulity paremters')
#print('check this block2')
if st.checkbox('Show raw data'):
#st.subheader('Raw data')
st.write('Full Dataset', Stations)
selected_indices = st.multiselect('Select rows:', Stations.index)
selected_rows = Stations.loc[selected_indices]
st.write('Selected Rows', selected_rows)
print('check this block3')
st.sidebar.markdown("### Measurements locations on map")
#st.sidebar.markdown("Sensors different considered locations in Stuttgart")
#if not st.sidebar.checkbox("Hide", True, key='1'):
#st.map(Stations.query("Windspeed>=0.0")[["lat", "lon"]])
st.sidebar.pydeck_chart(pdk.Deck(
map_style='mapbox://styles/mapbox/light-v9',
initial_view_state=pdk.ViewState(
longitude=9.183,
latitude=48.783,
zoom=13, #14 zoomed
pitch=50
),
layers=[
pdk.Layer(
'ScatterplotLayer',
data= Stations,
get_position='[lon, lat]',
get_radius=55,
# radius=20,
auto_highlight=True,
#elevation_scale=100,
#elevation_range=[0, 5000],
get_fill_color=[220,20,60], #red # marron 128,0,0 #(220,20,60)
pickable=True,
extruded=True
)
],
# layers=[
# pdk.Layer(
# 'ColumnLayer',
# data= Stations,
# get_position='[lon, lat]',
# get_elevation='[PM10]',
# radius=20,
# auto_highlight=True,
# elevation_scale=100,
# elevation_range=[0, 5000],
# get_fill_color=[255, 140, 0],#orange
# pickable=True,
# extruded=True
# )
# ],
tooltip={
'html': '<b>Sensor Name:</b> {sensor}',
'style': {
'color': 'white'
}}
))
##
#if not st.sidebar.checkbox("Hide", True, key='2'):
st.sidebar.title("Sensor data: filtering selector")
#st.sidebar.markdown("### Wants to explore in-depth?: interact, select & visualise")
st.sidebar.markdown("Perform spatial-temporal querry on different sensors and their nature comparision analysis")
#
# starting the data from 2016 to 2019
today = datetime.date(2019, 1,1)
tomorrow = datetime.date(2019,1,7)
start_date = st.sidebar.date_input('Start date', today)
end_date = st.sidebar.date_input('End date', tomorrow)
#if start_date < end_date:
#st.success()
#st.success('Start date: `%s`\n\nEnd date:`%s`' % (start_date, end_date))
#else:
#st.error('Error: End date must fall after start date.')
print(start_date)
print(end_date)
print("type(end_date)", type(end_date))
print('type(time of Stations.iloc[1,0]) ', type(Stations.iloc[0,7]))
print("date and month Stations",Stations.iloc[0,7].year,Stations.iloc[0,7].month, Stations.iloc[0,7].day)
print("date and month displaying on the dashboard screen",start_date.year,start_date.month, start_date.day)
#
index4=[]
for i in range(0,Stations.shape[0],1):
df_manual_date = datetime.datetime(Stations.iloc[i,7].year , Stations.iloc[i,7].month , Stations.iloc[i,7].day )
start_manual_date = datetime.datetime(start_date.year , start_date.month , start_date.day )
end_manual_date = datetime.datetime(end_date.year , end_date.month , end_date.day )
if( df_manual_date >= start_manual_date and df_manual_date <= end_manual_date ):
index4.append(i)
#
print("index4", index4)
Stations=Stations.iloc[index4,:]
#df.reset_index()# for indexing the data
Stations.reset_index(drop=True, inplace=True)
print('Stations', Stations)
# # Use the full page instead of a narrow central column
# #st.beta_set_page_config(layout="wide")
comp_data = Stations
# temporal filtering
comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#start_date=datetime.date(2019, 1, 1)
#end_date=datetime.date(2019, 1, 8)
#d5 = st.date_input("date range without default", [start_date, end_date])
#st.sidebar.write(d5)
#print('type(time of Stations.iloc[1,0]) ', type(comp_data.iloc[0,7]))
#Space out the maps so the first one is 2x the size of the other three
#c1, c2, c3, c4 = st.beta_columns((2, 2, 1, 1))
st.markdown("### Sensors Inspection: compare sensors together")
#st.sidebar.markdown("Compare the nature of the selcted sensors and their temporal behaviour measurements in different considered Stuttgart's locations")
#if not st.sidebar.checkbox("Expand with unchecking", True, key='3'):
#st.title("Air Quality")
metrics = ['None','PM10','PM2_5','Windspeed','Humidity']
cols = st.selectbox('Sensors metric to view', metrics)
if (cols =='PM10'):
color = alt.Color('sensor:N')#
brush = alt.selection_interval(encodings=['x'])
click = alt.selection_multi(encodings=['color'])
highlight= alt.selection(type='single', on='mouseover',
fields=['sensor'], nearest=True)
base=alt.Chart(comp_data).mark_line(point=True).encode(
x='datetime:T',
y='PM10:Q',
color='sensor:N').properties(
width=1500
)
points1 = base.mark_circle().encode(
opacity=alt.value(0)
).add_selection(
highlight
).properties(
width=1500
),
color=alt.condition(brush, color, alt.value('lightgray')),
#size=alt.Size('Windspeed:Q',scale=alt.Scale(range=[10, 30]))#size=alt.Size('mean(PM10):Q',scale=alt.Scale(range=[5, 50]))
#).properties(width=1250, height=650).add_selection(brush).transform_filter(click)
# Bottom panel is a bar chart of weather type
lines1 = base.mark_line().encode(
size=alt.condition(~highlight, alt.value(1), alt.value(3))
)
# Bottom panel is a bar chart of weather type
bars = alt.Chart().mark_bar().encode(
x='count(PM10)',
y='sensor:N',
color=alt.condition(click, color, alt.value('lightgray')),
).transform_filter(
brush
).properties(width=1500
).add_selection(
click)
#st.altair_chart(alt.vconcat((points1 + lines1), bars))
st.altair_chart(alt.vconcat(points1, bars))
if (cols =='PM2_5'):
compare_graph=alt.Chart(comp_data).mark_line(point=True).encode(
x='datetime:T',
y='PM2_5:Q',
color='sensor:N').properties(
width=1500
)
st.altair_chart(compare_graph)
if (cols =='Windspeed'):
compare_graph=alt.Chart(comp_data).mark_line(point=True).encode(
x='datetime:T',
y='Windspeed:Q',
color='sensor:N').properties(
width=1500
)
st.altair_chart(compare_graph)
if (cols =='Humidity'):
compare_graph=alt.Chart(comp_data).mark_line(point=True).encode(
x='datetime:T',
y='Humd:Q',
color='sensor:N').properties(
width=1500
)
st.altair_chart(compare_graph)
# compare_graph2=alt.Chart(comp_data).mark_area().encode(
# x="datetime:T",
# y=alt.Y("PM10:Q", stack="normalize"),
# color="sensor:N"
# )
#column_select=WS
# highlight= alt.selection(type='single', on='mouseover',
# fields=['sensor'], nearest=True)
# base = alt.Chart(comp_data).encode(
# x='day(datetime)',
# y='mean(PM10)',
# color='sensor'
# )
# points1 = base.mark_circle().encode(
# opacity=alt.value(0)
# ).add_selection(
# highlight
# ).properties(
# width=600
# )
# lines1 = base.mark_line().encode(
# size=alt.condition(~highlight, alt.value(1), alt.value(3))
# )
# #2b chart
# highlight = alt.selection(type='single', on='mouseover',
# fields=['sensor'], nearest=True)
# base = alt.Chart(comp_data).encode(
# x='datetime',
# y='PM10',
# color='sensor'
# )
# points2 = base.mark_circle().encode(
# opacity=alt.value(0)
# ).add_selection(
# highlight
# ).properties(
# width=600
# )
# lines2 = base.mark_line().encode(
# size=alt.condition(~highlight, alt.value(1), alt.value(3))
# )
# #points + lines
# # to concatenate to chart horixonatally
# #c=alt.hconcat((points1 + lines1), (points2 + lines2))
# c=alt.vconcat((points1 + lines1), (points2 + lines2))
# st.altair_chart(compare_graph2)
c1, c2 = st.beta_columns((1, 2))
#comp_data = Stations
#print(comp_data)
#st.sidebar.markdown("a) Select sensors")
#if not st.sidebar.checkbox("Uncheck to expand", True, key='18'):
st.sidebar.markdown("Compare the nature of the each selcted sensors and their temporal behaviour measurements at different Stuttgart's locations")
#if not st.sidebar.checkbox("Expand with unchecking", True, key='3'):
parameter_select = st.sidebar.selectbox('Parameter', ['PM10', 'PM2_5','Windspeed','Humd'], key='19')
sensors_select = st.sidebar.selectbox("Select sensors", ("None", "A", 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'))
#sensors_select = st.sidebar.selectbox("Select sensors", ( "A", 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'))
chart_placeholder2 = st.empty()
#sensor A
if sensors_select=='A':
comp_data=comp_data.loc[(comp_data['sensor']=='A')]
with c1:
st.map(Stations.query("sensor=='A'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
#st.title("Environmental Temporal Filtering")
#bar_plot_method(comp_data,parameter_select)
# line = alt.Chart(comp_data).mark_line().encode(
# x='datetime',
# #y='mean(Windspeed)'
# y='Windspeed'
# )
# band = alt.Chart(comp_data).mark_errorband(extent='ci').encode(
# x='datetime',
# y=alt.Y('Windspeed', title='m/s'),
# )
# st.altair_chart(band + line)
# sensor B
if sensors_select=='B':
comp_data=comp_data.loc[(comp_data['sensor']=='B')]
with c1:
st.map(Stations.query("sensor=='B'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
## sensor C
if sensors_select=='C':
comp_data=comp_data.loc[(comp_data['sensor']=='C')]
with c1:
st.map(Stations.query("sensor=='C'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
# sensor D
if sensors_select=='D':
comp_data=comp_data.loc[(comp_data['sensor']=='D')]
with c1:
st.map(Stations.query("sensor=='D'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
# sensor E
if sensors_select=='E':
comp_data=comp_data.loc[(comp_data['sensor']=='E')]
with c1:
st.map(Stations.query("sensor=='E'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
#alt.X('day(datetime):O', title='week on avg', axis=alt.Axis(tickMinStep=0.5)),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
# sensor F
if sensors_select=='F':
comp_data=comp_data.loc[(comp_data['sensor']=='F')]
with c1:
st.map(Stations.query("sensor=='F'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
#sensor G
if sensors_select=='G':
comp_data=comp_data.loc[(comp_data['sensor']=='G')]
with c1:
st.map(Stations.query("sensor=='G'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
# sensor H
if sensors_select=='H':
comp_data=comp_data.loc[(comp_data['sensor']=='H')]
with c1:
st.map(Stations.query("sensor=='H'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
#sensor I
if sensors_select=='I':
comp_data=comp_data.loc[(comp_data['sensor']=='I')]
with c1:
st.map(Stations.query("sensor=='I'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
#sensor J
if sensors_select=='J':
comp_data=comp_data.loc[(comp_data['sensor']=='J')]
with c1:
st.map(Stations.query("sensor=='J'")[["lat", "lon"]])
with c2:
#comp_data['datetime']= pd.to_datetime(comp_data['time']).dt.strftime('%Y-%m-%dT%H:%M:%S')
#print('comp_data after filtering',comp_data)
c1 = alt.Chart(comp_data).mark_bar().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.X('day(datetime):O', title='week on avg'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
# alt.X('date(date)', title='date',axis=alt.Axis(
# tickCount=overview_df.shape[0],
# #tickOffset=2
# #tickCount="day",
# #tickCount=2,
# grid=False,
# #grid=True,
# #labelExpr="datum.value % 5 ? null : datum.label")
# #labelExpr="datum.label[0]")
# )),
#x='date(datetime)',
y=parameter_select,
#x=alt.X('date(datetime):T', axis=alt.Axis(title='Date', format=("%b %d"),labelAngle=10, grid=True)),
#x='hoursminutes(start)',
#x2='hoursminutes(end)',
# alt.X('date(date)'), #title='date',axis=alt.Axis(
#tickCount=overview_df.shape[0],
#tickOffset=2
#tickCount="day",
#tickCount=2,
#grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
#)),
#alt.X(parameter_select, title=parameter_select),
color=alt.Color('day(datetime)', title='week', scale=alt.Scale(scheme='category10')), #set1
tooltip=[ parameter_select]
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# c1=alt.Chart(overview_df).mark_bar(opacity=0.7).encode(
# x='date(date)',
# #y=alt.Y('day(date)', stack=None),
# y='day(date)',
# color=parameter_select,
# )
c2 = alt.Chart(comp_data).mark_rect().encode(
#alt.Y('monthdate(date):O', title='Month'),
alt.Y('hoursminutes(datetime):O', title='hour of day'),
#alt.X('datetime:O', title='tim'),
#alt.X('day(date)', title='week'),
# alt.X('date(date)', title='week')
#alt.X('date(date)', axis=alt.Axis(values=[0, 5, 10, 15, 20, 30])),
alt.X('date(datetime)', title='date',axis=alt.Axis(
tickCount=comp_data.shape[0],
#tickOffset=2,
#tickCount="date",
#tickCount=10,
grid=False,
#grid=True,
#labelExpr="datum.value % 5 ? null : datum.label")
#labelExpr="datum.label[0]")
)),
#alt.X(parameter_select, title=parameter_select), #scale=alt.Scale(scheme='turbo') # lightgreyred ,#lightmulti, #lightgreyteal
alt.Color(parameter_select, title=parameter_select, scale=alt.Scale(scheme='lightmulti')),#, scale=alt.Scale(scheme='brown'),
#tooltip=['monthdate(datetime)' , parameter_select]
#tooltip=['monthdate(datetime)']
#parameter_select, #alt.Color('temp:Q', title='temperature (F)')
# )
).properties(
width=300,
height=300
)
# alt.Chart(df).mark_circle().encode(
# x='a',
# y='b',
# color=alt.value(color),
# size='c'
# )
#chart_placeholder2.altair_chart(alt.hconcat(c1,c2))
st.altair_chart(alt.hconcat(c1,c2))
# # st.altair_chart(alt.Chart(comp_data).mark_rect().encode(
# # #week1= alt.Chart(comp_data).mark_rect().encode(
# # alt.X('day(date):O', title='week (in selcted month)'),
# # alt.Y('hours(date):O', title='hour'),
# # alt.Color(parameter_select, title=parameter_select), #parameter_select, #alt.Color('temp:Q', title='temperature (F)'),
# # tooltip=[parameter_select]
# # ).properties(
# # width=1000,
# # height=200
# # )
# # )
# # Inputs
# #d = st.date_input("Selected day", date(today.year, today.month, today.day-1))
# #opt = st.selectbox("Type of view", ['Map', 'Chart'], index=0)
# # Display data according to selected type of view
# #if opt == 'Map':
# # show_column_map(filtered_data)
# #elif opt == 'Chart':
# #show_bar_chart(filtered_data)
# # with c1:
# # st.pydeck_chart(pdk.Deck(
# # map_style='mapbox://styles/mapbox/light-v9',
# # initial_view_state=pdk.ViewState(
# # longitude=9.183,
# # latitude=48.783,
# # zoom=13,
# # pitch=50
# # ),
# # layers=[
# # pdk.Layer(
# # 'ColumnLayer',
# # data= Stations,
# # get_position='[lon, lat]',
# # get_elevation='[PM10]',
# # radius=20,
# # auto_highlight=True,
# # elevation_scale=100,
# # elevation_range=[0, 5000],
# # pickable=True,
# # extruded=True
# # )
# # ],
# # tooltip={
# # 'html': '<b>Sensor Name:</b> {sensor}',
# # 'style': {
# # 'color': 'white'
# # }}
# # ))
# ##################################################################################################
# ### plotting the sensors location on map#st.map(Stations.query("sensor== 'A' ")[["lat", "lon"]])
# #if (Stations.sensor[0]==selectedsensor):
# # plotting sensors as apoint in map
# #print('sesonion sensor', selectedsensor)
# #print('sesonion sensor', type(selectedsensor))
# #print('sesonion sensor', type(Stations.sensor))
# ## extracting the sensors data according to sensor data conditon selcted by the user
# #if any("selectedsensor" in s for s in Stations.sensor):
# # whatever
# #print('check test')
# #if selectedsensor=='A':
# #https://stackoverflow.com/questions/4843158/check-if-a-python-list-item-contains-a-string-inside-another-string
# #matching = [s for s in selectedsensor if any(xs in s for xs in Stations.sensor)]
# #print('check printing matching ', matching)
# #print('matching type', type(matching))
# #print('check printing matching ', matching[2])
# #filter_value=[]
# #for i in range(0,matching.shape[0], 1):
# #filter_value[i]= Stations.loc[(Stations['sensor']==(matching[i])) ] ;
# #print('filter_value \n' , filter_value, '\n') ;
# #filter_value1= Stations.loc[(Stations['sensor']==(matching[0])) ] ;
# #filter_value2 = Stations.loc[(Stations['sensor']==(matching[1])) ] ;
# #WS= filter_value1['Windspeed']
# #filter_value3= Stations.loc[(Stations['sensor']==(matching[2])) ] ;
# #filter_value4 = Stations.loc[(Stations['sensor']==(matching[3])) ] ;
# #print('filter_value1 \n' , filter_value1, '\n') ;
# #print('filter_value2 \n' , filter_value2, '\n') ;#source = data.stocks() #c=alt.Chart(Stations).mark_line().encode(x='day(time)', y='PM10',
# # """
# # #first altair chart
# # c=alt.Chart(Stations).mark_line().encode(x='time', y='PM10',
# # color='sensor',
# # strokeDash='sensor',
# # )
# # st.altair_chart(c)
# # """
#2 altair chart
#https://elib.uni-stuttgart.de/simple-search?query=Weiskopf+Daniel&sort_by=score&order=desc&rpp=10&etal=0&start=10
# sensor_list= ['A', 'B', 'C', 'D','E', 'F', 'G', 'H', 'I', 'J']
# #sensor_list =pd.Series(['A', 'B', 'C', 'D','E', 'F', 'G', 'H', 'I', 'J'])
# #listnames = show_names(name)
# selectednames=st.sidebar.multiselect('Select sensor names', sensor_list)
# print('selctname of sensors', selectednames)
# print('type of selctname of sensors', type(selectednames))
# #for name in selectednames:
# #df_final = df[df['c'].isin(A)]
# print('isin function selctname of sensors', comp_data.sensor.isin(selectednames))
# #st.map(comp_data.query("sensor"==[("sensor").isin(selectednames)]["lat", "lon"]))
# #st.map(comp_data.query("sensor"==[comp_data.sensor.isin(selectednames)[0]]["lat", "lon"]))
# #st.map(comp_data.query("sensor".isin(selectednames))["lat", "lon"])
# #df_new.loc[ df_new['sensor'].isin(['A' , 'C']) ]
# value2 = comp_data.loc[comp_data['sensor'].isin([selectednames]) ][['lat', 'lon']] ;
# print('shortlisted sensors', value2)
# #for i in range(0, len(selectednames)):
# # st.map(comp_data.query("sensor"=='A')[["lat", "lon"]])
# #st.map(Stations.query("sensor==name")[["lat", "lon"]])
# st.map(value2)
# c1, c2 = st.beta_columns((1, 1))
#comp_data = Stations
#print(comp_data)
#st.sidebar.markdown("a) Select sensors")
#if not st.sidebar.checkbox("Uncheck to expand", True, key='18'):
# parameter_select = st.sidebar.selectbox('Parameter', ['Windspeed','PM10', 'PM2_5', 'Humd'], key='19')
# sensors_select = st.sidebar.selectbox("Select sensors", ("None", "A", 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'))
# #sensors_select = st.sidebar.selectbox("Select sensors", ( "A", 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'))
# chart_placeholder2 = st.empty()
# #sensor A
# if sensors_select=='A':
# comp_data=comp_data.loc[(comp_data['sensor']=='A')]
# with c1:
# st.map(Stations.query("sensor=='A'")[["lat", "lon"]])
# with c2:
# st.sidebar.markdown("### Compare sensors")
# st.sidebar.markdown("Compare the nature of the selcted sensors and their temporal behaviour measurements in different considered Stuttgart's locations")
# #if not st.sidebar.checkbox("Hide", True, key='3'):
# #st.title("Air Quality")
# metrics = ['PM10','PM2_5','Windspeed','Humd']
# cols = st.selectbox('Sensors metric to view', metrics)
# if (cols =='PM10'):
# #column_select=WS
# highlight= alt.selection(type='single', on='mouseover',
# fields=['sensor'], nearest=True)
# base = alt.Chart(comp_data).encode(
# x='day(time)',
# y='mean(PM10)',
# color='sensor'
# )
# points1 = base.mark_circle().encode(
# opacity=alt.value(0)
# ).add_selection(
# highlight
# ).properties(
# width=600
# )
# lines1 = base.mark_line().encode(
# size=alt.condition(~highlight, alt.value(1), alt.value(3))
# )
# #2b chart
# highlight = alt.selection(type='single', on='mouseover',
# fields=['sensor'], nearest=True)
# base = alt.Chart(comp_data).encode(
# x='time',
# y='PM10',
# color='sensor'
# )
# points2 = base.mark_circle().encode(
# opacity=alt.value(0)
# ).add_selection(
# highlight
# ).properties(
# width=600
# )
# lines2 = base.mark_line().encode(
# size=alt.condition(~highlight, alt.value(1), alt.value(3))
# )
# #points + lines
# # to concatenate to chart horixonatally
# #c=alt.hconcat((points1 + lines1), (points2 + lines2))
# c=alt.vconcat((points1 + lines1), (points2 + lines2))
# st.altair_chart(c)
# def show_names(name):
# #if name == "sensors":
# # list1 = ['A', 'B', 'C', 'D',
# #'E', 'F', 'G', 'H', 'I', 'J']
# if name == "sensors":
# list1 = ['A', 'B', 'C', 'D',
# 'E', 'F', 'G', 'H', 'I', 'J']
# #elif name == "metrics":
# # list1 = ['Windflow','Humidity','Pm10','Pm2.5','NO']
# return list1
# def inp_det(type):
# if type == 'source':
# st.sidebar.write('### Select (sensors/metrics)')
# st.sidebar.markdown("Select, interact and visualise: Explain and devise your hypothesis with visual analytics")
# name = st.sidebar.text_input('Source sensor name')
# elif type == 'destination':
# st.write('Select (sensors/metrics')
# name = st.sidebar.text_input('Destination name')
# return name
# def main():
# #st.title("Environmental Dashboard")#st.markdown('The dashboard will visualize the Wind and Air Quality Situation in Stuttgart')
# #st.markdown("A visual anlytics tool for interactively anlysisng and exploring historical+spatial+temporal+future meterological and air qulity paremters")
# name = inp_det('source')
# session_state = SessionState.get(name="", button_sent=False)
# button_sent = st.sidebar.button("SUBMIT")
# if button_sent or session_state.button_sent: # <-- first time is button interaction, next time use state to go to multiselect
# session_state.button_sent = True
# #listnames = n.show_names(name)
# listnames = show_names(name)
# selectednames=st.sidebar.multiselect('Select sensor names',listnames)
# #st.write(selectednames)
# #sensors_on_map_with_parameters2.testmethod(selectednames)
# #sensors_on_map_with_parameters2_2.testmethod(selectednames)
# #Final_sensors_on_map_with_parameters2_2.testmethod(selectednames)
# if __name__ == "__main__":
# main()
#end of method
# c=alt.Chart(comp_data).mark_point().encode(
# alt.X(alt.repeat("column"), type='quantitative'),
# alt.Y(alt.repeat("row"), type='quantitative'),
# color='sensor'
# ).properties(
# width=200,
# height=200
# ).repeat(
# row=['time', 'time'],
# column=['PM10', 'PM2_5']
# ).interactive()
# st.altair_chart(c)
# c=alt.Chart(Stations).mark_point().encode(
# x='time',
# y='PM10',
# color='sensor'
# ).properties(
# width=180,
# height=180
# ).facet(
# column='sensor'
# )
# st.altair_chart(c)
# #3 altair chart
# selection = alt.selection_multi(fields=['sensor'], bind='legend')
# c=alt.Chart(comp_data).mark_area().encode(
# alt.X('time', axis=alt.Axis(domain=True, format='%d', tickSize=0)),
# alt.Y('PM10', stack='center', axis=None),
# alt.Color('sensor', scale=alt.Scale(scheme='category20b')),
# opacity=alt.condition(selection, alt.value(1), alt.value(0.2))
# ).add_selection(
# selection
# )
# st.altair_chart(c)
# print('last lines ')
# if not st.sidebar.checkbox("Hide", True, key='1'):
# metrics = ['PM10','PM2_5']
# cols = st.selectbox('Air quality metric to view', metrics)
# if (cols =='PM10'):
# concat_plot(Stations, cols)
#st.map(Stations.query("Windspeed>=0.0")[["lat", "lon"]])
#https://stackoverflow.com/questions/22591174/pandas-multiple-conditions-while-indexing-data-frame-unexpected-behavior
#df_filtered = df.query('a == 4 & b != 2')
# st.sidebar.markdown("### Which location measured highest today?: Pick date and see ")
# st.sidebar.markdown("Perform the temporal querry to highlight and on-fly identify ( or ask the system) the location which is measuring highest(either, WS, PM10, PM2_5, Humidity) among different considered locations in Stuttgart")
# if not st.sidebar.checkbox("Hide", True, key='14'):
# metrics = ['PM10','PM2_5','Windspeed','Humidity']
# cols = st.selectbox('Sensors metric to view', metrics)
# if (cols =='PM10'):
# st.map(Stations.query("PM10>=PM10.max()")[["lat", "lon", "sensor"]])
# if (cols =='PM2_5'):
# st.map(Stations.query("PM2_5>=PM2_5.max()")[["lat", "lon", "sensor"]])
# if (cols =='Windspeed'):
# st.map(Stations.query("Windspeed>=Windspeed.max()")[["lat", "lon", "sensor"]])
# if (cols =='Humidity'):
# st.map(Stations.query("Humd>=Humd.max()")[["lat", "lon", "sensor"]])
# # center on Liberty Bell
#st.map(Stations.query("Windspeed>=0.0")[["lat", "lon"]])
# layer = pdk.Layer(
# 'HexagonLayer',
# Stations,
# get_position='[lon, lat]',
# auto_highlight=True,
# elevation_scale=50,
# pickable=True,
# elevation_range=[0, 3000],
# extruded=True,
# coverage=1)
# # Set the viewport location
# view_state = pdk.ViewState(
# longitude=9.183,
# latitude=48.783,
# zoom=6,
# min_zoom=5,
# max_zoom=15,
# pitch=40.5,
# bearing=-27.36)
# # Combined all of it and render a viewport
# r = pdk.Deck(
# layers=[layer],
# initial_view_state=view_state,
# tooltip={
# 'html': '<b>Elevation Value:</b> {elevationValue}',
# 'style': {
# 'color': 'white'
# }
# }
# )
# r.to_html()
#print('the sesnors data type', Stations)
#d5 = st.sidebar.date_input("date range without default", [datetime.date(2019, 7, 6), datetime.date(2019, 7, 8)])
#st.sidebar.write(d5)
# alt.Chart(Stations).mark_geoshape()\
# .encode(color='sensors')\
# .add_selection(select_date)\
# .transform_filter(select_date)\
# .transform_lookup(
# lookup='id',
# from_=alt.LookupData(countries, key='id',
# fields=["type", "properties", "geometry"])
# )\
# .project('equirectangular')\
# .properties(
# width=500,
# height=300,
# title='Title'
# )
# =============================================================================
# Transformer model sensors nature monitoring
#data reading of all sensors predicted for 2020
# =============================================================================
pathName_input = 'C:\\Users\\Shub\\streamlite_dashboard\\data\\updated_Sensordata\\sensors_transformer_preditedoutputs\\'
fileName1 = 'designed_Allsensors2020_predicted.csv' ;
@st.cache
def load_data(nrows):
#df = pd.read_csv(( pathName_input +fileName ), sep = ",", nrows=nrows)
#data = pd.read_pickle(( pathName_input +fileName ), nrows=nrows)
#lowercase = lambda x: str(x).lower()
#Drop rows which contains any NaN or missing value
#newdf = df.dropna()
# Drop rows with NaN or missing value in all columns
#df = newdf.dropna(how='all')
#data.rename(lowercase, axis='columns', inplace=True)
#data['YEAR'] = pd.to_datetime(data['YEAR'])
# define eastern timezone
#eastern = timezone('US/Eastern')
# dti = dti.tz_localize('UTC')
#df_temp=copy.deepcopy(df)
sensorA = pd.read_csv(( pathName_input +fileName1 ), sep = ",", nrows=1000)
#sensorB = pd.read_csv(( pathName_input +fileName2 ), sep = ",", nrows=1000)
#sensorC = pd.read_csv(( pathName_input +fileName3 ), sep = ",", nrows=1000)
#sensorD = pd.read_csv(( pathName_input +fileName4 ), sep = ",",nrows=1000)
#sensorE = pd.read_csv(( pathName_input +fileName5 ), sep = ",", nrows=1000)
#sensorF = pd.read_csv(( pathName_input +fileName6 ), sep = ",",nrows=1000)
#sensorG = pd.read_csv(( pathName_input +fileName7 ), sep = ",",nrows=1000)
#sensorH = pd.read_csv(( pathName_input +fileName8 ), sep = ",",nrows=1000)
#sensorI = pd.read_csv(( pathName_input +fileName9 ), sep = ",",nrows=1000)
#sensorJ = pd.read_csv(( pathName_input +fileName10 ), sep = ",",nrows=1000)
Stations_monitoring = pd.concat([sensorA], axis=0)
Stations_monitoring["time"] = pd.to_datetime(
Stations_monitoring['YEAR'] + ' ' + Stations_monitoring['time'])
Stations_monitoring = Stations_monitoring.drop(["YEAR"], axis=1)
# Kepler needs time as string, otherwise it will throw an error
#sensor_all["time"] = sensor_all["time"].apply(str)
Stations_monitoring["time"] = pd.to_datetime(Stations_monitoring["time"],utc=True, dayfirst=True)
#df['timestamp'] = pd.to_datetime(df['date'], utc=True, dayfirst=True) #day saving problem recovered b the conversion to local time
#generate the datetime
#df['date'] = df['timestamp'].apply(lambda x: datetime.datetime(x.year,x.month,x.day, x.hour, x.minute, x.second))
#import time
#df['date']=time.strftime("%H:%M", time.strptime(str(df['timestamp']), "%Y-%m-%d %H:%M:%S"))
#df['date'] = df['date'].astype('datetime64[ns]')
#df['date']=df['date'].to_pydatetime()
#df_temp['date']= pd.to_datetime(df['date'], dayfirst=True)
return Stations_monitoring
Stations_monitoring = load_data(4700) #458384
print('\n concatenated data is \n ' , Stations_monitoring , '\n');
Stations_monitoring['Windspeed_maximum_value'] = pd.to_numeric( Stations_monitoring['Windspeed_maximum_value'] ) ;
Stations_monitoring['PM10_maximum_value'] = pd.to_numeric( Stations_monitoring['PM10_maximum_value']) ;
Stations_monitoring['PM2_5_maximum_value'] = pd.to_numeric( Stations_monitoring['PM2_5_maximum_value'] ) ;
Stations_monitoring['Humd_maximum_value'] = pd.to_numeric( Stations_monitoring['Humd_maximum_value'] ) ;
print ("Stations_monitoring['Windspeed_maximum_value']", Stations_monitoring['Windspeed_maximum_value'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment