Visualization Module
The visualize module provides rich visualization and analysis tools for infrastructure simulation results.
Dashboard
Real-time dashboard for infrastructure simulation monitoring.
- class infralib.visualize.dashboard.DashboardState(simulator: ~infralib.simulator.Simulator = None, is_running: bool = False, current_step: int = 0, max_steps: int = 1000, step_delay: float = 0.1, states_history: ~collections.deque = <factory>, budget_history: ~collections.deque = <factory>, cost_history: ~collections.deque = <factory>, failure_history: ~collections.deque = <factory>, action_history: ~collections.deque = <factory>)[source]
Bases:
objectContainer for dashboard state data.
- __init__(simulator: ~infralib.simulator.Simulator = None, is_running: bool = False, current_step: int = 0, max_steps: int = 1000, step_delay: float = 0.1, states_history: ~collections.deque = <factory>, budget_history: ~collections.deque = <factory>, cost_history: ~collections.deque = <factory>, failure_history: ~collections.deque = <factory>, action_history: ~collections.deque = <factory>) None
Network Visualization
Network topology visualization for infrastructure systems.
- class infralib.visualize.network.NetworkVisualizer[source]
Bases:
objectVisualize infrastructure networks and topologies.
- create_network_graph(components: list[dict], connections: list[tuple] = None, layout: str = 'spring') Figure[source]
Create network graph visualization of infrastructure components.
- create_geographic_map(components: list[dict], center_lat: float = 52.5, center_lon: float = 13.4, zoom: int = 10) Map[source]
Create geographic map with infrastructure components.
- create_cascade_visualization(components: list[dict], cascade_steps: list[dict], connections: list[tuple] = None) list[Figure][source]
Create animation frames showing cascade failure propagation.
Plots
Static visualization plots for infrastructure simulation data.
- class infralib.visualize.plots.PlotGenerator[source]
Bases:
objectGenerate various plots for infrastructure simulation analysis.
- plot_component_states(states_history: list[ndarray], title: str = 'Component States Over Time') Figure[source]
Plot component state evolution over time.
- plot_budget_usage(budget_history: list[float], cost_history: list[ndarray], title: str = 'Budget Usage Over Time') Figure[source]
Plot budget usage and spending patterns.
- plot_failure_analysis(states_history: list[ndarray], title: str = 'Failure Analysis') Figure[source]
Plot failure counts and patterns over time.
- plot_action_heatmap(actions_history: list[ndarray], title: str = 'Action Heatmap') Figure[source]
Plot heatmap of actions taken over time and components.
- plot_hierarchy_metrics(hierarchy_metrics: dict[str, dict], title: str = 'Hierarchy Performance') Figure[source]
Plot hierarchy-based performance metrics.
- plot_learning_curves(training_data: dict[str, list], title: str = 'RL Training Progress') Figure[source]
Plot RL training learning curves.
Simulator Plots
Matplotlib/Seaborn visualization utilities for infrastructure simulators.
- infralib.visualize.simulator_plots.set_plot_style(style: str = 'whitegrid', context: str = 'paper', font_scale: float = 1.5)[source]
Set consistent plot style for publication-quality figures.
- infralib.visualize.simulator_plots.plot_state_budget_history(simulator: Any, num_steps: int, save_path: str | None = None, show: bool = True, figsize: tuple[int, int] = (14, 15)) Figure[source]
Plot the distribution of component states over time, budget changes, and action counts.
This visualization provides a comprehensive view of the simulation history including: - Distribution of component states (violin plot) - Budget evolution over time - Action counts per timestep
- Parameters:
simulator (Simulator) – The simulator instance after simulation with state_history, budget_history, and action_history attributes
num_steps (int) – Number of time steps in the simulation
save_path (str, optional) – Path to save the figure
show (bool) – Whether to display the plot
figsize (tuple) – Figure size (width, height)
- Returns:
fig – The generated figure
- Return type:
- infralib.visualize.simulator_plots.plot_component_states_comparison(state_histories: list[ndarray], action_histories: list[ndarray] | None = None, labels: list[str] | None = None, failure_conditions: ndarray | None = None, component_idx: int = 0, type_indices: ndarray | None = None, max_steps: int | None = None, save_path: str | None = None, show: bool = True, figsize: tuple[int, int] | None = None) Figure[source]
Plot and compare condition index over time for a specific component across different policies.
This is useful for comparing how different control strategies affect individual component degradation and maintenance.
- Parameters:
state_histories (list of np.ndarray) – State history for each policy/strategy. Shape: (timesteps, n_components)
action_histories (list of np.ndarray, optional) – Action history for each policy. Shape: (timesteps, n_components)
labels (list of str, optional) – Labels for each policy/strategy
failure_conditions (np.ndarray, optional) – Failure thresholds for each component type
component_idx (int) – Index of component to visualize
type_indices (np.ndarray, optional) – Mapping from component index to component type
max_steps (int, optional) – Maximum number of steps to show
save_path (str, optional) – Path to save the figure
show (bool) – Whether to display the plot
figsize (tuple, optional) – Figure size (width, height)
- Returns:
fig – The generated figure
- Return type:
- infralib.visualize.simulator_plots.plot_action_distribution(action_history: ndarray, save_path: str | None = None, show: bool = True, figsize: tuple[int, int] = (10, 6)) Figure[source]
Plot the distribution of actions taken during simulation.
- Parameters:
- Returns:
fig – The generated figure
- Return type: