123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import csv
- import re
- import datetime
- import os
- # read_dddd_data:读取弹道导弹轨迹
- def read_dddd_data(filedir=".", filename="./dddd1.csv"):
- filepath = os.path.join(filedir, filename)
- data = []
- pattern = r"(\d+\s\w+\s\d+\s\d{2}:\d{2}:\d{2}.\d{3})\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)"
- # pattern = r'\s+(\d+\s\w+\s\d+\s\d{2}:\d{2}:\d{2}\.\d{3})\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)'
- # 打开CSV文件并读取内容
- with open(filepath, newline="") as csvfile:
- reader = csv.reader(csvfile)
- # 跳过CSV文件的第一行,即标题行
- next(reader)
- next(reader)
- next(reader)
- next(reader)
- next(reader)
- next(reader)
- next(reader)
- # 逐行读取CSV文件内容并添加到data列表中
- for row in reader:
- match = re.match(pattern, row[0])
- split_data = row[0].split(" ")
- if match:
- # 将匹配的内容存储到result_array中
- data.append(
- [match.group(1), match.group(2), match.group(3), match.group(4)]
- )
- return data
- # read_satellite_data:读取卫星轨迹
- def read_satellite_data(filedir="", filename="./dddd1.csv"):
- filepath = os.path.join(filedir, filename)
- data = []
- # pattern = r'(\d+\s\w+\s\d+\s\d{2}:\d{2}:\d{2}.\d{3})\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)'
- pattern = r"\s+(\d+\s\w+\s\d+\s\d{2}:\d{2}:\d{2}\.\d{3})\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)"
- # 打开CSV文件并读取内容
- with open(filepath, newline="") as csvfile:
- reader = csv.reader(csvfile)
- # 跳过CSV文件的第一行,即标题行
- next(reader)
- next(reader)
- next(reader)
- next(reader)
- next(reader)
- next(reader)
- next(reader)
- # 逐行读取CSV文件内容并添加到data列表中
- for row in reader:
- match = re.match(pattern, row[0])
- split_data = row[0].split(" ")
- if match:
- # 将匹配的内容存储到result_array中
- data.append(
- [match.group(1), match.group(2), match.group(3), match.group(4)]
- )
- return data
- # read_satellite_data:返回全部轨迹
- def get_position_by_time(
- starttime, stoptime, dddd_array, satellite_array, timestep, redunit, satellite
- ):
-
- # microseconds = ".000"
- # starttime = starttime + microseconds
- # stoptime = stoptime + microseconds
- start_time_obj = datetime.datetime.strptime(starttime, "%d %B %Y %H:%M:%S.%f")
- stop_time_obj = datetime.datetime.strptime(stoptime, "%d %B %Y %H:%M:%S.%f")
-
- # 使用timedelta增加时间
- current_time = start_time_obj
- index = 0
- final_data = []
- # while current_time + microseconds != stoptime:
- while current_time <= stop_time_obj:
- obj = {}
- for i in range(len(dddd_array)):
- if index < len(dddd_array[i]):
- item = dddd_array[i][index]
- obj["dateTime"] = item[0]
- obj[redunit[i].get("name")] = {
- "time": item[0],
- "x": item[1],
- "y": item[2],
- "z": item[3],
- }
- for j in range(len(satellite_array)):
- if index < len(satellite_array[j]):
- obj["dateTime"] = item[0]
- item = satellite_array[j][index]
- obj[satellite[j].get("name")] = {
- "time": item[0],
- "x": item[1],
- "y": item[2],
- "z": item[3],
- }
- final_data.append(obj)
- current_time = current_time + datetime.timedelta(seconds=int(timestep))
- index = index + 1
- return final_data
|