Analysis system¶
GOLIAT's analysis system processes simulation results and generates reports, plots, and publications. This document covers user-facing usage and internal architecture.
User guide¶
Running analysis¶
The analysis command aggregates results from multiple simulations and generates visualizations:
Command options:
--config <config>: Study configuration file (default:near_field_config)--format <pdf|png>: Plot output format (default:pdf)--analysis <path>: Path to analysis configuration JSON (default:configs/analysis.json)--generate-paper: Generate LaTeX paper after analysis completes
Example:
# Run analysis with PNG output
goliat analyze --config near_field_config --format png
# Run analysis and generate LaTeX paper
goliat analyze --config near_field_config --generate-paper
Analysis configuration¶
The analysis configuration file (configs/analysis.json) controls which plots are generated. Each plot type can be enabled or disabled:
{
"load_data": true,
"plot_average_sar_bar": true,
"plot_sar_heatmap": true,
"plot_pssar_line": false
}
Key settings:
load_data: Iffalse, loads cached results instead of re-processing (faster for re-plotting)- Plot flags: Set to
falseto skip specific plot types
Available plot types:
Near-field plots: - plot_average_sar_bar: Bar charts of average SAR by frequency - plot_average_pssar_bar: Bar charts of average psSAR10g by frequency - plot_sar_line: Line plots of SAR trends across frequencies - plot_pssar_line: Line plots of psSAR10g trends - plot_sar_distribution_boxplots: Boxplots showing SAR distributions - plot_sar_heatmap: Heatmaps of SAR by tissue and frequency - plot_peak_sar_heatmap: Heatmaps of peak SAR values - plot_power_balance_overview: Power balance visualization - plot_peak_location_3d_interactive: 3D interactive peak location plots - plot_peak_location_2d_projections: 2D projections of peak locations - plot_correlation_head_vs_eye_sar: Correlation scatter plots - plot_tissue_group_correlation_matrix: Correlation heatmaps - plot_bubble_mass_vs_sar: Bubble plots of mass vs SAR - plot_top20_tissues_ranking: Top 20 tissues ranking charts - plot_power_efficiency_trends: Power efficiency line plots - plot_penetration_depth_ratio: Penetration depth analysis - plot_tissue_frequency_response: Frequency response plots - plot_cdf: Cumulative distribution function plots - identify_outliers: Outlier detection and visualization
Far-field plots: - plot_whole_body_sar_bar: Whole-body SAR bar charts - plot_peak_sar_line: Peak SAR line plots - plot_far_field_distribution_boxplot: Distribution boxplots
Output structure¶
Analysis generates outputs in organized directories:
plots/
└── near_field/
└── <phantom_name>/
├── average_sar_bar_*.pdf
├── sar_heatmap_*.pdf
└── ...
results/
└── near_field/
└── <phantom_name>/
├── normalized_results_detailed.csv
└── normalized_results_summary.csv
CSV files:
normalized_results_detailed.csv: Per-simulation detailed data with all metricsnormalized_results_summary.csv: Aggregated statistics by frequency and scenario
Caching:
Processed results are cached in results/<study_type>/<phantom>/aggregated_results.pkl. Set "load_data": false in analysis config to skip re-processing and load from cache.
Paper generation¶
The --generate-paper flag creates a LaTeX document with all plots organized by section:
This generates paper/near_field/pure_results/results.tex with: - All plots organized by section and subsection - Automatic figure numbering and cross-references - Captions extracted from plot metadata files - IEEE format document structure
Check out the auto-generated first draft paper (only results) to see an example.
Developer guide¶
Architecture overview¶
The analysis system uses a strategy pattern to handle different study types:
graph TB
CLI[goliat analyze CLI]
Analyzer[Analyzer
orchestrator]
subgraph "Strategy Pattern"
BaseStrategy[BaseAnalysisStrategy
interface]
NearStrategy[NearFieldAnalysisStrategy]
FarStrategy[FarFieldAnalysisStrategy]
end
subgraph "Plotter Composition"
Plotter[Plotter
delegator]
BarPlotter[BarPlotter]
LinePlotter[LinePlotter]
HeatmapPlotter[HeatmapPlotter]
SpatialPlotter[SpatialPlotter]
OtherPlotters[11 other specialized plotters]
end
Results[Result Files
JSON + PKL]
CSV[CSV Reports]
Plots[Plot Files
PDF/PNG]
Paper[LaTeX Paper]
CLI --> Analyzer
Analyzer --> BaseStrategy
BaseStrategy --> NearStrategy
BaseStrategy --> FarStrategy
Analyzer --> Plotter
Plotter --> BarPlotter
Plotter --> LinePlotter
Plotter --> HeatmapPlotter
Plotter --> SpatialPlotter
Plotter --> OtherPlotters
Results --> Analyzer
Analyzer --> CSV
Analyzer --> Plots
Analyzer --> Paper
Core components¶
Analyzer¶
The Analyzer class orchestrates the analysis pipeline:
- Initialization: Sets up strategy and plotter based on study type
- Data loading: Delegates to strategy to load and process results
- Unit conversion: Normalizes SAR values to standard units (mW/kg)
- Caching: Saves processed data for faster re-plotting
- Report export: Generates CSV files
- Plot generation: Delegates to strategy for plot creation
Key methods:
run_analysis(): Main entry point, runs complete pipeline_process_single_result(): Processes one simulation's result files_convert_units_and_cache(): Normalizes units and caches results_export_reports(): Generates CSV output files
BaseAnalysisStrategy¶
Abstract base class defining the analysis interface. Subclasses implement study-specific logic:
Abstract methods:
load_and_process_results(): Iterates through results and processes eachget_normalization_factor(): Calculates SAR normalization factorextract_data(): Extracts structured data from result filesapply_bug_fixes(): Applies study-specific data correctionsgenerate_plots(): Creates all plots for the study type
Concrete implementations:
NearFieldAnalysisStrategy: Handles placement scenarios, positions, orientationsFarFieldAnalysisStrategy: Handles incident directions and polarizations
Plotter¶
The Plotter class uses composition to delegate to specialized plot modules:
Specialized plotters:
BarPlotter: Bar charts (average SAR, psSAR10g, whole-body SAR)LinePlotter: Line plots (SAR trends, psSAR10g trends, variations)BoxplotPlotter: Distribution boxplotsHeatmapPlotter: SAR heatmaps by tissue and frequencySpatialPlotter: 3D and 2D peak location visualizationsCorrelationPlotter: Correlation scatter plots and matricesBubblePlotter: Bubble charts (mass vs SAR)RankingPlotter: Top tissues ranking chartsPowerPlotter: Power efficiency and absorption plotsPenetrationPlotter: Penetration depth analysisTissueAnalysisPlotter: Tissue frequency response and mass/volumeCdfPlotter: Cumulative distribution functionsOutliersPlotter: Outlier detection and visualization
Data flow¶
- Result loading: Strategy iterates through configured scenarios
- File discovery: Locates
sar_results.jsonandsar_stats_all_tissues.pklfiles - Data extraction: Strategy extracts relevant metrics per simulation
- Normalization: Applies power normalization factors
- Aggregation: Combines all simulations into DataFrames
- Unit conversion: Converts to standard units (mW/kg)
- Caching: Saves processed DataFrames to pickle files
- Report generation: Exports CSV files
- Plot generation: Strategy calls plotter methods with DataFrames
Adding new plots¶
To add a new plot type:
-
Create specialized plotter (if needed):
-
Register in Plotter:
-
Add to strategy:
-
Add to analysis config:
Data structures¶
Main results DataFrame (results_df): - One row per simulation scenario - Columns: frequency_mhz, scenario_name, position, orientation, SAR metrics, etc. - Used for aggregated analysis and summary plots
Organ results DataFrame (all_organ_results_df): - One row per tissue per simulation - Columns: frequency_mhz, scenario_name, tissue_name, tissue_group, SAR metrics - Used for tissue-specific analysis and heatmaps
Tissue groups: - Defined in data/material_name_mapping.json - Groups like "eyes", "head", "skin", "genitals" aggregate multiple tissues - Used for summary statistics and group-level plots
Normalization¶
SAR values are normalized to 1W input power:
normalization_factor = target_power_w / simulated_power_w
normalized_sar = raw_sar * normalization_factor
Near-field: Uses target_power_mW from antenna config Far-field: Uses 1.0 (already normalized during simulation)
Caching mechanism¶
Processed results are cached to avoid re-processing:
- Cache location:
results/<study_type>/<phantom>/aggregated_results.pkl - Cache contents: Dictionary with
{"summary_results": results_df, "organ_results": all_organ_results_df} - Cache invalidation: Manual deletion or set
load_data: true
Usage:
# Skip data loading, use cache
analysis_config = {"load_data": False}
strategy = NearFieldAnalysisStrategy(config, phantom_name, analysis_config)
Error handling¶
The analysis system handles missing files gracefully:
- Missing result files: Logs warning, skips simulation
- Invalid data: Logs error, continues with available data
- Plot generation errors: Logs error, continues with other plots
Performance considerations¶
- Caching: Use
load_data: falsefor re-plotting (10-100x faster) - Plot selection: Disable unused plots in config to save time
- DataFrame operations: Uses pandas for efficient data manipulation
- Plot generation: Parallel plot generation not implemented (sequential)
Testing¶
Analysis components are tested in tests/test_analysis_*.py:
- Strategy implementations (
test_analysis_strategies.py) - Analyzer class (
test_analysis_analyzer.py) - Base strategy interface (
test_analysis_base_strategy.py) - CLI integration (
test_cli_run_analysis.py)
Run tests: