Giter Site home page Giter Site logo

zwim / suntime Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 36.54 MB

Calculates sunrise and sunset as well as different types of twilight depending on your geolocation.

License: GNU Affero General Public License v3.0

Lua 88.85% Makefile 0.24% C 10.59% Shell 0.31%
ephemeris dawn dusk sunrise sunset twilight

suntime's Introduction

Suntime

A Lua library to calculate sunrise and sunset as well as different types of twilight depending on your geolocation.

Features

The algorithm has been developed from scratch.

The implementation is very precise compared to NREL's Solar Position Algorithm (SPA) https://midcdmz.nrel.gov/spa/. Typical errors are within one minute for the next 30 years.

Some highlights:

  • honor sea level,
  • count in astronomical refraction (temperature dependent),
  • consider relativistic aberration,
  • take WGS84 geoid shape of the earth,
  • include the sun and earth diameter,
  • ...

Usage

See test.lua for an example.

0.) Load library:

local SunTime = require("suntime")

1.) Set your position:

SunTime:setPosition(name, latitude, longitude, timezone, height, true)

Coordinates in decimal degree: SunTime:setPosition("Innsbruck Flughafen", 47.25786, 11.35111, 1, 578, true)

or coordinates in radiant: SunTime:setPosition("Innsbruck Flughafen", 47.25786/180*math.pi, 11.35111/180*math.pi, 1, 578)

2.) Set equation of time

Default: SunTime:setAdvanced() -- advanced version valid for the next few hundred years

Optional: SunTime:setSimple() -- simple version valid for 2008-2027

3.) Set date

SunTime:setDate() -- use system settings

or

SunTime:setDate(y, m, d, dst)

SunTime:setDate(2021, 10, 30, true)

4.) Calulate times

SunTime:calculateTimes()

5.) Use the calculated times

Times are decimal hours, so 12.5 is 12:30:00. If a time does not exist the value is nil.

    self.rise
    self.set 

    self.rise_civil 
    self.set_civil 
    self.rise_nautic
    self.set_nautic 
    self.rise_astronomic 
    self.set_astronomic

    self.noon 
    self.midnight

    self.times = {}
    self.times[1]  = self.midnight and (self.midnight - 24)
    self.times[2]  = self.rise_astronomic
    self.times[3]  = self.rise_nautic
    self.times[4]  = self.rise_civil
    self.times[5]  = self.rise
    self.times[6]  = self.noon
    self.times[7]  = self.set
    self.times[8]  = self.set_civil
    self.times[9]  = self.set_nautic
    self.times[10] = self.set_astronomic
    self.times[11] = self.midnight

suntime's People

Contributors

zwim avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.