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

Sia2 kwargs #222

Merged
merged 6 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

- Add support for SIAv2. [#206]

- Add kwargs to sia2. [#222]

1.0 (2019-09-20)
================

Expand Down
27 changes: 22 additions & 5 deletions pyvo/dal/sia2.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
specifies response format(s).
max_records : int
allows the client to limit the number or records in the response
**kwargs : custom query parameters
single or a list of values (or tuples for intervals) custom query
parameters that a specific service accepts. The values of the
parameters need to follow the SIAv2 format and represent the
appropriate quantities (where applicable).
"""


Expand All @@ -90,7 +95,8 @@ def search(url, pos=None, band=None, time=None, pol=None,
spectral_resolving_power=None, exptime=None,
timeres=None, publisher_did=None, facility=None, collection=None,
instrument=None, data_type=None, calib_level=None,
target_name=None, res_format=None, maxrec=None, session=None):
target_name=None, res_format=None, maxrec=None, session=None,
**kwargs):
"""
submit a simple SIA query to a SIAv2 compatible service

Expand All @@ -113,7 +119,7 @@ def search(url, pos=None, band=None, time=None, pol=None,
instrument=instrument, data_type=data_type,
calib_level=calib_level, target_name=target_name,
res_format=res_format, maxrec=maxrec,
session=session)
session=session, **kwargs)


search.__doc__ = search.__doc__.replace('_SIA2_PARAMETERS',
Expand Down Expand Up @@ -173,7 +179,8 @@ def search(self, pos=None, band=None, time=None, pol=None,
spectral_resolving_power=None, exptime=None,
timeres=None, publisher_did=None, facility=None, collection=None,
instrument=None, data_type=None, calib_level=None,
target_name=None, res_format=None, maxrec=None, session=None):
target_name=None, res_format=None, maxrec=None, session=None,
**kwargs):
"""
Performs a SIAv2 search against a SIAv2 service

Expand All @@ -193,7 +200,7 @@ def search(self, pos=None, band=None, time=None, pol=None,
instrument=instrument, data_type=data_type,
calib_level=calib_level, target_name=target_name,
res_format=res_format, maxrec=maxrec,
session=session).execute()
session=session, **kwargs).execute()


class SIAQuery(DALQuery, AxisParamMixin):
Expand All @@ -209,7 +216,7 @@ def __init__(self, url, pos=None, band=None, time=None, pol=None,
facility=None, collection=None,
instrument=None, data_type=None, calib_level=None,
target_name=None, res_format=None, maxrec=None,
session=None):
session=None, **kwargs):
"""
initialize the query object with a url and the given parameters

Expand Down Expand Up @@ -305,6 +312,16 @@ def __init__(self, url, pos=None, band=None, time=None, pol=None,
for rf in _tolist(res_format):
self.res_format.add(rf)

for name, value in kwargs.items():
custom_arg = []
for kw in _tolist(value):
if isinstance(kw, tuple):
val = '{} {}'.format(kw[0], kw[1])
else:
val = str(kw)
custom_arg.append(val)
self[name] = custom_arg

self.maxrec = maxrec

__init__.__doc__ = \
Expand Down
9 changes: 9 additions & 0 deletions pyvo/dal/tests/test_sia2.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,12 @@ def test_query(self):

query.maxrec = 1000
assert query['MAXREC'] == '1000'

query = SIAQuery('someurl', custom_param=23)
assert query['custom_param'] == ['23']

query['custom_param'].append('-Inf 0')
assert query['custom_param'] == ['23', '-Inf 0']

query = SIAQuery('someurl', custom_param=[('-Inf', 0), (2, '+Inf')])
assert query['custom_param'] == ['-Inf 0', '2 +Inf']