Skip to content

Commit a79427a

Browse files
authored
Merge pull request #49 from NREL/fix/more-data-in-train-history
Fix/more data in train history
2 parents bcecc48 + 1867419 commit a79427a

37 files changed

+41661
-18852
lines changed

applications/calibration/zanzeff_set_speed_train_cal_post.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import matplotlib.pyplot as plt
55
import seaborn as sns
6-
sns.set()
6+
sns.set_theme()
77

88
from zanzeff_set_speed_train_cal import *
99

python/altrios/altrios_pyo3.pyi

+8
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ class SpeedTrace(SerdeAPI):
613613
def __copy__(self) -> Any: ...
614614
def __len__(self) -> int: ...
615615
def from_csv_file(pathstr: str) -> Self: ...
616+
def to_csv_file(self, pathstr: str): ...
616617

617618

618619
class TrainState:
@@ -621,6 +622,9 @@ class TrainState:
621622
offset_meters: float
622623
offset_back_meters: float
623624
total_dist_meters: float
625+
link_idx_front: int
626+
offset_in_link_meters: float
627+
grade_front: float
624628
speed_meters_per_second: float
625629
speed_limit_meters_per_second: float
626630
speed_target_meters_per_second: float
@@ -668,6 +672,10 @@ class TrainState:
668672
class TrainStateHistoryVec(SerdeAPI):
669673
time_seconds: list[float]
670674
offset_meters: list[float]
675+
offset_back_meters: list[float]
676+
link_idx_front: list[int]
677+
offset_in_link_meters: list[float]
678+
grade_front: list[float]
671679
speed_meters_per_second: list[float]
672680
speed_limit_meters_per_second: list[float]
673681
speed_target_meters_per_second: list[float]

python/altrios/demos/bel_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import os
1212
import seaborn as sns
1313

14-
sns.set()
14+
sns.set_theme()
1515

1616
SHOW_PLOTS = alt.utils.show_plots()
1717

python/altrios/demos/conv_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import os
1212
import seaborn as sns
1313

14-
sns.set()
14+
sns.set_theme()
1515

1616
SHOW_PLOTS = alt.utils.show_plots()
1717

python/altrios/demos/rollout_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import seaborn as sns
88
from pathlib import Path
99

10-
sns.set()
10+
sns.set_theme()
1111

1212
SHOW_PLOTS = alt.utils.show_plots()
1313

python/altrios/demos/set_speed_simple_corr_demo.py

+57-57
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import seaborn as sns
1111

1212
import altrios as alt
13-
sns.set()
13+
sns.set_theme()
1414

1515
SHOW_PLOTS = alt.utils.show_plots()
1616

@@ -78,62 +78,62 @@
7878
# pull out solved locomotive for plotting convenience
7979
loco0:alt.Locomotive = train_sim.loco_con.loco_vec.tolist()[0]
8080

81+
fig, ax = plt.subplots(4, 1, sharex=True)
82+
ax[0].plot(
83+
np.array(train_sim.history.time_seconds) / 3_600,
84+
train_sim.history.pwr_whl_out_watts,
85+
label="tract pwr",
86+
)
87+
ax[0].set_ylabel('Power')
88+
ax[0].legend()
89+
90+
ax[1].plot(
91+
np.array(train_sim.history.time_seconds) / 3_600,
92+
train_sim.history.res_aero_newtons,
93+
label='aero',
94+
)
95+
ax[1].plot(
96+
np.array(train_sim.history.time_seconds) / 3_600,
97+
train_sim.history.res_rolling_newtons,
98+
label='rolling',
99+
)
100+
ax[1].plot(
101+
np.array(train_sim.history.time_seconds) / 3_600,
102+
train_sim.history.res_curve_newtons,
103+
label='curve',
104+
)
105+
ax[1].plot(
106+
np.array(train_sim.history.time_seconds) / 3_600,
107+
train_sim.history.res_bearing_newtons,
108+
label='bearing',
109+
)
110+
ax[1].plot(
111+
np.array(train_sim.history.time_seconds) / 3_600,
112+
train_sim.history.res_grade_newtons,
113+
label='grade',
114+
)
115+
ax[1].set_ylabel('Force [N]')
116+
ax[1].legend()
117+
118+
ax[-1].plot(
119+
np.array(train_sim.history.time_seconds) / 3_600,
120+
train_sim.speed_trace.speed_meters_per_second,
121+
)
122+
ax[-1].set_xlabel('Time [hr]')
123+
ax[-1].set_ylabel('Speed [m/s]')
124+
125+
ax[2].plot(
126+
np.array(train_sim.history.time_seconds) / 3_600,
127+
np.array(loco0.res.history.soc)
128+
)
129+
130+
ax[2].set_ylabel('SOC')
131+
ax[2].legend()
132+
133+
plt.suptitle("Set Speed Train Sim Demo")
134+
plt.tight_layout()
135+
81136
if SHOW_PLOTS:
82-
fig, ax = plt.subplots(4, 1, sharex=True)
83-
ax[0].plot(
84-
np.array(train_sim.history.time_seconds) / 3_600,
85-
train_sim.history.pwr_whl_out_watts,
86-
label="tract pwr",
87-
)
88-
ax[0].set_ylabel('Power')
89-
ax[0].legend()
90-
91-
ax[1].plot(
92-
np.array(train_sim.history.time_seconds) / 3_600,
93-
train_sim.history.res_aero_newtons,
94-
label='aero',
95-
)
96-
ax[1].plot(
97-
np.array(train_sim.history.time_seconds) / 3_600,
98-
train_sim.history.res_rolling_newtons,
99-
label='rolling',
100-
)
101-
ax[1].plot(
102-
np.array(train_sim.history.time_seconds) / 3_600,
103-
train_sim.history.res_curve_newtons,
104-
label='curve',
105-
)
106-
ax[1].plot(
107-
np.array(train_sim.history.time_seconds) / 3_600,
108-
train_sim.history.res_bearing_newtons,
109-
label='bearing',
110-
)
111-
ax[1].plot(
112-
np.array(train_sim.history.time_seconds) / 3_600,
113-
train_sim.history.res_grade_newtons,
114-
label='grade',
115-
)
116-
ax[1].set_ylabel('Force [N]')
117-
ax[1].legend()
118-
119-
ax[-1].plot(
120-
np.array(train_sim.history.time_seconds) / 3_600,
121-
train_sim.speed_trace.speed_meters_per_second,
122-
)
123-
ax[-1].set_xlabel('Time [hr]')
124-
ax[-1].set_ylabel('Speed [m/s]')
125-
126-
ax[2].plot(
127-
np.array(train_sim.history.time_seconds) / 3_600,
128-
np.array(loco0.res.history.soc)
129-
)
130-
131-
ax[2].set_ylabel('SOC')
132-
ax[2].legend()
133-
134-
plt.suptitle("Set Speed Train Sim Demo")
135-
136-
plt.tight_layout()
137-
plt.show()
137+
fig.show()
138138

139139
# %%

python/altrios/demos/set_speed_train_sim_demo.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import seaborn as sns
77

88
import altrios as alt
9-
sns.set()
9+
sns.set_theme()
1010

1111
SHOW_PLOTS = alt.utils.show_plots()
1212

@@ -25,8 +25,7 @@
2525
# instantiate battery model
2626
# https://docs.rs/altrios-core/latest/altrios_core/consist/locomotive/powertrain/reversible_energy_storage/struct.ReversibleEnergyStorage.html#
2727
res = alt.ReversibleEnergyStorage.from_file(
28-
alt.resources_root() /
29-
"powertrains/reversible_energy_storages/Kokam_NMC_75Ah_flx_drive.yaml"
28+
alt.resources_root() / "powertrains/reversible_energy_storages/Kokam_NMC_75Ah_flx_drive.yaml"
3029
)
3130
# instantiate electric drivetrain (motors and any gearboxes)
3231
# https://docs.rs/altrios-core/latest/altrios_core/consist/locomotive/powertrain/electric_drivetrain/struct.ElectricDrivetrain.html
@@ -61,18 +60,15 @@
6160
loco_con=loco_con,
6261
)
6362

64-
rail_vehicle_file = "rolling_stock/rail_vehicles.csv"
65-
rail_vehicle_map = alt.import_rail_vehicles(alt.resources_root() / rail_vehicle_file)
66-
rail_vehicle = rail_vehicle_map[train_config.rail_vehicle_type]
67-
68-
network = alt.Network.from_file(alt.resources_root() / "networks/Taconite.yaml")
69-
# This data in this file were generated by running
70-
# ```python
71-
# [lp.link_idx.idx for lp in sim0.path_tpc.link_points]
72-
# ```
73-
# in sim_manager_demo.py.
74-
link_path = alt.LinkPath.from_csv_file(alt.resources_root() / "demo_data/link_points_idx.csv")
63+
rail_vehicle_file = "rolling_stock/" + train_config.rail_vehicle_type + ".yaml"
64+
rail_vehicle = alt.RailVehicle.from_file(
65+
alt.resources_root() / rail_vehicle_file)
7566

67+
network = alt.Network.from_file(
68+
alt.resources_root() / "networks/Taconite.yaml")
69+
link_path = alt.LinkPath.from_csv_file(
70+
alt.resources_root() / "demo_data/link_points_idx.csv"
71+
)
7672

7773
speed_trace = alt.SpeedTrace.from_csv_file(
7874
alt.resources_root() / "demo_data/speed_trace.csv"
@@ -86,7 +82,7 @@
8682
save_interval=SAVE_INTERVAL,
8783
)
8884

89-
train_sim.set_save_interval(1)
85+
train_sim.set_save_interval(SAVE_INTERVAL)
9086
t0 = time.perf_counter()
9187
train_sim.walk()
9288
t1 = time.perf_counter()

python/altrios/demos/sim_manager_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import seaborn as sns
99
from pathlib import Path
1010

11-
sns.set()
11+
sns.set_theme()
1212

1313
SHOW_PLOTS = alt.utils.show_plots()
1414
# %

python/altrios/demos/speed_limit_simple_corr_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import seaborn as sns
1111

1212
import altrios as alt
13-
sns.set()
13+
sns.set_theme()
1414

1515
SHOW_PLOTS = alt.utils.show_plots()
1616

0 commit comments

Comments
 (0)