Skip to main content

A Python class that allows for convenient conversion between different date and time formats/units

Project description

time_converter

A Python class that allows for convenient conversion between different date and time formats and units. The library supports both general-purpose Earth-based time units (such as Python's datetime type, Day-of-year or POSIX time) as well as time units useful for working with data from the Mars Science Laboratory and Chang'e 4 space missions. It can be easily extended to support additional units.

Note

This package is a maintained fork of the original time-converter by Johan von Forstner, who developed it in 2019 while working on the MSL and LND missions. As Johan has since left the space science field, the original package is no longer actively maintained. This fork is actively maintained by Zigong Xu and is the recommended version for use with LND_loader and Chang'e 4 data analysis.

Changes from the original:

  • Updated Chang'E 4 local time data (change4_localtime.dat) to support lunar days through 2032
  • Fixed lunar day off-by-one bug with spiceypy >= 6.0.0: lunarday=1 now works as direct input
  • Fixed NumPy compatibility (np.float removed in NumPy 1.20+)

The conversion between spacecraft clock and UTC is based on a pure Python reimplementation of the SCLK kernel functionality from NASA's SPICE library, together with the SCLK kernel file (msl.tsc) baked into the library.

Especially if very high accuracy (on the order of a few seconds or better) is required and/or the dependency on compiling the SPICE library is not an issue, I would instead recommend using SPICE directly for MSL SCLK conversions. In Python, this can be done with SpiceyPy.

Installation

pip install lnd-time-converter

Usage

from time_converter import Time

Time(2019.5, 'decimalyear').to('dt')
# > datetime.datetime(2019, 7, 2, 12, 0)

you can also supply list-like objects as input, the output will be a numpy array.

Time([2018.0, 2018.1], 'decimalyear').to('dt')
# > array([datetime.datetime(2019, 1, 1, 0, 0),
#          datetime.datetime(2019, 2, 6, 11, 59, 59, 999997)], dtype=object)

Supported units

Earth-based time units

Unit Example Name Abbreviated Name
Python datetime (UTC) datetime.datetime(2019, 1, 1, 0, 0) datetime dt
DoY Tuple (year, day of year) (2019, 1.0) doy
Decimal year 2019.0 decimalyear dy
POSIX time 1546300800 posix

Mars Science Laboratory

The MSL spacecraft clock (sclk) measures the number of seconds since January 1 2000, 11:58:55.816 UTC. However, due to drifting of the clock, some corrections need to be applied based on a file supplied by NASA, which this tool uses to do the conversion between sclk and other units.

Unit Example Name
MSL mission sol 2276.8306983767375 sol
MSL spacecraft clock 599570768.5720837 sclk

Chang'E 4

For Chang'E 4, the conversion of spacecraft clock time to datetime has already implemented, so it does not need to be included in time_converter. But we have implemented a converter for the lunar day number and local solar time at Chang'E 4's landing site:

Unit Example Name
Local solar time at Chang'E 4 (1, datetime.time(7, 32, 30)) ce4lst

Lunar day numbers start from 1 and can be used directly:

Time((1, datetime.time(8, 30)), 'ce4lst').to('dt')
# > datetime.datetime(2019, 1, 2, 4, 20, 28, 400000)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lnd_time_converter-2.1.3.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lnd_time_converter-2.1.3-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file lnd_time_converter-2.1.3.tar.gz.

File metadata

  • Download URL: lnd_time_converter-2.1.3.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for lnd_time_converter-2.1.3.tar.gz
Algorithm Hash digest
SHA256 4d60a0b29bdba1cb2574005a529a99885a868f23ad946b1bebc1488dd520f206
MD5 51b533305a2cada4d729231df96b18ed
BLAKE2b-256 a33cb5edbefe73ac001ab5b491474c4ff80426507cb6bf338d7e6ba40f387964

See more details on using hashes here.

File details

Details for the file lnd_time_converter-2.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for lnd_time_converter-2.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 558f51b81ef55895159e04173e27985b49ef7011115ad0dc22ec7919f7f26417
MD5 8b85df6a8f36c03ea7dda2b0de7ae396
BLAKE2b-256 64e898e8e256991799fa5b4c368a54ff9602dd5ef0364395f8b03a9e2ae7b801

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page