import{_ as i,c as a,a2 as e,o as t}from"./chunks/framework.DYF6f1aH.js";const n="/micromissiles-unity/assets/sim_visualizer.CwuQ1zYH.png",c=JSON.parse('{"title":"Simulation Logging","description":"","frontmatter":{},"headers":[],"relativePath":"Simulation_Logging.md","filePath":"Simulation_Logging.md"}'),l={name:"Simulation_Logging.md"};function p(h,s,r,o,d,k){return t(),a("div",null,s[0]||(s[0]=[e('

Simulation Logging

This guide provides instructions on how to access and interpret the simulation logs, how they are structured by the SimMonitor class, and how to utilize the provided visualize_log.py script to analyze simulation data. Additionally, it offers guidance on creating your own scripts for custom analysis.

Overview

Python simulation log visualizer

Simulation logs capture detailed telemetry and event data from each simulation run. These logs are essential for debugging, performance analysis, and understanding the behavior of agents within the simulation.

Logs are exported to the Telemetry/Logs folder in your operating system's persistent data path.

For example, on Windows, the logs are exported to:

C:\\Users\\<user>\\AppData\\LocalLow\\BAMLAB\\micromissiles\\Telemetry\\Logs

On macOS, the logs are exported to:

~/Library/Application Support/BAMLAB/micromissiles/Telemetry/Logs

visualize_log.py is an example script provided to help visualize and interpret the simulation logs. It is included in the Tools directory of the release download.

Understanding Log Files and Directory Structure

Log Directory Structure

Simulation logs are organized into timestamped directories within the Logs folder. Each simulation run generates a new directory named with the timestamp of the run.

For example:

Telemetry/
└── Logs/
    ├── 20241002_101305/
    │   ├── sim_telemetry_20241002_101311.csv
    │   ├── sim_events_20241002_101311.csv
    │   │
    │   ├── sim_telemetry_20241002_101306.csv
    │   └── sim_events_20241002_101306.csv
    ├── 20241002_012122/
    │   ├── sim_telemetry_20241002_012122.csv
    │   └── sim_events_20241002_012122.csv
    └── ...

Each simulation run produces two main CSV files:

Log Files Generated by SimMonitor

The logging system is managed by the SimMonitor class in the simulation codebase.

csharp
public class SimMonitor : MonoBehaviour
{
    // Responsible for logging simulation data
    // ...
}

Key Responsibilities of SimMonitor:

Telemetry Log Structure

The telemetry log provides a snapshot of the simulation at each time step for every agent. Key columns include:

Event Log Structure

The event log records significant occurrences within the simulation. Key columns include:

Running the visualize_log.py Script

The visualize_log.py script helps visualize agent trajectories and significant events in a 3D plot.

Locating the Script

After downloading and extracting the release package, you can find the script at:

Tools/visualize_log.py

Make sure you have Python 3 installed on your system, along with the required libraries to run the script.

Required Python Libraries

The script depends on the following Python libraries:

You can install them using pip:

bash
pip install pandas matplotlib numpy

Usage

Open a terminal or command prompt and navigate to the Tools directory:

bash
cd path/to/Tools/

Run the Script

To visualize the most recent simulation logs:

bash
python visualize_log.py

What the Script Does:

Specifying Log Files Manually

You can also provide specific file paths as arguments:

bash
python visualize_log.py path/to/sim_telemetry_file.csv path/to/sim_events_file.csv

Example Output

Total number of events: 150

Event Counts:
  HIT: 120
  MISS: 30

First hit at 5.00 seconds, last hit at 15.00 seconds

[3D plot window opens showing trajectories and events]

Interpreting the Plot

The 3D plot displays:

Adjusting the Visualization

Writing Your Own Scripts

The simulation logs are in CSV format, making them accessible for custom analysis and visualization.

Getting Started

For example, using Python and the pandas library, you can load the telemetry and event data like this:

python
import pandas as pd

telemetry_df = pd.read_csv('path/to/sim_telemetry_*.csv')
event_df = pd.read_csv('path/to/sim_events_*.csv')

Visualization

python
import matplotlib.pyplot as plt

plt.plot(telemetry_df['Time'], telemetry_df['AgentY'])
plt.xlabel('Time (s)')
plt.ylabel('Altitude (m)')
plt.title('Agent Altitude Over Time')
plt.show()

Sample Script: Calculating Miss Distances

python
import pandas as pd
import numpy as np

# Load telemetry and event data
telemetry_df = pd.read_csv('path/to/sim_telemetry_*.csv')
event_df = pd.read_csv('path/to/sim_events_*.csv')

# Filter miss events
miss_events = event_df[event_df['Event'] == 'MISS']

# Calculate miss distances
miss_distances = []
for idx, miss in miss_events.iterrows():
    agent_id = miss['AgentID']
    time = miss['Time']
    # Get agent position at the time of miss
    agent_state = telemetry_df[(telemetry_df['AgentID'] == agent_id) & (telemetry_df['Time'] == time)]
    if not agent_state.empty:
        x = agent_state['AgentX'].values[0]
        y = agent_state['AgentY'].values[0]
        z = agent_state['AgentZ'].values[0]
        # Calculate distance to target or predefined point
        distance = np.sqrt(x**2 + y**2 + z**2)
        miss_distances.append(distance)

# Output average miss distance
average_miss_distance = np.mean(miss_distances)
print(f'Average Miss Distance: {average_miss_distance:.2f} meters')

Suggestions for Analysis

Additional Resources

`,75)]))}const u=i(l,[["render",p]]);export{c as __pageData,u as default};