-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPVT.py
More file actions
114 lines (89 loc) · 3.48 KB
/
PVT.py
File metadata and controls
114 lines (89 loc) · 3.48 KB
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
"""PVT implements a class to describe (position, velocity, time) triplets.
History:
2001-01-10 ROwen Modified floatCnv to not handle NaN floating values,
since this failed on Mac OS X; it will still handle string "NaN" (any case).
2002-08-08 ROwen Modified to use new Astro.Tm functions which are in days, not sec.
2003-05-08 ROwen Modified to use RO.CnvUtil.
2003-11-21 ROwen Bug fix: __init__ did not check the data.
2005-06-08 ROwen Changed PVT to a new-style class.
2007-07-02 ROwen Added hasVel method.
2015-09-24 ROwen Replace "== None" with "is None" to modernize the code.
2015-11-03 ROwen Replace "!= None" with "is not None" to modernize the code.
"""
__all__ = ["PVT"]
import time
import numpy
import RO.Astro.Tm
import RO.CnvUtil
import RO.MathUtil
import RO.PhysConst
class PVT(object):
"""Defines a position, velocity, time triplet, where time is in TAI.
Inputs:
- pos position
- vel velocity (in units of position/sec)
- time TAI, MJD seconds
Each value must be one of: a float, a string representation of a float,
"NaN" (any case) or None. "NaN" and None mean "unknown" and are stored as None.
Raises ValueError if any value is invalid.
"""
def __init__(self, pos=None, vel=0.0, t=0.0):
self.pos = None
self.vel = 0.0
self.t = 0.0
self.set(pos, vel, t)
def __repr__(self):
return "PVT(%s, %s, %s)" % (str(self.pos), str(self.vel), str(self.t))
def getPos(self, t=None):
"""Returns the position at the specified time.
Time defaults to the current TAI.
Returns None if the pvt is invalid.
"""
if not self.isValid():
return None
if t is None:
t = RO.Astro.Tm.taiFromPySec() * RO.PhysConst.SecPerDay
return self.pos + (self.vel * (t - self.t))
def hasVel(self):
"""Return True if velocity is known and nonzero.
"""
return self.vel not in (0, None)
def isValid(self):
"""Returns True if the pvt is valid, False otherwise.
A pvt is valid if all values are known (not None and finite) and time > 0.
"""
return (self.pos is not None) and numpy.isfinite(self.pos) \
and (self.vel is not None) and numpy.isfinite(self.vel) \
and (self.t is not None) and numpy.isfinite(self.t) \
and (self.t > 0)
def set(self, pos=None, vel=None, t=None):
"""Sets pos, vel and t; all default to their current values
Each value must be one of: a float, a string representation of a float,
"NaN" (any case) or None. "NaN" means "unknown" and is stored as None.
Errors:
Raises ValueError if any value is invalid.
"""
if pos is not None:
self.pos = RO.CnvUtil.asFloatOrNone(pos)
if vel is not None:
self.vel = RO.CnvUtil.asFloatOrNone(vel)
if t is not None:
self.t = RO.CnvUtil.asFloatOrNone(t)
if __name__ == "__main__":
print("\nrunning PVT test")
currTAI = RO.Astro.Tm.taiFromPySec() * RO.PhysConst.SecPerDay
varList = (
PVT(),
PVT(25),
PVT(25, 0, currTAI),
PVT(25, 1),
PVT(25, 1, currTAI),
PVT('NaN', 'NaN', 'NaN')
)
for i in range(5):
t = RO.Astro.Tm.taiFromPySec() * RO.PhysConst.SecPerDay
print("\ntime =", t)
for var in varList:
print(var, "pos =", var.getPos(t))
if i < 4:
time.sleep(1)