Skip to content

Commit

Permalink
Find the maximum magnitude and coordinates
Browse files Browse the repository at this point in the history
Answers UCL-RITS#12
  • Loading branch information
nuttamas authored Oct 28, 2020
1 parent 9e16337 commit 0493eb2
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions week04/quakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,45 @@

# At the top of the file, import any libraries you will use.
# import ...
import requests

# If you want, you can define some functions to help organise your code.
# def helper_function(argument_1, argument_2):
# ...
quakes = requests.get("http://earthquake.usgs.gov/fdsnws/event/1/query.geojson",
params={
'starttime': "2000-01-01",
"maxlatitude": "58.723",
"minlatitude": "50.008",
"maxlongitude": "1.67",
"minlongitude": "-9.756",
"minmagnitude": "1",
"endtime": "2018-10-11",
"orderby": "time-asc"}
)
f = open("quakes.txt", "a")
f.write(quakes.text)
f.close()

import json
with open('quakes.txt', 'r') as source:
quakes_dict = json.loads(source.read())
with open('Data.json','w') as output2:
json.dump(quakes_dict,output2)
# When you run the file, it should print out the location and magnitude
# of the biggest earthquake.
# You can run the file with `python quakes.py` from this directory.
if __name__ == "__main__":
# ...do things here to find the results...

N = len(quakes_dict['features'])
mag = quakes_dict['features'][0]['properties']['mag']
coord = []
for key in range(0,N):
mag_new = quakes_dict['features'][key]['properties']['mag']
if mag_new > mag:
mag = mag_new
coord = quakes_dict['features'][key]['geometry']['coordinates']
# The lines below assume that the results are stored in variables
# named max_magnitude and coords, but you can change that.
print(f"The maximum magnitude is {max_magnitude} "
f"and it occured at coordinates {coords}.")
print('The maximum magnitude is ', mag,' and it occured at coordinates ',coord)

1 comment on commit 0493eb2

@nuttamas
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The maximum magnitude is 4.8 and it occured at coordinates [-2.15, 52.52, 9.4].

Please sign in to comment.