From 896aa6bd3567ed3a3fbf40829d91a79c2d9dfcde Mon Sep 17 00:00:00 2001 From: Allen Downey Date: Mon, 30 Aug 2021 14:35:02 -0400 Subject: [PATCH] Update documentation --- 01_query.html | 607 +++++++++++++- 02_coords.html | 1287 ++++++++++++++++++++++++++++- 03_motion.html | 449 +++++++++- 04_select.html | 169 +++- 05_join.html | 752 ++++++++++++++++- 06_photo.html | 371 +++++++++ 07_plot.html | 194 ++++- _images/04_select_16_0.png | Bin 0 -> 83706 bytes _images/04_select_18_0.png | Bin 0 -> 82031 bytes _images/04_select_31_0.png | Bin 80696 -> 80696 bytes _images/04_select_68_0.png | Bin 42357 -> 36712 bytes _images/04_select_74_0.png | Bin 0 -> 42357 bytes _images/05_join_72_0.png | Bin 0 -> 26285 bytes _images/06_photo_12_0.png | Bin 0 -> 21883 bytes _images/06_photo_42_0.png | Bin 0 -> 26457 bytes _images/06_photo_52_0.png | Bin 0 -> 26457 bytes _images/06_photo_62_0.png | Bin 0 -> 26589 bytes _images/06_photo_70_0.png | Bin 0 -> 25493 bytes _images/06_photo_91_0.png | Bin 0 -> 30794 bytes _images/06_photo_93_0.png | Bin 0 -> 9687 bytes _images/07_plot_13_0.png | Bin 0 -> 17905 bytes _images/07_plot_53_0.png | Bin 0 -> 153493 bytes _images/07_plot_59_0.png | Bin 0 -> 42716 bytes _images/07_plot_63_0.png | Bin 0 -> 37856 bytes _images/07_plot_69_0.png | Bin 0 -> 141913 bytes _images/07_plot_72_0.png | Bin 0 -> 131686 bytes _sources/01_query.ipynb | 825 ++++++++++++++++++- _sources/02_coords.ipynb | 1588 +++++++++++++++++++++++++++++++++++- _sources/03_motion.ipynb | 862 ++++++++++++++++++- _sources/04_select.ipynb | 350 +++++++- _sources/05_join.ipynb | 1264 +++++++++++++++++++++++++++- _sources/06_photo.ipynb | 722 +++++++++++++++- _sources/07_plot.ipynb | 332 +++++++- searchindex.js | 2 +- 34 files changed, 9432 insertions(+), 342 deletions(-) create mode 100644 _images/04_select_16_0.png create mode 100644 _images/04_select_18_0.png create mode 100644 _images/04_select_74_0.png create mode 100644 _images/05_join_72_0.png create mode 100644 _images/06_photo_12_0.png create mode 100644 _images/06_photo_42_0.png create mode 100644 _images/06_photo_52_0.png create mode 100644 _images/06_photo_62_0.png create mode 100644 _images/06_photo_70_0.png create mode 100644 _images/06_photo_91_0.png create mode 100644 _images/06_photo_93_0.png create mode 100644 _images/07_plot_13_0.png create mode 100644 _images/07_plot_53_0.png create mode 100644 _images/07_plot_59_0.png create mode 100644 _images/07_plot_63_0.png create mode 100644 _images/07_plot_69_0.png create mode 100644 _images/07_plot_72_0.png diff --git a/01_query.html b/01_query.html index d6d7f3c..88dff0f 100644 --- a/01_query.html +++ b/01_query.html @@ -253,11 +253,6 @@ Using Jupyter -
  • - - Installing libraries - -
  • Connecting to Gaia @@ -396,24 +391,6 @@ But you might find it easier to learn from -

    Installing libraries

    -

    If you are running this notebook on Colab, you should run the following cell to install the libraries we’ll need.

    -

    If you are running this notebook on your own computer, you might have to install these libraries yourself.

    -
    -
    -
    # If we're running on Colab, install libraries
    -
    -import sys
    -IN_COLAB = 'google.colab' in sys.modules
    -
    -if IN_COLAB:
    -    !pip install astroquery
    -
    -
    -
    -
    -

    Connecting to Gaia

    The library we’ll use to get Gaia data is Astroquery. @@ -425,6 +402,20 @@ Astroquery provides

    +
    +
    Created 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
    +
    +
    +

    This import statement creates a TAP+ connection; TAP stands for “Table Access Protocol”, which is a network protocol for sending queries to the database and getting back the results.

    @@ -442,15 +433,160 @@ Astroquery provides +
    +
    INFO: Retrieving tables... [astroquery.utils.tap.core]
    +INFO: Parsing tables... [astroquery.utils.tap.core]
    +INFO: Done. [astroquery.utils.tap.core]
    +
    +
    +

    The following for loop prints the names of the tables.

    -
    +
    for table in tables:
         print(table.name)
     
    +
    +
    external.apassdr9
    +external.gaiadr2_geometric_distance
    +external.gaiaedr3_distance
    +external.galex_ais
    +external.ravedr5_com
    +external.ravedr5_dr5
    +external.ravedr5_gra
    +external.ravedr5_on
    +external.sdssdr13_photoprimary
    +external.skymapperdr1_master
    +external.skymapperdr2_master
    +external.tmass_xsc
    +public.hipparcos
    +public.hipparcos_newreduction
    +public.hubble_sc
    +public.igsl_source
    +public.igsl_source_catalog_ids
    +public.tycho2
    +public.dual
    +tap_config.coord_sys
    +tap_config.properties
    +tap_schema.columns
    +tap_schema.key_columns
    +tap_schema.keys
    +tap_schema.schemas
    +tap_schema.tables
    +gaiaedr3.gaia_source
    +gaiaedr3.agn_cross_id
    +gaiaedr3.commanded_scan_law
    +gaiaedr3.dr2_neighbourhood
    +gaiaedr3.frame_rotator_source
    +gaiaedr3.allwise_best_neighbour
    +gaiaedr3.allwise_neighbourhood
    +gaiaedr3.apassdr9_best_neighbour
    +gaiaedr3.apassdr9_join
    +gaiaedr3.apassdr9_neighbourhood
    +gaiaedr3.gsc23_best_neighbour
    +gaiaedr3.gsc23_join
    +gaiaedr3.gsc23_neighbourhood
    +gaiaedr3.hipparcos2_best_neighbour
    +gaiaedr3.hipparcos2_neighbourhood
    +gaiaedr3.panstarrs1_best_neighbour
    +gaiaedr3.panstarrs1_join
    +gaiaedr3.panstarrs1_neighbourhood
    +gaiaedr3.ravedr5_best_neighbour
    +gaiaedr3.ravedr5_join
    +gaiaedr3.ravedr5_neighbourhood
    +gaiaedr3.sdssdr13_best_neighbour
    +gaiaedr3.sdssdr13_join
    +gaiaedr3.sdssdr13_neighbourhood
    +gaiaedr3.skymapperdr2_best_neighbour
    +gaiaedr3.skymapperdr2_join
    +gaiaedr3.skymapperdr2_neighbourhood
    +gaiaedr3.tmass_psc_xsc_best_neighbour
    +gaiaedr3.tmass_psc_xsc_join
    +gaiaedr3.tmass_psc_xsc_neighbourhood
    +gaiaedr3.tycho2tdsc_merge_best_neighbour
    +gaiaedr3.tycho2tdsc_merge_neighbourhood
    +gaiaedr3.urat1_best_neighbour
    +gaiaedr3.urat1_neighbourhood
    +gaiaedr3.gaia_source_simulation
    +gaiaedr3.gaia_universe_model
    +gaiaedr3.tycho2tdsc_merge
    +gaiadr1.aux_qso_icrf2_match
    +gaiadr1.ext_phot_zero_point
    +gaiadr1.allwise_best_neighbour
    +gaiadr1.allwise_neighbourhood
    +gaiadr1.gsc23_best_neighbour
    +gaiadr1.gsc23_neighbourhood
    +gaiadr1.ppmxl_best_neighbour
    +gaiadr1.ppmxl_neighbourhood
    +gaiadr1.sdss_dr9_best_neighbour
    +gaiadr1.sdss_dr9_neighbourhood
    +gaiadr1.tmass_best_neighbour
    +gaiadr1.tmass_neighbourhood
    +gaiadr1.ucac4_best_neighbour
    +gaiadr1.ucac4_neighbourhood
    +gaiadr1.urat1_best_neighbour
    +gaiadr1.urat1_neighbourhood
    +gaiadr1.cepheid
    +gaiadr1.phot_variable_time_series_gfov
    +gaiadr1.phot_variable_time_series_gfov_statistical_parameters
    +gaiadr1.rrlyrae
    +gaiadr1.variable_summary
    +gaiadr1.allwise_original_valid
    +gaiadr1.gsc23_original_valid
    +gaiadr1.ppmxl_original_valid
    +gaiadr1.sdssdr9_original_valid
    +gaiadr1.tmass_original_valid
    +gaiadr1.ucac4_original_valid
    +gaiadr1.urat1_original_valid
    +gaiadr1.gaia_source
    +gaiadr1.tgas_source
    +gaiadr2.aux_allwise_agn_gdr2_cross_id
    +gaiadr2.aux_iers_gdr2_cross_id
    +gaiadr2.aux_sso_orbit_residuals
    +gaiadr2.aux_sso_orbits
    +gaiadr2.dr1_neighbourhood
    +gaiadr2.allwise_best_neighbour
    +gaiadr2.allwise_neighbourhood
    +gaiadr2.apassdr9_best_neighbour
    +gaiadr2.apassdr9_neighbourhood
    +gaiadr2.gsc23_best_neighbour
    +gaiadr2.gsc23_neighbourhood
    +gaiadr2.hipparcos2_best_neighbour
    +gaiadr2.hipparcos2_neighbourhood
    +gaiadr2.panstarrs1_best_neighbour
    +gaiadr2.panstarrs1_neighbourhood
    +gaiadr2.ppmxl_best_neighbour
    +gaiadr2.ppmxl_neighbourhood
    +gaiadr2.ravedr5_best_neighbour
    +gaiadr2.ravedr5_neighbourhood
    +gaiadr2.sdssdr9_best_neighbour
    +gaiadr2.sdssdr9_neighbourhood
    +gaiadr2.tmass_best_neighbour
    +gaiadr2.tmass_neighbourhood
    +gaiadr2.tycho2_best_neighbour
    +gaiadr2.tycho2_neighbourhood
    +gaiadr2.urat1_best_neighbour
    +gaiadr2.urat1_neighbourhood
    +gaiadr2.sso_observation
    +gaiadr2.sso_source
    +gaiadr2.vari_cepheid
    +gaiadr2.vari_classifier_class_definition
    +gaiadr2.vari_classifier_definition
    +gaiadr2.vari_classifier_result
    +gaiadr2.vari_long_period_variable
    +gaiadr2.vari_rotation_modulation
    +gaiadr2.vari_rrlyrae
    +gaiadr2.vari_short_timescale
    +gaiadr2.vari_time_series_statistics
    +gaiadr2.panstarrs1_original_valid
    +gaiadr2.gaia_source
    +gaiadr2.ruwe
    +
    +
    +

    So that’s a lot of tables. The ones we’ll use are:

      @@ -466,6 +602,16 @@ Astroquery provides
    +
    +
    Retrieving table 'gaiadr2.gaia_source'
    +Parsing table 'gaiadr2.gaia_source'...
    +Done.
    +
    +
    +
    <astroquery.utils.tap.model.taptable.TapTableMeta at 0x7f50edd2aeb0>
    +
    +
    +

    Jupyter shows that the result is an object of type TapTableMeta, but it does not display the contents.

    To see the metadata, we have to print the object.

    @@ -475,18 +621,129 @@ Astroquery provides +
    +
    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
    +
    +
    +

    Columns

    The following loop prints the names of the columns in the table.

    -
    +
    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
    +
    +
    +

    You can probably infer what many of these columns are by looking at the names, but you should resist the temptation to guess. To find out what the columns mean, read the documentation.

    @@ -496,7 +753,113 @@ To find out what the columns mean, gaiadr2.panstarrs1_original_valid
    . Use load_table to get the metadata for this table. How many columns are there and what are their names?

    -
    # Solution goes here
    +
    # Solution
    +
    +meta2 = Gaia.load_table('gaiadr2.panstarrs1_original_valid')
    +print(meta2)
    +
    +for column in meta2.columns:
    +    print(column.name)
    +
    +
    +
    +
    +
    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
    +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
     
    @@ -537,6 +900,11 @@ To find out what the columns mean,
    +
    <astroquery.utils.tap.model.job.Job at 0x7f50edd2adc0>
    +
    +
    +

    The result is an object that represents the job running on a Gaia server.

    If you print it, it displays metadata for the forthcoming results.

    @@ -546,6 +914,22 @@ To find out what the columns mean,
    +
    <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
    + parallax float64  mas                                                           Parallax     2
    +Jobid: None
    +Phase: COMPLETED
    +Owner: None
    +Output file: sync_20210315090602.xml.gz
    +Results: None
    +
    +
    +

    Don’t worry about Results: None. That does not actually mean there are no results.

    However, Phase: COMPLETED indicates that the job is complete, so we can get the results like this:

    @@ -556,6 +940,11 @@ To find out what the columns mean,
    +
    astropy.table.table.Table
    +
    +
    +

    The type function indicates that the result is an Astropy Table.

    Optional detail: Why is table repeated three times? The first is the name of the module, the second is the name of the submodule, and the third is the name of the class. Most of the time we only care about the last one. It’s like the Linnean name for gorilla, which is Gorilla gorilla gorilla.

    @@ -571,6 +960,23 @@ To find out what the columns mean, +
    Table length=10 + + + + + + + + + + + + + + +
    source_idradecparallax
    degdegmas
    int64float64float64float64
    5887983246081387776227.978818386372-53.649969624501031.0493172163332998
    5887971250213117952228.32280834041364-53.662707262037260.29455652682279093
    5887991866047288704228.1582047014091-53.454724911639794-0.5789179941669236
    5887968673232040832228.07420888099884-53.80646128959610.41030970779603076
    5887979844465854720228.42547805195946-53.48882284470035-0.23379683441525864
    5887978607515442688228.23831627636855-53.56328249482688-0.9252161956789068
    5887978298278520704228.26015640396173-53.607284412896476--
    5887995581231772928228.12871598211902-53.373625663608316-0.3325818206439385
    5887982043490374016227.985260087594-53.6834444990555750.02878111976456593
    5887982971205433856227.89884570686218-53.67430215342567--

    Each column has a name, units, and a data type.

    For example, the units of ra and dec are degrees, and their data type is float64, which is a 64-bit floating-point number, used to store measurements with a fraction part.

    @@ -580,7 +986,23 @@ To find out what the columns mean, the documentation of this table and choose a column that looks interesting to you. Add the column name to the query and run it again. What are the units of the column you selected? What is its data type?

    -
    # Solution goes here
    +
    # Solution
    +
    +# Let's add
    +#
    +# radial_velocity : Radial velocity (double, Velocity[km/s] )
    +#
    +# Spectroscopic radial velocity in the solar barycentric 
    +# reference frame.
    +#
    +# The radial velocity provided is the median value of the 
    +# radial velocity measurements at all epochs.
    +
    +query = """SELECT 
    +TOP 10
    +source_id, ra, dec, parallax, radial_velocity
    +FROM gaiadr2.gaia_source
    +"""
     
    @@ -622,6 +1044,14 @@ We’ll use this clause to exclude nearby stars that are unlikely to be part of
    +
    +
    INFO: Query finished. [astroquery.utils.tap.core]
    +
    +
    +
    <astroquery.utils.tap.model.job.Job at 0x7f50edd40f40>
    +
    +
    +

    And here are the results.

    @@ -631,6 +1061,23 @@ We’ll use this clause to exclude nearby stars that are unlikely to be part of
    +
    +
    Table length=10 + + + + + + + + + + + + + + +
    source_idradecparallaxradial_velocity
    degdegmaskm / s
    int64float64float64float64float64
    5895270396817359872213.08433715252883-56.641047010056942.041947005434917--
    5895272561481374080213.2606587905109-56.550444015357150.15693467895110133--
    5895247410183786368213.38479712976664-56.97008551185148-0.19017525742552605--
    5895249226912448000213.41587389088238-56.849596577635786----
    5895261875598904576213.5508930114549-56.61037780154348-0.29471722363529257--
    5895258302187834624213.87631129557286-56.6785372590399060.6468437015289753--
    5895247444506644992213.33215109206796-56.9753477593809950.390215490234287--
    5895259470417635968213.78815034206346-56.645850474515940.953377710788918--
    5895264899260932352213.21521027193236-56.78420864489118----
    5895265925746051584213.17082359534547-56.745408851077540.2986918215101751--

    You might notice that some values of parallax are negative. As this FAQ explains, “Negative parallaxes are caused by errors in the observations.” They have “no physical meaning,” but they can be a “useful diagnostic on the quality of the astrometric solution.”

    @@ -646,7 +1093,16 @@ The modified query should fail, but notice that you don’t get much useful debu
    -
    # Solution goes here
    +
    # Solution
    +
    +# In this example, the WHERE clause is in the wrong place
    +
    +query = """SELECT 
    +TOP 3000
    +WHERE parallax < 1
    +source_id, ref_epoch, ra, dec, parallax
    +FROM gaiadr2.gaia_source
    +"""
     
    @@ -696,7 +1152,27 @@ Be careful to keep your Python out of your ADQL!

    Read about SQL operators here and then modify the previous query to select rows where bp_rp is between -0.75 and 2.

    -
    # Solution goes here
    +
    # Solution
    +
    +# Here's a solution using > and < operators
    +
    +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
    +"""
    +
    +# And here's a solution using the BETWEEN operator
    +
    +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
    +"""
     
    @@ -754,6 +1230,11 @@ That’s not required, but it is a common style.

    +
    +
    'SELECT \nTOP 10 \nsource_id, ra, dec, pmra, pmdec\nFROM gaiadr2.gaia_source\nWHERE parallax < 1\n  AND bp_rp BETWEEN -0.75 AND 2\n'
    +
    +
    +

    But if you print it, the line breaks appear as… line breaks.

    @@ -762,6 +1243,16 @@ That’s not required, but it is a common style.

    +
    +
    SELECT 
    +TOP 10 
    +source_id, ra, dec, pmra, pmdec
    +FROM gaiadr2.gaia_source
    +WHERE parallax < 1
    +  AND bp_rp BETWEEN -0.75 AND 2
    +
    +
    +

    Notice that the format specifier has been replaced with the value of columns.

    Let’s run it and see if it works:

    @@ -772,6 +1263,23 @@ That’s not required, but it is a common style.

    +
    +
    <Table length=10>
    +   name    dtype    unit                              description                            
    +--------- ------- -------- ------------------------------------------------------------------
    +source_id   int64          Unique source identifier (unique within a particular Data Release)
    +       ra float64      deg                                                    Right ascension
    +      dec float64      deg                                                        Declination
    +     pmra float64 mas / yr                         Proper motion in right ascension direction
    +    pmdec float64 mas / yr                             Proper motion in declination direction
    +Jobid: None
    +Phase: COMPLETED
    +Owner: None
    +Output file: sync_20210315091929.xml.gz
    +Results: None
    +
    +
    +
    @@ -780,6 +1288,23 @@ That’s not required, but it is a common style.

    +
    +
    Table length=10 + + + + + + + + + + + + + + +
    source_idradecpmrapmdec
    degdegmas / yrmas / yr
    int64float64float64float64float64
    5895272561481374080213.2606587905109-56.550444015357150.38944388983017151.2299266281737415
    5895261875598904576213.5508930114549-56.610377801543480.16203641364393007-4.672602679543312
    5895247444506644992213.33215109206796-56.975347759380995-7.474003156859284-3.538080792097856
    5895259470417635968213.78815034206346-56.64585047451594-5.287202255231853-0.8163762113468646
    5895265925746051584213.17082359534547-56.74540885107754-7.880749306158471-4.8585444120179595
    5895260913525974528213.66936020541976-56.66655190442016-4.7820929042428215-1.5566420086447643
    5895264212062283008213.7755742121852-56.51570859067397-6.657690998559842-1.7616494482071872
    5895253457497979136213.30929960610283-56.78849448744587-5.242106718924749-0.18655636353898095
    4143614130253524096269.1749117455479-18.534151399721172.61642745108048261.3244248889980894
    4065443904433108992273.26868565443743-24.421651815402857-1.663096652191022-2.6514745376067683

    Good so far.

    @@ -788,7 +1313,29 @@ That’s not required, but it is a common style.

    Modify query3_base to replace 1 with a format specifier like {max_parallax}. Now, when you call format, add a keyword argument that assigns a value to max_parallax, and confirm that the format specifier gets replaced with the value you provide.

    -
    # Solution goes here
    +
    # Solution
    +
    +query_base = """SELECT 
    +TOP 10
    +{columns}
    +FROM gaiadr2.gaia_source
    +WHERE parallax < {max_parallax} AND 
    +bp_rp BETWEEN -0.75 AND 2
    +"""
    +
    +query = query_base.format(columns=columns,
    +                          max_parallax=0.5)
    +print(query)
    +
    +
    +
    +
    +
    SELECT 
    +TOP 10
    +source_id, ra, dec, pmra, pmdec
    +FROM gaiadr2.gaia_source
    +WHERE parallax < 0.5 AND 
    +bp_rp BETWEEN -0.75 AND 2
     
    diff --git a/02_coords.html b/02_coords.html index 95aac6a..00c088a 100644 --- a/02_coords.html +++ b/02_coords.html @@ -243,11 +243,6 @@ Outline
  • -
  • - - Installing libraries - -
  • Working with Units @@ -352,26 +347,6 @@
  • Download the results of a query and store them in a file.

  • -
    -

    Installing libraries

    -

    If you are running this notebook on Colab, you can run the following cell to install the libraries we’ll use.

    -

    If you are running this notebook on your own computer, you might have to install these libraries yourself. See the instructions in the preface.

    -
    -
    -
    # If we're running on Colab, install libraries
    -
    -# TODO: When Colab can install gala, switch from astro-gala
    -
    -import sys
    -IN_COLAB = 'google.colab' in sys.modules
    -
    -if IN_COLAB:
    -    !pip install astroquery astro-gala
    -
    -
    -
    -
    -

    Working with Units

    The measurements we will work with are physical quantities, which means that they have two parts, a value and a unit. @@ -394,6 +369,1011 @@ For example, the coordinate \(30^{\ci

    +
    +
    ['A',
    + 'AA',
    + 'AB',
    + 'ABflux',
    + 'ABmag',
    + 'AU',
    + 'Angstrom',
    + 'B',
    + 'Ba',
    + 'Barye',
    + 'Bi',
    + 'Biot',
    + 'Bol',
    + 'Bq',
    + 'C',
    + 'Celsius',
    + 'Ci',
    + 'CompositeUnit',
    + 'D',
    + 'Da',
    + 'Dalton',
    + 'Debye',
    + 'Decibel',
    + 'DecibelUnit',
    + 'Dex',
    + 'DexUnit',
    + 'EA',
    + 'EAU',
    + 'EB',
    + 'EBa',
    + 'EC',
    + 'ED',
    + 'EF',
    + 'EG',
    + 'EGal',
    + 'EH',
    + 'EHz',
    + 'EJ',
    + 'EJy',
    + 'EK',
    + 'EL',
    + 'EN',
    + 'EOhm',
    + 'EP',
    + 'EPa',
    + 'ER',
    + 'ERy',
    + 'ES',
    + 'ESt',
    + 'ET',
    + 'EV',
    + 'EW',
    + 'EWb',
    + 'Ea',
    + 'Eadu',
    + 'Earcmin',
    + 'Earcsec',
    + 'Eau',
    + 'Eb',
    + 'Ebarn',
    + 'Ebeam',
    + 'Ebin',
    + 'Ebit',
    + 'Ebyte',
    + 'Ecd',
    + 'Echan',
    + 'Ecount',
    + 'Ect',
    + 'Ed',
    + 'Edeg',
    + 'Edyn',
    + 'EeV',
    + 'Eerg',
    + 'Eg',
    + 'Eh',
    + 'EiB',
    + 'Eib',
    + 'Eibit',
    + 'Eibyte',
    + 'Ek',
    + 'El',
    + 'Elm',
    + 'Elx',
    + 'Elyr',
    + 'Em',
    + 'Emag',
    + 'Emin',
    + 'Emol',
    + 'Eohm',
    + 'Epc',
    + 'Eph',
    + 'Ephoton',
    + 'Epix',
    + 'Epixel',
    + 'Erad',
    + 'Es',
    + 'Esr',
    + 'Eu',
    + 'Evox',
    + 'Evoxel',
    + 'Eyr',
    + 'F',
    + 'Farad',
    + 'Fr',
    + 'Franklin',
    + 'FunctionQuantity',
    + 'FunctionUnitBase',
    + 'G',
    + 'GA',
    + 'GAU',
    + 'GB',
    + 'GBa',
    + 'GC',
    + 'GD',
    + 'GF',
    + 'GG',
    + 'GGal',
    + 'GH',
    + 'GHz',
    + 'GJ',
    + 'GJy',
    + 'GK',
    + 'GL',
    + 'GN',
    + 'GOhm',
    + 'GP',
    + 'GPa',
    + 'GR',
    + 'GRy',
    + 'GS',
    + 'GSt',
    + 'GT',
    + 'GV',
    + 'GW',
    + 'GWb',
    + 'Ga',
    + 'Gadu',
    + 'Gal',
    + 'Garcmin',
    + 'Garcsec',
    + 'Gau',
    + 'Gauss',
    + 'Gb',
    + 'Gbarn',
    + 'Gbeam',
    + 'Gbin',
    + 'Gbit',
    + 'Gbyte',
    + 'Gcd',
    + 'Gchan',
    + 'Gcount',
    + 'Gct',
    + 'Gd',
    + 'Gdeg',
    + 'Gdyn',
    + 'GeV',
    + 'Gerg',
    + 'Gg',
    + 'Gh',
    + 'GiB',
    + 'Gib',
    + 'Gibit',
    + 'Gibyte',
    + 'Gk',
    + 'Gl',
    + 'Glm',
    + 'Glx',
    + 'Glyr',
    + 'Gm',
    + 'Gmag',
    + 'Gmin',
    + 'Gmol',
    + 'Gohm',
    + 'Gpc',
    + 'Gph',
    + 'Gphoton',
    + 'Gpix',
    + 'Gpixel',
    + 'Grad',
    + 'Gs',
    + 'Gsr',
    + 'Gu',
    + 'Gvox',
    + 'Gvoxel',
    + 'Gyr',
    + 'H',
    + 'Henry',
    + 'Hertz',
    + 'Hz',
    + 'IrreducibleUnit',
    + 'J',
    + 'Jansky',
    + 'Joule',
    + 'Jy',
    + 'K',
    + 'Kayser',
    + 'Kelvin',
    + 'KiB',
    + 'Kib',
    + 'Kibit',
    + 'Kibyte',
    + 'L',
    + 'L_bol',
    + 'L_sun',
    + 'LogQuantity',
    + 'LogUnit',
    + 'Lsun',
    + 'MA',
    + 'MAU',
    + 'MB',
    + 'MBa',
    + 'MC',
    + 'MD',
    + 'MF',
    + 'MG',
    + 'MGal',
    + 'MH',
    + 'MHz',
    + 'MJ',
    + 'MJy',
    + 'MK',
    + 'ML',
    + 'MN',
    + 'MOhm',
    + 'MP',
    + 'MPa',
    + 'MR',
    + 'MRy',
    + 'MS',
    + 'MSt',
    + 'MT',
    + 'MV',
    + 'MW',
    + 'MWb',
    + 'M_bol',
    + 'M_e',
    + 'M_earth',
    + 'M_jup',
    + 'M_jupiter',
    + 'M_p',
    + 'M_sun',
    + 'Ma',
    + 'Madu',
    + 'MagUnit',
    + 'Magnitude',
    + 'Marcmin',
    + 'Marcsec',
    + 'Mau',
    + 'Mb',
    + 'Mbarn',
    + 'Mbeam',
    + 'Mbin',
    + 'Mbit',
    + 'Mbyte',
    + 'Mcd',
    + 'Mchan',
    + 'Mcount',
    + 'Mct',
    + 'Md',
    + 'Mdeg',
    + 'Mdyn',
    + 'MeV',
    + 'Mearth',
    + 'Merg',
    + 'Mg',
    + 'Mh',
    + 'MiB',
    + 'Mib',
    + 'Mibit',
    + 'Mibyte',
    + 'Mjup',
    + 'Mjupiter',
    + 'Mk',
    + 'Ml',
    + 'Mlm',
    + 'Mlx',
    + 'Mlyr',
    + 'Mm',
    + 'Mmag',
    + 'Mmin',
    + 'Mmol',
    + 'Mohm',
    + 'Mpc',
    + 'Mph',
    + 'Mphoton',
    + 'Mpix',
    + 'Mpixel',
    + 'Mrad',
    + 'Ms',
    + 'Msr',
    + 'Msun',
    + 'Mu',
    + 'Mvox',
    + 'Mvoxel',
    + 'Myr',
    + 'N',
    + 'NamedUnit',
    + 'Newton',
    + 'Ohm',
    + 'P',
    + 'PA',
    + 'PAU',
    + 'PB',
    + 'PBa',
    + 'PC',
    + 'PD',
    + 'PF',
    + 'PG',
    + 'PGal',
    + 'PH',
    + 'PHz',
    + 'PJ',
    + 'PJy',
    + 'PK',
    + 'PL',
    + 'PN',
    + 'POhm',
    + 'PP',
    + 'PPa',
    + 'PR',
    + 'PRy',
    + 'PS',
    + 'PSt',
    + 'PT',
    + 'PV',
    + 'PW',
    + 'PWb',
    + 'Pa',
    + 'Padu',
    + 'Parcmin',
    + 'Parcsec',
    + 'Pascal',
    + 'Pau',
    + 'Pb',
    + 'Pbarn',
    + 'Pbeam',
    + 'Pbin',
    + 'Pbit',
    + 'Pbyte',
    + 'Pcd',
    + 'Pchan',
    + 'Pcount',
    + 'Pct',
    + 'Pd',
    + 'Pdeg',
    + 'Pdyn',
    + 'PeV',
    + 'Perg',
    + 'Pg',
    + 'Ph',
    + 'PiB',
    + 'Pib',
    + 'Pibit',
    + 'Pibyte',
    + 'Pk',
    + 'Pl',
    + 'Plm',
    + 'Plx',
    + 'Plyr',
    + 'Pm',
    + 'Pmag',
    + 'Pmin',
    + 'Pmol',
    + 'Pohm',
    + 'Ppc',
    + 'Pph',
    + 'Pphoton',
    + 'Ppix',
    + 'Ppixel',
    + 'Prad',
    + 'PrefixUnit',
    + 'Ps',
    + 'Psr',
    + 'Pu',
    + 'Pvox',
    + 'Pvoxel',
    + 'Pyr',
    + 'Quantity',
    + 'QuantityInfo',
    + 'QuantityInfoBase',
    + 'R',
    + 'R_earth',
    + 'R_jup',
    + 'R_jupiter',
    + 'R_sun',
    + 'Rayleigh',
    + 'Rearth',
    + 'Rjup',
    + 'Rjupiter',
    + 'Rsun',
    + 'Ry',
    + 'S',
    + 'ST',
    + 'STflux',
    + 'STmag',
    + 'Siemens',
    + 'SpecificTypeQuantity',
    + 'St',
    + 'Sun',
    + 'T',
    + 'TA',
    + 'TAU',
    + 'TB',
    + 'TBa',
    + 'TC',
    + 'TD',
    + 'TF',
    + 'TG',
    + 'TGal',
    + 'TH',
    + 'THz',
    + 'TJ',
    + 'TJy',
    + 'TK',
    + 'TL',
    + 'TN',
    + 'TOhm',
    + 'TP',
    + 'TPa',
    + 'TR',
    + 'TRy',
    + 'TS',
    + 'TSt',
    + 'TT',
    + 'TV',
    + 'TW',
    + 'TWb',
    + 'Ta',
    + 'Tadu',
    + 'Tarcmin',
    + 'Tarcsec',
    + 'Tau',
    + 'Tb',
    + 'Tbarn',
    + 'Tbeam',
    + 'Tbin',
    + 'Tbit',
    + 'Tbyte',
    + 'Tcd',
    + 'Tchan',
    + 'Tcount',
    + 'Tct',
    + 'Td',
    + 'Tdeg',
    + 'Tdyn',
    + 'TeV',
    + 'Terg',
    + 'Tesla',
    + 'Tg',
    + 'Th',
    + 'TiB',
    + 'Tib',
    + 'Tibit',
    + 'Tibyte',
    + 'Tk',
    + 'Tl',
    + 'Tlm',
    + 'Tlx',
    + 'Tlyr',
    + 'Tm',
    + 'Tmag',
    + 'Tmin',
    + 'Tmol',
    + 'Tohm',
    + 'Torr',
    + 'Tpc',
    + 'Tph',
    + 'Tphoton',
    + 'Tpix',
    + 'Tpixel',
    + 'Trad',
    + 'Ts',
    + 'Tsr',
    + 'Tu',
    + 'Tvox',
    + 'Tvoxel',
    + 'Tyr',
    + 'Unit',
    + 'UnitBase',
    + 'UnitConversionError',
    + 'UnitTypeError',
    + 'UnitsError',
    + 'UnitsWarning',
    + 'UnrecognizedUnit',
    + 'V',
    + 'Volt',
    + 'W',
    + 'Watt',
    + 'Wb',
    + 'Weber',
    + 'YA',
    + 'YAU',
    + 'YB',
    + 'YBa',
    + 'YC',
    + 'YD',
    + 'YF',
    + 'YG',
    + 'YGal',
    + 'YH',
    + 'YHz',
    + 'YJ',
    + 'YJy',
    + 'YK',
    + 'YL',
    + 'YN',
    + 'YOhm',
    + 'YP',
    + 'YPa',
    + 'YR',
    + 'YRy',
    + 'YS',
    + 'YSt',
    + 'YT',
    + 'YV',
    + 'YW',
    + 'YWb',
    + 'Ya',
    + 'Yadu',
    + 'Yarcmin',
    + 'Yarcsec',
    + 'Yau',
    + 'Yb',
    + 'Ybarn',
    + 'Ybeam',
    + 'Ybin',
    + 'Ybit',
    + 'Ybyte',
    + 'Ycd',
    + 'Ychan',
    + 'Ycount',
    + 'Yct',
    + 'Yd',
    + 'Ydeg',
    + 'Ydyn',
    + 'YeV',
    + 'Yerg',
    + 'Yg',
    + 'Yh',
    + 'Yk',
    + 'Yl',
    + 'Ylm',
    + 'Ylx',
    + 'Ylyr',
    + 'Ym',
    + 'Ymag',
    + 'Ymin',
    + 'Ymol',
    + 'Yohm',
    + 'Ypc',
    + 'Yph',
    + 'Yphoton',
    + 'Ypix',
    + 'Ypixel',
    + 'Yrad',
    + 'Ys',
    + 'Ysr',
    + 'Yu',
    + 'Yvox',
    + 'Yvoxel',
    + 'Yyr',
    + 'ZA',
    + 'ZAU',
    + 'ZB',
    + 'ZBa',
    + 'ZC',
    + 'ZD',
    + 'ZF',
    + 'ZG',
    + 'ZGal',
    + 'ZH',
    + 'ZHz',
    + 'ZJ',
    + 'ZJy',
    + 'ZK',
    + 'ZL',
    + 'ZN',
    + 'ZOhm',
    + 'ZP',
    + 'ZPa',
    + 'ZR',
    + 'ZRy',
    + 'ZS',
    + 'ZSt',
    + 'ZT',
    + 'ZV',
    + 'ZW',
    + 'ZWb',
    + 'Za',
    + 'Zadu',
    + 'Zarcmin',
    + 'Zarcsec',
    + 'Zau',
    + 'Zb',
    + 'Zbarn',
    + 'Zbeam',
    + 'Zbin',
    + 'Zbit',
    + 'Zbyte',
    + 'Zcd',
    + 'Zchan',
    + 'Zcount',
    + 'Zct',
    + 'Zd',
    + 'Zdeg',
    + 'Zdyn',
    + 'ZeV',
    + 'Zerg',
    + 'Zg',
    + 'Zh',
    + 'Zk',
    + 'Zl',
    + 'Zlm',
    + 'Zlx',
    + 'Zlyr',
    + 'Zm',
    + 'Zmag',
    + 'Zmin',
    + 'Zmol',
    + 'Zohm',
    + 'Zpc',
    + 'Zph',
    + 'Zphoton',
    + 'Zpix',
    + 'Zpixel',
    + 'Zrad',
    + 'Zs',
    + 'Zsr',
    + 'Zu',
    + 'Zvox',
    + 'Zvoxel',
    + 'Zyr',
    + '__builtins__',
    + '__cached__',
    + '__doc__',
    + '__file__',
    + '__loader__',
    + '__name__',
    + '__package__',
    + '__path__',
    + '__spec__',
    + 'a',
    + 'aA',
    + 'aAU',
    + 'aB',
    + 'aBa',
    + 'aC',
    + 'aD',
    + 'aF',
    + 'aG',
    + 'aGal',
    + 'aH',
    + 'aHz',
    + 'aJ',
    + 'aJy',
    + 'aK',
    + 'aL',
    + 'aN',
    + 'aOhm',
    + 'aP',
    + 'aPa',
    + 'aR',
    + 'aRy',
    + 'aS',
    + 'aSt',
    + 'aT',
    + 'aV',
    + 'aW',
    + 'aWb',
    + 'aa',
    + 'aadu',
    + 'aarcmin',
    + 'aarcsec',
    + 'aau',
    + 'ab',
    + 'abA',
    + 'abC',
    + 'abampere',
    + 'abarn',
    + 'abcoulomb',
    + 'abeam',
    + 'abin',
    + 'abit',
    + 'abyte',
    + 'acd',
    + 'achan',
    + 'acount',
    + 'act',
    + 'ad',
    + 'add_enabled_equivalencies',
    + 'add_enabled_units',
    + 'adeg',
    + 'adu',
    + 'adyn',
    + 'aeV',
    + 'aerg',
    + 'ag',
    + 'ah',
    + 'ak',
    + 'al',
    + 'allclose',
    + 'alm',
    + 'alx',
    + 'alyr',
    + 'am',
    + 'amag',
    + 'amin',
    + 'amol',
    + 'amp',
    + 'ampere',
    + 'angstrom',
    + 'annum',
    + 'aohm',
    + 'apc',
    + 'aph',
    + 'aphoton',
    + 'apix',
    + 'apixel',
    + 'arad',
    + 'arcmin',
    + 'arcminute',
    + 'arcsec',
    + 'arcsecond',
    + 'asr',
    + 'astronomical_unit',
    + 'astrophys',
    + 'attoBarye',
    + 'attoDa',
    + 'attoDalton',
    + 'attoDebye',
    + 'attoFarad',
    + 'attoGauss',
    + 'attoHenry',
    + 'attoHertz',
    + 'attoJansky',
    + 'attoJoule',
    + 'attoKayser',
    + 'attoKelvin',
    + 'attoNewton',
    + 'attoOhm',
    + 'attoPascal',
    + 'attoRayleigh',
    + 'attoSiemens',
    + 'attoTesla',
    + 'attoVolt',
    + 'attoWatt',
    + 'attoWeber',
    + 'attoamp',
    + 'attoampere',
    + 'attoannum',
    + 'attoarcminute',
    + 'attoarcsecond',
    + 'attoastronomical_unit',
    + 'attobarn',
    + 'attobarye',
    + 'attobit',
    + 'attobyte',
    + 'attocandela',
    + 'attocoulomb',
    + 'attocount',
    + 'attoday',
    + 'attodebye',
    + 'attodegree',
    + 'attodyne',
    + 'attoelectronvolt',
    + 'attofarad',
    + 'attogal',
    + 'attogauss',
    + 'attogram',
    + 'attohenry',
    + 'attohertz',
    + 'attohour',
    + 'attohr',
    + 'attojansky',
    + 'attojoule',
    + 'attokayser',
    + 'attolightyear',
    + 'attoliter',
    + 'attolumen',
    + 'attolux',
    + 'attometer',
    + 'attominute',
    + 'attomole',
    + 'attonewton',
    + 'attoparsec',
    + 'attopascal',
    + 'attophoton',
    + 'attopixel',
    + 'attopoise',
    + 'attoradian',
    + 'attorayleigh',
    + 'attorydberg',
    + 'attosecond',
    + 'attosiemens',
    + 'attosteradian',
    + 'attostokes',
    + 'attotesla',
    + 'attovolt',
    + 'attovoxel',
    + 'attowatt',
    + 'attoweber',
    + 'attoyear',
    + 'au',
    + 'avox',
    + 'avoxel',
    + 'ayr',
    + 'b',
    + 'bar',
    + 'barn',
    + 'barye',
    + 'beam',
    + 'beam_angular_area',
    + 'becquerel',
    + 'bin',
    + 'binary_prefixes',
    + 'bit',
    + 'bol',
    + 'brightness_temperature',
    + 'byte',
    + 'cA',
    + 'cAU',
    + 'cB',
    + 'cBa',
    + 'cC',
    + 'cD',
    + 'cF',
    + 'cG',
    + 'cGal',
    + 'cH',
    + 'cHz',
    + 'cJ',
    + 'cJy',
    + 'cK',
    + 'cL',
    + 'cN',
    + 'cOhm',
    + 'cP',
    + 'cPa',
    + 'cR',
    + 'cRy',
    + 'cS',
    + 'cSt',
    + 'cT',
    + 'cV',
    + 'cW',
    + 'cWb',
    + 'ca',
    + 'cadu',
    + 'candela',
    + 'carcmin',
    + 'carcsec',
    + 'cau',
    + 'cb',
    + 'cbarn',
    + 'cbeam',
    + 'cbin',
    + 'cbit',
    + 'cbyte',
    + 'ccd',
    + 'cchan',
    + 'ccount',
    + 'cct',
    + 'cd',
    + 'cdeg',
    + 'cdyn',
    + 'ceV',
    + 'centiBarye',
    + 'centiDa',
    + 'centiDalton',
    + 'centiDebye',
    + 'centiFarad',
    + 'centiGauss',
    + 'centiHenry',
    + 'centiHertz',
    + 'centiJansky',
    + 'centiJoule',
    + 'centiKayser',
    + 'centiKelvin',
    + 'centiNewton',
    + 'centiOhm',
    + 'centiPascal',
    + 'centiRayleigh',
    + 'centiSiemens',
    + 'centiTesla',
    + 'centiVolt',
    + 'centiWatt',
    + 'centiWeber',
    + 'centiamp',
    + 'centiampere',
    + 'centiannum',
    + 'centiarcminute',
    + 'centiarcsecond',
    + 'centiastronomical_unit',
    + 'centibarn',
    + 'centibarye',
    + 'centibit',
    + 'centibyte',
    + 'centicandela',
    + 'centicoulomb',
    + 'centicount',
    + 'centiday',
    + 'centidebye',
    + 'centidegree',
    + 'centidyne',
    + 'centielectronvolt',
    + 'centifarad',
    + 'centigal',
    + 'centigauss',
    + 'centigram',
    + 'centihenry',
    + 'centihertz',
    + 'centihour',
    + 'centihr',
    + 'centijansky',
    + 'centijoule',
    + 'centikayser',
    + 'centilightyear',
    + 'centiliter',
    + 'centilumen',
    + 'centilux',
    + 'centimeter',
    + 'centiminute',
    + 'centimole',
    + 'centinewton',
    + 'centiparsec',
    + 'centipascal',
    + 'centiphoton',
    + 'centipixel',
    + 'centipoise',
    + 'centiradian',
    + 'centirayleigh',
    + 'centirydberg',
    + 'centisecond',
    + 'centisiemens',
    + 'centisteradian',
    + 'centistokes',
    + 'centitesla',
    + 'centivolt',
    + 'centivoxel',
    + 'centiwatt',
    + 'centiweber',
    + 'centiyear',
    + 'cerg',
    + 'cg',
    + 'cgs',
    + 'ch',
    + 'chan',
    + 'ck',
    + 'cl',
    + 'clm',
    + 'clx',
    + 'clyr',
    + 'cm',
    + 'cmag',
    + 'cmin',
    + 'cmol',
    + 'cohm',
    + 'core',
    + 'coulomb',
    + 'count',
    + 'cpc',
    + 'cph',
    + 'cphoton',
    + 'cpix',
    + 'cpixel',
    + 'crad',
    + 'cs',
    + 'csr',
    + 'ct',
    + 'cu',
    + 'curie',
    + 'cvox',
    + 'cvoxel',
    + 'cy',
    + 'cycle',
    + 'cyr',
    + 'd',
    + 'dA',
    + 'dAU',
    + 'dB',
    + 'dBa',
    + 'dC',
    + 'dD',
    + 'dF',
    + 'dG',
    + 'dGal',
    + 'dH',
    + 'dHz',
    + 'dJ',
    + 'dJy',
    + 'dK',
    + 'dL',
    + 'dN',
    + 'dOhm',
    + 'dP',
    + 'dPa',
    + 'dR',
    + 'dRy',
    + 'dS',
    + 'dSt',
    + ...]
    +
    +
    +

    To create a quantity, we multiply a value by a unit.

    @@ -403,6 +1383,11 @@ For example, the coordinate \(30^{\ci
    +
    +
    astropy.units.quantity.Quantity
    +
    +
    +

    The result is a Quantity object. Jupyter knows how to display Quantities like this:

    @@ -412,6 +1397,10 @@ Jupyter knows how to display +
    +
    +\[10 \; \mathrm{{}^{\circ}}\]
    +

    Quantities provide a method called to that converts to other units. For example, we can compute the number of arcminutes in angle:

    @@ -421,6 +1410,10 @@ Jupyter knows how to display
    +
    +
    +\[600 \; \mathrm{{}^{\prime}}\]
    +

    If you add quantities, Astropy converts them to compatible units, if possible:

    @@ -429,6 +1422,10 @@ Jupyter knows how to display
    +
    +
    +\[10.5 \; \mathrm{{}^{\circ}}\]
    +

    If the units are not compatible, you get an error. For example:

    @@ -442,10 +1439,22 @@ For example:

    Then convert it to degrees.

    -
    # Solution goes here
    +
    # Solution
    +
    +radius = 5 * u.arcmin
    +print(radius)
    +
    +radius.to(u.degree)
     
    +
    +
    5.0 arcmin
    +
    +
    +
    +\[0.083333333 \; \mathrm{{}^{\circ}}\]
    +
    @@ -485,6 +1494,23 @@ Here’s how we run it.

    +
    +
    Created 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
    +
    +
    +
    <astroquery.utils.tap.model.job.Job at 0x7f277785fa30>
    +
    +
    +
    @@ -493,6 +1519,22 @@ Here’s how we run it.

    +
    +
    Table length=10 + + + + + + + + + + + + + +
    source_id
    int64
    3322773965056065536
    3322773758899157120
    3322774068134271104
    3322773930696320512
    3322774377374425728
    3322773724537891456
    3322773724537891328
    3322773930696321792
    3322773724537890944
    3322773930696322176

    Exercise

    @@ -501,10 +1543,29 @@ Here’s how we run it.

    In the previous query, replace TOP 10 source_id with COUNT(source_id) and run the query again. How many stars has Gaia identified in the cone we searched?

    -
    # Solution goes here
    +
    # Solution
    +
    +query = """SELECT 
    +COUNT(source_id)
    +FROM gaiadr2.gaia_source
    +WHERE 1=CONTAINS(
    +  POINT(ra, dec),
    +  CIRCLE(88.8, 7.4, 0.08333333))
    +"""
    +
    +job = Gaia.launch_job(query)
    +results = job.get_results()
    +results
     
    +
    +
    Table length=1 + + + + +
    count
    int64
    594
    @@ -544,6 +1605,12 @@ Here’s how we run it.

    +
    +
    <SkyCoord (ICRS): (ra, dec) in deg
    +    (88.8, 7.4)>
    +
    +
    +

    SkyCoord provides a function that transforms to other frames. For example, we can transform coords_icrs to Galactic coordinates like this:

    @@ -554,6 +1621,12 @@ For example, we can transform +
    +
    <SkyCoord (Galactic): (l, b) in deg
    +    (199.79693102, -8.95591653)>
    +
    +
    +

    Notice that in the Galactic frame, the coordinates are called l and b, not ra and dec.

    To transform to and from GD-1 coordinates, we’ll use a frame defined by Gala, which is an Astropy-affiliated library that provides tools for galactic dynamics.

    @@ -567,6 +1640,11 @@ For example, we can transform +
    +
    <GD1Koposov10 Frame>
    +
    +
    +

    We can use it to find the coordinates of Betelgeuse in the GD-1 frame, like this:

    @@ -576,6 +1654,12 @@ For example, we can transform
    +
    +
    <SkyCoord (GD1Koposov10): (phi1, phi2) in deg
    +    (-94.97222038, 34.5813813)>
    +
    +
    +

    Notice that the coordinates are called phi1 and phi2. These are the coordinates shown in the figure from the paper, above.

    @@ -589,7 +1673,30 @@ These are the coordinates shown in the figure from the paper, above.

    Hint: Because ICRS is built into Astropy, you can specify it by name, icrs (as we did with galactic).

    -
    # Solution goes here
    +
    # Solution
    +
    +origin_gd1 = SkyCoord(0*u.degree, 0*u.degree, frame=gd1_frame)
    +
    +# OR
    +
    +origin_gd1 = SkyCoord(phi1=0*u.degree, 
    +                      phi2=0*u.degree, 
    +                      frame=gd1_frame)
    +
    +# Note: because ICRS is built into Astropy, 
    +# we can identify it by string name
    +origin_gd1.transform_to('icrs')
    +
    +# More formally, we could instantiate it
    +from astropy.coordinates import ICRS
    +icrs_frame = ICRS()
    +origin_gd1.transform_to(icrs_frame)
    +
    +
    +
    +
    +
    <SkyCoord (ICRS): (ra, dec) in deg
    +    (200., 59.4504341)>
     
    @@ -641,6 +1748,12 @@ These are the coordinates shown in the figure from the paper, above.

    +
    +
    <SkyCoord (GD1Koposov10): (phi1, phi2) in deg
    +    [(-55., -8.), (-55.,  4.), (-45.,  4.), (-45., -8.), (-55., -8.)]>
    +
    +
    +

    Now we can use transform_to to convert to ICRS coordinates.

    @@ -650,6 +1763,14 @@ These are the coordinates shown in the figure from the paper, above.

    +
    +
    <SkyCoord (ICRS): (ra, dec) in deg
    +    [(146.27533314, 19.26190982), (135.42163944, 25.87738723),
    +     (141.60264825, 34.3048303 ), (152.81671045, 27.13611254),
    +     (146.27533314, 19.26190982)]>
    +
    +
    +

    Notice that a rectangle in one coordinate system is not necessarily a rectangle in another. In this example, the result is a (non-rectangular) polygon.

    @@ -672,6 +1793,15 @@ These are the coordinates shown in the figure from the paper, above.

    +
    +
    ['146.275 19.2619',
    + '135.422 25.8774',
    + '141.603 34.3048',
    + '152.817 27.1361',
    + '146.275 19.2619']
    +
    +
    +

    We can use the Python string function join to join t into a single string (with spaces between the pairs):

    @@ -681,6 +1811,11 @@ These are the coordinates shown in the figure from the paper, above.

    +
    +
    '146.275 19.2619 135.422 25.8774 141.603 34.3048 152.817 27.1361 146.275 19.2619'
    +
    +
    +

    That’s almost what we need, but we have to replace the spaces with commas.

    @@ -689,6 +1824,11 @@ These are the coordinates shown in the figure from the paper, above.

    +
    +
    '146.275, 19.2619, 135.422, 25.8774, 141.603, 34.3048, 152.817, 27.1361, 146.275, 19.2619'
    +
    +
    +

    The following function combines these steps.

    @@ -710,6 +1850,11 @@ These are the coordinates shown in the figure from the paper, above.

    +
    +
    '146.275, 19.2619, 135.422, 25.8774, 141.603, 34.3048, 152.817, 27.1361, 146.275, 19.2619'
    +
    +
    +
    @@ -763,6 +1908,18 @@ We need columns
    +
    +
    SELECT
    +TOP 10
    +source_id, ra, dec, pmra, pmdec
    +FROM gaiadr2.gaia_source
    +WHERE parallax < 1
    +  AND bp_rp BETWEEN -0.75 AND 2 
    +  AND 1 = CONTAINS(POINT(ra, dec), 
    +                   POLYGON(146.275, 19.2619, 135.422, 25.8774, 141.603, 34.3048, 152.817, 27.1361, 146.275, 19.2619))
    +
    +
    +

    As always, we should take a minute to proof-read the query before we launch it.

    @@ -772,6 +1929,24 @@ We need columns
    +
    +
    INFO: Query finished. [astroquery.utils.tap.core]
    +<Table length=10>
    +   name    dtype    unit                              description                            
    +--------- ------- -------- ------------------------------------------------------------------
    +source_id   int64          Unique source identifier (unique within a particular Data Release)
    +       ra float64      deg                                                    Right ascension
    +      dec float64      deg                                                        Declination
    +     pmra float64 mas / yr                         Proper motion in right ascension direction
    +    pmdec float64 mas / yr                             Proper motion in declination direction
    +Jobid: 1615815873808O
    +Phase: COMPLETED
    +Owner: None
    +Output file: async_20210315094433.vot
    +Results: None
    +
    +
    +

    Here are the results.

    @@ -781,6 +1956,23 @@ We need columns
    +
    +
    Table length=10 + + + + + + + + + + + + + + +
    source_idradecpmrapmdec
    degdegmas / yrmas / yr
    int64float64float64float64float64
    637987125186749568142.4830193599102321.75771616932985-2.51683846838757662.941813096629439
    638285195917112960142.2545294134634422.4761681711413782.6627020143457996-12.165984395577347
    638073505568978688142.6452855746807422.1669322495307818.30674739454163-7.950659620550862
    638086386175786752142.5773943092603422.227919514013650.9877856720147953-2.584105480335548
    638049655615392384142.5891356447861822.1107831666774180.24443878227817095-4.941079187010136
    638267565075964032141.8176222899961422.375696125322275-3.4131745896607961.8838892877285924
    638028902333511168143.1833980131767722.25124658123697.848511762712128-21.391145547787154
    638085767700610432142.934731946458922.46244080823965-3.6585960944321476-12.486419770278376
    638299863230178304142.2676974582326722.640183776884836-1.81683708922182971.0537342990941316
    637973067758974208142.8955129286901221.612824100339875-8.645166256559063-44.41164172204947

    Finally, we can remove TOP 10 run the query again.

    The result is bigger than our previous queries, so it will take a little longer.

    @@ -806,6 +1998,17 @@ We need columns +
    +
    SELECT
    +source_id, ra, dec, pmra, pmdec
    +FROM gaiadr2.gaia_source
    +WHERE parallax < 1
    +  AND bp_rp BETWEEN -0.75 AND 2 
    +  AND 1 = CONTAINS(POINT(ra, dec), 
    +                   POLYGON(146.275, 19.2619, 135.422, 25.8774, 141.603, 34.3048, 152.817, 27.1361, 146.275, 19.2619))
    +
    +
    +
    @@ -814,6 +2017,24 @@ We need columns
    +
    +
    INFO: Query finished. [astroquery.utils.tap.core]
    +<Table length=140339>
    +   name    dtype    unit                              description                            
    +--------- ------- -------- ------------------------------------------------------------------
    +source_id   int64          Unique source identifier (unique within a particular Data Release)
    +       ra float64      deg                                                    Right ascension
    +      dec float64      deg                                                        Declination
    +     pmra float64 mas / yr                         Proper motion in right ascension direction
    +    pmdec float64 mas / yr                             Proper motion in declination direction
    +Jobid: 1615815886707O
    +Phase: COMPLETED
    +Owner: None
    +Output file: async_20210315094446.vot
    +Results: None
    +
    +
    +
    @@ -822,6 +2043,11 @@ We need columns
    +
    +
    140339
    +
    +
    +

    There are more than 100,000 stars in this polygon, but that’s a manageable size to work with.

    @@ -850,6 +2076,11 @@ We need columns +
    +
    5.36407470703125
    +
    +
    +
    diff --git a/03_motion.html b/03_motion.html index c1fe0a6..a544a5c 100644 --- a/03_motion.html +++ b/03_motion.html @@ -243,11 +243,6 @@ Outline -
  • - - Installing libraries - -
  • Reload the data @@ -373,24 +368,6 @@
  • Save a DataFrame in an HDF5 file.

  • -
    -

    Installing libraries

    -

    If you are running this notebook on Colab, you can run the following cell to install the libraries we’ll use.

    -

    If you are running this notebook on your own computer, you might have to install these libraries yourself. See the instructions in the preface.

    -
    -
    -
    # 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
    -
    -
    -
    -
    -

    Reload the data

    In the previous lesson, we ran a query on the Gaia server and downloaded data for roughly 140,000 stars. We saved the data in a FITS file so that now, picking up where we left off, we can read the data from a local file rather than running the query again.

    @@ -432,6 +409,19 @@
    +
    +
    <Table length=140339>
    +   name    dtype    unit                              description                            
    +--------- ------- -------- ------------------------------------------------------------------
    +source_id   int64          Unique source identifier (unique within a particular Data Release)
    +       ra float64      deg                                                    Right ascension
    +      dec float64      deg                                                        Declination
    +     pmra float64 mas / yr                         Proper motion in right ascension direction
    +    pmdec float64 mas / yr                             Proper motion in declination direction
    + parallax float64      mas                                                           Parallax
    +
    +
    +
    @@ -444,6 +434,11 @@
    +
    +
    ['source_id', 'ra', 'dec', 'pmra', 'pmdec', 'parallax']
    +
    +
    +

    And select an individual column like this:

    @@ -452,6 +447,35 @@
    +
    +
    <Column name='ra' dtype='float64' unit='deg' description='Right ascension' length=140339> + + + + + + + + + + + + + + + + + + + + + + + + + + +
    142.48301935991023
    142.25452941346344
    142.64528557468074
    142.57739430926034
    142.58913564478618
    141.81762228999614
    143.18339801317677
    142.9347319464589
    142.26769745823267
    142.89551292869012
    142.2780935768316
    142.06138786534987
    ...
    143.05456487172972
    144.0436496516182
    144.06566578919313
    144.13177563215973
    143.77696341662764
    142.945956347594
    142.97282480557786
    143.4166017695258
    143.64484588686904
    143.41554585481808
    143.6908739159247
    143.7702681295401

    The result is a Column object that contains the data, and also the data type, units, and name of the column.

    @@ -460,6 +484,11 @@
    +
    +
    astropy.table.column.Column
    +
    +
    +

    The rows in the Table are numbered from 0 to n-1, where n is the number of rows. We can select the first row like this:

    @@ -468,6 +497,14 @@
    +
    +
    Row index=0 + + + + + +
    source_idradecpmrapmdecparallax
    degdegmas / yrmas / yrmas
    int64float64float64float64float64float64
    637987125186749568142.4830193599102321.75771616932985-2.51683846838757662.941813096629439-0.2573448962333354

    As you might have guessed, the result is a Row object.

    @@ -476,6 +513,11 @@
    +
    +
    astropy.table.row.Row
    +
    +
    +

    Notice that the bracket operator selects both columns and rows. You might wonder how it knows which to select. If the expression in brackets is a string, it selects a column; if the expression is an integer, it selects a row.

    @@ -486,6 +528,11 @@ If the expression in brackets is a string, it selects a column; if the expressio +
    +
    142.48301935991023
    +
    +
    +

    Or you can select a row and then an element from the row.

    @@ -494,6 +541,11 @@ If the expression in brackets is a string, it selects a column; if the expressio
    +
    +
    142.48301935991023
    +
    +
    +

    You get the same result either way.

    @@ -534,6 +586,9 @@ In that case, you might want to run the following Jupyter +_images/03_motion_30_0.png +

    The arguments to plt.plot are x, y, and a string that specifies the style. In this case, the letters ko indicate that we want a black, round marker (k is for black because b is for blue). The functions xlabel and ylabel put labels on the axes.

    @@ -548,7 +603,14 @@ The functions xlabe

    Note: Once you have made these changes, you might notice that the figure shows stripes with lower density of stars. These stripes are caused by the way Gaia scans the sky, which you can read about here. The dataset we are using, Gaia Data Release 2, covers 22 months of observations; during this time, some parts of the sky were scanned more than others.

    -
    # Solution goes here
    +
    # Solution
    +
    +# x = results['ra']
    +# y = results['dec']
    +# plt.plot(x, y, 'ko', markersize=0.1, alpha=0.1)
    +
    +# plt.xlabel('ra (degree ICRS)')
    +# plt.ylabel('dec (degree ICRS)');
     
    @@ -648,6 +710,9 @@ The coordinates in
    +
    +_images/03_motion_45_0.png +

    Remember that we started with a rectangle in the GD-1 frame. When transformed to the ICRS frame, it’s a non-rectangular region. Now, transformed back to the GD-1 frame, it’s a rectangle again.

    @@ -660,6 +725,11 @@ The coordinates in +
    +
    astropy.table.table.Table
    +
    +
    +

    And skycoord_gd1 is a SkyCoord object that contains the transformed coordinates and proper motions.

    @@ -668,6 +738,11 @@ The coordinates in
    +
    +
    astropy.coordinates.sky_coordinate.SkyCoord
    +
    +
    +

    On one hand, this division of labor makes sense because each object provides different capabilities. But working with multiple object types can be awkward.

    It will be more convenient to choose one object and get all of the data into it. We’ll choose a Pandas DataFrame, for two reasons:

    @@ -693,6 +768,11 @@ The coordinates in +
    +
    (140339, 6)
    +
    +
    +

    It also provides head, which displays the first few rows. head is useful for spot-checking large results as you go along.

    @@ -701,6 +781,82 @@ The coordinates in
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    source_idradecpmrapmdecparallax
    0637987125186749568142.48301921.757716-2.5168382.941813-0.257345
    1638285195917112960142.25452922.4761682.662702-12.1659840.422728
    2638073505568978688142.64528622.16693218.306747-7.9506600.103640
    3638086386175786752142.57739422.2279200.987786-2.584105-0.857327
    4638049655615392384142.58913622.1107830.244439-4.9410790.099625
    +

    Python detail: shape is an attribute, so we display its value without calling it as a function; head is a function, so we need the parentheses.

    Now we can extract the columns we want from skycoord_gd1 and add them as columns in the DataFrame. phi1 and phi2 contain the transformed coordinates.

    @@ -712,6 +868,11 @@ The coordinates in +
    +
    (140339, 8)
    +
    +
    +

    pm_phi1_cosphi2 and pm_phi2 contain the components of proper motion in the transformed frame.

    @@ -722,6 +883,11 @@ The coordinates in
    +
    +
    (140339, 10)
    +
    +
    +

    Detail: If you notice that SkyCoord has an attribute called proper_motion, you might wonder why we are not using it.

    We could have: proper_motion contains the same data as pm_phi1_cosphi2 and pm_phi2, but in a different format.

    @@ -736,6 +902,145 @@ One of the most useful of these functions is +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    source_idradecpmrapmdecparallaxphi1phi2pm_phi1pm_phi2
    count1.403390e+05140339.000000140339.000000140339.000000140339.000000140339.000000140339.000000140339.000000140339.000000140339.000000
    mean6.792399e+17143.82312226.780285-2.484404-6.1007770.179492-50.091158-1.803301-0.8689631.409208
    std3.792177e+163.6978503.0525925.9139397.2020470.7595902.8923443.4443986.6577146.518615
    min6.214900e+17135.42569919.286617-106.755260-138.065163-15.287602-54.999989-8.029159-115.275637-161.150142
    25%6.443517e+17140.96796624.592490-5.038789-8.341561-0.035981-52.602952-4.750426-2.948723-1.107128
    50%6.888060e+17143.73440926.746261-1.834943-4.6895960.362708-50.147362-1.6715020.5850371.987149
    75%6.976579e+17146.60735028.9905000.452893-1.9378090.657637-47.5932791.1605143.0017684.628965
    max7.974418e+17152.77739334.285481104.31992320.9810700.999957-44.9999854.01460939.80247179.275199
    +

    Exercise

    @@ -746,7 +1051,17 @@ One of the most useful of these functions is
    -
    # Solution goes here
    +
    # Solution
    +
    +# The most noticeable issue is that some of the
    +# parallax values are negative, which is non-physical.
    +
    +# The reason is that parallax measurements are less accurate
    +# for stars that are far away.
    +
    +# Fortunately, we don't use the parallax measurements in
    +# the analysis (one of the reasons we used constant distance
    +# for reflex correction).
     
    @@ -776,6 +1091,9 @@ Then we will use the bounds of the cluster to select stars that are more likely
    +
    +_images/03_motion_69_0.png +

    Most of the proper motions are near the origin, but there are a few extreme values. Following the example in the paper, we’ll use xlim and ylim to zoom in on the region near the origin.

    @@ -793,6 +1111,9 @@ Following the example in the paper, we’ll use +_images/03_motion_71_0.png +

    There is a hint of an overdense region near (-7.5, 0), but if you didn’t know where to look, you would miss it.

    To see the cluster more clearly, we need a sample that contains a higher proportion of stars in GD-1. @@ -811,6 +1132,11 @@ We’ll do that by selecting stars close to the centerline.

    +
    +
    pandas.core.series.Series
    +
    +
    +

    The result is a Series, which is the structure Pandas uses to represent columns.

    We can use a comparison operator, >, to compare the values in a Series to a constant.

    @@ -824,6 +1150,11 @@ We’ll do that by selecting stars close to the centerline.

    +
    +
    pandas.core.series.Series
    +
    +
    +

    The result is a Series of Boolean values, that is, True and False.

    @@ -832,6 +1163,16 @@ We’ll do that by selecting stars close to the centerline.

    +
    +
    0    False
    +1    False
    +2    False
    +3    False
    +4    False
    +Name: phi2, dtype: bool
    +
    +
    +

    To select values that fall between phi2_min and phi2_max, we’ll use the & operator, which computes “logical AND”. The result is true where elements from both Boolean Series are true.

    @@ -851,6 +1192,11 @@ The result is true where elements from both Boolean +
    25084
    +
    +
    +

    A Boolean Series is sometimes called a “mask” because we can use it to mask out some of the rows in a DataFrame and select the rest, like this:

    @@ -860,6 +1206,11 @@ The result is true where elements from both Boolean +
    pandas.core.frame.DataFrame
    +
    +
    +

    centerline_df is a DataFrame that contains only the rows from results_df that correspond to True values in mask. So it contains the stars near the centerline of GD-1.

    @@ -870,6 +1221,11 @@ So it contains the stars near the centerline of GD-1.

    +
    +
    25084
    +
    +
    +

    And what fraction of the rows we’ve selected.

    @@ -878,6 +1234,11 @@ So it contains the stars near the centerline of GD-1.

    +
    +
    0.1787386257562046
    +
    +
    +

    There are about 25,000 stars in this region, about 18% of the total.

    @@ -911,6 +1272,9 @@ So it contains the stars near the centerline of GD-1.

    +
    +_images/03_motion_94_0.png +

    Now we can see more clearly that there is a cluster near (-7.5, 0).

    You might notice that our figure is less dense than the one in the paper. That’s because we started with a set of stars from a relatively small region. The figure in the paper is based on a region about 10 times bigger.

    @@ -961,6 +1325,9 @@ So it contains the stars near the centerline of GD-1.

    +
    +_images/03_motion_102_0.png +

    Now that we’ve identified the bounds of the cluster in proper motion, we’ll use it to select rows from results_df.

    We’ll use the following function, which uses Pandas operators to make a mask that selects rows where series falls between low and high.

    @@ -992,6 +1359,11 @@ So it contains the stars near the centerline of GD-1.

    +
    +
    1049
    +
    +
    +

    Now we can use this mask to select rows from results_df.

    @@ -1001,6 +1373,11 @@ So it contains the stars near the centerline of GD-1.

    +
    +
    1049
    +
    +
    +

    These are the stars we think are likely to be in GD-1. Let’s see what they look like, plotting their coordinates (not their proper motion).

    @@ -1014,6 +1391,9 @@ So it contains the stars near the centerline of GD-1.

    +
    +_images/03_motion_112_0.png +

    Now that’s starting to look like a tidal stream!

    @@ -1028,6 +1408,11 @@ So it contains the stars near the centerline of GD-1.

    +
    +
    astropy.table.table.Table
    +
    +
    +

    Then we could write the Table to a FITS file, as we did in the previous lesson.

    But Pandas provides functions to write DataFrames in other formats; to see what they are find the functions here that begin with to_.

    @@ -1055,7 +1440,9 @@ So it contains the stars near the centerline of GD-1.

    Hint: Since the file already exists, you should not use mode='w'.

    -
    # Solution goes here
    +
    # Solution
    +
    +centerline_df.to_hdf(filename, 'centerline_df')
     
    @@ -1070,6 +1457,11 @@ So it contains the stars near the centerline of GD-1.

    +
    +
    2.2084197998046875
    +
    +
    +

    If you forget what the names of the Datasets in the file are, you can read them back like this:

    @@ -1079,6 +1471,11 @@ So it contains the stars near the centerline of GD-1.

    +
    +
    ['/centerline_df', '/selected_df']
    +
    +
    +

    Python note: We use a with statement here to open the file before the print statement and (automatically) close it after. Read more about context managers.

    The keys are the names of the Datasets. Notice that they start with /, which indicates that they are at the top level of the Dataset hierarchy, and not in a named “group”.

    diff --git a/04_select.html b/04_select.html index 3f95a5f..1227416 100644 --- a/04_select.html +++ b/04_select.html @@ -243,11 +243,6 @@ Outline -
  • - - Installing libraries - -
  • Reload the data @@ -332,24 +327,6 @@ We’ll also see how to write the results to a CSV file.

  • Save data in CSV format.

  • -
    -

    Installing libraries

    -

    If you are running this notebook on Colab, you can run the following cell to install the libraries we’ll use.

    -

    If you are running this notebook on your own computer, you might have to install these libraries yourself. See the instructions in the preface.

    -
    -
    -
    # 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
    -
    -
    -
    -
    -

    Reload the data

    You can download the data from the previous lesson or run the following cell, which downloads it if necessary.

    @@ -466,6 +443,9 @@ We’ll also see how to write the results to a CSV file.

    +
    +_images/04_select_16_0.png +

    Now we’ll make the same plot using proper motions in the ICRS frame, which are stored in columns pmra and pmdec.

    @@ -486,6 +466,9 @@ We’ll also see how to write the results to a CSV file.

    +
    +_images/04_select_18_0.png +

    The proper motions of the selected stars are more spread out in this frame, which is why it was preferable to do the selection in the GD-1 frame.

    But now we can define a polygon that encloses the proper motions of these stars in ICRS, and use that polygon as a selection criterion in an ADQL query.

    @@ -503,6 +486,11 @@ We’ll also see how to write the results to a CSV file.

    +
    +
    (1049, 2)
    +
    +
    +

    NOTE: If you are using an older version of Pandas, you might not have to_numpy(); you can use values instead, like this:

    points = selected_df[['pmra','pmdec']].values
    @@ -519,6 +507,11 @@ We’ll also see how to write the results to a CSV file.

    +
    +
    <scipy.spatial.qhull.ConvexHull at 0x7ff6207866a0>
    +
    +
    +

    hull.vertices contains the indices of the points that fall on the perimeter of the hull.

    @@ -527,6 +520,12 @@ We’ll also see how to write the results to a CSV file.

    +
    +
    array([ 692,  873,  141,  303,   42,  622,   45,   83,  127,  182, 1006,
    +        971,  967, 1001,  969,  940], dtype=int32)
    +
    +
    +

    We can use them as an index into the original array to select the corresponding rows.

    @@ -536,6 +535,26 @@ We’ll also see how to write the results to a CSV file.

    +
    +
    array([[ -4.05037121, -14.75623261],
    +       [ -3.41981085, -14.72365546],
    +       [ -3.03521988, -14.44357135],
    +       [ -2.26847919, -13.7140236 ],
    +       [ -2.61172203, -13.24797471],
    +       [ -2.73471401, -13.09054471],
    +       [ -3.19923146, -12.5942653 ],
    +       [ -3.34082546, -12.47611926],
    +       [ -5.67489413, -11.16083338],
    +       [ -5.95159272, -11.10547884],
    +       [ -6.42394023, -11.05981295],
    +       [ -7.09631023, -11.95187806],
    +       [ -7.30641519, -12.24559977],
    +       [ -7.04016696, -12.88580702],
    +       [ -6.00347705, -13.75912098],
    +       [ -4.42442296, -14.74641176]])
    +
    +
    +

    To plot the resulting polygon, we have to pull out the x and y coordinates.

    @@ -567,6 +586,9 @@ We’ll also see how to write the results to a CSV file.

    +
    +_images/04_select_31_0.png +

    So pm_vertices represents the polygon we want to select. The next step is to use it as part of an ADQL query.

    @@ -651,6 +673,11 @@ Here’s the function from Lesson 2 we used to do that.

    +
    +
    '135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862'
    +
    +
    +

    Here are the columns we want to select.

    @@ -669,6 +696,17 @@ Here’s the function from Lesson 2 we used to do that.

    +
    +
    SELECT
    +source_id, ra, dec, pmra, pmdec
    +FROM gaiadr2.gaia_source
    +WHERE parallax < 1
    +  AND bp_rp BETWEEN -0.75 AND 2 
    +  AND 1 = CONTAINS(POINT(ra, dec), 
    +                   POLYGON(135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862))
    +
    +
    +

    But don’t try to run that query. Because it selects a larger region, there are too many stars to handle in a single query. @@ -688,6 +726,11 @@ Using flatten +

    +
    '[ -4.05037121,-14.75623261, -3.41981085,-14.72365546, -3.03521988,-14.44357135, -2.26847919,-13.7140236 , -2.61172203,-13.24797471, -2.73471401,-13.09054471, -3.19923146,-12.5942653 , -3.34082546,-12.47611926, -5.67489413,-11.16083338, -5.95159272,-11.10547884, -6.42394023,-11.05981295, -7.09631023,-11.95187806, -7.30641519,-12.24559977, -7.04016696,-12.88580702, -6.00347705,-13.75912098, -4.42442296,-14.74641176]'
    +
    +
    +

    We just have to remove the brackets.

    @@ -697,13 +740,29 @@ Using flatten
    +
    +
    ' -4.05037121,-14.75623261, -3.41981085,-14.72365546, -3.03521988,-14.44357135, -2.26847919,-13.7140236 , -2.61172203,-13.24797471, -2.73471401,-13.09054471, -3.19923146,-12.5942653 , -3.34082546,-12.47611926, -5.67489413,-11.16083338, -5.95159272,-11.10547884, -6.42394023,-11.05981295, -7.09631023,-11.95187806, -7.30641519,-12.24559977, -7.04016696,-12.88580702, -6.00347705,-13.75912098, -4.42442296,-14.74641176'
    +
    +
    +

    Exercise

    Define query6_base, starting with query5_base and adding a new clause to select stars whose coordinates of proper motion, pmra and pmdec, fall within the polygon defined by pm_point_list.

    -
    # Solution goes here
    +
    # Solution
    +
    +query6_base = """SELECT 
    +{columns}
    +FROM gaiadr2.gaia_source
    +WHERE parallax < 1
    +  AND bp_rp BETWEEN -0.75 AND 2 
    +  AND 1 = CONTAINS(POINT(ra, dec), 
    +                   POLYGON({point_list}))
    +  AND 1 = CONTAINS(POINT(pmra, pmdec),
    +                   POLYGON({pm_point_list}))
    +"""
     
    @@ -714,7 +773,25 @@ Using flattenUse format to format query6_base and define query6, filling in the values of columns, point_list, and pm_point_list.

    -
    # Solution goes here
    +
    # Solution
    +
    +query6 = query6_base.format(columns=columns, 
    +                            point_list=point_list,
    +                            pm_point_list=pm_point_list)
    +print(query6)
    +
    +
    +
    +
    +
    SELECT 
    +source_id, ra, dec, pmra, pmdec
    +FROM gaiadr2.gaia_source
    +WHERE parallax < 1
    +  AND bp_rp BETWEEN -0.75 AND 2 
    +  AND 1 = CONTAINS(POINT(ra, dec), 
    +                   POLYGON(135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862))
    +  AND 1 = CONTAINS(POINT(pmra, pmdec),
    +                   POLYGON( -4.05037121,-14.75623261, -3.41981085,-14.72365546, -3.03521988,-14.44357135, -2.26847919,-13.7140236 , -2.61172203,-13.24797471, -2.73471401,-13.09054471, -3.19923146,-12.5942653 , -3.34082546,-12.47611926, -5.67489413,-11.16083338, -5.95159272,-11.10547884, -6.42394023,-11.05981295, -7.09631023,-11.95187806, -7.30641519,-12.24559977, -7.04016696,-12.88580702, -6.00347705,-13.75912098, -4.42442296,-14.74641176))
     
    @@ -729,6 +806,24 @@ Using flatten
    +
    +
    INFO: Query finished. [astroquery.utils.tap.core]
    +<Table length=7345>
    +   name    dtype    unit                              description                            
    +--------- ------- -------- ------------------------------------------------------------------
    +source_id   int64          Unique source identifier (unique within a particular Data Release)
    +       ra float64      deg                                                    Right ascension
    +      dec float64      deg                                                        Declination
    +     pmra float64 mas / yr                         Proper motion in right ascension direction
    +    pmdec float64 mas / yr                             Proper motion in declination direction
    +Jobid: 1616771462206O
    +Phase: COMPLETED
    +Owner: None
    +Output file: async_20210326111102.vot
    +Results: None
    +
    +
    +

    And get the results.

    @@ -738,6 +833,11 @@ Using flatten
    +
    +
    7345
    +
    +
    +

    We call the results candidate_table because it contains stars that are good candidates for GD-1.

    For the next lesson, we’ll need point_list and pm_point_list again, so we should save them in a file. @@ -752,6 +852,12 @@ To make one, we’ll start with a dictionary:

    +
    +
    {'point_list': '135.306, 8.39862, 126.51, 13.4449, 163.017, 54.2424, 172.933, 46.4726, 135.306, 8.39862',
    + 'pm_point_list': ' -4.05037121,-14.75623261, -3.41981085,-14.72365546, -3.03521988,-14.44357135, -2.26847919,-13.7140236 , -2.61172203,-13.24797471, -2.73471401,-13.09054471, -3.19923146,-12.5942653 , -3.34082546,-12.47611926, -5.67489413,-11.16083338, -5.95159272,-11.10547884, -6.42394023,-11.05981295, -7.09631023,-11.95187806, -7.30641519,-12.24559977, -7.04016696,-12.88580702, -6.00347705,-13.75912098, -4.42442296,-14.74641176'}
    +
    +
    +

    And use it to initialize a Series.

    @@ -761,6 +867,13 @@ To make one, we’ll start with a dictionary:

    +
    +
    point_list       135.306, 8.39862, 126.51, 13.4449, 163.017, 54...
    +pm_point_list     -4.05037121,-14.75623261, -3.41981085,-14.723...
    +dtype: object
    +
    +
    +

    Now we can save it in the usual way.

    @@ -787,6 +900,9 @@ To make one, we’ll start with a dictionary:

    +
    +_images/04_select_68_0.png +

    Here we can see why it was useful to transform these coordinates. In ICRS, it is more difficult to identity the stars near the centerline of GD-1.

    So let’s transform the results back to the GD-1 frame. @@ -844,6 +960,9 @@ Here’s the code we used to transform the coordinates and make a Pandas +

    +_images/04_select_74_0.png +

    We’re starting to see GD-1 more clearly. We can compare this figure with this panel from Figure 1 from the original paper:

    diff --git a/05_join.html b/05_join.html index 6b98ba7..bd422a1 100644 --- a/05_join.html +++ b/05_join.html @@ -243,11 +243,6 @@ Outline -
  • - - Installing libraries - -
  • Getting photometry data @@ -361,24 +356,6 @@ The following figure from the paper is a color-magnitude diagram for the stars s
  • Write ADQL queries involving JOIN operations.

  • -
    -

    Installing libraries

    -

    If you are running this notebook on Colab, you can run the following cell to install the libraries we’ll use.

    -

    If you are running this notebook on your own computer, you might have to install these libraries yourself. See the instructions in the preface.

    -
    -
    -
    # If we're running on Colab, install libraries
    -
    -import sys
    -IN_COLAB = 'google.colab' in sys.modules
    -
    -if IN_COLAB:
    -    !pip install astroquery
    -
    -
    -
    -
    -

    Getting photometry data

    The Gaia dataset contains some photometry data, including the variable bp_rp, which contains BP-RP color (the difference in mean flux between the BP and RP bands). @@ -414,6 +391,13 @@ Here’s the metadata for

    +
    +
    Retrieving table 'gaiadr2.panstarrs1_best_neighbour'
    +Parsing table 'gaiadr2.panstarrs1_best_neighbour'...
    +Done.
    +
    +
    +
    @@ -421,6 +405,16 @@ Here’s the metadata for
    +
    +
    TAP Table name: gaiadr2.gaiadr2.panstarrs1_best_neighbour
    +Description: Pan-STARRS1 BestNeighbour table lists each matched Gaia object with its
    +best neighbour in the external catalogue.
    +There are 1 327 157 objects in the filtered version of Pan-STARRS1 used
    +to compute this cross-match that have too early epochMean.
    +Num. columns: 7
    +
    +
    +

    And here are the columns.

    @@ -430,6 +424,17 @@ Here’s the metadata for
    +
    +
    source_id
    +original_ext_source_id
    +angular_distance
    +number_of_neighbours
    +number_of_mates
    +best_neighbour_multiplicity
    +gaia_astrometric_params
    +
    +
    +

    Here’s the documentation for these variables .

    The ones we’ll use are:

    @@ -458,6 +463,11 @@ Here’s the metadata for +
    +
    INFO: Query finished. [astroquery.utils.tap.core]
    +
    +
    +
    @@ -466,6 +476,17 @@ Here’s the metadata for
    +
    +
    Table length=5 + + + + + + + + +
    source_idnumber_of_neighboursnumber_of_matesoriginal_ext_source_id
    int64int32int16int64
    67459389724334807041069742925668851205
    60304667889559540481069742509325691172
    67564880993081696001069742879438541228
    67001549947150460161069743055581721207
    67570619413032527361069742856540241198
    @@ -477,6 +498,13 @@ Here’s the metadata for
    +
    +
    Retrieving table 'gaiadr2.panstarrs1_original_valid'
    +Parsing table 'gaiadr2.panstarrs1_original_valid'...
    +Done.
    +
    +
    +
    @@ -484,6 +512,77 @@ Here’s the metadata for
    +
    +
    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
    +
    +
    +

    And here are the columns.

    @@ -493,6 +592,36 @@ Here’s the metadata for
    +
    +
    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
    +
    +
    +

    Here’s the documentation for these variables .

    The ones we’ll use are:

    @@ -519,6 +648,11 @@ Here’s the metadata for +
    +
    INFO: Query finished. [astroquery.utils.tap.core]
    +
    +
    +
    @@ -527,6 +661,18 @@ Here’s the metadata for
    +
    +
    Table length=5 + + + + + + + + + +
    obj_idg_mean_psf_magi_mean_psf_mag
    mag
    int64float64float64
    67130655389101425--20.3516006469727
    67553305590067819--19.779899597168
    67551423248967849--19.8889007568359
    67132026238911331--20.9062995910645
    67553513677687787--21.2831001281738

    The following figure shows how these tables are related.