【问题标题】:Calculate the tilt of the moon crescent计算新月的倾斜度
【发布时间】:2019-12-04 19:26:08
【问题描述】:

可以用Skyfield计算月牙的倾斜度吗?还是直接?我知道来回的月牙石,我想正确地显示它。

https://www.calsky.com/cs.cgi/Moon/15?obs=4311082095747103&c=

# https://rhodesmill.org/skyfield/toc.html 
from skyfield import api

tmsc = api.load.timescale()
planets = api.load('de421.bsp')

import datetime
import pytz

toposloc = api.Topos('50.9409116 N', '6.9576131 E') # Köln local position on earth
toposabs = planets['earth'] + toposloc # absolute position incl earth 
DTUTC = datetime.datetime.now(datetime.timezone.utc)

# calc moon
astro = toposabs.at(tmsc.utc(DTUTC.year, DTUTC.month, DTUTC.day, DTUTC.hour, DTUTC.minute, DTUTC.second)).observe(planets['moon'])
app = astro.apparent()
alt, azi, distance = app.altaz()
altazmoon=[alt.degrees, azi.degrees] # save for later
_, lonmoon, _ = app.ecliptic_latlon()

【问题讨论】:

  • 受您的问题启发,Skyfield 的下一个版本将包含一个为您计算位置角度的函数。以下是演示如何使用该函数的文档预览:github.com/skyfielders/python-skyfield/blob/…
  • 哦,你是Skyfield的开发者。很高兴认识你。还要感谢您的新增功能。我真的很喜欢 Skyfield。

标签: python astronomy skyfield


【解决方案1】:

好的,感谢 stackoverflows 的建议,我在这里找到了这个答案,这可能就是我正在寻找的答案

Calculating moon face rotation as a function of Earth coordinates

我目前正在测试这个。至少在今天,如果我从窗外看,它看起来非常准确。好样的!

[edit:] 我已经测试了一周并更新了下面的代码。现在一切似乎都对了。感谢 Stackoverflow

import math

def moontilt(altazsun, altazmoon): # mathematical angle where the sun light shines from onto the moon disc (measured from 3 o’clock anticlockwise)
    dLon = math.radians(altazsun[1]-altazmoon[1])
    radaltsun = math.radians(altazsun[0])
    radaltmoon = math.radians(altazmoon[0])
    cosaltsun = math.cos(radaltsun)
    y = math.sin(dLon) * cosaltsun
    x = math.cos(radaltmoon) * math.sin(radaltsun) - math.sin(radaltmoon) * cosaltsun * math.cos(dLon)
    brng = math.atan2(y, x)
    return 90-math.degrees(brng) 

# calc sun
astro = toposabs.at(tmsc.utc(DTUTC.year, DTUTC.month, DTUTC.day, DTUTC.hour, DTUTC.minute, DTUTC.second)).observe(planets['sun'])
app = astro.apparent()
alt, azi, distance = app.altaz()
altazsun=[alt.degrees, azi.degrees] # save for later
_, lonsun, _ = app.ecliptic_latlon()

# get moon phase
moonphase = ((lonmoon.degrees - lonsun.degrees) % 360.0) / 360 #  0: new moon, 0.5: full moon, 1: new moon

# this should be the tilt from the standard displaying symbols in degrees of the crescent I draw with PIL
tilt=-moontilt(altazsun, altazmoon) # PIL.ImageDraw.Draw.chord measures angles increasing clockwise. Thus minus
if moonphase>0.5: tilt+=180 # after full moon the light is expected to shine from the opposite side of the moon (which is already taken into account in the standard moon icons)

【讨论】:

  • 如果它有助于简化您的代码,请注意alt.radiansazi.radians 将直接为您提供弧度并让您避免调用math.radians。 (但如果您需要在调试期间打印出来,也许您更喜欢有意义的值?)
  • 非常感谢您指出这一点,布兰登。当然,在 rad 工作更有意义。 (我的程序仍处于实验状态,目前我更容易获得学位。)
猜你喜欢
  • 2012-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 2012-12-11
相关资源
最近更新 更多