Skip to content

Commit 727a1d6

Browse files
committed
update unit tests and documentation
1 parent 7af39ae commit 727a1d6

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

skyfield/documentation/earth-satellites.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -518,22 +518,22 @@ position in the line-of-sight:
518518

519519
* :meth:`~skyfield.toposlib.Geoid.intersection_of()`
520520

521-
For example, first contruct an inertial :data:`~skyfield.framelib.LVLH` frame
522-
for the satellite position, then use the frame to define an attitude vector:
521+
For example, `roll`, `pitch`, and `yaw` angles can be provided to the
522+
:meth:`~skyfield.sgp4lib.EarthSatellite._attitude()` method, which will return
523+
a :class:`~skyfield.positionlib.ICRF` position vector representing
524+
the satellite's line-of-sight. The `target` and `center` attributes store the
525+
attitude vector and the satellite position, respectively;
523526

524527
.. testcode::
525528

526-
from skyfield.framelib import LVLH
527-
528-
satellite_lvlh = LVLH(geocentric)
529-
attitude = satellite_lvlh.icrf_looking_vector(pitch=0.0, roll=0.0)
530-
print('Frame:', satellite_lvlh)
531-
print('Attitude:', attitude)
529+
attitude = satellite._attitude(t=t, roll=0.0, pitch=0.0, yaw=0.0)
530+
print('Attitude.target:', attitude.target)
531+
print('Attitude.center:', attitude.center)
532532

533533
.. testoutput::
534534

535-
Frame: <LVLH> Center (399) Pointing Local Vertical Local Horizontal reference frame.
536-
Attitude: [ 0.57745914 0.2781511 -0.76757599]
535+
Attitude.target: [ 0.57745914 0.2781511 -0.76757599]
536+
Attitude.center: <Geocentric ICRS position and velocity at date t center=399 target=-125544>
537537

538538
In this case we have set the pitch and roll to zero, so the attitude vector
539539
is pointing toward the center of mass of the Earth, i.e., a unit vector
@@ -555,7 +555,7 @@ use the :meth:`~skyfield.toposlib.Geoid.intersection_of()` method:
555555

556556
.. testcode::
557557

558-
intersection = wgs84.intersection_of(geocentric, attitude)
558+
intersection = wgs84.intersection_of(attitude)
559559
print('Latitude:', intersection.latitude)
560560
print('Longitude:', intersection.longitude)
561561

skyfield/tests/test_earth_satellites.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_neutral_attitude():
220220
a = sat._attitude(t)
221221
# Attitude should be the negative of position vector.
222222
neg_p = -array(p) / length_of(array(p))
223-
assert allclose(a.center.au, p)
223+
assert allclose(a.center.xyz.au, p)
224224
assert allclose(a.target, neg_p)
225225

226226
def test_attitude():
@@ -232,17 +232,37 @@ def test_attitude():
232232

233233
for angle in angles:
234234
abs_angle = abs(angle)
235+
# Angle between attitude and position vector after pitch or roll should
236+
# be equal to the provided angle.
235237
a = sat._attitude(t, roll=angle)
236238
assert isclose(angle_between(a.target, -pos), abs_angle)
237239

238240
a = sat._attitude(t, pitch=angle)
239241
assert isclose(angle_between(a.target, -pos), abs_angle)
240242

243+
# Yaw without other rotations should not change attitude.
241244
a = sat._attitude(t, yaw=angle)
242245
assert isclose(angle_between(a.target, -pos), 0.0)
243246

244-
a = sat._attitude(t, pitch=angle, yaw=angle)
245-
assert allclose(angle_between(a.target, -pos), abs_angle)
247+
# Angle between attitude and position vector after yaw with pitch or
248+
# or roll should be equal to the provided angle, regardless of order.
249+
a = sat._attitude(t, pitch=angle, yaw=angle, rotation_order="yz")
250+
assert isclose(angle_between(a.target, -pos), abs_angle)
251+
252+
a = sat._attitude(t, pitch=angle, yaw=angle, rotation_order="zy")
253+
assert isclose(angle_between(a.target, -pos), abs_angle)
254+
255+
a = sat._attitude(t, roll=angle, yaw=angle, rotation_order="xz")
256+
assert isclose(angle_between(a.target, -pos), abs_angle)
257+
258+
a = sat._attitude(t, roll=angle, yaw=angle, rotation_order="zx")
259+
assert isclose(angle_between(a.target, -pos), abs_angle)
246260

247-
a = sat._attitude(t, roll=angle, yaw=angle)
248-
assert allclose(angle_between(a.target, -pos), abs_angle)
261+
# Rotations applied in reverse will result in different attitudes,
262+
# but the angle between attitude and position vector should be equal.
263+
axyz = sat._attitude(t, roll=angle, pitch=angle, yaw=angle)
264+
azyx = sat._attitude(t, roll=angle, pitch=angle, yaw=angle,
265+
rotation_order="zyx")
266+
assert isclose(
267+
angle_between(axyz.target, -pos), angle_between(azyx.target, -pos)
268+
)

0 commit comments

Comments
 (0)