I thought creating the bokeh plot in a subprocess using multiprocessing could be an idea, but I am new to this module and still have to try (and mainly debug) it.
Here is what I tried, but it fails :
(1) creating a maping function
def map_bokeh(inputs ):
print inputs
import sys
import pandas as pd
import numpy as np
import shapefile
import bokeh
from bokeh.io import output_notebook
from bokeh.models import HoverTool
from bokeh.plotting import figure, ColumnDataSource
from sortedcontainers import SortedSet
import matplotlib.pylab
france_hors_zdc = inputs[0]
nb_unite_by_cp = inputs[1]
unite_hors_zdc = inputs[2]
unite_dans_zdc = inputs[3]
import time
p = figure()
n_row = 100000
d = time.time()
output_file(“france_zdc_et_unites_%s.html”%d)
source = ColumnDataSource(france_hors_zdc[:n_row]
glyph = p.patches(source =source), xs = “lat”, ys = “lng”, fill_color=“white”,line_color=“white”)
p.add_tools(HoverTool(renderers=[glyph], tooltips=[(“cp”, “@cp”)], name=“hors_zdc”))
source = ColumnDataSource(nb_unite_by_cp[[‘lat’, ‘lng’,‘cp_y’, ‘unite’, ‘unites’, ‘color’]][:n_row])
glyph = p.patches(source =source, xs = “lat”, ys = “lng”, fill_color=“color”,)
p.add_tools(HoverTool(renderers=[glyph], tooltips=[(“cp”, “@cp_y”), (“nb unite”, “@unite”), (“liste unites”, “@unites”)], name=“zdc”))
source =ColumnDataSource(unite_hors_zdc[[u’unit’, u’pool’, u’X_lambert93’, u’Y_Lambert93’]][:n_row])
glyph = p.circle(source =source , x = u’X_lambert93’, y = u’Y_Lambert93’, color=“red”)
p.add_tools(HoverTool(renderers=[glyph], tooltips=[(“pool”, “@pool”), (“unite”, “@unit”)], name=“pool_units”))
source =ColumnDataSource(unite_dans_zdc[[u’unit’, u’pool’, u’X_lambert93’, u’Y_Lambert93’]][:n_row])
glyph = p.circle(source=source, x = u’X_lambert93’, y = u’Y_Lambert93’, color=“orange”)
p.add_tools(HoverTool(renderers=[glyph], tooltips=[(“pool”, “@pool”), (“unite”, “@unit”)], name=“pool_units”))
show(p)
d5 = time.time()
print "total time = ", d5-d
total_times.append(d5-d)
print total_times
``
(2) calling multiprocessing and maping the bokeh creation to one process (hoping the stack will flush by itself at the process’s death):
from multiprocessing import Pool
pool = Pool(1)
inputs = [[france_hors_zdc, nb_unite_by_cp, unite_hors_zdc, unite_dans_zdc]]
pool.map(map_bokeh, inputs)
``
But it never gives back any output.
It is even not sure that you can interrupt the kernel (I can’t)
Any insight ?
···
Le lundi 11 juillet 2016 22:46:45 UTC+2, Romain Jouin a écrit :
Hi,
I am using jupyter notebook to make a bokeh map.
Each time I re-do my cell, the calculation time is longer.
Here is the idea of my map : I do a four-step map :
total_times =
import time
p = figure()
n_row = 100000
output_file(“france_zdc_et_unites.html”)
d = time.time()
glyph = p.patches(source =ColumnDataSource(france_hors_zdc[:n_row]), xs = “lat”, ys = “lng”, fill_color=“white”,line_color=“white”)
p.add_tools(HoverTool(renderers=[glyph], tooltips=[(“cp”, “@cp”)], name=“hors_zdc”))
source = ColumnDataSource(nb_unite_by_cp[[‘lat’, ‘lng’,‘cp_y’, ‘unite’, ‘unites’, ‘color’]][:n_row])
glyph = p.patches(source =source, xs = “lat”, ys = “lng”, fill_color=“color”,)
p.add_tools(HoverTool(renderers=[glyph], tooltips=[(“cp”, “@cp_y”), (“nb unite”, “@unite”), (“liste unites”, “@unites”)], name=“zdc”))
source =ColumnDataSource(unite_hors_zdc[[u’unit’, u’pool’, u’X_lambert93’, u’Y_Lambert93’]][:n_row])
glyph = p.circle(source =source , x = u’X_lambert93’, y = u’Y_Lambert93’, color=“red”)
p.add_tools(HoverTool(renderers=[glyph], tooltips=[(“pool”, “@pool”), (“unite”, “@unit”)], name=“pool_units”))
source = ColumnDataSource(unite_dans_zdc[[u’unit’, u’pool’, u’X_lambert93’, u’Y_Lambert93’]][:n_row])
glyph = p.circle(source=source, x = u’X_lambert93’, y = u’Y_Lambert93’, color=“orange”)
p.add_tools(HoverTool(renderers=[glyph], tooltips=[(“pool”, “@pool”), (“unite”, “@unit”)], name=“pool_units”))
show(p)
d5 = time.time()
total_times.append(d5-d)
print total_times
``
The total time get each time bigger :
First iteration was about 10 sec, then after 3 or 4 I get : [29.3, 35.6, 42.9 ]
The size of the created html is also getting bigger and bigger : [26,7 Mo, 33,4 Mo 40,1Mo]
I tried to do a “del p” , it didn’t change anything
My activity monitor also tell me the python process is getting bigger at each iteration.
Anyone else has had the same issue ?
Is it a known issue ?
Any idea of a solution ?
Thx,
romain.