GDS
Python stack¶This notebook checks all software requirements for the course Geographic Data Science are correctly installed.
A successful run of the notebook implies no errors returned in any cell and every cell beyond the first one returning a printout of True
. This ensures a correct environment installed.
import black
import bokeh
import boto3
import bottleneck
import cenpy
import contextily
import cython
import dask
import dask_ml
import datashader
import geopandas
import geopy
import h3
import hdbscan
import ipyleaflet
import ipympl
import ipyparallel
import ipywidgets
import legendgram
import momepy
import nbdime
import netCDF4
import networkx
import osmnx
import palettable
import pandana
import polyline
import pyarrow
import pygeos
import pyrosm
import pysal
import qgrid
import rasterio
import rasterstats
import rio_cogeo
import rioxarray
import skimage
import sklearn
import seaborn
import spatialpandas
import statsmodels
import xarray_leaflet
import xrspatial
import xlrd
import xlsxwriter
pip
installs:
import ablog
import jupyter_book
import keplergl
try:
import pygeoda
except:
import warnings
warnings.warn("pygeoda not installed. This may be "\
"because the check it's not running on the "\
"official container")
import pytest_cov
import pytest_tornasync
import sphinx_press_theme
Legacy checks (in some ways superseded by those above but in some still useful)
import bokeh as bk
float(bk.__version__[:1]) >= 1
import matplotlib as mpl
float(mpl.__version__[:3]) >= 1.5
import seaborn as sns
float(sns.__version__[:3]) >= 0.6
import datashader as ds
float(ds.__version__[:3]) >= 0.6
import palettable as pltt
float(pltt.__version__[:3]) >= 3.1
sns.palplot(pltt.matplotlib.Viridis_10.hex_colors)
import pandas as pd
float(pd.__version__[:3]) >= 1
import dask
float(dask.__version__[:1]) >= 1
import sklearn
float(sklearn.__version__[:4]) >= 0.20
import statsmodels.api as sm
float(sm.__version__[2:4]) >= 10
import fiona
float(fiona.__version__[:3]) >= 1.8
import geopandas as gpd
float(gpd.__version__[:3]) >= 0.4
import pysal as ps
float(ps.__version__[:1]) >= 2
import rasterio as rio
float(rio.__version__[:1]) >= 1
from pysal import lib as libps
shp = libps.examples.get_path('columbus.shp')
db = geopandas.read_file(shp)
db.head()
db[['AREA', 'PERIMETER']].to_feather('db.feather')
tst = pd.read_feather('db.feather')
! rm db.feather
db.to_parquet('db.pq')
tst = gpd.read_parquet('db.pq')
! rm db.pq
import matplotlib.pyplot as plt
%matplotlib inline
f, ax = plt.subplots(1)
db.plot(facecolor='yellow', ax=ax)
ax.set_axis_off()
plt.show()
db.crs = 'EPSG:26918'
db_wgs84 = db.to_crs(epsg=4326)
db_wgs84.plot()
plt.show()
from pysal.viz import splot
from splot.mapping import vba_choropleth
f, ax = vba_choropleth(db['INC'], db['HOVAL'], db)
db.plot(column='INC', scheme='fisher_jenks', cmap=plt.matplotlib.cm.Blues)
plt.show()
city = osmnx.geocode_to_gdf('Berkeley, California, US')
osmnx.plot_footprints(osmnx.project_gdf(city));
from pyrosm import get_data
# Download data for the city of Helsinki
fp = get_data("Helsinki", directory="./")
print(fp)
# Get filepath to test PBF dataset
fp = pyrosm.get_data("test_pbf")
print("Filepath to test data:", fp)
# Initialize the OSM object
osm = pyrosm.OSM(fp)
# See the type
print("Type of 'osm' instance: ", type(osm))
from pyrosm import get_data
# Pyrosm comes with a couple of test datasets
# that can be used straight away without
# downloading anything
fp = get_data("test_pbf")
# Initialize the OSM parser object
osm = pyrosm.OSM(fp)
# Read all drivable roads
# =======================
drive_net = osm.get_network(network_type="driving")
drive_net.plot()
! rm Helsinki.osm.pbf
import numpy as np
import contextily as ctx
tl = ctx.providers.CartoDB.Positron
db = geopandas.read_file(ps.lib.examples.get_path('us48.shp'))
db.crs = "EPSG:4326"
dbp = db.to_crs(epsg=3857)
w, s, e, n = dbp.total_bounds
# Download raster
_ = ctx.bounds2raster(w, s, e, n, 'us.tif', url=tl)
# Load up and plot
source = rio.open('us.tif', 'r')
red = source.read(1)
green = source.read(2)
blue = source.read(3)
pix = np.dstack((red, green, blue))
bounds = (source.bounds.left, source.bounds.right, \
source.bounds.bottom, source.bounds.top)
f = plt.figure(figsize=(6, 6))
ax = plt.imshow(pix, extent=bounds)
ax = db.plot()
ctx.add_basemap(ax, crs=db.crs.to_string())
from ipyleaflet import Map, basemaps, basemap_to_tiles, SplitMapControl
m = Map(center=(42.6824, 365.581), zoom=5)
right_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-11-11")
left_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisAquaBands721CR, "2017-11-11")
control = SplitMapControl(left_layer=left_layer, right_layer=right_layer)
m.add_control(control)
m
# Convert us.tiff to COG with rio-cogeo
! rio cogeo create us.tif us_cog.tif
! rio cogeo validate us_cog.tif
# rioxarray + xarray_leaflet
us = rioxarray.open_rasterio("us_cog.tif")
from ipyleaflet import Map
m = Map(zoom=1, basemap=basemaps.CartoDB.DarkMatter)
m
l = us.rio.reproject("EPSG:4326").sel(band=2).leaflet.plot(m)
l.interact(opacity=(0.0,1.0))
! rm us.tif us_cog.tif
from IPython.display import GeoJSON
GeoJSON({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-118.4563712, 34.0163116]
}
})
from keplergl import KeplerGl
map_1 = KeplerGl()
map_1