from __future__ import annotations
import os
import time
from typing import Callable
import numpy as np
import brahe as bh
DEFAULT_ISS_TLE_LINE1 = (
"1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 0 2927"
)
DEFAULT_ISS_TLE_LINE2 = (
"2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537"
)
def setup_providers() -> None:
bh.initialize_eop()
bh.initialize_sw()
def default_leo_state() -> tuple[bh.Epoch, np.ndarray]:
epoch = bh.Epoch.from_datetime(2024, 1, 1, 0, 0, 0.0, 0.0, bh.TimeSystem.UTC)
oe = np.array([bh.R_EARTH + 500e3, 0.01, 97.8, 15.0, 30.0, 45.0])
state = bh.state_koe_to_eci(oe, bh.AngleFormat.DEGREES)
return epoch, state
def duration_from_env(default: float = 10.0) -> float:
raw = os.environ.get("PROFILE_DURATION_S")
if raw is None:
return default
try:
return float(raw)
except ValueError:
return default
def run_until_elapsed(duration_s: float, body: Callable[[], None]) -> int:
deadline = time.perf_counter() + duration_s
iters = 0
while time.perf_counter() < deadline:
body()
iters += 1
return iters