3
$\begingroup$

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!

$\endgroup$
0

1 Answer 1

4
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ I'm considering asking a separate question for this, but since this seems so related I'll just ask here and see if I get a response first: what if I want to do the opposite (i.e. get the "common name" of an object in the Gaia Archive? I'm aware that the vast majority of objects in the archive don't have easily identifiable names, but I'm specifically looking at the x closest stars to Sol, and many of them will tend to have familiar designations (like e.g. "Arcturus" or "Sirius" and so on. Is there any service I can cross-query from the Gaia ids to find such designations? $\endgroup$
    – Outis Nemo
    Mar 23 at 0:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .