Package: gaiadr3
Author:Behrouz SafariWebsite:AstroDataScience.Netgaiadr3Retrieve data and analysis package for Gaia Data Release 3InstallationInstall the latest version ofgaiadr3fromPyPI:pip install gaiadr3The only requirement ispandas.BackgroundGaia Data Release 3 presents two main types of data:tabularandancillary.
The tabular data can be retrieved using ADQL Tap queries and are described in theData ModelThe ancillary data are those that can not be accessed via ADQL Tap queries. Epoch photomerty and spectroscopic data are of this type.
You need to use DataLink to retrieve this type of data.Tap queriesThe standard way to retrieve tabular data is by using tap queries. Pass your script to thesql2dffunction. It will return two pandas dataframes: data and meta.>>>fromgaiadr3importsql2df>>>data,meta=sql2df('SELECT TOP 5 source_id, ra, dec FROM gaiadr3.gaia_source')>>>print(meta)descriptionunitnamesource_idUniquesourceidentifier(uniquewithinapart...NoneraRightascensiondegdecDeclinationdeg>>>print(data)source_idradec04116903625596296576266.323047-22.65107714116903625596299136266.321568-22.65183324116903625596302976266.320308-22.65267234116903625596305408266.321332-22.65137944116903625596305536266.321399-22.651430For ease of use, I have created some shortcut keywords which begin with '@'. Currently, they are:@MT : Main Table (gaiadr3.gaia_source)@LT : Lite Table (gaiadr3.gaia_source_lite)@COLS : A selection of the most important columns>>>data,meta=sql2df('SELECT TOP 3 @COLS FROM @MT')>>>datasource_idra...has_mcmc_gspphothas_mcmc_msc04116903625596296576266.323047...FalseFalse14116903625596299136266.321568...FalseFalse24116903625596302976266.320308...FalseFalse[3rowsx24columns]Get single sourceThe simplest way to get data for a single source, is usingGaiaObjectclass. You can create an instance of this class by passing asource_id:>>>fromgaiadr3importGaiaObject>>>source_id=30343944744320>>>obj=GaiaObject(source_id=source_id)Now you can use thedownloadmethod to retrieve both tabular and ancillary. This method accepts two boolean arguments:key_paramandancillary.
Both are True by default. After using this method, some important key parameter will be downloaded as a python dictionary in thekey_paramattribute.>>>obj.download()>>>print(obj.key_param['data']){'solution_id':1636148068921376768,'ra':45.09499151004629,'dec':0.4768361311353548,'parallax':1.120139133994462,'distance_gspphot':913.4706,'pm':19.76517,'pmra':19.35330019571839,'pmdec':4.013937591116442,'radial_velocity':40.224552,'teff_gspphot':12291.837,'logg_gspphot':4.0962,'phot_g_mean_mag':9.899,'phot_bp_mean_mag':9.873377,'phot_rp_mean_mag':9.918395,'phot_g_mean_flux':2067028.6966188122,'phot_bp_mean_flux':1534850.5584509764,'phot_rp_mean_flux':854673.6713712276,'has_epoch_photometry':True,'has_epoch_rv':False,'has_rvs':True,'has_xp_continuous':True,'has_xp_sampled':True,'has_mcmc_gspphot':True,'has_mcmc_msc':True}If you don't know what are these parameters, look atobj.key_param['meta'].The ancillary data will be downloaded as csv files in the 'data' folder in the working directory. These data, if exist, can be accessed as attributes:>>>print(obj.xp_samp)wavelengthfluxflux_error0336.07.519030e-158.592673e-161338.06.699424e-157.309379e-162340.05.937778e-156.685453e-163342.05.614390e-156.325656e-164344.05.726218e-156.402061e-16...........3381012.05.449369e-166.181877e-173391014.05.333555e-166.771072e-173401016.05.501445e-167.086527e-173411018.05.647527e-166.731273e-173421020.06.096352e-166.407823e-17[343rowsx3columns]Attributes corresponding to the ancillary data are:ep_phot,rvs,xp_samp,xp_cont. Use thehasattribute to see which of these are available.>>>print(obj.has){'EPOCH_PHOTOMETRY':True,'RVS':True,'XP_CONTINUOUS':True,'XP_SAMPLED':True,'MCMC_GSPPHOT':True,'MCMC_MSC':True}Get multiple sourcesIf you want to get ancillary data for multiple sources you should use DataLink class.>>>fromgaiadr3importDataLink>>>sources=[30343944744320,6196457933368101888]>>>dl=DataLink(source_id=sources,retrieval_type='ALL')>>>dl.download()By default, the data will be downloaded in 'data' folder in the working directory. For each object a folder will be created.
Using theget_objectsmethod, you can access each source as a GaiaObject as explained above.
Let's get the epoch photometry for green, blue and red bands for the first source:>>>objects=dl.get_objects()>>>g,b,r=objects[0].ep_phot>>>print(g)magfluxflux_errorTCB2014-09-0608:55:04.0771239.9106112.045042e+063983.5608442014-09-0610:41:40.7014099.9092722.047565e+063652.7922952014-12-2700:49:44.3651849.8909112.082487e+063175.2642092014-12-2702:36:15.6561669.8747712.113675e+064644.7324202015-01-1606:49:25.7788039.8837122.096341e+061828.4386782015-01-1608:35:59.4077739.8885412.087037e+062039.6189012015-02-1500:23:35.1483899.8646962.133381e+062924.8958162015-07-0719:46:09.4172329.8867472.090489e+062817.5814572015-08-0103:31:05.1475579.9224562.022854e+063171.9643692015-08-3003:21:11.6679369.8800552.103414e+06977.9452502016-01-0513:57:07.7393509.8802962.102947e+061754.4463622016-01-0515:43:39.1016259.8781652.107079e+061487.1121582016-01-3101:44:44.4228839.9191682.028988e+061516.9050392016-02-2503:16:43.0720889.9232052.021458e+062363.9311312016-07-1708:55:16.8733929.9054612.054766e+063400.4211582016-07-1710:41:51.8541959.9094432.047244e+061766.9530202016-08-1514:44:12.4323379.9049042.055821e+061543.5655922016-09-0814:45:34.4796899.8978312.069257e+062292.7320392016-09-0816:32:08.4061439.8866402.090695e+064654.8391122017-01-1421:05:28.3526749.9262622.015774e+061613.0078482017-01-1422:52:01.9249159.9093252.047467e+063051.2877802017-02-1310:01:27.4490799.9202222.027019e+061790.1276332017-02-1311:48:01.0241779.9266332.015085e+063115.3796302017-03-0521:57:47.8044859.8866282.090718e+061692.9445912017-03-0523:44:23.3990459.8779532.107490e+064360.998681See more atastrodatascience.net