Skip to content
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

Implement the AIASynopticClient #7842

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ef8ed3f
hotfix the quantity comparison for wavelengths
GillySpace27 Oct 18, 2024
4fddb3c
update the __init__ files in dataretriever and sources
GillySpace27 Oct 18, 2024
43088b4
init AIASynopticClient in Sources
GillySpace27 Oct 18, 2024
2504767
add standard test file
GillySpace27 Oct 18, 2024
9095859
temporarily include bespoke test files
GillySpace27 Oct 18, 2024
d74cb27
tweak examples
GillySpace27 Oct 18, 2024
578b0f0
clean up synoptic client
GillySpace27 Oct 18, 2024
2548761
move import to top of file
GillySpace27 Oct 18, 2024
c801575
iteration savepoint
GillySpace27 Oct 21, 2024
3398c47
fix wavelength selection
GillySpace27 Oct 21, 2024
54ba715
first fix of sample
GillySpace27 Oct 21, 2024
247517a
simplify the manual test case
GillySpace27 Oct 22, 2024
8441345
extensively refactor the main client
GillySpace27 Oct 22, 2024
2bf7ade
clean notebook example
GillySpace27 Oct 22, 2024
20c5216
Delete manual testing scripts
GillySpace27 Oct 23, 2024
740e5d9
Dump sources/__init__.py content
GillySpace27 Oct 23, 2024
5c8c925
update required vs supported attrs
GillySpace27 Oct 23, 2024
dae0c15
Update sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py
GillySpace27 Oct 24, 2024
a83a5a3
Update sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py
GillySpace27 Oct 24, 2024
06f0873
Merge branch 'main' into AIASynopticSecondTry
GillySpace27 Nov 28, 2024
8859017
idk
GillySpace27 Jan 13, 2025
faccbf3
Merge branch 'AIASynopticSecondTry' of https://github.com/GillySpace2…
GillySpace27 Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py
Co-authored-by: Nabil Freij <[email protected]>
  • Loading branch information
GillySpace27 and nabobalis authored Oct 24, 2024
commit a83a5a364e0e807b242082bad94a5f725866f11c
14 changes: 0 additions & 14 deletions sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@
import astropy.units as u

import sunpy.net.dataretriever.sources.aia_synoptic as aia_synoptic
from sunpy.net import attrs as a
from sunpy.net.dataretriever.client import QueryResponse
from sunpy.net.tests.strategies import time_attr
from sunpy.time import TimeRange, parse_time

Check warning on line 12 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L9-L12

Added lines #L9 - L12 were not covered by tests


@pytest.fixture
def aia_synoptic_client():

Check warning on line 16 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L15-L16

Added lines #L15 - L16 were not covered by tests
"""Fixture to provide an instance of AIASynopticClient."""
return aia_synoptic.AIASynopticClient()

Check warning on line 18 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L18

Added line #L18 was not covered by tests


@given(time_attr())
def test_can_handle_query(aia_synoptic_client, time):

Check warning on line 22 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L21-L22

Added lines #L21 - L22 were not covered by tests
"""
Test if the AIASynopticClient can handle specific queries.
"""

# Test with synoptic data
assert aia_synoptic_client._can_handle_query(time, a.Instrument.aia, aia_synoptic.AIASynopticData())

Check warning on line 28 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L28

Added line #L28 was not covered by tests

# If AIASynopticData is present, ignore resolution mismatch
assert aia_synoptic_client._can_handle_query(

Check warning on line 31 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L31

Added line #L31 was not covered by tests
time, a.Instrument.aia, a.Resolution(4.0), aia_synoptic.AIASynopticData()
)

# Test normal query without synoptic data
assert aia_synoptic_client._can_handle_query(time, a.Instrument.aia)
assert aia_synoptic_client._can_handle_query(time, a.Instrument.aia, a.Resolution(4.0))
assert not aia_synoptic_client._can_handle_query(time)

Check warning on line 38 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L36-L38

Added lines #L36 - L38 were not covered by tests


def mock_query_object(

Check warning on line 41 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L41

Added line #L41 was not covered by tests
aia_synoptic_client, start_time="2020-01-01T00:00:00.00", end_time="2020-01-01T23:59:59.999"
):
"""
Expand All @@ -52,7 +52,7 @@
Returns:
QueryResponse: A mocked query response object.
"""
obj = {

Check warning on line 55 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L55

Added line #L55 was not covered by tests
"Start Time": parse_time(start_time),
"End Time": parse_time(end_time),
"Instrument": "AIASynoptic",
Expand All @@ -62,11 +62,11 @@
"Wavelength": "0171",
"url": (r"https://jsoc1.stanford.edu/data/aia/synoptic/2023/10/11/H0000/AIA20231011_0000_0193.fits"),
}
return QueryResponse([obj], client=aia_synoptic_client)

Check warning on line 65 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L65

Added line #L65 was not covered by tests


@pytest.mark.remote_data
def test_fetch_working(aia_synoptic_client, tmp_path):

Check warning on line 69 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L68-L69

Added lines #L68 - L69 were not covered by tests
"""
Tests that data is fetched correctly.

Expand All @@ -74,33 +74,33 @@
aia_synoptic_client (AIASynopticClient): Fixture client instance.
tmp_path: Pytest fixture for creating temporary directories.
"""
response = mock_query_object(aia_synoptic_client)
download_dir = tmp_path / "downloads"

Check warning on line 78 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L77-L78

Added lines #L77 - L78 were not covered by tests

# Ensure the directory is empty before downloading
assert len(list(download_dir.glob("*"))) == 0

Check warning on line 81 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L81

Added line #L81 was not covered by tests

files = aia_synoptic_client.fetch(response, path=str(download_dir))

Check warning on line 83 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L83

Added line #L83 was not covered by tests

# Ensure exactly one file was downloaded
assert len(files) == 1
assert files[0].endswith(".fits")

Check warning on line 87 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L86-L87

Added lines #L86 - L87 were not covered by tests

# Ensure the file is correctly downloaded
downloaded_file = download_dir / os.path.basename(files[0])
assert downloaded_file.exists()
assert downloaded_file.stat().st_size > 0 # Check if file size is greater than 0

Check warning on line 92 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L90-L92

Added lines #L90 - L92 were not covered by tests


def test_basic_query(aia_synoptic_client):

Check warning on line 95 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L95

Added line #L95 was not covered by tests
"""
Basic test to perform a search query for synoptic data.
"""
# Define a time range for the query
time_range = TimeRange("2020-01-01", "2020-01-02")

Check warning on line 100 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L100

Added line #L100 was not covered by tests

# Perform a search query
query_result = aia_synoptic_client.search(

Check warning on line 103 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L103

Added line #L103 was not covered by tests
a.Time(time_range.start, time_range.end),
a.Wavelength(171 * u.angstrom),
a.Sample(12 * u.hour),
Expand All @@ -109,20 +109,6 @@
)

# Output the results
assert query_result is not None

Check warning on line 112 in sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py

View check run for this annotation

Codecov / codecov/patch

sunpy/net/dataretriever/sources/tests/test_aia_synoptic.py#L112

Added line #L112 was not covered by tests


if __name__ == "__main__":
from sunpy.net.dataretriever.sources.aia_synoptic import AIASynopticClient
from sunpy.net import attrs

start_time = "2020-01-01T00:00:00.00"
end_time = "2020-01-01T23:59:59.999"

Client = AIASynopticClient()
search_request = Client.search(
attrs.Time(start_time, end_time), attrs.Sample(1 * u.hour), attrs.Wavelength(193 * u.angstrom)
)
request = Client.fetch(search_request)
print(search_request)
print(request)
Loading