Astro (Astro v0.5.0) View Source
Functions for basic astronomical observations such as sunrise, sunset, solstice, equinox, moonrise, moonset and moon phase.
Link to this section Summary
Functions
Returns the date time of a given lunar phase at or after a given date time or date.
Returns the date time of a given lunar phase at or before a given date time or date.
Returns the date time of the new moon at or after a given date or date time.
Returns the date time of the new moon before a given date or date time.
Returns the datetime in UTC for either the March or September equinox.
Returns the number of hours of daylight for a given location on a given date.
Returns the lunar phase as a float number of degrees at a given date or date time.
Returns solar noon for a given date and location as a UTC datetime
Returns the datetime in UTC for either the June or December solstice.
Returns solar longitude for a given date. Solar longitude is used to identify the seasons.
Calculates the sunrise for a given location and date.
Calculates the sunset for a given location and date.
Link to this section Types
Specs
altitude() :: float()
Specs
angle() :: number()
Specs
date() :: map()
Specs
degrees() :: float()
Specs
latitude() :: float()
Specs
location() :: {longitude(), latitude()} | Geo.Point.t() | Geo.PointZ.t()
Specs
longitude() :: float()
Specs
meters() :: number()
Specs
options() :: keyword()
Specs
phase() :: angle()
Link to this section Functions
Specs
date_time_lunar_phase_at_or_after(date(), phase()) :: Calendar.datetime()
Returns the date time of a given lunar phase at or after a given date time or date.
Arguments
date_timeis aDateTimeor aDateor any struct that meets the requirements oft:Calendar.dateort:Calendar.datetimephaseis the required lunar phase expressed as a float number of degrees between0.0and360.0
Returns
- a
DateTimeat which the phase occurse.
Example
iex> Astro.date_time_lunar_phase_at_or_after(~D[2021-08-01], Astro.Lunar.full_moon())
~U[2021-08-22 12:01:02.170362Z]
date_time_lunar_phase_at_or_before(date_time, phase)
View Source (since 0.5.0)Specs
date_time_lunar_phase_at_or_before(date(), phase()) :: Calendar.datetime()
Returns the date time of a given lunar phase at or before a given date time or date.
Arguments
date_timeis aDateTimeor aDateor any struct that meets the requirements oft:Calendar.dateort:Calendar.datetimephaseis the required lunar phase expressed as a float number of degrees between0and3660
Returns
- a
DateTimeat which the phase occurse.
Example
iex> Astro.date_time_lunar_phase_at_or_before(~D[2021-08-01], Astro.Lunar.new_moon())
~U[2021-07-10 01:18:25.422335Z]
Specs
date_time_new_moon_at_or_after(date()) :: Calendar.datetime()
Returns the date time of the new moon at or after a given date or date time.
Arguments
date_timeis aDateTimeor aDateor any struct that meets the requirements oft:Calendar.dateort:Calendar.datetime
Returns
- a
DateTimeat which the new moon occurs.
Example
iex> Astro.date_time_new_moon_at_or_after ~D[2021-08-23]
~U[2021-09-07 00:52:05.476972Z]
Specs
date_time_new_moon_before(date()) :: Calendar.datetime()
Returns the date time of the new moon before a given date or date time.
Arguments
date_timeis aDateTimeor aDateor any struct that meets the requirements oft:Calendar.dateort:Calendar.datetime
Returns
- a
DateTimeat which the new moon occurs.
Example
iex> Astro.date_time_new_moon_before ~D[2021-08-23]
~U[2021-08-08 13:51:29.920452Z]
Specs
equinox(Calendar.year(), :march | :september) :: {:ok, DateTime.t()}
Returns the datetime in UTC for either the March or September equinox.
Arguments
yearis the gregorian year for which the equinox is to be calculatedeventis either:marchor:septemberindicating which of the two annual equinox datetimes is required
Returns
{:ok, datetime}representing the UTC datetime of the equinox
Examples
iex> Astro.equinox 2019, :march
{:ok, ~U[2019-03-20 21:58:06Z]}
iex> Astro.equinox 2019, :september
{:ok, ~U[2019-09-23 07:49:30Z]}Notes
This equinox calculation is expected to be accurate to within 2 minutes for the years 1000 CE to 3000 CE.
An equinox is commonly regarded as the instant of time when the plane of Earth's equator passes through the center of the Sun. This occurs twice each year: around 20 March and 23 September.
In other words, it is the moment at which the center of the visible Sun is directly above the equator.
Specs
hours_of_daylight(location(), Calendar.date()) :: {:ok, Time.t()}
Returns the number of hours of daylight for a given location on a given date.
Arguments
locationis the latitude, longitude and optionally elevation for the desired hours of daylight. It can be expressed as:{lng, lat}- a tuple with longitude and latitude as floating point numbers. Note the order of the arguments.- a
Geo.Point.tstruct to represent a location without elevation - a
Geo.PointZ.tstruct to represent a location and elevation
dateis any date in the Gregorian calendar (for example,Calendar.ISO)
Returns
{:ok, time}wheretimeis aTime.t()
Examples
iex> Astro.hours_of_daylight {151.20666584, -33.8559799094}, ~D[2019-12-07]
{:ok, ~T[14:18:45]}
# No sunset in summer
iex> Astro.hours_of_daylight {-62.3481, 82.5018}, ~D[2019-06-07]
{:ok, ~T[23:59:59]}
# No sunrise in winter
iex> Astro.hours_of_daylight {-62.3481, 82.5018}, ~D[2019-12-07]
{:ok, ~T[00:00:00]}Notes
In latitudes above the polar circles (approximately +/- 66.5631 degrees) there will be no hours of daylight in winter and 24 hours of daylight in summer.
Specs
Returns the lunar phase as a float number of degrees at a given date or date time.
Arguments
Returns
- the lunar phase as a float number of degrees.
Example
iex> Astro.lunar_phase_at ~U[2021-08-22 12:01:02.170362Z]
180.00001443052076
iex> Astro.lunar_phase_at(~U[2021-07-10 01:18:25.422335Z])
359.9999929267571
Specs
solar_noon(location(), Calendar.date()) :: {:ok, DateTime.t()}
Returns solar noon for a given date and location as a UTC datetime
Arguments
locationis the latitude, longitude and optionally elevation for the desired solar noon time. It can be expressed as:{lng, lat}- a tuple with longitude and latitude as floating point numbers. Note the order of the arguments.- a
Geo.Point.tstruct to represent a location without elevation - a
Geo.PointZ.tstruct to represent a location and elevation
dateis any date in the Gregorian calendar (for example,Calendar.ISO)
Returns
- a UTC datetime representing solar noon at the given location for the given date
Example
iex> Astro.solar_noon {151.20666584, -33.8559799094}, ~D[2019-12-06]
{:ok, ~U[2019-12-06 01:45:42Z]}Notes
Solar noon is the moment when the Sun passes a location's meridian and reaches its highest position in the sky. In most cases, it doesn't happen at 12 o'clock.
At solar noon, the Sun reaches its highest position in the sky as it passes the local meridian.
Specs
solstice(Calendar.year(), :june | :december) :: {:ok, DateTime.t()}
Returns the datetime in UTC for either the June or December solstice.
Arguments
yearis the gregorian year for which the solstice is to be calculatedeventis either:juneor:decemberindicating which of the two annual solstice datetimes is required
Returns
{:ok, datetime}representing the UTC datetime of the solstice
Examples
iex> Astro.solstice 2019, :december
{:ok, ~U[2019-12-22 04:18:57Z]}
iex> Astro.solstice 2019, :june
{:ok, ~U[2019-06-21 15:53:45Z]}Notes
This solstice calculation is expected to be accurate to within 2 minutes for the years 1000 CE to 3000 CE.
A solstice is an event occurring when the Sun appears to reach its most northerly or southerly excursion relative to the celestial equator on the celestial sphere. Two solstices occur annually, around June 21 and December 21.
The seasons of the year are determined by reference to both the solstices and the equinoxes.
The term solstice can also be used in a broader sense, as the day when this occurs. The day of a solstice in either hemisphere has either the most sunlight of the year (summer solstice) or the least sunlight of the year (winter solstice) for any place other than the Equator.
Alternative terms, with no ambiguity as to which hemisphere is the context, are "June solstice" and "December solstice", referring to the months in which they take place every year.
Specs
sun_apparent_longitude(Calendar.date()) :: degrees()
Returns solar longitude for a given date. Solar longitude is used to identify the seasons.
Arguments
dateis any date in the Gregorian calendar (for example,Calendar.ISO)
Returns
- a
floatnumber of degrees between 0 and 360 representing the solar longitude ondate
Examples
iex> Astro.sun_apparent_longitude ~D[2019-03-21]
0.08035853207991295
iex> Astro.sun_apparent_longitude ~D[2019-06-22]
90.32130455695378
iex> Astro.sun_apparent_longitude ~D[2019-09-23]
179.68691978440197
iex> Astro.sun_apparent_longitude ~D[2019-12-23]
270.83941087483504Notes
Solar longitude (the ecliptic longitude of the sun) in effect describes the position of the earth in its orbit, being zero at the moment of the vernal equinox.
Since it is based on how far the earth has moved in its orbit since the equinox, it is a measure of what time of the tropical year (the year of seasons) we are in, but without the inaccuracies of a calendar date, which is perturbed by leap years and calendar imperfections.
Specs
sunrise(location(), date(), options()) :: {:ok, DateTime.t()} | {:error, :time_zone_not_found | :no_time}
Calculates the sunrise for a given location and date.
Sunrise is the moment when the upper limb of the sun appears on the horizon in the morning.
Arguments
locationis the latitude, longitude and optionally elevation for the desired sunrise time. It can be expressed as:{lng, lat}- a tuple with longitude and latitude as floating point numbers. Note the order of the arguments.- a
Geo.Point.tstruct to represent a location without elevation - a
Geo.PointZ.tstruct to represent a location and elevation
dateis at:Date,t:NaiveDateTimeort:DateTimeto indicate the date of the year in which the sunrise time is required.optionsis a keyword list of options.
Options
solar_elevationrepresents the type of sunrise required. The default is:geometricwhich equates to a solar elevation of 90°. In this case the calulation also accounts for refraction and elevation to return a result which accords with the eyes perception. Other solar elevations are::civilrepresenting a solar elevation of 96.0°. At this point the sun is just below the horizon so there is generally enough natural light to carry out most outdoor activities.:nauticalrepresenting a solar elevation of 102.0° This is the point at which the horizon is just barely visible and the moon and stars can still be used for navigation.:astronomicalrepresenting a solar elevation of 108.0°. This is the point beyond which astronomical observation becomes impractical.- Any floating point number representing the desired solar elevation.
:time_zoneis the time zone to in which the sunrise is requested. The default is:defaultin which the sunrise time is reported in the time zone of the requested location. Any other time zone name supported by the option:time_zone_databaseis acceptabe.:time_zone_databaserepresents the module that implements theCalendar.TimeZoneDatabasebehaviour. The default isTzdata.TimeZoneDatabase.
Returns
a
DateTime.trepresenting the time of sunrise in the requested timzone at the requested location or{:error, :time_zone_not_found}if the requested time zone is unknown{:error, :no_time}if for the requested date and location there is no sunrise. This can occur at very high latitudes during summer and winter.
Examples
# Sunrise in Sydney, Australia
Astro.sunrise({151.20666584, -33.8559799094}, ~D[2019-12-04])
{:ok, #DateTime<2019-12-04 05:37:00.000000+11:00 AEDT Australia/Sydney>}
# Sunrise in Alert, Nanavut, Canada
Astro.sunrise({-62.3481, 82.5018}, ~D[2019-12-04])
{:error, :no_time}
Specs
sunset(location(), date(), options()) :: {:ok, DateTime.t()} | {:error, :time_zone_not_found | :no_time}
Calculates the sunset for a given location and date.
Sunset is the moment when the upper limb of the sun disappears below the horizon in the evening.
Arguments
locationis the latitude, longitude and optionally elevation for the desired sunrise time. It can be expressed as:{lng, lat}- a tuple with longitude and latitude as floating point numbers. Note the order of the arguments.- a
Geo.Point.tstruct to represent a location without elevation - a
Geo.PointZ.tstruct to represent a location and elevation
dateis at:Date,t:NaiveDateTimeort:DateTimeto indicate the date of the year in which the sunset time is required.optionsis a keyword list of options.
Options
solar_elevationrepresents the type of sunset required. The default is:geometricwhich equates to a solar elevation of 90°. In this case the calulation also accounts for refraction and elevation to return a result which accords with the eyes perception. Other solar elevations are::civilrepresenting a solar elevation of 96.0°. At this point the sun is just below the horizon so there is generally enough natural light to carry out most outdoor activities.:nauticalrepresenting a solar elevation of 102.0° This is the point at which the horizon is just barely visible and the moon and stars can still be used for navigation.:astronomicalrepresenting a solar elevation of 108.0°. This is the point beyond which astronomical observation becomes impractical.- Any floating point number representing the desired solar elevation.
:time_zoneis the time zone to in which the sunset is requested. The default is:defaultin which the sunset time is reported in the time zone of the requested location. Any other time zone name supported by the option:time_zone_databaseis acceptabe.:time_zone_databaserepresents the module that implements theCalendar.TimeZoneDatabasebehaviour. The default isTzdata.TimeZoneDatabase.
Returns
a
t:DateTimerepresenting the time of sunset in the requested time zone at the requested location or{:error, :time_zone_not_found}if the requested time zone is unknown{:error, :no_time}if for the requested date and location there is no sunset. This can occur at very high latitudes during summer and winter.
Examples
# Sunset in Sydney, Australia
Astro.sunset({151.20666584, -33.8559799094}, ~D[2019-12-04])
{:ok, #DateTime<2019-12-04 19:53:00.000000+11:00 AEDT Australia/Sydney>}
# Sunset in Alert, Nanavut, Canada
Astro.sunset({-62.3481, 82.5018}, ~D[2019-12-04])
{:error, :no_time}