From 2bf7b1d2975484d06337298e314c67f0a798b344 Mon Sep 17 00:00:00 2001 From: MohamedAli1937 Date: Thu, 26 Mar 2026 23:15:03 +0100 Subject: [PATCH 1/5] Add peek() to GenericSpectrogram Adds a peek function with sensible defaults and a colorbar, similar to the API provided by sunpy.map.Map and the 1D Spectrum class, facilitating quick-look visualization. --- changelog/peek.feature.rst | 2 ++ radiospectra/spectrogram/spectrogrambase.py | 23 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 changelog/peek.feature.rst diff --git a/changelog/peek.feature.rst b/changelog/peek.feature.rst new file mode 100644 index 00000000..07c233f8 --- /dev/null +++ b/changelog/peek.feature.rst @@ -0,0 +1,2 @@ +Add a ``peek()`` method to ``GenericSpectrogram``, which gives it a quick-look plotting functionality +similar to ``sunpy.map.Map.peek()`` and ``radiospectra.spectrum.Spectrum.peek()``. diff --git a/radiospectra/spectrogram/spectrogrambase.py b/radiospectra/spectrogram/spectrogrambase.py index f1cb2b3f..ae916747 100644 --- a/radiospectra/spectrogram/spectrogrambase.py +++ b/radiospectra/spectrogram/spectrogrambase.py @@ -107,3 +107,26 @@ def __repr__(self): f" {self.wavelength.min} - {self.wavelength.max}," f" {self.start_time.isot} to {self.end_time.isot}>" ) + + def peek(self, **kwargs): + """ + Displays a quick-look plot of the Spectrogram with a colorbar. + + Parameters + ---------- + **kwargs : `dict` + Any additional keyword arguments are passed to `~radiospectra.spectrogram.GenericSpectrogram.plot`. + + Returns + ------- + `matplotlib.figure.Figure` + The figure object containing the plot. + """ + import matplotlib.pyplot as plt + + figure = plt.figure() + axes = figure.add_subplot(111) + ret = self.plot(axes=axes, **kwargs) + figure.colorbar(ret) + figure.show() + return figure From 153718a6d1b21a9b893d1f7ab3e43a2f3ed1c61d Mon Sep 17 00:00:00 2001 From: MohamedAli1937 Date: Fri, 27 Mar 2026 09:36:09 +0100 Subject: [PATCH 2/5] Add changelog for feature #188 --- changelog/188.feature.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog/188.feature.rst diff --git a/changelog/188.feature.rst b/changelog/188.feature.rst new file mode 100644 index 00000000..07c233f8 --- /dev/null +++ b/changelog/188.feature.rst @@ -0,0 +1,2 @@ +Add a ``peek()`` method to ``GenericSpectrogram``, which gives it a quick-look plotting functionality +similar to ``sunpy.map.Map.peek()`` and ``radiospectra.spectrum.Spectrum.peek()``. From 3215b57db0fea0bfd6271aafcda5c46028203f87 Mon Sep 17 00:00:00 2001 From: MohamedAli1937 Date: Fri, 27 Mar 2026 09:37:05 +0100 Subject: [PATCH 3/5] Remove changelog entry for peek feature --- changelog/peek.feature.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 changelog/peek.feature.rst diff --git a/changelog/peek.feature.rst b/changelog/peek.feature.rst deleted file mode 100644 index 07c233f8..00000000 --- a/changelog/peek.feature.rst +++ /dev/null @@ -1,2 +0,0 @@ -Add a ``peek()`` method to ``GenericSpectrogram``, which gives it a quick-look plotting functionality -similar to ``sunpy.map.Map.peek()`` and ``radiospectra.spectrum.Spectrum.peek()``. From 1275f6ecbc992d697f96fdc25efd1e0c2f8d4440 Mon Sep 17 00:00:00 2001 From: MohamedAli1937 Date: Fri, 27 Mar 2026 12:04:17 +0100 Subject: [PATCH 4/5] Update spectrogram docs and improve peek implementation --- docs/code_ref/spectrogram.rst | 24 +++++++++++++++++++++ radiospectra/spectrogram/spectrogrambase.py | 21 +++++++++--------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/docs/code_ref/spectrogram.rst b/docs/code_ref/spectrogram.rst index cd288d25..e7575b1d 100644 --- a/docs/code_ref/spectrogram.rst +++ b/docs/code_ref/spectrogram.rst @@ -1,4 +1,28 @@ `radiospectra.spectrogram` ========================== +The `radiospectra.spectrogram` module provides classes and utilities for working with dynamic solar radio spectrograms. + +Visualizing Spectrograms +------------------------ + +All spectrogram objects in ``radiospectra`` inherit from :class:`~radiospectra.spectrogram.GenericSpectrogram`, which provides a :meth:`~radiospectra.spectrogram.GenericSpectrogram.peek` method for quick-look visualization. + +The ``peek()`` method creates a new figure and plots the spectrogram with sensible defaults, including an optional colorbar. + +.. plot:: + :include-source: + + from radiospectra.spectrogram import Spectrogram + import radiospectra.net + from sunpy.net import Fido, attrs as a + + # Search and download data + query = Fido.search(a.Time('2021/05/07 00:00', '2021/05/07 01:00'), a.Instrument.eovsa) + files = Fido.fetch(query) + + # Create spectrogram and peek + spec = Spectrogram(files[0]) + spec.peek() + .. automodapi:: radiospectra.spectrogram diff --git a/radiospectra/spectrogram/spectrogrambase.py b/radiospectra/spectrogram/spectrogrambase.py index ae916747..2fbab9bf 100644 --- a/radiospectra/spectrogram/spectrogrambase.py +++ b/radiospectra/spectrogram/spectrogrambase.py @@ -1,3 +1,5 @@ +from sunpy.visualization import peek_show + from radiospectra.exceptions import SpectraMetaValidationError from radiospectra.mixins import NonUniformImagePlotMixin, PcolormeshPlotMixin @@ -108,25 +110,22 @@ def __repr__(self): f" {self.start_time.isot} to {self.end_time.isot}>" ) - def peek(self, **kwargs): + @peek_show + def peek(self, show_colorbar=True, **kwargs): """ - Displays a quick-look plot of the Spectrogram with a colorbar. + Displays a quick-look plot of the Spectrogram. Parameters ---------- + show_colorbar : `bool`, optional + Whether to show a colorbar. Defaults to `True`. **kwargs : `dict` Any additional keyword arguments are passed to `~radiospectra.spectrogram.GenericSpectrogram.plot`. - - Returns - ------- - `matplotlib.figure.Figure` - The figure object containing the plot. """ import matplotlib.pyplot as plt figure = plt.figure() - axes = figure.add_subplot(111) + axes = figure.add_subplot() ret = self.plot(axes=axes, **kwargs) - figure.colorbar(ret) - figure.show() - return figure + if show_colorbar: + figure.colorbar(ret) From 4166f74acda3ea8f7b21952a07c2a4b6e7243efa Mon Sep 17 00:00:00 2001 From: MohamedAli1937 Date: Fri, 27 Mar 2026 12:16:39 +0100 Subject: [PATCH 5/5] docs: use mock data in plot directive to fix build timeout --- docs/code_ref/spectrogram.rst | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/docs/code_ref/spectrogram.rst b/docs/code_ref/spectrogram.rst index e7575b1d..b3b56ff5 100644 --- a/docs/code_ref/spectrogram.rst +++ b/docs/code_ref/spectrogram.rst @@ -13,16 +13,30 @@ The ``peek()`` method creates a new figure and plots the spectrogram with sensib .. plot:: :include-source: - from radiospectra.spectrogram import Spectrogram - import radiospectra.net - from sunpy.net import Fido, attrs as a - - # Search and download data - query = Fido.search(a.Time('2021/05/07 00:00', '2021/05/07 01:00'), a.Instrument.eovsa) - files = Fido.fetch(query) - - # Create spectrogram and peek - spec = Spectrogram(files[0]) + import numpy as np + import astropy.units as u + from astropy.time import Time + from radiospectra.spectrogram import GenericSpectrogram + + # Create artificial spectrogram data + times = Time("2021-01-01T00:00:00") + np.arange(100) * u.min + freqs = np.linspace(10, 100, 50) * u.MHz + data = np.random.rand(50, 100) + + # Define minimal metadata + meta = { + "observatory": "Example Data", + "instrument": "Mock Instrument", + "detector": "Mock Detector", + "start_time": times[0], + "end_time": times[-1], + "wavelength": u.Quantity([1, 10], unit=u.m), + "times": times, + "freqs": freqs, + } + + # Instantiate and peek + spec = GenericSpectrogram(data, meta) spec.peek() .. automodapi:: radiospectra.spectrogram