Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Week04 #28

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions week04/Exercise- Looking for location of largest earthquake.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import json\n",
"import numpy as np "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"#reads in data from the internet url given \n",
"quakes = requests.get(\"http://earthquake.usgs.gov/fdsnws/event/1/query.geojson\",\n",
" params={\n",
" 'starttime': \"2000-01-01\",\n",
" \"maxlatitude\": \"58.723\",\n",
" \"minlatitude\": \"50.008\",\n",
" \"maxlongitude\": \"1.67\",\n",
" \"minlongitude\": \"-9.756\",\n",
" \"minmagnitude\": \"1\",\n",
" \"endtime\": \"2018-10-11\",\n",
" \"orderby\": \"time-asc\"})"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#reads in data using json as a dictionary\n",
"earthquakes = json.loads(quakes.text)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"120"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#assuming count is the number of counted earthquakes in this dictionary\n",
"earthquakes['metadata']['count']"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"120"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# creates a list of all the magnitudes of the earthquakes \n",
"eq_size = [earthquakes['features'][i]['properties']['mag'] for i in range(earthquakes['metadata']['count'])]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# searches for the location of the largest earthquake within list eq_size\n",
"# location is stored as a list\n",
"location = [j for j in range(len(eq_size)) if eq_size[j] == np.max(eq_size)]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'England, United Kingdom'"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# gives location of the largest earthqukes\n",
"earthquakes['features'][location[0]]['properties']['place']"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading