|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +
|
| 4 | + PlotJPLHorizonsEphemeris |
| 5 | + |
| 6 | + - queries JPL horizons with astroquery |
| 7 | + - save the quey as a fits table |
| 8 | + - reads the query results from fits table |
| 9 | + - extracts columns pertaining to comets |
| 10 | + - converts date strings to Time objects |
| 11 | + for use with matplotlib.dates as mdates |
| 12 | + - plots each selected column in a subplot |
| 13 | + - mdates share x-axis on each sub plot |
| 14 | +
|
| 15 | +Created on Sat Mar 21 07:41:24 2020 |
| 16 | +@author: Charles Bell |
| 17 | +""" |
| 18 | + |
| 19 | +import matplotlib.pyplot as plt |
| 20 | +#https://astroquery.readthedocs.io/en/latest/ |
| 21 | +# from astroquery.jplhorizons import Horizons |
| 22 | +from astropy.table import Table |
| 23 | +from astropy.time import Time |
| 24 | +import matplotlib.dates as mdates |
| 25 | +from pandas.plotting import register_matplotlib_converters |
| 26 | +register_matplotlib_converters() |
| 27 | + |
| 28 | + |
| 29 | +""" |
| 30 | + 2021-Jan-01 00:00 |
| 31 | + returns 2021-01-01 00:00:00.000 |
| 32 | + which can be input to astropy.time.Time iso |
| 33 | + to plot dates with matplotlib |
| 34 | +""" |
| 35 | +def getDateTimeUTHorizons(datestr): |
| 36 | + yyyy = datestr[0:4] |
| 37 | + mm = datestr[5:8] |
| 38 | + if (mm == 'Jan'): |
| 39 | + mm = '01' |
| 40 | + if (mm == 'Feb'): |
| 41 | + mm = '02' |
| 42 | + if (mm == 'Mar'): |
| 43 | + mm = '03' |
| 44 | + if (mm == 'Apr'): |
| 45 | + mm = '04' |
| 46 | + if (mm == 'May'): |
| 47 | + mm = '05' |
| 48 | + if (mm == 'Jun'): |
| 49 | + mm = '06' |
| 50 | + if (mm == 'Jul'): |
| 51 | + mm = '07' |
| 52 | + if (mm == 'Aug'): |
| 53 | + mm = '08' |
| 54 | + if (mm == 'Sep'): |
| 55 | + mm = '09' |
| 56 | + if (mm == 'Oct'): |
| 57 | + mm = '10' |
| 58 | + if (mm == 'Nov'): |
| 59 | + mm = '11' |
| 60 | + if (mm == 'Dec'): |
| 61 | + mm = '12' |
| 62 | + dd = datestr[9:11] |
| 63 | + s = yyyy + '-' + mm + '-' + dd |
| 64 | + hrs = datestr[12:14] |
| 65 | + mins = datestr[15:17] |
| 66 | + s = s + ' ' + hrs + ':' + mins +":00.000" |
| 67 | + return s |
| 68 | + |
| 69 | +# uncomment the next three lines to query horizons and save the ephemeris to a fits table |
| 70 | +# obj = Horizons(id='C/2019 Y4', location='500',epochs={'start':'2020-01-01', 'stop':'2021-01-01','step':'1d'} ) |
| 71 | +# eph = obj.ephemerides() |
| 72 | +# eph.write('ephem.fits', format='fits', overwrite=True ) |
| 73 | + |
| 74 | + |
| 75 | +# assumes the ephemeris fits table has been saved |
| 76 | +# if you are modifying this demo code, you should only query the horisons server once |
| 77 | +# and then use the file copy to modify to your needs. |
| 78 | +eph = Table.read('ephem.fits') |
| 79 | + |
| 80 | +objectname = eph.columns[eph.index_column('targetname')] |
| 81 | +datetimestr = eph.columns[eph.index_column('datetime_str')] |
| 82 | +jd = eph.columns[eph.index_column('datetime_jd')] |
| 83 | +r = eph.columns[eph.index_column('r')] |
| 84 | +delta = eph.columns[eph.index_column('delta')] |
| 85 | +tmag = eph.columns[eph.index_column('Tmag')] |
| 86 | +nmag = eph.columns[eph.index_column('Nmag')] |
| 87 | +phase = eph.columns[eph.index_column('alpha')] |
| 88 | +elong = eph.columns[eph.index_column('elong')] |
| 89 | +psang = eph.columns[eph.index_column('sunTargetPA')] |
| 90 | +psamv = eph.columns[eph.index_column('velocityPA')] |
| 91 | +plang = eph.columns[eph.index_column('OrbPlaneAng')] |
| 92 | +trueanomaly = eph.columns[eph.index_column('true_anom')] |
| 93 | +ra = eph.columns[eph.index_column('RA')] |
| 94 | +dec = eph.columns[eph.index_column('DEC')] |
| 95 | +constellation = eph.columns[eph.index_column('constellation')] |
| 96 | + |
| 97 | +datetimes = [] |
| 98 | +for datestr in datetimestr: |
| 99 | + datetimeUT = getDateTimeUTHorizons(datestr) |
| 100 | + dateTime = Time(datetimeUT, format='iso').datetime |
| 101 | + datetimes.append(dateTime) |
| 102 | + |
| 103 | +fig, axs = plt.subplots(9, sharex=True, figsize=(20, 18)) |
| 104 | + |
| 105 | +fig.suptitle('JPL Horizons Ephemeris C/2019 Y4 (ATLAS)', x=0.50, y=0.91, fontsize=24) |
| 106 | + |
| 107 | + |
| 108 | +locator = mdates.AutoDateLocator() |
| 109 | +formatter = mdates.AutoDateFormatter(locator) |
| 110 | +axs[0].xaxis.set_major_locator(locator) |
| 111 | +axs[0].xaxis.set_major_formatter(formatter) |
| 112 | +axs[1].xaxis.set_major_locator(locator) |
| 113 | +axs[1].xaxis.set_major_formatter(formatter) |
| 114 | +axs[2].xaxis.set_major_locator(locator) |
| 115 | +axs[2].xaxis.set_major_formatter(formatter) |
| 116 | +axs[3].xaxis.set_major_locator(locator) |
| 117 | +axs[3].xaxis.set_major_formatter(formatter) |
| 118 | +axs[4].xaxis.set_major_locator(locator) |
| 119 | +axs[4].xaxis.set_major_formatter(formatter) |
| 120 | +axs[5].xaxis.set_major_locator(locator) |
| 121 | +axs[5].xaxis.set_major_formatter(formatter) |
| 122 | +axs[6].xaxis.set_major_locator(locator) |
| 123 | +axs[6].xaxis.set_major_formatter(formatter) |
| 124 | +axs[7].xaxis.set_major_locator(locator) |
| 125 | +axs[7].xaxis.set_major_formatter(formatter) |
| 126 | +axs[8].xaxis.set_major_locator(locator) |
| 127 | +axs[8].xaxis.set_major_formatter(formatter) |
| 128 | + |
| 129 | + |
| 130 | +# plot magnitude plots with inverted y-axis |
| 131 | +axs[0].invert_yaxis() # Total magnitude |
| 132 | +axs[1].invert_yaxis() # Nuclear magnitude |
| 133 | + |
| 134 | +# The x-axis formatted dates are shared in all plots |
| 135 | +axs[8].set_xlabel('Date', fontsize=20) |
| 136 | + |
| 137 | +axs[0].set_ylabel('Tmag', fontsize=20) |
| 138 | +axs[1].set_ylabel('Nmag', fontsize=20) |
| 139 | +axs[2].set_ylabel('r', fontsize=20) |
| 140 | +axs[3].set_ylabel('delta',fontsize=20) |
| 141 | +axs[4].set_ylabel('Phase',fontsize=20) |
| 142 | +axs[5].set_ylabel('Elong',fontsize=20) |
| 143 | +axs[6].set_ylabel('PsAng',fontsize=20) |
| 144 | +axs[7].set_ylabel('PsAMV',fontsize=20) |
| 145 | +axs[8].set_ylabel('PlAng',fontsize=20) |
| 146 | + |
| 147 | + |
| 148 | +axs[0].plot_date(datetimes, tmag, '.', xdate=True, ydate = False) |
| 149 | +axs[1].plot_date(datetimes, nmag, '.', xdate=True, ydate = False) |
| 150 | +axs[2].plot_date(datetimes, r, '.', xdate=True, ydate = False) |
| 151 | +axs[3].plot_date(datetimes, delta, '.', xdate=True, ydate = False) |
| 152 | +axs[4].plot_date(datetimes, phase, '.', xdate=True, ydate = False) |
| 153 | +axs[5].plot_date(datetimes, elong, '.', xdate=True, ydate = False) |
| 154 | +axs[6].plot_date(datetimes, psang, '.', xdate=True, ydate = False) |
| 155 | +axs[7].plot_date(datetimes, psamv, '.', xdate=True, ydate = False) |
| 156 | +axs[8].plot_date(datetimes, plang, '.', xdate=True, ydate = False) |
| 157 | + |
0 commit comments