| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #!/usr/bin/env python3
- import numpy as np
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- import matplotlib.cm as cm
- import matplotlib.colors as colors
- import argparse
- import sys
- from model_properties import model_properties
- def calculate_metric(model_type, metric, W, D):
- """
- Calculates the Z-axis data (metric) for the given model type over the meshgrid W, D.
- Uses the logic defined in model_properties.py.
- """
- # Create a vectorized wrapper around the model_properties function
- def get_value(w, d):
- props = model_properties(model_type, int(w), int(d))
- if metric == "models":
- return props.get("Atomic Models", 0)
- elif metric == "events":
- return props.get("Events", 0)
- return 0
- # Vectorize allows the function to operate on the numpy meshgrids W and D efficiently
- vec_calc = np.vectorize(get_value)
- return vec_calc(W, D)
- def plot_data(model_type, metric, max_val):
- w_vals = np.arange(1, max_val + 1)
- d_vals = np.arange(1, max_val + 1)
- W, D = np.meshgrid(w_vals, d_vals)
- print(f"Calculating '{metric}' for model '{model_type}'...")
- Z_data = calculate_metric(model_type, metric, W, D)
- x = W.ravel()
- y = D.ravel()
- z = np.zeros_like(x)
- dx = dy = 0.6
- dz = Z_data.ravel()
- norm = colors.Normalize(vmin=dz.min(), vmax=dz.max())
- colors_map = cm.viridis(norm(dz))
- fig = plt.figure(figsize=(12, 8))
- ax = fig.add_subplot(111, projection='3d')
- ax.bar3d(x - dx / 2, y - dy / 2, z, dx, dy, dz, shade=True, color=colors_map, zsort='average')
- metric_label = "# Atomic Models" if metric == "models" else "# Events"
- ax.set_xlabel('Width')
- ax.set_ylabel('Depth')
- ax.set_zlabel(metric_label)
- tick_step = max(1, max_val // 10)
- ax.set_xticks(w_vals[::tick_step])
- ax.set_yticks(d_vals[::tick_step])
- ax.set_title(f"{metric_label} for {model_type} Model")
- ax.view_init(elev=30, azim=-135)
- mappable = cm.ScalarMappable(norm=norm, cmap=cm.viridis)
- mappable.set_array(dz)
- cbar = fig.colorbar(mappable, ax=ax, shrink=0.6, pad=0.1)
- cbar.set_label('Count')
- plt.tight_layout()
- print("Displaying plot...")
- plt.show()
- def main():
- parser = argparse.ArgumentParser(description="Plot 3D bar chart for DEVS Model metrics.")
- parser.add_argument(
- "-m", "--model",
- type=str,
- choices=["LI", "HI", "HO", "HOmod"],
- default="LI",
- help="The model type to analyze (default: LI)"
- )
- parser.add_argument(
- "-z", "--z-axis",
- type=str,
- choices=["models", "events"],
- default="models",
- help="The metric to plot on the Z-axis: 'models' or 'events' (default: models)"
- )
- parser.add_argument(
- "-l", "--limit",
- type=int,
- default=25,
- help="Maximum value for Width and Depth ranges (default: 25)"
- )
- args = parser.parse_args()
- plot_data(args.model, args.z_axis, args.limit)
- if __name__ == "__main__":
- main()
|