1 Star 1 Fork 2

北京星火科技有限公司/TLE

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 4.00 KB
一键复制 编辑 原始数据 按行查看 历史
Li 提交于 2021-07-23 09:36 . 第一次提交“
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
from datetime import timedelta
from datetime import datetime
import ephem
import numpy as np
from dateutil import parser
def read_ephem(filename):
hfile = open(filename,'r')
listehpm = list()
while True:
try:
line1 = hfile.readline()
line2 = hfile.readline()
line3 = hfile.readline()
if (len(line1) > 0) and (len(line2) > 0) and (len(line3) > 0):
linelist = [line1.replace('\n',''),line2.replace('\n',''),line3.replace('\n','')]
listehpm.append(linelist)
#print(linelist)
else:
break
except:
#print(line1,line2,line3)
hfile.close()
break
return listehpm
def py_ephem(filename,hour):
#观察者的位置
me = ephem.Observer()
me.lon,me.lat,me.elevation = '122.48628','37.16523',10
listephem = read_ephem(filename)
colEph = check_mongo()
listRes = list()
for eph in listephem:
#一颗卫星的星历TLE
line1 = eph[0] # 'BEIDOU 3 (C01)'
line2 = eph[1] # '1 36287U 10001A 21188.89999442 -.00000272 00000-0 00000-0 0 9994'
line3 = eph[2] #'2 36287 1.9056 47.2725 0005565 83.3659 259.8549 1.00269550 42052'
sat = ephem.readtle(line1,line2,line3)
starttime = datetime.now()
nowtime = starttime
#先将 卫星名 加入List
listRes.append(sat.name)
# 指定时间段内 卫星的角度和时间点
listHour = list()
for i in range(3600*hour):
delta = timedelta(seconds=1)
nowtime = nowtime + delta
nowstring = nowtime.strftime("%Y-%m-%d %H:%M:%S")
me.date = nowstring #ephem.now()
sat.compute(me)
# 俯仰角度 大于 10° 认为可见
if(sat.alt * 180/3.14 > 10):
oneJSON ={
"name":sat.name,
"az":sat.az * 180/3.14,
"alt":sat.alt * 180/3.14,
"time":nowstring
}
listHour.append(oneJSON)
#colEph.insert_one(oneJSON)
#print(nowstring,sat.name,sat.az * 180 / 3.14,sat.alt * 180 / 3.14)
listRes.append(listHour)
return listRes
def check_mongo():
pass
#client = pymongo.MongoClient('mongodb://localhost:27017/')
#dblist = client.list_database_names()
#for e in dblist:
# print(e)
#dbEph = client["eph"]
#colEph = dbEph["eph_table"]
#collist = dbEph.list_collection_names()
#print(collist)
#return colEph
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
listRes = py_ephem('D:\GPS星历\gps-ops.txt',48)
listSat = list()
for i in range(len(listRes)):
if isinstance(listRes[i],list) and (len(listRes[i]) > 0):
parser.parse("2021-09-09")
dates = [parser.parse(js['time']) for js in listRes[i]]
deltsArray1 = np.diff(dates)
#加入开始时间
timelist = [dates[0]]
#遍历前后时间间隔是否 大于1秒
#存在间隔的话,加入间隔处的 开始时间和结束时间
delt1Second = timedelta(seconds=1)
for j in range(len(deltsArray1)):
if deltsArray1[j] > delt1Second:
timelist.append(dates[j])
timelist.append(dates[j+1])
#加入结束时间
timelist.append(dates[len(dates)-1])
oneJOSN = {
'satname':listRes[i-1],
'visiTime':timelist,
}
listSat.append(oneJOSN)
else:
#print(listRes[i])
pass
for sat in listSat:
print(sat)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
'''
'''
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Canby/tle.git
git@gitee.com:Canby/tle.git
Canby
tle
TLE
master

搜索帮助