{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Check `GDS` Python stack\n", "\n", "This notebook checks all software requirements for the course Geographic Data Science are correctly installed. \n", "\n", "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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import bokeh as bk\n", "float(bk.__version__[:1]) >= 1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib as mpl\n", "float(mpl.__version__[:3]) >= 1.5" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import mplleaflet as mpll" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import seaborn as sns\n", "float(sns.__version__[:3]) >= 0.6" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import datashader as ds\n", "float(ds.__version__[:3]) >= 0.6" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import palettable as pltt\n", "float(pltt.__version__[:3]) >= 3.1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sns.palplot(pltt.matplotlib.Viridis_10.hex_colors)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import qgrid" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "float(pd.__version__[:4]) >= 0.18" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import dask\n", "float(dask.__version__[:1]) >= 1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sklearn\n", "float(sklearn.__version__[:4]) >= 0.20" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import statsmodels.api as sm\n", "float(sm.version.version[:3]) >= 0.9" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pymc3 as pm\n", "float(pm.__version__[:3]) >= 3.6 " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import xlrd" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import xlsxwriter" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import networkx as nx" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import osmnx" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import fiona\n", "float(fiona.__version__[:3]) >= 1.8" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import geopandas as gpd\n", "float(gpd.__version__[:3]) >= 0.4" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "import pysal as ps\n", "float(ps.__version__[:1]) >= 2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import rasterio as rio\n", "float(rio.__version__[:1]) >= 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Test" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "shp = ps.lib.examples.get_path('columbus.shp')\n", "db = gpd.read_file(shp)\n", "db.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "db[['AREA', 'PERIMETER']].to_feather('db.feather')\n", "tst = pd.read_feather('db.feather')\n", "! rm db.feather" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "f, ax = plt.subplots(1)\n", "db.plot(facecolor='yellow', ax=ax)\n", "ax.set_axis_off()\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "db.crs['init'] = 'epsg:26918'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "db_wgs84 = db.to_crs(epsg=4326)\n", "db_wgs84.plot()\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pysal.viz.splot.mapping import vba_choropleth\n", "\n", "f, ax = vba_choropleth(db['INC'], db['HOVAL'], db)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "# Out until geopandas 0.5 comes in\n", "#db.plot(column='INC', scheme='fisher_jenks', cmap=plt.matplotlib.cm.Blues)\n", "#plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "city = osmnx.gdf_from_place('Berkeley, California')\n", "osmnx.plot_shape(osmnx.project_gdf(city));" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import contextily as ctx\n", "tl = ctx.tile_providers.ST_TONER_LITE\n", "\n", "db = gpd.read_file(ps.lib.examples.get_path('us48.shp'))\n", "db.crs = {'init': 'epsg:4326'}\n", "w, s, e, n = db.to_crs(epsg=3857).total_bounds\n", "dbp = db.to_crs(epsg=3857)\n", "# Download raster\n", "_ = ctx.bounds2raster(w, s, e, n, 'us.tif', url=tl)\n", "# Load up and plot\n", "source = rio.open('us.tif', 'r')\n", "red = source.read(1)\n", "green = source.read(2)\n", "blue = source.read(3)\n", "pix = np.dstack((red, green, blue))\n", "bounds = (source.bounds.left, source.bounds.right, \\\n", " source.bounds.bottom, source.bounds.top)\n", "f = plt.figure(figsize=(6, 6))\n", "ax = plt.imshow(pix, extent=bounds)\n", "\n", "! rm us.tif" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = db.to_crs(epsg=3857).plot()\n", "ctx.add_basemap(ax)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, basemaps, basemap_to_tiles, SplitMapControl\n", "\n", "m = Map(center=(42.6824, 365.581), zoom=5)\n", "\n", "right_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, \"2017-11-11\")\n", "left_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisAquaBands721CR, \"2017-11-11\")\n", "\n", "control = SplitMapControl(left_layer=left_layer, right_layer=right_layer)\n", "m.add_control(control)\n", "\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }