本文整理汇总了Python中PyKEP.planet方法的典型用法代码示例。如果您正苦于以下问题:Python PyKEP.planet方法的具体用法?Python PyKEP.planet怎么用?Python PyKEP.planet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyKEP
的用法示例。
在下文中一共展示了PyKEP.planet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_track
# 需要导入模块: import PyKEP [as 别名]
# 或者: from PyKEP import planet [as 别名]
def plot_track(self,data,predict=True,longplot=False):
UT = data[0]
shippids = data[1]
fig = plt.figure(figsize=(20,10))
kmap = mpl_toolkits.basemap.Basemap(rsphere=600000,celestial=True,resolution=None)
im = plt.imread("Kerbin_elevation.png")
#implot = plt.imshow(im)
kmap.imshow(im,origin="upper")
#UT = float(ss["UT"]) / 60 / 60 / 24
#ships = ss["VESSELS"]
#colors = ["red","green","white","cyan","orange","yellow","purple","brown"]
nearest=lambda a,l:min(l,key=lambda x:abs(x-a)) # Thanks stackexchange
if longplot:
steps = 720 #Minutes
else:
steps = 30 #Minutes
trackTime = steps/60/24 # 30 minutes
stepTime = 1.0/60.0/24.0 # 1 minute
reserved = []
for ship in shippids.values():
last_rascension = None
last_declination = None
if "debris" in ship.name.lower():
continue
XY = []
for i in xrange(steps):
stepEpoch = UT - i*stepTime
if stepEpoch<ship.min and not predict: #TODO: predictorbits
stepEpoch = ship.min #This is to ensure that no orbits are drawn which have unsure stuff
nt = nearest(stepEpoch,ship.datapoints.keys())
print "Epoch ",stepEpoch,"using datapoint",nt
dp = ship.datapoints[nt]
if len(dp) == 2:
XY.append([dp[0],dp[1]])
elif len(dp) == 7:
E = PyKEP.epoch(dp[0])
KepShip = PyKEP.planet(E,[dp[1],dp[2],dp[3],dp[4],dp[5],dp[6]],3531600000000,1,1,1)
r,v = KepShip.eph(PyKEP.epoch(stepEpoch))
r = np.array(r)
theta = -0.000290888209 * stepEpoch * 60 * 60 * 24
rmatrix = np.array([[np.cos(theta),np.sin(theta),0],[-np.sin(theta),np.cos(theta),0],[0,0,1]])
rr=np.dot(r,rmatrix)
ur = rr / np.linalg.norm(rr)
declination = np.arcsin(ur[2])
if ur[1] > 0:
rascension = np.degrees(np.arccos(ur[0] / np.cos(declination)))
elif ur[1] <= 0:
rascension = - np.degrees(np.arccos(ur[0]/ np.cos(declination)))
# print "360-",np.degrees(np.arccos(ur[0]/ np.cos(declination)))
declination = np.degrees(declination)
# Insert NaN if crossing 180 or -180
if last_rascension != None:
dif = rascension - last_rascension
if dif > 180 or dif < -180:
if dif < -180: # Going from 180 to -180
k = (declination - last_declination) / ((rascension - 180) + (180-last_rascension))
d = (180 - last_rascension)*k + last_declination
XY.append([180,d])
XY.append([np.NaN,np.NaN])
XY.append([-180,d])
else: # Going from -180 to 180
k = (declination - last_declination) / ((180-rascension) + (last_rascension-180))
d = (last_rascension-180)*k + last_declination
XY.append([-180,d])
XY.append([np.NaN,np.NaN])
XY.append([180,d])
XY.append([np.NaN,np.NaN]) #FLIP
last_rascension = rascension
last_declination = declination
XY.append([rascension,declination])
else:
print "Error"
sys.exit(1)
lastx = None
lasty = None
#color = random.choice(colors)
r = random.randint(100,255) / 255.0
g = random.randint(100,255)/ 255.0
b = random.randint(100,255)/ 255.0
color = (r,g,b)
#colors.remove(color)
alphafade = 1.0 / len(XY)
for i,point in enumerate(XY):
if i == 0:
lastx = point[0]
lasty = point[1]
continue
x = point[0]
y = point[1]
if lastx and lasty:
kmap.plot([x,lastx],[y,lasty],color=color,alpha=1-i*alphafade)
#.........这里部分代码省略.........