Skip to content

Commit

Permalink
Merge pull request #3 from robervalwalsh/irsetup-env-pt100
Browse files Browse the repository at this point in the history
Irsetup env pt100
  • Loading branch information
robervalwalsh authored Mar 18, 2021
2 parents 855ac23 + 81868d3 commit 219635b
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 34 deletions.
140 changes: 123 additions & 17 deletions infrared-setup/infrared-setup-environment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def get_history():
sel_data = {}
## FIXME: force date range, if nearest too old then "remove" data
for l in location:
if 'pt100' in l:
continue
last_idx = alldata[l].index.get_loc(fts, method='nearest')
last_ts = alldata[l].iloc[last_idx].name
first_idx = alldata[l].index.get_loc(its, method='nearest')
Expand All @@ -121,6 +123,36 @@ def get_history():
for key in observables:
ds[l][key].data = {'x':sdates, 'y':list(sel_data[l][key])}
ds[l][key].trigger('data', ds[l][key].data, ds[l][key].data)


## pt100
for l in location:
if not 'pt100' in l:
continue
last_idx = alldata[l].index.get_loc(fts, method='nearest')
last_ts = alldata[l].iloc[last_idx].name
first_idx = alldata[l].index.get_loc(its, method='nearest')
first_ts = alldata[l].iloc[first_idx].name

r_pt100[l]['temperature'].visible = True

# if last_ts-first_ts < 1 or l == 'left-top':
if last_ts-first_ts < 1:
sel_data[l] = alldata[l][0:0]
r_pt100[l]['temperature'].visible = False
else:
sel_data[l] = alldata[l].loc[first_ts:last_ts]

if first_ts < its:
sel_data[l] = sel_data[l][1:]
if last_ts > fts:
sel_data[l] = sel_data[l][:-1]

sdates = [datetime.fromtimestamp(ts) for ts in list(sel_data[l].index)]
ds_pt100[l]['temperature'].data = {'x':sdates, 'y':list(sel_data[l]['temperature'])}
ds_pt100[l]['temperature'].trigger('data', ds_pt100[l]['temperature'].data, ds_pt100[l]['temperature'].data)




def initialdata():
Expand All @@ -131,21 +163,20 @@ def initialdata():
for l in location:
last_idx = alldata[l].index.get_loc(now_ts, method='nearest')
last_ts = alldata[l].iloc[last_idx].name
# get the nearest index to midnight
first_idx = alldata[l].index.get_loc(midnight_ts, method='nearest')
# get the first timestamp
first_ts = alldata[l].iloc[first_idx].name
# if last_ts <= midnight_ts or l == 'left-top':
if last_ts <= midnight_ts:
sel_data[l] = alldata[l][0:0]
else:
# get the nearest index to midnight
first_idx = alldata[l].index.get_loc(midnight_ts, method='nearest')
# get the first timestamp
first_ts = alldata[l].iloc[first_idx].name
# get selected data
sel_data[l] = alldata[l].loc[first_ts:last_ts]

return sel_data



@linear()
def update(step):
readdata()
Expand All @@ -160,10 +191,18 @@ def readdata():
if not path.exists(mycsv):
continue

sdata[sensor[l]] = pd.read_csv(mycsv,names=("datetime","temperature","pressure","humidity"),parse_dates=[0],infer_datetime_format=True)
sdata[sensor[l]]['datetime'] = sdata[sensor[l]].datetime.dt.tz_localize('Europe/Berlin')

if not 'pt100' in sensor[l]:
sdata[sensor[l]] = pd.read_csv(mycsv,names=("datetime","temperature","pressure","humidity"),parse_dates=[0],infer_datetime_format=True,comment='#',header=0)
else:
sdata[sensor[l]] = pd.read_csv(mycsv,names=("datetime","temperature"),parse_dates=[0],infer_datetime_format=True,comment='#',header=0)

if l == 'outside':
sdata[sensor[l]]['datetime'] = sdata[sensor[l]].datetime.dt.tz_localize('Europe/Berlin')
else:
sdata[sensor[l]]['datetime'] = sdata[sensor[l]].datetime.dt.tz_localize('UTC')
# select only every n-th row: skip rows
skip = 20
skip = 1
if l == 'outside':
skip = 1
sdata[sensor[l]] = sdata[sensor[l]].iloc[::skip, :]
Expand All @@ -177,10 +216,11 @@ def readdata():
# reindex
sdata[sensor[l]] = sdata[sensor[l]].sort_index()

sdata[sensor[l]]["dewpoint"] = dew_point(sdata[sensor[l]]["temperature"],sdata[sensor[l]]["humidity"])
if not 'pt100' in sensor[l]:
sdata[sensor[l]]["dewpoint"] = dew_point(sdata[sensor[l]]["temperature"],sdata[sensor[l]]["humidity"])

sel_data[l] = sdata[sensor[l]]

return sel_data


Expand All @@ -193,6 +233,7 @@ def main () :
main ()

elif __name__.startswith('bokeh_app') or __name__.startswith('bk_script'):
date_format = ['%d %b %Y %H:%M:%S']
# name starts with bk_script (__name__ = bk_script_<some number>)

# read data from the files
Expand All @@ -205,9 +246,29 @@ def main () :
sensor = {}
# FIX ME! Need more colors
colors = ['firebrick','navy','green','lightblue','magenta','lightgreen','red','blue','black','gray']
sensors = ['raspberry7_bus1_ch1','raspberry7_bus4_ch1','raspberry7_bus6_ch1','raspberry7_bus5_ch1','raspberry8_bus5_ch1','raspberry8_bus6_ch1','raspberry8_bus4_ch1','raspberry8_bus1_ch1','raspberry9_bus1_ch1','krykWeather']
# sensors = ['raspberry7_bus1_ch1','raspberry7_bus4_ch1','raspberry7_bus6_ch1','raspberry7_bus5_ch1','raspberry8_bus5_ch1','raspberry8_bus6_ch1','raspberry8_bus4_ch1','raspberry8_bus1_ch1','raspberry9_bus1_ch1','krykWeather']
# location = ['sensor #1','sensor #2','sensor #3','sensor #4','sensor #5','sensor #6','sensor #7','sensor #8','ref sensor']
location = ['centre-bottom','right-bottom','right-middle','right-top','centre-top','left-top','left-middle','left-bottom','reference','outside']

location.append('pt100_1')
location.append('pt100_2')
location.append('pt100_3')
location.append('pt100_4')
colors.append('magenta')
colors.append('red')
colors.append('blue')
colors.append('green')
# location = ['centre-bottom','right-bottom','right-middle','right-top','centre-top','left-top','left-middle','left-bottom','reference']
sensors = []
for l in location:
if l == 'outside':
sensors.append('krykWeather')
continue
if 'pt100' in l:
sensors.append('irsetup_'+l)
continue
sensors.append('irsetup_bme680_'+l)

observables = ['dewpoint','temperature','pressure','humidity']
for i, l in enumerate(location):
color[l] = colors[i]
Expand All @@ -222,8 +283,9 @@ def main () :
plot[observables[1]] = figure(plot_width=500, plot_height=500,x_axis_type="datetime",x_range=plot[observables[0]].x_range,toolbar_location="above")
plot[observables[2]] = figure(plot_width=500, plot_height=500,x_axis_type="datetime",x_range=plot[observables[0]].x_range,toolbar_location="above")
plot[observables[3]] = figure(plot_width=500, plot_height=500,x_axis_type="datetime",x_range=plot[observables[0]].x_range,toolbar_location="above")
date_format = ['%d %b %Y %H:%M:%S']

for key, p in plot.items():

p.xaxis.formatter=DatetimeTickFormatter(
microseconds=date_format,
milliseconds=date_format,
Expand All @@ -238,8 +300,10 @@ def main () :
)
p.xaxis.major_label_orientation = pi/3
p.xaxis.axis_label = "Local time"

for l in location:
if 'pt100' in l:
continue
try:
sdates = [datetime.fromtimestamp(ts) for ts in list(inidata[l].index)]
except KeyError as e:
Expand All @@ -253,14 +317,56 @@ def main () :
p.legend.location = "top_left"
p.legend.orientation = "vertical"
p.legend.click_policy="hide"



plot['dewpoint'].yaxis.axis_label = "Dew Point (C)"
plot['temperature'].yaxis.axis_label = "Temperature (C)"
plot['pressure'].yaxis.axis_label = "Pressure (hPa)"
plot['humidity'].yaxis.axis_label = "Relative Humidity (%RH)"

## pt100 plot

plot_pt100 = {}
plot_pt100['temperature'] = figure(plot_width=500, plot_height=500,x_axis_type="datetime",x_range=plot['dewpoint'].x_range,toolbar_location="above")
plot_pt100['temperature'].xaxis.formatter=DatetimeTickFormatter(
microseconds=date_format,
milliseconds=date_format,
seconds=date_format,
minsec=date_format,
minutes=date_format,
hourmin=date_format,
hours=date_format,
days=date_format,
months=date_format,
years=date_format
)
plot_pt100['temperature'].xaxis.major_label_orientation = pi/3
plot_pt100['temperature'].xaxis.axis_label = "Local time"
r_pt100 = {}
ds_pt100 = {}
for l in location:
if not 'pt100' in l:
continue
r_pt100[l] = {}
ds_pt100[l] = {}
try:
sdates = [datetime.fromtimestamp(ts) for ts in list(inidata[l].index)]
except KeyError as e:
continue

r_pt100[l]['temperature'] = plot_pt100['temperature'].circle(sdates, list(inidata[l]['temperature']), fill_color=color[l], line_color=color[l], size=3,legend_label=l)
ds_pt100[l]['temperature'] = r_pt100[l]['temperature'].data_source
if len(ds_pt100[l]['temperature'].data['x']) < 1:
r_pt100[l]['temperature'].visible = False

plot_pt100['temperature'].legend.location = "top_left"
plot_pt100['temperature'].legend.orientation = "vertical"
plot_pt100['temperature'].legend.click_policy="hide"
plot_pt100['temperature'].yaxis.axis_label = "Dry Air Temperature (C)"





# sys.exit()

# pick a date
Expand All @@ -285,7 +391,7 @@ def main () :
v_space = PreText(text="",width=1, height=50)


curdoc().add_root(column(row(h_space,pre_head),row(h_space, date_picker_i, date_picker_f), row(h_space, hist_button),v_space,row(h_space,plot['dewpoint'],h_space,plot['temperature']), v_space,row(h_space,plot['humidity'],h_space,plot['pressure']), v_space))
curdoc().add_root(column(row(h_space,pre_head),row(h_space, date_picker_i, date_picker_f), row(h_space, hist_button),v_space,row(h_space,plot['dewpoint'],h_space,plot_pt100['temperature']), v_space,row(h_space,plot['temperature'],h_space,plot['humidity']), v_space,row(h_space,plot['pressure'],h_space), v_space))

# readdata()
# main()
Expand Down
43 changes: 26 additions & 17 deletions infrared-setup/server.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ description = Geb.26 Infrared Setup
verbose = 1

# daf
thermorasps = raspberry7-bus1-ch1 raspberry7-bus4-ch1 raspberry7-bus5-ch1 raspberry7-bus6-ch1 raspberry8-bus1-ch1 raspberry8-bus4-ch1 raspberry8-bus5-ch1 raspberry8-bus6-ch1 raspberry9-bus1-ch1
#thermorasps = raspberry9-bus1-ch1
#thermorasps = raspberry7-bus1-ch1 raspberry7-bus4-ch1 raspberry7-bus5-ch1 raspberry7-bus6-ch1 raspberry8-bus1-ch1 raspberry8-bus4-ch1 raspberry8-bus5-ch1 raspberry8-bus6-ch1 raspberry9-bus1-ch1
thermorasps = raspberry7-bus4-ch1 raspberry7-bus5-ch1 raspberry7-spi0-ch0 raspberry7-spi0-ch1 raspberry8-bus1-ch1 raspberry8-bus6-ch1 raspberry8-spi0-ch0 raspberry8-spi0-ch1 raspberry9-bus1-ch1

[storage]
path = /home/walsh/data/infrared-setup
Expand Down Expand Up @@ -90,25 +90,34 @@ name = irsetup_bme680_reference
description = RaspPi with meters
updateInterval = 180

[raspberry10-spi0-ch0]
host = fhlthermorasp10.desy.de
port = 50008
name = irsetup_pt100_test0
[raspberry7-spi0-ch0]
host = fhlthermorasp7.desy.de
port = 50020
name = irsetup_pt100_3
description = RaspPi with meters
updateInterval = 10
updateInterval = 180

[raspberry10-spi0-ch1]
host = fhlthermorasp10.desy.de
port = 50009
name = irsetup_pt100_test1
[raspberry7-spi0-ch1]
host = fhlthermorasp7.desy.de
port = 50021
name = irsetup_pt100_4
description = RaspPi with meters
updateInterval = 10
updateInterval = 180

[raspberry8-spi0-ch0]
host = fhlthermorasp8.desy.de
port = 50020
name = irsetup_pt100_1
description = RaspPi with meters
updateInterval = 180

[raspberry10-bus1-ch1]
host = fhlthermorasp10.desy.de
port = 50010
name = irsetup_bme680_test
[raspberry8-spi0-ch1]
host = fhlthermorasp8.desy.de
port = 50021
name = irsetup_pt100_2
description = RaspPi with meters
updateInterval = 10
updateInterval = 180




0 comments on commit 219635b

Please sign in to comment.