開発版ドキュメント · 0.2.3 30c2f8ba · 入門例の検証対象 0.2.3 · 版情報 · 既知の制限

ケーススタディ: イベント同期解析#

このチュートリアルでは、実務でのワークフローに即した例を紹介します。ログからのイベント抽出、時刻補正(模した例)、そしてイベントごとの解析・プロット生成までの一連の流れを SegmentTable で管理します。

イベント窓は引き続き gwpy.segments.Segment で表され、gwexpy は SegmentTable を通じてテーブル管理と apply() 駆動のバッチワークフローを提供します。GWpy の基本クラスと gwexpy 拡張の役割分担は、SegmentTable: 基本 と同じです。

import warnings


import warnings

with warnings.catch_warnings():

    import pandas as pd
    from gwpy.segments import Segment

    from gwexpy.table import SegmentTable

    # 1. Simulate finding events
    events_df = pd.DataFrame({
    "gps": [1234567890.1, 1234567895.5, 1234567900.2],
    "snr": [15, 8, 22]
    })

    # 2. Create SegmentTable from events
    # Define a 4-second window around each GPS time
    segs = [Segment(t-2, t+2) for t in events_df["gps"]]
    st = SegmentTable.from_segments(segs, snr=events_df["snr"])
    st
/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

バッチプロット生成#

apply() を使って、各イベントのズームプロットなどを一括生成し、そのファイルパスをテーブル自体に保存できます。

import os

os.makedirs("outputs", exist_ok=True)

def generate_event_plot(row):
    # Simulate plotting
    path = f"outputs/event_{row.index}.png"
    # plot = row["raw"].plot() -> plot.save(path)
    with open(path, "w") as f: f.write("Dummy PNG")
    return {"plot_path": path}

st_plots = st.apply(generate_event_plot)
st_plots.display()
span snr plot_path
0 (1234567888.1, 1234567892.1) 15 outputs/event_0.png
1 (1234567893.5, 1234567897.5) 8 outputs/event_1.png
2 (1234567898.2, 1234567902.2) 22 outputs/event_2.png

結果の絞り込みと出力#

最後に、特定の条件(SNR > 10 など)でテーブルをフィルタリングし、結果をエクスポートします。

st_best = st_plots.select(mask=st_plots.to_pandas()["snr"] > 10)
st_best.to_pandas()
span snr plot_path
0 (1234567888.1, 1234567892.1) 15 outputs/event_0.png
1 (1234567898.2, 1234567902.2) 22 outputs/event_2.png