我正在嘗試制作一個程式,它獲取國際空間站的緯度和經度坐標(來自Skyfield API)并將其繪制到散點圖上(使用 matplotlib)以顯示其估計的軌道路徑。問題是,當它被繪制到散點圖上時,會有一堆例外值(最初我認為這只是隨機的,但在繪制了一個軌道的每一秒的資料點之后,結果卻是某種其他型別的波動模式)。
Skyfield 以度分時 (DMS) 格式回傳其緯度和經度坐標,為了將它們繪制到圖表上,我將它們轉換為十進制度 (DD) 并將每對緯度坐標插入到串列中 - 所以也許這可能是一些數學問題?下圖顯示了國際空間站每秒鐘軌道的緯度和經度圖,代碼是 DMS 到 DD 轉換器函式,后跟(基本上是默認的 matplotlib 散點圖代碼。
ISS lat lon 散點圖影像
def dms2dd(latdms, londms):
latdd = str(latdms)
for num in range(1, 11):
if '0' str(num) in latdd:
latdd = latdd.replace('0', '')
if ' deg' in latdd or " '" in latdd or ' "' in latdd or ' ."' in latdd:
latdd = latdd.replace(' deg', '(')
latdd = latdd.replace(" '", '')
latdd = latdd.replace(' "', '(')
latdd = latdd.replace(' ."', '')
if latdd.startswith('-'):
latdd = latdd.replace('deg', ' (-')
latdd = latdd.replace("'", '/60) (-')
latdd = latdd.replace('"', '/3600)')
else:
latdd = latdd.replace('-', '')
latdd = latdd.replace('deg', ' (')
latdd = latdd.replace("'", '/60) (')
latdd = latdd.replace('"', '/3600)')
for x in range(0, 4):
latdd = latdd.removesuffix(' (-')
latdd = latdd.removesuffix(' (')
latdd = latdd.replace(' ', '')
latdd = eval(latdd)
londd = str(londms)
for num in range(1, 11):
if '0' str(num) in londd:
londd = londd.replace('0', '')
if ' deg' in londd or " '" in londd or ' "' in londd or ' ."' in londd:
londd = londd.replace(' deg', '(')
londd = londd.replace(" '", '')
londd = londd.replace(' "', '(')
londd = londd.replace(' ."', '')
if londd.startswith('-'):
londd = londd.replace('deg', ' (-')
londd = londd.replace("'", '/60) (-')
londd = londd.replace('"', '/3600)')
else:
londd = londd.replace('-', '')
londd = londd.replace('deg', ' (')
londd = londd.replace("'", '/60) (')
londd = londd.replace('"', '/3600)')
for x in range(0, 4):
londd = londd.removesuffix(' (-')
londd = londd.removesuffix(' (')
londd = londd.replace(' ', '')
londd = eval(londd)
return latdd, londd
plt.style.use('_mpl-gallery')
# datalat and datalon are just the list versions of the latitude and longitude coords
y = datalat
x = datalon
colors = np.random.uniform(15, 80, len(x))
fig, ax = plt.subplots()
ax.scatter(x, y, s=5, c=colors, vmin=100, vmax=100)
ax.set(xlim=(-180, 180), xticks=np.arange(-180, 180),
ylim=(-90, 90), yticks=np.arange(-180, 180))
plt.show()
uj5u.com熱心網友回復:
令人高興的是,Skyfield 使十進制度可直接用于經度和緯度,因此您無需決議字串。Angle根據此處的檔案,經度和緯度都是該類的實體:
https://rhodesmill.org/skyfield/api-topos.html#skyfield.toposlib.GeographicPosition.latitude
并且Angle直接提供度數、小時數和弧度:
https://rhodesmill.org/skyfield/api-units.html#skyfield.units.Angle
因此,給定一個地理位置g,您應該能夠直接詢問它g.longitude.degrees并g.latitude.degrees使用這些十進制數字。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/483278.html
標籤:Python matplotlib 数学 坐标 天空场
上一篇:將等高線轉換為直線
