Skip to content

Commit 171ef02

Browse files
Advertise .xyz attribute instead of .position
1 parent 71a2324 commit 171ef02

29 files changed

+188
-164
lines changed

CHANGELOG.rst

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ Changelog
99
Released versions
1010
-----------------
1111

12+
Next version
13+
------------
14+
15+
* The documentation now uses the newer name ``.xyz``, which has been
16+
quietly supported for around three years, for the
17+
:class:`~skyfield.positionlib.ICRF` attribute that was originally
18+
named ``.position`` and holds its position vector. The old name
19+
(which will continue to be supported) could lead to code that looked a
20+
little redundant, asking for the ``position`` of a ``position``::
21+
22+
position = mars.at(t)
23+
print(position.position)
24+
25+
So Skyfield now encourages code to ask for ``position.xyz`` instead.
26+
Another advantage is that the new name self-documents that it holds a
27+
numeric vector with three components.
28+
1229
v1.50 — 2024 February 15
1330
------------------------
1431

TODO.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ forget.
9797

9898
* Several interesting API questions arise because of
9999
`this Stack Overflow question <https://stackoverflow.com/questions/62654081/path-between-two-topos-locations-determine-latitude-and-longitude-where-a-giv>`_.
100-
Should I finally go through with renaming ``.position`` to ``.xyz``?
101100
Should ``.from_altaz()`` retain observer data
102101
so that a follow-up ``.altaz()`` returns the same coordinates?
103102
Should positions fully support math,
@@ -142,9 +141,9 @@ forget.
142141

143142
* Solar eclipses.
144143

145-
* Some users need to add offsets to vectors like .position and .velocity
144+
* Some users need to add offsets to vectors like .xyz and .velocity
146145
so should there be some official way to do so? We should either
147-
document the maneuver ``.position = Distance(au=old_position.au +
146+
document the maneuver ``.xyz = Distance(au=old_position.au +
148147
xyz)`` or (gulp!) make ``Distance`` objects susceptible of being
149148
modified in-place without their various units going out of sync.
150149

builders/build_novas_tests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def output_ephemeris_tests():
291291
def test_position_and_velocity(de405, ts):
292292
t = ts.tt_jd({jd!r})
293293
e = de405['earth'].at(t)
294-
compare(e.position.au, {pos!r}, 10 * meter)
294+
compare(e.xyz.au, {pos!r}, 10 * meter)
295295
compare(e.velocity.au_per_d, {vel!r}, 1e-5 * meter / one_second)
296296
297297
""")
@@ -316,7 +316,7 @@ def test_{slug}_geocentric_date{i}(de405, ts):
316316
e = de405['earth'].at(t)
317317
p = de405[{planet!r}]
318318
319-
distance = length_of((e - p.at(t)).position.au)
319+
distance = length_of((e - p.at(t)).xyz.au)
320320
compare(distance * OLD_AU, {distance1!r}, 0.014 * meter)
321321
322322
astrometric = e.observe(p)

design/broadcasting.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def main():
1717
observer = planets['earth'].at(t)
1818
target = planets['mars']
1919
r, v, t2, light_time = cfltt(observer, target)
20-
print(t.shape, observer.position.km.shape, r.shape)
20+
print(t.shape, observer.xyz.km.shape, r.shape)
2121

2222
print('==== N times, one observer, one target ====')
2323

@@ -26,7 +26,7 @@ def main():
2626
observer = planets['earth'].at(t)
2727
target = planets['mars']
2828
r, v, t2, light_time = cfltt(observer, target)
29-
print(t.shape, observer.position.km.shape, '->', r.shape)
29+
print(t.shape, observer.xyz.km.shape, '->', r.shape)
3030
print('Here is where the planet wound up:')
3131
print(r)
3232

@@ -45,17 +45,17 @@ def main():
4545
earth._at = build_multi_at(earth._at)
4646

4747
observer = earth.at(t)
48-
print('observer', observer.position.au.shape)
48+
print('observer', observer.xyz.au.shape)
4949

5050
target = planets['mars']
5151
target._at = build_multi_at(target._at) # Turn Mars into 2 planets.
52-
print('target', target.at(t).position.au.shape)
52+
print('target', target.at(t).xyz.au.shape)
5353

5454
# t = ts.tt(t.tt[:,None]) # What if we add a dimension to t?
5555
# print('t', t.shape)
5656

5757
r, v, t2, light_time = _correct_for_light_travel_time2(observer, target)
58-
print(t.shape, observer.position.km.shape, '->', r.shape)
58+
print(t.shape, observer.xyz.km.shape, '->', r.shape)
5959

6060
print('Does it look like a second planet 1 AU away at the same 4 times?')
6161
print('First planet:')
@@ -74,17 +74,17 @@ def main():
7474
earth = planets['earth']
7575
earth._at = build_multi_at(earth._at)
7676
observer = earth.at(t)
77-
print('observer', observer.position.au.shape)
77+
print('observer', observer.xyz.au.shape)
7878

7979
target = planets['mars']
8080
target._at = build_multi_at(target._at) # Turn Mars into 2 planets.
81-
print('target', target.at(t).position.au.shape)
81+
print('target', target.at(t).xyz.au.shape)
8282

8383
# t = ts.tt(t.tt[:,None]) # What if we add a dimension to t?
8484
# print('t', t.shape)
8585

8686
r, v, t2, light_time = _correct_for_light_travel_time3(observer, target)
87-
print(t.shape, observer.position.km.shape, '->', r.shape)
87+
print(t.shape, observer.xyz.km.shape, '->', r.shape)
8888

8989
print('Does it look like a second planet 1 AU away at the same 4 times?')
9090
print('First planet:')
@@ -109,15 +109,15 @@ def main():
109109

110110
earth = planets['earth']
111111
observer = earth.at(t)
112-
print('observer', observer.position.au.shape)
112+
print('observer', observer.xyz.au.shape)
113113
print('Supplementing dimensions')
114-
observer.position.au = observer.position.au[:,:,None]
114+
observer.xyz.au = observer.xyz.au[:,:,None]
115115
observer.velocity.au_per_d = observer.velocity.au_per_d[:,:,None]
116-
print('observer', observer.position.au.shape)
116+
print('observer', observer.xyz.au.shape)
117117

118118
target = planets['mars']
119119
target._at = build_multi_at(target._at) # Turn Mars into 2 planets.
120-
print('target', target.at(t).position.au.shape)
120+
print('target', target.at(t).xyz.au.shape)
121121

122122
# TODO: if we work out how we can expand the time's dimensions, as
123123
# in the following line, before earth.at(t) without raising an
@@ -130,7 +130,7 @@ def main():
130130
# print('t !!!!!!!!!!!!!!', t.tdb_fraction.shape)
131131

132132
r, v, t2, light_time = _correct_for_light_travel_time4(observer, target)
133-
print(t.shape, observer.position.au.shape, '->', r.shape)
133+
print(t.shape, observer.xyz.au.shape, '->', r.shape)
134134

135135
print('Does it look like a second planet 1 AU away at the same 4 times?')
136136
print('First planet:')
@@ -180,7 +180,7 @@ def _correct_for_light_travel_time(observer, target):
180180
whole = t.whole
181181
tdb_fraction = t.tdb_fraction
182182

183-
cposition = observer.position.au
183+
cposition = observer.xyz.au
184184
cvelocity = observer.velocity.au_per_d
185185

186186
tposition, tvelocity, gcrs_position, message = target._at(t)
@@ -222,7 +222,7 @@ def _correct_for_light_travel_time2(observer, target):
222222
whole = t.whole
223223
tdb_fraction = t.tdb_fraction
224224

225-
cposition = observer.position.au
225+
cposition = observer.xyz.au
226226
cvelocity = observer.velocity.au_per_d
227227

228228
tposition, tvelocity, gcrs_position, message = target._at(t)
@@ -276,7 +276,7 @@ def _correct_for_light_travel_time3(observer, target):
276276
whole = t.whole
277277
tdb_fraction = t.tdb_fraction
278278

279-
cposition = observer.position.au
279+
cposition = observer.xyz.au
280280
cvelocity = observer.velocity.au_per_d
281281

282282
cposition = cposition.T
@@ -327,7 +327,7 @@ def _correct_for_light_travel_time4(observer, target):
327327
whole = t.whole
328328
tdb_fraction = t.tdb_fraction
329329

330-
cposition = observer.position.au
330+
cposition = observer.xyz.au
331331
cvelocity = observer.velocity.au_per_d
332332

333333
print('======', cposition.shape)

design/satellite_is_sunlit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
sun_km_per_s = distance_sun_travels_in_one_orbit / 10 / 365.25 / 24 / 60 / 60
4646
print('Sun km/s:', sun_km_per_s)
4747

48-
light_delay_seconds = s2[0].position.length().light_seconds()
48+
light_delay_seconds = s2[0].xyz.length().light_seconds()
4949
print('Sample light delay from Sun to Earth (seconds):', light_delay_seconds)
5050

5151
print('How far does the Sun move in that time?')

design/sgp4_parallel.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ def test_iss():
108108
satellites = [iss]
109109
city = Topos('44.0247 N', '88.5426 W')
110110
for geo1 in positions_for(satellites, city, times):
111-
print(geo1.position.km)
111+
print(geo1.xyz.km)
112112
#
113113
print("Compare to EarthSatellite at():")
114114
difference = iss - city
115115
geo2 = difference.at(times)
116116
#geo2 = iss.at(times)
117-
print(geo2.position.km)
117+
print(geo2.xyz.km)
118118
#
119-
assert np.allclose(geo1.position.km, geo2.position.km)
119+
assert np.allclose(geo1.xyz.km, geo2.xyz.km)
120120
one_m_per_hour = 1.0 * 24.0 / AU_M
121121
assert abs(geo1.velocity.au_per_d - geo2.velocity.au_per_d).max() < one_m_per_hour
122122

@@ -136,8 +136,8 @@ def test_two_sats():
136136
kestrel1, iss1 = positions
137137
iss2 = (iss - city).at(times)
138138
kestrel2 = (kestrel - city).at(times)
139-
assert np.allclose(iss1.position.km, iss2.position.km)
140-
assert np.allclose(kestrel1.position.km, kestrel2.position.km)
139+
assert np.allclose(iss1.xyz.km, iss2.xyz.km)
140+
assert np.allclose(kestrel1.xyz.km, kestrel2.xyz.km)
141141
assert np.allclose(iss1.velocity.au_per_d, iss2.velocity.au_per_d)
142142
assert np.allclose(kestrel1.velocity.au_per_d, kestrel2.velocity.au_per_d)
143143

design/subpoint_accuracy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def main():
2323
for degrees in trial_angles:
2424
top = Topos(latitude_degrees=degrees, longitude_degrees=123,
2525
elevation_m=elevation_m)
26-
xyz_au = top.at(t).position.au
26+
xyz_au = top.at(t).xyz.au
2727
xyz_au = einsum('ij...,j...->i...', t.M, xyz_au)
2828
lat, lon, elev = reverse_terra(xyz_au, t.gast, n)
2929
lat = lat / DEG2RAD

documentation/api.rst

+5-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ Astronomical positions
328328

329329
The `ICRF` three-dimensional position vector serves as the base class
330330
for all of the following position classes. Each class represents an
331-
|xyz| ``.position`` and ``.velocity`` vector oriented to the axes of
331+
|xyz| ``.xyz`` and ``.velocity`` vector oriented to the axes of
332332
the International Celestial Reference System (ICRS),
333333
an inertial system that’s an update to J2000
334334
and that does not rotate with respect to the universe.
@@ -364,7 +364,7 @@ All position objects offer five basic attributes:
364364
.. PAT START
365365
366366
============= ========================================
367-
``.position`` An |xyz| `Distance`.
367+
``.xyz`` An |xyz| `Distance`.
368368
``.velocity`` An |xyz| `Velocity`, or ``None``.
369369
``.t`` The `Time` of the position, or ``None``.
370370
``.center`` Body the vector is measured from.
@@ -373,6 +373,9 @@ All position objects offer five basic attributes:
373373

374374
.. PAT END
375375
376+
The ``.xyz`` attribute used to be named ``.position``. To support older
377+
code, Skyfield will always recognize the original name as an alias.
378+
376379
All positions support these methods:
377380

378381
.. autosummary::

documentation/astropy.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ between the two libraries:
5959
t = ts.utc(1980, 1, 1)
6060
barycentric = earth.at(t)
6161

62-
print(barycentric.position.to(u.au))
62+
print(barycentric.xyz.to(u.au))
6363
print(barycentric.velocity.to(u.au / u.day))
6464

6565
.. testoutput::

documentation/earth-satellites.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ than those of the old J2000 system.)
508508
t = ts.utc(2014, 1, 23, 11, 18, 7)
509509

510510
geocentric = satellite.at(t)
511-
print(geocentric.position.km)
511+
print(geocentric.xyz.km)
512512

513513
.. testoutput::
514514

@@ -586,7 +586,7 @@ as plain |xyz| coordinates:
586586
.. testcode::
587587

588588
topocentric = difference.at(t)
589-
print(topocentric.position.km)
589+
print(topocentric.xyz.km)
590590

591591
.. testoutput::
592592

@@ -928,12 +928,12 @@ that are limiting this TLE set’s predictions:
928928

929929
geocentric = sat.at(ts.utc(2013, 11, 9))
930930
print('Before:')
931-
print(geocentric.position.km)
931+
print(geocentric.xyz.km)
932932
print(geocentric.message)
933933

934934
geocentric = sat.at(ts.utc(2013, 11, 13))
935935
print('\nAfter:')
936-
print(geocentric.position.km)
936+
print(geocentric.xyz.km)
937937
print(geocentric.message)
938938

939939
.. testoutput::

documentation/examples.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,11 @@ to both Accra, Ghana, and the top of Mount Bierstadt in Colorado.
752752
t = ts.utc(2019, 1, 1)
753753

754754
bierstadt = wgs84.latlon(39.5828 * N, 105.6686 * W, elevation_m=4287.012)
755-
m1 = length_of(bierstadt.at(t).position.m)
755+
m1 = length_of(bierstadt.at(t).xyz.m)
756756
print(int(m1))
757757

758758
accra = wgs84.latlon(5.6037 * N, 0.1870 * W, elevation_m=61)
759-
m2 = length_of(accra.at(t).position.m)
759+
m2 = length_of(accra.at(t).xyz.m)
760760
print(int(m2))
761761

762762
assert m2 > m1

documentation/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ and return results in native AstroPy units:
8282
.. testcode::
8383

8484
from astropy import units as u
85-
xyz = astrometric.position.to(u.au)
85+
xyz = astrometric.xyz.to(u.au)
8686
altitude = alt.to(u.deg)
8787

8888
print(xyz)

documentation/positions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ They support operations like:
224224

225225
.. testcode::
226226

227-
print('Earth x,y,z:', barycentric.position.au, 'au')
227+
print('Earth x,y,z:', barycentric.xyz.au, 'au')
228228
print('Mars relative velocity:', astrometric.velocity.km_per_s, 'km/s')
229229
print('Time of observation:', apparent.t.utc_strftime())
230230

documentation/time.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ We can compute the position of the Earth as an example:
540540
earth = planets['earth']
541541

542542
t = ts.utc(2014, 1, 1)
543-
pos = earth.at(t).position.au
543+
pos = earth.at(t).xyz.au
544544
print(pos)
545545

546546
.. testoutput::
@@ -553,7 +553,7 @@ We can compute the position of the Earth as an example:
553553

554554
days = [1, 2, 3, 4]
555555
t = ts.utc(2014, 1, days)
556-
pos = earth.at(t).position.au
556+
pos = earth.at(t).xyz.au
557557
print(pos)
558558

559559
.. testoutput::

skyfield/elementslib.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def osculating_elements_of(position, reference_frame=None, gm_km3_s2=None):
4242
' should specify one using the `gm_km3_s2` keyword argument')
4343

4444
if reference_frame is not None:
45-
position_vec = Distance(reference_frame.dot(position.position.au))
45+
position_vec = Distance(reference_frame.dot(position.xyz.au))
4646
velocity_vec = Velocity(reference_frame.dot(position.velocity.au_per_d))
4747
else:
48-
position_vec = position.position
48+
position_vec = position.xyz
4949
velocity_vec = position.velocity
5050

5151
return OsculatingElements(position_vec,

0 commit comments

Comments
 (0)