================================================================================
  Experiment 12: USGS Earthquake Analysis Dashboard
================================================================================

FULL QUESTION:
Retrieve earthquake data for the past 7 weeks using the USGS Earthquake API. Extract the following fields: Magnitude, Place, Time, Longitude, Latitude, Depth, and Tsunami Status. Perform statistical and time-series analysis on the retrieved earthquake data. Visualize the results using suitable charts and develop a dashboard to display the earthquake data, statistical analysis, time-series visualizations, and findings.

SHORT QUESTION:
Fetch USGS GeoJSON earthquake feed, compute statistical distributions, and render multi-chart Streamlit dashboard.

================================================================================
README & SETUP INSTRUCTIONS:
================================================================================
# Experiment 12: USGS Earthquake Analysis Dashboard

## Objective
Retrieve earthquake events from the USGS GeoJSON API, extract Magnitude, Place, Time, Coordinates, Depth, and Tsunami Status, and perform statistical and time-series analysis on an interactive dashboard.

## Requirements
```bash
pip install requests pandas matplotlib streamlit
```

## How to Run
```bash
streamlit run app.py
```

================================================================================
SOURCE CODE FILES:
================================================================================

1. app.py
--------------------------------------------------------------------------------
import streamlit as st
import pandas as pd
import requests
import matplotlib.pyplot as plt

st.title("USGS Earthquake Analysis Dashboard")

USGS_URL = (
    "https://earthquake.usgs.gov/fdsnws/event/1/query?"
    "format=geojson&starttime=2026-08-07&endtime=2026-09-25&minmagnitude=2.5&orderby=time"
)

res = requests.get(USGS_URL, timeout=20).json()
records = []
for f in res.get("features", []):
    props = f["properties"]
    geom = f["geometry"]["coordinates"]
    records.append({
        "Magnitude": props.get("mag"),
        "Place": props.get("place"),
        "Time": pd.to_datetime(props.get("time"), unit="ms"),
        "Longitude": geom[0],
        "Latitude": geom[1],
        "Depth": geom[2],
        "Tsunami Status": props.get("tsunami")
    })
df = pd.DataFrame(records).dropna(subset=["Magnitude", "Time"])

st.subheader("Statistical Summary")
st.write(df[["Magnitude", "Depth", "Tsunami Status"]].describe())

st.subheader("Time-Series Visualizations")
df_sorted = df.sort_values("Time")

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 6))
ax1.plot(df_sorted["Time"], df_sorted["Magnitude"])
ax1.set_ylabel("Magnitude")
ax1.set_title("Earthquake Magnitude over Time")

ax2.plot(df_sorted["Time"], df_sorted["Depth"])
ax2.set_xlabel("Date")
ax2.set_ylabel("Depth (km)")
ax2.set_title("Earthquake Focal Depth over Time")

plt.tight_layout()
st.pyplot(fig)

st.subheader("Recent Earthquakes")
st.write(df.head(50))
--------------------------------------------------------------------------------
