# How to use the skyfield.units.Distance function in skyfield

## To help you get started, we’ve selected a few skyfield examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

skyfielders / python-skyfield / skyfield / positionlib.py View on Github
``````# TODO: wobble

position_au = einsum('ij...,j...->i...', R, position_au)
r_au, alt, az = to_polar(position_au)

if temperature_C is None:
else:
if temperature_C == 'standard':
temperature_C = 10.0
if pressure_mbar == 'standard':
pressure_mbar = 1010.0 * exp(-elevation_m / 9.1e3)
alt = refract(alt * RAD2DEG, temperature_C, pressure_mbar)
alt = Angle(degrees=alt)

skyfielders / python-skyfield / skyfield / positionlib.py View on Github
``````def distance(self):
"""Compute the distance from the origin to this position.

>>> v = ICRF([1, 1, 0])
>>> print(v.distance())
1.41421 au

"""
return Distance(length_of(self.position.au))``````
skyfielders / python-skyfield / skyfield / positionlib.py View on Github
``````def galactic_xyz(self):
"""Compute galactic coordinates (x,y,z)"""
vector = _GALACTIC.dot(self.position.au)
return Distance(vector)``````
skyfielders / python-skyfield / skyfield / positionlib.py View on Github
``````Reference Frame (ITRF), an internationally agreed upon
Earth-centered Earth-fixed (ECEF) coordinate system that
rotates with the surface of the Earth itself.

"""
if self.center != 399:
raise ValueError("you can only ask for an Earth-centered position"
" to be converted into an ITRF coordinate")

t = self.t
au = mxv(t.M, self.position.au)

spin = rot_z(- t.gast * tau / 24.0)
au = mxv(spin, array(au))

return Distance(au)
``````
skyfielders / python-skyfield / skyfield / positionlib.py View on Github
``````def ecliptic_latlon(self, epoch=None):
"""Compute J2000 ecliptic coordinates (lat, lon, distance)

If you instead want the coordinates referenced to the dynamical
system defined by the Earth's true equator and equinox, provide
an epoch time.

"""
vector = self.ecliptic_xyz(epoch)
d, lat, lon = to_spherical(vector.au)
Distance(au=d))``````
skyfielders / python-skyfield / skyfield / toposlib.py View on Github
``````raise TypeError('please provide either latitude_degrees='
' or latitude='
' with north being positive')

if longitude_degrees is not None:
longitude = Angle(degrees=longitude_degrees)
elif isinstance(longitude, (str, float, tuple)):
longitude = _interpret_ltude(longitude, 'longitude', 'E', 'W')
elif not isinstance(longitude, Angle):
' or longitude='
' with east being positive')

self.latitude = latitude
self.longitude = longitude
self.elevation = Distance(m=elevation_m)
self.x = x
self.y = y

self.target = str(self)``````
skyfielders / python-skyfield / skyfield / positionlib.py View on Github
``````def _to_spice_frame(self, name):
vector = self.position.au
vector = inertial_frames[name].dot(vector)
d, dec, ra = to_polar(vector)
Distance(au=d))``````
skyfielders / python-skyfield / skyfield / units.py View on Github
``````def length(self):
"""Compute the length when this is an x,y,z vector.

The Euclidean vector length of this vector is returned as a new
:class:`~skyfield.units.Distance` object.

&gt;&gt;&gt; from skyfield.api import Distance
&gt;&gt;&gt; d = Distance(au=[1, 1, 0])
&gt;&gt;&gt; d.length()

"""
return Distance(au=length_of(self.au))``````
skyfielders / python-skyfield / skyfield / positionlib.py View on Github
``````def __init__(self, position_au, velocity_au_per_d=None, t=None,
center=None, target=None, observer_data=None):
self.t = t
self.position = Distance(position_au)
if velocity_au_per_d is None:
self.velocity = None
else:
self.velocity = Velocity(velocity_au_per_d)
# TODO: are center and target useful? Then why are they not
# propagated down to Astrometric and Apparent positions?
self.center = center
self.target = target
self.observer_data = observer_data``````
skyfielders / python-skyfield / skyfield / positionlib.py View on Github
``````def frame_latlon(self, frame):
"""Return as longitude, latitude, and distance in the given frame."""
R = frame.rotation_at(self.t)
vector = mxv(R, self.position.au)
d, lat, lon = to_spherical(vector)
Distance(au=d))``````

## skyfield

Elegant astronomy for Python

MIT