Skip to content

Commit

Permalink
Integration tests build, but probably fail
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Dec 3, 2023
1 parent e60fcfd commit 7dcefc0
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 136 deletions.
1 change: 1 addition & 0 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ use pyo3::prelude::*;
/// Configuration for exporting a trajectory to parquet.
#[derive(Clone, Default, Serialize, Deserialize, TypedBuilder)]
#[cfg_attr(feature = "python", pyclass)]
#[builder(doc)]
pub struct ExportCfg {
/// Fields to export, if unset, defaults to all possible fields.
#[builder(default, setter(strip_option))]
Expand Down
20 changes: 13 additions & 7 deletions src/od/simulator/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ impl TrackingArcSim<Orbit, RangeDoppler, GroundStation> {
/// 4. Repeat 2, 3 until the end of the trajectory
/// 5. Build each of these as "tracking strands" for this tracking device.
/// 6. THEN REMOVE OVERLAPPING MEASUREMENTS - ALGO TBD
pub fn build_schedule(&self, cosm: Arc<Cosm>) -> Result<HashMap<String, TrkConfig>, NyxError> {
pub fn generate_schedule(
&self,
cosm: Arc<Cosm>,
) -> Result<HashMap<String, TrkConfig>, NyxError> {
let mut built_cfg = self.configs.clone();
'devices: for (name, device) in self.devices.iter() {
let cfg = &self.configs[name];
Expand Down Expand Up @@ -339,9 +342,9 @@ impl TrackingArcSim<Orbit, RangeDoppler, GroundStation> {
Ok(built_cfg)
}

/// Sets the schedule to that built in `build_schedule`
pub fn compute_schedule(&mut self, cosm: Arc<Cosm>) -> Result<(), NyxError> {
self.configs = self.build_schedule(cosm)?;
/// Sets the schedule to that built in `generate_schedule`
pub fn build_schedule(&mut self, cosm: Arc<Cosm>) -> Result<(), NyxError> {
self.configs = self.generate_schedule(cosm)?;

Ok(())
}
Expand All @@ -359,7 +362,10 @@ impl TrackingArcSim<Spacecraft, RangeDoppler, GroundStation> {
/// 4. Repeat 2, 3 until the end of the trajectory
/// 5. Build each of these as "tracking strands" for this tracking device.
/// 6. THEN REMOVE OVERLAPPING MEASUREMENTS - ALGO TBD
pub fn build_schedule(&self, cosm: Arc<Cosm>) -> Result<HashMap<String, TrkConfig>, NyxError> {
pub fn generate_schedule(
&self,
cosm: Arc<Cosm>,
) -> Result<HashMap<String, TrkConfig>, NyxError> {
let mut built_cfg = self.configs.clone();
'devices: for (name, device) in self.devices.iter() {
let cfg = &self.configs[name];
Expand Down Expand Up @@ -435,8 +441,8 @@ impl TrackingArcSim<Spacecraft, RangeDoppler, GroundStation> {
}

/// Sets the schedule to that built in `build_schedule`
pub fn compute_schedule(&mut self, cosm: Arc<Cosm>) -> Result<(), NyxError> {
self.configs = self.build_schedule(cosm)?;
pub fn build_schedule(&mut self, cosm: Arc<Cosm>) -> Result<(), NyxError> {
self.configs = self.generate_schedule(cosm)?;

Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions src/od/simulator/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ impl Default for Handoff {

/// A scheduler allows building a scheduling of spaceraft tracking for a set of ground stations.
#[derive(Copy, Clone, Debug, Default, Deserialize, PartialEq, Serialize, TypedBuilder)]
#[builder(doc)]
pub struct Scheduler {
#[builder(default)]
pub handoff: Handoff,
#[builder(default)]
pub cadence: Cadence,
}

Expand Down
31 changes: 28 additions & 3 deletions src/od/simulator/trkconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use super::scheduler::Scheduler;
pub use crate::dynamics::{Dynamics, NyxError};
use crate::io::{duration_from_str, duration_to_str, epoch_from_str, epoch_to_str, ConfigError};
use crate::io::{ConfigRepr, Configurable};
Expand All @@ -28,26 +29,29 @@ use serde::Deserialize;
use serde_derive::Serialize;
use std::fmt::Debug;
use std::sync::Arc;

use super::scheduler::Scheduler;
use typed_builder::TypedBuilder;

/// Stores a tracking configuration, there is one per tracking data simulator (e.g. one for ground station #1 and another for #2).
/// By default, the tracking configuration is continuous and the tracking arc is from the beginning of the simulation to the end.
/// In Python, any value that is set to None at initialization will use the default values.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, TypedBuilder)]
#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyo3(module = "nyx_space.orbit_determination"))]
#[builder(doc)]
pub struct TrkConfig {
/// Set to automatically build a tracking schedule based on some criteria
#[serde(default)]
#[builder(default, setter(strip_option))]
pub scheduler: Option<Scheduler>,
#[serde(
serialize_with = "duration_to_str",
deserialize_with = "duration_from_str"
)]
/// Sampling rate once tracking has started
#[builder(default = 1.minutes())]
pub sampling: Duration,
/// List of tracking strands during which the given tracker will be tracking
#[builder(default, setter(strip_option))]
pub strands: Option<Vec<EpochRanges>>,
}

Expand Down Expand Up @@ -247,4 +251,25 @@ mod trkconfig_ut {
let configs: HashMap<String, TrkConfig> = TrkConfig::load_named(trkconfg_yaml).unwrap();
dbg!(configs);
}

#[test]
fn api_trk_config() {
use serde_yaml;

let cfg = TrkConfig::builder()
.sampling(15.seconds())
.scheduler(Scheduler::builder().handoff(Handoff::Overlap).build())
.build();

let serialized = serde_yaml::to_string(&cfg).unwrap();
println!("{serialized}");
let deserd: TrkConfig = serde_yaml::from_str(&serialized).unwrap();
assert_eq!(deserd, cfg);

let cfg = TrkConfig::builder()
.scheduler(Scheduler::builder().handoff(Handoff::Overlap).build())
.build();

assert_eq!(cfg.sampling, 60.seconds());
}
}
4 changes: 2 additions & 2 deletions tests/orbit_determination/multi_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn od_val_multi_body_ckf_perfect_stations() {

// Simulate tracking data
let mut arc_sim = TrackingArcSim::with_seed(all_stations, traj, configs, 0).unwrap();
arc_sim.disallow_overlap(); // Prevent overlapping measurements
arc_sim.build_schedule(cosm.clone()).unwrap();

let arc = arc_sim.generate_measurements(cosm.clone()).unwrap();

Expand Down Expand Up @@ -203,7 +203,7 @@ fn multi_body_ckf_covar_map() {

// Simulate tracking data
let mut arc_sim = TrackingArcSim::with_seed(all_stations, traj, configs, 0).unwrap();
arc_sim.disallow_overlap(); // Prevent overlapping measurements
arc_sim.build_schedule(cosm.clone()).unwrap();

let arc = arc_sim.generate_measurements(cosm.clone()).unwrap();

Expand Down
24 changes: 4 additions & 20 deletions tests/orbit_determination/resid_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn traj(epoch: Epoch) -> Traj<Orbit> {
}

#[fixture]
fn devices_n_configs(epoch: Epoch) -> (Vec<GroundStation>, HashMap<String, TrkConfig>) {
fn devices_n_configs() -> (Vec<GroundStation>, HashMap<String, TrkConfig>) {
// Load cosm
let cosm = Cosm::de438();

Expand All @@ -78,24 +78,8 @@ fn devices_n_configs(epoch: Epoch) -> (Vec<GroundStation>, HashMap<String, TrkCo

// Define the tracking configurations
let mut configs = HashMap::new();
configs.insert(
dss65_madrid.name.clone(),
TrkConfig {
// Make sure to start the tracking one integration time after the start of the trajectory
start: simulator::Availability::Epoch(epoch + 60.seconds()),
sampling: 60.seconds(),
..Default::default()
},
);
configs.insert(
dss34_canberra.name.clone(),
TrkConfig {
// Make sure to start the tracking one integration time after the start of the trajectory
start: simulator::Availability::Epoch(epoch + 60.seconds()),
sampling: 60.seconds(),
..Default::default()
},
);
configs.insert(dss65_madrid.name.clone(), TrkConfig::default());
configs.insert(dss34_canberra.name.clone(), TrkConfig::default());

(vec![dss65_madrid, dss34_canberra], configs)
}
Expand All @@ -112,7 +96,7 @@ fn tracking_arc(

// Simulate tracking data
let mut arc_sim = TrackingArcSim::with_seed(devices, traj, configs, 0).unwrap();
arc_sim.disallow_overlap(); // Prevent overlapping measurements
arc_sim.build_schedule(cosm.clone()).unwrap();

let arc = arc_sim.generate_measurements(cosm).unwrap();

Expand Down
24 changes: 4 additions & 20 deletions tests/orbit_determination/robust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn od_robust_test_ekf_realistic_one_way() {

// Simulate tracking data
let mut arc_sim = TrackingArcSim::with_seed(all_stations, traj.clone(), configs, 0).unwrap();
arc_sim.disallow_overlap(); // Prevent overlapping measurements
arc_sim.build_schedule(cosm.clone()).unwrap();

let arc = arc_sim.generate_measurements(cosm.clone()).unwrap();

Expand Down Expand Up @@ -268,24 +268,8 @@ fn od_robust_test_ekf_realistic_two_way() {

// Define the tracking configurations
let configs = HashMap::from([
(
dss65_madrid.name.clone(),
TrkConfig {
// Make sure to start the tracking one integration time after the start of the trajectory
start: simulator::Availability::Epoch(dt + 60.seconds()),
sampling: 60.seconds(),
..Default::default()
},
),
(
dss34_canberra.name.clone(),
TrkConfig {
// Make sure to start the tracking one integration time after the start of the trajectory
start: simulator::Availability::Epoch(dt + 60.seconds()),
sampling: 60.seconds(),
..Default::default()
},
),
(dss65_madrid.name.clone(), TrkConfig::default()),
(dss34_canberra.name.clone(), TrkConfig::default()),
]);

// Note that we do not have Goldstone so we can test enabling and disabling the EKF.
Expand Down Expand Up @@ -332,7 +316,7 @@ fn od_robust_test_ekf_realistic_two_way() {

// Simulate tracking data
let mut arc_sim = TrackingArcSim::with_seed(devices.clone(), traj.clone(), configs, 0).unwrap();
arc_sim.disallow_overlap(); // Prevent overlapping measurements
arc_sim.build_schedule(cosm.clone()).unwrap();

let arc = arc_sim.generate_measurements(cosm.clone()).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion tests/orbit_determination/spacecraft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn od_val_sc_mb_srp_reals_duals_models() {

// Simulate tracking data
let mut arc_sim = TrackingArcSim::with_seed(all_stations, traj, configs, 0).unwrap();
arc_sim.disallow_overlap(); // Prevent overlapping measurements
arc_sim.build_schedule(cosm.clone()).unwrap();

let arc = arc_sim.generate_measurements(cosm.clone()).unwrap();

Expand Down
93 changes: 23 additions & 70 deletions tests/orbit_determination/trackingarc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use nyx_space::md::prelude::*;
use nyx_space::od::msr::RangeDoppler;
use nyx_space::od::prelude::*;
use nyx_space::od::simulator::TrackingArcSim;
use nyx_space::od::simulator::{Availability, Cadence, EpochRanges, TrkConfig};
use nyx_space::od::simulator::{Cadence, EpochRanges, TrkConfig};
use rstest::*;
use std::collections::HashMap;
use std::env;
Expand Down Expand Up @@ -176,67 +176,22 @@ fn trk_simple(traj: Traj<Orbit>, devices: Vec<GroundStation>) {
assert_eq!(arc_concrete.device_cfg, arc.device_cfg);
}

/// Tests that exclusion epochs work
#[rstest]
fn trkconfig_zero_exclusion(traj: Traj<Orbit>, devices: Vec<GroundStation>) {
let cosm = Cosm::de438();

// Build a tracking config that should never see this vehicle.
let trkcfg = TrkConfig {
exclusion_epochs: Some(vec![EpochRanges {
start: traj.first().epoch(),
end: traj.last().epoch(),
}]),
..Default::default()
};
// Build the configs map
let mut configs = HashMap::new();
for device in &devices {
configs.insert(device.name.clone(), trkcfg.clone());
}

let mut trk = TrackingArcSim::<Orbit, RangeDoppler, _>::new(devices, traj, configs).unwrap();

let arc = trk.generate_measurements(cosm).unwrap();

assert_eq!(arc.measurements.len(), 0);
}

/// Tests that inclusion epochs work
#[rstest]
fn trkconfig_zero_inclusion(traj: Traj<Orbit>, devices: Vec<GroundStation>) {
let cosm = Cosm::de438();

// Build a tracking config that should always see this vehicle.
let trkcfg_always = TrkConfig {
strands: Some(vec![EpochRanges {
let trkcfg_always = TrkConfig::builder()
.strands(vec![EpochRanges {
start: traj.first().epoch(),
end: traj.last().epoch(),
}]),
..Default::default()
};
}])
.build();

// And one that is never included
let trkcfg_never = TrkConfig {
exclusion_epochs: Some(vec![EpochRanges {
start: traj.first().epoch(),
end: traj.last().epoch(),
}]),
..Default::default()
};
// Build the configs map
// Build the configs map, where we only have one of the two stations configured
let mut configs = HashMap::new();
for (dno, device) in devices.iter().enumerate() {
configs.insert(
device.name.clone(),
if dno == 0 {
println!("{}", device.name);
trkcfg_never.clone()
} else {
trkcfg_always.clone()
},
);
}
configs.insert(devices[1].name.clone(), trkcfg_always);

let mut trk = TrackingArcSim::<Orbit, RangeDoppler, _>::new(devices, traj, configs).unwrap();

Expand All @@ -256,13 +211,13 @@ fn trkconfig_zero_inclusion(traj: Traj<Orbit>, devices: Vec<GroundStation>) {
#[rstest]
fn trkconfig_invalid(traj: Traj<Orbit>, devices: Vec<GroundStation>) {
// Build a tracking config where the exclusion range is less than the sampling rate
let trkcfg = TrkConfig {
exclusion_epochs: Some(vec![EpochRanges {
let trkcfg = TrkConfig::builder()
.strands(vec![EpochRanges {
start: traj.first().epoch(),
end: traj.first().epoch(),
}]),
..Default::default()
};
}])
.build();

// Build the configs map
let mut configs = HashMap::new();
for device in &devices {
Expand Down Expand Up @@ -326,23 +281,21 @@ fn trkconfig_cadence(traj: Traj<Orbit>, devices: Vec<GroundStation>) {

configs.insert(
devices[0].name.clone(),
TrkConfig {
start: Availability::Visible,
scheduler: Cadence::Intermittent {
on: 0.2.hours(),
off: 20.days(),
},
..Default::default()
},
TrkConfig::builder()
.scheduler(
Scheduler::builder()
.cadence(Cadence::Intermittent {
on: 0.2.hours(),
off: 20.days(),
})
.build(),
)
.build(),
);

configs.insert(
devices[1].name.clone(),
TrkConfig {
start: Availability::Epoch(traj.last().epoch() - 10.hours()),
sampling: 26.1.seconds(),
..Default::default()
},
TrkConfig::builder().sampling(26.1.seconds()).build(),
);

let mut trk = TrackingArcSim::<Orbit, RangeDoppler, _>::new(devices, traj, configs).unwrap();
Expand Down
Loading

0 comments on commit 7dcefc0

Please sign in to comment.