94 lines
1.8 KiB
Python
94 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
|
|
from time import sleep, time
|
|
from random import random
|
|
import numpy as np
|
|
from epics import PV
|
|
from bokeh.plotting import curdoc, figure
|
|
from bokeh.models import ColumnDataSource
|
|
from bokeh.layouts import row
|
|
|
|
from c2cache import cache
|
|
|
|
|
|
data = {
|
|
"x": [],
|
|
"y": []
|
|
}
|
|
|
|
source = ColumnDataSource(data=data)
|
|
histo = ColumnDataSource(dict(left=[], right=[], top=[]))
|
|
image = ColumnDataSource(dict(image=[np.random.random((1000, 1000))]))
|
|
|
|
fig1 = figure()
|
|
fig1.step(x="x", y="y", source=source, mode="after")
|
|
fig1.circle(x="x", y="y", source=source)
|
|
|
|
fig2 = figure()
|
|
fig2.quad(left="left", right="right", top="top", bottom=0, source=histo)
|
|
|
|
fig3 = figure()
|
|
fig3.image(source=image, x=0, y=0, dw=1, dh=1, palette="Spectral11")
|
|
|
|
pv = PV("MTEST:RAND0")
|
|
|
|
pv_img = PV("MTEST:CHAN-IMAGE:FPICTURE", auto_monitor=True)
|
|
pv_height = PV("MTEST:CHAN-IMAGE:HEIGHT")
|
|
pv_width = PV("MTEST:CHAN-IMAGE:WIDTH")
|
|
|
|
|
|
def cb(value=None, **kwargs):
|
|
cache.append(value)
|
|
|
|
|
|
image_data = None
|
|
|
|
def cb_img(value=None, **kwargs):
|
|
print(len(value))
|
|
global image_data
|
|
if value is None:
|
|
return
|
|
height = pv_height.get()
|
|
width = pv_width.get()
|
|
if height is None or value is None:
|
|
return
|
|
image_data = value
|
|
image_data.shape = (height, width)
|
|
|
|
pv_img.add_callback(cb_img)
|
|
|
|
|
|
def update():
|
|
# print(cache.values)
|
|
times = cache.times
|
|
values = cache.values
|
|
data = {
|
|
"x": times,
|
|
"y": values
|
|
}
|
|
source.data.update(data)
|
|
|
|
counts, edges = np.histogram(values, bins="auto")
|
|
histo.data.update(left=edges[:-1], right=edges[1:], top=counts)
|
|
|
|
if image_data is not None:
|
|
# print(image_data.shape)
|
|
image.data.update(image=[image_data])
|
|
|
|
|
|
|
|
pv.add_callback(cb)
|
|
doc = curdoc()
|
|
doc.add_periodic_callback(update, 1000)
|
|
|
|
plt = row(
|
|
fig1,
|
|
fig2,
|
|
fig3
|
|
)
|
|
|
|
doc.add_root(plt)
|
|
|
|
|
|
|