Hi All,
I am working on a project that streams data to a ColumnDataSource and then uses the data in the column data source to create a streaming plot. Because this is not a public project I dont think I can reveal the whole code but I will describe what is happening here.
I first create a ColumnDataSource object:
source = ColumnDataSource(dict(
time=np.zeros(rollingWindowSize), roomTemp=np.zeros(rollingWindowSize)))
I then record data from a temperature sensor and update the ColumnDataSource as (note that im initializing the new data dictionary with an old value for the room temperature):
newData = dict(time=[t], roomTemp=[RT_store[-1]])
newData['roomTemp'] = [RT_store[-1]]
source.stream(newData,rollover=rollingWindowSize)
I then begin monitoring the plot. I noticed then that within the first 5 minutes of running the code the plot resets several times and then stabilizes for the remainder of the running time. Digging through the code I found that what happens is the data type of the source data is changing.
Before (ndarray):
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
After (list):
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 22.4, 22.4, 22.4, 22.4, 22.4, 22.4, 22.4, 22.4, 22.4, 22.4, 22.7, 22.7, 22.7]
In essence, type(source.data[‘roomTemp’]) changes from numpy array to list. When this happens the list is initially empty so the plot is reset. I’m not sure why the data type is reset, however, I have tracked the change to the stream function in Bokeh sources. Here the value of the oldkeys variable changes to unicode strings when the data type changes to list.
def stream(self, new_data, rollover=None):
import numpy as np
newkeys = set(new_data.keys())
oldkeys = set(self.data.keys())
print "newkeys " +str(newkeys)
print "oldkeys "+str(oldkeys)
if newkeys != oldkeys:
missing = oldkeys - newkeys
extra = newkeys - oldkeys
if missing and extra:
raise ValueError("Must stream updates to all existing columns (missing: %s, extra: %s)" % (", ".join(sorted(missing)), ", ".join(sorted(extra))))
elif missing:
raise ValueError("Must stream updates to all existing columns (missing: %s)" % ", ".join(sorted(missing)))
else:
raise ValueError("Must stream updates to all existing columns (extra: %s)" % ", ".join(sorted(extra)))
lengths = set()
for x in new_data.values():
if isinstance(x, np.ndarray):
if len(x.shape) != 1:
raise ValueError("stream(...) only supports 1d sequences, got ndarray with size %r" % (x.shape,))
lengths.add(x.shape[0])
else:
lengths.add(len(x))
if len(lengths) > 1:
raise ValueError("All streaming column updates must be the same length")
print "before "+str(new_data.values())
self.data._stream(self.document, self, new_data, rollover)
newkeys set([‘time’, ‘roomTemp’])
oldkeys set([u’time’, u’roomTemp’])
Does anyone know why this is happening? If not, where can I find this function to continue troubleshooting the code:
self.data._stream(self.document, self, new_data, rollover)