Skip to content
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
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ New Tools and Services
Service fixes and enhancements
------------------------------

gaia
^^^^

- Allow for setting row limits in query submissions through class
attribute. [#1641]


Infrastructure, Utility and Other Changes and Additions
-------------------------------------------------------




0.4 (2020-01-24)
================

Expand Down
3 changes: 3 additions & 0 deletions astroquery/gaia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions astroquery/gaia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down Expand Up @@ -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})
Expand All @@ -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,
Expand Down Expand Up @@ -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}),
Expand All @@ -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,
Expand Down
50 changes: 50 additions & 0 deletions astroquery/gaia/tests/test_gaia_remote.py
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose these values will change with new DRs, but let's cross that bridge when we get there.