增加了csv输出
This commit is contained in:
1 parent
bf8542bcc4
commit
f230285316
2 files changed
+24
-2
No files matched your search
@@ -21,7 +21,7 @@ from cryo_tank.tank_model import CryoTank
|
|||||||
from cryo_tank.heat_leak import MLIHeatLeak
|
from cryo_tank.heat_leak import MLIHeatLeak
|
||||||
from cryo_tank.solver import run
|
from cryo_tank.solver import run
|
||||||
from cryo_tank.output import (
|
from cryo_tank.output import (
|
||||||
save_history, plot_temperatures, plot_liquid_level,
|
save_history, save_history_csv, plot_temperatures, plot_liquid_level,
|
||||||
plot_he_flow, plot_heat_fluxes, plot_pressure,
|
plot_he_flow, plot_heat_fluxes, plot_pressure,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -67,6 +67,7 @@ def main():
|
|||||||
|
|
||||||
# --- Output ---
|
# --- Output ---
|
||||||
save_history(history, os.path.join(OUTPUT_DIR, "cryo_tank_history.npz"))
|
save_history(history, os.path.join(OUTPUT_DIR, "cryo_tank_history.npz"))
|
||||||
|
save_history_csv(history, os.path.join(OUTPUT_DIR, "cryo_tank_history.csv"))
|
||||||
plot_temperatures(history, os.path.join(OUTPUT_DIR, "cryo_tank_temperatures.png"))
|
plot_temperatures(history, os.path.join(OUTPUT_DIR, "cryo_tank_temperatures.png"))
|
||||||
plot_liquid_level(history, os.path.join(OUTPUT_DIR, "cryo_tank_level.png"))
|
plot_liquid_level(history, os.path.join(OUTPUT_DIR, "cryo_tank_level.png"))
|
||||||
plot_he_flow(history, os.path.join(OUTPUT_DIR, "cryo_tank_he_flow.png"))
|
plot_he_flow(history, os.path.join(OUTPUT_DIR, "cryo_tank_he_flow.png"))
|
||||||
|
|||||||
+22
-1
@@ -1,7 +1,7 @@
|
|||||||
# src/cryo_tank/output.py
|
# src/cryo_tank/output.py
|
||||||
"""
|
"""
|
||||||
Output helpers for the cryogenic tank simulation.
|
Output helpers for the cryogenic tank simulation.
|
||||||
Generates PNG plots and NPZ data files.
|
Generates PNG plots, NPZ data files, and CSV tables.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -19,6 +19,27 @@ def save_history(history, path):
|
|||||||
np.savez_compressed(path, **history)
|
np.savez_compressed(path, **history)
|
||||||
|
|
||||||
|
|
||||||
|
def save_history_csv(history, path):
|
||||||
|
"""Save all history time series to a CSV file."""
|
||||||
|
dirname = os.path.dirname(path)
|
||||||
|
if dirname:
|
||||||
|
os.makedirs(dirname, exist_ok=True)
|
||||||
|
|
||||||
|
field_names = list(history.keys())
|
||||||
|
columns = [np.asarray(history[name]) for name in field_names]
|
||||||
|
n_rows = len(columns[0]) if columns else 0
|
||||||
|
|
||||||
|
for name, values in zip(field_names, columns):
|
||||||
|
if values.ndim != 1:
|
||||||
|
raise ValueError(f"CSV history field must be 1D: {name}")
|
||||||
|
if len(values) != n_rows:
|
||||||
|
raise ValueError(f"CSV history field length mismatch: {name}")
|
||||||
|
|
||||||
|
data = np.column_stack(columns) if columns else np.empty((0, 0))
|
||||||
|
header = ",".join(field_names)
|
||||||
|
np.savetxt(path, data, delimiter=",", header=header, comments="")
|
||||||
|
|
||||||
|
|
||||||
def plot_temperatures(history, path):
|
def plot_temperatures(history, path):
|
||||||
"""Plot T_liq and T_ull vs time."""
|
"""Plot T_liq and T_ull vs time."""
|
||||||
fig, ax = plt.subplots(figsize=(10, 5))
|
fig, ax = plt.subplots(figsize=(10, 5))
|
||||||
|
|||||||
Reference in new issue
Block a user