Time conversion functions¶
Time transformations
This handles all the wibbly wobbly timey wimey stuff. Such as easy conversions between different time systems. Supported systems: GPS, UTC, GMST, LST, JD and MJD.
Formulae from:
IETF list of leap seconds ‘Leap seconds announced by the IERS’ https://www.ietf.org/timezones/data/leap-seconds.list
Duffett-Smith1990 ‘Astronomy with your personal computer’ ISBN 0-521-38995-X
USNO ‘Computing Greenwich Apparent Sidereal Time’ http://aa.usno.navy.mil/faq/docs/GAST.php
Adrian Price-Whelan apwlib.convert https://github.com/adrn/apwlib
- sapphire.transformations.clock.LEAP_SECONDS = (('January 1, 2017', 18), ('July 1, 2015', 17), ('July 1, 2012', 16), ('January 1, 2009', 15), ('January 1, 2006', 14), ('January 1, 1999', 13), ('July 1, 1997', 12), ('January 1, 1996', 11), ('July 1, 1994', 10), ('July 1, 1993', 9), ('July 1, 1992', 8), ('January 1, 1991', 7), ('January 1, 1990', 6), ('January 1, 1988', 5), ('July 1, 1985', 4), ('July 1, 1983', 3), ('July 1, 1982', 2), ('July 1, 1981', 1))¶
Dates of leap second introductions.
- sapphire.transformations.clock.time_to_decimal(time)¶
Converts a time or datetime object into decimal time
- Parameters:
time – datetime.time or datetime.datetime object.
- Returns:
decimal number representing the input time.
- sapphire.transformations.clock.decimal_to_time(hours)¶
Converts decimal time to a time object
- Parameters:
hours – datetime.time or datetime.datetime object.
- Returns:
decimal number representing the input time.
- sapphire.transformations.clock.date_to_juliandate(year, month, day)¶
Convert year, month, and day to a Julian Date
Julian Date is the number of days since noon on January 1, 4713 B.C. So the returned date will end in .5 because the date refers to midnight.
- Parameters:
year – a Gregorian year (B.C. years are negative).
month – a Gregorian month (1-12).
day – a Gregorian day (1-31).
- Returns:
the Julian Date for the given year, month, and day.
- sapphire.transformations.clock.datetime_to_juliandate(dt)¶
Convert a datetime object in UTC to a Julian Date
- Parameters:
dt – datetime object.
- Returns:
The Julian Date for the given datetime object.
- sapphire.transformations.clock.juliandate_to_modifiedjd(juliandate)¶
Convert a Julian Date to a Modified Julian Date
- Parameters:
juliandate – a Julian Date.
- Returns:
the Modified Julian Date.
- sapphire.transformations.clock.modifiedjd_to_juliandate(modifiedjd)¶
Convert a Modified Julian Date to Julian Date
- Parameters:
modifiedjf – a Modified Julian Date.
- Returns:
Julian Date.
- sapphire.transformations.clock.datetime_to_modifiedjd(dt)¶
Convert a datetime object in UTC to a Modified Julian Date
- Parameters:
dt – datetime object.
- Returns:
the Modified Julian Date.
- sapphire.transformations.clock.juliandate_to_gmst(juliandate)¶
Convert a Julian Date to Greenwich Mean Sidereal Time
- Parameters:
juliandate – Julian Date.
- Returns:
decimal hours in GMST.
- sapphire.transformations.clock.utc_to_gmst(dt)¶
Convert a datetime object in UTC time to Greenwich Mean Sidereal Time
- Parameters:
dt – datetime object in UTC time.
- Returns:
decimal hours in GMST.
- sapphire.transformations.clock.gmst_to_utc(dt)¶
Convert datetime object in Greenwich Mean Sidereal Time to UTC
Note: this requires a datetime object, not just the decimal hours.
- Parameters:
dt – datetime object in GMST time.
- Returns:
datetime object in UTC.
- sapphire.transformations.clock.juliandate_to_utc(juliandate)¶
Convert Julian Date to datetime object in UTC
- Parameters:
juliandate – a Julian Date.
- Returns:
datetime object in UTC time.
- sapphire.transformations.clock.modifiedjd_to_utc(modifiedjd)¶
Convert a Modified Julian Date to datetime object in UTC
- Parameters:
juliandate – a Modified Julian Date.
- Returns:
datetime object in UTC time.
- sapphire.transformations.clock.gmst_to_lst(hours, longitude)¶
Convert Greenwich Mean Sidereal Time to Local Sidereal Time
- Parameters:
hours – decimal hours in GMST.
longitude – location in degrees, east positive.
- Returns:
decimal hours in LST.
- sapphire.transformations.clock.lst_to_gmst(hours, longitude)¶
Convert Local Sidereal Time to Greenwich Mean Sidereal Time
- Parameters:
hours – decimal hours in LST.
longitude – location in degrees, east positive.
- Returns:
decimal hours in GMST.
- sapphire.transformations.clock.utc_to_lst(dt, longitude)¶
Convert UTC to Local Sidereal Time
- Parameters:
dt – datetime object in UTC.
longitude – location in degrees, east positive.
- Returns:
decimal hours in LST.
- sapphire.transformations.clock.gps_to_utc(timestamp)¶
Convert GPS time to UTC
- Parameters:
timestamp – GPS timestamp in seconds.
- Returns:
UTC timestamp in seconds.
- sapphire.transformations.clock.utc_to_gps(timestamp)¶
Convert UTC to GPS time
- Parameters:
timestamp – UTC timestamp in seconds.
- Returns:
GPS timestamp in seconds.
- sapphire.transformations.clock.utc_from_string(date)¶
Convert a date string to UTC
- Parameters:
date – date string.
- Returns:
UTC timestamp in seconds.
- sapphire.transformations.clock.gps_from_string(date)¶
Convert a date string to GPS time
- Parameters:
date – date string.
- Returns:
GPS timestamp in seconds.
- sapphire.transformations.clock.gps_to_lst(timestamp, longitude)¶
Convert a GPS timestamp to lst
- Parameters:
timestamp – GPS timestamp in seconds.
longitude – location in degrees, east positive.
- Returns:
decimal hours in LST.
- sapphire.transformations.clock.gps_to_datetime(timestamp)¶
Convert a GPS timestamp to datetime object
- Parameters:
timestamp – GPS timestamp in seconds.
- Returns:
datetime object.
- sapphire.transformations.clock.datetime_to_gps(dt)¶
Convert a GPS datetime object to a timestamp
- Parameters:
dt – GPS datetime object.
- Returns:
GPS timestamp in seconds.
- sapphire.transformations.clock.process_time(time)¶
Convert timestamp or datetime to timestamp
- Parameters:
time – GPS datetime object or GPS timestamp.
- Returns:
GPS timestamp.