{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n===================================================================\nDetermining and plotting the altitude/azimuth of a celestial object\n===================================================================\n\nThis example demonstrates coordinate transformations and the creation of\nvisibility curves to assist with observing run planning.\n\nIn this example, we make a `~astropy.coordinates.SkyCoord` instance for M33.\nThe altitude-azimuth coordinates are then found using\n`astropy.coordinates.EarthLocation` and `astropy.time.Time` objects.\n\nThis example is meant to demonstrate the capabilities of the\n`astropy.coordinates` package. For more convenient and/or complex observation\nplanning, consider the `astroplan `_\npackage.\n\n-------------------\n\n*By: Erik Tollerud, Kelle Cruz*\n\n*License: BSD*\n\n-------------------\n\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's suppose you are planning to visit picturesque Bear Mountain State Park\nin New York, USA. You're bringing your telescope with you (of course), and\nsomeone told you M33 is a great target to observe there. You happen to know\nyou're free at 11:00 pm local time, and you want to know if it will be up.\nAstropy can answer that.\n\nImport numpy and matplotlib. For the latter, use a nicer set of plot\nparameters and set up support for plotting/converting quantities.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nimport matplotlib.pyplot as plt\nfrom astropy.visualization import astropy_mpl_style, quantity_support\nplt.style.use(astropy_mpl_style)\nquantity_support()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import the packages necessary for finding coordinates and making\ncoordinate transformations\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import astropy.units as u\nfrom astropy.time import Time\nfrom astropy.coordinates import SkyCoord, EarthLocation, AltAz" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`astropy.coordinates.SkyCoord.from_name` uses Simbad to resolve object\nnames and retrieve coordinates.\n\nGet the coordinates of M33:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "m33 = SkyCoord.from_name('M33')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use `astropy.coordinates.EarthLocation` to provide the location of Bear\nMountain and set the time to 11pm EDT on 2012 July 12:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "bear_mountain = EarthLocation(lat=41.3*u.deg, lon=-74*u.deg, height=390*u.m)\nutcoffset = -4*u.hour # Eastern Daylight Time\ntime = Time('2012-7-12 23:00:00') - utcoffset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`astropy.coordinates.EarthLocation.get_site_names` and\n`~astropy.coordinates.EarthLocation.get_site_names` can be used to get\nlocations of major observatories.\n\nUse `astropy.coordinates` to find the Alt, Az coordinates of M33 at as\nobserved from Bear Mountain at 11pm on 2012 July 12.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "m33altaz = m33.transform_to(AltAz(obstime=time,location=bear_mountain))\nprint(\"M33's Altitude = {0.alt:.2}\".format(m33altaz))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is helpful since it turns out M33 is barely above the horizon at this\ntime. It's more informative to find M33's airmass over the course of\nthe night.\n\nFind the alt,az coordinates of M33 at 100 times evenly spaced between 10pm\nand 7am EDT:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "midnight = Time('2012-7-13 00:00:00') - utcoffset\ndelta_midnight = np.linspace(-2, 10, 100)*u.hour\nframe_July13night = AltAz(obstime=midnight+delta_midnight,\n location=bear_mountain)\nm33altazs_July13night = m33.transform_to(frame_July13night)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "convert alt, az to airmass with `~astropy.coordinates.AltAz.secz` attribute:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "m33airmasss_July13night = m33altazs_July13night.secz" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot the airmass as a function of time:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plt.plot(delta_midnight, m33airmasss_July13night)\nplt.xlim(-2, 10)\nplt.ylim(1, 4)\nplt.xlabel('Hours from EDT Midnight')\nplt.ylabel('Airmass [Sec(z)]')\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use `~astropy.coordinates.get_sun` to find the location of the Sun at 1000\nevenly spaced times between noon on July 12 and noon on July 13:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from astropy.coordinates import get_sun\ndelta_midnight = np.linspace(-12, 12, 1000)*u.hour\ntimes_July12_to_13 = midnight + delta_midnight\nframe_July12_to_13 = AltAz(obstime=times_July12_to_13, location=bear_mountain)\nsunaltazs_July12_to_13 = get_sun(times_July12_to_13).transform_to(frame_July12_to_13)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do the same with `~astropy.coordinates.get_moon` to find when the moon is\nup. Be aware that this will need to download a 10MB file from the internet\nto get a precise location of the moon.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from astropy.coordinates import get_moon\nmoon_July12_to_13 = get_moon(times_July12_to_13)\nmoonaltazs_July12_to_13 = moon_July12_to_13.transform_to(frame_July12_to_13)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Find the alt,az coordinates of M33 at those same times:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "m33altazs_July12_to_13 = m33.transform_to(frame_July12_to_13)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make a beautiful figure illustrating nighttime and the altitudes of M33 and\nthe Sun over that time:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plt.plot(delta_midnight, sunaltazs_July12_to_13.alt, color='r', label='Sun')\nplt.plot(delta_midnight, moonaltazs_July12_to_13.alt, color=[0.75]*3, ls='--', label='Moon')\nplt.scatter(delta_midnight, m33altazs_July12_to_13.alt,\n c=m33altazs_July12_to_13.az, label='M33', lw=0, s=8,\n cmap='viridis')\nplt.fill_between(delta_midnight, 0*u.deg, 90*u.deg,\n sunaltazs_July12_to_13.alt < -0*u.deg, color='0.5', zorder=0)\nplt.fill_between(delta_midnight, 0*u.deg, 90*u.deg,\n sunaltazs_July12_to_13.alt < -18*u.deg, color='k', zorder=0)\nplt.colorbar().set_label('Azimuth [deg]')\nplt.legend(loc='upper left')\nplt.xlim(-12*u.hour, 12*u.hour)\nplt.xticks((np.arange(13)*2-12)*u.hour)\nplt.ylim(0*u.deg, 90*u.deg)\nplt.xlabel('Hours from EDT Midnight')\nplt.ylabel('Altitude [deg]')\nplt.show()" ] } ], "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.6.7" } }, "nbformat": 4, "nbformat_minor": 0 }