From e25c745005cf155a2004805346c435670ad0eedf Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan <583379+adrn@users.noreply.github.com> Date: Fri, 21 Feb 2025 15:26:58 -0500 Subject: [PATCH] fix rebase issue --- .../3-Coordinates-Velocities.ipynb | 202 +++++------------- 1 file changed, 55 insertions(+), 147 deletions(-) diff --git a/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb b/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb index 076d9543..c47ab6e9 100644 --- a/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb +++ b/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb @@ -2,9 +2,7 @@ "cells": [ { "cell_type": "markdown", - "metadata": { - "id": "K3gI522hpNR1" - }, + "metadata": {}, "source": [ "# Astronomical Coordinates 3: Working with Velocity Data in astropy.coordinates\n", "\n", @@ -30,11 +28,19 @@ "- [Next tutorial: Astronomical Coordinates 4 - Cross-matching Catalogs](4-Coordinates-Crossmatch)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open('requirements.txt') as f:\n", + " print(f\"Required packages for this notebook:\\n{f.read()}\")" + ] + }, { "cell_type": "markdown", - "metadata": { - "id": "m3RngEEJpNR5" - }, + "metadata": {}, "source": [ "## Imports\n", "\n", @@ -44,13 +50,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "EI1u9VzIpNR6", - "outputId": "f7fdb1dc-4716-4449-bad0-73f6c588e94c" - }, + "metadata": {}, "outputs": [], "source": [ "import warnings\n", @@ -73,9 +73,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "Rtvp07W2pNR9" - }, + "metadata": {}, "source": [ "## More Than Sky Positions: Including Velocity Data in `SkyCoord`\n", "\n", @@ -89,9 +87,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "QOqwEMG3pNR9" - }, + "metadata": {}, "outputs": [], "source": [ "SkyCoord(\n", @@ -103,9 +99,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "1U0966fepNR-" - }, + "metadata": {}, "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", @@ -115,9 +109,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "GnQ8m4AGpNR-" - }, + "metadata": {}, "outputs": [], "source": [ "SkyCoord(\n", @@ -129,9 +121,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "x8fDaEI9pNR_" - }, + "metadata": {}, "source": [ "However, for some of the examples below we will continue to use scalar values for brevity. \n", "\n", @@ -141,9 +131,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "C-jgFsdfpNSA" - }, + "metadata": {}, "outputs": [], "source": [ "velocity_coord = SkyCoord(\n", @@ -157,9 +145,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "v7ztcRr-pNSB" - }, + "metadata": {}, "source": [ "The component data can then be accessed using the same names used to pass in the velocity components:" ] @@ -167,9 +153,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "p3_7hP6LpNSB" - }, + "metadata": {}, "outputs": [], "source": [ "velocity_coord.pm_ra_cosdec" @@ -178,9 +162,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "CM1TApDYpNSB" - }, + "metadata": {}, "outputs": [], "source": [ "velocity_coord.radial_velocity" @@ -188,9 +170,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "gxGKcYFZpNSC" - }, + "metadata": {}, "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:" ] @@ -198,9 +178,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "q6S7HmybpNSC" - }, + "metadata": {}, "outputs": [], "source": [ "velocity_coord_gal = velocity_coord.transform_to(Galactic())\n", @@ -209,9 +187,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "K9wL2Rl7pNSD" - }, + "metadata": {}, "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`:" ] @@ -219,9 +195,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "g-35XIlnpNSD" - }, + "metadata": {}, "outputs": [], "source": [ "velocity_coord_gal.pm_l_cosb" @@ -230,9 +204,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "PRZ_pt38pNSD" - }, + "metadata": {}, "outputs": [], "source": [ "velocity_coord_gal.pm_b" @@ -240,9 +212,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "GthFqig5pNSE" - }, + "metadata": {}, "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))" ] @@ -251,7 +221,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "id": "SKKyiObSpNSF", "tags": [ "raises-exception" ] @@ -271,9 +240,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "LJv8-Vt-1DYh" - }, + "metadata": {}, "source": [ "In order to transform to the `Galactocentric` frame, both distance and radial velocity of the object are required." ] @@ -281,9 +248,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "gdjBvnIM3D1U" - }, + "metadata": {}, "outputs": [], "source": [ "test_coord_2 = SkyCoord(\n", @@ -299,9 +264,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "rvo8IV2YpNSF" - }, + "metadata": {}, "source": [ "## Evolving Coordinate Positions Between Epochs\n", "\n", @@ -315,9 +278,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "oV1PLYwkpNSF" - }, + "metadata": {}, "outputs": [], "source": [ "# Skip this cell if you are not connected to the internet\n", @@ -328,14 +289,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 358 - }, - "id": "O-ntoKvEpNSG", - "outputId": "3a437357-ac0d-4c93-bc03-b45a87def9e8" - }, + "metadata": {}, "outputs": [], "source": [ "# the .read() below produces some warnings that we can safely ignore\n", @@ -347,9 +301,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "jiy-_1nhpNSG" - }, + "metadata": {}, "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:" ] @@ -357,9 +309,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "nPYC_wKzpNSH" - }, + "metadata": {}, "outputs": [], "source": [ "hd219829_row = gaia_tbl[gaia_tbl['phot_g_mean_mag'].argmin()]\n", @@ -368,9 +318,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "zyhOiroApNSH" - }, + "metadata": {}, "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", @@ -380,9 +328,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "AE2xkDyxpNSH" - }, + "metadata": {}, "outputs": [], "source": [ "hd219829_coord = SkyCoord(\n", @@ -398,9 +344,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "ioOAqGh2pNSI" - }, + "metadata": {}, "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", @@ -410,9 +354,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "A3T_h79VpNSI" - }, + "metadata": {}, "outputs": [], "source": [ "# Skip this cell if you are not connected to the internet\n", @@ -425,9 +367,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "CXbrurRipNSI" - }, + "metadata": {}, "outputs": [], "source": [ "dss_cutout_filename = 'dss_hd219829.fits'" @@ -435,9 +375,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "TiRZicmlpNSI" - }, + "metadata": {}, "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:\n", "\n", @@ -447,9 +385,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "x0dVL_sEpNSJ" - }, + "metadata": {}, "outputs": [], "source": [ "hdu = fits.open(dss_cutout_filename)[0]\n", @@ -471,9 +407,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "UrTg6qBRpNSJ" - }, + "metadata": {}, "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", @@ -483,9 +417,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "AiUtgluXpNSJ" - }, + "metadata": {}, "outputs": [], "source": [ "hd219829_coord.obstime" @@ -493,9 +425,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "CPyFWNZvpNSK" - }, + "metadata": {}, "source": [ "We can now use `apply_space_motion()` by passing in a new time, `new_obstime`, to compute the coordinates at:" ] @@ -503,9 +433,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "MoRt0KbxpNSK" - }, + "metadata": {}, "outputs": [], "source": [ "# this produces some warnings that we can safely ignore\n", @@ -518,9 +446,7 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "uf4MK0zupNSK" - }, + "metadata": {}, "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:" ] @@ -528,9 +454,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "npJ2V4BqpNSK" - }, + "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(1, 1, figsize=(8, 8),\n", @@ -556,36 +480,28 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "JOn_o0VQpNSL" - }, + "metadata": {}, "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": { - "id": "uVuz1hvOpNSL" - }, + "metadata": {}, "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" - }, + "metadata": {}, "source": [ "## Exercises\n" ] }, { "cell_type": "markdown", - "metadata": { - "id": "tZK2ibb0kKuo" - }, + "metadata": {}, "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)." ] @@ -593,28 +509,20 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "3Bz52TRvliZg" - }, + "metadata": {}, "outputs": [], "source": [] } ], "metadata": { - "colab": { - "name": "3-Coordinates-Velocities.ipynb", - "provenance": [] - }, "language_info": { "codemirror_mode": { - "name": "ipython", - "version": 3 + "name": "ipython" }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3" + "nbconvert_exporter": "python" } }, "nbformat": 4,