Source code for irfpy.mars.mars_calendar
""" Martian calendar.
https://en.wikipedia.org/wiki/Timekeeping_on_Mars
See also https://irfpy.irf.se/projects/spice/api/api_irfpy.spice.spicetools.html
.. tip::
To get the Ls (solar longitude), you can use SPICE function ``lspcn``.
.. code-block:: python
import datetime, spiceypy as spice, numpy as np
### Kernels should be loaded.
spice.furnsh('...') # Needed kernels should be loaded
### Or maybe for Mars, it is easier to install ``irfpy.aspera`` and
# from irfpy.mexpvat import mexspice as ms
# ms.init()
t = datetime.datetime(2019, 2, 26, 0, 0, 0)
et = spice.utc2et(t.strftime('%FT%T'))
ls = np.rad2deg(spice.lspcn('MARS', et, 'NONE'))
print('t:', t)
print('et:', et)
print('Ls:', kls)
"""
myear_per_sols = 668.5991
sol_per_secs = 88775.244147
myear_per_secs = myear_per_sols * sol_per_secs
[docs]def jdtt2msd(jd_tt):
r""" Convert Julian Day in Terrestrial Time to MSD (Mars Sol Date)
https://en.wikipedia.org/wiki/Timekeeping_on_Mars#Formulas_to_compute_MSD_and_MTC
:param jd_tt: Julian day in Terrestrial Time.
You may get the JD_TT from SPICE.
.. math::
MSD = \frac{JD_{TT} - 2405522.0028779}{1.0274912517}
.. note::
To convert the UTC to TT, the following SPICE functions are used.
.. code-block:: python
> import spiceypy as spice
> spice.furnsh('NAIF0012.TLS') # Furnsh the latest TLS.
> t = datetime.datetime(2019, 2, 24, 15, 9, 12)
> et = spice.str2et(t.strftime('%FT%T'))
> jd_tt = spice.unitim(et, 'ET', 'JDTDT') # TDT is approximately the same as TT
> print(jd_tt)
2458539.1321896296
>>> jd_tt = 2458539.1321896296
>>> msd = jdtt2msd(jd_tt)
>>> print('{:.8f}'.format(msd))
51598.61869774
"""
msd = jd_tt - 2405522.0028779
msd = msd / 1.0274912517
return msd
[docs]def msd2jdtt(msd):
r""" Convert MSD to Juliand Day (Terrestrial Time)
:param msd: Mars Sol Date (floating point)
:returns: Julian day (TT)
>>> msd = 51598.618697737846
>>> jd_tt = msd2jdtt(msd)
>>> print('{:.8f}'.format(jd_tt))
2458539.13218963
"""
_msd = msd * 1.0274912517
jd_tt = _msd + 2405522.0028779
return jd_tt
[docs]def jdtt2mtc(jd_tt):
r""" Convert Julian Day in Terrestrial Time to MSD + MTC.
:param jd_tt: Julian day in Terrestrial Time.
You may get the JD_TT from SPICE.
:returns: A tuple, (MSD, MTC_hr, MTC-min, MTC-sec)
.. math::
MSD &= \frac{JD_{TT} - 2405522.0028779}{1.0274912517} \\
MTC &= (MSD % 1) \times 24 hr
.. note::
Please find :meth:`jdtt2msd` to convert the UTC time to TT time.
>>> jd_tt = 2458539.1321896296 # UTC 2019-02-24T15:09:12
>>> msd, hr, mn, se = jdtt2mtc(jd_tt)
>>> print('{:d} {:d} {:d} {:.6f}'.format(msd, hr, mn, se))
51598 14 50 55.484550
"""
msd = jdtt2msd(jd_tt)
msd_int = int(msd // 1)
msd_frac = (msd % 1)
msd_frac *= 24
mtc_hr = int(msd_frac)
msd_frac -= mtc_hr
msd_frac *= 60
mtc_mn = int(msd_frac)
msd_frac -= mtc_mn
msd_frac *= 60
mtc_se = msd_frac
return (msd_int, mtc_hr, mtc_mn, mtc_se)