Skip to content

Commit d9864f2

Browse files
Merge pull request #261 from nyx-space/hotfix/tracking-schedule-not-applied
Revamp tracking schedule building
2 parents e645c8f + c5bd169 commit d9864f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2025
-1311
lines changed

data/tests/config/tracking_cfg.yaml

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
Demo ground station:
2-
start: Visible
3-
end: Visible
4-
schedule: Continuous
2+
scheduler:
3+
handoff: Overlap
4+
cadence: Continuous
5+
min_samples: 10
6+
sample_alignment: null
57
sampling: 1 min
68

79
Canberra:
8-
start: Visible
9-
end: Visible
10-
schedule: Continuous
10+
scheduler:
11+
handoff: Eager
12+
cadence: Continuous
13+
min_samples: 10
14+
sample_alignment: 10 s
1115
sampling: 1 min

data/tests/config/tracking_cfg_incl_excl.yaml

-17
This file was deleted.

data/tests/config/trk_cfg_od_val.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
scheduler:
2+
handoff: Overlap # Allow for overlapping measurement
3+
cadence: Continuous
4+
min_samples: 10
5+
sample_alignment: 10 s
6+
sampling: 10 s
7+
strands: null
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
Madrid:
2-
start: Visible
3-
end: !Epoch 2020-01-01 03:00:00 UTC
4-
schedule: Continuous
2+
strands:
3+
- start: 2020-01-01 00:00:00 TAI
4+
end: 2020-01-01 03:00:00 TAI
55
sampling: 1 min
66

77
Canberra:
8-
start: Visible
9-
end: !Epoch 2020-01-01 19:00:00 UTC
10-
schedule: !Intermittent
11-
on: 4 h
12-
off: 8 h
8+
strands:
9+
- start: 2020-01-01 02:40:00 TAI
10+
end: 2020-01-01 07:00:00 TAI
1311
sampling: 1 min
1412

1513
Goldstone:
16-
start: !Epoch 2020-01-01 09:00:00 UTC
17-
end: Visible
18-
schedule: Continuous
14+
strands:
15+
- start: 2020-01-01 19:30:00 TAI
16+
end: 2020-01-02 00:00:00 TAI
17+
- start: 2020-01-01 09:00:00 TAI
18+
end: 2020-01-01 12:00:00 TAI
1919
sampling: 1 min

src/io/mod.rs

+30
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use pyo3::prelude::*;
6464
/// Configuration for exporting a trajectory to parquet.
6565
#[derive(Clone, Default, Serialize, Deserialize, TypedBuilder)]
6666
#[cfg_attr(feature = "python", pyclass)]
67+
#[builder(doc)]
6768
pub struct ExportCfg {
6869
/// Fields to export, if unset, defaults to all possible fields.
6970
#[builder(default, setter(strip_option))]
@@ -327,6 +328,35 @@ where
327328
Ok(orbit_serde.into())
328329
}
329330

331+
pub(crate) fn maybe_duration_to_str<S>(
332+
duration: &Option<Duration>,
333+
serializer: S,
334+
) -> Result<S::Ok, S::Error>
335+
where
336+
S: Serializer,
337+
{
338+
if let Some(duration) = duration {
339+
duration_to_str(duration, serializer)
340+
} else {
341+
serializer.serialize_none()
342+
}
343+
}
344+
345+
pub(crate) fn maybe_duration_from_str<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error>
346+
where
347+
D: Deserializer<'de>,
348+
{
349+
if let Ok(s) = String::deserialize(deserializer) {
350+
if let Ok(duration) = Duration::from_str(&s) {
351+
Ok(Some(duration))
352+
} else {
353+
Ok(None)
354+
}
355+
} else {
356+
Ok(None)
357+
}
358+
}
359+
330360
#[allow(clippy::upper_case_acronyms)]
331361
#[derive(Debug)]
332362
pub enum ParsingError {

src/md/events/details.rs

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*
2+
Nyx, blazing fast astrodynamics
3+
Copyright (C) 2023 Christopher Rabotin <[email protected]>
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
use crate::errors::NyxError;
20+
use crate::linalg::allocator::Allocator;
21+
use crate::linalg::DefaultAllocator;
22+
use crate::md::prelude::{Interpolatable, Traj};
23+
use crate::md::EventEvaluator;
24+
use crate::time::Duration;
25+
use core::fmt;
26+
27+
/// Enumerates the possible edges of an event in a trajectory.
28+
///
29+
/// `EventEdge` is used to describe the nature of a trajectory event, particularly in terms of its temporal dynamics relative to a specified condition or threshold. This enum helps in distinguishing whether the event is occurring at a rising edge, a falling edge, or if the edge is unclear due to insufficient data or ambiguous conditions.
30+
#[derive(Copy, Clone, Debug, PartialEq)]
31+
pub enum EventEdge {
32+
/// Represents a rising edge of the event. This indicates that the event is transitioning from a lower to a higher evaluation of the event. For example, in the context of elevation, a rising edge would indicate an increase in elevation from a lower angle.
33+
Rising,
34+
/// Represents a falling edge of the event. This is the opposite of the rising edge, indicating a transition from a higher to a lower value of the event evaluator. For example, if tracking the elevation of an object, a falling edge would signify a
35+
Falling,
36+
/// If the edge cannot be clearly defined, it will be marked as unclear. This happens if the event is at a saddle point and the epoch precision is too large to find the exact slope.
37+
Unclear,
38+
}
39+
40+
/// Represents the details of an event occurring along a trajectory.
41+
///
42+
/// `EventDetails` encapsulates the state at which a particular event occurs in a trajectory, along with additional information about the nature of the event. This struct is particularly useful for understanding the dynamics of the event, such as whether it represents a rising or falling edge, or if the edge is unclear.
43+
///
44+
/// # Generics
45+
/// S: Interpolatable - A type that represents the state of the trajectory. This type must implement the `Interpolatable` trait, ensuring that it can be interpolated and manipulated according to the trajectory's requirements.
46+
#[derive(Clone, Debug, PartialEq)]
47+
pub struct EventDetails<S: Interpolatable>
48+
where
49+
DefaultAllocator:
50+
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
51+
{
52+
/// The state of the trajectory at the found event.
53+
pub state: S,
54+
/// Indicates whether the event is a rising edge, falling edge, or unclear. This helps in understanding the direction of change at the event point.
55+
pub edge: EventEdge,
56+
/// Numerical evaluation of the event condition, e.g. if seeking the apoapsis, this returns the near zero
57+
pub value: f64,
58+
/// Numertical evaluation of the event condition one epoch step before the found event (used to compute the rising/falling edge).
59+
pub prev_value: Option<f64>,
60+
/// Numertical evaluation of the event condition one epoch step after the found event (used to compute the rising/falling edge).
61+
pub next_value: Option<f64>,
62+
/// Precision of the epoch for this value
63+
pub pm_duration: Duration,
64+
// Store the representation of this event as a string because we can't move or clone the event reference
65+
pub repr: String,
66+
}
67+
68+
impl<S: Interpolatable> EventDetails<S>
69+
where
70+
DefaultAllocator:
71+
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
72+
{
73+
/// Generates detailed information about an event at a specific epoch in a trajectory.
74+
///
75+
/// This takes an `Epoch` as an input and returns a `Result<Self, NyxError>`.
76+
/// It is designed to determine the state of a trajectory at a given epoch, evaluate the specific event at that state, and ascertain the nature of the event (rising, falling, or unclear).
77+
/// The initialization intelligently determines the edge type of the event by comparing the event's value at the current, previous, and next epochs.
78+
/// It ensures robust event characterization in trajectories.
79+
///
80+
/// # Returns
81+
/// - `Ok(EventDetails<S>)` if the state at the given epoch can be determined and the event details are successfully evaluated.
82+
/// - `Err(NyxError)` if there is an error in retrieving the state at the specified epoch.
83+
///
84+
pub fn new<E: EventEvaluator<S>>(
85+
state: S,
86+
value: f64,
87+
event: &E,
88+
traj: &Traj<S>,
89+
) -> Result<Self, NyxError> {
90+
let epoch = state.epoch();
91+
let prev_value = if let Ok(state) = traj.at(epoch - event.epoch_precision()) {
92+
Some(event.eval(&state))
93+
} else {
94+
None
95+
};
96+
97+
let next_value = if let Ok(state) = traj.at(epoch + event.epoch_precision()) {
98+
Some(event.eval(&state))
99+
} else {
100+
None
101+
};
102+
103+
let edge = if let Some(prev_value) = prev_value {
104+
if let Some(next_value) = next_value {
105+
if prev_value > value && value > next_value {
106+
EventEdge::Falling
107+
} else if prev_value < value && value < next_value {
108+
EventEdge::Rising
109+
} else {
110+
warn!("could not determine edge of {} at {}", event, state.epoch(),);
111+
EventEdge::Unclear
112+
}
113+
} else if prev_value > value {
114+
EventEdge::Falling
115+
} else {
116+
EventEdge::Rising
117+
}
118+
} else if let Some(next_value) = next_value {
119+
if next_value > value {
120+
EventEdge::Rising
121+
} else {
122+
EventEdge::Falling
123+
}
124+
} else {
125+
warn!(
126+
"could not determine edge of {} because trajectory could be queried around {}",
127+
event,
128+
state.epoch()
129+
);
130+
EventEdge::Unclear
131+
};
132+
133+
Ok(EventDetails {
134+
edge,
135+
state,
136+
value,
137+
prev_value,
138+
next_value,
139+
pm_duration: event.epoch_precision(),
140+
repr: event.eval_string(&state).to_string(),
141+
})
142+
}
143+
}
144+
145+
impl<S: Interpolatable> fmt::Display for EventDetails<S>
146+
where
147+
DefaultAllocator:
148+
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
149+
{
150+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151+
let prev_fmt = match self.prev_value {
152+
Some(value) => format!("{value:.6}"),
153+
None => "".to_string(),
154+
};
155+
156+
let next_fmt = match self.next_value {
157+
Some(value) => format!("{value:.6}"),
158+
None => "".to_string(),
159+
};
160+
161+
write!(
162+
f,
163+
"{} and is {:?} (roots with {} intervals: {}, {:.6}, {})",
164+
self.repr, self.edge, self.pm_duration, prev_fmt, self.value, next_fmt
165+
)
166+
}
167+
}
168+
169+
#[derive(Clone, Debug, PartialEq)]
170+
pub struct EventArc<S: Interpolatable>
171+
where
172+
DefaultAllocator:
173+
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
174+
{
175+
pub rise: EventDetails<S>,
176+
pub fall: EventDetails<S>,
177+
}
178+
179+
impl<S: Interpolatable> fmt::Display for EventArc<S>
180+
where
181+
DefaultAllocator:
182+
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
183+
{
184+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
185+
write!(
186+
f,
187+
"{} until {} (lasts {})",
188+
self.rise,
189+
self.fall.state.epoch(),
190+
self.fall.state.epoch() - self.rise.state.epoch()
191+
)
192+
}
193+
}

src/md/events/evaluators.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::md::StateParameter;
2424
use crate::utils::between_pm_x;
2525
use crate::{Spacecraft, State};
2626

27-
fn angled_value(cur_angle: f64, desired_angle: f64) -> f64 {
27+
pub(crate) fn angled_value(cur_angle: f64, desired_angle: f64) -> f64 {
2828
if between_pm_x(cur_angle, desired_angle) > 0.0 {
2929
cur_angle - desired_angle
3030
} else {

src/md/events/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19+
pub mod details;
1920
pub mod evaluators;
21+
pub mod search;
2022
use super::StateParameter;
2123
use crate::cosmic::{Cosm, Frame};
2224
use crate::linalg::allocator::Allocator;

0 commit comments

Comments
 (0)