Skip to content

Commit

Permalink
Merge pull request #369 from nyx-space/feat/serde-bis
Browse files Browse the repository at this point in the history
Additional fixes for version 0.5.2
  • Loading branch information
ChristopherRabotin authored Dec 30, 2024
2 parents 1af2fe6 + a38aaf4 commit 3fe4183
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 124 deletions.
8 changes: 5 additions & 3 deletions anise/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ndarray = { workspace = true, optional = true }
url = { version = "2.5.0", optional = true }
serde = "1"
serde_derive = "1"
serde_dhall = { version = "0.12", optional = true }
serde_dhall = { version = "0.12", optional = true, default-features = false }
reqwest = { version = "0.12.0", optional = true, features = ["blocking"] }
platform-dirs = { version = "0.3.0", optional = true }
tabled = { workspace = true }
Expand All @@ -53,10 +53,12 @@ rstest = { workspace = true }
approx = "0.5.1"
polars = { version = "0.45.1", features = ["lazy", "parquet"] }
rayon = "1.7"
serde_yaml = "0.9.30"
serde_yml = "0.0.12"

[build-dependencies]
reqwest = { version = "0.12", features = ["blocking"], optional = true }
reqwest = { version = "0.12", features = [
"blocking",
], optional = true, default-features = false }

[features]
default = ["metaload"]
Expand Down
4 changes: 4 additions & 0 deletions anise/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,7 @@ ANISE is heavily inspired by the NAIF SPICE toolkit and its excellent documentat
## Contact

For any inquiries, feedback, or discussions, please [open an issue here](https://github.com/nyx-space/anise/issues) or contact the maintainer at [email protected].

## Versioning

ANISE abides by the Rust versioning rules for dependencies but not necessarily for dev-dependencies. Please open a ticket if this causes an issue.
4 changes: 2 additions & 2 deletions anise/src/math/cartesian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ mod cartesian_state_ut {
let frame = EARTH_J2000;
let state = CartesianState::new(10.0, 20.0, 30.0, 1.0, 2.0, 2.0, e, frame);

let serialized = serde_yaml::to_string(&state).unwrap();
let rtn: CartesianState = serde_yaml::from_str(&serialized).unwrap();
let serialized = serde_yml::to_string(&state).unwrap();
let rtn: CartesianState = serde_yml::from_str(&serialized).unwrap();

assert_eq!(rtn, state);
}
Expand Down
6 changes: 2 additions & 4 deletions anise/src/orientations/rotate_to_parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ impl Almanac {
// Not available as a BPC, so let's see if there's planetary data for it.
match self.planetary_data.get_by_id(source.orientation_id) {
Ok(planetary_data) => {
println!(
"query {source} wrt to its parent @ {epoch:E} using planetary data"
);
trace!("query {source} wrt to its parent @ {epoch:E} using planetary data");
// Fetch the parent info
let system_data =
match self.planetary_data.get_by_id(planetary_data.parent_id) {
Expand All @@ -121,7 +119,7 @@ impl Almanac {
.context(OrientationPhysicsSnafu)
}
Err(_) => {
println!("query {source} wrt to its parent @ {epoch:E} using Euler parameter data");
trace!("query {source} wrt to its parent @ {epoch:E} using Euler parameter data");
// Finally, let's see if it's in the loaded Euler Parameters.
// We can call `into` because EPs can be converted directly into DCMs.
Ok(self
Expand Down
54 changes: 27 additions & 27 deletions anise/src/structure/dataset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,14 @@ mod dataset_ut {
}),
inertia: Some(Inertia {
orientation_id: -20,
i_11_kgm2: 120.0,
i_22_kgm2: 180.0,
i_33_kgm2: 220.0,
i_12_kgm2: 20.0,
i_13_kgm2: -15.0,
i_23_kgm2: 30.0,
i_xx_kgm2: 120.0,
i_yy_kgm2: 180.0,
i_zz_kgm2: 220.0,
i_xy_kgm2: 20.0,
i_xz_kgm2: -15.0,
i_yz_kgm2: 30.0,
}),
mass_kg: Some(Mass::from_dry_and_fuel_masses(150.0, 50.6)),
mass: Some(Mass::from_dry_and_prop_masses(150.0, 50.6)),
drag_data: Some(DragData::default()),
};
let srp_sc = SpacecraftData {
Expand Down Expand Up @@ -598,10 +598,10 @@ mod dataset_ut {

// Build the lookup table
dataset
.push(srp_sc.clone(), Some(-20), Some("SRP spacecraft"))
.push(srp_sc, Some(-20), Some("SRP spacecraft"))
.unwrap();
dataset
.push(full_sc.clone(), Some(-50), Some("Full spacecraft"))
.push(full_sc, Some(-50), Some("Full spacecraft"))
.unwrap();

dataset.set_crc32();
Expand Down Expand Up @@ -633,7 +633,7 @@ mod dataset_ut {
// Grab a copy of the original data
let mut sc = dataset.get_by_name("SRP spacecraft").unwrap();
sc.srp_data.as_mut().unwrap().coeff_reflectivity = 1.1;
dataset.set_by_name("SRP spacecraft", sc.clone()).unwrap();
dataset.set_by_name("SRP spacecraft", sc).unwrap();
// Ensure that we've modified only that entry
assert_eq!(
dataset.get_by_name("Full spacecraft").unwrap(),
Expand All @@ -651,7 +651,7 @@ mod dataset_ut {
1.1,
"value was not modified"
);
assert!(dataset.set_by_name("Unavailable SC", sc.clone()).is_err());
assert!(dataset.set_by_name("Unavailable SC", sc).is_err());

// Test renaming by name
dataset
Expand Down Expand Up @@ -694,14 +694,14 @@ mod dataset_ut {
}),
inertia: Some(Inertia {
orientation_id: -20,
i_11_kgm2: 120.0,
i_22_kgm2: 180.0,
i_33_kgm2: 220.0,
i_12_kgm2: 20.0,
i_13_kgm2: -15.0,
i_23_kgm2: 30.0,
i_xx_kgm2: 120.0,
i_yy_kgm2: 180.0,
i_zz_kgm2: 220.0,
i_xy_kgm2: 20.0,
i_xz_kgm2: -15.0,
i_yz_kgm2: 30.0,
}),
mass_kg: Some(Mass::from_dry_and_fuel_masses(150.0, 50.6)),
mass: Some(Mass::from_dry_and_prop_masses(150.0, 50.6)),
drag_data: Some(DragData::default()),
};
let srp_sc = SpacecraftData {
Expand All @@ -713,19 +713,19 @@ mod dataset_ut {

let mut dataset = DataSet::<SpacecraftData, 16>::default();
dataset
.push(srp_sc.clone(), Some(-20), Some("SRP spacecraft"))
.push(srp_sc, Some(-20), Some("SRP spacecraft"))
.unwrap();

dataset
.push(full_sc.clone(), Some(-50), Some("Full spacecraft"))
.push(full_sc, Some(-50), Some("Full spacecraft"))
.unwrap();

// Pushing without name as ID -51
dataset.push(full_sc.clone(), Some(-51), None).unwrap();
dataset.push(full_sc, Some(-51), None).unwrap();

// Pushing without ID
dataset
.push(srp_sc.clone(), None, Some("ID less SRP spacecraft"))
.push(srp_sc, None, Some("ID less SRP spacecraft"))
.unwrap();

// Make sure to set the CRC32.
Expand Down Expand Up @@ -756,14 +756,14 @@ mod dataset_ut {

// Check that we can set by ID
let mut repr = dataset.get_by_id(-50).unwrap();
repr.mass_kg.as_mut().unwrap().dry_mass_kg = 100.5;
dataset.set_by_id(-50, repr.clone()).unwrap();
repr.mass.as_mut().unwrap().dry_mass_kg = 100.5;
dataset.set_by_id(-50, repr).unwrap();
assert_eq!(
dataset.get_by_id(-50).unwrap().mass_kg.unwrap().dry_mass_kg,
dataset.get_by_id(-50).unwrap().mass.unwrap().dry_mass_kg,
100.5,
"value was not modified"
);
assert!(dataset.set_by_id(111, repr.clone()).is_err());
assert!(dataset.set_by_id(111, repr).is_err());
// Test renaming by ID
dataset.lut.reid(-50, -52).unwrap();
// Calling this a second time will lead to an error
Expand All @@ -772,7 +772,7 @@ mod dataset_ut {
assert!(dataset.get_by_id(-50).is_err());
// Check that we can fetch that data as we modified it.
assert_eq!(
dataset.get_by_id(-52).unwrap().mass_kg.unwrap().dry_mass_kg,
dataset.get_by_id(-52).unwrap().mass.unwrap().dry_mass_kg,
100.5,
"value not reachable after reid"
);
Expand Down
13 changes: 11 additions & 2 deletions anise/src/structure/spacecraft/drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ use serde_derive::{Deserialize, Serialize};

#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct DragData {
/// Atmospheric drag area in m^2
/// Atmospheric drag area in m^2 -- default 0.0
pub area_m2: f64,
/// Drag coefficient (C_d)
/// Drag coefficient (C_d) -- default 2.2
pub coeff_drag: f64,
}

impl DragData {
pub fn from_area(area_m2: f64) -> Self {
Self {
area_m2,
..Default::default()
}
}
}

impl Default for DragData {
fn default() -> Self {
Self {
Expand Down
90 changes: 45 additions & 45 deletions anise/src/structure/spacecraft/inertia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,68 @@ use crate::NaifId;
pub struct Inertia {
/// Inertia tensor reference frame hash
pub orientation_id: NaifId,
/// Moment of inertia about the 1-axis
pub i_11_kgm2: f64,
/// Moment of inertia about the 2-axis
pub i_22_kgm2: f64,
/// Moment of inertia about the 3-axis
pub i_33_kgm2: f64,
/// Inertia cross product of the 1 and 2 axes
pub i_12_kgm2: f64,
/// Inertia cross product of the 1 and 2 axes
pub i_13_kgm2: f64,
/// Inertia cross product of the 2 and 3 axes
pub i_23_kgm2: f64,
/// Moment of inertia about the X axis, in kg \cdot m^2
pub i_xx_kgm2: f64,
/// Moment of inertia about the Y axis, in kg \cdot m^2
pub i_yy_kgm2: f64,
/// Moment of inertia about the Z axis, in kg \cdot m^2
pub i_zz_kgm2: f64,
/// Inertia cross product of the X and Y axes, in kg \cdot m^2
pub i_xy_kgm2: f64,
/// Inertia cross product of the X and Y axes, in kg \cdot m^2
pub i_xz_kgm2: f64,
/// Inertia cross product of the Y and Z axes, in kg \cdot m^2
pub i_yz_kgm2: f64,
}

impl Inertia {
pub fn tensor_kgm2(&self) -> Matrix3<f64> {
Matrix3::new(
self.i_11_kgm2,
self.i_12_kgm2,
self.i_13_kgm2,
self.i_12_kgm2,
self.i_22_kgm2,
self.i_23_kgm2,
self.i_13_kgm2,
self.i_23_kgm2,
self.i_33_kgm2,
self.i_xx_kgm2,
self.i_xy_kgm2,
self.i_xz_kgm2,
self.i_xy_kgm2,
self.i_yy_kgm2,
self.i_yz_kgm2,
self.i_xz_kgm2,
self.i_yz_kgm2,
self.i_zz_kgm2,
)
}
}

impl Encode for Inertia {
fn encoded_len(&self) -> der::Result<der::Length> {
self.orientation_id.encoded_len()?
+ self.i_11_kgm2.encoded_len()?
+ self.i_22_kgm2.encoded_len()?
+ self.i_33_kgm2.encoded_len()?
+ self.i_12_kgm2.encoded_len()?
+ self.i_13_kgm2.encoded_len()?
+ self.i_23_kgm2.encoded_len()?
+ self.i_xx_kgm2.encoded_len()?
+ self.i_yy_kgm2.encoded_len()?
+ self.i_zz_kgm2.encoded_len()?
+ self.i_xy_kgm2.encoded_len()?
+ self.i_xz_kgm2.encoded_len()?
+ self.i_yz_kgm2.encoded_len()?
}

fn encode(&self, encoder: &mut impl Writer) -> der::Result<()> {
self.orientation_id.encode(encoder)?;
self.i_11_kgm2.encode(encoder)?;
self.i_22_kgm2.encode(encoder)?;
self.i_33_kgm2.encode(encoder)?;
self.i_12_kgm2.encode(encoder)?;
self.i_13_kgm2.encode(encoder)?;
self.i_23_kgm2.encode(encoder)
self.i_xx_kgm2.encode(encoder)?;
self.i_yy_kgm2.encode(encoder)?;
self.i_zz_kgm2.encode(encoder)?;
self.i_xy_kgm2.encode(encoder)?;
self.i_xz_kgm2.encode(encoder)?;
self.i_yz_kgm2.encode(encoder)
}
}

impl<'a> Decode<'a> for Inertia {
fn decode<R: Reader<'a>>(decoder: &mut R) -> der::Result<Self> {
Ok(Self {
orientation_id: decoder.decode()?,
i_11_kgm2: decoder.decode()?,
i_22_kgm2: decoder.decode()?,
i_33_kgm2: decoder.decode()?,
i_12_kgm2: decoder.decode()?,
i_13_kgm2: decoder.decode()?,
i_23_kgm2: decoder.decode()?,
i_xx_kgm2: decoder.decode()?,
i_yy_kgm2: decoder.decode()?,
i_zz_kgm2: decoder.decode()?,
i_xy_kgm2: decoder.decode()?,
i_xz_kgm2: decoder.decode()?,
i_yz_kgm2: decoder.decode()?,
})
}
}
Expand All @@ -92,12 +92,12 @@ mod inertia_ut {
let repr = Inertia {
// Spacecraft IDs are typically negative
orientation_id: -20,
i_11_kgm2: 120.0,
i_22_kgm2: 180.0,
i_33_kgm2: 220.0,
i_12_kgm2: 20.0,
i_13_kgm2: -15.0,
i_23_kgm2: 30.0,
i_xx_kgm2: 120.0,
i_yy_kgm2: 180.0,
i_zz_kgm2: 220.0,
i_xy_kgm2: 20.0,
i_xz_kgm2: -15.0,
i_yz_kgm2: 30.0,
};

let mut buf = vec![];
Expand Down
Loading

0 comments on commit 3fe4183

Please sign in to comment.