Skip to main content

A free, fast and accurate Python package to compute the position of the Sun

Project description

SolTrack

A free, fast and simple Python package to compute the position of the Sun, as well as its rise and set times. SolTrack was originally written in C/C++ by Marc van der Sluys of the Sustainable energy research group of the HAN University of Applied Sciences in Arnhem, the Netherlands, and has now been translated to pure Python.

SolTrack performs about 12340 position calculations per second on a single 3.6 GHz core of my 2013 laptop, with an accuracy of 0.0030 ± 0.0016°. This makes it about 500x times faster than astropy, but around 50x slower than pyEphem, which is written in C. SolTrack has been used to control solar trackers, as well as modelling in solar energy.

Installation

This package can be installed using pip install soltrack. This should automatically install the dependency packages numpy and dataclasses (if you're not using Python 3.7+) if they haven't been installed already. If you are installing by hand, ensure that these packages are installed as well.

Example use

"""Example Python script to compute the position of the Sun and its rise and set times for a single instant."""

import soltrack as st

# Set preferences (all are False by default):
useDegrees             = True   # Input (geographic position) and output are in degrees
useNorthEqualsZero     = True   # Azimuth: 0 = South, pi/2 (90deg) = West  ->  0 = North, pi/2 (90deg) = East
computeRefrEquatorial  = True   # Compure refraction-corrected equatorial coordinates (Hour angle, declination)
computeDistance        = True   # Compute the distance to the Sun

# Set up geographical location (in degrees, since useDegrees=True) in a SolTrack Location dataclass object:
loc = st.Location(5.950270, 51.987380)  # longitude (>0: east of Greenwich),  latitude (>0: northern hemisphere)

# Set (UT!) date and time in a SolTrack Time dataclass object:
time = st.Time(2045, 7, 16,  6, 2, 49.217348)  # Date: 2045-07-16, time: 06:02:49.217348


# Compute positions - returns a st.Position object:
pos = st.computeSunPosition(loc, time, useDegrees, useNorthEqualsZero, computeRefrEquatorial, computeDistance)

# Compute rise and set times - returns a st.RiseSet object:
riseSet = st.computeSunRiseSet(loc, time, 0.0, useDegrees, useNorthEqualsZero)


# Write results to standard output:
print("Location:  %0.3lf E, %0.3lf N" % (loc.longitude, loc.latitude))
print("Date:      %4d %2d %2d" % (time.year, time.month, time.day))
print("Time:      %2d %2d %9.6lf" % (time.hour, time.minute, time.second))
print("JD:        %0.11lf" % (pos.julianDay))
print()

print("Ecliptic longitude, latitude:        %10.6lf° %10.6lf°" % (pos.longitude, 0.0))
print("Right ascension, declination:        %10.6lf° %10.6lf°" % (pos.rightAscension, pos.declination))
print("Uncorrected altitude:                            %10.6lf°" % (pos.altitude))
print("Corrected azimuth, altitude:         %10.6lf° %10.6lf°" % (pos.azimuthRefract, pos.altitudeRefract))
print("Corrected hour angle, declination:   %10.6lf° %10.6lf°" % (pos.hourAngleRefract, pos.declinationRefract))
print()

print("Rise time:      %11.5lf,    azimuth:   %11.5lf" % (riseSet.riseTime, riseSet.riseAzimuth))
print("Transit time:   %11.5lf,    altitude:  %11.5lf" % (riseSet.transitTime, riseSet.transitAltitude))
print("Set time:       %11.5lf,    azimuth:   %11.5lf" % (riseSet.setTime, riseSet.setAzimuth))
print()

SolTrack pages

Author and licence

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

soltrack-0.0.2.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

soltrack-0.0.2-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file soltrack-0.0.2.tar.gz.

File metadata

  • Download URL: soltrack-0.0.2.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.10

File hashes

Hashes for soltrack-0.0.2.tar.gz
Algorithm Hash digest
SHA256 430b08e426e6357d9af4af1978824701d2444cf0383dcbefc13b0f2b1e93f7b5
MD5 2e221d5145b184bdff01a450ba9f5719
BLAKE2b-256 210322acf8594bfe0a211f3765f19b875ff53b41c5fc3b0f64fede43dc1aa956

See more details on using hashes here.

File details

Details for the file soltrack-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: soltrack-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.10

File hashes

Hashes for soltrack-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f0cd3271153080939c8bf2bed16a1f867bb3da394fb15a8fc59e39e9c67d2e75
MD5 cc7d69ac89252716de1be92f8841da0d
BLAKE2b-256 c10e2a230ad47777b9412187a779cfb8bbbfb51a1d71ce4598014f997562a642

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page