Exemplo n.º 1
0
class MapPlot(object):
    def __init__(self):
        self.map_plot = Figure(
            tools="pan,wheel_zoom,tap", toolbar_location="right",
            logo=None, min_border=0, min_border_left=0,
            **get_paris_extent(0.6), # x_range & y_range
            plot_width=1100, plot_height=650)
        self.map_plot.add_tile(tile_source=OSM_TILE_SOURCE)
        self.map_plot_renderer = self.map_plot.patches(
            source=geo_source,
            xs="xs",
            ys="ys",
            line_width=2,
            line_color=None,
            selection_line_color="firebrick",
            nonselection_line_color=None,
            fill_color="colors",
            selection_fill_color="colors",
            nonselection_fill_color="colors",
            alpha=0.85,
            selection_alpha=0.9,
            nonselection_alpha=0.85)
        self.map_plot.axis.visible = None
        self.map_plot_ds = self.map_plot_renderer.data_source
    
    def get_plot(self):
        return self.map_plot
    
    def get_data_source(self):
        return self.map_plot_ds
Exemplo n.º 2
0
def plotMap(lat, lon, axis_range):
    x_offset, y_offset = convLL_XY(lat, lon)
    x_axis_range = [-axis_range+x_offset, axis_range+x_offset]
    y_axis_range = [-axis_range+y_offset, axis_range+y_offset]
    x_range = Range1d(start=x_axis_range[0], end=x_axis_range[1])
    y_range = Range1d(start=y_axis_range[0], end=y_axis_range[1])
    p = Figure(tools='pan,wheel_zoom', x_range=x_range, y_range=y_range, plot_height=800, plot_width=800)
    p.axis.visible = False
    STAMEN_TONER.url = 'http://tile.stamen.com/toner-lite/{Z}/{X}/{Y}.png'
    p.add_tile(STAMEN_TONER)
    return p
Exemplo n.º 3
0
def create_plot():
    axis_range = [-10000000, 10000000]
    p = Figure(tools='pan,wheel_zoom', x_range=axis_range, y_range=axis_range, plot_height=800, plot_width=800)
    p.axis.visible = False
    tile_source = RandomTileSource()
    tile_source.urls = []
    tile_source.attribution = STAMEN_TONER.attribution
    tile_source.urls.append(STAMEN_TONER.url)
    tile_source.urls.append('http://c.tile.openstreetmap.org/{Z}/{X}/{Y}.png')
    tile_source.urls.append('http://otile1.mqcdn.com/tiles/1.0.0/sat/{Z}/{X}/{Y}.jpg')
    p.add_tile(tile_source)
    return p
Exemplo n.º 4
0
def map():
    x_range = (-10000000, -11000000)
    y_range = (3500000, 5200000)

    plot = Figure(
        tools=TOOLS, title="Power Plant Locations", plot_width=1000, plot_height=500, x_range=x_range, y_range=y_range
    )
    plot.add_tile(STAMEN_TONER)
    plot.axis.visible = False
    plot.xgrid.grid_line_color = None
    plot.ygrid.grid_line_color = None
    m1 = plot.circle(x="lat", y="lon", source=source_map_bwr, size="size", fill_alpha=0, line_width=2, color="red")
    m2 = plot.square(x="lat", y="lon", source=source_map_pwr, size="size", fill_alpha=0, line_width=2, color="red")
    plot.select(dict(type=HoverTool)).tooltips = [("Plant Name", "@name"), ("Reactor and Containment", "@type")]

    return plot
Exemplo n.º 5
0
 
 # Create plot -------------------------------
 xmin = -8240227.037
 ymin = 4974203.152
 xmax = -8231283.905
 ymax = 4979238.441
 
 path = './data/projected.tif'
 
 fig = Figure(x_range=(xmin, xmax),
              y_range=(ymin, ymax),
              plot_height=600,
              plot_width=900,
              tools='pan,wheel_zoom')
 fig.background_fill_color = 'black'
 fig.add_tile(STAMEN_TONER, alpha=0) # used to set axis ranges
 fig.x_range.callback = CustomJS(code=dims_jscode, args=dict(plot=fig, dims=dims))
 fig.y_range.callback = CustomJS(code=dims_jscode, args=dict(plot=fig, dims=dims))
 fig.axis.visible = False
 fig.grid.grid_line_alpha = 0
 fig.min_border_left = 0
 fig.min_border_right = 0
 fig.min_border_top = 0
 fig.min_border_bottom = 0
 
 image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
 fig.image_rgba(source=image_source,
                image='image',
                x='x',
                y='y',
                dw='dw',
Exemplo n.º 6
0
throttle = setTimeout(update_dims, 100, "replace");
"""

# Create plot -------------------------------
xmin = -8240227.037
ymin = 4974203.152
xmax = -8231283.905
ymax = 4979238.441

fig = Figure(x_range=(xmin, xmax),
             y_range=(ymin, ymax),
             plot_height=600,
             plot_width=900,
             tools='pan,wheel_zoom')
fig.background_fill_color = 'black'
fig.add_tile(get_provider("STAMEN_TONER"), alpha=.3)
fig.x_range.callback = CustomJS(code=dims_jscode,
                                args=dict(plot=fig, dims=dims))
fig.y_range.callback = CustomJS(code=dims_jscode,
                                args=dict(plot=fig, dims=dims))
fig.axis.visible = False
fig.grid.grid_line_alpha = 0
fig.min_border_left = 0
fig.min_border_right = 0
fig.min_border_top = 0
fig.min_border_bottom = 0

image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
fig.image_rgba(source=image_source,
               image='image',
               x='x',
Exemplo n.º 7
0
throttle = setTimeout(update_dims, 100, "replace");
"""

# Create plot -------------------------------
xmin = -8240227.037
ymin = 4974203.152
xmax = -8231283.905
ymax = 4979238.441

fig = Figure(x_range=(xmin, xmax),
             y_range=(ymin, ymax),
             plot_height=600,
             plot_width=900,
             tools='pan,wheel_zoom')
fig.background_fill_color = 'black'
fig.add_tile(STAMEN_TONER, alpha=.3)
fig.x_range.callback = CustomJS(code=dims_jscode, args=dict(plot=fig, dims=dims))
fig.y_range.callback = CustomJS(code=dims_jscode, args=dict(plot=fig, dims=dims))
fig.axis.visible = False
fig.grid.grid_line_alpha = 0
fig.min_border_left = 0
fig.min_border_right = 0
fig.min_border_top = 0
fig.min_border_bottom = 0

image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
fig.image_rgba(source=image_source, image='image', x='x', y='y', dw='dw', dh='dh', dilate=False)

time_text = Paragraph(text='Time Period: 00:00 - 00:00')
controls = HBox(children=[time_text, time_select], width=fig.plot_width)
layout = VBox(children=[fig, controls])
Exemplo n.º 8
0
# Create plot -------------------------------
xmin = -8240227.037
ymin = 4974203.152
xmax = -8231283.905
ymax = 4979238.441

path = './data/projected.tif'

fig = Figure(x_range=(xmin, xmax),
             y_range=(ymin, ymax),
             plot_height=600,
             plot_width=900,
             tools='pan,wheel_zoom')
fig.background_fill_color = 'black'
fig.add_tile(STAMEN_TONER, alpha=0)  # used to set axis ranges
fig.x_range.callback = CustomJS(code=dims_jscode,
                                args=dict(plot=fig, dims=dims))
fig.y_range.callback = CustomJS(code=dims_jscode,
                                args=dict(plot=fig, dims=dims))
fig.axis.visible = False
fig.grid.grid_line_alpha = 0
fig.min_border_left = 0
fig.min_border_right = 0
fig.min_border_top = 0
fig.min_border_bottom = 0

image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
fig.image_rgba(source=image_source,
               image='image',
               x='x',
Exemplo n.º 9
0
throttle = setTimeout(update_dims, 100, "replace");
"""

# Create plot -------------------------------
xmin = -8240227.037
ymin = 4974203.152
xmax = -8231283.905
ymax = 4979238.441

fig = Figure(x_range=(xmin, xmax),
             y_range=(ymin, ymax),
             plot_height=600,
             plot_width=900,
             tools='pan,wheel_zoom')
fig.background_fill_color = 'black'
fig.add_tile(STAMEN_TONER, alpha=.3)
fig.x_range.callback = CustomJS(code=dims_jscode,
                                args=dict(plot=fig, dims=dims))
fig.y_range.callback = CustomJS(code=dims_jscode,
                                args=dict(plot=fig, dims=dims))
fig.axis.visible = False
fig.grid.grid_line_alpha = 0
fig.min_border_left = 0
fig.min_border_right = 0
fig.min_border_top = 0
fig.min_border_bottom = 0

image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
fig.image_rgba(source=image_source,
               image='image',
               x='x',
    output_backend="webgl",
)
cart_fig.background_fill_color = "grey"
cart_fig.background_fill_alpha = .5
# cb_fig = bokeh.plotting.Figure(plot_height=pw,plot_width=)
# cb_fig.toolbar.logo = None
# cb_fig.toolbar_location = None

# %%
# SCATTER

# noinspection PyUnresolvedReferences
# add tiles
tile_provider = bokeh.tile_providers.get_provider(
    bokeh.tile_providers.Vendors.CARTODBPOSITRON)
map_fig.add_tile(tile_provider)

# scatter in map
map_fig.scatter('GX', 'GY', source=source_master, size='r2', color=cm)

cart_fig.line('lo', 'la', source=source_bol, color='black')
cart_fig.scatter('x', 'y', source=source_master, radius='r', color=cm)

red_scat_map = map_fig.circle_cross(
    'gx',
    'gy',
    source=source_red_map,
    #                                color='red',
    fill_color=None,
    #                                line_color='green',
    size=20,
Exemplo n.º 11
0
    def plot_carto_single(self, data, frente, palette, path=FILE_OUT,
                          name_file="", low=0, high=100, show_plot=True):
        """

        :param data: df loaded by data_load
        :param frente: string, name of "partido" lowercase: diff, mas, cc, creemos, fpv, pan_bol
        :param palette: ej: P_GRAD_CC
        :param name_file: default:test
        :param low: cmap low limit: default: -80
        :param high: cmap high limit: defauilt: +80.
        :param path: file out
        :return: df
        """
        da_col = ['HAB','PAIS','MUN','REC','X','Y','LAT','LON','x','y',
                  'r','r2','GX','GY'
                  ]

        cart_init_val = self.CART_SLIDER_INIT  # add slider
        self.process_data(cart_init_val, data)


        if frente == "diff":
            low = self.C_BAR_LOW
            high = self.C_BAR_HIGH
            frente = "d_mas_cc"
            f1 = 'mas_o_cc'
            f2 = 'ad_mas_cc'
            _p = 'mas'
            _p1 = 'cc'
            da_col.append(frente)
            da_col.append(f1)
            da_col.append(f2)
            da_col.append(_p)
            da_col.append(_p1)
        if frente == "d_mas_creemos":
            low = self.C_BAR_LOW
            high = self.C_BAR_HIGH
            f1 = 'mas_o_creemos'
            f2 = 'ad_mas_creemos'
            da_col.append(frente)
            da_col.append(f1)
            da_col.append(f2)
            da_col.append('mas')
            da_col.append('creemos')

        da_col.append(frente)



        cm = linear_cmap(frente, palette=palette, low=low, high=high)



        data = data[da_col]
        source_master = ColumnDataSource(data)
        source_red_map = ColumnDataSource({'gx': [], 'gy': []})
        # la, lo = ebu.get_la_lo_bolivia()
        # source_bol = ColumnDataSource({'la': la, 'lo': lo})
        # source_red_car = ColumnDataSource({'lo': [], 'la': []})

        # JS CODE
        code_draw_red_map = """
        const data = {'gx': [], 'gy': []}
        const indices = cb_data.index.indices
        for (var i = 0; i < indices.length; i++ ) {
                data['gx'].push(source_master.data.GX[indices[i]])
                data['gy'].push(source_master.data.GY[indices[i]])
        }
        source_red_map.data = data
        """

        code_slider = """
            var data = source.data;
            var f = cb_obj.value
            var x = data['x']
            var y = data['y']
            var Y = data['Y']
            var X = data['X']
            var lat = data['LAT']
            var lon = data['LON']
            for (var i = 0; i < x.length; i++) {
                y[i] = (1-f)*lat[i] + f*Y[i]
                x[i] = (1-f)*lon[i] + f*X[i]
            }
            source.change.emit();
        """

        # FIGURES
        curr_time = ebu.get_bolivian_time(-3)

        pw = self.FIG_WIDTH

        callback_red_map = CustomJS(
            args={'source_master': source_master,
                  'source_red_map': source_red_map, },
            code=code_draw_red_map)

        hover_cart = bokeh.models.HoverTool(
            tooltips=self.TOOL_TIP_DIC[frente],
            callback=callback_red_map,
            # renderers = [red_scat_car]

        )

        cart_fig = Figure(plot_width=pw, plot_height=pw,
                          output_backend="webgl", )
        cart_fig.background_fill_color = "grey"
        cart_fig.background_fill_alpha = .5
        cart_fig.scatter('x', 'y', source=source_master, radius='r', color=cm)
        cart_fig.add_tools(hover_cart, )

        title = "Última actualización: " + curr_time["datetime_val"].strftime(
            "%Y-%m-%d %H:%M") + "BOT"


        map_fig = Figure(plot_width=pw, plot_height=pw,
                         x_axis_type='mercator',
                         y_axis_type='mercator',
                         output_backend="webgl",
                         title=title,
                         )

        # cb_fig = bokeh.plotting.Figure(plot_height=pw,plot_width=)
        # cb_fig.toolbar.logo = None
        # cb_fig.toolbar_location = None

        # SCATTER
        # noinspection PyUnresolvedReferences
        # add tiles
        tile_provider = bokeh.tile_providers.get_provider(
            bokeh.tile_providers.Vendors.CARTODBPOSITRON)
        map_fig.add_tile(tile_provider)

        # scatter in map
        map_fig.scatter(
            'GX', 'GY', source=source_master, size='r2',
            color=cm
        )

        # todo if we wont use map then we nee to delete the source
        # cart_fig.line('lo', 'la', source=source_bol, color='black')

        # noinspection PyUnusedLocal
        red_scat_map = map_fig.circle_cross('gx', 'gy',
                                            source=source_red_map,
                                            fill_color=None,
                                            size=20,
                                            line_color="white",
                                            line_width=4
                                            )

        # noinspection PyUnusedLocal
        red_scat_map = map_fig.circle_cross('gx', 'gy',
                                            source=source_red_map,
                                            fill_color=None,
                                            size=20,
                                            line_color="red",
                                            line_width=1
                                            )
        # red_scat_car = cart_fig.scatter('lo', 'la',
        # source=source_red_car, color='green')

        # add a hover tool that sets the link data for a hovered circle

        # callbacks

        # code = code_merged)

        # callback_red_car = CustomJS(
        # args={'source_master': source_master, 'source_red_car': source_red_car},
        # code=code_draw_red_car)

        # tools

        hover_map = bokeh.models.HoverTool(
            tooltips=self.TOOL_TIP_DIC[frente],
            # callback=callback_red_car,
            # renderers = [red_scat_map]
        )
        map_fig.add_tools(hover_map, )

        # slider
        callback_slider = CustomJS(args=dict(source=source_master),
                                   code=code_slider)

        slider = Slider(start=0, end=1, value=cart_init_val, step=.02,
                        title="carto")
        slider.js_on_change('value', callback_slider)

        # COLOR BAR
        ml = {int(i): str(np.abs(i)) for i in np.arange(-80, 81, 20)}
        cb = bokeh.models.ColorBar(
            color_mapper=cm['transform'],
            # width=int(.9 * 450),
            width='auto',
            location=(0, 0),
            #     title="DEN (N/km^2)",
            # title=(BAR_TITLE),
            # margin=0,padding=0,
            title_standoff=10,
            # ticker=bokeh.models.LogTicker(),
            orientation='horizontal',
            major_label_overrides=ml

        )

        cart_fig.add_layout(cb, 'above')
        # cb.title_text_align = 'left'
        cart_fig.title.text = self.BAR_TITLE_DIC[frente]
        cart_fig.title.align = 'center'

        # layout = row(column(slider, cart_f),map_f)
        layout = bokeh.layouts.gridplot(
            [[slider, None], [cart_fig, map_fig]], sizing_mode='scale_width',
            merge_tools=False)
        layout.max_width = 1400
        # layout = bokeh.layouts.column([slider, cart_fig])

        cart_fig.x_range.start = self.CXS
        cart_fig.x_range.end = self.CXE
        cart_fig.y_range.start = self.CYS
        cart_fig.y_range.end = self.CYE

        _ll = ebu.lola_to_cart(lo=[self.MXS, self.MXE], la=[self.MYS, self.MYE])
        map_fig.x_range.start = _ll[0][0]
        map_fig.x_range.end = _ll[0][1]
        map_fig.y_range.start = _ll[1][0]
        map_fig.y_range.end = _ll[1][1]

        cart_fig.xaxis.major_tick_line_color = None
        # turn off x-axis major ticks
        cart_fig.xaxis.minor_tick_line_color = None
        # turn off x-axis minor ticks
        cart_fig.yaxis.major_tick_line_color = None
        # turn off y-axis major ticks
        cart_fig.yaxis.minor_tick_line_color = None
        cart_fig.xaxis.major_label_text_font_size = '0pt'
        # turn off x-axis tick labels
        cart_fig.yaxis.major_label_text_font_size = '0pt'
        # turn off y-axis tick labels
        nam = 'z037_' + frente + '_' + name_file + '.html'
        nam_lat = 'z037_' + frente + '_' + 'latest' + '.html'
        nam1 = os.path.join(path, nam)

        nam2 = os.path.join(os.path.dirname(ebu.DIR), 'docs',
                            'graficas_htmls',
                            nam_lat)
        # bokeh.plotting.output_file(nam2)
        if show_plot:

            bokeh.plotting.show(layout)

        bokeh.plotting.save(layout, nam1)
        bokeh.plotting.save(layout, nam2)

        return data
Exemplo n.º 12
0
             tools=["wheel_zoom", "pan"],
             x_range=(-13000000, -7000000),
             y_range=(2750000, 6250000),
             webgl=True,
             active_scroll="wheel_zoom")
fig.axis.visible = False

STAMEN_TONER_BACKGROUND = WMTSTileSource(
    url='http://tile.stamen.com/toner-background/{Z}/{X}/{Y}.png',
    attribution=
    ('Map tiles by <a href="http://stamen.com">Stamen Design</a>, '
     'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>.'
     'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, '
     'under <a href="http://www.openstreetmap.org/copyright">ODbL</a>'))

fig.add_tile(STAMEN_TONER_BACKGROUND)

accidents.loc[accidents.DRUNK_DR != 0, "DRUNK_DR"] = "YES"
accidents.loc[accidents.DRUNK_DR == 0, "DRUNK_DR"] = "NO"
accidents.loc[accidents.SP != 0, "SP"] = "YES"
accidents.loc[accidents.SP == 0, "SP"] = "NO"
accidents.loc[accidents.WEATHER.isin([0, 1, 8, 10, 98, 99]),
              "WEATHER"] = "Clear"
accidents.loc[accidents.WEATHER == 2, "WEATHER"] = "Rain"
accidents.loc[accidents.WEATHER == 3, "WEATHER"] = "Sleet/Hail"
accidents.loc[accidents.WEATHER == 4, "WEATHER"] = "Snow"
accidents.loc[accidents.WEATHER == 5, "WEATHER"] = "Fog/Smog/Smoke"
accidents.loc[accidents.WEATHER == 6, "WEATHER"] = "Severe Crosswinds"
accidents.loc[accidents.WEATHER == 7, "WEATHER"] = "Blowing Sand, Soil, Dirt"
accidents.loc[accidents.WEATHER == 11, "WEATHER"] = "Blowing Snow"
accidents.loc[accidents.WEATHER == 12, "WEATHER"] = "Freezing Rain"
Exemplo n.º 13
0
fig = Figure(plot_width=1100, plot_height=650, tools=["wheel_zoom", "pan"],
            x_range=(-13000000, -7000000), y_range=(2750000, 6250000), webgl=True,
            active_scroll="wheel_zoom")
fig.axis.visible = False

STAMEN_TONER_BACKGROUND = WMTSTileSource(
    url='http://tile.stamen.com/toner-background/{Z}/{X}/{Y}.png',
    attribution=(
        'Map tiles by <a href="http://stamen.com">Stamen Design</a>, '
        'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>.'
        'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, '
        'under <a href="http://www.openstreetmap.org/copyright">ODbL</a>'
    )
)

fig.add_tile(STAMEN_TONER_BACKGROUND)

accidents.loc[accidents.DRUNK_DR != 0, "DRUNK_DR"] = "YES"
accidents.loc[accidents.DRUNK_DR == 0, "DRUNK_DR"] = "NO"
accidents.loc[accidents.SP != 0, "SP"] = "YES"
accidents.loc[accidents.SP == 0, "SP"] = "NO"
accidents.loc[accidents.WEATHER.isin([0,1,8,10,98,99]), "WEATHER"] = "Clear"
accidents.loc[accidents.WEATHER == 2, "WEATHER"] = "Rain"
accidents.loc[accidents.WEATHER == 3, "WEATHER"] = "Sleet/Hail"
accidents.loc[accidents.WEATHER == 4, "WEATHER"] = "Snow"
accidents.loc[accidents.WEATHER == 5, "WEATHER"] = "Fog/Smog/Smoke"
accidents.loc[accidents.WEATHER == 6, "WEATHER"] = "Severe Crosswinds"
accidents.loc[accidents.WEATHER == 7, "WEATHER"] = "Blowing Sand, Soil, Dirt"
accidents.loc[accidents.WEATHER == 11, "WEATHER"] = "Blowing Snow"
accidents.loc[accidents.WEATHER == 12, "WEATHER"] = "Freezing Rain"
Exemplo n.º 14
0
    # Create plot -------------------------------
    xmin = -8240227.037
    ymin = 4974203.152
    xmax = -8231283.905
    ymax = 4979238.441

    path = './data/projected.tif'

    fig = Figure(x_range=(xmin, xmax),
                 y_range=(ymin, ymax),
                 plot_height=600,
                 plot_width=900,
                 tools='pan,wheel_zoom')
    fig.background_fill_color = 'black'
    fig.add_tile(get_provider("STAMEN_TONER"),
                 alpha=0)  # used to set axis ranges
    fig.x_range.callback = CustomJS(code=dims_jscode,
                                    args=dict(plot=fig, dims=dims))
    fig.y_range.callback = CustomJS(code=dims_jscode,
                                    args=dict(plot=fig, dims=dims))
    fig.axis.visible = False
    fig.grid.grid_line_alpha = 0
    fig.min_border_left = 0
    fig.min_border_right = 0
    fig.min_border_top = 0
    fig.min_border_bottom = 0

    image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
    fig.image_rgba(source=image_source,
                   image='image',
                   x='x',
Exemplo n.º 15
0
    def plot_carto_single(self,
                          data,
                          frente,
                          palette,
                          name_file="test.html",
                          low=0,
                          high=100):
        """

        :param data: df loaded by data_load
        :param frente: string, name of "partido" lowercase: diff, mas, cc, creemos, fpv, panbol
        :param palette: ej: P_GRAD_CC
        :param name_file: default:test
        :param low: cmap low limit: default: -80
        :param high: cmap high limit: defauilt: +80.
        :return: df
        """
        if frente == "diff":
            low = self.C_BAR_LOW
            high = self.C_BAR_HIGH
            frente = "d_mas_cc"

        bokeh.plotting.output_file(self.FILE_OUT + '_' + frente + '_' +
                                   name_file)
        cart_init_val = self.CART_SLIDER_INIT  # add slider
        data['x'] = data['LON'] * (1 -
                                   cart_init_val) + data['X'] * cart_init_val
        data['y'] = data['LAT'] * (1 -
                                   cart_init_val) + data['Y'] * cart_init_val
        cm = linear_cmap(frente, palette=palette, low=low, high=high)

        data['mas'] = data['MAS'] / data['VV'] * 100
        data['cc'] = data['CC'] / data['VV'] * 100
        data['pdc'] = data['PDC'] / data['VV'] * 100
        #data['creemos'] = data['CREEMOS'] / data['VV'] * 100
        #data['fpv'] = data['FPV'] / data['VV'] * 100
        #data['panbol'] = data['PANBOL'] / data['VV'] * 100
        data['ad_mas_cc'] = data['d_mas_cc'].abs()
        data['mas_o_cc'] = 'n'
        data.loc[data['d_mas_cc'] >= 0, 'mas_o_cc'] = 'MAS'
        data.loc[data['d_mas_cc'] < 0, 'mas_o_cc'] = 'CC'

        source_master = ColumnDataSource(data)
        source_red_map = ColumnDataSource({'gx': [], 'gy': []})
        la, lo = ebu.get_la_lo_bolivia()
        source_bol = ColumnDataSource({'la': la, 'lo': lo})
        # source_red_car = ColumnDataSource({'lo': [], 'la': []})

        # JS CODE
        code_draw_red_map = """
        const data = {'gx': [], 'gy': []}
        const indices = cb_data.index.indices
        for (var i = 0; i < indices.length; i++ ) {
                data['gx'].push(source_master.data.GX[indices[i]])
                data['gy'].push(source_master.data.GY[indices[i]])
        }
        source_red_map.data = data
        """

        code_draw_red_car = """
        const data = {'lo': [], 'la': []}
        const indices = cb_data.index.indices
        for (var i = 0; i < indices.length; i++) {
                data['lo'].push(source_master.data.x[indices[i]])
                data['la'].push(source_master.data.y[indices[i]])
        }
        source_red_car.data = data
        """

        code_merged = """
        const data_map = {'lo': [], 'la': []}
        const data_car = {'gx': [], 'gy': []}
        const indices = cb_data.index.indices
        for (var i = 0; i < indices.length; i++) {
                data_map['lo'].push(source_master.data.x[indices[i]])
                data_map['la'].push(source_master.data.y[indices[i]])
                data_car['gx'].push(source_master.data.GX[indices[i]])
                data_car['gy'].push(source_master.data.GY[indices[i]])
        }
        source_red_car.data = data_car
        source_red_map.data = data_map
        """

        code_slider = """
            var data = source.data;
            var f = cb_obj.value
            var x = data['x']
            var y = data['y']
            var Y = data['Y']
            var X = data['X']
            var lat = data['LAT']
            var lon = data['LON']
            for (var i = 0; i < x.length; i++) {
                y[i] = (1-f)*lat[i] + f*Y[i]
                x[i] = (1-f)*lon[i] + f*X[i]
            }
            source.change.emit();
        """

        # FIGURES
        pw = self.FIG_WIDTH
        cart_fig = Figure(plot_width=pw,
                          plot_height=pw,
                          output_backend="webgl")
        map_fig = Figure(
            plot_width=pw,
            plot_height=pw,
            x_axis_type='mercator',
            y_axis_type='mercator',
            output_backend="webgl",
        )
        cart_fig.background_fill_color = "grey"
        cart_fig.background_fill_alpha = .5
        # cb_fig = bokeh.plotting.Figure(plot_height=pw,plot_width=)
        # cb_fig.toolbar.logo = None
        # cb_fig.toolbar_location = None

        # SCATTER
        # noinspection PyUnresolvedReferences
        # add tiles
        tile_provider = bokeh.tile_providers.get_provider(
            bokeh.tile_providers.Vendors.CARTODBPOSITRON)
        map_fig.add_tile(tile_provider)

        # scatter in map
        map_fig.scatter('GX', 'GY', source=source_master, size='r2', color=cm)

        # todo if we wont use map then we nee to delete the source
        # cart_fig.line('lo', 'la', source=source_bol, color='black')
        cart_fig.scatter('x', 'y', source=source_master, radius='r', color=cm)

        red_scat_map = map_fig.circle_cross(
            'gx',
            'gy',
            source=source_red_map,
            #                                color='red',
            fill_color=None,
            #                                line_color='green',
            size=20,
            line_color="white",
            line_width=4)

        red_scat_map = map_fig.circle_cross(
            'gx',
            'gy',
            source=source_red_map,
            #                                color='red',
            fill_color=None,
            #                                line_color='green',
            size=20,
            line_color="red",
            line_width=1)
        # red_scat_car = cart_fig.scatter('lo', 'la',
        # source=source_red_car, color='green')

        # add a hover tool that sets the link data for a hovered circle

        # callbacks
        callback_red_map = CustomJS(
            args={
                'source_master': source_master,
                'source_red_map': source_red_map,
                # 'source_red_car':source_red_car
            },
            code=code_draw_red_map)
        # code = code_merged)

        # callback_red_car = CustomJS(
        #     args={'source_master': source_master, 'source_red_car': source_red_car},
        #     code=code_draw_red_car)

        # tools

        hover_cart = bokeh.models.HoverTool(
            tooltips=self.TOOL_TIP_DIC[frente],
            callback=callback_red_map,
            # renderers = [red_scat_car]
        )
        cart_fig.add_tools(hover_cart, )

        hover_map = bokeh.models.HoverTool(
            tooltips=self.TOOL_TIP_DIC[frente],
            # callback=callback_red_car,
            # renderers = [red_scat_map]
        )
        map_fig.add_tools(hover_map, )

        # slider
        callback_slider = CustomJS(args=dict(source=source_master),
                                   code=code_slider)

        slider = Slider(start=0,
                        end=1,
                        value=cart_init_val,
                        step=.02,
                        title="carto")
        slider.js_on_change('value', callback_slider)

        # COLOR BAR
        ml = {int(i): str(np.abs(i)) for i in np.arange(-80, 81, 20)}
        cb = bokeh.models.ColorBar(
            color_mapper=cm['transform'],
            width=int(.9 * self.FIG_WIDTH),
            location=(0, 0),
            #     title="DEN (N/km^2)",
            # title=(BAR_TITLE),
            # margin=0,padding=0,
            title_standoff=10,
            # ticker=bokeh.models.LogTicker(),
            orientation='horizontal',
            major_label_overrides=ml)

        cart_fig.add_layout(cb, 'above')
        # cb.title_text_align = 'left'
        cart_fig.title.text = self.BAR_TITLE_DIC[frente]
        cart_fig.title.align = 'center'

        # layout = row(column(slider, cart_f),map_f)
        layout = bokeh.layouts.gridplot([[slider, None], [cart_fig, map_fig]],
                                        merge_tools=False)
        # layout = bokeh.layouts.column([slider, cart_fig])

        cart_fig.x_range.start = self.CXS
        cart_fig.x_range.end = self.CXE
        cart_fig.y_range.start = self.CYS
        cart_fig.y_range.end = self.CYE

        _ll = ebu.lola_to_cart(lo=[self.MXS, self.MXE],
                               la=[self.MYS, self.MYE])
        map_fig.x_range.start = _ll[0][0]
        map_fig.x_range.end = _ll[0][1]
        map_fig.y_range.start = _ll[1][0]
        map_fig.y_range.end = _ll[1][1]

        cart_fig.xaxis.major_tick_line_color = None  # turn off x-axis major ticks
        cart_fig.xaxis.minor_tick_line_color = None  # turn off x-axis minor ticks
        cart_fig.yaxis.major_tick_line_color = None  # turn off y-axis major ticks
        cart_fig.yaxis.minor_tick_line_color = None
        cart_fig.xaxis.major_label_text_font_size = '0pt'  # turn off x-axis tick labels
        cart_fig.yaxis.major_label_text_font_size = '0pt'  # turn off y-axis tick labels

        bokeh.plotting.show(layout)
        return data