Skip to main content

Quaker

Lightweight python API to USGS earthquake dataset. API Docs are located here

Installation

Clone the repo to your system and install

$ git clone https://github.com/BlakeJC94/quaker.git
$ cd quaker
$ pip install .

Quickstart

This package comes equipped with a batteries-included CLI interface for downloading the latest earthquake event data in CSV, GeoJSON, and plain text format from the USGS database.

usage: quaker [-h] [--format FORMAT] [--endtime ENDTIME] [--starttime STARTTIME] [--updatedafter UPDATEDAFTER]
              [--minlatitude MINLATITUDE] [--minlongitude MINLONGITUDE] [--maxlatitude MAXLATITUDE]
              [--maxlongitude MAXLONGITUDE] [--latitude LATITUDE] [--longitude LONGITUDE] [--maxradius MAXRADIUS]
              [--maxradiuskm MAXRADIUSKM] [--catalog CATALOG] [--contributor CONTRIBUTOR] [--eventid EVENTID]
              [--includeallmagnitudes] [--includeallorigins] [--includedeleted] [--includesuperseded]
              [--maxmagnitude MAXMAGNITUDE] [--mindepth MINDEPTH] [--minmagnitude MINMAGNITUDE] [--orderby ORDERBY]
              [argfile]

positional arguments:
  argfile               Optional comma separated file with API arguments

options:
  -h, --help            show this help message and exit

Formats arguments:
  --format FORMAT       (default: quakeml) Specify the output format, one of csv, geojson, kml, quakeml, csv, text,
                        xml

Time arguments:
  --endtime ENDTIME     (default: present time) Limit to events on or before the specified end time. NOTE: All times
                        use ISO8601 Date/Time format. Unless a timezone is specified, UTC is assumed
  --starttime STARTTIME
                        (default: NOW - 30 days) Limit to events on or after the specified start time. NOTE: All
                        times use ISO8601 Date/Time format. Unless a timezone is specified, UTC is assumed
  --updatedafter UPDATEDAFTER
                        (default: null) Limit to events updated after the specified time. NOTE: All times use
                        ISO8601 Date/Time format. Unless a timezone is specified, UTC is assumed

Location (rectangle) arguments:
  --minlatitude MINLATITUDE
                        (default: -90) [-90,90] degrees, Limit to events with a latitude larger than the specified
                        minimum. NOTE: min values must be less than max values
  --minlongitude MINLONGITUDE
                        (default: -180) [-360,360] degrees, Limit to events with a longitude larger than the
                        specified minimum. NOTE: rectangles may cross the date line by using a minlongitude < -180
                        or maxlongitude > 180. NOTE: min values must be less than max values
  --maxlatitude MAXLATITUDE
                        (default: 90) [-90,90] degrees, Limit to events with a latitude smaller than the specified
                        maximum. NOTE: min values must be less than max values
  --maxlongitude MAXLONGITUDE
                        (default: 180) [-360,360] degrees, Limit to events with a longitude smaller than the
                        specified maximum. NOTE: rectangles may cross the date line by using a minlongitude < -180
                        or maxlongitude > 180. NOTE: min values must be less than max values

Location (circle) arguments:
  --latitude LATITUDE   (default: null) [-90,90] degrees, Specify the latitude to be used for a radius search
  --longitude LONGITUDE
                        (default: null) [-180,180] degrees, Specify the longitude to be used for a radius search
  --maxradius MAXRADIUS
                        (default: 180) [0, 180] degrees, Limit to events within the specified maximum number of
                        degrees from the geographic point defined by the latitude and longitude parameters. NOTE:
                        This option is mutually exclusive with maxradiuskm and specifying both will result in an
                        error
  --maxradiuskm MAXRADIUSKM
                        (default: 20001.6) [0, 20001.6] km, Limit to events within the specified maximum number of
                        kilometers from the geographic point defined by the latitude and longitude parameters. NOTE:
                        This option is mutually exclusive with maxradius and specifying both will result in an error

Other arguments:
  --catalog CATALOG     (default: null) Limit to events from a specified catalog. Use the Catalogs Method to find
                        available catalogs. NOTE: when catalog and contributor are omitted, the most preferred
                        information from any catalog or contributor for the event is returned
  --contributor CONTRIBUTOR
                        (default: null) Limit to events contributed by a specified contributor. Use the Contributors
                        Method to find available contributors. NOTE: when catalog and contributor are omitted, the
                        most preferred information from any catalog or contributor for the event is returned
  --eventid EVENTID     (default: null) Select a specific event by ID; event identifiers are data center specific.
                        NOTE: Selecting a specific event implies includeallorigins, includeallmagnitudes, and,
                        additionally, associated moment tensor and focal-mechanisms are included
  --includeallmagnitudes
                        (default: false) Specify if all magnitudes for the event should be included, default is data
                        center dependent but is suggested to be the preferred magnitude only. NOTE: because
                        magnitudes and origins are strongly associated, this parameter is interchangeable with
                        includeallmagnitude
  --includeallorigins   (default: false) Specify if all origins for the event should be included, default is data
                        center dependent but is suggested to be the preferred origin only. NOTE: because magnitudes
                        and origins are strongly associated, this parameter is interchangable with
                        includeallmagnitude
  --includedeleted      (default: false) Specify if deleted products and events should be included. The value only
                        returns only deleted events. Deleted events otherwise return the HTTP status 409 Conflict.
                        NOTE: Only supported by the csv and geojson formats, which include status
  --includesuperseded   (default: false) Specify if superseded products should be included. This also includes all
                        deleted products, and is mutually exclusive to the includedeleted parameter. NOTE: Only
                        works when specifying eventid parameter
  --maxmagnitude MAXMAGNITUDE
                        (default: null) Limit to events with a magnitude smaller than the specified maximum
  --mindepth MINDEPTH   (default: -100) [-100, 1000] km Limit to events with depth more than the specified minimum
  --minmagnitude MINMAGNITUDE
                        (default: null) Limit to events with a magnitude larger than the specified minimum
  --orderby ORDERBY     Order the results. The allowed values are: time, time-asc, magnitude, magnitude-asc

Run quaker download and specify the parameters as keyword arguments and pipe the output to any location:

$ quaker download --format csv --starttime 2022-08-01 --endtime 2022-09-01 > earthquake_data.csv

For more details on the available query parameters, use quaker --help or view the USGS documentation.

Using the python API is also fairly straight-forward:

>>> import io
>>> import pandas as pd
>>> from quaker_db import Client
>>> client = Client()
# An empty query defaults to all events in the last 30 days
>>> recent_events = client.execute(format="csv")
>>> df = pd.read_csv(io.StringIO(recent_events))
# Large multi-page queries can also be handled
>>> events_from_last_5_months = client.execute(
...     format="csv",
...     starttime="2022-05-01",
...     endtime="2022-10-01",
... )
>>> df = pd.read_csv(io.StringIO(events_from_last_5_months))
# You can filter results by location using the API
>>> events_in_august_in_120km_within_tokyo_above_mag_3 = client.execute(
...     forma="csv",
...     starttime="2022-08-01",
...     endtime="2022-09-01",
...     latitude=35.652832,
...     longitude=139.839478,
...     maxradiuskm=120.0,
...     minmagnitude=3.0,
... }
# See `help(quaker_db.Query)` and https://earthquake.usgs.gov/fdsnws/event/1/ for more details

Contributing

This is a small personal project, but pull requests are most welcome!

  • Code is styled using [black](https://github.com/psf/black) (pip install black)
  • Code is linted with ruff (pip install ruff)
  • Requirements are managed using poetry
  • Semantic versioning is used in this repo
    • Major version: rare, substantial changes that break backward compatibility
    • Minor version: most changes - new features, models or improvements
    • Patch version: small bug fixes and documentation-only changes

Virtual environment handling by poetry is preferred:

# in the project directory
$ poetry install
$ poetry shell

Metadata

Release files for quaker-db 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quaker-db 2.0.0
File Size Uploaded Provenance
quaker_db-2.0.0.tar.gz 22.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for quaker-db 2.0.0
File Interpreter ABI Platform
quaker_db-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.8 kB

Release files / quaker_db-2.0.0.tar.gz

Download URL quaker_db-2.0.0.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d5b524f3f7a23b5b213407e2f12f266449acc1fc166681cfd8b3df18b752c482
BLAKE2b-256 checksum
How to use checksums
85db870677ba5dfe3ba001d3ef2647ae7318402e474de8fa50e4e243f4c00d1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.8 Linux/6.6.10-76060610-generic

Release files / quaker_db-2.0.0-py3-none-any.whl

Download URL quaker_db-2.0.0-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
361b324f8b5f08a59b01a34e6bdcd6d39aa46f942e94dcdf2fad32eb7e40924f
BLAKE2b-256 checksum
How to use checksums
415ad0cd662f6be89fbb2dcdede53a0e8b22be01dc57339275b360d9d9369633
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.8 Linux/6.6.10-76060610-generic

Security for quaker-db 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page