Module suntime

-- Author: Martin Zwicknagl (zwim) -- Date: 2021-10-29 -- The current source code of this file can be found on https://github.com/zwim/suntime.

Module to calculate ephemeris and other times depending on the sun position.

Maximal errors from 2020-2050 (compared to https://midcdmz.nrel.gov/spa/) are:

  • -43.52° Christchurch 66s
  • -20.16° Mauritius: 25s
  • 20.30° Honolulu: 47s
  • 33.58° Casablanca: 24s
  • 35.68° Tokio: 50s
  • 37.97° Athene: 24s
  • 38° Sacramento: 67s
  • 41.91° Rome: 27s
  • 47.25° Innsbruck: 13s
  • 52.32° Berlin: 30s
  • 59.92° Oslo: 42s
  • 64.14° Reykjavik: 69s
  • 65.69° Akureyri: <24s (except *)
  • 70.67° Hammerfest: <105s (except **)

*) A few days around beginning of summer (error <290s)

**) A few days after and before midnight sun (error <1200s)

Usage:

    local SunTime = require("suntime")
    
    time_zone = 0
    altitude = 50
    degree = true
    SunTime:setPosition("Reykjavik", 64.14381, -21.92626, timezone, altitude, degree)
    
    SunTime:setAdvanced()
    
    SunTime:setDate()
    
    SunTime:calculateTimes()
    
    print(SunTime.rise, SunTime.set, SunTime.set_civil) -- or similar see calculateTime()
    

Functions

SunTime:setPosition (name, latitude, longitude, time_zone, altitude, degree) Set position for later calculations
SunTime:setSimple () Use a simple equation of time (valid for the years 2008-2027)
SunTime:setAdvanced () Use an advanced equation of time (valid for the years 1800-2200 at least)
SunTime:calculateTimes (fast_twilight) Calculates the ephemeris and twilight times

Fields

SunTime.getZgl Function to get the equation of time, can be set by setSimple() or setAdvanced()


Functions

SunTime:setPosition (name, latitude, longitude, time_zone, altitude, degree)
Set position for later calculations

Parameters:

  • name Name of the location
  • latitude Geographical latitude, North is positive
  • longitude Geographical longitude, West is negative
  • time_zone Timezone e.g. CET = +1; if nil try to autodetect the current zone
  • altitude Altitude of the location above the sea level
  • degree if nil latitude and longitude are in radian, else in decimal degree
SunTime:setSimple ()
Use a simple equation of time (valid for the years 2008-2027)
SunTime:setAdvanced ()
Use an advanced equation of time (valid for the years 1800-2200 at least)
SunTime:calculateTimes (fast_twilight)
Calculates the ephemeris and twilight times

Parameters:

  • fast_twilight If not nil, then exact twilight times will be calculated.

Usage:

    SunTime:calculateTimes(fast_twilight)
    
    
    Times are in hours or nil if not applicable.
    
    You can then access:
        self.midnight_beginning
    
        self.rise_astronomic
        self.rise_nautic
        self.rise_civil
        self.rise
    
        self.noon
    
        self.set
        self.set_civil
        self.set_nautic
        self.set_astronomic
    
        self.midnight
    
    Or as values in a table:
        self.times[1]  midnight_beginning
        self.times[2]  rise_astronomic
        self.times[3]  rise_nautic
        self.times[4]  rise_civil
        self.times[5]  rise
        self.times[6]  noon
        self.times[7]  set
        self.times[8]  set_civil
        self.times[9]  set_nautic
        self.times[10] set_astronomic
        self.times[11] midnight

Fields

SunTime.getZgl
Function to get the equation of time, can be set by setSimple() or setAdvanced()
generated by LDoc 1.5.0 Last updated 2024-12-19 07:44:17