我怎么能用pyephem计算距离?

时间:2017-03-23 18:06:43

标签: pyephem

如果你们中的任何人知道如何计算坐标和卫星投影的距离,我需要一些帮助,我的意思是,当我预测卫星的路径时,我需要知道未来路径之间的距离是多少和我放的坐标。当那颗卫星靠近坐标时,发出一条消息警告通知我。

这是我正在使用的代码,你们可以帮助我,这将是很棒的。

from mpl_toolkits.basemap import Basemap
from geopy.distance import great_circle
from matplotlib import colors
from pyorbital import tlefile
import matplotlib.pyplot as plt
import numpy as np
import math
import ephem
from datetime import datetime


tlefile.TLE_URLS = (    'http://celestrak.com/NORAD/elements/resource.txt',)
sat_tle = tlefile.read('NUSAT 1 (FRESCO)')
sat = ephem.readtle("NUSAT 1 (FRESCO)", sat_tle.line1, sat_tle.line2)
obs = ephem.Observer()
# location for tge coordinates
print("Latitud ")
sat_lat = input()
print("Longitud suggested point")
sat_lon = input()
obs.lat = str(sat_lat)
obs.long = str(sat_lon)
# programar proyeccion del mapa
map = Basemap(projection='ortho', lat_0=sat_lat, lon_0=sat_lon, resolution='l')
# draw coastlines, country boundaries, fill continents.
map.drawcoastlines(linewidth=0.25)
map.drawcountries(linewidth=0.25)
map.fillcontinents(color='coral',lake_color='aqua')
# draw the edge of the map projection region (the projection limb)
map.drawmapboundary(fill_color='aqua')
# grid in latitud and longitud every 30 sec.
map.drawmeridians(np.arange(0,360,30))
map.drawparallels(np.arange(-90,90,30))



# plot
passes = 4
for p in range(passes):
    coords = []
    dists = []
    tr, azr, tt, altt, ts, azs = obs.next_pass(sat)
    print """Date/Time (UTC)       Alt/Azim   Lat/Long  Elev"""
    print """====================================================="""
    while tr < ts:
        obs.date = tr
        sat.compute(obs)
    print "%s | %4.1f %5.1f | %4.1f %+6.1f | %5.1f" % \
    (tr, math.degrees(sat.alt), math.degrees(sat.az), math.degrees(sat.sublat),              math.degrees(sat.sublong), sat.elevation/1000.)    
        sat_lat = math.degrees(sat.sublat)
        sat_lon = math.degrees(sat.sublong)
        dist = great_circle((sat_lat, sat_lon), (sat_lat, sat_lon)).miles
        coords.append([sat_lon, sat_lat])
        dists.append(dist)
        tr = ephem.Date(tr + 30.0 * ephem.second)
    md = min(dists)
    imd = 1 - (float(md) / 1400)
    hue = float(240) / float(360)
    clr = colors.hsv_to_rgb([hue, imd, 1])
    map.drawgreatcircle(coords[0][0], coords[0][1], coords[-1][0], coords[-1][1], linewidth=2, color=clr)
    obs.date = tr + ephem.minute
# map with UTC 
date = datetime.utcnow()
cs=map.nightshade(date)



plt.title('next '+ str(passes)+ ' passes of the satellite')
plt.show()

1 个答案:

答案 0 :(得分:0)

您可能希望查看http://rhodesmill.org/pyephem/quick.html#other-functions,其中描述了函数ephem.separation()。你可以用两个经度,纬度坐标对来调用它,它会告诉你它们有多远:

ephem.separation((lon1, lat1), (lon2, lat2))

因此,如果您将卫星的经度和纬度作为坐标对中的一个,以及您感兴趣的位置的经度和纬度作为另一个,那么您可以观察分离变得非常小的时候