OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
time_utils.py
Go to the documentation of this file.
1 """
2 Module to hold time utility classes and functions.
3 """
4 
5 from datetime import datetime, timezone, timedelta
6 import os
7 
8 def convert_month_day_to_doy(mon, dom, yr):
9  """
10  Returns a day of year computed from the provided month (mon parameter),
11  day of month(dom parameter), and year (yr parameter).
12  """
13  date_obj = datetime(int(yr), int(mon), int(dom))
14  doy = date_obj.timetuple().tm_yday
15  return doy
16 
17 def get_leap_seconds(taitime,epochyear=1958):
18  '''
19  Return the number of elapsed leap seconds given a TAI time in seconds
20  Requires tai-utc.dat
21  '''
22 
23  import julian
24 
25  epochsecs = (datetime(epochyear,1,1,0,0,0,tzinfo=timezone.utc) - datetime(1970,1,1,0,0,0,tzinfo=timezone.utc)).total_seconds()
26  taidt = datetime.utcfromtimestamp(taitime + epochsecs)
27  taiutc = os.path.join(os.environ['OCVARROOT'], 'common', 'tai-utc.dat')
28  leapsec = 0
29  with open(taiutc, "r") as tdat:
30  for line in tdat:
31  rec = line.rstrip().split(None, 7)
32  dt = julian.from_jd(float(rec[4]))
33  if dt < taidt:
34  leapsec = float(rec[6])
35 
36  return leapsec
def convert_month_day_to_doy(mon, dom, yr)
Definition: time_utils.py:8
def get_leap_seconds(taitime, epochyear=1958)
Definition: time_utils.py:17