"""Referential time tools
"""
from astropy.time import Time, TimeDelta
# TODO: TT = UTC + 69.184 s in 2018 !!! doc A. Sauvageo
TSVOM = 70.184 # s
[docs]def get_mjd_ref():
"""return the mjd reference for the SVOM mission
:return: mjd reference in mjd
:rtype: float
"""
return 57754.0
[docs]def convert_mjd_in_svomref_seconds(time_mjd):
"""
convert a time in mjd in a time in seconds from the mjd reference
:param time_mjd: time in mjd
:type time_mjd: float
:return: time in seconds
:rtype: float
"""
return (time_mjd - get_mjd_ref()) * 24 * 3600
[docs]def convert_mjd_in_svomref_seconds_ref(time_mjd, time_mjd_ref):
"""
convert a time in mjd in a time in seconds from the mjd reference
:param time_mjd: time in mjd
:type time_mjd: float
:param time_mjd_ref: time in mjd
:type time_mjd_ref: float
:return: time in seconds
:rtype: float
"""
return (time_mjd - time_mjd_ref) * 24 * 3600
[docs]def convert_svomref_seconds_in_mjd(time_s):
"""
convert a time in seconds from the mjd reference in a time in mjd
:param time_s: time in s from mjdref
:type time_s: float
:return: time in mjd
:rtype: float
"""
return time_s / (24. * 3600.) + get_mjd_ref()
# ## ADDED FOR DC2 PURPOSES ###
# TODO: review time conventions all over the code
# align time conventions with DC2/FSC ?
[docs]def from_isot_to_mjd(t_isot):
"""convert isot to mjd
:param t_isot:
"""
tmp = Time(t_isot, format='isot').mjd
return convert_mjd_in_svomref_seconds(tmp) + TSVOM
[docs]def from_mjd_to_isot(t_mjd):
"""convert mjd to isot
:param t_mjd:
"""
tmp = convert_svomref_seconds_in_mjd(t_mjd)
tmp_t = Time(tmp, format='mjd')
tmp_tsvom = TimeDelta(TSVOM, format='sec')
return (tmp_t - tmp_tsvom).isot
[docs]def create_time_tag_from_tstart(tstart):
"""Creates time tag of scientific products.
:param tstart: starting time of the observation
:type tstart: float
"""
t_ref = Time("2017-01-01T00:00:00.000").mjd
tstart_day = tstart / (24 * 3600.)
time_isot_tag = Time((tstart_day + t_ref), scale='tt', format='mjd').isot
time_isot_tag = time_isot_tag.replace("-", "")
time_isot_tag = time_isot_tag.replace(":", "")
return time_isot_tag.split(".")[0]