Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/more data in train history #49

Merged
merged 15 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
sns.set_theme()

from zanzeff_set_speed_train_cal import *

Expand Down
8 changes: 8 additions & 0 deletions python/altrios/altrios_pyo3.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ class SpeedTrace(SerdeAPI):
def __copy__(self) -> Any: ...
def __len__(self) -> int: ...
def from_csv_file(pathstr: str) -> Self: ...
def to_csv_file(self, pathstr: str): ...


class TrainState:
Expand All @@ -621,6 +622,9 @@ class TrainState:
offset_meters: float
offset_back_meters: float
total_dist_meters: float
link_idx_front: int
offset_in_link_meters: float
grade_front: float
speed_meters_per_second: float
speed_limit_meters_per_second: float
speed_target_meters_per_second: float
Expand Down Expand Up @@ -668,6 +672,10 @@ class TrainState:
class TrainStateHistoryVec(SerdeAPI):
time_seconds: list[float]
offset_meters: list[float]
offset_back_meters: list[float]
link_idx_front: list[int]
offset_in_link_meters: list[float]
grade_front: list[float]
speed_meters_per_second: list[float]
speed_limit_meters_per_second: list[float]
speed_target_meters_per_second: list[float]
Expand Down
2 changes: 1 addition & 1 deletion python/altrios/demos/bel_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import os
import seaborn as sns

sns.set()
sns.set_theme()

SHOW_PLOTS = alt.utils.show_plots()

Expand Down
2 changes: 1 addition & 1 deletion python/altrios/demos/conv_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import os
import seaborn as sns

sns.set()
sns.set_theme()

SHOW_PLOTS = alt.utils.show_plots()

Expand Down
2 changes: 1 addition & 1 deletion python/altrios/demos/rollout_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import seaborn as sns
from pathlib import Path

sns.set()
sns.set_theme()

SHOW_PLOTS = alt.utils.show_plots()

Expand Down
114 changes: 57 additions & 57 deletions python/altrios/demos/set_speed_simple_corr_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import seaborn as sns

import altrios as alt
sns.set()
sns.set_theme()

SHOW_PLOTS = alt.utils.show_plots()

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

fig, ax = plt.subplots(4, 1, sharex=True)
ax[0].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.pwr_whl_out_watts,
label="tract pwr",
)
ax[0].set_ylabel('Power')
ax[0].legend()

ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_aero_newtons,
label='aero',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_rolling_newtons,
label='rolling',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_curve_newtons,
label='curve',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_bearing_newtons,
label='bearing',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_grade_newtons,
label='grade',
)
ax[1].set_ylabel('Force [N]')
ax[1].legend()

ax[-1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.speed_trace.speed_meters_per_second,
)
ax[-1].set_xlabel('Time [hr]')
ax[-1].set_ylabel('Speed [m/s]')

ax[2].plot(
np.array(train_sim.history.time_seconds) / 3_600,
np.array(loco0.res.history.soc)
)

ax[2].set_ylabel('SOC')
ax[2].legend()

plt.suptitle("Set Speed Train Sim Demo")
plt.tight_layout()

if SHOW_PLOTS:
fig, ax = plt.subplots(4, 1, sharex=True)
ax[0].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.pwr_whl_out_watts,
label="tract pwr",
)
ax[0].set_ylabel('Power')
ax[0].legend()

ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_aero_newtons,
label='aero',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_rolling_newtons,
label='rolling',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_curve_newtons,
label='curve',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_bearing_newtons,
label='bearing',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_grade_newtons,
label='grade',
)
ax[1].set_ylabel('Force [N]')
ax[1].legend()

ax[-1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.speed_trace.speed_meters_per_second,
)
ax[-1].set_xlabel('Time [hr]')
ax[-1].set_ylabel('Speed [m/s]')

ax[2].plot(
np.array(train_sim.history.time_seconds) / 3_600,
np.array(loco0.res.history.soc)
)

ax[2].set_ylabel('SOC')
ax[2].legend()

plt.suptitle("Set Speed Train Sim Demo")

plt.tight_layout()
plt.show()
fig.show()

# %%
26 changes: 11 additions & 15 deletions python/altrios/demos/set_speed_train_sim_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import seaborn as sns

import altrios as alt
sns.set()
sns.set_theme()

SHOW_PLOTS = alt.utils.show_plots()

Expand All @@ -25,8 +25,7 @@
# instantiate battery model
# https://docs.rs/altrios-core/latest/altrios_core/consist/locomotive/powertrain/reversible_energy_storage/struct.ReversibleEnergyStorage.html#
res = alt.ReversibleEnergyStorage.from_file(
alt.resources_root() /
"powertrains/reversible_energy_storages/Kokam_NMC_75Ah_flx_drive.yaml"
alt.resources_root() / "powertrains/reversible_energy_storages/Kokam_NMC_75Ah_flx_drive.yaml"
)
# instantiate electric drivetrain (motors and any gearboxes)
# https://docs.rs/altrios-core/latest/altrios_core/consist/locomotive/powertrain/electric_drivetrain/struct.ElectricDrivetrain.html
Expand Down Expand Up @@ -61,18 +60,15 @@
loco_con=loco_con,
)

rail_vehicle_file = "rolling_stock/rail_vehicles.csv"
rail_vehicle_map = alt.import_rail_vehicles(alt.resources_root() / rail_vehicle_file)
rail_vehicle = rail_vehicle_map[train_config.rail_vehicle_type]

network = alt.Network.from_file(alt.resources_root() / "networks/Taconite.yaml")
# This data in this file were generated by running
# ```python
# [lp.link_idx.idx for lp in sim0.path_tpc.link_points]
# ```
# in sim_manager_demo.py.
link_path = alt.LinkPath.from_csv_file(alt.resources_root() / "demo_data/link_points_idx.csv")
rail_vehicle_file = "rolling_stock/" + train_config.rail_vehicle_type + ".yaml"
rail_vehicle = alt.RailVehicle.from_file(
alt.resources_root() / rail_vehicle_file)

network = alt.Network.from_file(
alt.resources_root() / "networks/Taconite.yaml")
link_path = alt.LinkPath.from_csv_file(
alt.resources_root() / "demo_data/link_points_idx.csv"
)

speed_trace = alt.SpeedTrace.from_csv_file(
alt.resources_root() / "demo_data/speed_trace.csv"
Expand All @@ -86,7 +82,7 @@
save_interval=SAVE_INTERVAL,
)

train_sim.set_save_interval(1)
train_sim.set_save_interval(SAVE_INTERVAL)
t0 = time.perf_counter()
train_sim.walk()
t1 = time.perf_counter()
Expand Down
2 changes: 1 addition & 1 deletion python/altrios/demos/sim_manager_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seaborn as sns
from pathlib import Path

sns.set()
sns.set_theme()

SHOW_PLOTS = alt.utils.show_plots()
# %
Expand Down
2 changes: 1 addition & 1 deletion python/altrios/demos/speed_limit_simple_corr_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import seaborn as sns

import altrios as alt
sns.set()
sns.set_theme()

SHOW_PLOTS = alt.utils.show_plots()

Expand Down
Loading
Loading