reemission.salib.visualize
- class reemission.salib.visualize.SobolResultVisualizer(results: ~reemission.salib.runners.SobolResults, par_name_map: ~typing.Dict[str, str] = <factory>)[source]
Bases:
object
Visualizes Sobol sensitivity analysis results. .. attribute:: results
The Sobol results to visualize.
- type:
SobolResults
- par_name_map: Dict[str, str]
- plot_S1_ST(ax: Axes, title: str = 'Sobol Sensitivity Indices', x_label_rotation: float = 45, tight_layout: bool = True) Axes [source]
Plot Sobol indices S1 and ST. :param ax: The axes to plot on. :type ax: plt.Axes :param title: The title of the plot. :type title: str :param tight_layout: Whether to apply tight layout to the plot. :type tight_layout: bool
- Returns:
The axes with the plot.
- Return type:
plt.Axes
- plot_output_histogram(ax: Axes, title: str = 'Distribution of model output', tight_layout: bool = True, plot_legend: bool = True) Axes [source]
Plot histogram of model outputs. :param ax: The axes to plot on. :type ax: plt.Axes :param title: The title of the plot. :type title: str :param tight_layout: Whether to apply tight layout to the plot. :type tight_layout: bool :param plot_legend: Whether to show the legend. :type plot_legend: bool
- Returns:
The axes with the plot.
- Return type:
plt.Axes
- plot_output_kde(ax: Axes, confidence_level: float = 0.95, ci_type: Literal['bca', 'percentile'] | None = None, title: str = 'Distribution of model output (Y)', tight_layout: bool = True, plot_legend: bool = True, xlims: Tuple[float, float] | None = None) Axes [source]
Improved version of the output histogram plot. :param ax: The axes to plot on. :type ax: plt.Axes :param confidence_level: Confidence level for the intervals. :type confidence_level: float :param ci_type: Type of confidence interval to use. :type ci_type: Optional[Literal[‘bca’, ‘percentile’]] :param title: The title of the plot. :type title: str :param tight_layout: Whether to apply tight layout to the plot. :type tight_layout: bool :param plot_legend: Whether to show the legend. :type plot_legend: bool
- Returns:
The axes with the plot.
- Return type:
plt.Axes
- plot_variance_contribution_by_group(ax: Axes, title: str = 'Variance contribution by uncertainty group', tight_layout: bool = True, plot_legend: bool = True) Axes [source]
Plots variance contribution for each parameter uncertainty group. :param ax: The axes to plot on. :type ax: plt.Axes :param title: The title of the plot. :type title: str :param tight_layout: Whether to apply tight layout to the plot. :type tight_layout: bool :param plot_legend: Whether to show the legend. :type plot_legend: bool
- Returns:
The axes with the plot.
- Return type:
plt.Axes
- results: SobolResults
- class reemission.salib.visualize.SobolScenarioResultsVisualizer(sc_results: SobolScenarioResults)[source]
Bases:
object
Visualizes Sobol sensitivity results with defined scenarios. .. attribute:: sc_results
The Sobol scenario results to visualize.
- type:
SobolScenarioResults
- plot_S1_ST(ax: Axes, title: str = 'Sobol Sensitivity Indices across scenarios', x_label_rotation: float = 45, confidence_level: float = 0.95, tight_layout: bool = True) Axes [source]
Plot Sobol indices S1 and ST. Uses bootstrap resampling to compute confidence intervals for the indices. This method collects all S1 and ST indices across scenarios, computes their means, and calculates confidence intervals using bootstrap resampling. It then plots the mean indices with asymmetric error bars representing the confidence intervals. The error bars are calculated as the difference between the mean and the lower/upper bounds of the confidence intervals. :param ax: The axes to plot on. :type ax: plt.Axes :param title: The title of the plot. :type title: str :param x_label_rotation: Rotation angle for x-axis labels. :type x_label_rotation: float :param confidence_level: Confidence level for error bars. :type confidence_level: float :param tight_layout: Whether to apply tight layout to the plot. :type tight_layout: bool
- Returns:
The axes with the plot.
- Return type:
plt.Axes
- plot_outputs_per_scenarios(ax: Axes, title: str = 'Outputs across multiple scenarios', x_label_rotation: float = 45, confidence_level: float = 0.95, width: float = 0.3, scenario_names: List[str] | None = None, connecting_linestyle: str | None = None, sorting: Literal['asc', 'desc'] | None = None, component_colors: List | None = None, tight_layout: bool = True, x_label: str = 'Reservoir') Axes [source]
Plot model outputs across scenarios with stacked error bars. :param ax: The axes to plot on. :type ax: plt.Axes :param title: The title of the plot. :type title: str :param x_label_rotation: Rotation angle for x-axis labels. :type x_label_rotation: float :param confidence_level: Confidence level for the prediction intervals. :type confidence_level: float :param width: Width of the bars in the plot. :type width: float :param scenario_names: Names of the scenarios to display on the x-axis. :type scenario_names: Optional[List[str]] :param connecting_linestyle: Line style for connecting points across scenarios. :type connecting_linestyle: Optional[str] :param sorting: Sorting order for the outputs. :type sorting: Optional[Literal[‘asc’, ‘desc’]] :param component_colors: Colors for the components in the stacked bars. :type component_colors: Optional[List] :param tight_layout: Whether to apply tight layout to the plot. :type tight_layout: bool :param x_label: Label for the x-axis. :type x_label: str
- Returns:
The axes with the plot.
- Return type:
plt.Axes
- plot_outputs_per_scenarios_simple(ax: Axes, title: str = 'Outputs across multiple scenarios', x_label_rotation: float = 45, confidence_level: float = 0.95, tight_layout: bool = True, sorting: Literal['asc', 'desc'] | None = None, scenario_names: List[str] | None = None, connecting_linestyle: str | None = None) Axes [source]
Plot model outputs across scenarios with simple error bars.
- Parameters:
ax (plt.Axes) – The axes to plot on.
title (str) – The title of the plot.
connecting_linestyle (Optional[str]) – Line style for connecting points across scenarios. Use None for no connecting lines.
- Returns:
The axes with the plot.
- Return type:
plt.Axes
- plot_variance_contributions_by_group(ax: Axes, title: str = 'Variance contribution by uncertainty group', confidence_level: float = 0.95, tight_layout: bool = True, plot_legend: bool = True) Axes [source]
Plots variance contribution for each parameter uncertainty group across all scenarios. :param ax: The axes to plot on. :type ax: plt.Axes :param title: The title of the plot. :type title: str :param confidence_level: Confidence level for the prediction intervals. :type confidence_level: float :param tight_layout: Whether to apply tight layout to the plot. :type tight_layout: bool :param plot_legend: Whether to show the legend. :type plot_legend: bool
- Returns:
The axes with the plot.
- Return type:
plt.Axes
- plot_variance_per_scenario(ax: Axes, title: str = 'Scenario-specific uncertainty decomposition', tight_layout: bool = True) Axes [source]
Plot variance contributions for each scenario. :param ax: The axes to plot on. :type ax: plt.Axes :param title: The title of the plot. :type title: str :param tight_layout: Whether to apply tight layout to the plot. :type tight_layout: bool
- Returns:
The axes with the plot.
- Return type:
plt.Axes
- sc_results: SobolScenarioResults
- reemission.salib.visualize.bootstrap_ci(data: ndarray, confidence_level: float, n_resamples: int) Tuple[ndarray, ndarray] [source]
Compute confidence intervals for the mean of each column in the data using bootstrapping. :param data: 2D array of shape (n_samples, n_features). :type data: np.ndarray :param confidence_level: Confidence level for the intervals (e.g., 0.95). :type confidence_level: float :param n_resamples: Number of bootstrap resamples to perform. :type n_resamples: int
- Returns:
Lower and upper bounds of the confidence intervals for each column.
- Return type:
Tuple[np.ndarray, np.ndarray]
- Raises:
ValueError – If confidence_level is not between 0 and 1 or n_resamples is not positive.
- reemission.salib.visualize.calculate_pr_half_width(variance: float, pred_interval: float = 95) float [source]
Calculate the half-width of the prediction interval. :param variance: The variance of the model output. :type variance: float :param pred_interval: The prediction interval percentage (default is 95). :type pred_interval: float
- Returns:
The half-width of the prediction interval.
- Return type:
float
- Raises:
ValueError – If variance is negative or prediction interval is not between 0 and 100
Functions
|
Compute confidence intervals for the mean of each column in the data using bootstrapping. |
|
Calculate the half-width of the prediction interval. |
Classes
|
Visualizes Sobol sensitivity analysis results. |
|
Visualizes Sobol sensitivity results with defined scenarios. |