openpytea.analysis

openpytea.analysis.direct_costs_data(plants, pct=False)[source]

Extract and organize direct cost data from one or more plants. This function aggregates direct cost information from equipment lists across one or more plants and prepares the data for visualization as a bar chart. :param plants: A single plant object or a list of plant objects from which to extract

direct cost data.

Parameters:

pct (bool, optional) – If True, return direct costs as percentages of the total. If False (default), return absolute cost values.

Returns:

A dictionary containing structured data for bar chart visualization, including: - Component costs keyed by equipment name - Plant names as x-axis labels - Currency symbol - Chart title and formatting information

Return type:

dict

Notes

  • If plants list is empty, USD currency symbol is used as default

  • Currency is automatically extracted from the first plant in the list

  • Each equipment’s direct cost is converted to float for numerical

operations

Examples

>>> plant1 = Plant(name="Plant A", currency="$")
>>> data = direct_costs_data(plant1)
>>> data = direct_costs_data([plant1, plant2], pct=True)
openpytea.analysis.fixed_capital_data(plants, additional_capex=False, pct=False)[source]

Generate fixed capital expenditure data for one or more plants. This function calculates and aggregates the fixed capital costs for given plants, breaking down costs into components (ISBL, OSBL, Design & Engineering, and Contingency). Optionally includes additional CAPEX costs if available. Args:

plants (Plant or list[Plant]): A single plant object or list of plant objects to generate fixed capital data for. additional_capex (bool, optional): If True, includes additional CAPEX costs

from the plant’s additional_capex_cost attribute. Defaults to False.

pct (bool, optional): If True, returns data as percentages of total CAPEX.

If False, returns absolute values. Defaults to False.

Returns:
dict: A dictionary containing structured bar chart data with keys:
  • “components”: List of dictionaries with CAPEX component

breakdowns - “labels”: List of plant names (x-axis labels) - “title”: Chart title (“Fixed CAPEX”) - “currency”: Currency symbol or code - “percentage”: Boolean indicating if values are percentages

Raises:

AttributeError: If plant objects lack required attributes (isbl, osbl, dne, etc.).

Example:
>>> plants = [plant1, plant2]
>>> data = fixed_capital_data(plants, additional_capex=True, pct=False)
>>> # Returns fixed CAPEX breakdown for both plants with additional
>>> # costs in absolute values
openpytea.analysis.variable_opex_data(plants, pct=False)[source]

Extract variable operational expenditure (OPEX) data from ‘ one or more plants. This function processes plant objects to compile their variable OPEX components and returns formatted data suitable for visualization. It handles multiple cost definition formats and supports currency representation. Args:

plants (Plant or list[Plant]): A single plant object or list of plant objects from which to extract variable OPEX data. pct (bool, optional): If True, display values as percentages. Default is False.

Returns:

dict: A dictionary containing structured data for visualization, including:

  • Components breakdown for each plant

  • X-axis labels (plant names)

  • Title: “Annual variable OPEX”

  • Currency symbol or format

  • Data formatted as percentages if pct=True

Notes:
  • Cost values are determined from (in priority order):
    1. “annual_cost” field

    2. “cost” field

    3. “consumption” * “price” calculation

  • If none of these fields exist, the component is skipped.

  • Component names are formatted via _make_label() function.

  • Currency is extracted from the first plant,

defaulting to “$” if no plants provided.

openpytea.analysis.fixed_opex_data(plants, pct=False)[source]

Generate fixed operating expenditure (OPEX) data for one or more plants. This function calculates and aggregates the fixed OPEX components for the given plants, including operating labor, supervision, maintenance, taxes, insurance, and other operational costs. :param plants: A single Plant object or a list of Plant objects for which to

calculate fixed OPEX data.

Parameters:

pct (bool, optional) – If True, return OPEX data as percentages. If False (default), return absolute values.

Returns:

A dictionary containing structured bar chart data with OPEX components and plant names. The structure includes: - Component costs (Operating labor, Supervision, Maintenance, etc.) - Plant names as x-axis labels - Currency information - Annual fixed OPEX totals

Return type:

dict

Notes

The function calculates the following fixed OPEX components: - Operating labor - Supervision - Direct salary overhead - Laboratory charges - Maintenance - Taxes & insurance - Rent of land - Environmental charges - Operating supplies - General plant overhead - Interest on working capital - Patents & royalties - Distribution & selling - Research & Development (R&D)

Examples

>>> result = fixed_opex_data(plant1)
>>> result = fixed_opex_data([plant1, plant2], pct=True)
openpytea.analysis.sensitivity_data(plants, parameter, plus_minus_value, n_points=21, metric='LCOP', label=None, additional_capex=False)[source]

Perform sensitivity analysis on one or more plants by varying a parameter. This function computes how a specified metric (e.g., LCOP) changes as a parameter is varied by a given percentage range. It supports both top-level parameters (capital, opex, etc.) and nested parameters (variable costs, product prices, etc.). :param plants: One or more Plant objects to analyze. If a single plant is provided,

it is converted to a list.

Parameters:
  • parameter (str) –

    The parameter to vary. Can be specified as: - A top-level key: “fixed_capital”, “fixed_opex”, “project_lifetime”,

    ”interest_rate”, or “operator_hourly_rate”

    • A nested key: “variable_opex_inputs.{key}” or “plant_products.{key}”

    • A shorthand: “{key}” (resolved to full path if unambiguous)

  • plus_minus_value (float) – The fraction (0-1) to vary the parameter by in both directions. For example, 0.2 varies from -20% to +20%.

  • n_points (int, optional) – Number of points along the variation range. Default is 21.

  • metric (str, optional) – The metric to compute. Default is “LCOP”. Will be converted to uppercase.

  • label (str, optional) – Custom label for the y-axis. If None, a default label is generated based on the metric and plant currency.

  • additional_capex (bool, optional) – Whether to include additional capital expenditure in calculations. Default is False.

Returns:

A dictionary containing: - “curves” : list of dict

List of results for each plant, each containing: - “plant” : str

Plant name or identifier

  • ”x”ndarray

    Percentage changes along the variation range

  • ”y”ndarray or list

    Metric values corresponding to each point

  • ”baseline”float

    Metric value at the baseline (0% variation)

  • ”xlabel”str

    Label for the x-axis (parameter name with % unit)

  • ”ylabel”str

    Label for the y-axis (metric name and unit)

  • ”parameter”str

    Full parameter name that was varied

  • ”metric”str

    Metric that was computed (uppercase)

Return type:

dict

Raises:

ValueError – If parameter is ambiguous across plants or unrecognized.

Notes

  • For “fixed_capital” and “fixed_opex”,

the original value is assumed to be 1.0 - If a parameter does not exist for a particular plant, a flat baseline curve is returned - Shorthand parameters are resolved from full nested keys (e.g., “CO2” -> “variable_opex_inputs.CO2”)

openpytea.analysis.tornado_data(plant, plus_minus_value, metric='LCOP', label=None, additional_capex=False)[source]

Generate tornado plot data for sensitivity analysis (no plotting). This function performs a sensitivity analysis on a plant model by varying key parameters and calculating their impact on a specified metric. The results are sorted by total effect magnitude to facilitate tornado plot visualization. :param plant: The plant object containing model parameters and configuration. :type plant: Plant :param plus_minus_value: The percentage or absolute value to vary each parameter by

(e.g., 0.1 for ±10%).

Parameters:
  • metric (str, optional) – The metric to analyze. Default is “LCOP” (Levelized Cost of Power). Common metrics: “LCOP”, “LCOH”, “IRR”, “NPV”.

  • label (str, optional) – Custom label for the metric on the x-axis. If None, uses default label based on currency and metric type.

  • additional_capex (bool, optional) – Whether to include additional capital expenditure in calculations. Default is False.

  • dict

    Dictionary containing tornado plot data with keys: - factors : list[str]

    Sorted list of parameter names by sensitivity magnitude (ascending).

    • lowsnp.ndarray

      Metric values when each factor is reduced (sorted by effect size).

    • highsnp.ndarray

      Metric values when each factor is increased (sorted by effect size).

    • base_valuefloat

      Metric value with baseline parameters.

    • labelslist[str]

      Display labels for each factor (sorted by effect size).

    • plus_minus_valuefloat

      The sensitivity variation used.

    • metricstr

      The analyzed metric in uppercase.

    • xlabelstr

      Label for the x-axis.

Examples

>>> tornado_data = tornado_data(plant, plus_minus_value=0.1, metric="LCOP")
>>> factors = tornado_data["factors"]
>>> lows = tornado_data["lows"]
>>> highs = tornado_data["highs"]
openpytea.analysis.monte_carlo(plant, num_samples=1000000, batch_size=1000, additional_capex=False)[source]

Probabilistic analysis of a plant’s economic performance by sampling input parameters from truncated normal distributions and computing economic metrics across all samples. Samples are processed in batches to manage memory.

Parameters:
  • plant (Plant) – A fully configured Plant instance. Baseline economic calculations are run internally before sampling begins. The original plant is not modified; results are stored on it after the simulation completes.

  • num_samples (int, optional) – Total number of Monte Carlo samples. Default is 1_000_000.

  • batch_size (int, optional) – Number of samples processed per batch. Smaller values reduce peak memory at the cost of slightly more overhead. Default is 1000.

  • additional_capex (bool, optional) – Include additional CAPEX in ROI and payback time calculations. Only applies when product prices are available. Default is False.

Returns:

A dictionary with the following keys:

  • "name" : str — plant name.

  • "metrics"dict — arrays of length num_samples:
    • "LCOP" — levelized cost of production (always populated).

    • "NPV" — net present value (requires product prices).

    • "ROI" — return on investment (requires product prices).

    • "PBT" — payback time (requires product prices).

  • "inputs"dict — sampled input arrays, always containing:
    • "Fixed capital factor"

    • "Fixed opex factor"

    • "Operator hourly rate"

    • "Project lifetime"

    • "Interest rate"

    • "{Item} price" for each variable OPEX item.

    • "{Product} product price" for each product.

    And conditionally (when std > 0 in project_uncertainties): - "Plant utilization" - "Tax rate"

  • "num_samples" : int — number of samples generated.

  • "additional_capex" : bool — whether additional CAPEX was included.

  • "currency" : str — currency symbol.

Return type:

dict

Notes

  • Sampling distributions for fixed capital factor, fixed opex factor, project lifetime, interest rate, plant utilization, and tax rate are controlled by the plant’s project_uncertainties configuration dict (see Plant class docstring). Default std, min, and max values are used when a parameter is absent from that dict.

  • plant_utilization and tax_rate have a default std of 0 and are only sampled when explicitly set to a positive value in project_uncertainties.

  • Variable OPEX items and products are sampled using the std, min, and max fields defined within each item’s own config dict.

  • The plant is deep-copied each batch to avoid mutating the original. After the run, monte_carlo_metrics and monte_carlo_inputs are written back to the original plant.

  • Progress is shown via a tqdm progress bar over batches.

Raises:

AttributeError – If the plant object lacks required economic calculation methods or configuration attributes.

Parameters:
  • num_samples (int)

  • batch_size (int)

  • additional_capex (bool)

Examples

>>> results = monte_carlo(plant, num_samples=10000, batch_size=500)
>>> lcop_values = results['metrics']['LCOP']
>>> roi_values = results['metrics']['ROI']