diff --git a/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb b/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb index cebd34b7..fed617fb 100644 --- a/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb +++ b/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb @@ -2,12 +2,14 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "K3gI522hpNR1" + }, "source": [ "# Astronomical Coordinates 3: Working with Velocity Data in astropy.coordinates\n", "\n", "## Authors\n", - "Adrian Price-Whelan\n", + "Adrian Price-Whelan, Saima Siddiqui, Luthien Liu, Zihao Chen\n", "\n", "## Learning Goals\n", "* Introduce how to represent and transform velocity data in `SkyCoord` objects\n", @@ -30,7 +32,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "m3RngEEJpNR5" + }, "source": [ "## Imports\n", "\n", @@ -40,7 +44,13 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "EI1u9VzIpNR6", + "outputId": "f7fdb1dc-4716-4449-bad0-73f6c588e94c" + }, "outputs": [], "source": [ "import warnings\n", @@ -48,6 +58,7 @@ "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import numpy as np\n", + "!pip install \"astroquery\"\n", "\n", "from astropy import units as u\n", "from astropy.coordinates import SkyCoord, Distance, Galactic\n", @@ -63,7 +74,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "Rtvp07W2pNR9" + }, "source": [ "## More Than Sky Positions: Including Velocity Data in `SkyCoord`\n", "\n", @@ -77,7 +90,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "QOqwEMG3pNR9" + }, "outputs": [], "source": [ "SkyCoord(\n", @@ -89,17 +104,31 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "v6EeE4KsfSpq" + }, + "source": [ + "**Thought Questions:**\n", + "What value did we put in for our right ascension? What about our declination? What units are they in?" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1U0966fepNR-" + }, "source": [ "Here, you may notice that the proper motion in right ascension has \"cosdec\" in the name: This is to explicitly note that the input here is expected to be the proper motion scaled by the cosine of the declination, which accounts for the fact that a change in longitude (right ascension) has different physical length at different latitudes (declinations).\n", "\n", - "Like the examples in previous tutorials demonstrated for positional coordinates, we can also create an array-valued `SkyCoord` object by passing in arrays of data for all of the components:" + "Like the examples in previous tutorials demonstrated for positional coordinates, we can also create an array-valued `SkyCoord` object by passing in arrays of data for all of the components. In this case, each value in the inputed array represents a quantity of an object among large data set. This method would be beneficial when dealing with large number of star collections like a star cluster:" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "GnQ8m4AGpNR-" + }, "outputs": [], "source": [ "SkyCoord(\n", @@ -111,7 +140,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "x8fDaEI9pNR_" + }, "source": [ "However, for some of the examples below we will continue to use scalar values for brevity. \n", "\n", @@ -121,7 +152,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "C-jgFsdfpNSA" + }, "outputs": [], "source": [ "velocity_coord = SkyCoord(\n", @@ -135,7 +168,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "v7ztcRr-pNSB" + }, "source": [ "The component data can then be accessed using the same names used to pass in the velocity components:" ] @@ -143,7 +178,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "p3_7hP6LpNSB" + }, "outputs": [], "source": [ "velocity_coord.pm_ra_cosdec" @@ -152,7 +189,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "CM1TApDYpNSB" + }, "outputs": [], "source": [ "velocity_coord.radial_velocity" @@ -160,7 +199,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "gxGKcYFZpNSC" + }, "source": [ "A `SkyCoord` object with velocity data can be transformed to other frames just like the position-only coordinate objects we used in the previous tutorials:" ] @@ -168,7 +209,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "q6S7HmybpNSC" + }, "outputs": [], "source": [ "velocity_coord_gal = velocity_coord.transform_to(Galactic())\n", @@ -177,7 +220,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "K9wL2Rl7pNSD" + }, "source": [ "Note that, like the position components, which change from `ra`,`dec` to `l`,`b`, the proper motion component names have changed to reflect naming conventions for the component names in a given frame: `pm_ra_cosdec` and `pm_dec` have become `pm_l_cosb` and `pm_b`:" ] @@ -185,7 +230,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "g-35XIlnpNSD" + }, "outputs": [], "source": [ "velocity_coord_gal.pm_l_cosb" @@ -194,7 +241,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "PRZ_pt38pNSD" + }, "outputs": [], "source": [ "velocity_coord_gal.pm_b" @@ -202,34 +251,68 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "GthFqig5pNSE" + }, "source": [ - "An important caveat to note when transforming a `SkyCoord` object with velocity data is that some reference frames require knowing the distances, or the full velocity vectors (i.e. proper motion components and radial velocity) in order to transform the velocities correctly. For example, a `SkyCoord` with only sky position and proper motion data cannot be transformed to a frame with a positional or velocity offset, such as the `Galactocentric` frame ([docs](https://docs.astropy.org/en/stable/coordinates/galactocentric.html))" + "An important caveat to note when transforming a `SkyCoord` object with velocity data is that some reference frames require knowing the distances, or the full velocity vectors (i.e. proper motion components and radial velocity) in order to transform the velocities correctly. For example, a `SkyCoord` with only sky position and proper motion data **CANNOT** be transformed to a frame with a positional or velocity offset, such as the `Galactocentric` frame ([docs](https://docs.astropy.org/en/stable/coordinates/galactocentric.html))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { + "id": "SKKyiObSpNSF", "tags": [ "raises-exception" ] }, "outputs": [], "source": [ - "test_coord = SkyCoord(\n", + "# This cell will NOT work (you will receive an ConvertError warning) - this is expected!\n", + "\n", + "test_coord_1 = SkyCoord(\n", " ra=10*u.deg, \n", " dec=20*u.deg,\n", " pm_ra_cosdec=1*u.mas/u.yr,\n", " pm_dec=2*u.mas/u.yr)\n", "\n", - "# This cell will raise an exception - this is expected!\n", - "test_coord.transform_to(coord.Galactocentric())" + "test_coord_1.transform_to(coord.Galactocentric())" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LJv8-Vt-1DYh" + }, + "source": [ + "In order to transform to the `Galactocentric` frame, both distance and radial velocity of the object are required." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "gdjBvnIM3D1U" + }, + "outputs": [], + "source": [ + "test_coord_2 = SkyCoord(\n", + " ra=10*u.deg, \n", + " dec=20*u.deg,\n", + " distance=10*u.pc,\n", + " pm_ra_cosdec=1*u.mas/u.yr,\n", + " pm_dec=2*u.mas/u.yr,\n", + " radial_velocity=100*u.km/u.s)\n", + "\n", + "test_coord_2.transform_to(coord.Galactocentric())" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "rvo8IV2YpNSF" + }, "source": [ "## Evolving Coordinate Positions Between Epochs\n", "\n", @@ -243,7 +326,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "oV1PLYwkpNSF" + }, "outputs": [], "source": [ "# Skip this cell if you are not connected to the internet\n", @@ -254,7 +339,14 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 358 + }, + "id": "O-ntoKvEpNSG", + "outputId": "3a437357-ac0d-4c93-bc03-b45a87def9e8" + }, "outputs": [], "source": [ "# the .read() below produces some warnings that we can safely ignore\n", @@ -266,7 +358,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "jiy-_1nhpNSG" + }, "source": [ "We know that HD 219829 will be the brightest source in this small region, so we can extract the row with the smallest G-band magnitude. Let's check the proper motion values for this source to make sure that they are large:" ] @@ -274,7 +368,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "nPYC_wKzpNSH" + }, "outputs": [], "source": [ "hd219829_row = gaia_tbl[gaia_tbl['phot_g_mean_mag'].argmin()]\n", @@ -283,7 +379,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "zyhOiroApNSH" + }, "source": [ "Indeed, it looks like this is our source! Let's construct a `SkyCoord` object for this source using the data from the *Gaia* archive:\n", "\n", @@ -293,7 +391,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "AE2xkDyxpNSH" + }, "outputs": [], "source": [ "hd219829_coord = SkyCoord(\n", @@ -309,7 +409,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "ioOAqGh2pNSI" + }, "source": [ "We now have a `SkyCoord` representation of the position and proper motion of the star HD 219829 as measured by *Gaia* and reported at the epoch J2015.5. What does this mean exactly? *Gaia* actually measures the (time-dependent) position of a star every time it scans the part of the sky that contains the source, and this is how *Gaia* is able to measure proper motions of stars. However, if every star is moving and changing its sky positions, how do we ever talk about \"the sky position\" of a star as opposed to \"the sky trajectory of a star\"?! The key is that catalogs often only report the position of a source at some reference epoch. For a survey that only observes the sky once or a few times (e.g., SDSS or 2MASS), this reference epoch might be \"the time that the star was observed.\" But for a mission like *Gaia*, which scans the sky many times, they perform astrometric fits to the individual position measurements, which allow them to measure the parallax, proper motion, and the reference position at a reference time for each source. For *Gaia* data release 2, the reference time is J2015.5, and the sky positions (and other quantities) reported in the catalog for each source are at this epoch. \n", "\n", @@ -319,7 +421,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "A3T_h79VpNSI" + }, "outputs": [], "source": [ "# Skip this cell if you are not connected to the internet\n", @@ -332,7 +436,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "CXbrurRipNSI" + }, "outputs": [], "source": [ "dss_cutout_filename = 'dss_hd219829.fits'" @@ -340,15 +446,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "TiRZicmlpNSI" + }, "source": [ - "We can now load the FITS image of the cutout and use `astropy.visualization` to display the image using its World Coordinate System (WCS) info ([docs](http://docs.astropy.org/en/latest/visualization/wcsaxes/index.html)). By passing in the WCS information (included in the FITS cutout header), we can over-plot a marker for the *Gaia*-measured sky position of HD 219829:" + "We can now load the FITS image of the cutout and use `astropy.visualization` to display the image using its World Coordinate System (WCS) info ([docs](http://docs.astropy.org/en/latest/visualization/wcsaxes/index.html)). By passing in the WCS information (included in the FITS cutout header), we can over-plot a marker for the *Gaia*-measured sky position of HD 219829:\n", + "\n", + "(If you are unfamiliar with the usage of FITS header and FITS image, check out these 2 tutorials having detailed explanation on these 2 topics: [FITS-Header](https://learn.astropy.org/tutorials/FITS-header.html) and [FITS-Image](https://learn.astropy.org/tutorials/FITS-images.html).)" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "x0dVL_sEpNSJ" + }, "outputs": [], "source": [ "hdu = fits.open(dss_cutout_filename)[0]\n", @@ -370,7 +482,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "UrTg6qBRpNSJ" + }, "source": [ "The brighest star (as observed by DSS) in this image is our target, and the red circle is where *Gaia* observed this star. As we excpected, it has moved quite a bit since the 1950's! We can account for this motion and predict the position of the star at around the time the DSS plate was observed. Let's assume that this plate was observed in 1950 exactly (this is not strictly correct, but should get us close enough).\n", "\n", @@ -380,7 +494,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "AiUtgluXpNSJ" + }, "outputs": [], "source": [ "hd219829_coord.obstime" @@ -388,7 +504,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "CPyFWNZvpNSK" + }, "source": [ "We can now use `apply_space_motion()` by passing in a new time, `new_obstime`, to compute the coordinates at:" ] @@ -396,7 +514,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "MoRt0KbxpNSK" + }, "outputs": [], "source": [ "# this produces some warnings that we can safely ignore\n", @@ -409,7 +529,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "uf4MK0zupNSK" + }, "source": [ "Let's now plot our predicted position for this source as it would appear in 1950 based on the *Gaia* position and proper motion:" ] @@ -417,7 +539,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "npJ2V4BqpNSK" + }, "outputs": [], "source": [ "fig, ax = plt.subplots(1, 1, figsize=(8, 8), \n", @@ -443,20 +567,60 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "JOn_o0VQpNSL" + }, "source": [ "The red circle is the same as in the previous image and shows the position of the source in the *Gaia* catalog (in 2015.5). The blue circle shows our prediction for the position of the source in 1950 - this looks much closer to where the star is in the DSS image!" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "uVuz1hvOpNSL" + }, "source": [ "In this tutorial, we have introduced how to store and transform velocity data along with positional data in `astropy.coordinates`. We also demonstrated how to use the velocity of a source to predict its position at an earlier or later time. " ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "joBu6r_nlfTp" + }, + "source": [ + "## Exercises\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tZK2ibb0kKuo" + }, + "source": [ + "Lalande 21185 is the brightest red dwarf star in the northern hemisphere and has a pretty high proper motion. Use the Gaia archive (https://gea.esac.esa.int/archive/) to find values and create a `SkyCoord` object for Lalande 21185. (Hint: earlier in the tutorial, we extracted information from a Gaia table and mentioned which Gaia column names match with our postition components)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "3Bz52TRvliZg" + }, + "outputs": [], + "source": [] } ], "metadata": { + "colab": { + "name": "3-Coordinates-Velocities.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -466,9 +630,10 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3" + "pygments_lexer": "ipython3", + "version": "3.9.12" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 1 } diff --git a/tutorials/astropy-coordinates/requirements.txt b/tutorials/astropy-coordinates/requirements.txt deleted file mode 100644 index f3cb4ae9..00000000 --- a/tutorials/astropy-coordinates/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -astropy -astroquery -matplotlib -numpy