Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various cleaning up -> version 0.5.2 #368

Merged
merged 5 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["anise", "anise-cli", "anise-gui", "anise-py"]

[workspace.package]
version = "0.5.1"
version = "0.5.2"
edition = "2021"
authors = ["Christopher Rabotin <christopher.rabotin@gmail.com>"]
description = "ANISE provides a toolkit and files for Attitude, Navigation, Instrument, Spacecraft, and Ephemeris data. It's a modern replacement of NAIF SPICE file."
Expand Down Expand Up @@ -45,7 +45,7 @@ pyo3-log = "0.12"
numpy = "0.23"
ndarray = ">= 0.15, < 0.17"

anise = { version = "0.5.1", path = "anise", default-features = false }
anise = { version = "0.5.2", path = "anise", default-features = false }

[profile.bench]
debug = true
Expand Down
8 changes: 4 additions & 4 deletions anise-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ hifitime = { workspace = true }
log = { workspace = true }
bytes = { workspace = true }
pretty_env_logger = { workspace = true }
eframe = { version = "0.29" }
egui = { version = "0.29" }
egui_extras = { version = "0.29", features = ["datepicker", "http", "image"] }
eframe = { version = "0.30" }
egui = { version = "0.30" }
egui_extras = { version = "0.30", features = ["datepicker", "http", "image"] }
rfd = { version = "0.15.0" }
egui_logger = "0.6.1"
egui_logger = "0.6.2"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/metaload/metaalmanac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl Default for MetaAlmanac {
.join("v0.5/moon_fk_de440.epa")
.unwrap()
.to_string(),
crc32: Some(0x6f0ad74c),
crc32: Some(0x21633903),
},
MetaFile {
uri: nyx_cloud_stor
Expand Down
4 changes: 2 additions & 2 deletions anise/src/almanac/metaload/metafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl MetaFile {
self.uri = dest_path_s;
return Ok(());
} else {
info!("Discarding cached {dest_path_s} - CRC32 differ (got {computed_crc32:x}, expected {crc32:x})");
info!("Discarding cached {dest_path_s} - CRC32 differ (got 0x{computed_crc32:x}, expected 0x{crc32:x})");
}
}
}
Expand Down Expand Up @@ -206,7 +206,7 @@ impl MetaFile {
file.write_all(&bytes).unwrap();

info!(
"Saved {url} to {} (CRC32 = {crc32:x})",
"Saved {url} to {} (CRC32 = 0x{crc32:x})",
dest_path.to_str().unwrap()
);

Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/metaload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mod meta_test {
, { crc32 = Some 0x8213b6e9
, uri = "http://public-data.nyxspace.com/anise/v0.5/pck11.pca"
}
, { crc32 = Some 0x6f0ad74c
, { crc32 = Some 0x21633903
, uri = "http://public-data.nyxspace.com/anise/v0.5/moon_fk_de440.epa"
}
, { crc32 = Some 0xcde5ca7d
Expand Down
106 changes: 56 additions & 50 deletions anise/src/astro/orbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ impl Orbit {
/// One should expect these errors to be on the order of 1e-12.
#[allow(clippy::too_many_arguments)]
pub fn try_keplerian(
sma: f64,
sma_km: f64,
ecc: f64,
inc: f64,
raan: f64,
aop: f64,
ta: f64,
inc_deg: f64,
raan_deg: f64,
aop_deg: f64,
ta_deg: f64,
epoch: Epoch,
frame: Frame,
) -> PhysicsResult<Self> {
Expand All @@ -74,14 +74,14 @@ impl Orbit {
} else {
ecc
};
let sma = if ecc > 1.0 && sma > 0.0 {
let sma = if ecc > 1.0 && sma_km > 0.0 {
warn!("eccentricity > 1 (hyperbolic) BUT SMA > 0 (elliptical): sign of SMA changed");
sma * -1.0
} else if ecc < 1.0 && sma < 0.0 {
sma_km * -1.0
} else if ecc < 1.0 && sma_km < 0.0 {
warn!("eccentricity < 1 (elliptical) BUT SMA < 0 (hyperbolic): sign of SMA changed");
sma * -1.0
sma_km * -1.0
} else {
sma
sma_km
};
if (sma * (1.0 - ecc)).abs() < 1e-3 {
// GMAT errors below one meter. Let's warn for below that, but not panic, might be useful for landing scenarios?
Expand All @@ -92,14 +92,14 @@ impl Orbit {
ParabolicEccentricitySnafu { limit: ECC_EPSILON }
);
if ecc > 1.0 {
let ta_deg = between_0_360(ta);
let ta_deg = between_0_360(ta_deg);
ensure!(
ta_deg <= (PI - (1.0 / ecc).acos()).to_degrees(),
HyperbolicTrueAnomalySnafu { ta_deg }
);
}
ensure!(
(1.0 + ecc * ta.to_radians().cos()).is_finite(),
(1.0 + ecc * ta_deg.to_radians().cos()).is_finite(),
InfiniteValueSnafu {
action: "computing radius of orbit"
}
Expand All @@ -109,28 +109,28 @@ impl Orbit {
// The conversion algorithm itself comes from GMAT's StateConversionUtil::ComputeKeplToCart
// NOTE: GMAT supports mean anomaly instead of true anomaly, but only for backward compatibility reasons
// so it isn't supported here.
let inc = inc.to_radians();
let raan = raan.to_radians();
let aop = aop.to_radians();
let ta = ta.to_radians();
let p = sma * (1.0 - ecc.powi(2));
let inc_rad = inc_deg.to_radians();
let raan_rad = raan_deg.to_radians();
let aop_rad = aop_deg.to_radians();
let ta_rad = ta_deg.to_radians();
let p_km = sma * (1.0 - ecc.powi(2));

ensure!(p.abs() >= f64::EPSILON, ParabolicSemiParamSnafu { p });
ensure!(p_km.abs() >= f64::EPSILON, ParabolicSemiParamSnafu { p_km });

// NOTE: At this point GMAT computes 1+ecc**2 and checks whether it's very small.
// It then reports that the radius may be too large. We've effectively already done
// this check above (and panicked if needed), so it isn't repeated here.
let radius = p / (1.0 + ecc * ta.cos());
let (sin_aop_ta, cos_aop_ta) = (aop + ta).sin_cos();
let (sin_inc, cos_inc) = inc.sin_cos();
let (sin_raan, cos_raan) = raan.sin_cos();
let (sin_aop, cos_aop) = aop.sin_cos();
let radius = p_km / (1.0 + ecc * ta_rad.cos());
let (sin_aop_ta, cos_aop_ta) = (aop_rad + ta_rad).sin_cos();
let (sin_inc, cos_inc) = inc_rad.sin_cos();
let (sin_raan, cos_raan) = raan_rad.sin_cos();
let (sin_aop, cos_aop) = aop_rad.sin_cos();
let x = radius * (cos_aop_ta * cos_raan - cos_inc * sin_aop_ta * sin_raan);
let y = radius * (cos_aop_ta * sin_raan + cos_inc * sin_aop_ta * cos_raan);
let z = radius * sin_aop_ta * sin_inc;
let sqrt_gm_p = (mu_km3_s2 / p).sqrt();
let cos_ta_ecc = ta.cos() + ecc;
let sin_ta = ta.sin();
let sqrt_gm_p = (mu_km3_s2 / p_km).sqrt();
let cos_ta_ecc = ta_rad.cos() + ecc;
let sin_ta = ta_rad.sin();

let vx = sqrt_gm_p * cos_ta_ecc * (-sin_aop * cos_raan - cos_inc * sin_raan * cos_aop)
- sqrt_gm_p * sin_ta * (cos_aop * cos_raan - cos_inc * sin_raan * sin_aop);
Expand All @@ -149,31 +149,31 @@ impl Orbit {
/// Attempts to create a new Orbit from the provided radii of apoapsis and periapsis, in kilometers
#[allow(clippy::too_many_arguments)]
pub fn try_keplerian_apsis_radii(
r_a: f64,
r_p: f64,
inc: f64,
raan: f64,
aop: f64,
ta: f64,
r_a_km: f64,
r_p_km: f64,
inc_deg: f64,
raan_deg: f64,
aop_deg: f64,
ta_deg: f64,
epoch: Epoch,
frame: Frame,
) -> PhysicsResult<Self> {
ensure!(
r_a > f64::EPSILON,
r_a_km > f64::EPSILON,
RadiusSnafu {
action: "radius of apoapsis is negative"
}
);
ensure!(
r_p > f64::EPSILON,
r_p_km > f64::EPSILON,
RadiusSnafu {
action: "radius of periapsis is negative"
}
);
// The two checks above ensure that sma > 0
let sma = (r_a + r_p) / 2.0;
let ecc = r_a / sma - 1.0;
Self::try_keplerian(sma, ecc, inc, raan, aop, ta, epoch, frame)
let sma = (r_a_km + r_p_km) / 2.0;
let ecc = r_a_km / sma - 1.0;
Self::try_keplerian(sma, ecc, inc_deg, raan_deg, aop_deg, ta_deg, epoch, frame)
}

/// Attempts to create a new Orbit around the provided frame from the borrowed state vector
Expand All @@ -196,31 +196,37 @@ impl Orbit {
/// One should expect these errors to be on the order of 1e-12.
#[allow(clippy::too_many_arguments)]
pub fn keplerian(
sma: f64,
sma_km: f64,
ecc: f64,
inc: f64,
raan: f64,
aop: f64,
ta: f64,
inc_deg: f64,
raan_deg: f64,
aop_deg: f64,
ta_deg: f64,
epoch: Epoch,
frame: Frame,
) -> Self {
Self::try_keplerian(sma, ecc, inc, raan, aop, ta, epoch, frame).unwrap()
Self::try_keplerian(
sma_km, ecc, inc_deg, raan_deg, aop_deg, ta_deg, epoch, frame,
)
.unwrap()
}

/// Creates a new Orbit from the provided radii of apoapsis and periapsis, in kilometers
#[allow(clippy::too_many_arguments)]
pub fn keplerian_apsis_radii(
r_a: f64,
r_p: f64,
inc: f64,
raan: f64,
aop: f64,
ta: f64,
r_a_km: f64,
r_p_km: f64,
inc_deg: f64,
raan_deg: f64,
aop_deg: f64,
ta_deg: f64,
epoch: Epoch,
frame: Frame,
) -> Self {
Self::try_keplerian_apsis_radii(r_a, r_p, inc, raan, aop, ta, epoch, frame).unwrap()
Self::try_keplerian_apsis_radii(
r_a_km, r_p_km, inc_deg, raan_deg, aop_deg, ta_deg, epoch, frame,
)
.unwrap()
}

/// Initializes a new orbit from the Keplerian orbital elements using the mean anomaly instead of the true anomaly.
Expand Down
4 changes: 2 additions & 2 deletions anise/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ pub enum PhysicsError {
},
#[snafu(display("parabolic orbits are physically impossible and the eccentricity calculated to be within {limit:e} of 1.0"))]
ParabolicEccentricity { limit: f64 },
#[snafu(display("parabolic orbits are physically impossible and the semilatus rectum (semi-parameter) calculated to be {p}"))]
ParabolicSemiParam { p: f64 },
#[snafu(display("parabolic orbits are physically impossible and the semilatus rectum (semi-parameter) calculated to be {p_km} km"))]
ParabolicSemiParam { p_km: f64 },
#[snafu(display("hyperbolic true anomaly is physically impossible: {ta_deg} deg"))]
HyperbolicTrueAnomaly { ta_deg: f64 },
#[snafu(display("calculation requires hyperbolic orbit, but its eccentricity is {ecc}"))]
Expand Down
7 changes: 3 additions & 4 deletions anise/src/frames/frameuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Documentation: https://nyxspace.com/
*/

use serde::{Deserialize, Serialize};

use crate::{
constants::{
celestial_objects::celestial_name_from_id, orientations::orientation_name_from_id,
Expand All @@ -20,10 +22,7 @@ pub use super::Frame;

/// A unique frame reference that only contains enough information to build the actual Frame object.
/// It cannot be used for any computations, is it be used in any structure apart from error structures.
///
/// # Usage note
/// You should almost always prefer Frame over FrameRef unless you will
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct FrameUid {
pub ephemeris_id: NaifId,
pub orientation_id: NaifId,
Expand Down
3 changes: 2 additions & 1 deletion anise/src/math/rotation/quaternion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use core::fmt;
use core::ops::Mul;
use der::{Decode, Encode, Reader, Writer};
use nalgebra::Matrix4x3;
use serde::{Deserialize, Serialize};
use snafu::ensure;

use super::EPSILON_RAD;
Expand Down Expand Up @@ -54,7 +55,7 @@ pub type Quaternion = EulerParameter;
///
/// # Usage
/// Importantly, ANISE prevents the composition of two Euler Parameters if the frames do not match.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct EulerParameter {
pub w: f64,
pub x: f64,
Expand Down
4 changes: 0 additions & 4 deletions anise/src/structure/dataset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ mod dataset_ut {
fn spacecraft_constants_lookup() {
// Build some data first.
let full_sc = SpacecraftData {
name: "full spacecraft".try_into().unwrap(),
srp_data: Some(SRPData {
area_m2: 2.0,
coeff_reflectivity: 1.8,
Expand All @@ -563,7 +562,6 @@ mod dataset_ut {
drag_data: Some(DragData::default()),
};
let srp_sc = SpacecraftData {
name: "SRP only spacecraft".try_into().unwrap(),
srp_data: Some(SRPData::default()),
..Default::default()
};
Expand Down Expand Up @@ -690,7 +688,6 @@ mod dataset_ut {
fn spacecraft_constants_lookup_builder() {
// Build some data first.
let full_sc = SpacecraftData {
name: "full spacecraft".try_into().unwrap(),
srp_data: Some(SRPData {
area_m2: 2.0,
coeff_reflectivity: 1.8,
Expand All @@ -708,7 +705,6 @@ mod dataset_ut {
drag_data: Some(DragData::default()),
};
let srp_sc = SpacecraftData {
name: "SRP only spacecraft".try_into().unwrap(),
srp_data: Some(SRPData::default()),
..Default::default()
};
Expand Down
3 changes: 2 additions & 1 deletion anise/src/structure/spacecraft/drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
* Documentation: https://nyxspace.com/
*/
use der::{Decode, Encode, Reader, Writer};
use serde_derive::{Deserialize, Serialize};

#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct DragData {
/// Atmospheric drag area in m^2
pub area_m2: f64,
Expand Down
3 changes: 2 additions & 1 deletion anise/src/structure/spacecraft/inertia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
*/
use der::{Decode, Encode, Reader, Writer};
use nalgebra::Matrix3;
use serde_derive::{Deserialize, Serialize};

use crate::NaifId;

/// Inertial tensor definition
#[derive(Copy, Clone, Debug, Default, PartialEq)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Inertia {
/// Inertia tensor reference frame hash
pub orientation_id: NaifId,
Expand Down
Loading
Loading