Files
astronomy/source/golang

astronomy

import "github.com/cosinekitty/astronomy/source/golang"

Package astronomy implements Astronomy Engine for the Go programming language.

It provides a suite of well-tested functions for calculating positions of the Sun, Moon, and planets, along with many practical phenomena visible from observers on the Earth, such as sunrise, sunset, seasons, eclipses, transits, and lunar phases.

Index

Constants

const (
    DaysPerTropicalYear       = 365.24217                                 // the number of days in one tropical year
    SpeedOfLightAuPerDay      = 173.1446326846693                         // the speed of light in vacuum expressed in astronomical units per day
    KmPerAu                   = 1.4959787069098932e+8                     // the number of kilometers in one astronomical unit
    AuPerLightYear            = 63241.07708807546                         // the number of astronomical units in one light year
    AsecToRad                 = 4.848136811095359935899141e-6             // factor to convert arcseconds to radians
    SunRadiusKm               = 695700.0                                  // the radius of the Sun in kilometers
    MercuryEquatorialRadiusKm = 2440.5                                    // the equatorial radius of Mercury in kilometers
    MercuryPolarRadiusKm      = 2438.3                                    // the polar radius of Mercury in kilometers
    VenusRadiusKm             = 6051.8                                    // the radius of Venus in kilometers
    EarthEquatorialRadiusKm   = 6378.1366                                 // the equatorial radius of the Earth in kilometers
    EarthEquatorialRadiusAu   = EarthEquatorialRadiusKm / KmPerAu         //the equatorial radius of the Earth in astronomical units
    EarthFlattening           = 0.996647180302104                         // the ratio of the Earth's polar radius to its equatorial radius
    EarthPolarRadiusKm        = EarthEquatorialRadiusKm * EarthFlattening // the polar radius of the Earth in kilometers
    MoonEquatorialRadiusKm    = 1738.1                                    // the Moon's equatorial radius in kilometers
    MoonPolarRadiusKm         = 1736.0                                    // the Moon's polar radius in kilometers
    MarsEquatorialRadiusKm    = 3396.2                                    // the equatorial radius of Mars in kilometers
    MarsPolarRadiusKm         = 3376.2                                    // the polar radius of Mars in kilometers
    JupiterEquatorialRadiusKm = 71492.0                                   // the equatorial radius of Jupiter in kilometers
    JupiterPolarRadiusKm      = 66854.0                                   // the polar radius of Jupiter in kilometers
    JupiterMeanRadiusKm       = 69911.0                                   // the volumetric mean radius of Jupiter in kilometers
    IoRadiusKm                = 1821.6                                    // the radius of Jupiter's moon Io in kilometers
    EuropaRadiusKm            = 1560.8                                    // the radius of Jupiter's moon Europa in kilometers
    GanymedeRadiusKm          = 2631.2                                    // the radius of Jupiter's moon Ganymede in kilometers
    CallistoRadiusKm          = 2410.3                                    // the radius of Jupiter's moon Callisto in kilometers
    SaturnEquatorialRadiusKm  = 60268.0                                   // the equatorial radius of Saturn in kilometers
    SaturnPolarRadiusKm       = 54364.0                                   // the polar radius of Saturn in kilometers
    UranusEquatorialRadiusKm  = 25559.0                                   // the equatorial radius of Uranus in kilometers
    UranusPolarRadiusKm       = 24973.0                                   // the polar radius of Uranus in kilometers
    NeptuneEquatorialRadiusKm = 24764.0                                   // the equatorial radius of Neptune in kilometers
    NeptunePolarRadiusKm      = 24341.0                                   // the polar radius of Neptune in kilometers
    PlutoRadiusKm             = 1188.3                                    // the radius of Pluto in kilometers
)

const (
    InvalidBody Body  = -1
    Mercury           = 0 // The planet Mercury
    Venus                 // The planet Venus
    Earth                 // The planet Earth
    Mars                  // The planet Mars
    Jupiter               // The planet Jupiter
    Saturn                // The planet Saturn
    Uranus                // The planet Uranus
    Neptune               // The planet Neptune
    Pluto                 // The dwarf planet Pluto
    Sun                   // The Sun
    Moon                  // The Earth's Moon
    Emb                   // The Earth/Moon Barycenter
    Ssb                   // The Solar System Barycenter
    Star1       = 101     // User-defined star #1
    Star2                 // User-defined star #2
    Star3                 // User-defined star #3
    Star4                 // User-defined star #4
    Star5                 // User-defined star #5
    Star6                 // User-defined star #6
    Star7                 // User-defined star #7
    Star8                 // User-defined star #8
)

const (
    InvalidNode    NodeEventKind = 0
    AscendingNode                = 1
    DescendingNode               = -1
)

func AngleBetween

func AngleBetween(avec AstroVector, bvec AstroVector) float64

AngleBetween calculates the angle in degrees between two vectors. Given a pair of vectors avec and bvec, this function returns the angle in degrees between the vectors in 3D space. The angle is measured in the plane that contains both vectors. The returned value is in the closed range [0, 180].

func DaysFromCalendar

func DaysFromCalendar(year, month, day, hour, minute int, second float64) float64

func DefineStar

func DefineStar(body Body, ra, dec, distanceLightYears float64) error

func DegreesFromRadians

func DegreesFromRadians(radians float64) float64

DegreesFromRadians converts an angle expressed in radians to an angle expressed in degrees.

func Dot

func Dot(a, b AstroVector) float64

Returns the scalar dot product of two vectors.

func RadiansFromDegrees

func RadiansFromDegrees(degrees float64) float64

RadiansFromDegrees converts an angle expressed in degrees to an angle expressed in radians.

func SiderealTime

func SiderealTime(time *AstroTime) float64

Given a date and time, SiderealTime calculates the rotation of the Earth, represented by the equatorial angle of the Greenwich prime meridian with respect to distant stars (not the Sun, which moves relative to background stars by almost one degree per day). This angle is called Greenwich Apparent Sidereal Time (GAST). GAST is measured in sidereal hours in the half-open range [0, 24). When GAST = 0, it means the prime meridian is aligned with the of-date equinox, corrected at that time for precession and nutation of the Earth's axis. In this context, the "equinox" is the direction in space where the Earth's orbital plane (the ecliptic) intersects with the plane of the Earth's equator, at the location on the Earth's orbit of the (seasonal) March equinox. As the Earth rotates, GAST increases from 0 up to 24 sidereal hours, then starts over at 0. To convert to degrees, multiply the return value by 15. As an optimization, this function caches the sidereal time value in the time parameter. The value is reused later as needed, to avoid redundant calculations.

type AstroMoonQuarter

type AstroMoonQuarter struct {
    Quarter int
    Time    AstroTime
}

type AstroSearchFunc

type AstroSearchFunc func(context interface{}, time AstroTime) float64

type AstroTime

type AstroTime struct {
    // Ut holds the floating point number of days of Universal Time since noon UTC January 1, 2000.
    // Astronomy Engine approximates UTC and UT1 as being the same thing, although they are
    // not exactly equivalent; UTC and UT1 can disagree by up to 0.9 seconds.
    // This approximation is sufficient for the accuracy requirements of Astronomy Engine.
    //
    // Universal Time Coordinate (UTC) is the international standard for legal and civil
    // timekeeping and replaces the older Greenwich Mean Time (GMT) standard.
    // UTC is kept in sync with unpredictable observed changes in the Earth's rotation
    // by occasionally adding leap seconds as needed.
    //
    // UT1 is an idealized time scale based on observed rotation of the Earth, which
    // gradually slows down in an unpredictable way over time, due to tidal drag by the Moon and Sun,
    // large scale weather events like hurricanes, and internal seismic and convection effects.
    // Conceptually, UT1 drifts from atomic time continuously and erratically, whereas UTC
    // is adjusted by a scheduled whole number of leap seconds as needed.
    //
    // The value in Ut is appropriate for any calculation involving the Earth's rotation,
    // such as calculating rise/set times, culumination, and anything involving apparent
    // sidereal time.
    //
    // Before the era of atomic timekeeping, days based on the Earth's rotation
    // were often known as ``mean solar days''.
    Ut  float64

    // Tt holds a Terrestrial Time value expressed in days.
    // Terrestrial Time is an atomic time scale defined as a number of days since noon on January 1, 2000.
    // In this system, days are not based on Earth rotations, but instead by
    // the number of elapsed [SI seconds] divided by 86400.
    // Unlike Ut, Tt increases uniformly without adjustments for changes in the Earth's rotation.
    //
    // The value in Tt is used for calculations of movements not involving the Earth's rotation,
    // such as the orbits of planets around the Sun, or the Moon around the Earth.
    //
    // Historically, Terrestrial Time has also been known by the term ``Ephemeris Time'' (ET).
    //
    // [SI seconds]: https://physics.nist.gov/cuu/Units/second.html
    Tt  float64
    // contains filtered or unexported fields
}

func TimeFromCalendar

func TimeFromCalendar(year, month, day, hour, minute int, second float64) AstroTime

TimeFromCalendar returns an AstroTime value for a date and time expressed in civil UTC.

func TimeFromTerrestrialDays

func TimeFromTerrestrialDays(tt float64) AstroTime

TimeFromTerrestrialDays converts a Terrestrial Time (TT) day value, also known as ephemeris days, to an AstroTime value that can be used for astronomy calculations.

func TimeFromUniversalDays

func TimeFromUniversalDays(ut float64) AstroTime

TimeFromUniversalDays converts a UTC number of days since January 1, 2000 into an AstroTime value that can be used for astronomy calculations.

func (AstroTime) AddDays

func (time AstroTime) AddDays(days float64) AstroTime

Given an AstroTime value, creates a new AstroTime value that is the specified number of UT days in the future (positive) or past (negative).

type AstroVector

AstroVector represents a position in 3D space at a given time. Usually the distance components are expressed in astronomical units (AU). The origin and orientation system depends on context. Occasionally AstroVector is used to represent a velocity vector, in which case the component units are astronomical units per day.

type AstroVector struct {
    X   float64
    Y   float64
    Z   float64
    T   AstroTime
}

func GeoMoon

func GeoMoon(time AstroTime) AstroVector

GeoMoon calculates the equatorial geocentric position of the Moon at a given time. The returned vector indicates the Moon's center relative to the Earth's center. The vector components are expressed in AU (astronomical units). The coordinates are oriented with respect to the Earth's equator at the J2000 epoch. In Astronomy Engine, this orientation is called EQJ.

func RotateVector

func RotateVector(rotation RotationMatrix, vector AstroVector) AstroVector

RotateVector applies a rotation to a vector, yielding a vector in another orientation system.

func (AstroVector) Length

func (vec AstroVector) Length() float64

Returns the length of vec expressed in the same distance units as vec's components.

type AtmosphereInfo

AtmosphereInfo contains information about idealized atmospheric variables at a given elevation.

type AtmosphereInfo struct {
    Pressure    float64 // atmospheric pressure in pascals
    Temperature float64 // atmospheric temperature in kelvins
    Density     float64 // atmospheric density relative to sea level
}

func Atmosphere

func Atmosphere(elevationMeters float64) (AtmosphereInfo, error)

Atmosphere calculates U.S. Standard Atmosphere (1976) variables as a function of elevation. elevationMeters is the elevation above sea level at which to calculate atmospheric variables. It must be in the range -500 to +100000 or an error will occur. 1. COESA, U.S. Standard Atmosphere, 1976, U.S. Government Printing Office, Washington, DC, 1976. 2. Jursa, A. S., Ed., Handbook of Geophysics and the Space Environment, Air Force Geophysics Laboratory, 1985. See: https://hbcp.chemnetbase.com/faces/documents/14_12/14_12_0001.xhtml https://ntrs.nasa.gov/api/citations/19770009539/downloads/19770009539.pdf https://www.ngdc.noaa.gov/stp/space-weather/online-publications/miscellaneous/us-standard-atmosphere-1976/us-standard-atmosphere_st76-1562_noaa.pdf

type AxisInfo

type AxisInfo struct {
    Ra    float64
    Dec   float64
    Spin  float64
    North AstroVector
}

type Body

type Body int

type CalendarDateTime

CalendarDateTime represents a Gregorian calendar date and time within plus or minus 1 million years from the year 0.

type CalendarDateTime struct {
    Year   int     // The year value in the range -999999 to +999999.
    Month  int     // The calendar month in the range 1..12.
    Day    int     // The day of the month in the range 1..31.
    Hour   int     // The hour in the range 0..23.
    Minute int     // The minute in the range 0..59.
    Second float64 // The real-valued second in the half-open range [0, 60).
}

func CalendarFromDays

func CalendarFromDays(ut float64) (*CalendarDateTime, error)

CalendarFromDays converts a J2000 day value to a Gregorian calendar date and time.

type DeltaTimeFunc

type DeltaTimeFunc func(ut float64) float64

type Ecliptic

A location of a body expressed in angular coordinates relative to the plane of the Earth's orbit around the Sun

type Ecliptic struct {
    Vec  AstroVector // The object position expressed as a Cartesian vector in the same ecliptic orientation system
    Elat float64     // Eclilptic latitude in degrees north (positive) or south (negative) with respect to the ecliptic plane, in the closed range [-90, +90].
    Elon float64     // Ecliptic longitude in degrees, in the half-open range [0, 360).
}

type Equatorial

A location of a body expressed in angular coordinates relative to the Earth's equator

type Equatorial struct {
    Ra   float64     // Right Ascension in sidereal hours, in the half-open range [0, 24)
    Dec  float64     // Declination in degrees north (positive) or south (negative) of the celestial equator, in the closed range [-90, +90].
    Dist float64     // Distance of an object in astronomical units [AU]
    Vec  AstroVector // The position expressed as a Cartesian vector in the same equatorial orientation system
}

type JupiterMoonsInfo

type JupiterMoonsInfo struct {
    Io       StateVector
    Europa   StateVector
    Ganymede StateVector
    Callisto StateVector
}

type LibrationInfo

type LibrationInfo struct {
    Elat    float64
    Elon    float64
    Mlat    float64
    Mlon    float64
    DistKm  float64
    DiamDeg float64
}

type NodeEventInfo

type NodeEventInfo struct {
    Time AstroTime
    Kind NodeEventKind
}

type NodeEventKind

type NodeEventKind int

type Observer

The location of a point on or near the surface of the Earth

type Observer struct {
    Latitude  float64 // Latitude degrees north (positive) or south (negative) of the equator
    Longitude float64 // Longitude east (positive) or west (negative) of the prime meridian passing through Greenwich, England
    Height    float64 // Height above mean sea level in meters
}

type Refraction

type Refraction int

const (
    NoRefraction Refraction = iota
    NormalRefraction
    JplHorizonsRefraction
)

type RotationMatrix

RotationMatrix is a 3x3 matrix used to convert a vector from one orientation system to another.

type RotationMatrix struct {
    Rot [3][3]float64
}

func CombineRotation

func CombineRotation(a, b RotationMatrix) RotationMatrix

CombineRotation combines the effects of two consecutive rotation matrices into a single rotation matrix.

func IdentityMatrix

func IdentityMatrix() RotationMatrix

Creates a rotation matrix that represents no rotation at all.

func InverseRotation

func InverseRotation(rotation RotationMatrix) RotationMatrix

Calculates the inverse of a rotation matrix. Given a rotation matrix that performs some coordinate transform, this function returns the matrix that reverses that transform.

func RotationEqdEqj

func RotationEqdEqj(time *AstroTime) RotationMatrix

Calculates a rotation matrix that converts equator-of-date (EQD) to J2000 mean equator (EQJ).

type SeasonsInfo

type SeasonsInfo struct {
    MarEquinox  AstroTime
    JunSolstice AstroTime
    SepEquinox  AstroTime
    DecSolstice AstroTime
}

type Spherical

Spherical coordinates for a body in space

type Spherical struct {
    Lat  float64 // a latitude-like angle expressed in degrees
    Lon  float64 // a longitude-like angle expressed in degrees
    Dist float64 // a distance expressed in astronomical units
}

type StateVector

StateVector represents the combined position and velocity of a body at a given moment of time.

type StateVector struct {
    X   float64
    Y   float64
    Z   float64
    Vx  float64
    Vy  float64
    Vz  float64
    T   AstroTime
}

func RotateState

func RotateState(rotation RotationMatrix, state StateVector) StateVector

func (StateVector) Position

func (state StateVector) Position() AstroVector

Position returns the position vector inside a state vector.

func (StateVector) Velocity

func (state StateVector) Velocity() AstroVector

Position returns the velocity vector inside a state vector.

type TimeFormat

type TimeFormat int

const (
    TimeFormatDay TimeFormat = iota
    TimeFormatMinute
    TimeFormatSecond
    TimeFormatMilli
)

type Topocentric

A location of a body as seen from an observer's point of view on or near the surface of the Earth. The topocentric position can optionally be corrected for atmospheric refraction.

type Topocentric struct {
    Azimuth  float64 // The compass direction of the object, where north = 0, east = 90, south = 180, and west = 270.
    Altitude float64 // The angle above (positive) or below (negative) the observer's horizon in degrees, in the range [-90, +90].
    Ra       float64 // The body's apparent right ascension
    Dec      float64 // The body's apparent declination
}

Generated by gomarkdoc