brahe 1.4.0

Brahe is a modern satellite dynamics library for research and engineering applications designed to be easy-to-learn, high-performance, and quick-to-deploy. The north-star of the development is enabling users to solve meaningful problems and answer questions quickly, easily, and correctly.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
/*!
 * Access computation API
 *
 * This module provides a unified function for computing access windows
 * between satellites and ground locations. It integrates window finding,
 * constraint evaluation, and property computation with an ergonomic API
 * that accepts both single items and slices.
 */

use crate::access::constraints::AccessConstraint;
use crate::access::location::AccessibleLocation;
use crate::access::properties::AccessPropertyComputer;
use crate::access::windows::{AccessSearchConfig, AccessWindow, find_access_windows};
use crate::time::Epoch;
use crate::utils::BraheError;
use crate::utils::state_providers::{DIdentifiableStateProvider, ToPropagatorRefs};
use crate::utils::threading::get_thread_pool;
use rayon::prelude::*;

// ================================
// Conversion Traits for Ergonomic API
// ================================

/// Trait to convert various location inputs into a slice of references.
///
/// This trait enables the unified `location_accesses` function to accept
/// either single locations or slices/vectors of locations.
pub(crate) trait ToLocationRefs<L: AccessibleLocation> {
    fn to_refs(&self) -> Vec<&L>;
}

// Single location reference
impl<L: AccessibleLocation> ToLocationRefs<L> for L {
    fn to_refs(&self) -> Vec<&L> {
        vec![self]
    }
}

// Slice of locations
impl<L: AccessibleLocation> ToLocationRefs<L> for [L] {
    fn to_refs(&self) -> Vec<&L> {
        self.iter().collect()
    }
}

// Vec of locations
impl<L: AccessibleLocation> ToLocationRefs<L> for Vec<L> {
    fn to_refs(&self) -> Vec<&L> {
        self.iter().collect()
    }
}

// ================================
// Internal Computation Functions
// ================================

/// Sequential access computation (for debugging or single-threaded operation)
fn compute_accesses_sequential<L, P>(
    locations: &[&L],
    propagators: &[&P],
    search_start: Epoch,
    search_end: Epoch,
    constraint: &dyn AccessConstraint,
    property_computers: Option<&[&dyn AccessPropertyComputer]>,
    search_config: &AccessSearchConfig,
) -> Result<Vec<AccessWindow>, BraheError>
where
    L: AccessibleLocation,
    P: DIdentifiableStateProvider,
{
    let mut all_windows = Vec::new();

    for location in locations {
        for propagator in propagators {
            let mut windows = find_access_windows(
                *location,
                *propagator,
                search_start,
                search_end,
                constraint,
                property_computers,
                Some(search_config),
            )?;
            all_windows.append(&mut windows);
        }
    }

    // Sort by window start time
    all_windows.sort_by(|a, b| {
        a.window_open
            .partial_cmp(&b.window_open)
            .unwrap_or(std::cmp::Ordering::Equal)
    });

    Ok(all_windows)
}

/// Parallel access computation using rayon
fn compute_accesses_parallel<L, P>(
    locations: &[&L],
    propagators: &[&P],
    search_start: Epoch,
    search_end: Epoch,
    constraint: &dyn AccessConstraint,
    property_computers: Option<&[&dyn AccessPropertyComputer]>,
    search_config: &AccessSearchConfig,
) -> Result<Vec<AccessWindow>, BraheError>
where
    L: AccessibleLocation + Sync,
    P: DIdentifiableStateProvider + Sync,
{
    // Create all location-propagator pairs
    let pairs: Vec<(&L, &P)> = locations
        .iter()
        .flat_map(|loc| propagators.iter().map(move |prop| (*loc, *prop)))
        .collect();

    // Compute windows in parallel
    let results: Result<Vec<Vec<AccessWindow>>, BraheError> = pairs
        .par_iter()
        .map(|(location, propagator)| {
            find_access_windows(
                *location,
                *propagator,
                search_start,
                search_end,
                constraint,
                property_computers,
                Some(search_config),
            )
        })
        .collect();

    let mut all_windows: Vec<AccessWindow> = results?.into_iter().flatten().collect();

    // Sort by window start time
    all_windows.sort_by(|a, b| {
        a.window_open
            .partial_cmp(&b.window_open)
            .unwrap_or(std::cmp::Ordering::Equal)
    });

    Ok(all_windows)
}

// ================================
// Unified Access Computation API
// ================================

/// Compute access windows for locations and propagators.
///
/// This function accepts either single items or slices/vectors for both
/// locations and propagators, automatically handling the conversion.
/// All location-propagator pairs are computed and results are returned
/// sorted by window start time.
///
/// # Arguments
/// * `locations` - Single location or slice/vec of locations
/// * `propagators` - Single propagator or slice/vec of propagators
/// * `search_start` - Start of search window
/// * `search_end` - End of search window
/// * `constraint` - Access constraints to evaluate
/// * `property_computers` - Optional custom property computers
/// * `config` - Optional search configuration (time step, adaptive parameters, tolerance, subdivisions)
///
/// # Returns
/// Result containing vector of `AccessWindow` objects sorted by start time,
/// or error if property computation fails
///
/// # Examples
/// ```
/// use brahe::access::*;
/// use brahe::eop::*;
/// use brahe::propagators::KeplerianPropagator;
/// use brahe::time::{Epoch, TimeSystem};
/// use brahe::constants::R_EARTH;
/// use nalgebra::Vector6;
///
/// // Set up EOP
/// let eop = StaticEOPProvider::from_values((0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
/// set_global_eop_provider(eop);
///
/// // Create a location (latitude, longitude in degrees, altitude in meters)
/// let location = PointLocation::new(40.7128, -74.0060, 0.0);
///
/// // Create epoch and orbital state
/// let epoch = Epoch::from_datetime(2024, 1, 1, 0, 0, 0.0, 0.0, TimeSystem::UTC);
/// let state = Vector6::new(R_EARTH + 600e3, 0.0, 0.0, 0.0, 7.5e3, 0.0);
/// let propagator = KeplerianPropagator::from_eci(epoch, state, 60.0);
///
/// // Create constraint
/// let constraint = ElevationConstraint::new(Some(10.0), None).unwrap();
///
/// // Compute access windows for 24 hours
/// let windows = location_accesses(
///     &location,
///     &propagator,
///     epoch,
///     epoch + 86400.0,
///     &constraint,
///     None,
///     None,
/// ).unwrap();
///
/// // Windows contains all periods when satellite is above 10 degrees elevation
/// for window in windows {
///     println!("Access from {} to {}", window.window_open, window.window_close);
/// }
/// ```
#[allow(private_bounds)]
pub fn location_accesses<L, P, Locs, Props>(
    locations: &Locs,
    propagators: &Props,
    search_start: Epoch,
    search_end: Epoch,
    constraint: &dyn AccessConstraint,
    property_computers: Option<&[&dyn AccessPropertyComputer]>,
    config: Option<&AccessSearchConfig>,
) -> Result<Vec<AccessWindow>, BraheError>
where
    L: AccessibleLocation + Sync,
    P: DIdentifiableStateProvider + Sync,
    Locs: ToLocationRefs<L> + ?Sized,
    Props: ToPropagatorRefs<P> + ?Sized,
{
    let search_config = config.copied().unwrap_or_default();

    let loc_refs = locations.to_refs();
    let prop_refs = propagators.to_refs();

    // Process all location-propagator combinations

    if search_config.parallel {
        // Parallel computation using rayon
        if let Some(n_threads) = search_config.num_threads {
            // Use custom thread pool with specific thread count
            let pool = rayon::ThreadPoolBuilder::new()
                .num_threads(n_threads)
                .build()
                .expect("Failed to build thread pool");

            pool.install(|| {
                compute_accesses_parallel(
                    &loc_refs,
                    &prop_refs,
                    search_start,
                    search_end,
                    constraint,
                    property_computers,
                    &search_config,
                )
            })
        } else {
            // Use global thread pool (default: 90% of cores)
            get_thread_pool().install(|| {
                compute_accesses_parallel(
                    &loc_refs,
                    &prop_refs,
                    search_start,
                    search_end,
                    constraint,
                    property_computers,
                    &search_config,
                )
            })
        }
    } else {
        // Sequential computation
        compute_accesses_sequential(
            &loc_refs,
            &prop_refs,
            search_start,
            search_end,
            constraint,
            property_computers,
            &search_config,
        )
    }
}

// ================================
// Tests
// ================================

#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
    use super::*;
    use crate::access::constraints::ElevationConstraint;
    use crate::access::location::PointLocation;
    use crate::constants::{AngleFormat, R_EARTH};
    use crate::propagators::keplerian_propagator::KeplerianPropagator;
    use crate::time::TimeSystem;
    use crate::utils::testing::setup_global_test_eop;
    use nalgebra::Vector6;

    fn create_test_propagator(epoch: Epoch) -> KeplerianPropagator {
        let oe = Vector6::new(R_EARTH + 500e3, 0.0, 45.0_f64.to_radians(), 0.0, 0.0, 0.0);
        KeplerianPropagator::new(
            epoch,
            oe,
            crate::trajectories::traits::OrbitFrame::ECI,
            crate::trajectories::traits::OrbitRepresentation::Keplerian,
            Some(AngleFormat::Radians),
            60.0,
        )
    }

    #[test]
    fn test_location_accesses_single() {
        setup_global_test_eop();

        let location = PointLocation::new(45.0, 0.0, 0.0);
        let epoch = Epoch::from_datetime(2024, 1, 1, 0, 0, 0.0, 0.0, TimeSystem::UTC);
        let propagator = create_test_propagator(epoch);

        let period = 5674.0;
        let search_end = epoch + (period * 2.0);

        let constraint = ElevationConstraint::new(Some(5.0), None).unwrap();

        let config = AccessSearchConfig {
            initial_time_step: 60.0,
            adaptive_step: false,
            adaptive_fraction: 0.75,
            parallel: true,
            num_threads: None,
            time_tolerance: 0.1,
            ..Default::default()
        };

        let windows = location_accesses(
            &location,
            &propagator,
            epoch,
            search_end,
            &constraint,
            None,
            Some(&config),
        )
        .unwrap();

        // Should find at least one window
        assert!(
            !windows.is_empty(),
            "Expected at least 1 window, found {}",
            windows.len()
        );

        // Verify windows are sorted
        for i in 1..windows.len() {
            assert!(windows[i - 1].window_open <= windows[i].window_open);
        }
    }

    #[test]
    fn test_location_accesses_multiple_sats() {
        setup_global_test_eop();

        let location = PointLocation::new(45.0, 0.0, 0.0);
        let epoch = Epoch::from_datetime(2024, 1, 1, 0, 0, 0.0, 0.0, TimeSystem::UTC);

        // Create 3 propagators with different RAANs
        let propagators = vec![
            create_test_propagator(epoch),
            {
                let oe = Vector6::new(
                    R_EARTH + 500e3,
                    0.0,
                    45.0_f64.to_radians(),
                    60.0_f64.to_radians(), // Different RAAN
                    0.0,
                    0.0,
                );
                KeplerianPropagator::new(
                    epoch,
                    oe,
                    crate::trajectories::traits::OrbitFrame::ECI,
                    crate::trajectories::traits::OrbitRepresentation::Keplerian,
                    Some(AngleFormat::Radians),
                    60.0,
                )
            },
            {
                let oe = Vector6::new(
                    R_EARTH + 500e3,
                    0.0,
                    45.0_f64.to_radians(),
                    120.0_f64.to_radians(), // Different RAAN
                    0.0,
                    0.0,
                );
                KeplerianPropagator::new(
                    epoch,
                    oe,
                    crate::trajectories::traits::OrbitFrame::ECI,
                    crate::trajectories::traits::OrbitRepresentation::Keplerian,
                    Some(AngleFormat::Radians),
                    60.0,
                )
            },
        ];

        let period = 5674.0;
        let search_end = epoch + (period * 2.0);

        let constraint = ElevationConstraint::new(Some(5.0), None).unwrap();

        let config = AccessSearchConfig {
            initial_time_step: 60.0,
            adaptive_step: false,
            adaptive_fraction: 0.75,
            parallel: true,
            num_threads: None,
            time_tolerance: 0.1,
            ..Default::default()
        };

        let windows = location_accesses(
            &location,
            &propagators,
            epoch,
            search_end,
            &constraint,
            None,
            Some(&config),
        )
        .unwrap();

        // Should find windows from multiple satellites
        assert!(
            !windows.is_empty(),
            "Expected at least 1 window, found {}",
            windows.len()
        );

        // Verify windows are sorted
        for i in 1..windows.len() {
            assert!(windows[i - 1].window_open <= windows[i].window_open);
        }
    }

    #[test]
    fn test_location_accesses_multiple_locations() {
        setup_global_test_eop();

        let locations = vec![
            PointLocation::new(0.0, 45.0, 0.0),    // 45°N, 0°E (lon, lat, alt)
            PointLocation::new(-120.0, 30.0, 0.0), // 30°N, 120°W
        ];

        let epoch = Epoch::from_datetime(2024, 1, 1, 0, 0, 0.0, 0.0, TimeSystem::UTC);
        let propagator = create_test_propagator(epoch);

        let period = 5674.0;
        let search_end = epoch + (period * 3.0); // More time to ensure access to both locations

        let constraint = ElevationConstraint::new(Some(5.0), None).unwrap();

        let config = AccessSearchConfig {
            initial_time_step: 60.0,
            adaptive_step: false,
            adaptive_fraction: 0.75,
            parallel: true,
            num_threads: None,
            time_tolerance: 0.1,
            ..Default::default()
        };

        let windows = location_accesses(
            &locations,
            &propagator,
            epoch,
            search_end,
            &constraint,
            None,
            Some(&config),
        )
        .unwrap();

        // Should find windows for multiple locations
        assert!(
            !windows.is_empty(),
            "Expected at least 1 window, found {}",
            windows.len()
        );

        // Verify windows are sorted
        for i in 1..windows.len() {
            assert!(windows[i - 1].window_open <= windows[i].window_open);
        }
    }

    #[test]
    fn test_location_accesses_multiple() {
        setup_global_test_eop();

        let locations = vec![
            PointLocation::new(0.0, 45.0, 0.0),    // 45°N, 0°E (lon, lat, alt)
            PointLocation::new(-120.0, 30.0, 0.0), // 30°N, 120°W
        ];

        let epoch = Epoch::from_datetime(2024, 1, 1, 0, 0, 0.0, 0.0, TimeSystem::UTC);

        let propagators = vec![create_test_propagator(epoch), {
            let oe = Vector6::new(
                R_EARTH + 500e3,
                0.0,
                45.0_f64.to_radians(),
                60.0_f64.to_radians(),
                0.0,
                0.0,
            );
            KeplerianPropagator::new(
                epoch,
                oe,
                crate::trajectories::traits::OrbitFrame::ECI,
                crate::trajectories::traits::OrbitRepresentation::Keplerian,
                Some(AngleFormat::Radians),
                60.0,
            )
        }];

        let period = 5674.0;
        let search_end = epoch + (period * 3.0);

        let constraint = ElevationConstraint::new(Some(5.0), None).unwrap();

        let config = AccessSearchConfig {
            initial_time_step: 60.0,
            adaptive_step: false,
            adaptive_fraction: 0.75,
            parallel: true,
            num_threads: None,
            time_tolerance: 0.1,
            ..Default::default()
        };

        let windows = location_accesses(
            &locations,
            &propagators,
            epoch,
            search_end,
            &constraint,
            None,
            Some(&config),
        )
        .unwrap();

        // Should find windows for multiple location-satellite pairs
        assert!(
            !windows.is_empty(),
            "Expected at least 1 window, found {}",
            windows.len()
        );

        // Verify windows are sorted
        for i in 1..windows.len() {
            assert!(windows[i - 1].window_open <= windows[i].window_open);
        }
    }

    #[test]
    fn test_location_accesses_sequential() {
        setup_global_test_eop();

        let location = PointLocation::new(45.0, 0.0, 0.0);
        let epoch = Epoch::from_datetime(2024, 1, 1, 0, 0, 0.0, 0.0, TimeSystem::UTC);
        let propagator = create_test_propagator(epoch);

        let period = 5674.0;
        let search_end = epoch + (period * 2.0);

        let constraint = ElevationConstraint::new(Some(5.0), None).unwrap();

        // Test with parallel: false to exercise sequential code path
        let config = AccessSearchConfig {
            initial_time_step: 60.0,
            adaptive_step: false,
            adaptive_fraction: 0.75,
            parallel: false, // Use sequential computation
            num_threads: None,
            time_tolerance: 0.1,
            ..Default::default()
        };

        let windows = location_accesses(
            &location,
            &propagator,
            epoch,
            search_end,
            &constraint,
            None,
            Some(&config),
        )
        .unwrap();

        // Should find at least one window
        assert!(
            !windows.is_empty(),
            "Expected at least 1 window, found {}",
            windows.len()
        );

        // Verify windows are sorted
        for i in 1..windows.len() {
            assert!(windows[i - 1].window_open <= windows[i].window_open);
        }
    }

    #[test]
    fn test_access_identification_traceability() {
        use crate::propagators::sgp_propagator::SGPPropagator;
        use crate::utils::Identifiable;

        setup_global_test_eop();

        // -- Locations --
        let new_york = PointLocation::new(-74.006, 40.7128, 0.0)
            .with_name("NewYork")
            .with_id(1);
        let london = PointLocation::new(-0.1276, 51.5074, 0.0)
            .with_name("London")
            .with_id(2);
        let locations = vec![new_york, london];

        // -- Propagators (SGP4 from 3LE) --
        // ISS (NORAD 25544) - 2026 epoch
        let iss = SGPPropagator::from_3le(
            Some("ISS"),
            "1 25544U 98067A   26071.86901803  .00011348  00000-0  21655-3 0  9990",
            "2 25544  51.6324  56.6367 0007924 186.1410 173.9482 15.48614629556825",
            60.0,
        )
        .unwrap();
        // Hubble (NORAD 20580) - 2026 epoch
        let hubble = SGPPropagator::from_3le(
            Some("HST"),
            "1 20580U 90037B   26071.94420327  .00008743  00000-0  28877-3 0  9998",
            "2 20580  28.4723  17.7975 0001801 157.8636 202.2037 15.29540863773810",
            60.0,
        )
        .unwrap();

        // Verify default identification after construction
        assert_eq!(iss.get_name(), Some("ISS"));
        assert_eq!(iss.get_id(), Some(25544));
        assert_eq!(hubble.get_name(), Some("HST"));
        assert_eq!(hubble.get_id(), Some(20580));

        // Verify PointLocation defaults before builder methods
        let bare = PointLocation::new(0.0, 0.0, 0.0);
        assert_eq!(bare.get_name(), None);
        assert_eq!(bare.get_id(), None);
        assert!(bare.get_uuid().is_some()); // Auto-generated in constructor

        // Verify locations have identity set
        assert_eq!(locations[0].get_name(), Some("NewYork"));
        assert_eq!(locations[0].get_id(), Some(1));
        assert_eq!(locations[1].get_name(), Some("London"));
        assert_eq!(locations[1].get_id(), Some(2));

        let propagators = vec![iss, hubble];

        // -- Search window: 24 hours from a 2026 epoch --
        let search_start = Epoch::from_datetime(2026, 3, 13, 0, 0, 0.0, 0.0, TimeSystem::UTC);
        let search_end = search_start + 86400.0;

        let constraint = ElevationConstraint::new(Some(10.0), None).unwrap();

        let windows = location_accesses(
            &locations,
            &propagators,
            search_start,
            search_end,
            &constraint,
            None,
            None,
        )
        .unwrap();

        // Should find access windows
        assert!(
            !windows.is_empty(),
            "Expected at least 1 access window, found 0"
        );

        // -- Traceability assertions --
        for window in &windows {
            // Every window must have location and satellite identification
            assert!(
                window.location_name.is_some(),
                "Window missing location_name"
            );
            assert!(window.location_id.is_some(), "Window missing location_id");
            assert!(
                window.satellite_name.is_some(),
                "Window missing satellite_name"
            );
            assert!(window.satellite_id.is_some(), "Window missing satellite_id");

            let loc_id = window.location_id.unwrap();
            let sat_id = window.satellite_id.unwrap();

            // Location ID must be one of our locations
            assert!(
                loc_id == 1 || loc_id == 2,
                "Unexpected location_id: {loc_id}"
            );
            // Satellite ID must be one of our NORAD IDs
            assert!(
                sat_id == 25544 || sat_id == 20580,
                "Unexpected satellite_id: {sat_id}"
            );

            // No cross-contamination: name must match ID
            let loc_name = window.location_name.as_deref().unwrap();
            let sat_name = window.satellite_name.as_deref().unwrap();

            match loc_id {
                1 => assert_eq!(loc_name, "NewYork"),
                2 => assert_eq!(loc_name, "London"),
                _ => unreachable!(),
            }
            match sat_id {
                25544 => assert_eq!(sat_name, "ISS"),
                20580 => assert_eq!(sat_name, "HST"),
                _ => unreachable!(),
            }

            // Auto-generated window name should contain both location and satellite names
            let window_name = window.name.as_deref().unwrap();
            assert!(
                window_name.contains(loc_name),
                "Window name '{window_name}' should contain location name '{loc_name}'"
            );
            assert!(
                window_name.contains(sat_name),
                "Window name '{window_name}' should contain satellite name '{sat_name}'"
            );
            assert!(
                window_name.contains("Access"),
                "Window name '{window_name}' should contain 'Access'"
            );
        }
    }

    #[test]
    fn test_access_default_uuid_traceability() {
        use crate::utils::Identifiable;
        use std::collections::HashSet;

        setup_global_test_eop();

        // Create locations with NO explicit identity — only auto-generated UUIDs
        let loc1 = PointLocation::new(0.0, 45.0, 0.0);
        let loc2 = PointLocation::new(-120.0, 30.0, 0.0);

        // Create propagators with NO explicit name/id/uuid
        let epoch = Epoch::from_datetime(2024, 1, 1, 0, 0, 0.0, 0.0, TimeSystem::UTC);
        let prop1 = create_test_propagator(epoch);
        let prop2 = {
            let oe = Vector6::new(
                R_EARTH + 500e3,
                0.0,
                45.0_f64.to_radians(),
                60.0_f64.to_radians(),
                0.0,
                0.0,
            );
            KeplerianPropagator::new(
                epoch,
                oe,
                crate::trajectories::traits::OrbitFrame::ECI,
                crate::trajectories::traits::OrbitRepresentation::Keplerian,
                Some(AngleFormat::Radians),
                60.0,
            )
        };

        // All objects should have auto-generated UUIDs
        let loc1_uuid = loc1
            .get_uuid()
            .expect("loc1 should have auto-generated UUID");
        let loc2_uuid = loc2
            .get_uuid()
            .expect("loc2 should have auto-generated UUID");
        let prop1_uuid = prop1
            .get_uuid()
            .expect("prop1 should have auto-generated UUID");
        let prop2_uuid = prop2
            .get_uuid()
            .expect("prop2 should have auto-generated UUID");

        // All UUIDs should be unique
        let all_uuids: HashSet<_> = [loc1_uuid, loc2_uuid, prop1_uuid, prop2_uuid]
            .into_iter()
            .collect();
        assert_eq!(all_uuids.len(), 4, "All 4 UUIDs should be unique");

        let loc_uuids: HashSet<_> = [loc1_uuid, loc2_uuid].into_iter().collect();
        let sat_uuids: HashSet<_> = [prop1_uuid, prop2_uuid].into_iter().collect();

        // Compute access windows
        let period = 5674.0;
        let search_end = epoch + (period * 3.0);
        let constraint = ElevationConstraint::new(Some(5.0), None).unwrap();
        let config = AccessSearchConfig {
            initial_time_step: 60.0,
            adaptive_step: false,
            time_tolerance: 0.1,
            ..Default::default()
        };

        let windows = location_accesses(
            &vec![loc1, loc2],
            &vec![prop1, prop2],
            epoch,
            search_end,
            &constraint,
            None,
            Some(&config),
        )
        .unwrap();

        assert!(!windows.is_empty(), "Expected at least 1 access window");

        for window in &windows {
            // Every window should carry location and satellite UUIDs
            assert!(
                window.location_uuid.is_some(),
                "Window missing location_uuid"
            );
            assert!(
                window.satellite_uuid.is_some(),
                "Window missing satellite_uuid"
            );

            let loc_uuid = window.location_uuid.unwrap();
            let sat_uuid = window.satellite_uuid.unwrap();

            // UUIDs should match one of our source objects
            assert!(
                loc_uuids.contains(&loc_uuid),
                "Window location_uuid {loc_uuid} doesn't match any source location"
            );
            assert!(
                sat_uuids.contains(&sat_uuid),
                "Window satellite_uuid {sat_uuid} doesn't match any source propagator"
            );
        }

        // Group windows by satellite UUID to verify filtering works
        let unique_sat_uuids: HashSet<_> =
            windows.iter().filter_map(|w| w.satellite_uuid).collect();
        assert!(
            !unique_sat_uuids.is_empty(),
            "Should be able to group windows by satellite UUID"
        );

        // Group windows by location UUID
        let unique_loc_uuids: HashSet<_> = windows.iter().filter_map(|w| w.location_uuid).collect();
        assert!(
            !unique_loc_uuids.is_empty(),
            "Should be able to group windows by location UUID"
        );
    }
}