Skip to content

ENZ Frame

ENZ is the topocentric horizon frame with E pointing east, N north, and Z along the geodetic vertical. It is SEZ with its horizontal axes reordered, \(E_\mathrm{ENZ} = E_\mathrm{SEZ}\) and \(N_\mathrm{ENZ} = -S_\mathrm{SEZ}\), and its functions take the same ECEF site and target states.

import numpy as np

import brahe as bh

bh.initialize_eop()

r_gs = bh.position_geodetic_to_ecef(
    np.array([30.0, 45.0, 500.0]), bh.AngleFormat.DEGREES
)
x_gs = np.concatenate([r_gs, np.zeros(3)])

oe = np.array([bh.R_EARTH + 700e3, 0.01, 97.8, 15.0, 30.0, 105.0])
x_eci = bh.state_koe_to_eci(oe, bh.AngleFormat.DEGREES)
epc = bh.Epoch.from_datetime(2024, 3, 1, 0, 0, 0.0, 0.0, bh.UTC)
x_sat = bh.state_gcrf_to_itrf(epc, x_eci)

x_rel_enz = bh.state_ecef_to_enz(x_gs, x_sat)
azel = bh.position_enz_to_azel(x_rel_enz[:3], bh.AngleFormat.DEGREES)
print(f"Azimuth: {azel[0]:.3f} deg, Elevation: {azel[1]:.3f} deg")

x_rel_sez = bh.state_ecef_to_sez(x_gs, x_sat)
is_sez_permutation = (
    x_rel_enz[0] == x_rel_sez[1]
    and x_rel_enz[1] == -x_rel_sez[0]
    and x_rel_enz[2] == x_rel_sez[2]
)
print("ENZ columns are the SEZ permutation (E=E, N=-S, Z=Z):", is_sez_permutation)

x_aircraft = np.concatenate([r_gs, np.array([-120.0, 180.0, 90.0])])
omega_enz = bh.omega_enz(x_aircraft)
omega_sez = bh.omega_sez(x_aircraft)
omega_permuted = np.array([omega_sez[1], -omega_sez[0], omega_sez[2]])
print(
    "Moving site omega_enz matches the permuted SEZ rate:",
    np.linalg.norm(omega_enz - omega_permuted) < 1e-15,
)

bh.register_object("GS", lambda epoch: x_gs, bh.CelestialFrame.ITRF)
rel_graph = bh.state_frame_to_frame(
    bh.CelestialFrame.ITRF, bh.ReferenceFrame.ENZ("GS"), epc, x_sat
)
print(
    "Frame graph matches state_ecef_to_enz:",
    np.linalg.norm(rel_graph - x_rel_enz) < 1e-6,
)
bh.clear_object_registry()
use brahe as bh;
use brahe::frames::{CelestialFrame, ReferenceFrame};
use brahe::time::{Epoch, TimeSystem};
use brahe::utils::BraheError;
use brahe::utils::state_providers::SStateProvider;
use nalgebra::{Vector3, Vector6};

/// A state provider returning a fixed state at every epoch, for registering
/// the ground station as an object.
struct ConstantProvider(Vector6<f64>);
impl SStateProvider for ConstantProvider {
    fn state(&self, _epoch: Epoch) -> Result<Vector6<f64>, BraheError> {
        Ok(self.0)
    }
}

fn main() {
    bh::initialize_eop().unwrap();

    let r_gs =
        bh::position_geodetic_to_ecef(Vector3::new(30.0, 45.0, 500.0), bh::AngleFormat::Degrees)
            .unwrap();
    let x_gs = Vector6::new(r_gs[0], r_gs[1], r_gs[2], 0.0, 0.0, 0.0);

    let oe = Vector6::new(bh::R_EARTH + 700e3, 0.01, 97.8, 15.0, 30.0, 105.0);
    let x_eci = bh::state_koe_to_eci(oe, bh::AngleFormat::Degrees);
    let epc = Epoch::from_datetime(2024, 3, 1, 0, 0, 0.0, 0.0, TimeSystem::UTC);
    let x_sat = bh::state_gcrf_to_itrf(epc, x_eci);

    let x_rel_enz = bh::state_ecef_to_enz(x_gs, x_sat);
    let azel = bh::position_enz_to_azel(
        x_rel_enz.fixed_rows::<3>(0).into_owned(),
        bh::AngleFormat::Degrees,
    );
    println!("Azimuth: {:.3} deg, Elevation: {:.3} deg", azel[0], azel[1]);

    let x_rel_sez = bh::state_ecef_to_sez(x_gs, x_sat);
    let is_sez_permutation = x_rel_enz[0] == x_rel_sez[1]
        && x_rel_enz[1] == -x_rel_sez[0]
        && x_rel_enz[2] == x_rel_sez[2];
    println!(
        "ENZ columns are the SEZ permutation (E=E, N=-S, Z=Z): {}",
        is_sez_permutation
    );

    let x_aircraft = Vector6::new(r_gs[0], r_gs[1], r_gs[2], -120.0, 180.0, 90.0);
    let omega_enz = bh::omega_enz(x_aircraft);
    let omega_sez = bh::omega_sez(x_aircraft);
    let omega_permuted = Vector3::new(omega_sez[1], -omega_sez[0], omega_sez[2]);
    println!(
        "Moving site omega_enz matches the permuted SEZ rate: {}",
        (omega_enz - omega_permuted).norm() < 1e-15
    );

    bh::register_object("GS", ConstantProvider(x_gs), CelestialFrame::ITRF).unwrap();
    let rel_graph =
        bh::state_frame_to_frame(CelestialFrame::ITRF, ReferenceFrame::ENZ("GS"), epc, x_sat)
            .unwrap();
    println!(
        "Frame graph matches state_ecef_to_enz: {}",
        (rel_graph - x_rel_enz).norm() < 1e-6
    );
    bh::clear_object_registry();
}
Output
1
2
3
4
Azimuth: 94.481 deg, Elevation: 27.511 deg
ENZ columns are the SEZ permutation (E=E, N=-S, Z=Z): True
Moving site omega_enz matches the permuted SEZ rate: True
Frame graph matches state_ecef_to_enz: True
1
2
3
4
Azimuth: 94.481 deg, Elevation: 27.511 deg
ENZ columns are the SEZ permutation (E=E, N=-S, Z=Z): true
Moving site omega_enz matches the permuted SEZ rate: true
Frame graph matches state_ecef_to_enz: true

See Also