|
| 1 | +# |
| 2 | +# Plot orbit observer |
| 3 | +# |
| 4 | +# arg[1] : read_file_tag : time tag for default CSV output log file. ex. 220627_142946 |
| 5 | +# |
| 6 | + |
| 7 | +# |
| 8 | +# Import |
| 9 | +# |
| 10 | +# plots |
| 11 | +import matplotlib.pyplot as plt |
| 12 | +# numpy |
| 13 | +import numpy as np |
| 14 | +# local function |
| 15 | +from common import find_latest_log_tag |
| 16 | +from common import add_log_file_arguments |
| 17 | +from common import read_3d_vector_from_csv |
| 18 | +from common import read_scalar_from_csv |
| 19 | +# arguments |
| 20 | +import argparse |
| 21 | + |
| 22 | +# Arguments |
| 23 | +aparser = argparse.ArgumentParser() |
| 24 | +aparser = add_log_file_arguments(aparser) |
| 25 | +aparser.add_argument('--no-gui', action='store_true') |
| 26 | +args = aparser.parse_args() |
| 27 | + |
| 28 | +# |
| 29 | +# Read Arguments |
| 30 | +# |
| 31 | +# log file path |
| 32 | +path_to_logs = args.logs_dir |
| 33 | + |
| 34 | +read_file_tag = args.file_tag |
| 35 | +if read_file_tag == None: |
| 36 | + print("file tag does not found. use latest.") |
| 37 | + read_file_tag = find_latest_log_tag(path_to_logs) |
| 38 | + |
| 39 | +print("log: " + read_file_tag) |
| 40 | + |
| 41 | +# |
| 42 | +# CSV file name |
| 43 | +# |
| 44 | +read_file_name = path_to_logs + '/' + 'logs_' + read_file_tag + '/' + read_file_tag + '_default.csv' |
| 45 | + |
| 46 | +# |
| 47 | +# Data read and edit |
| 48 | +# |
| 49 | +# Read S2E CSV |
| 50 | +time = read_scalar_from_csv(read_file_name, 'elapsed_time[s]') |
| 51 | + |
| 52 | +measured_position_eci_m = read_3d_vector_from_csv(read_file_name, 'orbit_observer_position_i', 'm') |
| 53 | +true_position_eci_m = read_3d_vector_from_csv(read_file_name, 'spacecraft_position_i', 'm') |
| 54 | + |
| 55 | +measured_velocity_eci_m_s = read_3d_vector_from_csv(read_file_name, 'orbit_observer_velocity_i', 'm/s') |
| 56 | +true_velocity_eci_m_s = read_3d_vector_from_csv(read_file_name, 'spacecraft_velocity_i', 'm/s') |
| 57 | + |
| 58 | +# Statistics |
| 59 | +position_error_m = measured_position_eci_m[:, 1:] - true_position_eci_m[:, 1:] |
| 60 | +position_average = [0.0, 0.0, 0.0] |
| 61 | +position_standard_deviation = [0.0, 0.0, 0.0] |
| 62 | +velocity_error_m = measured_velocity_eci_m_s[:, 1:] - true_velocity_eci_m_s[:, 1:] |
| 63 | +velocity_average = [0.0, 0.0, 0.0] |
| 64 | +velocity_standard_deviation = [0.0, 0.0, 0.0] |
| 65 | +for i in range(3): |
| 66 | + position_average[i] = position_error_m[i].mean() |
| 67 | + position_standard_deviation[i] = position_error_m[i].std() |
| 68 | + velocity_average[i] = velocity_error_m[i].mean() |
| 69 | + velocity_standard_deviation[i] = velocity_error_m[i].std() |
| 70 | + |
| 71 | +# |
| 72 | +# Plot |
| 73 | +# |
| 74 | +unit = ' m' |
| 75 | +fig, axis = plt.subplots(3, 1, squeeze = False, tight_layout = True, sharex = True) |
| 76 | +axis[0, 0].plot(time[0], measured_position_eci_m[0], marker=".", c="red", label="MEASURED-X") |
| 77 | +axis[0, 0].plot(time[0], true_position_eci_m[0], marker=".", c="orange", label="TRUE-X") |
| 78 | +axis[0, 0].text(0.01, 0.99, "Error average:" + format(position_average[0], '+.2e') + unit, verticalalignment = 'top', transform = axis[0, 0].transAxes) |
| 79 | +axis[0, 0].text(0.01, 0.79, "Standard deviation:" + format(position_standard_deviation[0], '+.2e') + unit, verticalalignment = 'top', transform = axis[0, 0].transAxes) |
| 80 | +axis[0, 0].legend(loc = 'upper right') |
| 81 | + |
| 82 | +axis[1, 0].plot(time[0], measured_position_eci_m[1], marker=".", c="green", label="MEASURED-Y") |
| 83 | +axis[1, 0].plot(time[0], true_position_eci_m[1], marker=".", c="yellow", label="TRUE-Y") |
| 84 | +axis[1, 0].text(0.01, 0.99, "Error average:" + format(position_average[1], '+.2e') + unit, verticalalignment = 'top', transform = axis[1, 0].transAxes) |
| 85 | +axis[1, 0].text(0.01, 0.79, "Standard deviation:" + format(position_standard_deviation[1], '+.2e') + unit, verticalalignment = 'top', transform = axis[1, 0].transAxes) |
| 86 | +axis[1, 0].legend(loc = 'upper right') |
| 87 | + |
| 88 | +axis[2, 0].plot(time[0], measured_position_eci_m[2], marker=".", c="blue", label="MEASURED-Z") |
| 89 | +axis[2, 0].plot(time[0], true_position_eci_m[2], marker=".", c="purple", label="TRUE-Z") |
| 90 | +axis[2, 0].text(0.01, 0.99, "Error average:" + format(position_average[2], '+.2e') + unit, verticalalignment = 'top', transform = axis[2, 0].transAxes) |
| 91 | +axis[2, 0].text(0.01, 0.79, "Standard deviation:" + format(position_standard_deviation[2], '+.2e') + unit, verticalalignment = 'top', transform = axis[2, 0].transAxes) |
| 92 | +axis[2, 0].legend(loc = 'upper right') |
| 93 | + |
| 94 | +fig.suptitle("Orbit observer position results @ ECI") |
| 95 | +fig.supylabel("Position [m]") |
| 96 | +fig.supxlabel("Time [s]") |
| 97 | + |
| 98 | +unit = ' m/s' |
| 99 | +fig, axis = plt.subplots(3, 1, squeeze = False, tight_layout = True, sharex = True) |
| 100 | +axis[0, 0].plot(time[0], measured_velocity_eci_m_s[0], marker=".", c="red", label="MEASURED-X") |
| 101 | +axis[0, 0].plot(time[0], true_velocity_eci_m_s[0], marker=".", c="orange", label="TRUE-X") |
| 102 | +axis[0, 0].text(0.01, 0.99, "Error average:" + format(velocity_average[0], '+.2e') + unit, verticalalignment = 'top', transform = axis[0, 0].transAxes) |
| 103 | +axis[0, 0].text(0.01, 0.79, "Standard deviation:" + format(velocity_standard_deviation[0], '+.2e') + unit, verticalalignment = 'top', transform = axis[0, 0].transAxes) |
| 104 | +axis[0, 0].legend(loc = 'upper right') |
| 105 | + |
| 106 | +axis[1, 0].plot(time[0], measured_velocity_eci_m_s[1], marker=".", c="green", label="MEASURED-Y") |
| 107 | +axis[1, 0].plot(time[0], true_velocity_eci_m_s[1], marker=".", c="yellow", label="TRUE-Y") |
| 108 | +axis[1, 0].text(0.01, 0.99, "Error average:" + format(velocity_average[1], '+.2e') + unit, verticalalignment = 'top', transform = axis[1, 0].transAxes) |
| 109 | +axis[1, 0].text(0.01, 0.79, "Standard deviation:" + format(velocity_standard_deviation[1], '+.2e') + unit, verticalalignment = 'top', transform = axis[1, 0].transAxes) |
| 110 | +axis[1, 0].legend(loc = 'upper right') |
| 111 | + |
| 112 | +axis[2, 0].plot(time[0], measured_velocity_eci_m_s[2], marker=".", c="blue", label="MEASURED-Z") |
| 113 | +axis[2, 0].plot(time[0], true_velocity_eci_m_s[2], marker=".", c="purple", label="TRUE-Z") |
| 114 | +axis[2, 0].text(0.01, 0.99, "Error average:" + format(velocity_average[2], '+.2e') + unit, verticalalignment = 'top', transform = axis[2, 0].transAxes) |
| 115 | +axis[2, 0].text(0.01, 0.79, "Standard deviation:" + format(velocity_standard_deviation[2], '+.2e') + unit, verticalalignment = 'top', transform = axis[2, 0].transAxes) |
| 116 | +axis[2, 0].legend(loc = 'upper right') |
| 117 | + |
| 118 | +fig.suptitle("Orbit observer velocity results @ ECI") |
| 119 | +fig.supylabel("Velocity [m/s]") |
| 120 | +fig.supxlabel("Time [s]") |
| 121 | + |
| 122 | +# Data save |
| 123 | +if args.no_gui: |
| 124 | + plt.savefig(read_file_tag + "_orbit_observer.png") # save last figure only |
| 125 | +else: |
| 126 | + plt.show() |
0 commit comments