def RelativeLST2AbsoluteTime(lst, now=None): """ Returns today's DateTime in UTC, defined as first corresponding time after now, from given LST in hours. """ lst = DateTime.DateTimeDelta(0, lst, 0, 0) if now is None: now = DateTime.gmt() else: now = dt2mxDT(now) # Now's mjd at 0h mjd0 = int(now.mjd) # Convert requested LST to degrees requested_lst = 15 * lst.hours # Local LMST for 0h UT in degrees lst0 = (180.0 / math.pi) * slalib.sla_gmst(mjd0) + GBTLONG # LST difference between 0h UT and requested LST lst_offset = requested_lst - lst0 solar_sidereal_ratio = (365.25 / 366.25) # options for solar time at 1 day sidereal intervals options = [] for cycle in range(720, -1080, -360): solar_time = ((lst_offset - cycle) / 15.0) * solar_sidereal_ratio mjd = mjd0 + solar_time / 24 options.append(DateTime.DateTimeFromMJD(mjd)) # Select the time following the target time target = DateTime.DateTimeFromMJD(now.mjd) for option in options: if target < option: return mxDT2dt(option) return mxDT2dt(option[-1])
def TimeStamp2DateTime(mjd, secs): "Translates MJD integer and double seconds since midnight into a datetime." mxDT = DateTime.DateTimeFromMJD(mjd + secs / 86400) return mxDT2dt(mxDT)
def mjd2dt(mjd): "Translates from MJD to built-in module datetime." return mxDT2dt(DateTime.DateTimeFromMJD(mjd))