Skip to content

Commit c4dc014

Browse files
committed
Implement Simbad query for new astroquery 4.8.0 Simbad API and test both the old and new API
1 parent 2e807b8 commit c4dc014

File tree

3 files changed

+61
-22
lines changed

3 files changed

+61
-22
lines changed

.github/workflows/build.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,12 @@ jobs:
251251
- name: Install astropy
252252
if: ${{ matrix.REQUIRES_ASTROPY }}
253253
run: pip install astropy pyerfa
254-
- name: Install astroquery
255-
if: ${{ matrix.REQUIRES_ASTROQUERY }}
254+
- name: Install astroquery (latest release)
255+
if: ${{ matrix.REQUIRES_ASTROQUERY && endsWith(matrix.TEST_FILES,'-k test_energy_jacobi_conservation') }}
256256
run: pip install astroquery
257+
- name: Install astroquery (bleeding edge)
258+
if: ${{ matrix.REQUIRES_ASTROQUERY && endsWith(matrix.TEST_FILES,'not test_energy_jacobi_conservation') }}
259+
run: pip install --pre astroquery
257260
- name: Install numba
258261
if: ${{ matrix.REQUIRES_NUMBA }}
259262
run: |

galpy/orbit/Orbits.py

+52-20
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
_APY_GE_31,
4343
_APY_LOADED,
4444
_APY_UNITS,
45+
_AQ_GT_47,
4546
_ASTROQUERY_LOADED,
4647
_NUMEXPR_LOADED,
4748
)
@@ -7471,35 +7472,66 @@ def _from_name_oneobject(name, obs):
74717472
# Make sure to make an HTTPS request so this code works in the browser
74727473
simbad.SIMBAD_URL = simbad.SIMBAD_URL.replace("http://", "https://")
74737474
simbad.add_votable_fields(
7474-
"ra(d)", "dec(d)", "pmra", "pmdec", "rv_value", "plx", "distance"
7475+
"ra" if _AQ_GT_47 else "ra(d)",
7476+
"dec" if _AQ_GT_47 else "dec(d)",
7477+
"pmra",
7478+
"pmdec",
7479+
"rvz_radvel" if _AQ_GT_47 else "rv_value",
74757480
)
7476-
simbad.remove_votable_fields("main_id", "coordinates")
7481+
if not _AQ_GT_47:
7482+
simbad.add_votable_fields("plx", "distance")
74777483
# query SIMBAD for the named object
74787484
try:
74797485
simbad_table = simbad.query_object(name)
74807486
except OSError: # pragma: no cover
74817487
raise OSError("failed to connect to SIMBAD")
74827488
if not simbad_table:
74837489
raise ValueError(f"failed to find {name} in SIMBAD")
7484-
# check that the necessary coordinates have been found
7485-
missing = simbad_table.mask
7486-
if any(missing["RA_d", "DEC_d", "PMRA", "PMDEC", "RV_VALUE"][0]) or all(
7487-
missing["PLX_VALUE", "Distance_distance"][0]
7488-
):
7489-
raise ValueError(
7490-
"failed to find some coordinates for {} in " "SIMBAD".format(name)
7491-
)
7492-
ra, dec, pmra, pmdec, vlos = simbad_table[
7493-
"RA_d", "DEC_d", "PMRA", "PMDEC", "RV_VALUE"
7494-
][0]
7495-
# get a distance value
7496-
if not missing["PLX_VALUE"][0]:
7497-
dist = 1.0 / simbad_table["PLX_VALUE"][0]
7490+
if _AQ_GT_47:
7491+
# check that the necessary coordinates have been found
7492+
missing = simbad_table.mask
7493+
if any(missing["ra", "dec", "pmra", "pmdec", "rvz_radvel"][0]):
7494+
raise ValueError(
7495+
"failed to find some coordinates for {} in " "SIMBAD".format(name)
7496+
)
7497+
ra, dec, pmra, pmdec, vlos = simbad_table[
7498+
"ra", "dec", "pmra", "pmdec", "rvz_radvel"
7499+
][0]
7500+
# get a distance value
7501+
simbad.add_votable_fields("plx_value")
7502+
simbad_table = simbad.query_object(name)
7503+
if not simbad_table or (
7504+
hasattr(simbad_table["plx_value"][0], "mask")
7505+
and simbad_table["plx_value"][0].mask
7506+
): # No parallax, try to find a distance
7507+
simbad.add_votable_fields("mesdistance")
7508+
simbad_table = simbad.query_object(name)
7509+
if not simbad_table:
7510+
raise ValueError(f"Failed to find a distance for {name} in SIMBAD")
7511+
dist = simbad_table["mesdistance.dist"][0]
7512+
else:
7513+
dist = 1.0 / simbad_table["plx_value"][0]
74987514
else:
7499-
dist_str = (
7500-
str(simbad_table["Distance_distance"][0]) + simbad_table["Distance_unit"][0]
7501-
)
7502-
dist = units.Quantity(dist_str).to(units.kpc).value
7515+
# check that the necessary coordinates have been found
7516+
missing = simbad_table.mask
7517+
if any(missing["RA_d", "DEC_d", "PMRA", "PMDEC", "RV_VALUE"][0]) or all(
7518+
missing["PLX_VALUE", "Distance_distance"][0]
7519+
):
7520+
raise ValueError(
7521+
"failed to find some coordinates for {} in " "SIMBAD".format(name)
7522+
)
7523+
ra, dec, pmra, pmdec, vlos = simbad_table[
7524+
"RA_d", "DEC_d", "PMRA", "PMDEC", "RV_VALUE"
7525+
][0]
7526+
# get a distance value
7527+
if not missing["PLX_VALUE"][0]:
7528+
dist = 1.0 / simbad_table["PLX_VALUE"][0]
7529+
else:
7530+
dist_str = (
7531+
str(simbad_table["Distance_distance"][0])
7532+
+ simbad_table["Distance_unit"][0]
7533+
)
7534+
dist = units.Quantity(dist_str).to(units.kpc).value
75037535
return [ra, dec, dist, pmra, pmdec, vlos]
75047536

75057537

galpy/util/_optional_deps.py

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
from astroquery.simbad import Simbad
3333
except ImportError:
3434
_ASTROQUERY_LOADED = False
35+
else:
36+
import astroquery
37+
38+
_AQ_GT_47 = parse_version(astroquery.__version__) > parse_version("0.4.7")
3539

3640
# numexpr
3741
_NUMEXPR_LOADED = True

0 commit comments

Comments
 (0)