<jupyter_start><jupyter_text>===================================================================Determining and plotting the altitude/azimuth of a celestial object===================================================================This example demonstrates coordinate transformations and the creation ofvisibility curves to assist with observing run planning.In this example, we make a `~astropy.coordinates.SkyCoord` instance for M33.The altitude-azimuth coordinates are then found using`astropy.coordinates.EarthLocation` and `astropy.time.Time` objects.This example is meant to demonstrate the capabilities of the`astropy.coordinates` package. For more convenient and/or complex observationplanning, consider the `astroplan `_package.-------------------*By: <NAME>, <NAME>**License: BSD*------------------- Let's suppose you are planning to visit picturesque Bear Mountain State Parkin New York, USA. You're bringing your telescope with you (of course), andsomeone told you M33 is a great target to observe there. You happen to knowyou're free at 11:00 pm local time, and you want to know if it will be up.Astropy can answer that.Make print work the same in all versions of Python, set up numpy,matplotlib, and use a nicer set of plot parameters:<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from astropy.visualization import astropy_mpl_style
plt.style.use(astropy_mpl_style)<jupyter_output><empty_output><jupyter_text>Import the packages necessary for finding coordinates and makingcoordinate transformations<jupyter_code>import astropy.units as u
from astropy.time import Time
from astropy.coordinates import SkyCoord, EarthLocation, AltAz<jupyter_output><empty_output><jupyter_text>`astropy.coordinates.SkyCoord.from_name` uses Simbad to resolve objectnames and retrieve coordinates.Get the coordinates of M33:<jupyter_code>m33 = SkyCoord.from_name('M33')<jupyter_output><empty_output><jupyter_text>Use `astropy.coordinates.EarthLocation` to provide the location of BearMountain and set the time to 11pm EDT on 2012 July 12:<jupyter_code>bear_mountain = EarthLocation(lat=41.3*u.deg, lon=-74*u.deg, height=390*u.m)
utcoffset = -4*u.hour  # Eastern Daylight Time
time = Time('2012-7-12 23:00:00') - utcoffset<jupyter_output><empty_output><jupyter_text>`astropy.coordinates.EarthLocation.get_site_names` and`~astropy.coordinates.EarthLocation.get_site_names` can be used to getlocations of major observatories.Use `astropy.coordinates` to find the Alt, Az coordinates of M33 at asobserved from Bear Mountain at 11pm on 2012 July 12.<jupyter_code>m33altaz = m33.transform_to(AltAz(obstime=time,location=bear_mountain))
print("M33's Altitude = {0.alt:.2}".format(m33altaz))<jupyter_output>M33's Altitude = 0.13 deg<jupyter_text>This is helpful since it turns out M33 is barely above the horizon at thistime. It's more informative to find M33's airmass over the course ofthe night.Find the alt,az coordinates of M33 at 100 times evenly spaced between 10pmand 7am EDT:<jupyter_code>midnight = Time('2012-7-13 00:00:00') - utcoffset
delta_midnight = np.linspace(-2, 10, 100)*u.hour
frame_July13night = AltAz(obstime=midnight+delta_midnight,
                          location=bear_mountain)
m33altazs_July13night = m33.transform_to(frame_July13night)<jupyter_output><empty_output><jupyter_text>convert alt, az to airmass with `~astropy.coordinates.AltAz.secz` attribute:<jupyter_code>m33airmasss_July13night = m33altazs_July13night.secz<jupyter_output><empty_output><jupyter_text>Plot the airmass as a function of time:<jupyter_code>plt.plot(delta_midnight, m33airmasss_July13night)
plt.xlim(-2, 10)
plt.ylim(1, 4)
plt.xlabel('Hours from EDT Midnight')
plt.ylabel('Airmass [Sec(z)]')
plt.show()<jupyter_output><empty_output><jupyter_text>Use  `~astropy.coordinates.get_sun` to find the location of the Sun at 1000evenly spaced times between noon on July 12 and noon on July 13:<jupyter_code>from astropy.coordinates import get_sun
delta_midnight = np.linspace(-12, 12, 1000)*u.hour
times_July12_to_13 = midnight + delta_midnight
frame_July12_to_13 = AltAz(obstime=times_July12_to_13, location=bear_mountain)
sunaltazs_July12_to_13 = get_sun(times_July12_to_13).transform_to(frame_July12_to_13)<jupyter_output><empty_output><jupyter_text>Do the same with `~astropy.coordinates.get_moon` to find when the moon isup. Be aware that this will need to download a 10MB file from the internetto get a precise location of the moon.<jupyter_code>from astropy.coordinates import get_moon
moon_July12_to_13 = get_moon(times_July12_to_13)
moonaltazs_July12_to_13 = moon_July12_to_13.transform_to(frame_July12_to_13)<jupyter_output><empty_output><jupyter_text>Find the alt,az coordinates of M33 at those same times:<jupyter_code>m33altazs_July12_to_13 = m33.transform_to(frame_July12_to_13)<jupyter_output><empty_output><jupyter_text>Make a beautiful figure illustrating nighttime and the altitudes of M33 andthe Sun over that time:<jupyter_code>plt.plot(delta_midnight, sunaltazs_July12_to_13.alt, color='r', label='Sun')
plt.plot(delta_midnight, moonaltazs_July12_to_13.alt, color=[0.75]*3, ls='--', label='Moon')
plt.scatter(delta_midnight, m33altazs_July12_to_13.alt,
            c=m33altazs_July12_to_13.az, label='M33', lw=0, s=8,
            cmap='viridis')
plt.fill_between(delta_midnight.to('hr').value, 0, 90,
                 sunaltazs_July12_to_13.alt < -0*u.deg, color='0.5', zorder=0)
plt.fill_between(delta_midnight.to('hr').value, 0, 90,
                 sunaltazs_July12_to_13.alt < -18*u.deg, color='k', zorder=0)
plt.colorbar().set_label('Azimuth [deg]')
plt.legend(loc='upper left')
plt.xlim(-12, 12)
plt.xticks(np.arange(13)*2 -12)
plt.ylim(0, 90)
plt.xlabel('Hours from EDT Midnight')
plt.ylabel('Altitude [deg]')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12197231833910034, 'fraction_numerical': 0.04602076124567474, 'mean_word_length': 6.656953642384106, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '324699', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 2175, 'n_tokens_neox': 1916, 'n_words': 480, 'path': 'plot_obs-planning.ipynb', 'repo_name': 'Niu-LIU/Canopus', 'size': '5791'}