コード例 #1
0
def load_accdb_and_python_datasets(veh_nums=None):
    p1, c1 = vehdb.merge_db_vehicle_subgroups(
        inp_h5fname, "prop", "cycle", veh_nums=veh_nums
    )
    p2, c2 = vehdb.merge_db_vehicle_subgroups(
        out_h5fname, "oprop", "cycle", veh_nums=veh_nums
    )

    ## Originally fetched as 2-levels (veh, item) MultiIndex Series.
    p1 = p1.unstack()
    p2 = p2.unstack()

    ## By the spec, V rounded to 2-digits,
    #  But exporting MSAccess --> Excel outputs garbage decimals!
    #
    v_cols = "v v_orig v_cap v_downscale".split()
    c1[v_cols] = vround(c1[v_cols])

    ## accdb does not offer `n_max`.(?)
    p1["n_max"] = nround1(p1["n_max1 n_max2 n_max3".split()].max(axis=1))

    return p1, c1, p2, c2
コード例 #2
0
ファイル: test_engine.py プロジェクト: ankostis/wltp
def test_make_v_grid(start, end, nsamples):
    grid = engine._make_v_grid(start, end)
    assert len(grid) == nsamples
    npt.assert_allclose(grid, invariants.vround(grid))
コード例 #3
0
ファイル: test_engine.py プロジェクト: ankostis/wltp
        wio.veh_name(case): interpolate_veh(case)
        for case in vehnums_to_run
    }
    df = pd.concat(
        results.values(),
        axis=0,
        keys=results.keys(),
        names=["vehicle", "v"],
        verify_integrity=True,
    )
    assert df.index.names == ["vehicle", "v"]
    assert (df.index.levels[0] == wio.veh_names(vehnums_to_run)).all()
    assert df.columns.names == ["item", "gear"]
    assert not (set("n Pwot ASM".split()) - set(df.columns.levels[0]))
    npt.assert_allclose(df.index.levels[1],
                        invariants.vround(df.index.levels[1]))


def test_attach_p_avail_in_gwots_smoketest(h5_accdb):
    gwots = pd.DataFrame({("p", "g1"): [], ("ASM", "g1"): []})
    engine.attach_p_avail_in_gwots(gwots, f_safety_margin=0.1)


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),
コード例 #4
0
def test_dsc_pipelines(wltc_class):
    aug = wio.make_autograph()
    ops = aug.wrap_funcs([
        *pipelines.downscale_pipeline().ops,
        *pipelines.compensate_capped_pipeline().ops,
        *pipelines.v_distances_pipeline().ops,
        # fake dsc & cap
        operation(None, "FAKE.V_dsc", "wltc_class_data/V_cycle", "V_dsc"),
    ])
    pipe = compose(..., *ops)
    inp = {
        "wltc_data": datamodel.get_wltc_data(),
        "wltc_class": wltc_class,
        "v_cap": 60,  # class1 max(V) is 60.4
    }
    sol = pipe.compute(inp)
    assert len(sol["compensate_phases_t_extra"]) == len(
        sol["class_phase_boundaries"])

    exp_t_missing = ([0, 1, 0], [0, 10, 43, 192], [0, 8, 81,
                                                   203], [0, 8, 81, 203])
    assert sol["compensate_phases_t_extra"].tolist(
    ) == exp_t_missing[wltc_class]

    exp_compensated_phases = [
        [(0, 589), (590, 1023), (1023, 1612)],
        [(0, 589), (599, 1032), (1075, 1530), (1722, 2045)],
        [(0, 589), (597, 1030), (1111, 1566), (1769, 2092)],
        [(0, 589), (597, 1030), (1111, 1566), (1769, 2092)],
    ]
    compensated_phases = sol["compensated_phase_boundaries"]
    assert compensated_phases == exp_compensated_phases[wltc_class]

    V_compensated = sol["V_compensated"]
    assert compensated_phases[-1][-1] == V_compensated.index[-1]
    assert (sol["V_dsc"].sum() - V_compensated.sum()) < inp["v_cap"]

    exp_compensated_distances = [
        [11988.4, 29146.9, 41135.3],
        [11162.2, 28209.7, 51666.1, 70103.2],
        [11140.3, 28110.5, 50564.1, 69069.5],
        [11140.3, 28241.0, 50779.8, 69285.2],
    ]
    compensated_distances = sol["compensated_distances"]
    assert (inv.vround(compensated_distances["cumsum"]) ==
            exp_compensated_distances[wltc_class]).all()

    ## No CAPPING

    inp = {
        "wltc_data": datamodel.get_wltc_data(),
        "wltc_class": wltc_class,
        "v_cap": 0,
    }
    sol = pipe.compute(inp)
    assert len(sol["compensate_phases_t_extra"]) == len(
        sol["class_phase_boundaries"])

    regular_phases = sol["class_phase_boundaries"]
    V_compensated = sol["V_compensated"]
    assert regular_phases[-1][-1] == V_compensated.index[-1]
    assert sol["V_dsc"].sum() == sol["V_compensated"].sum()