def test_map_data_use_ambient_pressure2(): # Try out inches of water column and barometric pressure in inHg. data2 = os.path.join(_data_dir, "data2.csv") data2_meta = os.path.join(_data_dir, "data2_meta.csv") m = pyo.ConcreteModel("Data Test Model") m.time = pyo.Set(initialize=[1, 2, 3]) m.pressure = pyo.Var(m.time, doc="pressure (Pa)", initialize=101325) m.temperature = pyo.Var(m.time, doc="temperature (K)", initialize=300) m.volume = pyo.Var(m.time, doc="volume (m^3)", initialize=10) def retag(tag): return tag.replace(".junk", "") df, df_meta = da.read_data( data2, data2_meta, model=m, rename_mapper=retag, unit_system="mks", ambient_pressure="Pamb", ambient_pressure_unit="inHg", ) # Check that the unit conversions are okay, same pressures as data1 # differnt units, so the data read in should be the same assert df["P"]["1901-3-3 10:00"] == pytest.approx(96526.6, rel=1e-2) assert df["P"]["1901-3-3 12:00"] == pytest.approx(195886, rel=1e-2)
def test_map_data_use_ambient_pressure(): # Try out PSIG and barometric pressure in PSIA. data1 = os.path.join(_data_dir, "data1.csv") data1_meta = os.path.join(_data_dir, "data1_meta.csv") m = pyo.ConcreteModel("Data Test Model") m.time = pyo.Set(initialize=[1, 2, 3]) m.pressure = pyo.Var(m.time, doc="pressure (Pa)", initialize=101325) m.temperature = pyo.Var(m.time, doc="temperature (K)", initialize=300) m.volume = pyo.Var(m.time, doc="volume (m^3)", initialize=10) def retag(tag): return tag.replace(".junk", "") df, df_meta = da.read_data( data1, data1_meta, model=m, rename_mapper=retag, unit_system="mks", ambient_pressure="Pamb", ambient_pressure_unit="psi", ) # Check that the unit conversions are okay assert df["P"]["1901-3-3 12:00"] == pytest.approx(195886, rel=1e-4)
def test_map_data(): data1 = os.path.join(_data_dir, "data1.csv") data1_meta = os.path.join(_data_dir, "data1_meta.csv") m = pyo.ConcreteModel("Data Test Model") m.time = pyo.Set(initialize=[1, 2, 3]) m.pressure = pyo.Var(m.time, doc="pressure (Pa)", initialize=101325) m.temperature = pyo.Var(m.time, doc="temperature (K)", initialize=300) m.volume = pyo.Var(m.time, doc="volume (m^3)", initialize=10) def retag(tag): return tag.replace(".junk", "") df, df_meta = da.read_data(data1, data1_meta, model=m, rename_mapper=retag, unit_system="mks") # Check for expected columns in data and meta data assert "T" in df assert "P" in df assert "V" in df assert "T" in df_meta assert "P" in df_meta assert "V" in df_meta # Check that the unit strings updated after conversion assert df_meta["T"]["units"] == "kelvin" # this next unit is Pa assert df_meta["P"]["units"] == "kilogram / meter / second ** 2" assert df_meta["V"]["units"] == "meter ** 3" # Check that the unit conversions are okay assert df["T"]["1901-3-3 12:00"] == pytest.approx(300, rel=1e-4) assert df["P"]["1901-3-3 12:00"] == pytest.approx(200000, rel=1e-4) assert df["V"]["1901-3-3 12:00"] == pytest.approx(5.187286689, rel=1e-4) # Check the mapping of the tags to the model (the 1 key is the time indexed # from the model, because the reference is for a time-indexed variable) assert pyo.value(df_meta["T"]["reference"][1]) == pytest.approx(300, rel=1e-4) assert pyo.value(df_meta["P"]["reference"][1]) == pytest.approx(101325, rel=1e-4) assert pyo.value(df_meta["V"]["reference"][1]) == pytest.approx(10, rel=1e-4)
def read_data(model, metadata="data/meta_data.csv", data="data/data_small.csv"): _log.info("Reading data...") df, df_meta = mdata.read_data( model=model, csv_file=data, csv_file_metadata=metadata, ambient_pressure="BAROMETRIC-PRESS", ambient_pressure_unit="inHg", unit_system="mks", ) # drop tags # FWH1 Shell Pressure df.drop("S105", axis=1, inplace=True) del df_meta["S105"] # FWH2 Extraction Temperature #df.drop("S302", axis=1, inplace=True) #del df_meta["S302"] # FWH2 Extraction Temperature #df.drop("S202", axis=1, inplace=True) #del df_meta["S202"] # for now drop attemperator flow #df.drop("FW463", axis=1, inplace=True) #del df_meta["FW463"] df.drop("BG3503", axis=1, inplace=True) del df_meta["BG3503"] df.drop("BG3505", axis=1, inplace=True) del df_meta["BG3505"] # Second hot reheat pressure measure (don't double weight) df.drop("S640", axis=1, inplace=True) del df_meta["S640"] df.drop("S202", axis=1, inplace=True) del df_meta["S202"] # want the data for number of mills in service, but don't want it in # objective and such del df_meta["num_mills"] # Calculated tags can go here # keep paper mill and attemperator flow nonnegative. df["5C0002FLOW"] = np.maximum(df["5C0002FLOW"], 0) #df["FW463"] += 0.265 #df["FW463"] = np.maximum(df["FW463"], 0) # Average the O2 readings df["BG3506"] = (df["BG3506A"] + df["BG3506B"]) / 2.0 df.drop("BG3506A", axis=1, inplace=True) df.drop("BG3506B", axis=1, inplace=True) del df_meta["BG3506A"] del df_meta["BG3506B"] # Add the two main aux cooling water volumetric flows to get total mol flow df["CWCOND_MOL"] = (df["CW119"] + df["CW129"]) * 997000 / 18.015 df["CWAUXCOND_MOL"] = df["CW317-COND"] * 997000 / 18.015 df["PAPERFLOW_MOL"] = np.sqrt( df["5C0002FLOW"]) * 24.29 * 0.4816 * 1000 / 2.2046 / 3600 / 0.018015 df["gross_mw"] = df["1JT66801S"] * 1e-6 df_meta["CWCOND_MOL"] = { "description": "Condenser cooling water mole flow", "reference_string": "m.fs_main.fs_stc.condenser.inlet_2.flow_mol[:]", "units": "mol/s", } df_meta["CWAUXCOND_MOL"] = { "description": "Aux condenser cooling water mole flow", "reference_string": "m.fs_main.fs_stc.aux_condenser.inlet_2.flow_mol[:]", "units": "mol/s", } df_meta["PAPERFLOW_MOL"] = { "description": "Paper mill mole flow", "reference_string": "m.fs_main.fs_stc.turb.hp_split[14].outlet_3.flow_mol[:]", "units": "mol/s", } df_meta["gross_mw"] = { "description": "Gross power in MW", "reference_string": None, "units": "MW", } df_meta["BG3506"] = { "description": "Dry Flue gas O2 fraction", "reference_string": "m.fs_main.fs_blr.aBoiler.fluegas_o2_pct_dry[:]", "units": "None", } mdata.update_metadata_model_references(model, df_meta) # bin the data and calculate the standard deviation mdata.bin_data(df, bin_by="gross_mw", bin_no="bin_number", bin_nom="bin_nominal_mw", bin_size=5, min_value=85, max_value=235) bin_stdev = mdata.bin_stdev(df, bin_no="bin_number") # drop data from bins where there isn't enough data to calculate stdev idx = df.index[~df["bin_number"].isin(bin_stdev)] df.drop(idx, axis=0, inplace=True) _log.info("Done reading data") return df, df_meta, bin_stdev