Skip to main content

Lightweight python API to USGS earthquake dataset

Project description

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

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

quaker_db-2.0.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

quaker_db-2.0.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file quaker_db-2.0.0.tar.gz.

File metadata

  • Download URL: quaker_db-2.0.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.6.10-76060610-generic

File hashes

Hashes for quaker_db-2.0.0.tar.gz
Algorithm Hash digest
SHA256 d5b524f3f7a23b5b213407e2f12f266449acc1fc166681cfd8b3df18b752c482
MD5 b05ce9829399ec8aee36c0cb1c514ef0
BLAKE2b-256 85db870677ba5dfe3ba001d3ef2647ae7318402e474de8fa50e4e243f4c00d1b

See more details on using hashes here.

File details

Details for the file quaker_db-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: quaker_db-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.6.10-76060610-generic

File hashes

Hashes for quaker_db-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 361b324f8b5f08a59b01a34e6bdcd6d39aa46f942e94dcdf2fad32eb7e40924f
MD5 028e91f8546fe7a23d3b41639d5ca8b2
BLAKE2b-256 415ad0cd662f6be89fbb2dcdede53a0e8b22be01dc57339275b360d9d9369633

See more details on using hashes here.

Supported by

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