Skip to content

Commit 5bd963d

Browse files
committed
update unit tests and documentation
1 parent 4bdc3bc commit 5bd963d

2 files changed

Lines changed: 36 additions & 16 deletions

File tree

skyfield/documentation/earth-satellites.rst

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

553553
* :meth:`~skyfield.toposlib.Geoid.intersection_of()`
554554

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

558561
.. testcode::
559562

560-
from skyfield.framelib import LVLH
561-
562-
satellite_lvlh = LVLH(geocentric)
563-
attitude = satellite_lvlh.icrf_looking_vector(pitch=0.0, roll=0.0)
564-
print('Frame:', satellite_lvlh)
565-
print('Attitude:', attitude)
563+
attitude = satellite._attitude(t=t, roll=0.0, pitch=0.0, yaw=0.0)
564+
print('Attitude.target:', attitude.target)
565+
print('Attitude.center:', attitude.center)
566566

567567
.. testoutput::
568568

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

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

590590
.. testcode::
591591

592-
intersection = wgs84.intersection_of(geocentric, attitude)
592+
intersection = wgs84.intersection_of(attitude)
593593
print('Latitude:', intersection.latitude)
594594
print('Longitude:', intersection.longitude)
595595

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)