STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
plot_thrust_curve.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""Plot thrust curve from CSV (time_s, thrust_N)."""
3import argparse
4from pathlib import Path
5
6import matplotlib.pyplot as plt
7import numpy as np
8
9
10def main() -> None:
11 parser = argparse.ArgumentParser(description="Plot thrust curve CSV")
12 parser.add_argument(
13 "input",
14 type=Path,
15 nargs="?",
16 default=Path("output/lut/thrust_curve.csv"),
17 help="Thrust curve CSV path",
18 )
19 parser.add_argument(
20 "-o",
21 "--output",
22 type=Path,
23 default=None,
24 help="Save figure path (default: input with .png)",
25 )
26 args = parser.parse_args()
27
28 data = np.loadtxt(args.input, delimiter=",", skiprows=1)
29 time_s = data[:, 0]
30 thrust_N = data[:, 1]
31
32 fig, ax = plt.subplots(figsize=(8, 4))
33 ax.plot(time_s, thrust_N, "b-", linewidth=1.5)
34 ax.set_xlabel("Time [s]")
35 ax.set_ylabel("Thrust [N]")
36 ax.set_title("Thrust Curve (Layer 2 pressure curves)")
37 ax.grid(True, alpha=0.3)
38 ax.set_xlim(0, time_s[-1])
39 fig.tight_layout()
40
41 out = args.output or args.input.with_suffix(".png")
42 out.parent.mkdir(parents=True, exist_ok=True)
43 fig.savefig(out, dpi=150)
44 plt.close(fig)
45 print(f"Saved {out}")
46
47
48if __name__ == "__main__":
49 main()