Skip to content

Commit

Permalink
Validation of line of sight computation
Browse files Browse the repository at this point in the history
The issue had been fixed in a prior commit for 0.4.4
  • Loading branch information
ChristopherRabotin committed Oct 3, 2024
1 parent 2532881 commit 81b6402
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
3 changes: 3 additions & 0 deletions anise/src/almanac/aer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ impl Almanac {
/// Computes the azimuth (in degrees), elevation (in degrees), and range (in kilometers) of the
/// receiver state (`rx`) seen from the transmitter state (`tx`), once converted into the SEZ frame of the transmitter.
///
/// # Warning
/// The obstructing body _should_ be a tri-axial ellipsoid body, e.g. IAU_MOON_FRAME.
///
/// # Algorithm
/// 1. If any obstructing_bodies are provided, ensure that none of these are obstructing the line of sight between the receiver and transmitter.
/// 2. Compute the SEZ (South East Zenith) frame of the transmitter.
Expand Down
9 changes: 5 additions & 4 deletions anise/src/astro/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use std::fmt::Display;
use crate::errors::PhysicsError;
use crate::frames::Frame;

use hifitime::{Duration, Epoch, TimeUnits};

use crate::constants::SPEED_OF_LIGHT_KM_S;
use hifitime::{Duration, Epoch};

#[cfg(feature = "python")]
use pyo3::exceptions::PyTypeError;
Expand Down Expand Up @@ -60,7 +58,7 @@ impl AzElRange {
}

/// Returns whether there is an obstruction.
pub fn is_obstructed(&self) -> bool {
pub const fn is_obstructed(&self) -> bool {
self.obstructed_by.is_some()
}

Expand All @@ -75,6 +73,9 @@ impl AzElRange {
range_rate_km_s: f64,
obstructed_by: Option<Frame>,
) -> Self {
use crate::constants::SPEED_OF_LIGHT_KM_S;
use hifitime::TimeUnits;

Self {
epoch,
azimuth_deg,
Expand Down
48 changes: 46 additions & 2 deletions anise/tests/ephemerides/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Documentation: https://nyxspace.com/
*/

use anise::astro::Occultation;
use anise::astro::{AzElRange, Occultation};
use anise::constants::celestial_objects::{EARTH, VENUS};
use anise::constants::frames::{
EARTH_ITRF93, EARTH_J2000, IAU_EARTH_FRAME, IAU_MOON_FRAME, MOON_J2000, SUN_J2000, VENUS_J2000,
Expand Down Expand Up @@ -317,6 +317,14 @@ fn validate_gh_283_multi_barycenter_and_los(almanac: Almanac) {
let obsrvr = "-85";

let mut prev_occult: Option<Occultation> = None;
let mut prev_aer: Option<AzElRange> = None;
let mut access_count = 0;
let mut access_start: Option<Epoch> = None;

let access_times = [
Unit::Minute * 4 + Unit::Second * 1,
Unit::Hour * 1 + Unit::Minute * 6 + 49 * Unit::Second,
];

for epoch in TimeSeries::inclusive(epoch, epoch + period, 1.seconds()) {
// Rebuild the ground station at this new epoch
Expand All @@ -335,8 +343,33 @@ fn validate_gh_283_multi_barycenter_and_los(almanac: Almanac) {
.unwrap();

let aer = almanac
.azimuth_elevation_range_sez(rx_lro, tx_madrid, Some(MOON_J2000), None)
.azimuth_elevation_range_sez(rx_lro, tx_madrid, Some(IAU_MOON_FRAME), None)
.unwrap();

if let Some(prev_aer) = prev_aer {
if prev_aer.is_obstructed() && !aer.is_obstructed() {
// New access
access_count += 1;
access_start = Some(aer.epoch);
} else if !prev_aer.is_obstructed() && aer.is_obstructed() {
// End of access
if let Some(access_start) = access_start {
// We've had a full access strand.
let access_end = aer.epoch;
let access_duration = (access_end - access_start).round(Unit::Second * 1);
println!(
"#{access_count}\t{access_start} - {access_end}\t{}",
access_duration
);
assert_eq!(access_times[access_count], access_duration);
}
}
// dbg!(prev_aer.is_obstructed(), aer.is_obstructed());
} else if !aer.is_obstructed() {
access_start = Some(aer.epoch);
}
prev_aer = Some(aer);

if aer.obstructed_by.is_some() {
obstructions += 1;
} else {
Expand Down Expand Up @@ -417,6 +450,17 @@ fn validate_gh_283_multi_barycenter_and_los(almanac: Almanac) {
prev_occult = Some(occult)
}

if let Some(access_start) = access_start {
// We've had a full access strand.
let access_end = epoch + period;
let access_duration = (access_end - access_start).round(Unit::Second * 1);
println!(
"#{access_count}\t{access_start} - {access_end}\t{}",
access_duration
);
assert_eq!(access_times[access_count], access_duration);
}

assert_eq!(obstructions, 2762);
assert_eq!(no_obstructions, 4250);
}

0 comments on commit 81b6402

Please sign in to comment.