import torch
import numpy as np
import pandas as pd
# 读取数据集,假设是 NumPy 二维数组(分为三个文件)
array_imu = np.loadtxt("ADIS16460.txt")
array_gps = np.loadtxt("GNSS_RTK.pos")
array_truth = np.loadtxt("truth.nav")
# 将 NumPy 数组转换为 Pandas DataFrame,并指定列名(原始数据没有列表头列,需自己指定)
df_imu = pd.DataFrame(array_imu, columns=['GNSSTime', 'angle_x_axis', 'angle_y_axis','angle_z_axis','velocity_x_axis','velocity_y_axis','velocity_z_axis']) # 替换 'IMU_Column1', 'IMU_Column2', ... 为实际的列名
df_gps = pd.DataFrame(array_gps, columns=['GNSSTime', 'geodetic_latitude', 'geodetic_longitude','geodetic_height','latitude_deviation', 'longitude_deviation','height_deviation',]) # 替换 'GPS_Column1', 'GPS_Column2', ... 为实际的列名
df_truth = pd.DataFrame(array_truth, columns=['week','GNSSTime', 'geodetic_latitude_truth', 'geodetic_longitude_truth','geodetic_height_truth','velocity_north_truth', 'velocity_east_truth','velocity_down_truth','roll_truth','pitch_truth','yaw_truth',]) # 替换 'Truth_Column1', 'Truth_Column2', ... 为实际的列名
# 合并 IMU 和 GPS 数据(以gps中时间列为基准)
df_merged = pd.merge_asof(
df_gps.sort_values(by='GNSSTime'), df_imu.sort_values(by='GNSSTime'),
on='GNSSTime', direction='nearest')
# 再合并真实数据(以上一个函数的时间列为基准)
df_merged = pd.merge_asof(
df_merged, df_truth.sort_values(by='GNSSTime'),
on='GNSSTime', direction='nearest')
# 保存合并后的数据到一个新的文件
df_merged.to_csv("wuhan_fusion2.csv", index=False)
这段代码首先以 GNSS_RTK.pos
数据集为基础,依次将 ADIS16460
和 truth.nav
数据集与其合并。merge_asof
函数用于进行基于最近时间的模糊合并,确保每一步的合并都是基于 GNSS_RTK.pos
文件的时间。这样处理可以保证 Time
列值的一致性和准确的时间对齐。