-
-
Notifications
You must be signed in to change notification settings - Fork 38
Fix #110: Ensure spectrogram plotting correctly handles non-UTC time scales #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
517e6d9
Fix: ensure time scale is converted to UTC before plotting
704a878
Test: add verification for non-UTC time scale plotting
a1d1b65
Changelog: add 144.bugfix.rst
5a18b2e
Fix #110: Update spectrogram plotting to support non-UTC time scales …
9e0203d
Fix CI py312-oldestdeps: Ignore pyparsing PyparsingDeprecationWarning…
3f5bd90
Move time_support import to module level
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed an issue where plotting spectrograms with non-UTC time scales (e.g., 'tt') would result in time offsets by ensuring conversion to UTC before plotting. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import matplotlib | ||
|
|
||
| matplotlib.use("Agg") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from unittest import mock | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
|
|
||
| import astropy.units as u | ||
| from astropy.time import Time | ||
|
|
||
| from radiospectra.spectrogram.spectrogrambase import GenericSpectrogram | ||
|
|
||
|
|
||
| def _get_spectrogram_with_time_scale(scale): | ||
| times = Time("2020-01-01T00:00:00", format="isot", scale=scale) + np.arange(4) * u.min | ||
| frequencies = np.linspace(10, 40, 4) * u.MHz | ||
| meta = { | ||
| "observatory": "Test", | ||
| "instrument": "TestInst", | ||
| "detector": "TestDet", | ||
| "start_time": times[0], | ||
| "end_time": times[-1], | ||
| "wavelength": np.array([1, 10]) * u.m, | ||
| "times": times, | ||
| "freqs": frequencies, | ||
| } | ||
| return GenericSpectrogram(np.arange(16).reshape(4, 4), meta) | ||
|
|
||
|
|
||
| def test_plot_uses_time_support_for_datetime_conversion(): | ||
| spec = _get_spectrogram_with_time_scale("tt") | ||
|
|
||
| mesh = spec.plot() | ||
| x_limits = np.array(mesh.axes.get_xlim()) | ||
| expected_tt_limits = mesh.axes.convert_xunits(spec.times[[0, -1]]) | ||
|
|
||
| plt.close(mesh.axes.figure) | ||
|
|
||
| np.testing.assert_allclose(x_limits, expected_tt_limits) | ||
|
|
||
|
|
||
| def test_plotim_uses_time_support_for_datetime_conversion(): | ||
| spec = _get_spectrogram_with_time_scale("tt") | ||
| fig, axes = plt.subplots() | ||
|
|
||
| with ( | ||
| mock.patch("matplotlib.image.NonUniformImage.set_interpolation", autospec=True), | ||
| mock.patch("matplotlib.image.NonUniformImage.set_data", autospec=True) as set_data, | ||
| ): | ||
| spec.plotim(fig=fig, axes=axes) | ||
|
|
||
| plt.close(fig) | ||
|
|
||
| _, x_values, y_values, image = set_data.call_args.args | ||
| expected_tt = axes.convert_xunits(spec.times) | ||
|
|
||
| np.testing.assert_allclose(x_values, expected_tt) | ||
| np.testing.assert_allclose(y_values, spec.frequencies.value) | ||
| np.testing.assert_allclose(image, spec.data) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.