Skip to content

Commit

Permalink
Merge pull request #1431 from jongyeob/add_sample_key
Browse files Browse the repository at this point in the history
Add a 'sample' keyword to apply time interval between SDO data from JSOC
  • Loading branch information
ayshih committed Jun 22, 2015
2 parents daff1a7 + 62e64d9 commit beeb866
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Latest
x first.
* map.rsun_arcseconds is now map.rsun_obs as it returns a quantity.
* Map properties are now named tuples rather than dictionaries.
* net.jsoc can query data series with time sampling by a Sample attribute implemented in vso.
* MapCube.plot and MapCube.peek now support a user defined plot_function argument for customising the animation.

0.5.0
Expand Down
29 changes: 20 additions & 9 deletions sunpy/net/jsoc/attrs.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
from __future__ import absolute_import

__all__ = ['Series', 'Protocol', 'Notify', 'Compression', 'Wavelength', 'Time',
'Segment', 'Sample']

import astropy.units as u

from sunpy.net.attr import (Attr, AttrWalker, AttrAnd, AttrOr)
from sunpy.net.vso.attrs import Time, _VSOSimpleAttr
from sunpy.net.attr import Attr, AttrWalker, AttrAnd, AttrOr
from sunpy.net.vso.attrs import _VSOSimpleAttr
from sunpy.net.vso.attrs import Time as vTime, Sample as vSample

__all__ = ['Series', 'Protocol', 'Notify', 'Compression', 'Wavelength', 'Time',
'Segment']
###############################################################################
# This is a horrific hack to make automodapi pick up these as jsoc attrs.


class Time(Time):
"""
Time range to download
"""
class Time(vTime):
__doc__ = vTime.__doc__
pass


class Sample(vSample):
__doc__ = vSample.__doc__
pass

###############################################################################


class Series(_VSOSimpleAttr):
Expand Down Expand Up @@ -49,7 +59,8 @@ class Notify(_VSOSimpleAttr):
def __init__(self, value):
super(Notify, self).__init__(value)
if value.find('@') == -1:
raise ValueError("Notify attribute must contain an '@' symbol to be a valid email address")
raise ValueError("Notify attribute must contain an '@' symbol "
"to be a valid email address")
self.value = value


Expand Down
18 changes: 12 additions & 6 deletions sunpy/net/jsoc/jsoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,19 +474,24 @@ def _make_recordset(self, start_time, end_time, series, wavelength='',
if not series.startswith('aia'):
raise TypeError("This series does not support the wavelength attribute.")
else:
if isinstance(wavelength, list):
wavelength = [int(np.ceil(wave.to(u.AA).value)) for wave in wavelength]
wavelength = str(wavelength)
else:
wavelength = '[{0}]'.format(int(np.ceil(wavelength.to(u.AA).value)))
if isinstance(wavelength, list):
wavelength = [int(np.ceil(wave.to(u.AA).value)) for wave in wavelength]
wavelength = str(wavelength)
else:
wavelength = '[{0}]'.format(int(np.ceil(wavelength.to(u.AA).value)))

# Extract and format segment
if segment != '':
segment = '{{{segment}}}'.format(segment=segment)

dataset = '{series}[{start}-{end}]{wavelength}{segment}'.format(
sample = kwargs.get('sample', '')
if sample:
sample = '@{}s'.format(sample)

dataset = '{series}[{start}-{end}{sample}]{wavelength}{segment}'.format(
series=series, start=start_time.strftime("%Y.%m.%d_%H:%M:%S_TAI"),
end=end_time.strftime("%Y.%m.%d_%H:%M:%S_TAI"),
sample=sample,
wavelength=wavelength, segment=segment)

return dataset
Expand All @@ -510,6 +515,7 @@ def _make_query_payload(self, start_time, end_time, series, notify=None,

dataset = self._make_recordset(start_time, end_time, series, **kwargs)
kwargs.pop('wavelength', None)
kwargs.pop('sample',None)

# Build full POST payload
payload = {'ds': dataset,
Expand Down
4 changes: 2 additions & 2 deletions sunpy/net/jsoc/tests/test_jsoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def test_empty_jsoc_response():

@pytest.mark.online
def test_query():
Jresp = client.query(attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'),
attrs.Series('hmi.M_45s'))
Jresp = client.query(attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:01:30'),
attrs.Series('hmi.M_45s'),attrs.Sample(90*u.second))
assert isinstance(Jresp, JSOCResponse)
assert len(Jresp) == 2

Expand Down
32 changes: 31 additions & 1 deletion sunpy/net/vso/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ def __repr__(self):


class Time(Attr, _Range):
"""
Specify the time range of the query.
Parameters
----------
start : SunPy Time String or `~sunpy.time.TimeRange`.
The start time in a format parseable by `~sunpy.time.parse_time` or
a `sunpy.time.TimeRange` object.
end : SunPy Time String
The end time of the range.
near: SunPy Time String
Return a singular record closest in time to this value as possible,
inside the start and end window. Note: not all providers support this.
"""
def __init__(self, start, end=None, near=None):
if end is None and not isinstance(start, _TimeRange):
raise ValueError("Specify start and end or start has to be a TimeRange")
Expand Down Expand Up @@ -193,7 +211,19 @@ class Filter(_VSOSimpleAttr):


class Sample(_VSOSimpleAttr):
pass
"""
Time interval for data sampling.
Parameters
----------
value : `astropy.units.Quantity`
A sampling rate convertable to seconds.
"""
@u.quantity_input(value=u.s)
def __init__(self, value):
super(Sample,self).__init__(value)
self.value = value.to(u.s).value


class Quicklook(_VSOSimpleAttr):
Expand Down

0 comments on commit beeb866

Please sign in to comment.