如何使用Astropy将MJD(Julian Date)转换为UTC?

发布于 2025-02-06 20:13:29 字数 43 浏览 2 评论 0 原文

我在Astropy网站上尝试了一些东西,但仍然需要帮助。那里有人知道吗?

I've tried stuff on the astropy website but still need help. Anyone out there got a clue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

顾忌 2025-02-13 20:13:29

The documentation at https://docs.astropy.org/en/stable/time/index.html is a good place to start. There you will learn about the distinction between a time format like MJD and a time scale like UTC.

攒一口袋星星 2025-02-13 20:13:29

看起来这返回了所需的结果。

from astropy.time import Time

# Start with some time in modified julian date (MJD)
mjd = 58134.09699299725

# Convert to Julian Date
jd = mjd + 2400000.5

# Convert to astropy Time object
t = Time(jd, format='jd')

# Convert to datetime
utc = t.to_datetime()

Looks like this returns the desired result.

from astropy.time import Time

# Start with some time in modified julian date (MJD)
mjd = 58134.09699299725

# Convert to Julian Date
jd = mjd + 2400000.5

# Convert to astropy Time object
t = Time(jd, format='jd')

# Convert to datetime
utc = t.to_datetime()
阳光下的泡沫是彩色的 2025-02-13 20:13:29

MJD是日期格式,而UTC是时间尺度,因此我认为您的意思是将MJD转换为ISO等另一种标准格式。

如果您的MJD时间已经达到UTC量表,则可以传递到Astropy Time对象(如上述答案之一),并将其直接称为MJD格式(可以避免使用MJD到JD转换)。此外,如果您的时代处于另一个量表(例如TDB或TT),则可以在传递时间类时指定,并且可以为您转换。默认的比例尺Astropy Time用途是UTC。

from astropy.time import Time

# Start with some time in modified julian date (MJD)
mjd = 58134.09699299725

# create Time object (no JD conversion!)
t = Time(mjd, format='mjd')    # --> if MJD not in UTC, can add scale flag: scale='tdb'

# return in ISO format 
print(t.iso)                  # ---> '2018-01-16 02:19:40.195'

# can show in different scales
print(t.tdb.iso)              # ---> '2018-01-16 02:20:49.379'

# can also return Time object as JD
print(t.jd)                   # ---> 2458134.5969929975

对于可以与Astropy Time一起使用的时间格式和秤的完整列表,您可以分别运行命令 time.formats time.scales.scales

MJD is a date format whereas UTC is a time scale, so I assume you mean convert MJD to another standard format like ISO.

If your MJD time is already in UTC scale, you can pass to an astropy Time object (like one of the above answers) and directly call it as a MJD format (can avoid the MJD to JD conversion). Additionally, if your epoch is in another scale (like TDB or TT) you can specify that when passing to the Time class and it will be able to convert for you. The default scale astropy Time uses is UTC.

from astropy.time import Time

# Start with some time in modified julian date (MJD)
mjd = 58134.09699299725

# create Time object (no JD conversion!)
t = Time(mjd, format='mjd')    # --> if MJD not in UTC, can add scale flag: scale='tdb'

# return in ISO format 
print(t.iso)                  # ---> '2018-01-16 02:19:40.195'

# can show in different scales
print(t.tdb.iso)              # ---> '2018-01-16 02:20:49.379'

# can also return Time object as JD
print(t.jd)                   # ---> 2458134.5969929975

For a full list of the time formats and scales you can use with astropy Time, you can run the commands Time.FORMATS and Time.SCALES respectively.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文