Function: I try to build a skript which shows geo-data on a map. This data changes and should be updatet continually.
I have a file which gathers the neccesary information via ROS and saves it in a dict which will be serialized it with pickle.
This file also starts the bokeh skript via subprocess.Popen('bokeh serve --show outputBokeh_liveData.py', shell=True)
.
Thank you for your time!
Error
File "pickle.py", line 964, in load_binfloat:
self.append(unpack('>d', self.read(8))[0]) Traceback (most recent call last):
File "/home/ebike/.local/lib/python2.7/site-packages/bokeh/application/handlers/code_runner.py", line 179, in run
exec(self._code, module.__dict__)
File "/home/ebike/workspaces/ebike2x_ws/src/bike_diag_plot_pkg/src/outputBokeh_liveData.py", line 21, in <module>
plot_data = pickle.load(pickle_in)
File "/usr/lib/python2.7/pickle.py", line 1384, in load
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 964, in load_binfloat
self.append(unpack('>d', self.read(8))[0])
error: unpack requires a string argument of length 8
Code
from bokeh.models import CrosshairTool
from bokeh.plotting import ColumnDataSource, figure, curdoc
from bokeh.tile_providers import STAMEN_TERRAIN_RETINA, get_provider
from bokeh.client import push_session
from helper_functions import wgs84_to_web_mercator, find_plot_size, pos_col_line, pos_col_map, return_first_place_list
import pickle
# depickle plot_data from diag_rosbag_online.py
with open("plot_data_live_traj.pickle", "rb") as pickle_in:
plot_data = pickle.load(pickle_in)
pickle_in.close()
# map start view coords -> takes coords from middle point of measurement
gmap_coords = (plot_data['latitudeB'][len(plot_data['latitudeB'])-1][0], plot_data['longitudeB'][len(plot_data['longitudeB'])-1][0])
map_lon = [gmap_coords[0]-0.001, gmap_coords[0]+0.001] # left and right viewlimit of openstreetmap
map_lat = [gmap_coords[1]-0.001, gmap_coords[1]+0.001] # upper and lower viewlimit of openstreetmap
# convert gmap (wgs84) coords into web mercator for openstreetmap
map_lat_m, map_lon_m = wgs84_to_web_mercator(lat=map_lat, lon=map_lon)
# size of plots
plot_h, plot_w = find_plot_size()
# define source and map
source = ColumnDataSource(dict(y_b_m = [],
x_b_m = [],
y_c_m = [],
x_c_m = []))
# Tools for plots
TOOLS = "wheel_zoom,reset,save,help"
crosshair_maps_osm_large = CrosshairTool(dimensions="both")
# Some parameters for the plots
tile_provider_large = get_provider(STAMEN_TERRAIN_RETINA)
# Create figures
traj_osm_large = figure(y_range=(map_lon_m[0], map_lon_m[1]), x_range=(map_lat_m[0], map_lat_m[1]),
x_axis_type="mercator", y_axis_type="mercator",
plot_height = plot_h*2, plot_width = plot_w*3, title="Trajectory Map Terrain", tools=TOOLS)
traj_osm_large.add_tools(crosshair_maps_osm_large)
traj_osm_large.add_tile(tile_provider_large)
traj_osm_large.yaxis.axis_label = 'Longitude [Degree]'
traj_osm_large.xaxis.axis_label = 'Latitude [Degree]'
# Plotting
traj_osm_large.multi_line('y_b_m', 'x_b_m', source=source, line_width=1, legend_label="Bike", color="red")
traj_osm_large.multi_line('y_c_m', 'x_c_m', source=source, line_width=1, legend_label="Car", color="green")
traj_osm_large.legend.location = "top_left"
traj_osm_large.legend.click_policy = "hide"
# Start Callbacks and show
curdoc().add_root(traj_osm_large)
def update():
# depickle plot_data from diag_rosbag_online.py
with open("plot_data_live_traj.pickle", "rb") as pickle_in:
plot_data = pickle.load(pickle_in)
pickle_in.close()
latitudeB_m, longitudeB_m = wgs84_to_web_mercator(lat=plot_data['longitudeB'], lon=plot_data['latitudeB'])
latitudeC_m, longitudeC_m = wgs84_to_web_mercator(lat=plot_data['longitudeC'], lon=plot_data['latitudeC'])
new_data = dict(y_b_m = [latitudeB_m],
x_b_m = [longitudeB_m],
y_c_m = [latitudeC_m],
x_c_m = [longitudeC_m])
source.stream(new_data, rollover=30)
curdoc().add_periodic_callback(update, 1000)
pickle.load
- it has nothing to do with Bokeh, it seems that your data is corrupted or was created by an incompatible pickle implementationupdate()
. What deserialization method is usually used, when plotting liveplots with bokeh?