def calc_class_sums(cl): V = datamodel.get_class_v_cycle(cl) cycle_parts = datamodel.get_class_parts_limits(cl, edges=True) prev = (0, 0) for partno, (start, end) in enumerate(itz.sliding_window(2, cycle_parts), 1): start += start_offset end += end_offset sums = calc_v_sums(V.loc[start:end]) cums = calc_v_sums(V.loc[start:end], prev) results.append((cl, f"phase-{partno}", *sums, *cums)) prev = cums return results
def test_wltc_validate_checksums(self): for cl in datamodel.get_class_names(): ## Test below the helper api in datamodel. # cycle = datamodel.get_class_v_cycle(cl) cd = datamodel.get_class(cl) numsum = cycle.sum() checksum = cd["checksum"] self.assertAlmostEqual(numsum, checksum) parts = datamodel.get_class_parts_limits(cl) cycle_parts = np.split(cycle, parts) for partnum, (pchk, cpart) in enumerate( zip(cd["part_checksums"], cycle_parts)): self.assertAlmostEqual(pchk, cpart.sum(), msg=f"class={cl}, partnum={partnum}")
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_phase_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.calc_p_avail_in_gwots(gwots, SM=SM) gwots["p_resist"] = vehicle.calc_road_load_power(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"
def class_boundaries(wltc_class, offset_start, offset_end): cycle_parts = datamodel.get_class_parts_limits(wltc_class, edges=True) return (f"[{start + offset_start}, {end + offset_end}]" for start, end in itz.sliding_window(2, cycle_parts))
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() # %% t_cold_end = 470 # gap for all classes for err in cb.validate_nims_t_cold_end(t_cold_end, wltc_parts): raise err # %% acc_cycle = vehdb.load_vehicle_nodes(h5, caseno, "cycle") print(list(acc_cycle.columns))