From d2aba4f624f44817435982023261cdc6462b400c Mon Sep 17 00:00:00 2001 From: Daniel Fortunov Date: Thu, 10 May 2018 09:17:56 -0400 Subject: [PATCH] Remove .ipynb_checkpoints/ dir and add to .gitignore --- Notebook/.gitignore | 1 + .../00_Jupyter_Demo-checkpoint.ipynb | 510 ----------- .../01_Geopandas_Intro-checkpoint.ipynb | 673 --------------- .../02_Geopandas_Advanced-checkpoint.ipynb | 796 ------------------ .../03_Raster-checkpoint.ipynb | 109 --- 5 files changed, 1 insertion(+), 2088 deletions(-) create mode 100644 Notebook/.gitignore delete mode 100644 Notebook/.ipynb_checkpoints/00_Jupyter_Demo-checkpoint.ipynb delete mode 100644 Notebook/.ipynb_checkpoints/01_Geopandas_Intro-checkpoint.ipynb delete mode 100644 Notebook/.ipynb_checkpoints/02_Geopandas_Advanced-checkpoint.ipynb delete mode 100644 Notebook/.ipynb_checkpoints/03_Raster-checkpoint.ipynb diff --git a/Notebook/.gitignore b/Notebook/.gitignore new file mode 100644 index 0000000..87620ac --- /dev/null +++ b/Notebook/.gitignore @@ -0,0 +1 @@ +.ipynb_checkpoints/ diff --git a/Notebook/.ipynb_checkpoints/00_Jupyter_Demo-checkpoint.ipynb b/Notebook/.ipynb_checkpoints/00_Jupyter_Demo-checkpoint.ipynb deleted file mode 100644 index 4f85fc7..0000000 --- a/Notebook/.ipynb_checkpoints/00_Jupyter_Demo-checkpoint.ipynb +++ /dev/null @@ -1,510 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Welcome to this Jupyter Notebook!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Cells can contain markdown or Python code - this is a markdown cell" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Tour" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Take a look at the menus and buttons" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Add and delete cells (you may want to add a cell to test something along the way)\n", - "# Move cells up and down\n", - "# Clear and run multiple cells" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Intro to Python" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# This is a comment, ignored by Python. It only lasts a single line.\n", - "'''This is a doc string. \n", - "Also ignored by Python but can span multiple lines'''" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# integers\n", - "1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# variable assignment\n", - "x = 1\n", - "type(x)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# floats\n", - "2.0" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# variable assignment\n", - "y = 2.0\n", - "type(y)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# arithmetic\n", - "3 * 4" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# strings\n", - "name = 'Christy' # single quotes is fine\n", - "lastname = \"Heaton\" # double quotes is also fine, but you have to use the same type for a single string" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "name,lastname" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# indexing with strings\n", - "name[2]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# lists - mutable containers\n", - "a = [1,2,3]\n", - "b = ['house','work','pet store']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a + b" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a.append(5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# the pop method\n", - "b.pop()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "b" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# list comprehensions\n", - "[x + 2 for x in range(10)]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# tuples - immutable containers\n", - "c = (1,2,3)\n", - "d = ('house','work','pet store')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "c + d" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# this will error\n", - "c.append(5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# dictionaries\n", - "f = {'one':'house', 'two':'work','three':'pet store'}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# get the value with the key of 2\n", - "f['two']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "f['four'] = 'brewery'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "f" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# functions\n", - "\n", - "def myfun(n,m):\n", - " '''adds two numbers together'''\n", - " return n+m" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "z = myfun(6, 7)\n", - "z" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Built-in functions\n", - "# print\n", - "print('Hello world!')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# type\n", - "type('hello')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# range\n", - "list(range(10))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# zip\n", - "print(c)\n", - "print(d)\n", - "list(zip(c,d))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# casting\n", - "catcount = 2\n", - "print('I have ' + str(catcount) + ' cats')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Python and version notes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are using Python in this Jupyter Notebook, but (if you set it up differently), you can also run R, Julia, and [many other languages](https://github.com/jupyter/jupyter/wiki/Jupyter-kernels) in Jupyter Notebooks." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print('This is a Python cell!')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This Notebook is using Python verion 3. If you are used to Python 2, note some differences." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# When you divide two integers, you get a float. In Python 2, you would get an integer with any remainder cut off.\n", - "5/6" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Print statements need parenthesis. In Python 2, you didn't need them.\n", - "print('Python 3 is great!!')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# As far as I know this tutorial will also work in Python 2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## The Jupyter Notebook Workflow" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Create a variable to hold the value 100\n", - "x = 100" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# This cell remembers the value of x. We can do some processing on x.\n", - "x = x - 4" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "x" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your turn. Divide x by 2 and reassign it to the variable x" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# accidentally dividing by 3...\n", - "x = x/3" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# x should now be 48.0, but its 32.0. Oh no!\n", - "x" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Not to worry, just re-run the cells starting from when x was defined!\n", - "# A simple example, but a trick that might come in later if something gets messed up." - ] - } - ], - "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.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Notebook/.ipynb_checkpoints/01_Geopandas_Intro-checkpoint.ipynb b/Notebook/.ipynb_checkpoints/01_Geopandas_Intro-checkpoint.ipynb deleted file mode 100644 index 213601c..0000000 --- a/Notebook/.ipynb_checkpoints/01_Geopandas_Intro-checkpoint.ipynb +++ /dev/null @@ -1,673 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note: many sources were used for putting this Notebook together, often code and comments are included as-is from the original source. Sources are provided ahead of the content that was taken from them. Thank you to the creators of the many wonderful Geopandas resources already in existance!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Exploring Geopandas " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "First we need to import our libraries" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "import matplotlib as mpl\n", - "import matplotlib.pyplot as plt\n", - "\n", - "from shapely.geometry import Point\n", - "\n", - "import pandas as pd\n", - "\n", - "import geopandas as gpd\n", - "from geopandas import GeoSeries, GeoDataFrame" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's start by making some simple graphs\n", - "Source: https://github.com/geohackweek/tutorial_contents" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's check the version of the libraries we're using. Do yours look the same as mine?\n", - "mpl.__version__, pd.__version__, gpd.__version__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There are two main data structures in GeoPandas, a GeoSeries and a GeoDataFrame. These are subclasses the Pandas Series and DataFrame, respectively." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's create a GeoSeries, a vector where each entry in the vector is a set of shapes corresponding to one observation.\n", - "# We'll use a list of shapely Point objects using the Point constructor (note: you can also make Lines and Polygons)\n", - "gs = GeoSeries([Point(-120, 45), Point(-121.2, 46), Point(-122.9, 47.5)])\n", - "gs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check the type and length of our GeoSeries\n", - "type(gs), len(gs)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Coordinates are of no use unless you know their reference system. Set the projection/crs to WGS 84, aka EPSG 4326\n", - "gs.crs = {'init': 'epsg:4326'}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# We can plot our points with the plot function, with some customizations\n", - "gs.plot(marker='*', color='red', markersize=100, figsize=(4, 4))\n", - "\n", - "# We limit the bounds to our area, but this will happen by default\n", - "plt.xlim([-123, -119.8])\n", - "plt.ylim([44.8, 47.7]);" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Now let's make a GeoDataFrame, a tabular data structure that contains a GeoSeries\n", - "# Let's define a simple dictionary of lists, that we’ll use again later.\n", - "data = {'name': ['House', 'Work', 'Pet Store'],\n", - " 'lat': [45, 46, 47.5],\n", - " 'lon': [-120, -121.2, -122.9]}\n", - "print(data)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Review of using dictionaries\n", - "print(list(data.keys()))\n", - "print(list(data.values()))\n", - "print(data['name'])\n", - "print(data['name'][1])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Review the built-in zip method\n", - "x = [1, 2, 3]\n", - "y = [4, 5, 6]\n", - "zipped = zip(x, y)\n", - "list(zipped)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Now we create a list of Point shapely objects out of the X & Y coordinate lists\n", - "# Very important - the geometry is what makes the data spatial\n", - "geo = [Point(xy) for xy in zip(data['lon'], data['lat'])]\n", - "geo" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "type(geo)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# We’ll wrap up by creating a GeoSeries where we explicitly define the index values\n", - "# The index is how it orients it in a row format\n", - "gs = GeoSeries(geo, index=data['name'])\n", - "gs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Create a DataFrame using our GeoSeries\n", - "df = pd.DataFrame(data)\n", - "print(df)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# This turns our latitude and longitude \n", - "print(type(data['lon']))\n", - "data['lon']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# ...into a pandas DataFrame\n", - "print(type(df))\n", - "df['lon']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Finally we use the DataFrame and the “list-of-shapely-Point-objects” approach to create a GeoDataFrame. \n", - "gdf = GeoDataFrame(df, geometry=geo)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# There’s nothing new to visualize, but this time we’re using the plot method from a GeoDataFrame, not from a GeoSeries. \n", - "gdf.plot(marker='*', color='green', markersize=50, figsize=(3, 3))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Using Geopandas Datasets\n", - "Source: http://geopandas.org/mapping.html\n", - "\n", - "We have now made some point objects, but it's more fun to work with real data. Geopandas comes with some datasets that we can use!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Load some sample data:\n", - "world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true, - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "# Let's examine the top few rows\n", - "world.head()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Plot it\n", - "world.plot()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's play with plotting the head and tail \n", - "world.head(10).plot()\n", - "# world.tail().plot()\n", - "# world.tail(5).plot()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Plot a few objects by sorting by a column\n", - "world.sort_values('pop_est', ascending = False).head(3).plot()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# cities is another geopandas dataset. It includes points for the capitals of each country.\n", - "cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Again we'll look at the top few rows\n", - "cities.head()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Plot the cities using the default style\n", - "cities.plot()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Plot the cities using custom style\n", - "cities.plot(marker='*', color='green', markersize=5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "YOUR TURN #1: Play around with making the city dots different colors and sizes" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n", - "\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "# We can exclude Antarctica by name\n", - "world = world[(world.pop_est>0) & (world.name!=\"Antarctica\") & (world.name!=\"Fr. S. Antarctic Lands\")]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "world.plot()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "# The data came with a gdp_md_est (estimated GDP) and a pop_est (estimated population) column, \n", - "# so we can use this data to make a new column, gdp_per_cap (GDP per capita).\n", - "# Create a new column named `gdp_per_cap` and use existing columns to calculate the GDP.\n", - "world['gdp_per_cap'] = world.gdp_md_est / world.pop_est" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's take a look at the new column\n", - "world.head()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What are the 5 countries with the highest GDP?\n", - "world.sort_values('gdp_per_cap', ascending = False).head()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "# We can plot the map, coloring our countries by their gdp_per_cap value, creating a choropleth map\n", - "world.plot(column='gdp_per_cap')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "GeoPandas uses color schemes from [Color Brewer](http://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3). Check it out!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "# We can change the style using the cmap (short for `color map`) property\n", - "world.plot(column='gdp_per_cap', cmap='Oranges')\n", - "\n", - "# Try setting the cmap property to YlGn" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "See colormap options [here](https://matplotlib.org/users/colormaps.html)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "# You can change the default classification scheme, note I also changed the cmap, for fun\n", - "base = world.plot(column='gdp_per_cap', cmap='BuPu', scheme='quantiles')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "YOUR TURN #2: The scheme option can be set to 'equal_interval', 'quantiles', or 'fisher_jenks'. \n", - "Try out each one. See the difference?\n", - "\n", - "More info on classification schemes [here](http://pysal.readthedocs.io/en/latest/library/esda/mapclassify.html)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n", - "\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# We can plot the cities on top of our new choropleth map\n", - "\n", - "# Create a variable to hold our choropleth map, call it base\n", - "base = world.plot(column='gdp_per_cap', cmap='OrRd', scheme='quantiles')\n", - "\n", - "# Now when you plot the cities, set an ax property to the variable you just created\n", - "cities.plot(ax=base, marker='o', color='black', markersize=5)\n", - "\n", - "# Now you will get them both on the same map" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Geopandas is geo-enabled [Pandas](https://pandas.pydata.org/), a Python data science library, so we have everything that comes with Pandas already!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Make a plot of gdp_per_cap\n", - "fig, ax = plt.subplots(figsize=(10,8))\n", - "_ = ax.hist(world['gdp_per_cap'], bins=40)\n", - "ax.set_title(\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fig, ax = plt.subplots(figsize=(10,8))\n", - "y = world.sort_values('gdp_per_cap', ascending = False)['gdp_per_cap'][:5]\n", - "x = world.sort_values('gdp_per_cap', ascending = False)['name'][:5]\n", - "ax.bar(x,y)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Managing Projections" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Source: http://geopandas.org/projections.html\n", - "\n", - "We saw before how we can set a projection. We can also check a projection and re-project.\n", - "\n", - "When you are doing spatial analysis all of your data MUST be in the same coordinate reference system!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check original projection/coordinate system or CRS\n", - "world.crs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# It's WGS-84, a spherical coordinate system AKA 'epsg:4326'\n", - "# It can't be shown on a flat surface but when you try typically gets projected into a Platte Carree projection\n", - "# This the the CRS used by GPS/Satellites and GeoJSON\n", - "base = world.plot()\n", - "base.set_title(\"WGS84 (lat/lon)\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Set the projection to the Mercator projection (epsg=3395)\n", - "world = world.to_crs(epsg=3395)\n", - "base = world.plot()\n", - "base.set_title(\"Mercator\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Set the projection to Polar Stereographic (epsg=3995)\n", - "world = world.to_crs(epsg=3995)\n", - "base = world.plot()\n", - "base.set_title(\"Polar Stereographic\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try re-running one of the cells above where you created a plot with just world, it will now be in Polar Stereographic!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "YOUR TURN #3: Make a basemap with the Mercator projection and add `cities` to it. Hint: you will have to change the crs of `cities`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You might see some streaky lines through your Mercator projection map. This is an oddity!" - ] - } - ], - "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.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Notebook/.ipynb_checkpoints/02_Geopandas_Advanced-checkpoint.ipynb b/Notebook/.ipynb_checkpoints/02_Geopandas_Advanced-checkpoint.ipynb deleted file mode 100644 index 39cb628..0000000 --- a/Notebook/.ipynb_checkpoints/02_Geopandas_Advanced-checkpoint.ipynb +++ /dev/null @@ -1,796 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Spatial Problem: In what cities will we be able to see upcoming solar eclipses?" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "An eclipse of the sun, or solar eclipse, happens when the moon moves between the sun and Earth. When this happens, the moon blocks the light of the sun from reaching Earth. There was a widely publicized solar eclipse that passed over the contiguous United States in 2017. Let's re-live the excitment by finding out where we can see solar eclipses in the future, using Python!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "First we need to import our libraries" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "import matplotlib.pyplot as plt\n", - "\n", - "import pandas as pd\n", - "import geopandas as gpd\n", - "#from geopandas import GeoSeries, GeoDataFrame\n", - "\n", - "# new imports \n", - "import os\n", - "data_pth = \"../Data/\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now to use some of our own data!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Look in your Data directory to see this shapefile\n", - "eclipses = gpd.read_file(os.path.join(data_pth, \"Eclipses.shp\"))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's see what we've got in tabular format\n", - "eclipses.head()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Another way to view tabular data is to transpose rows and columns\n", - "eclipses.head().T" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check the coordinate reference system of our data, its crs\n", - "eclipses.crs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Now we plot. Note that for simplicity and asthetics some eclipses were removed\n", - "# from the dataset or clipped if they crossed the International Date Line\n", - "eclipses.plot()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Examine what the envelope of our data looks like. This comes in handy sometimes when you want to simplify\n", - "# your data, or if you want to zoom to a certain object's extent\n", - "eclipses.envelope.plot()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# We can examine number of shapes/records for each year\n", - "eclipses['Year'].value_counts()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Where exactly are these paths? Let's add our basemap to make this clear.\n", - "world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))\n", - "base = world.plot(color='lightgrey', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "# Pass ax=base to the second layer\n", - "eclipses.plot(ax=base)\n", - "# There is an axis by default. You can see it if you comment out the below.\n", - "base.set_axis_off()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's load in the cities provided by geopandas. Note these are just the capitals.\n", - "cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Now we'll plot our basemap, our eclipse paths, and our cities\n", - "base = world.plot(color='lightgrey', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "eclipses.plot(ax=base)\n", - "cities.plot(marker='*', color='yellow', markersize=5, ax=base)\n", - "base.axis('off')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# But we want MORE cities, so let's use our own. This is a local shapefile in your data directory.\n", - "cities = gpd.read_file(os.path.join(data_pth, \"ne_10m_populated_places.shp\"))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cities.head()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check the crs of our new cities data\n", - "cities.crs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Is the cities data still in the same crs as the eclipse data? Let's check.\n", - "eclipses.crs == cities.crs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Great. Let's plot it all again\n", - "base = world.plot(color='lightgrey', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "eclipses.plot(ax=base)\n", - "cities.plot(marker='*', color='yellow', markersize=5, ax=base)\n", - "base.axis('off')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's change our eclipse colors and transparency\n", - "base = world.plot(color='lightgrey', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "eclipses.plot(ax=base, cmap='tab10', alpha=0.5)\n", - "cities.plot(marker='*', color='yellow', markersize=5, ax=base)\n", - "base.axis('off')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# We can examine the years that we have data for\n", - "eclipses['Year']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# But how do we know which is which?\n", - "base = world.plot(color='lightgrey', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "\n", - "# We can add a catetorical value and set the column to Year. We can also add a legend.\n", - "eclipses.plot(ax=base, cmap='tab10', categorical=True, alpha=0.5, column = \"Year\", legend=True)\n", - "base.axis('off')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's get that legend out of the way.\n", - "base.get_legend().set_bbox_to_anchor((.05,.7))\n", - "base.get_figure()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Which eclipses will cover the largest population?" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Instead of coloring the eclipses by year, we want to color based on the number of people that ought to be able to see them" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Start by getting all the cities that intersect any eclipse\n", - "allecities = gpd.sjoin(cities, eclipses, how='inner', op='intersects')\n", - "allecities.head().T" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "allecities = pd.DataFrame(allecities[['POP_MAX', 'Year']])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "allecities.head()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Create a temporary variable to hold our years and populations\n", - "g = allecities.groupby(['Year'])[[\"POP_MAX\"]].sum()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "g" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "eclipses_pop = pd.merge(eclipses, g, left_on='Year', right_index=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "eclipses_pop.head().T" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "base = world.plot(color='lightgrey', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "eclipses_pop.plot(ax=base, cmap='Oranges', categorical=True, alpha=0.5, column = \"POP_MAX\", legend=True)\n", - "base.axis('off')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "g.sort_values('POP_MAX', ascending = False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Are any eclipses passing over Cleveland?" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can find out by intersecting the cities with the eclipse paths, then seeing if Cleveland is in the result!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's create a variable to just hold the Cleveland city point\n", - "mycity = cities.loc[cities['NAME'] == 'Cleveland']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Now we can use sjoin and intersects to find out of Cleveland intersects any eclipse paths\n", - "emycity = gpd.sjoin(mycity, eclipses, how='inner', op='intersects')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def eresult(city, eclipse):\n", - " if len(city) > 0:\n", - " return '{} eclipse(s) will pass through {}. Year(s): {}'.format(len(eclipse), list(city['NAME'])[0], [y for y in eclipse['Year']])\n", - " else:\n", - " return 'No eclipses passing through {}'.format(list(city['NAME'])[0])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "eresult(mycity, emycity)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# There is one! Let's assign that eclipse to a variable.\n", - "# This will only work if there is a 1:1 city:eclipse, hence the if/else. This will help if you want to try another city.\n", - "if len(emycity) > 1:\n", - " print('What luck! This city has more than one eclipse! But a city that has just has one.')\n", - "elif len(emycity) == 1:\n", - " emycity = eclipses.loc[eclipses['Year'] == int(emycity['Year'])]\n", - "else:\n", - " print('There are no eclipses in your city')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Plot it!\n", - "base = world.plot(color='lightgray', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "if len(emycity) > 0:\n", - " emycity.plot(ax=base, color='black', edgecolor='yellow', alpha=0.5, legend=True)\n", - " bounds = emycity.geometry.bounds\n", - "mycity.plot(marker='*', color='red', markersize=500, ax=base)\n", - "\n", - "# Zoom to the bounds of the eclipse by setting the bounds to the min/max x/y of your layer\n", - "plt.xlim([bounds.minx.min()-5, bounds.maxx.max()+5])\n", - "plt.ylim([bounds.miny.min()-5, bounds.maxy.max()+5])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Are there any eclipses passing over your city?" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Which Eclipse Do You Want to Map?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's look at our options again\n", - "eclipses['Year']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# And plot again\n", - "base = world.plot(color='lightgrey', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "eclipses.plot(ax=base, cmap='tab10', categorical=True, alpha=0.5, column = \"Year\", legend=True)\n", - "base.axis('off')\n", - "base.get_legend().set_bbox_to_anchor((.05,.7))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# I'll pick the one from 2017, it was on my birthday after all.\n", - "myeclipse = eclipses[(eclipses['Year'] == 2017)]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's plot it \n", - "base = world.plot(color='lightgrey', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "myeclipse.plot(ax=base)\n", - "cities.plot(marker='*', color='yellow', markersize=5, ax=base)\n", - "base.axis('off')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Plot again, but this time I want to zoom in on my chosen eclipse path\n", - "base = world.plot(color='lightgrey', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "myeclipse.plot(ax=base)\n", - "cities.plot(marker='*', color='yellow', markersize=5, ax=base)\n", - "bounds = myeclipse.geometry.bounds\n", - "plt.xlim([bounds.minx.min()-5, bounds.maxx.max()+5])\n", - "plt.ylim([bounds.miny.min()-5, bounds.maxy.max()+5])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's style the plot so that the eclipse looks eclipse-ier\n", - "base = world.plot(color='lightgray', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "myeclipse.plot(ax=base, color='black', edgecolor='yellow', alpha=0.75)\n", - "cities.plot(marker='o', color='white', markersize=2, ax=base)\n", - "bounds = myeclipse.geometry.bounds\n", - "plt.xlim([bounds.minx.min()-5, bounds.maxx.max()+5])\n", - "plt.ylim([bounds.miny.min()-5, bounds.maxy.max()+5])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check that the crs are the same for myeclipse and cities\n", - "print('data is in the same crs:', myeclipse.crs == cities.crs, ':', myeclipse.crs)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# We can see that there are a few cities that intersect my path! But we want to know which ones.\n", - "# Do a spatial join to get the intersection\n", - "# from geopandas.tools import sjoin\n", - "ecities = gpd.sjoin(cities, myeclipse, how='inner', op='intersects')\n", - "ecities.head()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's plot the results!\n", - "base = world.plot(color='lightgray', linewidth=0.5, edgecolor='white', figsize=(15,5))\n", - "myeclipse.plot(ax=base, color='black', edgecolor='yellow', alpha=0.75)\n", - "ecities.plot(marker='o', color='white', markersize=2, ax=base)\n", - "bounds = myeclipse.geometry.bounds\n", - "plt.xlim([bounds.minx.min()-5, bounds.maxx.max()+5])\n", - "plt.ylim([bounds.miny.min()-5, bounds.maxy.max()+5])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print('Wow! There are {} cities in your path!'.format(len(ecities)))\n", - "print()\n", - "print(ecities['NAME'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Make it Slippy" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we want to put our data on a slippy map. But before we do, let's take a quick detour. (Note: refer back to slides for Tile exercises)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import folium" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's find the centroid of the eclipse we chose, so that we can center our folum map on it\n", - "x = myeclipse.centroid.x.values[0]\n", - "y = myeclipse.centroid.y.values[0]\n", - "print('y: ' + str(y) + ', x: ' + str(x))\n", - "\n", - "# Note: results will vary depending on the eclipse you chose" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's choose a basemap! There are many options, [check them out](https://deparkes.co.uk/2016/06/10/folium-map-tiles/)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Note: no matter what projection you were in before, the folium maps will be in Web Mercator\n", - "map_osm = folium.Map(location=[y, x], zoom_start=3)\n", - "map_osm" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "map_carto = folium.Map(\n", - " location=[y, x],\n", - " tiles='Cartodb Positron',\n", - " zoom_start=3\n", - ")\n", - "map_carto" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "map_stamen = folium.Map(\n", - " location=[y, x],\n", - " tiles='stamenwatercolor',\n", - " zoom_start=3\n", - ")\n", - "map_stamen" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "folium.GeoJson(ecities,name='Eclipse Cities').add_to(map_stamen)\n", - "folium.GeoJson(myeclipse,name='Eclipse Path').add_to(map_stamen)\n", - "\n", - "# Add a layer control if you like\n", - "folium.LayerControl().add_to(map_stamen)\n", - "\n", - "map_stamen" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# You can write a function that creates a map with all of your properties\n", - "# This one creates popups for your cities\n", - "\n", - "def plot_city_pop(ecities, myeclipse):\n", - " # generate a new map\n", - " folium_map = folium.Map(location=[y, x], zoom_start=3, tiles=\"CartoDB dark_matter\")\n", - " folium.GeoJson(myeclipse,name='Eclipse Path').add_to(folium_map)\n", - " # for each row in the data, add a cicle marker\n", - " for index, row in ecities.iterrows():\n", - " \n", - " # generate the popup message that is shown on click.\n", - " popup_text = \"Name: {}
Pop: {}\"\n", - " popup_text = popup_text.format(row[\"NAME\"], row[\"POP_MAX\"])\n", - " \n", - " folium.CircleMarker(location=(row['geometry'].y, row['geometry'].x),radius=5,popup=popup_text,fill=True).add_to(folium_map) \n", - "\n", - " # Add a layer control if you like\n", - " folium.LayerControl().add_to(folium_map)\n", - " \n", - " return folium_map" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Call the function to create the map\n", - "plot_city_pop(ecities, myeclipse)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Saving your results as a Esri Shapefile is easy with GeoPandas\n", - "# myeclipse.to_file('../Data/myeclipse.shp', driver='ESRI Shapefile')\n", - "# ecities.to_file('../Data/ecities.shp', driver='ESRI Shapefile')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Your turn: Go Nuts!\n", - "\n", - "**Make your own map **\n", - "* Choose a base map\n", - "* Add any of the data we've worked with so far\n", - "* Choose your own colors and styles\n", - "* Add or change the popups\n", - "* Use GeoPandas to answer any lingering questions about these eclipses, then plot it on your slippy map\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m = folium.Map(location=[41.4993, -81.6944], zoom_start=7)\n", - "m.choropleth(\n", - " geo_data=eclipses,\n", - " fill_color='Black',\n", - " fill_opacity=0.3,\n", - " line_weight=2,\n", - ")\n", - "\n", - "m" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "I hope you enjoyed this tutorial. Thank you!" - ] - } - ], - "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.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Notebook/.ipynb_checkpoints/03_Raster-checkpoint.ipynb b/Notebook/.ipynb_checkpoints/03_Raster-checkpoint.ipynb deleted file mode 100644 index ad43e85..0000000 --- a/Notebook/.ipynb_checkpoints/03_Raster-checkpoint.ipynb +++ /dev/null @@ -1,109 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copied from https://github.com/jmt2080ad/spatial_r_workshop_public/blob/master/exercises/RasterANDSP_Tutorial.Rmd" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "#import rasterio etc" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "# load in alki trees\n", - "# Data/alkiTrees_UTM.shp\n", - "# do any other stuff to get them working (set crs if needed)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "# plot them with a basemap" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "# load in raster data\n", - "# Data/Seattle_NAIP.tif" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "# verify that they are in the same crs" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "# they are not, so reproject one and save it" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# in R: \n", - "#NDVI <- (sea$Seattle_NAIP.4 - sea$Seattle_NAIP.1)/(sea$Seattle_NAIP.4 + sea$Seattle_NAIP.1) \n", - "#NDVI plot(NDVI)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "# plot the results" - ] - } - ], - "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.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}