Skip to content

Commit

Permalink
start working on figures
Browse files Browse the repository at this point in the history
  • Loading branch information
moustakas committed May 23, 2020
1 parent 8b0cf23 commit 67d50b4
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 144 deletions.
115 changes: 0 additions & 115 deletions py/LSLGA/desiutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
from matplotlib.patches import Ellipse
from astropy.coordinates import SkyCoord, HeliocentricTrueEcliptic, ICRS, Longitude
import astropy.units as u
from astropy.time import Time
from astropy.utils import iers
from .iers import freeze_iers


def plot_slices(x, y, x_lo, x_hi, y_cut, num_slices=5, min_count=100, axis=None,
set_ylim_from_stats=True, scatter=True):
Expand Down Expand Up @@ -1003,114 +999,3 @@ def plot_sky_binned(ra, dec, weights=None, data=None, plot_type='grid',
return ax


def plot_iers(which='auto', num_points=500, save=None):
"""Plot IERS data from 2015-2025.
Plots the UT1-UTC time offset and polar x,y motions over a 10-year
period that includes the DESI survey, to demonstrate the time ranges
when different sources (IERS-A, IERS-B) are used and where values
are predicted then fixed.
This function is primarily intended to document and debug the
:func:`desiutil.iers.freeze_iers` function.
Requires that the matplotlib package is installed.
Parameters
----------
which : {'auto', 'A', 'B', 'frozen'}
Select which IERS table source to use. The default 'auto' matches
the internal astropy default. Use 'A' or 'B' to force the source
to be either the latest IERS-A table (which will be downloaded),
or the IERS-B table packaged with the current version of astropy.
The 'frozen' option calls :func:`~desiutil.iers.freeze_iers`.
num_points : :class:`int`, optional
The number of times covering 2015-25 to calculate and plot.
save : :class:`str`, optional
Name of file where plot should be saved. Format is inferred from
the extension.
Returns
-------
:func:`tuple`
Tuple (figure, axes) returned by ``plt.subplots()``.
"""
#
# These values are copied from the desisurvey config.yaml file.
# They may or may not reflect the latest configuration.
#
# Survey nominally starts on night of this date. Format is YYYY-MM-DD.
first_day = date(2019, 12, 1)
# Survey nominally ends on morning of this date. Format is YYYY-MM-DD.
last_day = date(2024, 11, 30)

# Calculate UTC midnight timestamps covering 2015 - 2025
start = Time('2015-01-01 00:00')
stop = Time('2025-01-01 00:00')
mjd = np.linspace(start.mjd, stop.mjd, num_points)
times = Time(mjd, format='mjd')

t_lo = matplotlib.dates.date2num(start.datetime)
t_hi = matplotlib.dates.date2num(stop.datetime)
t = np.linspace(t_lo, t_hi, num_points)

t_start = matplotlib.dates.date2num(first_day)
t_stop = matplotlib.dates.date2num(last_day)

# Load the specified IERS table.
if which == 'auto':
iers = iers.IERS_Auto.open()
elif which == 'B':
iers = iers.IERS_B.open()
elif which == 'A':
# This requires network access to download the latest file.
iers = iers.IERS_A.open(iers.conf.iers_auto_url)
elif which == 'frozen':
freeze_iers()
iers = iers.IERS_Auto.open()
else:
raise ValueError('Invalid which option.')

# Calculate UT1-UTC using the IERS table.
dt, dt_status = iers.ut1_utc(times, return_status=True)
dt = dt.to(u.s).value

# Calculate polar x,y motion using the IERS table.
pmx, pmy, pm_status = iers.pm_xy(times, return_status=True)
pmx = pmx.to(u.arcsec).value
pmy = pmy.to(u.arcsec).value

assert np.all(dt_status == pm_status)
codes = np.unique(dt_status)

fig, ax = plt.subplots(2, 1, sharex=True, figsize=(8, 6))

labels = {-2: 'Fixed', 0: 'IERS-B', 1: 'IERS-A', 2: 'Predict'}
styles = {-2: 'r:', 0: 'b-', 1: 'go', 2: 'r--'}
ms = 3
for code in codes:
sel = dt_status == code
ax[0].plot(t[sel], dt[sel], styles[code], ms=ms, label=labels[code])
ax[1].plot(t[sel], pmx[sel], styles[code], ms=ms, label='Polar x')
ax[1].plot(t[sel], pmy[sel], styles[code], ms=ms, label='Polar y')

ax[0].legend(ncol=4)
ax[0].set_ylabel('UT1 - UTC [s]')
ax[1].set_ylabel('Polar x,y motion [arcsec]')

for i in range(2):
# Vertical lines showing the survey start / stop dates.
ax[i].axvline(t_start, ls='--', c='k')
ax[i].axvline(t_stop, ls='--', c='k')

# Use year labels for the horizontal axis.
xaxis = ax[1].xaxis
xaxis.set_major_locator(matplotlib.dates.YearLocator())
xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%Y'))
ax[i].set_xlim(start.datetime, stop.datetime)

plt.tight_layout()
if save:
plt.savefig(save)

return fig, ax
163 changes: 134 additions & 29 deletions science/paper1/figures.ipynb

Large diffs are not rendered by default.

0 comments on commit 67d50b4

Please sign in to comment.