In [1]:
import numpy as np
import pandas as pd
from bokeh.plotting import figure 
from bokeh.io import output_notebook, show
from bokeh.transform import factor_cmap
from bokeh.palettes import Category20
from bokeh.models import HoverTool, ColumnDataSource
output_notebook()
Loading BokehJS ...
In [2]:
from data.loader import get_kasios_obs, get_obs, map_path

Loading Data

All Birds file

In [3]:
df = get_obs(songs = False)
df['alpha'] = 1

Test Birds file

In [4]:
df_test = get_kasios_obs(songs = False)
df_test["name"] = "Test bird n° " + df_test.index.astype(str)
df_test["color"] = "red"

Map visualization with Bokeh

In [5]:
source = ColumnDataSource(data=dict(
    x=df['X'],
    y=df['Y'],
    name=df["English_name"],
    color = df["color"]
))

source_test = ColumnDataSource(data=dict(
    x=df_test['X'],
    y=df_test['Y'],
    name=df_test["name"],
    number=df_test.index
))

source_dumping = ColumnDataSource(data=dict(
    x=[148],
    y=[159],
    name=[""]
))


TOOLS="crosshair,pan,wheel_zoom,zoom_in,zoom_out,box_zoom,undo,redo,reset,tap,save,box_select,poly_select,lasso_select,"

# put details on cursor
hover = HoverTool()
hover.tooltips = [
    ("Bird type", "@name"),
    ("Position", "(@x, @y)"),
]

p = figure(x_range=(0,200), y_range=(0,200), tools=TOOLS, 
          title='Map with all the species and the Kasios test birds')

p.tools.append(hover)

# plot map
p.image_url(url=[map_path],
            x=0, y=0, w=200, h=200, anchor="bottom_left")

# plot all birds
p.scatter("x", "y", size=7, alpha=0.6, color="color", source=source)

# plot the 15 "test birds"
p.scatter("x", "y", size=20, color="red", source=source_test, legend="Test birds",
          alpha=0.8)
p.text('x', 'y', text='number', x_offset=-5, y_offset=8,
       source=source_test, text_font_size='10pt', text_color='white')

# location of the dumping site
p.scatter("x", "y", size=30, marker="circle_cross", fill_alpha=0.2, line_width=2, 
          source = source_dumping, legend="Dumping site")

show(p)
In [6]:
df_blue_pipit = df.loc[df['English_name'] == 'Rose-crested Blue Pipit']

source = ColumnDataSource(data=dict(
    x=df_blue_pipit['X'],
    y=df_blue_pipit['Y'],
    name=df_blue_pipit['English_name']
))

source_test = ColumnDataSource(data=dict(
    x=df_test['X'],
    y=df_test['Y'],
    name=df_test['name'],
    number=df_test.index
))

source_dumping = ColumnDataSource(data=dict(
    x=[148],
    y=[159],
    name=[""]
))


TOOLS="crosshair,pan,wheel_zoom,zoom_in,zoom_out,box_zoom,undo,redo,reset,tap,save,box_select,poly_select,lasso_select,"

# put details on cursor
hover = HoverTool()
hover.tooltips = [
    ("Bird type", "@name"),
    ("Position", "(@x, @y)"),
]

p = figure(x_range=(0,200), y_range=(0,200), tools=TOOLS,
          title='Map with the Blue Pipits and the Kasios test birds')

p.tools.append(hover)

# plot map
p.image_url(url=[map_path],
            x=0, y=0, w=200, h=200, anchor="bottom_left")

# plot all birds
p.scatter(x="x", y="y", size=7, alpha=0.6, color="dodgerblue", source=source, 
          legend='Blue Pipit')

# plot the 15 "test birds"
p.scatter(x="x", y="y", size=20, color="red", source=source_test, 
          alpha=0.8, legend="Kasios Test birds")
p.text('x', 'y', text='number', x_offset=-5, y_offset=8,
       source=source_test, text_font_size='10pt', text_color='white')

# location of the dumping site
p.scatter(x="x", y="y", size=30, marker="circle_cross", fill_alpha=0.2, line_width=2, 
          source = source_dumping, legend="Dumping site")

show(p)
Check the interactive visualizations in the notebook "2_dynamic_map.ipynb".