"""
GMAT Python API Integration for high-fidelity truth propagation.
"""
from typing import Any, Dict, List, Optional
import numpy as np
from opengnc.interfaces.base import ExternalPropagator
try:
import gmatpy as gmat
GMAT_AVAILABLE = True
except ImportError:
GMAT_AVAILABLE = False
[docs]
class GMATInterface(ExternalPropagator):
"""
Standardized interface for the NASA GMAT Python API.
Used for truth propagation and mission analysis.
"""
def __init__(self) -> None:
self.connected = False
if GMAT_AVAILABLE:
self.connect()
[docs]
def connect(self, **kwargs: Any) -> bool:
"""Initialize GMAT engine."""
if not GMAT_AVAILABLE:
return False
# GMAT setup logic...
self.connected = True
return True
[docs]
def disconnect(self) -> None:
"""Release GMAT resources."""
self.connected = False
[docs]
def propagate(
self,
initial_state: np.ndarray,
start_jd: float,
duration_sec: float,
step_sec: float,
) -> Dict[str, np.ndarray]:
"""
Run high-fidelity propagation using GMAT.
Returns
-------
Dict[str, np.ndarray]
'times' and 'states' arrays.
"""
if not self.connected:
raise RuntimeError("GMAT not connected. Check GMAT installation and environment.")
# Placeholder for GMAT object orchestration:
# 1. Create Spacecraft
# 2. Set State (Cartesian)
# 3. Create Propagator (JGM-2/3, Gravity, Drag, SRP)
# 4. Run Mission
# 5. Retrieve Data
print(f"Propagating {duration_sec}s with GMAT...")
# Since I cannot execute GMAT here, this is the standardized API skeleton
num_steps = int(duration_sec / step_sec) + 1
times = np.linspace(start_jd, start_jd + duration_sec / 86400.0, num_steps)
# Mocking output for now:
states = np.tile(initial_state, (num_steps, 1))
return {"times": times, "states": states}
[docs]
def setup_force_model(self, gravity_deg: int = 20, drag: bool = True) -> None:
"""Configure GMAT force model."""
if not self.connected:
return
# GMAT ForceModel implementation
pass