Beispiel #1
0
    def compare_vehicle(h5db, vehnum, oprops, cycle, wots_vmax):
        oprops = pd.Series(oprops)
        db_oprops = h5db.get(vehdb.vehnode(vehnum, props_group_suffix))
        db_cycle = h5db.get(vehdb.vehnode(vehnum, cycle_group_suffix))
        db_wots_vmax = h5db.get(vehdb.vehnode(vehnum, wots_vmax_group_suffix))

        to_compare = [(oprops, db_oprops), (cycle, db_cycle), (wots_vmax, db_wots_vmax)]

        for calced, stored in to_compare:
            if not calced.equals(stored):
                df = pd.concat((calced, stored)).drop_duplicates(keep=False)
                display(df)
                raise Exception(f"Calced-vs-stored differ in {len(df)} rows!")
Beispiel #2
0
    def store_vehicle(h5db, vehnum, oprops, cycle, wots_vmax):
        log.info("STORING veh(v%0.3i)...", vehnum)

        g = vehdb.vehnode(vehnum, props_group_suffix)
        h5db.put(g, pd.Series(oprops))
        vehdb.provenir_h5node(h5db, g, title="Pyalgo generated")

        g = vehdb.vehnode(vehnum, cycle_group_suffix)
        h5db.put(g, cycle)
        vehdb.provenir_h5node(h5db, g, title="Pyalgo generated")

        g = vehdb.vehnode(vehnum, wots_vmax_group_suffix)
        h5db.put(g, wots_vmax)
        vehdb.provenir_h5node(h5db, g, title="Pyalgo generated")
Beispiel #3
0
def store_results_per_car(
    h5db,
    specs,
    overrides,
    pwots,
    cycles,
    all_cases=None,
    props_group_suffix="prop",
    overrides_group_suffix="override",
    wot_group_suffix="wot",
    cycle_group_suffix="cycle",
    c_vehnum=c_vehnum,
    c_case_id=c_case,
):
    """
    Populate h5db with results collected from a folder full of (`V123.xls`, ...) exchel-files.

    :param cycles:
        if none, also `specs` are not stored!

        vehicles/
            +--v001/
            |   +--props      (series) scalar inputs & outputs generated by AccDB
            |   +--wot        (df) not all vehicles have wot
            |   +--cycle      (df) cycle-run generated by AccDB
            |   +--override   (series) pyalgo must also override these kv-pairs
            +...
    """
    base = vehdb.provenance_info(files=[veh_inputs_excel[0], veh_results_excel[0]])

    if all_cases is None:
        all_cases = set()
        if specs is not None:
            all_cases.update(specs[c_case_id])
        if overrides is not None:
            all_cases.update(overrides.keys())
        if cycles is not None:
            all_cases.update(cycles[c_case_id].unique())
    log.info("Will store %s cases: %s", len(all_cases), all_cases)

    for case in sorted(all_cases):
        vehnum = cycles is not None and int(
            cycles.loc[cycles[c_case_id] == case, c_vehnum].iloc[0]
        )
        log.info(f"+++ Case: %s, Veh: %s (out of %s)...", case, vehnum, len(all_cases))

        ## Store WOT
        #
        if pwots is not None:
            pwot = pwots.loc[pwots[c_engno] == vehnum, :]
            assert pwot.size, (case, vehnum)
            pwot, SM = extract_SM_from_pwot(pwot)
            assert SM and pwot.size, (case, vehnum, SM, pwot)
            pwot_node = vehdb.vehnode(vehnum, wot_group_suffix)
            if not skip_h5_write:
                h5db.put(pwot_node, pwot)
                vehdb.provenir_h5node(
                    h5db,
                    pwot_node,
                    title="Full-load-curve of the test-car, as delivered by Heinz on 13 May 2019",
                    files=[wots_excel[0]],
                    base=base,
                )

        if specs is not None and cycles is not None:
            cyc = cycles.loc[cycles[c_case_id] == case].set_index("tim")
            try:
                cyc, oprops = vehdb.drop_scalar_columns(cyc, scalar_columns)
            except Exception:
                display(case, vehdb.grid(cyc, fitcols=False))
                raise

            ## Store INP/OUT props
            #
            props = specs.loc[specs[c_case_id] == vehnum, :].squeeze()
            assert isinstance(props, pd.Series), props
            props.update(pd.Series(oprops))
            props[c_SM] = SM
            props_group = vehdb.vehnode(case, props_group_suffix)
            if not skip_h5_write:
                h5db.put(props_group, pd.Series(props))
                vehdb.provenir_h5node(
                    h5db,
                    props_group,
                    title="Input specs & scalar results produced by AccDB",
                    base=base,
                )

            ## Store CYCLE
            #
            cycle_group = vehdb.vehnode(case, cycle_group_suffix)
            if not skip_h5_write:
                h5db.put(cycle_group, cyc)
                vehdb.provenir_h5node(
                    h5db, cycle_group, title="Cycle-run produced by AccDB", base=base
                )

        ## Store OVERRIDES
        #
        if overrides is not None and case in overrides:
            overrides_group = vehdb.vehnode(case, overrides_group_suffix)
            if not skip_h5_write:
                h5db.put(overrides_group, pd.Series(overrides[case]))
                vehdb.provenir_h5node(
                    h5db,
                    overrides_group,
                    title="Values to override, as specified manually by Heinz",
                    files=[
                        "VehData/Differences between ACCESS tool versions 16_ and 20_09_2019.xlsx"
                    ],
                    base=base,
                )