You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何优化火箭发射数据计算的速度曲线,实现平滑且少数据丢失?

火箭发射数据计算垂直速度曲线不稳定问题排查

我尝试从火箭发射原始数据中计算各类变量,但得出的垂直速度曲线极其不稳定,既无法读取也无法用于后续计算。想弄清楚这是数据质量问题、代码逻辑错误,还是存在一种能在不丢失大量数据的前提下平滑曲线的方法。

不稳定的速度曲线

我的代码

# Essa Hattar
# essa.hattar@wmich.edu
# the purpose of this code is to extract rocket data from a json file and graph its variables

import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import make_interp_spline
import json

# set folders to pull from file
time = []
total_speed = []  # NOTE: turns out "velocity" is total SPEED not vertical velocity
altitude = []


def file_name():
    while True:
        json_name = input('Enter the json file name: ')

        try:
            data = open((json_name + '.json'), 'r')
            data.close()
            return json_name
        except FileNotFoundError:
            print(f'The file name {json_name}.json does not exist')


def extract_data(json_name):
    data = open((json_name + '.json'), 'r')

    # for every line in file
    for line in data:
        line_dict = json.loads(line)
        # sets data from dict into folders
        time.append(line_dict.get('time'))
        total_speed.append(line_dict.get('velocity'))
        altitude.append(line_dict.get('altitude'))

    # close file b/c not needed anymore
    data.close()
    return time, total_speed, altitude


def calc_vert_velocity(time, altitude):
    # velocity == change in distance/ time
    velocity = [0]
    time_v = [0]  # time and velocity folder need to be same length for graph, so I need a new time folder
    # these are all the "start" variables that I will refer too
    time_last = 0
    altitude_last = 0

    for i in range(len(time)):
        if altitude_last != altitude[i]:
            # calc
            velocity_temp = (altitude[i] - altitude_last) / (time[i] - time_last)
            # velocity_temp *= 1000  # convert to meters
            velocity_temp = round(velocity_temp, 2)
            # append folder
            velocity.append(velocity_temp)
            time_v.append(time[i])
            # set condition variables
            time_last = time[i]
            altitude_last = altitude[i]

    return velocity, time_v


def calc_acceleration(time_v, velocity):
    pass


def show_graph(json_name, time, altitude, velocity, time_v):

    plt.figure(figsize=(10, 5))


    # altitude/time
    plt.subplot(121)
    plt.plot(time, altitude, 'g')
    plt.title('Altitude/Time')
    plt.xlabel('Seconds')
    plt.ylabel('Km')


    # velocity/time
    plt.subplot(122)

    # here down is with spline
    x = np.array(time_v)
    y = np.array(velocity)
 
    X_Y_Spline = make_interp_spline(x, y)

    # Returns evenly spaced numbers
    # over a specified interval.
    X_ = np.linspace(x.min(), x.max(), 200)
    Y_ = X_Y_Spline(X_)
    plt.plot(X_, Y_, 'b')
    # here up is with spline

    """
    plt.plot(time_v, velocity, 'b', linewidth=.5)  # without spline
    """

    plt.title('Velocity/Time')
    plt.xlabel('Seconds')
    plt.ylabel('Km/s')


    plt.suptitle(f'{json_name} Telemetry')
    plt.show()


def main():
    # get file name from user
    json_name = file_name()

    time, total_speed, altitude = extract_data(json_name)
    velocity, time_v = calc_vert_velocity(time, altitude)
    show_graph(json_name, time, altitude, velocity, time_v)


main()

已做尝试与疑问

关于calc_vert_velocity()函数

  • 我通过仅在高度发生测量变化时计算速度,移除了大量不必要的零值,试图让数据更易读,也尝试过不同形式重写计算公式。
  • 考虑过对3-5个数据点取平均值,但担心这属于数据篡改。

关于绘图

  • 已尝试使用make_interp_spline()手动平滑数据曲线,但效果不佳。

使用的数据

我使用的是CRS-11 raw数据集,该数据集下的所有文件均可与代码兼容。

需求

希望先排查代码逻辑是否存在错误,再手动检查数据。

内容的提问来源于stack exchange,提问作者EssaHattar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 03:07:18