GWpy

raw JSON →
4.0.1 verified Fri May 01 auth: no python

GWpy is a Python package for gravitational-wave astrophysics, enabling data analysis and visualization of gravitational-wave data. Version 4.0.1 requires Python >=3.11. It provides high-level access to time series, frequency series, and spectrograms, with integration to GWOSC and other data sources. The library is under active development with regular releases.

pip install gwpy
error ImportError: cannot import name 'TimeSeries' from 'gwpy'
cause Incorrect import path: trying to import TimeSeries directly from gwpy top-level package.
fix
Use 'from gwpy.timeseries import TimeSeries' instead.
error OSError: [Errno 22] Invalid argument when opening data file
cause Often due to file path containing non-ASCII characters or using Windows paths in Linux-style string.
fix
Ensure file paths are correct and use raw strings or forward slashes.
error ValueError: The given GPS end time is not in the data frame's interval
cause The requested GPS time range falls outside the available data segment (e.g., detector not operating).
fix
Check the data availability using 'gwpy.segments.DataQualityFlag' or query the data range first.
error HTTPError: 401 Unauthorized when accessing NDS2 server
cause Missing or invalid authentication token for NDS2 data access.
fix
Obtain a token from LIGO's datafind service and set it as GWPY_TOKEN environment variable, or pass token='your_token' to fetch methods.
breaking In GWpy 4.0.0+, the minimum Python version is 3.11. Older Python versions (3.10, 3.9) are no longer supported. Upgrade Python if you encounter import errors.
fix Ensure your environment uses Python >= 3.11. Run 'python --version' to check.
breaking Fetching data from LIGO data servers (NDS2) now requires authentication tokens. The old anonymous access is deprecated and may fail.
fix Register at https://datafind.ligo.org and set environment variable 'GWPY_TOKEN' or pass 'token' argument to fetch methods.
gotcha The 'fetch_open_data' method may return data with gaps (e.g., if detector is not in science mode). Always check for missing data before analysis.
fix Use the 'segmentlist' property of TimeSeries to verify coverage, or use 'DataQualityFlag' to check if data is valid.
deprecated The 'gwpy.timeseries.TimeSeriesDict' is deprecated in favor of 'gwpy.timeseries.TimeSeries' with dictionary-like access. Use 'TimeSeriesDict' only for legacy code.
fix Use 'gwpy.timeseries.TimeSeries.fetch_open_data' for multiple channels or iterate over a list of frequencies.

Fetch gravitational-wave strain data from GWOSC using a TimeSeries object. Requires internet access. The os.environ.get simulates an optional token.

from gwpy.timeseries import TimeSeries
import os

# Fetch 30 seconds of gravitational-wave strain data from GWOSC
# from the LIGO Hanford detector (H1) during GW170817
h1_data = TimeSeries.fetch_open_data(
    'H1', 1187008882, 1187008912,  # GPS start and end
    sample_rate=4096,  # Downsample to 4096 Hz
    verbose=True,
    token=os.environ.get('GWPY_TOKEN', '')
)
print(h1_data)
print('Data length:', len(h1_data), 'samples')