當前位置: 首頁>>代碼示例>>Python>>正文


Python PyKEP.planet方法代碼示例

本文整理匯總了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)
#.........這裏部分代碼省略.........
開發者ID:voneiden,項目名稱:ksp-groundtrack,代碼行數:103,代碼來源:track.py


注:本文中的PyKEP.planet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。