[Python] 纯文本查看 复制代码
#!/usr/bin/env python
# encoding: utf-8
"""
@author: shiqi
@file: interpolate_utils
@time: 2019-12-11 15:34
@desc:
"""
import pandas as pd
from scipy.interpolate import interp1d
from pathlib import Path
from test_interface.algorithm import post, tmt
def my_interpolate():
post_path = Path(r"C:\Users\Administrator\Desktop\0027-1-02-0001-20191205-154946-TC.PosT")
tmt_path = Path(r"C:\Users\Administrator\Desktop\0027-1-02-0001-20191205-154950_2019_12_5_20_14_52.tmt")
post_gps_list, post_latitude_list, post_longitude_list, \
post_h_ell_list, post_roll_list, post_pitch_list, post_heading_list = post.read_post(post_path)
tmt_gps_list = tmt.read_tmt(tmt_path)
print(len(post_gps_list), len(post_latitude_list))
# 对xyzrph进行关于gps的cubic差值(三次样条差值)
# f_latitude = scipy.interpolate.CubicSpline(post_gps_list, post_latitude_list)
f_latitude = interp1d(post_gps_list, post_latitude_list, kind="cubic")
f_longitude = interp1d(post_gps_list, post_longitude_list, kind="cubic")
f_h_ell = interp1d(post_gps_list, post_h_ell_list, kind="cubic")
f_roll = interp1d(post_gps_list, post_roll_list, kind="cubic")
f_pitch = interp1d(post_gps_list, post_pitch_list, kind="cubic")
f_heading = interp1d(post_gps_list, post_heading_list, kind="cubic")
tmt_latitude_list = []
tmt_longitude_list = []
tmt_h_ell_list = []
tmt_roll_list = []
tmt_pitch_list = []
tmt_heading_list = []
for gps in tmt_gps_list:
latitude = f_latitude(gps)
longitude = f_longitude(gps)
h_ell = f_h_ell(gps)
roll = f_roll(gps)
pitch = f_pitch(gps)
heading = f_heading(gps)
tmt_latitude_list.append(latitude)
tmt_longitude_list.append(longitude)
tmt_h_ell_list.append(h_ell)
tmt_roll_list.append(roll)
tmt_pitch_list.append(pitch)
tmt_heading_list.append(heading)
return tmt_gps_list, tmt_latitude_list, tmt_longitude_list, tmt_h_ell_list, \
tmt_roll_list, tmt_pitch_list, tmt_heading_list
pass
def interpolate_result():
g, n, e, u, r, p, h = my_interpolate()
cam = pd.DataFrame({"GPSTime": g, "Latitude": n, "Longitude": e, "H-Ell": u, "Roll": r, "Pitch": p, "Heading": h},
dtype="float64")
# decimals = pd.Series([4, 11, 11, 3, 5, 5, 5],
# index=["GPSTime", "Latitude", "Longitude", "H-Ell", "Roll", "Pitch", "Heading"])
# cam = cam.round(decimals)
cam["GPSTime"] = cam["GPSTime"].map(lambda x: '%.4f' % x)
cam["Latitude"] = cam["Latitude"].map(lambda x: '%.11f' % x)
cam["Longitude"] = cam["Longitude"].map(lambda x: '%.11f' % x)
cam["H-Ell"] = cam["H-Ell"].map(lambda x: '%.3f' % x)
cam["Roll"] = cam["Roll"].map(lambda x: '%.5f' % x)
cam["Pitch"] = cam["Pitch"].map(lambda x: '%.5f' % x)
cam["Heading"] = cam["Heading"].map(lambda x: '%.5f' % x)
# cam1 为奇数行,reset_index(drop=True) 添加索引 True丢失原始索引
cam1 = cam.iloc[0::2] # .reset_index(drop=True)
# cam2 为偶数行,reset_index(drop=True) 添加索引 True丢失原始索引
cam2 = cam.iloc[1::2] # .reset_index(drop=True)
print(cam1)
cam1.to_csv(r"C:\Users\Administrator\Desktop\cam1.PosT", encoding="utf-8", index=None)
cam2.to_csv(r"C:\Users\Administrator\Desktop\cam2.PosT", encoding="utf-8", index=None)
pass
if __name__ == '__main__':
# a3 = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})
# print(a3)
interpolate_result()
pass