| Title: | R Bindings to the 'Astronomy Engine' C Library |
|---|---|
| Description: | Provides access to the 'Astronomy Engine' C library (<https://github.com/cosinekitty/astronomy>) by Don Cross. The library calculates positions of the Sun, Moon, and planets, and predicts astronomical events such as rise/set times, lunar phases, equinoxes, solstices, eclipses, and transits. It is based on the 'VSOP87' planetary model and is accurate to within approximately one arcminute. This package bundles the single-file C source so that other R packages can link against it via 'LinkingTo' without shipping their own copy. |
| Authors: | Mitchell O'Hara-Wild [aut, cre] (ORCID: <https://orcid.org/0000-0001-6729-7695>), Don Cross [aut, cph] (Author of the bundled Astronomy Engine C library) |
| Maintainer: | Mitchell O'Hara-Wild <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9000 |
| Built: | 2026-05-31 08:33:18 UTC |
| Source: | https://github.com/mitchelloharawild/astronomyengine |
Returns the angle between a celestial body and the Sun, as seen from the center of the Earth. This angle helps determine how easy it is to see the body away from the glare of the Sun.
astro_angle_from_sun(body, time)astro_angle_from_sun(body, time)
body |
Integer code identifying the celestial body. Must not be Earth. |
time |
A POSIXct date-time value indicating the observation time. |
A list with the following elements:
The angle in degrees between the Sun and the body as seen from the center of the Earth.
Status code from the underlying C function.
time <- as.POSIXct("2025-06-15 12:00:00", tz = "UTC") astro_angle_from_sun(body = astro_body["MERCURY"], time = time)time <- as.POSIXct("2025-06-15 12:00:00", tz = "UTC") astro_angle_from_sun(body = astro_body["MERCURY"], time = time)
Calculates the barycentric (solar system barycenter) position and velocity vectors for a given celestial body at a specified time.
astro_bary_state(body, time)astro_bary_state(body, time)
body |
Identifier of celestial body (e.g., |
time |
A POSIXct time value. |
The vectors are expressed in J2000 mean equator coordinates (the mean equator of the Earth at noon UTC on 1 January 2000).
A list with elements:
X position in AU.
Y position in AU.
Z position in AU.
X velocity in AU/day.
Y velocity in AU/day.
Z velocity in AU/day.
Observation time as POSIXct.
time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_bary_state(astro_body["MARS"], time)time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_bary_state(astro_body["MARS"], time)
Integer codes used by Astronomy Engine to identify celestial bodies.
Pass these constants (or their integer values) to functions that accept
a body argument.
astro_bodyastro_body
An integer vector with named elements:
0
1
2
3
4
5
6
7
8
9
10
11 — Earth/Moon Barycenter
12 — Solar System Barycenter
astro_body["SUN"] astro_body["MARS"]astro_body["SUN"] astro_body["MARS"]
Returns the integer code corresponding to the given English name.
astro_body_code(name)astro_body_code(name)
name |
One of the following strings: Sun, Moon, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, EMB, SSB. |
If name is one of the listed strings (case-sensitive), the returned value is the corresponding integer code (see astro_body), otherwise it is -1.
astro_body_code("Sun") astro_body_code("Neptune")astro_body_code("Sun") astro_body_code("Neptune")
Finds the name of a celestial body.
astro_body_name(body)astro_body_name(body)
body |
The celestial body whose name is to be found. |
The English-language name of the celestial body, or "" if the body is not valid.
astro_body_name(astro_body["SUN"]) astro_body_name(9L)astro_body_name(astro_body["SUN"]) astro_body_name(9L)
Given two rotation matrices, returns a combined rotation matrix that is equivalent to rotating based on the first matrix, followed by the second.
astro_combine_rotation(a, b)astro_combine_rotation(a, b)
a |
The first rotation to apply |
b |
The second rotation to apply |
The combined rotation matrix
# Combine two identity matrices (result is also identity) rot_a <- astro_identity_matrix() rot_b <- astro_identity_matrix() combined <- astro_combine_rotation(rot_a, rot_b)# Combine two identity matrices (result is also identity) rot_a <- astro_identity_matrix() rot_b <- astro_identity_matrix() combined <- astro_combine_rotation(rot_a, rot_b)
Uses the computer's system clock to find the current UTC date and time. Converts that date and time to a POSIXct value and returns the result. Callers can pass this value to other Astronomy Engine functions to calculate current observational conditions.
astro_current_time()astro_current_time()
On supported platforms (Linux/Unix, Mac, Windows), the time is measured with microsecond resolution.
A POSIXct value representing the current UTC date and time.
astro_current_time()astro_current_time()
Converts equatorial coordinates in the J2000 frame (mean equator of Earth at noon UTC on 1 January 2000) to true ecliptic coordinates of date (relative to the plane of Earth's orbit on the given date).
astro_ecliptic(x, y, z, time)astro_ecliptic(x, y, z, time)
x |
X coordinate in AU. |
y |
Y coordinate in AU. |
z |
Z coordinate in AU. |
time |
A POSIXct time value. |
A list with elements:
X coordinate (Cartesian) in ecliptic frame in AU.
Y coordinate (Cartesian) in ecliptic frame in AU.
Z coordinate (Cartesian) in ecliptic frame in AU.
Ecliptic longitude in degrees.
Ecliptic latitude in degrees.
Distance in AU.
Observation time as POSIXct.
time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_ecliptic(1.0, 0.5, 0.2, time)time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_ecliptic(1.0, 0.5, 0.2, time)
Calculates the angle around the ecliptic plane of a celestial body as seen from the center of the Sun. The angle is measured prograde (in the direction of Earth's orbit) in degrees from the true equinox of date, with values in the range [0, 360).
astro_ecliptic_longitude(body, time)astro_ecliptic_longitude(body, time)
body |
Identifier of celestial body (e.g., |
time |
A POSIXct time value. |
A numeric value with the ecliptic longitude in degrees [0, 360).
time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_ecliptic_longitude(astro_body[["MARS"]], time)time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_ecliptic_longitude(astro_body[["MARS"]], time)
Determines visibility of a celestial body relative to the Sun, as seen from the Earth. Returns information about the elongation angle and whether the body is best observed in the morning or evening.
astro_elongation(body, time)astro_elongation(body, time)
body |
Integer code identifying the celestial body. |
time |
A POSIXct date-time value indicating the observation time. |
A list with the following elements:
Integer flag indicating morning (0) or evening (1) visibility.
The angle in degrees between the Earth-Sun and Earth-body vectors. Range: [0, 180].
The absolute difference in ecliptic longitude between the body and the Sun. Range: [0, 180].
A POSIXct value representing the observation time.
Status code from the underlying C function.
time <- as.POSIXct("2025-06-15 12:00:00", tz = "UTC") astro_elongation(body = astro_body["MERCURY"], time = time)time <- as.POSIXct("2025-06-15 12:00:00", tz = "UTC") astro_elongation(body = astro_body["MERCURY"], time = time)
Calculates equatorial coordinates of a celestial body as seen by an observer on Earth's surface.
astro_equator( body, time, latitude, longitude, height = 0, equdate = FALSE, aberration = TRUE )astro_equator( body, time, latitude, longitude, height = 0, equdate = FALSE, aberration = TRUE )
body |
Identifier of celestial body (e.g., |
time |
A POSIXct time value. |
latitude |
Observer's geographic latitude in degrees (positive north). |
longitude |
Observer's geographic longitude in degrees (positive east). |
height |
Observer's height in meters above sea level. |
equdate |
One of |
aberration |
One of |
This function corrects for light travel time and topocentric parallax (the angular shift depending on the observer's location on Earth). Parallax correction is most significant for the Moon but has a small effect on other bodies.
A list with elements:
Right ascension in sidereal hours.
Declination in degrees.
Distance in AU.
time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_equator(astro_body[["MARS"]], time, latitude = -33.87, longitude = 151.21)time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_equator(astro_body[["MARS"]], time, latitude = -33.87, longitude = 151.21)
Given an equatorial vector, calculates equatorial angular coordinates (right ascension and declination).
Given an equatorial vector, calculates equatorial angular coordinates (right ascension and declination).
astro_equator_from_vector(vector) astro_equator_from_vector(vector)astro_equator_from_vector(vector) astro_equator_from_vector(vector)
vector |
A list with components:
|
A list representing equatorial coordinates with elements:
ra: Right ascension in sidereal hours (0-24)
dec: Declination in degrees (-90 to +90)
dist: Distance in AU
vec: The original vector
status: Status code (0 = success)
A list with components:
Right ascension in sidereal hours
Declination in degrees
Distance to the celestial body in AU
Equatorial coordinates in Cartesian vector form
Status code (0 = success)
vec <- list(x = 1, y = 0.5, z = 0.25, t = as.POSIXct("2024-01-01", tz = "UTC")) equ <- astro_equator_from_vector(vec) # Convert vector to equatorial coordinates vec <- list(x = 1, y = 0, z = 0, t = as.POSIXct("2024-01-01", tz = "UTC")) equ <- astro_equator_from_vector(vec)vec <- list(x = 1, y = 0.5, z = 0.25, t = as.POSIXct("2024-01-01", tz = "UTC")) equ <- astro_equator_from_vector(vec) # Convert vector to equatorial coordinates vec <- list(x = 1, y = 0, z = 0, t = as.POSIXct("2024-01-01", tz = "UTC")) equ <- astro_equator_from_vector(vec)
Calculates the position of a celestial body as a vector using the center of the Earth as the origin. The result is expressed as a Cartesian vector in the J2000 equatorial system (the mean equator of the Earth at noon UTC on 1 January 2000).
astro_geo_vector(body, time, aberration = "ABERRATION")astro_geo_vector(body, time, aberration = "ABERRATION")
body |
Identifier of celestial body (e.g., |
time |
A POSIXct time value. |
aberration |
One of |
This function corrects for light travel time. The position of the body is back-dated by the amount of time it takes light to travel from that body to an observer on Earth.
The position can optionally be corrected for aberration, an effect causing the apparent direction of the body to be shifted due to transverse movement of the Earth.
A list with elements:
X coordinate in AU.
Y coordinate in AU.
Z coordinate in AU.
Observation time as POSIXct.
time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_geo_vector(astro_body["MARS"], time)time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_geo_vector(astro_body["MARS"], time)
Calculates the position of a celestial body as a vector using the center of the Sun as the origin. The result is expressed as a Cartesian vector in the J2000 equatorial system (the mean equator of the Earth at noon UTC on 1 January 2000).
astro_helio_vector(body, time)astro_helio_vector(body, time)
body |
Identifier of celestial body (e.g., |
time |
A POSIXct time value. |
The position is not corrected for light travel time or aberration.
A list with elements:
X coordinate in AU.
Y coordinate in AU.
Z coordinate in AU.
Observation time as POSIXct.
time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_helio_vector(astro_body[["MARS"]], time)time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_helio_vector(astro_body[["MARS"]], time)
Calculates the apparent location of a body relative to the local horizon of an observer on Earth.
astro_horizon( time, latitude, longitude, ra, dec, refraction = "REFRACTION_NORMAL" )astro_horizon( time, latitude, longitude, ra, dec, refraction = "REFRACTION_NORMAL" )
time |
A POSIXct time value. |
latitude |
Observer's geographic latitude in degrees (positive north). |
longitude |
Observer's geographic longitude in degrees (positive east). |
ra |
Right ascension of the body in sidereal hours. |
dec |
Declination of the body in degrees. |
refraction |
One of |
Given a date, time, geographic location, and equatorial coordinates of a celestial body, this function returns horizontal coordinates (azimuth and altitude) relative to the horizon.
The ra and dec must be equator-of-date coordinates. Equator-of-date coordinates can be
obtained by calling astro_equator() with equdate = "EQUATOR_OF_DATE" and
aberration = "ABERRATION".
Atmospheric refraction correction is recommended. Pass refraction = "REFRACTION_NORMAL"
to correct for optical lensing of the Earth's atmosphere that causes objects to appear
higher above the horizon than they actually are.
A list with elements:
Azimuth angle in degrees (eastward from north).
Altitude angle in degrees (positive above horizon).
Right ascension of the body in sidereal hours.
Declination of the body in degrees.
time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_horizon(time, latitude = -33.87, longitude = 151.21, ra = 10.5, dec = -20.0)time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_horizon(time, latitude = -33.87, longitude = 151.21, ra = 10.5, dec = -20.0)
Given a horizontal Cartesian vector, returns horizontal azimuth and altitude.
Given a horizontal Cartesian vector, returns horizontal azimuth and altitude.
astro_horizon_from_vector(vector, refraction = 1L) astro_horizon_from_vector(vector, refraction = 1L)astro_horizon_from_vector(vector, refraction = 1L) astro_horizon_from_vector(vector, refraction = 1L)
vector |
A list with components:
|
refraction |
Refraction option (0 = REFRACTION_NONE, 1 = REFRACTION_NORMAL, 2 = REFRACTION_JPLHOR). REFRACTION_NORMAL: correct altitude for atmospheric refraction (recommended). REFRACTION_NONE: no atmospheric refraction correction is performed. REFRACTION_JPLHOR: for JPL Horizons compatibility testing only; not recommended for normal use. |
IMPORTANT: This function differs from astro_sphere_from_vector in two ways:
The longitude value represents azimuth defined clockwise from north (e.g., east = +90), preserving traditional navigational conventions.
This function optionally corrects for atmospheric refraction.
The returned structure contains the azimuth in the lon field, measured in
degrees clockwise from north: east = +90 degrees, west = +270 degrees.
IMPORTANT: This function differs from astro_sphere_from_vector() in two ways:
astro_sphere_from_vector() returns a lon value that represents azimuth defined
counterclockwise from north (e.g., west = +90), but this function represents a
clockwise rotation (e.g., east = +90). The difference is because
astro_sphere_from_vector() is intended to preserve the vector "right-hand rule",
while this function defines azimuth in a more traditional way as used in
navigation and cartography.
This function optionally corrects for atmospheric refraction, while
astro_sphere_from_vector() does not.
The returned structure contains the azimuth in lon.
It is measured in degrees clockwise from north: east = +90 degrees, west = +270 degrees.
The altitude is stored in lat.
The distance to the observed object is stored in dist, and is expressed in
astronomical units (AU).
A list representing horizontal coordinates with elements:
lat: Altitude in degrees (-90 to +90)
lon: Azimuth in degrees (0-360, clockwise from north)
dist: Distance in AU
status: Status code (0 = success)
A list with components:
Altitude angle in degrees (corrected for refraction if requested)
Azimuth in degrees clockwise from north
Distance in AU
Status code (0 = success)
# Vector pointing east at 45° altitude vec <- list(x = 0, y = -0.707, z = 0.707, t = as.POSIXct("2024-01-01", tz = "UTC")) hor <- astro_horizon_from_vector(vec, refraction = 1) # Convert horizontal vector to angular coordinates vec <- list(x = 0, y = -1, z = 0, t = as.POSIXct("2024-01-01", tz = "UTC")) hor <- astro_horizon_from_vector(vec, refraction = 1)# Vector pointing east at 45° altitude vec <- list(x = 0, y = -0.707, z = 0.707, t = as.POSIXct("2024-01-01", tz = "UTC")) hor <- astro_horizon_from_vector(vec, refraction = 1) # Convert horizontal vector to angular coordinates vec <- list(x = 0, y = -1, z = 0, t = as.POSIXct("2024-01-01", tz = "UTC")) hor <- astro_horizon_from_vector(vec, refraction = 1)
Finds the hour angle of a body for a given observer and time. The hour angle indicates the body's position in the sky with respect to Earth's rotation.
astro_hour_angle(body, time, latitude, longitude, height = 0)astro_hour_angle(body, time, latitude, longitude, height = 0)
body |
Integer body code (see astro_body). |
time |
A |
latitude |
Observer's geographic latitude in degrees. |
longitude |
Observer's geographic longitude in degrees. |
height |
Observer's height above sea level in metres. Default |
The hour angle is 0 when the body culminates (reaches its highest point), and increases by 1 unit for every sidereal hour that passes. A value of 12 means the body is at its lowest point. A value of 24 is equivalent to 0.
A numeric value representing the hour angle in the range [0, 24), where each unit is one sidereal hour.
t <- as.POSIXct("2025-06-21 12:00:00", tz = "UTC") astro_hour_angle(astro_body[["SUN"]], t, latitude = -33.8688, longitude = 151.2093)t <- as.POSIXct("2025-06-21 12:00:00", tz = "UTC") astro_hour_angle(astro_body[["SUN"]], t, latitude = -33.8688, longitude = 151.2093)
Returns a rotation matrix that has no effect on orientation.
This matrix can be the starting point for other operations,
such as using a series of calls to astro_pivot() to
create a custom rotation matrix.
astro_identity_matrix()astro_identity_matrix()
A list with components:
A 3x3 rotation matrix
Status code (0 = success)
# Create an identity matrix id <- astro_identity_matrix() id# Create an identity matrix id <- astro_identity_matrix() id
Calculates visual magnitude, phase angle, and related illumination information for a celestial body as seen from Earth.
astro_illumination(body, time)astro_illumination(body, time)
body |
An integer representing a celestial body (see |
time |
A |
Visual magnitude is a measure of brightness, where smaller (or negative) values indicate brighter objects and larger values indicate dimmer objects.
Phase angle is the angle in degrees between the Sun and Earth as seen from the body's center. It indicates what fraction of the body appears illuminated from Earth:
Phase angle near 0° means the body appears "full"
Phase angle near 90° means the body appears "half full"
Phase angle near 180° means the body appears as a thin crescent
For Saturn, the returned list includes ring_tilt, which is the tilt angle
in degrees of Saturn's rings as seen from Earth (0° means edge-on and nearly invisible).
A list containing:
The input time as a POSIXct object.
Visual magnitude (numeric).
Phase angle in degrees (numeric).
Fraction of the body illuminated from 0 to 1 (numeric).
Distance from Sun in AU (numeric).
Saturn's ring tilt in degrees, 0 for other bodies (numeric).
# Get illumination data for Mars on 2025-06-21 time <- as.POSIXct("2025-06-21", tz = "UTC") astro_illumination(astro_body["MARS"], time)# Get illumination data for Mars on 2025-06-21 time <- as.POSIXct("2025-06-21", tz = "UTC") astro_illumination(astro_body["MARS"], time)
Given a rotation matrix that performs some coordinate transform, this function returns the matrix that reverses that transform.
astro_inverse_rotation(rotation)astro_inverse_rotation(rotation)
rotation |
A rotation matrix (list with |
A rotation matrix that performs the opposite transformation
# Create a rotation and invert it rot <- astro_identity_matrix() inv <- astro_inverse_rotation(rot)# Create a rotation and invert it rot <- astro_identity_matrix() inv <- astro_inverse_rotation(rot)
Given a UTC calendar date and time, calculates a POSIXct value that can be passed to other Astronomy Engine functions for performing various calculations relating to that date and time.
astro_make_time(year, month, day, hour = 0L, minute = 0L, second = 0)astro_make_time(year, month, day, hour = 0L, minute = 0L, second = 0)
year |
Integer UTC calendar year (e.g. 2025). |
month |
Integer UTC calendar month in the range 1–12. |
day |
Integer UTC calendar day in the range 1–31. |
hour |
Integer UTC hour of the day in the range 0–23. Default 0. |
minute |
Integer UTC minute in the range 0–59. Default 0. |
second |
Numeric UTC floating-point second in the range [0, 60). Default 0. |
It is the caller's responsibility to ensure that the parameter values are correct. The parameters are not checked for validity, and this function never returns any indication of an error. Invalid values, for example passing in February 31, may cause unexpected return values.
A POSIXct value in UTC that represents the given calendar date
and time.
astro_make_time(2025, 6, 21) astro_make_time(2025, 6, 21, 12, 30, 0)astro_make_time(2025, 6, 21) astro_make_time(2025, 6, 21, 12, 30, 0)
Returns the Moon's phase as an angle from 0 to 360 degrees, where 0 is new moon, 90 is first quarter, 180 is full moon, and 270 is third quarter.
astro_moon_phase(time)astro_moon_phase(time)
time |
A POSIXct datetime representing the observation time. |
A numeric value representing the Moon's phase angle in degrees (0-360).
astro_moon_phase(as.POSIXct("2025-02-19 12:00:00", tz = "UTC"))astro_moon_phase(as.POSIXct("2025-02-19 12:00:00", tz = "UTC"))
After using astro_search_lunar_eclipse() to find the first lunar eclipse,
call this function to find the next consecutive lunar eclipse.
Pass in the peak value from the previous call.
astro_next_lunar_eclipse(prev_eclipse_time)astro_next_lunar_eclipse(prev_eclipse_time)
prev_eclipse_time |
A |
A list with the following elements:
Integer code for eclipse type (0=penumbral, 1=partial, 2=total).
Fraction of Moon's disc covered by Earth's umbra (0-1).
POSIXct time of eclipse peak.
Semi-duration of total phase in minutes.
Semi-duration of partial phase in minutes.
Semi-duration of penumbral phase in minutes.
start <- as.POSIXct("2025-01-01", tz = "UTC") first_eclipse <- astro_search_lunar_eclipse(start) next_eclipse <- astro_next_lunar_eclipse(first_eclipse$peak)start <- as.POSIXct("2025-01-01", tz = "UTC") first_eclipse <- astro_search_lunar_eclipse(start) next_eclipse <- astro_next_lunar_eclipse(first_eclipse$peak)
Continues searching for lunar quarters from a previous search result.
Call this function repeatedly after astro_search_moon_quarter() to
find consecutive lunar quarters.
astro_next_moon_quarter(mq)astro_next_moon_quarter(mq)
mq |
A list returned by |
A list with:
Integer 0-3: 0 = new moon, 1 = first quarter, 2 = full moon, 3 = third quarter.
POSIXct datetime of the next lunar quarter.
start <- as.POSIXct("2025-02-19", tz = "UTC") q1 <- astro_search_moon_quarter(start) q2 <- astro_next_moon_quarter(q1) q3 <- astro_next_moon_quarter(q2)start <- as.POSIXct("2025-02-19", tz = "UTC") q1 <- astro_search_moon_quarter(start) q2 <- astro_next_moon_quarter(q1) q3 <- astro_next_moon_quarter(q2)
Finds the next transit of Mercury or Venus after a previous transit. Call this repeatedly to find successive transits.
astro_next_transit(body, prev_transit_time)astro_next_transit(body, prev_transit_time)
body |
Integer code for the planet. Use |
prev_transit_time |
A |
A list with elements:
Start time of the transit (POSIXct).
Time of closest approach (POSIXct).
End time of the transit (POSIXct).
Angular separation at peak in arcminutes.
start <- as.POSIXct("2025-01-01", tz = "UTC") transit1 <- astro_search_transit(astro_body["MERCURY"], start) transit2 <- astro_next_transit(astro_body["MERCURY"], transit1$peak)start <- as.POSIXct("2025-01-01", tz = "UTC") transit1 <- astro_search_transit(astro_body["MERCURY"], start) transit2 <- astro_next_transit(astro_body["MERCURY"], transit1$peak)
Calculates the effective gravitational acceleration experienced by an observer on the Earth's surface. This combines inward gravitational acceleration with outward centrifugal acceleration due to Earth's rotation.
astro_observer_gravity(latitude, height)astro_observer_gravity(latitude, height)
latitude |
The geographic latitude of the observer in degrees north of the equator (range: -90 to +90). By formula symmetry, only the absolute value of latitude matters. |
height |
The elevation above sea level in meters. Accuracy is best in the range 0 to 100,000 meters. |
This function implements the WGS 84 Ellipsoidal Gravity Formula, which accounts for the Earth's oblate spheroid shape and rotation.
The effective gravitational acceleration in meters per second squared (m/s²).
The returned value increases toward the Earth's poles and decreases toward the equator, consistent with the weight measured by a spring scale of a fixed mass moved to different latitudes and heights on Earth.
# Calculate gravity at sea level in different locations gravity_equator <- astro_observer_gravity(latitude = 0, height = 0) gravity_pole <- astro_observer_gravity(latitude = 90, height = 0) gravity_sydney <- astro_observer_gravity(latitude = -33.8688, height = 0) # Gravity is stronger at the poles cat(sprintf("Equator: %.6f m/s²\n", gravity_equator)) cat(sprintf("Pole: %.6f m/s²\n", gravity_pole)) cat(sprintf("Sydney: %.6f m/s²\n", gravity_sydney))# Calculate gravity at sea level in different locations gravity_equator <- astro_observer_gravity(latitude = 0, height = 0) gravity_pole <- astro_observer_gravity(latitude = 90, height = 0) gravity_sydney <- astro_observer_gravity(latitude = -33.8688, height = 0) # Gravity is stronger at the poles cat(sprintf("Equator: %.6f m/s²\n", gravity_equator)) cat(sprintf("Pole: %.6f m/s²\n", gravity_pole)) cat(sprintf("Sydney: %.6f m/s²\n", gravity_sydney))
Calculates the geocentric equatorial position and velocity vectors of an observer on the surface of the Earth, taking into account the Earth's rotation.
astro_observer_state(time, latitude, longitude, height, of_date = FALSE)astro_observer_state(time, latitude, longitude, height, of_date = FALSE)
time |
A POSIXct date and time for which to calculate the observer's state vector. |
latitude |
The geographic latitude of the observer in degrees north of the equator (range: -90 to +90). |
longitude |
The geographic longitude of the observer in degrees east of the prime meridian (range: 0 to 360 or -180 to +180). |
height |
The elevation of the observer above sea level in meters. |
of_date |
Logical. If |
A list with components:
Equatorial x-coordinate in AU
Equatorial y-coordinate in AU
Equatorial z-coordinate in AU
Equatorial x-velocity in AU/day
Equatorial y-velocity in AU/day
Equatorial z-velocity in AU/day
The time (POSIXct) at which the state vector is valid
Status code (0 = success)
The position vector components are expressed in Astronomical Units (AU). Multiply by #KM_PER_AU to convert to kilometers. The velocity components are in AU per day.
If only position is needed without velocity, astro_observer_vector() is slightly
more efficient.
# Get observer state at Sydney Observatory time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") obs_state <- astro_observer_state(time, latitude = -33.8688, longitude = 151.2093, height = 0) obs_state# Get observer state at Sydney Observatory time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") obs_state <- astro_observer_state(time, latitude = -33.8688, longitude = 151.2093, height = 0) obs_state
Calculates the geocentric equatorial position vector of an observer
on the surface of the Earth, taking into account the Earth's rotation.
This is the inverse function of astro_vector_observer().
astro_observer_vector(time, latitude, longitude, height, of_date = FALSE)astro_observer_vector(time, latitude, longitude, height, of_date = FALSE)
time |
A POSIXct date and time for which to calculate the observer's position vector. |
latitude |
The geographic latitude of the observer in degrees north of the equator (range: -90 to +90). |
longitude |
The geographic longitude of the observer in degrees east of the prime meridian (range: 0 to 360 or -180 to +180). |
height |
The elevation of the observer above sea level in meters. |
of_date |
Logical. If |
A list with components:
Equatorial x-coordinate in AU
Equatorial y-coordinate in AU
Equatorial z-coordinate in AU
The time (POSIXct) at which the vector is valid
Status code (0 = success)
The vector represents the displacement from Earth's center to the observer, expressed in Astronomical Units (AU). Multiply by #KM_PER_AU to convert to kilometers.
# Get observer position at Sydney Observatory time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") obs_vec <- astro_observer_vector(time, latitude = -33.8688, longitude = 151.2093, height = 0) obs_vec# Get observer position at Sydney Observatory time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") obs_vec <- astro_observer_vector(time, latitude = -33.8688, longitude = 151.2093, height = 0) obs_vec
Determines where one body appears around the ecliptic plane as seen from Earth, relative to another body's apparent position.
astro_pair_longitude(body1, body2, time)astro_pair_longitude(body1, body2, time)
body1 |
First body (e.g., |
body2 |
Second body (e.g., |
time |
A POSIXct time value. |
The returned angle is in the range [0, 360) degrees. The angle is 0 when the two bodies are at the same ecliptic longitude. The angle increases in the prograde direction (the direction planets orbit the Sun). When the angle is 180 degrees, the bodies appear on opposite sides of the sky.
Neither body1 nor body2 may be the Earth.
A list with element:
Ecliptic longitude difference in degrees [0, 360).
time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_pair_longitude(astro_body["SUN"], astro_body["MOON"], time)time <- as.POSIXct("2025-02-19 22:10:12", tz = "UTC") astro_pair_longitude(astro_body["SUN"], astro_body["MOON"], time)
Given a rotation matrix, a selected coordinate axis, and an angle in degrees, this function pivots the rotation matrix by that angle around that coordinate axis.
astro_pivot(rotation, axis, angle)astro_pivot(rotation, axis, angle)
rotation |
The input rotation matrix |
axis |
An integer that selects which coordinate axis to rotate around: 0 = x, 1 = y, 2 = z. Any other value will fail with an error. |
angle |
An angle in degrees indicating the amount of rotation around the specified axis.
Positive angles indicate rotation counterclockwise as seen from the positive
direction along that axis, looking towards the origin point of the orientation system.
Any finite number of degrees is allowed, but best precision will result from keeping
|
For example, if you have rotation matrix that converts ecliptic coordinates (ECL)
to horizontal coordinates (HOR), but you really want to convert ECL to the orientation
of a telescope camera pointed at a given body, you can use astro_pivot() twice:
(1) pivot around the zenith axis by the body's azimuth, then (2) pivot around the
western axis by the body's altitude angle. The resulting rotation matrix will then
reorient ECL coordinates to the orientation of your telescope camera.
A pivoted rotation matrix
# Create an identity matrix and pivot it rot <- astro_identity_matrix() pivoted <- astro_pivot(rot, axis = 2, angle = 45) # Rotate 45° around z-axis# Create an identity matrix and pivot it rot <- astro_identity_matrix() pivoted <- astro_pivot(rot, axis = 2, angle = 45) # Rotate 45° around z-axis
This function transforms a vector in one orientation to a vector in another orientation.
astro_rotate_vector(rotation, vector)astro_rotate_vector(rotation, vector)
rotation |
A rotation matrix that specifies how the orientation of the vector is to be changed |
vector |
The vector whose orientation is to be changed. A list with components:
|
A vector in the orientation specified by rotation
# Create a vector and rotate it vec <- list(x = 1, y = 0, z = 0, t = as.POSIXct("2024-01-01", tz = "UTC")) rot <- astro_identity_matrix() rotated <- astro_rotate_vector(rot, vec)# Create a vector and rotate it vec <- list(x = 1, y = 0, z = 0, t = as.POSIXct("2024-01-01", tz = "UTC")) rot <- astro_identity_matrix() rotated <- astro_rotate_vector(rot, vec)
Calculates a rotation matrix from J2000 mean ecliptic (ECL) to equatorial of-date (EQD).
astro_rotation_ECL_EQD(time)astro_rotation_ECL_EQD(time)
time |
A POSIXct object representing the date and time. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: ECL = ecliptic system, using equator at J2000 epoch.
Target: EQD = equatorial system, using equator of date.
A rotation matrix that converts ECL to EQD.
astro_rotation_ECL_EQD(Sys.time())astro_rotation_ECL_EQD(Sys.time())
Calculates a rotation matrix from J2000 mean ecliptic (ECL) to J2000 mean equator (EQJ).
astro_rotation_ECL_EQJ()astro_rotation_ECL_EQJ()
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: ECL = ecliptic system, using equator at J2000 epoch.
Target: EQJ = equatorial system, using equator at J2000 epoch.
A rotation matrix that converts ECL to EQJ.
astro_rotation_ECL_EQJ()astro_rotation_ECL_EQJ()
Calculates a rotation matrix from J2000 mean ecliptic (ECL) to horizontal (HOR).
astro_rotation_ECL_HOR(time, latitude, longitude, height)astro_rotation_ECL_HOR(time, latitude, longitude, height)
time |
A POSIXct object representing the date and time of observation. |
latitude |
The observer's geographic latitude in degrees. |
longitude |
The observer's geographic longitude in degrees. |
height |
The observer's elevation above sea level in meters. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: ECL = ecliptic system, using equator at J2000 epoch.
Target: HOR = horizontal system (x = north, y = west, z = zenith).
A rotation matrix that converts ECL to HOR. The components of the horizontal vector are: x = north, y = west, z = zenith (straight up from the observer).
astro_rotation_ECL_HOR(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)astro_rotation_ECL_HOR(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)
Calculates a rotation matrix from true ecliptic of date (ECT) to equator of date (EQD).
astro_rotation_ECT_EQD(time)astro_rotation_ECT_EQD(time)
time |
A POSIXct object representing the date and time of the ecliptic/equator conversion. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: ECT = true ecliptic of date.
Target: EQD = equator of date.
A rotation matrix that converts ECT to EQD.
astro_rotation_ECT_EQD(Sys.time())astro_rotation_ECT_EQD(Sys.time())
Calculates a rotation matrix from true ecliptic of date (ECT) to J2000 mean equator (EQJ).
astro_rotation_ECT_EQJ(time)astro_rotation_ECT_EQJ(time)
time |
A POSIXct object representing the date and time at which the Earth's ecliptic defines the source orientation. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: ECT = ecliptic system, using true equinox of the specified date/time.
Target: EQJ = equatorial system, using mean equator at J2000 epoch.
A rotation matrix that converts ECT to EQJ.
astro_rotation_ECT_EQJ(Sys.time())astro_rotation_ECT_EQJ(Sys.time())
Calculates a rotation matrix from equatorial of-date (EQD) to J2000 mean ecliptic (ECL).
astro_rotation_EQD_ECL(time)astro_rotation_EQD_ECL(time)
time |
A POSIXct object representing the date and time. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: EQD = equatorial system, using equator of date.
Target: ECL = ecliptic system, using equator at J2000 epoch.
A rotation matrix that converts EQD to ECL.
astro_rotation_EQD_ECL(Sys.time())astro_rotation_EQD_ECL(Sys.time())
Calculates a rotation matrix from equator of date (EQD) to true ecliptic of date (ECT).
astro_rotation_EQD_ECT(time)astro_rotation_EQD_ECT(time)
time |
A POSIXct object representing the date and time of the equator/ecliptic conversion. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: EQD = equator of date.
Target: ECT = true ecliptic of date.
A rotation matrix that converts EQD to ECT.
astro_rotation_EQD_ECT(Sys.time())astro_rotation_EQD_ECT(Sys.time())
Calculates a rotation matrix from equatorial of-date (EQD) to J2000 mean equator (EQJ).
astro_rotation_EQD_EQJ(time)astro_rotation_EQD_EQJ(time)
time |
A POSIXct object representing the date and time at which the Earth's equator defines the source orientation. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: EQD = equatorial system, using equator of the specified date/time.
Target: EQJ = equatorial system, using mean equator at J2000 epoch.
A rotation matrix that converts EQD to EQJ.
astro_rotation_EQD_EQJ(Sys.time())astro_rotation_EQD_EQJ(Sys.time())
Calculates a rotation matrix from equatorial of-date (EQD) to horizontal (HOR).
astro_rotation_EQD_HOR(time, latitude, longitude, height)astro_rotation_EQD_HOR(time, latitude, longitude, height)
time |
A POSIXct object representing the date and time at which the Earth's equator applies. |
latitude |
The observer's geographic latitude in degrees. |
longitude |
The observer's geographic longitude in degrees. |
height |
The observer's elevation above sea level in meters. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: EQD = equatorial system, using equator of the specified date/time.
Target: HOR = horizontal system (x = north, y = west, z = zenith).
A rotation matrix that converts EQD to HOR. The components of the horizontal vector are: x = north, y = west, z = zenith (straight up from the observer).
astro_rotation_EQD_HOR(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)astro_rotation_EQD_HOR(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)
Calculates a rotation matrix from J2000 mean equator (EQJ) to J2000 mean ecliptic (ECL).
astro_rotation_EQJ_ECL(time_posix)astro_rotation_EQJ_ECL(time_posix)
time_posix |
A POSIXct object specifying the date and time at which the Earth's equator defines the target orientation. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: EQJ = equatorial system, using equator at J2000 epoch.
Target: ECL = ecliptic system, using equator at J2000 epoch.
A rotation matrix that converts EQJ to ECL at the specified time.
time <- as.POSIXct("2024-01-01", tz = "UTC") astro_rotation_EQJ_ECL(time)time <- as.POSIXct("2024-01-01", tz = "UTC") astro_rotation_EQJ_ECL(time)
Calculates a rotation matrix from J2000 mean equator (EQJ) to true ecliptic of date (ECT).
astro_rotation_EQJ_ECT(time_posix)astro_rotation_EQJ_ECT(time_posix)
time_posix |
A POSIXct object specifying the date and time at which the Earth's equator defines the target orientation. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: EQJ = equatorial system, using mean equator at J2000 epoch.
Target: ECT = ecliptic system, using true equinox of the specified date/time.
A rotation matrix that converts EQJ to ECT at the specified time.
time <- as.POSIXct("2024-01-01", tz = "UTC") astro_rotation_EQJ_ECT(time)time <- as.POSIXct("2024-01-01", tz = "UTC") astro_rotation_EQJ_ECT(time)
Calculates a rotation matrix from J2000 mean equator (EQJ) to equatorial of-date (EQD).
astro_rotation_EQJ_EQD(time_posix)astro_rotation_EQJ_EQD(time_posix)
time_posix |
A POSIXct object specifying the date and time at which the Earth's equator defines the target orientation. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: EQJ = equatorial system, using equator at J2000 epoch.
Target: EQD = equatorial system, using equator of the specified date/time.
A rotation matrix that converts EQJ to EQD at the specified time.
time <- as.POSIXct("2024-01-01", tz = "UTC") astro_rotation_EQJ_EQD(time)time <- as.POSIXct("2024-01-01", tz = "UTC") astro_rotation_EQJ_EQD(time)
Calculates a rotation matrix from J2000 mean equator (EQJ) to galactic (GAL).
astro_rotation_EQJ_GAL()astro_rotation_EQJ_GAL()
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: EQJ = equatorial system, using the equator at the J2000 epoch.
Target: GAL = galactic system (IAU 1958 definition).
A rotation matrix that converts EQJ to GAL.
astro_rotation_EQJ_GAL()astro_rotation_EQJ_GAL()
Calculates a rotation matrix from J2000 mean equator (EQJ) to horizontal (HOR).
astro_rotation_EQJ_HOR(time, latitude, longitude, height)astro_rotation_EQJ_HOR(time, latitude, longitude, height)
time |
A POSIXct object representing the date and time of observation. |
latitude |
The observer's geographic latitude in degrees. |
longitude |
The observer's geographic longitude in degrees. |
height |
The observer's elevation above sea level in meters. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: EQJ = equatorial system, using the equator at J2000 epoch.
Target: HOR = horizontal system (x=North, y=West, z=Zenith).
A rotation matrix that converts EQJ to HOR. The components represent: x = north, y = west, z = zenith (straight up from observer).
astro_rotation_EQJ_HOR(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)astro_rotation_EQJ_HOR(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)
Calculates a rotation matrix from galactic (GAL) to J2000 mean equator (EQJ).
astro_rotation_GAL_EQJ()astro_rotation_GAL_EQJ()
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: GAL = galactic system (IAU 1958 definition).
Target: EQJ = equatorial system, using the equator at the J2000 epoch.
A rotation matrix that converts GAL to EQJ.
astro_rotation_GAL_EQJ()astro_rotation_GAL_EQJ()
Calculates a rotation matrix from horizontal (HOR) to J2000 mean ecliptic (ECL).
astro_rotation_HOR_ECL(time, latitude, longitude, height)astro_rotation_HOR_ECL(time, latitude, longitude, height)
time |
A POSIXct object representing the date and time of observation. |
latitude |
The observer's geographic latitude in degrees. |
longitude |
The observer's geographic longitude in degrees. |
height |
The observer's elevation above sea level in meters. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: HOR = horizontal system (x = north, y = west, z = zenith).
Target: ECL = ecliptic system, using equator at J2000 epoch.
A rotation matrix that converts HOR to ECL.
astro_rotation_HOR_ECL(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)astro_rotation_HOR_ECL(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)
Calculates a rotation matrix from horizontal (HOR) to equatorial of-date (EQD).
astro_rotation_HOR_EQD(time, latitude, longitude, height)astro_rotation_HOR_EQD(time, latitude, longitude, height)
time |
A POSIXct object representing the date and time at which the Earth's equator applies. |
latitude |
The observer's geographic latitude in degrees. |
longitude |
The observer's geographic longitude in degrees. |
height |
The observer's elevation above sea level in meters. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: HOR = horizontal system (x = north, y = west, z = zenith).
Target: EQD = equatorial system, using equator of the specified date/time.
A rotation matrix that converts HOR to EQD.
astro_rotation_HOR_EQD(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)astro_rotation_HOR_EQD(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)
Calculates a rotation matrix from horizontal (HOR) to J2000 mean equator (EQJ).
astro_rotation_HOR_EQJ(time, latitude, longitude, height)astro_rotation_HOR_EQJ(time, latitude, longitude, height)
time |
A POSIXct object representing the date and time of observation. |
latitude |
The observer's geographic latitude in degrees. |
longitude |
The observer's geographic longitude in degrees. |
height |
The observer's elevation above sea level in meters. |
This is one of the family of functions that returns a rotation matrix for converting from one orientation to another.
Source: HOR = horizontal system (x=North, y=West, z=Zenith).
Target: EQJ = equatorial system, using equator at J2000 epoch.
A rotation matrix that converts HOR to EQJ at time and for the observer.
astro_rotation_HOR_EQJ(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)astro_rotation_HOR_EQJ(Sys.time(), latitude = -35.28, longitude = 149.12, height = 0)
Finds when the center of a given body ascends or descends through a given altitude angle, as seen by an observer at the specified location on the Earth.
astro_search_altitude( body, time, latitude, longitude, height = 0, direction = 1L, limit_days = 1, altitude = 0 )astro_search_altitude( body, time, latitude, longitude, height = 0, direction = 1L, limit_days = 1, altitude = 0 )
body |
Integer body code (see astro_body). |
time |
A |
latitude |
Observer's geographic latitude in degrees. |
longitude |
Observer's geographic longitude in degrees. |
height |
Observer's height above sea level in metres. Default |
direction |
|
limit_days |
Maximum number of days to search. When positive, searches
forward in time; when negative, searches backward. Default |
altitude |
The desired altitude angle above (positive) or below (negative) the observer's local horizon, in degrees. Must be in the range [-90, +90]. |
This function is useful for finding twilight times. For example:
Civil dawn: direction = 1, altitude = -6
Civil dusk: direction = -1, altitude = -6
Nautical twilight: altitude = -12
Astronomical twilight: altitude = -18
A POSIXct value in UTC, or NA if no event is found within
limit_days.
t <- as.POSIXct("2025-06-21", tz = "UTC") # Find civil dawn (Sun at -6 degrees) astro_search_altitude(astro_body[["SUN"]], t, latitude = -33.8688, longitude = 151.2093, direction = 1L, altitude = -6)t <- as.POSIXct("2025-06-21", tz = "UTC") # Find civil dawn (Sun at -6 degrees) astro_search_altitude(astro_body[["SUN"]], t, latitude = -33.8688, longitude = 151.2093, direction = 1L, altitude = -6)
Searches for the time when the center of a body reaches a specified hour angle as seen by an observer on the Earth. The hour angle is 0 when the body reaches its highest point (culmination) above the horizon in a given day.
astro_search_hour_angle( body, time, latitude, longitude, height = 0, hour_angle = 0, direction = 1L )astro_search_hour_angle( body, time, latitude, longitude, height = 0, hour_angle = 0, direction = 1L )
body |
Integer body code (see astro_body). |
time |
A |
latitude |
Observer's geographic latitude in degrees. |
longitude |
Observer's geographic longitude in degrees. |
height |
Observer's height above sea level in metres. Default |
hour_angle |
An hour angle value in the range [0, 24) indicating the
number of sidereal hours after the body's most recent culmination.
Default |
direction |
|
To find when a body culminates (reaches maximum altitude), use hour_angle = 0.
To find when a body reaches its minimum altitude, use hour_angle = 12.
A list with elements:
POSIXct time of the event.
Azimuth angle in degrees (0° = North, 90° = East).
Altitude angle in degrees above the horizon.
t <- as.POSIXct("2025-06-21", tz = "UTC") # Find when the Sun culminates (hour_angle = 0) astro_search_hour_angle(astro_body[["SUN"]], t, latitude = -33.8688, longitude = 151.2093)t <- as.POSIXct("2025-06-21", tz = "UTC") # Find when the Sun culminates (hour_angle = 0) astro_search_hour_angle(astro_body[["SUN"]], t, latitude = -33.8688, longitude = 151.2093)
Searches for the first lunar eclipse that occurs after the given start time. A lunar eclipse may be penumbral, partial, or total.
astro_search_lunar_eclipse(start_time)astro_search_lunar_eclipse(start_time)
start_time |
A |
A list with the following elements:
Integer code for eclipse type (0=penumbral, 1=partial, 2=total).
Fraction of Moon's disc covered by Earth's umbra (0-1).
POSIXct time of eclipse peak.
Semi-duration of total phase in minutes.
Semi-duration of partial phase in minutes.
Semi-duration of penumbral phase in minutes.
start <- as.POSIXct("2025-01-01", tz = "UTC") astro_search_lunar_eclipse(start)start <- as.POSIXct("2025-01-01", tz = "UTC") astro_search_lunar_eclipse(start)
Finds the next date and time when Mercury or Venus reaches its maximum angle from the Sun as seen from the Earth. Maximum elongation events are the best opportunities for observing these inner planets.
astro_search_max_elongation(body, start_time)astro_search_max_elongation(body, start_time)
body |
Integer code for the celestial body. Must be Mercury (3) or Venus (2). Other values will fail. |
start_time |
A POSIXct date-time value indicating the search start time. The maximum elongation event found will be the first one occurring after this time. |
A list with the following elements:
Integer flag indicating morning (0) or evening (1) visibility.
The maximum elongation angle in degrees.
The ecliptic separation at maximum elongation.
A POSIXct value representing the time of maximum elongation.
Status code from the underlying C function.
start <- as.POSIXct("2025-01-01 00:00:00", tz = "UTC") astro_search_max_elongation(body = astro_body["MERCURY"], start_time = start)start <- as.POSIXct("2025-01-01 00:00:00", tz = "UTC") astro_search_max_elongation(body = astro_body["MERCURY"], start_time = start)
Searches for the time when the Moon reaches a specified phase angle.
astro_search_moon_phase(target_lon, start_time, limit_days)astro_search_moon_phase(target_lon, start_time, limit_days)
target_lon |
A numeric value in the range [0, 360) representing the target phase angle. Common values: 0 = new moon, 90 = first quarter, 180 = full moon, 270 = third quarter. |
start_time |
A POSIXct datetime to begin the search. |
limit_days |
A numeric value specifying the search window in days. Positive values search forward, negative values search backward. |
A POSIXct datetime when the Moon reaches the target phase.
start <- as.POSIXct("2025-02-19", tz = "UTC") astro_search_moon_phase(0, start, 30) # Find next new moonstart <- as.POSIXct("2025-02-19", tz = "UTC") astro_search_moon_phase(0, start, 30) # Find next new moon
Finds the first lunar quarter (new moon, first quarter, full moon, or third quarter) after the specified date and time.
astro_search_moon_quarter(start_time)astro_search_moon_quarter(start_time)
start_time |
A POSIXct datetime to begin the search. |
A list with:
Integer 0-3: 0 = new moon, 1 = first quarter, 2 = full moon, 3 = third quarter.
POSIXct datetime of the lunar quarter.
start <- as.POSIXct("2025-02-19", tz = "UTC") astro_search_moon_quarter(start)start <- as.POSIXct("2025-02-19", tz = "UTC") astro_search_moon_quarter(start)
Searches for the next date and time when Venus will appear brightest as seen from Earth. This function currently only supports Venus.
astro_search_peak_magnitude(body, start_time)astro_search_peak_magnitude(body, start_time)
body |
An integer representing the celestial body. Currently only
|
start_time |
A |
Venus reaches peak magnitude (maximum brightness) at certain times in its orbit. This is distinct from other brightness events: Mercury's peak magnitude occurs at superior conjunction when it's invisible, and outer planets reach peak magnitude at opposition.
The search may require iterating through multiple synodic periods of Venus to find an event after the specified start time. The function will search forward from the start time until it finds a valid peak magnitude event.
A list containing:
The time of peak magnitude as a POSIXct object.
Visual magnitude at peak brightness (numeric).
Phase angle in degrees (numeric).
Fraction of Venus illuminated (numeric).
Distance from Sun in AU (numeric).
Always 0 for Venus (numeric).
# Find when Venus will next reach peak magnitude after 2025-01-01 start <- as.POSIXct("2025-01-01", tz = "UTC") astro_search_peak_magnitude(astro_body["VENUS"], start)# Find when Venus will next reach peak magnitude after 2025-01-01 start <- as.POSIXct("2025-01-01", tz = "UTC") astro_search_peak_magnitude(astro_body["VENUS"], start)
Searches for the next time when the relative longitude (angle measured in the ecliptic plane from one planet to another as seen from the Sun) reaches a specified target angle.
astro_search_relative_longitude(body, target_rel_lon, start_time)astro_search_relative_longitude(body, target_rel_lon, start_time)
body |
An integer representing a planet other than Earth (see |
target_rel_lon |
Numeric. The desired relative longitude in degrees. Must be in the range [0, 360). |
start_time |
A |
Relative longitude defines several important astronomical events:
Conjunction (inferior for Mercury/Venus, opposition for outer planets)
Superior conjunction (planet on opposite side of Sun from Earth)
For planets orbiting closer to the Sun than Earth (Mercury, Venus), a relative longitude of 0° indicates inferior conjunction. For planets orbiting farther from the Sun, 0° indicates opposition (closest approach).
A POSIXct datetime object indicating when the target relative
longitude is reached.
# Find next opposition of Mars after 2025-01-01 start <- as.POSIXct("2025-01-01", tz = "UTC") astro_search_relative_longitude(astro_body["MARS"], 0, start)# Find next opposition of Mars after 2025-01-01 start <- as.POSIXct("2025-01-01", tz = "UTC") astro_search_relative_longitude(astro_body["MARS"], 0, start)
Searches for the next time a celestial body rises or sets as seen by an observer on the Earth. Rise time is when the body first starts to be visible above the horizon. Set time is when the body appears to vanish below the horizon. This function adjusts for the apparent angular radius of the observed body (significant only for the Sun and Moon) and corrects for atmospheric refraction.
astro_search_rise_set( body, time, latitude, longitude, height = 0, direction = 1L, limit_days = 1, meters_above_ground = 0 )astro_search_rise_set( body, time, latitude, longitude, height = 0, direction = 1L, limit_days = 1, meters_above_ground = 0 )
body |
Integer body code (see astro_body). |
time |
A |
latitude |
Observer's geographic latitude in degrees. |
longitude |
Observer's geographic longitude in degrees. |
height |
Observer's height above sea level in metres. Default |
direction |
|
limit_days |
Maximum number of days to search. When positive, searches
forward in time; when negative, searches backward. Default |
meters_above_ground |
Height of observer above the ground (not sea
level) in metres, for computing the dip of the horizon. Default |
Rise or set may not occur in every 24-hour period. For example, near the Earth's poles, there are long periods where the Sun stays below the horizon, never rising.
A POSIXct value in UTC, or NA if no event is found within
limit_days.
t <- as.POSIXct("2025-06-21", tz = "UTC") # Find next sunrise at Sydney Observatory astro_search_rise_set(astro_body[["SUN"]], t, latitude = -33.8688, longitude = 151.2093)t <- as.POSIXct("2025-06-21", tz = "UTC") # Find next sunrise at Sydney Observatory astro_search_rise_set(astro_body[["SUN"]], t, latitude = -33.8688, longitude = 151.2093)
Searches for the time when the Sun reaches a specified apparent ecliptic longitude as seen from the center of the Earth.
astro_search_sun_longitude(target_lon, start_time, limit_days)astro_search_sun_longitude(target_lon, start_time, limit_days)
target_lon |
Numeric. The desired ecliptic longitude in degrees, relative to the true equinox of date. Must be in the range [0, 360). Conventional values: 0 = March equinox, 90 = June solstice, 180 = September equinox, 270 = December solstice. |
start_time |
POSIXct. The date and time for starting the search. |
limit_days |
Numeric. The number of days to search forward from
|
This function can be used to determine equinoxes and solstices. However,
for calculating all equinoxes and solstices for a calendar year,
astro_seasons() is usually more convenient and efficient.
The search is performed within the time window from start_time to
start_time + limit_days. It is recommended to keep the search window
smaller than 10 days when possible.
A list with element:
POSIXct value indicating when the Sun reaches the target longitude.
# Find the March equinox in 2025 start <- as.POSIXct("2025-03-15", tz = "UTC") astro_search_sun_longitude(0, start, 10)# Find the March equinox in 2025 start <- as.POSIXct("2025-03-15", tz = "UTC") astro_search_sun_longitude(0, start, 10)
Finds the first transit of Mercury or Venus after a specified date. A transit occurs when an inferior planet passes between the Sun and Earth, with the planet's silhouette visible against the Sun.
astro_search_transit(body, start_time)astro_search_transit(body, start_time)
body |
Integer code for the planet. Use |
start_time |
A |
A list with elements:
Start time of the transit (POSIXct).
Time of closest approach (POSIXct).
End time of the transit (POSIXct).
Angular separation at peak in arcminutes.
start <- as.POSIXct("2025-01-01", tz = "UTC") astro_search_transit(astro_body["MERCURY"], start)start <- as.POSIXct("2025-01-01", tz = "UTC") astro_search_transit(astro_body["MERCURY"], start)
Calculates the dates and times of both equinoxes and both solstices for a given calendar year.
astro_seasons(year)astro_seasons(year)
year |
Integer calendar year. While any integer is accepted, only the years 1800 through 2100 have been validated for accuracy. Unit testing against data from the United States Naval Observatory confirms that all equinoxes and solstices for this range are within 2 minutes of the correct time. |
The equinoxes are the moments twice each year when the plane of the Earth's equator passes through the center of the Sun. In other words, the Sun's declination is zero at both equinoxes. The March equinox defines the beginning of spring in the northern hemisphere and the beginning of autumn in the southern hemisphere. The September equinox defines the beginning of autumn in the northern hemisphere and the beginning of spring in the southern hemisphere.
The solstices are the moments twice each year when one of the Earth's poles is most tilted toward the Sun. More precisely, the Sun's declination reaches its minimum value at the December solstice, which defines the beginning of winter in the northern hemisphere and the beginning of summer in the southern hemisphere. The Sun's declination reaches its maximum value at the June solstice, which defines the beginning of summer in the northern hemisphere and the beginning of winter in the southern hemisphere.
A list of POSIXct values (in UTC):
March equinox.
June solstice.
September equinox.
December solstice.
astro_seasons(2025)astro_seasons(2025)
Given a Cartesian vector, returns latitude, longitude, and distance in spherical coordinates.
Given a Cartesian vector, returns latitude, longitude, and distance.
astro_sphere_from_vector(vector) astro_sphere_from_vector(vector)astro_sphere_from_vector(vector) astro_sphere_from_vector(vector)
vector |
A list with components:
|
A list representing spherical coordinates with elements:
lat: Latitude in degrees
lon: Longitude in degrees (0-360)
dist: Distance in AU
status: Status code (0 = success)
A list with components:
Latitude angle: -90..+90 degrees
Longitude angle: 0..360 degrees
Distance in AU
Status code (0 = success)
vec <- list(x = 1, y = 1, z = 1, t = as.POSIXct("2024-01-01", tz = "UTC")) sphere <- astro_sphere_from_vector(vec) # Convert Cartesian to spherical vec <- list(x = 1, y = 0, z = 0, t = as.POSIXct("2024-01-01", tz = "UTC")) sphere <- astro_sphere_from_vector(vec)vec <- list(x = 1, y = 1, z = 1, t = as.POSIXct("2024-01-01", tz = "UTC")) sphere <- astro_sphere_from_vector(vec) # Convert Cartesian to spherical vec <- list(x = 1, y = 0, z = 0, t = as.POSIXct("2024-01-01", tz = "UTC")) sphere <- astro_sphere_from_vector(vec)
Calculates the geocentric ecliptic coordinates of the Sun. The returned coordinates are based on the true equinox of date (the instantaneous intersection of the Earth's equatorial plane and the ecliptic plane at the given time).
astro_sun_position(time)astro_sun_position(time)
time |
A |
This function accounts for light travel time from the Sun and corrects for precession and nutation of the Earth's axis.
A list containing:
Ecliptic longitude in degrees.
Ecliptic latitude in degrees.
A list with Cartesian coordinates:
X-coordinate in AU.
Y-coordinate in AU.
Z-coordinate in AU.
Time as POSIXct.
time <- as.POSIXct("2025-03-20 09:00:00", tz = "UTC") astro_sun_position(time)time <- as.POSIXct("2025-03-20 09:00:00", tz = "UTC") astro_sun_position(time)
Given apparent angular horizontal coordinates, calculates a horizontal Cartesian vector.
Given apparent angular horizontal coordinates, calculate horizontal vector. The input azimuth is measured in degrees clockwise from north (east = +90). The returned vector is in the horizontal system: x = north, y = west, z = zenith (up).
astro_vector_from_horizon(sphere, time, refraction = 1L) astro_vector_from_horizon(sphere, time, refraction = 1L)astro_vector_from_horizon(sphere, time, refraction = 1L) astro_vector_from_horizon(sphere, time, refraction = 1L)
sphere |
A list with components:
|
time |
POSIXct time of the observation |
refraction |
Refraction option (0 = REFRACTION_NONE, 1 = REFRACTION_NORMAL, 2 = REFRACTION_JPLHOR).
This specifies how refraction is to be removed from the altitude stored in |
A list representing a horizontal Cartesian vector with elements:
x: North component in AU
y: West component in AU
z: Zenith (up) component in AU
t: Time value
status: Status code (0 = success)
A list representing a vector in the horizontal system with components:
North component in AU
West component in AU
Zenith (up) component in AU
The date and time (POSIXct)
Status code (0 = success)
# 30° altitude, facing south hor <- list(lat = 30, lon = 180, dist = 1) time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") vec <- astro_vector_from_horizon(hor, time, refraction = 1) # Convert horizontal coordinates to vector sphere <- list(lat = 45, lon = 90, dist = 1) # 45° altitude, 90° azimuth (east) time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") vec <- astro_vector_from_horizon(sphere, time, refraction = 1)# 30° altitude, facing south hor <- list(lat = 30, lon = 180, dist = 1) time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") vec <- astro_vector_from_horizon(hor, time, refraction = 1) # Convert horizontal coordinates to vector sphere <- list(lat = 45, lon = 90, dist = 1) # 45° altitude, 90° azimuth (east) time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") vec <- astro_vector_from_horizon(sphere, time, refraction = 1)
Given spherical coordinates and a time at which they are valid, returns a vector of Cartesian coordinates. The returned value includes the time, as required by the vector structure.
Given spherical coordinates and a time at which they are valid, returns a vector of Cartesian coordinates. The returned value includes the time, as required by the vector type.
astro_vector_from_sphere(sphere, time) astro_vector_from_sphere(sphere, time)astro_vector_from_sphere(sphere, time) astro_vector_from_sphere(sphere, time)
sphere |
A list with components:
|
time |
POSIXct time at which the coordinates are valid |
A list representing a Cartesian vector with elements:
x, y, z: Cartesian coordinates in AU
t: Time value
status: Status code (0 = success)
A list representing a vector with components:
The Cartesian x-coordinate in AU
The Cartesian y-coordinate in AU
The Cartesian z-coordinate in AU
The date and time (POSIXct) at which this vector is valid
Status code (0 = success)
sphere <- list(lat = 45, lon = 90, dist = 1.5) time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") vec <- astro_vector_from_sphere(sphere, time) # Convert spherical to Cartesian sphere <- list(lat = 0, lon = 0, dist = 1) time <- as.POSIXct("2024-01-01", tz = "UTC") vec <- astro_vector_from_sphere(sphere, time)sphere <- list(lat = 45, lon = 90, dist = 1.5) time <- as.POSIXct("2024-01-01 12:00:00", tz = "UTC") vec <- astro_vector_from_sphere(sphere, time) # Convert spherical to Cartesian sphere <- list(lat = 0, lon = 0, dist = 1) time <- as.POSIXct("2024-01-01", tz = "UTC") vec <- astro_vector_from_sphere(sphere, time)
Given a geocentric equatorial position vector, calculates the geographic
latitude, longitude, and elevation of the observer on Earth's surface.
This is the inverse function of astro_observer_vector().
astro_vector_observer(vector, of_date = FALSE)astro_vector_observer(vector, of_date = FALSE)
vector |
A list with components representing the observer's position vector:
The components are expressed in Astronomical Units (AU). Divide kilometers by #KM_PER_AU to convert to AU. |
of_date |
Logical. If |
A list with components:
Geographic latitude in degrees north of the equator (range: -90 to +90)
Geographic longitude in degrees east of the prime meridian (range: 0 to 360)
Elevation above sea level in meters
# Convert a position vector back to geographic coordinates obs_vec <- list( x = 0.00005, y = 0.00005, z = 0.00005, t = as.POSIXct("2024-01-01 12:00:00", tz = "UTC") ) obs <- astro_vector_observer(obs_vec) obs# Convert a position vector back to geographic coordinates obs_vec <- list( x = 0.00005, y = 0.00005, z = 0.00005, t = as.POSIXct("2024-01-01 12:00:00", tz = "UTC") ) obs <- astro_vector_observer(obs_vec) obs
Finds the next solar eclipse in a series after the given eclipse time.
Typically, you pass the peak value from a previous
search_global_solar_eclipse or next_global_solar_eclipse call.
next_global_solar_eclipse(prev_eclipse_time)next_global_solar_eclipse(prev_eclipse_time)
prev_eclipse_time |
A |
A list with the same structure as search_global_solar_eclipse.
start <- as.POSIXct("2025-01-01", tz = "UTC") eclipse1 <- search_global_solar_eclipse(start) eclipse2 <- next_global_solar_eclipse(eclipse1$peak)start <- as.POSIXct("2025-01-01", tz = "UTC") eclipse1 <- search_global_solar_eclipse(start) eclipse2 <- next_global_solar_eclipse(eclipse1$peak)
Finds the next solar eclipse in a series at a specific location.
Typically, you pass the peak value from a previous
search_local_solar_eclipse or next_local_solar_eclipse call.
next_local_solar_eclipse(prev_eclipse_time, latitude, longitude)next_local_solar_eclipse(prev_eclipse_time, latitude, longitude)
prev_eclipse_time |
A |
latitude |
Latitude of the observer in degrees (-90 to 90). |
longitude |
Longitude of the observer in degrees (-180 to 180). |
A list with the same structure as search_local_solar_eclipse.
start <- as.POSIXct("2025-01-01", tz = "UTC") eclipse1 <- search_local_solar_eclipse(start, 37.77, -122.41) eclipse2 <- next_local_solar_eclipse(eclipse1$peak$time, 37.77, -122.41)start <- as.POSIXct("2025-01-01", tz = "UTC") eclipse1 <- search_local_solar_eclipse(start, 37.77, -122.41) eclipse2 <- next_local_solar_eclipse(eclipse1$peak$time, 37.77, -122.41)
Given a lunar apsis event (perigee or apogee), finds the next apsis event in the series. This function alternates between finding perigees and apogees.
next_lunar_apsis(apsis)next_lunar_apsis(apsis)
apsis |
A list returned from |
A list with the same structure as search_lunar_apsis():
A POSIXct datetime of the next lunar apsis.
Integer code: 0 for perigee, 1 for apogee.
Distance in astronomical units.
Distance in kilometers.
start <- as.POSIXct("2025-01-01", tz = "UTC") apsis1 <- search_lunar_apsis(start) apsis2 <- next_lunar_apsis(apsis1) apsis3 <- next_lunar_apsis(apsis2)start <- as.POSIXct("2025-01-01", tz = "UTC") apsis1 <- search_lunar_apsis(start) apsis2 <- next_lunar_apsis(apsis1) apsis3 <- next_lunar_apsis(apsis2)
Given an aphelion event, this function finds the next perihelion event,
and vice versa. This requires an apsis event obtained from a call to
search_planet_apsis() or a previous call to next_planet_apsis().
next_planet_apsis(body, apsis)next_planet_apsis(body, apsis)
body |
Integer constant identifying the planet. Use |
apsis |
An apsis event (a list) obtained from a call to
|
A list with the same structure as returned by search_planet_apsis():
An integer flag: 0 for perihelion, 1 for aphelion.
A POSIXct value representing the date and time of the
next planetary apsis.
The distance from the planet to the Sun in astronomical units.
The distance from the planet to the Sun in kilometers.
# Find successive apsis events for Mars start <- as.POSIXct("2025-01-01", tz = "UTC") apsis1 <- search_planet_apsis(astro_body["MARS"], start) apsis2 <- next_planet_apsis(astro_body["MARS"], apsis1) apsis3 <- next_planet_apsis(astro_body["MARS"], apsis2)# Find successive apsis events for Mars start <- as.POSIXct("2025-01-01", tz = "UTC") apsis1 <- search_planet_apsis(astro_body["MARS"], start) apsis2 <- next_planet_apsis(astro_body["MARS"], apsis1) apsis3 <- next_planet_apsis(astro_body["MARS"], apsis2)
Searches for the first solar eclipse visible anywhere on Earth's surface
that occurs after the given start time. A solar eclipse may be partial,
annular, or total. To find a series of eclipses, use next_global_solar_eclipse
with the peak time from the previous result.
search_global_solar_eclipse(start_time)search_global_solar_eclipse(start_time)
start_time |
A |
A list containing:
Status code (0 = success).
Type of eclipse: 0 = partial, 1 = annular, 2 = total.
Peak time of the eclipse as POSIXct.
Distance in kilometers from Earth's center to Moon's shadow axis.
Latitude of peak eclipse.
Longitude of peak eclipse.
start <- as.POSIXct("2025-01-01", tz = "UTC") search_global_solar_eclipse(start)start <- as.POSIXct("2025-01-01", tz = "UTC") search_global_solar_eclipse(start)
Searches for the first solar eclipse visible at a specific location on Earth's
surface that occurs after the given start time. Note: an eclipse reported by
this function might be partly or completely invisible due to the time of day.
To find a series of eclipses, use next_local_solar_eclipse with the
peak time from the previous result.
search_local_solar_eclipse(start_time, latitude, longitude)search_local_solar_eclipse(start_time, latitude, longitude)
start_time |
A |
latitude |
Latitude of the observer in degrees (-90 to 90). |
longitude |
Longitude of the observer in degrees (-180 to 180). |
A list containing:
Status code (0 = success).
Type of eclipse: 0 = partial, 1 = annular, 2 = total.
Start of partial eclipse (list with time and altitude).
Start of total/annular eclipse (list with time and altitude).
Peak of eclipse (list with time and altitude).
End of total/annular eclipse (list with time and altitude).
End of partial eclipse (list with time and altitude).
start <- as.POSIXct("2025-01-01", tz = "UTC") eclipse <- search_local_solar_eclipse(start, latitude = 37.77, longitude = -122.41)start <- as.POSIXct("2025-01-01", tz = "UTC") eclipse <- search_local_solar_eclipse(start, latitude = 37.77, longitude = -122.41)
Finds the date and time of the Moon's closest distance (perigee) or farthest distance (apogee) with respect to the Earth after a given start time.
search_lunar_apsis(start_time)search_lunar_apsis(start_time)
start_time |
A |
The closest point is called perigee and the farthest point is called apogee. The word apsis refers to either event.
To iterate through consecutive alternating perigee and apogee events, call
search_lunar_apsis() once, then use the return value to call
next_lunar_apsis(). After that, keep feeding the previous return value from
next_lunar_apsis() into another call of next_lunar_apsis() as many times
as desired.
A list containing:
A POSIXct datetime of the next lunar apsis.
Integer code: 0 for perigee (APSIS_PERICENTER), 1 for apogee (APSIS_APOCENTER).
Distance in astronomical units.
Distance in kilometers.
start <- as.POSIXct("2025-01-01", tz = "UTC") apsis <- search_lunar_apsis(start) apsis$time apsis$kindstart <- as.POSIXct("2025-01-01", tz = "UTC") apsis <- search_lunar_apsis(start) apsis$time apsis$kind
Finds the date and time of a planet's perihelion (closest approach to the Sun) or aphelion (farthest distance from the Sun) after a given time.
search_planet_apsis(body, start_time)search_planet_apsis(body, start_time)
body |
Integer constant identifying the planet. Use |
start_time |
A |
The closest point is called perihelion and the farthest point is called aphelion.
To iterate through consecutive alternating perihelion and aphelion events,
call search_planet_apsis() once, then use the return value to call
next_planet_apsis(). After that, keep feeding the previous return value
into another call of next_planet_apsis() as many times as desired.
A list containing:
An integer flag: 0 for perihelion, 1 for aphelion.
A POSIXct value representing the date and time of the
next planetary apsis.
The distance from the planet to the Sun in astronomical units.
The distance from the planet to the Sun in kilometers.
# Find the next perihelion/aphelion of Mars after 2025-01-01 start <- as.POSIXct("2025-01-01", tz = "UTC") apsis <- search_planet_apsis(astro_body["MARS"], start) apsis# Find the next perihelion/aphelion of Mars after 2025-01-01 start <- as.POSIXct("2025-01-01", tz = "UTC") apsis <- search_planet_apsis(astro_body["MARS"], start) apsis