Skip to content

Commit

Permalink
got plotting mostly set up but encountered error
Browse files Browse the repository at this point in the history
  • Loading branch information
calbaker committed Jan 30, 2025
1 parent 98be1cf commit 960459d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
15 changes: 9 additions & 6 deletions cal_and_val/thermal/cal_hev.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@
assert len(cyc_files_for_cal) > 0
print("\ncyc_files_for_cal:\n", '\n'.join([cf.name for cf in cyc_files_for_cal]), sep='')

time_column = "Time[s]_RawFacilities"
speed_column = "Dyno_Spd[mph]"

def df_to_cyc(df: pd.DataFrame) -> fsim.Cycle:
cyc_dict = {
"time_seconds": df["Time[s]_RawFacilities"].to_list(),
"speed_meters_per_second": (df["Dyno_Spd[mph]"] * mps_per_mph).to_list(),
"time_seconds": df[time_column].to_list(),
"speed_meters_per_second": (df[speed_column] * mps_per_mph).to_list(),
"temp_amb_air_kelvin": (df["Cell_Temp[C]"] + celsius_to_kelvin_offset).to_list(),
# TODO: pipe solar load from `Cycle` into cabin thermal model
# TODO: use something (e.g. regex) to determine solar load
Expand Down Expand Up @@ -122,9 +125,9 @@ def veh_init(cyc_file_stem: str, dfs: Dict[str, pd.DataFrame]) -> fsim.Vehicle:
}
for key, df_for_cal in dfs_for_cal.items():
# filter out "before" time
df_for_cal = df_for_cal[df_for_cal["Time[s]_RawFacilities"] >= 0.0]
df_for_cal = df_for_cal[df_for_cal[time_column] >= 0.0]
# TODO: figure out if we should use an integrator for resampling rate vars
# df_for_cal = df_for_cal.set_index("Time[s]_RawFacilities")
# df_for_cal = df_for_cal.set_index(time_column)
# df_for_cal = df_for_cal.resample("1s", origin="start").bfill()
df_for_cal = df_for_cal[::10]
df_for_cal.reset_index(inplace=True)
Expand Down Expand Up @@ -159,9 +162,9 @@ def veh_init(cyc_file_stem: str, dfs: Dict[str, pd.DataFrame]) -> fsim.Vehicle:
}
for key, df_for_val in dfs_for_val.items():
# filter out "before" time
df_for_val = df_for_val[df_for_val["Time[s]_RawFacilities"] >= 0.0]
df_for_val = df_for_val[df_for_val[time_column] >= 0.0]
# TODO: figure out if we should use an integrator for resampling rate vars
# df_for_val = df_for_val.set_index("Time[s]_RawFacilities")
# df_for_val = df_for_val.set_index(time_column)
# df_for_val = df_for_val.resample("1s", origin="start").bfill()
df_for_val = df_for_val[::10]
df_for_val.reset_index(inplace=True)
Expand Down
47 changes: 45 additions & 2 deletions cal_and_val/thermal/val_hev.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pandas as pd
import matplotlib.pyplot as plt

from cal_hev import cal_mod_obj, val_mod_obj, save_path
from cal_hev import cal_mod_obj, val_mod_obj, save_path, time_column, mps_per_mph, speed_column

res_df = pd.read_csv(save_path / "pymoo_res_df.csv")
res_df['euclidean'] = (
Expand All @@ -9,4 +10,46 @@
best_df = res_df.iloc[best_row, :]
param_vals = res_df.iloc[best_row, : len(cal_mod_obj.param_fns)].to_numpy()

# plotting
# getting the solved models
(errors_cal, sds_cal) = cal_mod_obj.get_errors(
sim_drives=cal_mod_obj.update_params(param_vals),
return_mods=True,
)
(errors_val, sds_val) = val_mod_obj.get_errors(
sim_drives=val_mod_obj.update_params(param_vals),
return_mods=True,
)

# plotting
plot_save_path = save_path / "plots"
plot_save_path.mkdir(exist_ok=True)

for ((key, df_cal), sd_cal) in zip(cal_mod_obj.dfs.items(), sds_cal):
for obj_fn in cal_mod_obj.obj_fns:
fig, ax = plt.subplots(2, 1, sharex=True)
ax[0].plot(
sd_cal['veh']['history']['time_seconds'],
obj_fn[0](sd_cal),
label='mod',
)
ax[0].plot(
df_cal[time_column],
obj_fn[1](df_cal),
label='exp',
)
ax[0].legend()
ax[0].set_ylabel(obj_fn[0].__name__)

ax[1].plot(
sd_cal['veh']['history']['time_seconds'],
sd_cal['veh']['history']['speed_meters_per_second'],
label='mod',
)
ax[1].plot(
df_cal[time_column],
df_cal[speed_column] * mps_per_mph,
label='exp',
)
ax[1].legend()
ax[1].set_ylabel("Speed [m/s]")

0 comments on commit 960459d

Please sign in to comment.