Skip to content

Instantly share code, notes, and snippets.

@brendancol
brendancol / hdf_to_parquet.py
Created November 10, 2016 17:17
HDF5 Census -> Parquet
# Install fastparquet and pytables
# conda install pytables
# conda install -c conda-forge fastparquet
# conda install python-snappy
import pandas as pd
import fastparquet as fp
# Write file
df = pd.read_hdf(data_path, base)
@brendancol
brendancol / translate_alaska_hawaii.py
Last active April 23, 2021 17:38
Translating Alaska and Hawaii (Bokeh + Shapely)
import json
from bokeh.io import output_file
from bokeh.plotting import figure, show
from bokeh.models import GeoJSONDataSource
from shapely import affinity
from shapely.geometry import mapping, shape
def get_geojson():
@brendancol
brendancol / rasterio_datashader_polygons.py
Last active December 17, 2020 21:43
Datashader + Rasterio for Polygon shading (40K Polygons, 81M Vertices)
from __future__ import division
from functools import partial
import pyproj
from shapely.ops import transform
import numpy as np
from rasterio import features
from affine import Affine
import fiona
@brendancol
brendancol / snap_tiles_example.py
Last active April 10, 2025 15:41
Snapping Tile Renderer User Defined Model
from bokeh.plotting import figure, output_file, show
from bokeh.models.renderers import TileRenderer
from bokeh.tile_providers import STAMEN_TONER
from bokeh.models import Range1d
output_file('snap_tiles.html')
class SnappingTileRenderer(TileRenderer):
__implementation__ = """
_ = require "underscore"
from bokeh.models import Range1d
from bokeh.models import WMTSTileSource
from bokeh.models import ImageSource
from bokeh.plotting import figure
from bokeh.plotting import show
from bokeh.plotting import output_file
output_file('datashader_example.html')
@brendancol
brendancol / gist:e5e5c4fcf8e10f523654
Created October 21, 2015 19:34
Bokeh JavaScript API Example
function initializeMap() {
var data, i, options, r, scatter, val, x, xaxis, y, yaxis;
r = new Bokeh.Random(123456789);
var esri_natgeo_map_service = 'http://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{Z}/{Y}/{X}';
var esri_imagery_label = 'http://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{Z}/{Y}/{X}';
var osm_service = 'http://c.tile.openstreetmap.org/{Z}/{X}/{Y}.png';
var bing_service = 'http://t0.tiles.virtualearth.net/tiles/a{Q}.jpeg?g=854&mkt=en-US&token=Anz84uRE1RULeLwuJ0qKu5amcu5rugRXy1vKc27wUaKVyIv1SVZrUjqaOfXJJoI0'
git clone [email protected]:bokeh/bokeh.git
cd bokeh
git fetch --all
git checkout feature/add-tiled-basemap-renderer
python setup.py develop
python bokeh_tile_layer_example.py
from bokeh.plotting import figure, show, output_file
output_file("tile_layer_example.html", title="Tile Layer Example")
osm_service = 'http://c.tile.openstreetmap.org/{Z}/{X}/{Y}.png'
p = figure()
p.plot_width = 800
p.plot_height = 800
p.tile_layer(url=osm_service, tile_provider="WMTSTileProvider", tile_size=256)
show(p)
@brendancol
brendancol / _.md
Last active August 29, 2015 14:25 — forked from tonyfast/_.md
@brendancol
brendancol / bokeh_geographic_scatter_plot.py
Last active August 29, 2015 14:23
bokeh geographic scatter plot
from __future__ import print_function
import os
import sys
import pandas
from pysal.weights.Distance import DistanceBand
import numpy
numpy.random.seed(10)