← All Scripts
Live Data Script

Fetch Live Earthquakes from USGS

Pull the last 30 days of global seismic data directly from the USGS API. No file download, no setup. DuckDB reads the CSV over HTTPS.

LIVE DATA USGS API ~10,000 ROWS SCATTER PLOT

The Script

Copy this into the Script Console (Tools > Script Console) and hit Run. ColumnLens fetches the data, loads it into the results table, and renders a magnitude vs depth scatter plot.

-- fetch_earthquakes.lua — Live USGS earthquake data (last 30 days)
--
-- Fetches real-time earthquake data directly from the USGS API.
-- DuckDB's httpfs extension reads the CSV over HTTPS — no local download needed.
-- Scatter plot maps magnitude vs depth. City View works well with
-- height=mag, color=magType, district=place.

ds.log("=== USGS Earthquakes — Last 30 Days ===")
ds.log("Fetching live data from earthquake.usgs.gov...")

ds.query([[
    SELECT
        time,
        round(latitude, 3)  AS latitude,
        round(longitude, 3) AS longitude,
        round(depth, 1)     AS depth_km,
        round(mag, 1)       AS magnitude,
        magType              AS mag_type,
        nst                  AS station_count,
        round(gap, 0)::int  AS azimuthal_gap,
        round(dmin, 2)      AS distance_deg,
        round(rms, 3)       AS rms_residual,
        net                  AS network,
        place,
        type                 AS event_type,
        status,
        updated
    FROM read_csv_auto(
        'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv'
    )
    WHERE mag IS NOT NULL
    ORDER BY time DESC
]])

ds.log("Loaded " .. ds.data.row_count .. " seismic events")
ds.log("Columns: " .. table.concat(ds.data.column_names, ", "))

-- Scatter: magnitude vs depth
ds.chart.type  = "scatter"
ds.chart.x     = 4       -- depth_km
ds.chart.y     = {5}     -- magnitude
ds.chart.title = "Earthquake Magnitude vs Depth (Last 30 Days)"

ds.log("=== Chart ready ===")
ds.log("Try: SELECT place, magnitude, depth_km FROM _cl_result WHERE magnitude > 4 ORDER BY magnitude DESC")

Data Source

USGS Earthquake Hazards Program. Real-time CSV feed updated every minute. All earthquakes worldwide, last 30 days.

What You Get

15 columns: time, lat/lon, depth, magnitude, mag type, station count, network, place, event type, status.

Chart

Scatter plot: magnitude (Y) vs depth in km (X). Shallow quakes cluster left, deep subduction events appear right.

Try Next

Switch to City View. Set height to magnitude, color to depth_km, district to network. Or run the Earthquake Flyover script.


Run this script in ColumnLens

Paste it into the Script Console and see live earthquake data in seconds.

Download on the Mac App Store
Or try the free version (up to 100 MB)