Initial commit
This commit is contained in:
74
src/plot.py
Normal file
74
src/plot.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
||||
# Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import pandas as pd
|
||||
from pathlib import Path
|
||||
import argparse
|
||||
from tqdm import tqdm
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("directory", type=Path, help="Source data directory")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
directory: Path = args.directory
|
||||
|
||||
if not directory.is_dir():
|
||||
parser.error(f"{directory} is not a valid directory")
|
||||
|
||||
print(f"Processing data in: {directory}")
|
||||
|
||||
files: list[Path] = []
|
||||
|
||||
for path in directory.glob("*.csv"):
|
||||
stem = path.stem
|
||||
|
||||
try:
|
||||
base_name, channel = stem.rsplit("_", 1)
|
||||
except ValueError:
|
||||
print(f"Skipping badly named file: {path}")
|
||||
continue
|
||||
|
||||
if channel != "output":
|
||||
print(f"Skipping unknown file: {path}")
|
||||
continue
|
||||
|
||||
files.append(path)
|
||||
|
||||
|
||||
for file in files:
|
||||
output_df = pd.read_csv(file).set_index("time_us", drop=False)
|
||||
fig, ax = plt.subplots(figsize=(12, 6))
|
||||
|
||||
# RPM
|
||||
ax.plot(output_df["time_us"] / 1_000_000, output_df["crank"], label="crank")
|
||||
ax.plot(
|
||||
output_df["time_us"] / 1_000_000, output_df["cam"], label="cam", color="red"
|
||||
)
|
||||
ax.plot(
|
||||
output_df["time_us"] / 1_000_000,
|
||||
output_df["spark_1"],
|
||||
label="spark_1",
|
||||
color="green",
|
||||
)
|
||||
ax.plot(
|
||||
output_df["time_us"] / 1_000_000,
|
||||
output_df["spark_2"],
|
||||
label="spark_2",
|
||||
color="yellow",
|
||||
)
|
||||
ax.plot(
|
||||
output_df["time_us"] / 1_000_000,
|
||||
output_df["spark_3"],
|
||||
label="spark_3",
|
||||
color="orange",
|
||||
)
|
||||
ax.set_xlabel("Time (s)")
|
||||
ax.set_ylim(0, 1)
|
||||
ax.grid(True)
|
||||
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
plt.close(fig)
|
||||
Reference in New Issue
Block a user