API Reference¶
Quick links to the sections below:
Version¶
Skyfield offers a tuple skyfield.VERSION
that lets your code determine the installed version of Skyfield.
import skyfield
print(skyfield.VERSION)
Opening files¶
# File you already have.
from skyfield.api import load_file
planets = load_file('~/Downloads/de405.bsp')
|
Open a file on your local drive, using its extension to guess its type. |
# File you want Skyfield to download automatically.
from skyfield.api import load
ts = load.timescale()
planets = load('de405.bsp')
|
A tool for downloading and opening astronomical data files. |
|
Return the URL Skyfield will try downloading for a given filename. |
|
Return how recently |
|
Download a file, even if it’s already on disk; return its path. |
|
Return the path to |
|
Return a |
|
Load and parse a TLE file, returning a list of Earth satellites. |
Time scales¶
A script will typically start by building a single Skyfield Timescale
to use for all date and time conversions:
from skyfield import api
ts = api.load.timescale()
Its methods are:
Return the current date and time as a |
|
|
Return a |
|
Return a |
|
Build a |
|
Build a |
|
Build a |
|
Build a |
|
Build a |
|
Build a |
|
Build a |
|
Build a |
|
Build a |
|
Build a |
Build a Skyfield |
|
|
Return |
Time objects¶
The Time
class is Skyfield’s way of representing
either a single time, or a whole array of times.
The same time can be represented in several different time scales.
|
International Atomic Time (TAI) as a Julian date. |
|
Terrestrial Time (TT) as a Julian date. |
|
Terrestrial Time (TT) as floating point Julian years. |
|
Barycentric Dynamical Time (TDB) as a Julian date. |
|
Universal Time (UT1) as a Julian date. |
A couple of offsets between time scales are also available.
|
Difference TT − UT1 in seconds. |
|
Difference UT1 − UTC in seconds. |
Other time scales and conversions are available through its methods.
Convert to a string like ``A.D. |
|
|
Convert to an ISO 8601 string like |
|
Format the UTC time using a Python datetime formatting string. |
Convert to a Python |
|
Convert to a Python |
|
|
Convert to a Python |
Convert to a Python |
|
Return the proleptic Gregorian ordinal of the UTC date. |
|
TAI as a (year, month, day, hour, minute, second) Calendar date. |
|
TT as a (year, month, day, hour, minute, second) Calendar date. |
|
TDB as a (year, month, day, hour, minute, second) Calendar date. |
|
UT1 as a (year, month, day, hour, minute, second) Calendar date. |
|
|
Format TAI with a datetime strftime() format string. |
|
Format TT with a datetime strftime() format string. |
|
Format TDB with a datetime strftime() format string. |
|
Format UT1 with a datetime strftime() format string. |
3×3 rotation matrix: ICRS → equinox of this date. |
|
3×3 rotation matrix: equinox of this date → ICRS. |
|
Greenwich Mean Sidereal Time (GMST) in hours. |
|
Greenwich Apparent Sidereal Time (GAST) in hours. |
|
Compute the 3×3 nutation matrix N for this date. |
|
Compute the 3×3 precession matrix P for this date. |
|
Return an AstroPy object representing this time. |
Time utilities¶
|
Convert Julian day |
Vector functions¶
The common API shared by planets, Earth locations, and Earth satellites.
Given a time, computes a corresponding position. |
|
At time |
Either adding two vector functions v1 + v2
or subtracting them v1 - v2
produces a new function of time that, when invoked with .at(t)
,
returns the sum or difference of the vectors returned by the two functions.
Planetary ephemerides¶
By downloading a SpiceKernel
file,
Skyfield users can build vector functions
predicting the positions of the Moon, Sun, and planets.
See Planets and their moons: JPL ephemeris files.
|
Ephemeris file in NASA .bsp format. |
Close this ephemeris file. |
|
Return the comments string of this kernel. |
|
Return all target names that are valid with this kernel. |
|
|
Translate a target name into its integer code. |
Kernels also support lookup using the Python kernel['Mars']
syntax,
in which case they return a function of time
that returns vectors from the Solar System barycenter to the named body.
Planetary magnitudes¶
- skyfield.magnitudelib.planetary_magnitude(position)¶
Given the position of a planet, return its visual magnitude.
>>> from skyfield.api import load >>> from skyfield.magnitudelib import planetary_magnitude >>> ts = load.timescale() >>> t = ts.utc(2020, 7, 31) >>> eph = load('de421.bsp') >>> astrometric = eph['earth'].at(t).observe(eph['jupiter barycenter']) >>> print('%.2f' % planetary_magnitude(astrometric)) -2.73
The formulae are from Mallama and Hilton “Computing Apparent Planetary Magnitude for the Astronomical Almanac” (2018). Two of the formulae have inherent limits:
Saturn’s magnitude is unknown and the function will return
nan
(the floating-point value “Not a Number”) if the “illumination phase angle” — the angle of the vertex observer-Saturn-Sun — exceeds 6.5°.Neptune’s magnitude is unknown and will return
nan
if the illumination phase angle exceeds 1.9° and the position’s date is before the year 2000.
And one formula is not fully implemented (though contributions are welcome!):
Skyfield does not compute which features on Mars are facing the observer, which can introduce an error of ±0.06 magnitude.
Planetary reference frames¶
Planetary constants manager. |
|
Planetary constants frame, for building rotation matrices. |
Almanac¶
Routines to search for events like sunrise, sunset, and Moon phase.
|
Build a function of time that returns the quarter of the year. |
|
Return the Moon phase 0°–360° at time |
|
Build a function of time that returns the moon phase 0 through 3. |
|
Build a function of time that identifies lunar nodes. |
|
Build a function to find oppositions and conjunctions with the Sun. |
|
Build a function of time for finding when a body transits the meridian. |
|
Build a function of time that returns whether the Sun is up. |
|
Build a function of time returning whether it is dark, twilight, or day. |
|
Build a function of time that returns whether a body is up. |
|
Return the lunar eclipses between |
Geographic locations¶
Skyfield supports two Earth datums for translating between latitude/longitude and Cartesian coordinates. They each use a slightly different estimate of the Earth’s oblateness. The most popular is WGS84, which is used by the world’s GPS devices:
Each datum offers a method for taking a latitude and longitude
and returning a GeographicPosition
that knows its position in space:
|
Return a |
Going in the other direction, there are several methods for converting an existing Skyfield position into latitude, longitude, and height:
|
Return the latitude and longitude of a |
|
Return the height above the Earth’s ellipsoid of a |
|
Return the |
|
Return the point on the ellipsoid directly below a |
Once you have used either of the above approaches
to build a GeographicPosition
,
it offers several methods:
At time |
|
Return the Local Apparent Sidereal Time, in hours, at time |
|
|
Predict how the atmosphere will refract a position. |
Compute rotation from GCRS to this location’s altazimuth system. |
Kepler orbits¶
See Kepler Orbits for computing the positions of comets, asteroids, and other minor planets.
Kepler orbit data¶
|
Parse a Minor Planet Center orbits file into a Pandas dataframe. |
|
Parse a Minor Planet Center comets file into a Pandas dataframe. |
Parse a Minor Planet Center comets file into a Pandas dataframe. |
Earth satellites¶
By downloading TLE satellite element sets, Skyfield users can build vector functions that predict their positions. See Earth Satellites.
|
An Earth satellite loaded from a TLE file and propagated with SGP4. |
|
Build an EarthSatellite from a raw sgp4 Satrec object. |
|
The SGP4-specific True Equator Mean Equinox frame of reference. |
Stars and other distant objects¶
The position in the sky of a star or other fixed object. |
Astronomical positions¶
The ICRF
three-dimensional position vector serves as the base class
for all of the following position classes. Each class represents an
(x,y,z) .position
and .velocity
vector oriented to the axes of
the International Celestial Reference System (ICRS),
an inertial system that’s an update to J2000
and that does not rotate with respect to the universe.
An (x,y,z) position and velocity oriented to the ICRF axes. |
|
An (x,y,z) position measured from the Solar System barycenter. |
|
An astrometric (x,y,z) position relative to a particular observer. |
|
An apparent (x,y,z) position relative to a particular observer. |
|
An (x,y,z) position measured from the center of the Earth. |
Positions are usually generated by the at(t)
method of a vector
function, rather than being constructed manually. But you can also
build a position directly from a raw vector, or from right ascension and
declination coordinates with
position_of_radec()
.
|
Build a position object from a right ascension and declination. |
All position objects offer five basic attributes:
|
An (x,y,z) |
|
An (x,y,z) |
|
The |
|
Body the vector is measured from. |
|
Body the vector is measured to. |
All positions support these methods:
Compute the distance from the origin to this position. |
|
Compute the magnitude of the velocity vector. |
|
|
Compute equatorial RA, declination, and distance. |
Compute hour angle, declination, and distance. |
|
|
Compute (alt, az, distance) relative to the observer's horizon |
|
Generate an Apparent position from an altitude and azimuth. |
|
Return the angle between this position and another. |
|
Return this position as an (x,y,z) vector in a reference frame. |
|
Return (x,y,z) position and velocity vectors in a reference frame. |
|
Return longitude, latitude, and distance in the given frame. |
|
Return a reference frame longitude, latitude, range, and rates. |
|
Constructor: build a position from two vectors in a reference frame. |
|
Convert this distance to an AstroPy |
|
Return this position’s phase angle: the angle Sun-target-observer. |
Return the fraction of the target’s disc that is illuminated. |
|
|
Return whether a position in Earth orbit is in sunlight. |
In addition to the methods above, several subclasses of the base position class provide unique methods of their own:
|
Compute the |
Compute an |
Reference frames¶
The dynamical frame of the Earth’s true equator and equinox of date. |
|
The International Terrestrial Reference System (ITRS). |
|
Reference frame of the true ecliptic and equinox of date. |
|
Reference frame of the true ecliptic and equinox at J2000. |
|
Galactic System II reference frame. |
Constellations¶
- skyfield.api.load_constellation_map()¶
Load Skyfield’s constellation boundaries and return a lookup function.
Skyfield carries an internal map of constellation boundaries that is optimized for quick position lookup. Call this function to load the map and return a function mapping position to constellation name.
>>> from skyfield.api import position_of_radec, load_constellation_map >>> constellation_at = load_constellation_map() >>> north_pole = position_of_radec(0, 90) >>> constellation_at(north_pole) 'UMi'
If you pass an array of positions, you’ll receive an array of names.
- skyfield.api.load_constellation_names()¶
Return a list of abbreviation-name tuples, like
('Aql', 'Aquila')
.You can pass the list to Python’s
dict()
to build a dictionary that turns a constellation abbreviation into a full name:>>> from skyfield.api import load_constellation_names >>> d = dict(load_constellation_names()) >>> d['UMa'] 'Ursa Major'
By swapping the order of the two items, you can map the other way, from a full name back to an abbreviation:
>>> f = dict(reversed(item) for item in load_constellation_names()) >>> f['Ursa Major'] 'UMa'
- skyfield.data.stellarium.parse_constellations(lines)¶
Return a list of constellation outlines.
Each constellation outline is a list of edges, each of which is drawn between a pair of specific stars:
[ (name, [(star1, star2), (star3, star4), ...]), (name, [(star1, star2), (star3, star4), ...]), ... ]
Each name is a 3-letter constellation abbreviation; each star is an integer Hipparcos catalog number. See Drawing a finder chart for comet NEOWISE for an example of how to combine this data with the Hipparcos star catalog to draw constellation lines on a chart.
- skyfield.data.stellarium.parse_star_names(lines)¶
Return the names in a Stellarium
star_names.fab
file.Returns a list of named tuples, each of which offers a
.hip
attribute with a Hipparcos catalog number and a.name
attribute with the star name. Do not depend on the tuple having only length two; additional fields may be added in the future.
Searching¶
- skyfield.searchlib.find_discrete()¶
Find the times at which a discrete function of time changes value.
This routine is used to find instantaneous events like sunrise, transits, and the seasons. See Searching for the dates of astronomical events for how to use it yourself.
- skyfield.searchlib.find_maxima()¶
Find the local maxima in the values returned by a function of time.
This routine is used to find events like highest altitude and maximum elongation. See Searching for the dates of astronomical events for how to use it yourself.
- skyfield.searchlib.find_minima()¶
Find the local minima in the values returned by a function of time.
This routine is used to find events like minimum elongation. See Searching for the dates of astronomical events for how to use it yourself.
Osculating orbital elements¶
This routine returns osculating orbital elements for an object’s instantaneous position and velocity.
|
Produce the osculating orbital elements for a position. |
|
Distance object |
|
Angle object |
|
Angle object |
|
Angle object |
|
numpy.ndarray |
|
Angle object |
|
Angle object |
|
Angle object |
|
Angle object |
|
Angle object |
|
Angle object |
|
Distance object |
|
Time object |
|
numpy.ndarray |
|
Distance object |
|
Distance object |
|
Distance object |
|
Time object |
|
Angle object |
|
Angle object |
Units¶
Distance |
|
Velocity |
|
Angle |
|
Rate at which an angle is changing |
All three kinds of quantity support one or more methods.
Astronomical units. |
|
Kilometers (1,000 meters). |
|
Meters. |
|
Compute the length when this is an (x,y,z) vector. |
|
Return the length of this vector in light seconds. |
|
|
Convert this distance to the given AstroPy unit. |
Astronomical units per day. |
|
Kilometers per second. |
|
Meters per second. |
|
|
Convert this velocity to the given AstroPy unit. |
Radians (𝜏 = 2𝜋 in a circle). |
|
Hours (24h in a circle). |
|
Degrees (360° in a circle). |
|
Return the angle in arcminutes. |
|
Return the angle in arcseconds. |
|
Return the angle in milliarcseconds. |
|
|
Convert this angle to the given AstroPy unit. |
|
Convert to a tuple (hours, minutes, seconds). |
|
Convert to a tuple (sign, hours, minutes, seconds). |
|
Return a string like |
|
Convert to a tuple (degrees, minutes, seconds). |
|
Convert to a tuple (sign, degrees, minutes, seconds). |
|
Return a string like |
|
|
|
|
|
|
|
|
|
|
Units per day of Terrestrial Time. |
|
Units per hour of Terrestrial Time. |
|
Units per minute of Terrestrial Time. |
|
Units per second of Terrestrial Time. |
Trigonometry¶
|
Return the position angle of one position with respect to another. |