Skip to content

Commit

Permalink
Refactor two-body state vector representation and expose from Python (#…
Browse files Browse the repository at this point in the history
…46)

* Prototype exposing two-body states

* Refactor two body state vector representations

* Move time field into state

* Refactor some more

* Add Python type hints

* Use explicit methods

* Add Python example

* More tests

* Re-add TwoBody trait

* Add Python smoke tests and PyO3 unit test

* Test Python time wrapper

* Test Python frames wrapper

* Test Sun and barycenters

* Test planets

* Test all bodies

* Test PyBody

* Re-introduce `two_body` module and more tests

* Add anomaly tests
  • Loading branch information
helgee authored Jan 24, 2024
1 parent 2a34f4e commit 4688f40
Show file tree
Hide file tree
Showing 30 changed files with 2,183 additions and 1,053 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ jobs:
- name: Run tests
run: cargo test

python:
name: Python smoke tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Generate virtual environment
run: python -m venv .venv
- name: Build Python wrapper
uses: PyO3/maturin-action@v1
with:
command: develop
working-directory: ./crates/lox_py
args: --extras dev
- name: Run test
run: |
source .venv/bin/activate
pytest crates/lox_py/tests
fmt:
name: Rustfmt
runs-on: ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions .idea/lox-space.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 32 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ authors = ["Helge Eichhorn and the lox-space contributors"]

[workspace.dependencies]
lox_core = { path = "./crates/lox_core" }
float_eq = "1.0.1"
proptest = "1.4.0"
rstest = "0.18.2"
thiserror = "1.0"

15 changes: 8 additions & 7 deletions crates/lox-space/examples/iss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ fn main() {
let epoch = Epoch::from_date_and_time(TimeScale::TDB, date, time);
let position = DVec3::new(6068279.27, -1692843.94, -2516619.18) * 1e-3;
let velocity = DVec3::new(-660.415582, 5495.938726, -5303.093233) * 1e-3;
let iss = Cartesian::new(epoch, Earth, position, velocity);
let iss_cartesian = Cartesian::new(epoch, Earth, Icrf, position, velocity);
let iss = Keplerian::from(iss_cartesian);

println!(
"ISS Orbit for Julian Day {}",
iss.epoch().days_since_j2000(),
);
println!("ISS Orbit for Julian Day {}", iss.time().days_since_j2000(),);
println!("=============================");
println!("Semi-major axis: {:.3} km", iss.semi_major());
println!("Semi-major axis: {:.3} km", iss.semi_major_axis());
println!("Eccentricity: {:.6}", iss.eccentricity());
println!("Inclination: {:.3}°", iss.inclination().to_degrees());
println!(
"Longitude of ascending node: {:.3}°",
iss.ascending_node().to_degrees()
);
println!("Argument of perigee: {}°", iss.periapsis_arg().to_degrees());
println!(
"Argument of perigee: {}°",
iss.periapsis_argument().to_degrees()
);
println!("True anomaly: {:.3}°", iss.true_anomaly().to_degrees());
}
6 changes: 3 additions & 3 deletions crates/lox-space/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

pub use lox_core::bodies::*;

pub use lox_core::coords::two_body::{Cartesian, Keplerian};
pub use lox_core::coords::DVec3;
pub use lox_core::frames::*;
pub use lox_core::time::dates::*;
pub use lox_core::time::epochs::*;

pub use lox_core::two_body::{Cartesian, DVec3, Keplerian, TwoBody};
13 changes: 7 additions & 6 deletions crates/lox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ version = "0.1.0"
edition = "2021"

[dependencies]
float_eq = "1.0.1"
glam = "0.24.2"
num = "0.4.0"
float_eq.workspace = true
thiserror.workspace = true
glam = "0.25.0"
num = "0.4.1"
nom = "7.1.3"
fast_polynomial = "0.1.0"
dyn-clone = "1.0.16"

[dev-dependencies]
proptest = "1.1.0"
rstest = "0.18.2"
divan = "0.1.2"
proptest.workspace = true
rstest.workspace = true
divan = "0.1.11"

[[bench]]
name = "iau_frames"
Expand Down
Loading

0 comments on commit 4688f40

Please sign in to comment.