Skip to content

Commit

Permalink
⬆️ Update to Python 3.11 kernel, remove engarde
Browse files Browse the repository at this point in the history
  • Loading branch information
veit committed Aug 19, 2023
1 parent b070eae commit 4b5ba15
Show file tree
Hide file tree
Showing 125 changed files with 310,502 additions and 155,109 deletions.
57 changes: 29 additions & 28 deletions docs/clean-prep/bulwark.ipynb

Large diffs are not rendered by default.

99 changes: 53 additions & 46 deletions docs/clean-prep/dask-pipeline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import logging\n",
"import sys\n",
"import numpy as np\n",
"from time import sleep\n",
"\n",
"from datetime import datetime\n",
"from math import radians\n",
"from dask import delayed\n",
"from operator import itemgetter\n",
"from sklearn.neighbors import DistanceMetric"
"from time import sleep\n",
"\n",
"import numpy as np\n",
"import requests\n",
"\n",
"from dask import delayed\n",
"from sklearn.metrics import DistanceMetric"
]
},
{
Expand Down Expand Up @@ -71,7 +74,7 @@
"\n",
"<div class=\"alert alert-block alert-info\">\n",
"\n",
"**See also:**\n",
"**See also**\n",
"\n",
"* [Location APIs](https://locationiq.com/)\n",
"</div>"
Expand All @@ -85,20 +88,18 @@
"source": [
"def get_lat_long(address):\n",
" resp = requests.get(\n",
" 'https://eu1.locationiq.org/v1/search.php',\n",
" params={'key': '92e7ba84cf3465',\n",
" 'q': address,\n",
" 'format': 'json'}\n",
" \"https://eu1.locationiq.org/v1/search.php\",\n",
" params={\"key\": \"92e7ba84cf3465\", \"q\": address, \"format\": \"json\"},\n",
" )\n",
" if resp.status_code != 200:\n",
" print('There was a problem with your request!')\n",
" print(\"There was a problem with your request!\")\n",
" print(resp.content)\n",
" return\n",
" data = resp.json()[0]\n",
" return {\n",
" 'name': data.get('display_name'),\n",
" 'lat': float(data.get('lat')),\n",
" 'long': float(data.get('lon')),\n",
" \"name\": data.get(\"display_name\"),\n",
" \"lat\": float(data.get(\"lat\")),\n",
" \"long\": float(data.get(\"lon\")),\n",
" }"
]
},
Expand All @@ -119,7 +120,7 @@
}
],
"source": [
"get_lat_long('Berlin, Germany')"
"get_lat_long(\"Berlin, Germany\")"
]
},
{
Expand All @@ -129,16 +130,18 @@
"outputs": [],
"source": [
"locations = []\n",
"for city in ['Seattle, Washington',\n",
" 'Miami, Florida', \n",
" 'Berlin, Germany',\n",
" 'Singapore', \n",
" 'Wellington, New Zealand',\n",
" 'Beirut, Lebanon',\n",
" 'Beijing, China',\n",
" 'Nairobi, Kenya',\n",
" 'Cape Town, South Africa',\n",
" 'Buenos Aires, Argentina']:\n",
"for city in [\n",
" \"Seattle, Washington\",\n",
" \"Miami, Florida\",\n",
" \"Berlin, Germany\",\n",
" \"Singapore\",\n",
" \"Wellington, New Zealand\",\n",
" \"Beirut, Lebanon\",\n",
" \"Beijing, China\",\n",
" \"Nairobi, Kenya\",\n",
" \"Cape Town, South Africa\",\n",
" \"Buenos Aires, Argentina\",\n",
"]:\n",
" locations.append(get_lat_long(city))\n",
" sleep(2)"
]
Expand Down Expand Up @@ -200,10 +203,12 @@
"outputs": [],
"source": [
"def get_spaceship_location():\n",
" resp = requests.get('http://api.open-notify.org/iss-now.json')\n",
" location = resp.json()['iss_position']\n",
" return {'lat': float(location.get('latitude')),\n",
" 'long': float(location.get('longitude'))}"
" resp = requests.get(\"http://api.open-notify.org/iss-now.json\")\n",
" location = resp.json()[\"iss_position\"]\n",
" return {\n",
" \"lat\": float(location.get(\"latitude\")),\n",
" \"long\": float(location.get(\"longitude\")),\n",
" }"
]
},
{
Expand All @@ -213,7 +218,7 @@
"outputs": [],
"source": [
"def great_circle_dist(lon1, lat1, lon2, lat2):\n",
" dist = DistanceMetric.get_metric('haversine')\n",
" dist = DistanceMetric.get_metric(\"haversine\")\n",
" lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2])\n",
"\n",
" X = [[lat1, lon1], [lat2, lon2]]\n",
Expand All @@ -228,10 +233,10 @@
"outputs": [],
"source": [
"def iss_dist_from_loc(issloc, loc):\n",
" distance = great_circle_dist(issloc.get('long'), \n",
" issloc.get('lat'), \n",
" loc.get('long'), loc.get('lat'))\n",
" logging.info('ISS is ~%dkm from %s', int(distance), loc.get('name'))\n",
" distance = great_circle_dist(\n",
" issloc.get(\"long\"), issloc.get(\"lat\"), loc.get(\"long\"), loc.get(\"lat\")\n",
" )\n",
" logging.info(\"ISS is ~%dkm from %s\", int(distance), loc.get(\"name\"))\n",
" return distance"
]
},
Expand All @@ -242,14 +247,17 @@
"outputs": [],
"source": [
"def iss_pass_near_loc(loc):\n",
" resp = requests.get('http://api.open-notify.org/iss-pass.json',\n",
" params={'lat': loc.get('lat'), \n",
" 'lon': loc.get('long')})\n",
" data = resp.json().get('response')[0]\n",
" td = datetime.fromtimestamp(data.get('risetime')) - datetime.now()\n",
" resp = requests.get(\n",
" \"http://api.open-notify.org/iss-pass.json\",\n",
" params={\"lat\": loc.get(\"lat\"), \"lon\": loc.get(\"long\")},\n",
" )\n",
" data = resp.json().get(\"response\")[0]\n",
" td = datetime.fromtimestamp(data.get(\"risetime\")) - datetime.now()\n",
" m, s = divmod(int(td.total_seconds()), 60)\n",
" h, m = divmod(m, 60)\n",
" logging.info('ISS will pass near %s in %02d:%02d:%02d',loc.get('name'), h, m, s)\n",
" logging.info(\n",
" \"ISS will pass near %s in %02d:%02d:%02d\", loc.get(\"name\"), h, m, s\n",
" )\n",
" return td.total_seconds()"
]
},
Expand Down Expand Up @@ -325,10 +333,9 @@
"for loc in locations:\n",
" issloc = delayed(get_spaceship_location)()\n",
" dist = delayed(iss_dist_from_loc)(issloc, loc)\n",
" output.append((loc.get('name'), dist))\n",
" output.append((loc.get(\"name\"), dist))\n",
"\n",
"closest = delayed(lambda x: sorted(x, \n",
" key=itemgetter(1))[0])(output)"
"closest = delayed(lambda x: sorted(x, key=itemgetter(1))[0])(output)"
]
},
{
Expand Down Expand Up @@ -425,9 +432,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8",
"display_name": "Python 3.11 Kernel",
"language": "python",
"name": "python-38"
"name": "python311"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -439,7 +446,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.11.4"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
Expand Down
Loading

0 comments on commit 4b5ba15

Please sign in to comment.