kip

kip

ex_cldr Core Team

Astro - astronomy calculations (sunrise, sunset, moonrise, moonset, moon phase equinox, solstice, ...)

Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculates sunrise and sunset. In testing its precision is within 1 minute of the results returns from DateAndTime.com.

It makes use of tz_world to dereference geo coordinates to a timezone and tzdata for time zone conversions.

This lib started our as a requirement to support certain solar, lunar and lunisolar calendars but it has wider applicability.

Examples

# Sunrise in Sydney on December 4th
iex> Astro.sunrise({151.20666584, -33.8559799094}, ~D[2019-12-04])
{:ok, #DateTime<2019-12-04 05:37:00.000000+11:00 AEDT Australia/Sydney>}

# Sunset in Sydney on December 4th
iex> 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 the town of Alert in Nunavut, Canada
# ...doesn't exist since there is no sunset in summer
iex> Astro.sunset({-62.3481, 82.5018}, ~D[2019-07-01])
{:error, :no_time}

# ...or sunrise in winter
iex> Astro.sunrise({-62.3481, 82.5018}, ~D[2019-12-04])
{:error, :no_time}

Next steps (as of 0.5.0)

  • Sunrise
  • Sunset
  • Solstice
  • Equinox
  • Moon phase
  • Moon rise
  • Moon set

Most Liked

kip

kip

ex_cldr Core Team

A small update resulting in Astro version 0.9.0 that adds Astro.lunar_phase_emoji/1 to return the phase of the moon as an emoji. For example:

iex> Astro.lunar_phase_emoji 0
"πŸŒ‘"
iex> Astro.lunar_phase_emoji 45
"πŸŒ’"
iex> Astro.lunar_phase_emoji 90
"πŸŒ“"
iex> Astro.lunar_phase_emoji 135
"πŸŒ”"
iex> Astro.lunar_phase_emoji 180
"πŸŒ•"
iex> Astro.lunar_phase_emoji 245
"πŸŒ–"
iex> Astro.lunar_phase_emoji 270
"πŸŒ—"
iex> Astro.lunar_phase_emoji 320
"🌘"
iex> Astro.lunar_phase_emoji 360
"πŸŒ‘"

iex> ~U[2021-08-22 12:01:02.170362Z]
...> |> Astro.lunar_phase_at()
...> |> Astro.lunar_phase_emoji()
"πŸŒ•"
16
Post #6
kip

kip

ex_cldr Core Team

I’ve released Astro 1.0 almost exactly a year after the last published version. This indicates API stability for existing functions (stable in most cases for at least 3 years). There is only one new function in this release:

Enhancements

  • Release 1.0. This library was started four years ago and the public API has been stable for at least three of those years.

  • Adds Astro.sun_azimuth_altitude/2. Thanks to @kimlai for the suggestion. Closes #3.

kip

kip

ex_cldr Core Team

Astro version 0.6.0 is now out. This version avoids requiring some dependencies which makes the footprint smaller and compilation much faster. I have been using it to support the upcoming Chinese calendar with all tests passing so I consider the basic solar and lunar algorithms to be in solid shape.

Please note that Elixir 1.11 or later is required.

Roadmap

Roadmap to version 1.0 is to add Astro.moonrise/2 and Astro.moonset/2.

Additional development proposals or suggestions are very welcome.

Bug Fixes

  • Fix Astro.Math.atan_r/2

  • Fix Astro.Earth.ephemeris/1

Breaking changes

  • Change Astro.Time.date_time_{from, to}_iso_days/1 to Astro.Time.date_time_{from, to}_moment/1

Enhancements

  • Remove dependency on ex_cldr_calendar and jason

  • Add Astro.sun_position_at/1 which is a public API for returning the right ascension, declination and radius (distance to the sun) at a given date/time.

  • Add Astro.moon_position_at/1 which is a public API for returning the right ascension, declination and radius (distance to the moon) at a given date/time.

  • Add Astro.illuminated_fraction_of_moon_at/1 to return the fraction of the moon that is lit at a given date/time.

11
Post #5
kip

kip

ex_cldr Core Team

Astro version 0.5.0 is now out. The release adds functions that calculate the phase of the moon which, apart from anything else, is needed to calculate the Chinese calendar. Please note that Elixir 1.11 or later is required.

Bug Fixes

  • Updates documentation to be clear about installation and setup requirements for tz_world

  • Fixes test data for SΓ£o Paulo now that it no longer uses DST

  • Ensure :astro is started in test mode

Enhancements

This primary focus of this release is to add lunar calculations for moon phase.

  • Adds Astro.date_time_new_moon_before/1

  • Adds Astro.date_time_new_moon_at_or_after/1

  • Adds Astro.lunar_phase_at/1

  • Adds Astro.date_time_lunar_phase_at_or_before/2

  • Adds Astro.date_time_lunar_phase_at_or_after/2

kip

kip

ex_cldr Core Team

New version 0.2.0 is now out:

Enhancements

  • Add Astro.equinox/2and Astro.solstice/2 to calculate solstices and equinoxes for a year. From these can be derived the seasons.

  • Add Astro.Time.datetime_from_julian_days/1

  • Add Astro.Time.utc_datetime_from_terrestrial_datetime/1

Now on to lunar calculations (phase, moonrise, moonset)… And to implement the Persian calendar (which is a Solar based calendar).

Where Next?

Popular in Libraries Top

woylie
I released Doggo, a collection of unstyled Phoenix components. Features Unstyled Phoenix components. Storybook that can be added to...
New
praveenperera
FastRSS Parse RSS feeds very quickly: This is rust NIF built using rustler Uses the RSS rust crate to do the actual RSS parsing Speed...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
Crowdhailer
I have been updating a library that allows you to pipe between functions that use the erlang result tuple convention. Assuming you have...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
Antrater
Hi everyone! I’m thrilled to announce a huge thing. We have been developing Elixir Moon Design System for quite a while. We are finally ...
New
engineeringdept
I’ve just released the first version of Snap, an Elasticsearch client. It borrows ideas about application structure and process managemen...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
KallDrexx
For a good number of months I've been working on creating a very basic RTMP live video streaming server. Now that I have a very, very ba...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Sub Categories:

We're in Beta

About us Mission Statement