def test_full_build_smoketest(h5_accdb): vehnum = 8 veh_class = 3 # v008's class t_cold_end = 470 # stop in all classes prop, wot, n2vs = vehdb.load_vehicle_accdb(h5_accdb, vehnum) renames = vehdb.accdb_renames() prop = prop.rename(renames) wot = wot.rename(renames, axis=1) wot["n"] = wot.index V = datamodel.get_class_v_cycle(veh_class) wltc_parts = datamodel.get_class_parts_limits(veh_class) pm = cycler.PhaseMarker() cb = cycler.CycleBuilder(V) cb.cycle = pm.add_transition_markers(cb.cycle, cb.V, cb.A) for err in cb.validate_nims_t_cold_end(t_cold_end, wltc_parts): raise err cb.cycle = pm.add_class_phase_markers(cb.cycle, wltc_parts) SM = 0.1 gwots = engine.interpolate_wot_on_v_grid(wot, n2vs) gwots = engine.attach_p_avail_in_gwots(gwots, f_safety_margin=SM) gwots["p_resist"] = vehicle.calc_p_resist(gwots.index, prop.f0, prop.f1, prop.f2) kr = 1.03 cb.add_wots(gwots) cb.cycle["p_inert"] = vehicle.calc_inertial_power(cb.V, cb.A, prop.test_mass, kr) cb.cycle["p_req"] = vehicle.calc_required_power(cb.cycle["p_inert"], cb.cycle["p_resist"]) acc_cycle = vehdb.load_vehicle_nodes(h5_accdb, vehnum, "cycle") diffs = {} def cmpr_cols(c1, c2): diffs[c1.name] = (c1 - c2).abs() acc_cycle["P_tot"], "p_required"
disp_gwots(ac_props, py_props, gwots, 5) # %% [markdown] # ## Manual run # %% caseno = 64 # caseno = 48 # maxWOT # caseno = 20 # maxWOT last gear ac_props, wot, n2vs = vehdb.load_vehicle_accdb(inp_h5fname, caseno) wot = wot.rename(vehdb.accdb_renames(), axis=1) wot["n"] = wot.index ac_props = ac_props.rename(vehdb.accdb_renames()) gwots = engine.interpolate_wot_on_v_grid(wot, n2vs) gwots = engine.attach_p_avail_in_gwots(gwots, f_safety_margin=0.1) gwots["p_resist"] = vehicle.calc_p_resist(gwots.index, ac_props.f0, ac_props.f1, ac_props.f2) # %% w = wio.pstep_factory.get() gidx = wio.GearMultiIndexer.from_df(gwots) rec = vmax.calc_v_max(gwots) print(f"VMAX: {rec.v_max}, G_VMAX: {rec.g_vmax}, maxWOT? {rec.is_n_lim}") display(rec.wot[f"g{rec.g_vmax}"]) # %% [markdown] # # Museum # %% ## Test V_GRID construction always inside WOT_N engine._make_v_grid(1.201, 1.4999)
# %% # renames = vehdb.accdb_renames() # prop = prop.rename(renames) mdl = vehdb.mdl_from_accdb(prop, wot, n2vs) datamodel.validate_model(mdl, additional_properties="true") wot = mdl["wot"] # %% print(list(acc_cycle.columns)) print(list(mdl.keys())) # %% gwots = engine.interpolate_wot_on_v_grid(wot, n2vs) gwots = engine.attach_p_avail_in_gwots(gwots, f_safety_margin=0.1) gwots["p_resist"] = vehicle.calc_p_resist(gwots.index, mdl["f0"], mdl["f1"], mdl["f2"]) # %% V = datamodel.get_class_v_cycle(3) # %% cb = cycler.CycleBuilder(V) pm = cycler.PhaseMarker() # %% wltc_parts = datamodel.get_class_parts_limits(3, edges=True) cb.cycle = pm.add_class_phase_markers(cb.cycle, wltc_parts) # %% cb.cycle = pm.add_phase_markers(cb.cycle, cb.V, cb.A) cb.cycle.select_dtypes(bool).sum()
def make_class_fig(class_name, class_data): font_size = 8 tick_size = 6.5 ## Get cycle-data # # Typical car data test_mass, f0, f1, f2 = 1200, 0.3, 0.03, 0 v = class_data["V_cycle"] a = -v.diff(-1) p_inert = vehicle.calc_inertial_power(v, a, test_mass, 0) p_resist = vehicle.calc_p_resist(v, f0, f1, f2) p = vehicle.calc_required_power(p_inert, p_resist) p *= v.max() / p.max() t = np.arange(0, len(v)) part_limits = class_data["parts"] fig, ax1 = plt.subplots() ax1.set_xlabel("Time (s): ", size=font_size) ax1.xaxis.set_label_coords(-0.06, -0.030) for tl in ax1.get_xticklabels(): tl.set_size(tick_size) ax1.set_ylabel(r"Velocity ($km/h$)", color="b", size=font_size) for tl in ax1.get_yticklabels(): tl.set_color("b") tl.set_size(tick_size) ax2 = ax1.twinx() ax2.set_ylabel(r"Power required", color="m", size=font_size) ax2.set_yticklabels([]) ax2.fill_between(t, 0, p, color="m", alpha=0.3) _l_acc = ax1.plot(t, v, "b-")[0] # plt.legend([l_vel, l_acc], ['Velocity', 'Acceleration']) plt.title("WLTC %s" % class_name, size=9.5, weight="bold") ## Plot part-Limits # for limit in part_limits: _l = plt.axvline(limit, color="r", linewidth=2) ## Add part-labels. # # Trial'n error v_pos = 135 bbox = {"facecolor": "red", "alpha": 0.5, "pad": 4, "linewidth": 0} txts = datamodel.get_class_part_names(class_name) txts_pos = [0] + part_limits # [0.40, 0.67, 0.85] for (txt, h_pos) in zip(txts, txts_pos): ax1.text( h_pos + 18, # trial'n error v_pos, txt, style="italic", bbox=bbox, size=8, va="top", ha="left", ) ax1.grid() ax1.xaxis.grid = True ax1.yaxis.grid = True xlim = [0, 1800] # kmh ax1.set_xlim(xlim) ylim = [0, 140] # kmh ax1.set_ylim(ylim) ax2.set_ylim(ylim) fig.set_size_inches(2 * 2 * 1.618, 2) fig.tight_layout(pad=0) return fig