def _load_interactive_case( case_name, # increase vertical seperation between flags (but do not exceed max(V)) flag_mul=2, ): accdb_cycle = c1.loc[case_name].copy() accdb_gears = [c for c in accdb_cycle.columns if c.startswith("Ind_g")] cycle = c2.loc[case_name].dropna(how="all", axis=1).copy() ## Scale each flag into a different value, to plot separately, and # to plot in the same axis as V # (bc when plotting flags in `secondary_y`, grid is not working) # all_flags = [c for c in cycle.columns if c.startswith("ok_")] ok_flags = [c for c in all_flags if not c.startswith("ok_gear/")] flag_count = len(ok_flags) ok_flags = cycle.loc[:, ok_flags].copy() ok_gears = [c for c in all_flags if c.startswith("ok_gear/")] gear_count = len(ok_gears) ok_gears = cycle.loc[:, ok_gears] ok_flags[ok_flags < 0] = np.NAN # Restore NANFLAG --> NAN ok_flags = ok_flags * (np.arange(flag_count) + 1) * flag_mul ok_gears = ok_gears * (np.arange(gear_count) + flag_count + 1) * flag_mul cycle.columns = wio.inflate_columns(cycle.columns) ok_flags.columns = wio.inflate_columns(ok_flags.columns) ok_gears.columns = wio.inflate_columns(ok_gears.columns) return cycle, ok_flags, ok_gears, accdb_cycle, accdb_gears, p1.loc[ case_name]
def test_flatten_columns(): cols = pd.MultiIndex.from_tuples([("a", "aa"), ("b", "")], names=("gear", "item")) fcols = wio.flatten_columns(cols) infcols = wio.inflate_columns(fcols) assert cols.equals(infcols) assert cols.names == infcols.names with pytest.raises(AssertionError, match="MultiIndex?"): wio.inflate_columns(cols)
def is_more_low_powered_gears(cyc): cyc2 = cyc.copy() cyc2.columns = wio.inflate_columns(cyc2.columns) c22 = cyc2.iloc[1571:1579][["ok_p", "ok_max_n"]].dropna(axis=1, how="all") try: ## is there any row with all-low-p AND 2-or-more n-max-ok? bad_rows = (~c22["ok_p"].replace(-1, 0).astype("bool")).all(axis=1) & ( c22["ok_max_n"].replace(-1, 0).astype("bool").sum(axis=1) > 1) if bad_rows.any(): c22.columns = wio.flatten_columns(c22.columns) return ( list(bad_rows[bad_rows].index), pd.concat( (c22, cyc.iloc[1571:1579].loc[:, ["g_min", "g_max"]]), axis=1), ) except Exception as ex: print(ex)