2016-01-20 10:45:15 +00:00
|
|
|
{
|
|
|
|
"metadata": {
|
|
|
|
"name": ""
|
|
|
|
},
|
|
|
|
"nbformat": 3,
|
|
|
|
"nbformat_minor": 0,
|
|
|
|
"worksheets": [
|
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"# Import other notebooks\n",
|
|
|
|
"import io\n",
|
|
|
|
"from IPython.nbformat import current\n",
|
|
|
|
"\n",
|
|
|
|
"def execute_notebook(nbfile):\n",
|
|
|
|
" with io.open(nbfile) as f:\n",
|
|
|
|
" nb = current.read(f, 'json')\n",
|
|
|
|
" \n",
|
|
|
|
" ip = get_ipython()\n",
|
|
|
|
" for cell in nb.worksheets[0].cells:\n",
|
|
|
|
" if cell.cell_type != 'code':\n",
|
|
|
|
" continue\n",
|
|
|
|
" ip.run_cell(cell.input)\n",
|
|
|
|
"\n",
|
|
|
|
"execute_notebook(\"country_excludes.ipynb\")\n",
|
|
|
|
"execute_notebook(\"geofence_lib.ipynb\")\n",
|
|
|
|
"execute_notebook(\"header_files.ipynb\")\n",
|
|
|
|
"\n",
|
|
|
|
"import matplotlib"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 11
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"import json\n",
|
|
|
|
"json_data = open(\"countries_world.json\").read()\n",
|
|
|
|
"countries = json.loads(json_data)"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 12
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2016-02-03 19:15:05 +00:00
|
|
|
"def prepare_simple_grids(grids, tolerance=10*1000): # Approx 10km tolerance\n",
|
2016-01-20 10:45:15 +00:00
|
|
|
" simple = [simplify_points(points, tolerance) for points in grids]\n",
|
|
|
|
" return [s for s in simple if len(s) > 2]"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 13
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"c_prefix = []\n",
|
|
|
|
"\n",
|
|
|
|
"for c in countries:\n",
|
|
|
|
" if (c['prefix']):\n",
|
|
|
|
" c_prefix.append(c)"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
2016-02-02 20:22:57 +00:00
|
|
|
"outputs": [],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 14
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"print len(c_prefix)"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"output_type": "stream",
|
|
|
|
"stream": "stdout",
|
|
|
|
"text": [
|
2016-02-05 22:22:48 +00:00
|
|
|
"224\n"
|
2016-01-20 10:45:15 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 15
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"for c in c_prefix:\n",
|
2016-02-03 19:15:05 +00:00
|
|
|
" c['prefix_grids'] = prepare_simple_grids(c['simple_grids'], tolerance=10*1000) # 10km tolerance\n",
|
2016-01-20 10:45:15 +00:00
|
|
|
" c['prefix_outlines'] = fix_antiprime_outlines(ea_grid_to_lonlat(c['prefix_grids']))"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"output_type": "stream",
|
|
|
|
"stream": "stdout",
|
|
|
|
"text": [
|
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n",
|
2016-02-05 22:22:48 +00:00
|
|
|
"Swap!"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"output_type": "stream",
|
|
|
|
"stream": "stdout",
|
|
|
|
"text": [
|
|
|
|
"\n",
|
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n",
|
2016-01-20 10:45:15 +00:00
|
|
|
"Swap!\n",
|
|
|
|
"Swap!\n"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 16
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"# Filter out zero-length outlines\n",
|
|
|
|
"for c in c_prefix:\n",
|
|
|
|
" \n",
|
|
|
|
" filtered_outlines = []\n",
|
|
|
|
" for outline in c['prefix_outlines']:\n",
|
|
|
|
" if (len(outline) > 0):\n",
|
|
|
|
" filtered_outlines.append(outline)\n",
|
|
|
|
" \n",
|
|
|
|
" c['prefix_outlines'] = filtered_outlines"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 17
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"n_outlines = 0\n",
|
|
|
|
"n_points = 0\n",
|
|
|
|
"\n",
|
|
|
|
"for c in c_prefix:\n",
|
|
|
|
" n_outlines = n_outlines + len(c['prefix_outlines'])\n",
|
|
|
|
" \n",
|
|
|
|
" for outline in c['prefix_outlines']:\n",
|
|
|
|
" n_points = n_points + len(outline)\n",
|
|
|
|
" \n",
|
|
|
|
"print \"Total number of points {}\".format(n_points)\n",
|
|
|
|
"print \"Across {} outlines\".format(n_outlines)"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"output_type": "stream",
|
|
|
|
"stream": "stdout",
|
|
|
|
"text": [
|
2016-02-05 22:22:48 +00:00
|
|
|
"Total number of points 12299\n",
|
|
|
|
"Across 486 outlines\n"
|
2016-01-20 10:45:15 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 18
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"# Draw map\n",
|
|
|
|
"m = Basemap(projection='mill')\n",
|
|
|
|
" \n",
|
|
|
|
"m.fillcontinents(color='0.96')\n",
|
|
|
|
"m.drawcoastlines()\n",
|
|
|
|
"\n",
|
|
|
|
"for c in c_prefix:\n",
|
|
|
|
" draw_outlines(m, c['prefix_outlines'], c['colour'])"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"metadata": {},
|
|
|
|
"output_type": "display_data",
|
|
|
|
"text": [
|
2016-02-05 22:22:48 +00:00
|
|
|
"<matplotlib.figure.Figure at 0x7f95f4074690>"
|
2016-01-20 10:45:15 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 19
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2016-02-02 20:22:57 +00:00
|
|
|
"write_prefixes(c_prefix)"
|
2016-01-20 10:45:15 +00:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 20
|
2016-01-20 10:45:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
2016-02-02 20:22:57 +00:00
|
|
|
"outputs": [],
|
2016-02-03 19:15:05 +00:00
|
|
|
"prompt_number": 20
|
2016-01-20 10:45:15 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|