.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/spectrogram/coherencegram.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_spectrogram_coherencegram.py: .. sectionauthor:: Duncan Macleod .. currentmodule:: gwpy.timeseries Calculating the time-dependent coherence between two channels ############################################################# The standard coherence calculation outputs a frequency series (`~gwpy.frequencyseries.FrequencySeries`) giving a time-averaged measure of coherence. See :ref:`sphx_glr_examples_frequencyseries_coherence.py` for an example. The `TimeSeries` method :meth:`~TimeSeries.coherence_spectrogram` performs the same coherence calculation every ``stride``, giving a time-varying coherence measure. These data are available as part of the |GWOSC_AUX_RELEASE|_. .. GENERATED FROM PYTHON SOURCE LINES 39-40 First, we import the `TimeSeriesDict` .. GENERATED FROM PYTHON SOURCE LINES 40-42 .. code-block:: Python from gwpy.timeseries import TimeSeriesDict .. GENERATED FROM PYTHON SOURCE LINES 43-46 and then :meth:`~TimeSeriesDict.get` the data for the differential-arm length servo control loop error signal (``H1:LSC-DARM_IN1_DQ``) and the PSL periscope accelerometer (``H1:PEM-CS_ACC_PSL_PERISCOPE_X_DQ``): .. GENERATED FROM PYTHON SOURCE LINES 46-55 .. code-block:: Python data = TimeSeriesDict.get( ["H1:LSC-DARM_IN1_DQ", "H1:PEM-CS_ACC_PSL_PERISCOPE_X_DQ"], 1186741560, 1186742160, host="nds.gwosc.org", ) darm = data["H1:LSC-DARM_IN1_DQ"] acc = data["H1:PEM-CS_ACC_PSL_PERISCOPE_X_DQ"] .. rst-class:: sphx-glr-script-out .. code-block:: none /home/duncan.macleod/gwpy-nightly-build/conda/envs/gwpy-nightly-3.11/lib/python3.11/site-packages/igwn_auth_utils/requests.py:46: DeprecationWarning: Support for identity-based X.509 credentials for LIGO.ORG is being dropped. Calls to this utility will stop working on/around 20 May 2025. For details on this change please see https://computing.docs.ligo.org/guide/compsoft/roadmap/LVK/x509_retirement/ If you have questions about this message, or its implications, please consider opening an IGWN Computing Help Desk ticket: https://git.ligo.org/computing/helpdesk/-/issues/new return func(*args, **kwargs) .. GENERATED FROM PYTHON SOURCE LINES 56-59 We can then calculate the :meth:`~TimeSeries.coherence` of one `TimeSeries` with respect to the other, using an 2-second Fourier transform length, with a 1-second (50%) overlap: .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: Python coh = darm.coherence_spectrogram(acc, 10, fftlength=.5, overlap=.25) .. GENERATED FROM PYTHON SOURCE LINES 62-64 Finally, we can :meth:`~gwpy.spectrogram.Spectrogram.plot` the resulting data .. GENERATED FROM PYTHON SOURCE LINES 64-75 .. code-block:: Python plot = coh.plot() ax = plot.gca() ax.set_ylabel("Frequency [Hz]") ax.set_yscale("log") ax.set_ylim(10, 2000) ax.set_title( "Coherence between PSL periscope motion and LIGO-Hanford strain data", ) ax.grid(visible=True, which="both", axis="both") ax.colorbar(label="Coherence", clim=[0, 1], cmap="plasma") plot.show() .. image-sg:: /examples/spectrogram/images/sphx_glr_coherencegram_001.png :alt: Coherence between PSL periscope motion and LIGO-Hanford strain data :srcset: /examples/spectrogram/images/sphx_glr_coherencegram_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.170 seconds) .. _sphx_glr_download_examples_spectrogram_coherencegram.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: coherencegram.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: coherencegram.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: coherencegram.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_