Coder Social home page Coder Social logo

suntransit's Introduction

suntransit

Simple, fast approximation of sunrise, sunset time on Earth.

DOI

Earth system models and other biogeochemical simulations often require an estimate of the day length and, therefore, of sunrise and sunset times. Highly precise solar transit information can be obtained from Python libraries like pyephem and astral, but these are general-purpose libraries and the corresponding routines are slow. If we can tolerate an error in transit times on the order of a few minutes, then we should also be able to calculate transit times much faster! That's the idea here: using a fast approximation for sunrise and sunset times. Read more about the alternatives and the performance of an earlier version of this library.

Example Use

import datetime
import numpy as np
from suntransit import sunrise_sunset

missoula = (46.8625, -114.0117)
today = datetime.date(2021, 10, 7)

# Get (sunrise, sunset) hour in UTC
sunrise_sunset(missoula, today)
# (13.733140671716853, 1.062543659843307)

# Get (sunrise, sunset) hour in local time (GMT-6:00)
(np.array(sunrise_sunset(missoula, today)) - 6) % 24
# array([ 7.73314067, 19.06254366])

And for (quasi-)vectorization:

from functools import partial

calgary = (51.0458, -114.0575)
ankara = (39.93, 32.85)

data = np.stack([missoula, calgary, ankara], axis = 0)

alt_sunrise_sunset = partial(sunrise_sunset, dt = today)
np.apply_along_axis(alt_sunrise_sunset, 1, data).round(1)
# array([[13.7,  1.1],
#        [13.8,  1. ],
#        [ 3.9, 15.4]])

Installation

It is recommended to install with pip:

pip install suntransit

The only dependency is numpy.

Documentation

Online documentation can be found here.

Testing

python tests/tests.py

References

Meeus, Jean. "Astronomical Algorithms." 1991. William-Bell Inc. Richmond, Virginia, U.S.A.

U.S. Naval Observatory. "Almanac for Computers." 1990. Reproduced by Ed Williams. https://www.edwilliams.org/sunrise_sunset_algorithm.htm

suntransit's People

Contributors

arthur-e avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ronomal

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.