Skip to content

Commit 1af2fe6

Browse files
Merge pull request #368 from nyx-space/feat/serde
Various cleaning up -> version 0.5.2
2 parents b2258cf + fe512a5 commit 1af2fe6

File tree

17 files changed

+106
-117
lines changed

17 files changed

+106
-117
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["anise", "anise-cli", "anise-gui", "anise-py"]
44

55
[workspace.package]
6-
version = "0.5.1"
6+
version = "0.5.2"
77
edition = "2021"
88
authors = ["Christopher Rabotin <[email protected]>"]
99
description = "ANISE provides a toolkit and files for Attitude, Navigation, Instrument, Spacecraft, and Ephemeris data. It's a modern replacement of NAIF SPICE file."
@@ -45,7 +45,7 @@ pyo3-log = "0.12"
4545
numpy = "0.23"
4646
ndarray = ">= 0.15, < 0.17"
4747

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

5050
[profile.bench]
5151
debug = true

anise-gui/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ hifitime = { workspace = true }
1515
log = { workspace = true }
1616
bytes = { workspace = true }
1717
pretty_env_logger = { workspace = true }
18-
eframe = { version = "0.29" }
19-
egui = { version = "0.29" }
20-
egui_extras = { version = "0.29", features = ["datepicker", "http", "image"] }
18+
eframe = { version = "0.30" }
19+
egui = { version = "0.30" }
20+
egui_extras = { version = "0.30", features = ["datepicker", "http", "image"] }
2121
rfd = { version = "0.15.0" }
22-
egui_logger = "0.6.1"
22+
egui_logger = "0.6.2"
2323

2424
[target.'cfg(target_arch = "wasm32")'.dependencies]
2525
wasm-bindgen-futures = "0.4"

anise/src/almanac/metaload/metaalmanac.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl Default for MetaAlmanac {
267267
.join("v0.5/moon_fk_de440.epa")
268268
.unwrap()
269269
.to_string(),
270-
crc32: Some(0x6f0ad74c),
270+
crc32: Some(0x21633903),
271271
},
272272
MetaFile {
273273
uri: nyx_cloud_stor

anise/src/almanac/metaload/metafile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl MetaFile {
147147
self.uri = dest_path_s;
148148
return Ok(());
149149
} else {
150-
info!("Discarding cached {dest_path_s} - CRC32 differ (got {computed_crc32:x}, expected {crc32:x})");
150+
info!("Discarding cached {dest_path_s} - CRC32 differ (got 0x{computed_crc32:x}, expected 0x{crc32:x})");
151151
}
152152
}
153153
}
@@ -206,7 +206,7 @@ impl MetaFile {
206206
file.write_all(&bytes).unwrap();
207207

208208
info!(
209-
"Saved {url} to {} (CRC32 = {crc32:x})",
209+
"Saved {url} to {} (CRC32 = 0x{crc32:x})",
210210
dest_path.to_str().unwrap()
211211
);
212212

anise/src/almanac/metaload/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ mod meta_test {
144144
, { crc32 = Some 0x8213b6e9
145145
, uri = "http://public-data.nyxspace.com/anise/v0.5/pck11.pca"
146146
}
147-
, { crc32 = Some 0x6f0ad74c
147+
, { crc32 = Some 0x21633903
148148
, uri = "http://public-data.nyxspace.com/anise/v0.5/moon_fk_de440.epa"
149149
}
150150
, { crc32 = Some 0xcde5ca7d

anise/src/astro/orbit.rs

+56-50
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ impl Orbit {
5454
/// One should expect these errors to be on the order of 1e-12.
5555
#[allow(clippy::too_many_arguments)]
5656
pub fn try_keplerian(
57-
sma: f64,
57+
sma_km: f64,
5858
ecc: f64,
59-
inc: f64,
60-
raan: f64,
61-
aop: f64,
62-
ta: f64,
59+
inc_deg: f64,
60+
raan_deg: f64,
61+
aop_deg: f64,
62+
ta_deg: f64,
6363
epoch: Epoch,
6464
frame: Frame,
6565
) -> PhysicsResult<Self> {
@@ -74,14 +74,14 @@ impl Orbit {
7474
} else {
7575
ecc
7676
};
77-
let sma = if ecc > 1.0 && sma > 0.0 {
77+
let sma = if ecc > 1.0 && sma_km > 0.0 {
7878
warn!("eccentricity > 1 (hyperbolic) BUT SMA > 0 (elliptical): sign of SMA changed");
79-
sma * -1.0
80-
} else if ecc < 1.0 && sma < 0.0 {
79+
sma_km * -1.0
80+
} else if ecc < 1.0 && sma_km < 0.0 {
8181
warn!("eccentricity < 1 (elliptical) BUT SMA < 0 (hyperbolic): sign of SMA changed");
82-
sma * -1.0
82+
sma_km * -1.0
8383
} else {
84-
sma
84+
sma_km
8585
};
8686
if (sma * (1.0 - ecc)).abs() < 1e-3 {
8787
// GMAT errors below one meter. Let's warn for below that, but not panic, might be useful for landing scenarios?
@@ -92,14 +92,14 @@ impl Orbit {
9292
ParabolicEccentricitySnafu { limit: ECC_EPSILON }
9393
);
9494
if ecc > 1.0 {
95-
let ta_deg = between_0_360(ta);
95+
let ta_deg = between_0_360(ta_deg);
9696
ensure!(
9797
ta_deg <= (PI - (1.0 / ecc).acos()).to_degrees(),
9898
HyperbolicTrueAnomalySnafu { ta_deg }
9999
);
100100
}
101101
ensure!(
102-
(1.0 + ecc * ta.to_radians().cos()).is_finite(),
102+
(1.0 + ecc * ta_deg.to_radians().cos()).is_finite(),
103103
InfiniteValueSnafu {
104104
action: "computing radius of orbit"
105105
}
@@ -109,28 +109,28 @@ impl Orbit {
109109
// The conversion algorithm itself comes from GMAT's StateConversionUtil::ComputeKeplToCart
110110
// NOTE: GMAT supports mean anomaly instead of true anomaly, but only for backward compatibility reasons
111111
// so it isn't supported here.
112-
let inc = inc.to_radians();
113-
let raan = raan.to_radians();
114-
let aop = aop.to_radians();
115-
let ta = ta.to_radians();
116-
let p = sma * (1.0 - ecc.powi(2));
112+
let inc_rad = inc_deg.to_radians();
113+
let raan_rad = raan_deg.to_radians();
114+
let aop_rad = aop_deg.to_radians();
115+
let ta_rad = ta_deg.to_radians();
116+
let p_km = sma * (1.0 - ecc.powi(2));
117117

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

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

135135
let vx = sqrt_gm_p * cos_ta_ecc * (-sin_aop * cos_raan - cos_inc * sin_raan * cos_aop)
136136
- sqrt_gm_p * sin_ta * (cos_aop * cos_raan - cos_inc * sin_raan * sin_aop);
@@ -149,31 +149,31 @@ impl Orbit {
149149
/// Attempts to create a new Orbit from the provided radii of apoapsis and periapsis, in kilometers
150150
#[allow(clippy::too_many_arguments)]
151151
pub fn try_keplerian_apsis_radii(
152-
r_a: f64,
153-
r_p: f64,
154-
inc: f64,
155-
raan: f64,
156-
aop: f64,
157-
ta: f64,
152+
r_a_km: f64,
153+
r_p_km: f64,
154+
inc_deg: f64,
155+
raan_deg: f64,
156+
aop_deg: f64,
157+
ta_deg: f64,
158158
epoch: Epoch,
159159
frame: Frame,
160160
) -> PhysicsResult<Self> {
161161
ensure!(
162-
r_a > f64::EPSILON,
162+
r_a_km > f64::EPSILON,
163163
RadiusSnafu {
164164
action: "radius of apoapsis is negative"
165165
}
166166
);
167167
ensure!(
168-
r_p > f64::EPSILON,
168+
r_p_km > f64::EPSILON,
169169
RadiusSnafu {
170170
action: "radius of periapsis is negative"
171171
}
172172
);
173173
// The two checks above ensure that sma > 0
174-
let sma = (r_a + r_p) / 2.0;
175-
let ecc = r_a / sma - 1.0;
176-
Self::try_keplerian(sma, ecc, inc, raan, aop, ta, epoch, frame)
174+
let sma = (r_a_km + r_p_km) / 2.0;
175+
let ecc = r_a_km / sma - 1.0;
176+
Self::try_keplerian(sma, ecc, inc_deg, raan_deg, aop_deg, ta_deg, epoch, frame)
177177
}
178178

179179
/// Attempts to create a new Orbit around the provided frame from the borrowed state vector
@@ -196,31 +196,37 @@ impl Orbit {
196196
/// One should expect these errors to be on the order of 1e-12.
197197
#[allow(clippy::too_many_arguments)]
198198
pub fn keplerian(
199-
sma: f64,
199+
sma_km: f64,
200200
ecc: f64,
201-
inc: f64,
202-
raan: f64,
203-
aop: f64,
204-
ta: f64,
201+
inc_deg: f64,
202+
raan_deg: f64,
203+
aop_deg: f64,
204+
ta_deg: f64,
205205
epoch: Epoch,
206206
frame: Frame,
207207
) -> Self {
208-
Self::try_keplerian(sma, ecc, inc, raan, aop, ta, epoch, frame).unwrap()
208+
Self::try_keplerian(
209+
sma_km, ecc, inc_deg, raan_deg, aop_deg, ta_deg, epoch, frame,
210+
)
211+
.unwrap()
209212
}
210213

211214
/// Creates a new Orbit from the provided radii of apoapsis and periapsis, in kilometers
212215
#[allow(clippy::too_many_arguments)]
213216
pub fn keplerian_apsis_radii(
214-
r_a: f64,
215-
r_p: f64,
216-
inc: f64,
217-
raan: f64,
218-
aop: f64,
219-
ta: f64,
217+
r_a_km: f64,
218+
r_p_km: f64,
219+
inc_deg: f64,
220+
raan_deg: f64,
221+
aop_deg: f64,
222+
ta_deg: f64,
220223
epoch: Epoch,
221224
frame: Frame,
222225
) -> Self {
223-
Self::try_keplerian_apsis_radii(r_a, r_p, inc, raan, aop, ta, epoch, frame).unwrap()
226+
Self::try_keplerian_apsis_radii(
227+
r_a_km, r_p_km, inc_deg, raan_deg, aop_deg, ta_deg, epoch, frame,
228+
)
229+
.unwrap()
224230
}
225231

226232
/// Initializes a new orbit from the Keplerian orbital elements using the mean anomaly instead of the true anomaly.

anise/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ pub enum PhysicsError {
191191
},
192192
#[snafu(display("parabolic orbits are physically impossible and the eccentricity calculated to be within {limit:e} of 1.0"))]
193193
ParabolicEccentricity { limit: f64 },
194-
#[snafu(display("parabolic orbits are physically impossible and the semilatus rectum (semi-parameter) calculated to be {p}"))]
195-
ParabolicSemiParam { p: f64 },
194+
#[snafu(display("parabolic orbits are physically impossible and the semilatus rectum (semi-parameter) calculated to be {p_km} km"))]
195+
ParabolicSemiParam { p_km: f64 },
196196
#[snafu(display("hyperbolic true anomaly is physically impossible: {ta_deg} deg"))]
197197
HyperbolicTrueAnomaly { ta_deg: f64 },
198198
#[snafu(display("calculation requires hyperbolic orbit, but its eccentricity is {ecc}"))]

anise/src/frames/frameuid.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Documentation: https://nyxspace.com/
99
*/
1010

11+
use serde::{Deserialize, Serialize};
12+
1113
use crate::{
1214
constants::{
1315
celestial_objects::celestial_name_from_id, orientations::orientation_name_from_id,
@@ -20,10 +22,7 @@ pub use super::Frame;
2022

2123
/// A unique frame reference that only contains enough information to build the actual Frame object.
2224
/// It cannot be used for any computations, is it be used in any structure apart from error structures.
23-
///
24-
/// # Usage note
25-
/// You should almost always prefer Frame over FrameRef unless you will
26-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
25+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
2726
pub struct FrameUid {
2827
pub ephemeris_id: NaifId,
2928
pub orientation_id: NaifId,

anise/src/math/rotation/quaternion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use core::fmt;
1616
use core::ops::Mul;
1717
use der::{Decode, Encode, Reader, Writer};
1818
use nalgebra::Matrix4x3;
19+
use serde::{Deserialize, Serialize};
1920
use snafu::ensure;
2021

2122
use super::EPSILON_RAD;
@@ -54,7 +55,7 @@ pub type Quaternion = EulerParameter;
5455
///
5556
/// # Usage
5657
/// Importantly, ANISE prevents the composition of two Euler Parameters if the frames do not match.
57-
#[derive(Clone, Copy, Debug)]
58+
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
5859
pub struct EulerParameter {
5960
pub w: f64,
6061
pub x: f64,

anise/src/structure/dataset/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ mod dataset_ut {
545545
fn spacecraft_constants_lookup() {
546546
// Build some data first.
547547
let full_sc = SpacecraftData {
548-
name: "full spacecraft".try_into().unwrap(),
549548
srp_data: Some(SRPData {
550549
area_m2: 2.0,
551550
coeff_reflectivity: 1.8,
@@ -563,7 +562,6 @@ mod dataset_ut {
563562
drag_data: Some(DragData::default()),
564563
};
565564
let srp_sc = SpacecraftData {
566-
name: "SRP only spacecraft".try_into().unwrap(),
567565
srp_data: Some(SRPData::default()),
568566
..Default::default()
569567
};
@@ -690,7 +688,6 @@ mod dataset_ut {
690688
fn spacecraft_constants_lookup_builder() {
691689
// Build some data first.
692690
let full_sc = SpacecraftData {
693-
name: "full spacecraft".try_into().unwrap(),
694691
srp_data: Some(SRPData {
695692
area_m2: 2.0,
696693
coeff_reflectivity: 1.8,
@@ -708,7 +705,6 @@ mod dataset_ut {
708705
drag_data: Some(DragData::default()),
709706
};
710707
let srp_sc = SpacecraftData {
711-
name: "SRP only spacecraft".try_into().unwrap(),
712708
srp_data: Some(SRPData::default()),
713709
..Default::default()
714710
};

anise/src/structure/spacecraft/drag.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
* Documentation: https://nyxspace.com/
99
*/
1010
use der::{Decode, Encode, Reader, Writer};
11+
use serde_derive::{Deserialize, Serialize};
1112

12-
#[derive(Copy, Clone, Debug, PartialEq)]
13+
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
1314
pub struct DragData {
1415
/// Atmospheric drag area in m^2
1516
pub area_m2: f64,

anise/src/structure/spacecraft/inertia.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
*/
1010
use der::{Decode, Encode, Reader, Writer};
1111
use nalgebra::Matrix3;
12+
use serde_derive::{Deserialize, Serialize};
1213

1314
use crate::NaifId;
1415

1516
/// Inertial tensor definition
16-
#[derive(Copy, Clone, Debug, Default, PartialEq)]
17+
#[derive(Copy, Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1718
pub struct Inertia {
1819
/// Inertia tensor reference frame hash
1920
pub orientation_id: NaifId,

0 commit comments

Comments
 (0)