代码拉取完成,页面将自动刷新
# 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/
'''
'''
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。