SDKs overview

The USGS Earthquake Hazards Program (EHP) provides access to its extensive seismic data through a suite of web services conforming to the International Federation of Digital Seismograph Networks (FDSN) web service standards. These services include event, station, and waveform data, designed for interoperability and broad utility across scientific and educational applications. While the USGS EHP primarily offers direct web service access, the open nature of these services has led to the development of various community-driven Software Development Kits (SDKs) and libraries.

These SDKs and libraries abstract the complexities of direct HTTP requests and data parsing, allowing developers to integrate earthquake data into their applications using familiar programming paradigms. The FDSN web services support standard data formats such as XML and JSON for event metadata, and MiniSEED for waveform data, ensuring compatibility with a wide range of analytical tools and programming languages. The FDSN web services specification details the structure and functionality for accessing seismic data, promoting consistent access across different data centers. Developers can consult the USGS Earthquake Hazards Program's data products page for an overview of available data and access methods.

Official SDKs by language

The USGS Earthquake Hazards Program itself does not maintain official, language-specific SDKs in the traditional sense, where a single library is released and supported by the program for various languages. Instead, it provides FDSN web services that adhere to an international standard, allowing any programming language with HTTP client capabilities to interact with the data.

This approach emphasizes data accessibility and open standards over proprietary SDKs. However, the FDSN standard has facilitated the growth of community-contributed libraries in popular scientific computing languages. These libraries often wrap the FDSN web service calls, providing higher-level functions and objects for data retrieval and manipulation. This table focuses on the primary method of interaction, which is direct web service access:

Language/Method Package/API Endpoint Installation/Access Maturity
HTTP/REST FDSN Event Web Service Direct HTTP requests Stable (Standard)
HTTP/REST FDSN Station Web Service Direct HTTP requests Stable (Standard)
HTTP/REST FDSN Dataselect Web Service Direct HTTP requests Stable (Standard)

Installation

For direct interaction with USGS FDSN web services, no specific SDK installation is required beyond a developer's chosen programming language and its standard HTTP client libraries. Most modern programming environments include built-in or easily installable libraries for making web requests and parsing JSON or XML responses.

Python

Python offers several libraries for making HTTP requests:

  • Requests: A popular library for making HTTP requests. Install via pip: pip install requests
  • urllib: Built-in Python module for handling URLs. No installation required.

JavaScript (Node.js/Browser)

For JavaScript environments, common choices include:

  • Fetch API: Native to modern browsers and available in Node.js 18+. No installation required.
  • Axios: A promise-based HTTP client. Install via npm: npm install axios

R

R provides packages for web interaction and data handling:

  • httr: Comprehensive HTTP client. Install via CRAN: install.packages("httr")
  • jsonlite: For JSON parsing. Install via CRAN: install.packages("jsonlite")

Java

Java developers can use:

  • HttpClient (Apache HttpComponents): Robust HTTP client library. Available via Maven/Gradle.
  • java.net.HttpURLConnection: Built-in Java class for HTTP connections.

Quickstart example

This Python example demonstrates how to retrieve earthquake event data from the USGS FDSN Event Web Service using the requests library, filtering for events within a specific time range and magnitude.


import requests
import json

# Define the base URL for the FDSN Event Web Service
base_url = "https://earthquake.usgs.gov/fdsnws/event/1/query"

# Define parameters for the query
params = {
    "format": "geojson",
    "starttime": "2024-01-01",
    "endtime": "2024-01-02",
    "minmagnitude": 4.5,
    "latitude": 34.05,
    "longitude": -118.25,
    "maxradiuskm": 200
}

try:
    # Make the GET request to the USGS API
    response = requests.get(base_url, params=params)
    response.raise_for_status()  # Raise an HTTPError for bad responses (4xx or 5xx)

    # Parse the JSON response
    data = response.json()

    # Print some information about the earthquakes found
    print(f"Found {len(data['features'])} earthquakes.")
    for feature in data['features']:
        properties = feature['properties']
        geometry = feature['geometry']
        
        print(f"---")
        print(f"Time: {properties['time']}")
        print(f"Magnitude: {properties['mag']}")
        print(f"Place: {properties['place']}")
        print(f"Coordinates: {geometry['coordinates'][0]}, {geometry['coordinates'][1]}")

except requests.exceptions.HTTPError as http_err:
    print(f"HTTP error occurred: {http_err}")
except requests.exceptions.ConnectionError as conn_err:
    print(f"Connection error occurred: {conn_err}")
except requests.exceptions.Timeout as timeout_err:
    print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
    print(f"An error occurred: {req_err}")
except json.JSONDecodeError:
    print(f"Error decoding JSON from response: {response.text[:200]}...")

Community libraries

Due to the standardized nature of FDSN web services, several community-developed libraries exist to simplify interaction with the USGS Earthquake Hazards Program data. These libraries often provide convenience functions for common tasks like data retrieval, parsing, and sometimes visualization.

Python

  • ObsPy: A widely used Python framework for seismological data analysis. ObsPy can access FDSN web services, including those from USGS, for event, station, and waveform data. It provides powerful tools for processing and plotting seismic data.
    • Installation: pip install obspy
    • Documentation: ObsPy FDSN client tutorial
  • pysep: While focused on seismic inversion, pysep utilizes ObsPy and other tools to interact with seismic data, including FDSN services.

R

  • RNetCDF: While not exclusively for earthquake data, this package can handle NetCDF files, a format sometimes used for geological data, and can be combined with httr for web service interactions.
    • Installation: install.packages("RNetCDF")
    • Documentation: RNetCDF CRAN documentation
  • seismologyR: A package for general seismological analysis in R, which may include functions for fetching or processing data from FDSN-compatible sources.
    • Source: Specific package details vary; search CRAN for "seismology" related packages.

MATLAB

  • GIS and Mapping Toolbox: MATLAB's built-in toolboxes can be used to process and visualize geospatial data, including earthquake locations obtained from the FDSN web services. Custom scripts can be written to make HTTP requests.
    • Documentation: MATLAB web map server documentation
  • Seismic Toolbox for MATLAB: Community-contributed toolboxes are often found on MATLAB File Exchange that offer seismological functions, which may include data import capabilities for FDSN data.
    • Source: Search MATLAB File Exchange for seismic toolboxes.

Developers are encouraged to consult the documentation for these libraries and the USGS Earthquake Hazards Program's data product pages for the most current information on data access and usage. The FDSN standard itself is maintained by the International Federation of Digital Seismograph Networks, which ensures persistent access methods.