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

ADAPT Client #7463

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

ADAPT Client #7463

wants to merge 15 commits into from

Conversation

GillySpace27
Copy link

PR Description

Adds functionality to download ADAPT maps using FIDO.
This addresses the following issue: #7152

I believe that the core of this code works but I cant get a dev environment running to test things. I believe I'll have to do more work putting the right parts in the right places for sunpy, but I wanted to get this started by uploading what I have.

Copy link
Author

@GillySpace27 GillySpace27 left a comment

Choose a reason for hiding this comment

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

Ok, I think that the client works now, though there may be some code linting that could be helpful.

Copy link
Contributor

@nabobalis nabobalis left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @GillySpace27!

I hope it was ok for me to look over this while it was in draft.

setup.cfg Outdated Show resolved Hide resolved
sunpy/net/__init__.py Outdated Show resolved Hide resolved
sunpy/net/dataretriever/attrs/__init__.py Outdated Show resolved Hide resolved
sunpy/net/dataretriever/attrs/adapt.py Outdated Show resolved Hide resolved
sunpy/net/dataretriever/attrs/adapt.py Outdated Show resolved Hide resolved
sunpy/net/dataretriever/sources/adapt.py Outdated Show resolved Hide resolved
sunpy/net/dataretriever/sources/adapt.py Show resolved Hide resolved
sunpy/net/dataretriever/sources/adapt.py Outdated Show resolved Hide resolved
sunpy/net/dataretriever/sources/adapt.py Outdated Show resolved Hide resolved
sunpy/net/dataretriever/sources/adapt.py Outdated Show resolved Hide resolved
Copy link
Author

@GillySpace27 GillySpace27 left a comment

Choose a reason for hiding this comment

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

I think I did everything except for the test parts, which I'm not experienced with. Please feel free to give this another once-over.

@nabobalis
Copy link
Contributor

Hi @GillySpace27, sorry for not getting back to you sooner, I will go over this soon but I have two suggestions:

  1. Can you add back "sunpy/net/dataretriever/sources/init.py", I think that has to be there.

  2. For the tests, you can avoid having to write the tests from scratch by just copying the file from say one of the goes test files, update the client to use adapt and then tweak the calls to the client with the correct attrs. That should reduce the burden on you and would cover most of the tests we would need for a new client.

sunpy/net/dataretriever/sources/adapt.py Outdated Show resolved Hide resolved
sunpy/net/dataretriever/sources/adapt.py Outdated Show resolved Hide resolved
Comment on lines +80 to +94
def carrington_time(CR=2193, frames=1):
"""Get the start date for the start of a carrington rotation,
and a duration that will retrieve a given number of frames

Returns:
_type_: _description_
"""
date = sunpy.coordinates.sun.carrington_rotation_time(CR)
date_end = date + frames*(3*1.9999999 * u.hour)

# Format the Search Dates
tstring = r"%Y-%m-%dT%H:%M:%S"
get_date =date.strftime(tstring)
get_date_end=date_end.strftime(tstring)
return get_date, get_date_end
Copy link
Contributor

Choose a reason for hiding this comment

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

This I think should be moved elsewhere, maybe to sunpy.time?

This also overlaps with https://docs.sunpy.org/en/stable/generated/api/sunpy.coordinates.sun.carrington_rotation_time.html

I need input from the others for the best solution.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, this is just a super basic wrapper around that carrington_rotation_time function, I'm glad to put it wherever (I suspect using the strftime is probably not necessary either since it is a Quantity)

Copy link
Member

Choose a reason for hiding this comment

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

There are people better qualified to answer this than me but...

There are some issues with the implementation here but I think we can look past that to a more general view on what it is trying to do:

So I assume you have this here because you think it will be useful to search via Carrington rotation rather than via a Timerange. As this stands I don't see this adding anything other than what exists on the function you have wrapped.

What I mean is that other than working out how much the end time should differ from the start time to get n results, a user can already convert a 2 CR numbers to times and then insert those into the attrs. Indeed if the user wants n results they can just select the first n rows from the query response before calling Fetch. I also don't think it fits with the other clients where we have a unique helper function in a dataretrieverclient file that has to be called independently before calling a query.

Now what would be cool....

If searching by CR is desired then we could add a CarringtonRotation attr and have the can handle function check for either a.Time or a.CR and then, I don't know exactly where, but either in a pre_search_hook on the generic client or via attrwalker add_converter then we could optionally take either a CR number or a a.Time range to carry out an ADAPT search.

Now what form that new attr should take, I don't know. Your current API is start + number of observations but start+end makes a lot more sense rather than having an attr be composed of 2 different typed values. Is there a particular reason for your choices?

This would be much more teachable via an example than I think preconverrting the CR into times manually.

I wouldn't mind that being a separate follow on PR, as it isn't necessary for the client to operate, but I am not super keen on this function as it stands. I will bow down to those with greater knowledge though (and if so then we need to work on the implementation).

Keen to hear others thoughts.

sunpy/net/dataretriever/sources/adapt.py Outdated Show resolved Hide resolved
sunpy/net/dataretriever/sources/adapt.py Outdated Show resolved Hide resolved
@nabobalis nabobalis added net Affects the net submodule Whats New? Needs a section added to the current Whats New? page. No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers) labels Mar 26, 2024
Copy link
Author

@GillySpace27 GillySpace27 left a comment

Choose a reason for hiding this comment

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

Thanks for the additional comments! I did everything except the tests, which I will definitely get around to ASAP. Let me know if you see anything else!


>>> start_datetime, end_datetime = carrington_time(CR, frames)
>>> longitude_type = '0'
>>> res = Fido.search(attrs.Instrument('adapt'), attrs.Time(start_datetime, end_datetime), ADAPTLngType(LngType))
Copy link
Contributor

@nabobalis nabobalis Mar 26, 2024

Choose a reason for hiding this comment

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

Suggested change
>>> res = Fido.search(attrs.Instrument('adapt'), attrs.Time(start_datetime, end_datetime), ADAPTLngType(LngType))
>>> res = Fido.search(a.Time(start_datetime, end_datetime), a.Instrument('adapt'), a.adapt.ADAPTLngType(longitude_type))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net Affects the net submodule No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers) Whats New? Needs a section added to the current Whats New? page.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants