Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrote code to pick out strongest earthquakes #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

erg43
Copy link

@erg43 erg43 commented Oct 25, 2021

Answers UCL-MPHY0021-21-22/RSE-Classwork#13

was useful to practice with json/yaml files.
Found two events with same max magnitude.


data_asdict = json.loads(text)
with open('response.json', 'w') as file:
file.write(json.dumps(data_asdict, indent=4))

Choose a reason for hiding this comment

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

Nice use of indent!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, using indent=... makes for a much more readable file.
You can make the code a bit shorter by using json.dump, which will essentially do the same as dumps and then write.

print(f"The strongest earthquakes were at coordinates of {max_location} with magnitude {max_magnitude}, There were two earthquakes with equal largest magnitude")

Choose a reason for hiding this comment

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

Good job spotting that there were two earthquakes with equal magnitude

Copy link

@shashvatshukla shashvatshukla left a comment

Choose a reason for hiding this comment

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

Nicely done.

@@ -3,6 +3,8 @@
# However, we will use a more powerful and simpler library called requests.
# This is external library that you may need to install first.
import requests
import yaml
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you need this import here since you're not working with YAML!

Comment on lines +33 to +34
"The text is in dictionary format, under a string"
"get dictionary out using json"
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's good to write comments to explain what you're doing and why, as you do here and later, though note that in Python comment lines should start with a a # . You can leave multi-line comments enclosed in """...""", but those are best reserved for documenting functions etc ("docstrings").


data_asdict = json.loads(text)
with open('response.json', 'w') as file:
file.write(json.dumps(data_asdict, indent=4))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, using indent=... makes for a much more readable file.
You can make the code a bit shorter by using json.dump, which will essentially do the same as dumps and then write.

"for each event, 'mag' key gives magnitude. 'place' key gives place name, but 'geometry' 'coordinates'"
"gives the coordinates of the location"
"The time of the earthquake claims to use the ISO8601 Date/Time format, but this doesn't appear true..."
"What does 'time'=956553055700 mean? Seconds since something?"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hopefully this was clarified in the classwork exercise!

Comment on lines +76 to +77
index_of_max = [index for index, item in enumerate(magnitudes) if item == max_mag]
max_locs = locations[index_of_max[0]], locations[index_of_max[1]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

As said in another review, good job making this general enough to handle multiple earthquakes with the same magnitude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants