I am attempting to query Gaia programmatically in python to get certain properties for specific stars. I can write a query which obtains some properties, but only for all stars, not a set of stars or one specific star. Ideally I would just be able to pass the query function a star name but I can't figure out from the documentation how to do this (or even how to make the star name, rather than just the Gaia source_id, a column in the returned table). My current script is as follows:

query = """SELECT source_id, ra, dec, parallax FROM gaiadr2.gaia_source """
job = Gaia.launch_job(query)
results = job.get_results()

Any pointers are much appreciated!


Hello Random_Astro_Student,

If you have not already, refer to this document. Section 14.1.1 provides the schema for gaiasource. You will note that there is no field with a name (eg: 'Alpha Centauri A').

I had queried Gaia data using the function below. GaiaDR2SourceIDs is a comma separated string (ID1,ID2,ID3,.....,IDn) for ID's to retrieve. FolderForLocalStorage is a destination folder to store the retrieved data rows in CSV. I had done this to avoid any possible issues where I would not be able to access the Gaia servers.

# ---------------------------------------------------------------------------
def GetGAIAData(GaiaDR2SourceIDs, FolderForLocalStorage):
    # gets the GAIA data for the provided GaiaDR2SourceIDs's
    # and writes to a local CSV
    dfGaia = pd.DataFrame()
    #job = Gaia.launch_job_async( "select top 100 * from gaiadr2.gaia_source where parallax>0 and parallax_over_error>3. ") # Select `good' parallaxes
    qry = "SELECT * FROM gaiadr2.gaia_source gs WHERE gs.source_id in (" + GaiaDR2SourceIDs + ");"
    job = Gaia.launch_job_async( qry )
    tblGaia = job.get_results()       #Astropy table
    dfGaia = tblGaia.to_pandas()      #convert to Pandas dataframe
    npGAIARecords = dfGaia.to_numpy() #convert to numpy array    
    lstGAIARecords = [list(x) for x in npGAIARecords]   #convert to List[]
    FileForLocalStorage = FolderForLocalStorage + str(lstGAIARecords[0][2]) + '.csv'  # use SourceID from 1st record
    dfGaia.to_csv (FileForLocalStorage, index = False, header=True)    

If you only have a few stars you might get their Gaia Source_ID values by direct querying on SIMBAD or using AstroQuery as in sample below.

from astroquery.simbad import Simbad
result_table = Simbad.query_objectids("eta carinae")
for x in result_table:
    if 'gaia' in x['ID'].lower():
        print (x['ID'])

You may also do away with direct query to Gaia, instead using astroquery.gaia.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.