From 3839ab99e97c2099b8a914c0ac26b9133ace055b Mon Sep 17 00:00:00 2001 From: Adrian Damian Date: Sun, 19 Apr 2020 10:48:32 +1200 Subject: [PATCH 1/4] Added support for custom arguments to sia2 --- pyvo/dal/sia2.py | 27 ++++++++++++++++++++++----- pyvo/dal/tests/test_sia2.py | 9 +++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/pyvo/dal/sia2.py b/pyvo/dal/sia2.py index 1f6a0b4a0..819bdc7a4 100644 --- a/pyvo/dal/sia2.py +++ b/pyvo/dal/sia2.py @@ -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). """ @@ -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 @@ -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', @@ -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 @@ -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): @@ -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 @@ -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 ii in kwargs: + custom_arg = [] + for kw in _tolist(kwargs[ii]): + if isinstance(kw, tuple): + val = '{} {}'.format(kw[0], kw[1]) + else: + val = str(kw) + custom_arg.append(val) + self[ii] = custom_arg + self.maxrec = maxrec __init__.__doc__ = \ diff --git a/pyvo/dal/tests/test_sia2.py b/pyvo/dal/tests/test_sia2.py index 315539eac..0bbf22816 100644 --- a/pyvo/dal/tests/test_sia2.py +++ b/pyvo/dal/tests/test_sia2.py @@ -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'] From 16f43eb6e3240455b41eb5ca4aaea36e19b08bbf Mon Sep 17 00:00:00 2001 From: Adrian Damian Date: Sun, 19 Apr 2020 10:57:57 +1200 Subject: [PATCH 2/4] Fixed style --- pyvo/dal/sia2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyvo/dal/sia2.py b/pyvo/dal/sia2.py index 819bdc7a4..c55a852fc 100644 --- a/pyvo/dal/sia2.py +++ b/pyvo/dal/sia2.py @@ -84,7 +84,7 @@ 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 that a specific service accepts. The values of the parameters need to follow the SIAv2 format and represent the appropriate quantities (where applicable). """ From 4efc23a41700be9663f1a00587e8bd30cf3807e6 Mon Sep 17 00:00:00 2001 From: Adrian Damian Date: Mon, 20 Apr 2020 07:28:08 +1200 Subject: [PATCH 3/4] Updated changes log --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 7d93e2a18..ed9ce8f59 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,8 @@ - Add support for SIAv2. [#206] +- Add kwargs to sia2. [#222] + 1.0 (2019-09-20) ================ From 95720ad1d6f8af51b81c0cf9d427ec8e9bafdb84 Mon Sep 17 00:00:00 2001 From: Adrian Damian Date: Fri, 24 Apr 2020 07:20:08 +1200 Subject: [PATCH 4/4] Rework after code review --- pyvo/dal/sia2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyvo/dal/sia2.py b/pyvo/dal/sia2.py index c55a852fc..4faef97da 100644 --- a/pyvo/dal/sia2.py +++ b/pyvo/dal/sia2.py @@ -312,15 +312,15 @@ def __init__(self, url, pos=None, band=None, time=None, pol=None, for rf in _tolist(res_format): self.res_format.add(rf) - for ii in kwargs: + for name, value in kwargs.items(): custom_arg = [] - for kw in _tolist(kwargs[ii]): + for kw in _tolist(value): if isinstance(kw, tuple): val = '{} {}'.format(kw[0], kw[1]) else: val = str(kw) custom_arg.append(val) - self[ii] = custom_arg + self[name] = custom_arg self.maxrec = maxrec