Skip to content

Commit

Permalink
Merge pull request #569 from saimafsiddiqui/NEWCOORD3
Browse files Browse the repository at this point in the history
Changes to the Coordinates 3 tutorial
  • Loading branch information
adrn authored Feb 21, 2025
2 parents 090c266 + e25c745 commit ae239d2
Showing 1 changed file with 68 additions and 20 deletions.
88 changes: 68 additions & 20 deletions tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"# 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",
Expand Down Expand Up @@ -91,7 +91,7 @@
"outputs": [],
"source": [
"SkyCoord(\n",
" ra=10*u.deg, \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)"
Expand All @@ -103,7 +103,7 @@
"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:"
]
},
{
Expand All @@ -113,7 +113,7 @@
"outputs": [],
"source": [
"SkyCoord(\n",
" ra=np.linspace(0, 10, 5)*u.deg, \n",
" ra=np.linspace(0, 10, 5)*u.deg,\n",
" dec=np.linspace(5, 20, 5)*u.deg,\n",
" pm_ra_cosdec=np.linspace(-5, 5, 5)*u.mas/u.yr,\n",
" pm_dec=np.linspace(-5, 5, 5)*u.mas/u.yr)"
Expand All @@ -135,7 +135,7 @@
"outputs": [],
"source": [
"velocity_coord = SkyCoord(\n",
" ra=10*u.deg, \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",
Expand Down Expand Up @@ -214,7 +214,7 @@
"cell_type": "markdown",
"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))"
"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))"
]
},
{
Expand All @@ -227,14 +227,39 @@
},
"outputs": [],
"source": [
"test_coord = SkyCoord(\n",
" ra=10*u.deg, \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": {},
"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": {},
"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())"
]
},
{
Expand All @@ -257,7 +282,7 @@
"outputs": [],
"source": [
"# Skip this cell if you are not connected to the internet\n",
"gaia_tbl = Gaia.query_object(SkyCoord.from_name('HD 219829'), \n",
"gaia_tbl = Gaia.query_object(SkyCoord.from_name('HD 219829'),\n",
" radius=1*u.arcmin)"
]
},
Expand All @@ -268,9 +293,9 @@
"outputs": [],
"source": [
"# the .read() below produces some warnings that we can safely ignore\n",
"with warnings.catch_warnings(): \n",
"with warnings.catch_warnings():\n",
" warnings.simplefilter('ignore', UserWarning)\n",
" \n",
"\n",
" gaia_tbl = QTable.read('HD_219829_query_results.ecsv')"
]
},
Expand Down Expand Up @@ -307,7 +332,7 @@
"outputs": [],
"source": [
"hd219829_coord = SkyCoord(\n",
" ra=hd219829_row['ra'], \n",
" ra=hd219829_row['ra'],\n",
" dec=hd219829_row['dec'],\n",
" distance=Distance(parallax=hd219829_row['parallax']),\n",
" pm_ra_cosdec=hd219829_row['pmra'],\n",
Expand Down Expand Up @@ -352,7 +377,9 @@
"cell_type": "markdown",
"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:"
"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).)"
]
},
{
Expand All @@ -364,7 +391,7 @@
"hdu = fits.open(dss_cutout_filename)[0]\n",
"wcs = WCS(hdu.header)\n",
"\n",
"fig, ax = plt.subplots(1, 1, figsize=(8, 8), \n",
"fig, ax = plt.subplots(1, 1, figsize=(8, 8),\n",
" subplot_kw=dict(projection=wcs))\n",
"ax.imshow(hdu.data, origin='lower', cmap='Greys_r')\n",
"ax.set_xlabel('RA')\n",
Expand Down Expand Up @@ -410,9 +437,9 @@
"outputs": [],
"source": [
"# this produces some warnings that we can safely ignore\n",
"with warnings.catch_warnings(): \n",
"with warnings.catch_warnings():\n",
" warnings.simplefilter('ignore', UserWarning)\n",
" \n",
"\n",
" hd219829_coord_1950 = hd219829_coord.apply_space_motion(\n",
" new_obstime=Time('J1950'))"
]
Expand All @@ -430,7 +457,7 @@
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 1, figsize=(8, 8), \n",
"fig, ax = plt.subplots(1, 1, figsize=(8, 8),\n",
" subplot_kw=dict(projection=wcs))\n",
"ax.imshow(hdu.data, origin='lower', cmap='Greys_r')\n",
"ax.set_xlabel('RA')\n",
Expand Down Expand Up @@ -464,6 +491,27 @@
"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": {},
"source": [
"## Exercises\n"
]
},
{
"cell_type": "markdown",
"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)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -478,5 +526,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 4
"nbformat_minor": 1
}

0 comments on commit ae239d2

Please sign in to comment.