This page will walk you through setting up your environment and writing your first Brahe script. All subsequent examples in the getting started guide and documentation will assume you are using this same environment setup.
For python, we will assume you are using uv as your package manager and environment tool. If you haven't already installed it, you can so from their instructions here.
Rust is building native support for running single-file scripts with "cargo script" in an upcoming release (tracking issue). Once this is available we will migrate over to using the native cargo support and remove the rust-script dependency.
To use Brahe in a script, we need to declare it as a dependency of the script so that it is properly imported when we run the script. To do this you can use the following preamble at the top of your script file:
Now we can write your first script. We'll use Brahe to predict the next time the International Space Station (ISS) will be in view of NASA Johnson Space Center (JSC) in Houston, TX.
To do this, we need to import brahe, download the latest ephemeris information for the ISS, and then use that information to predict the next pass of the ISS over JSC, and print the results.
To do this, add the following code to your script after the preamble:
importbraheasbh# Initialize EOPbh.initialize_eop()# Set the locationlocation=bh.PointLocation(-122.4194,# Longitude [deg]37.7749,# Latitude [deg]0.0# Altitude [m]).with_name("San Francisco")# Get the latest TLE for the ISS (NORAD ID 25544) from Celestrakclient=bh.celestrak.CelestrakClient()propagator=client.get_sgp_propagator(catnr=25544,step_size=60.0)# Configure Search Windowepoch_start=bh.Epoch.now()epoch_end=epoch_start+7*86400.0# 7 days later# Set access constraints -> Must be above 10 degrees elevationconstraint=bh.ElevationConstraint(min_elevation_deg=10.0)# Compute access windowswindows=bh.location_accesses(location,propagator,epoch_start,epoch_end,constraint)# Print first 3 access windowsforwindowinwindows[:3]:print(f"Access Window: {window.window_open} to {window.window_close}, Duration: {window.duration/60:.2f} minutes")
Save this file as first_script.py and you can run it with:
#[allow(unused_imports)]usebraheasbh;usebrahe::utils::Identifiable;fnmain(){// Initialize EOPbh::initialize_eop().unwrap();// Set the locationletlocation=bh::PointLocation::new(-122.4194,// Longitude [deg]37.7749,// Latitude [deg]0.0// Altitude [m]).with_name("San Francisco");// Get the latest TLE for the ISS (NORAD ID 25544) from Celestrakletclient=bh::celestrak::CelestrakClient::new();letpropagator=client.get_sgp_propagator_by_catnr(25544,60.0).unwrap();// Configure Search Windowletepoch_start=bh::Epoch::now();letepoch_end=epoch_start+7.0*86400.0;// 7 days later// Set access constraints -> Must be above 10 degrees elevationletconstraint=bh::ElevationConstraint::new(Some(10.0),None).unwrap();// Compute access windowsletwindows=bh::location_accesses(&location,&propagator,epoch_start,epoch_end,&constraint,None,None,).unwrap();// Print first 3 access windowsforwindowinwindows.iter().take(3){println!("Access Window: {} to {}, Duration: {:.2} minutes",window.window_open,window.window_close,window.duration()/60.0);}}
Save this file as first_script.rs and you can run it with: