def test_interpolate_wot_on_v_grid(h5_accdb): def interpolate_veh(case): _prop, wot, n2vs = vehdb.load_vehicle_accdb(h5_accdb, case) wot = wot[["Pwot", "ASM"]] wot["n"] = wot.index return engine.interpolate_wot_on_v_grid(wot, n2vs) all_cases = vehdb.all_vehnums(h5_accdb) results = {wio.veh_name(case): interpolate_veh(case) for case in all_cases}
def test_calc_p_available(h5_accdb): def check_p_avail(case): _prop, wot, _n2vs = vehdb.load_vehicle_accdb(h5_accdb, case) p_avail = engine.calc_p_available(wot["Pwot"], 0.1, wot["ASM"]) try: assert (p_avail - wot["Pavai"] < 1e-12).all() except Exception as ex: if isinstance(ex, AssertionError) and case == 48: print(f"Ignoring known BAD case {case} with ghost ASM.") else: raise all_cases = vehdb.all_vehnums(h5_accdb) for case in all_cases: check_p_avail(case)
def test_calc_n_95(h5_accdb): results = [] visited_wots = set() for case in vehdb.all_vehnums(h5_accdb): (props, wot, _a) = vehdb.load_vehicle_accdb(h5_accdb, case) vehnum = props["vehicle_no"] if vehnum in visited_wots: continue visited_wots.add(vehnum) props = props.rename({ "idling_speed": "n_idle", "rated_speed": "n_rated", "rated_power": "p_rated", }) wot = wot.rename({"Pwot": "p", "Pwot_norm": "p_norm"}, axis=1) wot["n"] = wot.index wot = engine.preproc_wot( props.rename({ "idling_speed": "n_idle", "rated_speed": "n_rated" }), wot) n95 = engine.calc_n_95(wot, props["n_rated"], props["p_rated"]) results.append(n95) df = pd.DataFrame(results, columns=["n95_low", "n95_high"], dtype="float64") # print(df.describe().values) aggregate_tol = 1e-4 # The digits copied from terminal. exp = np.array([ [116.0, 116.0], [3656.11189008, 4784.66622629], [1337.23040635, 1428.79658641], [1680.0, 2897.4405215], [2837.63712814, 3750.68145459], [3215.01884177, 4142.35055724], [4512.5, 6000.03571429], [7843.72440418, 8817.60270757], ]) assert (df.describe().values - exp < aggregate_tol).all(None)
def _permatest_and_random_vehnums(h5_accdb): sample_ratio = 0.14 # ~x7 test-runs would cover all with vehdb.openh5(h5_accdb) as h5db: all_vehs = set(vehdb.all_vehnums(h5db)) permatest_vehs = [ 1, # >9 gears 23, # Known bads 42, 46, 48, 52, 53, 90, # AccDB not respecting n_min=0.9 x n_idle (Annex 2-3.k.3) 25, # Diffs in gears above 2 35, # Vehicle has too many insufficient powers 75, # Extensions 117, 119, 121, 125, ] remain_vehs = all_vehs - set(permatest_vehs) sample_size = int(sample_ratio * len(remain_vehs)) sample_vehs = random.sample(remain_vehs, sample_size) run_vehs = permatest_vehs + sample_vehs log.info( "Sample-testing %s(%.1f%%) out of %s accdb vehicles (%.1f%% at random).", len(run_vehs), 100 * len(run_vehs) / len(all_vehs), len(all_vehs), 100 * sample_ratio, ) return run_vehs