Hi. I have these two snippets of code which have the same objective: finding the Gaia designation of a star from the Hipparcos catalog, which has HIP = 79672. Below is the code:
from astroquery.gaia import Gaia
from astropy.coordinates import SkyCoord
from astroquery.simbad import Simbad
'''
First piece of code is below
'''
#####################################################################
gaiadr3_table = Gaia.load_table('gaiadr3.gaia_source')
job = Gaia.launch_job("select ra from gaiadr3.gaia_source")
ra = job.get_results()
job = Gaia.launch_job("select dec from gaiadr3.gaia_source")
dec = job.get_results()
catalog = SkyCoord(ra=ra, dec=dec, unit="deg")
c = SkyCoord.from_name('HIP 79672')
idx, d2d, d3d = c.match_to_catalog_sky(catalog, 1)
job = Gaia.launch_job("select designation from gaiadr3.gaia_source")
designation = job.get_results()
print("Result of first piece of code:")
print(designation[idx])
print("\n")
#####################################################################
'''
Second piece of code below
'''
#####################################################################
tab = Simbad.query_objectids('HIP 79672')
print("Result of second piece of code:")
print([id for id in tab['ID'] if id.startswith('Gaia DR3')][0])
#####################################################################
Below is the output of the python program:
/usr/bin/python3.11 /home/h/Downloads/match.py
Retrieving table 'gaiadr3.gaia_source'
Result of first piece of code:
DESIGNATION
----------------------------
Gaia DR3 1000000057322000000
Result of second piece of code:
Gaia DR3 4345775217221821312
Process finished with exit code 0
I confess that I don’t quite understand how the first piece of code works.
I only understand that it does the following things:
- Stores the ra and dec columns of the Gaia catalog in the ‘catalog’ variable
- Stores the coordinates of the identifier star ‘HIP 79672’ in variable c
- Search in catalog for the ‘object’ c
The second section searches, in Simbad, all the identifiers for the star HIP 79672. After that, it “filters” the results so that only those starting with ‘HIP’ remain.
I’m sure only the result of the second code snippet is correct.
Could someone please explain the following three points to me?
- What exactly does the first piece of code?
- Why is the first code snippet not returning the correct result?
- How can I fix the first piece of code so that it returns the correct result?