saal 0.1.0

Wrappers for the Standardized Astrodynamics Algorithms Library (SAAL)
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
use pyo3::prelude::*;
use pyo3::PyTypeInfo;

use crate::enums::{
    AssociationStatus, B3Type, Classification, DuplicateKeyMode, ElsetKeyMode, ElementType,
    FundamentalCatalog, KeyMode, KeyOrder, PositionInTrack, SGP4OutputEphemerisFrame, TLEType,
};

#[pyclass(name = "KeyMode", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyKeyMode {
    NoDuplicates,
    DirectMemoryAccess,
}

impl From<PyKeyMode> for KeyMode {
    fn from(value: PyKeyMode) -> Self {
        match value {
            PyKeyMode::NoDuplicates => KeyMode::NoDuplicates,
            PyKeyMode::DirectMemoryAccess => KeyMode::DirectMemoryAccess,
        }
    }
}

impl From<KeyMode> for PyKeyMode {
    fn from(value: KeyMode) -> Self {
        match value {
            KeyMode::NoDuplicates => PyKeyMode::NoDuplicates,
            KeyMode::DirectMemoryAccess => PyKeyMode::DirectMemoryAccess,
        }
    }
}

#[pymethods]
impl PyKeyMode {
    fn __int__(&self) -> i32 {
        match self {
            PyKeyMode::NoDuplicates => KeyMode::NoDuplicates as i32,
            PyKeyMode::DirectMemoryAccess => KeyMode::DirectMemoryAccess as i32,
        }
    }
}

#[pyclass(name = "KeyOrder", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyKeyOrder {
    Ascending,
    Descending,
    Fastest,
    LoadTime,
}

impl From<PyKeyOrder> for KeyOrder {
    fn from(value: PyKeyOrder) -> Self {
        match value {
            PyKeyOrder::Ascending => KeyOrder::Ascending,
            PyKeyOrder::Descending => KeyOrder::Descending,
            PyKeyOrder::Fastest => KeyOrder::Fastest,
            PyKeyOrder::LoadTime => KeyOrder::LoadTime,
        }
    }
}

impl From<KeyOrder> for PyKeyOrder {
    fn from(value: KeyOrder) -> Self {
        match value {
            KeyOrder::Ascending => PyKeyOrder::Ascending,
            KeyOrder::Descending => PyKeyOrder::Descending,
            KeyOrder::Fastest => PyKeyOrder::Fastest,
            KeyOrder::LoadTime => PyKeyOrder::LoadTime,
        }
    }
}

#[pymethods]
impl PyKeyOrder {
    fn __int__(&self) -> i32 {
        match self {
            PyKeyOrder::Ascending => KeyOrder::Ascending as i32,
            PyKeyOrder::Descending => KeyOrder::Descending as i32,
            PyKeyOrder::Fastest => KeyOrder::Fastest as i32,
            PyKeyOrder::LoadTime => KeyOrder::LoadTime as i32,
        }
    }
}

#[pyclass(name = "DuplicateKeyMode", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyDuplicateKeyMode {
    ReturnZero,
    ReturnKey,
}

impl From<PyDuplicateKeyMode> for DuplicateKeyMode {
    fn from(value: PyDuplicateKeyMode) -> Self {
        match value {
            PyDuplicateKeyMode::ReturnZero => DuplicateKeyMode::ReturnZero,
            PyDuplicateKeyMode::ReturnKey => DuplicateKeyMode::ReturnKey,
        }
    }
}

impl From<DuplicateKeyMode> for PyDuplicateKeyMode {
    fn from(value: DuplicateKeyMode) -> Self {
        match value {
            DuplicateKeyMode::ReturnZero => PyDuplicateKeyMode::ReturnZero,
            DuplicateKeyMode::ReturnKey => PyDuplicateKeyMode::ReturnKey,
        }
    }
}

#[pymethods]
impl PyDuplicateKeyMode {
    fn __int__(&self) -> i32 {
        match self {
            PyDuplicateKeyMode::ReturnZero => DuplicateKeyMode::ReturnZero as i32,
            PyDuplicateKeyMode::ReturnKey => DuplicateKeyMode::ReturnKey as i32,
        }
    }
}

#[pyclass(name = "ElsetKeyMode", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyElsetKeyMode {
    NoDuplicates,
    DirectMemoryAccess,
}

impl From<PyElsetKeyMode> for ElsetKeyMode {
    fn from(value: PyElsetKeyMode) -> Self {
        match value {
            PyElsetKeyMode::NoDuplicates => ElsetKeyMode::NoDuplicates,
            PyElsetKeyMode::DirectMemoryAccess => ElsetKeyMode::DirectMemoryAccess,
        }
    }
}

impl From<ElsetKeyMode> for PyElsetKeyMode {
    fn from(value: ElsetKeyMode) -> Self {
        match value {
            ElsetKeyMode::NoDuplicates => PyElsetKeyMode::NoDuplicates,
            ElsetKeyMode::DirectMemoryAccess => PyElsetKeyMode::DirectMemoryAccess,
        }
    }
}

#[pymethods]
impl PyElsetKeyMode {
    fn __int__(&self) -> i32 {
        match self {
            PyElsetKeyMode::NoDuplicates => ElsetKeyMode::NoDuplicates as i32,
            PyElsetKeyMode::DirectMemoryAccess => ElsetKeyMode::DirectMemoryAccess as i32,
        }
    }
}

#[pyclass(name = "ElementType", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyElementType {
    TwoLineSGP,
    TwoLineSGP4,
    TwoLineSP,
    SPVector,
    VCM,
    Ephemeris,
    TwoLineXP,
}

impl From<PyElementType> for ElementType {
    fn from(value: PyElementType) -> Self {
        match value {
            PyElementType::TwoLineSGP => ElementType::TwoLineSGP,
            PyElementType::TwoLineSGP4 => ElementType::TwoLineSGP4,
            PyElementType::TwoLineSP => ElementType::TwoLineSP,
            PyElementType::SPVector => ElementType::SPVector,
            PyElementType::VCM => ElementType::VCM,
            PyElementType::Ephemeris => ElementType::Ephemeris,
            PyElementType::TwoLineXP => ElementType::TwoLineXP,
        }
    }
}

impl From<ElementType> for PyElementType {
    fn from(value: ElementType) -> Self {
        match value {
            ElementType::TwoLineSGP => PyElementType::TwoLineSGP,
            ElementType::TwoLineSGP4 => PyElementType::TwoLineSGP4,
            ElementType::TwoLineSP => PyElementType::TwoLineSP,
            ElementType::SPVector => PyElementType::SPVector,
            ElementType::VCM => PyElementType::VCM,
            ElementType::Ephemeris => PyElementType::Ephemeris,
            ElementType::TwoLineXP => PyElementType::TwoLineXP,
        }
    }
}

#[pymethods]
impl PyElementType {
    fn __int__(&self) -> i32 {
        match self {
            PyElementType::TwoLineSGP => ElementType::TwoLineSGP as i32,
            PyElementType::TwoLineSGP4 => ElementType::TwoLineSGP4 as i32,
            PyElementType::TwoLineSP => ElementType::TwoLineSP as i32,
            PyElementType::SPVector => ElementType::SPVector as i32,
            PyElementType::VCM => ElementType::VCM as i32,
            PyElementType::Ephemeris => ElementType::Ephemeris as i32,
            PyElementType::TwoLineXP => ElementType::TwoLineXP as i32,
        }
    }
}

#[pyclass(name = "TLEType", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyTleType {
    SGP,
    SGP4,
    SP,
    XP,
}

impl From<PyTleType> for TLEType {
    fn from(value: PyTleType) -> Self {
        match value {
            PyTleType::SGP => TLEType::SGP,
            PyTleType::SGP4 => TLEType::SGP4,
            PyTleType::SP => TLEType::SP,
            PyTleType::XP => TLEType::XP,
        }
    }
}

impl From<TLEType> for PyTleType {
    fn from(value: TLEType) -> Self {
        match value {
            TLEType::SGP => PyTleType::SGP,
            TLEType::SGP4 => PyTleType::SGP4,
            TLEType::SP => PyTleType::SP,
            TLEType::XP => PyTleType::XP,
        }
    }
}

#[pymethods]
impl PyTleType {
    fn __int__(&self) -> i32 {
        match self {
            PyTleType::SGP => TLEType::SGP as i32,
            PyTleType::SGP4 => TLEType::SGP4 as i32,
            PyTleType::SP => TLEType::SP as i32,
            PyTleType::XP => TLEType::XP as i32,
        }
    }
}

#[pyclass(name = "Classification", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyClassification {
    Unclassified,
    Confidential,
    Secret,
}

impl From<PyClassification> for Classification {
    fn from(value: PyClassification) -> Self {
        match value {
            PyClassification::Unclassified => Classification::Unclassified,
            PyClassification::Confidential => Classification::Confidential,
            PyClassification::Secret => Classification::Secret,
        }
    }
}

impl From<Classification> for PyClassification {
    fn from(value: Classification) -> Self {
        match value {
            Classification::Unclassified => PyClassification::Unclassified,
            Classification::Confidential => PyClassification::Confidential,
            Classification::Secret => PyClassification::Secret,
        }
    }
}

#[pymethods]
impl PyClassification {
    fn __int__(&self) -> i32 {
        match self {
            PyClassification::Unclassified => Classification::Unclassified as i32,
            PyClassification::Confidential => Classification::Confidential as i32,
            PyClassification::Secret => Classification::Secret as i32,
        }
    }
}

#[pyclass(name = "B3Type", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyB3Type {
    Zero,
    One,
    Two,
    Three,
    Four,
    Five,
    Six,
    Eight,
    Nine,
}

impl From<PyB3Type> for B3Type {
    fn from(value: PyB3Type) -> Self {
        match value {
            PyB3Type::Zero => B3Type::Zero,
            PyB3Type::One => B3Type::One,
            PyB3Type::Two => B3Type::Two,
            PyB3Type::Three => B3Type::Three,
            PyB3Type::Four => B3Type::Four,
            PyB3Type::Five => B3Type::Five,
            PyB3Type::Six => B3Type::Six,
            PyB3Type::Eight => B3Type::Eight,
            PyB3Type::Nine => B3Type::Nine,
        }
    }
}

impl From<B3Type> for PyB3Type {
    fn from(value: B3Type) -> Self {
        match value {
            B3Type::Zero => PyB3Type::Zero,
            B3Type::One => PyB3Type::One,
            B3Type::Two => PyB3Type::Two,
            B3Type::Three => PyB3Type::Three,
            B3Type::Four => PyB3Type::Four,
            B3Type::Five => PyB3Type::Five,
            B3Type::Six => PyB3Type::Six,
            B3Type::Eight => PyB3Type::Eight,
            B3Type::Nine => PyB3Type::Nine,
        }
    }
}

#[pymethods]
impl PyB3Type {
    fn __int__(&self) -> i32 {
        let value: B3Type = (*self).into();
        i8::from(value) as i32
    }
}

#[pyclass(name = "PositionInTrack", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyPositionInTrack {
    Beginning,
    Middle,
    End,
}

impl From<PyPositionInTrack> for PositionInTrack {
    fn from(value: PyPositionInTrack) -> Self {
        match value {
            PyPositionInTrack::Beginning => PositionInTrack::Beginning,
            PyPositionInTrack::Middle => PositionInTrack::Middle,
            PyPositionInTrack::End => PositionInTrack::End,
        }
    }
}

impl From<PositionInTrack> for PyPositionInTrack {
    fn from(value: PositionInTrack) -> Self {
        match value {
            PositionInTrack::Beginning => PyPositionInTrack::Beginning,
            PositionInTrack::Middle => PyPositionInTrack::Middle,
            PositionInTrack::End => PyPositionInTrack::End,
        }
    }
}

#[pymethods]
impl PyPositionInTrack {
    fn __int__(&self) -> i32 {
        let value: PositionInTrack = (*self).into();
        i32::from(value)
    }
}

#[pyclass(name = "AssociationStatus", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyAssociationStatus {
    Statistical,
    High,
    Medium,
    Low,
    None,
}

impl From<PyAssociationStatus> for AssociationStatus {
    fn from(value: PyAssociationStatus) -> Self {
        match value {
            PyAssociationStatus::Statistical => AssociationStatus::Statistical,
            PyAssociationStatus::High => AssociationStatus::High,
            PyAssociationStatus::Medium => AssociationStatus::Medium,
            PyAssociationStatus::Low => AssociationStatus::Low,
            PyAssociationStatus::None => AssociationStatus::None,
        }
    }
}

impl From<AssociationStatus> for PyAssociationStatus {
    fn from(value: AssociationStatus) -> Self {
        match value {
            AssociationStatus::Statistical => PyAssociationStatus::Statistical,
            AssociationStatus::High => PyAssociationStatus::High,
            AssociationStatus::Medium => PyAssociationStatus::Medium,
            AssociationStatus::Low => PyAssociationStatus::Low,
            AssociationStatus::None => PyAssociationStatus::None,
        }
    }
}

#[pymethods]
impl PyAssociationStatus {
    fn __int__(&self) -> i32 {
        let value: AssociationStatus = (*self).into();
        i32::from(value)
    }
}

pub fn register_enums(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
    parent_module.add_class::<PyKeyMode>()?;
    parent_module.add_class::<PyKeyOrder>()?;
    parent_module.add_class::<PyDuplicateKeyMode>()?;
    parent_module.add_class::<PyElsetKeyMode>()?;
    parent_module.add_class::<PyElementType>()?;
    parent_module.add_class::<PyTleType>()?;
    parent_module.add_class::<PyClassification>()?;
    parent_module.add_class::<PyB3Type>()?;
    parent_module.add_class::<PyPositionInTrack>()?;
    parent_module.add_class::<PyAssociationStatus>()?;
    parent_module.add_class::<PyFundamentalCatalog>()?;
    parent_module.add_class::<PySGP4OutputEphemerisFrame>()?;
    Ok(())
}

fn enum_member<T: PyTypeInfo>(py: Python<'_>, name: &str) -> PyResult<PyObject> {
    let enum_type = py.get_type::<T>();
    let member = enum_type.getattr(name)?;
    Ok(member.into())
}

pub fn py_key_mode(py: Python<'_>, mode: KeyMode) -> PyResult<PyObject> {
    let name = match mode {
        KeyMode::NoDuplicates => "NoDuplicates",
        KeyMode::DirectMemoryAccess => "DirectMemoryAccess",
    };
    enum_member::<PyKeyMode>(py, name)
}

pub fn py_elset_key_mode(py: Python<'_>, mode: ElsetKeyMode) -> PyResult<PyObject> {
    let name = match mode {
        ElsetKeyMode::NoDuplicates => "NoDuplicates",
        ElsetKeyMode::DirectMemoryAccess => "DirectMemoryAccess",
    };
    enum_member::<PyElsetKeyMode>(py, name)
}

pub fn py_duplicate_key_mode(py: Python<'_>, mode: DuplicateKeyMode) -> PyResult<PyObject> {
    let name = match mode {
        DuplicateKeyMode::ReturnZero => "ReturnZero",
        DuplicateKeyMode::ReturnKey => "ReturnKey",
    };
    enum_member::<PyDuplicateKeyMode>(py, name)
}

pub fn py_fundamental_catalog(py: Python<'_>, catalog: FundamentalCatalog) -> PyResult<PyObject> {
    let name = match catalog {
        FundamentalCatalog::Four => "Four",
        FundamentalCatalog::Five => "Five",
    };
    enum_member::<PyFundamentalCatalog>(py, name)
}

#[pyclass(name = "FundamentalCatalog", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PyFundamentalCatalog {
    Four,
    Five,
}

impl From<PyFundamentalCatalog> for FundamentalCatalog {
    fn from(value: PyFundamentalCatalog) -> Self {
        match value {
            PyFundamentalCatalog::Four => FundamentalCatalog::Four,
            PyFundamentalCatalog::Five => FundamentalCatalog::Five,
        }
    }
}

impl From<FundamentalCatalog> for PyFundamentalCatalog {
    fn from(value: FundamentalCatalog) -> Self {
        match value {
            FundamentalCatalog::Four => PyFundamentalCatalog::Four,
            FundamentalCatalog::Five => PyFundamentalCatalog::Five,
        }
    }
}

#[pymethods]
impl PyFundamentalCatalog {
    fn __int__(&self) -> i32 {
        match self {
            PyFundamentalCatalog::Four => FundamentalCatalog::Four as i32,
            PyFundamentalCatalog::Five => FundamentalCatalog::Five as i32,
        }
    }
}

#[pyclass(name = "SGP4OutputEphemerisFrame", eq, frozen)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PySGP4OutputEphemerisFrame {
    TEME,
    J2000,
}

impl From<PySGP4OutputEphemerisFrame> for SGP4OutputEphemerisFrame {
    fn from(value: PySGP4OutputEphemerisFrame) -> Self {
        match value {
            PySGP4OutputEphemerisFrame::TEME => SGP4OutputEphemerisFrame::TEME,
            PySGP4OutputEphemerisFrame::J2000 => SGP4OutputEphemerisFrame::J2000,
        }
    }
}

impl From<SGP4OutputEphemerisFrame> for PySGP4OutputEphemerisFrame {
    fn from(value: SGP4OutputEphemerisFrame) -> Self {
        match value {
            SGP4OutputEphemerisFrame::TEME => PySGP4OutputEphemerisFrame::TEME,
            SGP4OutputEphemerisFrame::J2000 => PySGP4OutputEphemerisFrame::J2000,
        }
    }
}

#[pymethods]
impl PySGP4OutputEphemerisFrame {
    fn __int__(&self) -> i32 {
        match self {
            PySGP4OutputEphemerisFrame::TEME => SGP4OutputEphemerisFrame::TEME as i32,
            PySGP4OutputEphemerisFrame::J2000 => SGP4OutputEphemerisFrame::J2000 as i32,
        }
    }
}