Skip to content

Package Conventions

There are a few common conventions that are useful to know when working with Brahe.

Vector Types

In Python, Brahe uses array-like types (lists, tuples, numpy arrays, etc.) as inputs for vector quantities (e.g. position, velocity, etc.) and returns numpy arrays as outputs for vector quantities. In Rust, Brahe uses nalgebra arrays for both inputs and outputs of vector quantities.

import brahe as bh
import numpy as np

# Brahe inputs can be python lists
list_input = [-122.41, 37.77, 16.0]
ecef_list = bh.position_geodetic_to_ecef(list_input, bh.AngleFormat.DEGREES)

# It can also be numpy arrays
array_input = np.array([-122.41, 37.77, 16.0])
ecef_array = bh.position_geodetic_to_ecef(array_input, bh.AngleFormat.DEGREES)

# Any array-like (python set, tuple, etc.) will work as well
tuple_input = (-122.41, 37.77, 16.0)
ecef_tuple = bh.position_geodetic_to_ecef(tuple_input, bh.AngleFormat.DEGREES)

print(f'ECEF from list: {ecef_list}')
print(f'ECEF from array: {ecef_array}')
print(f'ECEF from tuple: {ecef_tuple}')

# The output of Brahe functions that return vectors is always a numpy array
print(f'Type of ECEF output: {type(ecef_list)}')
print(f'Type of ECEF output: {type(ecef_array)}')
#[allow(unused_imports)]
use brahe as bh;
use nalgebra as na;

fn main() {
    // In rust inputs must be nalgebra arrays
    let array_input = na::Vector3::new(-122.41, 37.77, 16.0);
    let ecef_array = bh::position_geodetic_to_ecef(array_input, bh::AngleFormat::Degrees);

    // println!("ECEF from vec: {:?}", ecef_vec);
    println!("ECEF from array: {:?}", ecef_array);

    // The output of Brahe functions that return vectors is always a nalgebra array
    println!("Type of ECEF output: {}", std::any::type_name_of_val(&ecef_array));
}
Output
1
2
3
4
5
ECEF from list: [-2705661.06457674 -4261795.32689662  3885305.39466925]
ECEF from array: [-2705661.06457674 -4261795.32689662  3885305.39466925]
ECEF from tuple: [-2705661.06457674 -4261795.32689662  3885305.39466925]
Type of ECEF output: <class 'numpy.ndarray'>
Type of ECEF output: <class 'numpy.ndarray'>
ECEF from array: Ok([[-2705661.0645767376, -4261795.326896624, 3885305.394669255]])
Type of ECEF output: core::result::Result<nalgebra::base::matrix::Matrix<f64, nalgebra::base::dimension::Const<3>, nalgebra::base::dimension::Const<1>, nalgebra::base::array_storage::ArrayStorage<f64, 3, 1>>, alloc::string::String>

SI Units

Brahe uses SI base units (meters, seconds, kilograms, etc.) for all inputs and outputs of physical quantities unless otherwise specified. This is to remove any ambiguity about the units of inputs and outputs, and to make it easier to work with the library and chain together different functions without needing to worry about unit conversions.

It is the responsibility of the user to ensure that the inputs to Brahe functions are in the correct units, and to convert the outputs of Brahe functions to the desired units if needed.

Angle Format

For functions that deal with angular quantities for either inputs or outputs, Brahe provides the AngleFormat enum to specify the format of the angles. Given the frequency of working with different angle formats this makes it easy to work with different formats without needing to manually convert before or after calling Brahe functions.