Skip to content

Add setter for times attribute to support light travel time corrections#140

Open
Amityush-lgtm wants to merge 2 commits intosunpy:mainfrom
Amityush-lgtm:add-settable-times-attribute
Open

Add setter for times attribute to support light travel time corrections#140
Amityush-lgtm wants to merge 2 commits intosunpy:mainfrom
Amityush-lgtm:add-settable-times-attribute

Conversation

@Amityush-lgtm
Copy link

@Amityush-lgtm Amityush-lgtm commented Feb 9, 2026

PR Description

Adds a setter for the times property in GenericSpectrogram to enable users to update time coordinates. This allows for light travel time corrections when comparing data from multiple spacecraft at different distances (e.g., Solar Orbiter RPW and Parker Solar Probe).
Closes #77

What changed

  • Added a times setter in radiospectra/spectrogram/spectrogrambase.py

    • Accepts astropy.time.Time
    • Also accepts time-like astropy.units.Quantity (e.g., 500 * u.s) and applies it as an offset to the existing Time array
    • Validates length matches the current time axis
    • Validates inputs are time-compatible
    • Updates meta["start_time"] / meta["end_time"] to stay consistent with the updated axis
  • Added unit tests in radiospectra/tests/test_spectrogrambase.py covering:

    • setting Time directly
    • applying a Quantity offset
    • metadata updates
    • error cases (wrong length, invalid type, incompatible units)

Example

Before:

spec.times = spec.times + 500*u.s  # AttributeError

After:

import astropy.units as u
spec.times = spec.times + 500*u.s 
# Metadata automatically updated

@samaloney @hayesla

@Amityush-lgtm Amityush-lgtm force-pushed the add-settable-times-attribute branch from 9214d59 to ecfd4aa Compare February 9, 2026 10:14
@Amityush-lgtm
Copy link
Author

Hi @samaloney,

I’ve updated the PR to address the initial CI failures (renamed the changelog to #140 and fixed the linting issues).

The remaining CI failures in radiospectra.net.sources.tests appear to be pre-existing and unrelated to this PR. I confirmed this by running the test suite on a clean checkout of upstream/main and seeing the same failures.

These failures seem to be due to recent breaking changes in sunpy 7.1.0’s Scraper class that the radiospectra network clients haven’t accounted for yet. The changes in spectrogrambase.py and the new tests added in this PR are passing as expected.

Let me know if you’d like me to open a separate issue for the SunPy compatibility problem or if there’s anything else you’d like me to adjust here.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to set time attribute

1 participant