Created
September 22, 2025 20:42
-
-
Save mirontoli/2c48bb7026f1f89c3f21200cdb57efb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_day.geojson | |
| from pathlib import Path | |
| import json | |
| import plotly.express as px | |
| def get_contents(): | |
| path = Path('data/1.0_day.geojson') | |
| contents = path.read_text(encoding='utf-8') | |
| all_eq_data = json.loads(contents) | |
| return all_eq_data | |
| def make_readable(): | |
| all_eq_data = get_contents() | |
| # create a more readable version of the data file | |
| path = Path('data/readable_earthquakes.geojson') | |
| readable_contents = json.dumps(all_eq_data, indent=4) | |
| path.write_text(readable_contents) | |
| def get_data(): | |
| all_eq_data = get_contents() | |
| all_eq_dicts = all_eq_data['features'] | |
| # print(len(all_eq_dicts)) | |
| mags, lons, lats, titles = [], [], [], [] | |
| for eq_dict in all_eq_dicts: | |
| mag = eq_dict['properties']['mag'] | |
| lon = eq_dict['geometry']['coordinates'][0] | |
| lat = eq_dict['geometry']['coordinates'][1] | |
| title = eq_dict['properties']['title'] | |
| mags.append(mag) | |
| lons.append(lon) | |
| lats.append(lat) | |
| titles.append(title) | |
| return mags, lons, lats, titles | |
| def examine(): | |
| print('examine') | |
| mags, lons, lats, titles = get_data() | |
| print(mags[:10]) | |
| print(lons[:5]) | |
| print(lats[:5]) | |
| print(titles[:5]) | |
| def plot_map(): | |
| mags, lons, lats, titles = get_data() | |
| title = 'Global Earthquakes' | |
| fig = px.scatter_geo(lat=lats, lon=lons, size=mags, | |
| color=mags, | |
| color_continuous_scale='Viridis', | |
| labels={'color':'Magnitude'}, | |
| projection='natural earth', | |
| hover_name=titles, | |
| title=title) | |
| # fig.show() | |
| fig.write_html('plot2.html', auto_open=True) | |
| def main(): | |
| print("Hello from 004-earthquakes!") | |
| # make_readable() | |
| # examine() | |
| plot_map() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment