.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/spectrogram/spectrogram2.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_spectrogram2.py: .. sectionauthor:: Duncan Macleod .. currentmodule:: gwpy.timeseries Plotting an over-dense, short-duration `Spectrogram` #################################################### The normal `~TimeSeries.spectrogram` method uses non-overlapping intervals to calculate discrete PSDs for each stride. This is fine for long-duration data, but give poor resolution when studying short-duration phenomena. The `~TimeSeries.spectrogram2` method allows for highly-overlapping FFT calculations to over-sample the frequency content of the input `TimeSeries` to produce a much more feature-rich output. .. GENERATED FROM PYTHON SOURCE LINES 36-38 To demonstrate this, we can download some data associated with the gravitational-wave event GW510914: .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: Python from gwpy.timeseries import TimeSeries lho = TimeSeries.fetch_open_data("H1", 1126259458, 1126259467) .. GENERATED FROM PYTHON SOURCE LINES 43-46 and can :meth:`~TimeSeries.highpass` and :meth:`~TimeSeries.whiten` the remove low-frequency noise and try and enhance low-amplitude signals across the middle of the frequency band: .. GENERATED FROM PYTHON SOURCE LINES 46-50 .. code-block:: Python hp = lho.highpass(20) white = hp.whiten(4, 2).crop(1126259460, 1126259465) .. GENERATED FROM PYTHON SOURCE LINES 51-60 .. note:: We chose to :meth:`~TimeSeries.crop` out the leading and trailing 2 seconds of the the whitened data series here to remove any filtering artefacts that may have been introduced. Now we can call the `~TimeSeries.spectrogram2` method of `gwdata` to calculate our over-dense `~gwpy.spectrogram.Spectrogram`, using a 1/16-second FFT length and high overlap: .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python specgram = white.spectrogram2(fftlength=1/16., overlap=15/256.) ** (1/2.) specgram = specgram.crop_frequencies(20) # drop everything below highpass .. GENERATED FROM PYTHON SOURCE LINES 65-66 Finally, we make a plot: .. GENERATED FROM PYTHON SOURCE LINES 66-74 .. code-block:: Python plot = specgram.plot(norm="log", cmap="viridis", yscale="log") ax = plot.gca() ax.set_title("LIGO-Hanford strain data around GW150914") ax.set_xlim(1126259462, 1126259463) ax.colorbar(label=r"Strain ASD [1/$\sqrt{\mathrm{Hz}}$]") plot.show() .. image-sg:: /examples/spectrogram/images/sphx_glr_spectrogram2_001.png :alt: LIGO-Hanford strain data around GW150914 :srcset: /examples/spectrogram/images/sphx_glr_spectrogram2_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 75-80 Here we can see the trace of a high-mass binary black hole system, referred to as GW150914. For more details on this signal, please see `Abbott et al. (2016) `_ (the joint LSC-Virgo publication announcing this detection). .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.627 seconds) .. _sphx_glr_download_examples_spectrogram_spectrogram2.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: spectrogram2.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: spectrogram2.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: spectrogram2.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_