示例#1
0
def test_n_max_pipeline():
    pipe = pipelines.n_max_pipeline()
    props = goodvehicle.goodVehicle()
    wot = engine.preproc_wot(props, props["wot"])
    sol = pipe.compute(
        {
            **dtz.keyfilter(
                lambda k: k in ("n_rated", "p_rated", "n2v_ratios"), props),
            "wot":
            wot,
            "cycle": {
                "V": pd.Series([120])
            },
            "v_max":
            190.3,
            "g_vmax":
            6,
        })
    assert (list(sol) == """
        p_rated n_rated n2v_ratios wot cycle v_max g_vmax n2v_g_vmax
        n_95_low n_95_high n_max_cycle n_max_vehicle n_max
        """.split())

    steps = [getattr(n, "name", n) for n in sol.plan.steps]
    steps_executed = [getattr(n, "name", n) for n in sol.executed]
    print(steps, steps_executed)
    exp_steps = "calc_n2v_g_vmax calc_n_95 calc_n_max_cycle calc_n_max_vehicle calc_n_max".split(
    )
    assert steps == steps_executed == exp_steps
示例#2
0
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)
示例#3
0
def test_preproc_wot_equals(mdl, xy):
    got = engine.preproc_wot(mdl, xy)
    assert isinstance(got, pd.DataFrame) and got.shape == (3, 4)
    got = got.reset_index(drop=True)
    exp = engine.preproc_wot(mdl, pd.DataFrame(_NP, columns=["n", "p"]))
    assert (got.to_numpy() == exp.to_numpy()).all(None)
示例#4
0
def test_pre_proc_high_level(mdl, wot):
    engine.preproc_wot(mdl, wot)