<p>Hello Random_Astro_Student,</p>
<p>If you have not already, refer to <a href="https://gea.esac.esa.int/archive/documentation/GDR2/" rel="nofollow noreferrer">this</a> document. <a href="https://gea.esac.esa.int/archive/documentation/GDR2/Gaia_archive/chap_datamodel/sec_dm_main_tables/ssec_dm_gaia_source.html" rel="nofollow noreferrer">Section 14.1.1</a> provides the schema for <em>gaiasource</em>. You will note that there is no field with a name (eg: 'Alpha Centauri A').</p>
<p>I had queried Gaia data using the function below. <em>GaiaDR2SourceIDs</em> is a comma separated string (<em>ID1,ID2,ID3,.....,IDn</em>) for ID's to retrieve. <em>FolderForLocalStorage</em> 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.</p>
<pre><code># ---------------------------------------------------------------------------
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( &quot;select top 100 * from gaiadr2.gaia_source where parallax&gt;0 and parallax_over_error&gt;3. &quot;) # Select `good' parallaxes
    qry = &quot;SELECT * FROM gaiadr2.gaia_source gs WHERE gs.source_id in (&quot; + GaiaDR2SourceIDs + &quot;);&quot;
    
    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)    
</code></pre>
<p>If you only have a few stars you might get their Gaia <em>Source_ID</em> values by direct querying on <a href="http://simbad.u-strasbg.fr/simbad/" rel="nofollow noreferrer">SIMBAD</a> or using <a href="https://astroquery.readthedocs.io/en/latest/simbad/simbad.html#query-object-identifiers" rel="nofollow noreferrer">AstroQuery</a> as in sample below.</p>
<pre><code>from astroquery.simbad import Simbad
result_table = Simbad.query_objectids(&quot;eta carinae&quot;)
        
for x in result_table:
    if 'gaia' in x['ID'].lower():
        print (x['ID'])
</code></pre>
<p>You may also do away with direct query to Gaia, instead using <a href="https://astroquery.readthedocs.io/en/latest/gaia/gaia.html" rel="nofollow noreferrer">astroquery.gaia</a>.</p>

CC BY-SA 4.0
2023-03-23T00:35:12.543Z
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?
Outis Nemo
CC BY-SA 4.0
2021-09-30T18:33:00.903Z
2021-10-01T21:25:11.017Z
2021-10-01T21:25:11.017Z
Astro Grech
<p>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:</p>
<pre><code>query = &quot;&quot;&quot;SELECT source_id, ra, dec, parallax FROM gaiadr2.gaia_source &quot;&quot;&quot;
job = Gaia.launch_job(query)
results = job.get_results()
</code></pre>
<p>Any pointers are much appreciated!</p>

<observational-astronomy><python><gaia>
Query Gaia by star name
Random_Astro_Student
# Query Gaia by star name

(Asked by: username_0 on 2021-09-27)

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!

**Tags:** observational-astronomy, python, gaia

---

## 1 answers

### Answer by username_1 on 2021-09-30. Score: 5

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.

> **Comments:**
> **username_2**: 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?  

---

