Skip to main content

hpr_forensics/synthetic/
smoothed.rs

1//! The smoother held to the synthetic flights' truth ([M7.2d][m7-2d]): each flight's own log
2//! smoothed, its height and vertical speed compared with the truth's at four moments, and the
3//! share of flights whose truth falls outside the smoother's 90% interval on each side counted.
4//!
5//! **The moments**, on the truth's clock: burnout, the top vertical speed, apogee, and one moment
6//! drawn per flight, uniformly between liftoff and landing, on a stream of its own
7//! ([`moment_drawn`]). Each flight gives one comparison a moment, so the flights' comparisons are
8//! independent. The truth is the center of mass's height above where it stood at launch and its
9//! vertical speed (`truth`'s module).
10//!
11//! **Holding** ([ADR-300][adr-300]): a 90% interval misses about 5% of the time on each side. For
12//! each state and moment, each side's misses are counted over a set's smoothed flights, and the
13//! smoother holds there when that count's two-sided 99.9% Clopper–Pearson interval reaches down to
14//! 5%: the flights don't show it misses more often than it says. An interval wider than it needs
15//! to be holds; one that misses too often doesn't.
16//!
17//! [m7-2d]: https://hpr.fusionspace.co/decisions-and-roadmap.html#m7-2d
18//! [adr-300]: https://github.com/nrdptel/fusionspace-eridanus/blob/main/docs/decisions/0300-the-smoother-and-its-check.md
19
20use std::collections::BTreeMap;
21
22use hpr_core::random::SeededRng;
23use hpr_flightdata::log::{FlightLog, Quantity};
24use hpr_flightdata::smoother::{self, Deweighted, Health, INTERVAL_Z, Options, Reason, Sensor};
25use serde::{Deserialize, Serialize};
26
27use super::logger::Profile;
28use super::{Flight, Set};
29
30/// The moments the smoother is checked at.
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
32#[serde(rename_all = "kebab-case")]
33pub enum Moment {
34    /// The motor's burnout.
35    Burnout,
36    /// The top vertical speed.
37    TopSpeed,
38    /// Apogee.
39    Apogee,
40    /// A moment drawn uniformly between liftoff and landing.
41    Drawn,
42}
43
44impl Moment {
45    /// Every moment.
46    pub const ALL: [Self; 4] = [Self::Burnout, Self::TopSpeed, Self::Apogee, Self::Drawn];
47
48    /// Its name.
49    pub fn name(self) -> &'static str {
50        match self {
51            Self::Burnout => "burnout",
52            Self::TopSpeed => "top speed",
53            Self::Apogee => "apogee",
54            Self::Drawn => "a drawn moment",
55        }
56    }
57}
58
59/// The smoothed states.
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
61#[serde(rename_all = "kebab-case")]
62pub enum StateName {
63    /// The height above the pad.
64    Height,
65    /// The vertical speed.
66    Speed,
67}
68
69impl StateName {
70    /// Both.
71    pub const ALL: [Self; 2] = [Self::Height, Self::Speed];
72
73    /// Its name.
74    pub fn name(self) -> &'static str {
75        match self {
76            Self::Height => "height",
77            Self::Speed => "speed",
78        }
79    }
80}
81
82/// One comparison: the smoothed value less the truth, and the smoother's standard error.
83#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
84pub struct Compared {
85    /// The smoothed value less the truth.
86    pub error: f64,
87    /// The smoother's standard error.
88    pub sd: f64,
89}
90
91impl Compared {
92    /// Whether the truth lies below the 90% interval (the smoother reads high).
93    pub fn truth_below(&self) -> bool {
94        !self.finite() || self.error > INTERVAL_Z * self.sd
95    }
96
97    /// Whether it lies above.
98    pub fn truth_above(&self) -> bool {
99        !self.finite() || -self.error > INTERVAL_Z * self.sd
100    }
101
102    /// Whether the error and its standard error are both numbers: one that isn't misses on both
103    /// sides, as a NaN compares false and would otherwise count as held.
104    fn finite(&self) -> bool {
105        self.error.is_finite() && self.sd.is_finite()
106    }
107}
108
109/// One flight's check.
110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
111pub struct Checked {
112    /// Its logger.
113    pub profile: Profile,
114    /// Why its log wasn't smoothed; `None` if it was.
115    pub withheld: Option<Reason>,
116    /// Each moment and state, compared.
117    pub compared: Vec<(Moment, StateName, Compared)>,
118    /// Its health card; `None` if it was withheld.
119    pub health: Option<Health>,
120    /// Whether its log has a GNSS track.
121    pub has_gnss: bool,
122}
123
124/// The moment drawn for flight `index` of `set`, s on the truth's clock, uniformly between
125/// `liftoff_s` and `landing_s`, on a stream keyed by the set's seed, the index and the
126/// smoother's own key, so no other draw moves.
127pub fn moment_drawn(set: Set, index: u64, liftoff_s: f64, landing_s: f64) -> f64 {
128    let mut rng = SeededRng::for_stream(set.seed(), &[index, super::SMOOTHER_MOMENT_KEY]);
129    liftoff_s + rng.uniform() * (landing_s - liftoff_s)
130}
131
132/// The flight's own log as a logger that writes only from launch would have written it ([#982]):
133/// every sample of every sensor before the truth's liftoff is gone, the clock and the logger's zero
134/// as they were. A track of pressures has no zero without its pad and is withheld, as a real one is.
135///
136/// [#982]: https://github.com/nrdptel/fusionspace-eridanus/issues/982
137pub fn launch_started(flight: &Flight) -> FlightLog {
138    let from_s = flight.draw.logger.pad_s + flight.truth.events.liftoff_s;
139    let mut log = flight.log.clone();
140    let first = log.time_s.partition_point(|t| *t < from_s);
141    log.time_s.drain(..first);
142    if !log.altitude_m.is_empty() {
143        log.altitude_m.drain(..first);
144    }
145    for channel in &mut log.channels {
146        let first = channel.time_s.partition_point(|t| *t < from_s);
147        channel.time_s.drain(..first);
148        channel.values.drain(..first);
149    }
150    log
151}
152
153/// Checks one flight's smoothed log against its truth.
154pub fn check(flight: &Flight, options: Options) -> Checked {
155    check_log(flight, &flight.log, options)
156}
157
158/// Checks a log of `flight`, its own or one written from it, against the flight's truth.
159pub fn check_log(flight: &Flight, log: &FlightLog, options: Options) -> Checked {
160    let profile = flight.draw.logger.profile;
161    let has_gnss = log
162        .channels
163        .iter()
164        .any(|c| c.quantity == Quantity::GnssAltitude);
165    let smoothed = match smoother::smooth_with(log, &hpr_flightdata::readings::read(log), options) {
166        Ok(smoothed) => smoothed,
167        Err(withheld) => {
168            return Checked {
169                profile,
170                withheld: Some(withheld.reason),
171                compared: Vec::new(),
172                health: None,
173                has_gnss,
174            };
175        }
176    };
177    let truth = &flight.truth;
178    let events = &truth.events;
179    let moments = [
180        (Moment::Burnout, events.burnout_s),
181        (Moment::TopSpeed, truth.top_speed().1),
182        (Moment::Apogee, events.apogee_s),
183        (
184            Moment::Drawn,
185            moment_drawn(
186                flight.draw.set,
187                flight.draw.index,
188                events.liftoff_s,
189                events.landing_s,
190            ),
191        ),
192    ];
193    let mut compared = Vec::new();
194    for (moment, t) in moments {
195        let (Some(true_state), Some(state)) =
196            (truth.at(t), smoothed.at(t + flight.draw.logger.pad_s))
197        else {
198            // A moment the smoothed track doesn't reach misses on both sides, so every smoothed
199            // flight counts in every cell.
200            for state in StateName::ALL {
201                compared.push((
202                    moment,
203                    state,
204                    Compared {
205                        error: f64::NAN,
206                        sd: f64::NAN,
207                    },
208                ));
209            }
210            continue;
211        };
212        compared.push((
213            moment,
214            StateName::Height,
215            Compared {
216                error: state.height_m - (true_state.height_m - truth.pad_height_m),
217                sd: state.height_sd_m,
218            },
219        ));
220        compared.push((
221            moment,
222            StateName::Speed,
223            Compared {
224                error: state.speed_m_s - true_state.vertical_speed_m_s,
225                sd: state.speed_sd_m_s,
226            },
227        ));
228    }
229    Checked {
230        profile,
231        withheld: None,
232        compared,
233        health: Some(smoothed.health),
234        has_gnss,
235    }
236}
237
238/// One state at one moment over a set's flights.
239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
240pub struct Cell {
241    /// The moment.
242    pub moment: Moment,
243    /// The state.
244    pub state: StateName,
245    /// The flights compared.
246    pub flights: u64,
247    /// Those whose truth lay below the interval.
248    pub below: u64,
249    /// Those whose truth lay above it.
250    pub above: u64,
251    /// The share inside it.
252    pub coverage: f64,
253    /// The lower edge of the 99.9% Clopper–Pearson interval on each side's miss share: below,
254    /// then above.
255    pub lowest_miss_share: [f64; 2],
256    /// Whether it has flights and neither side is shown to miss more than 5%.
257    pub holds: bool,
258    /// The median standard error, in the state's unit.
259    pub median_sd: f64,
260    /// The largest, in the state's unit: an interval can hold by being too wide to say anything.
261    pub largest_sd: f64,
262}
263
264/// A set's check.
265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
266pub struct SetCheck {
267    /// The flights checked.
268    pub flights: u64,
269    /// Those withheld, by reason.
270    pub withheld: BTreeMap<String, u64>,
271    /// Every moment and state.
272    pub cells: Vec<Cell>,
273    /// The same, per logger.
274    pub by_logger: BTreeMap<String, Vec<Cell>>,
275    /// The smoothed flights' health cards, summed.
276    pub health: HealthTally,
277}
278
279/// One sensor's health over a set's smoothed flights.
280#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
281pub struct SensorTally {
282    /// The logs that have it.
283    pub logs: u64,
284    /// Its samples.
285    pub samples: u64,
286    /// Those the gate rejected.
287    pub rejected: u64,
288    /// Those not weighed.
289    pub unweighed: u64,
290    /// How many times it was taken back after a second of rejections.
291    pub resets: u64,
292    /// The logs with at least one rejection.
293    pub logs_rejecting: u64,
294}
295
296/// A set's health cards, summed.
297#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
298pub struct HealthTally {
299    /// Each sensor, by [`Sensor::name`].
300    pub sensors: BTreeMap<String, SensorTally>,
301    /// The spans the barometer was de-weighted over as transonic.
302    pub transonic_spans: u64,
303    /// Those after a charge.
304    pub charge_spans: u64,
305    /// The logs whose GNSS receiver was trusted at some point.
306    pub gnss_trusted: u64,
307    /// The steps the pass back couldn't solve, over every log.
308    pub unsmoothed_steps: u64,
309    /// The logs smoothed.
310    pub logs: u64,
311    /// Those on an assumed pad.
312    pub assumed_pad: u64,
313    /// Those whose accelerometer was set aside.
314    pub accelerometer_set_aside: u64,
315    /// Those whose smoothed apogee passes the reading's bound.
316    pub apogee_past_reading_bound: u64,
317}
318
319impl HealthTally {
320    fn add(&mut self, health: &Health) {
321        for s in &health.sensors {
322            let t = self.sensors.entry(s.sensor.name().to_owned()).or_default();
323            t.logs += 1;
324            t.samples += s.samples as u64;
325            t.rejected += s.rejected as u64;
326            t.unweighed += s.unweighed as u64;
327            t.resets += s.resets as u64;
328            t.logs_rejecting += u64::from(s.rejected > 0);
329        }
330        for span in &health.deweighted {
331            match span.why {
332                Deweighted::Transonic => self.transonic_spans += 1,
333                Deweighted::Charge => self.charge_spans += 1,
334            }
335        }
336        let has_gnss = health.sensors.iter().any(|s| s.sensor == Sensor::Gnss);
337        self.gnss_trusted += u64::from(has_gnss && health.gnss_trusted_s.is_some());
338        self.unsmoothed_steps += health.unsmoothed_steps as u64;
339        self.logs += 1;
340        self.assumed_pad += u64::from(health.assumed_pad);
341        self.accelerometer_set_aside += u64::from(health.accelerometer_set_aside);
342        self.apogee_past_reading_bound += u64::from(health.apogee_past_reading_bound);
343    }
344}
345
346impl SetCheck {
347    /// The logs withheld for a reason other than having no barometer: a log the smoother can't
348    /// finish would otherwise leave every cell, its misses with it, so each one fails the check.
349    pub fn lost(&self) -> u64 {
350        let no_barometer = format!("{:?}", Reason::NoBarometer);
351        self.withheld
352            .iter()
353            .filter(|(reason, _)| **reason != no_barometer)
354            .map(|(_, n)| n)
355            .sum()
356    }
357
358    /// Whether every cell holds, the set's and each logger's, and no log was [`lost`](Self::lost).
359    pub fn holds(&self) -> bool {
360        self.lost() == 0
361            && self
362                .cells
363                .iter()
364                .chain(self.by_logger.values().flatten())
365                .all(|c| c.holds)
366    }
367}
368
369/// The confidence of the band on a miss share.
370pub const BAND_CONFIDENCE: f64 = 0.999;
371
372/// The miss share each side of a 90% interval allows.
373pub const MISS_SHARE: f64 = 0.05;
374
375/// `ln k!`.
376fn ln_factorial(k: u64) -> f64 {
377    (2..=k).map(|i| (i as f64).ln()).sum()
378}
379
380/// `P(X ≥ x)` for `X ~ Binomial(n, p)`.
381fn upper_tail(x: u64, n: u64, p: f64) -> f64 {
382    if x == 0 {
383        return 1.0;
384    }
385    if p <= 0.0 {
386        return 0.0;
387    }
388    if p >= 1.0 {
389        return 1.0;
390    }
391    let ln_n = ln_factorial(n);
392    let (lp, lq) = (p.ln(), (1.0 - p).ln());
393    let mut ln_k = 0.0;
394    let mut below = 0.0;
395    for k in 0..x {
396        if k > 0 {
397            ln_k += (k as f64).ln();
398        }
399        let ln_choose = ln_n - ln_k - ln_factorial(n - k);
400        below += (ln_choose + k as f64 * lp + (n - k) as f64 * lq).exp();
401    }
402    (1.0 - below).max(0.0)
403}
404
405/// The lower edge of the two-sided Clopper–Pearson interval on a binomial share, at `confidence`:
406/// the `p` at which `P(X ≥ x) = (1 − confidence)/2`, by bisection; 0 when `x` is 0 (C. J. Clopper
407/// and E. S. Pearson, *Biometrika* 26(4), 404–413, 1934). NaN, which no cell holds on, when `x`
408/// exceeds `n` or `confidence` isn't strictly between 0 and 1.
409pub fn clopper_pearson_lower(x: u64, n: u64, confidence: f64) -> f64 {
410    if x > n || !(confidence > 0.0 && confidence < 1.0) {
411        return f64::NAN;
412    }
413    if x == 0 {
414        return 0.0;
415    }
416    let target = 0.5 * (1.0 - confidence);
417    let (mut lo, mut hi) = (0.0_f64, x as f64 / n as f64);
418    for _ in 0..200 {
419        let mid = 0.5 * (lo + hi);
420        if upper_tail(x, n, mid) < target {
421            lo = mid;
422        } else {
423            hi = mid;
424        }
425    }
426    0.5 * (lo + hi)
427}
428
429/// The upper edge of the two-sided Clopper–Pearson interval on a binomial share at `confidence`,
430/// `1 −` the lower edge of the share of the other outcome; 1 when `x` is `n`. NaN where
431/// [`clopper_pearson_lower`] is.
432pub fn clopper_pearson_upper(x: u64, n: u64, confidence: f64) -> f64 {
433    if x > n {
434        return f64::NAN;
435    }
436    1.0 - clopper_pearson_lower(n - x, n, confidence)
437}
438
439fn cell(moment: Moment, state: StateName, compared: &[Compared]) -> Cell {
440    let flights = compared.len() as u64;
441    let below = compared.iter().filter(|c| c.truth_below()).count() as u64;
442    let above = compared.iter().filter(|c| c.truth_above()).count() as u64;
443    // Counted apart: a comparison that isn't a number misses on both sides.
444    let inside = compared
445        .iter()
446        .filter(|c| !c.truth_below() && !c.truth_above())
447        .count() as u64;
448    let lowest = [
449        clopper_pearson_lower(below, flights, BAND_CONFIDENCE),
450        clopper_pearson_lower(above, flights, BAND_CONFIDENCE),
451    ];
452    let mut sds: Vec<f64> = compared.iter().map(|c| c.sd).collect();
453    sds.sort_by(f64::total_cmp);
454    let median_sd = if sds.is_empty() {
455        f64::NAN
456    } else {
457        sds[sds.len() / 2]
458    };
459    let largest_sd = sds.last().copied().unwrap_or(f64::NAN);
460    Cell {
461        moment,
462        state,
463        flights,
464        below,
465        above,
466        coverage: if flights == 0 {
467            f64::NAN
468        } else {
469            inside as f64 / flights as f64
470        },
471        lowest_miss_share: lowest,
472        // A cell of no flights shows nothing.
473        holds: flights > 0 && lowest.iter().all(|&l| l <= MISS_SHARE),
474        median_sd,
475        largest_sd,
476    }
477}
478
479fn cells(checks: &[&Checked]) -> Vec<Cell> {
480    let mut out = Vec::new();
481    for moment in Moment::ALL {
482        for state in StateName::ALL {
483            let compared: Vec<Compared> = checks
484                .iter()
485                .flat_map(|c| c.compared.iter())
486                .filter(|(m, s, _)| *m == moment && *s == state)
487                .map(|(_, _, c)| *c)
488                .collect();
489            out.push(cell(moment, state, &compared));
490        }
491    }
492    out
493}
494
495/// A set's check from its flights' checks.
496pub fn tally(checks: &[Checked]) -> SetCheck {
497    let mut withheld = BTreeMap::new();
498    for check in checks {
499        if let Some(reason) = check.withheld {
500            *withheld.entry(format!("{reason:?}")).or_insert(0) += 1;
501        }
502    }
503    let all: Vec<&Checked> = checks.iter().collect();
504    let mut by_logger = BTreeMap::new();
505    for profile in Profile::ALL {
506        let mine: Vec<&Checked> = checks
507            .iter()
508            .filter(|c| c.profile == profile && c.withheld.is_none())
509            .collect();
510        if !mine.is_empty() {
511            by_logger.insert(profile.name().to_owned(), cells(&mine));
512        }
513    }
514    let mut health = HealthTally::default();
515    for h in checks.iter().filter_map(|c| c.health.as_ref()) {
516        health.add(h);
517    }
518    SetCheck {
519        flights: checks.len() as u64,
520        withheld,
521        cells: cells(&all),
522        by_logger,
523        health,
524    }
525}
526
527#[cfg(test)]
528mod tests {
529    use super::*;
530
531    #[test]
532    fn clopper_pearson_matches_the_definition() {
533        // The lower edges from the definition, `P(X ≥ x) = (1 − confidence)/2`, with exact integer
534        // binomial coefficients in 60-digit decimal arithmetic (Python's `math.comb`, `decimal`).
535        let lower = clopper_pearson_lower(5, 100, 0.95);
536        assert!((lower - 0.016_431_879).abs() < 1e-8, "{lower}");
537        let lower = clopper_pearson_lower(50, 1000, 0.999);
538        assert!((lower - 0.030_238_692).abs() < 1e-8, "{lower}");
539        let lower = clopper_pearson_lower(75, 1000, 0.999);
540        assert!((lower - 0.050_351_908).abs() < 1e-8, "{lower}");
541        assert_eq!(clopper_pearson_lower(0, 1000, 0.999), 0.0);
542        // More misses than flights, or a confidence that isn't one, has no edge.
543        assert!(clopper_pearson_lower(5, 3, 0.999).is_nan());
544        assert!(clopper_pearson_lower(1, 0, 0.999).is_nan());
545        assert!(clopper_pearson_lower(5, 100, f64::NAN).is_nan());
546        assert!(clopper_pearson_lower(5, 100, 1.0).is_nan());
547        assert!(clopper_pearson_lower(5, 100, 0.0).is_nan());
548    }
549
550    #[test]
551    fn the_upper_edge_mirrors_the_lower_one() {
552        // ADR-257 §1: at 1,000 flights a tail passes with 29 to 74 misses, its band holding 5%.
553        let holds = |x| {
554            clopper_pearson_lower(x, 1000, 0.999) <= 0.05
555                && 0.05 <= clopper_pearson_upper(x, 1000, 0.999)
556        };
557        assert!(!holds(28) && holds(29) && holds(74) && !holds(75));
558        // ADR-308 §3: at set A's 820 readings, 22 to 63.
559        let holds_820 = |x| {
560            clopper_pearson_lower(x, 820, 0.999) <= 0.05
561                && 0.05 <= clopper_pearson_upper(x, 820, 0.999)
562        };
563        assert!(!holds_820(21) && holds_820(22) && holds_820(63) && !holds_820(64));
564        // And at set B's 845, 23 to 64.
565        let holds_845 = |x| {
566            clopper_pearson_lower(x, 845, 0.999) <= 0.05
567                && 0.05 <= clopper_pearson_upper(x, 845, 0.999)
568        };
569        assert!(!holds_845(22) && holds_845(23) && holds_845(64) && !holds_845(65));
570        assert_eq!(clopper_pearson_upper(1000, 1000, 0.999), 1.0);
571        assert!(clopper_pearson_upper(5, 3, 0.999).is_nan());
572    }
573
574    #[test]
575    fn a_log_withheld_with_a_barometer_fails_the_check() {
576        let inside = Compared {
577            error: 0.0,
578            sd: 1.0,
579        };
580        let smoothed = |profile: Profile| Checked {
581            profile,
582            withheld: None,
583            compared: Moment::ALL
584                .iter()
585                .flat_map(|&m| StateName::ALL.iter().map(move |&s| (m, s, inside)))
586                .collect(),
587            health: None,
588            has_gnss: false,
589        };
590        let withheld = |profile: Profile, reason: Reason| Checked {
591            profile,
592            withheld: Some(reason),
593            compared: Vec::new(),
594            health: None,
595            has_gnss: false,
596        };
597        let profile = Profile::ALL[0];
598        let mut checks: Vec<Checked> = (0..100).map(|_| smoothed(profile)).collect();
599        checks.push(withheld(profile, Reason::NoBarometer));
600        let set = tally(&checks);
601        assert_eq!(set.lost(), 0);
602        assert!(set.holds());
603        for reason in [Reason::Diverged, Reason::NoLiftoff, Reason::TooLong] {
604            let mut lost = checks.clone();
605            lost.push(withheld(profile, reason));
606            let set = tally(&lost);
607            assert_eq!(set.lost(), 1, "{reason:?}");
608            // Every cell still holds: the log left them, which is what the check must catch.
609            assert!(set.cells.iter().all(|c| c.holds), "{reason:?}");
610            assert!(!set.holds(), "{reason:?}");
611        }
612    }
613
614    #[test]
615    fn a_cell_holds_until_its_misses_show_more_than_five_percent() {
616        let make = |misses: usize| -> Vec<Compared> {
617            (0..1000)
618                .map(|k| Compared {
619                    error: if k < misses { 2.0 } else { 0.0 },
620                    sd: 1.0,
621                })
622                .collect()
623        };
624        assert!(cell(Moment::Apogee, StateName::Height, &make(50)).holds);
625        // 74 misses in 1,000: the band's lower edge 0.0495; 75: 0.0504.
626        assert!(cell(Moment::Apogee, StateName::Height, &make(74)).holds);
627        assert!(!cell(Moment::Apogee, StateName::Height, &make(75)).holds);
628    }
629
630    #[test]
631    fn a_comparison_that_isnt_a_number_misses_and_an_empty_cell_shows_nothing() {
632        let nan = Compared {
633            error: f64::NAN,
634            sd: 1.0,
635        };
636        let inside = Compared {
637            error: 0.0,
638            sd: 1.0,
639        };
640        let c = cell(Moment::Apogee, StateName::Height, &[nan, inside, inside]);
641        assert_eq!((c.flights, c.below, c.above), (3, 1, 1));
642        assert!((c.coverage - 2.0 / 3.0).abs() < 1e-12, "{}", c.coverage);
643        assert!(!cell(Moment::Apogee, StateName::Height, &[]).holds);
644    }
645}