mirror of
https://github.com/AllenDowney/AstronomicalData.git
synced 2026-07-28 14:47:02 -07:00
64 KiB
64 KiB
In [1]:
# If we're running on Colab, install libraries
import sys
IN_COLAB = 'google.colab' in sys.modules
if IN_COLAB:
!pip install astroquery astro-gala pyiaIn [2]:
from astroquery.gaia import GaiaCreated TAP+ (v1.2.1) - Connection: Host: gea.esac.esa.int Use HTTPS: True Port: 443 SSL Port: 443 Created TAP+ (v1.2.1) - Connection: Host: geadata.esac.esa.int Use HTTPS: True Port: 443 SSL Port: 443
In [3]:
tables = Gaia.load_tables(only_names=True)INFO: Retrieving tables... [astroquery.utils.tap.core] INFO: Parsing tables... [astroquery.utils.tap.core] INFO: Done. [astroquery.utils.tap.core]
In [4]:
for table in (tables):
print(table.get_qualified_name())external.external.apassdr9 external.external.gaiadr2_geometric_distance external.external.galex_ais external.external.ravedr5_com external.external.ravedr5_dr5 external.external.ravedr5_gra external.external.ravedr5_on external.external.sdssdr13_photoprimary external.external.skymapperdr1_master external.external.tmass_xsc public.public.hipparcos public.public.hipparcos_newreduction public.public.hubble_sc public.public.igsl_source public.public.igsl_source_catalog_ids public.public.tycho2 public.public.dual tap_config.tap_config.coord_sys tap_config.tap_config.properties tap_schema.tap_schema.columns tap_schema.tap_schema.key_columns tap_schema.tap_schema.keys tap_schema.tap_schema.schemas tap_schema.tap_schema.tables gaiadr1.gaiadr1.aux_qso_icrf2_match gaiadr1.gaiadr1.ext_phot_zero_point gaiadr1.gaiadr1.allwise_best_neighbour gaiadr1.gaiadr1.allwise_neighbourhood gaiadr1.gaiadr1.gsc23_best_neighbour gaiadr1.gaiadr1.gsc23_neighbourhood gaiadr1.gaiadr1.ppmxl_best_neighbour gaiadr1.gaiadr1.ppmxl_neighbourhood gaiadr1.gaiadr1.sdss_dr9_best_neighbour gaiadr1.gaiadr1.sdss_dr9_neighbourhood gaiadr1.gaiadr1.tmass_best_neighbour gaiadr1.gaiadr1.tmass_neighbourhood gaiadr1.gaiadr1.ucac4_best_neighbour gaiadr1.gaiadr1.ucac4_neighbourhood gaiadr1.gaiadr1.urat1_best_neighbour gaiadr1.gaiadr1.urat1_neighbourhood gaiadr1.gaiadr1.cepheid gaiadr1.gaiadr1.phot_variable_time_series_gfov gaiadr1.gaiadr1.phot_variable_time_series_gfov_statistical_parameters gaiadr1.gaiadr1.rrlyrae gaiadr1.gaiadr1.variable_summary gaiadr1.gaiadr1.allwise_original_valid gaiadr1.gaiadr1.gsc23_original_valid gaiadr1.gaiadr1.ppmxl_original_valid gaiadr1.gaiadr1.sdssdr9_original_valid gaiadr1.gaiadr1.tmass_original_valid gaiadr1.gaiadr1.ucac4_original_valid gaiadr1.gaiadr1.urat1_original_valid gaiadr1.gaiadr1.gaia_source gaiadr1.gaiadr1.tgas_source gaiadr2.gaiadr2.aux_allwise_agn_gdr2_cross_id gaiadr2.gaiadr2.aux_iers_gdr2_cross_id gaiadr2.gaiadr2.aux_sso_orbit_residuals gaiadr2.gaiadr2.aux_sso_orbits gaiadr2.gaiadr2.dr1_neighbourhood gaiadr2.gaiadr2.allwise_best_neighbour gaiadr2.gaiadr2.allwise_neighbourhood gaiadr2.gaiadr2.apassdr9_best_neighbour gaiadr2.gaiadr2.apassdr9_neighbourhood gaiadr2.gaiadr2.gsc23_best_neighbour gaiadr2.gaiadr2.gsc23_neighbourhood gaiadr2.gaiadr2.hipparcos2_best_neighbour gaiadr2.gaiadr2.hipparcos2_neighbourhood gaiadr2.gaiadr2.panstarrs1_best_neighbour gaiadr2.gaiadr2.panstarrs1_neighbourhood gaiadr2.gaiadr2.ppmxl_best_neighbour gaiadr2.gaiadr2.ppmxl_neighbourhood gaiadr2.gaiadr2.ravedr5_best_neighbour gaiadr2.gaiadr2.ravedr5_neighbourhood gaiadr2.gaiadr2.sdssdr9_best_neighbour gaiadr2.gaiadr2.sdssdr9_neighbourhood gaiadr2.gaiadr2.tmass_best_neighbour gaiadr2.gaiadr2.tmass_neighbourhood gaiadr2.gaiadr2.tycho2_best_neighbour gaiadr2.gaiadr2.tycho2_neighbourhood gaiadr2.gaiadr2.urat1_best_neighbour gaiadr2.gaiadr2.urat1_neighbourhood gaiadr2.gaiadr2.sso_observation gaiadr2.gaiadr2.sso_source gaiadr2.gaiadr2.vari_cepheid gaiadr2.gaiadr2.vari_classifier_class_definition gaiadr2.gaiadr2.vari_classifier_definition gaiadr2.gaiadr2.vari_classifier_result gaiadr2.gaiadr2.vari_long_period_variable gaiadr2.gaiadr2.vari_rotation_modulation gaiadr2.gaiadr2.vari_rrlyrae gaiadr2.gaiadr2.vari_short_timescale gaiadr2.gaiadr2.vari_time_series_statistics gaiadr2.gaiadr2.panstarrs1_original_valid gaiadr2.gaiadr2.gaia_source gaiadr2.gaiadr2.ruwe
In [5]:
meta = Gaia.load_table('gaiadr2.gaia_source')
metaOut [5]:
Retrieving table 'gaiadr2.gaia_source' Parsing table 'gaiadr2.gaia_source'... Done.
<astroquery.utils.tap.model.taptable.TapTableMeta at 0x7f922376e0a0>
In [6]:
print(meta)TAP Table name: gaiadr2.gaiadr2.gaia_source Description: This table has an entry for every Gaia observed source as listed in the Main Database accumulating catalogue version from which the catalogue release has been generated. It contains the basic source parameters, that is only final data (no epoch data) and no spectra (neither final nor epoch). Num. columns: 96
In [7]:
for column in meta.columns:
print(column.name)solution_id designation source_id random_index ref_epoch ra ra_error dec dec_error parallax parallax_error parallax_over_error pmra pmra_error pmdec pmdec_error ra_dec_corr ra_parallax_corr ra_pmra_corr ra_pmdec_corr dec_parallax_corr dec_pmra_corr dec_pmdec_corr parallax_pmra_corr parallax_pmdec_corr pmra_pmdec_corr astrometric_n_obs_al astrometric_n_obs_ac astrometric_n_good_obs_al astrometric_n_bad_obs_al astrometric_gof_al astrometric_chi2_al astrometric_excess_noise astrometric_excess_noise_sig astrometric_params_solved astrometric_primary_flag astrometric_weight_al astrometric_pseudo_colour astrometric_pseudo_colour_error mean_varpi_factor_al astrometric_matched_observations visibility_periods_used astrometric_sigma5d_max frame_rotator_object_type matched_observations duplicated_source phot_g_n_obs phot_g_mean_flux phot_g_mean_flux_error phot_g_mean_flux_over_error phot_g_mean_mag phot_bp_n_obs phot_bp_mean_flux phot_bp_mean_flux_error phot_bp_mean_flux_over_error phot_bp_mean_mag phot_rp_n_obs phot_rp_mean_flux phot_rp_mean_flux_error phot_rp_mean_flux_over_error phot_rp_mean_mag phot_bp_rp_excess_factor phot_proc_mode bp_rp bp_g g_rp radial_velocity radial_velocity_error rv_nb_transits rv_template_teff rv_template_logg rv_template_fe_h phot_variable_flag l b ecl_lon ecl_lat priam_flags teff_val teff_percentile_lower teff_percentile_upper a_g_val a_g_percentile_lower a_g_percentile_upper e_bp_min_rp_val e_bp_min_rp_percentile_lower e_bp_min_rp_percentile_upper flame_flags radius_val radius_percentile_lower radius_percentile_upper lum_val lum_percentile_lower lum_percentile_upper datalink_url epoch_photometry_url
In [8]:
# Solution
meta2 = Gaia.load_table('gaiadr2.panstarrs1_original_valid')
print(meta2)Retrieving table 'gaiadr2.panstarrs1_original_valid' Parsing table 'gaiadr2.panstarrs1_original_valid'... Done. TAP Table name: gaiadr2.gaiadr2.panstarrs1_original_valid Description: The Panoramic Survey Telescope and Rapid Response System (Pan-STARRS) is a system for wide-field astronomical imaging developed and operated by the Institute for Astronomy at the University of Hawaii. Pan-STARRS1 (PS1) is the first part of Pan-STARRS to be completed and is the basis for Data Release 1 (DR1). The PS1 survey used a 1.8 meter telescope and its 1.4 Gigapixel camera to image the sky in five broadband filters (g, r, i, z, y). The current table contains a filtered subsample of the 10 723 304 629 entries listed in the original ObjectThin table. We used only ObjectThin and MeanObject tables to extract panstarrs1OriginalValid table, this means that objects detected only in stack images are not included here. The main reason for us to avoid the use of objects detected in stack images is that their astrometry is not as good as the mean objects astrometry: “The stack positions (raStack, decStack) have considerably larger systematic astrometric errors than the mean epoch positions (raMean, decMean).” The astrometry for the MeanObject positions uses Gaia DR1 as a reference catalog, while the stack positions use 2MASS as a reference catalog. In details, we filtered out all objects where: - nDetections = 1 - no good quality data in Pan-STARRS, objInfoFlag 33554432 not set - mean astrometry could not be measured, objInfoFlag 524288 set - stack position used for mean astrometry, objInfoFlag 1048576 set - error on all magnitudes equal to 0 or to -999; - all magnitudes set to -999; - error on RA or DEC greater than 1 arcsec. The number of objects in panstarrs1OriginalValid is 2 264 263 282. The panstarrs1OriginalValid table contains only a subset of the columns available in the combined ObjectThin and MeanObject tables. A description of the original ObjectThin and MeanObjects tables can be found at: https://outerspace.stsci.edu/display/PANSTARRS/PS1+Database+object+and+detection+tables Download: http://mastweb.stsci.edu/ps1casjobs/home.aspx Documentation: https://outerspace.stsci.edu/display/PANSTARRS http://pswww.ifa.hawaii.edu/pswww/ References: The Pan-STARRS1 Surveys, Chambers, K.C., et al. 2016, arXiv:1612.05560 Pan-STARRS Data Processing System, Magnier, E. A., et al. 2016, arXiv:1612.05240 Pan-STARRS Pixel Processing: Detrending, Warping, Stacking, Waters, C. Z., et al. 2016, arXiv:1612.05245 Pan-STARRS Pixel Analysis: Source Detection and Characterization, Magnier, E. A., et al. 2016, arXiv:1612.05244 Pan-STARRS Photometric and Astrometric Calibration, Magnier, E. A., et al. 2016, arXiv:1612.05242 The Pan-STARRS1 Database and Data Products, Flewelling, H. A., et al. 2016, arXiv:1612.05243 Catalogue curator: SSDC - ASI Space Science Data Center https://www.ssdc.asi.it/ Num. columns: 26
In [9]:
# Solution
for column in meta2.columns:
print(column.name)obj_name obj_id ra dec ra_error dec_error epoch_mean g_mean_psf_mag g_mean_psf_mag_error g_flags r_mean_psf_mag r_mean_psf_mag_error r_flags i_mean_psf_mag i_mean_psf_mag_error i_flags z_mean_psf_mag z_mean_psf_mag_error z_flags y_mean_psf_mag y_mean_psf_mag_error y_flags n_detections zone_id obj_info_flag quality_flag
In [10]:
query1 = """SELECT
TOP 10
source_id, ref_epoch, ra, dec, parallax
FROM gaiadr2.gaia_source"""In [11]:
job1 = Gaia.launch_job(query1)
job1Out [11]:
<astroquery.utils.tap.model.job.Job at 0x7f9222e9cb20>
In [12]:
print(job1)<Table length=10>
name dtype unit description
--------- ------- ---- ------------------------------------------------------------------
source_id int64 Unique source identifier (unique within a particular Data Release)
ref_epoch float64 yr Reference epoch
ra float64 deg Right ascension
dec float64 deg Declination
parallax float64 mas Parallax
Jobid: None
Phase: COMPLETED
Owner: None
Output file: sync_20201005090721.xml.gz
Results: None
In [13]:
results1 = job1.get_results()
type(results1)Out [13]:
astropy.table.table.Table
In [14]:
results1Out [14]:
Table length=10
| source_id | ref_epoch | ra | dec | parallax |
|---|---|---|---|---|
| yr | deg | deg | mas | |
| int64 | float64 | float64 | float64 | float64 |
| 4530738361793769600 | 2015.5 | 281.56725362448725 | 20.40682117430378 | 0.9785380604519425 |
| 4530752651135081216 | 2015.5 | 281.0861565355257 | 20.523350496351846 | 0.2674800612552977 |
| 4530743343951405568 | 2015.5 | 281.37114418299177 | 20.474147574053124 | -0.43911323550176806 |
| 4530755060627162368 | 2015.5 | 281.2676236268299 | 20.558523922346158 | 1.1422630184554958 |
| 4530746844341315968 | 2015.5 | 281.1370431749541 | 20.377852388898184 | 1.0092247424630945 |
| 4530768456615026432 | 2015.5 | 281.8720921436347 | 20.31829694530366 | -0.06900136127674149 |
| 4530763513119137280 | 2015.5 | 281.9211808864116 | 20.20956829578524 | 0.1266016679823622 |
| 4530736364618539264 | 2015.5 | 281.4913475613274 | 20.346579041327693 | 0.3894019486060072 |
| 4530735952305177728 | 2015.5 | 281.4085549165704 | 20.311030903719928 | 0.2041189982608354 |
| 4530751281056022656 | 2015.5 | 281.0585328377638 | 20.460309556214753 | 0.10294642821734962 |
In [15]:
query2 = """SELECT TOP 3000
source_id, ref_epoch, ra, dec, parallax
FROM gaiadr2.gaia_source
WHERE parallax < 1
"""In [16]:
job2 = Gaia.launch_job_async(query2)
print(job2)INFO: Query finished. [astroquery.utils.tap.core]
<Table length=3000>
name dtype unit description
--------- ------- ---- ------------------------------------------------------------------
source_id int64 Unique source identifier (unique within a particular Data Release)
ref_epoch float64 yr Reference epoch
ra float64 deg Right ascension
dec float64 deg Declination
parallax float64 mas Parallax
Jobid: 1601903242219O
Phase: COMPLETED
Owner: None
Output file: async_20201005090722.vot
Results: None
In [17]:
results2 = job2.get_results()
results2Out [17]:
Table length=3000
| source_id | ref_epoch | ra | dec | parallax |
|---|---|---|---|---|
| yr | deg | deg | mas | |
| int64 | float64 | float64 | float64 | float64 |
| 4530738361793769600 | 2015.5 | 281.56725362448725 | 20.40682117430378 | 0.9785380604519425 |
| 4530752651135081216 | 2015.5 | 281.0861565355257 | 20.523350496351846 | 0.2674800612552977 |
| 4530743343951405568 | 2015.5 | 281.37114418299177 | 20.474147574053124 | -0.43911323550176806 |
| 4530768456615026432 | 2015.5 | 281.8720921436347 | 20.31829694530366 | -0.06900136127674149 |
| 4530763513119137280 | 2015.5 | 281.9211808864116 | 20.20956829578524 | 0.1266016679823622 |
| 4530736364618539264 | 2015.5 | 281.4913475613274 | 20.346579041327693 | 0.3894019486060072 |
| 4530735952305177728 | 2015.5 | 281.4085549165704 | 20.311030903719928 | 0.2041189982608354 |
| 4530751281056022656 | 2015.5 | 281.0585328377638 | 20.460309556214753 | 0.10294642821734962 |
| 4530740938774409344 | 2015.5 | 281.3762569536416 | 20.436140058941206 | 0.9242670062090182 |
| ... | ... | ... | ... | ... |
| 4467710915011802624 | 2015.5 | 269.9680969307347 | 1.1429085038160882 | 0.42361471245557913 |
| 4467706551328679552 | 2015.5 | 270.033164589881 | 1.0565747323689927 | 0.922888231734588 |
| 4467712255037300096 | 2015.5 | 270.7724717923047 | 0.6581664892880896 | -2.669179465293931 |
| 4467735001181761792 | 2015.5 | 270.3628606248308 | 0.8947079323599124 | 0.6117399163086398 |
| 4467737101421916672 | 2015.5 | 270.5110834661444 | 0.9806225910160181 | -0.39818224846127004 |
| 4467707547757327488 | 2015.5 | 269.88746280594927 | 1.0212759940136962 | 0.7741412301054209 |
| 4467732772094573056 | 2015.5 | 270.55997182760126 | 0.9037072088489417 | -1.7920417800164183 |
| 4467732355491087744 | 2015.5 | 270.6730790702491 | 0.9197224705139885 | -0.3464446494840354 |
| 4467717099766944512 | 2015.5 | 270.57667173120825 | 0.726277659009568 | 0.05443955111134051 |
| 4467719058265781248 | 2015.5 | 270.7248052971514 | 0.8205551921782785 | 0.3733943917490343 |
In [18]:
# Solution
# This is what most people will probably do
query = """SELECT TOP 10
source_id, ref_epoch, ra, dec, parallax
FROM gaiadr2.gaia_source
WHERE parallax < 1
AND bp_rp > -0.75 AND bp_rp < 2
"""In [19]:
# Solution
# But if someone notices the BETWEEN operator,
# they might do this
query = """SELECT TOP 10
source_id, ref_epoch, ra, dec, parallax
FROM gaiadr2.gaia_source
WHERE parallax < 1
AND bp_rp BETWEEN -0.75 AND 2
"""In [20]:
job1.jobid, job2.jobidOut [20]:
(None, '1601903242219O')
In [21]:
Gaia.remove_jobs([job2.jobid])Removed jobs: '['1601903242219O']'.
In [22]:
columns = 'source_id, ra, dec, pmra, pmdec, parallax, parallax_error, radial_velocity'In [23]:
query3_base = """SELECT TOP 10
{columns}
FROM gaiadr2.gaia_source
WHERE parallax < 1
AND bp_rp BETWEEN -0.75 AND 2
"""In [24]:
query3 = query3_base.format(columns=columns)In [25]:
query3Out [25]:
'SELECT TOP 10 \nsource_id, ra, dec, pmra, pmdec, parallax, parallax_error, radial_velocity\nFROM gaiadr2.gaia_source\nWHERE parallax < 1\n AND bp_rp BETWEEN -0.75 AND 2\n'
In [26]:
print(query3)SELECT TOP 10 source_id, ra, dec, pmra, pmdec, parallax, parallax_error, radial_velocity FROM gaiadr2.gaia_source WHERE parallax < 1 AND bp_rp BETWEEN -0.75 AND 2
In [27]:
job3 = Gaia.launch_job(query3)
print(job3)<Table length=10>
name dtype unit description n_bad
--------------- ------- -------- ------------------------------------------------------------------ -----
source_id int64 Unique source identifier (unique within a particular Data Release) 0
ra float64 deg Right ascension 0
dec float64 deg Declination 0
pmra float64 mas / yr Proper motion in right ascension direction 0
pmdec float64 mas / yr Proper motion in declination direction 0
parallax float64 mas Parallax 0
parallax_error float64 mas Standard error of parallax 0
radial_velocity float64 km / s Radial velocity 10
Jobid: None
Phase: COMPLETED
Owner: None
Output file: sync_20201005090726.xml.gz
Results: None
In [28]:
results3 = job3.get_results()
results3Out [28]:
Table length=10
| source_id | ra | dec | pmra | pmdec | parallax | parallax_error | radial_velocity |
|---|---|---|---|---|---|---|---|
| deg | deg | mas / yr | mas / yr | mas | mas | km / s | |
| int64 | float64 | float64 | float64 | float64 | float64 | float64 | float64 |
| 4467710915011802624 | 269.9680969307347 | 1.1429085038160882 | 2.0233280236600626 | -2.5692427875510266 | 0.42361471245557913 | 0.470352406647465 | -- |
| 4467706551328679552 | 270.033164589881 | 1.0565747323689927 | -3.414829591355289 | -3.8437215857495737 | 0.922888231734588 | 0.927008559859825 | -- |
| 4467712255037300096 | 270.7724717923047 | 0.6581664892880896 | -3.5620173752896025 | -6.595792323153987 | -2.669179465293931 | 0.9719742773203504 | -- |
| 4467735001181761792 | 270.3628606248308 | 0.8947079323599124 | 2.1307079926489205 | 0.8826727710910712 | 0.6117399163086398 | 0.509812721702093 | -- |
| 4467737101421916672 | 270.5110834661444 | 0.9806225910160181 | 0.17532366511560785 | -5.113270239706202 | -0.39818224846127004 | 0.7549581886719651 | -- |
| 4467707547757327488 | 269.88746280594927 | 1.0212759940136962 | -2.6382230817672987 | -3.707776532049287 | 0.7741412301054209 | 0.3022057897812064 | -- |
| 4467732355491087744 | 270.6730790702491 | 0.9197224705139885 | -2.2735991502653037 | -11.864952855984358 | -0.3464446494840354 | 0.4937921513912002 | -- |
| 4467717099766944512 | 270.57667173120825 | 0.726277659009568 | -3.4598362614808367 | -4.601426893365921 | 0.05443955111134051 | 0.8867339293525688 | -- |
| 4467719058265781248 | 270.7248052971514 | 0.8205551921782785 | -3.255079498426542 | -9.249285069111085 | 0.3733943917490343 | 0.390952370410666 | -- |
| 4467722326741572352 | 270.87431291888504 | 0.8595565975869158 | 0.10696398351859826 | 1.2035993780158853 | -0.11850943432864373 | 0.1660452431882023 | -- |
In [29]:
# Solution
query4_base = """SELECT TOP 10
{columns}
FROM gaiadr2.gaia_source
WHERE parallax < {max_parallax} AND
bp_rp BETWEEN -0.75 AND 2
"""In [30]:
# Solution
query4 = query4_base.format(columns=columns,
max_parallax=0.5)
print(query)SELECT TOP 10 source_id, ra, dec, pmra, pmdec, parallax, parallax_error, radial_velocity FROM gaiadr2.gaia_source WHERE parallax < 0.5 AND bp_rp BETWEEN -0.75 AND 2
Cell:
[Cell type raw - unsupported, skipped]