Home
SolarPosition.jl
SolarPosition.jl provides a simple, unified interface to a collection of validated solar position algorithms written in pure, performant julia.
Solar positioning algorithms are commonly used to calculate the solar zenith and azimuth angles, which are essential for various applications where the sun is important, such as:
- Solar energy systems
- Building design
- Climate studies
- Astronomy
Acknowledgement
This package is based on the work done by researchers in the field of solar photovoltaics in the packages solposx and pvlib-python. In particular the positioning and refraction methods have been adapted from solposx, while the SPA algorithm and the deltat calculation are ported from pvlib-python. These packages also provide validation data necessary to ensure correctness of the algorithm implementations.
Example Usage
using SolarPosition, Dates, TimeZones
# define observer location (latitude, longitude, altitude in meters)
obs = Observer(52.35888, 4.88185, 100.0) # Van Gogh Museum, Amsterdam
tz = TimeZone("Europe/Brussels")
# a few hours of timestamps
times = collect(DateTime(2023, 6, 21, 10):Hour(1):DateTime(2023, 6, 21, 15));
# compute solar positions for all timestamps
positions = solar_position(obs, times)6-element StructArray(::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}) with eltype SolPos{Float64}:
SolPos(azimuth=136.1908215897601°, elevation=55.13208390809107°, zenith=34.86791609190893°)
SolPos(azimuth=160.3753655770986°, elevation=59.974081481305134°, zenith=30.025918518694862°)
SolPos(azimuth=188.39925979964613°, elevation=60.87918930278909°, zenith=29.120810697210917°)
SolPos(azimuth=214.62987222053295°, elevation=57.493462259959394°, zenith=32.5065377400406°)
SolPos(azimuth=235.5258846451899°, elevation=50.992647293443966°, zenith=39.007352706556034°)
SolPos(azimuth=251.77304757136397°, elevation=42.790197455865076°, zenith=47.209802544134924°)Sunrise and Sunset Calculations
Calculate sunrise, sunset, and solar noon for a specific date with timezone:
result = transit_sunrise_sunset(obs, ZonedDateTime(2023, 6, 21, tz))TransitSunriseSunset{TimeZones.ZonedDateTime}(TimeZones.ZonedDateTime(2023, 6, 20, 13, 42, 2, tz"Europe/Brussels"), TimeZones.ZonedDateTime(2023, 6, 20, 5, 17, 55, tz"Europe/Brussels"), TimeZones.ZonedDateTime(2023, 6, 20, 22, 6, 10, tz"Europe/Brussels"))Find the next sunrise from a specific time in UTC:
next_sunrise(obs, DateTime(2023, 6, 21, 12, 30))2023-06-22T03:18:19Find the next sunset in UTC:
next_sunset(obs, DateTime(2023, 6, 21, 12, 30))2023-06-21T20:06:24Solar positioning algorithms
Here we provide an overview of the solar positioning algorithms currently implemented in SolarPosition.jl. Each algorithm is described with its reference paper, claimed accuracy and implementation status.
| Algorithm | Reference | Accuracy | Default Refraction | Status |
|---|---|---|---|---|
PSA | Blanco-Muriel et al. | ±0.0083° | None | ✅ |
NOAA | Global Monitoring Laboratory | ±0.0167° | HUGHES | ✅ |
Walraven | Walraven, 1978 | ±0.0100° | None | ✅ |
USNO | U.S. Naval Observatory | ±0.0500° | None | ✅ |
SPA | Reda & Andreas, 2004 | ±0.0003° | Built-in | ✅ |
Refraction correction algorithms
Atmospheric refraction correction algorithms available in SolarPosition.jl.
| Algorithm | Reference | Atmospheric Parameters | Status |
|---|---|---|---|
HUGHES | Hughes, 1985 | Pressure, Temperature | ✅ |
ARCHER | Archer et al., 1980 | None | ✅ |
BENNETT | Bennett, 1982 | Pressure, Temperature | ✅ |
MICHALSKY | Michalsky, 1988 | None | ✅ |
SG2 | Blanc & Wald, 2012 | Pressure, Temperature | ✅ |
SPARefraction | Reda & Andreas, 2004 | Pressure, Temperature | ✅ |
Extensions
SolarPosition.jl provides optional extensions that are automatically loaded when you import the corresponding packages:
| Extension | Trigger Package | Features |
|---|---|---|
| Makie | Makie.jl | Plotting recipes for solar position visualization |
| OhMyThreads | OhMyThreads.jl | Parallel computation of solar positions |
| ModelingToolkit | ModelingToolkit.jl | Symbolic solar position models for simulations |
How to Cite
If you use SolarPosition.jl in your work, please cite using the reference given in CITATION.cff.
Contributing
If you want to make contributions of any kind, please first that a look into our contributing guide directly on GitHub or the contributing page on the website