Skip to main content

CLI tool to fetch and analyze earthquake data from USGS

Project description

Quake Analyzer

License Python Version PyPI Version

quake-analyzer is a command-line tool that fetches and analyzes earthquake data, including filtering based on magnitude and location, calculating recurrence intervals, and generating reports. This tool can help researchers and enthusiasts analyze earthquake data from the USGS database over various timeframes.

Quake Analyzer Screenshot


Features

  • Fetch earthquake data from the USGS Earthquake API.
  • Filter earthquakes based on magnitude and region.
  • Analyze major earthquakes and their recurrence intervals.
  • Export the list to CSV.
  • Plot the count of major earthquakes per year.
  • Estimate the recurrence interval and probability of future major earthquakes.

Installation

git clone https://github.com/danielhaim1/quake-analyzer.git
cd quake-analyzer
pip install -e .

Dependencies

This project relies on the following major Python libraries:

  • pandas for data manipulation and analysis.
  • requests for fetching data from the USGS API.
  • matplotlib for plotting data (optional, used with the --plot flag).

Options

Option Description Default
--data Manually pass quakes as [[timestamp, magnitude, location], ...] None
--fetch Fetch recent earthquakes from USGS None
--minmag Minimum magnitude to filter 6.0
--days Number of days to look back from today 1825 (5 years)
--location Location name to filter by (supports city, state, or country from CSVs) None
--radius Radius in kilometers around the specified location None
--export Export results to CSV Off
--plot Plot earthquakes per year Off
--estimate Estimate the recurrence interval and probability of major quakes Off

Examples

Global major quakes in past 20 years

quake-analyzer --fetch --minmag 6.0 --days 7300

Estimate Next Quake

quake-analyzer --fetch --minmag 6.0 --days 7300 --estimate

Location based filtering

# Quakes near Tokyo (within 300 km)
quake-analyzer --fetch --location "Tokyo" --radius 300 --minmag 5.5 --days 3650

# California region, major quakes (last 20 years)
quake-analyzer --fetch --location "California" --radius 500 --minmag 6.0 --days 7300

# Chile, strong events only
quake-analyzer --fetch --location "Chile" --radius 400 --minmag 6.8 --days 7300

Custom manual input

# Manually analyze a couple of events
quake-analyzer --data "[['2021-12-01T12:00:00', 6.5, 'Tokyo'], ['2022-01-01T15:00:00', 7.0, 'Santiago']]"

Export and Plot

# Export filtered results to CSV
quake-analyzer --fetch --location "Alaska" --radius 500 --minmag 6.0 --days 3650 --export

# Plot quake frequency per year
quake-analyzer --fetch --location "Indonesia" --radius 500 --minmag 6.0 --days 7300 --plot

# Export and plot together
quake-analyzer --fetch --location "Mexico" --radius 300 --minmag 6.2 --days 5000 --export --plot

Location Resolution

You can pass --location using names of:

  • Cities (e.g., Tokyo, San Francisco)
  • States (e.g., California, Bavaria)
  • Countries (e.g., Japan, Mexico)

Coordinates are looked up from:

src/data/
├── cities.csv
├── states.csv
├── countries.csv

Each file should include:

name,latitude,longitude

Estimate: How It Works

The estimation feature calculates two important metrics based on recent earthquake data:

  1. Recurrence Interval: The average time interval (in years) between major earthquakes (≥ 6.0 magnitude).
  2. Probability: The estimated probability of a major earthquake occurring within the next year.

How the Estimate is Calculated:

  • The tool first filters major quakes (≥ 6.0 magnitude) from the fetched or provided earthquake data.
  • It then calculates the time intervals between consecutive quakes.
  • The mean recurrence interval is computed as the average of those time intervals.
  • Finally, the probability of an earthquake occurring within the next year is estimated as 1 / mean recurrence interval.

Example:

quake-analyzer --fetch --location "Tokyo" --radius 300 --minmag 6.0 --days 3650 --estimate
  • Fetch earthquake data for Tokyo (within a 300 km radius).
  • Filter by magnitude ≥ 6.0.
  • Estimate the recurrence interval and probability based on the quakes in that region over the last 10 years (3650 days).

Outputs

The tool will output earthquake data in the terminal, including:

  • The total number of major earthquakes.

  • The years in which earthquakes occurred.

  • Gaps between major earthquakes.

  • A summary of earthquakes per year.

  • Estimates of recurrence intervals and probabilities (if --estimate is used).

  • If --export is used, the results will be saved to a CSV file with the following columns:

  • Years Ago

  • Magnitude

  • Date

  • Timestamp

  • Location

  • Type (Major or Moderate)

  • Mean Recurrence Interval (years)

  • Estimated Probability (per year)


Screenshots

Quake Analyzer Screenshot (Estimate) Quake Analyzer Screenshot Quake Analyzer Screenshot Quake Analyzer Screenshot Quake Analyzer Screenshot Quake Analyzer Screenshot


Notes

  • USGS limits results to 20 years and 2000 entries per request.
  • For smaller magnitudes (e.g., 3.0+), results may be capped quickly, especially in active zones.
  • Timestamp columns in exported CSVs include both quake time and export time.
  • Plots require matplotlib. Install via:
pip install matplotlib

License

This project is licensed under the MIT License. See the LICENSE file for details.


Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


Reporting Bugs

If you encounter a bug or issue, please open an issue on the GitHub repository with as much detail as possible including:

  • Command used
  • Stack trace or error message
  • Your OS and Python version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quake_analyzer-0.0.6.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quake_analyzer-0.0.6-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file quake_analyzer-0.0.6.tar.gz.

File metadata

  • Download URL: quake_analyzer-0.0.6.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quake_analyzer-0.0.6.tar.gz
Algorithm Hash digest
SHA256 a0f9c0baf14420fa73223720e0056871b92e71de18a85c88d35d9393c05c3b1a
MD5 4c92c11f9a020c7e43d1021e13840080
BLAKE2b-256 dd36d1574b10aabbe3223aed3be1308ee64b014bd5015b00872bf45091ca40df

See more details on using hashes here.

Provenance

The following attestation bundles were made for quake_analyzer-0.0.6.tar.gz:

Publisher: publish.yml on danielhaim1/quake-analyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quake_analyzer-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: quake_analyzer-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quake_analyzer-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8cb09552e86539bf91db8c5a784a3d8d137493dfac3063c5ff0f5f0d5b532d16
MD5 fc14faa014f83cc07d7a7b8b00a82b4e
BLAKE2b-256 153b2ec7245be3fd6fbfa968397ea7725ff758afd0c3bd83519227cd526bb8f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for quake_analyzer-0.0.6-py3-none-any.whl:

Publisher: publish.yml on danielhaim1/quake-analyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page