Caltech-IPAC / kete

Kete Solar System Survey tools
https://Caltech-IPAC.github.io/kete
BSD 3-Clause "New" or "Revised" License
12 stars 1 forks source link

Time conversion - Fraction of year #46

Closed dahlend closed 5 months ago

dahlend commented 5 months ago

It is helpful for plotting to have tools which convert a JD to the year + fraction of year.

import calendar

def days_in_year(year):
    """Return the number of days in the specified year."""
    return 365 + calendar.isleap(year)

def ymd(jd):
    """Given a JD, return the time as year + fraction of year."""
    tup = neospy.Time(jd).time.utc.datetime.timetuple()
    # tup.tm_yday should probably have a -1
    frac = neospy.time.d_h_m_s_to_float_days(tup.tm_yday, tup.tm_hour, tup.tm_min, tup.tm_sec)
    return tup.tm_year + frac / days_in_year(tup.tm_year)