watertap.flowsheets.METAB package
Submodules
watertap.flowsheets.METAB.input_space_generation module
- watertap.flowsheets.METAB.input_space_generation.create_samples(method='LHS', input_var_info=None, sample_numbers=10, csv_file='./results/input_data.csv')[source]
Generate input samples over a defined variable space and write them to a CSV file
- Parameters:
method (str, optional) – Sampling strategy to use. This currently only supports the Latin Hypercube Sampling (LHS) method
input_var_info (dict, optional) – Ordered mapping of input variable names
sample_numbers (int, optional) – Number of sample points to generate
csv_file (str, optional) – Path to the output CSV file
- Returns:
None. Results are written to
csv_fileand a confirmation message is printed on success.
watertap.flowsheets.METAB.model_evaluation module
- watertap.flowsheets.METAB.model_evaluation.collect_results(case=None, results=None, mass=True)[source]
Gathers flowrates from four output streams — effluent, methane biogas (reactor 2 extraction), hydrogen biogas (reactor 1 extraction), and reactor 1 extracted biogas — and concatenates them into a single wide-format row. Column names are prefixed to distinguish streams:
eff_: effluent digestate (no prefix applied)bge2_: biogas extraction from reactor 2 (CH4-rich)bgr2_: biogas from reactor 2 hydrogen streambge1_: biogas extraction from reactor 1
- Parameters:
case – An EXPOsan METAB system object whose
outsstreams will be read.results (pd.DataFrame, optional) – Accumulator DataFrame from previous iterations.
mass (bool, optional) – If
True, useget_mass_flowratefor all streams. IfFalse, use the molar flowrate helpers (get_eff_fr,get_ch4_fr,get_h2_fr,get_r1_ex_biogas_fr).
- Returns:
Updated accumulator with the current run’s output appended as a new row
- Return type:
pd.DataFrame
- watertap.flowsheets.METAB.model_evaluation.export_output_data(df, filename=None)[source]
Export a DataFrame of output results to a CSV file.
- Parameters:
df – Output data to export
filename (str, optional) – Full path (including filename and extension) for the output CSV file. Passed directly to
df.to_csv(). Defaults toNone.
- Returns:
None
- watertap.flowsheets.METAB.model_evaluation.get_ch4_fr(case=None, df=None)[source]
Extract methane stream molar flowrates from a METAB system and append them to a DataFrame
- Parameters:
case – An EXPOsan METAB system object with an
outsattributedf – Existing DataFrame to append the new row to. If
None, a new DataFrame is created from the extracted flowrates.
- Returns:
DataFrame containing one row of CH4 stream molar flowrates, with component names as columns
- Return type:
pd.DataFrame
- watertap.flowsheets.METAB.model_evaluation.get_eff_fr(case=None, df=None)[source]
Extract effluent molar flowrates from a METAB system and append them to a DataFrame
- Parameters:
case – An EXPOsan METAB system object with an
outsattributedf – Existing DataFrame to append the new row to. If
None, a new DataFrame is created from the extracted flowrates.
- Returns:
DataFrame containing one row of effluent molar flowrates, with component names as columns
- Return type:
pd.DataFrame
- watertap.flowsheets.METAB.model_evaluation.get_h2_fr(case=None, df=None)[source]
Extract hydrogen stream molar flowrates from a METAB system and append them to a DataFrame.
- Parameters:
case – An EXPOsan METAB system object with an
outsattributedf – Existing DataFrame to append the new row to.
- Returns:
DataFrame containing one row of H2 stream molar flowrates, with component names as columns
- Return type:
pd.DataFrame
- watertap.flowsheets.METAB.model_evaluation.get_input_data(filename=None)[source]
Load input variable data from a CSV file or return a hardcoded default dataset. If no filename is provided, a small default dataset with three sample points is returned, covering influent flowrate, temperature, and hydraulic retention time.
- Parameters:
filename (str, optional) – Path to a CSV file containing input variable columns
- Returns:
DataFrame with one row per sample point
- Return type:
pd.DataFrame
- watertap.flowsheets.METAB.model_evaluation.get_mass_flowrate(case=None, df=None, stream=None)[source]
Extract mass flowrates and volumetric flowrate from a stream and append them to a DataFrame.
Reads component mass flowrates directly from a stream’s state vector, using the stream’s component list as column names. A
Volumetric Flowratecolumn is appended from the last element of the state vector. Columns where all values are zero are dropped from the result.- Parameters:
case – An EXPOsan METAB system object
df – Existing DataFrame to append the new row to
stream – An EXPOsan stream object with
componentsandstateattributes
- Returns:
DataFrame with one row of mass flowrates and volumetric flowrate, with zero-only columns removed.
- Return type:
pd.DataFrame
- watertap.flowsheets.METAB.model_evaluation.get_r1_ex_biogas_fr(case=None, df=None)[source]
Extract reactor 1 extracted biogas molar flowrates from a METAB system and append them to a DataFrame.
- Parameters:
case – An EXPOsan METAB system object with an
outsattributedf – Existing DataFrame to append the new row to
- Returns:
DataFrame containing one row of reactor 1 biogas molar flowrates, with component names as columns
- Return type:
pd.DataFrame
- watertap.flowsheets.METAB.model_evaluation.run_model(df)[source]
Iterates over all rows of the input DataFrame, configures a two-stage fluidized-bed METAB system with membrane gas extraction for each set of conditions, simulates it using the BDF solver, and accumulates the output stream flowrates into a single results DataFrame.
Fixed model parameters applied to every run:
n_stages: 2reactor_type:"FB"(fluidized bed)gas_extraction:"M"(membrane)t_span: 200 (simulation time in days)
- Parameters:
df (pd.DataFrame) – Input DataFrame with one row per simulation run. Must contain columns
inf_fr(influent flowrate, m³/d),temp(reactor temperature, °C), andhrt(total hydraulic retention time, d).- Returns:
Accumulated output flowrates from all simulation runs, as returned by
collect_results. Returns an empty dict ifexposanis not installed or no rows are processed.- Return type:
pd.DataFrame
watertap.flowsheets.METAB.performance_estimation module
- watertap.flowsheets.METAB.performance_estimation.display_plot(surrogate, dataframe, method='poly', path=None, show=True)[source]
Produces one parity plot per output variable and consolidates into a PDF
- Parameters:
surrogate – IDAES surrogate object
dataframe – DataFrame containing input and output columns corresponding to the surrogate’s labels
method (str, optional) – Surrogate method identifier used to name the output PDF file (e.g.
"poly","kri","rbf")path (str, optional) – Directory in which to save the PDF
show (bool, optional) – Whether to display each figure interactively via matplotlib
- Returns:
One figure per output variable
- Return type:
list[matplotlib.figure.Figure]
- watertap.flowsheets.METAB.performance_estimation.performance_estimation(surrogate=None, dataframe=None)[source]
Evaluates the surrogate against the provided dataframe and returns a DataFrame summarising fit metrics for each output variable.
- Parameters:
surrogate – IDAES surrogate object Must implement input_labels(), output_labels(), and evaluate_surrogate()
dataframe (pd.DataFrame) – DataFrame containing both input and output columns corresponding to the surrogate’s input_labels() and output_labels()
- Returns:
- One row per output variable with columns:
Comp: output variable nameR2: coefficient of determinationRMSE: root mean squared errorMSE: mean squared errorMAE: mean absolute errormaxAE: maximum absolute errorSSE: sum of squared errors
- Return type:
pd.DataFrame
watertap.flowsheets.METAB.surrogate_model_generator module
- watertap.flowsheets.METAB.surrogate_model_generator.gen_surrogate_model(tool='idaes', method='poly', feed_data=None, input_data=None, output_data=None)[source]
Train an IDAES surrogate model and save it to disk alongside a parity plot.
Method-specific configuration:
"poly"PySMO polynomial up to order 6, multinomials enabled,80/20 train/test split, 3-fold cross-validation.
"kri": PySMO Kriging with numerical gradients and regularization."rbf": PySMO RBF with cubic basis function."alamo"ALAMO with constant, linear, exponential, log, sin, cosbasis functions and monomial/multi-linear powers up to 3.
- Parameters:
tool (str, optional) – Surrogate toolbox identifier
method (str, optional) – Surrogate modelling method
feed_data – Combined input and output DataFrame used for training
input_data (pd.DataFrame, optional) – Input variables DataFrame. Used to derive input labels and bounds
output_data (pd.DataFrame, optional) – Output variables DataFrame.
- Returns:
<method>_surrogate.json: serialised surrogate model.<method>_parity.pdf: parity plot for all output variables.
- Return type:
None. Writes the following files to the module directory
- watertap.flowsheets.METAB.surrogate_model_generator.get_data(input_data_file='/home/docs/checkouts/readthedocs.org/user_builds/watertap/checkouts/1.7.0/watertap/flowsheets/METAB/input_data.csv', output_data_file='/home/docs/checkouts/readthedocs.org/user_builds/watertap/checkouts/1.7.0/watertap/flowsheets/METAB/output_data.csv')[source]
Load input and output data from CSV files and combine them into a single feed DataFrame.
- Parameters:
input_data_file – Path to the input variables CSV file.
output_data_file – Path to the output variables CSV file.
- Returns:
feed_data: Combined input and output DataFrame used for training.input_data: Input variables only.output_data: Output variables only (first column dropped).
- Return type:
tuple
- watertap.flowsheets.METAB.surrogate_model_generator.outputs_selections(output_data)[source]
Filter and reorder output data columns to the standard ADM1 component set.
The selected outputs are (in order):
S_su,S_aa,S_fa,S_va,S_bu,S_pro,S_ac,S_h2,S_ch4,S_IC,S_IN,S_I,X_c,X_ch,X_pr,X_li,X_su,X_aa,X_fa,X_c4,X_pro,X_ac,X_h2,X_I,VolumetricFlowrate.- Parameters:
output_data (pd.DataFrame) – Raw output DataFrame as loaded from CSV.
- Returns:
Output DataFrame restricted to the standard ADM1 component columns in the order listed above
- Return type:
pd.DataFrame