├── .condarc ├── .gitignore ├── Makefile ├── README.md ├── atoms ├── README.md ├── clustering │ └── README.md ├── collaboration │ └── README.md ├── context │ ├── README.md │ ├── delayed_gratification.ipynb │ ├── learning_a_language.ipynb │ ├── learning_python.ipynb │ ├── programming_and_geography.ipynb │ └── why_code.ipynb ├── data │ └── remote.ipynb ├── foundations │ ├── .gitignore │ ├── Basics.ipynb │ ├── Conditions.ipynb │ ├── Debugging.ipynb │ ├── Dictionaries.ipynb │ ├── Functions.ipynb │ ├── Iteration.ipynb │ ├── Jupyter.ipynb │ ├── LICENSE │ ├── Learning_a_Language.ipynb │ ├── Lists.ipynb │ ├── Programming_and_Geography.ipynb │ ├── Programming_in_Python.ipynb │ ├── README.md │ ├── Thinking_Like_a_Computer.ipynb │ ├── Why_Code.ipynb │ └── data │ │ ├── UK_Major_Metro_Areas.csv │ │ └── UK_Metro_Areas.csv ├── ml │ └── README.md ├── network_analysis │ └── README.md ├── os │ ├── README.md │ ├── img │ │ └── Software_Carpentry.png │ ├── paths.ipynb │ ├── unix_shell.ipynb │ └── whats_going_on.ipynb ├── point_patterns │ └── README.md ├── statistics │ └── README.md ├── visualization │ ├── README.md │ └── choropleth_classification.ipynb └── zonal_analysis │ └── README.md ├── builds ├── .gitignore └── README.md ├── compile-geodemographics.ipynb ├── compile.ipynb ├── environment.yml ├── extractor.ipynb ├── geopyter.yml ├── geopyter ├── __init__.py └── core.py ├── parser.ipynb ├── requirements.txt ├── sessions ├── .ipynb_checkpoints │ └── Session-Test-checkpoint.ipynb ├── Example.ipynb ├── Getting_Oriented.ipynb ├── README.md ├── geodemographics.ipynb └── visualization.ipynb └── setup.py /.condarc: -------------------------------------------------------------------------------- 1 | channel_priority: strict 2 | channels: 3 | - conda-forge 4 | - defaults 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Name of pysal package to develop on 2 | PACKAGE=geopyter 3 | 4 | # build the container 5 | container: 6 | docker build -t $(PACKAGE) . 7 | 8 | # run jupyter notebook for development 9 | nb: 10 | docker run --rm -p 8888:8888 -v ${PWD}:/home/jovyan $(PACKAGE) 11 | 12 | # run a shell for development, manually launch jupyter 13 | cli: 14 | docker run -it -p 8888:8888 -v ${PWD}:/home/jovyan $(PACKAGE) sh -c "/home/jovyan/develop.sh && /bin/bash" 15 | shell: 16 | docker run -it -p 8888:8888 -v ${PWD}:/home/jovyan $(PACKAGE) /bin/bash 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GeoPyTeR: Geographical Python Teaching Resource 2 | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/pysal/geopyter/master) 3 | 4 | 5 | ## Vision 6 | GeoPyTer is a project to support open source geospatial education using Python. 7 | 8 | 9 | ## Structure 10 | 11 | The philosophy of GeoPyTeR is that the value added that a geoeducator brings to their course rests in their perspective on the topic at hand. 12 | 13 | At the core of GeoPyTeR are *atoms* which represent thematic content on a particular geospatial topic in the form of Jupyter notebooks. The atoms form the building blocks for modules, or lectures, that can be formed through a mash-up of atoms. Modules, in turn, can be combined to compose a course. The articulation of an instructor's perspective is in the composition of specific atoms the instructor selects for a module together with the narrative that integrates the atoms to construct the lecture. 14 | 15 | ## Atoms 16 | 17 | 1. [Foundations (of Programming)](./foundations/README.md) 18 | * Getting Started 19 | * Basics (Variables) 20 | * Conditions 21 | * Debugging 22 | * Iteration 23 | * Lists 24 | * Dictionaries 25 | * Functions 26 | * Libraries 27 | * Classes & Methods 28 | 1. [Reading & Writing (Unix File I/O)](.//README.md) 29 | 1. [Charts & Graphs](.//README.md) 30 | 1. [Standardisation & Transformation](.//README.md) 31 | 1. [Non-Spatial Inferential Statistics](./statistics/README.md) 32 | 1. [Non-Spatial Bayesian Statistics](.//README.md) 33 | 1. [Maps](./maps/README.md) 34 | 1. [Point Pattern Analysis](./point_patterns/README.md) 35 | 1. [Zonal Analysis](./zonal_analysis/README.md) 36 | 1. [Raster Analysis](./raster_analysis/README.md) 37 | 1. [Non-Spatial Clustering](.//README.md) 38 | 1. [Spatial Clustering](.//README.md) 39 | 1. [Machine Learning](./ml/README.md) 40 | 1. [Network Analysis](./network_analysis/README.md) 41 | 1. [ABMs & CAs](.//README.md) 42 | 1. [GWR](.//README.md) 43 | 1. [Hierarchical Modelling](.//README.md) 44 | 45 | ## Depends 46 | 47 | - GitPython (>= 2.0.6?) 48 | - Markdown (>= 2.6.7?) 49 | - nbformat (>= v4?) 50 | 51 | ## Contributing 52 | 53 | We invite any interested educator, researcher or developer to join the project. The content and structure of this teaching project itself is licensed under the [Creative Commons Attribution-ShareAlike 4.0 license][ccasa], and the contributing source code is licensed under The [MIT License][mit]. 54 | 55 | [ccasa]: https://creativecommons.org/licenses/by-sa/4.0/legalcode 56 | [mit]: https://opensource.org/licenses/MIT 57 | -------------------------------------------------------------------------------- /atoms/README.md: -------------------------------------------------------------------------------- 1 | # Atoms 2 | -------------------------------------------------------------------------------- /atoms/clustering/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pysal/geopyter/19542b84a321567b6d2c294a0c710cf1e2613765/atoms/clustering/README.md -------------------------------------------------------------------------------- /atoms/collaboration/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pysal/geopyter/19542b84a321567b6d2c294a0c710cf1e2613765/atoms/collaboration/README.md -------------------------------------------------------------------------------- /atoms/context/README.md: -------------------------------------------------------------------------------- 1 | # Context 2 | 3 | These atoms are intended to provide useful contextual material for why learning to programme is a good idea, and how it fits into the larger history of geography. 4 | 5 | ## Notebooks 6 | 7 | - [Programming and Geography](programming_and_geography.ipynb) 8 | - [Why Code?](why_code.ipynb) 9 | - [Learning a (New) Language](learning_a_language.ipynb) 10 | - [Learning Python](learning_python.ipynb) 11 | - [Delayed Gratification](delayed_gratification.ipynb) 12 | -------------------------------------------------------------------------------- /atoms/context/delayed_gratification.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "geopyter": { 7 | "Contributors": [ 8 | "Michele Ferretti (https://github.com/miccferr)", 9 | "Jon Reades (https://github.com/jreades)", 10 | "James Millington (https://github.com/jamesdamillington)", 11 | "Jon Reades (https://github.com/jreades)" 12 | ], 13 | "git": { 14 | "active_branch": "master", 15 | "author.name": "Jon Reades", 16 | "authored_date": "2017-06-05 16:12:59", 17 | "committed_date": "2017-06-05 16:12:59", 18 | "committer.name": "Jon Reades", 19 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 20 | } 21 | } 22 | }, 23 | "source": [ 24 | "# Delayed Gratification\n", 25 | "\n", 26 | "- Contributors: Jon Reades (jon@reades.com); James Millington (jamesdamillington@gmail.com)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Programming is about Delayed Gratification\n", 34 | "\n", 35 | "Learning to program involves a _lot_ of delayed gratification: you will need to invest quite a bit of time in learning to crawl before you can walk, and even more time in learning to walk before you can run. A well-designed programming language like Python can make it a little bit _easier_ to learn each step, but it still _**won't make it easy**_. \n", 36 | "\n", 37 | "We've said this before and we'll say it again (and again, and again) that you *must* think of this as learning a language: at first very little will make sense and you won't be able to say much more than 'hello, my name is X', but if you *practice* (**regularly**, cramming doesn't work in the same way that it doesn't work for learning French or Chienese) and really *think* about what you're doing it will get easier and easier, and faster and faster, to program.\n", 38 | "\n", 39 | "Learning to download files from the Internet using *only* code is a good case in point: why learn to do this when you could just open up a web browser, navigate to the site with the file you want, and then save it to your Downloads folder?\n", 40 | "\n", 41 | "Several reasons:\n", 42 | "\n", 43 | "1. Because this is annoying and time-consuming if you have to download *lots* of files (e.g. satellite imagery or Census data), or if you need to update your results regularly (e.g. weather or tweets). If you do this using code then you can get the computer to do the work for you! We can write code to talk to a web server, ask for a list of files (or scrape a list of files from a web page), and then download each one in turn... all from you clicking 'Run'.\n", 44 | "\n", 45 | "2. Because you can also organise your data a lot more logically. By default, when you download a file using a web browser it will save it to your Downloads folder with a name that may or may not make much sense to you. Using code, not only can we specify exactly where we want the data saved (and this can include doing things like creating new directories automatically for each month or Census variable), but we can even *automate* the naming of the file so that it is something easy for us to read.\n", 46 | "\n", 47 | "3. A not so obvious benefit is that you will need to think _logically_ and in an _organised_ way about how you manage data when you start doing data analysis, and using code to do all of this forces you to be logical right from the start: you will almost never receive raw data that doesn't require some 'pre-processing' work; so if you save your raw data and your processed data in the same directory how can you be sure you've loaded the right file? It's much easier to have two folders -- `raw` or `source`, and `clean` or `output` -- and use Python to read in raw data from one directory and then write the processed data out to a different directory than it would be using Excel's `File > Save As`. That's because the path is just _text_ and you can easily work with it that way!\n", 48 | "\n", 49 | "4. Also, these solutions are *scalable*: once you've learned how to write the code to scrape data from one web site, you can use the _same_ code to scrape data from a *different* computer somewhere else on the Internet. So instead of solving *one* specific problem, you are actually solving a whole *class* of problems at once! That's being lazy in a good way.\n", 50 | "\n", 51 | "Solving problems. Thinking logically. What employer wouldn't love someone with those skills?" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "## Command Chaining\n", 59 | "\n", 60 | "Here's an example of this 'in action'. In and of itself the advantages of the Terminal (a.k.a. shell) might not be obvious, but we can write code in the Terminal that _chains_ commands together to do several things in one go. **You do not *need* to run this example** because it's for illustrative purposes:\n", 61 | "\n", 62 | "```\n", 63 | "curl -L http://bit.ly/2vrUFKi | head -3 | awk -F\",\" '{ print $2, $4, $6; }'\n", 64 | "```\n", 65 | "\n", 66 | "**_Note_**: If you _do_ want to run the code above then you will probably need to install 'Unix utilities' on your computer:\n", 67 | "- **On a Mac** you will need to run (from the Terminal!) the following command: `xcode-select --install`. This installs the `curl` utility along with a bunch of other useful applications.\n", 68 | "- **On Windows** you will probably need to run something like `conda install posix` but unless you want to donate a Windows machine I can't test this.\n", 69 | "- Once that's done you should copy+paste the above on to _one line_ of the Terminal, hit 'Return' and see some output from [this file](http://bit.ly/2vrUFKi) printed to the Terminal.\n", 70 | "\n", 71 | "This command might seem _really_ cryptic but we can break this problem down into steps (as I did when trying to remember how to do it!):\n", 72 | "\n", 73 | "1. `curl` -- this is a tool that allows you to download a file from the internet using only the Terminal, and `-L` is a 'flag' that tells curl to follow any redirects issued by the server.\n", 74 | "2. `head` -- this utility works with the _top_ part of a file (`tail` starts working with the _end_ of a file) and `-3` is also a flag which means 'take only the _first_ line of the file (so `head -10` would take the first _ten_ lines of the file).\n", 75 | "3. We 'glue' the output of `curl` together with `head` using `|` (known as a 'pipe') -- this tells the computer to pass the output of `curl` to the input of `head` (so head sees this as a file).\n", 76 | "4. We then direct the output of `head` to a *third* command which splits the output of head on commas (`-f\",\"`) and then outputs the 2nd, 4th, and 6th columns of the file.\n", 77 | "\n", 78 | "So this one line of _code_ allows you to something quite complex (normally involving a web browser, Microsoft Excel, and some selecting and copying) all in one short command. The point of this is that we are gaining in power at the cost of 'ease of use'. All of this *might* be a bit faster to do 'by hand' if you only need to do it *once*, but when we start doing analysis you almost never need to do something only once." 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "Here's an example that does basically the _same_ thing (and then some) as the Terminal code above, but using Python code (and a larger file) instead:" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [ 94 | "import csv\n", 95 | "import requests as r\n", 96 | "\n", 97 | "url = 'http://bit.ly/2iIK9bA'\n", 98 | "data = r.get(url)\n", 99 | "content = data.content.decode('utf-8').splitlines()\n", 100 | "cr = csv.reader(content)\n", 101 | "\n", 102 | "for row in cr:\n", 103 | " if row[3] != 'Population':\n", 104 | " print(row[1] + \" has a population of \" + \"{:,}\".format(int(row[3])))" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": {}, 110 | "source": [ 111 | "Just to highlight what we've just done:\n", 112 | "\n", 113 | "1. We retrieved a CSV file from somewhere on this planet using `requests`,\n", 114 | "2. We 'parsed' it so that each `row` became something from which we could extract variables thanks to the magic of the `csv` library that we `import`,\n", 115 | "3. We skip the first row because it's a 'header' row and doesn't contain data,\n", 116 | "4. We print out the 2nd and 4th columns of the CSV file.\n", 117 | "\n", 118 | "You can see what the source looked like [here](http://bit.ly/2iIK9bA). And you'll note that the URL looks _exactly_ like the path that we saw when we used the Terminal to navigate between directories. \n", 119 | "\n", 120 | "So if you grasp the concept in one context, you can apply it in others. _That_ is scalability!" 121 | ] 122 | } 123 | ], 124 | "metadata": { 125 | "anaconda-cloud": {}, 126 | "geopyter": { 127 | "Contributors": [ 128 | "Michele Ferretti (https://github.com/miccferr)", 129 | "Jon Reades (https://github.com/jreades)", 130 | "James Millington (https://github.com/jamesdamillington)" 131 | ], 132 | "git": { 133 | "active_branch": "master", 134 | "author.name": "Jon Reades", 135 | "authored_date": "2017-06-05 16:12:59", 136 | "committed_date": "2017-06-05 16:12:59", 137 | "committer.name": "Jon Reades", 138 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 139 | }, 140 | "libs": {} 141 | }, 142 | "kernelspec": { 143 | "display_name": "Python 3", 144 | "language": "python", 145 | "name": "python3" 146 | }, 147 | "language_info": { 148 | "codemirror_mode": { 149 | "name": "ipython", 150 | "version": 3 151 | }, 152 | "file_extension": ".py", 153 | "mimetype": "text/x-python", 154 | "name": "python", 155 | "nbconvert_exporter": "python", 156 | "pygments_lexer": "ipython3", 157 | "version": "3.6.5" 158 | } 159 | }, 160 | "nbformat": 4, 161 | "nbformat_minor": 2 162 | } 163 | -------------------------------------------------------------------------------- /atoms/context/learning_python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "geopyter": { 7 | "Contributors": "Jon Reades (https://github.com/jreades)", 8 | "git": { 9 | "active_branch": "master", 10 | "author.name": "Jon Reades", 11 | "authored_date": "2017-06-05 16:12:59", 12 | "committed_date": "2017-06-05 16:12:59", 13 | "committer.name": "Jon Reades", 14 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 15 | } 16 | } 17 | }, 18 | "source": [ 19 | "# Learning Python \n", 20 | "\n", 21 | "- Contributors: Jon Reades (jon@reades.com); James Millington (jamesdamillington@gmail.com)\n" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": { 27 | "geopyter": { 28 | "Contributors": [ 29 | "Michele Ferretti (https://github.com/miccferr)", 30 | "Jon Reades (https://github.com/jreades)", 31 | "James Millington (https://github.com/jamesdamillington)", 32 | "Michele Ferretti (https://github.com/miccferr)", 33 | "Jon Reades (https://github.com/jreades)", 34 | "James Millington (https://github.com/jamesdamillington)" 35 | ], 36 | "git": { 37 | "active_branch": "master", 38 | "author.name": "Jon Reades", 39 | "authored_date": "2017-06-05 16:12:59", 40 | "committed_date": "2017-06-05 16:12:59", 41 | "committer.name": "Jon Reades", 42 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 43 | } 44 | } 45 | }, 46 | "source": [ 47 | "## Python vs R\n", 48 | "\n", 49 | "In these notebooks we will be using the Python programming language. As with human languages, there are _many_ [programming languages](http://www.computerhope.com/jargon/p/proglang.htm) in the world, each with their own advantages and disadvantages, and each with their own vocabulary (allowed words) and grammar (syntax). We use Python. Alongside Python, the other language that is often mentioned by people doing data-led research is [R](https://www.r-project.org). It's the _other_ one that many of your lecturers and a lot of other scientists use in a lot of their work. There's [a great deal of debate about the relative merits of Python and R](https://www.quora.com/Which-is-better-for-data-analysis-R-or-Python), but for our purposes _both_ Python and R can help us to undertake geographical analysis. That is, in fact, the premise of this entire course! \n", 50 | "\n", 51 | "So why have we chosen to use Python here? Of the two languages, we think that Python has some specific advantages:\n", 52 | "\n", 53 | "1. It was designed for teaching, so its syntax is easier for a human to 'parse' than R's\n", 54 | "2. It is more _like_ other languages, so its more readily transferrable if you need to learn another language. Think of it as learning Italian, which also makes it easier to learn Spanish and French.\n", 55 | "3. It is the one most-used as part of a _geographical workflow_ – what we mean by this is that you can find Python buried inside of ESRI's ArcGIS and the open-source QGIS applications, and it also sits behind (or talks to) a number of other tools that allow us to work flexibly and scalably with geo-data. \n", 56 | "4. Is is easier to operationalise – Python offers more services/tools to enable you to turn something from a 'hack' ([which doesn't mean what you think it means](https://en.wikipedia.org/wiki/Hacks_at_the_Massachusetts_Institute_of_Technology) into a 'service'.\n", 57 | "\n", 58 | "However, if you have been told R is the way to go then don't worry, the concepts covered here still translate. And many of the contributors to to these notebooks use both languages... it just depends on the problem. " 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": { 64 | "geopyter": { 65 | "Contributors": [ 66 | "Michele Ferretti (https://github.com/miccferr)", 67 | "Jon Reades (https://github.com/jreades)", 68 | "James Millington (https://github.com/jamesdamillington)", 69 | "Michele Ferretti (https://github.com/miccferr)", 70 | "Jon Reades (https://github.com/jreades)", 71 | "James Millington (https://github.com/jamesdamillington)" 72 | ], 73 | "git": { 74 | "active_branch": "master", 75 | "author.name": "Jon Reades", 76 | "authored_date": "2017-06-05 16:12:59", 77 | "committed_date": "2017-06-05 16:12:59", 78 | "committer.name": "Jon Reades", 79 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 80 | } 81 | } 82 | }, 83 | "source": [ 84 | "## Python what?\n", 85 | "Python was invented by [Guido van Rossum](https://en.wikipedia.org/wiki/Guido_van_Rossum) in the late 1980s and he continues in the role of 'benevolent dictator' to this day, which means that he (and some other very smart people) try to to ensure that the language continues to meet the basic goals of:\n", 86 | "* Being very easy to read (syntax)\n", 87 | "* Using plain-English for many functions and operators (allowed words)\n", 88 | "* Has a comprehensive style guide: [PEP8](https://www.python.org/dev/peps/pep-0008/) (syntax)\n", 89 | "* Has no unnecessary special formatting characters (syntax _and_ allowed words)\n", 90 | "\n", 91 | "So while Python is not language that enables the computer to make calculations the fastest (C and C++ are faster), nor is it the safest (you wouldn't use it to fly a rocket to Mars), it _is_ a very readable, learnable and maintainable language.\n", 92 | "\n", 93 | "So if you want to learn to code, to do 'data science', or build a business, Python is a great choice.\n", 94 | "\n", 95 | "The points above are also made in [Python In A Nutshell](http://mbrochh.github.io/python-101/#/6/1) by [Martin Brochhaus](https://github.com/mbrochh) which you may find interesting and useful to accompany your learning of Python." 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": { 101 | "geopyter": { 102 | "Contributors": [ 103 | "Michele Ferretti (https://github.com/miccferr)", 104 | "Jon Reades (https://github.com/jreades)", 105 | "James Millington (https://github.com/jamesdamillington)", 106 | "Michele Ferretti (https://github.com/miccferr)", 107 | "Jon Reades (https://github.com/jreades)", 108 | "James Millington (https://github.com/jamesdamillington)" 109 | ], 110 | "git": { 111 | "active_branch": "master", 112 | "author.name": "Jon Reades", 113 | "authored_date": "2017-06-05 16:12:59", 114 | "committed_date": "2017-06-05 16:12:59", 115 | "committer.name": "Jon Reades", 116 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 117 | } 118 | } 119 | }, 120 | "source": [ 121 | "### Three takes on Python\n", 122 | "The images below are links to three videos pitched in quite different ways at the advantages of Python, all of which touch on issues we'll be dealing with later... so watch the videos (even if they're a bit silly in places)!\n", 123 | "\n", 124 | "[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/aXKVOLwpDg8/0.jpg)](http://www.youtube.com/watch?v=aXKVOLwpDg8)\n", 125 | "\n", 126 | "[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/Hn4FbT4wMms/0.jpg)](http://www.youtube.com/watch?v=Hn4FbT4wMms)\n", 127 | "\n", 128 | "[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/G8brQdClo9s/0.jpg)](http://www.youtube.com/watch?v=G8brQdClo9s)" 129 | ] 130 | } 131 | ], 132 | "metadata": { 133 | "anaconda-cloud": {}, 134 | "geopyter": { 135 | "Contributors": [ 136 | "Michele Ferretti (https://github.com/miccferr)", 137 | "Jon Reades (https://github.com/jreades)", 138 | "James Millington (https://github.com/jamesdamillington)" 139 | ], 140 | "git": { 141 | "active_branch": "master", 142 | "author.name": "Jon Reades", 143 | "authored_date": "2017-06-05 16:12:59", 144 | "committed_date": "2017-06-05 16:12:59", 145 | "committer.name": "Jon Reades", 146 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 147 | }, 148 | "libs": {} 149 | }, 150 | "kernelspec": { 151 | "display_name": "Python 3", 152 | "language": "python", 153 | "name": "python3" 154 | }, 155 | "language_info": { 156 | "codemirror_mode": { 157 | "name": "ipython", 158 | "version": 3 159 | }, 160 | "file_extension": ".py", 161 | "mimetype": "text/x-python", 162 | "name": "python", 163 | "nbconvert_exporter": "python", 164 | "pygments_lexer": "ipython3", 165 | "version": "3.6.5" 166 | } 167 | }, 168 | "nbformat": 4, 169 | "nbformat_minor": 2 170 | } 171 | -------------------------------------------------------------------------------- /atoms/context/programming_and_geography.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "geopyter": { 7 | "Contributors": "Jon Reades (https://github.com/jreades)", 8 | "git": { 9 | "active_branch": "master", 10 | "author.name": "Jon Reades", 11 | "authored_date": "2017-06-05 16:12:59", 12 | "committed_date": "2017-06-05 16:12:59", 13 | "committer.name": "Jon Reades", 14 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 15 | } 16 | } 17 | }, 18 | "source": [ 19 | "# Programming and Geography \n", 20 | "\n", 21 | "- Contributors: Jon Reades (jon@reades.com); James Millington (jamesdamillington@gmail.com)\n" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": { 27 | "geopyter": { 28 | "Contributors": "Jon Reades (https://github.com/jreades)", 29 | "git": { 30 | "active_branch": "master", 31 | "author.name": "Jon Reades", 32 | "authored_date": "2017-06-05 16:12:59", 33 | "committed_date": "2017-06-05 16:12:59", 34 | "committer.name": "Jon Reades", 35 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 36 | } 37 | } 38 | }, 39 | "source": [ 40 | "## The Fall and Rise of Geocomputation\n", 41 | "\n", 42 | "We live in a world transformed by big (geo)data: from Facebook likes and satellites, to travel cards and drones, the process of collecting and analysing data about the world around us is becoming very, very cheap. Twenty years ago, gathering data about the human and physical environment was expensive, but now a lot of it is generated as the ‘exhaust’ of day-to-day activity: tapping on to the bus or train, taking photos (whether from a satellite, drone, or disposable camera), making phone calls, using our credit cards, and surfing the web. And that's before you start looking at the Terabytes of data being generated by satellites, air quality and river flow sensors, and other Earth Observation Systems! \n", 43 | "\n", 44 | "As the costs of capturing, curating, and processing these data sets falls, the discipline of geography is changing. You face a world in which many of the defining career options for geographers with basic quantitative skills will either no longer exist, or will have been seriously de-skilled. So much can now be done through a web browser (e.g. [CartoDB](https://carto.com)) that specifying ‘Knowledge of ArcGIS’ is becoming superfluous; not because geo-analysis jobs are no longer in demand or no longer done -- in fact, they are more vital than ever -- but because the market for these skills has split in two: expensive, specialist software is being superseded by simple, non-specialist web-based tools on the ‘basic’ side, and by customised code on the 'advanced' side.\n", 45 | "\n", 46 | "It is for these reasons that terms like 'geocomputation', 'computational geography' and 'geographic data science' are back in vogue. After a period in which GIS was front-and-center for many geographers with an interest in spatial data (as well for many geographers who objected to the shortcomings of quantitative approaches), the availability of data and advanced computational techniques (including Machine Learning), together with the 'discovery' by other disciplines of the role of geography in 'big data' processes, has created a need for a 'new' (or old, depending on your view) type of geographer able to reason much more directly _through_ code while remaining rooted in the critical geographic tradition that is aware of the short-comings (and opportunities) of data.\n", 47 | "\n", 48 | "### Further Reading\n", 49 | "\n", 50 | "- Arribas-Bel, D. and Reades, J. (2018). 'Geography and computers: Past, present, and future', *Geography Compass*, DOI: [10.1111/gec3.12403](https://doi.org/10.1111/gec3.12403)." 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": { 56 | "geopyter": { 57 | "Contributors": "Jon Reades (https://github.com/jreades)", 58 | "git": { 59 | "active_branch": "master", 60 | "author.name": "Jon Reades", 61 | "authored_date": "2017-06-05 16:12:59", 62 | "committed_date": "2017-06-05 16:12:59", 63 | "committer.name": "Jon Reades", 64 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 65 | } 66 | } 67 | }, 68 | "source": [ 69 | "## What is Geocomputation?\n", 70 | "\n", 71 | "Computational approaches -- which is to say, approaches to geography using computers excuting commands written in programming code -- differ in important ways from the quantitative skills taught in traditional geography ‘methods’ classes: computational geography is underpinned by algorithms that employ concepts such as _iteration_ and _recursion_, and we use these to tackle everything from a data processing problem to an entire research question. \n", 72 | "\n", 73 | "\"Open\n", 74 | "\n", 75 | "For example, Alex Singleton’s OpenAtlas (available for free from the [Consumer Data Research Centre](https://data.cdrc.ac.uk/product/cdrc-2011-census-open-atlas)) contains 134,567 maps. Alex designed and wrote a script to _iterate_ over the Census areas (i.e. to ‘visit’ each area in turn when creating a map), and to _recurse_ into smaller sub-regions from larger regions (i.e. to keep drilling down into smaller and smaller geographies) in order to generate maps at, literally, every conceivable scale. Then he let the computer do the ‘boring bit’ of actually creating each and every map. " 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": { 81 | "geopyter": { 82 | "Contributors": "Jon Reades (https://github.com/jreades)", 83 | "git": { 84 | "active_branch": "master", 85 | "author.name": "Jon Reades", 86 | "authored_date": "2017-06-05 16:12:59", 87 | "committed_date": "2017-06-05 16:12:59", 88 | "committer.name": "Jon Reades", 89 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 90 | } 91 | } 92 | }, 93 | "source": [ 94 | "### Thinking Algorithmically\n", 95 | "\n", 96 | "Thinking _algorithmically_ requires students and professionals to deal with abstraction: we don’t want to define how each analysis should work – or how each map should look – rather, we want to specify a set of rules about how to select and display data on a map, and then let the computer make them all for us. In this way of working it’s not really any more work to create 500 or 5,000 maps than it is to create 5 because we’ve already told the computer how to make useful maps. \n", 97 | "\n", 98 | "Here's another way to think about it:\n", 99 | "\n", 100 | "> _An algorithm is like a recipe. It takes \"inputs\" (the ingredients), performs a set of simple and (hopefully) well-defined steps, and then terminates after producing an \"output\" (the meal)._\n", 101 | "\n", 102 | "This article also goes on to make some interesing points about AI and deep learning that are [well worth a read](https://medium.com/@geomblog/when-an-algorithm-isn-t-2b9fe01b9bb5), but for our purposes the bit about a _recipe_ is the important bit: how would you break your problem down into steps _like the ones you'd see for a recipe_?\n", 103 | "\n", 104 | "Learning to think this way is _hard work_: the _first_ time I try a new recipe I really don't know how things are going to taste. Similarly, the first time I use an algorithm to make a map or solve a problem I usually don't actually know exactly how my maps are going to look until _after_ I've made them. The difference from the 'normal', non-computational way of working is that I make a few changes to my code and then just run it again. And again... as many times as I need to in order to get what I want. I can keep changing the recipe until I get it just right." 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": { 110 | "geopyter": { 111 | "Contributors": "Jon Reades (https://github.com/jreades)", 112 | "git": { 113 | "active_branch": "master", 114 | "author.name": "Jon Reades", 115 | "authored_date": "2017-06-05 16:12:59", 116 | "committed_date": "2017-06-05 16:12:59", 117 | "committer.name": "Jon Reades", 118 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 119 | } 120 | } 121 | }, 122 | "source": [ 123 | "### Thinking Like a Programmer\n", 124 | "\n", 125 | "However, trying the same recipe again and again and again _also_ sounds like hard work! Wouldn't it be faster to just click and choose what you want the computer to do in SPSS or ArcMap? Well, yes and no. The two advantages to doing this with code over pointing-and-clicking are: 1) your solution is _transferrable_; and 2) thinking 'like a programmer' is also about problem-solving, and that _also_ transfers very nicely to the 'real world' of employment.\n", 126 | "\n", 127 | "Why do we say this:\n", 128 | "\n", 129 | "1. Programming solutions are transferrable because you aren't just solving _one_ problem, you are solving _classes_ of problems. In the same way that many recipes build on the same basic ingredients (sometimes adding something new for added 'spice'), many applications use the same basic ingredients: it's how they're put together in new ways that leads to new outputs. It's a lot like Lego.\n", 130 | "\n", 131 | "2. Thinking like a programmer also translates well because you are learning to deal with abstraction. Yes, the details of a problem matter (just as ignoring cultural differences between two countries can matter), but it's important to be able to break a really big, messy, complex problem down into smaller, tidier, more comprehensible bits that you _can_ tackle. Programmers deal with this every day, so they tend to develop important skills in understanding and dealing with practical challenges of the sort that you'll face every day in your career.\n", 132 | "\n", 133 | "Here's another [useful bit of insight](https://medium.freecodecamp.org/how-to-think-like-a-programmer-lessons-in-problem-solving-d1d8bf1de7d2?source=userActivityShare-65ab89778550-1526122060&gi=f9005e8aacb5):\n", 134 | "\n", 135 | "> The best way \\[of solving problems\\] involves a) having a framework and b) practicing it.\n", 136 | "> \n", 137 | "> Problem-solving skills are almost unanimously the most important qualification that employers look for... more than programming languages proficiency, debugging, and system design...\n", 138 | ">\n", 139 | "> — Hacker Rank (2018 Developer Skills Report)\n", 140 | "\n", 141 | "You really should [read the article](https://medium.freecodecamp.org/how-to-think-like-a-programmer-lessons-in-problem-solving-d1d8bf1de7d2) (it's not very long) but here are the key points:\n", 142 | "\n", 143 | "1. Understand the problem -- most problems are hard because you don't understand them _and_ you will only know that you've understood it when you can explain it in plain-English.\n", 144 | "2. Plan -- if you just dive in without thinking about what you need your code to take in and spit out then you're going to waste a _lot_ of time.\n", 145 | "3. Divide -- break a hard problem down into simple, small steps and tackle them in small, simple blocks of code. _Never_ try to just sit down and 'code'.\n", 146 | "4. Debug with a fresh eye -- if you really feel stuck, step away from the computer for 5 minutes, take a deep breath, and try to look at the problem with a fresh set of eyes rather than just diving back in. Most problems boil down to either not seeing the big picture, or not realising that the computer is doing _exactly what you told it to do_, and _not what you meant for it to do_.\n", 147 | "5. Practice -- find ways to practice problem-solving and coding (not necessarily at the same time).\n", 148 | "\n", 149 | "If you don't take our word for it, how about taking Richard Feynman's word on it?\n", 150 | "\n", 151 | "> If you can’t explain something in simple terms, you don’t understand it.\n", 152 | "\n", 153 | "" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": { 159 | "geopyter": { 160 | "Contributors": "Jon Reades (https://github.com/jreades)", 161 | "git": { 162 | "active_branch": "master", 163 | "author.name": "Jon Reades", 164 | "authored_date": "2017-06-05 16:12:59", 165 | "committed_date": "2017-06-05 16:12:59", 166 | "committer.name": "Jon Reades", 167 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 168 | } 169 | } 170 | }, 171 | "source": [ 172 | "### The Open Source Ethos\n", 173 | "\n", 174 | "Once I've got a solution to my current problem, I can take that code and apply it to a new problem. Or a new case study. _Or_, I can [post it online](https://github.com/kingsgeocomp) and let others build off of my work to tackle problems that I've not even considered! Giving away my code might seem like a bad idea, but think about this: in a world of exciting research questions, are you going to be able to tackle every single one? Your own work _already_ builds off of code that other people gave away (the Mac OS, Linux, QGIS, Python, etc.)... perhaps you should give something back to the community? Not _just_ because it's a nice thing to do, but because people will find out about you through your code. And those people might be in a position to offer you a job, or they might approach you as a collaborator, or they might point someone else with an interesting opportunity in your direction because you have built a reputation as a 'contributor'." 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": {}, 180 | "source": [ 181 | "## Computers: good or bad?\n", 182 | "\n", 183 | "The best way to be a 'good' programmer is to know when the computer can help you and when it will just get in the way. A computer cannot 'solve' a problem for you, but it _can_ help you to find the answer when you've told it what to look for and what rules to use in that search. A computer can only do _exactly_ what you tell it to do, so if you don't know what to do then the computer won't either.\n", 184 | "\n", 185 | "One of the founders of computing, [Charles Babbage](https://en.wikiquote.org/wiki/Charles_Babbage#Passages_from_the_Life_of_a_Philosopher_.281864.29) had this to say:\n", 186 | "\n", 187 | "> On two occasions I have been asked, — \"Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?\" In one case a member of the Upper, and in the other a member of the Lower, House put this question. I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.\n", 188 | "> _Passages from the Life of a Philosopher (1864), ch. 5 \"Difference Engine No. 1\"_\n", 189 | "\n", 190 | "What are computers good at?\n", 191 | "- Doing the same thing over and over\n", 192 | "- Doing _exactly_ what they are told to do\n", 193 | "\n", 194 | "What are computers currently still bad at?\n", 195 | "- Generating knowledge\n", 196 | "- Being creative\n", 197 | "\n", 198 | "There is a long-standing contest, called the Turing Test in honour of [the famous computer pioneer](https://en.wikipedia.org/wiki/Alan_Turing), that demonstrates this difference rather nicely: a computer passes the Turing test if it can fool a person into thinking that they're talking to another person. Some people have claimed that if a computer can _really_ pass the Turing Test by keeping up a conversation of indefinite length on any range of topics then we'll have to declare that machines have become full AIs (Artificial Intelligences). To put it another way: if it sounds like a human and responds like a human... then is it a human?\n", 199 | "\n", 200 | "Perhaps fortunately for us, althoug computers are getting a lot better at holding up their end of the conversation they still seem to have a hard time fooling anyone for very long. In contrast, bigger and better computers have now beat the best humans at Chess and Go, and are being used to help us understand earthquakes and climate change on a huge scale. Here, computers can do billions -- or trillions -- of calculations a second to work out that if 'A' happens then 'B' is the next most likely thing to happen, and so on and so on.\n", 201 | "\n", 202 | "The difference is that games like Go and Chess have well-understood rules as (ultimately) do natural processes like climate change and earthquakes. Chess is 'easier' for a computer than Go because a big enough computer can work out every possible chess move and pick the best one, whereas it can't do that for Go and so has to make 'choices' based on incomplete information. Earthquakes have even more 'rules', but as far we know they still follow _some_ set of rules dictated by physics and chemistry. \n", 203 | "\n", 204 | "People, however, don't use the same unchanging rules in conversation. Yes, conversations have norms, unless you're using an online comment forum where it's normal to start a conversation by asking someone if they're an idiot, but people don't just 'play games' within the rules, they actually play with the rules themselves in a way that computers find very, very hard to follow. Think of sarcasm: you say one thing but it means exactly the opposite. And if it's delivered deadpan then sometimes even people have trouble knowing if you're being sincere!\n", 205 | "\n", 206 | "That's why AI of the sort you might have seen in _2001_ or _Blade Runner_ has been twenty years away for the last sixty years! Recently, computers have been getting better and better at doing really difficult things, but it's usually still in a narrow area where we understand the rules and we normally need to spend a lot of time training the computer. \n", 207 | "\n", 208 | "#### More About the Turing Test\n", 209 | "Turing, A (1950), _Computing Machinery and Intelligence, Mind_ LIX (236): 433–460\n", 210 | "doi: [10.1093/mind/LIX.236.433](http://dx.doi.org/10.1093/mind/LIX.236.433), ISSN 0026-4423" 211 | ] 212 | }, 213 | { 214 | "cell_type": "markdown", 215 | "metadata": {}, 216 | "source": [ 217 | "### Further Reading \n", 218 | "\n", 219 | "A big gap is opening up between the stuff that can be done by pushing buttons (which no longer even really requires geographical training) and the 'cutting edge'. There are many pieces that argue this case, but here are a few to start with:\n", 220 | "\n", 221 | "* [Why the Future of Geography is Cheap](https://www.rgs.org/schools/teaching-resources/why-the-future-of-geography-is-cheap/)\n", 222 | "* [GIS Jobs of Today](http://www.directionsmag.com/entry/gis-jobs-of-today-should-you-have-programming-skills/473296): should you have programming skills?" 223 | ] 224 | } 225 | ], 226 | "metadata": { 227 | "anaconda-cloud": {}, 228 | "geopyter": { 229 | "Contributors": [ 230 | "Michele Ferretti (https://github.com/miccferr)", 231 | "Jon Reades (https://github.com/jreades)", 232 | "James Millington (https://github.com/jamesdamillington)" 233 | ], 234 | "git": { 235 | "active_branch": "master", 236 | "author.name": "Jon Reades", 237 | "authored_date": "2017-06-05 16:12:59", 238 | "committed_date": "2017-06-05 16:12:59", 239 | "committer.name": "Jon Reades", 240 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 241 | }, 242 | "libs": {} 243 | }, 244 | "kernelspec": { 245 | "display_name": "Python 3", 246 | "language": "python", 247 | "name": "python3" 248 | }, 249 | "language_info": { 250 | "codemirror_mode": { 251 | "name": "ipython", 252 | "version": 3 253 | }, 254 | "file_extension": ".py", 255 | "mimetype": "text/x-python", 256 | "name": "python", 257 | "nbconvert_exporter": "python", 258 | "pygments_lexer": "ipython3", 259 | "version": "3.6.5" 260 | } 261 | }, 262 | "nbformat": 4, 263 | "nbformat_minor": 2 264 | } 265 | -------------------------------------------------------------------------------- /atoms/context/why_code.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "geopyter": { 7 | "Contributors": "Jon Reades (https://github.com/jreades)", 8 | "git": { 9 | "active_branch": "master", 10 | "author.name": "Jon Reades", 11 | "authored_date": "2017-06-05 16:12:59", 12 | "committed_date": "2017-06-05 16:12:59", 13 | "committer.name": "Jon Reades", 14 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 15 | } 16 | } 17 | }, 18 | "source": [ 19 | "# Why Learn to Code?\n", 20 | "\n", 21 | "- Contributors: Jon Reades (jon@reades.com); James Millington (jamesdamillington@gmail.com)\n" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": { 27 | "geopyter": { 28 | "Contributors": [ 29 | "Michele Ferretti (https://github.com/miccferr)", 30 | "Jon Reades (https://github.com/jreades)", 31 | "James Millington (https://github.com/jamesdamillington)", 32 | "Michele Ferretti (https://github.com/miccferr)", 33 | "Jon Reades (https://github.com/jreades)", 34 | "James Millington (https://github.com/jamesdamillington)" 35 | ], 36 | "git": { 37 | "active_branch": "master", 38 | "author.name": "Jon Reades", 39 | "authored_date": "2017-06-05 16:12:59", 40 | "committed_date": "2017-06-05 16:12:59", 41 | "committer.name": "Jon Reades", 42 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 43 | } 44 | } 45 | }, 46 | "source": [ 47 | "## Why _you_ should learn to program\n", 48 | "\n", 49 | "There are many good reasons for geographers to learn to code, but let's start with some good _general_ reasons why _you_ should learn to program a computer even if you never use it to make a map or complete a bit of spatial analysis.\n", 50 | "\n", 51 | "> You should learn how to program a computer because it teaches you how to think.\n", 52 | "\n", 53 | "[![Why You Should Learn How to Code](http://img.youtube.com/vi/UD2xoiCGTDo/0.jpg)](https://youtu.be/UD2xoiCGTDo)\n", 54 | "\n", 55 | "And here is a useful perspective on whether or not learning to code is hard:\n", 56 | "\n", 57 | "> If you don't have a reason for learning to code outside of trying making lots of money that's not a very long term passion... but when you have an idea or a problem that you're passionate about solving then that's why we keep on going... but do you need to have an understanding of complex math or logic skills, the answer is no.\n", 58 | "\n", 59 | "[![Is Learning to Code Hard](http://img.youtube.com/vi/k7Txbdvzx90/0.jpg)](https://youtu.be/k7Txbdvzx90)\n", 60 | "\n", 61 | "So while 'making money' is (often) a nice outcome of learning to code, having a passion for what you want to _do_ with your code is what's going to get you through the worst parts of the learning curve. You also need to be realistic: to become a professional programmer is something that happens over many years, you probably won't just take a couple of classes and then go out into the world saying \"I'm a programmer.\"\n", 62 | "\n", 63 | "And, no, you do _not_ need to know advanced maths in order to learn how to code: you need to be able to think logically and to reframe your problems in ways that align _with_ the computer." 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": { 69 | "geopyter": { 70 | "Contributors": [ 71 | "Michele Ferretti (https://github.com/miccferr)", 72 | "Jon Reades (https://github.com/jreades)", 73 | "James Millington (https://github.com/jamesdamillington)", 74 | "Michele Ferretti (https://github.com/miccferr)", 75 | "Jon Reades (https://github.com/jreades)", 76 | "James Millington (https://github.com/jamesdamillington)" 77 | ], 78 | "git": { 79 | "active_branch": "master", 80 | "author.name": "Jon Reades", 81 | "authored_date": "2017-06-05 16:12:59", 82 | "committed_date": "2017-06-05 16:12:59", 83 | "committer.name": "Jon Reades", 84 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 85 | } 86 | } 87 | }, 88 | "source": [ 89 | "## The Benefits of Coding?\n", 90 | "\n", 91 | "In a practical context we think that the benefits of learning to code fall into three categories:\n", 92 | "1. **Flexibility**: a computer can often apply the _same_ analytical process to a completely different data set (_e.g._ rainfall in UK vs rainfall in the US) with minimal effort compared to trying to do each step manually in, say, Excel or SPSS. For students it comes down to this: if you discover a newer, better data set half way through your dissertation and want to use this for your analysis instead of the old, inaccurate data, it's a lot easier and faster to update your analyses if you have used code to do the analysis to-date!\n", 93 | "2. **Reproducibility**: recently, it's been discovered that a lot of research cannot be reproduced. In other words, if one scientist tries to duplicate what someone else did in order to check something out (as is important in the scientific method) they're finding that the results don't line up. So a second example of why coding your data analysis for a dissertation: you've just finished your analysis when someone points out that you made a mistake with the data right back at the beginning; redoing all of that in Excel or SPSS would be a nightmare, but with code it can be as easy as changing one line and hitting 'Run'!\n", 94 | "3. **Scalability**: a computer doesn't care if you throw 10 lines or 10 billion lines at it, the only thing that changes is how long it takes to get an answer. In other words, if your code 'works' on a subset of your data it should also work on your entire data set no matter how big it is. This is also a good way to develop code: rather than try to read in the whole data set in one go while you're still trying to understand it, take a few rows and make sure you're handling _those_ ones correctly (and if what you see squares with what you were told) before expanding to larger and larger subsets.\n", 95 | "\n", 96 | "Often, the payoff for coding the answer to a problem instead of just clicking through the options in SPSS or Arc can seem a long way away. It's like learning a new language: you spend a lot of time asking directions to the train station or whether someone had a nice breakfast before you can start work on the novel or the business case. But the payoff _is_ there if you stick with it!" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": { 102 | "geopyter": { 103 | "Contributors": [ 104 | "Michele Ferretti (https://github.com/miccferr)", 105 | "Jon Reades (https://github.com/jreades)", 106 | "James Millington (https://github.com/jamesdamillington)", 107 | "Michele Ferretti (https://github.com/miccferr)", 108 | "Jon Reades (https://github.com/jreades)", 109 | "James Millington (https://github.com/jamesdamillington)" 110 | ], 111 | "git": { 112 | "active_branch": "master", 113 | "author.name": "Jon Reades", 114 | "authored_date": "2017-06-05 16:12:59", 115 | "committed_date": "2017-06-05 16:12:59", 116 | "committer.name": "Jon Reades", 117 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 118 | } 119 | } 120 | }, 121 | "source": [ 122 | "## The 3 virtues of a programmer\n", 123 | "\n", 124 | "Another useful idea comes from [Larry Wall](https://en.wikipedia.org/wiki/Larry_Wall) (the man with the strong 'tache game below!), who created a programming language called Perl. Larry said that programmers had three virtues: **Laziness, Hubris, and Impatience**. \n", 125 | "\n", 126 | "\n", 127 | "\n", 128 | "Some of the reasons that these are virtues in programming (but not in your studies!) are as follows:\n", 129 | "\n", 130 | "1. **Laziness** makes you want to put in the effort _now_ to reduce the amount of effort you'll have to put in _later_. It might be a lot of work to produce a map of _one_ US State automatically using code, but once you've worked out how to do it for one state, then you've also figured out how to do it for _all 50_! That is useful laziness.\n", 131 | "2. **Hubris** makes you want to write code that other people won't want to \"say bad things about\". Over time you'll come to understand more intuitively what makes 'good' code in more detail (and we cover it a bit in the last notebook), but the short version is: it's efficient, it's easy to read, and it's clever.\n", 132 | "3. **Impatience** is about wanting the answer _now_ and looking for ways to get _there_ as quickly as possible. Being impatient doesn't mean just jumping into writing code, it actually means that you _first_ look too see whether and how other people have solved similar problems before starting work on your own code. Rather than reinventing the wheel, we try to stand on the shoulder of giants.\n", 133 | "\n", 134 | "**_Hint_**: you'll see a lot of laziness when you start trying to write code. Programmers don't like writing **`remove`** when they could just write **`rm`**, nor do they like writing **`define`** when they could just write **`def`**. Keep an eye out for these mnemonics as they can be pretty daunting at first." 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": { 140 | "geopyter": { 141 | "Contributors": [ 142 | "Michele Ferretti (https://github.com/miccferr)", 143 | "Jon Reades (https://github.com/jreades)", 144 | "James Millington (https://github.com/jamesdamillington)", 145 | "Michele Ferretti (https://github.com/miccferr)", 146 | "Jon Reades (https://github.com/jreades)", 147 | "James Millington (https://github.com/jamesdamillington)" 148 | ], 149 | "git": { 150 | "active_branch": "master", 151 | "author.name": "Jon Reades", 152 | "authored_date": "2017-06-05 16:12:59", 153 | "committed_date": "2017-06-05 16:12:59", 154 | "committer.name": "Jon Reades", 155 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 156 | } 157 | } 158 | }, 159 | "source": [ 160 | "### The 3 false virtues\n", 161 | "\n", 162 | "Larry also pointed out that these virtues had three mirror-image false virtues:\n", 163 | "\n", 164 | "1. **False laziness** happens when you leave something working but half-finished and, most likely, about to break. When you start using [StackOverflow](http://www.stackoverflow.com/) you may find that it makes it easy to copy+paste answers into your notebook and then you can glue it together messily. This isn't the same as _understanding_ and _adapting_ the solution that you found online to _your_ problem, so it's false laziness. To really develop a learning mindset, [don't copy+paste code, type it out](https://medium.freecodecamp.com/the-benefits-of-typing-instead-of-copying-54ed734ad849#.es5mw1j0z). \n", 165 | "2. **False hubris** is thinking that no one else's code is 'good enough' for you. Sometimes copy+paste is false laziness, but refusing to recognise when copy+paste (or importing a library, more on this later) _is_ the right thing to do is false hubris.\n", 166 | "3. **False impatience** is getting started on coding your answer to a problem when you don't yet understand what the problem actually _is_. One thing that a lot of programmers do is half-listen to what someone has asked them to do and then go haring off without sitting down to make any kind of plan. It's like writing an essay without having done the readings. Nudge, nudge.\n", 167 | "\n", 168 | "There's a lot more thinking on this here: http://blog.teamtreehouse.com/the-programmers-virtues" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "metadata": {}, 174 | "source": [ 175 | "## On Accessible Code\n", 176 | "\n", 177 | "In the early days of computing, programs weren't even written in English (or any other human language), they were written in Assembly/Machine Code. One of the people who thought that was crazy was this rather impressive Rear Admiral:\n", 178 | "\n", 179 | "\n", 180 | "\n", 181 | "[Grace Hopper](https://en.wikipedia.org/wiki/Grace_Hopper) felt that applications should be written in a way that more people could understand; this would be good for the military, but it would also be good for business and society in general. For her efforts she is now known as the Mother of COBOL (the COmmon Business Oriented Language), a language that is still in (some) use today. " 182 | ] 183 | } 184 | ], 185 | "metadata": { 186 | "anaconda-cloud": {}, 187 | "geopyter": { 188 | "Contributors": [ 189 | "Michele Ferretti (https://github.com/miccferr)", 190 | "Jon Reades (https://github.com/jreades)", 191 | "James Millington (https://github.com/jamesdamillington)" 192 | ], 193 | "git": { 194 | "active_branch": "master", 195 | "author.name": "Jon Reades", 196 | "authored_date": "2017-06-05 16:12:59", 197 | "committed_date": "2017-06-05 16:12:59", 198 | "committer.name": "Jon Reades", 199 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 200 | }, 201 | "libs": {} 202 | }, 203 | "kernelspec": { 204 | "display_name": "Python 3", 205 | "language": "python", 206 | "name": "python3" 207 | }, 208 | "language_info": { 209 | "codemirror_mode": { 210 | "name": "ipython", 211 | "version": 3 212 | }, 213 | "file_extension": ".py", 214 | "mimetype": "text/x-python", 215 | "name": "python", 216 | "nbconvert_exporter": "python", 217 | "pygments_lexer": "ipython3", 218 | "version": "3.6.5" 219 | } 220 | }, 221 | "nbformat": 4, 222 | "nbformat_minor": 2 223 | } 224 | -------------------------------------------------------------------------------- /atoms/foundations/.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints 2 | *DS_Store 3 | -------------------------------------------------------------------------------- /atoms/foundations/Debugging.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Notebook-3: Dealing with Errors & Debugging\n", 8 | "\n", 9 | "- Contributors: Michele Ferretti (mic.ferretti@gmail.com); Jon Reades (jon@reades.com)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "#### Lesson Topics: \n", 17 | "\n", 18 | "- Introduction to errors \n", 19 | " - Syntax Errors\n", 20 | " - Exceptions \n", 21 | "- How to read errors\n", 22 | "- Learn to find help\n", 23 | "\n", 24 | "Welcome to the third Code Camp notebook! This lesson is all about learning to deal with the (unavoidable) errors that you wil encounter when programming in Ptyhon. Most programmers spend _most_ of their day dealing with errors of one sort or another: sometimes they are easy to solve (e.g. you mis-typed a variable name), other times they are very, very hard (e.g. you are writing a cloud computing platform and have to deal with competition for resources). Either way, learning how to find, diagnose, and resolve errors, as well as how to minimize their consequences, is thus a crucial skill for programmers. \n", 25 | "\n", 26 | "*DISCLAIMER: This notebook is heavily based on the [official Python Documentation](https://docs.python.org/2/tutorial/errors.html) about Errors and Exception. Check it out for further examples.*" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "---\n", 34 | "# Introduction to errors\n", 35 | "\n", 36 | "In the preceding notebooks we've already pointed out a few simple errors and made some suggestions about how to read them, but as you have seen when there's something wrong Python stops whatever it's doing and prints out an error message.\n", 37 | "\n", 38 | "Consider this:" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": { 45 | "collapsed": false 46 | }, 47 | "outputs": [], 48 | "source": [ 49 | "prnt \"Ouch!\"" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "Or our familiar \"divsion by zero\" example:" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": { 63 | "collapsed": false 64 | }, 65 | "outputs": [], 66 | "source": [ 67 | "45 / 0" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "As you can see, depending on what just broke we see different error messages fromy the Python interpreter. Although it's not the most crucial distinction, there are roughly two main kinds of errors: **Syntax Errors** and **Exceptions**." 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "## Syntax Errors\n", 82 | "\n", 83 | "A Syntax Error is likely to the be the most frequent error you encounter when you're getting started. Syntax errors occur when the Python interpreter has trouble *[parsing](https://en.wikipedia.org/wiki/Parsing)* your code. In other words, it can read what you've typed but it doesn't quite make sense.\n", 84 | "\n", 85 | "It's a bit like when someone who doesn't speak your language fluently makes a mistake that to you seems funny, but to them is quite natural because they're extrapolating from what they know in a different language. Many English-speakers who are 'embarassed' by their level of Spanish are also apparently happy to inform Spanish-speakers that they are pregnant ('embarazada')! Or perhaps you think that the opposite of 'regardless' is 'irregardless'? These are natural mistakes, but they are 'errors' nonetheless. It's just that human beings – being smart – can figure out what you meant, while computers – being almost irredeemably stupid – cannot.\n", 86 | "\n", 87 | "### A simple typo\n", 88 | "In the first example for instance, the error consists in a misspelled `print` command:\n", 89 | "\n", 90 | "```python\n", 91 | "File \"\", line 1\n", 92 | " prnt \"Ouch!\"\n", 93 | " ^\n", 94 | "SyntaxError: invalid syntax\n", 95 | "```\n", 96 | "\n", 97 | "Let's read the error message together, from top-to-bottom: \n", 98 | "- First, the interpreter prints out the file name and the line number where it thinks the error can be found. In our simple case that's not a big deal since we only have two lines of code anyway, but if you had thousands of lines of code spread across dozens of separate files this could be a life-saver!\n", 99 | "- In addition, Python also prints the _actual_ line where it threw up its hands and said \"I can't read this!\" \n", 100 | "- It has even added a little 'caret' ( ‸ ) to try to point out where on that line it _thinks_ the error is. We wouldn't recommend that you study _only_ that bit of code (it pointed to 'Ouch!' after all, not to `prnt`) but it's not a bad place to start.. \n", 101 | "- Lastly, Python prints out vye clearly that the error is something to do with the syntax.\n", 102 | "\n", 103 | "```python\n", 104 | "SyntaxError: invalid syntax\n", 105 | "```\n", 106 | "\n", 107 | "It really can't get better than this. Let's try to see if you can fix some bits of broken code by reading the errors and spotting the place where I've made some mistakes.\n", 108 | "\n", 109 | "\n" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "### A Challenge for You!" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": null, 122 | "metadata": { 123 | "collapsed": false 124 | }, 125 | "outputs": [], 126 | "source": [ 127 | "projection=\"Cassini-Soldner\" \n", 128 | "print \"The \" projection + \" preserves distances along the central meridian.\"" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "*Hint:* remember to look at what is happening *before* the caret!" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": null, 141 | "metadata": { 142 | "collapsed": false 143 | }, 144 | "outputs": [], 145 | "source": [ 146 | "other_projection \"Mollweide\"\n", 147 | "print \"In the \" + other_projection + \" projection, meridians are ellipses.\"" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "*Hint:* which line is the error on?" 155 | ] 156 | }, 157 | { 158 | "cell_type": "markdown", 159 | "metadata": {}, 160 | "source": [ 161 | "## Exceptions\n", 162 | "\n", 163 | "Even if your code is syntatically exemplary (i.e. it's all perfectly written before you hit 'run'), errors might still occur for a wide variety of reasons: your computer is freaking out, you're not online, you haven't defined a variable yet... Obviously, these aren't syntax errors because your code would ordinarly work fine, it's just that something is missing and we think this is... _exceptional_. \n", 164 | "\n", 165 | "To help you find out which of the problems you've just hit, Python has the concept of exceptions and a huge taxonomy of specific errors ([here's a list](https://docs.python.org/2/library/exceptions.html)). That way, when something exceptional happens we know whether to restart the computer, check the Internet connection, or look for the place where the variable was supposedly defined.\n", 166 | "\n", 167 | "Let's start by considering these two *exception* examples:" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "metadata": { 174 | "collapsed": false 175 | }, 176 | "outputs": [], 177 | "source": [ 178 | "print london + \"has an approx. popoulation of 8.5 million people \"\n" 179 | ] 180 | }, 181 | { 182 | "cell_type": "markdown", 183 | "metadata": {}, 184 | "source": [ 185 | "What do you think is going on here? What's the 'value' stored in the London variable here?" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": null, 191 | "metadata": { 192 | "collapsed": false 193 | }, 194 | "outputs": [], 195 | "source": [ 196 | "\"london has an approx. popoulation of\" + 8.5 + \"million people \"\n" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": {}, 202 | "source": [ 203 | "We've seen this error before: remember that programmers don't like to write 'string' when they could write 'str', and that 'float' means 'floating point number'." 204 | ] 205 | }, 206 | { 207 | "cell_type": "markdown", 208 | "metadata": {}, 209 | "source": [ 210 | "And now let's reconsider the \"Division By Zero\" Exception:" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "metadata": { 217 | "collapsed": false 218 | }, 219 | "outputs": [], 220 | "source": [ 221 | "4 / 0" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "First of all we can see that every exception displays a specific message in the last line which gives you useful information about what just went wrong. That's because* exceptions* are different from plain *syntax errors* because they come in different types which are recognized by Python and printed accordingly. In our three examples above the *Exceptions* were: `NameError`, `TypeError`and `ZeroDivisionError`. These are the *exception types*.\n", 229 | "\n", 230 | "As with the *syntax errors*, the remaining part of the error message gives us useful pointers to how to go about fixing the code:\n", 231 | "\n", 232 | "- Once again Python starts with the location. This time though, it doesn't immediately point to a specific line but rather it explicits the *stack traceback*[1](https://en.wikipedia.org/wiki/Stack_trace)[2](https://en.wikipedia.org/wiki/Call_stack#STACK-FRAME) level (i.e. **very roughly speaking** the list of operations active in your code) where some mischief happened. \n", 233 | "\n", 234 | "- Luckly, there's a line reference in the following line (see the purple arrow (--->) pointing at line 1)\n", 235 | "\n", 236 | "```python\n", 237 | " in () \n", 238 | "----> 1 4 / 0\n", 239 | "ZeroDivisionError: integer division or modulo by zero\n", 240 | "\n", 241 | "```\n", 242 | "\n", 243 | "Do you see how these are different from *Syntax Errors* conceptually and that they require you to do something different? Indeed, *Exceptions* are clearly specified in the language for two main reasons:\n", 244 | "\n", 245 | "- It allows you to restrict the range of possibilities regarding what went wrong, allowing faster and easier debugging. \n", 246 | "- Because exceptions are \"named\" errors, they're easier for the programmer to \"catch\" when the code is running. \n", 247 | "\n", 248 | "In other words, you can't know in advance whether your application will always have Internet access, so rather than just having your program 'blow up' or say \"Can't run, sorry!\", wouldn't it be better if it printed a helpful message to the user saying \"Hey, I don't seem to be online. Can you check the network connection?\" So in Python, one part of the application can 'throw' an exception (\"Hey, I'm not online\") when it tries to download a file and then it's up to the application to _catch_ that problem and print a warning to the user.\n", 249 | "\n", 250 | "If you see any of the following commands `TRY/EXCEPT/FINALLY` then that means a programmer is trying to limit the damage that could be caused by an exception." 251 | ] 252 | }, 253 | { 254 | "cell_type": "markdown", 255 | "metadata": {}, 256 | "source": [ 257 | "### A Challenge for You!" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": null, 263 | "metadata": { 264 | "collapsed": false 265 | }, 266 | "outputs": [], 267 | "source": [ 268 | "london_population= 8600000\n", 269 | "print london_population + \" is greater than \" + paris_population " 270 | ] 271 | }, 272 | { 273 | "cell_type": "markdown", 274 | "metadata": {}, 275 | "source": [ 276 | "HINT: define a new variable with the amount of people living in the French capital _AND_ think about the _type_ of data that `london_population` and `paris_population` hold." 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": null, 282 | "metadata": { 283 | "collapsed": false 284 | }, 285 | "outputs": [], 286 | "source": [ 287 | "paris_population = '2.4'\n", 288 | "london_population / paris_population " 289 | ] 290 | }, 291 | { 292 | "cell_type": "markdown", 293 | "metadata": {}, 294 | "source": [ 295 | "HINT: Remember that you can convert a number into a string with the appropriate function" 296 | ] 297 | }, 298 | { 299 | "cell_type": "markdown", 300 | "metadata": {}, 301 | "source": [ 302 | "# How to read errors\n", 303 | "---\n", 304 | "\n", 305 | "Here's a \"rule of thumb\" list of actions to take when Python throws an error at you:\n", 306 | "\n", 307 | "- *Don't Panic!*\n", 308 | "- Take a deep breath and *READ CAREFULLY* the error message.\n", 309 | "- Ask yourself: is it a *Syntax Error* or an *Exception*?\n", 310 | "- In both cases: where's the faulty line?\n", 311 | "- For *Syntax Errors*: where's the little caret character ( ‸ ) pointing at?\n", 312 | "- For *Exceptions*: what kind of exception is that? Read the [Official Docs](https://docs.python.org/2/library/exceptions.html) and try to make sense of it\n", 313 | "- *No, really. Don't Panic!*" 314 | ] 315 | }, 316 | { 317 | "cell_type": "markdown", 318 | "metadata": {}, 319 | "source": [ 320 | "# Learn to find help\n", 321 | "---\n", 322 | "\n", 323 | "As we briefely mentioned in the opening Notebook-0, [Google is your friend!](http://lmgtfy.com/?q=%22Learning+what+questions+to+ask+is+a+skill+in+itself%22+-Somebody+smart). And we really mean it. \n", 324 | "\n", 325 | "![stackOverflow](img/stack-overflow.jpg)\n", 326 | "\n", 327 | "Learning what to look for when something goes awry in your code is the first step in order to fix it. The second is consulting all the available resources (and then -only then- you *might* think about asking for help).\n", 328 | "Thus knowing where to look for additional information is of paramount importance. The largest website/community/forum online that programmers from all over the world (and regardless of the technology/programming language they are using) consult daily is **StackOverflow**.\n", 329 | "\n", 330 | "Its name itself is a nerdy inside joke to a *bad* situation in programming:\n", 331 | "\n", 332 | ">When a program attempts to use more space than is available on the call stack... the stack is said to overflow, typically resulting in a program crash. (source: [Wikipedia](https://en.wikipedia.org/wiki/Stack_overflow) )\n", 333 | "\n", 334 | "AS the name implies that's the first resource that you want to consult in case your programs is not behaving as expected. For a quick overview of it's features refer directly to [StackOverflow's intro section](http://stackoverflow.com/tour).\n", 335 | "\n", 336 | "Lastly, in order to maximise your chances of success (and to avoid flooding the board with unclear and repetitive questions) read thoroughly the [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) section and always refer to the [Help Center](http://stackoverflow.com/help/asking).\n", 337 | "\n", 338 | "This is not meant to put you off in any way, but rather to let you know from the first moment what is the appropriate Netiquette and accetable code of conduct that will make you stand out as competent programmer, even when you are asking for help.\n", 339 | "\n", 340 | "\n" 341 | ] 342 | }, 343 | { 344 | "cell_type": "markdown", 345 | "metadata": {}, 346 | "source": [ 347 | "# Code (Applied Geo-example)\n", 348 | "---" 349 | ] 350 | }, 351 | { 352 | "cell_type": "markdown", 353 | "metadata": {}, 354 | "source": [ 355 | "If in the previous notebook we didn't even left the UK, this time we'll fly to the far away magical [Null Island](https://en.wikipedia.org/wiki/Null_Island).\n", 356 | "\n", 357 | "![null-islan](img/null-island.png)\n", 358 | "\n", 359 | "From its official government's [touristic office](http://www.nullisland.com/):\n", 360 | " \n", 361 | "> The Republic of Null Island\t \n", 362 | "> *LIKE NO PLACE ON EARTH!*\n", 363 | "\n", 364 | "\n", 365 | "In order to get there, you'll have to first solve the exercise, avoiding those pesky *Syntax Errors* and *Exceptions\"!" 366 | ] 367 | }, 368 | { 369 | "cell_type": "code", 370 | "execution_count": null, 371 | "metadata": { 372 | "collapsed": false 373 | }, 374 | "outputs": [], 375 | "source": [ 376 | "longitude = ???(0.0)\n", 377 | "latitude ??? str(0.0)\n", 378 | "\n", 379 | "\n", 380 | "# King's College marker\n", 381 | "KCL_position = \"https://www.openstreetmap.org/?mlat=\"+???+\"&mlon=\"+longitude+\"#map=5/\"+latitude+\"/\"+longitude\n", 382 | " \n", 383 | "prnt KCL_position\n" 384 | ] 385 | }, 386 | { 387 | "cell_type": "markdown", 388 | "metadata": {}, 389 | "source": [ 390 | "**Congratulations on your finishing you second lesson, and enjoy your trip to the beautiful Null Island!*** \n", 391 | "\n", 392 | "\n" 393 | ] 394 | }, 395 | { 396 | "cell_type": "markdown", 397 | "metadata": {}, 398 | "source": [ 399 | "To conclude: remember to always read the output, and try to understand what Python is telling you. You might learn a lot from these simple messages! " 400 | ] 401 | }, 402 | { 403 | "cell_type": "markdown", 404 | "metadata": {}, 405 | "source": [ 406 | "### Further references:\n", 407 | "\n", 408 | "\n", 409 | "For more information on the island you might watch this [short video](https://motherboard.vice.com/read/a-journey-to-the-center-of-null-island). \n", 410 | "\n", 411 | "If you are on Twitter, don't forget to follow the [Null Island buoy](https://twitter.com/NullIslandBuoy)!\n", 412 | "\n", 413 | "\n", 414 | "General list or resources\n", 415 | "- [Awesome list of resources](https://github.com/vinta/awesome-python)\n", 416 | "- [Python Docs](https://docs.python.org/2.7/tutorial/introduction.html)\n", 417 | "- [HitchHiker's guide to Python](http://docs.python-guide.org/en/latest/intro/learning/)\n", 418 | "- [Python for Informatics](http://www.pythonlearn.com/book_007.pdf)\n", 419 | "- [Learn Python the Hard Way](http://learnpythonthehardway.org/book/)\n", 420 | "- [CodeAcademy](https://www.codecademy.com/learn/python)\n", 421 | "\n" 422 | ] 423 | }, 424 | { 425 | "cell_type": "code", 426 | "execution_count": null, 427 | "metadata": { 428 | "collapsed": true 429 | }, 430 | "outputs": [], 431 | "source": [] 432 | } 433 | ], 434 | "metadata": { 435 | "anaconda-cloud": {}, 436 | "kernelspec": { 437 | "display_name": "Python [Root]", 438 | "language": "python", 439 | "name": "Python [Root]" 440 | }, 441 | "language_info": { 442 | "codemirror_mode": { 443 | "name": "ipython", 444 | "version": 2 445 | }, 446 | "file_extension": ".py", 447 | "mimetype": "text/x-python", 448 | "name": "python", 449 | "nbconvert_exporter": "python", 450 | "pygments_lexer": "ipython2", 451 | "version": "2.7.12" 452 | } 453 | }, 454 | "nbformat": 4, 455 | "nbformat_minor": 0 456 | } 457 | -------------------------------------------------------------------------------- /atoms/foundations/Jupyter.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "geopyter": { 7 | "Contributors": "Jon Reades (https://github.com/jreades)", 8 | "git": { 9 | "active_branch": "master", 10 | "author.name": "Jon Reades", 11 | "authored_date": "2017-06-05 16:12:59", 12 | "committed_date": "2017-06-05 16:12:59", 13 | "committer.name": "Jon Reades", 14 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 15 | } 16 | } 17 | }, 18 | "source": [ 19 | "# Getting Started" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "geopyter": { 26 | "Contributors": [ 27 | "Michele Ferretti (https://github.com/miccferr)", 28 | "Jon Reades (https://github.com/jreades)", 29 | "James Millington (https://github.com/jamesdamillington)", 30 | "Michele Ferretti (https://github.com/miccferr)", 31 | "Jon Reades (https://github.com/jreades)", 32 | "James Millington (https://github.com/jamesdamillington)" 33 | ], 34 | "git": { 35 | "active_branch": "master", 36 | "author.name": "Jon Reades", 37 | "authored_date": "2017-06-05 16:12:59", 38 | "committed_date": "2017-06-05 16:12:59", 39 | "committer.name": "Jon Reades", 40 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 41 | } 42 | } 43 | }, 44 | "source": [ 45 | "## This is a Jupyter Notebook\n", 46 | "\n", 47 | "There's no reason you'd know this yet, but the web page you're looking at is also known as a 'Jupyter notebook' -- it's why you can 'run' code as part of the web page. Check out this example by clicking in the box (next to the In [ ]) and hitting the 'run' button in the toolbar above or typing Ctrl+Return at the same time." 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": { 54 | "geopyter": { 55 | "Contributors": [ 56 | "Michele Ferretti (https://github.com/miccferr)", 57 | "Jon Reades (https://github.com/jreades)", 58 | "James Millington (https://github.com/jamesdamillington)", 59 | "Michele Ferretti (https://github.com/miccferr)", 60 | "Jon Reades (https://github.com/jreades)", 61 | "James Millington (https://github.com/jamesdamillington)" 62 | ], 63 | "git": { 64 | "active_branch": "master", 65 | "author.name": "Jon Reades", 66 | "authored_date": "2017-06-05 16:12:59", 67 | "committed_date": "2017-06-05 16:12:59", 68 | "committer.name": "Jon Reades", 69 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 70 | } 71 | } 72 | }, 73 | "outputs": [], 74 | "source": [ 75 | "print('Hello world')" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "If all has gone well you should have seen `Hello world` appear on a line all on its own. That was Python code running in a notebook. Here's some more code:" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": {}, 89 | "outputs": [], 90 | "source": [ 91 | "print( (1+2+3+4)/4 )" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "You can check that this gave you the right answer at the bottom of this page. \n", 99 | "\n", 100 | "Anyway, because of their history, some people will call these \"iPython notebooks\", others will came them \"Jupyter notebooks\", and some will just stick with \"notebooks\". They are all the same thing. \n", 101 | "\n", 102 | "Here's some more code to run as proof that this is actual code:" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": { 109 | "scrolled": true 110 | }, 111 | "outputs": [], 112 | "source": [ 113 | "import sys\n", 114 | "print(sys.version)" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": { 120 | "geopyter": { 121 | "Contributors": [ 122 | "Michele Ferretti (https://github.com/miccferr)", 123 | "Jon Reades (https://github.com/jreades)", 124 | "James Millington (https://github.com/jamesdamillington)", 125 | "Michele Ferretti (https://github.com/miccferr)", 126 | "Jon Reades (https://github.com/jreades)", 127 | "James Millington (https://github.com/jamesdamillington)" 128 | ], 129 | "git": { 130 | "active_branch": "master", 131 | "author.name": "Jon Reades", 132 | "authored_date": "2017-06-05 16:12:59", 133 | "committed_date": "2017-06-05 16:12:59", 134 | "committer.name": "Jon Reades", 135 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 136 | } 137 | } 138 | }, 139 | "source": [ 140 | "You don't need to understand all of that output, the point is that this is Python and we can do anything in a notebook that we would in a program.\n", 141 | "\n", 142 | "Rather than throw you in at the deep end with examples taken from computer science classes, for Code Camp we've tried to give you _geographical_ examples whenever possible in the hopes that the early examples will seem a _little_ less abstract and a _little_ more relevant to _your_ needs. Of course, the early examples are also very basic so the payoff might not be obvious right away, but trust us: if you stick with it you will start to change your thinking about geography as a discipline and about the power of computers to transform _everything_.\n", 143 | "\n", 144 | "So, before we do any more coding, let's think about why might want to use this technology in geography." 145 | ] 146 | } 147 | ], 148 | "metadata": { 149 | "anaconda-cloud": {}, 150 | "geopyter": { 151 | "Contributors": [ 152 | "Michele Ferretti (https://github.com/miccferr)", 153 | "Jon Reades (https://github.com/jreades)", 154 | "James Millington (https://github.com/jamesdamillington)" 155 | ], 156 | "git": { 157 | "active_branch": "master", 158 | "author.name": "Jon Reades", 159 | "authored_date": "2017-06-05 16:12:59", 160 | "committed_date": "2017-06-05 16:12:59", 161 | "committer.name": "Jon Reades", 162 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 163 | }, 164 | "libs": {} 165 | }, 166 | "kernelspec": { 167 | "display_name": "Python 3", 168 | "language": "python", 169 | "name": "python3" 170 | }, 171 | "language_info": { 172 | "codemirror_mode": { 173 | "name": "ipython", 174 | "version": 3 175 | }, 176 | "file_extension": ".py", 177 | "mimetype": "text/x-python", 178 | "name": "python", 179 | "nbconvert_exporter": "python", 180 | "pygments_lexer": "ipython3", 181 | "version": "3.6.5" 182 | } 183 | }, 184 | "nbformat": 4, 185 | "nbformat_minor": 2 186 | } 187 | -------------------------------------------------------------------------------- /atoms/foundations/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 King's Geocomputation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /atoms/foundations/Learning_a_Language.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Learning a (New) Language\n", 8 | "- Contributors: Michele Ferretti (https://github.com/miccferr); Jon Reades (https://github.com/jreades); James Millington (https://github.com/jamesdamillington)" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## Mathematics is a Language, so is Code\n", 16 | "\n", 17 | "There are obviously many ways that you can calculate the mean (also known as the _average_ if your maths is a little rusty): in your head, using pencil and paper, on a calculator, in Excel... and, of course, using code! For a small set of simple numbers, using your brain is going to be a lot faster than typing it into a calculator or computer.\n", 18 | "\n", 19 | "**_Quick_, what's the mean of: `1, 2, 3, and 4`?**\n", 20 | "\n", 21 | "### Try doing this with code!\n", 22 | "\n", 23 | "In the area immediately below this sentence you should see something like \"In [ ]\". On the right of this is an empty box into which you can type computer code. Do you remember how to calculate the mean using a set of numbers and a calculator? That's all we're doing now, it's just that we're doing it from a keyboard instead of a keypad. " 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": { 30 | "collapsed": true 31 | }, 32 | "outputs": [], 33 | "source": [] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "Type an 'equation' to calculate the mean of the four numbers above on the empty line right above this sentence and then click the 'play' button on the tool bar at the top of the window to run your first piece of Python code! If everything has gone well then you should see something like \"Out [ ]\" appear.\n", 40 | "\n", 41 | "_HINT: the 'play' button is the sideways-pointing triangle in the area underneath the currently open tab. You can **also** type Ctrl+Return (that's the Control button and the Return button simultaneously) to run the code when you've got your cursor in the code box and in the long run this will be much faster than clicking with the mouse._\n", 42 | "\n", 43 | "_HINT: Your equation should include the four numbers above with some `+` symbols and `(` and `)`, a `/` symbol, and another number._\n", 44 | "\n", 45 | "Did you get 2.5? If you didn't, don't panic! This is something that we're going to come back to again and again: computers do exactly what you tell them to do, even if you tell them to do something that you _later_ realise was a bit silly." 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "## Silly is not stupid (learning languages is hard)\n", 53 | "\n", 54 | "This is really important: **just because you told the computer to do something that you eventually realise was 'silly' does _not_ mean that _you_ are stupid**. \n", 55 | "\n", 56 | "Did you ever try to learn a foreign language? Did you expect to be fluent after a couple of classes? Assuming that you had a realistic expectation of how far you'd get with French, Chinese, or English, then you probably figured it'd be a few years before you could even hold a conversation with someone else. So why would you expect to sit down at a computer and be able to hold a conversation with it (which is another way of thinking about what coding is) after reading a few pages of text and watching a YouTube video or two?\n", 57 | "\n", 58 | "You will need to give it time, you will need to get used to looking at the documentation, you will need to ask for help (this seems like a good time to introduce [Stack Overflow](http://stackoverflow.com/)), and you will need to persevere." 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "## Practice makes perfect\n", 66 | "\n", 67 | "Your language class (assuming that you took one) probably had a 'lab' where you practiced your new language and you probably made a lot of mistakes when you were getting started. It's the same for programming: the reason you got a 'silly' answer is that we haven't taught you how to ask the right question yet! For a language like Python \"`2`\" is not the same as \"`2.0`\"... With this information can you now guess what you might need to change in the 'coding block' above to get the right answer? Don't worry if you still can't get the right answer, how to 'talk numbers' is the main topic in the _next_ notebook.\n", 68 | "\n", 69 | "So, we want you to remember that there are no stupid questions when it comes to programming. We have _all_ been lost at one point or another! Your lecturers and instructors _frequently_ still ask for help (often by asking Google!), it's just that we do it for harder questions. And that's only because we have had a lot more practice in the language of programming. So the _only_ stupid thing you can do in this course is to assume that you can speed through the questions and don't have to practice or think through the technical aspects of coding. \n", 70 | "\n", 71 | "There are web sites that will give you answers (in fact, we're going to point you to some of them) but if you don't expend any effort in trying to understand how the code works, or if you just copy the answer off of your friend, that's the same as assuming you'll learn a foreign language just because you're setting next to a friend who is taking the same language course! _That_ is silly." 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "### When computers beat brains (or calculators)\n", 79 | "\n", 80 | "What makes a computer potentially _better_ than a calculator (or your brain) is that a computer isn't daunted by having to count lots of numbers and it doesn't need you to input each number individually! The computer can also do things like: \n", 81 | "\n", 82 | "- find out the amount of rain that fell in London, Manchester, and Edinburgh yesterday from an online weather service;\n", 83 | "- work out the average rainfall for these three cities; and then \n", 84 | "- work out the standard deviation for rainfall.\n", 85 | "\n", 86 | "And it can do all of this in a matter of milliseconds! It can also do the same for 3,000 cities just as eaisly; sure, it'll take a little bit longer, but it's the _same basic code_. \n", 87 | "\n", 88 | "In other words code is [scalable](https://en.wikipedia.org/wiki/Scalability) in a way that brains and calculators are not and that is a crucial difference.\n", 89 | "\n", 90 | "Here's a trivial example of when computer start to get better and faster than brains:" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": { 97 | "collapsed": true 98 | }, 99 | "outputs": [], 100 | "source": [ 101 | "(23495.23 + 9238832.657 + 2 + 12921)/4" 102 | ] 103 | } 104 | ], 105 | "metadata": { 106 | "anaconda-cloud": {}, 107 | "kernelspec": { 108 | "display_name": "Python 3", 109 | "language": "python", 110 | "name": "python3" 111 | }, 112 | "language_info": { 113 | "codemirror_mode": { 114 | "name": "ipython", 115 | "version": 3 116 | }, 117 | "file_extension": ".py", 118 | "mimetype": "text/x-python", 119 | "name": "python", 120 | "nbconvert_exporter": "python", 121 | "pygments_lexer": "ipython3", 122 | "version": "3.6.5" 123 | } 124 | }, 125 | "nbformat": 4, 126 | "nbformat_minor": 2 127 | } 128 | -------------------------------------------------------------------------------- /atoms/foundations/Programming_and_Geography.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Programming and Geography \n", 8 | "- Contributors: Jon Reades (https://github.com/jreades)" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## The Rise (Again) of Computational Geography\n", 16 | "\n", 17 | "We live in a world transformed by big (geo)data: from Facebook likes and satellites, to travel cards and drones, the process of collecting and analysing data about the world around us is becoming very, very cheap. Twenty years ago, gathering data about the human and physical environment was expensive, but now a lot of it is generated as the ‘exhaust’ of day-to-day activity: tapping on to the bus or train, taking photos (whether from a satellite, drone, or disposable camera), making phone calls, using our credit cards, and surfing the web. And that's before you start looking at the Terabytes of data being generated by satellites, air quality and river flow sensors, and other Earth Observation Systems! \n", 18 | "\n", 19 | "As the costs of capturing, curating, and processing these data sets falls, the discipline of geography is changing. You face a world in which many of the defining career options for geographers with basic quantitative skills will either no longer exist, or will have been seriously de-skilled. So much can now be done through a web browser (e.g. [CartoDB](https://carto.com) that specifying ‘Knowledge of ArcGIS’ is becoming superfluous; not because geo-analysis jobs are no longer in demand or no longer done -- in fact, they are more vital than ever -- but because the market for these skills has split in two: expensive, specialist software is being superseded by simple, non-specialist web-based tools on the ‘basic’ side, and by customised code on the ‘advanced’ side. \n", 20 | "\n", 21 | "## What's the Difference?\n", 22 | "\n", 23 | "### Not Just Quantitative Geography\n", 24 | "\n", 25 | "Computational approaches -- which is to say, approaches to geography using code -- differ in important ways from the quantitative skills commonly taught in ‘methods’ classes: computational geography is underpinned by algorithms that employ concepts such as _iteration_ and _recursion_, and we use these to tackle everything from a data processing problem to an entire research question. For example, Alex Singleton’s OpenAtlas (available for free from the [Consumer Data Research Centre](https://data.cdrc.ac.uk/product/cdrc-2011-census-open-atlas)) contains 134,567 maps. Alex designed and wrote a script to _iterate_ over the Census areas (i.e. to ‘visit’ each area in turn when creating a map), and to _recurse_ into smaller sub-regions from larger regions (i.e. to keep drilling down into smaller and smaller geographies) in order to generate maps at, literally, every conceivable scale. Then he let the computer do the ‘boring bit’ of actually creating each and every map. \n", 26 | "\n", 27 | "### Thinking Algorithmically\n", 28 | "\n", 29 | "Thinking _algorithmically_ requires students – and professionals – to deal with abstraction: we don’t want to define how each analysis should work, or how each map should look; rather, we want to specify a set of rules about how to select and display data on a map, and then let the computer make them all for us. In this way of working it’s not really any more work to create 500 maps than it is to create 5 because we’ve been able to tell the computer how to make maps in a way that it can ‘understand’ or, more accurately, apply. But learning to think this way is _hard work_: I usually don't actually know exactly what my maps are going to look like until _after_ I've made them. Often, I'll find that the first time around they don't show quite what I want, or that what I thought would be interesting, wasn't. But the difference from the 'normal' way of working is that I make a few tweaks to my code and then just run the code again. And again... as many times as I need to in order to get what I want.\n", 30 | "\n", 31 | "### The Open Source Ethos\n", 32 | "\n", 33 | "And then I can take that code and apply it to a new problem. Or a new case study. I can post it online and let others build off of my work. Giving away my code might seem like a bad idea, but think about this: in a world of exciting research questions, are you going to be able to tackle every one? And your own work _already_ builds off of code that other people gave away... perhaps you should give back to the community? Not just because it's a good thing to do, but because people will learn who you are. They might be in a position to offer you a job, or they might approach you as a collaborator, or they might point someone else with an interesting opportunity in your direction because you have built a reputation as a contributor." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Further Reading \n", 41 | "\n", 42 | "A big gap is opening up between the stuff that can be done by pushing buttons (which no longer even really requires geographical training) and the 'cutting edge'. There are many pieces that argue this case, but here are a few to start with:\n", 43 | "\n", 44 | "* [Why the Future of Geography is Cheap](https://www.rgs.org/schools/teaching-resources/why-the-future-of-geography-is-cheap/)\n", 45 | "* [GIS Jobs of Today](http://www.directionsmag.com/entry/gis-jobs-of-today-should-you-have-programming-skills/473296): should you have programming skills?" 46 | ] 47 | } 48 | ], 49 | "metadata": { 50 | "anaconda-cloud": {}, 51 | "kernelspec": { 52 | "display_name": "Python 3", 53 | "language": "python", 54 | "name": "python3" 55 | }, 56 | "language_info": { 57 | "codemirror_mode": { 58 | "name": "ipython", 59 | "version": 3 60 | }, 61 | "file_extension": ".py", 62 | "mimetype": "text/x-python", 63 | "name": "python", 64 | "nbconvert_exporter": "python", 65 | "pygments_lexer": "ipython3", 66 | "version": "3.6.5" 67 | } 68 | }, 69 | "nbformat": 4, 70 | "nbformat_minor": 2 71 | } 72 | -------------------------------------------------------------------------------- /atoms/foundations/Programming_in_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Programming in Python\n", 8 | "\n", 9 | "- Contributors: Michele Ferretti (https://github.com/miccferr); Jon Reades (https://github.com/jreades); James Millington (https://github.com/jamesdamillington)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## Competing Computer Languages\n", 17 | "\n", 18 | "In these notebooks we will be using the Python programming language. As with human languages, there are _many_ [programming languages](http://www.computerhope.com/jargon/p/proglang.htm) in the world, each with their own advantages and disadvantages, and each with their own vocabulary (allowed words) and grammar (syntax). We use Python. " 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "### Python vs R\n", 26 | "\n", 27 | "Alongside Python, the other language that is often mentioned by people doing data-led research is [R](https://www.r-project.org). It's the _other_ one that many of your lecturers and a lot of other scientists use in a lot of their work. There's [a great deal of debate about the relative merits of Python and R](https://www.quora.com/Which-is-better-for-data-analysis-R-or-Python), but for our purposes _both_ Python and R can help us to undertake geographical analysis. That is, in fact, the premise of this entire course! \n", 28 | "\n", 29 | "So why have we chosen to use Python here? Of the two languages, we think that Python has some specific advantages:\n", 30 | "\n", 31 | "1. It was designed for teaching, so its syntax is easier for a human to 'parse' than R's\n", 32 | "2. It is more _like_ other languages, so its more readily transferrable if you need to learn another language. Think of it as learning Italian, which also makes it easier to learn Spanish and French, instead of Icelandic (no offence Iceland, we love you too!).\n", 33 | "3. It is the one most-used as part of a _geographical workflow_ – what we mean by this is that you can find Python buried inside of ESRI's ArcGIS and the open-source QGIS applications, and it also sits behind (or talks to) a number of other tools that allow us to work flexibly and scalably with geo-data. \n", 34 | "4. Is is easier to operationalise – Python offers more services/tools to enable you to turn something from a 'hack' ([which doesn't mean what you think it means](https://en.wikipedia.org/wiki/Hacks_at_the_Massachusetts_Institute_of_Technology) into a 'service'.\n", 35 | "\n", 36 | "However, if you have been told R is the way to go then don't worry, the concepts covered here still translate. And many of the contributors to to these notebooks use both languages... it just depends on the problem. \n", 37 | "\n", 38 | "Right now, we are using Python version 2.7. You can also download a version 3 of Python -- we're sticking with the older version for the time being because there are more (geo) tools available to us in Python 2 than Python 3 but we _will_ be changing soon. So, for now, if at any point you are asked to choose between Python versions, make sure you pick 2.X (there will be a 2.8 and 2.9 eventually)." 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "### Python what?\n", 46 | "Python was invented by [Guido van Rossum](https://en.wikipedia.org/wiki/Guido_van_Rossum) in the late 1980s and he continues in the role of 'benevolent dictator' to this day, which means that he (and some other very smart people) try to to ensure that the language continues to meet the basic goals of:\n", 47 | "* Being very easy to read (syntax)\n", 48 | "* Using plain-English for many functions and operators (allowed words)\n", 49 | "* Has a comprehensive style guide: [PEP8](https://www.python.org/dev/peps/pep-0008/) (syntax)\n", 50 | "* Has no unnecessary special formatting characters (syntax _and_ allowed words)\n", 51 | "\n", 52 | "So while Python is not language that enables the computer to make calculations the fastest (C and C++ are faster), nor is it the safest (you wouldn't use it to fly a rocket to Mars), it _is_ a very readable, learnable and maintainable language.\n", 53 | "\n", 54 | "So if you want to learn to code, to do 'data science', or build a business, Python is a great choice.\n", 55 | "\n", 56 | "The points above are also made in [Python In A Nutshell](http://mbrochh.github.io/python-101/#/6/1) by [Martin Brochhaus](https://github.com/mbrochh) which you may find interesting and useful to accompany your learning of Python." 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "#### Three takes on Python\n", 64 | "The images below are links to three videos pitched in quite different ways at the advantages of Python, all of which touch on issues we'll be dealing with later... so watch the videos (even if they're a bit silly in places)!\n", 65 | "\n", 66 | "[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/aXKVOLwpDg8/0.jpg)](http://www.youtube.com/watch?v=aXKVOLwpDg8)\n", 67 | "\n", 68 | "[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/Hn4FbT4wMms/0.jpg)](http://www.youtube.com/watch?v=Hn4FbT4wMms)\n", 69 | "\n", 70 | "[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/G8brQdClo9s/0.jpg)](http://www.youtube.com/watch?v=G8brQdClo9s)" 71 | ] 72 | } 73 | ], 74 | "metadata": { 75 | "anaconda-cloud": {}, 76 | "kernelspec": { 77 | "display_name": "Python 3", 78 | "language": "python", 79 | "name": "python3" 80 | }, 81 | "language_info": { 82 | "codemirror_mode": { 83 | "name": "ipython", 84 | "version": 3 85 | }, 86 | "file_extension": ".py", 87 | "mimetype": "text/x-python", 88 | "name": "python", 89 | "nbconvert_exporter": "python", 90 | "pygments_lexer": "ipython3", 91 | "version": "3.6.5" 92 | } 93 | }, 94 | "nbformat": 4, 95 | "nbformat_minor": 2 96 | } 97 | -------------------------------------------------------------------------------- /atoms/foundations/README.md: -------------------------------------------------------------------------------- 1 | # Foundational Concepts in Programming 2 | 3 | This atom contains the introductory materials to take geography students who have never programmed before from the 'hello world' level through to their first function. We deliberately ignore some of the subtleties of Python (classes, inheritance, etc.) in favour of getting students going as quickly as possible. 4 | 5 | ## Data Sets 6 | 7 | Examples in this atom make use of the following data sets: 8 | 1. [UK_Major_Metro_Areas.csv](./data/UK_Major_Metro_Areas.csv) (Derived from Wikipedia data) -- this data set contains one header row and ten observations; it is intended to be easy to read for students so that they can understand what is going on when the read in the file. The file is provided by default with a Git checkout, and the permanent remote URL is: [https://github.com/pysal/geopyter/tree/master/atoms/foundations/data/UK_Metro_Areas.csv](https://github.com/pysal/geopyter/tree/master/atoms/foundations/data/UK_Metro_Areas.csv) 9 | 2. [UK_Metro_Areas.csv](./data/UK_Metro_Areas.csv) (Derived from Wikipedia data) -- this data set contains one header row and 73 observations; it is intended to demonstrate the value of computers in parsing data sets that do _not_ scan easily. The file is provided by default with a Git checkout, and the permanent remote URL is: [https://github.com/pysal/geopyter/tree/master/atoms/foundations/data/UK_Metro_Areas.csv](https://github.com/pysal/geopyter/tree/master/atoms/foundations/data/UK_Metro_Areas.csv) 10 | 3. US Regional Income Data: this can be found in the `pysal.examples` directory under `us_income/usjoin.csv`. 11 | 12 | Since the third data set is provided by default with PySAL it does not need to be downloaded from a remote URL or checked out of Git. You access this file using the following code: 13 | ```python 14 | import os 15 | import pysal as ps 16 | f = ps.open(os.path.join(ps.examples.example_dir, 'us_income/usjoin.csv')) 17 | ``` 18 | 19 | ## Sequencing 20 | 21 | You are always free to import as much or as little of the atom as you need, but the intended sequence for the materials is: 22 | 23 | - [Why Learn to Code?](Why_Code.ipynb) 24 | - [Programming and Geography](Programming_and_Geography.ipynb) 25 | - [Learning a (New) Language](Learning_a_Language.ipynb) 26 | - [Programming in Python](Programming_in_Python.ipynb) 27 | - [A Brief Note about Jupyter](Jupyter.ipynb) 28 | - [Thinking Like a Computer](Getting_Started.ipynb) 29 | - [The Basics](Basics.ipynb) 30 | - [Dealing with Errors & Debugging](Debugging.ipynb) 31 | - [Conditions](Conditions.ipynb) 32 | - [Lists](Lists.ipynb) 33 | - [Dictionaries](Dictionaries.ipynb) 34 | - [Iteration](Iteration.ipynb) 35 | - [Functions](Functions.ipynb) 36 | 37 | -------------------------------------------------------------------------------- /atoms/foundations/Thinking_Like_a_Computer.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Thinking Like a Computer\n", 8 | "\n", 9 | "- Contributors: Michele Ferretti (https://github.com/miccferr); Jon Reades (https://github.com/jreades); James Millington (https://github.com/jamesdamillington)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## What *is* a computer?\n", 17 | "\n", 18 | "At it's most basic, a computer is a programmable device for performing calculations.\n", 19 | "\n", 20 | "_This_ is a kind of computer.\n", 21 | "\n", 22 | "\n", 23 | "As is _this_.\n", 24 | "\n", 25 | "\n", 26 | "If you've never really got to grips with what is happening inside a computer, then this TedED video would be a good way to get started because it helps to explain the basics of things like I/O and what actually happens when you click with the mouse on a button. In fact, you will see that we've used code to import the YouTube video in a way that requires me to do very little work and this is one of the strengths of programming: that someone else created the code to embed a YouTube video into an iPython notebooks (which is what this web page is) and all I need to do is know how to ask that code to find the video on the YouTube web site. Everything else happens automatically." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "### What's Going on Inside Your Computer?\n", 34 | "\n", 35 | "Let's find out through some videos – we've tried to pick ones that encompass a range of styles and levels, so we hope you'll find something that 'speaks to you' in here. If not, well Google and YouTube are your friends: we won't pretend to have all the answers and you might find by searching something that is right on your level. [This first video](http://www.youtube.com/watch?v=AkFi90lZmXA) is about what's going on inside your computer.\n", 36 | "\n", 37 | "[![What's Going On in There?](http://img.youtube.com/vi/AkFi90lZmXA/0.jpg)](http://www.youtube.com/watch?v=AkFi90lZmXA)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "### How a Computer Adds Numbers\n", 45 | "\n", 46 | "[This next video](http://www.youtube.com/watch?v=VBDoT8o4q00) is a little more technical and we don't really expect you to remember it, but it touches on a lot of really important concepts: binary numbers, Boolean logic, and how these basic building blocks are assembled into much more complex processes like adding numbers or, ultimately, manipulating data.\n", 47 | "\n", 48 | "[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/VBDoT8o4q00/0.jpg)](http://www.youtube.com/watch?v=VBDoT8o4q00)" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "The really important thing to get from this last video is that computers are chaining together long sets of simple operations which always basically work out to 1 or 0, which is the same as True or False. This is [Boolean logic](http://computer.howstuffworks.com/boolean.htm) and we're going to be doing a lot more with it later in this set of sessions, but you should always keep in mind that a huge set of calculations are going on in your computer in an order specified by a set of _rules_: do 'A', then do 'B', then... When these rules become sufficiently complex they are called algorithms. And when they get so complicated that they are not easy to write down as a set of logical outputs, it's often easier to express in a more human-readable form... which is why we have [programming languages](http://www.computerhope.com/jargon/p/proglang.htm).\n", 56 | "\n", 57 | "But remember: finding the average of a set of numbers involves an algorithm (which in-turn in a digital comupter is based on lots of logical operations involving 1s and 0s). And calculating the probability that the lecturer won't show up to the first lecture also involves an algorithm, it's just that it's a much more complicated one unless you take matters into your own hands and arrange for an accident..." 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "## Computers: good or bad?\n", 65 | "\n", 66 | "What are computers good at?\n", 67 | "- Doing the same thing over and over\n", 68 | "- Doing _exactly_ what they are told to do\n", 69 | "\n", 70 | "What are computers currently still bad at?\n", 71 | "- Generating knowledge\n", 72 | "- Being creative\n", 73 | "\n", 74 | "There is a long-standing contest, called the Turing Test in honour of [the famous computer pioneer](https://en.wikipedia.org/wiki/Alan_Turing), that demonstrates this difference rather nicely: a computer passes the Turing test if it can fool a person into thinking that they're talking to another person. Some people have claimed that if a computer can _really_ pass the Turing Test by keeping up a conversation of indefinite length on any range of topics then we'll have to declare that machines have become full AIs (Artificial Intelligences). To put it another way: if it sounds like a human and responds like a human... then is it a human?\n", 75 | "\n", 76 | "Perhaps fortunately for us, althoug computers are getting a lot better at holding up their end of the conversation they still seem to have a hard time fooling anyone for very long. In contrast, bigger and better computers have now beat the best humans at Chess and Go, and are being used to help us understand earthquakes and climate change on a huge scale. Here, computers can do billions -- or trillions -- of calculations a second to work out that if 'A' happens then 'B' is the next most likely thing to happen, and so on and so on.\n", 77 | "\n", 78 | "The difference is that games like Go and Chess have well-understood rules as (ultimately) do natural processes like climate change and earthquakes. Chess is 'easier' for a computer than Go because a big enough computer can work out every possible chess move and pick the best one, whereas it can't do that for Go and so has to make 'choices' based on incomplete information. Earthquakes may have even more 'rules', but as far we know they still follow _some_ set of rules dictated by physics, chemistry, and chance. \n", 79 | "\n", 80 | "People, however, don't use the same unchanging rules in conversation. Yes, conversations have norms, unless you're using an online comment forum where it's normal to start a conversation by asking someone if they're an idiot, but people don't just 'play games' within the rules, they actually play with the rules themselves in a way that computers find very, very hard to follow. Think of sarcasm: you say one thing but mean exactly the opposite; and your delivery is sufficiently deadpan then sometimes even real people have trouble knowing if you're being sincere!\n", 81 | "\n", 82 | "That's why AI of the sort you might have seen in _2001_ or _Blade Runner_ has been twenty years away for the last sixty years! Recently, computers have been getting better and better at doing really difficult things, but it's usually still in a narrow area where we understand the rules and we normally need to spend a _lot_ of time training the computer. \n", 83 | "\n", 84 | "#### More About the Turing Test\n", 85 | "Turing, A (1950), _Computing Machinery and Intelligence, Mind_ LIX (236): 433–460\n", 86 | "doi: [10.1093/mind/LIX.236.433](http://dx.doi.org/10.1093/mind/LIX.236.433), ISSN 0026-4423" 87 | ] 88 | } 89 | ], 90 | "metadata": { 91 | "anaconda-cloud": {}, 92 | "kernelspec": { 93 | "display_name": "Python 3", 94 | "language": "python", 95 | "name": "python3" 96 | }, 97 | "language_info": { 98 | "codemirror_mode": { 99 | "name": "ipython", 100 | "version": 3 101 | }, 102 | "file_extension": ".py", 103 | "mimetype": "text/x-python", 104 | "name": "python", 105 | "nbconvert_exporter": "python", 106 | "pygments_lexer": "ipython3", 107 | "version": "3.6.5" 108 | } 109 | }, 110 | "nbformat": 4, 111 | "nbformat_minor": 2 112 | } 113 | -------------------------------------------------------------------------------- /atoms/foundations/Why_Code.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Why Learn to Code?\n", 8 | "\n", 9 | "- Contributors: Michele Ferretti (https://github.com/miccferr); Jon Reades (https://github.com/jreades); James Millington (https://github.com/jamesdamillington)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## Why _you_ should learn to program\n", 17 | "\n", 18 | "There are many good reasons for geographers to learn to code, but let's start with some good _general_ reasons why _you_ should learn to program a computer even if you never use it to make a map or complete a bit of spatial analysis: \n", 19 | "\n", 20 | "[![Why You Should Learn How to Code](http://img.youtube.com/vi/UD2xoiCGTDo/0.jpg)](https://youtu.be/UD2xoiCGTDo)\n", 21 | "\n", 22 | "And here is a useful perspective on whether or not learning to code is hard:\n", 23 | "\n", 24 | "[![Why You Should Learn How to Code](http://img.youtube.com/vi/k7Txbdvzx90/0.jpg)](https://youtu.be/k7Txbdvzx90)\n", 25 | "\n", 26 | "Perhaps the best point here is that 'making money' is (often) a nice outcome of learning to code, but having a passion for what you want to _do_ with code is what's going to get you through the learning curve. That said, you also need to be realistic: to become a professional programmer is something that happens over many years, you probably won't just take a couple of classes and then go out into the world saying \"I'm a programmer.\"\n", 27 | "\n", 28 | "And, no, you do _not_ need to know advanced maths in order to learn how to code: you need to be able to think logically and to reframe your problems in ways that align _with_ the computer." 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## The Benefits of Coding?\n", 36 | "\n", 37 | "In a practical context we think that the benefits of learning to code fall into three categories:\n", 38 | "1. **Flexibility**: a computer can often apply the _same_ analytical process to a completely different data set (_e.g._ rainfall in UK vs rainfall in the US) with minimal effort compared to trying to do each step manually in, say, Excel or SPSS. For students it comes down to this: if you discover a newer, better data set half way through your dissertation and want to use this for your analysis instead of the old, inaccurate data, it's a lot easier and faster to update your analyses if you have used code to do the analysis to-date!\n", 39 | "2. **Reproducibility**: recently, it's been discovered that a lot of research cannot be reproduced. In other words, if one scientist tries to duplicate what someone else did in order to check something out (as is important in the scientific method) they're finding that the results don't line up. So a second example of why coding your data analysis for a dissertation: you've just finished your analysis when someone points out that you made a mistake with the data right back at the beginning; redoing all of that in Excel or SPSS would be a nightmare, but with code it can be as easy as changing one line and hitting 'Run'!\n", 40 | "3. **Scalability**: a computer doesn't care if you throw 10 lines or 10 billion lines at it, the only thing that changes is how long it takes to get an answer. In other words, if your code 'works' on a subset of your data it should also work on your entire data set no matter how big it is. This is also a good way to develop code: rather than try to read in the whole data set in one go while you're still trying to understand it, take a few rows and make sure you're handling _those_ ones correctly (and if what you see squares with what you were told) before expanding to larger and larger subsets.\n", 41 | "\n", 42 | "Often, the payoff for coding the answer to a problem instead of just clicking through the options in SPSS or Arc can seem a long way away. It's like learning a new language: you spend a lot of time asking directions to the train station or whether someone had a nice breakfast before you can start work on the novel or the business case. But the payoff _is_ there if you stick with it!" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "## The 3 virtues of a programmer\n", 50 | "\n", 51 | "Another useful idea comes from [Larry Wall](https://en.wikipedia.org/wiki/Larry_Wall) (the man with the strong 'tache game below!), who created a programming language called Perl. Larry said that programmers had three virtues: Laziness, Hubris, and Impatience. \n", 52 | "\n", 53 | "\n", 54 | "\n", 55 | "Some of the reasons that these are virtues in programming (but not in your studies!) are as follows:\n", 56 | "\n", 57 | "1. **Laziness** makes you want to put in the effort _now_ to reduce the amount of effort you'll have to put in _later_. So it might take a lot of work to produce a map of _one_ US State automatically using code, but as as your _data_ is good then once you've worked out how to do it for one state, you've also figured out how to do it for _all 50_!\n", 58 | "2. **Hubris** makes you want to write code that other people won't want to \"say bad things about\". In the course we'll get into what makes 'good' code in more detail, but the short version is: it's efficient, it's easy to read, and it's clever.\n", 59 | "3. **Impatience** is about wanting the answer _now_ and looking for ways to get there as quickly as possible. That actually means that you first look too see if and how other people have solved similar problems before starting work on your own code. Rather than reinventing the wheel, we try to stand on the shoulder of giants.\n", 60 | "\n", 61 | "**_Hint: you'll also see a lot of laziness when you start trying to write code. Programmers don't like writing `remove` when they could just write `rm`, nor do they like writing `define` when they could just write `def`. Keep an eye out for these mnemonics as they can be pretty daunting at first._**" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "### The 3 false virtues\n", 69 | "\n", 70 | "Larry also pointed out that these virtues had three mirror-image false virtues:\n", 71 | "\n", 72 | "1. **False laziness** happens when you leave something working but half-finished and, most likely, about to break. When you start using [StackOverflow](http://www.stackoverflow.com/) you may find that it makes it easy to copy+paste answers into your notebook and then you can glue it together messily. This isn't the same as _understanding_ and _adapting_ the solution that you found online to _your_ problem, so it's false laziness. To really develop a learning mindset, [don't copy+paste code, type it out](https://medium.freecodecamp.com/the-benefits-of-typing-instead-of-copying-54ed734ad849#.es5mw1j0z). \n", 73 | "2. **False hubris** is thinking that no one else's code is 'good enough' for you. Sometimes copy+paste is false laziness, but refusing to recognise when copy+paste (or importing a library, more on this later) _is_ the right thing to do is false hubris.\n", 74 | "3. **False impatience** is getting started on coding your answer to a problem when you don't yet understand what the problem actually _is_. One thing that a lot of programmers do is half-listen to what someone has asked them to do and then go haring off without sitting down to make any kind of plan. It's like writing an essay without having done the readings. Nudge, nudge.\n", 75 | "\n", 76 | "There's a lot more thinking on this here: http://blog.teamtreehouse.com/the-programmers-virtues" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "## Being a 'good' programmer\n", 84 | "\n", 85 | "The best way to be a 'good' programmer is to know when the computer can help you and when it will just get in the way. A computer cannot 'solve' a problem for you, but it _can_ help you to find the answer when you've told it what to look for and what rules to use in that search. A computer can only do _exactly_ what you tell it to do, so if you don't know what to do then the computer won't either.\n", 86 | "\n", 87 | "One of the founders of computing, [Charles Babbage](https://en.wikiquote.org/wiki/Charles_Babbage#Passages_from_the_Life_of_a_Philosopher_.281864.29) had this to say:\n", 88 | "\n", 89 | "> On two occasions I have been asked, — \"Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?\" In one case a member of the Upper, and in the other a member of the Lower, House put this question. I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.\n", 90 | "> _Passages from the Life of a Philosopher (1864), ch. 5 \"Difference Engine No. 1\"_\n", 91 | "\n", 92 | "Modern programmers call this: garbage in, garbage out. GIGO, for short.\n", 93 | "\n", 94 | "**_The single most important thing that you can learn is how to think abstractly about solving a problem in a way that you can communicate to a computer._** \n", 95 | "\n", 96 | "What we mean is this: the real power of the computer isn't figuring out how to add `1, 2, 3, 4` together and calculate the mean, it's figuring out how to add _any possible set of numbers_ together and get the computer to work out the mean. That's what we mean about abstraction: it's not solving the problem _once_, it's solving any set of related problems _at the same time_! \n", 97 | "\n", 98 | "These notebooks will get you started down that path, but remember: you're not stupid if you don't know how to explain things to the computer so that it can help you find the answer. You're still learning the basics of how to communicate with computers; there are two things that _are_ silly: the first is expecting to be able to run before you can walk; the second is copying and pasting answers without trying to understand _why_ they are answers." 99 | ] 100 | } 101 | ], 102 | "metadata": { 103 | "anaconda-cloud": {}, 104 | "kernelspec": { 105 | "display_name": "Python 3", 106 | "language": "python", 107 | "name": "python3" 108 | }, 109 | "language_info": { 110 | "codemirror_mode": { 111 | "name": "ipython", 112 | "version": 3 113 | }, 114 | "file_extension": ".py", 115 | "mimetype": "text/x-python", 116 | "name": "python", 117 | "nbconvert_exporter": "python", 118 | "pygments_lexer": "ipython3", 119 | "version": "3.6.5" 120 | } 121 | }, 122 | "nbformat": 4, 123 | "nbformat_minor": 2 124 | } 125 | -------------------------------------------------------------------------------- /atoms/foundations/data/UK_Major_Metro_Areas.csv: -------------------------------------------------------------------------------- 1 | id,Name,Rank,Longitude,Latitude,Population 2 | 1,Greater London,1,-18162.92767,6711153.709,9787426 3 | 2,Greater Manchester,2,-251761.802,7073067.458,2553379 4 | 3,West Midlands,3,-210635.2396,6878950.083,2440986 5 | 4,West Yorkshire,4,-185959.3022,7145450.207,1777934 6 | 5,Glasgow,5,-473845.2389,7538620.144,1209143 7 | 6,Liverpool,6,-340595.1768,7063197.083,864122 8 | 7,South Hampshire,7,-174443.8647,6589419.084,855569 9 | 8,Tyneside,8,-187604.3647,7356018.207,774891 10 | 9,Nottingham,9,-131672.2399,6979298.895,729977 11 | 10,Sheffield,10,-163545.3257,7055177.403,685368 -------------------------------------------------------------------------------- /atoms/foundations/data/UK_Metro_Areas.csv: -------------------------------------------------------------------------------- 1 | id,Name,Rank,Population,Longitude,Latitude,Area,Density,Subs,MetroArea,Changes 2 | 1,Greater London,1,9787426,-18162.92767,6711153.709,1737.9,5630,"London Boroughs, Hemel Hempstead, Watford, Woking, Harlow, St Albans, Bracknell",London,"The addition of Guildford, Harlow, Bracknell and St Albans" 3 | 2,Greater Manchester,2,2553379,-251761.802,7073067.458,630.3,4051,"Manchester, Salford, Bolton, Stockport, Oldham, Rochdale, Bury, Trafford, Tameside",Manchester,"The addition of Golborne, Glossop and Newton-le-Willows" 4 | 3,West Midlands,3,2440986,-210635.2396,6878950.083,598.9,4076,"Birmingham, Wolverhampton, West Bromwich, Dudley, Walsall, Solihull",Birmingham, 5 | 4,West Yorkshire,4,1777934,-185959.3022,7145450.207,487.8,3645,"Leeds, Bradford, Wakefield, Huddersfield, Dewsbury, Keighley, Halifax",Leeds-Bradford,The addition of Halifax 6 | 5,Glasgow,5,1209143,-473845.2389,7538620.144,368.5,3390,"Glasgow, Paisley, Clydebank",Glasgow, 7 | 6,Liverpool,6,864122,-340595.1768,7063197.083,199.6,4329,"Liverpool, Bootle, Litherland, Crosby, Prescot, St. Helens, Ashton-in-Makerfield",Liverpool,The addition of Ashton-in-Makerfield 8 | 7,South Hampshire,7,855569,-174443.8647,6589419.084,192,4455,"Southampton, Portsmouth, Eastleigh, Gosport, Fareham, Havant, Horndean",Southampton-Portsmouth,Portsmouth Urban Area and Southampton Urban Area combined into one. 9 | 8,Tyneside,8,774891,-187604.3647,7356018.207,180.5,4292,"Newcastle upon Tyne, Gateshead, South Shields, Tynemouth, Wallsend, Whitley Bay, Jarrow",Newcastle-Sunderland,"Washington, Chester-Le-Street, Hetton-le-Hole and Houghton-le-Spring are no longer part of the built-up area." 10 | 9,Nottingham,9,729977,-131672.2399,6979298.895,176.4,4139,"Nottingham, Beeston, Carlton, West Bridgford, Ilkeston, Hucknall",Nottingham-Derby, 11 | 10,Sheffield,10,685368,-163545.3257,7055177.403,167.5,4092,"Sheffield, Rotherham, Rawmarsh",Sheffield, 12 | 11,Bristol,11,617280,-283223.6223,6708480.482,144.4,4274,"Bristol, Filton, Pill, Frampton Cotterell, Kingswood, Warmley, Mangotsfield, Winterbourne",Bristol, 13 | 12,Belfast,12,579127,-659942.9337,7289187.543,,,,Belfast, 14 | 13,Leicester,13,508916,-128587.7477,6917403.419,109.4,4653,"Leicester, Syston, Whetstone, Birstall, Narborough, Enderby",Leicester,Ratby no longer part of the built-up area. 15 | 14,Edinburgh,14,482005,-353961.3096,7552397.542,,,,Edinburgh, 16 | 15,Brighton and Hove,15,474485,-18368.56048,6593326.107,89.4,5304,"Brighton and Hove, Worthing, Littlehampton, Shoreham-by-Sea",Brighton,"Rottingdean, Saltdean and Findon are no longer part of the built-up area." 17 | 16,Bournemouth/Poole,16,466266,-243742.1224,6565360.045,131,3559,"Bournemouth, Poole, Christchurch, Ferndown, New Milton, Wimborne Minster",Bournemouth/Poole,Ferndown and Wimborne Minster now part of the built-up area. 18 | 17,Cardiff,17,447287,-357251.4345,6710125.544,102.3,4370,"Cardiff, Caerphilly, Penarth, Pontypridd",Cardiff-Newport,Caerphilly and Pontypridd now part of the built-up area. 19 | 18,Teesside,18,376633,-136813.0602,7284252.355,108.2,3482,"Middlesbrough, Stockton-On-Tees, Billingham, Redcar",Middlesbrough,"Eston & Southbank now part of Middlesbrough sub-division, no longer counted as separate sub-division" 20 | 19,Stoke-on-Trent,19,372775,-246620.9817,6990197.434,103.9,3588,"Stoke-on-Trent, Newcastle-under-Lyme, Kidsgrove",Stoke-on-Trent, 21 | 20,Coventry,20,359262,-169303.0444,6876688.122,81.3,4420,"Coventry, Bedworth",Birmingham, 22 | 21,Sunderland,21,335415,-156142.5445,7336483.09,83.5,4018,"Sunderland, Washington, Chester-Le-Street, Hetton-le-Hole, Houghton-le-Spring",Newcastle-Sunderland,"Addition of Washington, Chester-Le-Street, Hetton-le-Hole and Houghton-le-Spring" 23 | 22,Birkenhead,22,325264,-373290.7939,7038726.778,88.2,3687,"Birkenhead, Wallasey, Ellesmere Port, Bebington",Liverpool, 24 | 23,Reading,23,318014,-113370.9196,6703134.029,83.7,3800,"Reading, Wokingham, Woodley, Crowthorne",London,Bracknell no longer part of the built-up area. 25 | 24,Kingston upon Hull,24,314018,-41707.88464,7124167.211,82.6,3802,"Kingston upon Hull, Cottingham, Hessle",Hull, 26 | 25,Preston,25,313322,-306768.5792,7125401.008,82.4,3802,"Preston, Bamber Bridge, Chorley, Fulwood, Leyland",Preston,The addition of Longton and Adlington to the built-up area. 27 | 26,Newport,26,306844,-283737.7043,6751971.822,84.2,3643,"Newport, Pontypool, Cwmbran, Blackwood, Risca, Ystrad Mynach",Cardiff-Newport,"Pontypool, Cwmbran and Blackwood added to the built-up area." 28 | 27,Swansea,27,300352,-451534.0788,6738811.322,87.6,3431,"Swansea, Neath, Port Talbot, Ystradgynlais, Pontardawe",Swansea/Neath/Port Talbot,Ystradgynlais now part of the built-up area. 29 | 28,Southend-on-Sea,28,295310,78176.04472,6724005.759,71.8,4111,"Southend-on-Sea, Hullbridge, Rayleigh, Rochford",London,Hullbridge now part of the built-up area. 30 | 29,Derby,29,270468,-168172.064,6970353.868,64.1,4219,"Derby, Borrowash, Duffield",Nottingham-Derby, 31 | 30,Plymouth,30,260203,-464283.3132,6512203.963,59.7,4356,"Plymouth, Plymstock",Plymouth, 32 | 31,Luton,31,258018,-53017.6893,6785284.337,50.7,5088,"Luton, Dunstable, Houghton Regis",London, 33 | 32,Farnborough/Aldershot,32,252397,-87152.73608,6664783.509,78.5,3217,"Farnborough, Aldershot, Camberley, Farnham, Frimley, Sandhurst, Yateley",London, 34 | 33,Medway Towns,33,243931,58435.29477,6698507.291,52.2,4677,"Gillingham, Chatham, Rochester",London, 35 | 34,Blackpool,34,239409,-342137.4229,7142674.164,61.3,3908,"Blackpool, Lytham St Annes, Poulton-le-Fylde, Thornton, Cleveleys",Blackpool,Fleetwood no longer forms part of the built-up area. 36 | 35,Milton Keynes,35,229941,-88797.79857,6803791.29,62.5,3678,"'Milton Keynes',[7] Bletchley, Newport Pagnell, Woburn Sands",Milton Keynes,The addition of Woburn Sands. 37 | 36,Northampton,37,215963,-108538.5485,6849853.04,57.9,3731,"Northampton, Collingtree",Northampton, 38 | 37,Barnsley/Dearne Valley,36,223281,-167966.4312,7087358.938,59.7,3739,"Barnsley, Wath upon Dearne, Wombwell, Hoyland",Sheffield, 39 | 38,Norwich,38,213166,142539.1149,6915861.173,61.9,3444,"Norwich, Taverham, Costessey, Cringleford, Hellesdon",Norwich, 40 | 39,Aberdeen,39,207932,-237470.3216,7791034.42,,,,Aberdeen, 41 | 40,Swindon,40,185609,-197166.2905,6721743.798,47.1,3945,"Swindon, Haydon Wick, Stratton St. Margaret, Broad Blunsdon, Blunsdon St Andrew, Wroughton",Swindon, 42 | 41,Crawley,41,180508,-21144.60345,6652651.174,58.1,3107,"Crawley, Horley, East Grinstead, Copthorne, Crawley Down",London,"The addition of East Grinstead, Copthorne and Crawley Down." 43 | 42,Ipswich,42,178835,125265.9587,6817157.423,49.1,3639,"Ipswich, Kesgrave, Woodbridge",Ipswich,The addition of Woodbridge. 44 | 43,Wigan,43,175405,-298337.6339,7086947.672,43.8,4009,"Wigan, Skelmersdale, Standish, Ince-in-Makerfield",Manchester, 45 | 44,Mansfield,44,171958,-136298.9781,7011274.798,48.4,3556,"Mansfield, Sutton-in-Ashfield, Kirkby-in-Ashfield, Mansfield Woodhouse",Nottingham-Derby, 46 | 45,Oxford,45,171380,-140411.6344,6760402.767,37.4,4585,"Oxford, Kennington, Wheatley",Oxford,The addition of Kennington and Wheatley. 47 | 46,Warrington,46,165456,-299160.1652,7058981.61,44.9,3686,Warrington,Liverpool, 48 | 47,Slough,47,163777,-72141.54081,6715986.08,34.1,4797,"Slough, Stoke Poges, Poyle",London, 49 | 48,Peterborough,48,163379,-30192.44717,6905990.798,44.2,3693,"Peterborough, Farcet",Peterborough, 50 | 49,Cambridge,49,158434,10934.11522,6840188.298,42.1,3760,"Cambridge, Fen Ditton, Girton, Histon",Cambridge,Addition of Histon and Impington and Fen Ditton 51 | 50,Doncaster,50,158141,-129718.7281,7086125.141,43.5,3634,"Doncaster, Bentley, Armthorpe, Sprotbrough",Sheffield,Addition of Bessacarr 52 | 51,Dundee,51,157444,-340286.7276,7653671.702,,,,Dundee, 53 | 52,York,52,153717,-123961.0094,7163443.078,34,4518,"York, Earswick",York, 54 | 53,Gloucester,53,150053,-252275.8841,6775208.329,40.4,3718,"Gloucester, Innsworth",Gloucester-Cheltenham, 55 | 54,Burnley,54,149422,-250425.1888,7130181.971,35.7,4183,"Burnley, Padiham, Brierfield Colne, Barrowford Nelson",Blackburn-Burnley, 56 | 55,Basildon,57,144859,43629.73231,6724057.167,37.1,3902,"Basildon, Wickford, Ramsden Heath, North Benfleet",London,The addition of Wickford to the urban area. 57 | 56,Grimsby,58,134160,-11891.12691,7088438.51,35.3,3804,"Grimsby, Cleethorpes, Waltham",Grimsby,New Waltham is no longer part of the Built-up area. 58 | 57,Hastings,59,133422,62856.40023,6599340.867,33.2,4019,"Hastings, Bexhill",Hastings, 59 | 58,High Wycombe,60,133204,-87666.81811,6735058.523,39.2,3398,"High Wycombe, Cookham, Hughenden Valley",London, 60 | 59,Thanet,61,125370,140174.3375,6678303.867,27.9,4495,"Margate, Ramsgate, Broadstairs",Thanet, 61 | 60,Accrington/Rossendale,62,125059,-274381.4113,7122059.475,30,4168,"Accrington, Rawtenstall, Bacup, Great Harwood, Haslingden, Oswaldtwistle",Blackburn-Burnley,Accrington Urban Area and Rossendale Urban Area combined. 62 | 61,Burton-upon-Trent,63,122199,-183491.7085,6946860.319,35,3487,"Burton-upon-Trent, Swadlincote",Burton-upon-Trent,"The addition of Swadlincote, Stapenhill and Winshill[8]" 63 | 62,Colchester,64,121859,99459.04075,6777830.148,32.7,3732,"Colchester, Marks Tey",Colchester, 64 | 63,Eastbourne,65,118219,30777.68157,6580833.914,25.1,4705,"Eastbourne, Polegate",Brighton, 65 | 64,Exeter,66,117763,-391592.1141,6566850.883,28.5,4133,"Exeter, Topsham",Exeter, 66 | 65,Cheltenham,67,116447,-228319.6615,6781531.538,28.9,4034,"Cheltenham,",Gloucester-Cheltenham, 67 | 66,Paignton/Torquay,68,115410,-398172.3641,6525724.32,31.5,3667,"Paignton, Torquay, Marldon",Torbay, 68 | 67,Lincoln,69,114879,-62219.75763,7025463.462,32.7,3518,"Lincoln, North Hykeham",Lincoln, 69 | 68,Chesterfield,70,113057,-159278.4449,7029576.118,34.6,3263,"Chesterfield, Staveley, Wingerworth, Holymoorside",Sheffield,Addition of Wingerworth to the Built-up area. 70 | 69,Chelmsford,71,111511,51289.55456,6754850.681,26.2,4259,"Chelmsford, Little Waltham",London, 71 | 70,Basingstoke,72,107642,-125554.6637,6669307.431,29.4,3662,Basingstoke,London, 72 | 71,Maidstone,73,107627,56224.74204,6670129.963,25.4,4229,Maidstone,London, 73 | 72,Bedford,74,106940,-53171.9139,6826410.9,24.8,4309,"Bedford, Kempston",Bedford, 74 | 73,Worcester,75,-248934.3509,6837103.806,101659,24.7,4121,"Worcester, Norton",Worcester, -------------------------------------------------------------------------------- /atoms/ml/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pysal/geopyter/19542b84a321567b6d2c294a0c710cf1e2613765/atoms/ml/README.md -------------------------------------------------------------------------------- /atoms/network_analysis/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pysal/geopyter/19542b84a321567b6d2c294a0c710cf1e2613765/atoms/network_analysis/README.md -------------------------------------------------------------------------------- /atoms/os/README.md: -------------------------------------------------------------------------------- 1 | # Operating Systems 2 | 3 | This atom is intended to provide basica material about how a computer works, together with an introduction to the Unix shell (and Windows if anyone wants to donate a machine). 4 | 5 | ## Notebooks 6 | 7 | - [What's Going On in There?](whats_going_on.ipynb) 8 | - [Navigating Your Computer with Code](paths.ipynb) 9 | - [The Unix Shell](unix_shell.ipynb) 10 | 11 | -------------------------------------------------------------------------------- /atoms/os/img/Software_Carpentry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pysal/geopyter/19542b84a321567b6d2c294a0c710cf1e2613765/atoms/os/img/Software_Carpentry.png -------------------------------------------------------------------------------- /atoms/os/paths.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "geopyter": { 7 | "Contributors": [ 8 | "Michele Ferretti (https://github.com/miccferr)", 9 | "Jon Reades (https://github.com/jreades)", 10 | "James Millington (https://github.com/jamesdamillington)", 11 | "Jon Reades (https://github.com/jreades)" 12 | ], 13 | "git": { 14 | "active_branch": "master", 15 | "author.name": "Jon Reades", 16 | "authored_date": "2017-06-05 16:12:59", 17 | "committed_date": "2017-06-05 16:12:59", 18 | "committer.name": "Jon Reades", 19 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 20 | } 21 | } 22 | }, 23 | "source": [ 24 | "# Paths\n", 25 | "\n", 26 | "- Contributors: Michele Ferretti (mic.ferretti@gmail.com); Jon Reades (jon@reades.com); James Millington (jamesdamillington@gmail.com)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Working Without Buttons\n", 34 | "\n", 35 | "When you use an app on your mobile phone or on your computer it will often save your files somewhere convenient so that you can find them again, but this isn't magic: a programmer made a choice about how to do this for you, and now that you're learning to program _you_ have to make that choice.\n", 36 | "\n", 37 | "So at _some_ point you will need to learn how to read/write data from elsewhere on the computer or the Internet. At that point, for anyone who learned to use a computer after about 1992, computers can seem very unfriendly indeed! That's because when you are programming you will need to give the computer a lot more information about how to find, read, and write data. " 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Working with Paths\n", 45 | "\n", 46 | "Have you ever thought about how and where files are stored on your computer? Probably not, unless you were very, very bored. Unfortunately, when you start programming you *do* need to learn a bit more about this -- enough, at least, to tell Python where to find the file that you want it to read... though you can do much more than that!\n", 47 | "\n", 48 | "A few starting principles:\n", 49 | "\n", 50 | "1. Directories (a.k.a. folders) and files all have a unique location _somewhere_ on your hard drive.\n", 51 | "\n", 52 | "2. A directory (or folder) can contain other directories and files. \n", 53 | "\n", 54 | "3. A file cannot contain a directory. *[OK, **some** types of files -- such as a Zip archive -- can contain a folder.]*\n", 55 | "\n", 56 | "4. The directory that sits at the 'top' of your hard drive (_i.e._ the _one_ directory that is not _in_ another directory) is known as the **root directory**.\n", 57 | "\n", 58 | "5. A file must be stored in a directory (there are no root files).\n", 59 | "\n", 60 | "6. The directory in which _your_ settings and documents are saved (_i.e._ the stuff associated with your _username_) is known as the **home directory**." 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "### Paths in Python\n", 68 | "\n", 69 | "Below is a 'code block' that will run some Python code. It's not important that you understand *all* of what is happening, but there are two very important things to know:\n", 70 | "\n", 71 | "1. To 'run' a code block, you can either click inside the code block with your mouse and then hit the two-key combination: `Ctrl+Enter` (that's holding down the 'Control' key and then hitting the 'Return' key!)\n", 72 | "\n", 73 | "2. Pay attention to the lines in green that start with a \\#, as that is a 'comment' that tells you what is going on. Comments are good practice for programming as they give us a way to explain code 'inline'.\n", 74 | "\n", 75 | "Let's try this!" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 16, 81 | "metadata": {}, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "I am running in the directory...\n", 88 | "/Users/jreades/Documents/github/geopyter/atoms/os\n", 89 | "\n", 90 | "The home directory is...\n", 91 | "/Users/jreades\n", 92 | "\n", 93 | "The home directory was last modified at...\n", 94 | "Tuesday 25 September 2018 at 05:38 AM BST\n", 95 | "\n" 96 | ] 97 | } 98 | ], 99 | "source": [ 100 | "# Import a useful library written by someone else\n", 101 | "import os\n", 102 | "import time\n", 103 | "\n", 104 | "# The Current Working Directory (cwd)\n", 105 | "print(\"I am running in the directory...\")\n", 106 | "print(os.getcwd())\n", 107 | "print(\"\")\n", 108 | "\n", 109 | "# The Home Directory (~)\n", 110 | "print(\"The home directory is...\")\n", 111 | "print(os.path.expanduser(\"~\"))\n", 112 | "print(\"\")\n", 113 | "\n", 114 | "# Late Modification Time (mtime)\n", 115 | "print(\"The home directory was last modified at...\")\n", 116 | "print(time.strftime('%A %d %B %Y at %I:%S %p %Z',time.localtime(os.path.getmtime(os.path.expanduser(\"~\")))))\n", 117 | "print(\"\")" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "That last example was intended to be hard to puzzle out. Yes, it's difficult to read, but think for a minute about what the code has just done: Python has taken a directory (your home directory) and asked the computer to tell it when this directory was *last modified*; using this, it then generated a human-readable output indicating the day of the week, date, time, AM/PM and timezone of that modification. " 125 | ] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "metadata": {}, 130 | "source": [ 131 | "#### A Small Challenge\n", 132 | "\n", 133 | "Using [the documentation](https://docs.python.org/3/library/time.html#time.strftime) see if you can figure out how to change the full weekday name to the abbreviated weekday name! You will need to learn how to use the documentation eventually, so why not start now?\n", 134 | "\n", 135 | "Here's a clue: you need to change exactly *one* letter in this line of code and will be somehwere in the first block of code marked in *red*:" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 17, 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "name": "stdout", 145 | "output_type": "stream", 146 | "text": [ 147 | "Tuesday 25 September 2018 at 05:38 AM BST\n" 148 | ] 149 | } 150 | ], 151 | "source": [ 152 | "print(time.strftime('%A %d %B %Y at %I:%S %p %Z',time.localtime(os.path.getmtime(os.path.expanduser(\"~\")))))" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "## Why Paths Matter\n", 160 | "\n", 161 | "You need to think of all code as running at a 'location' on your computer: in other words, when you want to read or write data you also need to know where you 'are' (i.e. where your code is running) or you could end up being unable to find your work or, worse, overwriting something **really important** on your computer. \n", 162 | "\n", 163 | "As the end of the day, using paths to move around your computer using code is the same as using the Finder (or Windows Explorer) to move around your computer! In programming parlance, you to move 'down' into sub-folders or 'up' into parent directories to see what's available at that 'level' of the drive. \n", 164 | "\n", 165 | "For people who are used to just saving a document pretty much anywhere on their computer (or iPad or iPhone) and having it accessible via Spotlight/Search functions this can take a _lot_ of getting used to, but remember that in learning to program we're gradually stripping away the bells and whistles that sit between you and what the computer's actually doing. \n", 166 | "\n", 167 | "Here's some code to find photos saved in your home directory:" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 54, 173 | "metadata": {}, 174 | "outputs": [ 175 | { 176 | "name": "stdout", 177 | "output_type": "stream", 178 | "text": [ 179 | "Match: DSC01469.jpg\n", 180 | "Match: city.jpg\n", 181 | "Match: IMG_5899.jpg\n", 182 | "Match: IMG_5907.jpg\n", 183 | "Match: IMG_5898.jpg\n", 184 | "Match: IMG_5904.jpg\n", 185 | "Match: IMG_5910.jpg\n", 186 | "Match: IMG_5901.jpg\n", 187 | "Match: IMG_5903.jpg\n", 188 | "Match: ad2944f6-bdc3-4787-9866-86d1a62bf75e.jpg\n", 189 | "Match: af0d8ec2-ed33-4db2-8ef1-04d101cb0e60.jpg\n", 190 | "Match: Geo-ML Historical Climat and Weather.jpg\n", 191 | "Match: emptyname 88.jpg\n", 192 | "Match: 24af6e1d-2583-4932-b708-dcdf49e0b5c9.jpg\n", 193 | "Match: 27b43af6-ed5d-4129-958e-c0d2acb67291.jpg\n", 194 | "Match: 8D3D0277-7130-4329-AE0E-612F7B341414.jpg\n", 195 | "Match: A32A1301-E5A5-4371-A69D-75B5D4C6F9D9.jpg\n", 196 | "Match: d0fb07b0-6c5f-4418-a6b6-0bc4cf9f3fed.jpg\n", 197 | "Match: 0495b2bd-afd5-46fd-acad-f78e4126c7aa.jpg\n" 198 | ] 199 | } 200 | ], 201 | "source": [ 202 | "# A useful library of code\n", 203 | "import os\n", 204 | "\n", 205 | "# Some variables to count the number of images found\n", 206 | "max_matches = 20\n", 207 | "cur_matches = 0\n", 208 | "\n", 209 | "# The code\n", 210 | "exclude = set(['Cache','Library','Music'])\n", 211 | "for (dirpath, dirnames, filenames) in os.walk(os.path.expanduser('~'), topdown=True):\n", 212 | " dirnames[:] = set(dirnames) - exclude\n", 213 | " dirnames[:] = [d for d in dirnames if not d.startswith('.')]\n", 214 | " \n", 215 | " for f in filenames:\n", 216 | " if f.endswith(\".jpg\"):\n", 217 | " \n", 218 | " cur_matches += 1\n", 219 | " \n", 220 | " if cur_matches < max_matches:\n", 221 | " print(\"Match: \" + f)\n", 222 | " else:\n", 223 | " break" 224 | ] 225 | }, 226 | { 227 | "cell_type": "markdown", 228 | "metadata": {}, 229 | "source": [ 230 | "### Special Paths\n", 231 | "\n", 232 | "Finally, there are a few 'special' paths that you need to know about when using the Terminal or Python:\n", 233 | "\n", 234 | "- `/` is the **root directory** (so `cd /` would take you to the 'root' of the hard drive)\n", 235 | "- `~` is the **home directory** (this is a shortcut: it's the same as typing `cd /Users/myusername/`)\n", 236 | "- `.` means the **current directory** (this is avoid ambiguity: `cd ./myusername/Documents` would assume that in the current directory there is a sub-directory called `Documents` under `myusername`)\n", 237 | "- `..` means the **next directory up** (this is so that you don't have to type out `cd /Users/myusername/Settings` just to go from `Documents` 'over' to `Settings`; instead, you can use `cd ../Settings/`.\n", 238 | "\n", 239 | "In terms of terminology: any path that starts with a `/` is an _**absolute path**_ because we are starting from the _**root**_ directory; any path that starts with either `..` or `.` is a _**relative path**_ because it is starting from the _**current**_ directory and is relative to where the Terminal or program 'is' now.\n", 240 | "\n", 241 | "### Windows vs Everyone Else\n", 242 | "\n", 243 | "For historical reasons, Windows has long been just a bit different from Unix/Linux/Mac in how paths are specified: on Windows it has long been the case that the path separator was `\\`, not `/` (`:` also isn't allowed in file name on a Mac for historical reasons)!\n", 244 | "\n", 245 | "So the following Unix/Mac path: `/Users/myusername/Documents/`\n", 246 | "\n", 247 | "On a Windows machine would usually be: `\\Users\\myusername\\Documents\\`\n", 248 | "\n", 249 | "If you remember that on a Unix/Mac we use `\\` to manage things like spaces in a directory name then you can see how it gets pretty confusing and complicated pretty quickly when you start to program... But in Python we can cope with _both_ of these situations and others using the `os` library (short for 'operating system'); see the examples below!\n", 250 | "\n", 251 | "**Remember**: to turn code you need click in the code block below and then either type `Ctrl+Enter` or hit the 'Run' button on the menu bar above." 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": null, 257 | "metadata": {}, 258 | "outputs": [], 259 | "source": [ 260 | "import os\n", 261 | "# Create a path by joining together the input arguments\n", 262 | "print(os.path.join('Users','myusername','Documents'))\n", 263 | "print(\" \")\n", 264 | "# Create an absolute path (starts with '/') and file names that contain spaces (we don't need to worry about spaces)\n", 265 | "print(os.path.join('/','Users','myusername','Documents','My Work','Code Camp'))\n", 266 | "print(\" \")\n", 267 | "# Create a relative path (starts with '..') and file names that contain spaces (we don't need to worry about spaces)\n", 268 | "print(os.path.join('..','Documents','My Work','Code Camp'))\n", 269 | "print(\" \")\n", 270 | "# 'Expand' the current user's home directory (~) into an absolute path\n", 271 | "print(os.path.expanduser(\"~\"))\n", 272 | "print(\" \")\n", 273 | "# 'Expand' the current directory path (.) into an absolute path\n", 274 | "print(os.path.abspath('.'))\n", 275 | "print(\" \")" 276 | ] 277 | } 278 | ], 279 | "metadata": { 280 | "anaconda-cloud": {}, 281 | "geopyter": { 282 | "Contributors": [ 283 | "Michele Ferretti (https://github.com/miccferr)", 284 | "Jon Reades (https://github.com/jreades)", 285 | "James Millington (https://github.com/jamesdamillington)" 286 | ], 287 | "git": { 288 | "active_branch": "master", 289 | "author.name": "Jon Reades", 290 | "authored_date": "2017-06-05 16:12:59", 291 | "committed_date": "2017-06-05 16:12:59", 292 | "committer.name": "Jon Reades", 293 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 294 | }, 295 | "libs": {} 296 | }, 297 | "kernelspec": { 298 | "display_name": "Python 3", 299 | "language": "python", 300 | "name": "python3" 301 | }, 302 | "language_info": { 303 | "codemirror_mode": { 304 | "name": "ipython", 305 | "version": 3 306 | }, 307 | "file_extension": ".py", 308 | "mimetype": "text/x-python", 309 | "name": "python", 310 | "nbconvert_exporter": "python", 311 | "pygments_lexer": "ipython3", 312 | "version": "3.6.5" 313 | } 314 | }, 315 | "nbformat": 4, 316 | "nbformat_minor": 2 317 | } 318 | -------------------------------------------------------------------------------- /atoms/os/unix_shell.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "geopyter": { 7 | "Contributors": [ 8 | "Michele Ferretti (https://github.com/miccferr)", 9 | "Jon Reades (https://github.com/jreades)", 10 | "James Millington (https://github.com/jamesdamillington)", 11 | "Jon Reades (https://github.com/jreades)" 12 | ], 13 | "git": { 14 | "active_branch": "master", 15 | "author.name": "Jon Reades", 16 | "authored_date": "2017-06-05 16:12:59", 17 | "committed_date": "2017-06-05 16:12:59", 18 | "committer.name": "Jon Reades", 19 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 20 | } 21 | } 22 | }, 23 | "source": [ 24 | "# The Terminal\n", 25 | "\n", 26 | "- Contributors: Jon Reades (jon@reades.com)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Working Without Buttons\n", 34 | "\n", 35 | "Eventually, you will need to understand how to use your computer's Terminal. Without going into the gory details, the Terminal allows you to do a lot of things using only the keyboard: install applications or libraries, download files, list directories, configure scripts, etc., etc. Being able to use the Terminal will also help you to understand what Python is doing as well, so it will also help you to *debug* problems in your code more easily. We *could* write our own introduction to the Terminal, but we think we're better off standing on the shoulders of giants (clicking the image will take you to: http://swcarpentry.github.io/shell-novice/):" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "[![Link to Software Carpentry Web Site](./img/Software_Carpentry.png)](http://swcarpentry.github.io/shell-novice/)" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "## Remembering Shell Commands\n", 50 | "\n", 51 | "It's been said that [one of the virtues of programmers is laziness](https://blog.teamtreehouse.com/the-programmers-virtues), and understanding this laziness is the key to understanding why most programming commands can look like the result of monkeys hitting keys at random. In fact, laziness is critical to being able to write code without constantly having to check Google. \n", 52 | "\n", 53 | "Here are some shell commands and what they do:\n", 54 | "\n", 55 | "| Command | Short For... | What It Does |\n", 56 | "|-------- |------------- |------------- |\n", 57 | "| ls | list | List the contents of the directory I'm about to give you ('`ls ~`' lists the contents of your home directory; '`ls ..`' lists the contents of the parent directory; etc.) |\n", 58 | "| cd | change directory | Move to the path I'm about to give you ('`cd ~`' moves you to your home directory; '`cd ..`' moves you to the parent directory; etc.) | \n", 59 | "| pwd | print working directory | Show the path of the current current directory (_i.e._ where am I now?) |\n", 60 | "| head | Get the head of a file | Print the first few lines of the specified file (_e.g._ `head somefile.csv`) |\n", 61 | "| tail | Get the tail of a file | Print the last few lines of the specified file (_e.g._ `tail -n 2 somefile.csv`) |\n", 62 | "| clear | Clear the Terminal | When the Terminal looks really busy with old output that you don't need any more just type `clear` |\n", 63 | "| exit | Exit the Terminal | To close an open Terminal window |\n", 64 | "| mv | Move a directory or file | Like dragging things in the Finder window (_e.g._ `mv somefile.csv ../another_dir/` to move the file `somefile.csv` _over_ to a directory named `another_dir` that is accessible from the parent directory of this one) |\n", 65 | "| cp | Copy a directory or file | Like dragging things in the Finder window (_e.g._ `cp somefile.csv ../another_dir/` to make a copy of the file `somefile.csv` in a directory named `another_dir` that is accessible from the parent directory of this one) |\n", 66 | "\n", 67 | "You can see how all of these commands are basically abbreviations/mnemonics that make it easy for programmers to be lazy, but productive: less time typing == more time thinking/doing." 68 | ] 69 | } 70 | ], 71 | "metadata": { 72 | "anaconda-cloud": {}, 73 | "geopyter": { 74 | "Contributors": [ 75 | "Michele Ferretti (https://github.com/miccferr)", 76 | "Jon Reades (https://github.com/jreades)", 77 | "James Millington (https://github.com/jamesdamillington)" 78 | ], 79 | "git": { 80 | "active_branch": "master", 81 | "author.name": "Jon Reades", 82 | "authored_date": "2017-06-05 16:12:59", 83 | "committed_date": "2017-06-05 16:12:59", 84 | "committer.name": "Jon Reades", 85 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 86 | }, 87 | "libs": {} 88 | }, 89 | "kernelspec": { 90 | "display_name": "Python 3", 91 | "language": "python", 92 | "name": "python3" 93 | }, 94 | "language_info": { 95 | "codemirror_mode": { 96 | "name": "ipython", 97 | "version": 3 98 | }, 99 | "file_extension": ".py", 100 | "mimetype": "text/x-python", 101 | "name": "python", 102 | "nbconvert_exporter": "python", 103 | "pygments_lexer": "ipython3", 104 | "version": "3.6.5" 105 | } 106 | }, 107 | "nbformat": 4, 108 | "nbformat_minor": 2 109 | } 110 | -------------------------------------------------------------------------------- /atoms/os/whats_going_on.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# What's going on in there?\n", 8 | "\n", 9 | "- Contributors: Michele Ferretti (mic.ferretti@gmail.com); Jon Reades (jon@reades.com); James Millington (jamesdamillington@gmail.com)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": { 15 | "geopyter": { 16 | "Contributors": [ 17 | "Michele Ferretti (https://github.com/miccferr)", 18 | "Jon Reades (https://github.com/jreades)", 19 | "James Millington (https://github.com/jamesdamillington)", 20 | "Jon Reades (https://github.com/jreades)" 21 | ], 22 | "git": { 23 | "active_branch": "master", 24 | "author.name": "Jon Reades", 25 | "authored_date": "2017-06-05 16:12:59", 26 | "committed_date": "2017-06-05 16:12:59", 27 | "committer.name": "Jon Reades", 28 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 29 | } 30 | } 31 | }, 32 | "source": [ 33 | "### What *is* a computer?\n", 34 | "\n", 35 | "In order to understand how to _program_ a computer it helps to _think_ like a computer. At least a little bit. As we learn to program, the world will seem a bit less friendly (maybe a *lot* less friendly) in the short term, but if you keep at it you will gain the ability to work much more quickly and powerfully with the computer through code. At it's most basic, a computer is a programmable device for performing calculations.\n", 36 | "\n", 37 | "_This_ is a kind of computer.\n", 38 | "\n", 39 | "\n", 40 | "\n", 41 | "\n", 42 | "As is _this_.\n", 43 | "\n", 44 | "" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "There are a huge number of videos on YouTube and resources accessible from Google that delve into more detail than we possibly can here about what is happening inside your computer." 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": { 57 | "geopyter": { 58 | "Contributors": [ 59 | "Michele Ferretti (https://github.com/miccferr)", 60 | "Jon Reades (https://github.com/jreades)", 61 | "James Millington (https://github.com/jamesdamillington)", 62 | "Jon Reades (https://github.com/jreades)" 63 | ], 64 | "git": { 65 | "active_branch": "master", 66 | "author.name": "Jon Reades", 67 | "authored_date": "2017-06-05 16:12:59", 68 | "committed_date": "2017-06-05 16:12:59", 69 | "committer.name": "Jon Reades", 70 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 71 | } 72 | } 73 | }, 74 | "source": [ 75 | "### What's Going on Inside Your Computer?\n", 76 | "\n", 77 | "If you've never really got to grips with what is happening inside a computer, then this high-level [FreeCodeCamp](https://www.freecodecamp.org) introduction is a good place to start. In particular, this will be a really useful introduction to the *terminology* used by computer programmers." 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "[![How do computers and the internet work?](http://img.youtube.com/vi/AV_VYsJnHQQ/0.jpg)](http://www.youtube.com/watch?v=AkFi90lZmXA)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "*Note*: code is everywhere. In fact, we've used code to import this YouTube video! One of the strengths of programming over point-and-click is that someone else created the code to embed a YouTube video into this web page and I 'only' need to know how to tell that code to find the video on the YouTube web site. Everything else happens automatically." 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": { 97 | "geopyter": { 98 | "Contributors": [ 99 | "Michele Ferretti (https://github.com/miccferr)", 100 | "Jon Reades (https://github.com/jreades)", 101 | "James Millington (https://github.com/jamesdamillington)", 102 | "Jon Reades (https://github.com/jreades)" 103 | ], 104 | "git": { 105 | "active_branch": "master", 106 | "author.name": "Jon Reades", 107 | "authored_date": "2017-06-05 16:12:59", 108 | "committed_date": "2017-06-05 16:12:59", 109 | "committer.name": "Jon Reades", 110 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 111 | } 112 | } 113 | }, 114 | "source": [ 115 | "This [TedED video](http://www.youtube.com/watch?v=AkFi90lZmXA) goes into a *little* more detail on the basics such as: what actually happens when you click on a button using your mouse? " 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": { 121 | "geopyter": { 122 | "Contributors": [ 123 | "Michele Ferretti (https://github.com/miccferr)", 124 | "Jon Reades (https://github.com/jreades)", 125 | "James Millington (https://github.com/jamesdamillington)", 126 | "Jon Reades (https://github.com/jreades)" 127 | ], 128 | "git": { 129 | "active_branch": "master", 130 | "author.name": "Jon Reades", 131 | "authored_date": "2017-06-05 16:12:59", 132 | "committed_date": "2017-06-05 16:12:59", 133 | "committer.name": "Jon Reades", 134 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 135 | } 136 | } 137 | }, 138 | "source": [ 139 | "[![What's Going On in There?](http://img.youtube.com/vi/AkFi90lZmXA/0.jpg)](http://www.youtube.com/watch?v=AkFi90lZmXA)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": { 145 | "geopyter": { 146 | "Contributors": [ 147 | "Michele Ferretti (https://github.com/miccferr)", 148 | "Jon Reades (https://github.com/jreades)", 149 | "James Millington (https://github.com/jamesdamillington)", 150 | "Jon Reades (https://github.com/jreades)" 151 | ], 152 | "git": { 153 | "active_branch": "master", 154 | "author.name": "Jon Reades", 155 | "authored_date": "2017-06-05 16:12:59", 156 | "committed_date": "2017-06-05 16:12:59", 157 | "committer.name": "Jon Reades", 158 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 159 | } 160 | } 161 | }, 162 | "source": [ 163 | "### How a Computer Adds Numbers\n", 164 | "\n", 165 | "[This next video](http://www.youtube.com/watch?v=VBDoT8o4q00) is a little more technical and we don't really expect you to remember it, but it touches on a lot of really important concepts: binary numbers, Boolean logic, and how these basic building blocks are assembled into much more complex processes like adding numbers or, ultimately, manipulating data.\n", 166 | "\n", 167 | "[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/VBDoT8o4q00/0.jpg)](http://www.youtube.com/watch?v=VBDoT8o4q00)" 168 | ] 169 | }, 170 | { 171 | "cell_type": "markdown", 172 | "metadata": { 173 | "geopyter": { 174 | "Contributors": [ 175 | "Michele Ferretti (https://github.com/miccferr)", 176 | "Jon Reades (https://github.com/jreades)", 177 | "James Millington (https://github.com/jamesdamillington)", 178 | "Jon Reades (https://github.com/jreades)" 179 | ], 180 | "git": { 181 | "active_branch": "master", 182 | "author.name": "Jon Reades", 183 | "authored_date": "2017-06-05 16:12:59", 184 | "committed_date": "2017-06-05 16:12:59", 185 | "committer.name": "Jon Reades", 186 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 187 | } 188 | } 189 | }, 190 | "source": [ 191 | "The really important thing to get from this last video is that computers are chaining together long sets of simple operations which always basically work out to 1 or 0, which is the same as True or False. This is [Boolean logic](http://computer.howstuffworks.com/boolean.htm) and it is integral to computation _and_ to data processing, but you should always keep in mind that a huge set of calculations are going on in your computer in an order specified by a set of _rules_: do 'A', then do 'B', then... When these rules become sufficiently complex (they become like long recipes!) they are called algorithms. And when they get so complicated that they are not easy to write down as a set of logical outputs, it's often easier to express in a more human-readable form... which is why we have [programming languages](http://www.computerhope.com/jargon/p/proglang.htm).\n", 192 | "\n", 193 | "But remember: finding the average of a set of numbers involves an algorithm (which, in a digital comupter, is based on lots of logical operations involving 1s and 0s). And calculating the probability that the lecturer won't show up to the first lecture also involves an algorithm, it's just that it's a much more complicated one unless you take matters into your own hands and arrange for an accident..." 194 | ] 195 | } 196 | ], 197 | "metadata": { 198 | "anaconda-cloud": {}, 199 | "geopyter": { 200 | "Contributors": [ 201 | "Michele Ferretti (https://github.com/miccferr)", 202 | "Jon Reades (https://github.com/jreades)", 203 | "James Millington (https://github.com/jamesdamillington)" 204 | ], 205 | "git": { 206 | "active_branch": "master", 207 | "author.name": "Jon Reades", 208 | "authored_date": "2017-06-05 16:12:59", 209 | "committed_date": "2017-06-05 16:12:59", 210 | "committer.name": "Jon Reades", 211 | "sha": "2fce1fab4c3c28acabee493a24302e5ee1e8a1eb" 212 | }, 213 | "libs": {} 214 | }, 215 | "kernelspec": { 216 | "display_name": "Python 3", 217 | "language": "python", 218 | "name": "python3" 219 | }, 220 | "language_info": { 221 | "codemirror_mode": { 222 | "name": "ipython", 223 | "version": 3 224 | }, 225 | "file_extension": ".py", 226 | "mimetype": "text/x-python", 227 | "name": "python", 228 | "nbconvert_exporter": "python", 229 | "pygments_lexer": "ipython3", 230 | "version": "3.6.5" 231 | } 232 | }, 233 | "nbformat": 4, 234 | "nbformat_minor": 2 235 | } 236 | -------------------------------------------------------------------------------- /atoms/point_patterns/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pysal/geopyter/19542b84a321567b6d2c294a0c710cf1e2613765/atoms/point_patterns/README.md -------------------------------------------------------------------------------- /atoms/statistics/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pysal/geopyter/19542b84a321567b6d2c294a0c710cf1e2613765/atoms/statistics/README.md -------------------------------------------------------------------------------- /atoms/visualization/README.md: -------------------------------------------------------------------------------- 1 | # Visualization 2 | 3 | Atoms in this module cover data visualization, choropleth mapping, and interactive geovisualization. 4 | 5 | | Atom | Author | 6 | |------------------------------------|--------------------------| 7 | | [Choropleth Classification][cc] | [Serge Rey][sr] | 8 | 9 | 10 | [cc]: choropleth_classification.ipynb 11 | [sr]: https://github.com/sjsrey 12 | -------------------------------------------------------------------------------- /atoms/zonal_analysis/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pysal/geopyter/19542b84a321567b6d2c294a0c710cf1e2613765/atoms/zonal_analysis/README.md -------------------------------------------------------------------------------- /builds/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | -README.md 3 | -------------------------------------------------------------------------------- /builds/README.md: -------------------------------------------------------------------------------- 1 | # builds 2 | 3 | Code to build the notebooks 4 | -------------------------------------------------------------------------------- /compile-geodemographics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 11, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "from geopyter import core" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 12, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Instantiating: sessions/geodemographics.ipynb\n", 22 | "Instantiating: data/remote.ipynb\n", 23 | "Unable to determine version for: zipfile\n", 24 | "Currently we check .__version__ and .version\n", 25 | "Unable to determine version for: io\n", 26 | "Currently we check .__version__ and .version\n", 27 | "Unable to determine version for: os\n", 28 | "Currently we check .__version__ and .version\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "nb = core.NoteBook(\"sessions/geodemographics.ipynb\")" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 13, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "name": "stdout", 43 | "output_type": "stream", 44 | "text": [ 45 | "Importing all of Processing Remote Geodata\n", 46 | "Composing content for sessions/geodemographics.ipynb with 78 cells of new content.\n" 47 | ] 48 | } 49 | ], 50 | "source": [ 51 | "nb.compile()" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 14, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "nb.write(fn='builds/geodemographics.ipynb')" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [] 69 | } 70 | ], 71 | "metadata": { 72 | "anaconda-cloud": {}, 73 | "kernelspec": { 74 | "display_name": "Python 3", 75 | "language": "python", 76 | "name": "python3" 77 | }, 78 | "language_info": { 79 | "codemirror_mode": { 80 | "name": "ipython", 81 | "version": 3 82 | }, 83 | "file_extension": ".py", 84 | "mimetype": "text/x-python", 85 | "name": "python", 86 | "nbconvert_exporter": "python", 87 | "pygments_lexer": "ipython3", 88 | "version": "3.7.6" 89 | } 90 | }, 91 | "nbformat": 4, 92 | "nbformat_minor": 2 93 | } 94 | -------------------------------------------------------------------------------- /compile.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "from geopyter import core" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 2, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Instantiating: sessions/Getting_Oriented.ipynb\n", 22 | "Instantiating: https://raw.githubusercontent.com/kingsgeocomp/code-camp/master/notebook-01.ipynb\n", 23 | "Instantiating: foundations/Why_Code.ipynb\n", 24 | "Instantiating: foundations/Learning_a_Language.ipynb\n", 25 | "Instantiating: foundations/Programming_in_Python.ipynb\n", 26 | "Instantiating: foundations/Thinking_Like_a_Computer.ipynb\n" 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "nb = core.NoteBook(\"sessions/Getting_Oriented.ipynb\")" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 3, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "No contributors found for: Notebook-1: Getting Started\n", 44 | "Getting section from https://raw.githubusercontent.com/kingsgeocomp/code-camp/master/notebook-01.ipynb: h2. This is a Jupyter Notebook\n", 45 | "Retrieving selection: h2. This is a Jupyter Notebook.\n", 46 | "Importing all of Why Learn to Code?\n", 47 | "Importing all of Learning a (New) Language\n", 48 | "Importing all of Programming in Python\n", 49 | "Importing all of Thinking Like a Computer\n", 50 | "Composing content for sessions/Getting_Oriented.ipynb with 35 cells of new content.\n", 51 | "No contributors found for: Notebook-1: Getting Started\n" 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "nb.compile()" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 4, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "No contributors found for: Notebook-1: Getting Started\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "nb.write(fn='builds/Session 1 - Getting Oriented.ipynb')" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 5, 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "Instantiating: sessions/visualization.ipynb\n", 86 | "Instantiating: foundations/Why_Code.ipynb\n", 87 | "Instantiating: visualization/choropleth_classification.ipynb\n" 88 | ] 89 | }, 90 | { 91 | "name": "stderr", 92 | "output_type": "stream", 93 | "text": [ 94 | "/opt/conda/lib/python3.7/site-packages/pysal/explore/segregation/network/network.py:16: UserWarning: You need pandana and urbanaccess to work with segregation's network module\n", 95 | "You can install them with `pip install urbanaccess pandana` or `conda install -c udst pandana urbanaccess`\n", 96 | " \"You need pandana and urbanaccess to work with segregation's network module\\n\"\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "nb = core.NoteBook(\"sessions/visualization.ipynb\")" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 6, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "Importing all of Why Learn to Code?\n", 114 | "Importing all of Classification for Choropleth Mapping\n", 115 | "Composing content for sessions/visualization.ipynb with 110 cells of new content.\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "nb.compile()" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 7, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "nb.write(fn='builds/Session 1 -Visualization.ipynb')" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 8, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "from geopyter.core import read_nb\n", 139 | "import geopyter" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "nb = geopyter.core.NoteBook('sessions/visualization.ipynb')" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": null, 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "nb.nb_path" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "dir(nb)" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": null, 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "nb.get_metadata()" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": null, 181 | "metadata": { 182 | "scrolled": true 183 | }, 184 | "outputs": [], 185 | "source": [ 186 | "nb.compose_metadata()" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": null, 192 | "metadata": {}, 193 | "outputs": [], 194 | "source": [ 195 | "nb.compile()" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": null, 201 | "metadata": {}, 202 | "outputs": [], 203 | "source": [ 204 | "nb.compiled.metadata" 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": null, 210 | "metadata": {}, 211 | "outputs": [], 212 | "source": [ 213 | "nb.cells" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": null, 219 | "metadata": {}, 220 | "outputs": [], 221 | "source": [ 222 | "nb.compiled.metadata" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": null, 228 | "metadata": {}, 229 | "outputs": [], 230 | "source": [ 231 | "lib" 232 | ] 233 | } 234 | ], 235 | "metadata": { 236 | "anaconda-cloud": {}, 237 | "kernelspec": { 238 | "display_name": "Python 3", 239 | "language": "python", 240 | "name": "python3" 241 | }, 242 | "language_info": { 243 | "codemirror_mode": { 244 | "name": "ipython", 245 | "version": 3 246 | }, 247 | "file_extension": ".py", 248 | "mimetype": "text/x-python", 249 | "name": "python", 250 | "nbconvert_exporter": "python", 251 | "pygments_lexer": "ipython3", 252 | "version": "3.7.3" 253 | } 254 | }, 255 | "nbformat": 4, 256 | "nbformat_minor": 2 257 | } 258 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: geopyter 2 | channels: 3 | - conda-forge 4 | - defaults 5 | dependencies: 6 | - descartes 7 | - gitpython 8 | - jupyterlab 9 | - pysal 10 | - requests 11 | -------------------------------------------------------------------------------- /extractor.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Extracting from Jupyter Notebooks" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [ 18 | "import nbformat\n", 19 | "import io\n", 20 | "xrange = range" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 2, 26 | "metadata": { 27 | "collapsed": true 28 | }, 29 | "outputs": [], 30 | "source": [ 31 | "import md2py" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | "# Reading Notebooks" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 3, 44 | "metadata": { 45 | "collapsed": true 46 | }, 47 | "outputs": [], 48 | "source": [ 49 | "def read_nb(nb):\n", 50 | " with io.open(nb, 'r', encoding='utf8') as f:\n", 51 | " nb = nbformat.read(f, nbformat.NO_CONVERT)\n", 52 | " return nb\n", 53 | "\n", 54 | "def write_nb(nb, fn):\n", 55 | " if not fn.endswith('.ipynb'):\n", 56 | " fn += '.ipynb'\n", 57 | " with io.open(fn, 'w', encoding='utf8') as f:\n", 58 | " nbformat.write(nb, f, nbformat.NO_CONVERT)\n", 59 | "\n", 60 | "def dump_nb(nb, cells=5, lines=5):\n", 61 | " for c in xrange(0, cells):\n", 62 | " print(\"====== \" + nb.cells[c]['cell_type'] + \" ======\")\n", 63 | " src = nb.cells[c]['source'].splitlines()\n", 64 | " if len(src) > lines:\n", 65 | " print('\\n'.join(src[0:lines]))\n", 66 | " print(\"...\")\n", 67 | " else:\n", 68 | " print(nb.cells[c]['source'])" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 4, 74 | "metadata": { 75 | "collapsed": false 76 | }, 77 | "outputs": [], 78 | "source": [ 79 | "source_nb = 'atoms/foundations/Dictionaries.ipynb'\n", 80 | "\n", 81 | "inb = read_nb(source_nb)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 5, 87 | "metadata": { 88 | "collapsed": false 89 | }, 90 | "outputs": [ 91 | { 92 | "data": { 93 | "text/plain": [ 94 | "nbformat.notebooknode.NotebookNode" 95 | ] 96 | }, 97 | "execution_count": 5, 98 | "metadata": {}, 99 | "output_type": "execute_result" 100 | } 101 | ], 102 | "source": [ 103 | "type(inb)" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 6, 109 | "metadata": { 110 | "collapsed": false 111 | }, 112 | "outputs": [ 113 | { 114 | "data": { 115 | "text/plain": [ 116 | "dict_keys(['nbformat', 'cells', 'nbformat_minor', 'metadata'])" 117 | ] 118 | }, 119 | "execution_count": 6, 120 | "metadata": {}, 121 | "output_type": "execute_result" 122 | } 123 | ], 124 | "source": [ 125 | "inb.keys()" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 7, 131 | "metadata": { 132 | "collapsed": false 133 | }, 134 | "outputs": [ 135 | { 136 | "data": { 137 | "text/plain": [ 138 | "{'anaconda-cloud': {},\n", 139 | " 'kernelspec': {'display_name': 'Python [conda root]',\n", 140 | " 'language': 'python',\n", 141 | " 'name': 'conda-root-py'},\n", 142 | " 'language_info': {'codemirror_mode': {'name': 'ipython', 'version': 3},\n", 143 | " 'file_extension': '.py',\n", 144 | " 'mimetype': 'text/x-python',\n", 145 | " 'name': 'python',\n", 146 | " 'nbconvert_exporter': 'python',\n", 147 | " 'pygments_lexer': 'ipython3',\n", 148 | " 'version': '3.5.2'}}" 149 | ] 150 | }, 151 | "execution_count": 7, 152 | "metadata": {}, 153 | "output_type": "execute_result" 154 | } 155 | ], 156 | "source": [ 157 | "inb.metadata" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 8, 163 | "metadata": { 164 | "collapsed": true 165 | }, 166 | "outputs": [], 167 | "source": [ 168 | "cells = inb['cells']" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 9, 174 | "metadata": { 175 | "collapsed": false 176 | }, 177 | "outputs": [ 178 | { 179 | "data": { 180 | "text/plain": [ 181 | "list" 182 | ] 183 | }, 184 | "execution_count": 9, 185 | "metadata": {}, 186 | "output_type": "execute_result" 187 | } 188 | ], 189 | "source": [ 190 | "type(cells)" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 10, 196 | "metadata": { 197 | "collapsed": false 198 | }, 199 | "outputs": [ 200 | { 201 | "data": { 202 | "text/plain": [ 203 | "41" 204 | ] 205 | }, 206 | "execution_count": 10, 207 | "metadata": {}, 208 | "output_type": "execute_result" 209 | } 210 | ], 211 | "source": [ 212 | "len(cells)" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 11, 218 | "metadata": { 219 | "collapsed": false 220 | }, 221 | "outputs": [ 222 | { 223 | "data": { 224 | "text/plain": [ 225 | "list" 226 | ] 227 | }, 228 | "execution_count": 11, 229 | "metadata": {}, 230 | "output_type": "execute_result" 231 | } 232 | ], 233 | "source": [ 234 | "type(cells)" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 12, 240 | "metadata": { 241 | "collapsed": false 242 | }, 243 | "outputs": [ 244 | { 245 | "name": "stdout", 246 | "output_type": "stream", 247 | "text": [ 248 | "====== markdown ======\n", 249 | "# Notebook-6: Dictionaries\n", 250 | "====== markdown ======\n", 251 | "### Lesson Content \n", 252 | "\n", 253 | "Welcome back to the fifth Code Camp notebook! In this lesson we'll contiune our exploration of more advanced data structures. Last time we took a peek at a way to represent ordered collections of items via **lists**.\n", 254 | "\n", 255 | "This time we'll use **dictionaries** to create collections of unordered items (this is just an easy distinction - there's much more to it - but it's a good way to start wrapping your head around the subject).\n", 256 | "...\n", 257 | "====== markdown ======\n", 258 | "# Dictionaries\n", 259 | "----\n", 260 | "\n", 261 | "Dictionaries are another kind of data structure that is frequently used in Python. Like lists, the dictionary is also found in other programming languages, often under a different name. For instance, Python dictionaries might be referred to elsewhere as \"maps\", \"hashes\", or \"associative arrays\").\n", 262 | "\n", 263 | "...\n", 264 | "====== code ======\n", 265 | "myDict = {\n", 266 | " \"key1\": \"Value 1\",\n", 267 | " \"key2\": \"2nd Value\",\n", 268 | " 3: \"3rd Value\",\n", 269 | " \"Fourth Key\": [4.0, 'Jon']\n", 270 | "...\n", 271 | "====== markdown ======\n", 272 | "Did you notice that when we printed out `myDict` it didn't print out the elements of dictionary in the same order as we put items into it? That's what we mean when we say that dictionaries are _un_-ordered. Always remember that you have no idea how things are stored in a dictionary can't rely on indexing like you can with a list. Explaining _why_ this works this way is something you'd encounter in a first year Computer Science course.\n", 273 | "\n", 274 | "And notice too that every type of data can go into a dictionary: strings, integers, and floats. There's even a _list_ in there (`[4.0, 'Jon']`)! The _only_ constraint is that the **key must be *immutable***; this means that it is a simple, static identifier and that can't change the value of a key later such as you might using a list, dictionary, or changing variable.\n" 275 | ] 276 | } 277 | ], 278 | "source": [ 279 | "dump_nb(inb)" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 38, 285 | "metadata": { 286 | "collapsed": false 287 | }, 288 | "outputs": [], 289 | "source": [ 290 | "import re\n", 291 | "rh1 = re.compile('(? 0:\n", 444 | " candidates = [parent for parent in h_cells[parent_level]]\n", 445 | " parents.extend([c for c in candidates if c < child])\n", 446 | " parent_level -= 1\n", 447 | " \n", 448 | " parent = max(parents)\n", 449 | " print(child, parent)\n" 450 | ] 451 | }, 452 | { 453 | "cell_type": "code", 454 | "execution_count": null, 455 | "metadata": { 456 | "collapsed": true 457 | }, 458 | "outputs": [], 459 | "source": [] 460 | }, 461 | { 462 | "cell_type": "code", 463 | "execution_count": null, 464 | "metadata": { 465 | "collapsed": true 466 | }, 467 | "outputs": [], 468 | "source": [] 469 | } 470 | ], 471 | "metadata": { 472 | "anaconda-cloud": {}, 473 | "kernelspec": { 474 | "display_name": "Python [conda root]", 475 | "language": "python", 476 | "name": "conda-root-py" 477 | }, 478 | "language_info": { 479 | "codemirror_mode": { 480 | "name": "ipython", 481 | "version": 3 482 | }, 483 | "file_extension": ".py", 484 | "mimetype": "text/x-python", 485 | "name": "python", 486 | "nbconvert_exporter": "python", 487 | "pygments_lexer": "ipython3", 488 | "version": "3.5.2" 489 | } 490 | }, 491 | "nbformat": 4, 492 | "nbformat_minor": 0 493 | } 494 | -------------------------------------------------------------------------------- /geopyter.yml: -------------------------------------------------------------------------------- 1 | # Run `conda-env create -f geopyter.yml` 2 | name: geopyter 3 | channels: 4 | - defaults 5 | - conda-forge 6 | dependencies: 7 | - python=3 8 | - pip 9 | - contextily 10 | - geopandas 11 | - ipython 12 | - ipywidgets 13 | - jupyter 14 | - jupyterlab 15 | - mplleaflet 16 | - networkx 17 | - nodejs 18 | - osmnx 19 | - palettable 20 | - pillow 21 | - pip: 22 | - gitpython 23 | - geopy 24 | - markdown 25 | - nbdime 26 | - nbformat 27 | - polyline 28 | - pysal>=2.0rc2 29 | - rasterio 30 | - requests 31 | - scikit-learn 32 | - seaborn 33 | - statsmodels 34 | - xlrd 35 | - xlsxwriter 36 | -------------------------------------------------------------------------------- /geopyter/__init__.py: -------------------------------------------------------------------------------- 1 | __version__='0.1.0' 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | scipy>=0.11 2 | numpy>=1.3 3 | pandas 4 | libpysal 5 | -------------------------------------------------------------------------------- /sessions/.ipynb_checkpoints/Session-Test-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# My First Session\n", 8 | "\n", 9 | "- Contributors: Contributor 1; Contributor 2" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## Double-Import (Dictionaries -> Conditions)\n", 17 | "\n", 18 | "select = h1.Notebook-6: Dictionaries" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "@include {\n", 26 | " src = foundations/Dictionaries-Test.ipynb\n", 27 | " select = h1.Notebook-6: Dictionaries\n", 28 | "}" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Booleans Import (Directy)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "@include { \n", 43 | " src = foundations/Conditions.ipynb \n", 44 | " select = h3.Testing for Equality\n", 45 | "}" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "## Single-Import (Functions 101 Import)\n", 53 | "\n", 54 | "First we are going to deal with functions because they're important: select = h2.Functions 101" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "@include {\n", 62 | " src = foundations/Functions.ipynb\n", 63 | " select = h2.Functions 101\n", 64 | "}" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 1, 70 | "metadata": { 71 | "collapsed": false 72 | }, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "Let's run some code!\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "print(\"Let's run some code!\")" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "Some other markdown." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 2, 96 | "metadata": { 97 | "collapsed": false 98 | }, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "Some more code.\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "print(\"Some more code.\")" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "@include {\n", 117 | " src = foundations/Functions.ipynb\n", 118 | " select = h3.Assigning to a Variable -h4.A challenge for you!\n", 119 | "}" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "## Single-Import (Choropleth without Maximum Breaks)\n", 127 | "\n", 128 | "And try something from the Choropleth notebook: select = h3.Numerical summaries; h3.Univariate Distribution Visualization; h2.PySAL Classifiers -h3.Maximum Breaks" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "@include {\n", 136 | " src = visualization/choropleth_classification.ipynb\n", 137 | " select = h3.Numerical summaries; h3.Univariate Distribution Visualization; h2.PySAL Classifiers -h3.Maximum Breaks\n", 138 | "}" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 3, 144 | "metadata": { 145 | "collapsed": false 146 | }, 147 | "outputs": [ 148 | { 149 | "data": { 150 | "text/plain": [ 151 | "8" 152 | ] 153 | }, 154 | "execution_count": 3, 155 | "metadata": {}, 156 | "output_type": "execute_result" 157 | } 158 | ], 159 | "source": [ 160 | "3+5" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 4, 166 | "metadata": { 167 | "collapsed": false 168 | }, 169 | "outputs": [ 170 | { 171 | "name": "stdout", 172 | "output_type": "stream", 173 | "text": [ 174 | "1.13.0\n" 175 | ] 176 | } 177 | ], 178 | "source": [ 179 | "import pysal\n", 180 | "print pysal.version" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "Done! Let's see how we did." 188 | ] 189 | } 190 | ], 191 | "metadata": { 192 | "anaconda-cloud": {}, 193 | "kernelspec": { 194 | "display_name": "Python [Root]", 195 | "language": "python", 196 | "name": "Python [Root]" 197 | }, 198 | "language_info": { 199 | "codemirror_mode": { 200 | "name": "ipython", 201 | "version": 2 202 | }, 203 | "file_extension": ".py", 204 | "mimetype": "text/x-python", 205 | "name": "python", 206 | "nbconvert_exporter": "python", 207 | "pygments_lexer": "ipython2", 208 | "version": "2.7.12" 209 | } 210 | }, 211 | "nbformat": 4, 212 | "nbformat_minor": 0 213 | } 214 | -------------------------------------------------------------------------------- /sessions/Example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# My First Session\n", 8 | "\n", 9 | "- Contributors: Contributor 1 (contributor@example.ac.uk); Contributor 2 (contributor@example.edu)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## Import (Dictionaries)\n", 17 | "\n", 18 | "```\n", 19 | "select 'h1.Notebook-6: Dictionaries' from Dictionaries.ipynb\n", 20 | "```\n", 21 | "----" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "@include {\n", 29 | " src = foundations/Dictionaries.ipynb\n", 30 | " select = h1.Notebook-6: Dictionaries\n", 31 | "}" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | "----\n", 39 | "\n", 40 | "## Import (Functions 101)\n", 41 | "\n", 42 | "First we are going to deal with functions because they're important: select = h2.Functions 101\n", 43 | "\n", 44 | "----" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "@include {\n", 52 | " src = foundations/Functions.ipynb\n", 53 | " select = h2.Functions 101\n", 54 | "}" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "----\n", 62 | "\n", 63 | "#### Some other markdown." 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 2, 69 | "metadata": { 70 | "collapsed": false 71 | }, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "Some more code.\n" 78 | ] 79 | } 80 | ], 81 | "source": [ 82 | "print(\"Some more code.\")" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "```\n", 90 | "select 'h3.Assigning to a Variable' without 'h4.A challenge for you!' or 'h4.Another challenge for you!' from Functions.ipynb\n", 91 | "```\n", 92 | "----" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "@include {\n", 100 | " src = foundations/Functions.ipynb\n", 101 | " select = h3.Assigning to a Variable -h4.A challenge for you! -h4.Another challenge for you!\n", 102 | "}" 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "metadata": {}, 108 | "source": [ 109 | "----\n", 110 | "\n", 111 | "## Import (Choropleth without Maximum Breaks)\n", 112 | "\n", 113 | "And try something from the Choropleth notebook in a different directory: \n", 114 | "```\n", 115 | "select = 'h3.Numerical summaries'; 'h3.Univariate Distribution Visualization'; 'h2.PySAL Classifiers -h3.Maximum Breaks' from choropoleth_classification.ipynb\n", 116 | "```\n", 117 | "----" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "@include {\n", 125 | " src = visualization/choropleth_classification.ipynb\n", 126 | " select = h3.Numerical summaries; h3.Univariate Distribution Visualization; h2.PySAL Classifiers -h3.Maximum Breaks\n", 127 | "}" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "----\n", 135 | "And some more executable code..." 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 3, 141 | "metadata": { 142 | "collapsed": false 143 | }, 144 | "outputs": [ 145 | { 146 | "data": { 147 | "text/plain": [ 148 | "8" 149 | ] 150 | }, 151 | "execution_count": 3, 152 | "metadata": {}, 153 | "output_type": "execute_result" 154 | } 155 | ], 156 | "source": [ 157 | "3+5" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 4, 163 | "metadata": { 164 | "collapsed": false 165 | }, 166 | "outputs": [ 167 | { 168 | "name": "stdout", 169 | "output_type": "stream", 170 | "text": [ 171 | "1.13.0\n" 172 | ] 173 | } 174 | ], 175 | "source": [ 176 | "import pysal\n", 177 | "print pysal.version" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "Done! Let's see how we did." 185 | ] 186 | } 187 | ], 188 | "metadata": { 189 | "anaconda-cloud": {}, 190 | "kernelspec": { 191 | "display_name": "Python [Root]", 192 | "language": "python", 193 | "name": "Python [Root]" 194 | }, 195 | "language_info": { 196 | "codemirror_mode": { 197 | "name": "ipython", 198 | "version": 2 199 | }, 200 | "file_extension": ".py", 201 | "mimetype": "text/x-python", 202 | "name": "python", 203 | "nbconvert_exporter": "python", 204 | "pygments_lexer": "ipython2", 205 | "version": "2.7.12" 206 | } 207 | }, 208 | "nbformat": 4, 209 | "nbformat_minor": 0 210 | } 211 | -------------------------------------------------------------------------------- /sessions/Getting_Oriented.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Session 1: Getting Started\n", 8 | "- Contributors: Jon Reades (https://github.com/jreades)" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "@include {\n", 16 | " src = https://raw.githubusercontent.com/kingsgeocomp/code-camp/master/notebook-01.ipynb\n", 17 | " select = h2. This is a Jupyter Notebook\n", 18 | "}" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "@include {\n", 26 | " src = foundations/Why_Code.ipynb\n", 27 | "}" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "@include {\n", 35 | " src = foundations/Learning_a_Language.ipynb\n", 36 | "}" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "@include {\n", 44 | " src = foundations/Programming_in_Python.ipynb\n", 45 | "}" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "@include {\n", 53 | " src = foundations/Thinking_Like_a_Computer.ipynb\n", 54 | "}" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "## Further Reading:\n", 62 | "\n", 63 | "- A **must** read: [The Hard Way is Easier](http://learnpythonthehardway.org/book/intro.html)\n", 64 | "- Two easy and accessible videos to start wrapping your head around programming (although they are not Python-centric) [1](https://www.youtube.com/watch?v=qUVWM2Q4vAU) and [2](https://www.youtube.com/watch?v=AImF__7FyzM)" 65 | ] 66 | } 67 | ], 68 | "metadata": { 69 | "anaconda-cloud": {}, 70 | "kernelspec": { 71 | "display_name": "Python 3", 72 | "language": "python", 73 | "name": "python3" 74 | }, 75 | "language_info": { 76 | "codemirror_mode": { 77 | "name": "ipython", 78 | "version": 3 79 | }, 80 | "file_extension": ".py", 81 | "mimetype": "text/x-python", 82 | "name": "python", 83 | "nbconvert_exporter": "python", 84 | "pygments_lexer": "ipython3", 85 | "version": "3.6.5" 86 | } 87 | }, 88 | "nbformat": 4, 89 | "nbformat_minor": 2 90 | } 91 | -------------------------------------------------------------------------------- /sessions/README.md: -------------------------------------------------------------------------------- 1 | # Sessions Directory 2 | 3 | A session is what you would deliver in one continuous block of teaching time (either in-person or online). So, typically, it would be the same as a practical lab session or an evening's homework. 4 | 5 | This is where you would set up your own notebooks where you've remixed content from the atoms and added your own 'gloss' on the material to prepare it for teaching. We've also provided example sessions that can also be assembled as part of a full course spanning a week (intensive), a term or a semester. 6 | -------------------------------------------------------------------------------- /sessions/visualization.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Session 1: Getting Started with Visualization\n", 8 | "- Contributors: Serge Rey (https://github.com/sjsrey)" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "@include {\n", 16 | " src = foundations/Why_Code.ipynb\n", 17 | "}" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "@include{ \n", 25 | " src = visualization/choropleth_classification.ipynb\n", 26 | "}" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Further Reading:\n", 34 | "\n", 35 | "- A **must** read: [The Hard Way is Easier](http://learnpythonthehardway.org/book/intro.html)\n", 36 | "- Two easy and accessible videos to start wrapping your head around programming (although they are not Python-centric) [1](https://www.youtube.com/watch?v=qUVWM2Q4vAU) and [2](https://www.youtube.com/watch?v=AImF__7FyzM)" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [] 45 | } 46 | ], 47 | "metadata": { 48 | "anaconda-cloud": {}, 49 | "kernelspec": { 50 | "display_name": "Python 3", 51 | "language": "python", 52 | "name": "python3" 53 | }, 54 | "language_info": { 55 | "codemirror_mode": { 56 | "name": "ipython", 57 | "version": 3 58 | }, 59 | "file_extension": ".py", 60 | "mimetype": "text/x-python", 61 | "name": "python", 62 | "nbconvert_exporter": "python", 63 | "pygments_lexer": "ipython3", 64 | "version": "3.7.3" 65 | } 66 | }, 67 | "nbformat": 4, 68 | "nbformat_minor": 2 69 | } 70 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | from setuptools import setup, find_packages 4 | 5 | from distutils.command.build_py import build_py 6 | 7 | import os 8 | 9 | from os import path 10 | this_directory = path.abspath(path.dirname(__file__)) 11 | with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f: 12 | long_description = f.read() 13 | 14 | # Get __version__ from geopyter/__init__.py without importing the package 15 | # __version__ has to be defined in the first line 16 | with open('geopyter/__init__.py', 'r') as f: 17 | exec(f.readline()) 18 | 19 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly 20 | # update it when the contents of directories change. 21 | if os.path.exists('MANIFEST'): 22 | os.remove('MANIFEST') 23 | 24 | def _get_requirements_from_files(groups_files): 25 | groups_reqlist = {} 26 | 27 | for k,v in groups_files.items(): 28 | with open(v, 'r') as f: 29 | pkg_list = f.read().splitlines() 30 | groups_reqlist[k] = pkg_list 31 | 32 | return groups_reqlist 33 | 34 | def setup_package(): 35 | # get all file endings and copy whole file names without a file suffix 36 | # assumes nested directories are only down one level 37 | _groups_files = { 38 | 'base': 'requirements.txt', 39 | 'plus_conda': 'requirements_plus_conda.txt', 40 | 'plus_pip': 'requirements_plus_pip.txt', 41 | 'dev': 'requirements_dev.txt', 42 | 'docs': 'requirements_docs.txt' 43 | } 44 | 45 | reqs = _get_requirements_from_files(_groups_files) 46 | install_reqs = reqs.pop('base') 47 | extras_reqs = reqs 48 | 49 | setup( 50 | name='geopyter', 51 | version=__version__, 52 | description="Geographical Python Teaching Resource", 53 | long_description=long_description, 54 | maintainer="PySAL Developers", 55 | maintainer_email='pysal-dev@googlegroups.com', 56 | url='http://pysal.org/geopyter', 57 | download_url='https://pypi.python.org/pypi/geopyter', 58 | license='BSD', 59 | py_modules=['geopyter'], 60 | packages=find_packages(), 61 | test_suite='nose.collector', 62 | tests_require=['nose'], 63 | keywords='spatial statistics', 64 | classifiers=[ 65 | 'Development Status :: 4 - Beta', 66 | 'Intended Audience :: Science/Research', 67 | 'Intended Audience :: Developers', 68 | 'Intended Audience :: Education', 69 | 'Topic :: Scientific/Engineering', 70 | 'Topic :: Scientific/Engineering :: GIS', 71 | 'License :: OSI Approved :: BSD License', 72 | 'Programming Language :: Python', 73 | 'Programming Language :: Python :: 3.6', 74 | 'Programming Language :: Python :: 3.7' 75 | ], 76 | install_requires=install_reqs, 77 | extras_require=extras_reqs, 78 | cmdclass={'build_py': build_py}, 79 | python_requires='>3.5' 80 | ) 81 | 82 | 83 | if __name__ == '__main__': 84 | setup_package() 85 | --------------------------------------------------------------------------------