gdar-orbit 1.2.0.post2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gdar/orbit/__init__.py +3 -0
- gdar/orbit/attitude.py +425 -0
- gdar/orbit/frame_transformations.py +162 -0
- gdar/orbit/orbit.py +2453 -0
- gdar_orbit-1.2.0.post2.dist-info/METADATA +143 -0
- gdar_orbit-1.2.0.post2.dist-info/RECORD +8 -0
- gdar_orbit-1.2.0.post2.dist-info/WHEEL +4 -0
- gdar_orbit-1.2.0.post2.dist-info/licenses/LICENSE +202 -0
gdar/orbit/__init__.py
ADDED
gdar/orbit/attitude.py
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
# Silence warning about missing numba -- we don't use those parts anyway
|
|
6
|
+
with warnings.catch_warnings():
|
|
7
|
+
# warnings.simplefilter("ignore")
|
|
8
|
+
warnings.filterwarnings("ignore", module="quaternion")
|
|
9
|
+
import quaternion as quat # module
|
|
10
|
+
|
|
11
|
+
from gdar.base.gtime import sec, tai2utc, utc2tai
|
|
12
|
+
from gdar.base.util import split_last, unit_vector
|
|
13
|
+
from gdar.orbit.frame_transformations import tod_from_itrs
|
|
14
|
+
|
|
15
|
+
# from .coordinates import eci_from_ecef, ecef_from_eci
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
Convention:
|
|
20
|
+
|
|
21
|
+
Attitude is defined as the 3D rotation which transforms the coordinates of a
|
|
22
|
+
vector expressed in the GDAR body-fixed system to ITRF (one example of an ECEF
|
|
23
|
+
coordinate system).
|
|
24
|
+
|
|
25
|
+
The GDAR body-fixed system is used to express pointing of the instrument, and
|
|
26
|
+
is defined as follows:
|
|
27
|
+
* The z axis is the boresight direction, where elevation and azimuth angles
|
|
28
|
+
are both zero.
|
|
29
|
+
* The x axis coincides with the axis of the antenna which will align most
|
|
30
|
+
closely to the direction of forward travel of the satellite.
|
|
31
|
+
* The y axis completes the right-handed system.
|
|
32
|
+
|
|
33
|
+
Any particular instrument platform's definition of a body-fixed system is
|
|
34
|
+
likely to be different from this definition. The reader of such information is
|
|
35
|
+
responsible for modifying the attitude read such that the conventions above are
|
|
36
|
+
followed.
|
|
37
|
+
|
|
38
|
+
When azimuth and elevation (for a particular pointing direction) is discussed,
|
|
39
|
+
the elevation angle is the complement of the angle this pointing makes with the
|
|
40
|
+
y axis. For an instrument pointing to the right, elevation increases as the
|
|
41
|
+
pointing direction rotates away from nadir. Azimuth is the angle between the
|
|
42
|
+
z-axis and the projection of the pointing vector to the x-z plane.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
# Furthermore, define the following alternate coordinate system
|
|
46
|
+
# (a control reference system fixed to the satellite body).
|
|
47
|
+
# * zz-axis: nadir pointing vector
|
|
48
|
+
# * yy-axis: perpendicular to ECI statevector velocity and x-axis
|
|
49
|
+
# (pointing to the right of satellite track)
|
|
50
|
+
# * xx-axis: completes the right hand system
|
|
51
|
+
# (almost ECI velocity direction)
|
|
52
|
+
# Now, assume that the satellite attitude is composed of three /extrinsic/
|
|
53
|
+
# rotations in the following order:
|
|
54
|
+
# 1) Roll around the xx-axis
|
|
55
|
+
# 2) Pitch around the yy-axis
|
|
56
|
+
# 3) Yaw around the zz-axis
|
|
57
|
+
# Note that this is equivalent to three /intrinsic/ rotations of
|
|
58
|
+
# the same magnitude and sign, but in the opposite order:
|
|
59
|
+
# 1) Yaw around the zz-axis
|
|
60
|
+
# 2) Pitch around the yy'-axis (yy' is yy yawed around zz)
|
|
61
|
+
# 3) Roll around the xx''-axis (xx'' is xx yawed around zz then
|
|
62
|
+
# pitched around yy')
|
|
63
|
+
# """
|
|
64
|
+
|
|
65
|
+
quaternion_dtype = [
|
|
66
|
+
("utc", "datetime64[ns]"), # absolute time in UTC
|
|
67
|
+
("tai", "datetime64[ns]"), # absolute time in TAI
|
|
68
|
+
("s", np.double), # scalar part
|
|
69
|
+
("v", np.double, (3,)),
|
|
70
|
+
] # vector part
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
att_dtype = [
|
|
74
|
+
("utc", "datetime64[ns]"), # absolute time in UTC
|
|
75
|
+
("tai", "datetime64[ns]"), # absolute time in TAI
|
|
76
|
+
("quat", np.double, (4,)),
|
|
77
|
+
] # [re, x, y, z]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Attitude(object):
|
|
81
|
+
"""Quaternion-based satellite attitude representation.
|
|
82
|
+
|
|
83
|
+
Stores a uniformly-sampled sequence of unit quaternions and provides
|
|
84
|
+
spherical linear interpolation (SLERP) to evaluate attitude at
|
|
85
|
+
arbitrary times. The quaternions represent the rotation from the
|
|
86
|
+
GDAR body-fixed frame to ITRF (see module-level docstring).
|
|
87
|
+
|
|
88
|
+
Parameters
|
|
89
|
+
----------
|
|
90
|
+
qt_arr : np.ndarray
|
|
91
|
+
``(N, 4)`` array of quaternion components ``[re, x, y, z]``,
|
|
92
|
+
or an array of ``numpy.quaternion`` objects.
|
|
93
|
+
t : np.ndarray
|
|
94
|
+
Corresponding time stamps — either ``datetime64`` (absolute) or
|
|
95
|
+
float seconds relative to *time_ref*.
|
|
96
|
+
time_ref : datetime64 or float, optional
|
|
97
|
+
Reference epoch for relative times.
|
|
98
|
+
time_scale : str or None, optional
|
|
99
|
+
``'UTC'`` or ``'TAI'`` — scale of *time_ref*. If None, only
|
|
100
|
+
relative times are supported.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
def __init__(self, qt_arr, t, time_ref=None, time_scale=None):
|
|
104
|
+
"""Initialise with quaternion samples and associated times.
|
|
105
|
+
|
|
106
|
+
The rotation from a platform-specific body frame to the GDAR
|
|
107
|
+
body-fixed frame must already be applied to *qt_arr*.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
if len(qt_arr) != len(t):
|
|
111
|
+
raise ValueError("Must have same # of quaternions and times.")
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
self._quaternions = quat.as_quat_array(qt_arr)
|
|
115
|
+
except ValueError:
|
|
116
|
+
# Hopefully arises because array is already quaternions,
|
|
117
|
+
# but how to check?
|
|
118
|
+
self._quaternions = qt_arr
|
|
119
|
+
|
|
120
|
+
self.set_time_ref(time_ref, time_scale=time_scale)
|
|
121
|
+
self._time = self._get_relative_time(t, time_scale=time_scale)
|
|
122
|
+
|
|
123
|
+
# Make sure data is evenly sampled
|
|
124
|
+
dt = np.diff(self._time)
|
|
125
|
+
assert np.allclose(dt[1:], dt[0])
|
|
126
|
+
self._dt = dt[0]
|
|
127
|
+
|
|
128
|
+
def get_quaternion(self, t, time_scale=None):
|
|
129
|
+
"""
|
|
130
|
+
Calculate quaternion for time 't' using spherical linear interpolation.
|
|
131
|
+
|
|
132
|
+
This is the basis for all user-oriented functionality.
|
|
133
|
+
The quaternions returned by this method represent attitude as defined
|
|
134
|
+
in the top-level docstring.
|
|
135
|
+
"""
|
|
136
|
+
tint_rel = self._get_relative_time(t, time_scale=time_scale)
|
|
137
|
+
Qtab = self._quaternions
|
|
138
|
+
|
|
139
|
+
idx = np.array((tint_rel - self._time[0]) / self._dt, dtype=np.int64)
|
|
140
|
+
if np.any(np.logical_or(idx < 0, idx >= len(Qtab))):
|
|
141
|
+
raise IndexError("Cannot extrapolate quaternions.")
|
|
142
|
+
w = (tint_rel - (self._time[0] + self._dt * idx)) / self._dt
|
|
143
|
+
|
|
144
|
+
return np.slerp_vectorized(Qtab[idx], Qtab[idx + 1], w)
|
|
145
|
+
|
|
146
|
+
# if np.isscalar(t):
|
|
147
|
+
# return pyq.Quaternion.slerp(Qtab[idx[0]], Qtab[idx[0]+1], w[0])
|
|
148
|
+
|
|
149
|
+
# qlist = list()
|
|
150
|
+
# for n, i in enumerate(idx):
|
|
151
|
+
# qlist.append(pyq.Quaternion.slerp(Qtab[i], Qtab[i+1], w[n]))
|
|
152
|
+
# return qlist
|
|
153
|
+
|
|
154
|
+
def get_attitude(self, t, time_scale=None, boresight=False, as_matrix=False, in_gcrs=False):
|
|
155
|
+
"""Retrieve interpolated attitude at time *t*.
|
|
156
|
+
|
|
157
|
+
Parameters
|
|
158
|
+
----------
|
|
159
|
+
t : float or np.datetime64
|
|
160
|
+
Query time(s).
|
|
161
|
+
time_scale : str, optional
|
|
162
|
+
``'UTC'`` or ``'TAI'`` when *t* is absolute.
|
|
163
|
+
boresight : bool, optional
|
|
164
|
+
If True, return only the boresight (z-axis) direction vector.
|
|
165
|
+
as_matrix : bool, optional
|
|
166
|
+
If True, return the full 3x3 rotation matrix.
|
|
167
|
+
in_gcrs : bool, optional
|
|
168
|
+
If True, return attitude in GCRS (not yet implemented).
|
|
169
|
+
|
|
170
|
+
Returns
|
|
171
|
+
-------
|
|
172
|
+
quaternion, np.ndarray
|
|
173
|
+
Quaternion(s), rotation matrix, or boresight vector depending
|
|
174
|
+
on keyword flags.
|
|
175
|
+
"""
|
|
176
|
+
if in_gcrs:
|
|
177
|
+
# Here we need access to absolute time
|
|
178
|
+
raise NotImplementedError("To be continued ...")
|
|
179
|
+
|
|
180
|
+
qt = self.get_quaternion(t, time_scale=time_scale)
|
|
181
|
+
|
|
182
|
+
# if np.isscalar(t):
|
|
183
|
+
# qt = [qt]
|
|
184
|
+
|
|
185
|
+
if as_matrix:
|
|
186
|
+
return quat.as_rotation_matrix(qt)
|
|
187
|
+
# qt = np.array([q.rotation_matrix for q in qt])
|
|
188
|
+
|
|
189
|
+
elif boresight:
|
|
190
|
+
return quat.as_rotation_matrix(qt)[..., -1]
|
|
191
|
+
# qt = np.array([q.rotation_matrix[:,-1] for q in qt])
|
|
192
|
+
|
|
193
|
+
# if np.isscalar(t):
|
|
194
|
+
# return qt[0]
|
|
195
|
+
|
|
196
|
+
return qt
|
|
197
|
+
|
|
198
|
+
def get_pointing(self, t, azimuth=0, elevation=0, y_elevation=False, time_scale=None):
|
|
199
|
+
"""
|
|
200
|
+
provides pointing direction as vector in in terrestric frame,
|
|
201
|
+
given azimuth and elevation angles in gdar frame.
|
|
202
|
+
azimuth and elevation both default to 0, which means boresight.
|
|
203
|
+
|
|
204
|
+
The keyword y_elevation determines the semantics for azimuth and
|
|
205
|
+
elevation angles:
|
|
206
|
+
|
|
207
|
+
- If y_elevation is False (default), then az and el are the angles
|
|
208
|
+
away from the z axis in the xz and yz planes, respectively
|
|
209
|
+
- If y_elevation is True, then el is the complement of the angle
|
|
210
|
+
between the pointing and the y axis.
|
|
211
|
+
|
|
212
|
+
For small azimuth and elevation angles, the difference should be small
|
|
213
|
+
NB! Azimuth and Elevation angles in degrees!
|
|
214
|
+
"""
|
|
215
|
+
from numpy import cos, radians, sin, tan
|
|
216
|
+
|
|
217
|
+
# The most common default case has a convenient short cut
|
|
218
|
+
if azimuth == 0 and elevation == 0:
|
|
219
|
+
return self.get_attitude(t, time_scale=time_scale, boresight=True)
|
|
220
|
+
|
|
221
|
+
if y_elevation:
|
|
222
|
+
# Common definition, elevation is complement of angle from y axis
|
|
223
|
+
# but this definition is not symmetric in azimuth and elevation angles
|
|
224
|
+
saz, caz = sin(radians(azimuth)), cos(radians(azimuth))
|
|
225
|
+
sel, cel = sin(radians(elevation)), cos(radians(elevation))
|
|
226
|
+
|
|
227
|
+
uvec = np.array([cel * saz, sel, cel * caz])
|
|
228
|
+
else:
|
|
229
|
+
# The default, az and el are angles away from z axis in xz and yz
|
|
230
|
+
# planes, respectively
|
|
231
|
+
taz = tan(radians(azimuth))
|
|
232
|
+
tel = tan(radians(elevation))
|
|
233
|
+
|
|
234
|
+
uvec = unit_vector([taz, tel, 1])
|
|
235
|
+
|
|
236
|
+
M = self.get_attitude(t, time_scale=time_scale, as_matrix=True)
|
|
237
|
+
|
|
238
|
+
return M @ uvec
|
|
239
|
+
|
|
240
|
+
def _get_relative_time(self, t, time_scale=None):
|
|
241
|
+
try:
|
|
242
|
+
num_type = (np.integer, np.signedinteger, np.floating)
|
|
243
|
+
if np.any([np.issubdtype(t.dtype, dtype) for dtype in num_type]):
|
|
244
|
+
# Assuming we have real valued numbers, this will work.
|
|
245
|
+
return t
|
|
246
|
+
except AttributeError:
|
|
247
|
+
# t is not a numpy data type (no 'dtype' attribute)
|
|
248
|
+
# check if we have a scalar real valued number.
|
|
249
|
+
if isinstance(t, (int, float)):
|
|
250
|
+
return t
|
|
251
|
+
raise ValueError()
|
|
252
|
+
# If we reach here, we have a numpy type.
|
|
253
|
+
# Check for absolute time.
|
|
254
|
+
if np.issubdtype(t.dtype, np.datetime64):
|
|
255
|
+
if self._ref_tai is None:
|
|
256
|
+
raise ValueError("'t' cannot be absolute if ref time is not set.")
|
|
257
|
+
if time_scale.upper() == "TAI":
|
|
258
|
+
return (t - self._ref_tai) / sec
|
|
259
|
+
if time_scale.upper() == "UTC":
|
|
260
|
+
return (utc2tai(t) - self._ref_tai) / sec
|
|
261
|
+
if time_scale is None:
|
|
262
|
+
raise ValueError("'time_scale' must be set if time 't' is absolute.")
|
|
263
|
+
raise ValueError("Unknown time_scale: " + time_scale)
|
|
264
|
+
# If we reach here, 't' has a weird type.
|
|
265
|
+
raise TypeError("Unsupported time type: " + str(type(t)))
|
|
266
|
+
|
|
267
|
+
def _get_absolute_time(self, t, time_scale=None):
|
|
268
|
+
"""
|
|
269
|
+
Return absolute time (in TAI) for given time value(s).
|
|
270
|
+
If argument is absolute time, time_scale must be given
|
|
271
|
+
("TAI" or "UTC").
|
|
272
|
+
If argument is relative time (number of seconds) then
|
|
273
|
+
time reference must have been set previously.
|
|
274
|
+
"""
|
|
275
|
+
# If absolute time was given, check that we have the scale
|
|
276
|
+
if np.issubdtype(t.dtype, np.datetime64):
|
|
277
|
+
if time_scale is None:
|
|
278
|
+
raise ValueError("'time_scale' must be set if time 't' is absolute.")
|
|
279
|
+
if time_scale.upper() == "TAI":
|
|
280
|
+
return t
|
|
281
|
+
if time_scale.upper() == "UTC":
|
|
282
|
+
return utc2tai(t)
|
|
283
|
+
raise ValueError("Unknown time_scale: " + time_scale)
|
|
284
|
+
|
|
285
|
+
# If we reach this point, t is relative
|
|
286
|
+
if self._ref_tai is None:
|
|
287
|
+
raise ValueError("'t' cannot be relative if ref time is not set.")
|
|
288
|
+
|
|
289
|
+
return self._ref_tai + sec * t
|
|
290
|
+
|
|
291
|
+
def set_time_ref(self, time_ref, time_scale=None):
|
|
292
|
+
if time_scale is None:
|
|
293
|
+
self._ref_tai = None
|
|
294
|
+
return
|
|
295
|
+
t_ref = np.datetime64(time_ref, "ns")
|
|
296
|
+
if time_scale.upper() == "TAI":
|
|
297
|
+
self._ref_tai = t_ref
|
|
298
|
+
return
|
|
299
|
+
if time_scale.upper() == "UTC":
|
|
300
|
+
self._ref_tai = utc2tai(t_ref)
|
|
301
|
+
return
|
|
302
|
+
raise ValueError("Time scale must be either 'TAI' or 'UTC'")
|
|
303
|
+
|
|
304
|
+
def get_time_ref(self, time_scale=None):
|
|
305
|
+
if time_scale is None:
|
|
306
|
+
return 0.0
|
|
307
|
+
if time_scale.upper() == "TAI":
|
|
308
|
+
return self._ref_tai
|
|
309
|
+
if time_scale.upper() == "UTC":
|
|
310
|
+
return tai2utc(self._ref_tai)
|
|
311
|
+
raise ValueError("Absolute ref time must be either 'TAI' or 'UTC'")
|
|
312
|
+
|
|
313
|
+
def to_ndarray(self):
|
|
314
|
+
qarr = np.empty(len(self._quaternions), dtype=quaternion_dtype)
|
|
315
|
+
qarr["tai"] = self._ref_tai + self._time * sec
|
|
316
|
+
qarr["utc"] = tai2utc(qarr["tai"])
|
|
317
|
+
for i, q in enumerate(self._quaternions):
|
|
318
|
+
qarr[i]["s"] = q.w
|
|
319
|
+
qarr[i]["v"] = q.vec
|
|
320
|
+
return qarr
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def pt_from_azel(az, el):
|
|
324
|
+
"""Convert azimuth and elevation angles to a unit pointing vector.
|
|
325
|
+
|
|
326
|
+
Uses the *y_elevation* convention: elevation is the complement of
|
|
327
|
+
the angle from the y-axis.
|
|
328
|
+
|
|
329
|
+
Parameters
|
|
330
|
+
----------
|
|
331
|
+
az, el : float
|
|
332
|
+
Azimuth and elevation in degrees.
|
|
333
|
+
|
|
334
|
+
Returns
|
|
335
|
+
-------
|
|
336
|
+
np.ndarray
|
|
337
|
+
Unit vector ``[x, y, z]`` in the body-fixed frame.
|
|
338
|
+
"""
|
|
339
|
+
caz, saz = np.cos(np.radians(az)), np.sin(np.radians(az))
|
|
340
|
+
cel, sel = np.cos(np.radians(el)), np.sin(np.radians(el))
|
|
341
|
+
return np.array([cel * saz, sel, cel * caz])
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def quat_as_tait_bryan_angles(q):
|
|
345
|
+
"""Convert quaternion(s) to Tait-Bryan (roll, pitch, yaw) angles.
|
|
346
|
+
|
|
347
|
+
The returned angles correspond to extrinsic rotations: roll around x,
|
|
348
|
+
pitch around y, yaw around z.
|
|
349
|
+
|
|
350
|
+
Borrowing heavily from https://github.com/moble/quaternion/
|
|
351
|
+
and its ``as_euler_angles()`` method, modified using
|
|
352
|
+
https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
|
|
353
|
+
|
|
354
|
+
Parameters
|
|
355
|
+
----------
|
|
356
|
+
q : np.ndarray of quaternion
|
|
357
|
+
Input quaternion array.
|
|
358
|
+
|
|
359
|
+
Returns
|
|
360
|
+
-------
|
|
361
|
+
np.ndarray
|
|
362
|
+
Array of shape ``q.shape + (3,)`` with ``[roll, pitch, yaw]``
|
|
363
|
+
in radians.
|
|
364
|
+
"""
|
|
365
|
+
phi_theta_psi = np.empty(q.shape + (3,), dtype=float)
|
|
366
|
+
w, x, y, z = split_last(quat.as_float_array(q))
|
|
367
|
+
|
|
368
|
+
phi_theta_psi[..., 0] = np.arctan2(2 * (w * x + y * z), 1 - 2 * (x * x + y * y))
|
|
369
|
+
sinp = 2 * (w * y - z * x)
|
|
370
|
+
phi_theta_psi[..., 1] = np.where(
|
|
371
|
+
np.abs(sinp) > 1, np.copysign(np.pi / 2, sinp), np.arcsin(sinp)
|
|
372
|
+
)
|
|
373
|
+
phi_theta_psi[..., 2] = np.arctan2(2 * (w * z + x * y), 1 - 2 * (y * y + z * z))
|
|
374
|
+
return phi_theta_psi
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def zero_doppler_steering(orbit, time, roll=0.0, utc=False, tai=False):
|
|
378
|
+
"""Calculate quaternions yielding perfect zero-Doppler steering.
|
|
379
|
+
|
|
380
|
+
The returned quaternions rotate the GDAR body-fixed frame so that the
|
|
381
|
+
body z-axis (boresight) is perpendicular to the instantaneous
|
|
382
|
+
inertial velocity vector.
|
|
383
|
+
|
|
384
|
+
Parameters
|
|
385
|
+
----------
|
|
386
|
+
orbit : Orbit
|
|
387
|
+
Orbit object providing ``get_statevector``.
|
|
388
|
+
time : array_like
|
|
389
|
+
Azimuth time(s), relative or absolute.
|
|
390
|
+
roll : float, optional
|
|
391
|
+
Roll angle in radians around the body x-axis (velocity direction),
|
|
392
|
+
following the right-hand rule. At roll=0 the z-axis (boresight)
|
|
393
|
+
points as close to nadir as possible. Positive roll tilts the
|
|
394
|
+
boresight to the left of the ground track; negative roll tilts it
|
|
395
|
+
to the right. Default 0.
|
|
396
|
+
utc, tai : bool
|
|
397
|
+
Time scale when *time* is absolute datetime64.
|
|
398
|
+
|
|
399
|
+
Returns
|
|
400
|
+
-------
|
|
401
|
+
quaternion array
|
|
402
|
+
Attitude quaternion(s) in the True-of-Date frame.
|
|
403
|
+
"""
|
|
404
|
+
beta = 0.0060611
|
|
405
|
+
omega = 0.729211585e-4
|
|
406
|
+
|
|
407
|
+
sv_itrs = orbit.get_statevector(time, utc=utc, tai=tai)
|
|
408
|
+
sv_tod = tod_from_itrs(sv_itrs)
|
|
409
|
+
|
|
410
|
+
w = np.array([0, 0, omega])
|
|
411
|
+
ux = unit_vector(sv_tod.vel + np.cross(w, sv_tod.pos))
|
|
412
|
+
|
|
413
|
+
pos = sv_tod.pos.copy()
|
|
414
|
+
pos[2] *= 1.0 + beta
|
|
415
|
+
uy0 = unit_vector(np.cross(ux, pos))
|
|
416
|
+
uz0 = np.cross(ux, uy0)
|
|
417
|
+
|
|
418
|
+
# Apply roll: right-hand rotation around ux (the x/velocity axis)
|
|
419
|
+
cr, sr = np.cos(roll), np.sin(roll)
|
|
420
|
+
uy = cr * uy0 + sr * uz0
|
|
421
|
+
uz = -sr * uy0 + cr * uz0
|
|
422
|
+
|
|
423
|
+
R = np.stack((ux, uy, uz), axis=-1)
|
|
424
|
+
|
|
425
|
+
return quat.from_rotation_matrix(R)
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Statevector-level coordinate frame transformations.
|
|
3
|
+
#
|
|
4
|
+
# Rotation matrices are obtained from gdar.base.coordinates; this module
|
|
5
|
+
# wraps them to operate on statevector recarrays (pos + vel), applying
|
|
6
|
+
# velocity corrections where needed.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
from gdar.base.coordinates import (
|
|
12
|
+
gm2000_from_gcrs as _gm2000_from_gcrs_mat,
|
|
13
|
+
)
|
|
14
|
+
from gdar.base.coordinates import (
|
|
15
|
+
itrs_from_gcrs as _itrs_from_gcrs_mat,
|
|
16
|
+
)
|
|
17
|
+
from gdar.base.coordinates import (
|
|
18
|
+
tirs_from_tod as _tirs_from_tod_mat,
|
|
19
|
+
)
|
|
20
|
+
from gdar.base.coordinates import (
|
|
21
|
+
tod_from_gcrs as _tod_from_gcrs_mat,
|
|
22
|
+
)
|
|
23
|
+
from gdar.base.gtime import astropy_time
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _get_time(statevector):
|
|
27
|
+
"""Convert statevector TAI field to an Astropy Time object."""
|
|
28
|
+
# TODO: update gdar.base.coordinates functions to accept numpy datetime64
|
|
29
|
+
# directly, removing the need for this conversion step.
|
|
30
|
+
return astropy_time(statevector["tai"], tai=True)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def gcrs_from_itrs(statevector):
|
|
34
|
+
"""Transform a statevector from ITRS to GCRS."""
|
|
35
|
+
R = _itrs_from_gcrs_mat(_get_time(statevector)).T
|
|
36
|
+
svec = statevector.copy()
|
|
37
|
+
svec["pos"] = np.matmul(R, statevector["pos"])
|
|
38
|
+
svec["vel"] = np.matmul(R, statevector["vel"])
|
|
39
|
+
return svec
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def itrs_from_gcrs(statevector):
|
|
43
|
+
"""Transform a statevector from GCRS to ITRS."""
|
|
44
|
+
R = _itrs_from_gcrs_mat(_get_time(statevector))
|
|
45
|
+
svec = statevector.copy()
|
|
46
|
+
svec["pos"] = np.matmul(R, statevector["pos"])
|
|
47
|
+
svec["vel"] = np.matmul(R, statevector["vel"])
|
|
48
|
+
return svec
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def tod_from_gcrs(statevector):
|
|
52
|
+
"""Transform a statevector from GCRS to True Equinox of Date.
|
|
53
|
+
|
|
54
|
+
Uses the IAU 2006 precession/nutation model (IERS Technical Note
|
|
55
|
+
no. 36, method 2).
|
|
56
|
+
"""
|
|
57
|
+
R = _tod_from_gcrs_mat(_get_time(statevector))
|
|
58
|
+
sv = statevector.copy()
|
|
59
|
+
sv.pos = np.matmul(R, sv.pos)
|
|
60
|
+
sv.vel = np.matmul(R, sv.vel)
|
|
61
|
+
return sv
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def gcrs_from_tod(statevector):
|
|
65
|
+
"""Transform a statevector from True Equinox of Date to GCRS.
|
|
66
|
+
|
|
67
|
+
Uses the IAU 2006 precession/nutation model (IERS Technical Note
|
|
68
|
+
no. 36, method 2).
|
|
69
|
+
"""
|
|
70
|
+
R = _tod_from_gcrs_mat(_get_time(statevector)).T
|
|
71
|
+
sv = statevector.copy()
|
|
72
|
+
sv.pos = np.matmul(R, sv.pos)
|
|
73
|
+
sv.vel = np.matmul(R, sv.vel)
|
|
74
|
+
return sv
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def tirs_from_tod(statevector):
|
|
78
|
+
"""Transform a statevector from True Equinox of Date (ToD) to TIRS.
|
|
79
|
+
|
|
80
|
+
Applies the Greenwich Apparent Sidereal Time rotation and corrects
|
|
81
|
+
the velocity for Earth rotation.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
statevector : np.recarray
|
|
86
|
+
Statevector with ``tai``, ``pos``, ``vel`` fields, in ToD frame.
|
|
87
|
+
|
|
88
|
+
Returns
|
|
89
|
+
-------
|
|
90
|
+
np.recarray
|
|
91
|
+
Statevector in the TIRS frame.
|
|
92
|
+
"""
|
|
93
|
+
rz = _tirs_from_tod_mat(_get_time(statevector))
|
|
94
|
+
sv = statevector.copy()
|
|
95
|
+
w = np.array([0.0, 0.0, 0.729211585e-4])
|
|
96
|
+
sv.vel = np.matmul(rz, sv.vel + np.cross(w, sv.pos))
|
|
97
|
+
sv.pos = np.matmul(rz, sv.pos)
|
|
98
|
+
return sv
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def tod_from_tirs(statevector):
|
|
102
|
+
"""Transform a statevector from TIRS to True Equinox of Date (ToD).
|
|
103
|
+
|
|
104
|
+
Inverse of ``tirs_from_tod``: removes the Earth-rotation velocity
|
|
105
|
+
correction and applies the inverse sidereal-time rotation.
|
|
106
|
+
|
|
107
|
+
Parameters
|
|
108
|
+
----------
|
|
109
|
+
statevector : np.recarray
|
|
110
|
+
Statevector with ``tai``, ``pos``, ``vel`` fields, in TIRS frame.
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
np.recarray
|
|
115
|
+
Statevector in the ToD frame.
|
|
116
|
+
"""
|
|
117
|
+
rz = _tirs_from_tod_mat(_get_time(statevector)).T
|
|
118
|
+
sv = statevector.copy()
|
|
119
|
+
w = np.array([0.0, 0.0, 0.729211585e-4])
|
|
120
|
+
sv.vel = np.matmul(rz, sv.vel) - np.cross(w, sv.pos)
|
|
121
|
+
sv.pos = np.matmul(rz, sv.pos)
|
|
122
|
+
return sv
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def gm2000_from_gcrs(statevector):
|
|
126
|
+
"""Transform a statevector from GCRS to GM2000 (EME2000 / J2000.0)."""
|
|
127
|
+
R = _gm2000_from_gcrs_mat(_get_time(statevector))
|
|
128
|
+
sv = statevector.copy()
|
|
129
|
+
sv.pos = np.matmul(R, sv.pos)
|
|
130
|
+
sv.vel = np.matmul(R, sv.vel)
|
|
131
|
+
return sv
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def gcrs_from_gm2000(statevector):
|
|
135
|
+
"""Transform a statevector from GM2000 (EME2000 / J2000.0) to GCRS."""
|
|
136
|
+
R = _gm2000_from_gcrs_mat(_get_time(statevector)).T
|
|
137
|
+
sv = statevector.copy()
|
|
138
|
+
sv.pos = np.matmul(R, sv.pos)
|
|
139
|
+
sv.vel = np.matmul(R, sv.vel)
|
|
140
|
+
return sv
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def tod_from_itrs(statevector):
|
|
144
|
+
"""Transform a statevector from ITRS to True Equinox of Date, via GCRS."""
|
|
145
|
+
return tod_from_gcrs(gcrs_from_itrs(statevector))
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def itrs_from_tod(statevector):
|
|
149
|
+
"""Transform a statevector from True Equinox of Date to ITRS, via GCRS."""
|
|
150
|
+
return itrs_from_gcrs(gcrs_from_tod(statevector))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def gm2000_from_itrs(statevector):
|
|
154
|
+
"""Transform a statevector from ITRS to GM2000 (EME2000 / J2000.0),
|
|
155
|
+
via GCRS."""
|
|
156
|
+
return gm2000_from_gcrs(gcrs_from_itrs(statevector))
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def itrs_from_gm2000(statevector):
|
|
160
|
+
"""Transform a statevector from GM2000 (EME2000 / J2000.0) to ITRS,
|
|
161
|
+
via GCRS."""
|
|
162
|
+
return itrs_from_gcrs(gcrs_from_gm2000(statevector))
|