Skip to content

Add sunpy timerange support#360

Merged
nabobalis merged 2 commits intomainfrom
timerange
Sep 13, 2025
Merged

Add sunpy timerange support#360
nabobalis merged 2 commits intomainfrom
timerange

Conversation

@nabobalis
Copy link
Member

@nabobalis nabobalis commented Sep 13, 2025

Fixes #359

Summary by Sourcery

Add support for sunpy.time.TimeRange objects in get_pointing_table and update tests accordingly

New Features:

  • Allow get_pointing_table to accept sunpy.time.TimeRange in addition to astropy Time

Tests:

  • Add test for retrieving pointing table using a TimeRange

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 13, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR extends get_pointing_table to accept sunpy TimeRange objects by adding type checks and proper start/end extraction, updates the docstring accordingly, and adds a test to verify the new functionality.

Sequence diagram for get_pointing_table time_range parameter handling

sequenceDiagram
participant Caller
participant get_pointing_table
Caller->>get_pointing_table: call with time_range
alt time_range is Time
    get_pointing_table->>get_pointing_table: extract start, end from Time
else time_range is TimeRange
    get_pointing_table->>get_pointing_table: extract start, end from TimeRange
else invalid type
    get_pointing_table->>get_pointing_table: raise TypeError
end
Loading

Class diagram for updated get_pointing_table function parameter handling

classDiagram
class get_pointing_table {
    +get_pointing_table(source: str, time_range: Time | TimeRange | tuple)
}
class Time {
    +start
    +end
}
class TimeRange {
    +start
    +end
}
get_pointing_table --> Time : accepts
get_pointing_table --> TimeRange : accepts
Loading

File-Level Changes

Change Details Files
Add support for sunpy.time.TimeRange inputs in get_pointing_table
  • Check if time_range is TimeRange and extract start/end
  • Retain support for Time objects by indexing
  • Raise TypeError for unsupported types
aiapy/calibrate/util.py
Update docstring to document new TimeRange support
  • Include TimeRange in time_range parameter description
aiapy/calibrate/util.py
Add test for TimeRange support
  • Introduce pytest remote_data test using TimeRange
  • Assert QTable type and correct start/stop bounds
aiapy/calibrate/tests/test_util.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `aiapy/calibrate/util.py:238` </location>
<code_context>
             msg = "time_range must be provided if the source is 'jsoc'"
             raise ValueError(msg)
-        start, end = time_range
+        if isinstance(time_range, Time):
+            start, end = time_range[0], time_range[-1]
+        elif isinstance(time_range, TimeRange):
+            start, end = time_range.start, time_range.end
</code_context>

<issue_to_address>
Indexing into Time objects may not always yield expected start/end times.

If time_range contains more than two elements, [0] and [-1] may not represent the correct start and end. Please ensure time_range is always two elements, or update the logic to handle cases with more.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        if isinstance(time_range, Time):
            start, end = time_range[0], time_range[-1]
        elif isinstance(time_range, TimeRange):
            start, end = time_range.start, time_range.end
=======
        if isinstance(time_range, Time):
            if len(time_range) != 2:
                msg = (
                    "If time_range is a Time object, it must contain exactly two elements "
                    "representing the start and end times."
                )
                raise ValueError(msg)
            start, end = time_range[0], time_range[1]
        elif isinstance(time_range, TimeRange):
            start, end = time_range.start, time_range.end
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `aiapy/calibrate/tests/test_util.py:122` </location>
<code_context>


+@pytest.mark.remote_data
+def test_get_pointing_table_timerange() -> None:
+    t = Time("2021-01-01T00:00:00", scale="utc")
+    table = get_pointing_table("jsoc", time_range=TimeRange(t - 3 * u.h, t + 3 * u.h))
+    assert isinstance(table, QTable)
+    assert table["T_START"].min() == Time("2020-12-31T21:00:00", scale="utc")
+    assert table["T_STOP"].max() == Time("2021-01-01T09:00:00", scale="utc")
+
+
</code_context>

<issue_to_address>
Missing test for invalid TimeRange input types.

Add a test that passes an invalid type to time_range to verify the TypeError is raised as intended.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@nabobalis nabobalis force-pushed the timerange branch 2 times, most recently from daa4119 to 505fd0e Compare September 13, 2025 21:27
@wtbarnes
Copy link
Contributor

Holy copilot

@nabobalis
Copy link
Member Author

Its the future, might as well embrace it.

@nabobalis
Copy link
Member Author

Less code now.

@nabobalis nabobalis merged commit c0c09a9 into main Sep 13, 2025
18 of 20 checks passed
@nabobalis nabobalis deleted the timerange branch September 13, 2025 22:18
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.

Accept sunpy.time.TimeRange objects as input to get_pointing_table

2 participants