{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Coordinate systems: Examples and exercises - Python Notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Below you can find some examples of using the Python library \"astropy\" to perfrom commonly used astronomical co-ordinate transformations. Read through this \"Examples\" Section and **try executing each cell in turn yourself**, and then continue onto the \"Exercises\" section, where you can use similar commands to solve some different problems. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Examples" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this tutorial we will look at coordinates and coordinate systems. Let us start with defining a coordinate object. Orion A has J2000 equatorial coordinates R.A. 05h35m17s and Dec. -05d23m28s. " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "from astropy.coordinates import SkyCoord\n", "# Define target as Orion A, coordinates from e.g. \n", "# http://ned.ipac.caltech.edu\n", "orion = SkyCoord('05h35m17s', '-05d23m28s') \n", "# SkyCoord assumes we're using ICRS coordinate system as default\n", "# First we can print the coordinate object itself.\n", "print(orion)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What is Orion A's declination expressed in decimal degrees and radians?" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dec -5.391111111111112 degrees\n", "-0.0940926rad\n", "Dec = -5.391111111111112 degrees = -0.09409263922973876 radians\n" ] } ], "source": [ "from astropy import units as u\n", "# We can print each coordinate in various units\n", "print(\"Dec\", orion.dec.degree, \"degrees\")\n", "print(orion.dec.to_string(unit=u.radian))\n", "print(\"Dec = \" + str(orion.dec.deg) + ' degrees = ' + str(orion.dec.radian) + ' radians')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another common coordinate system is the Galactic system. The galactic longitude (l) and latitude (b) for Orion A is simply:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "print(orion.galactic)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Astropy knows about not only celestial coordinates, but also terrestial coordinates and time systems. This is very useful to, for example, calculate source altitude for a specific time and place. To calculate altitudes at Kuntunse observatory, we first need to define it as an EarthLocation object. We use \"units\" to specify the angles for latitude and longitude." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from astropy import units as u\n", "from astropy.coordinates import EarthLocation\n", "\n", "# Define kuntunse observatory location.\n", "# Positive lat, lon towards North and East \n", "# (The default reference ellipsoid is the latest \n", "# revision of the World Geodetic System WGS84)\n", "\n", "kuntunse = EarthLocation(lat = 5.7504*u.deg, lon = -0.3051*u.deg)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(, , )\n" ] } ], "source": [ "# Once we have an EarthLocation object, we can e.g. \n", "# calculate the corresponding geocentric X,Y,Z coordinates as \n", "print(kuntunse.geocentric)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We're interested in source altitude from Kuntunse at a specific time. First define the date and time when we observe:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Time: 2017-04-24T14:00:00.000\n" ] } ], "source": [ "from astropy.time import Time\n", "# Observing time\n", "time = Time('2017-04-24T14:00:00', location = kuntunse)\n", "print(\"Time:\", time)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Astropy time objects are very nice, since we can easily convert to other time frames such as Local Sidereal Time LST." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: failed to download ftp://cddis.gsfc.nasa.gov/pub/products/iers/finals2000A.all and https://datacenter.iers.org/data/9/finals2000A.all, using local IERS-B: [astropy.utils.iers.iers]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "LST at Kuntunse: 4h09m56.4566s\n" ] } ], "source": [ "# Print this as LST\n", "print(\"LST at Kuntunse:\", str(time.sidereal_time('apparent')))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "ename": "SyntaxError", "evalue": "invalid syntax (, line 1)", "output_type": "error", "traceback": [ "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m HA = LST - RA, so since RA for Orion A is '05h35m17s', the hour angle is negative so the object is setting\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" ] } ], "source": [ "HA = LST - RA, so since RA for Orion A is '05h35m17s', the hour angle is negative so the object is setting " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To calculate the altitude for Orion A at the specified time and place, using the AltAz function:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from astropy.coordinates import SkyCoord, AltAz\n", "# Define orion A as a coordinate object\n", "orion = SkyCoord('05h35m17s', '-05d23m28s')\n", "\n", "# Calculate the local altitude and azimuth at Kuntunse at the specified time\n", "altaz = orion.transform_to(AltAz(obstime=time,location=kuntunse))\n", "\n", "# Print the altaz object to see all details.\n", "print(altaz)\n", "# Print source altitude in degrees\n", "print(\"Orion A altitude a this time is \" + str(round(altaz.alt.deg,2)) + \" degrees\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercises for the student\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(1) (Complete the Table in the Co-ordinate System exercises pdf - no Python coding required for this.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(2) The Crab Nebula (Tau A) is the brightest radio source in the sky and has RA = 05h 34m 32s and Dec = +22° 00′ 52'' in J2000 epoch co-ordinates.\n", "\n", "- Create at SkyCoord object for TauA, in a similar way as was for Orion A above. \n", "\n", "Now use this object to find the galactic co-ordinates TauA." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Student to insert code here...\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(3) An observer would like to observe TauA from the Onsala 20 m telescope in Sweden (lat 57.395773N, lon 11.926377E).\n", "\n", "- Use astropy to create a suitable location object for Onsala. \n", "\n", "The observer would like observe TauA on 15 June 2021 at 05:30 **local time**.\n", "\n", "- Use astropy.time to create a suitable Time object to represent this local time.\n", "\n", "Now use the AltAz function to calculate the altitude and elevation of TauA at the observing time. Is the object observable (i.e. above the horizon)?" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Student to insert code here.\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Is the object observable (i.e. above the horizon)?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Student to insert code here.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Is the object rising or setting (altitude increasing or decreasing with respect to time)?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Student to insert code here.\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }