From fda99cfebf6afd189d7182db266735a3cf9adb52 Mon Sep 17 00:00:00 2001 From: MARCHAND MANON Date: Fri, 13 Dec 2024 17:53:32 +0100 Subject: [PATCH 1/3] fix: allow to add the votable field 'ident' in query_objects this is fixed by setting an alias for the ident table in the join, so that the ambiguity is lifted with the join done by add_votable_field --- CHANGES.rst | 3 +++ astroquery/simbad/core.py | 13 ++++++++++--- astroquery/simbad/tests/test_simbad.py | 7 ++++--- astroquery/simbad/tests/test_simbad_remote.py | 7 +++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 46761a7ced..a63d8a5668 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -149,6 +149,9 @@ simbad A helper method was added ``astroquery.simbad.utils.CriteriaTranslator`` to translate between the sim-script syntax and the TAP/ADQL syntax. [#2954] +- fixed ``query_objects`` that would not work in combination with the additional field + ``ident`` [#3149] + skyview ^^^^^^^ diff --git a/astroquery/simbad/core.py b/astroquery/simbad/core.py index 9f16ea122b..feeeb3517c 100644 --- a/astroquery/simbad/core.py +++ b/astroquery/simbad/core.py @@ -90,6 +90,7 @@ class _Join: column_left: Any column_right: Any join_type: str = field(default="JOIN") + alias: str = field(default=None) class SimbadClass(BaseVOQuery): @@ -670,10 +671,11 @@ def query_objects(self, object_names, *, wildcard=False, criteria=None, upload_name = "TAP_UPLOAD.script_infos" columns.append(_Column(upload_name, "*")) + # join on ident needs an alias in case the users want to add the votable field ident left_joins = [_Join("ident", _Column(upload_name, "user_specified_id"), - _Column("ident", "id"), "LEFT JOIN"), + _Column("ident", "id"), "LEFT JOIN", "ident_upload"), _Join("basic", _Column("basic", "oid"), - _Column("ident", "oidref"), "LEFT JOIN")] + _Column("ident_upload", "oidref"), "LEFT JOIN")] for join in joins: left_joins.append(_Join(join.table, join.column_left, join.column_right, "LEFT JOIN")) @@ -1415,7 +1417,12 @@ def _query(self, top, columns, joins, criteria, from_table="basic", else: unique_joins = [] [unique_joins.append(join) for join in joins if join not in unique_joins] - join = " " + " ".join([(f'{join.join_type} {join.table} ON {join.column_left.table}."' + # the joined tables can have an alias. We handle the two cases here + join = " " + " ".join([(f'{join.join_type} {join.table} AS {join.alias} ' + f'ON {join.column_left.table}."{join.column_left.name}" = ' + f'{join.alias}."{join.column_right.name}"') + if join.alias is not None else + (f'{join.join_type} {join.table} ON {join.column_left.table}."' f'{join.column_left.name}" = {join.column_right.table}."' f'{join.column_right.name}"') for join in unique_joins]) diff --git a/astroquery/simbad/tests/test_simbad.py b/astroquery/simbad/tests/test_simbad.py index aec4b23c20..ad59007919 100644 --- a/astroquery/simbad/tests/test_simbad.py +++ b/astroquery/simbad/tests/test_simbad.py @@ -408,9 +408,10 @@ def test_query_objects(): # no wildcard and additional criteria adql = simbad.core.Simbad.query_objects(("m1", "m2"), criteria="otype = 'Galaxy..'", get_query_payload=True)["QUERY"] - expected = ('FROM TAP_UPLOAD.script_infos LEFT JOIN ident ON TAP_UPLOAD.script_infos.' - '"user_specified_id" = ident."id" LEFT JOIN basic ON basic."oid" = ident."oidref"' - ' WHERE (otype = \'Galaxy..\')') + expected = ('FROM TAP_UPLOAD.script_infos LEFT JOIN ident AS ident_upload ' + 'ON TAP_UPLOAD.script_infos.' + '"user_specified_id" = ident_upload."id" LEFT JOIN basic ' + 'ON basic."oid" = ident_upload."oidref" WHERE (otype = \'Galaxy..\')') assert adql.endswith(expected) # with wildcard adql = simbad.core.Simbad.query_objects(("M *", "NGC *"), wildcard=True, get_query_payload=True)["QUERY"] diff --git a/astroquery/simbad/tests/test_simbad_remote.py b/astroquery/simbad/tests/test_simbad_remote.py index d5084940d1..1cc690689d 100644 --- a/astroquery/simbad/tests/test_simbad_remote.py +++ b/astroquery/simbad/tests/test_simbad_remote.py @@ -204,3 +204,10 @@ def test_add_votable_fields(self): simbad_instance.add_votable_fields("u") result = simbad_instance.query_object("HD 147933") assert all(filtername in result.colnames for filtername in {"u", "U", "V"}) + + def test_double_ident_in_query_objects(self): + simbad = Simbad() + simbad.add_votable_fields("ident") + result = simbad.query_objects(['HD 1']) + assert len(result) > 1 + assert all(result["main_id"] == "HD 1") From 932671792d5dd1c4f94fb1215201e88348e3c233 Mon Sep 17 00:00:00 2001 From: MARCHAND MANON Date: Fri, 13 Dec 2024 18:01:18 +0100 Subject: [PATCH 2/3] docs: update to reflect changes in Simbad - new rotation measurement for Sirius - more presice value for M1's position - new main id for Barnard's exoplanet - new proper motion measurement for BD+30 --- docs/simbad/query_tap.rst | 21 ++++++++++++--------- docs/simbad/simbad.rst | 19 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/docs/simbad/query_tap.rst b/docs/simbad/query_tap.rst index 72542b16db..69ecdb38fd 100644 --- a/docs/simbad/query_tap.rst +++ b/docs/simbad/query_tap.rst @@ -195,22 +195,25 @@ that is the measurement table for rotations. Their common column is ``oidref``. .. doctest-remote-data:: >>> from astroquery.simbad import Simbad - >>> query = """SELECT bibcode AS "Rotation Measurements Bibcodes" + >>> query = """SELECT DISTINCT bibcode AS "Rotation Measurements Bibcodes" ... FROM ident JOIN mesrot USING(oidref) ... WHERE id = 'Sirius'; ... """ - >>> Simbad.query_tap(query) - + >>> bibcodes = Simbad.query_tap(query) + >>> bibcodes.sort("Rotation Measurements Bibcodes") + >>> bibcodes +
Rotation Measurements Bibcodes - object + object ------------------------------ - 2023ApJS..266...11B - 2016A&A...589A..83G - 2002A&A...393..897R - 1995ApJS...99..135A - 1970CoKwa.189....0U 1970CoAsi.239....1B + 1970CoKwa.189....0U + 1995ApJS...99..135A + 2002A&A...393..897R + 2005yCat.3244....0G 2011A&A...531A.143D + 2016A&A...589A..83G + 2023ApJS..266...11B This returns six papers in which the SIMBAD team found rotation data for Sirius. diff --git a/docs/simbad/simbad.rst b/docs/simbad/simbad.rst index 5eca9e6371..3424ed53f6 100644 --- a/docs/simbad/simbad.rst +++ b/docs/simbad/simbad.rst @@ -66,7 +66,7 @@ to query the messier object M1: main_id ra dec ... coo_wavelength coo_bibcode matched_id deg deg ... ------- ------- ------- ... -------------- ------------------- ---------- - M 1 83.6287 22.0147 ... R 1995AuJPh..48..143S M 1 + M 1 83.6324 22.0174 ... X 2022A&A...661A..38P M 1 `Wildcards`_ are supported. Note that this makes the query case-sensitive. This allows, for instance, to query messier objects from 1 through 9: @@ -203,12 +203,12 @@ If the center is defined by coordinates, then the best solution is to use a >>> Simbad.query_region(SkyCoord(31.0087, 14.0627, unit=(u.deg, u.deg), ... frame='galactic'), radius=2 * u.arcsec)
- main_id ra ... coo_wavelength coo_bibcode - deg ... - object float64 ... str1 object - ------------------- ----------------- ... -------------- ------------------- - GJ 699 b 269.4520769586187 ... O 2020yCat.1350....0G - NAME Barnard's star 269.4520769586187 ... O 2020yCat.1350....0G + main_id ra ... coo_wavelength coo_bibcode + deg ... + object float64 ... str1 object + --------------------- ----------------- ... -------------- ------------------- + NAME Barnard's Star b 269.4520769586187 ... O 2020yCat.1350....0G + NAME Barnard's star 269.4520769586187 ... O 2020yCat.1350....0G .. Note:: @@ -466,7 +466,7 @@ with: >>> from astroquery.simbad import Simbad >>> Simbad.list_votable_fields()[["name", "description"]] -
+
name description object object ----------- ------------------------------------------------------- @@ -584,11 +584,12 @@ constraint on the first character of the ``mespm.bibcode`` column >>> simbad.add_votable_fields("mesPM", "otype") >>> pm_measurements = simbad.query_object("BD+30 2512", criteria=criteria) >>> pm_measurements[["main_id", "mespm.pmra", "mespm.pmde", "mespm.bibcode"]] -
+
main_id mespm.pmra mespm.pmde mespm.bibcode mas / yr mas / yr object float32 float32 object ----------- ---------- ---------- ------------------- + BD+30 2512 -631.6 -289.5 2016ApJ...817..112S BD+30 2512 -631.662 -308.469 2020yCat.1350....0G BD+30 2512 -631.6 -289.5 2016ApJS..224...36K BD+30 2512 -631.625 -308.495 2018yCat.1345....0G From 7d96ebdc7b63e534e39d3d849154617f75e7e16d Mon Sep 17 00:00:00 2001 From: MARCHAND MANON Date: Fri, 13 Dec 2024 18:20:02 +0100 Subject: [PATCH 3/3] docs: sort output by galdim_majaxis for more repetability --- astroquery/simbad/core.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/astroquery/simbad/core.py b/astroquery/simbad/core.py index feeeb3517c..28f37b6af1 100644 --- a/astroquery/simbad/core.py +++ b/astroquery/simbad/core.py @@ -718,28 +718,29 @@ def query_region(self, coordinates, radius=2*u.arcmin, *, Examples -------- - Look for large galaxies in two cones + Look for largest galaxies in two cones >>> from astroquery.simbad import Simbad >>> from astropy.coordinates import SkyCoord >>> simbad = Simbad() >>> simbad.ROW_LIMIT = 5 - >>> simbad.add_votable_fields("otype") # doctest: +REMOTE_DATA + >>> simbad.add_votable_fields("otype", "dim") # doctest: +REMOTE_DATA >>> coordinates = SkyCoord([SkyCoord(186.6, 12.7, unit=("deg", "deg")), ... SkyCoord(170.75, 23.9, unit=("deg", "deg"))]) >>> result = simbad.query_region(coordinates, radius="2d5m", - ... criteria="otype = 'Galaxy..' AND galdim_majaxis>8") # doctest: +REMOTE_DATA - >>> result.sort("main_id") # doctest: +REMOTE_DATA - >>> result["main_id", "otype"] # doctest: +REMOTE_DATA + ... criteria="otype = 'Galaxy..' AND galdim_majaxis>8.5") # doctest: +REMOTE_DATA + >>> result.sort("galdim_majaxis", reverse=True) # doctest: +REMOTE_DATA + >>> result["main_id", "otype", "galdim_majaxis"] # doctest: +REMOTE_DATA
- main_id otype - object object - ------------ ------ - LEDA 40577 GiG - LEDA 41362 GiC - M 86 GiG - M 87 AGN - NGC 4438 LIN + main_id otype galdim_majaxis + arcmin + object object float32 + ------------ ------ -------------- + LEDA 41362 GiC 11.0 + M 86 GiG 10.47 + LEDA 40917 AG? 10.3 + M 87 AGN 9.12 + NGC 4438 LIN 8.91 Notes ----- @@ -1334,7 +1335,7 @@ def query_tap(self, query: str, *, maxrec=10000, get_query_payload=False, **uplo ... my_table_name=letters_table) # doctest: +REMOTE_DATA
alphabet - object + str1 -------- a b