Development documentation · 0.2.3 30c2f8ba · Intro examples tested with 0.2.3 · Version details · Known limitations

Segment Analysis: Visualization#

SegmentTable provides rich plotting features, specifically optimized for comparing spectra over multiple segments via overlay_spectra().

The segment boundaries are still gwpy.segments.Segment, and the spectra being overlaid are GWpy FrequencySeries objects. gwexpy adds the table-oriented visualization layer by collecting those GWpy base classes in SegmentTable and providing overlay, color grading, and overview layouts on top. For the base relationship between GWpy classes and gwexpy extensions, see SegmentTable: Basics.

import warnings


import warnings

with warnings.catch_warnings():

    import numpy as np
    np.random.seed(42)
    from gwpy.frequencyseries import FrequencySeries
    from gwpy.segments import Segment

    from gwexpy.table import SegmentTable

    def make_fs(i):
        f = np.linspace(1, 32, 256)
        data = (1.0/(f**1.5)) * (1.0 + i*0.1)
        return FrequencySeries(data, frequencies=f)

    segs = [Segment(i*100, i*100+100) for i in range(10)]
    st = SegmentTable.from_segments(segs, snr=np.random.uniform(5, 20, 10))
    st.add_series_column("asd", data=[make_fs(i) for i in range(10)], kind="frequencyseries")

    # 1. Overlay spectra graded by start time (default)
    plot = st.overlay_spectra("asd", color_by="t0")
    plot
/home/runner/micromamba/envs/gwexpy/lib/python3.11/site-packages/gwpy/time/_ligotimegps.py:42: UserWarning: Wswiglal-redir-stdio:

SWIGLAL standard output/error redirection is enabled in IPython.
This may lead to performance penalties. To disable locally, use:

with lal.no_swig_redirect_standard_output_error():
    ...

To disable globally, use:

lal.swig_redirect_standard_output_error(False)

Note however that this will likely lead to error messages from
LAL functions being either misdirected or lost when called from
Jupyter notebooks.

To suppress this warning, use:

import warnings
warnings.filterwarnings("ignore", "Wswiglal-redir-stdio")
import lal

  from lal import LIGOTimeGPS
../../_images/332ff53ead36e23f843f2856c037e07d4ce91a3fd7c8506f333e7b65fd2e8dce.png

Color Grading by Meta Column#

You can color individual lines based on any numeric meta column (e.g., SNR).

plot = st.overlay_spectra("asd", color_by="snr", cmap="plasma")
plot
../../_images/40c00703f1c79958a3bb13108de12703973b92e490803f4f183765c4312abf42.png ../../_images/40c00703f1c79958a3bb13108de12703973b92e490803f4f183765c4312abf42.png

Overview Layouts#

Use segments() to see the temporal layout of your table.

st.segments(color="snr")
../../_images/c0d4a5f4bb8c5897e3f101cf9045dd88c61bf637f5d2b9aafa9ebdd2d2f5b5ca.png ../../_images/c0d4a5f4bb8c5897e3f101cf9045dd88c61bf637f5d2b9aafa9ebdd2d2f5b5ca.png