def test_generate_table_errors(gtmodel): m = gtmodel sd = {"a": m.state_a[0], "b1": m.state_b[0,1]} heading=["F"] with pytest.raises(AssertionError): st = generate_table(sd, attributes=[("flow_mol",)], heading=heading) with pytest.raises(KeyError): st = generate_table(sd, attributes=[("flow_mol", "coffee")], heading=heading) with pytest.raises(TypeError): st = generate_table(sd, attributes=["flow_mol"], heading=heading)
def stream_table(sdict, fname=None): """Make a stream table as a Pandas Dataframe, and optionally save it to a CSV file. Args: m: steady state plant model to make a stream table for fname: If not none the file to save the CSV file to Returns: Dataframe """ df = tables.generate_table( blocks=sdict, attributes=[ "flow_mass", "flow_mol", "temperature", "pressure", "enth_mol", "vapor_frac", ("flow_mol_comp", "O2"), ("flow_mol_comp", "N2"), ("flow_mol_comp", "NO"), ("flow_mol_comp", "CO2"), ("flow_mol_comp", "H2O"), ("flow_mol_comp", "SO2"), ], exception=False, # since there are two property packs with differnt # components, ignore missing indexes ) df.sort_index(inplace=True) df.to_csv(fname) return df
def test_generate_table(gtmodel): m = gtmodel sd = {"a": m.state_a[0], "b1": m.state_b[(0,1)]} # This tests what happens if one of the requested attributes gives a division # by zero error and if one of the attributes doesn't exist. With flow it # tests indexed attributes. st = generate_table( sd, attributes=["pressure", "temperature", "div0", ("flow_mol", "CO2"), ("flow_mol", "H2O"), "not_there", ("not_there_array", "hi")], heading=["P", "T", "ERR", "F_CO2", "F_H2O", "Miss", "Miss[hi]"]) assert st.loc["a"]["P"] == 11000 assert st.loc["a"]["F_CO2"] == 110 assert st.loc["a"]["F_H2O"] == 111 assert st.loc["a"]["T"] == 1100*2 assert isna(st.loc["a"]["ERR"]) assert isna(st.loc["a"]["Miss"]) assert st.loc["b1"]["P"] == 10000 assert st.loc["b1"]["F_CO2"] == 100 assert st.loc["b1"]["F_H2O"] == 101 assert st.loc["b1"]["T"] == 1000*2 assert isna(st.loc["b1"]["ERR"]) assert isna(st.loc["b1"]["Miss"])
def test_mixed_table(gtmodel): m = gtmodel sd = { "a": m.state_a[0], "b[1]": m.state_b[(0, 1)], "b[2]": m.state_b[(0, 2)], "b[3]": m.state_b[(0, 3)], "c": m.state_c[0], } st = generate_table( sd, exception=False, attributes=( "pressure", "temperature", "flow_mol", "flow_vol", "enth_mol", ("flow_mol", "CO2"), ("flow_mol", "H2O"), ), heading=( "P", "T", "F", "Fvol", "h", "F[CO2]", "F[H2O]", ) ) assert st.loc["a"]["P"] == 11000 assert st.loc["a"]["F[CO2]"] == 110 assert st.loc["a"]["F[H2O]"] == 111 assert isna(st.loc["a"]["Fvol"]) assert isna(st.loc["a"]["F"]) assert st.loc["a"]["T"] == 1100*2 assert st.loc["c"]["P"] == 1000 assert isna(st.loc["c"]["F[CO2]"]) assert isna(st.loc["c"]["F[H2O]"]) assert st.loc["c"]["Fvol"] == 30 assert st.loc["c"]["F"] == 10 assert st.loc["c"]["T"] == 300
def test_generate_table(): m = ConcreteModel() m.state_a = TestStateBlock() m.state_b = TestStateBlock([1, 2, 3]) m.state_a.pressure = 11000 m.state_a.enth_mol = 1100 m.state_a.flow_mol = 110 m.state_b[1].pressure = 10000 m.state_b[1].enth_mol = 1000 m.state_b[1].flow_mol = 100 m.state_b[2].pressure = 20000 m.state_b[2].enth_mol = 2000 m.state_b[2].flow_mol = 200 m.state_b[3].pressure = 30000 m.state_b[3].enth_mol = 3000 m.state_b[3].flow_mol = 300 sd = {"a": m.state_a, "b1": m.state_b[1]} st = generate_table(sd, attributes=[ "pressure", "temperature", "div0", "flow_mol", "not_there" ], heading=["P", "T", "ERR", "F", "Miss"]) assert (st.loc["a"]["P"] == 11000) assert (abs(st.loc["a"]["T"] - 1100 * 2) < 0.001) assert (isna(st.loc["a"]["ERR"])) assert (isna(st.loc["a"]["Miss"])) assert (st.loc["b1"]["P"] == 10000) assert (abs(st.loc["b1"]["T"] - 1000 * 2) < 0.001) assert (isna(st.loc["b1"]["ERR"])) assert (isna(st.loc["b1"]["Miss"]))