CADETProcess.comparison.Comparator#

class CADETProcess.comparison.Comparator(name)[source]#

Bases: Structure

Class for comparing simulation results against reference data.

Attributes:
namestr

Name of the Comparator instance.

referencesdict

Dictionary containing the reference data to be compared against.

solution_pathsdict

Dictionary containing the solution path for each difference metric.

metricslist

list[DifferenceBase]: List of difference metrics.

add_difference_metric(difference_metric: DifferenceBase | str, *args: Any, **kwargs: Any) DifferenceBase[source]#

Add a difference metric to the Comparator.

Parameters:
difference_metricDifferenceBase

Difference metric instance to register.

solution_pathstr

Path to the solution in SimulationResults.

Returns:
DifferenceBase
Raises:
TypeError

If difference_metric is not a DifferenceBase instance.

Notes

Passing a metric class name as a string is deprecated. Construct the metric directly instead:

metric = SSE(reference)
comparator.add_difference_metric(metric, 'outlet.outlet')

The string form will be removed in v1.0.

add_reference(reference: SolutionBase, update: bool | None = False, smooth: bool | None = False) None[source]#

Add reference to the Comparator.

Deprecated since version Use: the new API instead: construct the metric with the reference directly and pass the instance to add_difference_metric(). This method will be removed in v1.0.

Parameters:
referenceSolutionBase

Reference for comparison with SimulationResults.

updateOptional[bool], default=False

If True, update existing reference.

smoothOptional[bool], default=False

If True, smooth data before comparison.

Raises:
TypeError

If reference is not an instance of SolutionBase.

CADETProcessError

If Reference already exists.

property bad_metrics: list[float]#

list[float]: Worst case metrics for all difference metrics.

evaluate(simulation_results: SimulationResults) list[float][source]#

Evaluate all metrics for a given simulation and return the results as a list.

Parameters:
simulation_resultsSimulationResults

The SimulationResults object containing the solutions for all metrics.

Returns:
list[float]

A list containing the values of all difference of metrics after comparison.

extract_solution(simulation_results: SimulationResults, metric: DifferenceBase) SolutionBase[source]#

Extract the solution for a given metric from the SimulationResults object.

Parameters:
simulation_resultsSimulationResults

The SimulationResults object containing the solution.

metricDifferenceBase

The difference metric object for which to extract the solution.

Returns:
SolutionBase

The solution for the given metric.

Raises:
CADETProcessError

If the solution path for the given metric is not found.

property labels: list[str]#

list[str]: List of metric labels.

property metrics: list[DifferenceBase]#

list[DifferenceBase]: List of difference metrics.

property n_difference_metrics: int#

int: Number of difference metrics in the Comparator.

property n_metrics: int#

int: Number of metrics to be evaluated.

name#

Parameter descriptor constrained to string values.

plot_comparison(simulation_results: SimulationResults, x_axis_in_minutes: bool | None = True, ax: ndarray[Axes] | None = None, setup_figure_kwargs: dict | None = None) tuple[Figure, ndarray[tuple[Any, ...], dtype[Axes]]][source]#

Plot the comparison of the simulation results with the reference data.

Parameters:
simulation_resultsSimulationResults

Simulation results to compare to reference data.

x_axis_in_minutes: Optional[bool], default=True

If True, the x-axis will be plotted using minutes. The default is True.

axnp.ndarray[plt.Axes] | None, default=None

Optional array of Matplotlib Axes. If not provided, a new figure is created.

setup_figure_kwargsdict | None, default=None

Additional options to setup the figure.

Returns:
tuple

A tuple containing: - list[plt.Figure]: A list of Matplotlib Figure objects. - npt.NDArray[plt.Axes]: An array of Axes objects with one Axes per

difference metric.