From 116fbd53034e3553f45ea1aadcf772cd94e8592b Mon Sep 17 00:00:00 2001 From: nmearl Date: Mon, 10 Feb 2020 11:36:42 -0500 Subject: [PATCH 1/3] Allow setting row limits in Gaia queries --- astroquery/gaia/__init__.py | 3 ++ astroquery/gaia/core.py | 5 +++ astroquery/gaia/tests/test_gaia_remote.py | 50 +++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 astroquery/gaia/tests/test_gaia_remote.py diff --git a/astroquery/gaia/__init__.py b/astroquery/gaia/__init__.py index 642a8c942e..1dd9972dc6 100644 --- a/astroquery/gaia/__init__.py +++ b/astroquery/gaia/__init__.py @@ -30,6 +30,9 @@ class Conf(_config.ConfigNamespace): "Name of RA parameter in table") MAIN_GAIA_TABLE_DEC = _config.ConfigItem("dec", "Name of Dec parameter in table") + ROW_LIMIT = _config.ConfigItem(50, + "Number of rows to return from database " + "query (set to -1 for unlimited).") conf = Conf() diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index d9a0a57552..e5c90c5e48 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -32,6 +32,7 @@ class GaiaClass(TapPlus): MAIN_GAIA_TABLE = conf.MAIN_GAIA_TABLE MAIN_GAIA_TABLE_RA = conf.MAIN_GAIA_TABLE_RA MAIN_GAIA_TABLE_DEC = conf.MAIN_GAIA_TABLE_DEC + ROW_LIMIT = conf.ROW_LIMIT def __init__(self, tap_plus_conn_handler=None, datalink_handler=None): super(GaiaClass, self).__init__(url="https://gea.esac.esa.int/", @@ -182,6 +183,7 @@ def __query_object(self, coordinate, radius=None, width=None, height=None, query = """ SELECT + {row_limit} DISTANCE( POINT('ICRS', {ra_column}, {dec_column}), POINT('ICRS', {ra}, {dec}) @@ -203,6 +205,7 @@ def __query_object(self, coordinate, radius=None, width=None, height=None, ORDER BY dist ASC """.format(**{ + 'row_limit': "TOP {0}".format(self.ROW_LIMIT) if self.ROW_LIMIT > 0 else "", 'ra_column': self.MAIN_GAIA_TABLE_RA, 'dec_column': self.MAIN_GAIA_TABLE_DEC, 'columns': columns, 'table_name': self.MAIN_GAIA_TABLE, @@ -329,6 +332,7 @@ def __cone_search(self, coordinate, radius, table_name=MAIN_GAIA_TABLE, query = """ SELECT + {row_limit} {columns}, DISTANCE( POINT('ICRS', {ra_column}, {dec_column}), @@ -345,6 +349,7 @@ def __cone_search(self, coordinate, radius, table_name=MAIN_GAIA_TABLE, dist ASC """.format(**{ 'ra_column': ra_column_name, + 'row_limit': "TOP {0}".format(self.ROW_LIMIT) if self.ROW_LIMIT > 0 else "", 'dec_column': dec_column_name, 'columns': columns, 'ra': ra, 'dec': dec, 'radius': radiusDeg, diff --git a/astroquery/gaia/tests/test_gaia_remote.py b/astroquery/gaia/tests/test_gaia_remote.py new file mode 100644 index 0000000000..efd37bf1b2 --- /dev/null +++ b/astroquery/gaia/tests/test_gaia_remote.py @@ -0,0 +1,50 @@ +import astropy.units as u +import pytest +from astropy.coordinates import SkyCoord +from astropy.tests.helper import remote_data + +from .. import GaiaClass + + +@remote_data +def test_query_object_row_limit(): + Gaia = GaiaClass() + coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs') + width = u.Quantity(0.1, u.deg) + height = u.Quantity(0.1, u.deg) + r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + + assert len(r) == Gaia.ROW_LIMIT + + Gaia.ROW_LIMIT = 10 + r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + + assert len(r) == 10 == Gaia.ROW_LIMIT + + Gaia.ROW_LIMIT = -1 + r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + + assert len(r) == 176 + + +@remote_data +def test_cone_search_row_limit(): + Gaia = GaiaClass() + coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs') + radius = u.Quantity(0.1, u.deg) + j = Gaia.cone_search_async(coord, radius) + r = j.get_results() + + assert len(r) == Gaia.ROW_LIMIT + + Gaia.ROW_LIMIT = 10 + j = Gaia.cone_search_async(coord, radius) + r = j.get_results() + + assert len(r) == 10 == Gaia.ROW_LIMIT + + Gaia.ROW_LIMIT = -1 + j = Gaia.cone_search_async(coord, radius) + r = j.get_results() + + assert len(r) == 1188 From 3e4de75daa69af05bfc215b6d03ac4c59fafb320 Mon Sep 17 00:00:00 2001 From: nmearl Date: Mon, 10 Feb 2020 11:43:11 -0500 Subject: [PATCH 2/3] Update change log --- CHANGES.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 521ba1acb5..28077f0867 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,15 @@ Service fixes and enhancements Infrastructure, Utility and Other Changes and Additions ------------------------------------------------------- +Service Fixes and Enhancements +------------------------------ + +gaia +^^^^ + +- Allow for setting row limits in query submissions through class attribute. [#1641] + + 0.4 (2020-01-24) ================ From 20393b86bb0c791c48619c168b8ba1c50d972296 Mon Sep 17 00:00:00 2001 From: Brigitta Sipocz Date: Thu, 13 Feb 2020 19:19:41 -0800 Subject: [PATCH 3/3] remove duplicated changelog section [skip ci] --- CHANGES.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 28077f0867..f4099d72d3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,17 +8,16 @@ New Tools and Services Service fixes and enhancements ------------------------------ +gaia +^^^^ -Infrastructure, Utility and Other Changes and Additions -------------------------------------------------------- +- Allow for setting row limits in query submissions through class + attribute. [#1641] -Service Fixes and Enhancements ------------------------------- -gaia -^^^^ +Infrastructure, Utility and Other Changes and Additions +------------------------------------------------------- -- Allow for setting row limits in query submissions through class attribute. [#1641]