Adds peek() function for GenericSpectrogram#188
Adds peek() function for GenericSpectrogram#188MohamedAli1937 wants to merge 5 commits intosunpy:mainfrom
peek() function for GenericSpectrogram#188Conversation
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.
samaloney
left a comment
There was a problem hiding this comment.
Looks ok, should add some narrative style documentation to the root https://github.com/sunpy/radiospectra/blob/main/docs/code_ref/spectrogram.rst describing, showing this.
| f" {self.start_time.isot} to {self.end_time.isot}>" | ||
| ) | ||
|
|
||
| def peek(self, **kwargs): |
There was a problem hiding this comment.
should probably use @peek_show like in sunpy so the figure isn't returned to have a similar API
| import matplotlib.pyplot as plt | ||
|
|
||
| figure = plt.figure() | ||
| axes = figure.add_subplot(111) |
There was a problem hiding this comment.
Don't think this is needed
| axes = figure.add_subplot(111) | |
| axes = figure.add_subplot() |
| figure = plt.figure() | ||
| axes = figure.add_subplot(111) | ||
| ret = self.plot(axes=axes, **kwargs) | ||
| figure.colorbar(ret) |
There was a problem hiding this comment.
This should probably be an option in the method e.g. show_coloarbar=True
|
Hi @samaloney, could you please take a look? My local tests pass with Python 3.14/SunPy 7.1, but I'm hitting 'Unknown problems' on the CI/RTD builds. I suspect a version compatibility issue with the decorator or a documentation timeout. Thanks! |
PR Description
Fixes #185
Summary:
This PR adds a
peek()method to theGenericSpectrogrambase class to provide quick-look plotting functionality, aligning the object with the design philosophy and API conventions already established bysunpy.map.Map.peek()andradiospectra.spectrum.Spectrum.peek().Motivation and Context:
Currently, taking a "quick look" at a
GenericSpectrogramwith a colorbar requires users to write roughly 5 lines of boilerplate code: manually importing matplotlib, setting up a figure and subplot, calling the underlying.plot()method, and manually passing the returnedQuadMeshto afig.colorbar(ret)call.Providing a built-in
peek()method reduces this to a singlespec.peek()call, enabling users to immediately view their spectral data with sensible visualization defaults (like automatic colorbars and labels) upon instantiation.Changes:
peek(self, **kwargs)toGenericSpectrograminspectrogrambase.py.self.plot(**kwargs)(inherited fromPcolormeshPlotMixin), catching the returnedQuadMeshand automatically mapping it to aFigure.colorbar(). All extra**kwargsare cleanly passed down into thepcolormeshlogic.AI Assistance Disclosure
AI tools were used for: