# Path: skyfield/constants.py
# DAY_S = 86400.0


import numpy as np
from ..constants import DAY_S

# This regular expression must remain a plain string; attempting to
# compile it triggers a bug in older NumPy versions like 1.14.3:
# https://github.com/skyfielders/python-skyfield/issues/372
_R = (b'(?m)^......(.........) . '
      b'(.\\d.......)......... '
      b'(.\\d.......).........  '
      b'.(.\\d........)')

def parse_x_y_dut1_from_finals_all(f):
    return np.fromregex(f, _R, [
        ('utc_mjd', float),
        ('x_arcseconds', float),
        ('y_arcseconds', float),
        ('dut1', float),
    ])

def install_polar_motion_table(ts, finals_data):
    t = ts.utc(1858, 11, 17.0 + finals_data['utc_mjd'])
    ts.polar_motion_table = (
        t.tt,
        np.array(finals_data['x_arcseconds']),
        np.array(finals_data['y_arcseconds']),
    )

def build_timescale_arrays(utc_mjd, dut1):
    big_jumps = np.diff(dut1) > 0.9
    leap_second_mask = np.concatenate([[False], big_jumps])
    tt_minus_utc = np.cumsum(leap_second_mask) + 32.184 + 12.0


# Path: skyfield/constants.py
# DAY_S = 86400.0


# Path: skyfield/data/iers.py
import numpy as np
from ..constants import DAY_S


# This regular expression must remain a plain string; attempting to
# compile it triggers a bug in older NumPy versions like 1.14.3:
# https://github.com/skyfielders/python-skyfield/issues/372
_R = (b'(?m)^......(.........) . '
      b'(.\\d.......)......... '
      b'(.\\d.......).........  '
      b'.(.\\d........)')

def parse_x_y_dut1_from_finals_all(f):
    return np.fromregex(f, _R, [
        ('utc_mjd', float),
        ('x_arcseconds', float),
        ('y_arcseconds', float),
        ('dut1', float),
    ])

def install_polar_motion_table(ts, finals_data):
    t = ts.utc(1858, 11, 17.0 + finals_data['utc_mjd'])
    ts.polar_motion_table = (
        t.tt,
        np.array(finals_data['x_arcseconds']),
        np.array(finals_data['y_arcseconds']),
    )

def build_timescale_arrays(utc_mjd, dut1):
    big_jumps = np.diff(dut1) > 0.9
    leap_second_mask = np.concatenate([[False], big_jumps])
    tt_minus_utc = np.cumsum(leap_second_mask) + 32.184 + 12.0


    daily_tt = utc_mjd + tt_minus_utc / DAY_S + 2400000.5