8

Python astral library ported to Go

 3 years ago
source link: https://sj14.gitlab.io/post/2021/04-19-astral-go/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python astral library ported to Go

2021-04-19

Calculations for the position of the sun and moon.

This is a Go port of the Python astral package. Check out the latest Go version on Github.

The astral package provides the means to calculate the following times of the sun:

  • sunrise
  • midnight
  • sunset
  • daylight
  • night
  • twilight
  • blue hour
  • golden hour
  • rahukaalam TODO

plus solar azimuth and elevation at a specific latitude/longitude. It can also calculate the moon phase for a specific date.

Besides the package for usage in you own programs, we also provide a tool for showing the data.

Installation

go get github.com/sj14/astral/cmd/astral

Usage

Usage of astral:
  -elev float
        elevation of the observer
  -format string
        time output format according to Go parsing (default "Jan _2 15:04:05")
  -lat float
        latitude of the observer
  -long float
        longitude of the observer
  -time string
        day/time used for the calculation (defaults to current time)

Example

$ astral -lat 51.58 -long 6.52
Sun Apr 18 11:12:45 CEST 2021
Latitude 51.58 Longitude 6.52 Elevation 0
Apr 18 05:55:07 Dawn
Apr 18 05:55:07 Blue Hour Start
Apr 18 06:09:04 Blue Hour End
Apr 18 06:09:04 Golden Hour Start
Apr 18 06:31:44 Sunrise
Apr 18 07:15:56 Golden Hour End
Apr 18 13:33:18 Noon
Apr 18 19:51:24 Golden Hour Start
Apr 18 20:35:45 Sunset
Apr 18 20:58:33 Golden Hour End
Apr 18 20:58:33 Blue Hour Start
Apr 18 21:12:35 Blue Hour End
Apr 18 21:12:35 Dusk
Apr 19 01:33:13 Midnight
Moon Phase: New Moon (5.47788888888889)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK