time
Utilities for calculating time operations
Can convert delta time from seconds since an epoch to time since a different epoch
Can calculate the time in days since epoch from calendar dates
Can count the number of leap seconds between a given GPS time and UTC
Syncs leap second files with NIST servers
Calling Sequence
Count the number of leap seconds between a GPS time and UTC
import SMBcorr.time
leap_seconds = SMBcorr.time.count_leap_seconds(gps_seconds)
Convert a time from seconds since 1980-01-06T00:00:00 to Modified Julian Days (MJD)
import SMBcorr.time
MJD = SMBcorr.time.convert_delta_time(delta_time, epoch1=(1980,1,6,0,0,0),
epoch2=(1858,11,17,0,0,0), scale=1.0/86400.0)
Convert a calendar date into Modified Julian Days
import SMBcorr.time
MJD = SMBcorr.time.convert_calendar_dates(YEAR,MONTH,DAY,hour=HOUR,
minute=MINUTE,second=SECOND,epoch=(1858,11,17,0,0,0))
General Methods
- SMBcorr.time.parse_date_string(date_string)[source]
parse a date string of the form
time-units since
yyyy-mm-dd hh:mm:ssyyyy-mm-dd hh:mm:ssfor exact calendar dates
- Parameters:
- date_string: str
time-units since yyyy-mm-dd hh:mm:ss
- Returns:
- epoch: list
epoch of delta time
- conversion_factor: float
multiplication factor to convert to seconds
- SMBcorr.time.split_date_string(date_string)[source]
split a date string into units and epoch
- Parameters:
- date_string: str
time-units since yyyy-mm-dd hh:mm:ss
- SMBcorr.time.datetime_to_list(date)[source]
convert a datetime object into a list
- Parameters:
- date: datetime object
- Returns:
- date: list
[year,month,day,hour,minute,second]
- SMBcorr.time.calendar_days(year)[source]
Calculates the number of days per month for a given year
- Parameters:
- year: int or float
calendar year
- Returns:
- dpm: list
number of days for each month
- SMBcorr.time.convert_datetime(date, epoch=(1970, 1, 1, 0, 0, 0))[source]
Convert a numpy datetime array to seconds since
epoch- Parameters:
- date: obj
numpy datetime array
- epoch: tuple, default (1970,1,1,0,0,0)
epoch for output delta_time
- Returns:
- delta_time: float
seconds since epoch
- SMBcorr.time.convert_delta_time(delta_time, epoch1=None, epoch2=None, scale=1.0)[source]
Convert delta time from seconds since
epoch1to time sinceepoch2- Parameters:
- delta_time: float
seconds since epoch1
- epoch1: tuple or NoneType, default None
epoch for input delta_time
- epoch2: tuple or NoneType, default None
epoch for output delta_time
- scale: float, default 1.0
scaling factor for converting time to output units
- SMBcorr.time.convert_calendar_dates(year, month, day, hour=0.0, minute=0.0, second=0.0, epoch=(1992, 1, 1, 0, 0, 0), scale=1.0)[source]
Calculate the time in time units since
epochfrom calendar dates- Parameters:
- year: float
calendar year
- month: float
month of the year
- day: float
day of the month
- hour: float, default 0.0
hour of the day
- minute: float, default 0.0
minute of the hour
- second: float, default 0.0
second of the minute
- epoch: tuple, default (1992,1,1,0,0,0)
epoch for output delta_time
- scale: float, default 1.0
scaling factor for converting time to output units
- Returns:
- delta_time: float
days since epoch
- SMBcorr.time.convert_calendar_decimal(year, month, day=None, hour=None, minute=None, second=None, DofY=None)[source]
Converts from calendar date into decimal years taking into account leap years
- Parameters:
- year: float
calendar year
- month: float
calendar month
- day: float or NoneType, default None
day of the month
- hour: float or NoneType, default None
hour of the day
- minute: float or NoneType, default None
minute of the hour
- second: float or NoneType, default None
second of the minute
- DofY: float or NoneType, default None
day of the year (January 1 = 1)
- Returns:
- t_date: float
date in decimal-year format
References
[1]Dershowitz, N. and E.M. Reingold. 2008. Calendrical Calculations. Cambridge: Cambridge University Press.
- SMBcorr.time.convert_julian(JD, **kwargs)[source]
Converts from Julian day to calendar date and time
- Parameters:
- JD: float
Julian Day (days since 01-01-4713 BCE at 12:00:00)
- astype: str or NoneType, default None
convert output to variable type
- format: str, default ‘dict’
format of output variables
'dict': dictionary with variable keys'tuple': tuple in most-to-least-significant order'zip': aggregated variable sets
- Returns:
- year: float
calendar year
- month: float
calendar month
- day: float
day of the month
- hour: float
hour of the day
- minute: float
minute of the hour
- second: float
second of the minute
References
[1]“Numerical Recipes in C”, by William H. Press, Brian P. Flannery, Saul A. Teukolsky, and William T. Vetterling. Cambridge University Press, 1988 (second printing).
[2]Hatcher, D. A., “Simple Formulae for Julian Day Numbers and Calendar Dates”, Quarterly Journal of the Royal Astronomical Society, 25(1), 1984.
- SMBcorr.time.count_leap_seconds(GPS_Time, truncate=True)[source]
Counts the number of leap seconds between a given GPS time and UTC
- Parameters:
- GPS_Time: float
seconds since January 6, 1980 at 00:00:00
- truncate: bool, default True
Reduce list of leap seconds to positive GPS times
- Returns:
- n_leaps: float
number of elapsed leap seconds
- SMBcorr.time.get_leap_seconds(truncate=True)[source]
Gets a list of GPS times for when leap seconds occurred
- Parameters:
- truncate: bool, default True
Reduce list of leap seconds to positive GPS times
- Returns:
- GPS time: float
GPS seconds when leap seconds occurred
- SMBcorr.time.update_leap_seconds(timeout=20, verbose=False, mode=509)[source]
Connects to servers to download leap-seconds.list files from NIST servers
Servers and Mirrors
- Parameters:
- timeout: int, default 20
timeout in seconds for blocking operations
- verbose: bool, default False
print file information about output file
- mode: oct, default 0o775
permissions mode of output file