-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create basic fido client for PSP fields radio data
- Loading branch information
Shane Maloney
committed
Apr 4, 2020
1 parent
d7e68db
commit d7c1c43
Showing
4 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
|
||
from .callisto import CallistoSpectrogram | ||
from .swaves import SWavesSpectrogram | ||
from .psp import RFRClient |
This file contains 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,90 @@ | ||
from datetime import datetime | ||
|
||
import astropy.units as u | ||
from astropy.time.core import TimeDelta | ||
from astropy.time import Time | ||
|
||
from sunpy.net.dataretriever.client import GenericClient | ||
from sunpy.time.timerange import TimeRange | ||
from sunpy.util.scraper import Scraper | ||
|
||
__all__ = ['RFRClient'] | ||
|
||
class RFRClient(GenericClient): | ||
""" | ||
Provides access to the LYRA/Proba2 data `archive <http://proba2.oma.be/lyra/data/bsd/>`__ | ||
hosted by the `PROBA2 Science Center <http://proba2.oma.be>`__. | ||
Examples | ||
-------- | ||
>>> from sunpy.net import Fido, attrs as a | ||
>>> results = Fido.search(a.Time("2019/10/01", "2019/11/01"), | ||
... a.Instrument('RFR')) #doctest: +REMOTE_DATA | ||
>>> results #doctest: +REMOTE_DATA +ELLIPSIS | ||
<sunpy.net.fido_factory.UnifiedResponse object at ...> | ||
Results from 1 Provider: | ||
<BLANKLINE> | ||
2 Results from the LYRAClient: | ||
Start Time End Time Source Instrument Wavelength | ||
------------------- ------------------- ------ ---------- ---------- | ||
2016-01-01 00:00:00 2016-01-02 00:00:00 Proba2 lyra nan | ||
2016-01-01 00:00:00 2016-01-02 00:00:00 Proba2 lyra nan | ||
<BLANKLINE> | ||
<BLANKLINE> | ||
""" | ||
|
||
def _get_url_for_timerange(self, timerange, **kwargs): | ||
""" | ||
Return URL(s) for corresponding timerange. | ||
Parameters | ||
---------- | ||
timerange : `~sunpy.time.TimeRange` | ||
The time range you want the files for. | ||
Returns | ||
------- | ||
`list` | ||
The URL(s) for the corresponding timerange. | ||
""" | ||
rfr_pattern = ('https://spdf.gsfc.nasa.gov/pub/data/psp/fields/l2/rfs_hfr/%Y/' | ||
'psp_fld_l2_rfs_hfr_%Y%m%d_v02.cdf') | ||
rfr_files = Scraper(rfr_pattern) | ||
urls = rfr_files.filelist(timerange) | ||
|
||
return urls | ||
|
||
def _get_time_for_url(self, urls): | ||
rfr_pattern = ('psp_fld_l2_rfs_hfr_%Y%m%d_v02.cdf') | ||
times = list() | ||
for url in urls: | ||
filename = url.split('/')[-1] | ||
time_start = Time(datetime.strptime(filename, rfr_pattern)) | ||
times.append(TimeRange(time_start, time_start + TimeDelta(1 * u.day))) | ||
return times | ||
|
||
|
||
def _makeimap(self): | ||
""" | ||
Helper Function:used to hold information about source. | ||
""" | ||
self.map_['source'] = 'PSP' | ||
self.map_['instrument'] = 'FIELDS' | ||
self.map_['physobs'] = 'flux' | ||
self.map_['provider'] = 'gsfc' | ||
|
||
@classmethod | ||
def _can_handle_query(cls, *query): | ||
""" | ||
Answers whether client can service the query. | ||
Parameters | ||
---------- | ||
query : list of query objects | ||
Returns | ||
------- | ||
boolean | ||
answer as to whether client can service the query | ||
""" | ||
chkattr = ['Time', 'Instrument'] | ||
chklist = [x.__class__.__name__ in chkattr for x in query] | ||
for x in query: | ||
if x.__class__.__name__ == 'Instrument' and x.value.lower() == 'rfr': | ||
return all(chklist) | ||
return False |
This file contains 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,11 @@ | ||
import pytest | ||
|
||
from sunpy.net import Fido, attrs as a | ||
|
||
from radiospectra.sources.psp import RFRClient | ||
|
||
|
||
def test_psp_client(): | ||
res = client.search(a.Time('2012/3/4', '2012/3/6'), a.Instrument('rhr')) | ||
print(res) | ||
result = Fido.search(a.Time('2012/3/4', '2012/3/6'), a.Instrument('rhr')) |
This file contains 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 |
---|---|---|
|
@@ -18,7 +18,8 @@ install_requires = | |
bs4 | ||
beautifulsoup4 | ||
lxml | ||
|
||
zeep | ||
drms | ||
|
||
[options.extras_require] | ||
test = | ||
|