.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/miscellaneous/open-data-spectrogram.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_miscellaneous_open-data-spectrogram.py: .. sectionauthor:: Duncan Macleod .. currentmodule:: gwpy.timeseries Plotting a spectrogram of all open data for many hours ###################################################### In order to study interferometer performance, it is common in LIGO to plot all of the data for a day, in order to determine trends, and see data-quality issues. This is done for the LIGO-Virgo detector network, with `up-to-date plots `__ available from |GWOSC|. This example demonstrates how to download data segments from GWOSC, then use those to build a multi-hour spectrogram plot of LIGO-Livingston strain data. .. GENERATED FROM PYTHON SOURCE LINES 39-48 .. currentmodule:: gwpy.segments Getting the segments -------------------- First, we need to fetch the Open Data timeline segments from GWOSC. To do that we can call the :meth:`DataQualityFlag.fetch_open_data` method using ``'H1_DATA'`` as the flag (for an explanation of what this means, read up on `The S6 Data Release `__). .. GENERATED FROM PYTHON SOURCE LINES 48-56 .. code-block:: Python from gwpy.segments import DataQualityFlag l1segs = DataQualityFlag.fetch_open_data( "L1_DATA", "Aug 17 2017 08:00", "Aug 17 2017 16:00", ) .. GENERATED FROM PYTHON SOURCE LINES 57-58 For sanity, lets plot these segments: .. GENERATED FROM PYTHON SOURCE LINES 58-66 .. code-block:: Python splot = l1segs.plot( figsize=[12, 3], epoch="August 17 2017", ) splot.show() splot.close() # hide .. GENERATED FROM PYTHON SOURCE LINES 67-69 We see that the LIGO Hanford Observatory detector was operating for the majority of the day, with a few outages of ~30 minutes or so. .. GENERATED FROM PYTHON SOURCE LINES 71-73 We can use the :func:`abs` function to display the total amount of time spent taking data: .. GENERATED FROM PYTHON SOURCE LINES 73-76 .. code-block:: Python print(abs(l1segs.active)) .. rst-class:: sphx-glr-script-out .. code-block:: none 25796 .. GENERATED FROM PYTHON SOURCE LINES 77-85 .. currentmodule:: gwpy.timeseries Working with strain data ------------------------ Now, we can loop through the active segments of ``'L1_DATA'`` and fetch the strain `TimeSeries` for each segment, calculating a :class:`~gwpy.spectrogram.Spectrogram` for each segment. .. GENERATED FROM PYTHON SOURCE LINES 85-98 .. code-block:: Python from gwpy.timeseries import TimeSeries spectrograms = [] for start, end in l1segs.active: l1strain = TimeSeries.fetch_open_data( "L1", start, end, verbose=True, ) specgram = l1strain.spectrogram(30, fftlength=4) ** (1/2.) spectrograms.append(specgram) .. rst-class:: sphx-glr-script-out .. code-block:: none Fetched 4 URLs from gwosc.org for [1186992018 .. 1187001382)) Reading data... [Done] Reading data... [Done] Reading data... [Done] Reading data... [Done] Fetched 1 URLs from gwosc.org for [1187004231 .. 1187004416)) Reading data... [Done] Fetched 5 URLs from gwosc.org for [1187004571 .. 1187020818)) Reading data... [Done] Reading data... [Done] Reading data... [Done] Reading data... [Done] Reading data... [Done] .. GENERATED FROM PYTHON SOURCE LINES 99-100 Finally, we can build a :meth:`~gwpy.spectrogram.Spectrogram.plot`: .. GENERATED FROM PYTHON SOURCE LINES 100-123 .. code-block:: Python # Create an empty plot with a single set of Axes from gwpy.plot import Plot plot = Plot(figsize=(12, 6)) ax = plot.gca() # add each spectrogram to the Axes for specgram in spectrograms: ax.imshow(specgram) # finalise the plot metadata ax.set_xscale("auto-gps", epoch="Aug 17 2017") ax.set_ylim(20, 2000) ax.set_yscale("log") ax.set_ylabel("Frequency [Hz]") ax.set_title("LIGO-Livingston strain data") ax.colorbar( cmap="viridis", norm="log", clim=(5e-24, 1e-21), label=r"Strain noise [1/$\sqrt{\mathrm{Hz}}$]", ) # add the segments as a 'state' indicator along the bottom plot.add_segments_bar(l1segs) plot.show() .. image-sg:: /examples/miscellaneous/images/sphx_glr_open-data-spectrogram_001.png :alt: LIGO-Livingston strain data :srcset: /examples/miscellaneous/images/sphx_glr_open-data-spectrogram_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 12.267 seconds) .. _sphx_glr_download_examples_miscellaneous_open-data-spectrogram.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: open-data-spectrogram.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: open-data-spectrogram.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: open-data-spectrogram.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_