Long story short: I want to plot Gaia astrometry data to TESS imagery in Python. How is it possible? See below for elaborated version.
I have 64x64 pixel TESS
Really nice example. Just to mention that you can also integrate the query to the Gaia archive by using the astroquery.gaia module included in astropy
https://astroquery.readthedocs.io/en/latest/gaia/gaia.html
In this way, you will be able to run the same queries that are inside the Gaia archive UI and change to different sources in an easier way
from astroquery.simbad import Simbad
import astropy.units as u
from astropy.coordinates import SkyCoord
from astroquery.gaia import Gaia
result_table = Simbad.query_object("Gaia DR2 4687500098271761792")
raValue = result_table['RA']
decValue = result_table['DEC']
coord = SkyCoord(ra=raValue, dec=decValue, unit=(u.hour, u.degree), frame='icrs')
query = """SELECT TOP 1000 * FROM gaiadr2.gaia_source
WHERE CONTAINS(POINT('ICRS',gaiadr2.gaia_source.ra,gaiadr2.gaia_source.dec),
CIRCLE('ICRS',{ra},{dec},0.2777777777777778))=1 ORDER BY random_index""".format(ra=str(coord.ra.deg[0]),dec=str(coord.dec.deg[0]))
job = Gaia.launch_job_async(query)
r = job.get_results()
ralist = r['ra'].tolist()
declist = r['dec'].tolist()
import matplotlib.pyplot as plt
plt.scatter(ralist,declist,marker='+')
plt.show()
Please notice I have added the order by random_index that will eliminate this strange non-circular behaviour. This index is quite useful to do not force the full output for initial tests.
Also, I have declared the coordinates output for the right ascension from Simbad as hours.
Finally, I have used the asynchronous query that has less limitations in execution time and maximum rows in the response.
You can also change the query to
query = """SELECT * FROM gaiadr2.gaia_source
WHERE CONTAINS(POINT('ICRS',gaiadr2.gaia_source.ra,gaiadr2.gaia_source.dec),
CIRCLE('ICRS',{ra},{dec},0.2777777777777778))=1""".format(ra=str(coord.ra.deg[0]),dec=str(coord.dec.deg[0]))
(removing the limitation to 1000 rows) (in this case, the use of the random index is not necessary) to have a full response from the server.
Of course, this query takes some time to be executed (around 1.5 minutes). The full query will return 103574 rows.