-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathele220.py
1702 lines (1516 loc) · 42.7 KB
/
ele220.py
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
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
Parsing and formatting for four orbit formats:
* the 220 column format for minor planets
* the 90 column format for minor planets
* the 220 column format for natural satellites of outer planets
* the 255 column format for comets
Parsing is provided with classes Ele220, Ele90, EleSat, EleComet. Formatting
is provided class EleFields, but currently only implemented for the 220 and 90
column minor planet formats, not for the natural satellite or comet formats.
"""
import datetime
import math
import novas.compat as novas
__all__ = ['Ele220', 'Ele90', 'EleSat', 'EleComet']
k = 0.01720209895
_ps = {
'd': 'DE200',
'f': 'DE245',
'h': 'DE403',
'j': 'DE405'
}
class _Ele(str):
"""base class for 220 and 90 character element lines.
Parameters
----------
str : string
The 220 or character element line. A trailing newline is okay.
"""
# slice objects hold column bounds for the raw fields within the 220
# character line. Primarily for internal use, not as part of the API.
_timePeri = slice(12, 24)
_argPeri = slice(24, 34)
_node = slice(34, 44)
_inc = slice(44, 54)
_periDist = slice(54, 64)
_ecc = slice(64, 74)
def timePeri(self):
"""
Returns
-------
float
Date of perihelion passage/JDT
"""
return JDFromPacked(self[_Ele._timePeri])
def argPeri(self):
"""
Returns
-------
float
Argument of perihelion (deg/J2000.0)
"""
return float7(self[_Ele._argPeri])
def node(self):
"""
Returns
-------
float
Longitude of ascending node (deg/J2000.0)
"""
return float7(self[_Ele._node])
def inc(self):
"""
Returns
-------
float
Inclination of orbit (deg/J2000.0)
"""
return float7(self[_Ele._inc])
def periDist(self):
"""
Returns
-------
float
Perihelion distance (AU)
"""
return float9p(self[_Ele._periDist])
def ecc(self):
"""
Returns
-------
float
Eccentricity
"""
return float9(self[_Ele._ecc])
class Ele220(_Ele):
"""holds a 220 character element line.
Class Ele220 instantiates on a 220 character line, then methods interpret
individual field values. A design assumption is that many applications
will not need all fields but only some subset. Instantiation therefore
does not do any parsing. Individual methods interpret and return single
field values.
Thus depending on the application, Ele220 may not be best for orbit
represention but only for parsing. For example you might define an orbit
class in some way suitable for computation, then instantiate an Ele220 on
a line from an orbit file, then use the methods of the Ele220 object in
constrution of your computation-suitable orbit object. This way only the
fields you need are parsed; they are parsed once and then the Ele220 object
is no longer needed.
Note the methods ma1, argPeri1, node1, inc1, ecc3, and a3 have little
computatinal use. They interpret fields appearing in the 220 column
format as "readable" values with reduced precision. Full precision
values are either available as other methods or can be computed from
other methods.
Parameters
----------
str : string
220 character element line. Extra length such as a trailing newline
is okay.
"""
_desig = slice(0, 7)
_g = slice(7, 12)
# 12:74 are standard elements
_pertEpoch = slice(75, 80)
_designation = slice(80, 90)
_h = slice(91, 96)
_maEpoch = slice(97, 102)
_ma1 = slice(103, 108)
_argPeri1 = slice(109, 114)
_node1 = slice(115, 120)
_inc1 = slice(121, 126)
_ecc3 = slice(127, 132)
_a3 = slice(133, 140)
_numOpp = slice(141, 144)
_arc = slice(144, 150)
_numObs = slice(150, 156)
_uNote = 157 # overloaded column
_comp = slice(159, 168)
_ref = slice(169, 178)
_first = slice(179, 184)
_last = slice(185, 190)
_rms = slice(191, 196)
_pertScheme = 197
_pertCoarse = slice(199, 202)
_pert = slice(203, 207)
# there can be some capital letters after _pert. no method.
_numScore = slice(212, 214)
_curOppScore = 214
def desig(self):
"""
Returns
-------
string
a short designation, no longer than 7 characters, whitespace
trimmed. This may be a temporary or packed designation, either
permanent or provisional.
See also
--------
designation : Unpacked designation
"""
return self[Ele220._desig].strip()
def g(self):
"""
Returns
-------
float
Slope parameter, G
"""
return float(self[Ele220._g])
def pertEpoch(self):
"""
Returns
-------
None or float
float is epoch jd
"""
pe = self[Ele220._pertEpoch]
if pe.isspace():
return None
return JDFromPacked(pe)
def designation(self):
"""
Returns
-------
string
a non-packed designation, up to 10 characters, whitespace
trimmed.
See also
--------
desig : Packed designation
"""
return self[Ele220._designation].strip()
'''
def h(self):
"""
Returns
-------
float
Absolute magnitude, H
"""
return float(self[Ele220._h])
'''
def h(self):
"""
Returns
-------
float
Absolute magnitude, H, if field is filled
None
if field is blank
"""
try:
return float(self[Ele220._h])
except ValueError:
if not self[Ele220._h].isspace():
raise
def maEpoch(self):
"""
Returns
-------
float
Epoch JD
"""
return JDFromPacked(self[Ele220._maEpoch])
def ma1(self):
"""
Returns
-------
float
Mean anomaly in degrees, precision limited to one decimal place.
"""
return float(self[Ele220._ma1])
def argPeri1(self):
"""
Returns
-------
float
Argument of perihelion in degrees, precision limited to one
decimal place.
"""
return float(self[Ele220._argPeri1])
def node1(self):
"""
Returns
-------
float
Longitude of ascending node in degrees, precision limited to one
decimal place.
"""
return float(self[Ele220._node1])
def inc1(self):
"""
Returns
-------
float
Inclination in degrees, precision limited to one decimal place.
"""
return float(self[Ele220._inc1])
def ecc3(self):
"""
Returns
-------
float
Eccentricity, precision limited to three decimal places.
"""
return float(self[Ele220._ecc3])
def a3(self):
"""
Returns
-------
float
Semi-major axis in AU, precision limited to three decimal places.
"""
return float(self[Ele220._a3])
def numOpp(self):
"""
Returns
-------
int
Number of oppositions included in solution
"""
return int(self[Ele220._numOpp])
def arc(self):
"""
Returns
-------
int
Arc length of observations included in solution (/days)
"""
return int(self[Ele220._arc])
def numObs(self):
"""
Returns
-------
int
Number of observations included in solution
"""
return int(self[Ele220._numObs])
def u(self):
"""
Returns
-------
int
U value (a number from 0 to 9) if present.
10 if not present. (10 is not a valid U value.)
"""
try:
return int(self[Ele220._uNote])
except ValueError:
return 10
def uNote(self):
"""
Returns
-------
string
single character note from the U field, if one exists, '' otherwise
"""
n = self[Ele220._uNote]
if n == ' ' or n.isdigit():
return ''
return n
def comp(self):
"""
Returns
-------
string
Computer name, up to 9 characters, whitespace trimmed
"""
return self[Ele220._comp].strip()
def ref(self):
"""
Returns
-------
string
Reference, up to 9 characters, whitespace trimmed
"""
return self[Ele220._ref].strip()
def first(self):
"""
Returns
-------
float
Date of first included observation as JD
"""
return JDFromPacked(self[Ele220._first])
def last(self):
"""
Returns
-------
float
Date of last included observation as JD
"""
return JDFromPacked(self[Ele220._last])
def rms(self):
"""
Returns
-------
float
r.m.s. fit of included obserations (/")
"""
return float(self[Ele220._rms])
def pertScheme(self):
"""
Returns
-------
string
a string such as 'DE200', 'DE403', 'DE405', or ''
"""
if self[Ele220._pertEpoch.start] == ' ':
return ''
return _ps.get(self[Ele220._pertScheme], '')
def pertCoarse(self):
"""
Returns
-------
string
a string such as 'M-v' or ''
"""
if self[Ele220._pertEpoch.start] == ' ':
return ''
return self[Ele220._pertCoarse].strip()
def perturbers(self):
"""
Returns
-------
string
4 character perturber code if present, '' otherwise
"""
if self[Ele220._pertEpoch.start] == ' ':
return ''
return self[Ele220._pert]
def numScore(self):
"""
Returns
-------
int
a number from 0 to 219 if present.
-1 if not present.
"""
s = self[Ele220._numScore]
if s.isspace():
return -1
n = int(s[1])
return n if s[0] == ' ' else b62(s[0]) * 10 + n
def curOppScore(self):
"""
Returns
-------
int
a number from 0 to 9 if present.
-1 if not present.
"""
s = self[Ele220._curOppScore]
return -1 if s == ' ' else int(s)
class Ele90(_Ele):
"""holds a 90 character element line.
Parameters
----------
str : string
The 90 character element line. A trailing newline is okay.
See also
--------
Ele220
"""
_desig = slice(0, 7)
_h = slice(7, 12)
# 12:74 are standard elements
_first = slice(80, 85)
_last = slice(85, 90)
def desig(self):
"""
Returns
-------
string
a short designation, no longer than 7 characters, whitespace
trimmed. This may be a temporary or packed designation, either
permanent or provisional.
See also
--------
designation : Unpacked designation
"""
return self[Ele90._desig].strip()
def h(self):
"""
Returns
-------
float
Absolute magnitude, H, if field is filled
None
if field is blank
"""
try:
return float(self[Ele90._h])
except ValueError:
if not self[Ele90._h].isspace():
raise
def first(self):
"""
Returns
-------
float
Date of first included observation as JD
"""
return JDFromPacked(self[Ele90._first])
def last(self):
"""
Returns
-------
float
Date of last included observation as JD
"""
return JDFromPacked(self[Ele90._last])
class EleSat(_Ele):
"""holds a 220 character element line for a natural satellite
Class EleSat instantiates on a 220 character line, then methods interpret
individual field values. A design assumption is that many applications
will not need all fields but only some subset. Instantiation therefore
does not do any parsing. Individual methods interpret and return single
field values.
Parameters
----------
str : string
220 character element line. Extra length such as a trailing newline
is okay.
"""
_permDesig = slice(0, 4)
# [4] is always 'S'
_tempDesig = slice(5, 12)
# 12:74 are standard elements
_pertEpoch = slice(75, 80)
_designation = slice(80, 91)
_h = slice(91, 96)
_maEpoch = slice(97, 102)
_ma1 = slice(103, 108)
_argPeri1 = slice(109, 114)
_node1 = slice(115, 120)
_inc1 = slice(121, 126)
_ecc3 = slice(127, 132)
_a3 = slice(133, 140)
_arc = slice(144, 150)
_numObs = slice(150, 156)
_comp = slice(159, 168)
_ref = slice(169, 178)
_first = slice(179, 184)
_last = slice(185, 190)
_rms = slice(191, 196)
_pertScheme = 197
_pertCoarse = slice(199, 202)
_pert = slice(203, 207)
_numScore = slice(212, 214)
_curOppScore = 214
def permDesig(self):
"""
Returns
-------
string
permanent designation, 4 characters if present, '' if not present.
"""
return self[EleSat._permDesig].strip()
def tempDesig(self):
"""
Returns
-------
string
temporary designation, 7 characters if present, '' if not present.
"""
return self[EleSat._tempDesig].strip()
def pertEpoch(self):
"""
Returns
-------
float
epoch jd
"""
return JDFromPacked(self[EleSat._pertEpoch])
def designation(self):
"""
Returns
-------
string
unpacked designation.
"""
return self[EleSat._designation].strip()
'''
def h(self):
"""
Returns
-------
float
Absolute magnitude, H
"""
return float(self[EleSat._h])
'''
def h(self):
"""
Returns
-------
float
Absolute magnitude, H, if field is filled
None
if field is blank
"""
try:
return float(self[EleSat._h])
except ValueError:
if not self[EleSat._h].isspace():
raise
def maEpoch(self):
"""
Returns
-------
float
Epoch JD
"""
return JDFromPacked(self[EleSat._maEpoch])
def ma1(self):
"""
Returns
-------
float
Mean anomaly in degrees, precision limited to one decimal place.
"""
return float(self[EleSat._ma1])
def argPeri1(self):
"""
Returns
-------
float
Argument of perihelion in degrees, precision limited to one
decimal place.
"""
return float(self[EleSat._argPeri1])
def node1(self):
"""
Returns
-------
float
Longitude of ascending node in degrees, precision limited to one
decimal place.
"""
return float(self[EleSat._node1])
def inc1(self):
"""
Returns
-------
float
Inclination in degrees, precision limited to one decimal place.
"""
return float(self[EleSat._inc1])
def ecc3(self):
"""
Returns
-------
float
Eccentricity, precision limited to three decimal places.
"""
return float(self[EleSat._ecc3])
def a3(self):
"""
Returns
-------
float
Semi-major axis in AU, precision limited to three decimal places.
"""
return float(self[EleSat._a3])
def arc(self):
"""
Returns
-------
int
Arc length of observations included in solution
"""
return int(self[EleSat._arc])
def numObs(self):
"""
Returns
-------
int
Number of observations included in solution
"""
return int(self[EleSat._numObs])
def comp(self):
"""
Returns
-------
string
Computer name, up to 9 characters, whitespace trimmed
"""
return self[EleSat._comp].strip()
def ref(self):
"""
Returns
-------
string
Reference, up to 9 characters, whitespace trimmed
"""
return self[EleSat._ref].strip()
def first(self):
"""
Returns
-------
float
Date of first included observation as JD
"""
return JDFromPacked(self[EleSat._first])
def last(self):
"""
Returns
-------
float
Date of last included observation as JD
"""
return JDFromPacked(self[EleSat._last])
def rms(self):
"""
Returns
-------
float
r.m.s. fit of included obserations
"""
return float(self[EleSat._rms])
def pertScheme(self):
"""
Returns
-------
string
a string such as 'DE200', 'DE403', 'DE405', or ''
"""
return _ps.get(self[EleSat._pertScheme], '')
def pertCoarse(self):
"""
Returns
-------
string
a string such as 'M-v' or ''
"""
return self[EleSat._pertCoarse].strip()
def perturbers(self):
"""
Returns
-------
string
4 character perturber code if present, '' otherwise
"""
return self[EleSat._pert]
def numScore(self):
"""
Returns
-------
int
a number from 0 to 219 if present.
-1 if not present.
"""
s = self[EleSat._numScore]
if s.isspace():
return -1
n = int(s[1])
return n if s[0] == ' ' else b62(s[0]) * 10 + n
def curOppScore(self):
"""
Returns
-------
int
a number from 0 to 9 if present.
-1 if not present.
"""
s = self[EleSat._curOppScore]
return -1 if s == ' ' else int(s)
class EleComet(_Ele):
"""holds a 256 character comet element line.
Parameters
----------
str : string
The 256 character element line. A trailing newline is okay.
"""
_permDesig = slice(0, 5) # includes orbit type at [4]
_tempDesig = slice(4, 12) # includes orbit type at [4]
_tempDes1 = 5 # first position after the orbit type
_frag = 11
_frag2 = slice(10, 12)
# 12:74 are standard elements
# [74] is usually blank but sometimes has an 'a', or an 'S'.
# there is no method for this.
_pertEpoch = slice(75, 80)
_name = slice(80, 109)
_comp = slice(109, 120) # there can be a leading @
_pubYear = slice(121, 125)
_pub = slice(125, 129)
# unknown fields here. looks like float, int, float, int, and a
# date formatted as a string.
_timeScale = 163
_pubVol = slice(165, 174)
_numObs = slice(176, 181) # first char can be A or N, last can be +
_nonGravStar = 181
_first = slice(183, 188)
_last = slice(189, 194)
_pertScheme = 195
# there can be a capital letter in 196. no method.
_pertCoarse = slice(197, 200)
_pert = slice(201, 205)
# [206] typically has a digit in it.
# 208, 209, and 210 are note fields, no methods for these, except
# that a ! in 210 obviously means that fields in [183:210] cannot be
# interpreted by _first, _last, _pertScheme, _pertCoarse, _pert.
# if 210 contains a !, [183:210] has unknown meaning.
_notes = slice(208, 210)
# a '!' sometimes appears in [219]
# [222:251] hold non-grav parameters, at least if [_nonGravStar] is '*'.
# Interpretation of these columns in non-* cases is unknown.
_ng_style = 221
_ng_a1 = slice(222, 232)
_ng_a2 = slice(232, 243)
_ng_a3 = slice(243, 251)
_rms = slice(251, 255)
def permDesig(self):
"""
Returns
-------
string
permanent designation, 5 characters if present, '' if not.
"""
return self[EleComet._permDesig] if self[0] > ' ' else ''
def tempDesig(self):
"""
Returns
-------
string
temporary designation, including leading orbit type character,
8 characters altogether if present, '' if not present.
"""
if self[EleComet._tempDes1] > ' ':
return self[EleComet._tempDesig]
return ''
def frag(self):
"""
Returns
-------
string
1 or 2 character fragment identifer if present.
'' if not present.
"""
# _frag is the last position of _tempDesig. if there's no lowercase
# letter there, there's no fragment identifier.
if self[EleComet._frag] < 'a':
return ''
# non-space after the orbit type character at the start of tempDesig
# means the tempDesig is present and the fragment can only be the
# single character.
if self[EleComet._tempDesig.start + 1] > ' ':
return self[EleComet._frag]
# else, with no temp des, the field is free to hold two character
# fragment designations.
if self[EleComet._frag2.start] == ' ':
return self[EleComet._frag]
return self[EleComet._frag2]
def pertEpoch(self):
"""
Returns
-------
None or float
float is epoch jd
"""
pe = self[EleComet._pertEpoch]
if pe.isspace():
return None
return JDFromPacked(pe)
def name(self):
"""
Returns
-------
string
Comet name
"""
return self[EleComet._name].strip()
def comp(self):
"""
Returns
-------
string
Orbit computer name. The first character can be '@', which
means it can be expanded with an external list,
comet_computers.txt.
"""
return self[EleComet._comp].strip()
def pubYear(self):
"""
Returns
-------
string
"""
return self[EleComet._pubYear].strip()
def pub(self):
"""
Returns
-------
string
"""
return self[EleComet._pub].strip()
def timeScale(self):
"""
Returns
-------
string
Either "TT/TDT" or "UTC".
"""
if self[EleComet._timePeri.start] < 'J':
return "TT/TDT" if self[EleComet._timeScale] == 'T' else "UTC"
return "UTC" if self[EleComet._timeScale] == 'U' else "TT/TDT"
def pubVol(self):
"""
Returns
-------
string
"""
return self[EleComet._pubVol].strip()
def numObs(self):
"""
Returns
-------
int
Number of observations used in orbit solution.
"""
n = self[EleComet._numObs]
if n[0] in "AN":
return int(n[1:])
if n[4] == '+':
return int(n[:4])
return int(n)
def numObsAN(self):
"""
Returns
-------
string
'A' or 'N' where one of these characters appears before numObs.
"""
n0 = self[EleComet._numObs.start]
return n0 if n0 in "AN" else ""
def numObsPlus(self):
"""
Returns