.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/timeseries/pycbc-snr.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_timeseries_pycbc-snr.py: .. sectionauthor:: Duncan Macleod .. currentmodule:: gwpy.timeseries Calculating the SNR associated with an astrophysical signal model ################################################################# The example :ref:`sphx_glr_examples_signal_gw150914.py` showed us we can visually extract a signal from the noise using basic signal-processing techniques. However, an actual astrophysical search algorithm detects signals by calculating the signal-to-noise ratio (SNR) of data for each in a large bank of signal models, known as templates. Using |pycbc|_ (the actual search code), we can do that. .. GENERATED FROM PYTHON SOURCE LINES 37-40 Data access and conditioning ---------------------------- First we fetch some of the public data from |GWOSC|_: .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python from gwpy.timeseries import TimeSeries data = TimeSeries.fetch_open_data("H1", 1126259446, 1126259478) .. GENERATED FROM PYTHON SOURCE LINES 45-46 and condition it by applying a highpass filter at 15 Hz .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: Python high = data.highpass(15) .. GENERATED FROM PYTHON SOURCE LINES 50-56 This is important to remove noise at lower frequencies that isn't accurately calibrated, and swamps smaller noises at higher frequencies. For this example, we want to calculate the SNR over a 4 second segment, so we calculate a Power Spectral Density with a 4 second FFT length (using all of the data), then :meth:`~TimeSeries.crop` the data: .. GENERATED FROM PYTHON SOURCE LINES 56-60 .. code-block:: Python psd = high.psd(4, 2) zoom = high.crop(1126259460, 1126259464) .. GENERATED FROM PYTHON SOURCE LINES 61-68 Generating a signal model ------------------------- In order to calculate signal-to-noise ratio, we need a signal model against which to compare our data. For this we import :func:`pycbc.waveform.get_fd_waveform ` and generate a template as a `pycbc.types.FrequencySeries `: .. GENERATED FROM PYTHON SOURCE LINES 68-79 .. code-block:: Python from pycbc.waveform import get_fd_waveform hp, _ = get_fd_waveform( approximant="IMRPhenomD", mass1=40, mass2=32, f_lower=20, f_final=2048, delta_f=psd.df.value, ) .. GENERATED FROM PYTHON SOURCE LINES 80-86 Calculating SNR --------------- At this point we are ready to calculate the SNR, so we import the :func:`pycbc.filter.matched_filter ` method, and pass it our template, the data, and the PSD: .. GENERATED FROM PYTHON SOURCE LINES 86-96 .. code-block:: Python from pycbc.filter import matched_filter snr = matched_filter( hp, zoom.to_pycbc(), psd=psd.to_pycbc(), low_frequency_cutoff=15, ) snrts = TimeSeries.from_pycbc(snr).abs() .. GENERATED FROM PYTHON SOURCE LINES 97-108 .. tip:: Here we have used the :meth:`~TimeSeries.to_pycbc` methods of the `~gwpy.timeseries.TimeSeries` and `~gwpy.frequencyseries.FrequencySeries` objects to convert from GWpy objects to something that PyCBC functions can understand, and then used the :meth:`~TimeSeries.from_pycbc` method to convert back to a GWpy object. Visualisation ------------- We can plot the SNR `TimeSeries` around the region of interest: .. GENERATED FROM PYTHON SOURCE LINES 108-117 .. code-block:: Python plot = snrts.plot() ax = plot.gca() ax.set_xlim(1126259461, 1126259463) ax.set_epoch(1126259462.427) ax.set_ylabel("Signal-to-noise ratio (SNR)") ax.set_title("LIGO-Hanford signal-correlation for GW150914") plot.show() .. image-sg:: /examples/timeseries/images/sphx_glr_pycbc-snr_001.png :alt: LIGO-Hanford signal-correlation for GW150914 :srcset: /examples/timeseries/images/sphx_glr_pycbc-snr_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 118-122 We can clearly see a large spike (above 17!) at the time of the |GW150914|_ signal! This is, in principle, how the full, blind, CBC search is performed, using all of the available data, and a bank of tens of thousand of signal models. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.029 seconds) .. _sphx_glr_download_examples_timeseries_pycbc-snr.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pycbc-snr.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pycbc-snr.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pycbc-snr.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_